PROXY  WHOIS  RQUOTE  TEXTS  SOFT  FOREX  BBOARD
 Music  Philosophy  Code  Literature  Russian

= ROOT|Technical|Code_Examples|Perl|Proxy|pingomatic-1.013.pl =

page 4 of 7



    my $host_type = $e->w->desc;
    my $pingdef = $pingdefs{$host_type};
    if ($got eq "r") {
	if (eof $fd) {
	    $pingdef->canceled($e->w);
	    $e->w->stop;
	} else {
	    my $line = scalar <$fd>;
	    chomp $line;
	    $pingdef->add($line);
	}
    } else {
	$pingdef->addempty;
    }
}

sub show_ping_stat {
    my $res = '';
    my %host2time;
    foreach my $pingdef (map {
	$_->[1]
	} sort {
	    $a->[0] <=> $b->[0]
	} map {
	    [$_->time(10), $_];
	} values %pingdefs) {
	$host2time{$pingdef->host} = $pingdef->time(1, "as_string");
	$res .= sprintf
	    "%-30s %-6s %-1s %-10s %-10s\n",
	    $pingdef->host,
	    (defined $pingdef->type ? $pingdef->type : "ping"),
	    $pingdef->active ? 'x' : ' ',
	    $pingdef->time(1, "as_string"),
	    $pingdef->time(10, "as_string");
    }

    my $statusline = "*** " . scalar(localtime) . " update: $update s ***\n";
    print "$clearchr$statusline$res";

    if ($logfh) {
	print $logfh join("\t", epoch2isodate(time), map { $host2time{$pingdefs{$_}->host} } sort keys %pingdefs) . "\n";

    }
}

sub get_nameserver {
    @nameserver = ();
    if (open(NS, "/etc/resolv.conf")) {
	while(<NS>) {
	    s/#.*//g;
	    if (/nameserver\s+(.*)\s*$/) {
		push @nameserver, $1;
	    }
	}
	close NS;
    } else {
	warn "Can't open resolv.conf\n";
    }
    if (!@nameserver) {
	warn "Can't get any nameserver\n";
    }
}

sub try_later {
#XXX geht nicht
#     foreach my $host (keys %PingDef::try_later) {
# 	if (fork == 0) {
# 	    system("ping", "-c", "1", $host);
# 	    if (!$?) {
# 		my $pingdef = $PingDef::try_later{$host};
# 		$pingdef->{Canceled} = 0;
# 		$pingdef->{Watcher}->start;
# 		delete $PingDef::try_later{$host};
# 	    }
# 	}
#     }
}

sub handle_key {
    my $e = shift;
    my $got = $e->got;
    if ($got eq 'r') {
	if (defined(my $key = ReadKey(-1))) {
	    my $update_changed;
	    if ($key =~ /^[qx]$/) {
		kill -9 => $$;
		exit(0); # for other OSes
	    } elsif ($key eq '-' and $update > 1) {
		$update--;
		$update_changed++;
	    } elsif ($key eq '+') {
		$update++;
		$update_changed++;
	    } elsif ($key =~ /^\d$/ and $key > 0) {
		$update = $key;
		$update_changed++;
	    } elsif ($key eq 'a') {
		add_host();
	    }

	    if ($update_changed) {
=4=

1|2|3| < PREV = PAGE 4 = NEXT > |5|6|7

UP TO ROOT | UP TO DIR | TO FIRST PAGE

Google
 


E-mail Facebook Google Digg del.icio.us BlinkList Fark Furl Ma.gnolia Netscape NewsVine Reddit Slashdot Spurl StumbleUpon Technorati YahooMyWeb LiveJournal Blogmarks TwitThis Live News2.ru BobrDobr.ru Memori.ru MoeMesto.ru

0.00574899 wallclock secs ( 0.01 usr + 0.00 sys = 0.01 CPU)