]>
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.proxy'} = {'caption' => 'Webproxy',
239 'uri' => '/cgi-bin/proxy.cgi',
240 'title' => "Webproxy",
243 $subnetwork->{'20.urlfilter'} = {'caption' => 'URL-Filter',
244 'uri' => '/cgi-bin/urlfilter.cgi',
245 'title' => "URL-Filter",
248 $subnetwork->{'30.dhcp'} = {'caption' => $tr{'dhcp server'},
249 'uri' => '/cgi-bin/dhcp.cgi',
250 'title' => "$tr{'dhcp server'}",
253 $subnetwork->{'40.scheduler'} = {
254 'caption' => $tr{'scheduler'},
255 'uri' => '/cgi-bin/connscheduler.cgi',
256 'title' => "$tr{'scheduler'}",
259 $subnetwork->{'50.hosts'} = {
260 'caption' => $tr{'edit hosts'},
261 'uri' => '/cgi-bin/hosts.cgi',
262 'title' => "$tr{'edit hosts'}",
265 $subnetwork->{'60.upload'} = {
266 'caption' => $tr{'upload'},
267 'uri' => '/cgi-bin/upload.cgi',
268 'title' => "$tr{'upload'}",
271 $subnetwork->{'70.aliases'} = {
272 'caption' => $tr{'aliases'},
273 'uri' => '/cgi-bin/aliases.cgi',
274 'title' => "$tr{'aliases'}",
277 $subnetwork->{'80.wakeonlan'} = {
278 'caption' => $tr{'WakeOnLan'},
279 'uri' => '/cgi-bin/wakeonlan.cgi',
280 'title' => "$tr{'WakeOnLan'}",
284 my %subserviceshash = ();
285 my $subservices = \
%subserviceshash;
288 $subservices->{'10.openvpn'} = {
289 'caption' => 'OpenVPN',
290 'uri' => '/cgi-bin/ovpnmain.cgi',
291 'title' => "$tr{'virtual private networking'}",
294 $subservices->{'20.ipsec'} = {
295 'caption' => 'IPSec',
296 'uri' => '/cgi-bin/vpnmain.cgi',
297 'title' => "$tr{'virtual private networking'}",
300 $subservices->{'30.dyndns'} = {'caption' => $tr{'dynamic dns'},
301 'uri' => '/cgi-bin/ddns.cgi',
302 'title' => "$tr{'dynamic dns'}",
305 $subservices->{'40.time'} = {'caption' => $tr{'time server'},
306 'uri' => '/cgi-bin/time.cgi',
307 'title' => "$tr{'time server'}",
310 $subservices->{'50.qos'} = {'caption' => 'Quality of Service',
311 'uri' => '/cgi-bin/qos.cgi',
312 'title' => "Quality of Service",
315 $subservices->{'60.ids'} = {'caption' => $tr{'intrusion detection'},
317 'uri' => '/cgi-bin/ids.cgi',
318 'title' => "$tr{'intrusion detection system'}",
323 my %subfirewallhash = ();
324 my $subfirewall = \
%subfirewallhash;
327 $subfirewall->{'10.dnat'} = {
328 'caption' => $tr{'ssport forwarding'},
329 'uri' => '/cgi-bin/portfw.cgi',
330 'title' => "$tr{'ssport forwarding'}",
333 $subfirewall->{'20.xtaccess'} = {
334 'caption' => $tr{'external access'},
335 'uri' => '/cgi-bin/xtaccess.cgi',
336 'title' => "$tr{'external access'}",
339 $subfirewall->{'30.wireless'} = {
340 'caption' => $tr{'blue access'},
341 'uri' => '/cgi-bin/wireless.cgi',
342 'title' => "$tr{'blue access'}",
345 $subfirewall->{'40.dmz'} = {
346 'caption' => $tr{'ssdmz pinholes'},
347 'uri' => '/cgi-bin/dmzholes.cgi',
348 'title' => "$tr{'dmz pinhole configuration'}",
351 $subfirewall->{'50.outgoing'} = {
352 'caption' => $tr{'outgoing firewall'},
353 'uri' => '/cgi-bin/outgoingfw.cgi',
354 'title' => "$tr{'outgoing firewall'}",
357 $subfirewall->{'60.fwopts'} = {
358 'caption' => $tr{'options fw'},
359 'uri' => '/cgi-bin/optionsfw.cgi',
360 'title' => "$tr{'options fw'}",
364 my %sublogshash = ();
365 my $sublogs = \
%sublogshash;
367 $sublogs->{'10.summary'} = {'caption' => $tr{'log summary'},
368 'uri' => '/cgi-bin/logs.cgi/summary.dat',
369 'title' => "$tr{'log summary'}",
372 $sublogs->{'20.settings'} = {'caption' => $tr{'log settings'},
373 'uri' => '/cgi-bin/logs.cgi/config.dat',
374 'title' => "$tr{'log settings'}",
377 $sublogs->{'30.proxy'} = {'caption' => $tr{'proxy logs'},
378 'uri' => '/cgi-bin/logs.cgi/proxylog.dat',
379 'title' => "$tr{'proxy logs'}",
382 $sublogs->{'40.firewall'} = {'caption' => $tr{'firewall logs'},
383 'uri' => '/cgi-bin/logs.cgi/firewalllog.dat',
384 'title' => "$tr{'firewall logs'}",
387 $sublogs->{'50.ids'} = {'caption' => $tr{'ids logs'},
388 'uri' => '/cgi-bin/logs.cgi/ids.dat',
389 'title' => "$tr{'ids logs'}",
392 $sublogs->{'60.urlfilter'} = {
393 'caption' => $tr{'urlfilter log'},
394 'uri' => '/cgi-bin/logs.cgi/urlfilter.dat',
395 'title' => "$tr{'urlfilter log'}",
398 $sublogs->{'70.openvpn'} = {'caption' => $tr{'openvpn log'},
399 'uri' => '/cgi-bin/logs.cgi/openvpn.dat',
400 'title' => "$tr{'openvpn log'}",
403 $sublogs->{'80.system'} = {'caption' => $tr{'system logs'},
404 'uri' => '/cgi-bin/logs.cgi/log.dat',
405 'title' => "$tr{'system logs'}",
408 $sublogs->{'90.userlog'} = {'caption' => $tr{'user proxy logs'},
409 'uri' => '/cgi-bin/logs.cgi/userlog.dat',
410 'title' => "$tr{'user log'}",
414 my %subipfirehash = ();
415 my $subipfire = \
%subipfirehash;
416 $subipfire->{'10.pakfire'} = {'caption' => 'Pakfire',
417 'uri' => '/cgi-bin/pakfire.cgi',
418 'title' => "Pakfire",
421 $subipfire->{'20.asterisk'} = {'caption' => 'Asterisk',
422 'uri' => '/cgi-bin/asterisk.cgi',
423 'title' => "Asterisk",
426 $subipfire->{'30.samba'} = {'caption' => 'Samba',
427 'uri' => '/cgi-bin/samba.cgi',
431 $subipfire->{'99.help'} = {'caption' => $tr{'help'},
432 'uri' => '/cgi-bin/help.cgi',
433 'title' => "$tr{'help'}",
439 $menu->{'01.system'} = {'caption' => $tr{'alt system'},
441 'subMenu' => $subsystem
443 $menu->{'02.status'} = {'caption' => $tr{'status'},
445 'subMenu' => $substatus
447 $menu->{'03.network'} = {'caption' => $tr{'network'},
449 'subMenu' => $subnetwork
451 $menu->{'04.services'} = {'caption' => $tr{'alt services'},
453 'subMenu' => $subservices
455 $menu->{'05.firewall'} = {'caption' => $tr{'firewall'},
457 'subMenu' => $subfirewall
459 $menu->{'06.proxy'} = {'caption' => $tr{'alt proxy'},
461 'subMenu' => $subproxy
463 $menu->{'07.ipfire'} = {'caption' => 'IPFire',
465 'subMenu' => $subipfire
467 $menu->{'08.logs'} = {'caption' => $tr{'alt logs'},
469 'subMenu' => $sublogs
472 if (! blue_used
() && ! orange_used
()) {
473 $menu->{'05.firewall'}{'subMenu'}->{'40.dmz'}{'enabled'} = 0;
476 $menu->{'05.firewall'}{'subMenu'}->{'30.wireless'}{'enabled'} = 0;
478 if ( $ethsettings{'CONFIG_TYPE'} =~ /^(2|3|6|7)$/ && $ethsettings{'RED_TYPE'} eq 'STATIC' ) {
479 $menu->{'03.network'}{'subMenu'}->{'70.aliases'}{'enabled'} = 1;
485 print "Pragma: no-cache\n";
486 print "Cache-control: no-cache\n";
487 print "Connection: close\n";
488 print "Content-type: text/html\n\n";
491 sub is_menu_visible
($) {
494 return (-e
$ENV{'DOCUMENT_ROOT'}."/../$link");
500 if (! $root->{'enabled'}) {
503 if ($root->{'uri'} !~ /^$/) {
505 if ($root->{'vars'} !~ /^$/) {
506 $vars = '?'. $root->{'vars'};
508 if (! is_menu_visible
($root->{'uri'})) {
511 return $root->{'uri'}.$vars;
513 my $submenus = $root->{'subMenu'};
517 foreach my $item (sort keys %$submenus) {
518 my $link = getlink
($submenus->{$item});
530 my $uri = $conf->{'uri'};
531 my $vars = $conf->{'vars'};
532 my $novars = $conf->{'novars'};
537 if ($uri ne $URI[0]) {
541 if ($URI[1] !~ /^$/) {
548 return ($URI[1] eq $vars);
558 foreach my $item (sort keys %$root) {
559 my $val = $root->{$item};
560 if (compare_url
($val)) {
561 $val->{'selected'} = 1;
562 if ($val->{'title'} !~ /^$/) {
563 return $val->{'title'};
565 return 'EMPTY TITLE';
568 my $title = gettitle
($val->{'subMenu'});
570 $val->{'selected'} = 1;
584 foreach my $k1 ( sort keys %$menu ) {
585 if (! $menu->{$k1}{'enabled'}) {
589 my $link = getlink
($menu->{$k1});
593 if (! is_menu_visible
($link)) {
596 if ($menu->{$k1}->{'selected'}) {
597 print '<li class="selected">';
603 <div class="rcorner">
604 <a href="$link">$menu->{$k1}{'caption'}</a>
624 foreach my $item (%$root) {
625 if ($root->{$item}{'selected'}) {
626 return $root->{$item};
631 sub showsubsection
($$) {
641 my $selected = getselected
($root);
645 my $submenus = $selected->{'subMenu'};
655 foreach my $item (sort keys %$submenus) {
656 my $hash = $submenus->{$item};
657 if (! $hash->{'enabled'}) {
661 my $link = getlink
($hash);
665 if (! is_menu_visible
($link)) {
668 if ($hash->{'selected'}) {
669 print '<li class="selected">';
675 <a href="$link">$hash->{'caption'}</a>
690 sub showsubsubsection
($) {
695 my $selected = getselected
($root);
699 if (! $selected->{'subMenu'}) {
703 showsubsection
($selected->{'subMenu'}, 'menu-subtop');
709 if ($URI[0] =~ /.*\/([^\
/]+)\.cgi/) {
714 $helpfile .= '.help.html';
716 my $helpuri = '/doc/'.$language.'/'.$helpfile;
717 if (! -e
$ENV{'DOCUMENT_ROOT'}.$helpuri) {
727 my $extrahead = shift;
729 @URI=split ('\?', $ENV{'REQUEST_URI'} );
730 &readhash
("${swroot}/main/settings", \
%settings);
733 my $h2 = gettitle
($menu);
734 my $helpuri = get_helpuri
();
736 $title = "IPFire - $title";
737 if ($settings{'WINDOWWITHHOSTNAME'} eq 'on') {
738 $title = "$settings{'HOSTNAME'}.$settings{'DOMAINNAME'} - $title";
743 PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
744 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
748 <title>$title</title>
751 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
754 if ($settings{'FX'} ne 'off') {
756 <meta http-equiv="Page-Enter" content="blendTrans(Duration=0.5,Transition=12)">
757 <meta http-equiv="Page-Exit" content="blendTrans(Duration=0.5,Transition=12)">
762 <link rel="shortcut icon" href="/favicon.ico" />
763 <style type="text/css">\@import url(/include/style.css);</style>
764 <style type="text/css">\@import url(/include/menu.css);</style>
765 <style type="text/css">\@import url(/include/content.css);</style>
766 <script language="javascript" type="text/javascript">
768 function swapVisibility(id) {
769 el = document.getElementById(id);
770 if(el.style.display != 'block') {
771 el.style.display = 'block'
774 el.style.display = 'none'
781 <!-- IPFIRE HEADER -->
786 <img id="logo-product" src="/images/logo_ipfire.gif">
787 <div id="header-icons">
788 <a href="http://users.ipfire.eu/" target="_blank"><img border="0" src="/images/help.gif"></a>
805 &showsubsection
($menu);
808 <p><center><img src="/images/iptux.png" width='160px' height='160px'></center></p>
810 <td width="100%" valign="top">
811 <div id="page-content">
816 &showsubsubsection
($menu);
819 require 'ipfire-network.pl';
820 $supported = check_support
();
821 warn_unsupported
($supported);
825 sub openpagewithoutmenu
{
828 my $extrahead = shift;
830 @URI=split ('\?', $ENV{'REQUEST_URI'} );
831 &readhash
("${swroot}/main/settings", \
%settings);
834 my $h2 = gettitle
($menu);
835 my $helpuri = get_helpuri
();
837 $title = "IPFire - $title";
838 if ($settings{'WINDOWWITHHOSTNAME'} eq 'on') {
839 $title = "$settings{'HOSTNAME'}.$settings{'DOMAINNAME'} - $title";
844 PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
845 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
849 <title>$title</title>
852 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
855 if ($settings{'FX'} eq 'on') {
857 <meta http-equiv="Page-Enter" content="blendTrans(Duration=0.5,Transition=12)">
858 <meta http-equiv="Page-Exit" content="blendTrans(Duration=0.5,Transition=12)">
863 <link rel="shortcut icon" href="/favicon.ico" />
864 <style type="text/css">\@import url(/include/style.css);</style>
865 <style type="text/css">\@import url(/include/menu.css);</style>
866 <style type="text/css">\@import url(/include/content.css);</style>
867 <script language="javascript" type="text/javascript">
869 function swapVisibility(id) {
870 el = document.getElementById(id);
871 if(el.style.display != 'block') {
872 el.style.display = 'block'
875 el.style.display = 'none'
882 <!-- IPFIRE HEADER -->
887 <img id="logo-product" src="/images/logo_ipfire.gif">
888 <div id="header-icons">
889 <a href="http://users.ipfire.eu/" target="_blank"><img border="0" src="/images/help.gif"></a>
900 <p><center><img src="/images/iptux.png" width='160px' height='160px'></center></p>
902 <td width="100%" valign="top">
903 <div id="page-content">
910 my $status = &connectionstatus
();
911 $uptime = `/usr/bin/uptime`;
916 <div style="font-size: 9px"><b>Status:</b> $status <b>Uptime:</b>$uptime <b>Version:</b> $FIREBUILD</div>
932 $bgcolor = "style='background-color: $colourerr;'";
940 # print "</td></tr></table></td></tr></table>\n"
949 if ($caption) { print "<h3>$caption</h3>\n"; } else { print " "; }
951 print "<table class=\"list\"><tr><td align=\"$align\">\n";
956 print "</td></tr></table><br><br>";
961 my $filename = $_[0];
964 # write cgi vars to the file.
965 open(FILE
, ">${filename}") or die "Unable to write file $filename";
967 foreach $var (keys %$hash)
969 $val = $hash->{$var};
970 # Darren Critchley Jan 17, 2003 added the following because when submitting with a graphic, the x and y
971 # location of the mouse are submitted as well, this was being written to the settings file causing
972 # some serious grief! This skips the variable.x and variable.y
973 if (!($var =~ /(.x|.y)$/)) {
976 if (!($var =~ /^ACTION/)) {
977 print FILE
"${var}=${val}\n"; }
985 my $filename = $_[0];
989 open(FILE
, $filename) or die "Unable to read file $filename";
994 ($var, $val) = split /=/, $_, 2;
1000 # Untaint variables read from hash
1001 $var =~ /([A-Za-z0-9_-]*)/; $var = $1;
1002 $val =~ /([\w\W]*)/; $val = $1;
1003 $hash->{$var} = $val;
1010 my ($hash, $params) = @_;
1011 my $cgi = CGI
->new ();
1012 $hash->{'__CGI__'} = $cgi;
1013 return if ($ENV{'REQUEST_METHOD'} ne 'POST');
1014 if (!$params->{'wantfile'}) {
1015 $CGI::DISABLE_UPLOADS
= 1;
1016 $CGI::POST_MAX
= 512 * 1024;
1018 $CGI::POST_MAX
= 10 * 1024 * 1024;
1021 $cgi->referer() =~ m/^https?\:\/\
/([^\/]+)/;
1023 $cgi->url() =~ m/^https?\:\/\
/([^\/]+)/;
1024 my $servername = $1;
1025 return if ($referer ne $servername);
1027 ### Modified for getting multi-vars, split by |
1028 %temp = $cgi->Vars();
1029 foreach my $key (keys %temp) {
1030 $hash->{$key} = $temp{$key};
1031 $hash->{$key} =~ s/\0/|/g;
1032 $hash->{$key} =~ s/^\s*(.*?)\s*$/$1/;
1035 if (($params->{'wantfile'})&&($params->{'filevar'})) {
1036 $hash->{$params->{'filevar'}} = $cgi->upload
1037 ($params->{'filevar'});
1044 my $logmessage = $_[0];
1045 $logmessage =~ /([\w\W]*)/;
1047 system('/usr/bin/logger', '-t', 'ipfire', $logmessage);
1052 my ($dev, $ino, $mode, $nlink, $uid, $gid, $rdev, $size,
1053 $atime, $mtime, $ctime, $blksize, $blocks) = stat $_[0];
1056 my $totalsecs = $now - $mtime;
1057 my $days = int($totalsecs / 86400);
1058 my $totalhours = int($totalsecs / 3600);
1059 my $hours = $totalhours % 24;
1060 my $totalmins = int($totalsecs / 60);
1061 my $mins = $totalmins % 60;
1062 my $secs = $totalsecs % 60;
1064 return "${days}d ${hours}h ${mins}m ${secs}s";
1071 if (!($ip =~ /^(\d+)\.(\d+)\.(\d+)\.(\d+)$/)) {
1075 @octets = ($1, $2, $3, $4);
1076 foreach $_ (@octets)
1080 if ($_ < 0 || $_ > 255) {
1091 # secord part an ip?
1092 if (&validip
($mask)) {
1094 # second part a number?
1097 if (!($mask =~ /^\d+$/)) {
1099 if ($mask >= 0 && $mask <= 32) {
1106 my $ipormask = $_[0];
1108 # see if it is a IP only.
1109 if (&validip
($ipormask)) {
1111 # split it into number and mask.
1112 if (!($ipormask =~ /^(.*?)\/(.*?
)$/)) {
1116 # first part not a ip?
1117 if (!(&validip
($ip))) {
1119 return &validmask
($mask);
1124 my $ipandmask = $_[0];
1126 # split it into number and mask.
1127 if (!($ipandmask =~ /^(.*?)\/(.*?
)$/)) {
1131 # first part not a ip?
1132 if (!(&validip
($ip))) {
1134 return &validmask
($mask);
1145 if ($_ >= 1 && $_ <= 65535) {
1152 my $checkmac = $_[0];
1153 my $ot = '[0-9a-f]{2}'; # 2 Hex digits (one octet)
1154 if ($checkmac !~ /^$ot:$ot:$ot:$ot:$ot:$ot$/i)
1163 # Checks a hostname against RFC1035
1164 my $hostname = $_[0];
1166 # Each part should be at least two characters in length
1167 # but no more than 63 characters
1168 if (length ($hostname) < 2 || length ($hostname) > 63) {
1170 # Only valid characters are a-z, A-Z, 0-9 and -
1171 if ($hostname !~ /^[a-zA-Z0-9-]*$/) {
1173 # First character can only be a letter or a digit
1174 if (substr ($hostname, 0, 1) !~ /^[a-zA-Z0-9]*$/) {
1176 # Last character can only be a letter or a digit
1177 if (substr ($hostname, -1, 1) !~ /^[a-zA-Z0-9]*$/) {
1184 # Checks a domain name against RFC1035
1185 my $domainname = $_[0];
1186 my @parts = split (/\./, $domainname); # Split hostname at the '.'
1188 foreach $part (@parts) {
1189 # Each part should be at least two characters in length
1190 # but no more than 63 characters
1191 if (length ($part) < 2 || length ($part) > 63) {
1193 # Only valid characters are a-z, A-Z, 0-9 and -
1194 if ($part !~ /^[a-zA-Z0-9-]*$/) {
1196 # First character can only be a letter or a digit
1197 if (substr ($part, 0, 1) !~ /^[a-zA-Z0-9]*$/) {
1199 # Last character can only be a letter or a digit
1200 if (substr ($part, -1, 1) !~ /^[a-zA-Z0-9]*$/) {
1208 # Checks a fully qualified domain name against RFC1035
1210 my @parts = split (/\./, $fqdn); # Split hostname at the '.'
1211 if (scalar(@parts) < 2) { # At least two parts should
1212 return 0;} # exist in a FQDN
1213 # (i.e. hostname.domain)
1214 foreach $part (@parts) {
1215 # Each part should be at least two characters in length
1216 # but no more than 63 characters
1217 if (length ($part) < 2 || length ($part) > 63) {
1219 # Only valid characters are a-z, A-Z, 0-9 and -
1220 if ($part !~ /^[a-zA-Z0-9-]*$/) {
1222 # First character can only be a letter or a digit
1223 if (substr ($part, 0, 1) !~ /^[a-zA-Z0-9]*$/) {
1225 # Last character can only be a letter or a digit
1226 if (substr ($part, -1, 1) !~ /^[a-zA-Z0-9]*$/) {
1232 sub validportrange
# used to check a port range
1234 my $port = $_[0]; # port values
1235 $port =~ tr/-/:/; # replace all - with colons just in case someone used -
1236 my $srcdst = $_[1]; # is it a source or destination port
1238 if (!($port =~ /^(\d+)\:(\d+)$/)) {
1240 if (!(&validport
($port))) {
1241 if ($srcdst eq 'src'){
1242 return $tr{'source port numbers'};
1244 return $tr{'destination port numbers'};
1252 if ($srcdst eq 'src'){
1253 return $tr{'bad source range'};
1255 return $tr{'bad destination range'};
1260 if (!(&validport
($_))) {
1261 if ($srcdst eq 'src'){
1262 return $tr{'source port numbers'};
1264 return $tr{'destination port numbers'};
1272 # Test if IP is within a subnet
1273 # Call: IpInSubnet (Addr, Subnet, Subnet Mask)
1274 # Subnet can be an IP of the subnet: 10.0.0.0 or 10.0.0.1
1275 # Everything in dottted notation
1276 # Return: TRUE/FALSE
1279 $ip = unpack('N', inet_aton
(shift));
1280 $start = unpack('N', inet_aton
(shift));
1281 $mask = unpack('N', inet_aton
(shift));
1282 $start &= $mask; # base of subnet...
1283 $end = $start + ~$mask;
1284 return (($ip >= $start) && ($ip <= $end));
1289 return 0 if ( $mail !~ /^[0-9a-zA-Z\.\-\_]+\@[0-9a-zA-Z\.\-]+$/ );
1290 return 0 if ( $mail =~ /^[^0-9a-zA-Z]|[^0-9a-zA-Z]$/);
1291 return 0 if ( $mail !~ /([0-9a-zA-Z]{1})\@./ );
1292 return 0 if ( $mail !~ /.\@([0-9a-zA-Z]{1})/ );
1293 return 0 if ( $mail =~ /.\.\-.|.\-\..|.\.\..|.\-\-./g );
1294 return 0 if ( $mail =~ /.\.\_.|.\-\_.|.\_\..|.\_\-.|.\_\_./g );
1295 return 0 if ( $mail !~ /\.([a-zA-Z]{2,3})$/ );
1300 my ($filename, $hash) = @_;
1302 open(FILE
, $filename) or die "Unable to read file $filename";
1305 my ($key, $rest, @temp);
1307 ($key, $rest) = split (/,/, $_, 2);
1308 if ($key =~ /^[0-9]+$/ && $rest) {
1309 @temp = split (/,/, $rest);
1310 $hash->{$key} = \
@temp;
1317 sub writehasharray
{
1318 my ($filename, $hash) = @_;
1321 open(FILE
, ">$filename") or die "Unable to write to file $filename";
1323 foreach $key (keys %$hash) {
1324 if ( $hash->{$key} ) {
1326 foreach $i (0 .. $#{$hash->{$key}}) {
1327 print FILE
",$hash->{$key}[$i]";
1336 sub findhasharraykey
{
1337 foreach my $i (1 .. 1000000) {
1338 if ( ! exists $_[0]{$i}) {
1346 my $outstring =$_[0];
1347 $outstring =~ tr/,/ / if not defined $_[1] or $_[1] ne 'y';
1348 $outstring =~ s/&/&/g;
1349 $outstring =~ s/\'/'/g;
1350 $outstring =~ s/\"/"/g;
1351 $outstring =~ s/</</g;
1352 $outstring =~ s/>/>/g;
1356 sub connectionstatus
1358 my %pppsettings = ();
1359 my %netsettings = ();
1362 $pppsettings{'PROFILENAME'} = 'None';
1363 &General
::readhash
("${General::swroot}/ppp/settings", \
%pppsettings);
1364 &General
::readhash
("${General::swroot}/ethernet/settings", \
%netsettings);
1367 if ( ! ( $netsettings{'CONFIG_TYPE'} =~ /^(2|3|6|7)$/ && $netsettings{'RED_TYPE'} =~ /^(DHCP|STATIC)$/ ) ) {
1368 $profileused="- $pppsettings{'PROFILENAME'}";
1371 if ( ( $pppsettings{'METHOD'} eq 'DHCP' && $netsettings{'RED_TYPE'} ne 'PPTP')
1372 || $netsettings{'RED_TYPE'} eq 'DHCP' ) {
1373 if (open(IFACE
, "${General::swroot}/red/iface")) {
1377 $iface =~ /([a-zA-Z0-9]*)/; $iface = $1;
1381 my ($timestr, $connstate);
1382 if ($netsettings{'CONFIG_TYPE'} =~ /^(0|1|4|5)$/ && $pppsettings{'TYPE'} =~ /^isdn/) {
1383 # Count ISDN channels
1384 my ($idmap, $chmap, $drmap, $usage, $flags, $phone);
1388 open (FILE
, "/dev/isdninfo");
1390 $idmap = <FILE
>; chop $idmap;
1391 $chmap = <FILE
>; chop $chmap;
1392 $drmap = <FILE
>; chop $drmap;
1393 $usage = <FILE
>; chop $usage;
1394 $flags = <FILE
>; chop $flags;
1395 $phone = <FILE
>; chop $phone;
1397 $phone =~ s/^phone(\s*):(\s*)//;
1399 @phonenumbers = split / /, $phone;
1401 foreach (@phonenumbers) {
1408 ## Connection status
1412 } elsif ($count == 1) {
1418 if (-e
"${General::swroot}/red/active") {
1419 $timestr = &General
::age
("${General::swroot}/red/active");
1420 $connstate = "<span class='ipcop_StatusBig'>$Lang::tr{'connected'} - $number channel (<span class='ipcop_StatusBigRed'>$timestr</span>) $profileused</span>";
1423 if (-e
"${General::swroot}/red/dial-on-demand") {
1424 $connstate = "<span class='ipcop_StatusBig'>$Lang::tr{'dod waiting'} $profileused</span>";
1426 $connstate = "<span class='ipcop_StatusBig'>$Lang::tr{'idle'} $profileused</span>";
1429 $connstate = "<span class='ipcop_StatusBig'>$Lang::tr{'connecting'} $profileused</span>";
1432 } elsif ($netsettings{'RED_TYPE'} eq "STATIC" || $pppsettings {'METHOD'} eq 'STATIC') {
1433 if (-e
"${General::swroot}/red/active") {
1434 $timestr = &General
::age
("${General::swroot}/red/active");
1435 $connstate = "<span class='ipcop_StatusBig'>$Lang::tr{'connected'} (<span class='ipcop_StatusBigRed'>$timestr</span>) $profileused</span>";
1437 $connstate = "<span class='ipcop_StatusBig'>$Lang::tr{'idle'} $profileused</span>";
1439 } elsif ( ( (-e
"${General::swroot}/dhcpc/dhcpcd-$iface.pid") && $netsettings{'RED_TYPE'} ne 'PPTP' ) ||
1440 !system("/bin/ps -ef | /bin/grep -q '[p]ppd'") || !system("/bin/ps -ef | /bin/grep -q '[c]onnectioncheck'")) {
1441 if (-e
"${General::swroot}/red/active") {
1442 $timestr = &General
::age
("${General::swroot}/red/active");
1443 if ($pppsettings{'TYPE'} =~ /^(modem|bewanadsl|conexantpciadsl|eagleusbadsl)$/) {
1445 if ($pppsettings{'TYPE'} eq 'modem') {
1446 open(CONNECTLOG
, "/var/log/connect.log");
1447 while (<CONNECTLOG
>) {
1449 $speed = (split / /)[6];
1453 } elsif ($pppsettings{'TYPE'} eq 'bewanadsl') {
1454 $speed = `/usr/bin/unicorn_status | /bin/grep Rate | /usr/bin/cut -f2 -d ':'`;
1455 } elsif ($pppsettings{'TYPE'} eq 'conexantpciadsl') {
1456 $speed = `/bin/cat /proc/net/atm/CnxAdsl:* | /bin/grep 'Line Rates' | /bin/sed -e 's+Line Rates: Receive+Rx+' -e 's+Transmit+Tx+'`;
1457 } elsif ($pppsettings{'TYPE'} eq 'eagleusbadsl') {
1458 $speed = `/usr/sbin/eaglestat | /bin/grep Rate`;
1460 $connstate = "<span class='ipcop_StatusBig'>$Lang::tr{'connected'} (<span class='ipcop_StatusBigRed'>$timestr</span>) $profileused (\@$speed)</span>";
1462 $connstate = "<span class='ipcop_StatusBig'>$Lang::tr{'connected'} (<span class='ipcop_StatusBigRed'>$timestr</span>) $profileused</span>";
1465 if (-e
"${General::swroot}/red/dial-on-demand") {
1466 $connstate = "<span class='ipcop_StatusBig'>$Lang::tr{'dod waiting'} $profileused</span>";
1468 $connstate = "<span class='ipcop_StatusBig'>$Lang::tr{'connecting'} $profileused</span>";
1472 $connstate = "<span class='ipcop_StatusBig'>$Lang::tr{'idle'} $profileused</span>";
1478 # Darren Critchley - darrenc@telus.net - (c) 2003
1479 # &srtarray(SortOrder, AlphaNumeric, SortDirection, ArrayToBeSorted)
1480 # This subroutine will take the following parameters:
1481 # ColumnNumber = the column which you want to sort on, starts at 1
1482 # AlphaNumberic = a or n (lowercase) defines whether the sort should be alpha or numberic
1483 # SortDirection = asc or dsc (lowercase) Ascending or Descending sort
1484 # ArrayToBeSorted = the array that wants sorting
1486 # Returns an array that is sorted to your specs
1488 # If SortOrder is greater than the elements in array, then it defaults to the first element
1491 my ($colno, $alpnum, $srtdir, @tobesorted) = @_;
1496 my $ttlitems = scalar @tobesorted; # want to know the number of rows in the passed array
1497 if ($ttlitems < 1){ # if no items, don't waste our time lets leave
1498 return (@tobesorted);
1500 my @tmp = split(/\,/,$tobesorted[0]);
1501 $ttlitems = scalar @tmp; # this should be the number of elements in each row of the passed in array
1503 # Darren Critchley - validate parameters
1504 if ($colno > $ttlitems){$colno = '1';}
1505 $colno--; # remove one from colno to deal with arrays starting at 0
1506 if($colno < 0){$colno = '0';}
1507 if ($alpnum ne '') { $alpnum = lc($alpnum); } else { $alpnum = 'a'; }
1508 if ($srtdir ne '') { $srtdir = lc($srtdir); } else { $srtdir = 'src'; }
1510 foreach $line (@tobesorted)
1514 my @temp = split(/\,/,$line);
1515 # Darren Critchley - juggle the fields so that the one we want to sort on is first
1516 my $tmpholder = $temp[0];
1517 $temp[0] = $temp[$colno];
1518 $temp[$colno] = $tmpholder;
1520 for ($ctr=0; $ctr < $ttlitems ; $ctr++) {
1521 $newline=$newline . $temp[$ctr] . ",";
1524 push(@tmparray,$newline);
1527 if ($alpnum eq 'n') {
1528 @tmparray = sort {$a <=> $b} @tmparray;
1530 @tmparray = (sort @tmparray);
1532 foreach $line (@tmparray)
1536 my @temp = split(/\,/,$line);
1537 my $tmpholder = $temp[0];
1538 $temp[0] = $temp[$colno];
1539 $temp[$colno] = $tmpholder;
1541 for ($ctr=0; $ctr < $ttlitems ; $ctr++){
1542 $newline=$newline . $temp[$ctr] . ",";
1545 push(@srtedarray,$newline);
1549 if ($srtdir eq 'dsc') {
1550 @tmparray = reverse(@srtedarray);
1553 return (@srtedarray);
1557 sub speedtouchversion
1559 if (-f
"/proc/bus/usb/devices")
1561 $speedtouch=`/bin/cat /proc/bus/usb/devices | /bin/grep 'Vendor=06b9 ProdID=4061' | /usr/bin/cut -d ' ' -f6`;
1562 if ($speedtouch eq '') {
1563 $speedtouch= $tr{'connect the modem'};
1566 $speedtouch='USB '.$tr{'not running'};
1571 sub CheckSortOrder
{
1572 #Sorting of allocated leases
1573 if ($ENV{'QUERY_STRING'} =~ /^IPADDR|^ETHER|^HOSTNAME|^ENDTIME/ ) {
1574 my $newsort=$ENV{'QUERY_STRING'};
1575 &readhash
("${swroot}/dhcp/settings", \
%dhcpsettings);
1576 $act=$dhcpsettings{'SORT_LEASELIST'};
1578 if ($act =~ $newsort) {
1579 if ($act !~ 'Rev') {$Rev='Rev'};
1583 $dhcpsettings{'SORT_LEASELIST'}=$newsort;
1584 &writehash
("${swroot}/dhcp/settings", \
%dhcpsettings);
1585 $dhcpsettings{'ACTION'} = 'SORT'; # avoid the next test "First lauch"
1590 sub PrintActualLeases
1592 &openbox
('100%', 'left', $tr{'current dynamic leases'});
1594 <table width='100%'>
1596 <td width='25%' align='center'><a href='$ENV{'SCRIPT_NAME'}?IPADDR'><b>$tr{'ip address'}</b></a></td>
1597 <td width='25%' align='center'><a href='$ENV{'SCRIPT_NAME'}?ETHER'><b>$tr{'mac address'}</b></a></td>
1598 <td width='20%' align='center'><a href='$ENV{'SCRIPT_NAME'}?HOSTNAME'><b>$tr{'hostname'}</b></a></td>
1599 <td width='30%' align='center'><a href='$ENV{'SCRIPT_NAME'}?ENDTIME'><b>$tr{'lease expires'} (local time d/m/y)</b></a></td>
1604 open(LEASES
,"/var/state/dhcp/dhcpd.leases") or die "Can't open dhcpd.leases";
1605 while ($line = <LEASES
>) {
1606 next if( $line =~ /^\s*#/ );
1608 @temp = split (' ', $line);
1610 if ($line =~ /^\s*lease/) {
1612 #All field are not necessarily read. Clear everything
1618 if ($line =~ /^\s*ends/) {
1619 $line =~ /(\d+)\/(\d
+)\
/(\d+) (\d+):(\d+):(\d+)/;
1620 $endtime = timegm
($6, $5, $4, $3, $2 - 1, $1 - 1900);
1623 if ($line =~ /^\s*hardware ethernet/) {
1628 if ($line =~ /^\s*client-hostname/) {
1629 $hostname = "$temp[1] $temp[2] $temp[3]";
1630 $hostname =~ s/;//g;
1631 $hostname =~ s/\"//g;
1635 @record = ('IPADDR',$ip,'ENDTIME',$endtime,'ETHER',$ether,'HOSTNAME',$hostname);
1636 $record = {}; # create a reference to empty hash
1637 %{$record} = @record; # populate that hash with @record
1638 $entries{$record->{'IPADDR'}} = $record; # add this to a hash of hashes
1644 foreach my $key (sort leasesort
keys %entries) {
1646 my $hostname = &cleanhtml
($entries{$key}->{HOSTNAME
},"y");
1649 print "<tr bgcolor='$table1colour'>";
1652 print "<tr bgcolor='$table2colour'>";
1656 <td align='center'>$entries{$key}->{IPADDR}</td>
1657 <td align='center'>$entries{$key}->{ETHER}</td>
1658 <td align='center'> $hostname </td>
1663 ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $dst) = localtime ($entries{$key}->{ENDTIME
});
1664 $enddate = sprintf ("%02d/%02d/%d %02d:%02d:%02d",$mday,$mon+1,$year+1900,$hour,$min,$sec);
1666 if ($entries{$key}->{ENDTIME
} < time() ){
1667 print "<strike>$enddate</strike>";
1680 # This sub is used during display of actives leases
1682 if (rindex ($dhcpsettings{'SORT_LEASELIST'},'Rev') != -1)
1684 $qs=substr ($dhcpsettings{'SORT_LEASELIST'},0,length($dhcpsettings{'SORT_LEASELIST'})-3);
1685 if ($qs eq 'IPADDR') {
1686 @a = split(/\./,$entries{$a}->{$qs});
1687 @b = split(/\./,$entries{$b}->{$qs});
1693 $entries{$b}->{$qs} cmp $entries{$a}->{$qs};
1698 $qs=$dhcpsettings{'SORT_LEASELIST'};
1699 if ($qs eq 'IPADDR') {
1700 @a = split(/\./,$entries{$a}->{$qs});
1701 @b = split(/\./,$entries{$b}->{$qs});
1707 $entries{$a}->{$qs} cmp $entries{$b}->{$qs};
1714 opendir(DIR
, "${swroot}/uplinks/") || return \
@uplinks;
1715 foreach my $dir (readdir(DIR
)) {
1716 next if ($dir =~ /^\./);
1717 next if (-f
"${swroot}/uplinks/$dir");
1718 push(@uplinks, $dir);
1725 my $filename = shift;
1727 open (F
, $filename) || return "";
1734 sub get_red_ifaces_by_type
($) {
1736 my @gottypeiface = ();
1737 my @gottypeuplink = ();
1740 my $ref=get_uplinks
();
1743 foreach my $link (@uplinks) {
1745 &readhash
("${swroot}/uplinks/$link/settings", \
%set);
1747 push(@gottype, $link);
1749 my $iface = $set{'RED_DEV'};
1751 $iface = get_iface
("${swroot}/uplinks/$link/interface");
1755 if ($set{'RED_TYPE'} eq $type) {
1756 push(@gottypeiface, $iface);
1757 push(@gottypeuplink, $link);
1760 return (\
@gottypeiface, \
@gottypeuplink, \
@gottype);
1763 sub get_red_ifaces
() {
1764 return `cat ${swroot}/uplinks/*/interface 2>/dev/null`;
1767 sub get_zone_devices
($) {
1770 open (FILE
, "${swroot}/ethernet/$bridge") || return "";
1771 foreach my $line (<FILE
>) {
1774 push(@ifaces, $line);