]>
git.ipfire.org Git - ipfire-2.x.git/blob - config/cfgroot/header.pl
d07a2133a415188c7c6d69f7ebdef5ec4eee6f14
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()
18 $|=1; # line buffering
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
= '';
42 my $menu = \
%menuhash;
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";
55 ### Initialize environment
56 &readhash
("${swroot}/main/settings", \
%settings);
57 &readhash
("${swroot}/ethernet/settings", \
%ethsettings);
58 $language = $settings{'LANGUAGE'};
59 $hostname = $settings{'HOSTNAME'};
62 ### Initialize language
63 if ($language =~ /^(\w+)$/) {$language = $1;}
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}";
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}";
91 require "${swroot}/langs/en.pl";
92 require "${swroot}/langs/${language}.pl";
95 if ($ethsettings{'CONFIG_TYPE'} =~ /^[1357]$/) {
102 if ($ethsettings{'CONFIG_TYPE'} =~ /^[4567]$/) {
109 if ($ethsettings{'CONFIG_TYPE'} =~ /^[0145]$/) {
117 my %subsystemhash = ();
118 my $subsystem = \
%subsystemhash;
120 $subsystem->{'01.home'} = {
121 'caption' => $tr{'alt home'},
122 'uri' => '/cgi-bin/index.cgi',
123 'title' => "$tr{'alt home'}",
126 $subsystem->{'02.passwords'} = {
127 'caption' => $tr{'sspasswords'},
128 'uri' => '/cgi-bin/changepw.cgi',
129 'title' => "$tr{'sspasswords'}",
132 $subsystem->{'03.ssh'} = {
133 'caption' => $tr{'ssh access'},
134 'uri' => '/cgi-bin/remote.cgi',
135 'title' => "$tr{'ssh access'}",
138 $subsystem->{'04.gui'} = {
139 'caption' => $tr{'gui settings'},
140 'uri' => '/cgi-bin/gui.cgi',
141 'title' => "$tr{'gui settings'}",
144 $subsystem->{'05.shutdown'} = {
145 'caption' => $tr{'shutdown'},
146 'uri' => '/cgi-bin/shutdown.cgi',
147 'title' => "$tr{'shutdown'} / $tr{'reboot'}",
150 $subsystem->{'99.credits'} = {
151 'caption' => $tr{'credits'},
152 'uri' => '/cgi-bin/credits.cgi',
153 'title' => "$tr{'credits'}",
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'}",
165 $substatus->{'02.networkstatus'} = {
166 'caption' => $tr{'ssnetwork status'},
167 'uri' => '/cgi-bin/netstatus.cgi',
168 'title' => "$tr{'ssnetwork status'}",
171 $substatus->{'03.systemgraphs'} = {
172 'caption' => $tr{'system graphs'},
173 'uri' => '/cgi-bin/graphs.cgi',
175 'title' => "$tr{'system graphs'}",
178 $substatus->{'04.trafficgraphs'} = {
179 'caption' => $tr{'sstraffic graphs'},
180 'uri' => '/cgi-bin/graphs.cgi',
181 'vars' => 'graph=network',
182 'title' => "$tr{'sstraffic graphs'}",
185 $substatus->{'05.proxygraphs'} = {
186 'caption' => $tr{'ssproxy graphs'},
187 'uri' => '/cgi-bin/proxygraphs.cgi',
188 'title' => "$tr{'ssproxy graphs'}",
191 $substatus->{'06.fwhits'} = {
192 'caption' => 'Firewallhits',
193 'uri' => '/cgi-bin/fwhits.cgi',
194 'title' => "IPFire Firewallhits",
197 $substatus->{'07.connections'} = {
198 'caption' => $tr{'connections'},
199 'uri' => '/cgi-bin/connections.cgi',
200 'title' => "$tr{'connections'}",
203 $substatus->{'08.nettraf'} = {
204 'caption' => $tr{'sstraffic'},
205 'uri' => '/cgi-bin/traffic.cgi',
206 'title' => "$tr{'sstraffic'}",
209 $substatus->{'99.iptfilters'} = {
210 'caption' => $tr{'iptfilters iptable rules'},
211 'uri' => '/cgi-bin/iptfilters.cgi',
212 'title' => "$tr{'iptfilters iptable rules'}",
216 my %subnetworkhash = ();
217 my $subnetwork = \
%subnetworkhash;
219 $subnetwork->{'01.proxy'} = {'caption' => 'Webproxy',
220 'uri' => '/cgi-bin/proxy.cgi',
221 'title' => "Webproxy",
224 $subnetwork->{'02.urlfilter'} = {'caption' => 'URL-Filter',
225 'uri' => '/cgi-bin/urlfilter.cgi',
226 'title' => "URL-Filter",
229 $subnetwork->{'03.dhcp'} = {'caption' => $tr{'dhcp server'},
230 'uri' => '/cgi-bin/dhcp.cgi',
231 'title' => "$tr{'dhcp server'}",
234 $subnetwork->{'04.dialup'} = {
235 'caption' => $tr{'alt dialup'},
236 'uri' => '/cgi-bin/pppsetup.cgi',
237 'title' => "$tr{'alt dialup'}",
240 $subnetwork->{'05.hosts'} = {
241 'caption' => $tr{'edit hosts'},
242 'uri' => '/cgi-bin/hosts.cgi',
243 'title' => "$tr{'edit hosts'}",
246 $subnetwork->{'06.upload'} = {
247 'caption' => $tr{'upload'},
248 'uri' => '/cgi-bin/upload.cgi',
249 'title' => "$tr{'upload'}",
252 $subnetwork->{'07.aliases'} = {
253 'caption' => $tr{'aliases'},
254 'uri' => '/cgi-bin/aliases.cgi',
255 'title' => "$tr{'aliases'}",
259 my %subserviceshash = ();
260 my $subservices = \
%subserviceshash;
263 $subservices->{'01.openvpn'} = {
264 'caption' => 'OpenVPN',
265 'uri' => '/cgi-bin/ovpnmain.cgi',
266 'title' => "$tr{'virtual private networking'}",
269 $subservices->{'02.ipsec'} = {
270 'caption' => 'IPSec',
271 'uri' => '/cgi-bin/vpnmain.cgi',
272 'title' => "$tr{'virtual private networking'}",
275 $subservices->{'03.dyndns'} = {'caption' => $tr{'dynamic dns'},
276 'uri' => '/cgi-bin/ddns.cgi',
277 'title' => "$tr{'dynamic dns'}",
280 $subservices->{'04.time'} = {'caption' => $tr{'time server'},
281 'uri' => '/cgi-bin/time.cgi',
282 'title' => "$tr{'time server'}",
285 $subservices->{'05.qos'} = {'caption' => 'Quality of Service',
286 'uri' => '/cgi-bin/qos.cgi',
287 'title' => "Quality of Service",
290 $subservices->{'06.ids'} = {'caption' => $tr{'intrusion detection'},
292 'uri' => '/cgi-bin/ids.cgi',
293 'title' => "$tr{'intrusion detection system'} (Snort)",
298 my %subfirewallhash = ();
299 my $subfirewall = \
%subfirewallhash;
302 $subfirewall->{'01.dnat'} = {
303 'caption' => $tr{'ssport forwarding'},
304 'uri' => '/cgi-bin/portfw.cgi',
305 'title' => "$tr{'ssport forwarding'}",
308 $subfirewall->{'02.xtaccess'} = {
309 'caption' => $tr{'external access'},
310 'uri' => '/cgi-bin/xtaccess.cgi',
311 'title' => "$tr{'external access'}",
314 $subfirewall->{'03.wireless'} = {
315 'caption' => $tr{'blue access'},
316 'uri' => '/cgi-bin/wireless.cgi',
317 'title' => "$tr{'blue access'}",
320 $subfirewall->{'04.dmz'} = {
321 'caption' => $tr{'ssdmz pinholes'},
322 'uri' => '/cgi-bin/dmzholes.cgi',
323 'title' => "$tr{'ssdmz pinhole'}",
326 $subfirewall->{'05.outgoing'} = {
327 'caption' => $tr{'outgoing firewall'},
328 'uri' => '/cgi-bin/outgoingfw.cgi',
329 'title' => "$tr{'outgoing firewall'}",
332 $subfirewall->{'06.fwopts'} = {
333 'caption' => $tr{'options fw'},
334 'uri' => '/cgi-bin/optionsfw.cgi',
335 'title' => "$tr{'options fw'}",
339 my %sublogshash = ();
340 my $sublogs = \
%sublogshash;
342 $sublogs->{'01.summary'} = {'caption' => $tr{'log summary'},
343 'uri' => '/cgi-bin/logs.cgi/summary.dat',
344 'title' => "$tr{'log summary'}",
347 $sublogs->{'02.settings'} = {'caption' => $tr{'log settings'},
348 'uri' => '/cgi-bin/logs.cgi/config.dat',
349 'title' => "$tr{'log settings'}",
352 $sublogs->{'03.proxy'} = {'caption' => $tr{'proxy logs'},
353 'uri' => '/cgi-bin/logs.cgi/proxylog.dat',
354 'title' => "$tr{'proxy log'}",
357 $sublogs->{'04.firewall'} = {'caption' => $tr{'firewall logs'},
358 'uri' => '/cgi-bin/logs.cgi/firewalllog.dat',
359 'title' => "$tr{'firewall logs'}",
362 $sublogs->{'05.ids'} = {'caption' => $tr{'ids logs'},
363 'uri' => '/cgi-bin/logs.cgi/ids.dat',
364 'title' => "$tr{'ids logs'}",
367 $sublogs->{'07.urlfilter'} = {
368 'caption' => $tr{'urlfilter log'},
369 'uri' => '/cgi-bin/logs.cgi/urlfilter.dat',
370 'title' => "$tr{'urlfilter log'}",
373 $sublogs->{'08.openvpn'} = {'caption' => $tr{'openvpn log'},
374 'uri' => '/cgi-bin/logs.cgi/openvpn.dat',
375 'title' => "$tr{'openvpn log'}",
378 $sublogs->{'09.system'} = {'caption' => $tr{'system logs'},
379 'uri' => '/cgi-bin/logs.cgi/log.dat',
380 'title' => "$tr{'system log'}",
383 $sublogs->{'10.userlog'} = {'caption' => $tr{'user proxy logs'},
384 'uri' => '/cgi-bin/logs.cgi/userlog.dat',
385 'title' => "$tr{'user log'}",
389 my %subipfirehash = ();
390 my $subipfire = \
%subipfirehash;
391 $subipfire->{'01.pakfire'} = {'caption' => $tr{'pakfire'},
392 'uri' => '/cgi-bin/pakfire.cgi',
393 'title' => "$tr{'paketmanager'}",
396 $subipfire->{'02.asterisk'} = {'caption' => $tr{'asterisk'},
397 'uri' => '/cgi-bin/asterisk.cgi',
398 'title' => "$tr{'asterisk'}",
401 $subipfire->{'02.samba'} = {'caption' => $tr{'samba'},
402 'uri' => '/cgi-bin/samba.cgi',
403 'title' => "$tr{'samba'}",
406 $subipfire->{'99.help'} = {'caption' => $tr{'help'},
407 'uri' => '/cgi-bin/help.cgi',
408 'title' => "$tr{'help'}",
414 $menu->{'01.system'} = {'caption' => $tr{'alt system'},
416 'subMenu' => $subsystem
418 $menu->{'02.status'} = {'caption' => $tr{'status'},
420 'subMenu' => $substatus
422 $menu->{'03.network'} = {'caption' => $tr{'network'},
424 'subMenu' => $subnetwork
426 $menu->{'04.services'} = {'caption' => $tr{'alt services'},
428 'subMenu' => $subservices
430 $menu->{'05.firewall'} = {'caption' => $tr{'firewall'},
432 'subMenu' => $subfirewall
434 $menu->{'06.proxy'} = {'caption' => $tr{'alt proxy'},
436 'subMenu' => $subproxy
438 $menu->{'07.ipfire'} = {'caption' => 'IPFire',
440 'subMenu' => $subipfire
442 $menu->{'08.logs'} = {'caption' => $tr{'alt logs'},
444 'subMenu' => $sublogs
447 if (! blue_used
() && ! orange_used
()) {
448 $menu->{'05.firewall'}{'subMenu'}->{'04.dmz'}{'enabled'} = 0;
451 $menu->{'05.firewall'}{'subMenu'}->{'03.wireless'}{'enabled'} = 0;
453 if (! $ethsettings{'CONFIG_TYPE'} =~ /^(2|3|6|7)$/ && $ethsettings{'RED_TYPE'} eq 'STATIC' ) {
454 $menu->{'03.network'}{'subMenu'}->{'04.aliases'}{'enabled'} = 0;
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";
466 sub is_menu_visible
($) {
469 return (-e
$ENV{'DOCUMENT_ROOT'}."/../$link");
475 if (! $root->{'enabled'}) {
478 if ($root->{'uri'} !~ /^$/) {
480 if ($root->{'vars'} !~ /^$/) {
481 $vars = '?'. $root->{'vars'};
483 if (! is_menu_visible
($root->{'uri'})) {
486 return $root->{'uri'}.$vars;
488 my $submenus = $root->{'subMenu'};
492 foreach my $item (sort keys %$submenus) {
493 my $link = getlink
($submenus->{$item});
505 my $uri = $conf->{'uri'};
506 my $vars = $conf->{'vars'};
507 my $novars = $conf->{'novars'};
512 if ($uri ne $URI[0]) {
516 if ($URI[1] !~ /^$/) {
523 return ($URI[1] eq $vars);
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'};
540 return 'EMPTY TITLE';
543 my $title = gettitle
($val->{'subMenu'});
545 $val->{'selected'} = 1;
559 foreach my $k1 ( sort keys %$menu ) {
560 if (! $menu->{$k1}{'enabled'}) {
564 my $link = getlink
($menu->{$k1});
568 if (! is_menu_visible
($link)) {
571 if ($menu->{$k1}->{'selected'}) {
572 print '<li class="selected">';
578 <div class="rcorner">
579 <a href="$link">$menu->{$k1}{'caption'}</a>
599 foreach my $item (%$root) {
600 if ($root->{$item}{'selected'}) {
601 return $root->{$item};
606 sub showsubsection
($$) {
616 my $selected = getselected
($root);
620 my $submenus = $selected->{'subMenu'};
630 foreach my $item (sort keys %$submenus) {
631 my $hash = $submenus->{$item};
632 if (! $hash->{'enabled'}) {
636 my $link = getlink
($hash);
640 if (! is_menu_visible
($link)) {
643 if ($hash->{'selected'}) {
644 print '<li class="selected">';
650 <a href="$link">$hash->{'caption'}</a>
665 sub showsubsubsection
($) {
670 my $selected = getselected
($root);
674 if (! $selected->{'subMenu'}) {
678 showsubsection
($selected->{'subMenu'}, 'menu-subtop');
684 if ($URI[0] =~ /.*\/([^\
/]+)\.cgi/) {
689 $helpfile .= '.help.html';
691 my $helpuri = '/doc/'.$language.'/'.$helpfile;
692 if (! -e
$ENV{'DOCUMENT_ROOT'}.$helpuri) {
702 my $extrahead = shift;
704 @URI=split ('\?', $ENV{'REQUEST_URI'} );
705 &readhash
("${swroot}/main/settings", \
%settings);
708 my $h2 = gettitle
($menu);
709 my $helpuri = get_helpuri
();
711 $title = "IPFire - $title";
712 if ($settings{'WINDOWWITHHOSTNAME'} eq 'on') {
713 $title = "$settings{'HOSTNAME'}.$settings{'DOMAINNAME'} - $title";
718 PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
719 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
723 <title>$title</title>
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">
735 function swapVisibility(id) {
736 el = document.getElementById(id);
737 if(el.style.display != 'block') {
738 el.style.display = 'block'
741 el.style.display = 'none'
748 <!-- IPFIRE 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>
772 &showsubsection
($menu);
775 <p><center><img src="/images/iptux.png" width='160px' height='160px'></center></p>
777 <td width="100%" valign="top">
778 <div id="page-content">
783 &showsubsubsection
($menu);
786 require 'ipfire-network.pl';
787 $supported = check_support
();
788 warn_unsupported
($supported);
793 my $status = &connectionstatus
();
794 $uptime = `/usr/bin/uptime`;
799 <div style="font-size: 9px"><b>Status:</b> $status <b>Uptime:</b>$uptime</div>
815 $bgcolor = "style='background-color: $colourerr;'";
823 # print "</td></tr></table></td></tr></table>\n"
832 if ($caption) { print "<h3>$caption</h3>\n"; } else { print " "; }
834 print "<table class=\"list\"><tr><td align=\"$align\">\n";
839 print "</td></tr></table><br><br>";
844 my $filename = $_[0];
847 # write cgi vars to the file.
848 open(FILE
, ">${filename}") or die "Unable to write file $filename";
850 foreach $var (keys %$hash)
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)$/)) {
859 if (!($var =~ /^ACTION/)) {
860 print FILE
"${var}=${val}\n"; }
868 my $filename = $_[0];
872 open(FILE
, $filename) or die "Unable to read file $filename";
877 ($var, $val) = split /=/, $_, 2;
883 # Untaint variables read from hash
884 $var =~ /([A-Za-z0-9_-]*)/; $var = $1;
885 $val =~ /([\w\W]*)/; $val = $1;
886 $hash->{$var} = $val;
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;
901 $CGI::POST_MAX
= 10 * 1024 * 1024;
904 $cgi->referer() =~ m/^https?\:\/\
/([^\/]+)/;
906 $cgi->url() =~ m/^https?\:\/\
/([^\/]+)/;
908 return if ($referer ne $servername);
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/;
918 if (($params->{'wantfile'})&&($params->{'filevar'})) {
919 $hash->{$params->{'filevar'}} = $cgi->upload
920 ($params->{'filevar'});
927 my $logmessage = $_[0];
928 $logmessage =~ /([\w\W]*)/;
930 system('/usr/bin/logger', '-t', 'ipfire', $logmessage);
935 my ($dev, $ino, $mode, $nlink, $uid, $gid, $rdev, $size,
936 $atime, $mtime, $ctime, $blksize, $blocks) = stat $_[0];
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;
947 return "${days}d ${hours}h ${mins}m ${secs}s";
954 if (!($ip =~ /^(\d+)\.(\d+)\.(\d+)\.(\d+)$/)) {
958 @octets = ($1, $2, $3, $4);
963 if ($_ < 0 || $_ > 255) {
975 if (&validip
($mask)) {
977 # second part a number?
980 if (!($mask =~ /^\d+$/)) {
982 if ($mask >= 0 && $mask <= 32) {
989 my $ipormask = $_[0];
991 # see if it is a IP only.
992 if (&validip
($ipormask)) {
994 # split it into number and mask.
995 if (!($ipormask =~ /^(.*?)\/(.*?
)$/)) {
999 # first part not a ip?
1000 if (!(&validip
($ip))) {
1002 return &validmask
($mask);
1007 my $ipandmask = $_[0];
1009 # split it into number and mask.
1010 if (!($ipandmask =~ /^(.*?)\/(.*?
)$/)) {
1014 # first part not a ip?
1015 if (!(&validip
($ip))) {
1017 return &validmask
($mask);
1028 if ($_ >= 1 && $_ <= 65535) {
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)
1046 # Checks a hostname against RFC1035
1047 my $hostname = $_[0];
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) {
1053 # Only valid characters are a-z, A-Z, 0-9 and -
1054 if ($hostname !~ /^[a-zA-Z0-9-]*$/) {
1056 # First character can only be a letter or a digit
1057 if (substr ($hostname, 0, 1) !~ /^[a-zA-Z0-9]*$/) {
1059 # Last character can only be a letter or a digit
1060 if (substr ($hostname, -1, 1) !~ /^[a-zA-Z0-9]*$/) {
1067 # Checks a domain name against RFC1035
1068 my $domainname = $_[0];
1069 my @parts = split (/\./, $domainname); # Split hostname at the '.'
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) {
1076 # Only valid characters are a-z, A-Z, 0-9 and -
1077 if ($part !~ /^[a-zA-Z0-9-]*$/) {
1079 # First character can only be a letter or a digit
1080 if (substr ($part, 0, 1) !~ /^[a-zA-Z0-9]*$/) {
1082 # Last character can only be a letter or a digit
1083 if (substr ($part, -1, 1) !~ /^[a-zA-Z0-9]*$/) {
1091 # Checks a fully qualified domain name against RFC1035
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) {
1102 # Only valid characters are a-z, A-Z, 0-9 and -
1103 if ($part !~ /^[a-zA-Z0-9-]*$/) {
1105 # First character can only be a letter or a digit
1106 if (substr ($part, 0, 1) !~ /^[a-zA-Z0-9]*$/) {
1108 # Last character can only be a letter or a digit
1109 if (substr ($part, -1, 1) !~ /^[a-zA-Z0-9]*$/) {
1115 sub validportrange
# used to check a port range
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
1121 if (!($port =~ /^(\d+)\:(\d+)$/)) {
1123 if (!(&validport
($port))) {
1124 if ($srcdst eq 'src'){
1125 return $tr{'source port numbers'};
1127 return $tr{'destination port numbers'};
1135 if ($srcdst eq 'src'){
1136 return $tr{'bad source range'};
1138 return $tr{'bad destination range'};
1143 if (!(&validport
($_))) {
1144 if ($srcdst eq 'src'){
1145 return $tr{'source port numbers'};
1147 return $tr{'destination port numbers'};
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
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));
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})$/ );
1183 my ($filename, $hash) = @_;
1185 open(FILE
, $filename) or die "Unable to read file $filename";
1188 my ($key, $rest, @temp);
1190 ($key, $rest) = split (/,/, $_, 2);
1191 if ($key =~ /^[0-9]+$/ && $rest) {
1192 @temp = split (/,/, $rest);
1193 $hash->{$key} = \
@temp;
1200 sub writehasharray
{
1201 my ($filename, $hash) = @_;
1204 open(FILE
, ">$filename") or die "Unable to write to file $filename";
1206 foreach $key (keys %$hash) {
1207 if ( $hash->{$key} ) {
1209 foreach $i (0 .. $#{$hash->{$key}}) {
1210 print FILE
",$hash->{$key}[$i]";
1219 sub findhasharraykey
{
1220 foreach my $i (1 .. 1000000) {
1221 if ( ! exists $_[0]{$i}) {
1229 my $outstring =$_[0];
1230 $outstring =~ tr/,/ / if not defined $_[1] or $_[1] ne 'y';
1231 $outstring =~ s/&/&/g;
1232 $outstring =~ s/\'/'/g;
1233 $outstring =~ s/\"/"/g;
1234 $outstring =~ s/</</g;
1235 $outstring =~ s/>/>/g;
1238 sub connectionstatus
1241 opendir UPLINKS
, "/var/ipfire/uplinks" or die "Cannot read uplinks: $!";
1242 foreach my $uplink (sort grep !/^\./, readdir UPLINKS
) {
1243 if ( -f
"${swroot}/uplinks/${uplink}/active") {
1245 $timestr = &age
("${swroot}/uplinks/${uplink}/active");
1246 $status = "$tr{'connected'}: $uplink (<span class='ipcop_StatusBigRed'>$timestr</span>) ";
1248 $timestr = &age
("${swroot}/uplinks/${uplink}/active");
1249 $status = "$status , $uplink (<span class='ipcop_StatusBigRed'>$timestr</span>) ";
1251 } elsif ( -f
"${swroot}/uplinks/${uplink}/connecting") {
1253 $status = "$tr{'connecting'} $uplink";
1255 $status = "$status , $tr{'connecting'} $uplink (<span class='ipcop_StatusBigRed'>$timestr</span>) ";
1262 $status = "$tr{'idle'}";
1264 $connstate = "<span class='ipcop_StatusBig'>$status</span>";
1269 # Darren Critchley - darrenc@telus.net - (c) 2003
1270 # &srtarray(SortOrder, AlphaNumeric, SortDirection, ArrayToBeSorted)
1271 # This subroutine will take the following parameters:
1272 # ColumnNumber = the column which you want to sort on, starts at 1
1273 # AlphaNumberic = a or n (lowercase) defines whether the sort should be alpha or numberic
1274 # SortDirection = asc or dsc (lowercase) Ascending or Descending sort
1275 # ArrayToBeSorted = the array that wants sorting
1277 # Returns an array that is sorted to your specs
1279 # If SortOrder is greater than the elements in array, then it defaults to the first element
1282 my ($colno, $alpnum, $srtdir, @tobesorted) = @_;
1287 my $ttlitems = scalar @tobesorted; # want to know the number of rows in the passed array
1288 if ($ttlitems < 1){ # if no items, don't waste our time lets leave
1289 return (@tobesorted);
1291 my @tmp = split(/\,/,$tobesorted[0]);
1292 $ttlitems = scalar @tmp; # this should be the number of elements in each row of the passed in array
1294 # Darren Critchley - validate parameters
1295 if ($colno > $ttlitems){$colno = '1';}
1296 $colno--; # remove one from colno to deal with arrays starting at 0
1297 if($colno < 0){$colno = '0';}
1298 if ($alpnum ne '') { $alpnum = lc($alpnum); } else { $alpnum = 'a'; }
1299 if ($srtdir ne '') { $srtdir = lc($srtdir); } else { $srtdir = 'src'; }
1301 foreach $line (@tobesorted)
1305 my @temp = split(/\,/,$line);
1306 # Darren Critchley - juggle the fields so that the one we want to sort on is first
1307 my $tmpholder = $temp[0];
1308 $temp[0] = $temp[$colno];
1309 $temp[$colno] = $tmpholder;
1311 for ($ctr=0; $ctr < $ttlitems ; $ctr++) {
1312 $newline=$newline . $temp[$ctr] . ",";
1315 push(@tmparray,$newline);
1318 if ($alpnum eq 'n') {
1319 @tmparray = sort {$a <=> $b} @tmparray;
1321 @tmparray = (sort @tmparray);
1323 foreach $line (@tmparray)
1327 my @temp = split(/\,/,$line);
1328 my $tmpholder = $temp[0];
1329 $temp[0] = $temp[$colno];
1330 $temp[$colno] = $tmpholder;
1332 for ($ctr=0; $ctr < $ttlitems ; $ctr++){
1333 $newline=$newline . $temp[$ctr] . ",";
1336 push(@srtedarray,$newline);
1340 if ($srtdir eq 'dsc') {
1341 @tmparray = reverse(@srtedarray);
1344 return (@srtedarray);
1348 sub speedtouchversion
1350 if (-f
"/proc/bus/usb/devices")
1352 $speedtouch=`/bin/cat /proc/bus/usb/devices | /bin/grep 'Vendor=06b9 ProdID=4061' | /usr/bin/cut -d ' ' -f6`;
1353 if ($speedtouch eq '') {
1354 $speedtouch= $tr{'connect the modem'};
1357 $speedtouch='USB '.$tr{'not running'};
1362 sub CheckSortOrder
{
1363 #Sorting of allocated leases
1364 if ($ENV{'QUERY_STRING'} =~ /^IPADDR|^ETHER|^HOSTNAME|^ENDTIME/ ) {
1365 my $newsort=$ENV{'QUERY_STRING'};
1366 &readhash
("${swroot}/dhcp/settings", \
%dhcpsettings);
1367 $act=$dhcpsettings{'SORT_LEASELIST'};
1369 if ($act =~ $newsort) {
1370 if ($act !~ 'Rev') {$Rev='Rev'};
1374 $dhcpsettings{'SORT_LEASELIST'}=$newsort;
1375 &writehash
("${swroot}/dhcp/settings", \
%dhcpsettings);
1376 $dhcpsettings{'ACTION'} = 'SORT'; # avoid the next test "First lauch"
1381 sub PrintActualLeases
1383 &openbox
('100%', 'left', $tr{'current dynamic leases'});
1385 <table width='100%'>
1387 <td width='25%' align='center'><a href='$ENV{'SCRIPT_NAME'}?IPADDR'><b>$tr{'ip address'}</b></a></td>
1388 <td width='25%' align='center'><a href='$ENV{'SCRIPT_NAME'}?ETHER'><b>$tr{'mac address'}</b></a></td>
1389 <td width='20%' align='center'><a href='$ENV{'SCRIPT_NAME'}?HOSTNAME'><b>$tr{'hostname'}</b></a></td>
1390 <td width='30%' align='center'><a href='$ENV{'SCRIPT_NAME'}?ENDTIME'><b>$tr{'lease expires'} (local time d/m/y)</b></a></td>
1395 open(LEASES
,"/var/lib/dhcp/dhcpd.leases") or die "Can't open dhcpd.leases";
1396 while ($line = <LEASES
>) {
1397 next if( $line =~ /^\s*#/ );
1399 @temp = split (' ', $line);
1401 if ($line =~ /^\s*lease/) {
1403 #All field are not necessarily read. Clear everything
1409 if ($line =~ /^\s*ends/) {
1410 $line =~ /(\d+)\/(\d
+)\
/(\d+) (\d+):(\d+):(\d+)/;
1411 $endtime = timegm
($6, $5, $4, $3, $2 - 1, $1 - 1900);
1414 if ($line =~ /^\s*hardware ethernet/) {
1419 if ($line =~ /^\s*client-hostname/) {
1420 $hostname = "$temp[1] $temp[2] $temp[3]";
1421 $hostname =~ s/;//g;
1422 $hostname =~ s/\"//g;
1426 @record = ('IPADDR',$ip,'ENDTIME',$endtime,'ETHER',$ether,'HOSTNAME',$hostname);
1427 $record = {}; # create a reference to empty hash
1428 %{$record} = @record; # populate that hash with @record
1429 $entries{$record->{'IPADDR'}} = $record; # add this to a hash of hashes
1435 foreach my $key (sort leasesort
keys %entries) {
1437 my $hostname = &cleanhtml
($entries{$key}->{HOSTNAME
},"y");
1440 print "<tr bgcolor='$table1colour'>";
1443 print "<tr bgcolor='$table2colour'>";
1447 <td align='center'>$entries{$key}->{IPADDR}</td>
1448 <td align='center'>$entries{$key}->{ETHER}</td>
1449 <td align='center'> $hostname </td>
1454 ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $dst) = localtime ($entries{$key}->{ENDTIME
});
1455 $enddate = sprintf ("%02d/%02d/%d %02d:%02d:%02d",$mday,$mon+1,$year+1900,$hour,$min,$sec);
1457 if ($entries{$key}->{ENDTIME
} < time() ){
1458 print "<strike>$enddate</strike>";
1471 # This sub is used during display of actives leases
1473 if (rindex ($dhcpsettings{'SORT_LEASELIST'},'Rev') != -1)
1475 $qs=substr ($dhcpsettings{'SORT_LEASELIST'},0,length($dhcpsettings{'SORT_LEASELIST'})-3);
1476 if ($qs eq 'IPADDR') {
1477 @a = split(/\./,$entries{$a}->{$qs});
1478 @b = split(/\./,$entries{$b}->{$qs});
1484 $entries{$b}->{$qs} cmp $entries{$a}->{$qs};
1489 $qs=$dhcpsettings{'SORT_LEASELIST'};
1490 if ($qs eq 'IPADDR') {
1491 @a = split(/\./,$entries{$a}->{$qs});
1492 @b = split(/\./,$entries{$b}->{$qs});
1498 $entries{$a}->{$qs} cmp $entries{$b}->{$qs};
1505 opendir(DIR
, "${swroot}/uplinks/") || return \
@uplinks;
1506 foreach my $dir (readdir(DIR
)) {
1507 next if ($dir =~ /^\./);
1508 next if (-f
"${swroot}/uplinks/$dir");
1509 push(@uplinks, $dir);
1516 my $filename = shift;
1518 open (F
, $filename) || return "";
1525 sub get_red_ifaces_by_type
($) {
1527 my @gottypeiface = ();
1528 my @gottypeuplink = ();
1531 my $ref=get_uplinks
();
1534 foreach my $link (@uplinks) {
1536 &readhash
("${swroot}/uplinks/$link/settings", \
%set);
1538 push(@gottype, $link);
1540 my $iface = $set{'RED_DEV'};
1542 $iface = get_iface
("${swroot}/uplinks/$link/interface");
1546 if ($set{'RED_TYPE'} eq $type) {
1547 push(@gottypeiface, $iface);
1548 push(@gottypeuplink, $link);
1551 return (\
@gottypeiface, \
@gottypeuplink, \
@gottype);
1554 sub get_red_ifaces
() {
1555 return `cat ${swroot}/uplinks/*/interface 2>/dev/null`;
1558 sub get_zone_devices
($) {
1561 open (FILE
, "${swroot}/ethernet/$bridge") || return "";
1562 foreach my $line (<FILE
>) {
1565 push(@ifaces, $line);