]> git.ipfire.org Git - ipfire-2.x.git/blob - src/wio/wio.cgi
Merge branch 'next' of ssh://git.ipfire.org/pub/git/ipfire-2.x into next-suricata
[ipfire-2.x.git] / src / wio / wio.cgi
1 #!/usr/bin/perl
2 #
3 ###############################################################################
4 # #
5 # IPFire.org - A linux based firewall #
6 # Copyright (C) 2017-2018 Stephan Feddersen <sfeddersen@ipfire.org> #
7 # All Rights Reserved. #
8 # #
9 # This program is free software: you can redistribute it and/or modify #
10 # it under the terms of the GNU General Public License as published by #
11 # the Free Software Foundation, either version 3 of the License, or #
12 # (at your option) any later version. #
13 # #
14 # This program is distributed in the hope that it will be useful, #
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of #
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
17 # GNU General Public License for more details. #
18 # #
19 # You should have received a copy of the GNU General Public License #
20 # along with this program. If not, see <http://www.gnu.org/licenses/>. #
21 # #
22 ###############################################################################
23 #
24 # Version: 2018/02/27 16:54:23
25 #
26 # This wio.cgi is based on the Code from the IPCop WIO Addon
27 # and is extremly adapted to work with IPFire.
28 #
29 # Autor: Stephan Feddersen
30 # Co-Autor: Alexander Marx
31 # Co-Autor: Frank Mainz
32 #
33
34 use strict;
35
36 # enable only the following on debugging purpose
37 #use warnings;
38 #no warnings 'once';
39 #use CGI::Carp 'fatalsToBrowser';
40
41 my $debug = 0;
42
43 use Socket;
44 use POSIX qw(strftime);
45 use File::Copy;
46 use Fatal qw/ open /;
47 use Net::Telnet;
48
49 require '/var/ipfire/general-functions.pl';
50 require '/var/ipfire/network-functions.pl';
51 require '/var/ipfire/lang.pl';
52 require '/var/ipfire/header.pl';
53 require '/usr/lib/wio/wio-lib.pl';
54 require '/usr/lib/wio/wio-graphs.pl';
55
56 my $logdir = "/var/log/wio";
57
58 my ( %mainsettings, %mailsettings, %wiosettings, %cgiparams, %netsettings, %ipshash,
59 %vpnconfighash, %ovpnconfighash, %ovpnccdconfhash, %ovpnsettings, %checked, %selected, %color ) = ();
60
61 &General::readhash('/var/ipfire/main/settings', \%mainsettings);
62 &General::readhash('/var/ipfire/ethernet/settings', \%netsettings);
63 &General::readhash('/var/ipfire/dma/mail.conf', \%mailsettings);
64 &General::readhash('/var/ipfire/wio/wio.conf', \%wiosettings);
65 &General::readhash("/srv/web/ipfire/html/themes/".$mainsettings{'THEME'}."/include/colors.txt", \%color);
66 &General::readhasharray('/var/ipfire/ovpn/ovpnconfig', \%ovpnconfighash);
67 &General::readhash('/var/ipfire/ovpn/settings', \%ovpnsettings);
68 &General::readhasharray('/var/ipfire/ovpn/ccd.conf', \%ovpnccdconfhash);
69 &General::readhasharray('/var/ipfire/vpn/config', \%vpnconfighash);
70
71 my $ipadrfile = "$logdir/wioips";
72 my $onoffip = "$logdir/wioscip";
73 my $wiosettings = "/var/ipfire/wio/wio.conf";
74 my $dyndnsconfig = "/var/ipfire/ddns/config";
75 my $importfile = "$logdir/importfile";
76 my $wiofile = "$logdir/wiofile";
77 my $editfile = "$logdir/editfile";
78 my $hostfile = "/var/ipfire/main/hosts";
79 my $dhcpfile = "/var/ipfire/dhcp/fixleases";
80 my $imgstatic = "/images/wio";
81 my $rrddir = "/var/log/rrd/wio";
82 my $refreshbox = '<meta http-equiv="refresh" content="0;url=/cgi-bin/wio.cgi">';
83 my $sortstring = '^IPADR|^HOST';
84 my $ovpnaddon = "/var/ipfire/ovpn";
85 my $ovpnpid = "/var/run/openvpn.pid";
86 my $vpnpid = "/var/run/charon.pid";
87 my $redactive = "/var/ipfire/red/active";
88 my $redip = '-';
89 my $now = strftime "%Y-%m-%d", localtime;
90
91 if ( -e $redactive ) {
92 open(IPADDR, "/var/ipfire/red/local-ipaddress");
93 $redip = <IPADDR>;
94 close IPADDR;
95 chomp($redip);
96 }
97
98 my $i = 0;
99 my $idarp = 0;
100 my $iddyndns = 0;
101 my $idvpn = 0;
102 my $idovpn = 0;
103 my $idsort = 0;
104 my $nr = 0;
105 my $count = 0;
106 my $showcount = 0;
107
108 my $arpbuttontext = "$Lang::tr{'wio_show_table_on'}";
109 my $clientimportbuttontext = "$Lang::tr{'wio_show_table_on'}";
110 my $networksearchbuttontext = "$Lang::tr{'wio_show_table_on'}";
111
112 my ( $message, $infomessage, $errormessage, $importmessage ) = '';
113
114 my ( $buttontext, $host, $timestamp, $ipadr, $on, $remark, $dyndns, $dyndnsip, $sendemailon, $net, $dev, $iprange, $output, $write, $webinterface,
115 $sendemailoff, $pingmethode, $online, $color, $bgcolor, $exitcode, $id, $line, $interface, $counter, $vpnn2nip, $vpnn2nmask, $ddns, $edc,
116 $edd, $wmon, $wmoff, $ipfqdn, $http, $wioscan, $statustxt, $status, $key, $ic, $text, $image ) = ();
117
118 my ( @temp, @dates, @ipaddresses, @names, @remark, @sendemailon, @sendemailoff, @current, @ddns, @match, @webinterface, @arpcache, @arpadd, @line,
119 @hosts, @vpnstatus, @ovpnstatus, @activ, @dyndns, @pingmethode, @status, @id, @write, @log );
120
121 my @nosaved = ('ACTION','ID','CLIENTID','TIMESTAMP','IPADR','HOST','REMARK','DYNDNS','SENDEMAILON','SENDEMAILOFF','PINGMETHODE','ONLINE','WEBINTERFACE');
122
123 my @devs_color = ('GREEN','BLUE','ORANGE','RED');
124 my @devs_net = ('green0','blue0','orange0','red0');
125 my @devs_img = ('green.png','blue.png','orange.png','red.png');
126 my @devs_alt = ('green','blue','orange','red');
127
128 my %ifacecolor = ( GREEN => 'wio_run_green', BLUE => 'wio_run_blue', ORANGE => 'wio_run_orange');
129
130 &loadips();
131
132 ## some wio settings
133
134 $wiosettings{'ACTION'} = '';
135 $wiosettings{'COUNT'} = '';
136 $wiosettings{'ID'} = '';
137 $wiosettings{'CLIENTID'} = '';
138 $wiosettings{'SORT'} = 'IPADR';
139 $wiosettings{'HOST'} = '';
140 $wiosettings{'IPADR'} = '';
141 $wiosettings{'EN'} = 'on';
142 $wiosettings{'REMARK'} = '';
143 $wiosettings{'DYNDNS'} = '';
144 $wiosettings{'CLIENTREMARK'} = '';
145 $wiosettings{'SENDEMAILON'} = '';
146 $wiosettings{'SENDEMAILOFF'} = '';
147 $wiosettings{'PINGMETHODE'} = 'ip';
148 $wiosettings{'WEBINTERFACE'} = '----';
149 $wiosettings{'TIMEOUT'} = '1';
150 $wiosettings{'TIMESTAMP'} = '';
151 $wiosettings{'ONLINE'} = 'off';
152 $wiosettings{'CRON'} = '15';
153 $wiosettings{'OVPNCRON'} = '5';
154 $wiosettings{'ENABLE'} = 'off';
155 $wiosettings{'LOGGING'} = 'off';
156 $wiosettings{'MAILREMARK'} = 'off';
157 $wiosettings{'MAILSTYLE'} = 'email';
158 $wiosettings{'OVPNRWMAIL'} = 'off';
159 $wiosettings{'SHUTDOWN'} = 'off';
160 $wiosettings{'WIOGUISHOWARPTABLE'} = '';
161 $wiosettings{'WIOGUISHOWCLIENTIMPORTTABLE'} = '';
162 $wiosettings{'WIOGUISHOWNETWORKSEARCHTABLE'} = '';
163
164 &Header::getcgihash(\%wiosettings);
165 &Header::getcgihash(\%mainsettings);
166 &Header::getcgihash(\%mailsettings);
167 &Header::getcgihash(\%netsettings);
168
169 if ( $mailsettings{'USEMAIL'} eq 'on' ) { $wiosettings{'SENDEMAIL'} = 'on'; }
170 else { $wiosettings{'SENDEMAIL'} = 'off'; }
171
172 if ( -e $wiofile ) { goto WIOSCAN; }
173
174 ## get network ips
175 foreach (@devs_color) {
176 if ( $netsettings{"${_}_DEV"} ne '' ) {
177 $wiosettings{"${_}_IPLOW"} = &Network::find_next_ip_address($netsettings{"${_}_NETADDRESS"}, 1);
178 $wiosettings{"${_}_IPHIGH"} = &Network::find_next_ip_address($netsettings{"${_}_BROADCAST"}, -1);
179 }
180 }
181
182 ## save wio settings
183
184 if ( $wiosettings{'ACTION'} eq $Lang::tr{'wio_save'}.'1' ) {
185 unless ( `ps -A | grep wio.pl` ) {
186 $cgiparams{'SORT'} = $wiosettings{'SORT'};
187 $cgiparams{'CRON'} = $wiosettings{'CRON'};
188 $cgiparams{'OVPNCRON'} = $wiosettings{'OVPNCRON'};
189 $cgiparams{'ENABLE'} = $wiosettings{'ENABLE'};
190 $cgiparams{'LOGGING'} = $wiosettings{'LOGGING'};
191 $cgiparams{'TIMEOUT'} = $wiosettings{'TIMEOUT'};
192 $cgiparams{'ACTION'} = $wiosettings{'ACTION'};
193 $cgiparams{'CLIENTREMARK'} = $wiosettings{'CLIENTREMARK'};
194 $cgiparams{'MAILREMARK'} = $wiosettings{'MAILREMARK'};
195 $cgiparams{'MAILSTYLE'} = $wiosettings{'MAILSTYLE'};
196 $cgiparams{'OVPNRWMAIL'} = $wiosettings{'OVPNRWMAIL'};
197 $cgiparams{'SHUTDOWN'} = $wiosettings{'SHUTDOWN'};
198
199 &General::writehash($wiosettings, \%cgiparams);
200 &General::readhash($wiosettings, \%wiosettings);
201
202 if ( $wiosettings{'ENABLE'} eq 'off' ) {
203 &WIO::clearfile($ipadrfile);
204 unlink glob "$rrddir/*";
205 }
206 }
207 else {
208 $infomessage = "$Lang::tr{'wio_error_function'}";
209 }
210 }
211
212 ## save imported clients
213
214 if ( $wiosettings{'ACTION'} eq $Lang::tr{'wio_save'}.'2' ) {
215 unless ( `ps -A | grep wio.pl` ) {
216 while ( $count < $wiosettings{'COUNT'} ) {
217 if ( defined($wiosettings{"USE$count"}) && $wiosettings{"USE$count"} eq 'on' ) {
218 $wiosettings{'CLIENTID'} = $wiosettings{'CLIENTID$count'};
219 $wiosettings{'TIMESTAMP'} = $wiosettings{"TIMESTAMP$count"};
220 $wiosettings{'IPADR'} = $wiosettings{"IPADR$count"};
221 $wiosettings{'HOST'} = $wiosettings{"HOST$count"};
222 $wiosettings{'EN'} = $wiosettings{"EN$count"};
223 $wiosettings{'REMARK'} = $wiosettings{"REMARK$count"};
224 $wiosettings{'DYNDNS'} = $wiosettings{"DYNDNS$count"};
225 $wiosettings{'SENDEMAILON'} = $wiosettings{"SENDEMAILON$count"};
226 $wiosettings{'SENDEMAILOFF'} = $wiosettings{"SENDEMAILOFF$count"};
227 $wiosettings{'PINGMETHODE'} = $wiosettings{"PINGMETHODE$count"};
228 $wiosettings{'ONLINE'} = $wiosettings{"ONLINE$count"};
229
230 &validSave();
231
232 if ($errormessage) {
233 open(FILE, ">> $editfile");
234 print FILE "$wiosettings{'CLIENTID'},$wiosettings{'TIMESTAMP'},$wiosettings{'IPADR'},$wiosettings{'HOST'},$wiosettings{'EN'},$wiosettings{'REMARK'},$wiosettings{'DYNDNS'},$wiosettings{'SENDEMAILON'},$wiosettings{'SENDEMAILOFF'},$wiosettings{'PINGMETHODE'},$wiosettings{'ONLINE'},$wiosettings{'WEBINTERFACE'}\n";
235 close(FILE);
236 $importmessage = $errormessage;
237 }
238 else {
239 $wiosettings{'CLIENTID'} = &General::findhasharraykey (\%ipshash);
240 unshift (@current, "$wiosettings{'CLIENTID'},$wiosettings{'TIMESTAMP'},$wiosettings{'IPADR'},$wiosettings{'HOST'},$wiosettings{'EN'},$wiosettings{'REMARK'},$wiosettings{'DYNDNS'},$wiosettings{'SENDEMAILON'},$wiosettings{'SENDEMAILOFF'},$wiosettings{'PINGMETHODE'},$wiosettings{'ONLINE'},$wiosettings{'WEBINTERFACE'}\n");
241 &SortDataFile('',@current);
242 }
243 }
244 $count++;
245 }
246
247 map ($wiosettings{$_} = '' ,@nosaved);
248 unlink ($importfile);
249 if ( -e "$editfile" ) { goto EDIT; }
250 }
251 else {
252 $infomessage = "$Lang::tr{'wio_error_function'}";
253 }
254 }
255
256 ## add or update client
257
258 if ( $wiosettings{'ACTION'} eq $Lang::tr{'wio_client_add'} ) {
259 unless ( `ps -A | grep wio.pl` ) {
260 &validSave();
261
262 unless ($errormessage) {
263 if ( $wiosettings{'ID'} eq '' && $wiosettings{'ACTION'} ne $Lang::tr{'edit'} ) {
264 $wiosettings{'CLIENTID'} = &General::findhasharraykey (\%ipshash);
265 unshift (@current, "$wiosettings{'CLIENTID'},$wiosettings{'TIMESTAMP'},$wiosettings{'IPADR'},$wiosettings{'HOST'},$wiosettings{'EN'},$wiosettings{'REMARK'},$wiosettings{'DYNDNS'},$wiosettings{'SENDEMAILON'},$wiosettings{'SENDEMAILOFF'},$wiosettings{'PINGMETHODE'},$wiosettings{'ONLINE'},$wiosettings{'WEBINTERFACE'}\n");
266 }
267 else {
268 @current[$wiosettings{'ID'}] = "$wiosettings{'CLIENTID'},$wiosettings{'TIMESTAMP'},$wiosettings{'IPADR'},$wiosettings{'HOST'},$wiosettings{'EN'},$wiosettings{'REMARK'},$wiosettings{'DYNDNS'},$wiosettings{'SENDEMAILON'},$wiosettings{'SENDEMAILOFF'},$wiosettings{'PINGMETHODE'},$wiosettings{'ONLINE'},$wiosettings{'WEBINTERFACE'}\n";
269 }
270 }
271 else { goto ERROR; }
272
273 map ($wiosettings{$_} = '' ,@nosaved);
274 &SortDataFile('',@current);
275 }
276 else {
277 $infomessage = "$Lang::tr{'wio_error_function'}";
278 }
279 }
280
281 ## show / hide arptable
282
283 if ( $wiosettings{'WIOGUISHOWARPTABLE'} eq 'arptable' ) {
284 if ( $wiosettings{'ACTION'} eq $Lang::tr{'wio_show_table_off'} ) {
285 $wiosettings{'WIOGUISHOWARPTABLE'} = 'off';
286 $arpbuttontext = "$Lang::tr{'wio_show_table_on'}";
287 }
288 else {
289 $wiosettings{'WIOGUISHOWARPTABLE'} = 'on';
290 $arpbuttontext = "$Lang::tr{'wio_show_table_off'}";
291 }
292 }
293
294 ## show / hide clientimporttable
295
296 if ( $wiosettings{'WIOGUISHOWCLIENTIMPORTTABLE'} eq 'clientimport' ) {
297 if ( $wiosettings{'ACTION'} eq $Lang::tr{'wio_show_table_off'} ) {
298 $wiosettings{'WIOGUISHOWCLIENTIMPORTTABLE'} = 'off';
299 $clientimportbuttontext = "$Lang::tr{'wio_show_table_on'}";
300 }
301 else {
302 $wiosettings{'WIOGUISHOWCLIENTIMPORTTABLE'} = 'on';
303 $clientimportbuttontext = "$Lang::tr{'wio_show_table_off'}";
304 }
305 }
306
307 ## show / hide networksearchtable
308
309 if ( $wiosettings{'WIOGUISHOWNETWORKSEARCHTABLE'} eq 'networksearch' ) {
310 if ( $wiosettings{'ACTION'} eq $Lang::tr{'wio_show_table_off'} ) {
311 $wiosettings{'WIOGUISHOWNETWORKSEARCHTABLE'} = 'off';
312 $networksearchbuttontext = "$Lang::tr{'wio_show_table_on'}";
313 }
314 else {
315 $wiosettings{'WIOGUISHOWNETWORKSEARCHTABLE'} = 'on';
316 $networksearchbuttontext = "$Lang::tr{'wio_show_table_off'}";
317 }
318 }
319
320 ## add arp client
321
322 if ( $wiosettings{'ACTION'} eq $Lang::tr{'wio_add'} ) {
323 unless ( `ps -A | grep wio.pl` ) {
324 open(FILE, "$logdir/.arpcache");
325 @arpadd = <FILE>;
326 close (FILE);
327
328 chomp(@arpadd[$wiosettings{'ID'}]);
329 @temp = split (/\,/, @arpadd[$wiosettings{'ID'}]);
330
331 $wiosettings{'CLIENTID'} = &General::findhasharraykey (\%ipshash);
332 $wiosettings{'IPADR'} = $temp[1];
333 $wiosettings{'HOST'} = $temp[2];
334 $wiosettings{'EN'} = 'on';
335
336 $wiosettings{'PINGMETHODE'} = 'ip';
337 $wiosettings{'ONLINE'} = 'off';
338
339 open(FILE, ">> $editfile");
340 print FILE "$wiosettings{'CLIENTID'},$wiosettings{'TIMESTAMP'},$wiosettings{'IPADR'},$wiosettings{'HOST'},$wiosettings{'EN'},$wiosettings{'REMARK'},$wiosettings{'DYNDNS'},$wiosettings{'SENDEMAILON'},$wiosettings{'SENDEMAILOFF'},$wiosettings{'PINGMETHODE'},$wiosettings{'ONLINE'},$wiosettings{'WEBINTERFACE'}\n";
341 close(FILE);
342
343 goto EDIT;
344 }
345 else {
346 undef($wiosettings{'ID'});
347 $infomessage = "$Lang::tr{'wio_error_function'}";
348 }
349 }
350
351 ## enable / disable client || enable / disable dyndns || enable / disable sendemailon || enable / disable sendemailoff || change ip / fqdn
352
353 if ( $wiosettings{'ACTION'} eq $Lang::tr{'enable disable client'} ) { $edc = 'on'; }
354 if ( $wiosettings{'ACTION'} eq $Lang::tr{'enable disable dyndns'} ) { $edd = 'on'; }
355 if ( $wiosettings{'ACTION'} eq $Lang::tr{'wio_mail_online'} ) { $wmon = 'on'; }
356 if ( $wiosettings{'ACTION'} eq $Lang::tr{'wio_mail_offline'} ) { $wmoff = 'on'; }
357 if (( $wiosettings{'ACTION'} eq $Lang::tr{'wio_ip_on'} ) || ( $wiosettings{'ACTION'} eq $Lang::tr{'wio_fqdn_on'} )) { $ipfqdn = 'on'; }
358
359 if ( defined($edc) || defined($edd) || defined($wmon) || defined($wmoff) || defined($ipfqdn) ) {
360 unless ( `ps -A | grep wio.pl` ) {
361 chomp(@current[$wiosettings{'ID'}]);
362 @temp = split (/\,/, @current[$wiosettings{'ID'}]);
363
364 if ( $edc eq 'on' ) {
365 $temp[4] = $temp[4] ne '' ? '' : 'on';
366 $temp[10] = '';
367 $temp[11] = '';
368 $temp[1] = '';
369 unlink "$rrddir/$temp[0].rrd";
370 }
371 elsif ( $edd eq 'on' ) { $temp[6] = $temp[6] ne '' ? '' : 'on'; }
372 elsif ( $wmon eq 'on' ) { $temp[7] = $temp[7] ne '' ? '' : 'on'; }
373 elsif ( $wmoff eq 'on' ) { $temp[8] = $temp[8] ne '' ? '' : 'on'; }
374 elsif ( $ipfqdn eq 'on' ) { $temp[9] = $temp[9] eq 'fqdn' ? 'ip' : 'fqdn'; }
375
376 @current[$wiosettings{'ID'}] = join (',', @temp)."\n";
377 undef($wiosettings{'ID'});
378
379 &writeips();
380 }
381 else {
382 undef($wiosettings{'ID'});
383 $infomessage = "$Lang::tr{'wio_error_function'}";
384 }
385 }
386
387 ## refresh wio status || refresh single client status
388
389 if ( $wiosettings{'ACTION'} eq $Lang::tr{'wio_refresh'} || $wiosettings{'ACTION'} eq $Lang::tr{'wio_sc_refresh'} ) {
390
391 if ( $wiosettings{'ACTION'} eq $Lang::tr{'wio_sc_refresh'} ) {
392 open(FILE, "> $onoffip");
393 print FILE @current[$wiosettings{'ID'}];
394 close(FILE);
395
396 undef($wiosettings{'ID'});
397 }
398
399 unless ( `ps -A | grep wio.pl` ) {
400
401 &Header::showhttpheaders();
402 &Header::openpage($Lang::tr{'wio'}, 1, $refreshbox);
403 &Header::openbigbox('100%', 'left', '');
404 &Header::openbox('100%', 'left', $Lang::tr{'wio_info'});
405
406 print"
407 <table align='center' width='100%'>
408 <tr><td align='center'>$Lang::tr{'wio_msg'}</td></tr>
409 <tr><td>&nbsp;</td></tr>
410 <tr><td align='center'><img align='middle' src='/images/indicator.gif' /></td></tr>
411 </table>
412 ";
413
414 &Header::closebox();
415 &Header::closebigbox();
416 &Header::closepage();
417
418 while ( system("/usr/local/bin/wiohelper", "&") ) {}
419
420 exit 0;
421 }
422 else {
423 $infomessage = "$Lang::tr{'wio_already_running'}";
424 unlink($onoffip);
425 }
426
427 }
428
429 ## refresh dyndns ip
430
431 if ( $wiosettings{'ACTION'} eq $Lang::tr{'wio_dyndns_refresh'} ) {
432 unless ( `ps -A | grep wio.pl` ) {
433 chomp(@current[$wiosettings{'ID'}]);
434 @temp = split (/\,/, @current[$wiosettings{'ID'}]);
435
436 ($temp[2], $infomessage) = &WIO::getdyndnsip($temp[2], $temp[3]);
437
438 @current[$wiosettings{'ID'}] = join (',', @temp)."\n";
439
440 &writeips();
441
442 undef($wiosettings{'ID'});
443 }
444 else {
445 $infomessage = "$Lang::tr{'wio_error_function'}";
446 }
447 }
448
449 ## edit client
450
451 if ( $wiosettings{'ACTION'} eq $Lang::tr{'edit'} ) {
452 unless ( `ps -A | grep wio.pl` ) {
453 chomp(@current[$wiosettings{'ID'}]);
454 @temp = split (/\,/, @current[$wiosettings{'ID'}]);
455
456 $wiosettings{'CLIENTID'} = $temp[0];
457 $wiosettings{'TIMESTAMP'} = $temp[1];
458 $wiosettings{'IPADR'} = $temp[2];
459 $wiosettings{'HOST'} = $temp[3];
460 $wiosettings{'EN'} = $temp[4];
461 $wiosettings{'REMARK'} = $temp[5];
462 $wiosettings{'DYNDNS'} = $temp[6];
463 $wiosettings{'SENDEMAILON'} = $temp[7];
464 $wiosettings{'SENDEMAILOFF'} = $temp[8];
465 $wiosettings{'PINGMETHODE'} = $temp[9];
466 $wiosettings{'ONLINE'} = $temp[10];
467 $wiosettings{'WEBINTERFACE'} = $temp[11];
468 }
469 else {
470 undef($wiosettings{'ACTION'});
471 $infomessage = "$Lang::tr{'wio_error_function'}";
472 }
473 }
474
475 ## remove client
476
477 if ( $wiosettings{'ACTION'} eq $Lang::tr{'wio_remove_client'} ) {
478 unless ( `ps -A | grep wio.pl` ) {
479 chomp(@current[$wiosettings{'ID'}]);
480
481 @temp = split (/\,/, @current[$wiosettings{'ID'}]);
482
483 unlink "$rrddir/$temp[0].rrd";
484
485 splice (@current,$wiosettings{'ID'},1);
486
487 &writeips();
488
489 undef($wiosettings{'ID'});
490 }
491 else {
492 undef($wiosettings{'ID'});
493 $infomessage = "$Lang::tr{'wio_error_function'}";
494 }
495 }
496
497 ## remove all clients
498
499 if ( $wiosettings{'ACTION'} eq $Lang::tr{'wio_remove_all'} ) {
500 unless ( `ps -A | grep wio.pl` ) {
501 &WIO::clearfile($ipadrfile);
502 unlink glob "$rrddir/*";
503 undef(@current);
504 }
505 else {
506 $infomessage = "$Lang::tr{'wio_error_function'}";
507 }
508 }
509
510 ## back function
511
512 if ( $wiosettings{'ACTION'} eq $Lang::tr{'wio_back'} ) {
513 if ( -e "$importfile" ) { unlink ($importfile); }
514 map ($wiosettings{$_} = '' ,@nosaved);
515 undef($errormessage);
516 }
517
518 ## import hosts, fixleases or csv file || scan networks (green/blue/orange)
519
520 if ( $wiosettings{'ACTION'} eq 'wio_run_green' ||
521 $wiosettings{'ACTION'} eq 'wio_run_blue' ||
522 $wiosettings{'ACTION'} eq 'wio_run_orange') { $wioscan = 'on'; }
523
524 if ( $wiosettings{'ACTION'} eq $Lang::tr{'wio_import'}.'1' ||
525 $wiosettings{'ACTION'} eq $Lang::tr{'wio_import'}.'2' ||
526 $wiosettings{'ACTION'} eq $Lang::tr{'wio_import'}.'3' ||
527 defined($wioscan) || defined($importmessage) ) {
528
529 unless ( `ps -A | grep wio.pl` ) {
530 if ( $wiosettings{'ACTION'} eq $Lang::tr{'wio_import'}.'1' && $importmessage eq '' ) {
531
532 &Header::getcgihash(\%wiosettings, {'wantfile' => 1, 'filevar' => 'CSVFILE'});
533
534 if ( $wiosettings{'CSVFILE'} eq '' ) {
535 $errormessage = $Lang::tr{'wio_no_file_selected'};
536 $message = 2; goto ERROR;
537 }
538
539 if ( $wiosettings{'CSVFILE'} =~ /[^a-z0-9A-Z\ \.\-\_\:\\]+/ ) {
540 $errormessage = $Lang::tr{'wio_no_csv_error'};
541 $message = 2; goto ERROR;
542 }
543
544 if ( !($wiosettings{'CSVFILE'} =~ /.csv$/) ) {
545 $errormessage = $Lang::tr{'wio_no_csv'};
546 $message = 2; goto ERROR;
547 }
548
549 if (copy($wiosettings{'CSVFILE'}, "$logdir/importfile") != 1) {
550 $errormessage = $!;
551 $message = 2; goto ERROR;
552 }
553 }
554
555 EDIT:
556
557 &General::readhash($wiosettings, \%wiosettings);
558
559 &Header::showhttpheaders();
560 &Header::openpage($Lang::tr{'wio'}, 1, '');
561 &Header::openbigbox('100%', 'left');
562
563 if ($importmessage) {
564 &Header::openbox('100%', 'left', $Lang::tr{'wio_error'}, 'error');
565 print" <table width='100%'><tr><td><font class='base'>$importmessage</font></td></tr></table>";
566 &Header::closebox();
567 }
568
569 if ( -e "$editfile" ) {
570 open(FILE, "< $editfile" ); }
571 elsif ( $wiosettings{'ACTION'} eq $Lang::tr{'wio_import'}.'1' ) {
572 open(FILE, "< $importfile" ); }
573 elsif ( $wiosettings{'ACTION'} eq $Lang::tr{'wio_import'}.'2' ) {
574 open(FILE, "< $hostfile" ); }
575 elsif ( $wiosettings{'ACTION'} eq $Lang::tr{'wio_import'}.'3' ) {
576 open(FILE, "< $dhcpfile" ); }
577 elsif ( $wioscan eq 'on' ) {
578
579 foreach (keys(%ifacecolor)) {
580 if ( $netsettings{"${_}_DEV"} eq $wiosettings{'ID'} ) {
581 $dev = $netsettings{"${_}_DEV"};
582 $iprange = $wiosettings{"${_}_IPLOW"} . "-" . $wiosettings{"${_}_IPHIGH"};
583
584 if ( $_ eq 'GREEN' ) { $color = "$Header::colourgreen"; $net = $Lang::tr{'wio_msg_green'}; }
585 elsif ( $_ eq 'BLUE' ) { $color = "$Header::colourblue"; $net = $Lang::tr{'wio_msg_blue'}; }
586 else { $color = "$Header::colourorange"; $net = $Lang::tr{'wio_msg_orange'}; }
587 }
588 }
589
590 &Header::openbox('100%', 'left', $Lang::tr{'wio_info'});
591 print"<table width='100%'>
592 <tr><td align='center'><font class='base'>$Lang::tr{'wio_msg_left'} </font><font class='base' color='$color'><b>$net</b></font> $Lang::tr{'wio_msg_center'} <font class='base' color='$color'><b>$dev</b></font><font class='base'> $Lang::tr{'wio_msg_right'} $Lang::tr{'wio_msg_hint'}</font></td></tr>
593 <tr><td>&nbsp;</td></tr>
594 <tr><td align='center'><img align='middle' src='/images/indicator.gif' /></td></tr>
595 </table>";
596 &Header::closebox();
597 &Header::closebigbox();
598
599 open(FILE, "/usr/local/bin/wioscan -wsa $dev $iprange |" );
600
601 }
602
603 @hosts = <FILE>;
604 close(FILE);
605
606 if ( $wioscan ne 'on' && ! -e $wiofile ) { @hosts = sort @hosts; }
607 else {
608 open(FILE, "> $wiofile");
609 print FILE @hosts;
610 close(FILE);
611
612 print"<meta http-equiv=\"refresh\" content=\"0; URL=$ENV{'SCRIPT_NAME'}\">";
613 exit 0;
614 }
615
616 WIOSCAN:
617
618 if ( -e $wiofile ) {
619 open(FILE, "< $wiofile");
620 @hosts = <FILE>;
621 close (FILE);
622
623 &General::readhash($wiosettings, \%wiosettings);
624
625 &Header::showhttpheaders();
626 &Header::openpage($Lang::tr{'wio'}, 1, '');
627 &Header::openbigbox('100%', 'left');
628 }
629
630 foreach (@hosts) {
631 chomp;
632
633 @line = split (/\,/, $_);
634
635 if ( -e $editfile || -e $importfile ) {
636 $wiosettings{'CLIENTID$count'} = $line[0];
637 $wiosettings{'TIMESTAMP$count'} = $line[1];
638 $wiosettings{'IPADR$count'} = $line[2];
639 $wiosettings{'HOST$count'} = $line[3];
640 $wiosettings{'EN$count'} = $line[4];
641 $wiosettings{'REMARK$count'} = $line[5];
642 $wiosettings{'DYNDNS$count'} = $line[6];
643 $wiosettings{'SENDEMAILON$count'} = $line[7];
644 $wiosettings{'SENDEMAILOFF$count'} = $line[8];
645 $wiosettings{'PINGMETHODE$count'} = $line[9];
646 $wiosettings{'ONLINE$count'} = $line[10];
647 $wiosettings{'WEBINTERFACE$count'} = $line[11];
648 $wiosettings{'USE$count'} = 'on';
649 }
650 else {
651 $wiosettings{'IPADR$count'} = $line[1];
652 $wiosettings{'EN$count'} = 'on';
653 $wiosettings{'PINGMETHODE$count'} = 'ip';
654 $wiosettings{'USE$count'} = 'on';
655
656 if ( $wiosettings{'ACTION'} eq $Lang::tr{'wio_import'}.'2' ) {
657 $wiosettings{'HOST$count'} = $line[2];
658 $wiosettings{'DOM$count'} = $line[3];
659 $wiosettings{'REMARK$count'} = '';
660 }
661 elsif ( $wioscan eq 'on' || -e $wiofile ) {
662 $wiosettings{'HOST$count'} = gethostbyaddr(inet_aton($line[1]), AF_INET);
663 if ($wiosettings{'HOST$count'} eq '') { $wiosettings{'HOST$count'} = $line[1]; }
664 $wiosettings{'REMARK$count'} = '';
665 $wiosettings{'WEBINTERFACE$count'} = '';
666 }
667 else {
668 $wiosettings{'HOST$count'} = $line[7];
669 $wiosettings{'REMARK$count'} = $line[6];
670 }
671 }
672
673 $checked{'EN$count'}{'on'} = ($wiosettings{'EN$count'} eq '' ) ? '' : "checked='checked'";
674
675 $checked{'DYNDNS$count'}{'on'} = ($wiosettings{'DYNDNS$count'} eq '' ) ? '' : "checked='checked'";
676 $checked{'SENDEMAILON$count'}{'on'} = ($wiosettings{'SENDEMAILON$count'} eq '' ) ? '' : "checked='checked'";
677 $checked{'SENDEMAILOFF$count'}{'on'} = ($wiosettings{'SENDEMAILOFF$count'} eq '' ) ? '' : "checked='checked'";
678
679 $checked{'PINGMETHODE$count'}{'ip'} = $checked{'PINGMETHODE$count'}{'fqdn'} = '';
680 $checked{'PINGMETHODE$count'}{$wiosettings{'PINGMETHODE$count'}} = "checked='checked'";
681
682 $checked{'USE$count'}{'on'} = ($wiosettings{'USE$count'} eq '' ) ? '' : "checked='checked'";
683
684 $selected{'WEBINTERFACE$count'}{'----'} = '';
685 $selected{'WEBINTERFACE$count'}{'HTTP'} = '';
686 $selected{'WEBINTERFACE$count'}{'HTTPS'} = '';
687 $selected{'WEBINTERFACE$count'}{$wiosettings{'WEBINTERFACE$count'}} = "selected='selected'";
688
689 if (! &WIO::checkinto($wiosettings{'IPADR$count'}, $wiosettings{'HOST$count'}, @current) ) {
690
691 if ( $importmessage ) {
692 &Header::openbox('100%', 'left', "$Lang::tr{'wio_import_data'}'$wiosettings{'HOST$count'}'$Lang::tr{'wio_import_data1'}");
693 }
694 elsif ( $wiosettings{'ACTION'} eq $Lang::tr{'wio_import'}.'1' || $wioscan eq 'on' || -e $wiofile || -e $editfile ) {
695 &Header::openbox('100%', 'left', "$Lang::tr{'wio_import_data'}'$wiosettings{'HOST$count'}'$Lang::tr{'wio_import_data2'}");
696 }
697 elsif ( $wiosettings{'ACTION'} eq $Lang::tr{'wio_import'}.'2' ) {
698 &Header::openbox('100%', 'left', "$Lang::tr{'wio_import_data'}'$wiosettings{'HOST$count'}.$wiosettings{'DOM$count'}'$Lang::tr{'wio_import_data2'}");
699 }
700 else {
701 &Header::openbox('100%', 'left', $Lang::tr{'wio_import_leases'});
702 }
703
704 print"
705 <form method='post' action='$ENV{'SCRIPT_NAME'}' enctype='multipart/form-data'>
706 <input type='hidden' name='ONLINE$count' value='$wiosettings{'ONLINE$count'}' />
707
708 <table width='100%'>
709 <tr>
710 <td>$Lang::tr{'wio_use'}</td>
711 <td><input type='checkbox' name='USE$count' $checked{'USE$count'}{'on'} /></td>
712 </tr>
713 <tr>
714 <td>$Lang::tr{'wio_client_enable'}</td>
715 <td><input type='checkbox' name='EN$count' $checked{'EN$count'}{'on'} /></td>
716 </tr>
717 <tr>
718 <td>$Lang::tr{'host ip'}:</td>
719 <td><input type='text' name='IPADR$count' value='$wiosettings{'IPADR$count'}' size='18' /></td>
720 <td>$Lang::tr{'hostname'}:</td>
721 ";
722
723 if ( $wiosettings{'ACTION'} eq $Lang::tr{'wio_import'}.'2' ) {
724 print"<td><input type='text' name='HOST$count' size='18' value='$wiosettings{'HOST$count'}.$wiosettings{'DOM$count'}' /></td>";
725 }
726 else {
727 print"<td><input type='text' name='HOST$count' size='18' value='$wiosettings{'HOST$count'}' /></td>";
728 }
729
730 print"
731 <td>$Lang::tr{'remark'}:</td>
732 <td><input type='text' name='REMARK$count' value='$wiosettings{'REMARK$count'}' size='18' /></td>
733 </tr>
734 <tr>
735 <td class='base'>$Lang::tr{'wio_ping_send'}:</td>
736 <td align='left'><input type='radio' name='PINGMETHODE$count' value='ip' $checked{'PINGMETHODE$count'}{'ip'} />&nbsp;IP&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type='radio' name='PINGMETHODE$count' value='fqdn' $checked{'PINGMETHODE$count'}{'fqdn'} />&nbsp;FQDN</td>
737 <td>$Lang::tr{'wio_dyndns'}:</td>
738 <td><input type='checkbox' name='DYNDNS$count' $checked{'DYNDNS$count'}{'on'} /></td>
739 ";
740
741 if ( $wiosettings{'SENDEMAIL'} eq 'on' ) {
742 print"<td>$Lang::tr{'wio_sendemail'}:</td>
743 <td><input type='checkbox' name='SENDEMAILON$count' $checked{'SENDEMAILON$count'}{'on'} />&nbsp;$Lang::tr{'wio_online'}&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type='checkbox' name='SENDEMAILOFF$count' $checked{'SENDEMAILOFF$count'}{'on'} />&nbsp;$Lang::tr{'wio_offline'}</td>";
744 }
745 else {
746 print"<td colspan='2'>&nbsp;</td>";
747 }
748
749 print"
750 </tr>
751 <tr>
752 <td height='30'>$Lang::tr{'wio_link_open'}:</td>
753 <td align='left' colspan='5'>
754 <select size='1' name='WEBINTERFACE$count' width='80' style='width: 80px'>
755 <option value='----' $selected{'WEBINTERFACE$count'}{'----'}>----</option>
756 <option value='HTTP' $selected{'WEBINTERFACE$count'}{'HTTP'}>HTTP</option>
757 <option value='HTTPS' $selected{'WEBINTERFACE$count'}{'HTTPS'}>HTTPS</option>
758 </select>
759 </td>
760 </tr>
761 </table>
762 ";
763
764 &Header::closebox();
765 $showcount++;
766 }
767 $count++;
768 }
769
770 if ( $showcount gt 0 ) {
771 &Header::openbox('100%', 'left', $Lang::tr{'wio_import_infos'});
772
773 print"
774 <table width='100%'>
775 <tr>
776 ";
777
778 if ($importmessage) { print"<td>&nbsp;</td>"; }
779 else { print"<td><font color='$color{'color11'}'>$Lang::tr{'wio_import_infos_csv'}</font></td>"; }
780
781 print"
782 </tr>
783 <tr><td colspan='4'>&nbsp;</td></tr>
784 </table>
785 <table width='100%'>
786 <tr>
787 <td width='25%'>&nbsp;</td>
788 <td width='25%'><input type='hidden' name='COUNT' value='$count' /><input type='hidden' name='ACTION' value='$Lang::tr{'wio_save'}2' /><input type='submit' name='SUBMIT' value='$Lang::tr{'wio_save'}' /></form></td>
789 <td width='25%'><form method='post' action='$ENV{'SCRIPT_NAME'}' enctype='multipart/form-data'><input type='submit' name='ACTION' value='$Lang::tr{'wio_back'}' /></form></td>
790 <td width='25%'>&nbsp;</td>
791 </tr>
792 </table>
793 ";
794
795 &Header::closebox();
796 &Header::closebigbox();
797 &Header::closepage();
798 }
799 else {
800 print"<meta http-equiv=\"refresh\" content=\"0; URL=$ENV{'SCRIPT_NAME'}?INFO\">";
801 }
802
803 if ( -e "$editfile" ) { unlink ($editfile); }
804 if ( -e "$wiofile" ) { unlink($wiofile); }
805 exit 0;
806 }
807 else {
808 $infomessage = "$Lang::tr{'wio_error_function'}";
809 }
810 }
811
812 ## skript function
813
814 if ($ENV{'QUERY_STRING'} =~ /$sortstring/ ) {
815 my $string = $ENV{'QUERY_STRING'};
816
817 if ( $string eq 'INFO' ) {
818 $infomessage = $Lang::tr{'wio_import_info_csv'};
819 }
820 else {
821 &General::readhash($wiosettings, \%wiosettings);
822
823 my $actual = $wiosettings{'SORT'};
824
825 if ($actual =~ $string) {
826 my $Rev = '';
827 if ($actual !~ 'Rev') { $Rev = 'Rev'; }
828 $string.=$Rev;
829 }
830
831 system("/bin/sed -i 's#$wiosettings{'SORT'}#$string#g' $wiosettings");
832
833 $wiosettings{'SORT'} = $string;
834 map ($wiosettings{$_} = '' ,@nosaved);
835 &SortDataFile('',@current);
836 }
837 }
838
839 ## main part
840
841 ERROR:
842
843 unless($message == 1) { &General::readhash($wiosettings, \%wiosettings); }
844
845 for ($i=5; $i<=60; $i+=5) { $selected{'CRON'}{$i} = ''; }
846
847 $selected{'CRON'}{$wiosettings{'CRON'}} = "selected='selected'";
848
849 for ($i=1; $i<=15; $i++) {
850 $selected{'TIMEOUT'}{$i} = '';
851 $selected{'OVPNCRON'}{$i} = '';
852 }
853
854 $selected{'TIMEOUT'}{$wiosettings{'TIMEOUT'}} = "selected='selected'";
855 $selected{'OVPNCRON'}{$wiosettings{'OVPNCRON'}} = "selected='selected'";
856
857 $checked{'ENABLE'}{'off'} = $checked{'ENABLE'}{'on'} = '';
858 $checked{'ENABLE'}{$wiosettings{'ENABLE'}} = "checked='checked'";
859
860 $checked{'LOGGING'}{'off'} = $checked{'LOGGING'}{'on'} = '';
861 $checked{'LOGGING'}{$wiosettings{'LOGGING'}} = "checked='checked'";
862
863 $checked{'CLIENTREMARK'}{'off'} = $checked{'CLIENTREMARK'}{'on'} = '';
864 $checked{'CLIENTREMARK'}{$wiosettings{'CLIENTREMARK'}} = "checked='checked'";
865
866 $checked{'MAILREMARK'}{'off'} = $checked{'MAILREMARK'}{'on'} = '';
867 $checked{'MAILREMARK'}{$wiosettings{'MAILREMARK'}} = "checked='checked'";
868
869 $checked{'OVPNRWMAIL'}{'off'} = $checked{'OVPNRWMAIL'}{'on'} = '';
870 $checked{'OVPNRWMAIL'}{$wiosettings{'OVPNRWMAIL'}} = "checked='checked'";
871
872 $checked{'SHUTDOWN'}{'off'} = $checked{'SHUTDOWN'}{'on'} = '';
873 $checked{'SHUTDOWN'}{$wiosettings{'SHUTDOWN'}} = "checked='checked'";
874
875 $checked{'MAILSTYLE'}{'smail'} = $checked{'MAILSTYLE'}{'email'} = '';
876 $checked{'MAILSTYLE'}{$wiosettings{'MAILSTYLE'}} = "checked='checked'";
877
878 &Header::showhttpheaders();
879 &Header::openpage($Lang::tr{'wio'}, 1, "<meta http-equiv='expires' content='-1'><meta http-equiv='cache-control' content='no-store, no-cache, must-revalidate'><meta http-equiv='pragma' content='no-cache'>");
880 &Header::openbigbox('100%', 'left', '');
881
882 ## DEBUG / ERROR / INFO / UPDATE
883
884 if ( $debug ) {
885 &Header::openbox('100%', 'left', 'DEBUG', 'warning');
886
887 print"errormessage: $errormessage<br />\n";
888 print"infomessage: $infomessage<br />\n";
889
890 &hrline();
891
892 my $wiodebug = 0;
893 foreach (sort keys %wiosettings) {
894 print"$_ = $wiosettings{$_}<br />\n";
895 $wiodebug++;
896 }
897
898 &hrline();
899
900 my $netdebug = 0;
901 foreach (sort keys %netsettings) {
902 print"$_ = $netsettings{$_}<br />\n";
903 $netdebug++;
904 }
905 &Header::closebox();
906 }
907
908 if ( $errormessage ) {
909 &Header::openbox('100%', 'left', $Lang::tr{'wio_error'}, 'error');
910 print"<table width='100%'><tr><td><font class='base'><b>$errormessage</b></font></td></tr></table>";
911 &Header::closebox();
912 }
913
914 if ( $infomessage ) {
915 &Header::openbox('100%', 'left', $Lang::tr{'wio_info'}, 'warning');
916 print"<table width='100%'><tr><td><font class='base'><b>$infomessage</b></font></td></tr></table>";
917 &Header::closebox();
918 }
919
920 ## wio configuration
921
922 if ( $wiosettings{'ACTION'} eq $Lang::tr{'edit'}.'1' || $message == 1 || $wiosettings{'ENABLE'} eq 'off' ) {
923
924 &Header::openbox('100%', 'left', $Lang::tr{'wio settings'});
925
926 print"
927 <form method='post' action='$ENV{'SCRIPT_NAME'}' enctype='multipart/form-data'>
928 <table width='100%'>
929 <tr>
930 <td width='55%' bgcolor='$color{'color20'}' align='left' height='20'><b>&nbsp;$Lang::tr{'wio_settings_msg'}</b></td>
931 <td width='2%'>&nbsp;</td>
932 <td width='43%'>&nbsp;</td>
933 </tr>
934 <tr><td colspan='3'>&nbsp;</td></tr>
935 <tr>
936 <td colspan='3'>$Lang::tr{'wio_settings_msg_hint'}</td>
937 </tr>
938 <tr><td colspan='3'>&nbsp;</td></tr>
939 <tr>
940 <td align='right'>$Lang::tr{'wio enabled'}</td>
941 ";
942
943 print"<td>&nbsp;</td>";
944
945 if ( $wiosettings{'ENABLE'} eq 'on' ) {
946 print"<td align='left'><input type='checkbox' onClick=\"return confirm('$Lang::tr{'wio_disable_hint'}')\" name='ENABLE' $checked{'ENABLE'}{'on'} /></td>";
947 }
948 else {
949 print"<td align='left'><input type='checkbox' name='ENABLE' $checked{'ENABLE'}{'on'} /></td>";
950 }
951 print"
952 </tr>
953 <tr><td colspan='3'>&nbsp;</td></tr>
954 <tr>
955 <td align='right'>$Lang::tr{'wio_shutdown'}</td>
956 <td>&nbsp;</td>
957 <td align='left'><input type='checkbox' name='SHUTDOWN' $checked{'SHUTDOWN'}{'on'} /></td>
958 </tr>
959 <tr><td colspan='3'>&nbsp;</td></tr>
960 <tr>
961 <td align='right'>$Lang::tr{'wio cron'}</td>
962 <td>&nbsp;</td>
963 <td align='left'><select size='1' name='CRON' size='5'>
964 ";
965
966 for ($i=5; $i<=60; $i+=5) {
967 $_ = sprintf("%02s",$i);
968 print "<option $selected{'CRON'}{$_}>$_</option>\n";
969 }
970
971 print"
972 </select>&nbsp;$Lang::tr{'wio min'}</td>
973 </tr>
974 <tr><td colspan='3'>&nbsp;</td></tr>
975 <tr>
976 <td align='right'>$Lang::tr{'wio timeout'}</td>
977 <td>&nbsp;</td>
978 <td align='left'><select size='1' name='TIMEOUT' size='5'>
979 ";
980
981 for ($i=1; $i<=15; $i++) {
982 $_ = sprintf("%02s",$i);
983 print "<option $selected{'TIMEOUT'}{$_}>$_</option>\n";
984 }
985
986 print"
987 </select>&nbsp;$Lang::tr{'wio sec'}</td>
988 </tr>
989 <tr><td colspan='3'>&nbsp;</td></tr>
990 <tr>
991 <td align='right'>$Lang::tr{'wio_logging'}</td>
992 <td>&nbsp;</td>
993 <td align='left'><input type='checkbox' name='LOGGING' $checked{'LOGGING'}{'on'} /></td>
994 </tr>
995 <tr><td colspan='3'>&nbsp;</td></tr>
996 <tr>
997 <td align='right'>$Lang::tr{'wio_clientremark'}</td>
998 <td>&nbsp;</td>
999 <td align='left'><input type='checkbox' name='CLIENTREMARK' $checked{'CLIENTREMARK'}{'on'} /></td>
1000 </tr>
1001 <tr><td colspan='3'>&nbsp;</td></tr>
1002 ";
1003
1004 if ( $wiosettings{'SENDEMAIL'} eq 'on' ) {
1005 print"
1006 <tr>
1007 <td align='right'>$Lang::tr{'wio_mail_style'}:</td>
1008 <td>&nbsp;</td>
1009 <td align='left'><input type='radio' name='MAILSTYLE' value='smail' $checked{'MAILSTYLE'}{'smail'} />&nbsp;$Lang::tr{'wio_mail_smail'}&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type='radio' name='MAILSTYLE' value='email' $checked{'MAILSTYLE'}{'email'} />&nbsp;$Lang::tr{'wio_mail_email'}</td>
1010 </tr>
1011 <tr><td colspan='3'>&nbsp;</td></tr>
1012 <tr>
1013 <td align='right'>$Lang::tr{'wio_mailremark_enabled'}</td>
1014 <td>&nbsp;</td>
1015 <td align='left'><input type='checkbox' name='MAILREMARK' $checked{'MAILREMARK'}{'on'}></td>
1016 </tr>
1017 <tr><td colspan='3'>&nbsp;</td></tr>
1018 ";
1019 }
1020 if ( -e "$ovpnaddon" || ! -z "/var/ipfire/vpn/config" ) {
1021 print"
1022 <tr>
1023 <td align='right'>$Lang::tr{'wio_mail_ovpnrw'}</td>
1024 <td>&nbsp;</td>
1025 <td align='left'><input type='checkbox' name='OVPNRWMAIL' $checked{'OVPNRWMAIL'}{'on'}></td>
1026 </tr>
1027 <tr><td colspan='3'>&nbsp;</td></tr>
1028 <tr>
1029 <td align='right'>$Lang::tr{'wio_ovpn_cron'}</td>
1030 <td>&nbsp;</td>
1031 <td align='left'><select size='1' name='OVPNCRON' size='5'>
1032 ";
1033
1034 for ($i=1; $i<=15; $i++) {
1035 $_ = sprintf("%02s",$i);
1036 print "<option $selected{'OVPNCRON'}{$_}>$_</option>\n";
1037 }
1038
1039 print"
1040 </select>&nbsp;$Lang::tr{'wio min'}</td>
1041 </tr>
1042 <tr><td colspan='3'>&nbsp;</td></tr>
1043 ";
1044 }
1045 print"
1046 <tr><td colspan='3'>&nbsp;</td></tr>
1047 <tr>
1048 <td colspan='2'>&nbsp;</td>
1049 <td align='left'><input type='hidden' name='ACTION' value='$Lang::tr{'wio_save'}1' /><input type='submit' name='submit' value='$Lang::tr{'wio_save'}' />"
1050 .($wiosettings{'ENABLE'} ne 'off' ? "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type='button' onClick='location.href=\"/cgi-bin/wio.cgi\"' value='$Lang::tr{'wio_back'}'>" : "")
1051 ."</td>
1052 </tr>
1053 </table>
1054 </form>
1055 ";
1056
1057 &Header::closebox();
1058 &Header::closebigbox();
1059 &Header::closepage();
1060 exit 0;
1061 }
1062
1063 ## wio client status
1064
1065 if ( $wiosettings{'ENABLE'} eq 'on') {
1066 if ( !$errormessage && $wiosettings{'ACTION'} ne $Lang::tr{'edit'} || $message == 2 ) {
1067 &Header::openbox('100%', 'left', $Lang::tr{'wio stat'});
1068
1069 foreach (@current) {
1070 chomp;
1071
1072 ($id,$timestamp,$ipadr,$host,$on,$remark,$dyndns,$sendemailon,$sendemailoff,$pingmethode,$online,$webinterface) = split (/\,/, $_);
1073
1074 if ( defined($dyndns) && ( $dyndns =~ 'on' ) ) {
1075 ($dyndnsip, $infomessage) = &WIO::getdyndnsip($ipadr, $host);
1076
1077 if ( $dyndnsip ne $ipadr ) {
1078 $ipadr = $dyndnsip;
1079 $write = 'on';
1080 }
1081 }
1082
1083 push (@id,($id));
1084
1085 if ( $on eq 'on' ) { push (@dates,($timestamp)); }
1086 else { push (@dates,('-')); }
1087
1088 push (@ipaddresses,($ipadr));
1089 push (@names,($host));
1090 push (@activ,($on));
1091 push (@remark,($remark));
1092 push (@dyndns,($dyndns));
1093 push (@sendemailon,($sendemailon));
1094 push (@sendemailoff,($sendemailoff));
1095 push (@pingmethode,($pingmethode));
1096 push (@status,($online));
1097 push (@webinterface,($webinterface));
1098
1099 push (@write, "$id,$timestamp,$ipadr,$host,$on,$remark,$dyndns,$sendemailon,$sendemailoff,$pingmethode,$online,$webinterface\n");
1100
1101 $nr++;
1102 }
1103
1104 if ( defined($write) ) { &writeips(); }
1105
1106 ## wan connection
1107
1108 print"
1109 <table border='0' width='100%' bordercolor='$Header::bordercolour' cellspacing='0' cellpadding='0' style='border-collapse: collapse'>
1110 <tr height='25'>
1111 <td width='33%' bgcolor='$color{'color20'}' align='left'><b>&nbsp;$Lang::tr{'wio_wan_con'}</b></td>
1112 <td width='67%' align='right'>&nbsp;</td>
1113 </tr>
1114 <tr><td colspan='2'>&nbsp;</td></tr>
1115 </table>
1116
1117 <table border='0' width='100%' bordercolor='$Header::bordercolour' cellspacing='0' cellpadding='0' style='border-collapse: collapse'>
1118 <tr bgcolor='$color{'color20'}' height='20'>
1119 <td width='3%' align='center'><b>$Lang::tr{'wio_id'}</b></td>
1120 <td width='15%' align='center'><b>$Lang::tr{'wio ipadress'}</b></td>
1121 <td width='3%' align='center'><b>$Lang::tr{'wio network'}</b></td>
1122 <td width='15%' align='center'><b>$Lang::tr{'wio_lanname'}</b></td>
1123 <td width='15%' align='center'><b>$Lang::tr{'wio_wanname'}</b></td>
1124 <td width='24%' align='center'><b>$Lang::tr{'wio_dyndns_hosts'}</b></td>
1125 <td width='11%' align='center'><b>$Lang::tr{'wio image'}</b></td>
1126 <td width='14%' align='center'><b>$Lang::tr{'wio_connected'}</b></td>
1127 </tr>
1128 <tr bgcolor='$color{'color22'}' height='20'>
1129 <td align='center'>01</td>
1130 <td align='center'><font color='$Header::colourred'>$redip</b></font></td>
1131 <td align='center'><img align='middle' src='$imgstatic/red.png' alt='$Lang::tr{'internet'}' title='$Lang::tr{'internet'}' /></td>
1132 <td align='center'><font color='$Header::colourgreen'>".$mainsettings{'HOSTNAME'}.".".$mainsettings{'DOMAINNAME'}."</font></td>
1133 <td align='center'><font color='$Header::colourred'>".( $redip ne '-' ? (gethostbyaddr(pack("C4", split (/\./, $redip)), 2))[0] : '-' )."</font></td>
1134 <td align='center'>
1135 ";
1136
1137 if ( -s "$dyndnsconfig" ) {
1138
1139 open(FILE, "< $dyndnsconfig");
1140 @ddns = <FILE>;
1141 close (FILE);
1142
1143 $ddns = @ddns;
1144 $bgcolor = "blue";
1145
1146 foreach (@ddns) {
1147 chomp;
1148
1149 @temp = split (/\,/, $_);
1150
1151 if ( $temp[7] eq "on" ) { $bgcolor = ( &General::DyndnsServiceSync (&General::GetDyndnsRedIP,$temp[1],$temp[2]) ? "$Header::colourgreen" : "$Header::colourred" ); }
1152
1153 print"<font color='$bgcolor'>$temp[1].$temp[2]</font>";
1154
1155 if ( $iddyndns++ ne ($ddns-1) ) { print"<b>, </b>"; }
1156 }
1157 }
1158 else { print"<b> - </b>"; }
1159
1160 print"
1161 </td>
1162 <td align='center'>
1163 <table bgcolor='".( -e $redactive ? "${Header::colourgreen}" : "${Header::colourred}" )."' cellpadding='2' cellspacing='0' width='100%'>
1164 <tr height='20'>
1165 <td align='center'><font color='white'><b>".( -e $redactive ? $Lang::tr{'wio_wan_up'} : $Lang::tr{'wio_wan_down'} )."</b></font></td>
1166 </tr>
1167 </table>
1168 </td>
1169 <td align='center'><font color='$Header::colourred'>".( -e "$redactive" ? &General::age("$redactive") : '-' )."</font></td>
1170 </tr>
1171 <tr height='1'><td colspan='9' bgcolor='#696565'></td></tr>
1172 </table>
1173 ";
1174
1175 &hrline();
1176
1177 ## vpn connection(s)
1178
1179 if ( -e "$vpnpid" ) {
1180
1181 @vpnstatus = `/usr/local/bin/ipsecctrl I`;
1182
1183 print"
1184 <table border='0' width='100%' bordercolor='$Header::bordercolour' cellspacing='0' cellpadding='0' style='border-collapse: collapse'>
1185 <tr height='25'>
1186 <td width='33%' bgcolor='$color{'color20'}' align='left'><b>&nbsp;$Lang::tr{'wio_vpn_con'}</b></td>
1187 <td width='67%'>&nbsp;</td>
1188 </tr>
1189 <tr><td colspan='2'>&nbsp;</td></tr>
1190 </table>
1191 <table border='0' width='100%' bordercolor='$Header::bordercolour' cellspacing='0' cellpadding='0' style='border-collapse: collapse'>
1192 <tr bgcolor='$color{'color20'}' height='20'>
1193 <td width='3%' align='center'><b>$Lang::tr{'wio_id'}</b></td>
1194 <td width='19%' align='center'><b>$Lang::tr{'wio checked'}</b></td>
1195 <td width='20%' align='center'><b>$Lang::tr{'name'}</b></td>
1196 <td width='8%' align='center'><b>$Lang::tr{'type'}</b></td>
1197 <td width='25%' align='center'><b>$Lang::tr{'wio_common_name'}</b></td>
1198 <td width='11%' align='center'><b>$Lang::tr{'wio image'}</b></td>
1199 <td width='14%' align='center'><b>$Lang::tr{'wio_connected'}</b></td>
1200 </tr>
1201 ";
1202
1203 foreach $key (sort SortByTunnelName (keys(%vpnconfighash))) {
1204
1205 my $vpncheck = '';
1206
1207 if ( -e '/var/log/wio/.vpncache' ) {
1208 $vpncheck = strftime("%d.%m.%Y - %H:%M:%S",localtime(((stat('/var/log/wio/.vpncache'))[9])));
1209 }
1210
1211 $status = "bgcolor='${Header::colourred}'";
1212 $statustxt = "$Lang::tr{'capsclosed'}";
1213
1214 if ($vpnconfighash{$key}[0] eq 'off') {
1215 $status = "bgcolor='${Header::colourblue}'";
1216 $statustxt = "$Lang::tr{'capsclosed'}";
1217 }
1218
1219 foreach (@vpnstatus) {
1220 if ($_ =~ /$vpnconfighash{$key}[1]\{.*INSTALLED/) {
1221 $status = "bgcolor='${Header::colourgreen}'";
1222 $statustxt = "$Lang::tr{'capsopen'}";
1223 last;
1224 }
1225 }
1226
1227 print"<tr".($idvpn % 2?" bgcolor='$color{'color20'}'":" bgcolor='$color{'color22'}'")." height='20'>";
1228
1229 my $vpnnr = $idvpn+1;
1230
1231 printf ("<td align='center'> %02d</td>", $vpnnr);
1232
1233 print"<td align='center'>$vpncheck</td>
1234 <td align='center'>$vpnconfighash{$key}[1]</td>
1235 <td align='center'><img align='middle' src='$imgstatic/".( $vpnconfighash{$key}[3] eq 'host' ? "vpnrw.png' alt='$Lang::tr{'wio_rw'}' title='$Lang::tr{'wio_rw'}'" : "vpnn2n.png' alt='$Lang::tr{'wio_n2n'}' title='$Lang::tr{'wio_n2n'}'")." /></td>
1236 <td align='center'>".($vpnconfighash{$key}[2] eq '%auth-dn' ? "$vpnconfighash{$key}[9]" : ($vpnconfighash{$key}[4] eq 'cert' ? "$vpnconfighash{$key}[2]" : ($vpnconfighash{$key}[8] ne '' ? "$vpnconfighash{$key}[10]" : "&nbsp;")))."</td>
1237 <td align='center'>
1238 <table $status cellpadding='2' cellspacing='0' width='100%'>
1239 <tr height='20'>
1240 <td align='center'><font color='white'><b>$statustxt</b></font></td>
1241 </tr>
1242 </table>
1243 </td>
1244 <td align='center' height='20'>&nbsp;</td>
1245 </tr>
1246 ";
1247
1248 if ($vpnconfighash{$key}[25] && $wiosettings{'CLIENTREMARK'} eq 'on') {
1249 print"<tr".($idvpn % 2?" bgcolor='$color{'color20'}'":" bgcolor='$color{'color22'}'")." height='20'><td>&nbsp;</td><td colspan='16' align='left'>$vpnconfighash{$key}[25]</td></tr>";
1250 }
1251 print"<tr height='1'><td colspan='7' bgcolor='#696565'></td></tr>";
1252 $idvpn++
1253 }
1254
1255 print"</table>";
1256 &hrline();
1257 }
1258
1259 ## openvpn connection(s)
1260
1261 if ( -e "$ovpnpid" ) {
1262
1263 @ovpnstatus = `cat /var/run/ovpnserver.log`;
1264
1265 print"
1266 <table border='0' width='100%' bordercolor='$Header::bordercolour' cellspacing='0' cellpadding='0' style='border-collapse: collapse'>
1267 <tr height='25'>
1268 <td width='33%' bgcolor='$color{'color20'}' align='left'><b>&nbsp;$Lang::tr{'wio_ovpn_con'}</b></td>
1269 <td width='67%'>&nbsp;</td>
1270 </tr>
1271 <tr><td colspan='2'>&nbsp;</td></tr>
1272 </table>
1273 <table border='0' width='100%' bordercolor='$Header::bordercolour' cellspacing='0' cellpadding='0' style='border-collapse: collapse'>
1274 <tr bgcolor='$color{'color20'}' height='20'>
1275 <td width='3%' align='center'><b>$Lang::tr{'wio_id'}</b></td>
1276 <td width='19%' align='center'><b>$Lang::tr{'wio checked'}</b></td>
1277 <td width='20%' align='center'><b>$Lang::tr{'wio ipadress'}</b></td>
1278 <td width='8%' align='center'><b>$Lang::tr{'type'}</b></td>
1279 <td width='25%' align='center'><b>$Lang::tr{'common name'}</b></td>
1280 <td width='11%' align='center'><b>$Lang::tr{'wio image'}</b></td>
1281 <td width='14%' align='center'><b>$Lang::tr{'wio_connected'}</b></td>
1282 </tr>
1283 ";
1284
1285 foreach $key (keys %ovpnconfighash) {
1286
1287 my ( $ovpnclt, $ovpntime, $ovpnrwip, $ovpncheck ) = '';
1288
1289 if ( -e '/var/log/wio/.ovpncache' ) {
1290 $ovpncheck = strftime("%d.%m.%Y - %H:%M:%S",localtime(((stat('/var/log/wio/.ovpncache'))[9])));
1291 }
1292
1293 print"<tr".($idovpn % 2?" bgcolor='$color{'color20'}'":" bgcolor='$color{'color22'}'")." height='20'>";
1294
1295 my $ovpnnr = $idovpn+1;
1296
1297 printf ("<td align='center' height='20'> %02d</td>", $ovpnnr);
1298
1299 if ($ovpnconfighash{$key}[3] eq 'net') {
1300 $image = "$imgstatic/ovpnn2n.png";
1301 $text = "$Lang::tr{'wio_n2n'}";
1302 }
1303 else {
1304 $image = "$imgstatic/ovpnrw.png";
1305 $text = "$Lang::tr{'wio_rw'}";
1306 }
1307
1308 if ( $ovpnconfighash{$key}[0] eq 'off' ) {
1309 $status = "${Header::colourblue}";
1310 $statustxt = "$Lang::tr{'capsclosed'}";
1311 }
1312 else {
1313 if ($ovpnconfighash{$key}[3] eq 'net') {
1314 if (-e "/var/run/$ovpnconfighash{$key}[1]n2n.pid") {
1315 my @output = "";
1316 my @tustate = "";
1317 my $tport = $ovpnconfighash{$key}[22];
1318 my $tnet = new Net::Telnet ( Timeout=>5, Errmode=>'return', Port=>$tport);
1319 if ($tport ne '') {
1320 $tnet->open('127.0.0.1');
1321 @output = $tnet->cmd(String => 'state', Prompt => '/(END.*\n|ERROR:.*\n)/');
1322 @tustate = split(/\,/, $output[1]);
1323 $ovpntime = &WIO::contime(scalar localtime($tustate[0]));
1324
1325 if (($tustate[1] eq 'CONNECTED')) {
1326 $status = "${Header::colourgreen}";
1327 $statustxt = "$Lang::tr{'capsopen'}";
1328 }else {
1329 $status = "${Header::colourred}";
1330 $statustxt = "$tustate[1]";
1331 }
1332 }
1333 }
1334 }
1335 else {
1336 foreach (@ovpnstatus) {
1337 if ( $_ =~ /^(.+),(\d+\.\d+\.\d+\.\d+\:\d+),(\d+),(\d+),(.+)/ ) {
1338 @match = split (m/^(.+),(\d+\.\d+\.\d+\.\d+\:\d+),(\d+),(\d+),(.+)/, $_);
1339 $match[1] =~ s/[_]/ /g;
1340 }
1341
1342 if ( $match[1] ne "Common Name" && ($match[1] eq $ovpnconfighash{$key}[2]) ) {
1343 $ovpnclt = $match[1];
1344 $ovpntime = &WIO::contime($match[5]);
1345 }
1346
1347 if ( $_ =~ /^(\d+\.\d+\.\d+\.\d+),(.+),(\d+\.\d+\.\d+\.\d+\:\d+),(.+)/ ) {
1348 @match = split(m/^(\d+\.\d+\.\d+\.\d+),(.+),(\d+\.\d+\.\d+\.\d+\:\d+),(.+)/, $_);
1349 }
1350
1351 if ( $match[1] ne "Virtual Address" && $match[2] eq $ovpnclt ) {
1352 $ovpnrwip = $match[1];
1353 $ovpncheck = &WIO::statustime($match[4]);
1354 }
1355
1356 if ( $ovpnclt eq $ovpnconfighash{$key}[2] ) {
1357 $status = "${Header::colourgreen}";
1358 $statustxt = "$Lang::tr{'capsopen'}";
1359 }
1360 else {
1361 $status = "${Header::colourred}";
1362 $statustxt = "$Lang::tr{'capsclosed'}";
1363 }
1364 }
1365 }
1366 }
1367
1368 print"
1369 <td align='center'>$ovpncheck</td>
1370 <td align='center'>".( defined($ovpnrwip)? "$ovpnrwip" : "&nbsp;")."</td>
1371 <td align='center'><img align='middle' src='$image' alt='$text' title='$text' /></td>
1372 <td align='center'>".($ovpnconfighash{$key}[2] eq '%auth-dn' ? "$ovpnconfighash{$key}[9]" : ($ovpnconfighash{$key}[4] eq 'cert' ? "$ovpnconfighash{$key}[2]": "&nbsp;"))."</td>
1373 <td align='center'><table bgcolor='$status' cellpadding='2' cellspacing='0' width='100%'><tr height='20'><td align='center'><font color='white'><b>$statustxt</b></font></td></tr></table></td>
1374 <td align='center'>".(defined($ovpntime)? "$ovpntime" : "&nbsp;")."</td>
1375 </tr>
1376 ";
1377 if ($ovpnconfighash{$key}[25] && $wiosettings{'CLIENTREMARK'} eq 'on') {
1378 print"<tr".($idovpn % 2?" bgcolor='$color{'color20'}'":" bgcolor='$color{'color22'}'")." height='20'><td>&nbsp;</td><td colspan='16' align='left'>$ovpnconfighash{$key}[25]</td></tr>";
1379 }
1380
1381 print"<tr height='1'><td colspan='17' bgcolor='#696565'></td></tr>";
1382 $idovpn++
1383 }
1384 print"</table>";
1385 &hrline();
1386 }
1387 #}
1388
1389 ## client status
1390
1391 print"
1392 <table border='0' width='100%' bordercolor='$Header::bordercolour' cellspacing='0' cellpadding='0' style='border-collapse: collapse'>
1393 <tr height='25'>
1394 <td width='33%' bgcolor='$color{'color20'}' align='left'><b>&nbsp;$Lang::tr{'wio_clients'}</b></td>
1395 <td width='67%'>&nbsp;</td>
1396 </tr>
1397 <tr><td colspan='2'>&nbsp;</td></tr>
1398 </table>
1399
1400 <table border='0' width='100%' bordercolor='$Header::bordercolour' cellspacing='0' cellpadding='0' style='border-collapse: collapse'>
1401 <tr bgcolor='$color{'color20'}' height='20'>
1402 <td width='3%' align='center'><b>$Lang::tr{'wio_id'}</b></td>
1403 <td width='4%' align='center'><b>$Lang::tr{'wio_activ'}</b></td>
1404 <td width='5%' align='center'><b>$Lang::tr{'wio_check'}</b></td>
1405 <td width='15%' align='center'><b>$Lang::tr{'wio checked'}</b></td>
1406 <td width='4%' align='center'><b>$Lang::tr{'wio_webinterface'}</b></td>
1407 <td width='11%' align='center'><a href='$ENV{'SCRIPT_NAME'}?IPADR'><b>$Lang::tr{'wio ipadress'}</b></a></td>
1408 <td width='5%' align='center'><b>$Lang::tr{'wio network'}</b></td>
1409 <td width='20%' align='center'><a href='$ENV{'SCRIPT_NAME'}?HOST'><b>$Lang::tr{'wio name'}</b></a></td>
1410 <td width='11%' align='center'><b>$Lang::tr{'wio image'}</b></td>
1411 <td width='4%' align='center'><form method='post' action='$ENV{'SCRIPT_NAME'}' enctype='multipart/form-data'><input type='hidden' name='ACTION' value='$Lang::tr{'wio_refresh'}' /><input type='image' name='$Lang::tr{'wio_refresh'}' src='$imgstatic/refresh.png' align='middle' alt='$Lang::tr{'wio_refresh'}' title='$Lang::tr{'wio_refresh'}' /></form></td>
1412 <td width='4%' colspan='2' align='center'><b>$Lang::tr{'wio_dyndns'}</b></td>
1413 <td width='12%' colspan='4' align='center'><b>$Lang::tr{'action'}</b></td>
1414 <td width='3%' align='center'><form method='post' action='$ENV{'SCRIPT_NAME'}' enctype='multipart/form-data'><input type='hidden' name='ACTION' value='$Lang::tr{'wio_remove_all'}' /><input type='image' name='$Lang::tr{'wio_remove_all'}' src='/images/delete.gif' align='middle' alt='$Lang::tr{'wio_remove_all'}' title='$Lang::tr{'wio_remove_all'}' onClick=\"return confirm('$Lang::tr{'wio_remove_all_hint'}')\"/></form></td>
1415 </tr>
1416 ";
1417
1418 for (my $a=0; $a<$nr; $a++) {
1419
1420 my $gif = 'off.gif';
1421 my $gdesc = $Lang::tr{'wio_client_off'};
1422 my $dyndnsimg = 'on.gif';
1423 my $dyndnsimgtxt = $Lang::tr{'wio_dyndns_on'};
1424 my $mailonimg = 'wio/mailgreenon.png';
1425 my $mailonimgtxt = $Lang::tr{'wio_mail_online_on'};
1426 my $mailoffimg = 'wio/mailredon.png';
1427 my $mailoffimgtxt = $Lang::tr{'wio_mail_offline_on'};
1428 my $pingimg = '';
1429 my $pingtxt = '';
1430 my $webimg = '';
1431
1432 if ( $activ[$a] eq 'on' ) {
1433 $gif = 'on.gif';
1434 $gdesc = $Lang::tr{'wio_client_on'};
1435 }
1436
1437 if ( $dyndns[$a] ne 'on' ) {
1438 $dyndnsimg = 'off.gif';
1439 $dyndnsimgtxt = $Lang::tr{'wio_dyndns_off'};
1440 }
1441
1442 if ( $sendemailon[$a] ne 'on' ) {
1443 $mailonimg = 'wio/mailgreenoff.png';
1444 $mailonimgtxt = $Lang::tr{'wio_mail_online_off'};
1445 }
1446
1447 if ( $sendemailoff[$a] ne 'on' ) {
1448 $mailoffimg = 'wio/mailredoff.png';
1449 $mailoffimgtxt = $Lang::tr{'wio_mail_offline_off'};
1450 }
1451
1452 if ( $webinterface[$a] eq 'HTTP' ) {
1453 $webimg = 'wio/http.png';
1454 }
1455 elsif ( $webinterface[$a] eq 'HTTPS' ) {
1456 $webimg = 'wio/https.png';
1457 }
1458 else {
1459 $webimg = 'wio/none.png';
1460 }
1461
1462 $bgcolor = $status[$a] eq "on" ? "${Header::colourgreen}" : ($status[$a] eq "off" && $dates[$a] eq "") ? "${Header::colourblue}" : "${Header::colourred}";
1463 $statustxt = $status[$a] eq "on" ? "$Lang::tr{'wio up'}" : ($status[$a] eq "off" && $dates[$a] eq "") ? "$Lang::tr{'wio_no_image'}" : "$Lang::tr{'wio down'}";
1464
1465 print"<tr".($a % 2?" bgcolor='$color{'color20'}'":" bgcolor='$color{'color22'}'")." height='20'>";
1466 printf ("<td align='center'> %02d</td>", $a+1);
1467
1468 print"<td align='center'><form method='post' action='$ENV{'SCRIPT_NAME'}' enctype='multipart/form-data'>
1469 <input type='hidden' name='ACTION' value='$Lang::tr{'enable disable client'}' />
1470 <input type='image' name='$Lang::tr{'enable disable client'}' src='/images/$gif' align='middle' alt='$gdesc' title='$gdesc' />
1471 <input type='hidden' name='ID' value='$a' /></form></td>";
1472
1473 if ( $pingmethode[$a] eq 'ip') {
1474 print"<td align='center'><form method='post' action='$ENV{'SCRIPT_NAME'}' enctype='multipart/form-data'>
1475 <input type='hidden' name='ACTION' value='$Lang::tr{'wio_ip_on'}' />
1476 <input type='image' name='$Lang::tr{'wio_ip_on'}' src='/images/wio/ip.png' align='middle' alt='$Lang::tr{'wio_ip_on'}' title='$Lang::tr{'wio_ip_on'}' />
1477 <input type='hidden' name='ID' value='$a' /></form></td>";
1478 }
1479 else {
1480 print"<td align='center'><form method='post' action='$ENV{'SCRIPT_NAME'}' enctype='multipart/form-data'>
1481 <input type='hidden' name='ACTION' value='$Lang::tr{'wio_fqdn_on'}' />
1482 <input type='image' name='$Lang::tr{'wio_fqdn_on'}' src='/images/wio/fqdn.png' align='middle' alt='$Lang::tr{'wio_fqdn_on'}' title='$Lang::tr{'wio_fqdn_on'}' />
1483 <input type='hidden' name='ID' value='$a' /></form></td>";
1484 }
1485
1486 print"<td align='center'>$dates[$a]</td>";
1487
1488 print"<td align='center'><img align='middle' src='/images/$webimg' /></td>";
1489
1490 if ( $webinterface[$a] eq 'HTTP' ) {
1491 print"<td align='center'><a title=\"$Lang::tr{'wio_webinterface_link'}\" href=\"http://$ipaddresses[$a]\" target=\"_blank\">$ipaddresses[$a]</a></td>";
1492 }
1493 elsif ( $webinterface[$a] eq 'HTTPS' ) {
1494 print"<td align='center'><a title=\"$Lang::tr{'wio_webinterface_link'}\" href=\"https://$ipaddresses[$a]\" target=\"_blank\">$ipaddresses[$a]</a></td>";
1495 }
1496 else {
1497 print"<td align='center'>$ipaddresses[$a]</td>";
1498 }
1499
1500 my $dotip = length($ipaddresses[$a]) - rindex($ipaddresses[$a],'.');
1501 SWITCH: {
1502 foreach (@devs_color) {
1503 my $in = 0;
1504 $ic = "${_}";
1505
1506 foreach $interface (@devs_net) {
1507 next if ( $netsettings{"$ic"."_DEV"} eq 'red0' && ($netsettings{"RED_TYPE"} eq 'DHCP' || $netsettings{"RED_TYPE"} eq 'PPPOE'));
1508 if ( $netsettings{"$ic"."_DEV"} eq $interface ) {
1509 if ( &General::IpInSubnet($ipaddresses[$a], $netsettings{"$ic"."_NETADDRESS"}, $netsettings{"$ic"."_NETMASK"}) ) {
1510 print"<td align='center' height='20'><img src='$imgstatic/$devs_img[$in]' alt='$Lang::tr{$devs_alt[$in]}' title='$Lang::tr{$devs_alt[$in]}' /></td>";
1511 last SWITCH;
1512 }
1513 }
1514 $in++;
1515 }
1516 }
1517
1518 if ( -e "$vpnpid" ) {
1519 foreach $key (keys(%vpnconfighash)) {
1520 next unless ($vpnconfighash{$key}[3] eq 'net');
1521
1522 my $convertip = &General::ipcidr2msk($vpnconfighash{$key}[11]);
1523
1524 my @net = split ("/", $convertip);
1525
1526 $vpnn2nip = $net[0];
1527 $vpnn2nmask = length($net[1]) - rindex($net[1],'.');
1528
1529 if (substr($ipaddresses[$a],0,length($ipaddresses[$a])-$dotip) eq substr($vpnn2nip,0,length($vpnn2nip)-$vpnn2nmask)) {
1530 print"<td align='center'><img align='middle' src='$imgstatic/vpn.png' alt='IPSec' title='IPSec' /></td>";
1531 last SWITCH;
1532 }
1533 }
1534 }
1535
1536 if ( $ovpnsettings{'DOVPN_SUBNET'} ne '' ) {
1537 @match = split ("/", $ovpnsettings{'DOVPN_SUBNET'});
1538
1539 if ( &General::IpInSubnet($ipaddresses[$a], $match[0], $match[1]) ) {
1540 print"<td align='center'><img src='$imgstatic/ovpn.png' alt='OpenVPN' title='OpenVPN' /></td>";
1541 last SWITCH;
1542 }
1543 }
1544
1545 if ( %ovpnccdconfhash ne '' ) {
1546 foreach $key (keys(%ovpnccdconfhash)) {
1547
1548 my $convertip = &General::ipcidr2msk($ovpnccdconfhash{$key}[1]);
1549 my @net = split ("/", $convertip);
1550
1551 $vpnn2nip = $net[0];
1552 $vpnn2nmask = length($net[1]) - rindex($net[1],'.');
1553
1554 if (substr($ipaddresses[$a],0,length($ipaddresses[$a])-$dotip) eq substr($vpnn2nip,0,length($vpnn2nip)-$vpnn2nmask)) {
1555 print"<td align='center'><img align='middle' src='$imgstatic/ovpn.png' alt='OpenVPN' title='OpenVPN' /></td>";
1556 last SWITCH;
1557 }
1558 }
1559 }
1560
1561 if ($netsettings{"RED_TYPE"} eq 'DHCP' || $netsettings{"RED_TYPE"} eq 'PPPOE') {
1562 my $redipadr = qx'ip addr | grep red0 | grep inet | awk "{print \$2}"';
1563 my @rednet = split ("/", $redipadr);
1564 chomp ($rednet[1]);
1565 my $red_netmask = General::iporsubtodec($rednet[1]);
1566 my $red_netaddress = Network::get_netaddress("$rednet[0]/$red_netmask");
1567
1568 if ( &General::IpInSubnet($ipaddresses[$a], $red_netaddress, $red_netmask) ) {
1569 print"<td align='center' height='20'><img src='$imgstatic/red.png' alt='$Lang::tr{'wio_red_lan'}' title='$Lang::tr{'wio_red_lan'}' /></td>";
1570 last SWITCH;
1571 }
1572 else {
1573 print"<td align='center'><img align='middle' src='$imgstatic/white.png' alt='$Lang::tr{'wio_unknown_lan'}' title='$Lang::tr{'wio_unknown_lan'}' /></td>";
1574 last SWITCH;
1575 }
1576 }
1577 }
1578
1579 if ( $webinterface[$a] eq 'HTTP' ) {
1580 print"<td align='center'><a title=\"$Lang::tr{'wio_webinterface_link'}\" href=\"http://$names[$a]\" target=\"_blank\">$names[$a]</a></td>";
1581 }
1582 elsif ( $webinterface[$a] eq 'HTTPS' ) {
1583 print"<td align='center'><a title=\"$Lang::tr{'wio_webinterface_link'}\" href=\"https://$names[$a]\" target=\"_blank\">$names[$a]</a></td>";
1584 }
1585 else {
1586 print"<td align='center'>$names[$a]</td>";
1587 }
1588
1589 print"
1590 <td>
1591 <table bgcolor='$bgcolor' cellpadding='2' cellspacing='0' width='100%'>
1592 <tr height='20'>
1593 <td align='center'><font color='$color{'color21'}'><b>$statustxt</b></font></td>
1594 </tr>
1595 </table>
1596 </td>
1597
1598 <td width='3%' align='center'><form method='post' action='$ENV{'SCRIPT_NAME'}' enctype='multipart/form-data'>
1599 <input type='hidden' name='ACTION' value='$Lang::tr{'wio_sc_refresh'}' />
1600 <input type='image' name='$Lang::tr{'wio_sc_refresh'}' src='$imgstatic/refresh.png' align='middle' alt='$Lang::tr{'wio_sc_refresh'}' title='$Lang::tr{'wio_sc_refresh'}' />
1601 <input type='hidden' name='ID' value='$a' /></form></td>
1602
1603 <td width='3%' align='center'><form method='post' action='$ENV{'SCRIPT_NAME'}' enctype='multipart/form-data'>
1604 <input type='hidden' name='ACTION' value='$Lang::tr{'enable disable dyndns'}' />
1605 <input type='image' name='$Lang::tr{'enable disable dyndns'}' src='/images/$dyndnsimg' align='middle' alt='$dyndnsimgtxt' title='$dyndnsimgtxt' />
1606 <input type='hidden' name='ID' value='$a' /></form></td>";
1607
1608 if ( defined($dyndns[$a]) && ($dyndns[$a] eq 'on') ) {
1609 print"<td width='3%' align='center'><form method='post' action='$ENV{'SCRIPT_NAME'}' enctype='multipart/form-data'>
1610 <input type='hidden' name='ACTION' value='$Lang::tr{'wio_dyndns_refresh'}' />
1611 <input type='image' name='$Lang::tr{'wio_dyndns_refresh'}' src='/images/reload.gif' align='middle' alt='$Lang::tr{'wio_dyndns_refresh'}' title='$Lang::tr{'wio_dyndns_refresh'}' />
1612 <input type='hidden' name='ID' value='$a' /></form></td>";
1613 }
1614 else {
1615 print"<td width='3%' align='center'>-</td>";
1616 }
1617
1618 if ( -e "/var/log/rrd/wio/$id[$a].rrd" ) {
1619 print"
1620 <td width='3%' align='center'><form method='post' action='/cgi-bin/wiographs.cgi' enctype='multipart/form-data'>
1621 <input type='image' name='$Lang::tr{'wio_graphs'}' src='$imgstatic/graph.png' align='middle' alt='$Lang::tr{'wio_graphs'}' title='$Lang::tr{'wio_graphs'}' />
1622 <input type='hidden' name='HOSTID' value='$id[$a]' /><input type='hidden' name='HOSTNAME' value='$names[$a]' /></form></td>
1623 ";
1624 }
1625 else {
1626 print "<td width='3%' align='center'><img src='$imgstatic/no_graph.png' align='middle' alt='$Lang::tr{'wio_no_graphs'}' title='$Lang::tr{'wio_no_graphs'}' /></td>";
1627 }
1628
1629 if ( $wiosettings{'SENDEMAIL'} eq 'on') {
1630 print"<td width='3%' align='center'><form method='post' action='$ENV{'SCRIPT_NAME'}' enctype='multipart/form-data'>
1631 <input type='hidden' name='ACTION' value='$Lang::tr{'wio_mail_online'}' />
1632 <input type='image' name='$Lang::tr{'wio_mail_online'}' src='/images/$mailonimg' align='middle' alt='$mailonimgtxt' title='$mailonimgtxt' />
1633 <input type='hidden' name='ID' value='$a' /></form></td>
1634 <td width='3%' align='center'><form method='post' action='$ENV{'SCRIPT_NAME'}' enctype='multipart/form-data'>
1635 <input type='hidden' name='ACTION' value='$Lang::tr{'wio_mail_offline'}' />
1636 <input type='image' name='$Lang::tr{'wio_mail_offline'}' src='/images/$mailoffimg' align='middle' alt='$mailoffimgtxt' title='$mailoffimgtxt' />
1637 <input type='hidden' name='ID' value='$a' /></form></td>";
1638 }
1639 else {
1640 print"<td width='3%' align='center'>-</td>
1641 <td width='3%' align='center'>-</td>";
1642 }
1643
1644 print"
1645 <td width='3%' align='center'><form method='post' action='$ENV{'SCRIPT_NAME'}' enctype='multipart/form-data'>
1646 <input type='hidden' name='ACTION' value='$Lang::tr{'edit'}' />
1647 <input type='image' name='$Lang::tr{'edit'}' src='/images/edit.gif' align='middle' alt='$Lang::tr{'edit'}' title='$Lang::tr{'edit'}' />
1648 <input type='hidden' name='ID' value='$a' /></form></td>
1649
1650 <td width='3%' align='center'><form method='post' action='$ENV{'SCRIPT_NAME'}' enctype='multipart/form-data'>
1651 <input type='hidden' name='ACTION' value='$Lang::tr{'wio_remove_client'}' />
1652 <input type='image' name='$Lang::tr{'wio_remove_client'}' src='/images/delete.gif' align='middle' alt='$Lang::tr{'wio_remove_client'}' title='$Lang::tr{'wio_remove_client'}' onClick=\"return confirm('$Lang::tr{'wio_remove_client_hint'}')\" />
1653 <input type='hidden' name='ID' value='$a' /></form></td></tr>
1654 ";
1655
1656 if ($remark[$a] && $wiosettings{'CLIENTREMARK'} eq 'on') {
1657 print"<tr".($a % 2?" bgcolor='$color{'color20'}'":" bgcolor='$color{'color22'}'")." height='20'><td>&nbsp;</td><td colspan='16' align='left'>$remark[$a]</td></tr>";
1658 }
1659 print"<tr height='1'><td colspan='17' bgcolor='#696565'></td></tr>";
1660 }
1661
1662 print"</table>";
1663
1664 &Header::closebox();
1665
1666 }
1667
1668 ## add / modify client
1669
1670 $checked{'EN'}{'on'} = ($wiosettings{'EN'} eq '' ) ? '' : "checked='checked'";
1671
1672 $checked{'DYNDNS'}{'off'} = $checked{'DYNDNS'}{'on'} = '';
1673 $checked{'DYNDNS'}{$wiosettings{'DYNDNS'}} = "checked='checked'";
1674
1675 $checked{'SENDEMAILON'}{'off'} = $checked{'SENDEMAILON'}{'on'} = '';
1676 $checked{'SENDEMAILON'}{$wiosettings{'SENDEMAILON'}} = "checked='checked'";
1677
1678 $checked{'SENDEMAILOFF'}{'off'} = $checked{'SENDEMAILOFF'}{'on'} = '';
1679 $checked{'SENDEMAILOFF'}{$wiosettings{'SENDEMAILOFF'}} = "checked='checked'";
1680
1681 if (! defined($errormessage) && $wiosettings{'ACTION'} ne $Lang::tr{'edit'} ) {
1682 $wiosettings{'PINGMETHODE'} = 'ip';
1683 }
1684
1685 $checked{'PINGMETHODE'}{'ip'} = $checked{'PINGMETHODE'}{'fqdn'} = '';
1686 $checked{'PINGMETHODE'}{$wiosettings{'PINGMETHODE'}} = "checked='checked'";
1687
1688 $selected{'WEBINTERFACE'}{'----'} = '';
1689 $selected{'WEBINTERFACE'}{'HTTP'} = '';
1690 $selected{'WEBINTERFACE'}{'HTTPS'} = '';
1691 $selected{'WEBINTERFACE'}{$wiosettings{'WEBINTERFACE'}} = "selected='selected'";
1692
1693 $buttontext = $Lang::tr{'wio_client_add'};
1694
1695 if ( $wiosettings{'ACTION'} eq $Lang::tr{'edit'} || defined($errormessage) && ! defined($message) ) {
1696 &Header::openbox('100%', 'left', $Lang::tr{'wio_edit_client'});
1697 $buttontext = $Lang::tr{'update'};
1698 }
1699 else {
1700 &Header::openbox('100%', 'left', $Lang::tr{'wio_edit_settings'});
1701 }
1702
1703 if (! defined($errormessage) && $wiosettings{'ACTION'} ne $Lang::tr{'edit'} ) {
1704 print"
1705 <table width='100%' border='0' bordercolor='$Header::bordercolour' cellspacing='0' cellpadding='0' style='border-collapse: collapse'>
1706 <tr>
1707 <td width='33%' bgcolor='$color{'color20'}' align='left' height='25'><b>&nbsp;$Lang::tr{'wio_add'}</b></td>
1708 <td width='67%' align='right'>&nbsp;</td>
1709 </tr>
1710 <tr>
1711 <td>&nbsp;</td>
1712 </tr>
1713 </table>
1714 ";
1715 }
1716
1717 print"
1718 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
1719 <input type='hidden' name='ID' value='$wiosettings{'ID'}' />
1720 <input type='hidden' name='CLIENTID' value='$wiosettings{'CLIENTID'}' />
1721 <input type='hidden' name='ONLINE' value='$wiosettings{'ONLINE'}' />
1722 <input type='hidden' name='TIMESTAMP' value='$wiosettings{'TIMESTAMP'}' />
1723 ";
1724
1725 print"
1726 <table width='100%' border='0' bordercolor='$Header::bordercolour' cellspacing='0' cellpadding='0' style='border-collapse: collapse'>
1727 <tr>
1728 <td height='30'>$Lang::tr{'wio_client_enable'}</td>
1729 <td align='left'><input type='checkbox' name='EN' $checked{'EN'}{'on'} /></td>
1730 <td colspan='4'>&nbsp;</td>
1731 </tr>
1732 <tr>
1733 <td height='30'>$Lang::tr{'wio ipadress'}:</td>
1734 <td align='left'><input type='text' name='IPADR' value='$wiosettings{'IPADR'}' size='25' /></td>
1735 <td>$Lang::tr{'wio name'}:</td>
1736 <td align='left'><input type='text' name='HOST' value='$wiosettings{'HOST'}' size='25' /></td>
1737 <td>$Lang::tr{'remark'}:</td>
1738 <td align='left'><input type='text' name='REMARK' value='$wiosettings{'REMARK'}' size='30'></td>
1739 </tr>
1740 <tr>
1741 <td height='30'>$Lang::tr{'wio_ping_send'}:</td>
1742 <td align='left'><input type='radio' name='PINGMETHODE' value='ip' $checked{'PINGMETHODE'}{'ip'} />&nbsp;IP&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type='radio' name='PINGMETHODE' value='fqdn' $checked{'PINGMETHODE'}{'fqdn'} />&nbsp;FQDN</td>
1743 <td>$Lang::tr{'wio_dyndns'}:</td>
1744 <td align='left'><input type='checkbox' name='DYNDNS' $checked{'DYNDNS'}{'on'} /></td>
1745 ";
1746
1747 if ( $wiosettings{'SENDEMAIL'} eq 'on' ) {
1748 print"<td>$Lang::tr{'wio_sendemail'}:</td>
1749 <td><input type='checkbox' name='SENDEMAILON' $checked{'SENDEMAILON'}{'on'} />&nbsp;$Lang::tr{'wio_online'}&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type='checkbox' name='SENDEMAILOFF' $checked{'SENDEMAILOFF'}{'on'} />&nbsp;$Lang::tr{'wio_offline'}</td>";
1750 }
1751 else {
1752 print"<td colspan='2'>&nbsp;</td>";
1753 }
1754
1755 print"
1756 </tr>
1757 <tr>
1758 <td height='30'>$Lang::tr{'wio_link_open'}:</td>
1759 <td align='left' colspan='5'>
1760 <select size='1' name='WEBINTERFACE' width='80' style='width: 80px'>
1761 <option value='----' $selected{'WEBINTERFACE'}{'----'}>----</option>
1762 <option value='HTTP' $selected{'WEBINTERFACE'}{'HTTP'}>HTTP</option>
1763 <option value='HTTPS' $selected{'WEBINTERFACE'}{'HTTPS'}>HTTPS</option>
1764 </select>
1765 </td>
1766 </tr>
1767 </table>
1768 <table width='100%' cellspacing='0' cellpadding='0' style='border-collapse: collapse'>
1769 <tr>
1770 <td width='20%' align='center'>&nbsp;</td>
1771 ";
1772
1773 if ( $buttontext eq $Lang::tr{'update'} && ( defined($errormessage) || $wiosettings{'ACTION'} eq $Lang::tr{'edit'}) && ! defined($message) ) {
1774 print"<td width='20%' align='center'>&nbsp;</td>
1775 <td width='20%' align='center'>&nbsp;</td>
1776 <td width='20%' align='center'><input type='hidden' name='ACTION' value='$Lang::tr{'wio_client_add'}' /><input type='submit' name='SUBMIT' value='$buttontext' /></td>
1777 <td width='20%' align='center'><input type='button' onClick='location.href=\"/cgi-bin/wio.cgi\"' value='$Lang::tr{'wio_back'}'></form></td>";
1778 }
1779 else {
1780 print"<td width='20%' align='center'>&nbsp;</td>
1781 <td width='20%' align='center'>&nbsp;</td>
1782 <td width='20%' align='center'>&nbsp;</td>
1783 <td width='20%' align='right'><input type='hidden' name='ACTION' value='$Lang::tr{'wio_client_add'}' /><input type='submit' name='SUBMIT' value='$buttontext' /></form></td>";
1784 }
1785
1786 print"
1787 </tr>
1788 </table>
1789 ";
1790
1791 if ( $wiosettings{'ENABLE'} eq 'on' && !$errormessage && $wiosettings{'ACTION'} ne $Lang::tr{'edit'} || $message == 2 ) {
1792
1793 &hrline();
1794
1795 ## arp table entries
1796
1797 print"
1798 <table border='0' width='100%' bordercolor='$Header::bordercolour' cellspacing='0' cellpadding='0' style='border-collapse: collapse'>
1799 <tr>
1800 <td width='33%' bgcolor='$color{'color20'}' align='left' height='25'><b>&nbsp;$Lang::tr{'wio_arp_table_entries'}</b></td>
1801 <td width='67%' align='right'><form method='post' action='$ENV{'SCRIPT_NAME'}'><input type='hidden' name='WIOGUISHOWARPTABLE' value='arptable' /><input type='submit' name='ACTION' value='$arpbuttontext' /></form></td>
1802 </tr>
1803 </table>
1804 ";
1805
1806 if ( $wiosettings{'WIOGUISHOWARPTABLE'} eq 'on' ) {
1807
1808 print"
1809 <table border='0' width='100%' bordercolor='$Header::bordercolour' cellspacing='0' cellpadding='0' style='border-collapse: collapse'>
1810 <tr><td colspan='2'>&nbsp;</td></tr>
1811 <tr bgcolor='$color{'color20'}'>
1812 <td width='5%' align='center' height='20'><b>$Lang::tr{'wio_id'}</b></td>
1813 <td width='20%' align='center' height='20'><b>$Lang::tr{'wio_hwaddress'}</b></td>
1814 <td width='20%' align='center' height='20'><b>$Lang::tr{'wio ipadress'}</b></td>
1815 <td width='15%' align='center' height='20'><b>$Lang::tr{'wio network'}</b></td>
1816 <td width='20%' align='center' height='20'><b>$Lang::tr{'wio name'}</b></td>
1817 <td width='15%' align='center' height='20'><b>$Lang::tr{'wio_iface'}</b></td>
1818 <td width='5%' align='center' height='20'><b>$Lang::tr{'action'}</b></td>
1819 </tr>
1820 ";
1821
1822 $output = `/sbin/ip neigh list`;
1823 $output = &Header::cleanhtml($output,"y");
1824
1825 my $arpcnt = 0;
1826
1827 foreach $line (split(/\n/, $output))
1828 {
1829 if ($line =~ m/^(.*) dev ([^ ]+) lladdr ([0-9a-f:]*) (.*)$/) {
1830 my $arphost = gethostbyaddr(inet_aton($1), AF_INET);
1831 if ( $arphost eq 'localhost' ) { $arphost = ''; }
1832 push (@arpcache, "$3,$1,$arphost,$2\n");
1833 }
1834 elsif ($line =~ m/^(.*) dev ([^ ]+) (.*)$/) {
1835 my $arphost = gethostbyaddr(inet_aton($1), AF_INET);
1836 if ( $arphost eq 'localhost' ) { $arphost = ''; }
1837 push (@arpcache, ",$1,$arphost,$2\n");
1838 }
1839
1840 $arpcnt++;
1841 }
1842
1843 &SortDataFile('arpcache',@arpcache);
1844
1845 foreach (@arpcache) {
1846 chomp;
1847
1848 @line = split (/\,/, $_);
1849
1850 print"<tr".($idarp % 2?" bgcolor='$color{'color20'}'":" bgcolor='$color{'color22'}'")." height='20'>";
1851 printf ("<td align='center'> %02d</td>", $idarp+1);
1852 print"<td align='center'>$line[0]</td>
1853 <td align='center'>$line[1]</td>";
1854
1855 SWITCH: {
1856
1857 foreach (@devs_color) {
1858 my $in = 0;
1859 $ic = "${_}";
1860
1861 foreach $interface (@devs_net) {
1862 next if ( $netsettings{"$ic"."_DEV"} eq 'red0' && ($netsettings{"RED_TYPE"} eq 'DHCP' || $netsettings{"RED_TYPE"} eq 'PPPOE'));
1863
1864 if ($netsettings{"$ic"."_DEV"} eq $interface) {
1865 if ( &General::IpInSubnet($line[1], $netsettings{"$ic"."_NETADDRESS"}, $netsettings{"$ic"."_NETMASK"}) ) {
1866 print"<td align='center'><img src='$imgstatic/$devs_img[$in]' alt='$Lang::tr{$devs_alt[$in]}' title='$Lang::tr{$devs_alt[$in]}' /></td>";
1867 last SWITCH;
1868 }
1869 }
1870
1871 $in++;
1872 }
1873 }
1874
1875 if ($netsettings{"RED_TYPE"} eq 'DHCP' || $netsettings{"RED_TYPE"} eq 'PPPOE') {
1876 my $redipadr = qx'ip addr | grep red0 | grep inet | awk "{print \$2}"';
1877 my @rednet = split ("/", $redipadr);
1878 chomp ($rednet[1]);
1879 my $red_netmask = General::iporsubtodec($rednet[1]);
1880 my $red_netaddress = Network::get_netaddress("$rednet[0]/$red_netmask");
1881
1882 if ( &General::IpInSubnet($line[1], $red_netaddress, $red_netmask) ) {
1883 print"<td align='center' height='20'><img src='$imgstatic/red.png' alt='$Lang::tr{'wio_red_lan'}' title='$Lang::tr{'wio_red_lan'}' /></td>";
1884 last SWITCH;
1885 }
1886 else {
1887 print"<td align='center'><img align='middle' src='$imgstatic/white.png' alt='$Lang::tr{'wio_unknown_lan'}' title='$Lang::tr{'wio_unknown_lan'}' /></td>";
1888 last SWITCH;
1889 }
1890 }
1891 }
1892
1893 print"<td align='center'>$line[2]</td>
1894 <td align='center'>".&WIO::color_devices($line[3])."</td>";
1895
1896 unless (&WIO::checkinto($line[1], '', @current)) {
1897 print"<td align='center'><form method='post' action='$ENV{'SCRIPT_NAME'}' enctype='multipart/form-data'>
1898 <input type='hidden' name='ACTION' value='$Lang::tr{'wio_add'}' />
1899 <input type='image' name='$Lang::tr{'wio_add'}' src='/images/add.gif' align='middle' alt='$Lang::tr{'wio_add'}' title='$Lang::tr{'wio_add'}' />
1900 <input type='hidden' name='ID' value='$idarp' /></form></td>";
1901 }
1902 else {
1903 print"<td align='center'><img src='$imgstatic/add.png' align='middle' alt='$Lang::tr{'wio_no_add'}' title='$Lang::tr{'wio_no_add'}' /></td>";
1904 }
1905
1906 print"</tr>";
1907 print"<tr height='1'><td colspan='17' bgcolor='#696565'></td></tr>";
1908 $idarp++
1909 }
1910
1911 print"
1912 </table>
1913 ";
1914 }
1915
1916 &hrline();
1917
1918 print"
1919 <table border='0' width='100%' bordercolor='$Header::bordercolour' cellspacing='0' cellpadding='0' style='border-collapse: collapse'>
1920 <tr>
1921 <td width='33%' bgcolor='$color{'color20'}' align='left' height='25'><b>&nbsp;$Lang::tr{'wio_import_file'}</b></td>
1922 <td width='67%' align='right'><form method='post' action='$ENV{'SCRIPT_NAME'}'><input type='hidden' name='WIOGUISHOWCLIENTIMPORTTABLE' value='clientimport' /><input type='submit' name='ACTION' value='$clientimportbuttontext' /></form></td>
1923 </tr>
1924 </table>
1925 ";
1926
1927 if ( $wiosettings{'WIOGUISHOWCLIENTIMPORTTABLE'} eq 'on' ) {
1928
1929 print"
1930 <table width='100%' cellspacing='0' cellpadding='0' style='border-collapse: collapse'>
1931 <tr><td colspan='3'>&nbsp;</td></tr>
1932 <tr bgcolor='$color{'color22'}'>
1933 <form method='post' action='/cgi-bin/wio.cgi' enctype='multipart/form-data'>
1934 <td width='35%' align='right'>$Lang::tr{'wio_import_csv'}&nbsp;</td>
1935 <td width='40%' align='center'><input type='file' name='CSVFILE' size='30' /></td>
1936 <td width='25%' align='right'><input type='hidden' name='ACTION' value='$Lang::tr{'wio_import'}1' /><input type='submit' name='SUBMIT' value='$Lang::tr{'wio_import'}' /></td>
1937 </form>
1938 </tr>
1939 <tr><td colspan='3'>&nbsp;</td></tr>
1940 <tr bgcolor='$color{'color22'}'>
1941 <form method='post' action='/cgi-bin/wio.cgi' enctype='multipart/form-data'>
1942 <td width='35%' align='right'>$Lang::tr{'wio_import_hosts'}&nbsp;</td>
1943 <td width='40%' align='center'>&nbsp;</td>
1944 <td width='25%' align='right'><input type='hidden' name='ACTION' value='$Lang::tr{'wio_import'}2' /><input type='submit' name='SUBMIT' value='$Lang::tr{'wio_import'}' /></td>
1945 </form>
1946 </tr>
1947 <tr><td colspan='3'>&nbsp;</td></tr>
1948 <tr bgcolor='$color{'color22'}'>
1949 <form method='post' action='/cgi-bin/wio.cgi' enctype='multipart/form-data'>
1950 <td width='35%' align='right'>$Lang::tr{'wio_import_fixleases'}&nbsp;</td>
1951 <td width='40%' align='center'>&nbsp;</td>
1952 <td width='25%' align='right'><input type='hidden' name='ACTION' value='$Lang::tr{'wio_import'}3' /><input type='submit' name='SUBMIT' value='$Lang::tr{'wio_import'}' /></td>
1953 </form>
1954 </tr>
1955 </table>
1956 ";
1957 }
1958
1959 &hrline;
1960
1961 print"
1962 <table border='0' width='100%' bordercolor='$Header::bordercolour' cellspacing='0' cellpadding='0' style='border-collapse: collapse'>
1963 <tr>
1964 <td width='33%' bgcolor='$color{'color20'}' align='left' height='25'><b>&nbsp;$Lang::tr{'wio_net_scan'}</b></td>
1965 <td width='67%' align='right'><form method='post' action='$ENV{'SCRIPT_NAME'}'><input type='hidden' name='WIOGUISHOWNETWORKSEARCHTABLE' value='networksearch' /><input type='submit' name='ACTION' value='$networksearchbuttontext' /></form></td>
1966 </tr>
1967 </table>
1968 ";
1969
1970 if ( $wiosettings{'WIOGUISHOWNETWORKSEARCHTABLE'} eq 'on' ) {
1971
1972 print"
1973 <table width='100%' cellspacing='0' cellpadding='0' style='border-collapse: collapse'>
1974 <tr>
1975 <td colspan='3'>&nbsp;</td>
1976 </tr>
1977 ";
1978
1979 foreach (keys(%ifacecolor)) {
1980 if ( $_ eq 'GREEN' ) { $color = "$Header::colourgreen"; $net = $Lang::tr{'wio_net_scan_green'}; }
1981 elsif ( $_ eq 'BLUE' ) { $color = "$Header::colourblue"; $net = $Lang::tr{'wio_net_scan_blue'}; }
1982 else { $color = "$Header::colourorange"; $net = $Lang::tr{'wio_net_scan_orange'}; }
1983
1984 if ( $netsettings{"${_}_DEV"} eq 'disabled' || $netsettings{"${_}_DEV"} eq '' || $netsettings{"${_}_ADDRESS"} eq '' ) { next; }
1985 else {
1986 print <<END;
1987
1988 <tr bgcolor='$color{'color22'}'>
1989 <td width='35%' align='right'><form method='post' action='$ENV{'SCRIPT_NAME'}' enctype='multipart/form-data'>$Lang::tr{'wio_net_scan_vl'} <font color='$color'><b>$net</b></font> $Lang::tr{'wio_net_scan_l'}<font color='$color'><b> $netsettings{"${_}_DEV"} </b></font>$Lang::tr{'wio_net_scan_r'}</td>
1990 <td width='40%' align='center'><input type='text' name='${_}_IPLOW' value='$wiosettings{"${_}_IPLOW"}' size='14' STYLE='background-color:$color; text-align: center; color:white' /> - <input type='text' name='${_}_IPHIGH' value='$wiosettings{"${_}_IPHIGH"}' size='14' STYLE='background-color:$color; text-align: center; color:white' /></td>
1991 <td width='25%' align='right'><input type='hidden' name='ACTION' value='$ifacecolor{$_}' /><input type='hidden' name='ID' value='$netsettings{"${_}_DEV"}' /><input type='submit' name='SUBMIT' value='$Lang::tr{'wio_net_scan_run'}'></form></td>
1992 </tr>
1993 <tr>
1994 <td colspan='3'>&nbsp;</td>
1995 </tr>
1996 END
1997 }
1998 }
1999
2000 print"
2001 </tr>
2002 </table>
2003 </form>
2004 ";
2005 }
2006 &Header::closebox();
2007 }
2008
2009 if ( $wiosettings{'ENABLE'} eq 'on' && !$errormessage && $wiosettings{'ACTION'} ne $Lang::tr{'edit'} || $message == 2 ) {
2010
2011 &Header::openbox('100%', 'left', $Lang::tr{'wio_service'});
2012
2013 print"
2014 <table border='0' width='100%' bordercolor='$Header::bordercolour' cellspacing='0' cellpadding='0' style='border-collapse: collapse'>
2015 <tr bgcolor='$color{'color22'}'>
2016 <td colspan='2' align='right'></td>
2017 ";
2018
2019 if ( $wiosettings{'LOGGING'} eq 'on' ) {
2020 print"<td width='10%' align='right'><form method='post' action='/cgi-bin/logs.cgi/log.dat' enctype='multipart/form-data'><input type='hidden' name='SECTION' value='wio' /><input type='submit' name='SUBMIT' value='$Lang::tr{'system logs'}' /></form></td>";
2021 }
2022
2023 print"
2024 <td width='10%' align='right'><form method='post' action='$ENV{'SCRIPT_NAME'}' enctype='multipart/form-data'><input type='hidden' name='ACTION' value='$Lang::tr{'edit'}1' /><input type='submit' name='SUBMIT' value='$Lang::tr{'wio_edit_set'}' /></form></td>
2025 </tr>
2026 </table>
2027 ";
2028 }
2029
2030 &Header::closebox();
2031 }
2032
2033 &Header::closebigbox();
2034 &Header::closepage();
2035
2036 ############################################################################################################################
2037
2038 sub SortDataFile {
2039 my ($data,@checkfile) = @_;
2040 my $idsort = 0;
2041 our %entries = ();
2042
2043 sub sortips {
2044 my $qs = '';
2045
2046 if (rindex ($wiosettings{'SORT'},'Rev') != -1) {
2047 $qs = substr ($wiosettings{'SORT'},0,length($wiosettings{'SORT'})-3);
2048
2049 if ($qs eq 'IPADR') {
2050 my @a = split (/\./,$entries{$a}->{$qs});
2051 my @b = split (/\./,$entries{$b}->{$qs});
2052 ($b[0]<=>$a[0]) ||
2053 ($b[1]<=>$a[1]) ||
2054 ($b[2]<=>$a[2]) ||
2055 ($b[3]<=>$a[3]);
2056 }
2057 else {
2058 $entries{$b}->{$qs} cmp $entries{$a}->{$qs};
2059 }
2060 }
2061 else {
2062 $qs = $wiosettings{'SORT'};
2063
2064 if ($qs eq 'IPADR') {
2065 my @a = split (/\./,$entries{$a}->{$qs});
2066 my @b = split (/\./,$entries{$b}->{$qs});
2067 ($a[0]<=>$b[0]) ||
2068 ($a[1]<=>$b[1]) ||
2069 ($a[2]<=>$b[2]) ||
2070 ($a[3]<=>$b[3]);
2071 }
2072 else {
2073 $entries{$a}->{$qs} cmp $entries{$b}->{$qs};
2074 }
2075 }
2076 }
2077
2078 if ($data eq 'arpcache') {
2079 foreach (@checkfile) {
2080 chomp;
2081 @temp = split (',', $_);
2082
2083 my @record = ('KEY',$idsort++,'MAC',$temp[0],'IPADR',$temp[1],'HOST',$temp[2],'REMARK',$temp[3],'IFACE',$temp[4]);
2084 my $record = ();
2085 %{$record} = @record;
2086 $entries{$record->{KEY}} = $record;
2087 }
2088
2089 open(FILE, "> $logdir/.arpcache");
2090
2091 foreach (sort sortips keys %entries) {
2092 print FILE "$entries{$_}->{MAC},$entries{$_}->{IPADR},$entries{$_}->{HOST},$entries{$_}->{REMARK},$entries{$_}->{IFACE},$entries{$_}->{HW}\n";
2093 }
2094
2095 close(FILE);
2096
2097 open (FILE, "$logdir/.arpcache");
2098 @arpcache = <FILE>;
2099 close (FILE);
2100 }
2101 else {
2102 foreach (@checkfile) {
2103 chomp;
2104 @temp = split (',', $_);
2105
2106 my @record = ('KEY',$idsort++,'CLIENTID',$temp[0],'TIMESTAMP',$temp[1],'IPADR',$temp[2],'HOST',$temp[3],'EN',$temp[4],'REMARK',$temp[5],'DYNDNS',$temp[6],'SENDEMAILON',$temp[7],'SENDEMAILOFF',$temp[8],'PINGMETHODE',$temp[9],'ONLINE',$temp[10],'WEBINTERFACE',$temp[11]);
2107 my $record = ();
2108 %{$record} = @record;
2109 $entries{$record->{KEY}} = $record;
2110 }
2111
2112 open(FILE, "> $ipadrfile");
2113
2114 foreach (sort sortips keys %entries) {
2115 print FILE "$entries{$_}->{CLIENTID},$entries{$_}->{TIMESTAMP},$entries{$_}->{IPADR},$entries{$_}->{HOST},$entries{$_}->{EN},$entries{$_}->{REMARK},$entries{$_}->{DYNDNS},$entries{$_}->{SENDEMAILON},$entries{$_}->{SENDEMAILOFF},$entries{$_}->{PINGMETHODE},$entries{$_}->{ONLINE},$entries{$_}->{WEBINTERFACE}\n";
2116 }
2117
2118 close(FILE);
2119
2120 &loadips();
2121 }
2122 }
2123
2124 ############################################################################################################################
2125
2126 sub hrline {
2127
2128 print"<table width='100%'><tr><td colspan='2' height='35'><hr></td></tr></table>";
2129
2130 }
2131
2132 ############################################################################################################################
2133
2134 sub back {
2135
2136 print"<table width='100%'><tr><td width='10%'><a href='/cgi-bin/wio.cgi'><img src='/images/wio/back.png' alt='$Lang::tr{'wio_back'}' title='$Lang::tr{'wio_back'}' /></a></td><td>&nbsp;</td></tr></table>";
2137
2138 }
2139
2140 ############################################################################################################################
2141
2142 sub loadips {
2143
2144 &General::readhasharray($ipadrfile, \%ipshash);
2145
2146 open(FILE, "< $ipadrfile");
2147 @current = <FILE>;
2148 close (FILE);
2149
2150 }
2151
2152 ############################################################################################################################
2153
2154 sub writeips {
2155
2156 open(FILE, "> $ipadrfile");
2157 if ( defined($write) ) { print FILE @write; }
2158 else { print FILE @current; }
2159 close(FILE);
2160
2161 }
2162
2163 ############################################################################################################################
2164
2165 sub SortByTunnelName {
2166
2167 if ($vpnconfighash{$a}[1] lt $vpnconfighash{$b}[1]) {
2168 return -1;
2169 }
2170 elsif ($vpnconfighash{$a}[1] gt $vpnconfighash{$b}[1]) {
2171 return 1;
2172 }
2173 else {
2174 return 0;
2175 }
2176
2177 }
2178
2179 ############################################################################################################################
2180
2181 sub validSave {
2182
2183 if ( $wiosettings{'IPADR'} eq '' && $wiosettings{'PINGMETHODE'} eq 'ip' && $wiosettings{'DYNDNS'} eq '' ) {
2184 $errormessage = $Lang::tr{'wio_ip_empty'};
2185 }
2186
2187 if ( $wiosettings{'IPADR'} ne '' && (! &General::validip($wiosettings{'IPADR'})) ) {
2188 $errormessage = $Lang::tr{'wio_ip_error'};
2189 }
2190
2191 if ( $wiosettings{'HOST'} eq '' && $wiosettings{'PINGMETHODE'} eq 'fqdn' ) {
2192 $errormessage = $Lang::tr{'wio_host_empty'};
2193 }
2194
2195 if ( $wiosettings{'HOST'} ne '' && (! &General::validdomainname($wiosettings{'HOST'})) ) {
2196 $errormessage = $Lang::tr{'wio_host_error'};
2197 }
2198
2199 if ( $wiosettings{'DYNDNS'} eq 'on' && (! defined($errormessage)) ) {
2200 unless(&General::validfqdn($wiosettings{'HOST'})) { $errormessage = $Lang::tr{'wio_fqdn_error'}; }
2201 ( $wiosettings{'IPADR'}, $infomessage ) = &WIO::getdyndnsip($wiosettings{'IPADR'}, $wiosettings{'HOST'});
2202 $wiosettings{'PINGMETHODE'} = 'fqdn';
2203 }
2204
2205 if ( $wiosettings{'ID'} eq '' && ! defined($errormessage) ) { $errormessage = &WIO::checkinto($wiosettings{'IPADR'}, $wiosettings{'HOST'}, @current); }
2206
2207 if ( $wiosettings{'REMARK'} ne '' ) { $wiosettings{'REMARK'} =~ s/,/&#44;/g; }
2208
2209 }