]>
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}";
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.dialup'} = {
134 'caption' => $tr{'alt dialup'},
135 'uri' => '/cgi-bin/pppsetup.cgi',
136 'title' => "$tr{'alt dialup'}",
139 $subsystem->{'30.passwords'} = {
140 'caption' => $tr{'sspasswords'},
141 'uri' => '/cgi-bin/changepw.cgi',
142 'title' => "$tr{'sspasswords'}",
145 $subsystem->{'40.ssh'} = {
146 'caption' => $tr{'ssh access'},
147 'uri' => '/cgi-bin/remote.cgi',
148 'title' => "$tr{'ssh access'}",
151 $subsystem->{'50.gui'} = {
152 'caption' => $tr{'gui settings'},
153 'uri' => '/cgi-bin/gui.cgi',
154 'title' => "$tr{'gui settings'}",
157 $subsystem->{'60.shutdown'} = {
158 'caption' => $tr{'shutdown'},
159 'uri' => '/cgi-bin/shutdown.cgi',
160 'title' => "$tr{'shutdown'} / $tr{'reboot'}",
163 $subsystem->{'99.credits'} = {
164 'caption' => $tr{'credits'},
165 'uri' => '/cgi-bin/credits.cgi',
166 'title' => "$tr{'credits'}",
170 my %substatushash = ();
171 my $substatus = \
%substatushash;
172 $substatus->{'10.systemstatus'} = {
173 'caption' => $tr{'sssystem status'},
174 'uri' => '/cgi-bin/status.cgi',
175 'title' => "$tr{'sssystem status'}",
178 $substatus->{'20.networkstatus'} = {
179 'caption' => $tr{'ssnetwork status'},
180 'uri' => '/cgi-bin/netstatus.cgi',
181 'title' => "$tr{'ssnetwork status'}",
184 $substatus->{'30.systemgraphs'} = {
185 'caption' => $tr{'system graphs'},
186 'uri' => '/cgi-bin/graphs.cgi',
188 'title' => "$tr{'system graphs'}",
191 $substatus->{'40.trafficgraphs'} = {
192 'caption' => $tr{'sstraffic graphs'},
193 'uri' => '/cgi-bin/graphs.cgi',
194 'vars' => 'graph=network',
195 'title' => "$tr{'sstraffic graphs'}",
198 $substatus->{'50.proxygraphs'} = {
199 'caption' => $tr{'ssproxy graphs'},
200 'uri' => '/cgi-bin/proxygraphs.cgi',
201 'title' => "$tr{'ssproxy graphs'}",
204 $substatus->{'60.fwhits'} = {
205 'caption' => 'Firewall-Diagramme',
206 'uri' => '/cgi-bin/fwhits.cgi',
207 'title' => "Firewall-Diagramme",
210 $substatus->{'70.hardwaregraphs'} = {
211 'caption' => "$tr{'hardware graphs'}",
212 'uri' => '/cgi-bin/hardwaregraphs.cgi',
213 'title' => "$tr{'hardware graphs'}",
216 $substatus->{'80.connections'} = {
217 'caption' => $tr{'connections'},
218 'uri' => '/cgi-bin/connections.cgi',
219 'title' => "$tr{'connections'}",
222 $substatus->{'90.nettraf'} = {
223 'caption' => $tr{'sstraffic'},
224 'uri' => '/cgi-bin/traffic.cgi',
225 'title' => "$tr{'sstraffic'}",
228 $substatus->{'99.iptable'} = {
229 'caption' => $tr{'iptable rules'},
230 'uri' => '/cgi-bin/iptables.cgi',
231 'title' => "$tr{'iptable rules'}",
235 my %subnetworkhash = ();
236 my $subnetwork = \
%subnetworkhash;
238 $subnetwork->{'10.netconf'} = {'caption' => "$tr{'net config'}",
239 'uri' => '/cgi-bin/netconfig.cgi',
240 'title' => "$tr{'net config'}",
243 $subnetwork->{'20.proxy'} = {'caption' => 'Webproxy',
244 'uri' => '/cgi-bin/proxy.cgi',
245 'title' => "Webproxy",
248 $subnetwork->{'30.urlfilter'} = {'caption' => 'URL-Filter',
249 'uri' => '/cgi-bin/urlfilter.cgi',
250 'title' => "URL-Filter",
253 $subnetwork->{'40.dhcp'} = {'caption' => $tr{'dhcp server'},
254 'uri' => '/cgi-bin/dhcp.cgi',
255 'title' => "$tr{'dhcp server'}",
258 $subnetwork->{'50.scheduler'} = {
259 'caption' => $tr{'scheduler'},
260 'uri' => '/cgi-bin/connscheduler.cgi',
261 'title' => "$tr{'scheduler'}",
264 $subnetwork->{'60.hosts'} = {
265 'caption' => $tr{'edit hosts'},
266 'uri' => '/cgi-bin/hosts.cgi',
267 'title' => "$tr{'edit hosts'}",
270 $subnetwork->{'70.upload'} = {
271 'caption' => $tr{'upload'},
272 'uri' => '/cgi-bin/upload.cgi',
273 'title' => "$tr{'upload'}",
276 $subnetwork->{'80.aliases'} = {
277 'caption' => $tr{'aliases'},
278 'uri' => '/cgi-bin/aliases.cgi',
279 'title' => "$tr{'aliases'}",
282 $subnetwork->{'90.wakeonlan'} = {
283 'caption' => $tr{'WakeOnLan'},
284 'uri' => '/cgi-bin/wakeonlan.cgi',
285 'title' => "$tr{'WakeOnLan'}",
289 my %subserviceshash = ();
290 my $subservices = \
%subserviceshash;
293 $subservices->{'10.openvpn'} = {
294 'caption' => 'OpenVPN',
295 'uri' => '/cgi-bin/ovpnmain.cgi',
296 'title' => "$tr{'virtual private networking'}",
299 $subservices->{'20.ipsec'} = {
300 'caption' => 'IPSec',
301 'uri' => '/cgi-bin/vpnmain.cgi',
302 'title' => "$tr{'virtual private networking'}",
305 $subservices->{'30.dyndns'} = {'caption' => $tr{'dynamic dns'},
306 'uri' => '/cgi-bin/ddns.cgi',
307 'title' => "$tr{'dynamic dns'}",
310 $subservices->{'40.time'} = {'caption' => $tr{'time server'},
311 'uri' => '/cgi-bin/time.cgi',
312 'title' => "$tr{'time server'}",
315 $subservices->{'50.qos'} = {'caption' => 'Quality of Service',
316 'uri' => '/cgi-bin/qos.cgi',
317 'title' => "Quality of Service",
320 $subservices->{'60.ids'} = {'caption' => $tr{'intrusion detection'},
322 'uri' => '/cgi-bin/ids.cgi',
323 'title' => "$tr{'intrusion detection system'}",
328 my %subfirewallhash = ();
329 my $subfirewall = \
%subfirewallhash;
332 $subfirewall->{'10.dnat'} = {
333 'caption' => $tr{'ssport forwarding'},
334 'uri' => '/cgi-bin/portfw.cgi',
335 'title' => "$tr{'ssport forwarding'}",
338 $subfirewall->{'20.xtaccess'} = {
339 'caption' => $tr{'external access'},
340 'uri' => '/cgi-bin/xtaccess.cgi',
341 'title' => "$tr{'external access'}",
344 $subfirewall->{'30.wireless'} = {
345 'caption' => $tr{'blue access'},
346 'uri' => '/cgi-bin/wireless.cgi',
347 'title' => "$tr{'blue access'}",
350 $subfirewall->{'40.dmz'} = {
351 'caption' => $tr{'ssdmz pinholes'},
352 'uri' => '/cgi-bin/dmzholes.cgi',
353 'title' => "$tr{'dmz pinhole configuration'}",
356 $subfirewall->{'50.outgoing'} = {
357 'caption' => $tr{'outgoing firewall'},
358 'uri' => '/cgi-bin/outgoingfw.cgi',
359 'title' => "$tr{'outgoing firewall'}",
362 $subfirewall->{'60.fwopts'} = {
363 'caption' => $tr{'options fw'},
364 'uri' => '/cgi-bin/optionsfw.cgi',
365 'title' => "$tr{'options fw'}",
369 my %sublogshash = ();
370 my $sublogs = \
%sublogshash;
372 $sublogs->{'10.summary'} = {'caption' => $tr{'log summary'},
373 'uri' => '/cgi-bin/logs.cgi/summary.dat',
374 'title' => "$tr{'log summary'}",
377 $sublogs->{'20.settings'} = {'caption' => $tr{'log settings'},
378 'uri' => '/cgi-bin/logs.cgi/config.dat',
379 'title' => "$tr{'log settings'}",
382 $sublogs->{'30.proxy'} = {'caption' => $tr{'proxy logs'},
383 'uri' => '/cgi-bin/logs.cgi/proxylog.dat',
384 'title' => "$tr{'proxy logs'}",
387 $sublogs->{'40.firewall'} = {'caption' => $tr{'firewall logs'},
388 'uri' => '/cgi-bin/logs.cgi/firewalllog.dat',
389 'title' => "$tr{'firewall logs'}",
392 $sublogs->{'50.ids'} = {'caption' => $tr{'ids logs'},
393 'uri' => '/cgi-bin/logs.cgi/ids.dat',
394 'title' => "$tr{'ids logs'}",
397 $sublogs->{'60.urlfilter'} = {
398 'caption' => $tr{'urlfilter log'},
399 'uri' => '/cgi-bin/logs.cgi/urlfilter.dat',
400 'title' => "$tr{'urlfilter log'}",
403 $sublogs->{'70.openvpn'} = {'caption' => $tr{'openvpn log'},
404 'uri' => '/cgi-bin/logs.cgi/openvpn.dat',
405 'title' => "$tr{'openvpn log'}",
408 $sublogs->{'80.system'} = {'caption' => $tr{'system logs'},
409 'uri' => '/cgi-bin/logs.cgi/log.dat',
410 'title' => "$tr{'system logs'}",
413 $sublogs->{'90.userlog'} = {'caption' => $tr{'user proxy logs'},
414 'uri' => '/cgi-bin/logs.cgi/userlog.dat',
415 'title' => "$tr{'user log'}",
419 my %subipfirehash = ();
420 my $subipfire = \
%subipfirehash;
421 $subipfire->{'10.pakfire'} = {'caption' => 'Pakfire',
422 'uri' => '/cgi-bin/pakfire.cgi',
423 'title' => "Pakfire",
426 $subipfire->{'20.asterisk'} = {'caption' => 'Asterisk',
427 'uri' => '/cgi-bin/asterisk.cgi',
428 'title' => "Asterisk",
431 $subipfire->{'30.samba'} = {'caption' => 'Samba',
432 'uri' => '/cgi-bin/samba.cgi',
436 $subipfire->{'99.help'} = {'caption' => $tr{'help'},
437 'uri' => '/cgi-bin/help.cgi',
438 'title' => "$tr{'help'}",
444 $menu->{'01.system'} = {'caption' => $tr{'alt system'},
446 'subMenu' => $subsystem
448 $menu->{'02.status'} = {'caption' => $tr{'status'},
450 'subMenu' => $substatus
452 $menu->{'03.network'} = {'caption' => $tr{'network'},
454 'subMenu' => $subnetwork
456 $menu->{'04.services'} = {'caption' => $tr{'alt services'},
458 'subMenu' => $subservices
460 $menu->{'05.firewall'} = {'caption' => $tr{'firewall'},
462 'subMenu' => $subfirewall
464 $menu->{'06.proxy'} = {'caption' => $tr{'alt proxy'},
466 'subMenu' => $subproxy
468 $menu->{'07.ipfire'} = {'caption' => 'IPFire',
470 'subMenu' => $subipfire
472 $menu->{'08.logs'} = {'caption' => $tr{'alt logs'},
474 'subMenu' => $sublogs
477 if (! blue_used
() && ! orange_used
()) {
478 $menu->{'05.firewall'}{'subMenu'}->{'40.dmz'}{'enabled'} = 0;
481 $menu->{'05.firewall'}{'subMenu'}->{'30.wireless'}{'enabled'} = 0;
483 if ( $ethsettings{'CONFIG_TYPE'} =~ /^(2|3|6|7)$/ && $ethsettings{'RED_TYPE'} eq 'STATIC' ) {
484 $menu->{'03.network'}{'subMenu'}->{'70.aliases'}{'enabled'} = 1;
490 print "Pragma: no-cache\n";
491 print "Cache-control: no-cache\n";
492 print "Connection: close\n";
493 print "Content-type: text/html\n\n";
496 sub is_menu_visible
($) {
499 return (-e
$ENV{'DOCUMENT_ROOT'}."/../$link");
505 if (! $root->{'enabled'}) {
508 if ($root->{'uri'} !~ /^$/) {
510 if ($root->{'vars'} !~ /^$/) {
511 $vars = '?'. $root->{'vars'};
513 if (! is_menu_visible
($root->{'uri'})) {
516 return $root->{'uri'}.$vars;
518 my $submenus = $root->{'subMenu'};
522 foreach my $item (sort keys %$submenus) {
523 my $link = getlink
($submenus->{$item});
535 my $uri = $conf->{'uri'};
536 my $vars = $conf->{'vars'};
537 my $novars = $conf->{'novars'};
542 if ($uri ne $URI[0]) {
546 if ($URI[1] !~ /^$/) {
553 return ($URI[1] eq $vars);
563 foreach my $item (sort keys %$root) {
564 my $val = $root->{$item};
565 if (compare_url
($val)) {
566 $val->{'selected'} = 1;
567 if ($val->{'title'} !~ /^$/) {
568 return $val->{'title'};
570 return 'EMPTY TITLE';
573 my $title = gettitle
($val->{'subMenu'});
575 $val->{'selected'} = 1;
589 foreach my $k1 ( sort keys %$menu ) {
590 if (! $menu->{$k1}{'enabled'}) {
594 my $link = getlink
($menu->{$k1});
598 if (! is_menu_visible
($link)) {
601 if ($menu->{$k1}->{'selected'}) {
602 print '<li class="selected">';
608 <div class="rcorner">
609 <a href="$link">$menu->{$k1}{'caption'}</a>
629 foreach my $item (%$root) {
630 if ($root->{$item}{'selected'}) {
631 return $root->{$item};
636 sub showsubsection
($$) {
646 my $selected = getselected
($root);
650 my $submenus = $selected->{'subMenu'};
660 foreach my $item (sort keys %$submenus) {
661 my $hash = $submenus->{$item};
662 if (! $hash->{'enabled'}) {
666 my $link = getlink
($hash);
670 if (! is_menu_visible
($link)) {
673 if ($hash->{'selected'}) {
674 print '<li class="selected">';
680 <a href="$link">$hash->{'caption'}</a>
695 sub showsubsubsection
($) {
700 my $selected = getselected
($root);
704 if (! $selected->{'subMenu'}) {
708 showsubsection
($selected->{'subMenu'}, 'menu-subtop');
714 if ($URI[0] =~ /.*\/([^\
/]+)\.cgi/) {
719 $helpfile .= '.help.html';
721 my $helpuri = '/doc/'.$language.'/'.$helpfile;
722 if (! -e
$ENV{'DOCUMENT_ROOT'}.$helpuri) {
732 my $extrahead = shift;
734 @URI=split ('\?', $ENV{'REQUEST_URI'} );
735 &readhash
("${swroot}/main/settings", \
%settings);
738 my $h2 = gettitle
($menu);
739 my $helpuri = get_helpuri
();
741 $title = "IPFire - $title";
742 if ($settings{'WINDOWWITHHOSTNAME'} eq 'on') {
743 $title = "$settings{'HOSTNAME'}.$settings{'DOMAINNAME'} - $title";
748 PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
749 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
753 <title>$title</title>
756 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
759 if ($settings{'FX'} ne 'off') {
761 <meta http-equiv="Page-Enter" content="blendTrans(Duration=0.5,Transition=12)">
762 <meta http-equiv="Page-Exit" content="blendTrans(Duration=0.5,Transition=12)">
767 <link rel="shortcut icon" href="/favicon.ico" />
768 <style type="text/css">\@import url(/include/style.css);</style>
769 <style type="text/css">\@import url(/include/menu.css);</style>
770 <style type="text/css">\@import url(/include/content.css);</style>
771 <script language="javascript" type="text/javascript">
773 function swapVisibility(id) {
774 el = document.getElementById(id);
775 if(el.style.display != 'block') {
776 el.style.display = 'block'
779 el.style.display = 'none'
786 <!-- IPFIRE HEADER -->
791 <img id="logo-product" src="/images/logo_ipfire.gif">
792 <div id="header-icons">
793 <a href="http://users.ipfire.eu/" target="_blank"><img border="0" src="/images/help.gif"></a>
810 &showsubsection
($menu);
813 <p><center><img src="/images/iptux.png" width='160px' height='160px'></center></p>
815 <td width="100%" valign="top">
816 <div id="page-content">
821 &showsubsubsection
($menu);
824 require 'ipfire-network.pl';
825 $supported = check_support
();
826 warn_unsupported
($supported);
830 sub openpagewithoutmenu
{
833 my $extrahead = shift;
835 @URI=split ('\?', $ENV{'REQUEST_URI'} );
836 &readhash
("${swroot}/main/settings", \
%settings);
839 my $h2 = gettitle
($menu);
840 my $helpuri = get_helpuri
();
842 $title = "IPFire - $title";
843 if ($settings{'WINDOWWITHHOSTNAME'} eq 'on') {
844 $title = "$settings{'HOSTNAME'}.$settings{'DOMAINNAME'} - $title";
849 PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
850 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
854 <title>$title</title>
857 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
860 if ($settings{'FX'} eq 'on') {
862 <meta http-equiv="Page-Enter" content="blendTrans(Duration=0.5,Transition=12)">
863 <meta http-equiv="Page-Exit" content="blendTrans(Duration=0.5,Transition=12)">
868 <link rel="shortcut icon" href="/favicon.ico" />
869 <style type="text/css">\@import url(/include/style.css);</style>
870 <style type="text/css">\@import url(/include/menu.css);</style>
871 <style type="text/css">\@import url(/include/content.css);</style>
872 <script language="javascript" type="text/javascript">
874 function swapVisibility(id) {
875 el = document.getElementById(id);
876 if(el.style.display != 'block') {
877 el.style.display = 'block'
880 el.style.display = 'none'
887 <!-- IPFIRE HEADER -->
892 <img id="logo-product" src="/images/logo_ipfire.gif">
893 <div id="header-icons">
894 <a href="http://users.ipfire.eu/" target="_blank"><img border="0" src="/images/help.gif"></a>
905 <p><center><img src="/images/iptux.png" width='160px' height='160px'></center></p>
907 <td width="100%" valign="top">
908 <div id="page-content">
915 my $status = &connectionstatus
();
916 $uptime = `/usr/bin/uptime`;
921 <div style="font-size: 9px"><b>Status:</b> $status <b>Uptime:</b>$uptime <b>Version:</b> $FIREBUILD</div>
937 $bgcolor = "style='background-color: $colourerr;'";
945 # print "</td></tr></table></td></tr></table>\n"
954 if ($caption) { print "<h3>$caption</h3>\n"; } else { print " "; }
956 print "<table class=\"list\"><tr><td align=\"$align\">\n";
961 print "</td></tr></table><br><br>";
966 my $filename = $_[0];
969 # write cgi vars to the file.
970 open(FILE
, ">${filename}") or die "Unable to write file $filename";
972 foreach $var (keys %$hash)
974 $val = $hash->{$var};
975 # Darren Critchley Jan 17, 2003 added the following because when submitting with a graphic, the x and y
976 # location of the mouse are submitted as well, this was being written to the settings file causing
977 # some serious grief! This skips the variable.x and variable.y
978 if (!($var =~ /(.x|.y)$/)) {
981 if (!($var =~ /^ACTION/)) {
982 print FILE
"${var}=${val}\n"; }
990 my $filename = $_[0];
994 open(FILE
, $filename) or die "Unable to read file $filename";
999 ($var, $val) = split /=/, $_, 2;
1005 # Untaint variables read from hash
1006 $var =~ /([A-Za-z0-9_-]*)/; $var = $1;
1007 $val =~ /([\w\W]*)/; $val = $1;
1008 $hash->{$var} = $val;
1015 my ($hash, $params) = @_;
1016 my $cgi = CGI
->new ();
1017 $hash->{'__CGI__'} = $cgi;
1018 return if ($ENV{'REQUEST_METHOD'} ne 'POST');
1019 if (!$params->{'wantfile'}) {
1020 $CGI::DISABLE_UPLOADS
= 1;
1021 $CGI::POST_MAX
= 512 * 1024;
1023 $CGI::POST_MAX
= 10 * 1024 * 1024;
1026 $cgi->referer() =~ m/^https?\:\/\
/([^\/]+)/;
1028 $cgi->url() =~ m/^https?\:\/\
/([^\/]+)/;
1029 my $servername = $1;
1030 return if ($referer ne $servername);
1032 ### Modified for getting multi-vars, split by |
1033 %temp = $cgi->Vars();
1034 foreach my $key (keys %temp) {
1035 $hash->{$key} = $temp{$key};
1036 $hash->{$key} =~ s/\0/|/g;
1037 $hash->{$key} =~ s/^\s*(.*?)\s*$/$1/;
1040 if (($params->{'wantfile'})&&($params->{'filevar'})) {
1041 $hash->{$params->{'filevar'}} = $cgi->upload
1042 ($params->{'filevar'});
1049 my $logmessage = $_[0];
1050 $logmessage =~ /([\w\W]*)/;
1052 system('/usr/bin/logger', '-t', 'ipfire', $logmessage);
1057 my ($dev, $ino, $mode, $nlink, $uid, $gid, $rdev, $size,
1058 $atime, $mtime, $ctime, $blksize, $blocks) = stat $_[0];
1061 my $totalsecs = $now - $mtime;
1062 my $days = int($totalsecs / 86400);
1063 my $totalhours = int($totalsecs / 3600);
1064 my $hours = $totalhours % 24;
1065 my $totalmins = int($totalsecs / 60);
1066 my $mins = $totalmins % 60;
1067 my $secs = $totalsecs % 60;
1069 return "${days}d ${hours}h ${mins}m ${secs}s";
1076 if (!($ip =~ /^(\d+)\.(\d+)\.(\d+)\.(\d+)$/)) {
1080 @octets = ($1, $2, $3, $4);
1081 foreach $_ (@octets)
1085 if ($_ < 0 || $_ > 255) {
1096 # secord part an ip?
1097 if (&validip
($mask)) {
1099 # second part a number?
1102 if (!($mask =~ /^\d+$/)) {
1104 if ($mask >= 0 && $mask <= 32) {
1111 my $ipormask = $_[0];
1113 # see if it is a IP only.
1114 if (&validip
($ipormask)) {
1116 # split it into number and mask.
1117 if (!($ipormask =~ /^(.*?)\/(.*?
)$/)) {
1121 # first part not a ip?
1122 if (!(&validip
($ip))) {
1124 return &validmask
($mask);
1129 my $ipandmask = $_[0];
1131 # split it into number and mask.
1132 if (!($ipandmask =~ /^(.*?)\/(.*?
)$/)) {
1136 # first part not a ip?
1137 if (!(&validip
($ip))) {
1139 return &validmask
($mask);
1150 if ($_ >= 1 && $_ <= 65535) {
1157 my $checkmac = $_[0];
1158 my $ot = '[0-9a-f]{2}'; # 2 Hex digits (one octet)
1159 if ($checkmac !~ /^$ot:$ot:$ot:$ot:$ot:$ot$/i)
1168 # Checks a hostname against RFC1035
1169 my $hostname = $_[0];
1171 # Each part should be at least two characters in length
1172 # but no more than 63 characters
1173 if (length ($hostname) < 2 || length ($hostname) > 63) {
1175 # Only valid characters are a-z, A-Z, 0-9 and -
1176 if ($hostname !~ /^[a-zA-Z0-9-]*$/) {
1178 # First character can only be a letter or a digit
1179 if (substr ($hostname, 0, 1) !~ /^[a-zA-Z0-9]*$/) {
1181 # Last character can only be a letter or a digit
1182 if (substr ($hostname, -1, 1) !~ /^[a-zA-Z0-9]*$/) {
1189 # Checks a domain name against RFC1035
1190 my $domainname = $_[0];
1191 my @parts = split (/\./, $domainname); # Split hostname at the '.'
1193 foreach $part (@parts) {
1194 # Each part should be at least two characters in length
1195 # but no more than 63 characters
1196 if (length ($part) < 2 || length ($part) > 63) {
1198 # Only valid characters are a-z, A-Z, 0-9 and -
1199 if ($part !~ /^[a-zA-Z0-9-]*$/) {
1201 # First character can only be a letter or a digit
1202 if (substr ($part, 0, 1) !~ /^[a-zA-Z0-9]*$/) {
1204 # Last character can only be a letter or a digit
1205 if (substr ($part, -1, 1) !~ /^[a-zA-Z0-9]*$/) {
1213 # Checks a fully qualified domain name against RFC1035
1215 my @parts = split (/\./, $fqdn); # Split hostname at the '.'
1216 if (scalar(@parts) < 2) { # At least two parts should
1217 return 0;} # exist in a FQDN
1218 # (i.e. hostname.domain)
1219 foreach $part (@parts) {
1220 # Each part should be at least two characters in length
1221 # but no more than 63 characters
1222 if (length ($part) < 2 || length ($part) > 63) {
1224 # Only valid characters are a-z, A-Z, 0-9 and -
1225 if ($part !~ /^[a-zA-Z0-9-]*$/) {
1227 # First character can only be a letter or a digit
1228 if (substr ($part, 0, 1) !~ /^[a-zA-Z0-9]*$/) {
1230 # Last character can only be a letter or a digit
1231 if (substr ($part, -1, 1) !~ /^[a-zA-Z0-9]*$/) {
1237 sub validportrange
# used to check a port range
1239 my $port = $_[0]; # port values
1240 $port =~ tr/-/:/; # replace all - with colons just in case someone used -
1241 my $srcdst = $_[1]; # is it a source or destination port
1243 if (!($port =~ /^(\d+)\:(\d+)$/)) {
1245 if (!(&validport
($port))) {
1246 if ($srcdst eq 'src'){
1247 return $tr{'source port numbers'};
1249 return $tr{'destination port numbers'};
1257 if ($srcdst eq 'src'){
1258 return $tr{'bad source range'};
1260 return $tr{'bad destination range'};
1265 if (!(&validport
($_))) {
1266 if ($srcdst eq 'src'){
1267 return $tr{'source port numbers'};
1269 return $tr{'destination port numbers'};
1277 # Test if IP is within a subnet
1278 # Call: IpInSubnet (Addr, Subnet, Subnet Mask)
1279 # Subnet can be an IP of the subnet: 10.0.0.0 or 10.0.0.1
1280 # Everything in dottted notation
1281 # Return: TRUE/FALSE
1284 $ip = unpack('N', inet_aton
(shift));
1285 $start = unpack('N', inet_aton
(shift));
1286 $mask = unpack('N', inet_aton
(shift));
1287 $start &= $mask; # base of subnet...
1288 $end = $start + ~$mask;
1289 return (($ip >= $start) && ($ip <= $end));
1294 return 0 if ( $mail !~ /^[0-9a-zA-Z\.\-\_]+\@[0-9a-zA-Z\.\-]+$/ );
1295 return 0 if ( $mail =~ /^[^0-9a-zA-Z]|[^0-9a-zA-Z]$/);
1296 return 0 if ( $mail !~ /([0-9a-zA-Z]{1})\@./ );
1297 return 0 if ( $mail !~ /.\@([0-9a-zA-Z]{1})/ );
1298 return 0 if ( $mail =~ /.\.\-.|.\-\..|.\.\..|.\-\-./g );
1299 return 0 if ( $mail =~ /.\.\_.|.\-\_.|.\_\..|.\_\-.|.\_\_./g );
1300 return 0 if ( $mail !~ /\.([a-zA-Z]{2,3})$/ );
1305 my ($filename, $hash) = @_;
1307 open(FILE
, $filename) or die "Unable to read file $filename";
1310 my ($key, $rest, @temp);
1312 ($key, $rest) = split (/,/, $_, 2);
1313 if ($key =~ /^[0-9]+$/ && $rest) {
1314 @temp = split (/,/, $rest);
1315 $hash->{$key} = \
@temp;
1322 sub writehasharray
{
1323 my ($filename, $hash) = @_;
1326 open(FILE
, ">$filename") or die "Unable to write to file $filename";
1328 foreach $key (keys %$hash) {
1329 if ( $hash->{$key} ) {
1331 foreach $i (0 .. $#{$hash->{$key}}) {
1332 print FILE
",$hash->{$key}[$i]";
1341 sub findhasharraykey
{
1342 foreach my $i (1 .. 1000000) {
1343 if ( ! exists $_[0]{$i}) {
1351 my $outstring =$_[0];
1352 $outstring =~ tr/,/ / if not defined $_[1] or $_[1] ne 'y';
1353 $outstring =~ s/&/&/g;
1354 $outstring =~ s/\'/'/g;
1355 $outstring =~ s/\"/"/g;
1356 $outstring =~ s/</</g;
1357 $outstring =~ s/>/>/g;
1361 sub connectionstatus
1363 my %pppsettings = ();
1364 my %netsettings = ();
1367 $pppsettings{'PROFILENAME'} = 'None';
1368 &General
::readhash
("${General::swroot}/ppp/settings", \
%pppsettings);
1369 &General
::readhash
("${General::swroot}/ethernet/settings", \
%netsettings);
1372 if ( ! ( $netsettings{'CONFIG_TYPE'} =~ /^(2|3|6|7)$/ && $netsettings{'RED_TYPE'} =~ /^(DHCP|STATIC)$/ ) ) {
1373 $profileused="- $pppsettings{'PROFILENAME'}";
1376 if ( ( $pppsettings{'METHOD'} eq 'DHCP' && $netsettings{'RED_TYPE'} ne 'PPTP')
1377 || $netsettings{'RED_TYPE'} eq 'DHCP' ) {
1378 if (open(IFACE
, "${General::swroot}/red/iface")) {
1382 $iface =~ /([a-zA-Z0-9]*)/; $iface = $1;
1386 my ($timestr, $connstate);
1387 if ($netsettings{'CONFIG_TYPE'} =~ /^(0|1|4|5)$/ && $pppsettings{'TYPE'} =~ /^isdn/) {
1388 # Count ISDN channels
1389 my ($idmap, $chmap, $drmap, $usage, $flags, $phone);
1393 open (FILE
, "/dev/isdninfo");
1395 $idmap = <FILE
>; chop $idmap;
1396 $chmap = <FILE
>; chop $chmap;
1397 $drmap = <FILE
>; chop $drmap;
1398 $usage = <FILE
>; chop $usage;
1399 $flags = <FILE
>; chop $flags;
1400 $phone = <FILE
>; chop $phone;
1402 $phone =~ s/^phone(\s*):(\s*)//;
1404 @phonenumbers = split / /, $phone;
1406 foreach (@phonenumbers) {
1413 ## Connection status
1417 } elsif ($count == 1) {
1423 if (-e
"${General::swroot}/red/active") {
1424 $timestr = &General
::age
("${General::swroot}/red/active");
1425 $connstate = "<span class='ipcop_StatusBig'>$Lang::tr{'connected'} - $number channel (<span class='ipcop_StatusBigRed'>$timestr</span>) $profileused</span>";
1428 if (-e
"${General::swroot}/red/dial-on-demand") {
1429 $connstate = "<span class='ipcop_StatusBig'>$Lang::tr{'dod waiting'} $profileused</span>";
1431 $connstate = "<span class='ipcop_StatusBig'>$Lang::tr{'idle'} $profileused</span>";
1434 $connstate = "<span class='ipcop_StatusBig'>$Lang::tr{'connecting'} $profileused</span>";
1437 } elsif ($netsettings{'RED_TYPE'} eq "STATIC" || $pppsettings {'METHOD'} eq 'STATIC') {
1438 if (-e
"${General::swroot}/red/active") {
1439 $timestr = &General
::age
("${General::swroot}/red/active");
1440 $connstate = "<span class='ipcop_StatusBig'>$Lang::tr{'connected'} (<span class='ipcop_StatusBigRed'>$timestr</span>) $profileused</span>";
1442 $connstate = "<span class='ipcop_StatusBig'>$Lang::tr{'idle'} $profileused</span>";
1444 } elsif ( ( (-e
"${General::swroot}/dhcpc/dhcpcd-$iface.pid") && $netsettings{'RED_TYPE'} ne 'PPTP' ) ||
1445 !system("/bin/ps -ef | /bin/grep -q '[p]ppd'") || !system("/bin/ps -ef | /bin/grep -q '[c]onnectioncheck'")) {
1446 if (-e
"${General::swroot}/red/active") {
1447 $timestr = &General
::age
("${General::swroot}/red/active");
1448 if ($pppsettings{'TYPE'} =~ /^(modem|bewanadsl|conexantpciadsl|eagleusbadsl)$/) {
1450 if ($pppsettings{'TYPE'} eq 'modem') {
1451 open(CONNECTLOG
, "/var/log/connect.log");
1452 while (<CONNECTLOG
>) {
1454 $speed = (split / /)[6];
1458 } elsif ($pppsettings{'TYPE'} eq 'bewanadsl') {
1459 $speed = `/usr/bin/unicorn_status | /bin/grep Rate | /usr/bin/cut -f2 -d ':'`;
1460 } elsif ($pppsettings{'TYPE'} eq 'conexantpciadsl') {
1461 $speed = `/bin/cat /proc/net/atm/CnxAdsl:* | /bin/grep 'Line Rates' | /bin/sed -e 's+Line Rates: Receive+Rx+' -e 's+Transmit+Tx+'`;
1462 } elsif ($pppsettings{'TYPE'} eq 'eagleusbadsl') {
1463 $speed = `/usr/sbin/eaglestat | /bin/grep Rate`;
1465 $connstate = "<span class='ipcop_StatusBig'>$Lang::tr{'connected'} (<span class='ipcop_StatusBigRed'>$timestr</span>) $profileused (\@$speed)</span>";
1467 $connstate = "<span class='ipcop_StatusBig'>$Lang::tr{'connected'} (<span class='ipcop_StatusBigRed'>$timestr</span>) $profileused</span>";
1470 if (-e
"${General::swroot}/red/dial-on-demand") {
1471 $connstate = "<span class='ipcop_StatusBig'>$Lang::tr{'dod waiting'} $profileused</span>";
1473 $connstate = "<span class='ipcop_StatusBig'>$Lang::tr{'connecting'} $profileused</span>";
1477 $connstate = "<span class='ipcop_StatusBig'>$Lang::tr{'idle'} $profileused</span>";
1483 # Darren Critchley - darrenc@telus.net - (c) 2003
1484 # &srtarray(SortOrder, AlphaNumeric, SortDirection, ArrayToBeSorted)
1485 # This subroutine will take the following parameters:
1486 # ColumnNumber = the column which you want to sort on, starts at 1
1487 # AlphaNumberic = a or n (lowercase) defines whether the sort should be alpha or numberic
1488 # SortDirection = asc or dsc (lowercase) Ascending or Descending sort
1489 # ArrayToBeSorted = the array that wants sorting
1491 # Returns an array that is sorted to your specs
1493 # If SortOrder is greater than the elements in array, then it defaults to the first element
1496 my ($colno, $alpnum, $srtdir, @tobesorted) = @_;
1501 my $ttlitems = scalar @tobesorted; # want to know the number of rows in the passed array
1502 if ($ttlitems < 1){ # if no items, don't waste our time lets leave
1503 return (@tobesorted);
1505 my @tmp = split(/\,/,$tobesorted[0]);
1506 $ttlitems = scalar @tmp; # this should be the number of elements in each row of the passed in array
1508 # Darren Critchley - validate parameters
1509 if ($colno > $ttlitems){$colno = '1';}
1510 $colno--; # remove one from colno to deal with arrays starting at 0
1511 if($colno < 0){$colno = '0';}
1512 if ($alpnum ne '') { $alpnum = lc($alpnum); } else { $alpnum = 'a'; }
1513 if ($srtdir ne '') { $srtdir = lc($srtdir); } else { $srtdir = 'src'; }
1515 foreach $line (@tobesorted)
1519 my @temp = split(/\,/,$line);
1520 # Darren Critchley - juggle the fields so that the one we want to sort on is first
1521 my $tmpholder = $temp[0];
1522 $temp[0] = $temp[$colno];
1523 $temp[$colno] = $tmpholder;
1525 for ($ctr=0; $ctr < $ttlitems ; $ctr++) {
1526 $newline=$newline . $temp[$ctr] . ",";
1529 push(@tmparray,$newline);
1532 if ($alpnum eq 'n') {
1533 @tmparray = sort {$a <=> $b} @tmparray;
1535 @tmparray = (sort @tmparray);
1537 foreach $line (@tmparray)
1541 my @temp = split(/\,/,$line);
1542 my $tmpholder = $temp[0];
1543 $temp[0] = $temp[$colno];
1544 $temp[$colno] = $tmpholder;
1546 for ($ctr=0; $ctr < $ttlitems ; $ctr++){
1547 $newline=$newline . $temp[$ctr] . ",";
1550 push(@srtedarray,$newline);
1554 if ($srtdir eq 'dsc') {
1555 @tmparray = reverse(@srtedarray);
1558 return (@srtedarray);
1562 sub speedtouchversion
1564 if (-f
"/proc/bus/usb/devices")
1566 $speedtouch=`/bin/cat /proc/bus/usb/devices | /bin/grep 'Vendor=06b9 ProdID=4061' | /usr/bin/cut -d ' ' -f6`;
1567 if ($speedtouch eq '') {
1568 $speedtouch= $tr{'connect the modem'};
1571 $speedtouch='USB '.$tr{'not running'};
1576 sub CheckSortOrder
{
1577 #Sorting of allocated leases
1578 if ($ENV{'QUERY_STRING'} =~ /^IPADDR|^ETHER|^HOSTNAME|^ENDTIME/ ) {
1579 my $newsort=$ENV{'QUERY_STRING'};
1580 &readhash
("${swroot}/dhcp/settings", \
%dhcpsettings);
1581 $act=$dhcpsettings{'SORT_LEASELIST'};
1583 if ($act =~ $newsort) {
1584 if ($act !~ 'Rev') {$Rev='Rev'};
1588 $dhcpsettings{'SORT_LEASELIST'}=$newsort;
1589 &writehash
("${swroot}/dhcp/settings", \
%dhcpsettings);
1590 $dhcpsettings{'ACTION'} = 'SORT'; # avoid the next test "First lauch"
1595 sub PrintActualLeases
1597 &openbox
('100%', 'left', $tr{'current dynamic leases'});
1599 <table width='100%'>
1601 <td width='25%' align='center'><a href='$ENV{'SCRIPT_NAME'}?IPADDR'><b>$tr{'ip address'}</b></a></td>
1602 <td width='25%' align='center'><a href='$ENV{'SCRIPT_NAME'}?ETHER'><b>$tr{'mac address'}</b></a></td>
1603 <td width='20%' align='center'><a href='$ENV{'SCRIPT_NAME'}?HOSTNAME'><b>$tr{'hostname'}</b></a></td>
1604 <td width='30%' align='center'><a href='$ENV{'SCRIPT_NAME'}?ENDTIME'><b>$tr{'lease expires'} (local time d/m/y)</b></a></td>
1609 open(LEASES
,"/var/state/dhcp/dhcpd.leases") or die "Can't open dhcpd.leases";
1610 while ($line = <LEASES
>) {
1611 next if( $line =~ /^\s*#/ );
1613 @temp = split (' ', $line);
1615 if ($line =~ /^\s*lease/) {
1617 #All field are not necessarily read. Clear everything
1623 if ($line =~ /^\s*ends/) {
1624 $line =~ /(\d+)\/(\d
+)\
/(\d+) (\d+):(\d+):(\d+)/;
1625 $endtime = timegm
($6, $5, $4, $3, $2 - 1, $1 - 1900);
1628 if ($line =~ /^\s*hardware ethernet/) {
1633 if ($line =~ /^\s*client-hostname/) {
1634 $hostname = "$temp[1] $temp[2] $temp[3]";
1635 $hostname =~ s/;//g;
1636 $hostname =~ s/\"//g;
1640 @record = ('IPADDR',$ip,'ENDTIME',$endtime,'ETHER',$ether,'HOSTNAME',$hostname);
1641 $record = {}; # create a reference to empty hash
1642 %{$record} = @record; # populate that hash with @record
1643 $entries{$record->{'IPADDR'}} = $record; # add this to a hash of hashes
1649 foreach my $key (sort leasesort
keys %entries) {
1651 my $hostname = &cleanhtml
($entries{$key}->{HOSTNAME
},"y");
1654 print "<tr bgcolor='$table1colour'>";
1657 print "<tr bgcolor='$table2colour'>";
1661 <td align='center'>$entries{$key}->{IPADDR}</td>
1662 <td align='center'>$entries{$key}->{ETHER}</td>
1663 <td align='center'> $hostname </td>
1668 ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $dst) = localtime ($entries{$key}->{ENDTIME
});
1669 $enddate = sprintf ("%02d/%02d/%d %02d:%02d:%02d",$mday,$mon+1,$year+1900,$hour,$min,$sec);
1671 if ($entries{$key}->{ENDTIME
} < time() ){
1672 print "<strike>$enddate</strike>";
1685 # This sub is used during display of actives leases
1687 if (rindex ($dhcpsettings{'SORT_LEASELIST'},'Rev') != -1)
1689 $qs=substr ($dhcpsettings{'SORT_LEASELIST'},0,length($dhcpsettings{'SORT_LEASELIST'})-3);
1690 if ($qs eq 'IPADDR') {
1691 @a = split(/\./,$entries{$a}->{$qs});
1692 @b = split(/\./,$entries{$b}->{$qs});
1698 $entries{$b}->{$qs} cmp $entries{$a}->{$qs};
1703 $qs=$dhcpsettings{'SORT_LEASELIST'};
1704 if ($qs eq 'IPADDR') {
1705 @a = split(/\./,$entries{$a}->{$qs});
1706 @b = split(/\./,$entries{$b}->{$qs});
1712 $entries{$a}->{$qs} cmp $entries{$b}->{$qs};
1719 opendir(DIR
, "${swroot}/uplinks/") || return \
@uplinks;
1720 foreach my $dir (readdir(DIR
)) {
1721 next if ($dir =~ /^\./);
1722 next if (-f
"${swroot}/uplinks/$dir");
1723 push(@uplinks, $dir);
1730 my $filename = shift;
1732 open (F
, $filename) || return "";
1739 sub get_red_ifaces_by_type
($) {
1741 my @gottypeiface = ();
1742 my @gottypeuplink = ();
1745 my $ref=get_uplinks
();
1748 foreach my $link (@uplinks) {
1750 &readhash
("${swroot}/uplinks/$link/settings", \
%set);
1752 push(@gottype, $link);
1754 my $iface = $set{'RED_DEV'};
1756 $iface = get_iface
("${swroot}/uplinks/$link/interface");
1760 if ($set{'RED_TYPE'} eq $type) {
1761 push(@gottypeiface, $iface);
1762 push(@gottypeuplink, $link);
1765 return (\
@gottypeiface, \
@gottypeuplink, \
@gottype);
1768 sub get_red_ifaces
() {
1769 return `cat ${swroot}/uplinks/*/interface 2>/dev/null`;
1772 sub get_zone_devices
($) {
1775 open (FILE
, "${swroot}/ethernet/$bridge") || return "";
1776 foreach my $line (<FILE
>) {
1779 push(@ifaces, $line);