]>
git.ipfire.org Git - ipfire-2.x.git/blob - config/cfgroot/header.pl
353e8c07b3acceae008d144051280d3d6525d66a
3 # This code is distributed under the terms of the GPL
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()
12 # $Id: header.pl,v 1.34.2.39 2004/11/26 15:51:27 alanh Exp $
20 $|=1; # line buffering
23 my $read_ver = `cat /etc/ipfire-release`;
24 if ($read_ver =~ /^$/) {
25 return "IPFire (unknown version)";
30 $Header::version
= get_version
();
31 $Header::revision
= 'final';
32 $Header::swroot
= '/var/ipfire';
33 $Header::pagecolour
= '#ffffff';
34 #$Header::tablecolour = '#a0a0a0';
35 $Header::tablecolour
= '#FFFFFF';
36 $Header::bigboxcolour
= '#F6F4F4';
37 $Header::boxcolour
= '#EAE9EE';
38 $Header::bordercolour
= '#000000';
39 $Header::table1colour
= '#E0E0E0';
40 $Header::table2colour
= '#F0F0F0';
41 $Header::colourred
= '#993333';
42 $Header::colourorange
= '#FF9933';
43 $Header::colouryellow
= '#FFFF00';
44 $Header::colourgreen
= '#339933';
45 $Header::colourblue
= '#333399';
46 $Header::colourfw
= '#000000';
47 $Header::colourvpn
= '#990099';
48 $Header::colourerr
= '#FF0000';
49 $Header::viewsize
= 150;
50 $Header::errormessage
= '';
52 my $menu = \
%menuhash;
58 ### Make sure this is an SSL request
59 if ($ENV{'SERVER_ADDR'} && $ENV{'HTTPS'} ne 'on') {
60 print "Status: 302 Moved\r\n";
61 print "Location: https://$ENV{'SERVER_ADDR'}:10443/$ENV{'PATH_INFO'}\r\n\r\n";
65 ### Initialize environment
66 &readhash
("${swroot}/main/settings", \
%settings);
67 &readhash
("${swroot}/ethernet/settings", \
%ethsettings);
68 $language = $settings{'LANGUAGE'};
69 $hostname = $settings{'HOSTNAME'};
72 ### Initialize language
73 if ($language =~ /^(\w+)$/) {$language = $1;}
75 ### Read English Files
76 if ( -d
"/var/ipfire/langs/en/" ) {
77 opendir(DIR
, "/var/ipfire/langs/en/");
78 @names = readdir(DIR
) or die "Cannot Read Directory: $!\n";
79 foreach $name(@names) {
80 next if ($name eq ".");
81 next if ($name eq "..");
82 next if (!($name =~ /\.pl$/));
83 require "${swroot}/langs/en/${name}";
88 ### Enable Language Files
89 if ( -d
"/var/ipfire/langs/${language}/" ) {
90 opendir(DIR
, "/var/ipfire/langs/${language}/");
91 @names = readdir(DIR
) or die "Cannot Read Directory: $!\n";
92 foreach $name(@names) {
93 next if ($name eq ".");
94 next if ($name eq "..");
95 next if (!($name =~ /\.pl$/));
96 require "${swroot}/langs/${language}/${name}";
101 require "${swroot}/langs/en.pl";
102 require "${swroot}/langs/${language}.pl";
105 if ($ethsettings{'CONFIG_TYPE'} =~ /^[1357]$/) {
112 if ($ethsettings{'CONFIG_TYPE'} =~ /^[4567]$/) {
119 if ($ethsettings{'CONFIG_TYPE'} =~ /^[0145]$/) {
127 my %subsystemhash = ();
128 my $subsystem = \
%subsystemhash;
130 $subsystem->{'01.home'} = {
131 'caption' => $tr{'alt home'},
132 'uri' => '/cgi-bin/index.cgi',
133 'title' => "$tr{'alt home'}",
136 $subsystem->{'02.netwizard'} = {
137 'caption' => $tr{'network configuration'},
138 'uri' => '/cgi-bin/netwizard.cgi',
139 'title' => "$tr{'network configuration'}",
142 $subsystem->{'03.updates'} = {
143 'caption' => $tr{'updates'},
144 'uri' => '/cgi-bin/updates.cgi',
145 'title' => "$tr{'updates'}",
148 $subsystem->{'04.passwords'} = {
149 'caption' => $tr{'sspasswords'},
150 'uri' => '/cgi-bin/changepw.cgi',
151 'title' => "$tr{'sspasswords'}",
154 $subsystem->{'05.ssh'} = {
155 'caption' => $tr{'ssh access'},
156 'uri' => '/cgi-bin/remote.cgi',
157 'title' => "$tr{'ssh access'}",
160 $subsystem->{'06.gui'} = {
161 'caption' => $tr{'gui settings'},
162 'uri' => '/cgi-bin/gui.cgi',
163 'title' => "$tr{'gui settings'}",
166 $subsystem->{'07.backup'} = {
167 'caption' => $tr{'backup'},
168 'uri' => '/cgi-bin/backup.cgi',
169 'title' => "$tr{'backup'} / $tr{'restore'}",
172 $subsystem->{'08.shutdown'} = {
173 'caption' => $tr{'shutdown'},
174 'uri' => '/cgi-bin/shutdown.cgi',
175 'title' => "$tr{'shutdown'} / $tr{'reboot'}",
178 $subsystem->{'09.credits'} = {
179 'caption' => $tr{'credits'},
180 'uri' => '/cgi-bin/credits.cgi',
181 'title' => "$tr{'credits'}",
185 my %substatushash = ();
186 my $substatus = \
%substatushash;
187 $substatus->{'01.systemstatus'} = {
188 'caption' => $tr{'sssystem status'},
189 'uri' => '/cgi-bin/status.cgi',
190 'title' => "$tr{'system status information'}",
193 $substatus->{'02.networkstatus'} = {
194 'caption' => $tr{'ssnetwork status'},
195 'uri' => '/cgi-bin/netstatus.cgi',
196 'title' => "$tr{'network status information'}",
199 $substatus->{'03.systemgraphs'} = {
200 'caption' => $tr{'system graphs'},
201 'uri' => '/cgi-bin/graphs.cgi',
203 'title' => "$tr{'system graphs'}",
206 $substatus->{'04.trafficgraphs'} = {
207 'caption' => $tr{'sstraffic graphs'},
208 'uri' => '/cgi-bin/graphs.cgi',
209 'vars' => 'graph=network',
210 'title' => "$tr{'network traffic graphs'}",
213 $substatus->{'05.proxygraphs'} = {
214 'caption' => $tr{'ssproxy graphs'},
215 'uri' => '/cgi-bin/proxygraphs.cgi',
216 'title' => "$tr{'proxy access graphs'}",
219 $substatus->{'06.connections'} = {
220 'caption' => $tr{'connections'},
221 'uri' => '/cgi-bin/connections.cgi',
222 'title' => "$tr{'connections'}",
225 $substatus->{'99.iptfilters'} = {
226 'caption' => $tr{'iptfilters iptable rules'},
227 'uri' => '/cgi-bin/iptfilters.cgi',
228 'title' => "$tr{'iptfilters iptable rules'}",
232 my %subnetworkhash = ();
233 my $subnetwork = \
%subnetworkhash;
235 $subnetwork->{'01.dialup'} = {
236 'caption' => $tr{'alt dialup'},
237 'uri' => '/cgi-bin/pppsetup.cgi',
238 'title' => "$tr{'dialup settings'}",
241 $subnetwork->{'02.hosts'} = {
242 'caption' => $tr{'edit hosts'},
243 'uri' => '/cgi-bin/hosts.cgi',
244 'title' => "$tr{'host configuration'}",
247 $subnetwork->{'03.upload'} = {
248 'caption' => $tr{'upload'},
249 'uri' => '/cgi-bin/upload.cgi',
250 'title' => "$tr{'firmware upload'}",
253 $subnetwork->{'04.aliases'} = {
254 'caption' => $tr{'aliases'},
255 'uri' => '/cgi-bin/aliases.cgi',
256 'title' => "$tr{'external aliases configuration'}",
261 my %subserviceshash = ();
262 my $subservices = \
%subserviceshash;
264 $subservices->{'01.dhcp'} = {
265 'caption' => $tr{'dhcp server'},
266 'uri' => '/cgi-bin/dhcp.cgi',
267 'title' => "$tr{'dhcp configuration'}",
270 $subservices->{'02.dyndns'} = {
271 'caption' => $tr{'dynamic dns'},
272 'uri' => '/cgi-bin/ddns.cgi',
273 'title' => "$tr{'dynamic dns client'}",
276 $subservices->{'03.time'} = {
277 'caption' => $tr{'time server'},
278 'uri' => '/cgi-bin/time.cgi',
279 'title' => "$tr{'time server'}",
282 $subservices->{'04.shaping'} = {
283 'caption' => $tr{'traffic shaping'},
284 'uri' => '/cgi-bin/shaping.cgi',
285 'title' => "$tr{'traffic shaping settings'}",
288 $subservices->{'05.ids'} = {'caption' => $tr{'intrusion detection'},
290 'uri' => '/cgi-bin/ids.cgi',
291 'title' => "$tr{'intrusion detection system'} (Snort)",
295 my %subfirewallhash = ();
296 my $subfirewall = \
%subfirewallhash;
299 $subfirewall->{'01.dnat'} = {
300 'caption' => $tr{'ssport forwarding'},
301 'uri' => '/cgi-bin/portfw.cgi',
302 'title' => "$tr{'port forwarding configuration'}",
305 $subfirewall->{'02.xtaccess'} = {
306 'caption' => $tr{'external access'},
307 'uri' => '/cgi-bin/xtaccess.cgi',
308 'title' => "$tr{'external access configuration'}",
311 $subfirewall->{'03.dmz'} = {
312 'caption' => $tr{'ssdmz pinholes'},
313 'uri' => '/cgi-bin/dmzholes.cgi',
314 'title' => "$tr{'dmz pinhole configuration'}",
317 $subfirewall->{'04.outgoing'} = {
318 'caption' => $tr{'outgoing firewall'},
319 'uri' => '/cgi-bin/outgoingfw.cgi',
320 'title' => "$tr{'outgoing firewall'}",
326 my %subhttphash = ();
327 my $subhttp = \
%subhttphash;
328 $subhttp->{'01.proxy'} = {
329 'caption' => $tr{'proxy'},
330 'uri' => '/cgi-bin/advproxy.cgi',
331 'title' => "HTTP: $tr{'web proxy configuration'}",
334 $subhttp->{'02.contentfilter'} = {
335 'caption' => $tr{'content filter'},
336 'uri' => '/cgi-bin/dansguardian.cgi',
337 'title' => "HTTP: $tr{'content filter'}",
340 $subhttp->{'03.antivirus'} = {
341 'caption' => $tr{'antivirus'},
342 'uri' => '/cgi-bin/httpantivirus.cgi',
343 'title' => "HTTP: $tr{'antivirus'}",
346 $subhttp->{'04.proxymanagment'} = {
347 'caption' => $tr{'DS Managment'},
348 'uri' => '/cgi-bin/proxygm.cgi',
349 'title' => "HTTP: $tr{'DS Managment'}",
352 $subhttp->{'05.activatedgroups'} = {
353 'caption' => $tr{'activated Groups'},
354 'uri' => '/cgi-bin/proxyag.cgi',
355 'title' => "HTTP: $tr{'activated Groups'}",
358 $subhttp->{'06.advancedproxy'} = {
359 'caption' => $tr{'Proxy Advanced'},
360 'uri' => '/cgi-bin/proxyad.cgi',
361 'title' => "HTTP: $tr{'Proxy Advanced'}",
366 my %subproxyhash = ();
367 my $subproxy = \
%subproxyhash;
369 $subproxy->{'01.http'} = {'caption' => $tr{'HTTP'},
371 'subMenu' => $subhttp
373 $subproxy->{'02.ftp'} = {'caption' => 'FTP',
380 my %subopenvpnhash = ();
381 my $subopenvpn = \
%subopenvpnhash;
382 $subopenvpn->{'01.server'} = {'caption' => $tr{'openvpn'},
383 'uri' => '/cgi-bin/openvpn.cgi',
384 'title' => "$tr{'virtual private networking'}",
387 $subopenvpn->{'02.client'} = {'caption' => $tr{'openvpnclient'},
388 'uri' => '/cgi-bin/openvpnclient.cgi',
389 'title' => "$tr{'virtual private networking'}",
394 my $subvpn = \
%subvpnhash;
396 $subvpn->{'01.openvpn'} = {'caption' => $tr{'openvpn'},
397 'subMenu' => $subopenvpn,
400 $subvpn->{'02.ipsec'} = {'caption' => $tr{'ipsec'},
401 'uri' => '/cgi-bin/vpnmain.cgi',
402 'title' => "$tr{'virtual private networking'}",
406 my %sublogshash = ();
407 my $sublogs = \
%sublogshash;
409 $sublogs->{'01.summary'} = {'caption' => $tr{'log summary'},
410 'uri' => '/cgi-bin/logs.cgi/summary.dat',
411 'title' => "$tr{'log summary'}",
414 $sublogs->{'02.settings'} = {'caption' => $tr{'log settings'},
415 'uri' => '/cgi-bin/logs.cgi/config.dat',
416 'title' => "$tr{'log settings'}",
419 $sublogs->{'03.proxy'} = {'caption' => $tr{'proxy logs'},
420 'uri' => '/cgi-bin/logs.cgi/proxylog.dat',
421 'title' => "$tr{'proxy log viewer'}",
424 $sublogs->{'04.firewall'} = {'caption' => $tr{'firewall logs'},
425 'uri' => '/cgi-bin/logs.cgi/firewalllog.dat',
426 'title' => "$tr{'firewall log viewer'}",
429 $sublogs->{'05.ids'} = {'caption' => $tr{'ids logs'},
430 'uri' => '/cgi-bin/logs.cgi/ids.dat',
431 'title' => "$tr{'intrusion detection system log viewer'}",
434 $sublogs->{'06.contentfilter'} = {'caption' => $tr{'content filter logs'},
435 'uri' => '/cgi-bin/logs.cgi/dansguardian.dat',
436 'title' => "$tr{'content filter log viewer'}",
439 $sublogs->{'07.urlfilter'} = {
440 'caption' => $tr{'urlfilter log'},
441 'uri' => '/cgi-bin/logs.cgi/urlfilter.dat',
442 'title' => "$tr{'urlfilter log'}",
445 $sublogs->{'08.openvpn'} = {'caption' => $tr{'openvpn log'},
446 'uri' => '/cgi-bin/logs.cgi/openvpn.dat',
447 'title' => "$tr{'openvpn log'}",
450 $sublogs->{'09.system'} = {'caption' => $tr{'system logs'},
451 'uri' => '/cgi-bin/logs.cgi/log.dat',
452 'title' => "$tr{'system log viewer'}",
455 $sublogs->{'10.userlog'} = {'caption' => $tr{'user proxy logs'},
456 'uri' => '/cgi-bin/logs.cgi/userlog.dat',
457 'title' => "$tr{'user log viewer'}",
462 $menu->{'01.system'} = {'caption' => $tr{'alt system'},
464 'subMenu' => $subsystem
466 $menu->{'02.status'} = {'caption' => $tr{'status'},
468 'subMenu' => $substatus
470 $menu->{'03.network'} = {'caption' => $tr{'network'},
472 'subMenu' => $subnetwork
474 $menu->{'04.services'} = {'caption' => $tr{'alt services'},
476 'subMenu' => $subservices
478 $menu->{'05.firewall'} = {'caption' => $tr{'firewall'},
480 'subMenu' => $subfirewall
482 $menu->{'06.proxy'} = {'caption' => $tr{'alt proxy'},
484 'subMenu' => $subproxy
486 $menu->{'07.vpn'} = {'caption' => 'VPN',
490 $menu->{'08.logs'} = {'caption' => $tr{'alt logs'},
492 'subMenu' => $sublogs
497 if (! blue_used
() && ! orange_used
()) {
498 $menu->{'05.firewall'}{'subMenu'}->{'03.dmz'}{'enabled'} = 0;
500 if (-e
'/etc/FLASH') {
501 $menu{'06.proxy'}{'subMenu'}->{'01.http'}{'subMenu'}->{'01.proxy'}{'enabled'} = 0; #disable squid
502 $menu{'04.services'}{'subMenu'}->{'05.ids'}{'enabled'} = 0; #disable ids
503 $menu{'08.logs'}{'subMenu'}->{'05.ids'}{'enabled'} = 0; #disable ids
509 print "Pragma: no-cache\n";
510 print "Cache-control: no-cache\n";
511 print "Connection: close\n";
512 print "Content-type: text/html\n\n";
515 sub is_menu_visible
($) {
518 return (-e
$ENV{'DOCUMENT_ROOT'}."/../$link");
524 if (! $root->{'enabled'}) {
527 if ($root->{'uri'} !~ /^$/) {
529 if ($root->{'vars'} !~ /^$/) {
530 $vars = '?'. $root->{'vars'};
532 if (! is_menu_visible
($root->{'uri'})) {
535 return $root->{'uri'}.$vars;
537 my $submenus = $root->{'subMenu'};
541 foreach my $item (sort keys %$submenus) {
542 my $link = getlink
($submenus->{$item});
554 my $uri = $conf->{'uri'};
555 my $vars = $conf->{'vars'};
556 my $novars = $conf->{'novars'};
561 if ($uri ne $URI[0]) {
565 if ($URI[1] !~ /^$/) {
572 return ($URI[1] eq $vars);
582 foreach my $item (sort keys %$root) {
583 my $val = $root->{$item};
584 if (compare_url
($val)) {
585 $val->{'selected'} = 1;
586 if ($val->{'title'} !~ /^$/) {
587 return $val->{'title'};
589 return 'EMPTY TITLE';
592 my $title = gettitle
($val->{'subMenu'});
594 $val->{'selected'} = 1;
608 foreach my $k1 ( sort keys %$menu ) {
609 if (! $menu->{$k1}{'enabled'}) {
613 my $link = getlink
($menu->{$k1});
617 if (! is_menu_visible
($link)) {
620 if ($menu->{$k1}->{'selected'}) {
621 print '<li class="selected">';
627 <div class="rcorner">
628 <a href="$link">$menu->{$k1}{'caption'}</a>
648 foreach my $item (%$root) {
649 if ($root->{$item}{'selected'}) {
650 return $root->{$item};
655 sub showsubsection
($$) {
665 my $selected = getselected
($root);
669 my $submenus = $selected->{'subMenu'};
679 foreach my $item (sort keys %$submenus) {
680 my $hash = $submenus->{$item};
681 if (! $hash->{'enabled'}) {
685 my $link = getlink
($hash);
689 if (! is_menu_visible
($link)) {
692 if ($hash->{'selected'}) {
693 print '<li class="selected">';
699 <a href="$link">$hash->{'caption'}</a>
714 sub showsubsubsection
($) {
719 my $selected = getselected
($root);
723 if (! $selected->{'subMenu'}) {
727 showsubsection
($selected->{'subMenu'}, 'menu-subtop');
733 if ($URI[0] =~ /.*\/([^\
/]+)\.cgi/) {
738 $helpfile .= '.help.html';
740 my $helpuri = '/doc/'.$language.'/'.$helpfile;
741 if (! -e
$ENV{'DOCUMENT_ROOT'}.$helpuri) {
751 my $extrahead = shift;
753 @URI=split ('\?', $ENV{'REQUEST_URI'} );
754 &readhash
("${swroot}/main/settings", \
%settings);
757 my $h2 = gettitle
($menu);
758 my $helpuri = get_helpuri
();
760 $title = "IPFire - $title";
761 if ($settings{'WINDOWWITHHOSTNAME'} eq 'on') {
762 $title = "$settings{'HOSTNAME'}.$settings{'DOMAINNAME'} - $title";
767 PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
768 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
772 <title>$title</title>
775 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
776 <link rel="shortcut icon" href="/favicon.ico" />
777 <style type="text/css">\@import url(/include/style.css);</style>
778 <style type="text/css">\@import url(/include/menu.css);</style>
779 <style type="text/css">\@import url(/include/content.css);</style>
781 <script language="javascript" type="text/javascript">
783 function swapVisibility(id) {
784 el = document.getElementById(id);
785 if(el.style.display != 'block') {
786 el.style.display = 'block'
789 el.style.display = 'none'
796 <!-- IPFIRE HEADER -->
801 <img id="logo-product" src="/images/logo_ipfire.gif">
802 <img id="logo-ipfire" src="/images/logo_ipfire2.gif">
803 <div id="header-icons">
807 if ($helpuri ne '') {
809 <a href="$helpuri" target="_blank"><img border="0" src="/images/help.gif"></a>
813 print '<img src="/images/help.gif">';
833 &showsubsection
($menu);
838 <td width="100%" valign="top">
839 <div id="page-content">
844 &showsubsubsection
($menu);
847 require 'ipfire-network.pl';
848 $supported = check_support
();
849 warn_unsupported
($supported);
854 my $status = &connectionstatus
();
855 $uptime = `/usr/bin/uptime`;
860 <div style="font-size: 9px"><b>Status:</b> $status <b>Uptime:</b>$uptime</div>
862 <p><a href="http://www.ipfire.org">IPFire</a> $version (c)</p>
865 <meta http-equiv="Page-Enter" content="blendTrans(Duration=1.0,Transition=12)">
866 <meta http-equiv="Page-Exit" content="blendTrans(Duration=1.0,Transition=12)">
879 $bgcolor = "style='background-color: $colourerr;'";
887 # print "</td></tr></table></td></tr></table>\n"
896 if ($caption) { print "<h3>$caption</h3>\n"; } else { print " "; }
898 print "<table class=\"list\"><tr><td align=\"$align\">\n";
903 print "</td></tr></table><br><br>";
908 my $filename = $_[0];
911 # write cgi vars to the file.
912 open(FILE
, ">${filename}") or die "Unable to write file $filename";
914 foreach $var (keys %$hash)
916 $val = $hash->{$var};
917 # Darren Critchley Jan 17, 2003 added the following because when submitting with a graphic, the x and y
918 # location of the mouse are submitted as well, this was being written to the settings file causing
919 # some serious grief! This skips the variable.x and variable.y
920 if (!($var =~ /(.x|.y)$/)) {
923 if (!($var =~ /^ACTION/)) {
924 print FILE
"${var}=${val}\n"; }
932 my $filename = $_[0];
936 open(FILE
, $filename) or die "Unable to read file $filename";
941 ($var, $val) = split /=/, $_, 2;
947 # Untaint variables read from hash
948 $var =~ /([A-Za-z0-9_-]*)/; $var = $1;
949 $val =~ /([\w\W]*)/; $val = $1;
950 $hash->{$var} = $val;
957 my ($hash, $params) = @_;
958 my $cgi = CGI
->new ();
959 $hash->{'__CGI__'} = $cgi;
960 return if ($ENV{'REQUEST_METHOD'} ne 'POST');
961 if (!$params->{'wantfile'}) {
962 $CGI::DISABLE_UPLOADS
= 1;
963 $CGI::POST_MAX
= 512 * 1024;
965 $CGI::POST_MAX
= 10 * 1024 * 1024;
968 $cgi->referer() =~ m/^https?\:\/\
/([^\/]+)/;
970 $cgi->url() =~ m/^https?\:\/\
/([^\/]+)/;
972 return if ($referer ne $servername);
974 ### Modified for getting multi-vars, split by |
975 %temp = $cgi->Vars();
976 foreach my $key (keys %temp) {
977 $hash->{$key} = $temp{$key};
978 $hash->{$key} =~ s/\0/|/g;
979 $hash->{$key} =~ s/^\s*(.*?)\s*$/$1/;
982 if (($params->{'wantfile'})&&($params->{'filevar'})) {
983 $hash->{$params->{'filevar'}} = $cgi->upload
984 ($params->{'filevar'});
991 my $logmessage = $_[0];
992 $logmessage =~ /([\w\W]*)/;
994 system('/usr/bin/logger', '-t', 'ipfire', $logmessage);
999 my ($dev, $ino, $mode, $nlink, $uid, $gid, $rdev, $size,
1000 $atime, $mtime, $ctime, $blksize, $blocks) = stat $_[0];
1003 my $totalsecs = $now - $mtime;
1004 my $days = int($totalsecs / 86400);
1005 my $totalhours = int($totalsecs / 3600);
1006 my $hours = $totalhours % 24;
1007 my $totalmins = int($totalsecs / 60);
1008 my $mins = $totalmins % 60;
1009 my $secs = $totalsecs % 60;
1011 return "${days}d ${hours}h ${mins}m ${secs}s";
1018 if (!($ip =~ /^(\d+)\.(\d+)\.(\d+)\.(\d+)$/)) {
1022 @octets = ($1, $2, $3, $4);
1023 foreach $_ (@octets)
1027 if ($_ < 0 || $_ > 255) {
1038 # secord part an ip?
1039 if (&validip
($mask)) {
1041 # second part a number?
1044 if (!($mask =~ /^\d+$/)) {
1046 if ($mask >= 0 && $mask <= 32) {
1053 my $ipormask = $_[0];
1055 # see if it is a IP only.
1056 if (&validip
($ipormask)) {
1058 # split it into number and mask.
1059 if (!($ipormask =~ /^(.*?)\/(.*?
)$/)) {
1063 # first part not a ip?
1064 if (!(&validip
($ip))) {
1066 return &validmask
($mask);
1071 my $ipandmask = $_[0];
1073 # split it into number and mask.
1074 if (!($ipandmask =~ /^(.*?)\/(.*?
)$/)) {
1078 # first part not a ip?
1079 if (!(&validip
($ip))) {
1081 return &validmask
($mask);
1092 if ($_ >= 1 && $_ <= 65535) {
1099 my $checkmac = $_[0];
1100 my $ot = '[0-9a-f]{2}'; # 2 Hex digits (one octet)
1101 if ($checkmac !~ /^$ot:$ot:$ot:$ot:$ot:$ot$/i)
1110 # Checks a hostname against RFC1035
1111 my $hostname = $_[0];
1113 # Each part should be at least two characters in length
1114 # but no more than 63 characters
1115 if (length ($hostname) < 2 || length ($hostname) > 63) {
1117 # Only valid characters are a-z, A-Z, 0-9 and -
1118 if ($hostname !~ /^[a-zA-Z0-9-]*$/) {
1120 # First character can only be a letter or a digit
1121 if (substr ($hostname, 0, 1) !~ /^[a-zA-Z0-9]*$/) {
1123 # Last character can only be a letter or a digit
1124 if (substr ($hostname, -1, 1) !~ /^[a-zA-Z0-9]*$/) {
1131 # Checks a domain name against RFC1035
1132 my $domainname = $_[0];
1133 my @parts = split (/\./, $domainname); # Split hostname at the '.'
1135 foreach $part (@parts) {
1136 # Each part should be at least two characters in length
1137 # but no more than 63 characters
1138 if (length ($part) < 2 || length ($part) > 63) {
1140 # Only valid characters are a-z, A-Z, 0-9 and -
1141 if ($part !~ /^[a-zA-Z0-9-]*$/) {
1143 # First character can only be a letter or a digit
1144 if (substr ($part, 0, 1) !~ /^[a-zA-Z0-9]*$/) {
1146 # Last character can only be a letter or a digit
1147 if (substr ($part, -1, 1) !~ /^[a-zA-Z0-9]*$/) {
1155 # Checks a fully qualified domain name against RFC1035
1157 my @parts = split (/\./, $fqdn); # Split hostname at the '.'
1158 if (scalar(@parts) < 2) { # At least two parts should
1159 return 0;} # exist in a FQDN
1160 # (i.e. hostname.domain)
1161 foreach $part (@parts) {
1162 # Each part should be at least two characters in length
1163 # but no more than 63 characters
1164 if (length ($part) < 2 || length ($part) > 63) {
1166 # Only valid characters are a-z, A-Z, 0-9 and -
1167 if ($part !~ /^[a-zA-Z0-9-]*$/) {
1169 # First character can only be a letter or a digit
1170 if (substr ($part, 0, 1) !~ /^[a-zA-Z0-9]*$/) {
1172 # Last character can only be a letter or a digit
1173 if (substr ($part, -1, 1) !~ /^[a-zA-Z0-9]*$/) {
1179 sub validportrange
# used to check a port range
1181 my $port = $_[0]; # port values
1182 $port =~ tr/-/:/; # replace all - with colons just in case someone used -
1183 my $srcdst = $_[1]; # is it a source or destination port
1185 if (!($port =~ /^(\d+)\:(\d+)$/)) {
1187 if (!(&validport
($port))) {
1188 if ($srcdst eq 'src'){
1189 return $tr{'source port numbers'};
1191 return $tr{'destination port numbers'};
1199 if ($srcdst eq 'src'){
1200 return $tr{'bad source range'};
1202 return $tr{'bad destination range'};
1207 if (!(&validport
($_))) {
1208 if ($srcdst eq 'src'){
1209 return $tr{'source port numbers'};
1211 return $tr{'destination port numbers'};
1219 # Test if IP is within a subnet
1220 # Call: IpInSubnet (Addr, Subnet, Subnet Mask)
1221 # Subnet can be an IP of the subnet: 10.0.0.0 or 10.0.0.1
1222 # Everything in dottted notation
1223 # Return: TRUE/FALSE
1226 $ip = unpack('N', inet_aton
(shift));
1227 $start = unpack('N', inet_aton
(shift));
1228 $mask = unpack('N', inet_aton
(shift));
1229 $start &= $mask; # base of subnet...
1230 $end = $start + ~$mask;
1231 return (($ip >= $start) && ($ip <= $end));
1236 return 0 if ( $mail !~ /^[0-9a-zA-Z\.\-\_]+\@[0-9a-zA-Z\.\-]+$/ );
1237 return 0 if ( $mail =~ /^[^0-9a-zA-Z]|[^0-9a-zA-Z]$/);
1238 return 0 if ( $mail !~ /([0-9a-zA-Z]{1})\@./ );
1239 return 0 if ( $mail !~ /.\@([0-9a-zA-Z]{1})/ );
1240 return 0 if ( $mail =~ /.\.\-.|.\-\..|.\.\..|.\-\-./g );
1241 return 0 if ( $mail =~ /.\.\_.|.\-\_.|.\_\..|.\_\-.|.\_\_./g );
1242 return 0 if ( $mail !~ /\.([a-zA-Z]{2,3})$/ );
1247 my ($filename, $hash) = @_;
1249 open(FILE
, $filename) or die "Unable to read file $filename";
1252 my ($key, $rest, @temp);
1254 ($key, $rest) = split (/,/, $_, 2);
1255 if ($key =~ /^[0-9]+$/ && $rest) {
1256 @temp = split (/,/, $rest);
1257 $hash->{$key} = \
@temp;
1264 sub writehasharray
{
1265 my ($filename, $hash) = @_;
1268 open(FILE
, ">$filename") or die "Unable to write to file $filename";
1270 foreach $key (keys %$hash) {
1271 if ( $hash->{$key} ) {
1273 foreach $i (0 .. $#{$hash->{$key}}) {
1274 print FILE
",$hash->{$key}[$i]";
1283 sub findhasharraykey
{
1284 foreach my $i (1 .. 1000000) {
1285 if ( ! exists $_[0]{$i}) {
1293 my $outstring =$_[0];
1294 $outstring =~ tr/,/ / if not defined $_[1] or $_[1] ne 'y';
1295 $outstring =~ s/&/&/g;
1296 $outstring =~ s/\'/'/g;
1297 $outstring =~ s/\"/"/g;
1298 $outstring =~ s/</</g;
1299 $outstring =~ s/>/>/g;
1302 sub connectionstatus
1305 opendir UPLINKS
, "/var/ipfire/uplinks" or die "Cannot read uplinks: $!";
1306 foreach my $uplink (sort grep !/^\./, readdir UPLINKS
) {
1307 if ( -f
"${swroot}/uplinks/${uplink}/active") {
1309 $timestr = &age
("${swroot}/uplinks/${uplink}/active");
1310 $status = "$tr{'connected'}: $uplink (<span class='ipcop_StatusBigRed'>$timestr</span>) ";
1312 $timestr = &age
("${swroot}/uplinks/${uplink}/active");
1313 $status = "$status , $uplink (<span class='ipcop_StatusBigRed'>$timestr</span>) ";
1315 } elsif ( -f
"${swroot}/uplinks/${uplink}/connecting") {
1317 $status = "$tr{'connecting'} $uplink";
1319 $status = "$status , $tr{'connecting'} $uplink (<span class='ipcop_StatusBigRed'>$timestr</span>) ";
1326 $status = "$tr{'idle'}";
1328 $connstate = "<span class='ipcop_StatusBig'>$status</span>";
1333 # Darren Critchley - darrenc@telus.net - (c) 2003
1334 # &srtarray(SortOrder, AlphaNumeric, SortDirection, ArrayToBeSorted)
1335 # This subroutine will take the following parameters:
1336 # ColumnNumber = the column which you want to sort on, starts at 1
1337 # AlphaNumberic = a or n (lowercase) defines whether the sort should be alpha or numberic
1338 # SortDirection = asc or dsc (lowercase) Ascending or Descending sort
1339 # ArrayToBeSorted = the array that wants sorting
1341 # Returns an array that is sorted to your specs
1343 # If SortOrder is greater than the elements in array, then it defaults to the first element
1346 my ($colno, $alpnum, $srtdir, @tobesorted) = @_;
1351 my $ttlitems = scalar @tobesorted; # want to know the number of rows in the passed array
1352 if ($ttlitems < 1){ # if no items, don't waste our time lets leave
1353 return (@tobesorted);
1355 my @tmp = split(/\,/,$tobesorted[0]);
1356 $ttlitems = scalar @tmp; # this should be the number of elements in each row of the passed in array
1358 # Darren Critchley - validate parameters
1359 if ($colno > $ttlitems){$colno = '1';}
1360 $colno--; # remove one from colno to deal with arrays starting at 0
1361 if($colno < 0){$colno = '0';}
1362 if ($alpnum ne '') { $alpnum = lc($alpnum); } else { $alpnum = 'a'; }
1363 if ($srtdir ne '') { $srtdir = lc($srtdir); } else { $srtdir = 'src'; }
1365 foreach $line (@tobesorted)
1369 my @temp = split(/\,/,$line);
1370 # Darren Critchley - juggle the fields so that the one we want to sort on is first
1371 my $tmpholder = $temp[0];
1372 $temp[0] = $temp[$colno];
1373 $temp[$colno] = $tmpholder;
1375 for ($ctr=0; $ctr < $ttlitems ; $ctr++) {
1376 $newline=$newline . $temp[$ctr] . ",";
1379 push(@tmparray,$newline);
1382 if ($alpnum eq 'n') {
1383 @tmparray = sort {$a <=> $b} @tmparray;
1385 @tmparray = (sort @tmparray);
1387 foreach $line (@tmparray)
1391 my @temp = split(/\,/,$line);
1392 my $tmpholder = $temp[0];
1393 $temp[0] = $temp[$colno];
1394 $temp[$colno] = $tmpholder;
1396 for ($ctr=0; $ctr < $ttlitems ; $ctr++){
1397 $newline=$newline . $temp[$ctr] . ",";
1400 push(@srtedarray,$newline);
1404 if ($srtdir eq 'dsc') {
1405 @tmparray = reverse(@srtedarray);
1408 return (@srtedarray);
1412 sub speedtouchversion
1414 if (-f
"/proc/bus/usb/devices")
1416 $speedtouch=`/bin/cat /proc/bus/usb/devices | /bin/grep 'Vendor=06b9 ProdID=4061' | /usr/bin/cut -d ' ' -f6`;
1417 if ($speedtouch eq '') {
1418 $speedtouch= $tr{'connect the modem'};
1421 $speedtouch='USB '.$tr{'not running'};
1426 sub CheckSortOrder
{
1427 #Sorting of allocated leases
1428 if ($ENV{'QUERY_STRING'} =~ /^IPADDR|^ETHER|^HOSTNAME|^ENDTIME/ ) {
1429 my $newsort=$ENV{'QUERY_STRING'};
1430 &readhash
("${swroot}/dhcp/settings", \
%dhcpsettings);
1431 $act=$dhcpsettings{'SORT_LEASELIST'};
1433 if ($act =~ $newsort) {
1434 if ($act !~ 'Rev') {$Rev='Rev'};
1438 $dhcpsettings{'SORT_LEASELIST'}=$newsort;
1439 &writehash
("${swroot}/dhcp/settings", \
%dhcpsettings);
1440 $dhcpsettings{'ACTION'} = 'SORT'; # avoid the next test "First lauch"
1445 sub PrintActualLeases
1447 &openbox
('100%', 'left', $tr{'current dynamic leases'});
1449 <table width='100%'>
1451 <td width='25%' align='center'><a href='$ENV{'SCRIPT_NAME'}?IPADDR'><b>$tr{'ip address'}</b></a></td>
1452 <td width='25%' align='center'><a href='$ENV{'SCRIPT_NAME'}?ETHER'><b>$tr{'mac address'}</b></a></td>
1453 <td width='20%' align='center'><a href='$ENV{'SCRIPT_NAME'}?HOSTNAME'><b>$tr{'hostname'}</b></a></td>
1454 <td width='30%' align='center'><a href='$ENV{'SCRIPT_NAME'}?ENDTIME'><b>$tr{'lease expires'} (local time d/m/y)</b></a></td>
1459 open(LEASES
,"/var/lib/dhcp/dhcpd.leases") or die "Can't open dhcpd.leases";
1460 while ($line = <LEASES
>) {
1461 next if( $line =~ /^\s*#/ );
1463 @temp = split (' ', $line);
1465 if ($line =~ /^\s*lease/) {
1467 #All field are not necessarily read. Clear everything
1473 if ($line =~ /^\s*ends/) {
1474 $line =~ /(\d+)\/(\d
+)\
/(\d+) (\d+):(\d+):(\d+)/;
1475 $endtime = timegm
($6, $5, $4, $3, $2 - 1, $1 - 1900);
1478 if ($line =~ /^\s*hardware ethernet/) {
1483 if ($line =~ /^\s*client-hostname/) {
1484 $hostname = "$temp[1] $temp[2] $temp[3]";
1485 $hostname =~ s/;//g;
1486 $hostname =~ s/\"//g;
1490 @record = ('IPADDR',$ip,'ENDTIME',$endtime,'ETHER',$ether,'HOSTNAME',$hostname);
1491 $record = {}; # create a reference to empty hash
1492 %{$record} = @record; # populate that hash with @record
1493 $entries{$record->{'IPADDR'}} = $record; # add this to a hash of hashes
1499 foreach my $key (sort leasesort
keys %entries) {
1501 my $hostname = &cleanhtml
($entries{$key}->{HOSTNAME
},"y");
1504 print "<tr bgcolor='$table1colour'>";
1507 print "<tr bgcolor='$table2colour'>";
1511 <td align='center'>$entries{$key}->{IPADDR}</td>
1512 <td align='center'>$entries{$key}->{ETHER}</td>
1513 <td align='center'> $hostname </td>
1518 ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $dst) = localtime ($entries{$key}->{ENDTIME
});
1519 $enddate = sprintf ("%02d/%02d/%d %02d:%02d:%02d",$mday,$mon+1,$year+1900,$hour,$min,$sec);
1521 if ($entries{$key}->{ENDTIME
} < time() ){
1522 print "<strike>$enddate</strike>";
1535 # This sub is used during display of actives leases
1537 if (rindex ($dhcpsettings{'SORT_LEASELIST'},'Rev') != -1)
1539 $qs=substr ($dhcpsettings{'SORT_LEASELIST'},0,length($dhcpsettings{'SORT_LEASELIST'})-3);
1540 if ($qs eq 'IPADDR') {
1541 @a = split(/\./,$entries{$a}->{$qs});
1542 @b = split(/\./,$entries{$b}->{$qs});
1548 $entries{$b}->{$qs} cmp $entries{$a}->{$qs};
1553 $qs=$dhcpsettings{'SORT_LEASELIST'};
1554 if ($qs eq 'IPADDR') {
1555 @a = split(/\./,$entries{$a}->{$qs});
1556 @b = split(/\./,$entries{$b}->{$qs});
1562 $entries{$a}->{$qs} cmp $entries{$b}->{$qs};
1569 opendir(DIR
, "${swroot}/uplinks/") || return \
@uplinks;
1570 foreach my $dir (readdir(DIR
)) {
1571 next if ($dir =~ /^\./);
1572 next if (-f
"${swroot}/uplinks/$dir");
1573 push(@uplinks, $dir);
1580 my $filename = shift;
1582 open (F
, $filename) || return "";
1589 sub get_red_ifaces_by_type
($) {
1591 my @gottypeiface = ();
1592 my @gottypeuplink = ();
1595 my $ref=get_uplinks
();
1598 foreach my $link (@uplinks) {
1600 &readhash
("${swroot}/uplinks/$link/settings", \
%set);
1602 push(@gottype, $link);
1604 my $iface = $set{'RED_DEV'};
1606 $iface = get_iface
("${swroot}/uplinks/$link/interface");
1610 if ($set{'RED_TYPE'} eq $type) {
1611 push(@gottypeiface, $iface);
1612 push(@gottypeuplink, $link);
1615 return (\
@gottypeiface, \
@gottypeuplink, \
@gottype);
1618 sub get_red_ifaces
() {
1619 return `cat ${swroot}/uplinks/*/interface 2>/dev/null`;
1622 sub get_zone_devices
($) {
1625 open (FILE
, "${swroot}/ethernet/$bridge") || return "";
1626 foreach my $line (<FILE
>) {
1629 push(@ifaces, $line);