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