]>
git.ipfire.org Git - people/teissler/ipfire-2.x.git/blob - config/cfgroot/header.pl
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{'system status information'}",
165 $substatus->{'02.networkstatus'} = {
166 'caption' => $tr{'ssnetwork status'},
167 'uri' => '/cgi-bin/netstatus.cgi',
168 'title' => "$tr{'network status information'}",
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{'network traffic graphs'}",
185 $substatus->{'05.proxygraphs'} = {
186 'caption' => $tr{'ssproxy graphs'},
187 'uri' => '/cgi-bin/proxygraphs.cgi',
188 'title' => "$tr{'proxy access graphs'}",
191 $substatus->{'06.connections'} = {
192 'caption' => $tr{'connections'},
193 'uri' => '/cgi-bin/connections.cgi',
194 'title' => "$tr{'connections'}",
197 $substatus->{'99.iptfilters'} = {
198 'caption' => $tr{'iptfilters iptable rules'},
199 'uri' => '/cgi-bin/iptfilters.cgi',
200 'title' => "$tr{'iptfilters iptable rules'}",
204 my %subnetworkhash = ();
205 my $subnetwork = \
%subnetworkhash;
207 $subnetwork->{'01.dialup'} = {
208 'caption' => $tr{'alt dialup'},
209 'uri' => '/cgi-bin/pppsetup.cgi',
210 'title' => "$tr{'dialup settings'}",
213 $subnetwork->{'02.hosts'} = {
214 'caption' => $tr{'edit hosts'},
215 'uri' => '/cgi-bin/hosts.cgi',
216 'title' => "$tr{'host configuration'}",
219 $subnetwork->{'03.upload'} = {
220 'caption' => $tr{'upload'},
221 'uri' => '/cgi-bin/upload.cgi',
222 'title' => "$tr{'firmware upload'}",
225 $subnetwork->{'04.aliases'} = {
226 'caption' => $tr{'aliases'},
227 'uri' => '/cgi-bin/aliases.cgi',
228 'title' => "$tr{'external aliases configuration'}",
231 $subnetwork->{'05.nettraf'} = {
232 'caption' => $tr{'sstraffic'},
233 'uri' => '/cgi-bin/traffic.cgi',
234 'title' => "$tr{'sstraffic'}",
237 $subnetwork->{'06.fwhits'} = {
238 'caption' => 'Firewallhits',
239 'uri' => '/cgi-bin/fwhits.cgi',
240 'title' => "IPFire Firewallhits",
243 $subnetwork->{'07.openvpn'} = {
244 'caption' => 'OpenVPN',
245 'uri' => '/cgi-bin/ovpnmain.cgi',
246 'title' => "$tr{'virtual private networking'}",
249 $subnetwork->{'08.ipsec'} = {
250 'caption' => 'IPSec',
251 'uri' => '/cgi-bin/vpnmain.cgi',
252 'title' => "$tr{'virtual private networking'}",
257 my %subserviceshash = ();
258 my $subservices = \
%subserviceshash;
260 $subservices->{'01.proxy'} = {'caption' => $tr{'proxy'},
261 'uri' => '/cgi-bin/proxy.cgi',
262 'title' => "HTTP: $tr{'web proxy configuration'}",
265 $subservices->{'02.dhcp'} = {'caption' => $tr{'dhcp server'},
266 'uri' => '/cgi-bin/dhcp.cgi',
267 'title' => "$tr{'dhcp configuration'}",
270 $subservices->{'03.dyndns'} = {'caption' => $tr{'dynamic dns'},
271 'uri' => '/cgi-bin/ddns.cgi',
272 'title' => "$tr{'dynamic dns client'}",
275 $subservices->{'04.time'} = {'caption' => $tr{'time server'},
276 'uri' => '/cgi-bin/time.cgi',
277 'title' => "$tr{'time server'}",
280 $subservices->{'05.qos'} = {'caption' => 'Quality of Service',
281 'uri' => '/cgi-bin/qos.cgi',
282 'title' => "$tr{'traffic shaping settings'}",
285 $subservices->{'06.ids'} = {'caption' => $tr{'intrusion detection'},
287 'uri' => '/cgi-bin/ids.cgi',
288 'title' => "$tr{'intrusion detection system'} (Snort)",
292 my %subfirewallhash = ();
293 my $subfirewall = \
%subfirewallhash;
296 $subfirewall->{'01.dnat'} = {
297 'caption' => $tr{'ssport forwarding'},
298 'uri' => '/cgi-bin/portfw.cgi',
299 'title' => "$tr{'port forwarding configuration'}",
302 $subfirewall->{'02.xtaccess'} = {
303 'caption' => $tr{'external access'},
304 'uri' => '/cgi-bin/xtaccess.cgi',
305 'title' => "$tr{'external access configuration'}",
308 $subfirewall->{'03.wireless'} = {
309 'caption' => $tr{'blue access'},
310 'uri' => '/cgi-bin/wireless.cgi',
311 'title' => "$tr{'blue access'}",
314 $subfirewall->{'04.dmz'} = {
315 'caption' => $tr{'ssdmz pinholes'},
316 'uri' => '/cgi-bin/dmzholes.cgi',
317 'title' => "$tr{'dmz pinhole configuration'}",
320 $subfirewall->{'05.outgoing'} = {
321 'caption' => $tr{'outgoing firewall'},
322 'uri' => '/cgi-bin/outgoingfw.cgi',
323 'title' => "$tr{'outgoing firewall'}",
327 my %sublogshash = ();
328 my $sublogs = \
%sublogshash;
330 $sublogs->{'01.summary'} = {'caption' => $tr{'log summary'},
331 'uri' => '/cgi-bin/logs.cgi/summary.dat',
332 'title' => "$tr{'log summary'}",
335 $sublogs->{'02.settings'} = {'caption' => $tr{'log settings'},
336 'uri' => '/cgi-bin/logs.cgi/config.dat',
337 'title' => "$tr{'log settings'}",
340 $sublogs->{'03.proxy'} = {'caption' => $tr{'proxy logs'},
341 'uri' => '/cgi-bin/logs.cgi/proxylog.dat',
342 'title' => "$tr{'proxy log viewer'}",
345 $sublogs->{'04.firewall'} = {'caption' => $tr{'firewall logs'},
346 'uri' => '/cgi-bin/logs.cgi/firewalllog.dat',
347 'title' => "$tr{'firewall log viewer'}",
350 $sublogs->{'05.ids'} = {'caption' => $tr{'ids logs'},
351 'uri' => '/cgi-bin/logs.cgi/ids.dat',
352 'title' => "$tr{'intrusion detection system log viewer'}",
355 $sublogs->{'07.urlfilter'} = {
356 'caption' => $tr{'urlfilter log'},
357 'uri' => '/cgi-bin/logs.cgi/urlfilter.dat',
358 'title' => "$tr{'urlfilter log'}",
361 $sublogs->{'08.openvpn'} = {'caption' => $tr{'openvpn log'},
362 'uri' => '/cgi-bin/logs.cgi/openvpn.dat',
363 'title' => "$tr{'openvpn log'}",
366 $sublogs->{'09.system'} = {'caption' => $tr{'system logs'},
367 'uri' => '/cgi-bin/logs.cgi/log.dat',
368 'title' => "$tr{'system log viewer'}",
371 $sublogs->{'10.userlog'} = {'caption' => $tr{'user proxy logs'},
372 'uri' => '/cgi-bin/logs.cgi/userlog.dat',
373 'title' => "$tr{'user log viewer'}",
377 my %subipfirehash = ();
378 my $subipfire = \
%subipfirehash;
379 $subipfire->{'01.pakfire'} = {'caption' => $tr{'pakfire'},
380 'uri' => '/cgi-bin/pakfire.cgi',
381 'title' => "$tr{'paketmanager'}",
384 $subipfire->{'02.asterisk'} = {'caption' => $tr{'asterisk'},
385 'uri' => '/cgi-bin/asterisk.cgi',
386 'title' => "$tr{'asterisk'}",
389 $subipfire->{'02.samba'} = {'caption' => $tr{'samba'},
390 'uri' => '/cgi-bin/samba.cgi',
391 'title' => "$tr{'samba'}",
394 $subipfire->{'99.help'} = {'caption' => $tr{'help'},
395 'uri' => '/cgi-bin/help.cgi',
396 'title' => "$tr{'help'}",
402 $menu->{'01.system'} = {'caption' => $tr{'alt system'},
404 'subMenu' => $subsystem
406 $menu->{'02.status'} = {'caption' => $tr{'status'},
408 'subMenu' => $substatus
410 $menu->{'03.network'} = {'caption' => $tr{'network'},
412 'subMenu' => $subnetwork
414 $menu->{'04.services'} = {'caption' => $tr{'alt services'},
416 'subMenu' => $subservices
418 $menu->{'05.firewall'} = {'caption' => $tr{'firewall'},
420 'subMenu' => $subfirewall
422 $menu->{'06.proxy'} = {'caption' => $tr{'alt proxy'},
424 'subMenu' => $subproxy
426 $menu->{'07.ipfire'} = {'caption' => 'IPFire',
428 'subMenu' => $subipfire
430 $menu->{'08.logs'} = {'caption' => $tr{'alt logs'},
432 'subMenu' => $sublogs
435 if (! blue_used
() && ! orange_used
()) {
436 $menu->{'05.firewall'}{'subMenu'}->{'04.dmz'}{'enabled'} = 0;
439 $menu->{'05.firewall'}{'subMenu'}->{'03.wireless'}{'enabled'} = 0;
441 if (! $ethsettings{'CONFIG_TYPE'} =~ /^(2|3|6|7)$/ && $ethsettings{'RED_TYPE'} eq 'STATIC' ) {
442 $menu->{'03.network'}{'subMenu'}->{'04.aliases'}{'enabled'} = 0;
448 print "Pragma: no-cache\n";
449 print "Cache-control: no-cache\n";
450 print "Connection: close\n";
451 print "Content-type: text/html\n\n";
454 sub is_menu_visible
($) {
457 return (-e
$ENV{'DOCUMENT_ROOT'}."/../$link");
463 if (! $root->{'enabled'}) {
466 if ($root->{'uri'} !~ /^$/) {
468 if ($root->{'vars'} !~ /^$/) {
469 $vars = '?'. $root->{'vars'};
471 if (! is_menu_visible
($root->{'uri'})) {
474 return $root->{'uri'}.$vars;
476 my $submenus = $root->{'subMenu'};
480 foreach my $item (sort keys %$submenus) {
481 my $link = getlink
($submenus->{$item});
493 my $uri = $conf->{'uri'};
494 my $vars = $conf->{'vars'};
495 my $novars = $conf->{'novars'};
500 if ($uri ne $URI[0]) {
504 if ($URI[1] !~ /^$/) {
511 return ($URI[1] eq $vars);
521 foreach my $item (sort keys %$root) {
522 my $val = $root->{$item};
523 if (compare_url
($val)) {
524 $val->{'selected'} = 1;
525 if ($val->{'title'} !~ /^$/) {
526 return $val->{'title'};
528 return 'EMPTY TITLE';
531 my $title = gettitle
($val->{'subMenu'});
533 $val->{'selected'} = 1;
547 foreach my $k1 ( sort keys %$menu ) {
548 if (! $menu->{$k1}{'enabled'}) {
552 my $link = getlink
($menu->{$k1});
556 if (! is_menu_visible
($link)) {
559 if ($menu->{$k1}->{'selected'}) {
560 print '<li class="selected">';
566 <div class="rcorner">
567 <a href="$link">$menu->{$k1}{'caption'}</a>
587 foreach my $item (%$root) {
588 if ($root->{$item}{'selected'}) {
589 return $root->{$item};
594 sub showsubsection
($$) {
604 my $selected = getselected
($root);
608 my $submenus = $selected->{'subMenu'};
618 foreach my $item (sort keys %$submenus) {
619 my $hash = $submenus->{$item};
620 if (! $hash->{'enabled'}) {
624 my $link = getlink
($hash);
628 if (! is_menu_visible
($link)) {
631 if ($hash->{'selected'}) {
632 print '<li class="selected">';
638 <a href="$link">$hash->{'caption'}</a>
653 sub showsubsubsection
($) {
658 my $selected = getselected
($root);
662 if (! $selected->{'subMenu'}) {
666 showsubsection
($selected->{'subMenu'}, 'menu-subtop');
672 if ($URI[0] =~ /.*\/([^\
/]+)\.cgi/) {
677 $helpfile .= '.help.html';
679 my $helpuri = '/doc/'.$language.'/'.$helpfile;
680 if (! -e
$ENV{'DOCUMENT_ROOT'}.$helpuri) {
690 my $extrahead = shift;
692 @URI=split ('\?', $ENV{'REQUEST_URI'} );
693 &readhash
("${swroot}/main/settings", \
%settings);
696 my $h2 = gettitle
($menu);
697 my $helpuri = get_helpuri
();
699 $title = "IPFire - $title";
700 if ($settings{'WINDOWWITHHOSTNAME'} eq 'on') {
701 $title = "$settings{'HOSTNAME'}.$settings{'DOMAINNAME'} - $title";
706 PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
707 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
711 <title>$title</title>
714 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
715 <meta http-equiv="Page-Enter" content="blendTrans(Duration=0.5,Transition=12)">
716 <meta http-equiv="Page-Exit" content="blendTrans(Duration=0.5,Transition=12)">
717 <link rel="shortcut icon" href="/favicon.ico" />
718 <style type="text/css">\@import url(/include/style.css);</style>
719 <style type="text/css">\@import url(/include/menu.css);</style>
720 <style type="text/css">\@import url(/include/content.css);</style>
721 <script language="javascript" type="text/javascript">
723 function swapVisibility(id) {
724 el = document.getElementById(id);
725 if(el.style.display != 'block') {
726 el.style.display = 'block'
729 el.style.display = 'none'
736 <!-- IPFIRE HEADER -->
741 <img id="logo-product" src="/images/logo_ipfire.gif">
742 <div id="header-icons">
743 <a href="http://users.ipfire.eu/" target="_blank"><img border="0" src="/images/help.gif"></a>
760 &showsubsection
($menu);
765 <td width="100%" valign="top">
766 <div id="page-content">
771 &showsubsubsection
($menu);
774 require 'ipfire-network.pl';
775 $supported = check_support
();
776 warn_unsupported
($supported);
781 my $status = &connectionstatus
();
782 $uptime = `/usr/bin/uptime`;
787 <div style="font-size: 9px"><b>Status:</b> $status <b>Uptime:</b>$uptime</div>
803 $bgcolor = "style='background-color: $colourerr;'";
811 # print "</td></tr></table></td></tr></table>\n"
820 if ($caption) { print "<h3>$caption</h3>\n"; } else { print " "; }
822 print "<table class=\"list\"><tr><td align=\"$align\">\n";
827 print "</td></tr></table><br><br>";
832 my $filename = $_[0];
835 # write cgi vars to the file.
836 open(FILE
, ">${filename}") or die "Unable to write file $filename";
838 foreach $var (keys %$hash)
840 $val = $hash->{$var};
841 # Darren Critchley Jan 17, 2003 added the following because when submitting with a graphic, the x and y
842 # location of the mouse are submitted as well, this was being written to the settings file causing
843 # some serious grief! This skips the variable.x and variable.y
844 if (!($var =~ /(.x|.y)$/)) {
847 if (!($var =~ /^ACTION/)) {
848 print FILE
"${var}=${val}\n"; }
856 my $filename = $_[0];
860 open(FILE
, $filename) or die "Unable to read file $filename";
865 ($var, $val) = split /=/, $_, 2;
871 # Untaint variables read from hash
872 $var =~ /([A-Za-z0-9_-]*)/; $var = $1;
873 $val =~ /([\w\W]*)/; $val = $1;
874 $hash->{$var} = $val;
881 my ($hash, $params) = @_;
882 my $cgi = CGI
->new ();
883 $hash->{'__CGI__'} = $cgi;
884 return if ($ENV{'REQUEST_METHOD'} ne 'POST');
885 if (!$params->{'wantfile'}) {
886 $CGI::DISABLE_UPLOADS
= 1;
887 $CGI::POST_MAX
= 512 * 1024;
889 $CGI::POST_MAX
= 10 * 1024 * 1024;
892 $cgi->referer() =~ m/^https?\:\/\
/([^\/]+)/;
894 $cgi->url() =~ m/^https?\:\/\
/([^\/]+)/;
896 return if ($referer ne $servername);
898 ### Modified for getting multi-vars, split by |
899 %temp = $cgi->Vars();
900 foreach my $key (keys %temp) {
901 $hash->{$key} = $temp{$key};
902 $hash->{$key} =~ s/\0/|/g;
903 $hash->{$key} =~ s/^\s*(.*?)\s*$/$1/;
906 if (($params->{'wantfile'})&&($params->{'filevar'})) {
907 $hash->{$params->{'filevar'}} = $cgi->upload
908 ($params->{'filevar'});
915 my $logmessage = $_[0];
916 $logmessage =~ /([\w\W]*)/;
918 system('/usr/bin/logger', '-t', 'ipfire', $logmessage);
923 my ($dev, $ino, $mode, $nlink, $uid, $gid, $rdev, $size,
924 $atime, $mtime, $ctime, $blksize, $blocks) = stat $_[0];
927 my $totalsecs = $now - $mtime;
928 my $days = int($totalsecs / 86400);
929 my $totalhours = int($totalsecs / 3600);
930 my $hours = $totalhours % 24;
931 my $totalmins = int($totalsecs / 60);
932 my $mins = $totalmins % 60;
933 my $secs = $totalsecs % 60;
935 return "${days}d ${hours}h ${mins}m ${secs}s";
942 if (!($ip =~ /^(\d+)\.(\d+)\.(\d+)\.(\d+)$/)) {
946 @octets = ($1, $2, $3, $4);
951 if ($_ < 0 || $_ > 255) {
963 if (&validip
($mask)) {
965 # second part a number?
968 if (!($mask =~ /^\d+$/)) {
970 if ($mask >= 0 && $mask <= 32) {
977 my $ipormask = $_[0];
979 # see if it is a IP only.
980 if (&validip
($ipormask)) {
982 # split it into number and mask.
983 if (!($ipormask =~ /^(.*?)\/(.*?
)$/)) {
987 # first part not a ip?
988 if (!(&validip
($ip))) {
990 return &validmask
($mask);
995 my $ipandmask = $_[0];
997 # split it into number and mask.
998 if (!($ipandmask =~ /^(.*?)\/(.*?
)$/)) {
1002 # first part not a ip?
1003 if (!(&validip
($ip))) {
1005 return &validmask
($mask);
1016 if ($_ >= 1 && $_ <= 65535) {
1023 my $checkmac = $_[0];
1024 my $ot = '[0-9a-f]{2}'; # 2 Hex digits (one octet)
1025 if ($checkmac !~ /^$ot:$ot:$ot:$ot:$ot:$ot$/i)
1034 # Checks a hostname against RFC1035
1035 my $hostname = $_[0];
1037 # Each part should be at least two characters in length
1038 # but no more than 63 characters
1039 if (length ($hostname) < 2 || length ($hostname) > 63) {
1041 # Only valid characters are a-z, A-Z, 0-9 and -
1042 if ($hostname !~ /^[a-zA-Z0-9-]*$/) {
1044 # First character can only be a letter or a digit
1045 if (substr ($hostname, 0, 1) !~ /^[a-zA-Z0-9]*$/) {
1047 # Last character can only be a letter or a digit
1048 if (substr ($hostname, -1, 1) !~ /^[a-zA-Z0-9]*$/) {
1055 # Checks a domain name against RFC1035
1056 my $domainname = $_[0];
1057 my @parts = split (/\./, $domainname); # Split hostname at the '.'
1059 foreach $part (@parts) {
1060 # Each part should be at least two characters in length
1061 # but no more than 63 characters
1062 if (length ($part) < 2 || length ($part) > 63) {
1064 # Only valid characters are a-z, A-Z, 0-9 and -
1065 if ($part !~ /^[a-zA-Z0-9-]*$/) {
1067 # First character can only be a letter or a digit
1068 if (substr ($part, 0, 1) !~ /^[a-zA-Z0-9]*$/) {
1070 # Last character can only be a letter or a digit
1071 if (substr ($part, -1, 1) !~ /^[a-zA-Z0-9]*$/) {
1079 # Checks a fully qualified domain name against RFC1035
1081 my @parts = split (/\./, $fqdn); # Split hostname at the '.'
1082 if (scalar(@parts) < 2) { # At least two parts should
1083 return 0;} # exist in a FQDN
1084 # (i.e. hostname.domain)
1085 foreach $part (@parts) {
1086 # Each part should be at least two characters in length
1087 # but no more than 63 characters
1088 if (length ($part) < 2 || length ($part) > 63) {
1090 # Only valid characters are a-z, A-Z, 0-9 and -
1091 if ($part !~ /^[a-zA-Z0-9-]*$/) {
1093 # First character can only be a letter or a digit
1094 if (substr ($part, 0, 1) !~ /^[a-zA-Z0-9]*$/) {
1096 # Last character can only be a letter or a digit
1097 if (substr ($part, -1, 1) !~ /^[a-zA-Z0-9]*$/) {
1103 sub validportrange
# used to check a port range
1105 my $port = $_[0]; # port values
1106 $port =~ tr/-/:/; # replace all - with colons just in case someone used -
1107 my $srcdst = $_[1]; # is it a source or destination port
1109 if (!($port =~ /^(\d+)\:(\d+)$/)) {
1111 if (!(&validport
($port))) {
1112 if ($srcdst eq 'src'){
1113 return $tr{'source port numbers'};
1115 return $tr{'destination port numbers'};
1123 if ($srcdst eq 'src'){
1124 return $tr{'bad source range'};
1126 return $tr{'bad destination range'};
1131 if (!(&validport
($_))) {
1132 if ($srcdst eq 'src'){
1133 return $tr{'source port numbers'};
1135 return $tr{'destination port numbers'};
1143 # Test if IP is within a subnet
1144 # Call: IpInSubnet (Addr, Subnet, Subnet Mask)
1145 # Subnet can be an IP of the subnet: 10.0.0.0 or 10.0.0.1
1146 # Everything in dottted notation
1147 # Return: TRUE/FALSE
1150 $ip = unpack('N', inet_aton
(shift));
1151 $start = unpack('N', inet_aton
(shift));
1152 $mask = unpack('N', inet_aton
(shift));
1153 $start &= $mask; # base of subnet...
1154 $end = $start + ~$mask;
1155 return (($ip >= $start) && ($ip <= $end));
1160 return 0 if ( $mail !~ /^[0-9a-zA-Z\.\-\_]+\@[0-9a-zA-Z\.\-]+$/ );
1161 return 0 if ( $mail =~ /^[^0-9a-zA-Z]|[^0-9a-zA-Z]$/);
1162 return 0 if ( $mail !~ /([0-9a-zA-Z]{1})\@./ );
1163 return 0 if ( $mail !~ /.\@([0-9a-zA-Z]{1})/ );
1164 return 0 if ( $mail =~ /.\.\-.|.\-\..|.\.\..|.\-\-./g );
1165 return 0 if ( $mail =~ /.\.\_.|.\-\_.|.\_\..|.\_\-.|.\_\_./g );
1166 return 0 if ( $mail !~ /\.([a-zA-Z]{2,3})$/ );
1171 my ($filename, $hash) = @_;
1173 open(FILE
, $filename) or die "Unable to read file $filename";
1176 my ($key, $rest, @temp);
1178 ($key, $rest) = split (/,/, $_, 2);
1179 if ($key =~ /^[0-9]+$/ && $rest) {
1180 @temp = split (/,/, $rest);
1181 $hash->{$key} = \
@temp;
1188 sub writehasharray
{
1189 my ($filename, $hash) = @_;
1192 open(FILE
, ">$filename") or die "Unable to write to file $filename";
1194 foreach $key (keys %$hash) {
1195 if ( $hash->{$key} ) {
1197 foreach $i (0 .. $#{$hash->{$key}}) {
1198 print FILE
",$hash->{$key}[$i]";
1207 sub findhasharraykey
{
1208 foreach my $i (1 .. 1000000) {
1209 if ( ! exists $_[0]{$i}) {
1217 my $outstring =$_[0];
1218 $outstring =~ tr/,/ / if not defined $_[1] or $_[1] ne 'y';
1219 $outstring =~ s/&/&/g;
1220 $outstring =~ s/\'/'/g;
1221 $outstring =~ s/\"/"/g;
1222 $outstring =~ s/</</g;
1223 $outstring =~ s/>/>/g;
1226 sub connectionstatus
1229 opendir UPLINKS
, "/var/ipfire/uplinks" or die "Cannot read uplinks: $!";
1230 foreach my $uplink (sort grep !/^\./, readdir UPLINKS
) {
1231 if ( -f
"${swroot}/uplinks/${uplink}/active") {
1233 $timestr = &age
("${swroot}/uplinks/${uplink}/active");
1234 $status = "$tr{'connected'}: $uplink (<span class='ipcop_StatusBigRed'>$timestr</span>) ";
1236 $timestr = &age
("${swroot}/uplinks/${uplink}/active");
1237 $status = "$status , $uplink (<span class='ipcop_StatusBigRed'>$timestr</span>) ";
1239 } elsif ( -f
"${swroot}/uplinks/${uplink}/connecting") {
1241 $status = "$tr{'connecting'} $uplink";
1243 $status = "$status , $tr{'connecting'} $uplink (<span class='ipcop_StatusBigRed'>$timestr</span>) ";
1250 $status = "$tr{'idle'}";
1252 $connstate = "<span class='ipcop_StatusBig'>$status</span>";
1257 # Darren Critchley - darrenc@telus.net - (c) 2003
1258 # &srtarray(SortOrder, AlphaNumeric, SortDirection, ArrayToBeSorted)
1259 # This subroutine will take the following parameters:
1260 # ColumnNumber = the column which you want to sort on, starts at 1
1261 # AlphaNumberic = a or n (lowercase) defines whether the sort should be alpha or numberic
1262 # SortDirection = asc or dsc (lowercase) Ascending or Descending sort
1263 # ArrayToBeSorted = the array that wants sorting
1265 # Returns an array that is sorted to your specs
1267 # If SortOrder is greater than the elements in array, then it defaults to the first element
1270 my ($colno, $alpnum, $srtdir, @tobesorted) = @_;
1275 my $ttlitems = scalar @tobesorted; # want to know the number of rows in the passed array
1276 if ($ttlitems < 1){ # if no items, don't waste our time lets leave
1277 return (@tobesorted);
1279 my @tmp = split(/\,/,$tobesorted[0]);
1280 $ttlitems = scalar @tmp; # this should be the number of elements in each row of the passed in array
1282 # Darren Critchley - validate parameters
1283 if ($colno > $ttlitems){$colno = '1';}
1284 $colno--; # remove one from colno to deal with arrays starting at 0
1285 if($colno < 0){$colno = '0';}
1286 if ($alpnum ne '') { $alpnum = lc($alpnum); } else { $alpnum = 'a'; }
1287 if ($srtdir ne '') { $srtdir = lc($srtdir); } else { $srtdir = 'src'; }
1289 foreach $line (@tobesorted)
1293 my @temp = split(/\,/,$line);
1294 # Darren Critchley - juggle the fields so that the one we want to sort on is first
1295 my $tmpholder = $temp[0];
1296 $temp[0] = $temp[$colno];
1297 $temp[$colno] = $tmpholder;
1299 for ($ctr=0; $ctr < $ttlitems ; $ctr++) {
1300 $newline=$newline . $temp[$ctr] . ",";
1303 push(@tmparray,$newline);
1306 if ($alpnum eq 'n') {
1307 @tmparray = sort {$a <=> $b} @tmparray;
1309 @tmparray = (sort @tmparray);
1311 foreach $line (@tmparray)
1315 my @temp = split(/\,/,$line);
1316 my $tmpholder = $temp[0];
1317 $temp[0] = $temp[$colno];
1318 $temp[$colno] = $tmpholder;
1320 for ($ctr=0; $ctr < $ttlitems ; $ctr++){
1321 $newline=$newline . $temp[$ctr] . ",";
1324 push(@srtedarray,$newline);
1328 if ($srtdir eq 'dsc') {
1329 @tmparray = reverse(@srtedarray);
1332 return (@srtedarray);
1336 sub speedtouchversion
1338 if (-f
"/proc/bus/usb/devices")
1340 $speedtouch=`/bin/cat /proc/bus/usb/devices | /bin/grep 'Vendor=06b9 ProdID=4061' | /usr/bin/cut -d ' ' -f6`;
1341 if ($speedtouch eq '') {
1342 $speedtouch= $tr{'connect the modem'};
1345 $speedtouch='USB '.$tr{'not running'};
1350 sub CheckSortOrder
{
1351 #Sorting of allocated leases
1352 if ($ENV{'QUERY_STRING'} =~ /^IPADDR|^ETHER|^HOSTNAME|^ENDTIME/ ) {
1353 my $newsort=$ENV{'QUERY_STRING'};
1354 &readhash
("${swroot}/dhcp/settings", \
%dhcpsettings);
1355 $act=$dhcpsettings{'SORT_LEASELIST'};
1357 if ($act =~ $newsort) {
1358 if ($act !~ 'Rev') {$Rev='Rev'};
1362 $dhcpsettings{'SORT_LEASELIST'}=$newsort;
1363 &writehash
("${swroot}/dhcp/settings", \
%dhcpsettings);
1364 $dhcpsettings{'ACTION'} = 'SORT'; # avoid the next test "First lauch"
1369 sub PrintActualLeases
1371 &openbox
('100%', 'left', $tr{'current dynamic leases'});
1373 <table width='100%'>
1375 <td width='25%' align='center'><a href='$ENV{'SCRIPT_NAME'}?IPADDR'><b>$tr{'ip address'}</b></a></td>
1376 <td width='25%' align='center'><a href='$ENV{'SCRIPT_NAME'}?ETHER'><b>$tr{'mac address'}</b></a></td>
1377 <td width='20%' align='center'><a href='$ENV{'SCRIPT_NAME'}?HOSTNAME'><b>$tr{'hostname'}</b></a></td>
1378 <td width='30%' align='center'><a href='$ENV{'SCRIPT_NAME'}?ENDTIME'><b>$tr{'lease expires'} (local time d/m/y)</b></a></td>
1383 open(LEASES
,"/var/lib/dhcp/dhcpd.leases") or die "Can't open dhcpd.leases";
1384 while ($line = <LEASES
>) {
1385 next if( $line =~ /^\s*#/ );
1387 @temp = split (' ', $line);
1389 if ($line =~ /^\s*lease/) {
1391 #All field are not necessarily read. Clear everything
1397 if ($line =~ /^\s*ends/) {
1398 $line =~ /(\d+)\/(\d
+)\
/(\d+) (\d+):(\d+):(\d+)/;
1399 $endtime = timegm
($6, $5, $4, $3, $2 - 1, $1 - 1900);
1402 if ($line =~ /^\s*hardware ethernet/) {
1407 if ($line =~ /^\s*client-hostname/) {
1408 $hostname = "$temp[1] $temp[2] $temp[3]";
1409 $hostname =~ s/;//g;
1410 $hostname =~ s/\"//g;
1414 @record = ('IPADDR',$ip,'ENDTIME',$endtime,'ETHER',$ether,'HOSTNAME',$hostname);
1415 $record = {}; # create a reference to empty hash
1416 %{$record} = @record; # populate that hash with @record
1417 $entries{$record->{'IPADDR'}} = $record; # add this to a hash of hashes
1423 foreach my $key (sort leasesort
keys %entries) {
1425 my $hostname = &cleanhtml
($entries{$key}->{HOSTNAME
},"y");
1428 print "<tr bgcolor='$table1colour'>";
1431 print "<tr bgcolor='$table2colour'>";
1435 <td align='center'>$entries{$key}->{IPADDR}</td>
1436 <td align='center'>$entries{$key}->{ETHER}</td>
1437 <td align='center'> $hostname </td>
1442 ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $dst) = localtime ($entries{$key}->{ENDTIME
});
1443 $enddate = sprintf ("%02d/%02d/%d %02d:%02d:%02d",$mday,$mon+1,$year+1900,$hour,$min,$sec);
1445 if ($entries{$key}->{ENDTIME
} < time() ){
1446 print "<strike>$enddate</strike>";
1459 # This sub is used during display of actives leases
1461 if (rindex ($dhcpsettings{'SORT_LEASELIST'},'Rev') != -1)
1463 $qs=substr ($dhcpsettings{'SORT_LEASELIST'},0,length($dhcpsettings{'SORT_LEASELIST'})-3);
1464 if ($qs eq 'IPADDR') {
1465 @a = split(/\./,$entries{$a}->{$qs});
1466 @b = split(/\./,$entries{$b}->{$qs});
1472 $entries{$b}->{$qs} cmp $entries{$a}->{$qs};
1477 $qs=$dhcpsettings{'SORT_LEASELIST'};
1478 if ($qs eq 'IPADDR') {
1479 @a = split(/\./,$entries{$a}->{$qs});
1480 @b = split(/\./,$entries{$b}->{$qs});
1486 $entries{$a}->{$qs} cmp $entries{$b}->{$qs};
1493 opendir(DIR
, "${swroot}/uplinks/") || return \
@uplinks;
1494 foreach my $dir (readdir(DIR
)) {
1495 next if ($dir =~ /^\./);
1496 next if (-f
"${swroot}/uplinks/$dir");
1497 push(@uplinks, $dir);
1504 my $filename = shift;
1506 open (F
, $filename) || return "";
1513 sub get_red_ifaces_by_type
($) {
1515 my @gottypeiface = ();
1516 my @gottypeuplink = ();
1519 my $ref=get_uplinks
();
1522 foreach my $link (@uplinks) {
1524 &readhash
("${swroot}/uplinks/$link/settings", \
%set);
1526 push(@gottype, $link);
1528 my $iface = $set{'RED_DEV'};
1530 $iface = get_iface
("${swroot}/uplinks/$link/interface");
1534 if ($set{'RED_TYPE'} eq $type) {
1535 push(@gottypeiface, $iface);
1536 push(@gottypeuplink, $link);
1539 return (\
@gottypeiface, \
@gottypeuplink, \
@gottype);
1542 sub get_red_ifaces
() {
1543 return `cat ${swroot}/uplinks/*/interface 2>/dev/null`;
1546 sub get_zone_devices
($) {
1549 open (FILE
, "${swroot}/ethernet/$bridge") || return "";
1550 foreach my $line (<FILE
>) {
1553 push(@ifaces, $line);