summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBirte Kristina Friesel <derf@finalrewind.org>2025-02-09 13:56:33 +0100
committerBirte Kristina Friesel <derf@finalrewind.org>2025-02-09 13:56:33 +0100
commite403f10952ae923d9b7acd4ea8694c7854c5601b (patch)
tree736c5846ef778a59ea155cbb8c92dd6d8f81d463
parent520e11a25e0c970cc0382af4bfb3565a9ced96fa (diff)
Add support for service-specific proxies
-rwxr-xr-xbin/hafas-m12
-rw-r--r--lib/Travel/Status/DE/HAFAS.pm7
-rw-r--r--lib/Travel/Status/DE/HAFAS/Services.pm.PL11
3 files changed, 23 insertions, 7 deletions
diff --git a/bin/hafas-m b/bin/hafas-m
index 474b5b4..7b89f13 100755
--- a/bin/hafas-m
+++ b/bin/hafas-m
@@ -59,7 +59,7 @@ GetOptions(
if ($list_services) {
printf(
- "%-40s %-14s %-15s %s\n\n",
+ "%-40s %-14s %-15s %s\n\n",
'operator', 'abbr. (-s)', 'languages (-l)',
'time zone'
);
@@ -70,8 +70,10 @@ if ($list_services) {
next;
}
printf(
- "%-40s %-14s %-15s %s\n",
- @{$service}{qw(name shortname)},
+ "%-40s%1s %-14s %-15s %s\n",
+ $service->{name},
+ $service->{geoip_lock} ? q{!} : q{ },
+ $service->{shortname},
join( q{ }, @{ $service->{languages} // [] } ),
$service->{time_zone} // q{},
);
@@ -657,8 +659,8 @@ else {
}
my $entry = [
- ( $d->is_cancelled ? '--:--' : $d->datetime->strftime('%H:%M') )
- . ( $d->tz_offset ? q{*} : ( q{ } x $offset_len ) ),
+ ( $d->is_cancelled ? '--:--' : $d->datetime->strftime('%H:%M') )
+ . ( $d->tz_offset ? q{*} : ( q{ } x $offset_len ) ),
$d->is_cancelled
? q{}
: format_delay( $d->delay, $delay_len ),
diff --git a/lib/Travel/Status/DE/HAFAS.pm b/lib/Travel/Status/DE/HAFAS.pm
index 638b4af..bc274d7 100644
--- a/lib/Travel/Status/DE/HAFAS.pm
+++ b/lib/Travel/Status/DE/HAFAS.pm
@@ -45,6 +45,13 @@ sub new {
if ( $service and $hafas_instance->{$service}{ua_string} ) {
$lwp_options{agent} = $hafas_instance->{$service}{ua_string};
}
+ if ( $service
+ and my $geoip_service = $hafas_instance->{$service}{geoip_lock} )
+ {
+ if ( my $proxy = $ENV{"HAFAS_PROXY_${geoip_service}"} ) {
+ $lwp_options{proxy} = [ [ 'http', 'https' ] => $proxy ];
+ }
+ }
$ua = LWP::UserAgent->new(%lwp_options);
$ua->env_proxy;
}
diff --git a/lib/Travel/Status/DE/HAFAS/Services.pm.PL b/lib/Travel/Status/DE/HAFAS/Services.pm.PL
index f0e1d18..2adaf71 100644
--- a/lib/Travel/Status/DE/HAFAS/Services.pm.PL
+++ b/lib/Travel/Status/DE/HAFAS/Services.pm.PL
@@ -72,6 +72,10 @@ sub load_instance {
$ret{request}{ver} = $data->{options}{version};
}
+ if ( $opt{geoip_lock} ) {
+ $ret{geoip_lock} = $opt{geoip_lock};
+ }
+
if ( $opt{lang} ) {
$ret{request}{lang} = $opt{lang};
}
@@ -182,8 +186,11 @@ my %hafas_instance = (
),
stopfinder => 'https://fahrplan.oebb.at/bin/ajax-getstop.exe',
},
- PKP =>
- { load_instance( 'pl/pkp', lang => 'pol' ), ua_string => 'Dalvik/2.1.0' },
+ PKP => {
+ load_instance( 'pl/pkp', lang => 'pol' ),
+ ua_string => 'Dalvik/2.1.0',
+ geoip_lock => 'PKP'
+ },
Resrobot => { load_instance( 'se/resrobot', lang => 'sve' ), },
RMV => { load_instance( 'de/rmv', lang => 'deu' ), },
RSAG => { load_instance( 'de/rsag', lang => 'deu' ), },