8 require LWP::UserAgent;
13 my $USER="adsl_303141";
14 my $USERNAME="Jan Kratochvil";
15 my $PASSWORD=&_priv_postget("uzivatel.gtsnovera.cz.pwd");
18 my $RX_THRESHOLD=200000; # 226085
19 my $TX_THRESHOLD=200000; # 291251
21 my $STABILIZE_ON=4*60;
24 $RX_THRESHOLD=$RX_THRESHOLD*$SECS/8;
25 $TX_THRESHOLD=$TX_THRESHOLD*$SECS/8;
26 $STABILIZE_OFF/=$SECS;
27 $STABILIZE_ON /=$SECS;
29 my $ua=LWP::UserAgent->new();
31 #$ua->env_proxy(); # conflicts with 'https'
32 push @{$ua->requests_redirectable()},"POST"; # probably not needed
33 my $jar=HTTP::Cookies->new();
34 $ua->cookie_jar($jar); # important
40 my $request=HTTP::Request->new(($content ? "POST" : "GET"),$url);
41 do { $request->content($_) if $_; } for $content;
42 my $response=$ua->simple_request($request);
43 die Dumper($response)."\n".$url if !$response->is_success() || !(my $r=$response->content());
51 my $full=$ENV{"HOME"}."/priv/postget.".$base;
53 open F,$full or die "$full: $!";
54 my $r=do { local $/; <F>; } or die "read \"$full\": $!";
55 close F or die "close \"$full\": $!";
62 my $login=simple("https://uzivatel.gtsnovera.cz/cgi-bin/login.pl",
63 'login='.URI::Escape::uri_escape($USER).'&password='.URI::Escape::uri_escape($PASSWORD),
64 )->decoded_content() or die "login";
65 $login=~m{<span class="textTitle1">\Q$USERNAME\E,</span>} or die $login."\nNo name found";
69 my($ignore_read,$ignore_write);
76 return if $ignore_read;
81 die "Looping to login" if $try++>0x10;
83 $change=simple("https://uzivatel.gtsnovera.cz/cgi-bin/fup.pl",
84 'action.'.($new ? 'setManual' : 'unsetManual').'=1',
85 )->decoded_content() or die "change: ".$new;
86 } while $change=~m{No authentication cookie was sent.};
87 my $is_on =($change=~m{\bFUP active\b});
88 my $is_off=($change=~m{\bFUP not active\b});
89 $is_on==!$is_off or die $change."\nInvalid change state";
90 $new==$is_on or die $change."\nChange not changed, wanted: ".$new;
96 if (defined(my $change=$ARGV[0])) {
103 my($rx_last,$tx_last);
109 my($what,$length)=@_;
111 return if $what==$on;
113 while ($length-->0) {
115 return if $what!=$history[$idx];
121 # 1: 107040 111123 Phys-irq i8042
122 # 6: 3 0 Phys-irq floppy
125 my $fname="/proc/interrupts";
127 open F,$fname or die "open \"$fname\": $!";
128 <F> or die "header \"$fname\"";;
133 last if $f[0]=~/^[A-Z]{3}:$/; # NMI/LOC/ERR/MIS
134 $f[0]=~/^\s*\d+:$/ or die $f[0];
135 next if $f[$#f] ne "i8042";
142 close F or die "open \"$fname\": $!";
147 my $input_last=time()+0;
150 my $input_now=input();
151 my $diff=$input_now-$input;
152 die $diff if $diff<0;
153 my $time_now=time()+0;
156 $input_last=$time_now;
158 my $time_diff=$time_now-$input_last;
159 return $time_diff>$INPUT_IDLE;
164 open F,"/proc/net/dev" or die;
165 my $dev=do { local $/; <F> or die; };
167 my($rx,$tx)=($dev=~/^\s*$IFDEV:\s*(\d+)(?:\s+\d+){7}\s+(\d+)\s/m) or die;
169 if (defined $rx_last) {
170 ### print(($rx-$rx_last)."\t".($tx-$tx_last)."\n");
171 $on_now=0 if ($rx-$rx_last) > $RX_THRESHOLD;
172 $on_now=0 if ($tx-$tx_last) > $TX_THRESHOLD;
174 $on_now=1 if my $input_idle=input_idle();
177 push @history,$on_now;
179 $print=($on_now ? "." : "v") if $input_idle;
180 $print="*" if $ignore_read;
182 history(1,($input_idle ? 0 : $STABILIZE_ON));
183 history(0,$STABILIZE_OFF);
184 $ignore_read=$ignore_write;