]>
git.ipfire.org Git - people/teissler/ipfire-2.x.git/blob - config/cfgroot/header.pl
2e621fb8a330cd692a5406d112ae7ad32c8a1c61
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}";
90 ### Read IPFire Buildversion
91 $FIREBUILD = "Datei firebuild nicht gefunden\n";
92 if (open(MYFile
, "<${swroot}/firebuild")) {
93 $FIREBUILD = <MYFile
>;
94 $FIREBUILD = "(Build: $FIREBUILD)";
98 require "${swroot}/langs/en.pl";
99 require "${swroot}/langs/${language}.pl";
102 if ($ethsettings{'CONFIG_TYPE'} =~ /^[1357]$/) {
109 if ($ethsettings{'CONFIG_TYPE'} =~ /^[4567]$/) {
116 if ($ethsettings{'CONFIG_TYPE'} =~ /^[0145]$/) {
124 my %subsystemhash = ();
125 my $subsystem = \
%subsystemhash;
127 $subsystem->{'10.home'} = {
128 'caption' => $tr{'alt home'},
129 'uri' => '/cgi-bin/index.cgi',
130 'title' => "$tr{'alt home'}",
133 $subsystem->{'20.passwords'} = {
134 'caption' => $tr{'sspasswords'},
135 'uri' => '/cgi-bin/changepw.cgi',
136 'title' => "$tr{'sspasswords'}",
139 $subsystem->{'30.ssh'} = {
140 'caption' => $tr{'ssh access'},
141 'uri' => '/cgi-bin/remote.cgi',
142 'title' => "$tr{'ssh access'}",
145 $subsystem->{'40.gui'} = {
146 'caption' => $tr{'gui settings'},
147 'uri' => '/cgi-bin/gui.cgi',
148 'title' => "$tr{'gui settings'}",
151 $subsystem->{'50.shutdown'} = {
152 'caption' => $tr{'shutdown'},
153 'uri' => '/cgi-bin/shutdown.cgi',
154 'title' => "$tr{'shutdown'} / $tr{'reboot'}",
157 $subsystem->{'99.credits'} = {
158 'caption' => $tr{'credits'},
159 'uri' => '/cgi-bin/credits.cgi',
160 'title' => "$tr{'credits'}",
164 my %substatushash = ();
165 my $substatus = \
%substatushash;
166 $substatus->{'10.systemstatus'} = {
167 'caption' => $tr{'sssystem status'},
168 'uri' => '/cgi-bin/status.cgi',
169 'title' => "$tr{'sssystem status'}",
172 $substatus->{'20.networkstatus'} = {
173 'caption' => $tr{'ssnetwork status'},
174 'uri' => '/cgi-bin/netstatus.cgi',
175 'title' => "$tr{'ssnetwork status'}",
178 $substatus->{'30.systemgraphs'} = {
179 'caption' => $tr{'system graphs'},
180 'uri' => '/cgi-bin/graphs.cgi',
182 'title' => "$tr{'system graphs'}",
185 $substatus->{'40.trafficgraphs'} = {
186 'caption' => $tr{'sstraffic graphs'},
187 'uri' => '/cgi-bin/graphs.cgi',
188 'vars' => 'graph=network',
189 'title' => "$tr{'sstraffic graphs'}",
192 $substatus->{'50.proxygraphs'} = {
193 'caption' => $tr{'ssproxy graphs'},
194 'uri' => '/cgi-bin/proxygraphs.cgi',
195 'title' => "$tr{'ssproxy graphs'}",
198 $substatus->{'60.fwhits'} = {
199 'caption' => 'Firewall-Diagramme',
200 'uri' => '/cgi-bin/fwhits.cgi',
201 'title' => "Firewall-Diagramme",
204 $substatus->{'70.hddtemp'} = {
205 'caption' => "$tr{'harddisk temperature graphs'}",
206 'uri' => '/cgi-bin/hddgraph.cgi',
207 'title' => "$tr{'harddisk temperature graphs'}",
210 $substatus->{'80.connections'} = {
211 'caption' => $tr{'connections'},
212 'uri' => '/cgi-bin/connections.cgi',
213 'title' => "$tr{'connections'}",
216 $substatus->{'90.nettraf'} = {
217 'caption' => $tr{'sstraffic'},
218 'uri' => '/cgi-bin/traffic.cgi',
219 'title' => "$tr{'sstraffic'}",
222 $substatus->{'99.iptable'} = {
223 'caption' => $tr{'iptable rules'},
224 'uri' => '/cgi-bin/iptables.cgi',
225 'title' => "$tr{'iptable rules'}",
229 my %subnetworkhash = ();
230 my $subnetwork = \
%subnetworkhash;
232 $subnetwork->{'10.proxy'} = {'caption' => 'Webproxy',
233 'uri' => '/cgi-bin/proxy.cgi',
234 'title' => "Webproxy",
237 $subnetwork->{'20.urlfilter'} = {'caption' => 'URL-Filter',
238 'uri' => '/cgi-bin/urlfilter.cgi',
239 'title' => "URL-Filter",
242 $subnetwork->{'30.dhcp'} = {'caption' => $tr{'dhcp server'},
243 'uri' => '/cgi-bin/dhcp.cgi',
244 'title' => "$tr{'dhcp server'}",
247 $subnetwork->{'40.dialup'} = {
248 'caption' => $tr{'alt dialup'},
249 'uri' => '/cgi-bin/pppsetup.cgi',
250 'title' => "$tr{'alt dialup'}",
253 $subnetwork->{'50.hosts'} = {
254 'caption' => $tr{'edit hosts'},
255 'uri' => '/cgi-bin/hosts.cgi',
256 'title' => "$tr{'edit hosts'}",
259 $subnetwork->{'60.upload'} = {
260 'caption' => $tr{'upload'},
261 'uri' => '/cgi-bin/upload.cgi',
262 'title' => "$tr{'upload'}",
265 $subnetwork->{'70.aliases'} = {
266 'caption' => $tr{'aliases'},
267 'uri' => '/cgi-bin/aliases.cgi',
268 'title' => "$tr{'aliases'}",
272 my %subserviceshash = ();
273 my $subservices = \
%subserviceshash;
276 $subservices->{'10.openvpn'} = {
277 'caption' => 'OpenVPN',
278 'uri' => '/cgi-bin/ovpnmain.cgi',
279 'title' => "$tr{'virtual private networking'}",
282 $subservices->{'20.ipsec'} = {
283 'caption' => 'IPSec',
284 'uri' => '/cgi-bin/vpnmain.cgi',
285 'title' => "$tr{'virtual private networking'}",
288 $subservices->{'30.dyndns'} = {'caption' => $tr{'dynamic dns'},
289 'uri' => '/cgi-bin/ddns.cgi',
290 'title' => "$tr{'dynamic dns'}",
293 $subservices->{'40.time'} = {'caption' => $tr{'time server'},
294 'uri' => '/cgi-bin/time.cgi',
295 'title' => "$tr{'time server'}",
298 $subservices->{'50.qos'} = {'caption' => 'Quality of Service',
299 'uri' => '/cgi-bin/qos.cgi',
300 'title' => "Quality of Service",
303 $subservices->{'60.ids'} = {'caption' => $tr{'intrusion detection'},
305 'uri' => '/cgi-bin/ids.cgi',
306 'title' => "$tr{'intrusion detection system'}",
311 my %subfirewallhash = ();
312 my $subfirewall = \
%subfirewallhash;
315 $subfirewall->{'10.dnat'} = {
316 'caption' => $tr{'ssport forwarding'},
317 'uri' => '/cgi-bin/portfw.cgi',
318 'title' => "$tr{'ssport forwarding'}",
321 $subfirewall->{'20.xtaccess'} = {
322 'caption' => $tr{'external access'},
323 'uri' => '/cgi-bin/xtaccess.cgi',
324 'title' => "$tr{'external access'}",
327 $subfirewall->{'30.wireless'} = {
328 'caption' => $tr{'blue access'},
329 'uri' => '/cgi-bin/wireless.cgi',
330 'title' => "$tr{'blue access'}",
333 $subfirewall->{'40.dmz'} = {
334 'caption' => $tr{'ssdmz pinholes'},
335 'uri' => '/cgi-bin/dmzholes.cgi',
336 'title' => "$tr{'dmz pinhole configuration'}",
339 $subfirewall->{'50.outgoing'} = {
340 'caption' => $tr{'outgoing firewall'},
341 'uri' => '/cgi-bin/outgoingfw.cgi',
342 'title' => "$tr{'outgoing firewall'}",
345 $subfirewall->{'60.fwopts'} = {
346 'caption' => $tr{'options fw'},
347 'uri' => '/cgi-bin/optionsfw.cgi',
348 'title' => "$tr{'options fw'}",
352 my %sublogshash = ();
353 my $sublogs = \
%sublogshash;
355 $sublogs->{'10.summary'} = {'caption' => $tr{'log summary'},
356 'uri' => '/cgi-bin/logs.cgi/summary.dat',
357 'title' => "$tr{'log summary'}",
360 $sublogs->{'20.settings'} = {'caption' => $tr{'log settings'},
361 'uri' => '/cgi-bin/logs.cgi/config.dat',
362 'title' => "$tr{'log settings'}",
365 $sublogs->{'30.proxy'} = {'caption' => $tr{'proxy logs'},
366 'uri' => '/cgi-bin/logs.cgi/proxylog.dat',
367 'title' => "$tr{'proxy logs'}",
370 $sublogs->{'40.firewall'} = {'caption' => $tr{'firewall logs'},
371 'uri' => '/cgi-bin/logs.cgi/firewalllog.dat',
372 'title' => "$tr{'firewall logs'}",
375 $sublogs->{'50.ids'} = {'caption' => $tr{'ids logs'},
376 'uri' => '/cgi-bin/logs.cgi/ids.dat',
377 'title' => "$tr{'ids logs'}",
380 $sublogs->{'60.urlfilter'} = {
381 'caption' => $tr{'urlfilter log'},
382 'uri' => '/cgi-bin/logs.cgi/urlfilter.dat',
383 'title' => "$tr{'urlfilter log'}",
386 $sublogs->{'70.openvpn'} = {'caption' => $tr{'openvpn log'},
387 'uri' => '/cgi-bin/logs.cgi/openvpn.dat',
388 'title' => "$tr{'openvpn log'}",
391 $sublogs->{'80.system'} = {'caption' => $tr{'system logs'},
392 'uri' => '/cgi-bin/logs.cgi/log.dat',
393 'title' => "$tr{'system logs'}",
396 $sublogs->{'90.userlog'} = {'caption' => $tr{'user proxy logs'},
397 'uri' => '/cgi-bin/logs.cgi/userlog.dat',
398 'title' => "$tr{'user log'}",
402 my %subipfirehash = ();
403 my $subipfire = \
%subipfirehash;
404 $subipfire->{'10.pakfire'} = {'caption' => 'Pakfire',
405 'uri' => '/cgi-bin/pakfire.cgi',
406 'title' => "Pakfire",
409 $subipfire->{'20.asterisk'} = {'caption' => 'Asterisk',
410 'uri' => '/cgi-bin/asterisk.cgi',
411 'title' => "Asterisk",
414 $subipfire->{'30.samba'} = {'caption' => 'Samba',
415 'uri' => '/cgi-bin/samba.cgi',
419 $subipfire->{'99.help'} = {'caption' => $tr{'help'},
420 'uri' => '/cgi-bin/help.cgi',
421 'title' => "$tr{'help'}",
427 $menu->{'01.system'} = {'caption' => $tr{'alt system'},
429 'subMenu' => $subsystem
431 $menu->{'02.status'} = {'caption' => $tr{'status'},
433 'subMenu' => $substatus
435 $menu->{'03.network'} = {'caption' => $tr{'network'},
437 'subMenu' => $subnetwork
439 $menu->{'04.services'} = {'caption' => $tr{'alt services'},
441 'subMenu' => $subservices
443 $menu->{'05.firewall'} = {'caption' => $tr{'firewall'},
445 'subMenu' => $subfirewall
447 $menu->{'06.proxy'} = {'caption' => $tr{'alt proxy'},
449 'subMenu' => $subproxy
451 $menu->{'07.ipfire'} = {'caption' => 'IPFire',
453 'subMenu' => $subipfire
455 $menu->{'08.logs'} = {'caption' => $tr{'alt logs'},
457 'subMenu' => $sublogs
460 if (! blue_used
() && ! orange_used
()) {
461 $menu->{'05.firewall'}{'subMenu'}->{'40.dmz'}{'enabled'} = 0;
464 $menu->{'05.firewall'}{'subMenu'}->{'30.wireless'}{'enabled'} = 0;
466 if (! $ethsettings{'CONFIG_TYPE'} =~ /^(2|3|6|7)$/ && $ethsettings{'RED_TYPE'} eq 'STATIC' ) {
467 $menu->{'03.network'}{'subMenu'}->{'70.aliases'}{'enabled'} = 1;
473 print "Pragma: no-cache\n";
474 print "Cache-control: no-cache\n";
475 print "Connection: close\n";
476 print "Content-type: text/html\n\n";
479 sub is_menu_visible
($) {
482 return (-e
$ENV{'DOCUMENT_ROOT'}."/../$link");
488 if (! $root->{'enabled'}) {
491 if ($root->{'uri'} !~ /^$/) {
493 if ($root->{'vars'} !~ /^$/) {
494 $vars = '?'. $root->{'vars'};
496 if (! is_menu_visible
($root->{'uri'})) {
499 return $root->{'uri'}.$vars;
501 my $submenus = $root->{'subMenu'};
505 foreach my $item (sort keys %$submenus) {
506 my $link = getlink
($submenus->{$item});
518 my $uri = $conf->{'uri'};
519 my $vars = $conf->{'vars'};
520 my $novars = $conf->{'novars'};
525 if ($uri ne $URI[0]) {
529 if ($URI[1] !~ /^$/) {
536 return ($URI[1] eq $vars);
546 foreach my $item (sort keys %$root) {
547 my $val = $root->{$item};
548 if (compare_url
($val)) {
549 $val->{'selected'} = 1;
550 if ($val->{'title'} !~ /^$/) {
551 return $val->{'title'};
553 return 'EMPTY TITLE';
556 my $title = gettitle
($val->{'subMenu'});
558 $val->{'selected'} = 1;
572 foreach my $k1 ( sort keys %$menu ) {
573 if (! $menu->{$k1}{'enabled'}) {
577 my $link = getlink
($menu->{$k1});
581 if (! is_menu_visible
($link)) {
584 if ($menu->{$k1}->{'selected'}) {
585 print '<li class="selected">';
591 <div class="rcorner">
592 <a href="$link">$menu->{$k1}{'caption'}</a>
612 foreach my $item (%$root) {
613 if ($root->{$item}{'selected'}) {
614 return $root->{$item};
619 sub showsubsection
($$) {
629 my $selected = getselected
($root);
633 my $submenus = $selected->{'subMenu'};
643 foreach my $item (sort keys %$submenus) {
644 my $hash = $submenus->{$item};
645 if (! $hash->{'enabled'}) {
649 my $link = getlink
($hash);
653 if (! is_menu_visible
($link)) {
656 if ($hash->{'selected'}) {
657 print '<li class="selected">';
663 <a href="$link">$hash->{'caption'}</a>
678 sub showsubsubsection
($) {
683 my $selected = getselected
($root);
687 if (! $selected->{'subMenu'}) {
691 showsubsection
($selected->{'subMenu'}, 'menu-subtop');
697 if ($URI[0] =~ /.*\/([^\
/]+)\.cgi/) {
702 $helpfile .= '.help.html';
704 my $helpuri = '/doc/'.$language.'/'.$helpfile;
705 if (! -e
$ENV{'DOCUMENT_ROOT'}.$helpuri) {
715 my $extrahead = shift;
717 @URI=split ('\?', $ENV{'REQUEST_URI'} );
718 &readhash
("${swroot}/main/settings", \
%settings);
721 my $h2 = gettitle
($menu);
722 my $helpuri = get_helpuri
();
724 $title = "IPFire - $title";
725 if ($settings{'WINDOWWITHHOSTNAME'} eq 'on') {
726 $title = "$settings{'HOSTNAME'}.$settings{'DOMAINNAME'} - $title";
731 PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
732 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
736 <title>$title</title>
739 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
742 if ($settings{'FX'} eq 'on') {
744 <meta http-equiv="Page-Enter" content="blendTrans(Duration=0.5,Transition=12)">
745 <meta http-equiv="Page-Exit" content="blendTrans(Duration=0.5,Transition=12)">
749 <link rel
="shortcut icon" href
="/favicon.ico" />
750 <style type
="text/css">\
@import url
(/include
/style.css);</style
>
751 <style type
="text/css">\
@import url
(/include
/menu.css);</style
>
752 <style type
="text/css">\
@import url
(/include
/content.css);</style
>
753 <script language
="javascript" type
="text/javascript">
755 function swapVisibility
(id
) {
756 el
= document
.getElementById
(id
);
757 if(el
.style
.display
!= 'block') {
758 el
.style
.display
= 'block'
761 el
.style
.display
= 'none'
768 <!-- IPFIRE HEADER
-->
773 <img id
="logo-product" src
="/images/logo_ipfire.gif">
774 <div id
="header-icons">
775 <a href
="http://users.ipfire.eu/" target
="_blank"><img border
="0" src
="/images/help.gif"></a
>
792 &showsubsection
($menu);
795 <p><center><img src="/images/iptux.png" width='160px' height='160px'></center></p>
797 <td width="100%" valign="top">
798 <div id="page-content">
803 &showsubsubsection
($menu);
806 require 'ipfire-network.pl';
807 $supported = check_support
();
808 warn_unsupported
($supported);
813 my $status = &connectionstatus
();
814 $uptime = `/usr/bin/uptime`;
819 <div style="font-size: 9px"><b>Status:</b> $status <b>Uptime:</b>$uptime <b>Version:</b> $FIREBUILD</div>
835 $bgcolor = "style='background-color: $colourerr;'";
843 # print "</td></tr></table></td></tr></table>\n"
852 if ($caption) { print "<h3>$caption</h3>\n"; } else { print " "; }
854 print "<table class=\"list\"><tr><td align=\"$align\">\n";
859 print "</td></tr></table><br><br>";
864 my $filename = $_[0];
867 # write cgi vars to the file.
868 open(FILE
, ">${filename}") or die "Unable to write file $filename";
870 foreach $var (keys %$hash)
872 $val = $hash->{$var};
873 # Darren Critchley Jan 17, 2003 added the following because when submitting with a graphic, the x and y
874 # location of the mouse are submitted as well, this was being written to the settings file causing
875 # some serious grief! This skips the variable.x and variable.y
876 if (!($var =~ /(.x|.y)$/)) {
879 if (!($var =~ /^ACTION/)) {
880 print FILE
"${var}=${val}\n"; }
888 my $filename = $_[0];
892 open(FILE
, $filename) or die "Unable to read file $filename";
897 ($var, $val) = split /=/, $_, 2;
903 # Untaint variables read from hash
904 $var =~ /([A-Za-z0-9_-]*)/; $var = $1;
905 $val =~ /([\w\W]*)/; $val = $1;
906 $hash->{$var} = $val;
913 my ($hash, $params) = @_;
914 my $cgi = CGI
->new ();
915 $hash->{'__CGI__'} = $cgi;
916 return if ($ENV{'REQUEST_METHOD'} ne 'POST');
917 if (!$params->{'wantfile'}) {
918 $CGI::DISABLE_UPLOADS
= 1;
919 $CGI::POST_MAX
= 512 * 1024;
921 $CGI::POST_MAX
= 10 * 1024 * 1024;
924 $cgi->referer() =~ m/^https?\:\/\
/([^\/]+)/;
926 $cgi->url() =~ m/^https?\:\/\
/([^\/]+)/;
928 return if ($referer ne $servername);
930 ### Modified for getting multi-vars, split by |
931 %temp = $cgi->Vars();
932 foreach my $key (keys %temp) {
933 $hash->{$key} = $temp{$key};
934 $hash->{$key} =~ s/\0/|/g;
935 $hash->{$key} =~ s/^\s*(.*?)\s*$/$1/;
938 if (($params->{'wantfile'})&&($params->{'filevar'})) {
939 $hash->{$params->{'filevar'}} = $cgi->upload
940 ($params->{'filevar'});
947 my $logmessage = $_[0];
948 $logmessage =~ /([\w\W]*)/;
950 system('/usr/bin/logger', '-t', 'ipfire', $logmessage);
955 my ($dev, $ino, $mode, $nlink, $uid, $gid, $rdev, $size,
956 $atime, $mtime, $ctime, $blksize, $blocks) = stat $_[0];
959 my $totalsecs = $now - $mtime;
960 my $days = int($totalsecs / 86400);
961 my $totalhours = int($totalsecs / 3600);
962 my $hours = $totalhours % 24;
963 my $totalmins = int($totalsecs / 60);
964 my $mins = $totalmins % 60;
965 my $secs = $totalsecs % 60;
967 return "${days}d ${hours}h ${mins}m ${secs}s";
974 if (!($ip =~ /^(\d+)\.(\d+)\.(\d+)\.(\d+)$/)) {
978 @octets = ($1, $2, $3, $4);
983 if ($_ < 0 || $_ > 255) {
995 if (&validip
($mask)) {
997 # second part a number?
1000 if (!($mask =~ /^\d+$/)) {
1002 if ($mask >= 0 && $mask <= 32) {
1009 my $ipormask = $_[0];
1011 # see if it is a IP only.
1012 if (&validip
($ipormask)) {
1014 # split it into number and mask.
1015 if (!($ipormask =~ /^(.*?)\/(.*?
)$/)) {
1019 # first part not a ip?
1020 if (!(&validip
($ip))) {
1022 return &validmask
($mask);
1027 my $ipandmask = $_[0];
1029 # split it into number and mask.
1030 if (!($ipandmask =~ /^(.*?)\/(.*?
)$/)) {
1034 # first part not a ip?
1035 if (!(&validip
($ip))) {
1037 return &validmask
($mask);
1048 if ($_ >= 1 && $_ <= 65535) {
1055 my $checkmac = $_[0];
1056 my $ot = '[0-9a-f]{2}'; # 2 Hex digits (one octet)
1057 if ($checkmac !~ /^$ot:$ot:$ot:$ot:$ot:$ot$/i)
1066 # Checks a hostname against RFC1035
1067 my $hostname = $_[0];
1069 # Each part should be at least two characters in length
1070 # but no more than 63 characters
1071 if (length ($hostname) < 2 || length ($hostname) > 63) {
1073 # Only valid characters are a-z, A-Z, 0-9 and -
1074 if ($hostname !~ /^[a-zA-Z0-9-]*$/) {
1076 # First character can only be a letter or a digit
1077 if (substr ($hostname, 0, 1) !~ /^[a-zA-Z0-9]*$/) {
1079 # Last character can only be a letter or a digit
1080 if (substr ($hostname, -1, 1) !~ /^[a-zA-Z0-9]*$/) {
1087 # Checks a domain name against RFC1035
1088 my $domainname = $_[0];
1089 my @parts = split (/\./, $domainname); # Split hostname at the '.'
1091 foreach $part (@parts) {
1092 # Each part should be at least two characters in length
1093 # but no more than 63 characters
1094 if (length ($part) < 2 || length ($part) > 63) {
1096 # Only valid characters are a-z, A-Z, 0-9 and -
1097 if ($part !~ /^[a-zA-Z0-9-]*$/) {
1099 # First character can only be a letter or a digit
1100 if (substr ($part, 0, 1) !~ /^[a-zA-Z0-9]*$/) {
1102 # Last character can only be a letter or a digit
1103 if (substr ($part, -1, 1) !~ /^[a-zA-Z0-9]*$/) {
1111 # Checks a fully qualified domain name against RFC1035
1113 my @parts = split (/\./, $fqdn); # Split hostname at the '.'
1114 if (scalar(@parts) < 2) { # At least two parts should
1115 return 0;} # exist in a FQDN
1116 # (i.e. hostname.domain)
1117 foreach $part (@parts) {
1118 # Each part should be at least two characters in length
1119 # but no more than 63 characters
1120 if (length ($part) < 2 || length ($part) > 63) {
1122 # Only valid characters are a-z, A-Z, 0-9 and -
1123 if ($part !~ /^[a-zA-Z0-9-]*$/) {
1125 # First character can only be a letter or a digit
1126 if (substr ($part, 0, 1) !~ /^[a-zA-Z0-9]*$/) {
1128 # Last character can only be a letter or a digit
1129 if (substr ($part, -1, 1) !~ /^[a-zA-Z0-9]*$/) {
1135 sub validportrange
# used to check a port range
1137 my $port = $_[0]; # port values
1138 $port =~ tr/-/:/; # replace all - with colons just in case someone used -
1139 my $srcdst = $_[1]; # is it a source or destination port
1141 if (!($port =~ /^(\d+)\:(\d+)$/)) {
1143 if (!(&validport
($port))) {
1144 if ($srcdst eq 'src'){
1145 return $tr{'source port numbers'};
1147 return $tr{'destination port numbers'};
1155 if ($srcdst eq 'src'){
1156 return $tr{'bad source range'};
1158 return $tr{'bad destination range'};
1163 if (!(&validport
($_))) {
1164 if ($srcdst eq 'src'){
1165 return $tr{'source port numbers'};
1167 return $tr{'destination port numbers'};
1175 # Test if IP is within a subnet
1176 # Call: IpInSubnet (Addr, Subnet, Subnet Mask)
1177 # Subnet can be an IP of the subnet: 10.0.0.0 or 10.0.0.1
1178 # Everything in dottted notation
1179 # Return: TRUE/FALSE
1182 $ip = unpack('N', inet_aton
(shift));
1183 $start = unpack('N', inet_aton
(shift));
1184 $mask = unpack('N', inet_aton
(shift));
1185 $start &= $mask; # base of subnet...
1186 $end = $start + ~$mask;
1187 return (($ip >= $start) && ($ip <= $end));
1192 return 0 if ( $mail !~ /^[0-9a-zA-Z\.\-\_]+\@[0-9a-zA-Z\.\-]+$/ );
1193 return 0 if ( $mail =~ /^[^0-9a-zA-Z]|[^0-9a-zA-Z]$/);
1194 return 0 if ( $mail !~ /([0-9a-zA-Z]{1})\@./ );
1195 return 0 if ( $mail !~ /.\@([0-9a-zA-Z]{1})/ );
1196 return 0 if ( $mail =~ /.\.\-.|.\-\..|.\.\..|.\-\-./g );
1197 return 0 if ( $mail =~ /.\.\_.|.\-\_.|.\_\..|.\_\-.|.\_\_./g );
1198 return 0 if ( $mail !~ /\.([a-zA-Z]{2,3})$/ );
1203 my ($filename, $hash) = @_;
1205 open(FILE
, $filename) or die "Unable to read file $filename";
1208 my ($key, $rest, @temp);
1210 ($key, $rest) = split (/,/, $_, 2);
1211 if ($key =~ /^[0-9]+$/ && $rest) {
1212 @temp = split (/,/, $rest);
1213 $hash->{$key} = \
@temp;
1220 sub writehasharray
{
1221 my ($filename, $hash) = @_;
1224 open(FILE
, ">$filename") or die "Unable to write to file $filename";
1226 foreach $key (keys %$hash) {
1227 if ( $hash->{$key} ) {
1229 foreach $i (0 .. $#{$hash->{$key}}) {
1230 print FILE
",$hash->{$key}[$i]";
1239 sub findhasharraykey
{
1240 foreach my $i (1 .. 1000000) {
1241 if ( ! exists $_[0]{$i}) {
1249 my $outstring =$_[0];
1250 $outstring =~ tr/,/ / if not defined $_[1] or $_[1] ne 'y';
1251 $outstring =~ s/&/&/g;
1252 $outstring =~ s/\'/'/g;
1253 $outstring =~ s/\"/"/g;
1254 $outstring =~ s/</</g;
1255 $outstring =~ s/>/>/g;
1259 sub connectionstatus
1261 my %pppsettings = ();
1262 my %netsettings = ();
1265 $pppsettings{'PROFILENAME'} = 'None';
1266 &General
::readhash
("${General::swroot}/ppp/settings", \
%pppsettings);
1267 &General
::readhash
("${General::swroot}/ethernet/settings", \
%netsettings);
1270 if ( ! ( $netsettings{'CONFIG_TYPE'} =~ /^(2|3|6|7)$/ && $netsettings{'RED_TYPE'} =~ /^(DHCP|STATIC)$/ ) ) {
1271 $profileused="- $pppsettings{'PROFILENAME'}";
1274 if ( ( $pppsettings{'METHOD'} eq 'DHCP' && $netsettings{'RED_TYPE'} ne 'PPTP')
1275 || $netsettings{'RED_TYPE'} eq 'DHCP' ) {
1276 if (open(IFACE
, "${General::swroot}/red/iface")) {
1280 $iface =~ /([a-zA-Z0-9]*)/; $iface = $1;
1284 my ($timestr, $connstate);
1285 if ($netsettings{'CONFIG_TYPE'} =~ /^(0|1|4|5)$/ && $pppsettings{'TYPE'} =~ /^isdn/) {
1286 # Count ISDN channels
1287 my ($idmap, $chmap, $drmap, $usage, $flags, $phone);
1291 open (FILE
, "/dev/isdninfo");
1293 $idmap = <FILE
>; chop $idmap;
1294 $chmap = <FILE
>; chop $chmap;
1295 $drmap = <FILE
>; chop $drmap;
1296 $usage = <FILE
>; chop $usage;
1297 $flags = <FILE
>; chop $flags;
1298 $phone = <FILE
>; chop $phone;
1300 $phone =~ s/^phone(\s*):(\s*)//;
1302 @phonenumbers = split / /, $phone;
1304 foreach (@phonenumbers) {
1311 ## Connection status
1315 } elsif ($count == 1) {
1321 if (-e
"${General::swroot}/red/active") {
1322 $timestr = &General
::age
("${General::swroot}/red/active");
1323 $connstate = "<span class='ipcop_StatusBig'>$Lang::tr{'connected'} - $number channel (<span class='ipcop_StatusBigRed'>$timestr</span>) $profileused</span>";
1326 if (-e
"${General::swroot}/red/dial-on-demand") {
1327 $connstate = "<span class='ipcop_StatusBig'>$Lang::tr{'dod waiting'} $profileused</span>";
1329 $connstate = "<span class='ipcop_StatusBig'>$Lang::tr{'idle'} $profileused</span>";
1332 $connstate = "<span class='ipcop_StatusBig'>$Lang::tr{'connecting'} $profileused</span>";
1335 } elsif ($netsettings{'RED_TYPE'} eq "STATIC" || $pppsettings {'METHOD'} eq 'STATIC') {
1336 if (-e
"${General::swroot}/red/active") {
1337 $timestr = &General
::age
("${General::swroot}/red/active");
1338 $connstate = "<span class='ipcop_StatusBig'>$Lang::tr{'connected'} (<span class='ipcop_StatusBigRed'>$timestr</span>) $profileused</span>";
1340 $connstate = "<span class='ipcop_StatusBig'>$Lang::tr{'idle'} $profileused</span>";
1342 } elsif ( ( (-e
"${General::swroot}/dhcpc/dhcpcd-$iface.pid") && $netsettings{'RED_TYPE'} ne 'PPTP' ) ||
1343 !system("/bin/ps -ef | /bin/grep -q '[p]ppd'") || !system("/bin/ps -ef | /bin/grep -q '[c]onnectioncheck'")) {
1344 if (-e
"${General::swroot}/red/active") {
1345 $timestr = &General
::age
("${General::swroot}/red/active");
1346 if ($pppsettings{'TYPE'} =~ /^(modem|bewanadsl|conexantpciadsl|eagleusbadsl)$/) {
1348 if ($pppsettings{'TYPE'} eq 'modem') {
1349 open(CONNECTLOG
, "/var/log/connect.log");
1350 while (<CONNECTLOG
>) {
1352 $speed = (split / /)[6];
1356 } elsif ($pppsettings{'TYPE'} eq 'bewanadsl') {
1357 $speed = `/usr/bin/unicorn_status | /bin/grep Rate | /usr/bin/cut -f2 -d ':'`;
1358 } elsif ($pppsettings{'TYPE'} eq 'conexantpciadsl') {
1359 $speed = `/bin/cat /proc/net/atm/CnxAdsl:* | /bin/grep 'Line Rates' | /bin/sed -e 's+Line Rates: Receive+Rx+' -e 's+Transmit+Tx+'`;
1360 } elsif ($pppsettings{'TYPE'} eq 'eagleusbadsl') {
1361 $speed = `/usr/sbin/eaglestat | /bin/grep Rate`;
1363 $connstate = "<span class='ipcop_StatusBig'>$Lang::tr{'connected'} (<span class='ipcop_StatusBigRed'>$timestr</span>) $profileused (\@$speed)</span>";
1365 $connstate = "<span class='ipcop_StatusBig'>$Lang::tr{'connected'} (<span class='ipcop_StatusBigRed'>$timestr</span>) $profileused</span>";
1368 if (-e
"${General::swroot}/red/dial-on-demand") {
1369 $connstate = "<span class='ipcop_StatusBig'>$Lang::tr{'dod waiting'} $profileused</span>";
1371 $connstate = "<span class='ipcop_StatusBig'>$Lang::tr{'connecting'} $profileused</span>";
1375 $connstate = "<span class='ipcop_StatusBig'>$Lang::tr{'idle'} $profileused</span>";
1381 # Darren Critchley - darrenc@telus.net - (c) 2003
1382 # &srtarray(SortOrder, AlphaNumeric, SortDirection, ArrayToBeSorted)
1383 # This subroutine will take the following parameters:
1384 # ColumnNumber = the column which you want to sort on, starts at 1
1385 # AlphaNumberic = a or n (lowercase) defines whether the sort should be alpha or numberic
1386 # SortDirection = asc or dsc (lowercase) Ascending or Descending sort
1387 # ArrayToBeSorted = the array that wants sorting
1389 # Returns an array that is sorted to your specs
1391 # If SortOrder is greater than the elements in array, then it defaults to the first element
1394 my ($colno, $alpnum, $srtdir, @tobesorted) = @_;
1399 my $ttlitems = scalar @tobesorted; # want to know the number of rows in the passed array
1400 if ($ttlitems < 1){ # if no items, don't waste our time lets leave
1401 return (@tobesorted);
1403 my @tmp = split(/\,/,$tobesorted[0]);
1404 $ttlitems = scalar @tmp; # this should be the number of elements in each row of the passed in array
1406 # Darren Critchley - validate parameters
1407 if ($colno > $ttlitems){$colno = '1';}
1408 $colno--; # remove one from colno to deal with arrays starting at 0
1409 if($colno < 0){$colno = '0';}
1410 if ($alpnum ne '') { $alpnum = lc($alpnum); } else { $alpnum = 'a'; }
1411 if ($srtdir ne '') { $srtdir = lc($srtdir); } else { $srtdir = 'src'; }
1413 foreach $line (@tobesorted)
1417 my @temp = split(/\,/,$line);
1418 # Darren Critchley - juggle the fields so that the one we want to sort on is first
1419 my $tmpholder = $temp[0];
1420 $temp[0] = $temp[$colno];
1421 $temp[$colno] = $tmpholder;
1423 for ($ctr=0; $ctr < $ttlitems ; $ctr++) {
1424 $newline=$newline . $temp[$ctr] . ",";
1427 push(@tmparray,$newline);
1430 if ($alpnum eq 'n') {
1431 @tmparray = sort {$a <=> $b} @tmparray;
1433 @tmparray = (sort @tmparray);
1435 foreach $line (@tmparray)
1439 my @temp = split(/\,/,$line);
1440 my $tmpholder = $temp[0];
1441 $temp[0] = $temp[$colno];
1442 $temp[$colno] = $tmpholder;
1444 for ($ctr=0; $ctr < $ttlitems ; $ctr++){
1445 $newline=$newline . $temp[$ctr] . ",";
1448 push(@srtedarray,$newline);
1452 if ($srtdir eq 'dsc') {
1453 @tmparray = reverse(@srtedarray);
1456 return (@srtedarray);
1460 sub speedtouchversion
1462 if (-f
"/proc/bus/usb/devices")
1464 $speedtouch=`/bin/cat /proc/bus/usb/devices | /bin/grep 'Vendor=06b9 ProdID=4061' | /usr/bin/cut -d ' ' -f6`;
1465 if ($speedtouch eq '') {
1466 $speedtouch= $tr{'connect the modem'};
1469 $speedtouch='USB '.$tr{'not running'};
1474 sub CheckSortOrder
{
1475 #Sorting of allocated leases
1476 if ($ENV{'QUERY_STRING'} =~ /^IPADDR|^ETHER|^HOSTNAME|^ENDTIME/ ) {
1477 my $newsort=$ENV{'QUERY_STRING'};
1478 &readhash
("${swroot}/dhcp/settings", \
%dhcpsettings);
1479 $act=$dhcpsettings{'SORT_LEASELIST'};
1481 if ($act =~ $newsort) {
1482 if ($act !~ 'Rev') {$Rev='Rev'};
1486 $dhcpsettings{'SORT_LEASELIST'}=$newsort;
1487 &writehash
("${swroot}/dhcp/settings", \
%dhcpsettings);
1488 $dhcpsettings{'ACTION'} = 'SORT'; # avoid the next test "First lauch"
1493 sub PrintActualLeases
1495 &openbox
('100%', 'left', $tr{'current dynamic leases'});
1497 <table width='100%'>
1499 <td width='25%' align='center'><a href='$ENV{'SCRIPT_NAME'}?IPADDR'><b>$tr{'ip address'}</b></a></td>
1500 <td width='25%' align='center'><a href='$ENV{'SCRIPT_NAME'}?ETHER'><b>$tr{'mac address'}</b></a></td>
1501 <td width='20%' align='center'><a href='$ENV{'SCRIPT_NAME'}?HOSTNAME'><b>$tr{'hostname'}</b></a></td>
1502 <td width='30%' align='center'><a href='$ENV{'SCRIPT_NAME'}?ENDTIME'><b>$tr{'lease expires'} (local time d/m/y)</b></a></td>
1507 open(LEASES
,"/var/state/dhcp/dhcpd.leases") or die "Can't open dhcpd.leases";
1508 while ($line = <LEASES
>) {
1509 next if( $line =~ /^\s*#/ );
1511 @temp = split (' ', $line);
1513 if ($line =~ /^\s*lease/) {
1515 #All field are not necessarily read. Clear everything
1521 if ($line =~ /^\s*ends/) {
1522 $line =~ /(\d+)\/(\d
+)\
/(\d+) (\d+):(\d+):(\d+)/;
1523 $endtime = timegm
($6, $5, $4, $3, $2 - 1, $1 - 1900);
1526 if ($line =~ /^\s*hardware ethernet/) {
1531 if ($line =~ /^\s*client-hostname/) {
1532 $hostname = "$temp[1] $temp[2] $temp[3]";
1533 $hostname =~ s/;//g;
1534 $hostname =~ s/\"//g;
1538 @record = ('IPADDR',$ip,'ENDTIME',$endtime,'ETHER',$ether,'HOSTNAME',$hostname);
1539 $record = {}; # create a reference to empty hash
1540 %{$record} = @record; # populate that hash with @record
1541 $entries{$record->{'IPADDR'}} = $record; # add this to a hash of hashes
1547 foreach my $key (sort leasesort
keys %entries) {
1549 my $hostname = &cleanhtml
($entries{$key}->{HOSTNAME
},"y");
1552 print "<tr bgcolor='$table1colour'>";
1555 print "<tr bgcolor='$table2colour'>";
1559 <td align='center'>$entries{$key}->{IPADDR}</td>
1560 <td align='center'>$entries{$key}->{ETHER}</td>
1561 <td align='center'> $hostname </td>
1566 ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $dst) = localtime ($entries{$key}->{ENDTIME
});
1567 $enddate = sprintf ("%02d/%02d/%d %02d:%02d:%02d",$mday,$mon+1,$year+1900,$hour,$min,$sec);
1569 if ($entries{$key}->{ENDTIME
} < time() ){
1570 print "<strike>$enddate</strike>";
1583 # This sub is used during display of actives leases
1585 if (rindex ($dhcpsettings{'SORT_LEASELIST'},'Rev') != -1)
1587 $qs=substr ($dhcpsettings{'SORT_LEASELIST'},0,length($dhcpsettings{'SORT_LEASELIST'})-3);
1588 if ($qs eq 'IPADDR') {
1589 @a = split(/\./,$entries{$a}->{$qs});
1590 @b = split(/\./,$entries{$b}->{$qs});
1596 $entries{$b}->{$qs} cmp $entries{$a}->{$qs};
1601 $qs=$dhcpsettings{'SORT_LEASELIST'};
1602 if ($qs eq 'IPADDR') {
1603 @a = split(/\./,$entries{$a}->{$qs});
1604 @b = split(/\./,$entries{$b}->{$qs});
1610 $entries{$a}->{$qs} cmp $entries{$b}->{$qs};
1617 opendir(DIR
, "${swroot}/uplinks/") || return \
@uplinks;
1618 foreach my $dir (readdir(DIR
)) {
1619 next if ($dir =~ /^\./);
1620 next if (-f
"${swroot}/uplinks/$dir");
1621 push(@uplinks, $dir);
1628 my $filename = shift;
1630 open (F
, $filename) || return "";
1637 sub get_red_ifaces_by_type
($) {
1639 my @gottypeiface = ();
1640 my @gottypeuplink = ();
1643 my $ref=get_uplinks
();
1646 foreach my $link (@uplinks) {
1648 &readhash
("${swroot}/uplinks/$link/settings", \
%set);
1650 push(@gottype, $link);
1652 my $iface = $set{'RED_DEV'};
1654 $iface = get_iface
("${swroot}/uplinks/$link/interface");
1658 if ($set{'RED_TYPE'} eq $type) {
1659 push(@gottypeiface, $iface);
1660 push(@gottypeuplink, $link);
1663 return (\
@gottypeiface, \
@gottypeuplink, \
@gottype);
1666 sub get_red_ifaces
() {
1667 return `cat ${swroot}/uplinks/*/interface 2>/dev/null`;
1670 sub get_zone_devices
($) {
1673 open (FILE
, "${swroot}/ethernet/$bridge") || return "";
1674 foreach my $line (<FILE
>) {
1677 push(@ifaces, $line);