]> git.ipfire.org Git - people/teissler/ipfire-2.x.git/blob - config/cfgroot/header.pl
HinzugefĆ¼gt:
[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::colourfw = '#000000';
36 $Header::colourvpn = '#990099';
37 $Header::colourerr = '#FF0000';
38 $Header::viewsize = 150;
39 $Header::errormessage = '';
40 my %menuhash = ();
41 my $menu = \%menuhash;
42 %settings = ();
43 %ethsettings = ();
44 @URI = ();
45 $Header::supported=0;
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'}:10443/$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
90 require "${swroot}/langs/en.pl";
91 require "${swroot}/langs/${language}.pl";
92
93 sub orange_used () {
94 if ($ethsettings{'CONFIG_TYPE'} =~ /^[1357]$/) {
95 return 1;
96 }
97 return 0;
98 }
99
100 sub blue_used () {
101 if ($ethsettings{'CONFIG_TYPE'} =~ /^[4567]$/) {
102 return 1;
103 }
104 return 0;
105 }
106
107 sub is_modem {
108 if ($ethsettings{'CONFIG_TYPE'} =~ /^[0145]$/) {
109 return 1;
110 }
111 return 0;
112 }
113
114 ### Initialize menu
115 sub genmenu {
116 my %subsystemhash = ();
117 my $subsystem = \%subsystemhash;
118
119 $subsystem->{'01.home'} = {
120 'caption' => $tr{'alt home'},
121 'uri' => '/cgi-bin/index.cgi',
122 'title' => "$tr{'alt home'}",
123 'enabled' => 1,
124 };
125 $subsystem->{'02.netwizard'} = {
126 'caption' => $tr{'network configuration'},
127 'uri' => '/cgi-bin/netwizard.cgi',
128 'title' => "$tr{'network configuration'}",
129 'enabled' => 1,
130 };
131 $subsystem->{'03.passwords'} = {
132 'caption' => $tr{'sspasswords'},
133 'uri' => '/cgi-bin/changepw.cgi',
134 'title' => "$tr{'sspasswords'}",
135 'enabled' => 1,
136 };
137 $subsystem->{'04.ssh'} = {
138 'caption' => $tr{'ssh access'},
139 'uri' => '/cgi-bin/remote.cgi',
140 'title' => "$tr{'ssh access'}",
141 'enabled' => 1,
142 };
143 $subsystem->{'05.gui'} = {
144 'caption' => $tr{'gui settings'},
145 'uri' => '/cgi-bin/gui.cgi',
146 'title' => "$tr{'gui settings'}",
147 'enabled' => 1,
148 };
149 $subsystem->{'06.backup'} = {
150 'caption' => $tr{'backup'},
151 'uri' => '/cgi-bin/backup.cgi',
152 'title' => "$tr{'backup'} / $tr{'restore'}",
153 'enabled' => 0,
154 };
155 $subsystem->{'07.shutdown'} = {
156 'caption' => $tr{'shutdown'},
157 'uri' => '/cgi-bin/shutdown.cgi',
158 'title' => "$tr{'shutdown'} / $tr{'reboot'}",
159 'enabled' => 1,
160 };
161 $subsystem->{'08.credits'} = {
162 'caption' => $tr{'credits'},
163 'uri' => '/cgi-bin/credits.cgi',
164 'title' => "$tr{'credits'}",
165 'enabled' => 1,
166 };
167
168 my %substatushash = ();
169 my $substatus = \%substatushash;
170 $substatus->{'01.systemstatus'} = {
171 'caption' => $tr{'sssystem status'},
172 'uri' => '/cgi-bin/status.cgi',
173 'title' => "$tr{'system status information'}",
174 'enabled' => 1,
175 };
176 $substatus->{'02.networkstatus'} = {
177 'caption' => $tr{'ssnetwork status'},
178 'uri' => '/cgi-bin/netstatus.cgi',
179 'title' => "$tr{'network status information'}",
180 'enabled' => 1,
181 };
182 $substatus->{'03.systemgraphs'} = {
183 'caption' => $tr{'system graphs'},
184 'uri' => '/cgi-bin/graphs.cgi',
185 'novars' => 1,
186 'title' => "$tr{'system graphs'}",
187 'enabled' => 1,
188 };
189 $substatus->{'04.trafficgraphs'} = {
190 'caption' => $tr{'sstraffic graphs'},
191 'uri' => '/cgi-bin/graphs.cgi',
192 'vars' => 'graph=network',
193 'title' => "$tr{'network traffic graphs'}",
194 'enabled' => 1,
195 };
196 $substatus->{'05.proxygraphs'} = {
197 'caption' => $tr{'ssproxy graphs'},
198 'uri' => '/cgi-bin/proxygraphs.cgi',
199 'title' => "$tr{'proxy access graphs'}",
200 'enabled' => 1,
201 };
202 $substatus->{'06.connections'} = {
203 'caption' => $tr{'connections'},
204 'uri' => '/cgi-bin/connections.cgi',
205 'title' => "$tr{'connections'}",
206 'enabled' => 1,
207 };
208 $substatus->{'99.iptfilters'} = {
209 'caption' => $tr{'iptfilters iptable rules'},
210 'uri' => '/cgi-bin/iptfilters.cgi',
211 'title' => "$tr{'iptfilters iptable rules'}",
212 'enabled' => 1,
213 };
214
215 my %subnetworkhash = ();
216 my $subnetwork = \%subnetworkhash;
217
218 $subnetwork->{'01.dialup'} = {
219 'caption' => $tr{'alt dialup'},
220 'uri' => '/cgi-bin/pppsetup.cgi',
221 'title' => "$tr{'dialup settings'}",
222 'enabled' => 0,
223 };
224 $subnetwork->{'02.hosts'} = {
225 'caption' => $tr{'edit hosts'},
226 'uri' => '/cgi-bin/hosts.cgi',
227 'title' => "$tr{'host configuration'}",
228 'enabled' => 1,
229 };
230 $subnetwork->{'03.upload'} = {
231 'caption' => $tr{'upload'},
232 'uri' => '/cgi-bin/upload.cgi',
233 'title' => "$tr{'firmware upload'}",
234 'enabled' => 0,
235 };
236 $subnetwork->{'04.aliases'} = {
237 'caption' => $tr{'aliases'},
238 'uri' => '/cgi-bin/aliases.cgi',
239 'title' => "$tr{'external aliases configuration'}",
240 'enabled' => 1,
241 };
242 $subnetwork->{'05.nettraf'} = {
243 'caption' => '$tr{'sstraffic'}',
244 'uri' => '/cgi-bin/traffic.cgi',
245 'title' => "$tr{'sstraffic'}",
246 'enabled' => 1,
247 };
248 $subnetwork->{'06.fwhits'} = {
249 'caption' => 'Firewallhits',
250 'uri' => '/cgi-bin/fwhits.cgi',
251 'title' => "IPFire Firewallhits",
252 'enabled' => 1,
253 };
254 $subnetwork->{'07.openvpn'} = {
255 'caption' => 'OpenVPN',
256 'uri' => '/cgi-bin/ovpnmain.cgi',
257 'title' => "$tr{'virtual private networking'}",
258 'enabled' => 1,
259 };
260 $subnetwork->{'08.ipsec'} = {
261 'caption' => 'IPSec,
262 'uri' => '/cgi-bin/vpnmain.cgi',
263 'title' => "$tr{'virtual private networking'}",
264 'enabled' => 1,
265 };
266
267
268 my %subserviceshash = ();
269 my $subservices = \%subserviceshash;
270
271 $subservices->{'01.proxy'} = {
272 'caption' => $tr{'proxy'},
273 'uri' => '/cgi-bin/proxy.cgi',
274 'title' => "HTTP: $tr{'web proxy configuration'}",
275 'enabled' => 1,
276 };
277 $subservices->{'02.dhcp'} = {
278 'caption' => $tr{'dhcp server'},
279 'uri' => '/cgi-bin/dhcp.cgi',
280 'title' => "$tr{'dhcp configuration'}",
281 'enabled' => 1,
282 };
283 $subservices->{'03.dyndns'} = {
284 'caption' => $tr{'dynamic dns'},
285 'uri' => '/cgi-bin/ddns.cgi',
286 'title' => "$tr{'dynamic dns client'}",
287 'enabled' => 1,
288 };
289 $subservices->{'04.time'} = {
290 'caption' => $tr{'time server'},
291 'uri' => '/cgi-bin/time.cgi',
292 'title' => "$tr{'time server'}",
293 'enabled' => 1,
294 };
295 $subservices->{'05.qos'} = {
296 'caption' => 'Quality of Service',
297 'uri' => '/cgi-bin/qos.cgi',
298 'title' => "$tr{'traffic shaping settings'}",
299 'enabled' => 1,
300 };
301 $subservices->{'06.ids'} = {'caption' => $tr{'intrusion detection'},
302 'enabled' => 1,
303 'uri' => '/cgi-bin/ids.cgi',
304 'title' => "$tr{'intrusion detection system'} (Snort)",
305 };
306
307
308 my %subfirewallhash = ();
309 my $subfirewall = \%subfirewallhash;
310
311
312 $subfirewall->{'01.dnat'} = {
313 'caption' => $tr{'ssport forwarding'},
314 'uri' => '/cgi-bin/portfw.cgi',
315 'title' => "$tr{'port forwarding configuration'}",
316 'enabled' => 1,
317 };
318 $subfirewall->{'02.xtaccess'} = {
319 'caption' => $tr{'external access'},
320 'uri' => '/cgi-bin/xtaccess.cgi',
321 'title' => "$tr{'external access configuration'}",
322 'enabled' => 1,
323 };
324 $subfirewall->{'03.dmz'} = {
325 'caption' => $tr{'ssdmz pinholes'},
326 'uri' => '/cgi-bin/dmzholes.cgi',
327 'title' => "$tr{'dmz pinhole configuration'}",
328 'enabled' => 1,
329 };
330 $subfirewall->{'04.outgoing'} = {
331 'caption' => $tr{'outgoing firewall'},
332 'uri' => '/cgi-bin/outgoingfw.cgi',
333 'title' => "$tr{'outgoing firewall'}",
334 'enabled' => 1,
335 };
336
337
338 my %sublogshash = ();
339 my $sublogs = \%sublogshash;
340
341 $sublogs->{'01.summary'} = {'caption' => $tr{'log summary'},
342 'uri' => '/cgi-bin/logs.cgi/summary.dat',
343 'title' => "$tr{'log summary'}",
344 'enabled' => 1
345 };
346 $sublogs->{'02.settings'} = {'caption' => $tr{'log settings'},
347 'uri' => '/cgi-bin/logs.cgi/config.dat',
348 'title' => "$tr{'log settings'}",
349 'enabled' => 1
350 };
351 $sublogs->{'03.proxy'} = {'caption' => $tr{'proxy logs'},
352 'uri' => '/cgi-bin/logs.cgi/proxylog.dat',
353 'title' => "$tr{'proxy log viewer'}",
354 'enabled' => 1
355 };
356 $sublogs->{'04.firewall'} = {'caption' => $tr{'firewall logs'},
357 'uri' => '/cgi-bin/logs.cgi/firewalllog.dat',
358 'title' => "$tr{'firewall log viewer'}",
359 'enabled' => 1
360 };
361 $sublogs->{'05.ids'} = {'caption' => $tr{'ids logs'},
362 'uri' => '/cgi-bin/logs.cgi/ids.dat',
363 'title' => "$tr{'intrusion detection system log viewer'}",
364 'enabled' => 1
365 };
366 $sublogs->{'06.contentfilter'} = {'caption' => $tr{'content filter logs'},
367 'uri' => '/cgi-bin/logs.cgi/dansguardian.dat',
368 'title' => "$tr{'content filter log viewer'}",
369 'enabled' => 1
370 };
371 $sublogs->{'07.urlfilter'} = {
372 'caption' => $tr{'urlfilter log'},
373 'uri' => '/cgi-bin/logs.cgi/urlfilter.dat',
374 'title' => "$tr{'urlfilter log'}",
375 'enabled' => 1,
376 };
377 $sublogs->{'08.openvpn'} = {'caption' => $tr{'openvpn log'},
378 'uri' => '/cgi-bin/logs.cgi/openvpn.dat',
379 'title' => "$tr{'openvpn log'}",
380 'enabled' => 1
381 };
382 $sublogs->{'09.system'} = {'caption' => $tr{'system logs'},
383 'uri' => '/cgi-bin/logs.cgi/log.dat',
384 'title' => "$tr{'system log viewer'}",
385 'enabled' => 1
386 };
387 $sublogs->{'10.userlog'} = {'caption' => $tr{'user proxy logs'},
388 'uri' => '/cgi-bin/logs.cgi/userlog.dat',
389 'title' => "$tr{'user log viewer'}",
390 'enabled' => 1
391 };
392
393 my %subipfirehash = ();
394 my $subipfire = \%subipfirehash;
395 $subipfire->{'01.pakfire'} = {'caption' => $tr{'pakfire'},
396 'uri' => '/cgi-bin/pakfire.cgi',
397 'title' => "$tr{'paketmanager'}",
398 'enabled' => 1,
399 };
400 $subipfire->{'02.asterisk'} = {'caption' => $tr{'asterisk'},
401 'uri' => '/cgi-bin/asterisk.cgi',
402 'title' => "$tr{'asterisk'}",
403 'enabled' => 1,
404 };
405 $subipfire->{'02.samba'} = {'caption' => $tr{'samba'},
406 'uri' => '/cgi-bin/samba.cgi',
407 'title' => "$tr{'samba'}",
408 'enabled' => 1,
409 };
410 $subipfire->{'99.help'} = {'caption' => $tr{'help'},
411 'uri' => '/cgi-bin/help.cgi',
412 'title' => "$tr{'help'}",
413 'enabled' => 1,
414 };
415
416
417
418 $menu->{'01.system'} = {'caption' => $tr{'alt system'},
419 'enabled' => 1,
420 'subMenu' => $subsystem
421 };
422 $menu->{'02.status'} = {'caption' => $tr{'status'},
423 'enabled' => 1,
424 'subMenu' => $substatus
425 };
426 $menu->{'03.network'} = {'caption' => $tr{'network'},
427 'enabled' => 1,
428 'subMenu' => $subnetwork
429 };
430 $menu->{'04.services'} = {'caption' => $tr{'alt services'},
431 'enabled' => 1,
432 'subMenu' => $subservices
433 };
434 $menu->{'05.firewall'} = {'caption' => $tr{'firewall'},
435 'enabled' => 1,
436 'subMenu' => $subfirewall
437 };
438 $menu->{'06.proxy'} = {'caption' => $tr{'alt proxy'},
439 'enabled' => 1,
440 'subMenu' => $subproxy
441 };
442 $menu->{'07.ipfire'} = {'caption' => 'IPFire',
443 'enabled' => 1,
444 'subMenu' => $subvpn
445 };
446 $menu->{'08.logs'} = {'caption' => $tr{'alt logs'},
447 'enabled' => 1,
448 'subMenu' => $sublogs
449 };
450
451 if (! blue_used() && ! orange_used()) {
452 $menu->{'05.firewall'}{'subMenu'}->{'03.dmz'}{'enabled'} = 0;
453 }
454 if (-e '/etc/FLASH') {
455 $menu{'06.proxy'}{'subMenu'}->{'01.http'}{'subMenu'}->{'01.proxy'}{'enabled'} = 0; #disable squid
456 $menu{'04.services'}{'subMenu'}->{'05.ids'}{'enabled'} = 0; #disable ids
457 $menu{'08.logs'}{'subMenu'}->{'05.ids'}{'enabled'} = 0; #disable ids
458 }
459 }
460
461 sub showhttpheaders
462 {
463 print "Pragma: no-cache\n";
464 print "Cache-control: no-cache\n";
465 print "Connection: close\n";
466 print "Content-type: text/html\n\n";
467 }
468
469 sub is_menu_visible($) {
470 my $link = shift;
471 $link =~ s#\?.*$##;
472 return (-e $ENV{'DOCUMENT_ROOT'}."/../$link");
473 }
474
475
476 sub getlink($) {
477 my $root = shift;
478 if (! $root->{'enabled'}) {
479 return '';
480 }
481 if ($root->{'uri'} !~ /^$/) {
482 my $vars = '';
483 if ($root->{'vars'} !~ /^$/) {
484 $vars = '?'. $root->{'vars'};
485 }
486 if (! is_menu_visible($root->{'uri'})) {
487 return '';
488 }
489 return $root->{'uri'}.$vars;
490 }
491 my $submenus = $root->{'subMenu'};
492 if (! $submenus) {
493 return '';
494 }
495 foreach my $item (sort keys %$submenus) {
496 my $link = getlink($submenus->{$item});
497 if ($link ne '') {
498 return $link;
499 }
500 }
501 return '';
502 }
503
504
505 sub compare_url($) {
506 my $conf = shift;
507
508 my $uri = $conf->{'uri'};
509 my $vars = $conf->{'vars'};
510 my $novars = $conf->{'novars'};
511
512 if ($uri eq '') {
513 return 0;
514 }
515 if ($uri ne $URI[0]) {
516 return 0;
517 }
518 if ($novars) {
519 if ($URI[1] !~ /^$/) {
520 return 0;
521 }
522 }
523 if (! $vars) {
524 return 1;
525 }
526 return ($URI[1] eq $vars);
527 }
528
529
530 sub gettitle($) {
531 my $root = shift;
532
533 if (! $root) {
534 return '';
535 }
536 foreach my $item (sort keys %$root) {
537 my $val = $root->{$item};
538 if (compare_url($val)) {
539 $val->{'selected'} = 1;
540 if ($val->{'title'} !~ /^$/) {
541 return $val->{'title'};
542 }
543 return 'EMPTY TITLE';
544 }
545
546 my $title = gettitle($val->{'subMenu'});
547 if ($title ne '') {
548 $val->{'selected'} = 1;
549 return $title;
550 }
551 }
552 return '';
553 }
554
555
556 sub showmenu() {
557 print <<EOF
558 <div id="menu-top">
559 <ul>
560 EOF
561 ;
562 foreach my $k1 ( sort keys %$menu ) {
563 if (! $menu->{$k1}{'enabled'}) {
564 next;
565 }
566
567 my $link = getlink($menu->{$k1});
568 if ($link eq '') {
569 next;
570 }
571 if (! is_menu_visible($link)) {
572 next;
573 }
574 if ($menu->{$k1}->{'selected'}) {
575 print '<li class="selected">';
576 } else {
577 print '<li>';
578 }
579
580 print <<EOF
581 <div class="rcorner">
582 <a href="$link">$menu->{$k1}{'caption'}</a>
583 </div>
584 </li>
585 EOF
586 ;
587 }
588
589 print <<EOF
590 </ul>
591 </div>
592 EOF
593 ;
594 }
595
596 sub getselected($) {
597 my $root = shift;
598 if (!$root) {
599 return 0;
600 }
601
602 foreach my $item (%$root) {
603 if ($root->{$item}{'selected'}) {
604 return $root->{$item};
605 }
606 }
607 }
608
609 sub showsubsection($$) {
610 my $root = shift;
611 my $id = shift;
612 if ($id eq '') {
613 $id = 'menu-left';
614 }
615
616 if (! $root) {
617 return;
618 }
619 my $selected = getselected($root);
620 if (! $selected) {
621 return;
622 }
623 my $submenus = $selected->{'subMenu'};
624 if (! $submenus) {
625 return;
626 }
627
628 print <<EOF
629 <div id="$id">
630 <ul>
631 EOF
632 ;
633 foreach my $item (sort keys %$submenus) {
634 my $hash = $submenus->{$item};
635 if (! $hash->{'enabled'}) {
636 next;
637 }
638
639 my $link = getlink($hash);
640 if ($link eq '') {
641 next;
642 }
643 if (! is_menu_visible($link)) {
644 next;
645 }
646 if ($hash->{'selected'}) {
647 print '<li class="selected">';
648 } else {
649 print '<li>';
650 }
651
652 print <<EOF
653 <a href="$link">$hash->{'caption'}</a>
654 </li>
655 EOF
656 ;
657 }
658
659 print <<EOF
660 </ul>
661 </div>
662 EOF
663 ;
664
665 }
666
667
668 sub showsubsubsection($) {
669 my $root = shift;
670 if (!$root) {
671 return;
672 }
673 my $selected = getselected($root);
674 if (! $selected) {
675 return
676 }
677 if (! $selected->{'subMenu'}) {
678 return
679 }
680
681 showsubsection($selected->{'subMenu'}, 'menu-subtop');
682 }
683
684
685 sub get_helpuri() {
686 my $helpfile = '';
687 if ($URI[0] =~ /.*\/([^\/]+)\.cgi/) {
688 $helpfile = $1;
689 } else {
690 return '';
691 }
692 $helpfile .= '.help.html';
693
694 my $helpuri = '/doc/'.$language.'/'.$helpfile;
695 if (! -e $ENV{'DOCUMENT_ROOT'}.$helpuri) {
696 return '';
697 }
698 return $helpuri;
699 }
700
701
702 sub openpage {
703 my $title = shift;
704 my $boh = shift;
705 my $extrahead = shift;
706
707 @URI=split ('\?', $ENV{'REQUEST_URI'} );
708 &readhash("${swroot}/main/settings", \%settings);
709 &genmenu();
710
711 my $h2 = gettitle($menu);
712 my $helpuri = get_helpuri();
713
714 $title = "IPFire - $title";
715 if ($settings{'WINDOWWITHHOSTNAME'} eq 'on') {
716 $title = "$settings{'HOSTNAME'}.$settings{'DOMAINNAME'} - $title";
717 }
718
719 print <<END
720 <!DOCTYPE html
721 PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
722 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
723
724 <html>
725 <head>
726 <title>$title</title>
727
728 $extrahead
729 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
730 <link rel="shortcut icon" href="/favicon.ico" />
731 <style type="text/css">\@import url(/include/style.css);</style>
732 <style type="text/css">\@import url(/include/menu.css);</style>
733 <style type="text/css">\@import url(/include/content.css);</style>
734
735 <script language="javascript" type="text/javascript">
736
737 function swapVisibility(id) {
738 el = document.getElementById(id);
739 if(el.style.display != 'block') {
740 el.style.display = 'block'
741 }
742 else {
743 el.style.display = 'none'
744 }
745 }
746 </script>
747
748 </head>
749 <body>
750 <!-- IPFIRE HEADER -->
751
752 <div id="main">
753
754 <div id="header">
755 <img id="logo-product" src="/images/logo_ipfire.gif">
756 <div id="header-icons">
757 END
758 ;
759
760 if ($helpuri ne '') {
761 print <<END
762 <a href="$helpuri" target="_blank"><img border="0" src="/images/help.gif"></a>
763 END
764 ;
765 } else {
766 print '<img src="/images/help.gif">';
767 }
768
769 print <<END
770 </div>
771 </div>
772
773 END
774 ;
775
776 &showmenu();
777
778 print <<END
779 <div id="content">
780 <table width="90%">
781 <tr>
782 <td valign="top">
783 END
784 ;
785
786 &showsubsection($menu);
787
788 print <<END
789
790 </td>
791 <td width="100%" valign="top">
792 <div id="page-content">
793 <h2>$h2</h2>
794 END
795 ;
796
797 &showsubsubsection($menu);
798
799 eval {
800 require 'ipfire-network.pl';
801 $supported = check_support();
802 warn_unsupported($supported);
803 };
804 }
805
806 sub closepage () {
807 my $status = &connectionstatus();
808 $uptime = `/usr/bin/uptime`;
809
810 print <<END
811 <div align="center">
812 <p>
813 <div style="font-size: 9px"><b>Status:</b> $status <b>Uptime:</b>$uptime</div>
814 </p>
815 </div>
816 </body>
817 <meta http-equiv="Page-Enter" content="blendTrans(Duration=1.0,Transition=12)">
818 <meta http-equiv="Page-Exit" content="blendTrans(Duration=1.0,Transition=12)">
819 </html>
820 END
821 ;
822 }
823
824 sub openbigbox
825 {
826 my $width = $_[0];
827 my $align = $_[1];
828 my $sideimg = $_[2];
829
830 if ($errormessage) {
831 $bgcolor = "style='background-color: $colourerr;'";
832 } else {
833 $bgcolor = '';
834 }
835 }
836
837 sub closebigbox
838 {
839 # print "</td></tr></table></td></tr></table>\n"
840 }
841
842 sub openbox
843 {
844 $width = $_[0];
845 $align = $_[1];
846 $caption = $_[2];
847
848 if ($caption) { print "<h3>$caption</h3>\n"; } else { print "&nbsp;"; }
849
850 print "<table class=\"list\"><tr><td align=\"$align\">\n";
851 }
852
853 sub closebox
854 {
855 print "</td></tr></table><br><br>";
856 }
857
858 sub writehash
859 {
860 my $filename = $_[0];
861 my $hash = $_[1];
862
863 # write cgi vars to the file.
864 open(FILE, ">${filename}") or die "Unable to write file $filename";
865 flock FILE, 2;
866 foreach $var (keys %$hash)
867 {
868 $val = $hash->{$var};
869 # Darren Critchley Jan 17, 2003 added the following because when submitting with a graphic, the x and y
870 # location of the mouse are submitted as well, this was being written to the settings file causing
871 # some serious grief! This skips the variable.x and variable.y
872 if (!($var =~ /(.x|.y)$/)) {
873 if ($val =~ / /) {
874 $val = "\'$val\'"; }
875 if (!($var =~ /^ACTION/)) {
876 print FILE "${var}=${val}\n"; }
877 }
878 }
879 close FILE;
880 }
881
882 sub readhash
883 {
884 my $filename = $_[0];
885 my $hash = $_[1];
886 my ($var, $val);
887
888 open(FILE, $filename) or die "Unable to read file $filename";
889
890 while (<FILE>)
891 {
892 chop;
893 ($var, $val) = split /=/, $_, 2;
894 if ($var)
895 {
896 $val =~ s/^\'//g;
897 $val =~ s/\'$//g;
898
899 # Untaint variables read from hash
900 $var =~ /([A-Za-z0-9_-]*)/; $var = $1;
901 $val =~ /([\w\W]*)/; $val = $1;
902 $hash->{$var} = $val;
903 }
904 }
905 close FILE;
906 }
907
908 sub getcgihash {
909 my ($hash, $params) = @_;
910 my $cgi = CGI->new ();
911 $hash->{'__CGI__'} = $cgi;
912 return if ($ENV{'REQUEST_METHOD'} ne 'POST');
913 if (!$params->{'wantfile'}) {
914 $CGI::DISABLE_UPLOADS = 1;
915 $CGI::POST_MAX = 512 * 1024;
916 } else {
917 $CGI::POST_MAX = 10 * 1024 * 1024;
918 }
919
920 $cgi->referer() =~ m/^https?\:\/\/([^\/]+)/;
921 my $referer = $1;
922 $cgi->url() =~ m/^https?\:\/\/([^\/]+)/;
923 my $servername = $1;
924 return if ($referer ne $servername);
925
926 ### Modified for getting multi-vars, split by |
927 %temp = $cgi->Vars();
928 foreach my $key (keys %temp) {
929 $hash->{$key} = $temp{$key};
930 $hash->{$key} =~ s/\0/|/g;
931 $hash->{$key} =~ s/^\s*(.*?)\s*$/$1/;
932 }
933
934 if (($params->{'wantfile'})&&($params->{'filevar'})) {
935 $hash->{$params->{'filevar'}} = $cgi->upload
936 ($params->{'filevar'});
937 }
938 return;
939 }
940
941 sub log
942 {
943 my $logmessage = $_[0];
944 $logmessage =~ /([\w\W]*)/;
945 $logmessage = $1;
946 system('/usr/bin/logger', '-t', 'ipfire', $logmessage);
947 }
948
949 sub age
950 {
951 my ($dev, $ino, $mode, $nlink, $uid, $gid, $rdev, $size,
952 $atime, $mtime, $ctime, $blksize, $blocks) = stat $_[0];
953 my $now = time;
954
955 my $totalsecs = $now - $mtime;
956 my $days = int($totalsecs / 86400);
957 my $totalhours = int($totalsecs / 3600);
958 my $hours = $totalhours % 24;
959 my $totalmins = int($totalsecs / 60);
960 my $mins = $totalmins % 60;
961 my $secs = $totalsecs % 60;
962
963 return "${days}d ${hours}h ${mins}m ${secs}s";
964 }
965
966 sub validip
967 {
968 my $ip = $_[0];
969
970 if (!($ip =~ /^(\d+)\.(\d+)\.(\d+)\.(\d+)$/)) {
971 return 0; }
972 else
973 {
974 @octets = ($1, $2, $3, $4);
975 foreach $_ (@octets)
976 {
977 if (/^0./) {
978 return 0; }
979 if ($_ < 0 || $_ > 255) {
980 return 0; }
981 }
982 return 1;
983 }
984 }
985
986 sub validmask
987 {
988 my $mask = $_[0];
989
990 # secord part an ip?
991 if (&validip($mask)) {
992 return 1; }
993 # second part a number?
994 if (/^0/) {
995 return 0; }
996 if (!($mask =~ /^\d+$/)) {
997 return 0; }
998 if ($mask >= 0 && $mask <= 32) {
999 return 1; }
1000 return 0;
1001 }
1002
1003 sub validipormask
1004 {
1005 my $ipormask = $_[0];
1006
1007 # see if it is a IP only.
1008 if (&validip($ipormask)) {
1009 return 1; }
1010 # split it into number and mask.
1011 if (!($ipormask =~ /^(.*?)\/(.*?)$/)) {
1012 return 0; }
1013 $ip = $1;
1014 $mask = $2;
1015 # first part not a ip?
1016 if (!(&validip($ip))) {
1017 return 0; }
1018 return &validmask($mask);
1019 }
1020
1021 sub validipandmask
1022 {
1023 my $ipandmask = $_[0];
1024
1025 # split it into number and mask.
1026 if (!($ipandmask =~ /^(.*?)\/(.*?)$/)) {
1027 return 0; }
1028 $ip = $1;
1029 $mask = $2;
1030 # first part not a ip?
1031 if (!(&validip($ip))) {
1032 return 0; }
1033 return &validmask($mask);
1034 }
1035
1036 sub validport
1037 {
1038 $_ = $_[0];
1039
1040 if (!/^\d+$/) {
1041 return 0; }
1042 if (/^0./) {
1043 return 0; }
1044 if ($_ >= 1 && $_ <= 65535) {
1045 return 1; }
1046 return 0;
1047 }
1048
1049 sub validmac
1050 {
1051 my $checkmac = $_[0];
1052 my $ot = '[0-9a-f]{2}'; # 2 Hex digits (one octet)
1053 if ($checkmac !~ /^$ot:$ot:$ot:$ot:$ot:$ot$/i)
1054 {
1055 return 0;
1056 }
1057 return 1;
1058 }
1059
1060 sub validhostname
1061 {
1062 # Checks a hostname against RFC1035
1063 my $hostname = $_[0];
1064
1065 # Each part should be at least two characters in length
1066 # but no more than 63 characters
1067 if (length ($hostname) < 2 || length ($hostname) > 63) {
1068 return 0;}
1069 # Only valid characters are a-z, A-Z, 0-9 and -
1070 if ($hostname !~ /^[a-zA-Z0-9-]*$/) {
1071 return 0;}
1072 # First character can only be a letter or a digit
1073 if (substr ($hostname, 0, 1) !~ /^[a-zA-Z0-9]*$/) {
1074 return 0;}
1075 # Last character can only be a letter or a digit
1076 if (substr ($hostname, -1, 1) !~ /^[a-zA-Z0-9]*$/) {
1077 return 0;}
1078 return 1;
1079 }
1080
1081 sub validdomainname
1082 {
1083 # Checks a domain name against RFC1035
1084 my $domainname = $_[0];
1085 my @parts = split (/\./, $domainname); # Split hostname at the '.'
1086
1087 foreach $part (@parts) {
1088 # Each part should be at least two characters in length
1089 # but no more than 63 characters
1090 if (length ($part) < 2 || length ($part) > 63) {
1091 return 0;}
1092 # Only valid characters are a-z, A-Z, 0-9 and -
1093 if ($part !~ /^[a-zA-Z0-9-]*$/) {
1094 return 0;}
1095 # First character can only be a letter or a digit
1096 if (substr ($part, 0, 1) !~ /^[a-zA-Z0-9]*$/) {
1097 return 0;}
1098 # Last character can only be a letter or a digit
1099 if (substr ($part, -1, 1) !~ /^[a-zA-Z0-9]*$/) {
1100 return 0;}
1101 }
1102 return 1;
1103 }
1104
1105 sub validfqdn
1106 {
1107 # Checks a fully qualified domain name against RFC1035
1108 my $fqdn = $_[0];
1109 my @parts = split (/\./, $fqdn); # Split hostname at the '.'
1110 if (scalar(@parts) < 2) { # At least two parts should
1111 return 0;} # exist in a FQDN
1112 # (i.e. hostname.domain)
1113 foreach $part (@parts) {
1114 # Each part should be at least two characters in length
1115 # but no more than 63 characters
1116 if (length ($part) < 2 || length ($part) > 63) {
1117 return 0;}
1118 # Only valid characters are a-z, A-Z, 0-9 and -
1119 if ($part !~ /^[a-zA-Z0-9-]*$/) {
1120 return 0;}
1121 # First character can only be a letter or a digit
1122 if (substr ($part, 0, 1) !~ /^[a-zA-Z0-9]*$/) {
1123 return 0;}
1124 # Last character can only be a letter or a digit
1125 if (substr ($part, -1, 1) !~ /^[a-zA-Z0-9]*$/) {
1126 return 0;}
1127 }
1128 return 1;
1129 }
1130
1131 sub validportrange # used to check a port range
1132 {
1133 my $port = $_[0]; # port values
1134 $port =~ tr/-/:/; # replace all - with colons just in case someone used -
1135 my $srcdst = $_[1]; # is it a source or destination port
1136
1137 if (!($port =~ /^(\d+)\:(\d+)$/)) {
1138
1139 if (!(&validport($port))) {
1140 if ($srcdst eq 'src'){
1141 return $tr{'source port numbers'};
1142 } else {
1143 return $tr{'destination port numbers'};
1144 }
1145 }
1146 }
1147 else
1148 {
1149 @ports = ($1, $2);
1150 if ($1 >= $2){
1151 if ($srcdst eq 'src'){
1152 return $tr{'bad source range'};
1153 } else {
1154 return $tr{'bad destination range'};
1155 }
1156 }
1157 foreach $_ (@ports)
1158 {
1159 if (!(&validport($_))) {
1160 if ($srcdst eq 'src'){
1161 return $tr{'source port numbers'};
1162 } else {
1163 return $tr{'destination port numbers'};
1164 }
1165 }
1166 }
1167 return;
1168 }
1169 }
1170
1171 # Test if IP is within a subnet
1172 # Call: IpInSubnet (Addr, Subnet, Subnet Mask)
1173 # Subnet can be an IP of the subnet: 10.0.0.0 or 10.0.0.1
1174 # Everything in dottted notation
1175 # Return: TRUE/FALSE
1176 sub IpInSubnet
1177 {
1178 $ip = unpack('N', inet_aton(shift));
1179 $start = unpack('N', inet_aton(shift));
1180 $mask = unpack('N', inet_aton(shift));
1181 $start &= $mask; # base of subnet...
1182 $end = $start + ~$mask;
1183 return (($ip >= $start) && ($ip <= $end));
1184 }
1185
1186 sub validemail {
1187 my $mail = shift;
1188 return 0 if ( $mail !~ /^[0-9a-zA-Z\.\-\_]+\@[0-9a-zA-Z\.\-]+$/ );
1189 return 0 if ( $mail =~ /^[^0-9a-zA-Z]|[^0-9a-zA-Z]$/);
1190 return 0 if ( $mail !~ /([0-9a-zA-Z]{1})\@./ );
1191 return 0 if ( $mail !~ /.\@([0-9a-zA-Z]{1})/ );
1192 return 0 if ( $mail =~ /.\.\-.|.\-\..|.\.\..|.\-\-./g );
1193 return 0 if ( $mail =~ /.\.\_.|.\-\_.|.\_\..|.\_\-.|.\_\_./g );
1194 return 0 if ( $mail !~ /\.([a-zA-Z]{2,3})$/ );
1195 return 1;
1196 }
1197
1198 sub readhasharray {
1199 my ($filename, $hash) = @_;
1200
1201 open(FILE, $filename) or die "Unable to read file $filename";
1202
1203 while (<FILE>) {
1204 my ($key, $rest, @temp);
1205 chomp;
1206 ($key, $rest) = split (/,/, $_, 2);
1207 if ($key =~ /^[0-9]+$/ && $rest) {
1208 @temp = split (/,/, $rest);
1209 $hash->{$key} = \@temp;
1210 }
1211 }
1212 close FILE;
1213 return;
1214 }
1215
1216 sub writehasharray {
1217 my ($filename, $hash) = @_;
1218 my ($key, @temp);
1219
1220 open(FILE, ">$filename") or die "Unable to write to file $filename";
1221
1222 foreach $key (keys %$hash) {
1223 if ( $hash->{$key} ) {
1224 print FILE "$key";
1225 foreach $i (0 .. $#{$hash->{$key}}) {
1226 print FILE ",$hash->{$key}[$i]";
1227 }
1228 }
1229 print FILE "\n";
1230 }
1231 close FILE;
1232 return;
1233 }
1234
1235 sub findhasharraykey {
1236 foreach my $i (1 .. 1000000) {
1237 if ( ! exists $_[0]{$i}) {
1238 return $i;
1239 }
1240 }
1241 }
1242
1243 sub cleanhtml
1244 {
1245 my $outstring =$_[0];
1246 $outstring =~ tr/,/ / if not defined $_[1] or $_[1] ne 'y';
1247 $outstring =~ s/&/&amp;/g;
1248 $outstring =~ s/\'/&#039;/g;
1249 $outstring =~ s/\"/&quot;/g;
1250 $outstring =~ s/</&lt;/g;
1251 $outstring =~ s/>/&gt;/g;
1252 return $outstring;
1253 }
1254 sub connectionstatus
1255 {
1256 my $status;
1257 opendir UPLINKS, "/var/ipfire/uplinks" or die "Cannot read uplinks: $!";
1258 foreach my $uplink (sort grep !/^\./, readdir UPLINKS) {
1259 if ( -f "${swroot}/uplinks/${uplink}/active") {
1260 if ( ! $status ) {
1261 $timestr = &age("${swroot}/uplinks/${uplink}/active");
1262 $status = "$tr{'connected'}: $uplink (<span class='ipcop_StatusBigRed'>$timestr</span>) ";
1263 } else {
1264 $timestr = &age("${swroot}/uplinks/${uplink}/active");
1265 $status = "$status , $uplink (<span class='ipcop_StatusBigRed'>$timestr</span>) ";
1266 }
1267 } elsif ( -f "${swroot}/uplinks/${uplink}/connecting") {
1268 if ( ! $status ) {
1269 $status = "$tr{'connecting'} $uplink";
1270 } else {
1271 $status = "$status , $tr{'connecting'} $uplink (<span class='ipcop_StatusBigRed'>$timestr</span>) ";
1272 }
1273 }
1274 $lines++;
1275 }
1276 closedir(UPLINKS);
1277 if ( ! $status ) {
1278 $status = "$tr{'idle'}";
1279 }
1280 $connstate = "<span class='ipcop_StatusBig'>$status</span>";
1281 return $connstate;
1282 }
1283
1284 sub srtarray
1285 # Darren Critchley - darrenc@telus.net - (c) 2003
1286 # &srtarray(SortOrder, AlphaNumeric, SortDirection, ArrayToBeSorted)
1287 # This subroutine will take the following parameters:
1288 # ColumnNumber = the column which you want to sort on, starts at 1
1289 # AlphaNumberic = a or n (lowercase) defines whether the sort should be alpha or numberic
1290 # SortDirection = asc or dsc (lowercase) Ascending or Descending sort
1291 # ArrayToBeSorted = the array that wants sorting
1292 #
1293 # Returns an array that is sorted to your specs
1294 #
1295 # If SortOrder is greater than the elements in array, then it defaults to the first element
1296 #
1297 {
1298 my ($colno, $alpnum, $srtdir, @tobesorted) = @_;
1299 my @tmparray;
1300 my @srtedarray;
1301 my $line;
1302 my $newline;
1303 my $ttlitems = scalar @tobesorted; # want to know the number of rows in the passed array
1304 if ($ttlitems < 1){ # if no items, don't waste our time lets leave
1305 return (@tobesorted);
1306 }
1307 my @tmp = split(/\,/,$tobesorted[0]);
1308 $ttlitems = scalar @tmp; # this should be the number of elements in each row of the passed in array
1309
1310 # Darren Critchley - validate parameters
1311 if ($colno > $ttlitems){$colno = '1';}
1312 $colno--; # remove one from colno to deal with arrays starting at 0
1313 if($colno < 0){$colno = '0';}
1314 if ($alpnum ne '') { $alpnum = lc($alpnum); } else { $alpnum = 'a'; }
1315 if ($srtdir ne '') { $srtdir = lc($srtdir); } else { $srtdir = 'src'; }
1316
1317 foreach $line (@tobesorted)
1318 {
1319 chomp($line);
1320 if ($line ne '') {
1321 my @temp = split(/\,/,$line);
1322 # Darren Critchley - juggle the fields so that the one we want to sort on is first
1323 my $tmpholder = $temp[0];
1324 $temp[0] = $temp[$colno];
1325 $temp[$colno] = $tmpholder;
1326 $newline = "";
1327 for ($ctr=0; $ctr < $ttlitems ; $ctr++) {
1328 $newline=$newline . $temp[$ctr] . ",";
1329 }
1330 chop($newline);
1331 push(@tmparray,$newline);
1332 }
1333 }
1334 if ($alpnum eq 'n') {
1335 @tmparray = sort {$a <=> $b} @tmparray;
1336 } else {
1337 @tmparray = (sort @tmparray);
1338 }
1339 foreach $line (@tmparray)
1340 {
1341 chomp($line);
1342 if ($line ne '') {
1343 my @temp = split(/\,/,$line);
1344 my $tmpholder = $temp[0];
1345 $temp[0] = $temp[$colno];
1346 $temp[$colno] = $tmpholder;
1347 $newline = "";
1348 for ($ctr=0; $ctr < $ttlitems ; $ctr++){
1349 $newline=$newline . $temp[$ctr] . ",";
1350 }
1351 chop($newline);
1352 push(@srtedarray,$newline);
1353 }
1354 }
1355
1356 if ($srtdir eq 'dsc') {
1357 @tmparray = reverse(@srtedarray);
1358 return (@tmparray);
1359 } else {
1360 return (@srtedarray);
1361 }
1362 }
1363
1364 sub speedtouchversion
1365 {
1366 if (-f "/proc/bus/usb/devices")
1367 {
1368 $speedtouch=`/bin/cat /proc/bus/usb/devices | /bin/grep 'Vendor=06b9 ProdID=4061' | /usr/bin/cut -d ' ' -f6`;
1369 if ($speedtouch eq '') {
1370 $speedtouch= $tr{'connect the modem'};
1371 }
1372 } else {
1373 $speedtouch='USB '.$tr{'not running'};
1374 }
1375 return $speedtouch
1376 }
1377
1378 sub CheckSortOrder {
1379 #Sorting of allocated leases
1380 if ($ENV{'QUERY_STRING'} =~ /^IPADDR|^ETHER|^HOSTNAME|^ENDTIME/ ) {
1381 my $newsort=$ENV{'QUERY_STRING'};
1382 &readhash("${swroot}/dhcp/settings", \%dhcpsettings);
1383 $act=$dhcpsettings{'SORT_LEASELIST'};
1384 #Reverse actual ?
1385 if ($act =~ $newsort) {
1386 if ($act !~ 'Rev') {$Rev='Rev'};
1387 $newsort.=$Rev
1388 };
1389
1390 $dhcpsettings{'SORT_LEASELIST'}=$newsort;
1391 &writehash("${swroot}/dhcp/settings", \%dhcpsettings);
1392 $dhcpsettings{'ACTION'} = 'SORT'; # avoid the next test "First lauch"
1393 }
1394
1395 }
1396
1397 sub PrintActualLeases
1398 {
1399 &openbox('100%', 'left', $tr{'current dynamic leases'});
1400 print <<END
1401 <table width='100%'>
1402 <tr>
1403 <td width='25%' align='center'><a href='$ENV{'SCRIPT_NAME'}?IPADDR'><b>$tr{'ip address'}</b></a></td>
1404 <td width='25%' align='center'><a href='$ENV{'SCRIPT_NAME'}?ETHER'><b>$tr{'mac address'}</b></a></td>
1405 <td width='20%' align='center'><a href='$ENV{'SCRIPT_NAME'}?HOSTNAME'><b>$tr{'hostname'}</b></a></td>
1406 <td width='30%' align='center'><a href='$ENV{'SCRIPT_NAME'}?ENDTIME'><b>$tr{'lease expires'} (local time d/m/y)</b></a></td>
1407 </tr>
1408 END
1409 ;
1410
1411 open(LEASES,"/var/lib/dhcp/dhcpd.leases") or die "Can't open dhcpd.leases";
1412 while ($line = <LEASES>) {
1413 next if( $line =~ /^\s*#/ );
1414 chomp($line);
1415 @temp = split (' ', $line);
1416
1417 if ($line =~ /^\s*lease/) {
1418 $ip = $temp[1];
1419 #All field are not necessarily read. Clear everything
1420 $endtime = 0;
1421 $ether = "";
1422 $hostname = "";
1423 }
1424
1425 if ($line =~ /^\s*ends/) {
1426 $line =~ /(\d+)\/(\d+)\/(\d+) (\d+):(\d+):(\d+)/;
1427 $endtime = timegm($6, $5, $4, $3, $2 - 1, $1 - 1900);
1428 }
1429
1430 if ($line =~ /^\s*hardware ethernet/) {
1431 $ether = $temp[2];
1432 $ether =~ s/;//g;
1433 }
1434
1435 if ($line =~ /^\s*client-hostname/) {
1436 $hostname = "$temp[1] $temp[2] $temp[3]";
1437 $hostname =~ s/;//g;
1438 $hostname =~ s/\"//g;
1439 }
1440
1441 if ($line eq "}") {
1442 @record = ('IPADDR',$ip,'ENDTIME',$endtime,'ETHER',$ether,'HOSTNAME',$hostname);
1443 $record = {}; # create a reference to empty hash
1444 %{$record} = @record; # populate that hash with @record
1445 $entries{$record->{'IPADDR'}} = $record; # add this to a hash of hashes
1446 }
1447 }
1448 close(LEASES);
1449
1450 my $id = 0;
1451 foreach my $key (sort leasesort keys %entries) {
1452
1453 my $hostname = &cleanhtml($entries{$key}->{HOSTNAME},"y");
1454
1455 if ($id % 2) {
1456 print "<tr bgcolor='$table1colour'>";
1457 }
1458 else {
1459 print "<tr bgcolor='$table2colour'>";
1460 }
1461
1462 print <<END
1463 <td align='center'>$entries{$key}->{IPADDR}</td>
1464 <td align='center'>$entries{$key}->{ETHER}</td>
1465 <td align='center'>&nbsp;$hostname </td>
1466 <td align='center'>
1467 END
1468 ;
1469
1470 ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $dst) = localtime ($entries{$key}->{ENDTIME});
1471 $enddate = sprintf ("%02d/%02d/%d %02d:%02d:%02d",$mday,$mon+1,$year+1900,$hour,$min,$sec);
1472
1473 if ($entries{$key}->{ENDTIME} < time() ){
1474 print "<strike>$enddate</strike>";
1475 } else {
1476 print "$enddate";
1477 }
1478 print "</td></tr>";
1479 $id++;
1480 }
1481
1482 print "</table>";
1483 &closebox();
1484 }
1485
1486
1487 # This sub is used during display of actives leases
1488 sub leasesort {
1489 if (rindex ($dhcpsettings{'SORT_LEASELIST'},'Rev') != -1)
1490 {
1491 $qs=substr ($dhcpsettings{'SORT_LEASELIST'},0,length($dhcpsettings{'SORT_LEASELIST'})-3);
1492 if ($qs eq 'IPADDR') {
1493 @a = split(/\./,$entries{$a}->{$qs});
1494 @b = split(/\./,$entries{$b}->{$qs});
1495 ($b[0]<=>$a[0]) ||
1496 ($b[1]<=>$a[1]) ||
1497 ($b[2]<=>$a[2]) ||
1498 ($b[3]<=>$a[3]);
1499 }else {
1500 $entries{$b}->{$qs} cmp $entries{$a}->{$qs};
1501 }
1502 }
1503 else #not reverse
1504 {
1505 $qs=$dhcpsettings{'SORT_LEASELIST'};
1506 if ($qs eq 'IPADDR') {
1507 @a = split(/\./,$entries{$a}->{$qs});
1508 @b = split(/\./,$entries{$b}->{$qs});
1509 ($a[0]<=>$b[0]) ||
1510 ($a[1]<=>$b[1]) ||
1511 ($a[2]<=>$b[2]) ||
1512 ($a[3]<=>$b[3]);
1513 }else {
1514 $entries{$a}->{$qs} cmp $entries{$b}->{$qs};
1515 }
1516 }
1517 }
1518
1519 sub get_uplinks() {
1520 my @uplinks = ();
1521 opendir(DIR, "${swroot}/uplinks/") || return \@uplinks;
1522 foreach my $dir (readdir(DIR)) {
1523 next if ($dir =~ /^\./);
1524 next if (-f "${swroot}/uplinks/$dir");
1525 push(@uplinks, $dir);
1526 }
1527 closedir(DIR);
1528 return \@uplinks;
1529 }
1530
1531 sub get_iface($) {
1532 my $filename = shift;
1533 chomp($filename);
1534 open (F, $filename) || return "";
1535 my $iface = <F>;
1536 close(F);
1537 chomp($iface);
1538 return $iface;
1539 }
1540
1541 sub get_red_ifaces_by_type($) {
1542 my $type=shift;
1543 my @gottypeiface = ();
1544 my @gottypeuplink = ();
1545 my @gottype = ();
1546
1547 my $ref=get_uplinks();
1548 my @uplinks=@$ref;
1549 my %set = ();
1550 foreach my $link (@uplinks) {
1551 eval {
1552 &readhash("${swroot}/uplinks/$link/settings", \%set);
1553 };
1554 push(@gottype, $link);
1555
1556 my $iface = $set{'RED_DEV'};
1557 if (!$iface) {
1558 $iface = get_iface("${swroot}/uplinks/$link/interface");
1559 }
1560 next if (!$iface);
1561
1562 if ($set{'RED_TYPE'} eq $type) {
1563 push(@gottypeiface, $iface);
1564 push(@gottypeuplink, $link);
1565 }
1566 }
1567 return (\@gottypeiface, \@gottypeuplink, \@gottype);
1568 }
1569
1570 sub get_red_ifaces() {
1571 return `cat ${swroot}/uplinks/*/interface 2>/dev/null`;
1572 }
1573
1574 sub get_zone_devices($) {
1575 my $bridge = shift;
1576 my @ifaces = ();
1577 open (FILE, "${swroot}/ethernet/$bridge") || return "";
1578 foreach my $line (<FILE>) {
1579 chomp($line);
1580 next if (!$line);
1581 push(@ifaces, $line);
1582 }
1583 close(FILE);
1584 return \@ifaces;
1585 }