]>
git.ipfire.org Git - people/pmueller/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}";
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'}",
271 $subnetwork->{'80.wakeonlan'} = {
272 'caption' => $tr{'WakeOnLan'},
273 'uri' => '/cgi-bin/wakeonlan.cgi',
274 'title' => "$tr{'WakeOnLan'}",
278 my %subserviceshash = ();
279 my $subservices = \
%subserviceshash;
282 $subservices->{'10.openvpn'} = {
283 'caption' => 'OpenVPN',
284 'uri' => '/cgi-bin/ovpnmain.cgi',
285 'title' => "$tr{'virtual private networking'}",
288 $subservices->{'20.ipsec'} = {
289 'caption' => 'IPSec',
290 'uri' => '/cgi-bin/vpnmain.cgi',
291 'title' => "$tr{'virtual private networking'}",
294 $subservices->{'30.dyndns'} = {'caption' => $tr{'dynamic dns'},
295 'uri' => '/cgi-bin/ddns.cgi',
296 'title' => "$tr{'dynamic dns'}",
299 $subservices->{'40.time'} = {'caption' => $tr{'time server'},
300 'uri' => '/cgi-bin/time.cgi',
301 'title' => "$tr{'time server'}",
304 $subservices->{'50.qos'} = {'caption' => 'Quality of Service',
305 'uri' => '/cgi-bin/qos.cgi',
306 'title' => "Quality of Service",
309 $subservices->{'60.ids'} = {'caption' => $tr{'intrusion detection'},
311 'uri' => '/cgi-bin/ids.cgi',
312 'title' => "$tr{'intrusion detection system'}",
317 my %subfirewallhash = ();
318 my $subfirewall = \
%subfirewallhash;
321 $subfirewall->{'10.dnat'} = {
322 'caption' => $tr{'ssport forwarding'},
323 'uri' => '/cgi-bin/portfw.cgi',
324 'title' => "$tr{'ssport forwarding'}",
327 $subfirewall->{'20.xtaccess'} = {
328 'caption' => $tr{'external access'},
329 'uri' => '/cgi-bin/xtaccess.cgi',
330 'title' => "$tr{'external access'}",
333 $subfirewall->{'30.wireless'} = {
334 'caption' => $tr{'blue access'},
335 'uri' => '/cgi-bin/wireless.cgi',
336 'title' => "$tr{'blue access'}",
339 $subfirewall->{'40.dmz'} = {
340 'caption' => $tr{'ssdmz pinholes'},
341 'uri' => '/cgi-bin/dmzholes.cgi',
342 'title' => "$tr{'dmz pinhole configuration'}",
345 $subfirewall->{'50.outgoing'} = {
346 'caption' => $tr{'outgoing firewall'},
347 'uri' => '/cgi-bin/outgoingfw.cgi',
348 'title' => "$tr{'outgoing firewall'}",
351 $subfirewall->{'60.fwopts'} = {
352 'caption' => $tr{'options fw'},
353 'uri' => '/cgi-bin/optionsfw.cgi',
354 'title' => "$tr{'options fw'}",
358 my %sublogshash = ();
359 my $sublogs = \
%sublogshash;
361 $sublogs->{'10.summary'} = {'caption' => $tr{'log summary'},
362 'uri' => '/cgi-bin/logs.cgi/summary.dat',
363 'title' => "$tr{'log summary'}",
366 $sublogs->{'20.settings'} = {'caption' => $tr{'log settings'},
367 'uri' => '/cgi-bin/logs.cgi/config.dat',
368 'title' => "$tr{'log settings'}",
371 $sublogs->{'30.proxy'} = {'caption' => $tr{'proxy logs'},
372 'uri' => '/cgi-bin/logs.cgi/proxylog.dat',
373 'title' => "$tr{'proxy logs'}",
376 $sublogs->{'40.firewall'} = {'caption' => $tr{'firewall logs'},
377 'uri' => '/cgi-bin/logs.cgi/firewalllog.dat',
378 'title' => "$tr{'firewall logs'}",
381 $sublogs->{'50.ids'} = {'caption' => $tr{'ids logs'},
382 'uri' => '/cgi-bin/logs.cgi/ids.dat',
383 'title' => "$tr{'ids logs'}",
386 $sublogs->{'60.urlfilter'} = {
387 'caption' => $tr{'urlfilter log'},
388 'uri' => '/cgi-bin/logs.cgi/urlfilter.dat',
389 'title' => "$tr{'urlfilter log'}",
392 $sublogs->{'70.openvpn'} = {'caption' => $tr{'openvpn log'},
393 'uri' => '/cgi-bin/logs.cgi/openvpn.dat',
394 'title' => "$tr{'openvpn log'}",
397 $sublogs->{'80.system'} = {'caption' => $tr{'system logs'},
398 'uri' => '/cgi-bin/logs.cgi/log.dat',
399 'title' => "$tr{'system logs'}",
402 $sublogs->{'90.userlog'} = {'caption' => $tr{'user proxy logs'},
403 'uri' => '/cgi-bin/logs.cgi/userlog.dat',
404 'title' => "$tr{'user log'}",
408 my %subipfirehash = ();
409 my $subipfire = \
%subipfirehash;
410 $subipfire->{'10.pakfire'} = {'caption' => 'Pakfire',
411 'uri' => '/cgi-bin/pakfire.cgi',
412 'title' => "Pakfire",
415 $subipfire->{'20.asterisk'} = {'caption' => 'Asterisk',
416 'uri' => '/cgi-bin/asterisk.cgi',
417 'title' => "Asterisk",
420 $subipfire->{'30.samba'} = {'caption' => 'Samba',
421 'uri' => '/cgi-bin/samba.cgi',
425 $subipfire->{'99.help'} = {'caption' => $tr{'help'},
426 'uri' => '/cgi-bin/help.cgi',
427 'title' => "$tr{'help'}",
433 $menu->{'01.system'} = {'caption' => $tr{'alt system'},
435 'subMenu' => $subsystem
437 $menu->{'02.status'} = {'caption' => $tr{'status'},
439 'subMenu' => $substatus
441 $menu->{'03.network'} = {'caption' => $tr{'network'},
443 'subMenu' => $subnetwork
445 $menu->{'04.services'} = {'caption' => $tr{'alt services'},
447 'subMenu' => $subservices
449 $menu->{'05.firewall'} = {'caption' => $tr{'firewall'},
451 'subMenu' => $subfirewall
453 $menu->{'06.proxy'} = {'caption' => $tr{'alt proxy'},
455 'subMenu' => $subproxy
457 $menu->{'07.ipfire'} = {'caption' => 'IPFire',
459 'subMenu' => $subipfire
461 $menu->{'08.logs'} = {'caption' => $tr{'alt logs'},
463 'subMenu' => $sublogs
466 if (! blue_used
() && ! orange_used
()) {
467 $menu->{'05.firewall'}{'subMenu'}->{'40.dmz'}{'enabled'} = 0;
470 $menu->{'05.firewall'}{'subMenu'}->{'30.wireless'}{'enabled'} = 0;
472 if ( $ethsettings{'CONFIG_TYPE'} =~ /^(2|3|6|7)$/ && $ethsettings{'RED_TYPE'} eq 'STATIC' ) {
473 $menu->{'03.network'}{'subMenu'}->{'70.aliases'}{'enabled'} = 1;
479 print "Pragma: no-cache\n";
480 print "Cache-control: no-cache\n";
481 print "Connection: close\n";
482 print "Content-type: text/html\n\n";
485 sub is_menu_visible
($) {
488 return (-e
$ENV{'DOCUMENT_ROOT'}."/../$link");
494 if (! $root->{'enabled'}) {
497 if ($root->{'uri'} !~ /^$/) {
499 if ($root->{'vars'} !~ /^$/) {
500 $vars = '?'. $root->{'vars'};
502 if (! is_menu_visible
($root->{'uri'})) {
505 return $root->{'uri'}.$vars;
507 my $submenus = $root->{'subMenu'};
511 foreach my $item (sort keys %$submenus) {
512 my $link = getlink
($submenus->{$item});
524 my $uri = $conf->{'uri'};
525 my $vars = $conf->{'vars'};
526 my $novars = $conf->{'novars'};
531 if ($uri ne $URI[0]) {
535 if ($URI[1] !~ /^$/) {
542 return ($URI[1] eq $vars);
552 foreach my $item (sort keys %$root) {
553 my $val = $root->{$item};
554 if (compare_url
($val)) {
555 $val->{'selected'} = 1;
556 if ($val->{'title'} !~ /^$/) {
557 return $val->{'title'};
559 return 'EMPTY TITLE';
562 my $title = gettitle
($val->{'subMenu'});
564 $val->{'selected'} = 1;
578 foreach my $k1 ( sort keys %$menu ) {
579 if (! $menu->{$k1}{'enabled'}) {
583 my $link = getlink
($menu->{$k1});
587 if (! is_menu_visible
($link)) {
590 if ($menu->{$k1}->{'selected'}) {
591 print '<li class="selected">';
597 <div class="rcorner">
598 <a href="$link">$menu->{$k1}{'caption'}</a>
618 foreach my $item (%$root) {
619 if ($root->{$item}{'selected'}) {
620 return $root->{$item};
625 sub showsubsection
($$) {
635 my $selected = getselected
($root);
639 my $submenus = $selected->{'subMenu'};
649 foreach my $item (sort keys %$submenus) {
650 my $hash = $submenus->{$item};
651 if (! $hash->{'enabled'}) {
655 my $link = getlink
($hash);
659 if (! is_menu_visible
($link)) {
662 if ($hash->{'selected'}) {
663 print '<li class="selected">';
669 <a href="$link">$hash->{'caption'}</a>
684 sub showsubsubsection
($) {
689 my $selected = getselected
($root);
693 if (! $selected->{'subMenu'}) {
697 showsubsection
($selected->{'subMenu'}, 'menu-subtop');
703 if ($URI[0] =~ /.*\/([^\
/]+)\.cgi/) {
708 $helpfile .= '.help.html';
710 my $helpuri = '/doc/'.$language.'/'.$helpfile;
711 if (! -e
$ENV{'DOCUMENT_ROOT'}.$helpuri) {
721 my $extrahead = shift;
723 @URI=split ('\?', $ENV{'REQUEST_URI'} );
724 &readhash
("${swroot}/main/settings", \
%settings);
727 my $h2 = gettitle
($menu);
728 my $helpuri = get_helpuri
();
730 $title = "IPFire - $title";
731 if ($settings{'WINDOWWITHHOSTNAME'} eq 'on') {
732 $title = "$settings{'HOSTNAME'}.$settings{'DOMAINNAME'} - $title";
737 PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
738 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
742 <title>$title</title>
745 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
748 if ($settings{'FX'} eq 'on') {
750 <meta http-equiv="Page-Enter" content="blendTrans(Duration=0.5,Transition=12)">
751 <meta http-equiv="Page-Exit" content="blendTrans(Duration=0.5,Transition=12)">
756 <link rel="shortcut icon" href="/favicon.ico" />
757 <style type="text/css">\@import url(/include/style.css);</style>
758 <style type="text/css">\@import url(/include/menu.css);</style>
759 <style type="text/css">\@import url(/include/content.css);</style>
760 <script language="javascript" type="text/javascript">
762 function swapVisibility(id) {
763 el = document.getElementById(id);
764 if(el.style.display != 'block') {
765 el.style.display = 'block'
768 el.style.display = 'none'
775 <!-- IPFIRE HEADER -->
780 <img id="logo-product" src="/images/logo_ipfire.gif">
781 <div id="header-icons">
782 <a href="http://users.ipfire.eu/" target="_blank"><img border="0" src="/images/help.gif"></a>
799 &showsubsection
($menu);
802 <p><center><img src="/images/iptux.png" width='160px' height='160px'></center></p>
804 <td width="100%" valign="top">
805 <div id="page-content">
810 &showsubsubsection
($menu);
813 require 'ipfire-network.pl';
814 $supported = check_support
();
815 warn_unsupported
($supported);
820 my $status = &connectionstatus
();
821 $uptime = `/usr/bin/uptime`;
826 <div style="font-size: 9px"><b>Status:</b> $status <b>Uptime:</b>$uptime <b>Version:</b> $FIREBUILD</div>
842 $bgcolor = "style='background-color: $colourerr;'";
850 # print "</td></tr></table></td></tr></table>\n"
859 if ($caption) { print "<h3>$caption</h3>\n"; } else { print " "; }
861 print "<table class=\"list\"><tr><td align=\"$align\">\n";
866 print "</td></tr></table><br><br>";
871 my $filename = $_[0];
874 # write cgi vars to the file.
875 open(FILE
, ">${filename}") or die "Unable to write file $filename";
877 foreach $var (keys %$hash)
879 $val = $hash->{$var};
880 # Darren Critchley Jan 17, 2003 added the following because when submitting with a graphic, the x and y
881 # location of the mouse are submitted as well, this was being written to the settings file causing
882 # some serious grief! This skips the variable.x and variable.y
883 if (!($var =~ /(.x|.y)$/)) {
886 if (!($var =~ /^ACTION/)) {
887 print FILE
"${var}=${val}\n"; }
895 my $filename = $_[0];
899 open(FILE
, $filename) or die "Unable to read file $filename";
904 ($var, $val) = split /=/, $_, 2;
910 # Untaint variables read from hash
911 $var =~ /([A-Za-z0-9_-]*)/; $var = $1;
912 $val =~ /([\w\W]*)/; $val = $1;
913 $hash->{$var} = $val;
920 my ($hash, $params) = @_;
921 my $cgi = CGI
->new ();
922 $hash->{'__CGI__'} = $cgi;
923 return if ($ENV{'REQUEST_METHOD'} ne 'POST');
924 if (!$params->{'wantfile'}) {
925 $CGI::DISABLE_UPLOADS
= 1;
926 $CGI::POST_MAX
= 512 * 1024;
928 $CGI::POST_MAX
= 10 * 1024 * 1024;
931 $cgi->referer() =~ m/^https?\:\/\
/([^\/]+)/;
933 $cgi->url() =~ m/^https?\:\/\
/([^\/]+)/;
935 return if ($referer ne $servername);
937 ### Modified for getting multi-vars, split by |
938 %temp = $cgi->Vars();
939 foreach my $key (keys %temp) {
940 $hash->{$key} = $temp{$key};
941 $hash->{$key} =~ s/\0/|/g;
942 $hash->{$key} =~ s/^\s*(.*?)\s*$/$1/;
945 if (($params->{'wantfile'})&&($params->{'filevar'})) {
946 $hash->{$params->{'filevar'}} = $cgi->upload
947 ($params->{'filevar'});
954 my $logmessage = $_[0];
955 $logmessage =~ /([\w\W]*)/;
957 system('/usr/bin/logger', '-t', 'ipfire', $logmessage);
962 my ($dev, $ino, $mode, $nlink, $uid, $gid, $rdev, $size,
963 $atime, $mtime, $ctime, $blksize, $blocks) = stat $_[0];
966 my $totalsecs = $now - $mtime;
967 my $days = int($totalsecs / 86400);
968 my $totalhours = int($totalsecs / 3600);
969 my $hours = $totalhours % 24;
970 my $totalmins = int($totalsecs / 60);
971 my $mins = $totalmins % 60;
972 my $secs = $totalsecs % 60;
974 return "${days}d ${hours}h ${mins}m ${secs}s";
981 if (!($ip =~ /^(\d+)\.(\d+)\.(\d+)\.(\d+)$/)) {
985 @octets = ($1, $2, $3, $4);
990 if ($_ < 0 || $_ > 255) {
1001 # secord part an ip?
1002 if (&validip
($mask)) {
1004 # second part a number?
1007 if (!($mask =~ /^\d+$/)) {
1009 if ($mask >= 0 && $mask <= 32) {
1016 my $ipormask = $_[0];
1018 # see if it is a IP only.
1019 if (&validip
($ipormask)) {
1021 # split it into number and mask.
1022 if (!($ipormask =~ /^(.*?)\/(.*?
)$/)) {
1026 # first part not a ip?
1027 if (!(&validip
($ip))) {
1029 return &validmask
($mask);
1034 my $ipandmask = $_[0];
1036 # split it into number and mask.
1037 if (!($ipandmask =~ /^(.*?)\/(.*?
)$/)) {
1041 # first part not a ip?
1042 if (!(&validip
($ip))) {
1044 return &validmask
($mask);
1055 if ($_ >= 1 && $_ <= 65535) {
1062 my $checkmac = $_[0];
1063 my $ot = '[0-9a-f]{2}'; # 2 Hex digits (one octet)
1064 if ($checkmac !~ /^$ot:$ot:$ot:$ot:$ot:$ot$/i)
1073 # Checks a hostname against RFC1035
1074 my $hostname = $_[0];
1076 # Each part should be at least two characters in length
1077 # but no more than 63 characters
1078 if (length ($hostname) < 2 || length ($hostname) > 63) {
1080 # Only valid characters are a-z, A-Z, 0-9 and -
1081 if ($hostname !~ /^[a-zA-Z0-9-]*$/) {
1083 # First character can only be a letter or a digit
1084 if (substr ($hostname, 0, 1) !~ /^[a-zA-Z0-9]*$/) {
1086 # Last character can only be a letter or a digit
1087 if (substr ($hostname, -1, 1) !~ /^[a-zA-Z0-9]*$/) {
1094 # Checks a domain name against RFC1035
1095 my $domainname = $_[0];
1096 my @parts = split (/\./, $domainname); # Split hostname at the '.'
1098 foreach $part (@parts) {
1099 # Each part should be at least two characters in length
1100 # but no more than 63 characters
1101 if (length ($part) < 2 || length ($part) > 63) {
1103 # Only valid characters are a-z, A-Z, 0-9 and -
1104 if ($part !~ /^[a-zA-Z0-9-]*$/) {
1106 # First character can only be a letter or a digit
1107 if (substr ($part, 0, 1) !~ /^[a-zA-Z0-9]*$/) {
1109 # Last character can only be a letter or a digit
1110 if (substr ($part, -1, 1) !~ /^[a-zA-Z0-9]*$/) {
1118 # Checks a fully qualified domain name against RFC1035
1120 my @parts = split (/\./, $fqdn); # Split hostname at the '.'
1121 if (scalar(@parts) < 2) { # At least two parts should
1122 return 0;} # exist in a FQDN
1123 # (i.e. hostname.domain)
1124 foreach $part (@parts) {
1125 # Each part should be at least two characters in length
1126 # but no more than 63 characters
1127 if (length ($part) < 2 || length ($part) > 63) {
1129 # Only valid characters are a-z, A-Z, 0-9 and -
1130 if ($part !~ /^[a-zA-Z0-9-]*$/) {
1132 # First character can only be a letter or a digit
1133 if (substr ($part, 0, 1) !~ /^[a-zA-Z0-9]*$/) {
1135 # Last character can only be a letter or a digit
1136 if (substr ($part, -1, 1) !~ /^[a-zA-Z0-9]*$/) {
1142 sub validportrange
# used to check a port range
1144 my $port = $_[0]; # port values
1145 $port =~ tr/-/:/; # replace all - with colons just in case someone used -
1146 my $srcdst = $_[1]; # is it a source or destination port
1148 if (!($port =~ /^(\d+)\:(\d+)$/)) {
1150 if (!(&validport
($port))) {
1151 if ($srcdst eq 'src'){
1152 return $tr{'source port numbers'};
1154 return $tr{'destination port numbers'};
1162 if ($srcdst eq 'src'){
1163 return $tr{'bad source range'};
1165 return $tr{'bad destination range'};
1170 if (!(&validport
($_))) {
1171 if ($srcdst eq 'src'){
1172 return $tr{'source port numbers'};
1174 return $tr{'destination port numbers'};
1182 # Test if IP is within a subnet
1183 # Call: IpInSubnet (Addr, Subnet, Subnet Mask)
1184 # Subnet can be an IP of the subnet: 10.0.0.0 or 10.0.0.1
1185 # Everything in dottted notation
1186 # Return: TRUE/FALSE
1189 $ip = unpack('N', inet_aton
(shift));
1190 $start = unpack('N', inet_aton
(shift));
1191 $mask = unpack('N', inet_aton
(shift));
1192 $start &= $mask; # base of subnet...
1193 $end = $start + ~$mask;
1194 return (($ip >= $start) && ($ip <= $end));
1199 return 0 if ( $mail !~ /^[0-9a-zA-Z\.\-\_]+\@[0-9a-zA-Z\.\-]+$/ );
1200 return 0 if ( $mail =~ /^[^0-9a-zA-Z]|[^0-9a-zA-Z]$/);
1201 return 0 if ( $mail !~ /([0-9a-zA-Z]{1})\@./ );
1202 return 0 if ( $mail !~ /.\@([0-9a-zA-Z]{1})/ );
1203 return 0 if ( $mail =~ /.\.\-.|.\-\..|.\.\..|.\-\-./g );
1204 return 0 if ( $mail =~ /.\.\_.|.\-\_.|.\_\..|.\_\-.|.\_\_./g );
1205 return 0 if ( $mail !~ /\.([a-zA-Z]{2,3})$/ );
1210 my ($filename, $hash) = @_;
1212 open(FILE
, $filename) or die "Unable to read file $filename";
1215 my ($key, $rest, @temp);
1217 ($key, $rest) = split (/,/, $_, 2);
1218 if ($key =~ /^[0-9]+$/ && $rest) {
1219 @temp = split (/,/, $rest);
1220 $hash->{$key} = \
@temp;
1227 sub writehasharray
{
1228 my ($filename, $hash) = @_;
1231 open(FILE
, ">$filename") or die "Unable to write to file $filename";
1233 foreach $key (keys %$hash) {
1234 if ( $hash->{$key} ) {
1236 foreach $i (0 .. $#{$hash->{$key}}) {
1237 print FILE
",$hash->{$key}[$i]";
1246 sub findhasharraykey
{
1247 foreach my $i (1 .. 1000000) {
1248 if ( ! exists $_[0]{$i}) {
1256 my $outstring =$_[0];
1257 $outstring =~ tr/,/ / if not defined $_[1] or $_[1] ne 'y';
1258 $outstring =~ s/&/&/g;
1259 $outstring =~ s/\'/'/g;
1260 $outstring =~ s/\"/"/g;
1261 $outstring =~ s/</</g;
1262 $outstring =~ s/>/>/g;
1266 sub connectionstatus
1268 my %pppsettings = ();
1269 my %netsettings = ();
1272 $pppsettings{'PROFILENAME'} = 'None';
1273 &General
::readhash
("${General::swroot}/ppp/settings", \
%pppsettings);
1274 &General
::readhash
("${General::swroot}/ethernet/settings", \
%netsettings);
1277 if ( ! ( $netsettings{'CONFIG_TYPE'} =~ /^(2|3|6|7)$/ && $netsettings{'RED_TYPE'} =~ /^(DHCP|STATIC)$/ ) ) {
1278 $profileused="- $pppsettings{'PROFILENAME'}";
1281 if ( ( $pppsettings{'METHOD'} eq 'DHCP' && $netsettings{'RED_TYPE'} ne 'PPTP')
1282 || $netsettings{'RED_TYPE'} eq 'DHCP' ) {
1283 if (open(IFACE
, "${General::swroot}/red/iface")) {
1287 $iface =~ /([a-zA-Z0-9]*)/; $iface = $1;
1291 my ($timestr, $connstate);
1292 if ($netsettings{'CONFIG_TYPE'} =~ /^(0|1|4|5)$/ && $pppsettings{'TYPE'} =~ /^isdn/) {
1293 # Count ISDN channels
1294 my ($idmap, $chmap, $drmap, $usage, $flags, $phone);
1298 open (FILE
, "/dev/isdninfo");
1300 $idmap = <FILE
>; chop $idmap;
1301 $chmap = <FILE
>; chop $chmap;
1302 $drmap = <FILE
>; chop $drmap;
1303 $usage = <FILE
>; chop $usage;
1304 $flags = <FILE
>; chop $flags;
1305 $phone = <FILE
>; chop $phone;
1307 $phone =~ s/^phone(\s*):(\s*)//;
1309 @phonenumbers = split / /, $phone;
1311 foreach (@phonenumbers) {
1318 ## Connection status
1322 } elsif ($count == 1) {
1328 if (-e
"${General::swroot}/red/active") {
1329 $timestr = &General
::age
("${General::swroot}/red/active");
1330 $connstate = "<span class='ipcop_StatusBig'>$Lang::tr{'connected'} - $number channel (<span class='ipcop_StatusBigRed'>$timestr</span>) $profileused</span>";
1333 if (-e
"${General::swroot}/red/dial-on-demand") {
1334 $connstate = "<span class='ipcop_StatusBig'>$Lang::tr{'dod waiting'} $profileused</span>";
1336 $connstate = "<span class='ipcop_StatusBig'>$Lang::tr{'idle'} $profileused</span>";
1339 $connstate = "<span class='ipcop_StatusBig'>$Lang::tr{'connecting'} $profileused</span>";
1342 } elsif ($netsettings{'RED_TYPE'} eq "STATIC" || $pppsettings {'METHOD'} eq 'STATIC') {
1343 if (-e
"${General::swroot}/red/active") {
1344 $timestr = &General
::age
("${General::swroot}/red/active");
1345 $connstate = "<span class='ipcop_StatusBig'>$Lang::tr{'connected'} (<span class='ipcop_StatusBigRed'>$timestr</span>) $profileused</span>";
1347 $connstate = "<span class='ipcop_StatusBig'>$Lang::tr{'idle'} $profileused</span>";
1349 } elsif ( ( (-e
"${General::swroot}/dhcpc/dhcpcd-$iface.pid") && $netsettings{'RED_TYPE'} ne 'PPTP' ) ||
1350 !system("/bin/ps -ef | /bin/grep -q '[p]ppd'") || !system("/bin/ps -ef | /bin/grep -q '[c]onnectioncheck'")) {
1351 if (-e
"${General::swroot}/red/active") {
1352 $timestr = &General
::age
("${General::swroot}/red/active");
1353 if ($pppsettings{'TYPE'} =~ /^(modem|bewanadsl|conexantpciadsl|eagleusbadsl)$/) {
1355 if ($pppsettings{'TYPE'} eq 'modem') {
1356 open(CONNECTLOG
, "/var/log/connect.log");
1357 while (<CONNECTLOG
>) {
1359 $speed = (split / /)[6];
1363 } elsif ($pppsettings{'TYPE'} eq 'bewanadsl') {
1364 $speed = `/usr/bin/unicorn_status | /bin/grep Rate | /usr/bin/cut -f2 -d ':'`;
1365 } elsif ($pppsettings{'TYPE'} eq 'conexantpciadsl') {
1366 $speed = `/bin/cat /proc/net/atm/CnxAdsl:* | /bin/grep 'Line Rates' | /bin/sed -e 's+Line Rates: Receive+Rx+' -e 's+Transmit+Tx+'`;
1367 } elsif ($pppsettings{'TYPE'} eq 'eagleusbadsl') {
1368 $speed = `/usr/sbin/eaglestat | /bin/grep Rate`;
1370 $connstate = "<span class='ipcop_StatusBig'>$Lang::tr{'connected'} (<span class='ipcop_StatusBigRed'>$timestr</span>) $profileused (\@$speed)</span>";
1372 $connstate = "<span class='ipcop_StatusBig'>$Lang::tr{'connected'} (<span class='ipcop_StatusBigRed'>$timestr</span>) $profileused</span>";
1375 if (-e
"${General::swroot}/red/dial-on-demand") {
1376 $connstate = "<span class='ipcop_StatusBig'>$Lang::tr{'dod waiting'} $profileused</span>";
1378 $connstate = "<span class='ipcop_StatusBig'>$Lang::tr{'connecting'} $profileused</span>";
1382 $connstate = "<span class='ipcop_StatusBig'>$Lang::tr{'idle'} $profileused</span>";
1388 # Darren Critchley - darrenc@telus.net - (c) 2003
1389 # &srtarray(SortOrder, AlphaNumeric, SortDirection, ArrayToBeSorted)
1390 # This subroutine will take the following parameters:
1391 # ColumnNumber = the column which you want to sort on, starts at 1
1392 # AlphaNumberic = a or n (lowercase) defines whether the sort should be alpha or numberic
1393 # SortDirection = asc or dsc (lowercase) Ascending or Descending sort
1394 # ArrayToBeSorted = the array that wants sorting
1396 # Returns an array that is sorted to your specs
1398 # If SortOrder is greater than the elements in array, then it defaults to the first element
1401 my ($colno, $alpnum, $srtdir, @tobesorted) = @_;
1406 my $ttlitems = scalar @tobesorted; # want to know the number of rows in the passed array
1407 if ($ttlitems < 1){ # if no items, don't waste our time lets leave
1408 return (@tobesorted);
1410 my @tmp = split(/\,/,$tobesorted[0]);
1411 $ttlitems = scalar @tmp; # this should be the number of elements in each row of the passed in array
1413 # Darren Critchley - validate parameters
1414 if ($colno > $ttlitems){$colno = '1';}
1415 $colno--; # remove one from colno to deal with arrays starting at 0
1416 if($colno < 0){$colno = '0';}
1417 if ($alpnum ne '') { $alpnum = lc($alpnum); } else { $alpnum = 'a'; }
1418 if ($srtdir ne '') { $srtdir = lc($srtdir); } else { $srtdir = 'src'; }
1420 foreach $line (@tobesorted)
1424 my @temp = split(/\,/,$line);
1425 # Darren Critchley - juggle the fields so that the one we want to sort on is first
1426 my $tmpholder = $temp[0];
1427 $temp[0] = $temp[$colno];
1428 $temp[$colno] = $tmpholder;
1430 for ($ctr=0; $ctr < $ttlitems ; $ctr++) {
1431 $newline=$newline . $temp[$ctr] . ",";
1434 push(@tmparray,$newline);
1437 if ($alpnum eq 'n') {
1438 @tmparray = sort {$a <=> $b} @tmparray;
1440 @tmparray = (sort @tmparray);
1442 foreach $line (@tmparray)
1446 my @temp = split(/\,/,$line);
1447 my $tmpholder = $temp[0];
1448 $temp[0] = $temp[$colno];
1449 $temp[$colno] = $tmpholder;
1451 for ($ctr=0; $ctr < $ttlitems ; $ctr++){
1452 $newline=$newline . $temp[$ctr] . ",";
1455 push(@srtedarray,$newline);
1459 if ($srtdir eq 'dsc') {
1460 @tmparray = reverse(@srtedarray);
1463 return (@srtedarray);
1467 sub speedtouchversion
1469 if (-f
"/proc/bus/usb/devices")
1471 $speedtouch=`/bin/cat /proc/bus/usb/devices | /bin/grep 'Vendor=06b9 ProdID=4061' | /usr/bin/cut -d ' ' -f6`;
1472 if ($speedtouch eq '') {
1473 $speedtouch= $tr{'connect the modem'};
1476 $speedtouch='USB '.$tr{'not running'};
1481 sub CheckSortOrder
{
1482 #Sorting of allocated leases
1483 if ($ENV{'QUERY_STRING'} =~ /^IPADDR|^ETHER|^HOSTNAME|^ENDTIME/ ) {
1484 my $newsort=$ENV{'QUERY_STRING'};
1485 &readhash
("${swroot}/dhcp/settings", \
%dhcpsettings);
1486 $act=$dhcpsettings{'SORT_LEASELIST'};
1488 if ($act =~ $newsort) {
1489 if ($act !~ 'Rev') {$Rev='Rev'};
1493 $dhcpsettings{'SORT_LEASELIST'}=$newsort;
1494 &writehash
("${swroot}/dhcp/settings", \
%dhcpsettings);
1495 $dhcpsettings{'ACTION'} = 'SORT'; # avoid the next test "First lauch"
1500 sub PrintActualLeases
1502 &openbox
('100%', 'left', $tr{'current dynamic leases'});
1504 <table width='100%'>
1506 <td width='25%' align='center'><a href='$ENV{'SCRIPT_NAME'}?IPADDR'><b>$tr{'ip address'}</b></a></td>
1507 <td width='25%' align='center'><a href='$ENV{'SCRIPT_NAME'}?ETHER'><b>$tr{'mac address'}</b></a></td>
1508 <td width='20%' align='center'><a href='$ENV{'SCRIPT_NAME'}?HOSTNAME'><b>$tr{'hostname'}</b></a></td>
1509 <td width='30%' align='center'><a href='$ENV{'SCRIPT_NAME'}?ENDTIME'><b>$tr{'lease expires'} (local time d/m/y)</b></a></td>
1514 open(LEASES
,"/var/state/dhcp/dhcpd.leases") or die "Can't open dhcpd.leases";
1515 while ($line = <LEASES
>) {
1516 next if( $line =~ /^\s*#/ );
1518 @temp = split (' ', $line);
1520 if ($line =~ /^\s*lease/) {
1522 #All field are not necessarily read. Clear everything
1528 if ($line =~ /^\s*ends/) {
1529 $line =~ /(\d+)\/(\d
+)\
/(\d+) (\d+):(\d+):(\d+)/;
1530 $endtime = timegm
($6, $5, $4, $3, $2 - 1, $1 - 1900);
1533 if ($line =~ /^\s*hardware ethernet/) {
1538 if ($line =~ /^\s*client-hostname/) {
1539 $hostname = "$temp[1] $temp[2] $temp[3]";
1540 $hostname =~ s/;//g;
1541 $hostname =~ s/\"//g;
1545 @record = ('IPADDR',$ip,'ENDTIME',$endtime,'ETHER',$ether,'HOSTNAME',$hostname);
1546 $record = {}; # create a reference to empty hash
1547 %{$record} = @record; # populate that hash with @record
1548 $entries{$record->{'IPADDR'}} = $record; # add this to a hash of hashes
1554 foreach my $key (sort leasesort
keys %entries) {
1556 my $hostname = &cleanhtml
($entries{$key}->{HOSTNAME
},"y");
1559 print "<tr bgcolor='$table1colour'>";
1562 print "<tr bgcolor='$table2colour'>";
1566 <td align='center'>$entries{$key}->{IPADDR}</td>
1567 <td align='center'>$entries{$key}->{ETHER}</td>
1568 <td align='center'> $hostname </td>
1573 ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $dst) = localtime ($entries{$key}->{ENDTIME
});
1574 $enddate = sprintf ("%02d/%02d/%d %02d:%02d:%02d",$mday,$mon+1,$year+1900,$hour,$min,$sec);
1576 if ($entries{$key}->{ENDTIME
} < time() ){
1577 print "<strike>$enddate</strike>";
1590 # This sub is used during display of actives leases
1592 if (rindex ($dhcpsettings{'SORT_LEASELIST'},'Rev') != -1)
1594 $qs=substr ($dhcpsettings{'SORT_LEASELIST'},0,length($dhcpsettings{'SORT_LEASELIST'})-3);
1595 if ($qs eq 'IPADDR') {
1596 @a = split(/\./,$entries{$a}->{$qs});
1597 @b = split(/\./,$entries{$b}->{$qs});
1603 $entries{$b}->{$qs} cmp $entries{$a}->{$qs};
1608 $qs=$dhcpsettings{'SORT_LEASELIST'};
1609 if ($qs eq 'IPADDR') {
1610 @a = split(/\./,$entries{$a}->{$qs});
1611 @b = split(/\./,$entries{$b}->{$qs});
1617 $entries{$a}->{$qs} cmp $entries{$b}->{$qs};
1624 opendir(DIR
, "${swroot}/uplinks/") || return \
@uplinks;
1625 foreach my $dir (readdir(DIR
)) {
1626 next if ($dir =~ /^\./);
1627 next if (-f
"${swroot}/uplinks/$dir");
1628 push(@uplinks, $dir);
1635 my $filename = shift;
1637 open (F
, $filename) || return "";
1644 sub get_red_ifaces_by_type
($) {
1646 my @gottypeiface = ();
1647 my @gottypeuplink = ();
1650 my $ref=get_uplinks
();
1653 foreach my $link (@uplinks) {
1655 &readhash
("${swroot}/uplinks/$link/settings", \
%set);
1657 push(@gottype, $link);
1659 my $iface = $set{'RED_DEV'};
1661 $iface = get_iface
("${swroot}/uplinks/$link/interface");
1665 if ($set{'RED_TYPE'} eq $type) {
1666 push(@gottypeiface, $iface);
1667 push(@gottypeuplink, $link);
1670 return (\
@gottypeiface, \
@gottypeuplink, \
@gottype);
1673 sub get_red_ifaces
() {
1674 return `cat ${swroot}/uplinks/*/interface 2>/dev/null`;
1677 sub get_zone_devices
($) {
1680 open (FILE
, "${swroot}/ethernet/$bridge") || return "";
1681 foreach my $line (<FILE
>) {
1684 push(@ifaces, $line);