]> git.ipfire.org Git - people/teissler/ipfire-2.x.git/blob - config/cfgroot/header.pl
Von nun an kann man statische Zuordnungen mit einem Klick aus einer dynamischen Zuord...
[people/teissler/ipfire-2.x.git] / config / cfgroot / header.pl
1 # SmoothWall CGIs
2 #
3 # This code is distributed under the terms of the GPL
4 #
5 # (c) The SmoothWall Team
6 # Copyright (C) 2002 Alex Hudson - getcgihash() rewrite
7 # Copyright (C) 2002 Bob Grant <bob@cache.ucr.edu> - validmac()
8 # Copyright (c) 2002/04/13 Steve Bootes - add alias section, helper functions
9 # Copyright (c) 2002/08/23 Mark Wormgoor <mark@wormgoor.com> validfqdn()
10 # Copyright (c) 2003/09/11 Darren Critchley <darrenc@telus.net> srtarray()
11 #
12 package Header;
13
14 use CGI();
15 use Socket;
16 use Time::Local;
17
18 $|=1; # line buffering
19
20 $Header::revision = 'final';
21 $Header::swroot = '/var/ipfire';
22 $Header::pagecolour = '#ffffff';
23 #$Header::tablecolour = '#a0a0a0';
24 $Header::tablecolour = '#FFFFFF';
25 $Header::bigboxcolour = '#F6F4F4';
26 $Header::boxcolour = '#EAE9EE';
27 $Header::bordercolour = '#000000';
28 $Header::table1colour = '#E0E0E0';
29 $Header::table2colour = '#F0F0F0';
30 $Header::colourred = '#993333';
31 $Header::colourorange = '#FF9933';
32 $Header::colouryellow = '#FFFF00';
33 $Header::colourgreen = '#339933';
34 $Header::colourblue = '#333399';
35 $Header::colourovpn = '#339999';
36 $Header::colourfw = '#000000';
37 $Header::colourvpn = '#990099';
38 $Header::colourerr = '#FF0000';
39 $Header::viewsize = 150;
40 $Header::errormessage = '';
41 my %menuhash = ();
42 my $menu = \%menuhash;
43 %settings = ();
44 %ethsettings = ();
45 @URI = ();
46
47 ### Make sure this is an SSL request
48 if ($ENV{'SERVER_ADDR'} && $ENV{'HTTPS'} ne 'on') {
49 print "Status: 302 Moved\r\n";
50 print "Location: https://$ENV{'SERVER_ADDR'}:444/$ENV{'PATH_INFO'}\r\n\r\n";
51 exit 0;
52 }
53
54 ### Initialize environment
55 &readhash("${swroot}/main/settings", \%settings);
56 &readhash("${swroot}/ethernet/settings", \%ethsettings);
57 $language = $settings{'LANGUAGE'};
58 $hostname = $settings{'HOSTNAME'};
59 $hostnameintitle = 0;
60
61 ### Initialize language
62 if ($language =~ /^(\w+)$/) {$language = $1;}
63
64 ### Read English Files
65 if ( -d "/var/ipfire/langs/en/" ) {
66 opendir(DIR, "/var/ipfire/langs/en/");
67 @names = readdir(DIR) or die "Cannot Read Directory: $!\n";
68 foreach $name(@names) {
69 next if ($name eq ".");
70 next if ($name eq "..");
71 next if (!($name =~ /\.pl$/));
72 require "${swroot}/langs/en/${name}";
73 };
74 };
75
76
77 ### Enable Language Files
78 if ( -d "/var/ipfire/langs/${language}/" ) {
79 opendir(DIR, "/var/ipfire/langs/${language}/");
80 @names = readdir(DIR) or die "Cannot Read Directory: $!\n";
81 foreach $name(@names) {
82 next if ($name eq ".");
83 next if ($name eq "..");
84 next if (!($name =~ /\.pl$/));
85 require "${swroot}/langs/${language}/${name}";
86 };
87 };
88
89 ### Read IPFire Buildversion
90 $FIREBUILD = "File not found: firebuild\n";
91 if (open(MYFile, "<${swroot}/firebuild")) {
92 $FIREBUILD = <MYFile>;
93 chomp($FIREBUILD);
94 $FIREBUILD = "(Build: $FIREBUILD)";
95 close(MYFile);
96 };
97
98 require "${swroot}/langs/en.pl";
99 require "${swroot}/langs/${language}.pl";
100 eval `/bin/cat /srv/web/ipfire/html/themes/$settings{'THEME'}/include/functions.pl`;
101
102 sub orange_used () {
103 if ($ethsettings{'CONFIG_TYPE'} =~ /^[1357]$/) {
104 return 1;
105 }
106 return 0;
107 }
108
109 sub blue_used () {
110 if ($ethsettings{'CONFIG_TYPE'} =~ /^[4567]$/) {
111 return 1;
112 }
113 return 0;
114 }
115
116 sub is_modem {
117 if ($ethsettings{'CONFIG_TYPE'} =~ /^[0145]$/) {
118 return 1;
119 }
120 return 0;
121 }
122
123 ### Initialize menu
124 sub genmenu {
125 my %subsystemhash = ();
126 my $subsystem = \%subsystemhash;
127
128 $subsystem->{'10.home'} = {
129 'caption' => $tr{'alt home'},
130 'uri' => '/cgi-bin/index.cgi',
131 'title' => "$tr{'alt home'}",
132 'enabled' => 1,
133 };
134 $subsystem->{'20.dialup'} = {
135 'caption' => $tr{'alt dialup'},
136 'uri' => '/cgi-bin/pppsetup.cgi',
137 'title' => "$tr{'alt dialup'}",
138 'enabled' => 1,
139 };
140 $subsystem->{'30.passwords'} = {
141 'caption' => $tr{'sspasswords'},
142 'uri' => '/cgi-bin/changepw.cgi',
143 'title' => "$tr{'sspasswords'}",
144 'enabled' => 1,
145 };
146 $subsystem->{'40.ssh'} = {
147 'caption' => $tr{'ssh access'},
148 'uri' => '/cgi-bin/remote.cgi',
149 'title' => "$tr{'ssh access'}",
150 'enabled' => 1,
151 };
152 $subsystem->{'50.gui'} = {
153 'caption' => $tr{'gui settings'},
154 'uri' => '/cgi-bin/gui.cgi',
155 'title' => "$tr{'gui settings'}",
156 'enabled' => 1,
157 };
158 $subsystem->{'60.shutdown'} = {
159 'caption' => $tr{'shutdown'},
160 'uri' => '/cgi-bin/shutdown.cgi',
161 'title' => "$tr{'shutdown'} / $tr{'reboot'}",
162 'enabled' => 1,
163 };
164 $subsystem->{'99.credits'} = {
165 'caption' => $tr{'credits'},
166 'uri' => '/cgi-bin/credits.cgi',
167 'title' => "$tr{'credits'}",
168 'enabled' => 1,
169 };
170
171 my %substatushash = ();
172 my $substatus = \%substatushash;
173 $substatus->{'10.systemstatus'} = {
174 'caption' => $tr{'sssystem status'},
175 'uri' => '/cgi-bin/status.cgi',
176 'title' => "$tr{'sssystem status'}",
177 'enabled' => 1,
178 };
179 $substatus->{'20.networkstatus'} = {
180 'caption' => $tr{'ssnetwork status'},
181 'uri' => '/cgi-bin/netstatus.cgi',
182 'title' => "$tr{'ssnetwork status'}",
183 'enabled' => 1,
184 };
185 $substatus->{'30.systemgraphs'} = {
186 'caption' => $tr{'system graphs'},
187 'uri' => '/cgi-bin/graphs.cgi',
188 'novars' => 1,
189 'title' => "$tr{'system graphs'}",
190 'enabled' => 1,
191 };
192 $substatus->{'40.trafficgraphs'} = {
193 'caption' => $tr{'sstraffic graphs'},
194 'uri' => '/cgi-bin/graphs.cgi',
195 'vars' => 'graph=network',
196 'title' => "$tr{'sstraffic graphs'}",
197 'enabled' => 1,
198 };
199 $substatus->{'50.proxygraphs'} = {
200 'caption' => $tr{'ssproxy graphs'},
201 'uri' => '/cgi-bin/proxygraphs.cgi',
202 'title' => "$tr{'ssproxy graphs'}",
203 'enabled' => 1,
204 };
205 $substatus->{'60.fwhits'} = {
206 'caption' => 'Firewall-Diagramme',
207 'uri' => '/cgi-bin/fwhits.cgi',
208 'title' => "Firewall-Diagramme",
209 'enabled' => 1,
210 };
211 $substatus->{'70.hardwaregraphs'} = {
212 'caption' => "$tr{'hardware graphs'}",
213 'uri' => '/cgi-bin/hardwaregraphs.cgi',
214 'title' => "$tr{'hardware graphs'}",
215 'enabled' => 1,
216 };
217 $substatus->{'80.connections'} = {
218 'caption' => $tr{'connections'},
219 'uri' => '/cgi-bin/connections.cgi',
220 'title' => "$tr{'connections'}",
221 'enabled' => 1,
222 };
223 $substatus->{'90.nettraf'} = {
224 'caption' => $tr{'sstraffic'},
225 'uri' => '/cgi-bin/traffic.cgi',
226 'title' => "$tr{'sstraffic'}",
227 'enabled' => 1,
228 };
229 $substatus->{'99.iptable'} = {
230 'caption' => $tr{'iptable rules'},
231 'uri' => '/cgi-bin/iptables.cgi',
232 'title' => "$tr{'iptable rules'}",
233 'enabled' => 1,
234 };
235
236 my %subnetworkhash = ();
237 my $subnetwork = \%subnetworkhash;
238
239 $subnetwork->{'10.netconf'} = {'caption' => "$tr{'net config'}",
240 'uri' => '/cgi-bin/netconfig.cgi',
241 'title' => "$tr{'net config'}",
242 'enabled' => 1,
243 };
244 $subnetwork->{'20.proxy'} = {'caption' => 'Webproxy',
245 'uri' => '/cgi-bin/proxy.cgi',
246 'title' => "Webproxy",
247 'enabled' => 1,
248 };
249 $subnetwork->{'30.urlfilter'} = {'caption' => 'URL-Filter',
250 'uri' => '/cgi-bin/urlfilter.cgi',
251 'title' => "URL-Filter",
252 'enabled' => 1,
253 };
254 $subnetwork->{'40.dhcp'} = {'caption' => $tr{'dhcp server'},
255 'uri' => '/cgi-bin/dhcp.cgi',
256 'title' => "$tr{'dhcp server'}",
257 'enabled' => 1,
258 };
259 $subnetwork->{'50.scheduler'} = {
260 'caption' => $tr{'connscheduler'},
261 'uri' => '/cgi-bin/connscheduler.cgi',
262 'title' => "$tr{'connscheduler'}",
263 'enabled' => 1,
264 };
265 $subnetwork->{'60.hosts'} = {
266 'caption' => $tr{'edit hosts'},
267 'uri' => '/cgi-bin/hosts.cgi',
268 'title' => "$tr{'edit hosts'}",
269 'enabled' => 1,
270 };
271 $subnetwork->{'70.upload'} = {
272 'caption' => $tr{'upload'},
273 'uri' => '/cgi-bin/upload.cgi',
274 'title' => "$tr{'upload'}",
275 'enabled' => 0,
276 };
277 $subnetwork->{'80.aliases'} = {
278 'caption' => $tr{'aliases'},
279 'uri' => '/cgi-bin/aliases.cgi',
280 'title' => "$tr{'aliases'}",
281 'enabled' => 0,
282 };
283 $subnetwork->{'90.wakeonlan'} = {
284 'caption' => $tr{'WakeOnLan'},
285 'uri' => '/cgi-bin/wakeonlan.cgi',
286 'title' => "$tr{'WakeOnLan'}",
287 'enabled' => 1,
288 };
289
290 my %subserviceshash = ();
291 my $subservices = \%subserviceshash;
292
293
294 $subservices->{'10.openvpn'} = {
295 'caption' => 'OpenVPN',
296 'uri' => '/cgi-bin/ovpnmain.cgi',
297 'title' => "$tr{'virtual private networking'}",
298 'enabled' => 1,
299 };
300 $subservices->{'20.ipsec'} = {
301 'caption' => 'IPSec',
302 'uri' => '/cgi-bin/vpnmain.cgi',
303 'title' => "$tr{'virtual private networking'}",
304 'enabled' => 1,
305 };
306 $subservices->{'30.dyndns'} = {'caption' => $tr{'dynamic dns'},
307 'uri' => '/cgi-bin/ddns.cgi',
308 'title' => "$tr{'dynamic dns'}",
309 'enabled' => 1,
310 };
311 $subservices->{'40.time'} = {'caption' => $tr{'time server'},
312 'uri' => '/cgi-bin/time.cgi',
313 'title' => "$tr{'time server'}",
314 'enabled' => 1,
315 };
316 $subservices->{'50.qos'} = {'caption' => 'Quality of Service',
317 'uri' => '/cgi-bin/qos.cgi',
318 'title' => "Quality of Service",
319 'enabled' => 1,
320 };
321 $subservices->{'60.ids'} = {'caption' => $tr{'intrusion detection'},
322 'enabled' => 1,
323 'uri' => '/cgi-bin/ids.cgi',
324 'title' => "$tr{'intrusion detection system'}",
325 };
326
327
328
329 my %subfirewallhash = ();
330 my $subfirewall = \%subfirewallhash;
331
332
333 $subfirewall->{'10.dnat'} = {
334 'caption' => $tr{'ssport forwarding'},
335 'uri' => '/cgi-bin/portfw.cgi',
336 'title' => "$tr{'ssport forwarding'}",
337 'enabled' => 1,
338 };
339 $subfirewall->{'20.xtaccess'} = {
340 'caption' => $tr{'external access'},
341 'uri' => '/cgi-bin/xtaccess.cgi',
342 'title' => "$tr{'external access'}",
343 'enabled' => 1,
344 };
345 $subfirewall->{'30.wireless'} = {
346 'caption' => $tr{'blue access'},
347 'uri' => '/cgi-bin/wireless.cgi',
348 'title' => "$tr{'blue access'}",
349 'enabled' => 1,
350 };
351 $subfirewall->{'40.dmz'} = {
352 'caption' => $tr{'ssdmz pinholes'},
353 'uri' => '/cgi-bin/dmzholes.cgi',
354 'title' => "$tr{'dmz pinhole configuration'}",
355 'enabled' => 1,
356 };
357 $subfirewall->{'50.outgoing'} = {
358 'caption' => $tr{'outgoing firewall'},
359 'uri' => '/cgi-bin/outgoingfw.cgi',
360 'title' => "$tr{'outgoing firewall'}",
361 'enabled' => 1,
362 };
363 $subfirewall->{'60.fwopts'} = {
364 'caption' => $tr{'options fw'},
365 'uri' => '/cgi-bin/optionsfw.cgi',
366 'title' => "$tr{'options fw'}",
367 'enabled' => 1,
368 };
369
370 my %sublogshash = ();
371 my $sublogs = \%sublogshash;
372
373 $sublogs->{'10.summary'} = {'caption' => $tr{'log summary'},
374 'uri' => '/cgi-bin/logs.cgi/summary.dat',
375 'title' => "$tr{'log summary'}",
376 'enabled' => 1
377 };
378 $sublogs->{'20.settings'} = {'caption' => $tr{'log settings'},
379 'uri' => '/cgi-bin/logs.cgi/config.dat',
380 'title' => "$tr{'log settings'}",
381 'enabled' => 1
382 };
383 $sublogs->{'30.proxy'} = {'caption' => $tr{'proxy logs'},
384 'uri' => '/cgi-bin/logs.cgi/proxylog.dat',
385 'title' => "$tr{'proxy logs'}",
386 'enabled' => 1
387 };
388 $sublogs->{'40.firewall'} = {'caption' => $tr{'firewall logs'},
389 'uri' => '/cgi-bin/logs.cgi/firewalllog.dat',
390 'title' => "$tr{'firewall logs'}",
391 'enabled' => 1
392 };
393 $sublogs->{'50.ids'} = {'caption' => $tr{'ids logs'},
394 'uri' => '/cgi-bin/logs.cgi/ids.dat',
395 'title' => "$tr{'ids logs'}",
396 'enabled' => 1
397 };
398 $sublogs->{'60.urlfilter'} = {
399 'caption' => $tr{'urlfilter logs'},
400 'uri' => '/cgi-bin/logs.cgi/urlfilter.dat',
401 'title' => "$tr{'urlfilter log'}",
402 'enabled' => 1,
403 };
404 $sublogs->{'70.openvpn'} = {'caption' => $tr{'openvpn log'},
405 'uri' => '/cgi-bin/logs.cgi/openvpn.dat',
406 'title' => "$tr{'openvpn log'}",
407 'enabled' => 1
408 };
409 $sublogs->{'80.system'} = {'caption' => $tr{'system logs'},
410 'uri' => '/cgi-bin/logs.cgi/log.dat',
411 'title' => "$tr{'system logs'}",
412 'enabled' => 1
413 };
414 $sublogs->{'90.userlog'} = {'caption' => $tr{'user proxy logs'},
415 'uri' => '/cgi-bin/logs.cgi/userlog.dat',
416 'title' => "$tr{'user log'}",
417 'enabled' => 1
418 };
419
420 my %subipfirehash = ();
421 my $subipfire = \%subipfirehash;
422 $subipfire->{'10.pakfire'} = {'caption' => 'Pakfire',
423 'uri' => '/cgi-bin/pakfire.cgi',
424 'title' => "Pakfire",
425 'enabled' => 1,
426 };
427 $subipfire->{'20.asterisk'} = {'caption' => 'Asterisk',
428 'uri' => '/cgi-bin/asterisk.cgi',
429 'title' => "Asterisk",
430 'enabled' => 1,
431 };
432 $subipfire->{'30.samba'} = {'caption' => 'Samba',
433 'uri' => '/cgi-bin/samba.cgi',
434 'title' => "Samba",
435 'enabled' => 1,
436 };
437 $subipfire->{'99.help'} = {'caption' => $tr{'help'},
438 'uri' => '/cgi-bin/help.cgi',
439 'title' => "$tr{'help'}",
440 'enabled' => 1,
441 };
442
443
444
445 $menu->{'01.system'} = {'caption' => $tr{'alt system'},
446 'enabled' => 1,
447 'subMenu' => $subsystem
448 };
449 $menu->{'02.status'} = {'caption' => $tr{'status'},
450 'enabled' => 1,
451 'subMenu' => $substatus
452 };
453 $menu->{'03.network'} = {'caption' => $tr{'network'},
454 'enabled' => 1,
455 'subMenu' => $subnetwork
456 };
457 $menu->{'04.services'} = {'caption' => $tr{'alt services'},
458 'enabled' => 1,
459 'subMenu' => $subservices
460 };
461 $menu->{'05.firewall'} = {'caption' => $tr{'firewall'},
462 'enabled' => 1,
463 'subMenu' => $subfirewall
464 };
465 $menu->{'06.proxy'} = {'caption' => $tr{'alt proxy'},
466 'enabled' => 1,
467 'subMenu' => $subproxy
468 };
469 $menu->{'07.ipfire'} = {'caption' => 'IPFire',
470 'enabled' => 1,
471 'subMenu' => $subipfire
472 };
473 $menu->{'08.logs'} = {'caption' => $tr{'alt logs'},
474 'enabled' => 1,
475 'subMenu' => $sublogs
476 };
477
478 if (! blue_used() && ! orange_used()) {
479 $menu->{'05.firewall'}{'subMenu'}->{'40.dmz'}{'enabled'} = 0;
480 }
481 if (! blue_used()) {
482 $menu->{'05.firewall'}{'subMenu'}->{'30.wireless'}{'enabled'} = 0;
483 }
484 if ( $ethsettings{'CONFIG_TYPE'} =~ /^(2|3|6|7)$/ && $ethsettings{'RED_TYPE'} eq 'STATIC' ) {
485 $menu->{'03.network'}{'subMenu'}->{'70.aliases'}{'enabled'} = 1;
486 }
487 }
488
489 sub showhttpheaders
490 {
491 print "Pragma: no-cache\n";
492 print "Cache-control: no-cache\n";
493 print "Connection: close\n";
494 print "Content-type: text/html\n\n";
495 }
496
497 sub is_menu_visible($) {
498 my $link = shift;
499 $link =~ s#\?.*$##;
500 return (-e $ENV{'DOCUMENT_ROOT'}."/../$link");
501 }
502
503
504 sub getlink($) {
505 my $root = shift;
506 if (! $root->{'enabled'}) {
507 return '';
508 }
509 if ($root->{'uri'} !~ /^$/) {
510 my $vars = '';
511 if ($root->{'vars'} !~ /^$/) {
512 $vars = '?'. $root->{'vars'};
513 }
514 if (! is_menu_visible($root->{'uri'})) {
515 return '';
516 }
517 return $root->{'uri'}.$vars;
518 }
519 my $submenus = $root->{'subMenu'};
520 if (! $submenus) {
521 return '';
522 }
523 foreach my $item (sort keys %$submenus) {
524 my $link = getlink($submenus->{$item});
525 if ($link ne '') {
526 return $link;
527 }
528 }
529 return '';
530 }
531
532
533 sub compare_url($) {
534 my $conf = shift;
535
536 my $uri = $conf->{'uri'};
537 my $vars = $conf->{'vars'};
538 my $novars = $conf->{'novars'};
539
540 if ($uri eq '') {
541 return 0;
542 }
543 if ($uri ne $URI[0]) {
544 return 0;
545 }
546 if ($novars) {
547 if ($URI[1] !~ /^$/) {
548 return 0;
549 }
550 }
551 if (! $vars) {
552 return 1;
553 }
554 return ($URI[1] eq $vars);
555 }
556
557
558 sub gettitle($) {
559 my $root = shift;
560
561 if (! $root) {
562 return '';
563 }
564 foreach my $item (sort keys %$root) {
565 my $val = $root->{$item};
566 if (compare_url($val)) {
567 $val->{'selected'} = 1;
568 if ($val->{'title'} !~ /^$/) {
569 return $val->{'title'};
570 }
571 return 'EMPTY TITLE';
572 }
573
574 my $title = gettitle($val->{'subMenu'});
575 if ($title ne '') {
576 $val->{'selected'} = 1;
577 return $title;
578 }
579 }
580 return '';
581 }
582
583 sub writehash
584 {
585 my $filename = $_[0];
586 my $hash = $_[1];
587
588 # write cgi vars to the file.
589 open(FILE, ">${filename}") or die "Unable to write file $filename";
590 flock FILE, 2;
591 foreach $var (keys %$hash)
592 {
593 $val = $hash->{$var};
594 # Darren Critchley Jan 17, 2003 added the following because when submitting with a graphic, the x and y
595 # location of the mouse are submitted as well, this was being written to the settings file causing
596 # some serious grief! This skips the variable.x and variable.y
597 if (!($var =~ /(.x|.y)$/)) {
598 if ($val =~ / /) {
599 $val = "\'$val\'"; }
600 if (!($var =~ /^ACTION/)) {
601 print FILE "${var}=${val}\n"; }
602 }
603 }
604 close FILE;
605 }
606
607 sub readhash
608 {
609 my $filename = $_[0];
610 my $hash = $_[1];
611 my ($var, $val);
612
613 open(FILE, $filename) or die "Unable to read file $filename";
614
615 while (<FILE>)
616 {
617 chop;
618 ($var, $val) = split /=/, $_, 2;
619 if ($var)
620 {
621 $val =~ s/^\'//g;
622 $val =~ s/\'$//g;
623
624 # Untaint variables read from hash
625 $var =~ /([A-Za-z0-9_-]*)/; $var = $1;
626 $val =~ /([\w\W]*)/; $val = $1;
627 $hash->{$var} = $val;
628 }
629 }
630 close FILE;
631 }
632
633 sub getcgihash {
634 my ($hash, $params) = @_;
635 my $cgi = CGI->new ();
636 $hash->{'__CGI__'} = $cgi;
637 return if ($ENV{'REQUEST_METHOD'} ne 'POST');
638 if (!$params->{'wantfile'}) {
639 $CGI::DISABLE_UPLOADS = 1;
640 $CGI::POST_MAX = 512 * 1024;
641 } else {
642 $CGI::POST_MAX = 10 * 1024 * 1024;
643 }
644
645 $cgi->referer() =~ m/^https?\:\/\/([^\/]+)/;
646 my $referer = $1;
647 $cgi->url() =~ m/^https?\:\/\/([^\/]+)/;
648 my $servername = $1;
649 return if ($referer ne $servername);
650
651 ### Modified for getting multi-vars, split by |
652 %temp = $cgi->Vars();
653 foreach my $key (keys %temp) {
654 $hash->{$key} = $temp{$key};
655 $hash->{$key} =~ s/\0/|/g;
656 $hash->{$key} =~ s/^\s*(.*?)\s*$/$1/;
657 }
658
659 if (($params->{'wantfile'})&&($params->{'filevar'})) {
660 $hash->{$params->{'filevar'}} = $cgi->upload
661 ($params->{'filevar'});
662 }
663 return;
664 }
665
666 sub log
667 {
668 my $logmessage = $_[0];
669 $logmessage =~ /([\w\W]*)/;
670 $logmessage = $1;
671 system('/usr/bin/logger', '-t', 'ipfire', $logmessage);
672 }
673
674 sub age
675 {
676 my ($dev, $ino, $mode, $nlink, $uid, $gid, $rdev, $size,
677 $atime, $mtime, $ctime, $blksize, $blocks) = stat $_[0];
678 my $now = time;
679
680 my $totalsecs = $now - $mtime;
681 my $days = int($totalsecs / 86400);
682 my $totalhours = int($totalsecs / 3600);
683 my $hours = $totalhours % 24;
684 my $totalmins = int($totalsecs / 60);
685 my $mins = $totalmins % 60;
686 my $secs = $totalsecs % 60;
687
688 return "${days}d ${hours}h ${mins}m ${secs}s";
689 }
690
691 sub validip
692 {
693 my $ip = $_[0];
694
695 if (!($ip =~ /^(\d+)\.(\d+)\.(\d+)\.(\d+)$/)) {
696 return 0; }
697 else
698 {
699 @octets = ($1, $2, $3, $4);
700 foreach $_ (@octets)
701 {
702 if (/^0./) {
703 return 0; }
704 if ($_ < 0 || $_ > 255) {
705 return 0; }
706 }
707 return 1;
708 }
709 }
710
711 sub validmask
712 {
713 my $mask = $_[0];
714
715 # secord part an ip?
716 if (&validip($mask)) {
717 return 1; }
718 # second part a number?
719 if (/^0/) {
720 return 0; }
721 if (!($mask =~ /^\d+$/)) {
722 return 0; }
723 if ($mask >= 0 && $mask <= 32) {
724 return 1; }
725 return 0;
726 }
727
728 sub validipormask
729 {
730 my $ipormask = $_[0];
731
732 # see if it is a IP only.
733 if (&validip($ipormask)) {
734 return 1; }
735 # split it into number and mask.
736 if (!($ipormask =~ /^(.*?)\/(.*?)$/)) {
737 return 0; }
738 $ip = $1;
739 $mask = $2;
740 # first part not a ip?
741 if (!(&validip($ip))) {
742 return 0; }
743 return &validmask($mask);
744 }
745
746 sub validipandmask
747 {
748 my $ipandmask = $_[0];
749
750 # split it into number and mask.
751 if (!($ipandmask =~ /^(.*?)\/(.*?)$/)) {
752 return 0; }
753 $ip = $1;
754 $mask = $2;
755 # first part not a ip?
756 if (!(&validip($ip))) {
757 return 0; }
758 return &validmask($mask);
759 }
760
761 sub validport
762 {
763 $_ = $_[0];
764
765 if (!/^\d+$/) {
766 return 0; }
767 if (/^0./) {
768 return 0; }
769 if ($_ >= 1 && $_ <= 65535) {
770 return 1; }
771 return 0;
772 }
773
774 sub validmac
775 {
776 my $checkmac = $_[0];
777 my $ot = '[0-9a-f]{2}'; # 2 Hex digits (one octet)
778 if ($checkmac !~ /^$ot:$ot:$ot:$ot:$ot:$ot$/i)
779 {
780 return 0;
781 }
782 return 1;
783 }
784
785 sub validhostname
786 {
787 # Checks a hostname against RFC1035
788 my $hostname = $_[0];
789
790 # Each part should be at least two characters in length
791 # but no more than 63 characters
792 if (length ($hostname) < 2 || length ($hostname) > 63) {
793 return 0;}
794 # Only valid characters are a-z, A-Z, 0-9 and -
795 if ($hostname !~ /^[a-zA-Z0-9-]*$/) {
796 return 0;}
797 # First character can only be a letter or a digit
798 if (substr ($hostname, 0, 1) !~ /^[a-zA-Z0-9]*$/) {
799 return 0;}
800 # Last character can only be a letter or a digit
801 if (substr ($hostname, -1, 1) !~ /^[a-zA-Z0-9]*$/) {
802 return 0;}
803 return 1;
804 }
805
806 sub validdomainname
807 {
808 # Checks a domain name against RFC1035
809 my $domainname = $_[0];
810 my @parts = split (/\./, $domainname); # Split hostname at the '.'
811
812 foreach $part (@parts) {
813 # Each part should be at least two characters in length
814 # but no more than 63 characters
815 if (length ($part) < 2 || length ($part) > 63) {
816 return 0;}
817 # Only valid characters are a-z, A-Z, 0-9 and -
818 if ($part !~ /^[a-zA-Z0-9-]*$/) {
819 return 0;}
820 # First character can only be a letter or a digit
821 if (substr ($part, 0, 1) !~ /^[a-zA-Z0-9]*$/) {
822 return 0;}
823 # Last character can only be a letter or a digit
824 if (substr ($part, -1, 1) !~ /^[a-zA-Z0-9]*$/) {
825 return 0;}
826 }
827 return 1;
828 }
829
830 sub validfqdn
831 {
832 # Checks a fully qualified domain name against RFC1035
833 my $fqdn = $_[0];
834 my @parts = split (/\./, $fqdn); # Split hostname at the '.'
835 if (scalar(@parts) < 2) { # At least two parts should
836 return 0;} # exist in a FQDN
837 # (i.e. hostname.domain)
838 foreach $part (@parts) {
839 # Each part should be at least two characters in length
840 # but no more than 63 characters
841 if (length ($part) < 2 || length ($part) > 63) {
842 return 0;}
843 # Only valid characters are a-z, A-Z, 0-9 and -
844 if ($part !~ /^[a-zA-Z0-9-]*$/) {
845 return 0;}
846 # First character can only be a letter or a digit
847 if (substr ($part, 0, 1) !~ /^[a-zA-Z0-9]*$/) {
848 return 0;}
849 # Last character can only be a letter or a digit
850 if (substr ($part, -1, 1) !~ /^[a-zA-Z0-9]*$/) {
851 return 0;}
852 }
853 return 1;
854 }
855
856 sub validportrange # used to check a port range
857 {
858 my $port = $_[0]; # port values
859 $port =~ tr/-/:/; # replace all - with colons just in case someone used -
860 my $srcdst = $_[1]; # is it a source or destination port
861
862 if (!($port =~ /^(\d+)\:(\d+)$/)) {
863
864 if (!(&validport($port))) {
865 if ($srcdst eq 'src'){
866 return $tr{'source port numbers'};
867 } else {
868 return $tr{'destination port numbers'};
869 }
870 }
871 }
872 else
873 {
874 @ports = ($1, $2);
875 if ($1 >= $2){
876 if ($srcdst eq 'src'){
877 return $tr{'bad source range'};
878 } else {
879 return $tr{'bad destination range'};
880 }
881 }
882 foreach $_ (@ports)
883 {
884 if (!(&validport($_))) {
885 if ($srcdst eq 'src'){
886 return $tr{'source port numbers'};
887 } else {
888 return $tr{'destination port numbers'};
889 }
890 }
891 }
892 return;
893 }
894 }
895
896 # Test if IP is within a subnet
897 # Call: IpInSubnet (Addr, Subnet, Subnet Mask)
898 # Subnet can be an IP of the subnet: 10.0.0.0 or 10.0.0.1
899 # Everything in dottted notation
900 # Return: TRUE/FALSE
901 sub IpInSubnet
902 {
903 $ip = unpack('N', inet_aton(shift));
904 $start = unpack('N', inet_aton(shift));
905 $mask = unpack('N', inet_aton(shift));
906 $start &= $mask; # base of subnet...
907 $end = $start + ~$mask;
908 return (($ip >= $start) && ($ip <= $end));
909 }
910
911 sub validemail {
912 my $mail = shift;
913 return 0 if ( $mail !~ /^[0-9a-zA-Z\.\-\_]+\@[0-9a-zA-Z\.\-]+$/ );
914 return 0 if ( $mail =~ /^[^0-9a-zA-Z]|[^0-9a-zA-Z]$/);
915 return 0 if ( $mail !~ /([0-9a-zA-Z]{1})\@./ );
916 return 0 if ( $mail !~ /.\@([0-9a-zA-Z]{1})/ );
917 return 0 if ( $mail =~ /.\.\-.|.\-\..|.\.\..|.\-\-./g );
918 return 0 if ( $mail =~ /.\.\_.|.\-\_.|.\_\..|.\_\-.|.\_\_./g );
919 return 0 if ( $mail !~ /\.([a-zA-Z]{2,3})$/ );
920 return 1;
921 }
922
923 sub readhasharray {
924 my ($filename, $hash) = @_;
925
926 open(FILE, $filename) or die "Unable to read file $filename";
927
928 while (<FILE>) {
929 my ($key, $rest, @temp);
930 chomp;
931 ($key, $rest) = split (/,/, $_, 2);
932 if ($key =~ /^[0-9]+$/ && $rest) {
933 @temp = split (/,/, $rest);
934 $hash->{$key} = \@temp;
935 }
936 }
937 close FILE;
938 return;
939 }
940
941 sub writehasharray {
942 my ($filename, $hash) = @_;
943 my ($key, @temp);
944
945 open(FILE, ">$filename") or die "Unable to write to file $filename";
946
947 foreach $key (keys %$hash) {
948 if ( $hash->{$key} ) {
949 print FILE "$key";
950 foreach $i (0 .. $#{$hash->{$key}}) {
951 print FILE ",$hash->{$key}[$i]";
952 }
953 }
954 print FILE "\n";
955 }
956 close FILE;
957 return;
958 }
959
960 sub findhasharraykey {
961 foreach my $i (1 .. 1000000) {
962 if ( ! exists $_[0]{$i}) {
963 return $i;
964 }
965 }
966 }
967
968 sub cleanhtml
969 {
970 my $outstring =$_[0];
971 $outstring =~ tr/,/ / if not defined $_[1] or $_[1] ne 'y';
972 $outstring =~ s/&/&amp;/g;
973 $outstring =~ s/\'/&#039;/g;
974 $outstring =~ s/\"/&quot;/g;
975 $outstring =~ s/</&lt;/g;
976 $outstring =~ s/>/&gt;/g;
977 return $outstring;
978 }
979
980 sub connectionstatus
981 {
982 my %pppsettings = ();
983 my %netsettings = ();
984 my $iface='';
985
986 $pppsettings{'PROFILENAME'} = 'None';
987 &General::readhash("${General::swroot}/ppp/settings", \%pppsettings);
988 &General::readhash("${General::swroot}/ethernet/settings", \%netsettings);
989
990 my $profileused='';
991 if ( ! ( $netsettings{'CONFIG_TYPE'} =~ /^(2|3|6|7)$/ && $netsettings{'RED_TYPE'} =~ /^(DHCP|STATIC)$/ ) ) {
992 $profileused="- $pppsettings{'PROFILENAME'}";
993 }
994
995 if ( ( $pppsettings{'METHOD'} eq 'DHCP' && $netsettings{'RED_TYPE'} ne 'PPTP')
996 || $netsettings{'RED_TYPE'} eq 'DHCP' ) {
997 if (open(IFACE, "${General::swroot}/red/iface")) {
998 $iface = <IFACE>;
999 close IFACE;
1000 chomp ($iface);
1001 $iface =~ /([a-zA-Z0-9]*)/; $iface = $1;
1002 }
1003 }
1004
1005 my ($timestr, $connstate);
1006 if ($netsettings{'CONFIG_TYPE'} =~ /^(0|1|4|5)$/ && $pppsettings{'TYPE'} =~ /^isdn/) {
1007 # Count ISDN channels
1008 my ($idmap, $chmap, $drmap, $usage, $flags, $phone);
1009 my @phonenumbers;
1010 my $count=0;
1011
1012 open (FILE, "/dev/isdninfo");
1013
1014 $idmap = <FILE>; chop $idmap;
1015 $chmap = <FILE>; chop $chmap;
1016 $drmap = <FILE>; chop $drmap;
1017 $usage = <FILE>; chop $usage;
1018 $flags = <FILE>; chop $flags;
1019 $phone = <FILE>; chop $phone;
1020
1021 $phone =~ s/^phone(\s*):(\s*)//;
1022
1023 @phonenumbers = split / /, $phone;
1024
1025 foreach (@phonenumbers) {
1026 if ($_ ne '???') {
1027 $count++;
1028 }
1029 }
1030 close (FILE);
1031
1032 ## Connection status
1033 my $number;
1034 if ($count == 0) {
1035 $number = 'none!';
1036 } elsif ($count == 1) {
1037 $number = 'single';
1038 } else {
1039 $number = 'dual';
1040 }
1041
1042 if (-e "${General::swroot}/red/active") {
1043 $timestr = &General::age("${General::swroot}/red/active");
1044 $connstate = "<span class='ipcop_StatusBig'>$Lang::tr{'connected'} - $number channel (<span class='ipcop_StatusBigRed'>$timestr</span>) $profileused</span>";
1045 } else {
1046 if ($count == 0) {
1047 if (-e "${General::swroot}/red/dial-on-demand") {
1048 $connstate = "<span class='ipcop_StatusBig'>$Lang::tr{'dod waiting'} $profileused</span>";
1049 } else {
1050 $connstate = "<span class='ipcop_StatusBig'>$Lang::tr{'idle'} $profileused</span>";
1051 }
1052 } else {
1053 $connstate = "<span class='ipcop_StatusBig'>$Lang::tr{'connecting'} $profileused</span>";
1054 }
1055 }
1056 } elsif ($netsettings{'RED_TYPE'} eq "STATIC" || $pppsettings {'METHOD'} eq 'STATIC') {
1057 if (-e "${General::swroot}/red/active") {
1058 $timestr = &General::age("${General::swroot}/red/active");
1059 $connstate = "<span class='ipcop_StatusBig'>$Lang::tr{'connected'} (<span class='ipcop_StatusBigRed'>$timestr</span>) $profileused</span>";
1060 } else {
1061 $connstate = "<span class='ipcop_StatusBig'>$Lang::tr{'idle'} $profileused</span>";
1062 }
1063 } elsif ( ( (-e "${General::swroot}/dhcpc/dhcpcd-$iface.pid") && $netsettings{'RED_TYPE'} ne 'PPTP' ) ||
1064 !system("/bin/ps -ef | /bin/grep -q '[p]ppd'") || !system("/bin/ps -ef | /bin/grep -q '[c]onnectioncheck'")) {
1065 if (-e "${General::swroot}/red/active") {
1066 $timestr = &General::age("${General::swroot}/red/active");
1067 if ($pppsettings{'TYPE'} =~ /^(modem|bewanadsl|conexantpciadsl|eagleusbadsl)$/) {
1068 my $speed;
1069 if ($pppsettings{'TYPE'} eq 'modem') {
1070 open(CONNECTLOG, "/var/log/connect.log");
1071 while (<CONNECTLOG>) {
1072 if (/CONNECT/) {
1073 $speed = (split / /)[6];
1074 }
1075 }
1076 close (CONNECTLOG);
1077 } elsif ($pppsettings{'TYPE'} eq 'bewanadsl') {
1078 $speed = `/usr/bin/unicorn_status | /bin/grep Rate | /usr/bin/cut -f2 -d ':'`;
1079 } elsif ($pppsettings{'TYPE'} eq 'conexantpciadsl') {
1080 $speed = `/bin/cat /proc/net/atm/CnxAdsl:* | /bin/grep 'Line Rates' | /bin/sed -e 's+Line Rates: Receive+Rx+' -e 's+Transmit+Tx+'`;
1081 } elsif ($pppsettings{'TYPE'} eq 'eagleusbadsl') {
1082 $speed = `/usr/sbin/eaglestat | /bin/grep Rate`;
1083 }
1084 $connstate = "$Lang::tr{'connected'} ($timestr) $profileused (\@$speed)";
1085 } else {
1086 $connstate = "$Lang::tr{'connected'} ($timestr) $profileused";
1087 }
1088 } else {
1089 if (-e "${General::swroot}/red/dial-on-demand") {
1090 $connstate = "$Lang::tr{'dod waiting'} $profileused";
1091 } else {
1092 $connstate = "$Lang::tr{'connecting'} $profileused";
1093 }
1094 }
1095 } else {
1096 $connstate = "$Lang::tr{'idle'} $profileused";
1097 }
1098 return $connstate;
1099 }
1100
1101 sub srtarray
1102 # Darren Critchley - darrenc@telus.net - (c) 2003
1103 # &srtarray(SortOrder, AlphaNumeric, SortDirection, ArrayToBeSorted)
1104 # This subroutine will take the following parameters:
1105 # ColumnNumber = the column which you want to sort on, starts at 1
1106 # AlphaNumberic = a or n (lowercase) defines whether the sort should be alpha or numberic
1107 # SortDirection = asc or dsc (lowercase) Ascending or Descending sort
1108 # ArrayToBeSorted = the array that wants sorting
1109 #
1110 # Returns an array that is sorted to your specs
1111 #
1112 # If SortOrder is greater than the elements in array, then it defaults to the first element
1113 #
1114 {
1115 my ($colno, $alpnum, $srtdir, @tobesorted) = @_;
1116 my @tmparray;
1117 my @srtedarray;
1118 my $line;
1119 my $newline;
1120 my $ttlitems = scalar @tobesorted; # want to know the number of rows in the passed array
1121 if ($ttlitems < 1){ # if no items, don't waste our time lets leave
1122 return (@tobesorted);
1123 }
1124 my @tmp = split(/\,/,$tobesorted[0]);
1125 $ttlitems = scalar @tmp; # this should be the number of elements in each row of the passed in array
1126
1127 # Darren Critchley - validate parameters
1128 if ($colno > $ttlitems){$colno = '1';}
1129 $colno--; # remove one from colno to deal with arrays starting at 0
1130 if($colno < 0){$colno = '0';}
1131 if ($alpnum ne '') { $alpnum = lc($alpnum); } else { $alpnum = 'a'; }
1132 if ($srtdir ne '') { $srtdir = lc($srtdir); } else { $srtdir = 'src'; }
1133
1134 foreach $line (@tobesorted)
1135 {
1136 chomp($line);
1137 if ($line ne '') {
1138 my @temp = split(/\,/,$line);
1139 # Darren Critchley - juggle the fields so that the one we want to sort on is first
1140 my $tmpholder = $temp[0];
1141 $temp[0] = $temp[$colno];
1142 $temp[$colno] = $tmpholder;
1143 $newline = "";
1144 for ($ctr=0; $ctr < $ttlitems ; $ctr++) {
1145 $newline=$newline . $temp[$ctr] . ",";
1146 }
1147 chop($newline);
1148 push(@tmparray,$newline);
1149 }
1150 }
1151 if ($alpnum eq 'n') {
1152 @tmparray = sort {$a <=> $b} @tmparray;
1153 } else {
1154 @tmparray = (sort @tmparray);
1155 }
1156 foreach $line (@tmparray)
1157 {
1158 chomp($line);
1159 if ($line ne '') {
1160 my @temp = split(/\,/,$line);
1161 my $tmpholder = $temp[0];
1162 $temp[0] = $temp[$colno];
1163 $temp[$colno] = $tmpholder;
1164 $newline = "";
1165 for ($ctr=0; $ctr < $ttlitems ; $ctr++){
1166 $newline=$newline . $temp[$ctr] . ",";
1167 }
1168 chop($newline);
1169 push(@srtedarray,$newline);
1170 }
1171 }
1172
1173 if ($srtdir eq 'dsc') {
1174 @tmparray = reverse(@srtedarray);
1175 return (@tmparray);
1176 } else {
1177 return (@srtedarray);
1178 }
1179 }
1180
1181 sub speedtouchversion
1182 {
1183 if (-f "/proc/bus/usb/devices")
1184 {
1185 $speedtouch=`/bin/cat /proc/bus/usb/devices | /bin/grep 'Vendor=06b9 ProdID=4061' | /usr/bin/cut -d ' ' -f6`;
1186 if ($speedtouch eq '') {
1187 $speedtouch= $tr{'connect the modem'};
1188 }
1189 } else {
1190 $speedtouch='USB '.$tr{'not running'};
1191 }
1192 return $speedtouch
1193 }
1194
1195 sub CheckSortOrder {
1196 #Sorting of allocated leases
1197 if ($ENV{'QUERY_STRING'} =~ /^IPADDR|^ETHER|^HOSTNAME|^ENDTIME/ ) {
1198 my $newsort=$ENV{'QUERY_STRING'};
1199 &readhash("${swroot}/dhcp/settings", \%dhcpsettings);
1200 $act=$dhcpsettings{'SORT_LEASELIST'};
1201 #Reverse actual ?
1202 if ($act =~ $newsort) {
1203 if ($act !~ 'Rev') {$Rev='Rev'};
1204 $newsort.=$Rev
1205 };
1206
1207 $dhcpsettings{'SORT_LEASELIST'}=$newsort;
1208 &writehash("${swroot}/dhcp/settings", \%dhcpsettings);
1209 $dhcpsettings{'ACTION'} = 'SORT'; # avoid the next test "First lauch"
1210 }
1211
1212 }
1213
1214 sub PrintActualLeases
1215 {
1216 &openbox('100%', 'left', $tr{'current dynamic leases'});
1217 print <<END
1218 <table width='100%'>
1219 <tr>
1220 <td width='25%' align='center'><a href='$ENV{'SCRIPT_NAME'}?IPADDR'><b>$tr{'ip address'}</b></a></td>
1221 <td width='25%' align='center'><a href='$ENV{'SCRIPT_NAME'}?ETHER'><b>$tr{'mac address'}</b></a></td>
1222 <td width='20%' align='center'><a href='$ENV{'SCRIPT_NAME'}?HOSTNAME'><b>$tr{'hostname'}</b></a></td>
1223 <td width='25%' align='center'><a href='$ENV{'SCRIPT_NAME'}?ENDTIME'><b>$tr{'lease expires'} (local time d/m/y)</b></a></td>
1224 <td width='5%' align='center'><b>Add to fix leases<b></td>
1225 </tr>
1226 END
1227 ;
1228
1229 open(LEASES,"/var/state/dhcp/dhcpd.leases") or die "Can't open dhcpd.leases";
1230 while ($line = <LEASES>) {
1231 next if( $line =~ /^\s*#/ );
1232 chomp($line);
1233 @temp = split (' ', $line);
1234
1235 if ($line =~ /^\s*lease/) {
1236 $ip = $temp[1];
1237 #All field are not necessarily read. Clear everything
1238 $endtime = 0;
1239 $ether = "";
1240 $hostname = "";
1241 }
1242
1243 if ($line =~ /^\s*ends/) {
1244 $line =~ /(\d+)\/(\d+)\/(\d+) (\d+):(\d+):(\d+)/;
1245 $endtime = timegm($6, $5, $4, $3, $2 - 1, $1 - 1900);
1246 }
1247
1248 if ($line =~ /^\s*hardware ethernet/) {
1249 $ether = $temp[2];
1250 $ether =~ s/;//g;
1251 }
1252
1253 if ($line =~ /^\s*client-hostname/) {
1254 $hostname = "$temp[1] $temp[2] $temp[3]";
1255 $hostname =~ s/;//g;
1256 $hostname =~ s/\"//g;
1257 }
1258
1259 if ($line eq "}") {
1260 @record = ('IPADDR',$ip,'ENDTIME',$endtime,'ETHER',$ether,'HOSTNAME',$hostname);
1261 $record = {}; # create a reference to empty hash
1262 %{$record} = @record; # populate that hash with @record
1263 $entries{$record->{'IPADDR'}} = $record; # add this to a hash of hashes
1264 }
1265 }
1266 close(LEASES);
1267
1268 my $id = 0;
1269 foreach my $key (sort leasesort keys %entries) {
1270 print "<form method='post' action='/cgi-bin/dhcp.cgi'>\n";
1271 my $hostname = &cleanhtml($entries{$key}->{HOSTNAME},"y");
1272
1273 if ($id % 2) {
1274 print "<tr bgcolor='$table1colour'>";
1275 }
1276 else {
1277 print "<tr bgcolor='$table2colour'>";
1278 }
1279
1280 print <<END
1281 <td align='center'><input type='hidden' name='FIX_ADDR' value='$entries{$key}->{IPADDR}' />$entries{$key}->{IPADDR}</td>
1282 <td align='center'><input type='hidden' name='FIX_MAC' value='$entries{$key}->{ETHER}' />$entries{$key}->{ETHER}</td>
1283 <td align='center'><input type='hidden' name='FIX_REMARK' value='$hostname' />&nbsp;$hostname</td>
1284 <td align='center'><input type='hidden' name='FIX_ENABLED' value='on' />
1285 END
1286 ;
1287
1288 ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $dst) = localtime ($entries{$key}->{ENDTIME});
1289 $enddate = sprintf ("%02d/%02d/%d %02d:%02d:%02d",$mday,$mon+1,$year+1900,$hour,$min,$sec);
1290
1291 if ($entries{$key}->{ENDTIME} < time() ){
1292 print "<strike>$enddate</strike>";
1293 } else {
1294 print "$enddate";
1295 }
1296 print <<END
1297 <td><input type='hidden' name='ACTION' value='$Lang::tr{'add'}2' /><input type='submit' name='SUBMIT' value='$Lang::tr{'add'}' />
1298 </td></td></tr></form>
1299 END
1300 ;
1301 $id++;
1302 }
1303
1304 print "</table>";
1305 &closebox();
1306 }
1307
1308
1309 # This sub is used during display of actives leases
1310 sub leasesort {
1311 if (rindex ($dhcpsettings{'SORT_LEASELIST'},'Rev') != -1)
1312 {
1313 $qs=substr ($dhcpsettings{'SORT_LEASELIST'},0,length($dhcpsettings{'SORT_LEASELIST'})-3);
1314 if ($qs eq 'IPADDR') {
1315 @a = split(/\./,$entries{$a}->{$qs});
1316 @b = split(/\./,$entries{$b}->{$qs});
1317 ($b[0]<=>$a[0]) ||
1318 ($b[1]<=>$a[1]) ||
1319 ($b[2]<=>$a[2]) ||
1320 ($b[3]<=>$a[3]);
1321 }else {
1322 $entries{$b}->{$qs} cmp $entries{$a}->{$qs};
1323 }
1324 }
1325 else #not reverse
1326 {
1327 $qs=$dhcpsettings{'SORT_LEASELIST'};
1328 if ($qs eq 'IPADDR') {
1329 @a = split(/\./,$entries{$a}->{$qs});
1330 @b = split(/\./,$entries{$b}->{$qs});
1331 ($a[0]<=>$b[0]) ||
1332 ($a[1]<=>$b[1]) ||
1333 ($a[2]<=>$b[2]) ||
1334 ($a[3]<=>$b[3]);
1335 }else {
1336 $entries{$a}->{$qs} cmp $entries{$b}->{$qs};
1337 }
1338 }
1339 }
1340
1341 sub get_uplinks() {
1342 my @uplinks = ();
1343 opendir(DIR, "${swroot}/uplinks/") || return \@uplinks;
1344 foreach my $dir (readdir(DIR)) {
1345 next if ($dir =~ /^\./);
1346 next if (-f "${swroot}/uplinks/$dir");
1347 push(@uplinks, $dir);
1348 }
1349 closedir(DIR);
1350 return \@uplinks;
1351 }
1352
1353 sub get_iface($) {
1354 my $filename = shift;
1355 chomp($filename);
1356 open (F, $filename) || return "";
1357 my $iface = <F>;
1358 close(F);
1359 chomp($iface);
1360 return $iface;
1361 }
1362
1363 sub get_red_ifaces_by_type($) {
1364 my $type=shift;
1365 my @gottypeiface = ();
1366 my @gottypeuplink = ();
1367 my @gottype = ();
1368
1369 my $ref=get_uplinks();
1370 my @uplinks=@$ref;
1371 my %set = ();
1372 foreach my $link (@uplinks) {
1373 eval {
1374 &readhash("${swroot}/uplinks/$link/settings", \%set);
1375 };
1376 push(@gottype, $link);
1377
1378 my $iface = $set{'RED_DEV'};
1379 if (!$iface) {
1380 $iface = get_iface("${swroot}/uplinks/$link/interface");
1381 }
1382 next if (!$iface);
1383
1384 if ($set{'RED_TYPE'} eq $type) {
1385 push(@gottypeiface, $iface);
1386 push(@gottypeuplink, $link);
1387 }
1388 }
1389 return (\@gottypeiface, \@gottypeuplink, \@gottype);
1390 }
1391
1392 sub get_red_ifaces() {
1393 return `cat ${swroot}/uplinks/*/interface 2>/dev/null`;
1394 }
1395
1396 sub get_zone_devices($) {
1397 my $bridge = shift;
1398 my @ifaces = ();
1399 open (FILE, "${swroot}/ethernet/$bridge") || return "";
1400 foreach my $line (<FILE>) {
1401 chomp($line);
1402 next if (!$line);
1403 push(@ifaces, $line);
1404 }
1405 close(FILE);
1406 return \@ifaces;
1407 }