git-svn: trunk@946
Nigel Horne authored on 2004/09/29 01:28:07... | ... |
@@ -20,8 +20,10 @@ |
20 | 20 |
# Usage "clamavmon [machines...]" where machines is an optional list of machine |
21 | 21 |
# running clamd. These will turn from green to red if clamd dies. Clicking on |
22 | 22 |
# the machine name gives the version of clamd running there. |
23 |
-# FIXME: clicking should give the data base information and date of last |
|
23 |
+ |
|
24 |
+# TODO: clicking should give the data base information and date of last |
|
24 | 25 |
# freshclam |
26 |
+# TODO: Resizing the program should resize the text area |
|
25 | 27 |
|
26 | 28 |
eval 'exec /usr/bin/perl -w -S $0 ${1+"$@"}' if 0; |
27 | 29 |
|
... | ... |
@@ -70,23 +72,27 @@ my $sock = IO::Socket::INET->new( |
70 | 70 |
Proto => 'udp', |
71 | 71 |
Type => SOCK_DGRAM) or die "$0: socket: $!\n"; |
72 | 72 |
|
73 |
+$sock->shutdown(SHUT_WR); |
|
73 | 74 |
$mw->fileevent($sock, 'readable', [ \&packet_ready, $sock ]); |
74 | 75 |
|
75 | 76 |
MainLoop; |
76 | 77 |
|
77 | 78 |
sub packet_ready { |
79 |
+ # print "packet_ready\n"; |
|
78 | 80 |
my $sock = shift; |
79 | 81 |
|
82 |
+ # my $mess = <$sock>; |
|
80 | 83 |
my $mess; |
81 | 84 |
$sock->recv($mess, 128); |
82 | 85 |
|
83 | 86 |
my $peeraddr = $sock->peerhost; |
84 | 87 |
|
85 |
- # print "From " . $peeraddr . " $mess\n"; |
|
88 |
+ # print "From $peeraddr $mess\n"; |
|
86 | 89 |
$text->insert('end', "From $peeraddr: $mess\n"); |
87 | 90 |
} |
88 | 91 |
|
89 | 92 |
sub pinger { |
93 |
+ # print "pinger\n"; |
|
90 | 94 |
foreach(@machines) { |
91 | 95 |
my $machine = $_->cget('-text'); |
92 | 96 |
my $sock = IO::Socket::INET->new( |
... | ... |
@@ -96,32 +102,50 @@ sub pinger { |
96 | 96 |
Timeout => 5, |
97 | 97 |
Type => SOCK_STREAM); |
98 | 98 |
|
99 |
- my $mess; |
|
100 |
- |
|
101 |
- my $background = $_->cget('-background'); |
|
102 |
- |
|
103 | 99 |
if($sock) { |
100 |
+ $mw->fileevent($sock, 'readable', [ \&pinger_ready, $_, $sock ]); |
|
104 | 101 |
print $sock "PING\n"; |
105 | 102 |
|
106 |
- $mess = <$sock>; |
|
103 |
+ $sock->shutdown(SHUT_WR); |
|
107 | 104 |
|
108 |
- close $sock; |
|
109 |
- } |
|
105 |
+ $mw->update; |
|
106 |
+ } else { |
|
107 |
+ my $background = $_->cget('-background'); |
|
110 | 108 |
|
111 |
- if($mess && ($mess ne "PONG\n")) { |
|
112 |
- # print "$machine is down\n"; |
|
113 | 109 |
if($background ne 'red') { |
114 | 110 |
$_->configure(-background => 'red'); |
115 | 111 |
} |
116 |
- } else { |
|
117 |
- # print "$machine is up\n"; |
|
118 |
- if($background ne 'green') { |
|
119 |
- $_->configure(-background => 'green'); |
|
120 |
- } |
|
121 | 112 |
} |
122 | 113 |
} |
123 | 114 |
} |
124 | 115 |
|
116 |
+sub pinger_ready { |
|
117 |
+ # print "pinger_ready\n"; |
|
118 |
+ my $machine = shift; |
|
119 |
+ my $sock = shift; |
|
120 |
+ |
|
121 |
+ # my $mess = <$sock>; |
|
122 |
+ my $mess; |
|
123 |
+ $sock->recv($mess, 6); |
|
124 |
+ |
|
125 |
+ my $peeraddr = $sock->peerhost; |
|
126 |
+ |
|
127 |
+ close $sock; |
|
128 |
+ |
|
129 |
+ my $background = $machine->cget('-background'); |
|
130 |
+ |
|
131 |
+ if($mess && ($mess ne "PONG\n")) { |
|
132 |
+ # print "$machine is down\n"; |
|
133 |
+ if($background ne 'red') { |
|
134 |
+ $machine->configure(-background => 'red'); |
|
135 |
+ } |
|
136 |
+ } else { |
|
137 |
+ # print "$machine is up\n"; |
|
138 |
+ if($background ne 'green') { |
|
139 |
+ $machine->configure(-background => 'green'); |
|
140 |
+ } |
|
141 |
+ } |
|
142 |
+} |
|
125 | 143 |
|
126 | 144 |
# TODO: this should be modeless |
127 | 145 |
sub about { |
... | ... |
@@ -159,8 +183,8 @@ sub drill { |
159 | 159 |
print $mess; |
160 | 160 |
|
161 | 161 |
my $state = $mw->DialogBox( |
162 |
- -title=>$machine, |
|
163 |
- -buttons=>["OK"] |
|
162 |
+ -title => $machine, |
|
163 |
+ -buttons => ["OK"] |
|
164 | 164 |
); |
165 | 165 |
|
166 | 166 |
$state->add('Label', |