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