]>
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()
20 $|=1; # line buffering
22 $Header::revision
= 'final';
23 $Header::swroot
= '/var/ipfire';
24 $Header::graphdir
='/srv/web/ipfire/html/graphs';
25 $Header::pagecolour
= '#ffffff';
26 #$Header::tablecolour = '#a0a0a0';
27 $Header::tablecolour
= '#FFFFFF';
28 $Header::bigboxcolour
= '#F6F4F4';
29 $Header::boxcolour
= '#EAE9EE';
30 $Header::bordercolour
= '#000000';
31 $Header::table1colour
= '#E0E0E0';
32 $Header::table2colour
= '#F0F0F0';
33 $Header::colourred
= '#993333';
34 $Header::colourorange
= '#FF9933';
35 $Header::colouryellow
= '#FFFF00';
36 $Header::colourgreen
= '#339933';
37 $Header::colourblue
= '#333399';
38 $Header::colourovpn
= '#339999';
39 $Header::colourfw
= '#000000';
40 $Header::colourvpn
= '#990099';
41 $Header::colourerr
= '#FF0000';
42 $Header::viewsize
= 150;
43 $Header::errormessage
= '';
45 my $menu = \
%menuhash;
49 my @URI = split('\?', $ENV{'REQUEST_URI'});
51 ### Make sure this is an SSL request
52 if ($ENV{'SERVER_ADDR'} && $ENV{'HTTPS'} ne 'on') {
53 print "Status: 302 Moved\r\n";
54 print "Location: https://$ENV{'SERVER_ADDR'}:444/$ENV{'PATH_INFO'}\r\n\r\n";
58 ### Initialize environment
59 &General
::readhash
("${swroot}/main/settings", \
%settings);
60 &General
::readhash
("${swroot}/ethernet/settings", \
%ethsettings);
61 &General
::readhash
("${swroot}/ppp/settings", \
%pppsettings);
62 $hostname = $settings{'HOSTNAME'};
65 ### Initialize language
66 require "${swroot}/lang.pl";
67 $language = &Lang
::FindWebLanguage
($settings{"LANGUAGE"});
69 ### Read English Files
70 if ( -d
"/var/ipfire/langs/en/" ) {
71 opendir(DIR
, "/var/ipfire/langs/en/");
72 @names = readdir(DIR
) or die "Cannot Read Directory: $!\n";
73 foreach $name(@names) {
74 next if ($name eq ".");
75 next if ($name eq "..");
76 next if (!($name =~ /\.pl$/));
77 require "${swroot}/langs/en/${name}";
82 ### Enable Language Files
83 if ( -d
"/var/ipfire/langs/${language}/" ) {
84 opendir(DIR
, "/var/ipfire/langs/${language}/");
85 @names = readdir(DIR
) or die "Cannot Read Directory: $!\n";
86 foreach $name(@names) {
87 next if ($name eq ".");
88 next if ($name eq "..");
89 next if (!($name =~ /\.pl$/));
90 require "${swroot}/langs/${language}/${name}";
94 ### Initialize user manual
96 &_read_manualpage_hash
("${General::swroot}/main/manualpages");
98 ### Load selected language and theme functions
99 require "${swroot}/langs/en.pl";
100 require "${swroot}/langs/${language}.pl";
101 eval `/bin/cat /srv/web/ipfire/html/themes/ipfire/include/functions.pl`;
104 if ($ethsettings{'GREEN_DEV'} && $ethsettings{'GREEN_DEV'} ne "") {
112 if ($ethsettings{'CONFIG_TYPE'} =~ /^[24]$/) {
119 if ($ethsettings{'CONFIG_TYPE'} =~ /^[34]$/) {
126 if ($ethsettings{'CONFIG_TYPE'} =~ /^[0]$/) {
135 my %subsystemhash = ();
136 my $subsystem = \
%subsystemhash;
138 my %substatushash = ();
139 my $substatus = \
%substatushash;
141 my %subnetworkhash = ();
142 my $subnetwork = \
%subnetworkhash;
144 my %subserviceshash = ();
145 my $subservices = \
%subserviceshash;
147 my %subfirewallhash = ();
148 my $subfirewall = \
%subfirewallhash;
150 my %subipfirehash = ();
151 my $subipfire = \
%subipfirehash;
153 my %sublogshash = ();
154 my $sublogs = \
%sublogshash;
156 if ( -e
"/var/ipfire/main/gpl_accepted") {
158 eval `/bin/cat /var/ipfire/menu.d/*.menu`;
159 eval `/bin/cat /var/ipfire/menu.d/*.main`;
162 $menu->{'05.firewall'}{'subMenu'}->{'60.wireless'}{'enabled'} = 0;
164 if ( $ethsettings{'CONFIG_TYPE'} =~ /^(1|2|3|4)$/ && $ethsettings{'RED_TYPE'} eq 'STATIC' ) {
165 $menu->{'03.network'}{'subMenu'}->{'70.aliases'}{'enabled'} = 1;
168 if (&General
::RedIsWireless
()) {
169 $menu->{'01.system'}{'subMenu'}->{'21.wlan'}{'enabled'} = 1;
172 if ( $ethsettings{'RED_TYPE'} eq "PPPOE" && $pppsettings{'MONPORT'} ne "" ) {
173 $menu->{'02.status'}{'subMenu'}->{'74.modem-status'}{'enabled'} = 1;
176 # Disable the Dialup/PPPoE menu item when the RED interface is in IP mode
177 # (the "Network" module is loaded by general-functions.pl)
178 if(&Network
::is_red_mode_ip
()) {
179 $menu->{'01.system'}{'subMenu'}->{'20.dialup'}{'enabled'} = 0;
182 # Disbale unusable things in cloud environments
183 if (&General
::running_in_cloud
()) {
184 $menu->{'03.network'}{'subMenu'}->{'30.dhcp'}{'enabled'} = 0;
185 $menu->{'03.network'}{'subMenu'}->{'80.macadressmenu'}{'enabled'} = 0;
186 $menu->{'03.network'}{'subMenu'}->{'90.wakeonlan'}{'enabled'} = 0;
193 print "Cache-control: private\n";
194 print "Content-type: text/html; charset=UTF-8\n\n";
197 sub is_menu_visible
($) {
200 return (-e
$ENV{'DOCUMENT_ROOT'}."/../$link");
206 if (! $root->{'enabled'}) {
209 if ($root->{'uri'} !~ /^$/) {
211 if ($root->{'vars'} !~ /^$/) {
212 $vars = '?'. $root->{'vars'};
214 if (! is_menu_visible
($root->{'uri'})) {
217 return $root->{'uri'}.$vars;
219 my $submenus = $root->{'subMenu'};
223 foreach my $item (sort keys %$submenus) {
224 my $link = getlink
($submenus->{$item});
236 my $uri = $conf->{'uri'};
237 my $vars = $conf->{'vars'};
238 my $novars = $conf->{'novars'};
243 if ($uri ne $URI[0]) {
247 if ($URI[1] !~ /^$/) {
254 return ($URI[1] eq $vars);
264 foreach my $item (sort keys %$root) {
265 my $val = $root->{$item};
266 if (compare_url
($val)) {
267 $val->{'selected'} = 1;
268 if ($val->{'title'} !~ /^$/) {
269 return $val->{'title'};
271 return 'EMPTY TITLE';
274 my $title = gettitle
($val->{'subMenu'});
276 $val->{'selected'} = 1;
284 my ($hash, $params) = @_;
285 my $cgi = CGI
->new ();
286 $hash->{'__CGI__'} = $cgi;
287 return if ($ENV{'REQUEST_METHOD'} ne 'POST');
288 if (!$params->{'wantfile'}) {
289 $CGI::DISABLE_UPLOADS
= 1;
290 $CGI::POST_MAX
= 1024 * 1024;
292 $CGI::POST_MAX
= 10 * 1024 * 1024;
295 $cgi->referer() =~ m/^https?\:\/\
/([^\/]+)/;
297 $cgi->url() =~ m/^https?\:\/\
/([^\/]+)/;
299 return if ($referer ne $servername);
301 ### Modified for getting multi-vars, split by |
302 %temp = $cgi->Vars();
303 foreach my $key (keys %temp) {
304 $hash->{$key} = $temp{$key};
305 $hash->{$key} =~ s/\0/|/g;
306 $hash->{$key} =~ s/^\s*(.*?)\s*$/$1/;
309 if (($params->{'wantfile'})&&($params->{'filevar'})) {
310 $hash->{$params->{'filevar'}} = $cgi->upload
311 ($params->{'filevar'});
318 return HTML
::Entities
::encode_entities
($s);
322 my $outstring =$_[0];
323 $outstring =~ tr/,/ / if not defined $_[1] or $_[1] ne 'y';
325 return escape
($outstring);
330 my %pppsettings = ();
331 my %netsettings = ();
334 $pppsettings{'PROFILENAME'} = 'None';
335 &General
::readhash
("${General::swroot}/ppp/settings", \
%pppsettings);
336 &General
::readhash
("${General::swroot}/ethernet/settings", \
%netsettings);
339 unless ( $netsettings{'RED_TYPE'} =~ /^(DHCP|STATIC)$/ ) {
340 $profileused="- $pppsettings{'PROFILENAME'}";
343 my ($timestr, $connstate);
345 my $connstate = "<span>$Lang::tr{'idle'} $profileused</span>";
347 if (-e
"${General::swroot}/red/active") {
348 $timestr = &General
::age
("${General::swroot}/red/active");
349 $connstate = "<span>$Lang::tr{'connected'} - (<span>$timestr</span>) $profileused</span>";
351 if ((open(KEEPCONNECTED
, "</var/ipfire/red/keepconnected") == false
) && ($pppsettings{'RECONNECTION'} eq "persistent")) {
352 $connstate = "<span>$Lang::tr{'connection closed'} $profileused</span>";
353 } elsif (($pppsettings{'RECONNECTION'} eq "dialondemand") && ( -e
"${General::swroot}/red/dial-on-demand")) {
354 $connstate = "<span>$Lang::tr{'dod waiting'} $profileused</span>";
356 $connstate = "<span>$Lang::tr{'connecting'} $profileused</span>" if (system("ps -ef | grep -q '[p]ppd'"));
364 #Sorting of allocated leases
365 if ($ENV{'QUERY_STRING'} =~ /^IPADDR|^ETHER|^HOSTNAME|^ENDTIME/ ) {
366 my $newsort=$ENV{'QUERY_STRING'};
367 &General
::readhash
("${swroot}/dhcp/settings", \
%dhcpsettings);
368 $act=$dhcpsettings{'SORT_LEASELIST'};
370 if ($act =~ $newsort) {
371 if ($act !~ 'Rev') {$Rev='Rev'};
375 $dhcpsettings{'SORT_LEASELIST'}=$newsort;
376 &General
::writehash
("${swroot}/dhcp/settings", \
%dhcpsettings);
377 $dhcpsettings{'ACTION'} = 'SORT'; # avoid the next test "First lauch"
382 sub PrintActualLeases
384 &openbox
('100%', 'left', $Lang::tr
{'current dynamic leases'});
386 <table width='100%' class='tbl'>
388 <th width='25%' align='center'><a href='$ENV{'SCRIPT_NAME'}?IPADDR'><b>$Lang::tr{'ip address'}</b></a></th>
389 <th width='25%' align='center'><a href='$ENV{'SCRIPT_NAME'}?ETHER'><b>$Lang::tr{'mac address'}</b></a></th>
390 <th width='20%' align='center'><a href='$ENV{'SCRIPT_NAME'}?HOSTNAME'><b>$Lang::tr{'hostname'}</b></a></th>
391 <th width='25%' align='center'><a href='$ENV{'SCRIPT_NAME'}?ENDTIME'><b>$Lang::tr{'lease expires'} (local time d/m/y)</b></a></th>
392 <th width='5%' align='center'><b>$Lang::tr{'dhcp make fixed lease'}</b></th>
397 open(LEASES
,"/var/state/dhcp/dhcpd.leases") or die "Can't open dhcpd.leases";
398 while (my $line = <LEASES
>) {
399 next if( $line =~ /^\s*#/ );
401 @temp = split (' ', $line);
403 if ($line =~ /^\s*lease/) {
405 #All field are not necessarily read. Clear everything
413 if ($line =~ /^\s*ends/) {
414 $line =~ /(\d+)\/(\d
+)\
/(\d+) (\d+):(\d+):(\d+)/;
415 $endtime = timegm
($6, $5, $4, $3, $2 - 1, $1 - 1900);
416 ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $dst) = localtime($endtime);
417 $endtime_print = sprintf ("%02d/%02d/%d %02d:%02d:%02d",$mday,$mon+1,$year+1900,$hour,$min,$sec);
418 $expired = $endtime < time();
421 if ($line =~ /^\s*hardware ethernet/) {
426 if ($line =~ /^\s*client-hostname/) {
427 $hostname = "$temp[1] $temp[2] $temp[3]";
428 $hostname =~ s/\"|[;\s]+?$//g; # remove quotes, trim semicolon and white space
432 @record = ('IPADDR',$ip,'ENDTIME',$endtime,'ETHER',$ether,'HOSTNAME',$hostname,'endtime_print',$endtime_print,'expired',$expired);
433 $record = {}; # create a reference to empty hash
434 %{$record} = @record; # populate that hash with @record
435 $entries{$record->{'IPADDR'}} = $record; # add this to a hash of hashes
442 my $divider_printed = 0;
443 foreach my $key (sort leasesort
keys %entries) {
444 my $hostname = &cleanhtml
($entries{$key}->{HOSTNAME
},"y");
445 my $hostname_print = $hostname;
446 if($hostname_print eq "") { #print blank space if no hostname is found
447 $hostname_print = " ";
450 # separate active and expired leases with a horizontal line
451 if(($entries{$key}->{expired
}) && ($divider_printed == 0)) {
452 $divider_printed = 1;
454 print "<tr><td colspan='5' bgcolor='$table1colour'><hr size='1'></td></tr>\n";
456 print "<tr><td colspan='5' bgcolor='$table2colour'><hr size='1'></td></tr>\n";
461 print "<form method='post' action='/cgi-bin/dhcp.cgi'><tr>\n";
463 $col="bgcolor='$table1colour'";
465 $col="bgcolor='$table2colour'";
468 if($entries{$key}->{expired
}) {
470 <td align='center' $col><input type='hidden' name='FIX_ADDR' value='$entries{$key}->{IPADDR}' /><strike><i>$entries{$key}->{IPADDR}</i></strike></td>
471 <td align='center' $col><input type='hidden' name='FIX_MAC' value='$entries{$key}->{ETHER}' /><strike><i>$entries{$key}->{ETHER}</i></strike></td>
472 <td align='center' $col><input type='hidden' name='FIX_REMARK' value='$hostname' /><strike><i>$hostname_print<i><strike></td>
473 <td align='center' $col><input type='hidden' name='FIX_ENABLED' value='on' /><strike><i>$entries{$key}->{endtime_print}</i></strike></td>
478 <td align='center' $col><input type='hidden' name='FIX_ADDR' value='$entries{$key}->{IPADDR}' />$entries{$key}->{IPADDR}</td>
479 <td align='center' $col><input type='hidden' name='FIX_MAC' value='$entries{$key}->{ETHER}' />$entries{$key}->{ETHER}</td>
480 <td align='center' $col><input type='hidden' name='FIX_REMARK' value='$hostname' />$hostname_print</td>
481 <td align='center' $col><input type='hidden' name='FIX_ENABLED' value='on' />$entries{$key}->{endtime_print}</td>
487 <td $col><input type='hidden' name='ACTION' value='$Lang::tr{'add'}2' /><input type='submit' name='SUBMIT' value='$Lang::tr{'add'}' /></td>
499 # This sub is used during display of actives leases
501 if (rindex ($dhcpsettings{'SORT_LEASELIST'},'Rev') != -1)
503 $qs=substr ($dhcpsettings{'SORT_LEASELIST'},0,length($dhcpsettings{'SORT_LEASELIST'})-3);
504 if ($qs eq 'IPADDR') {
505 @a = split(/\./,$entries{$a}->{$qs});
506 @b = split(/\./,$entries{$b}->{$qs});
507 $entries{$a}->{'expired'} <=> $entries{$b}->{'expired'} || # always sort by expiration first
513 $entries{$a}->{'expired'} <=> $entries{$b}->{'expired'} ||
514 $entries{$b}->{$qs} cmp $entries{$a}->{$qs};
519 $qs=$dhcpsettings{'SORT_LEASELIST'};
520 if ($qs eq 'IPADDR') {
521 @a = split(/\./,$entries{$a}->{$qs});
522 @b = split(/\./,$entries{$b}->{$qs});
523 $entries{$a}->{'expired'} <=> $entries{$b}->{'expired'} ||
529 $entries{$a}->{'expired'} <=> $entries{$b}->{'expired'} ||
530 $entries{$a}->{$qs} cmp $entries{$b}->{$qs};
537 my @array = split(/\//,$string);
538 my $string2 = $array[0];
540 if ( $string eq "*" or $string eq "" ){
542 } elsif ( $string =~ "ipsec" ){
543 return "<font color='".${Header
::colourvpn
}."'>".$string."</font>";
544 } elsif ( $string =~ "tun" ){
545 return "<font color='".${Header
::colourovpn
}."'>".$string."</font>";
546 } elsif ( $string =~ "lo" or $string =~ "127.0.0.0" ){
547 return "<font color='".${Header
::colourfw
}."'>".$string."</font>";
548 } elsif ( $string =~ $ethsettings{'GREEN_DEV'} or &General
::IpInSubnet
($string2,$ethsettings{'GREEN_NETADDRESS'},$ethsettings{'GREEN_NETMASK'}) ){
549 return "<font color='".${Header
::colourgreen
}."'>".$string."</font>";
550 } elsif ( $string =~ "ppp0" or $string =~ $ethsettings{'RED_DEV'} or $string =~ "0.0.0.0" or $string =~ $ethsettings{'RED_ADDRESS'} ){
551 return "<font color='".${Header
::colourred
}."'>".$string."</font>";
552 } elsif ( $ethsettings{'CONFIG_TYPE'}>1 and ( $string =~ $ethsettings{'BLUE_DEV'} or &General
::IpInSubnet
($string2,$ethsettings{'BLUE_NETADDRESS'},$ethsettings{'BLUE_NETMASK'}) )){
553 return "<font color='".${Header
::colourblue
}."'>".$string."</font>";
554 } elsif ( $ethsettings{'CONFIG_TYPE'}>2 and ( $string =~ $ethsettings{'ORANGE_DEV'} or &General
::IpInSubnet
($string2,$ethsettings{'ORANGE_NETADDRESS'},$ethsettings{'ORANGE_NETMASK'}) )){
555 return "<font color='".${Header
::colourorange
}."'>".$string."</font>";
561 # Get user manual URL for a configuration page inside the "/cgi-bin/"
562 # (reads current page from the environment variables unless defined)
563 # Returns empty if no URL is available
564 sub get_manualpage_url
() {
566 $cgifile //= substr($ENV{'SCRIPT_NAME'}, 9); # remove fixed "/cgi-bin/" path
568 # Ensure base url is configured
569 return unless($manualpages{'BASE_URL'});
572 if($cgifile && defined($manualpages{$cgifile})) {
573 return "$manualpages{'BASE_URL'}/$manualpages{$cgifile}";
576 # No manual page configured, return nothing
580 # Private function to load a hash of configured user manual pages from file
581 # (run check_manualpages.pl to make sure the file is correct)
582 sub _read_manualpage_hash
() {
585 open(my $file, "<", $filename) or return; # Fail silent
586 while(my $line = <$file>) {
588 next if(substr($line, 0, 1) eq '#'); # Skip comments
589 next if(index($line, '=', 1) == -1); # Skip incomplete lines
591 my($left, $value) = split(/=/, $line, 2);
592 if($left =~ /^([[:alnum:]\/._
-]+)$/) {
594 $manualpages{$key} = $value;
600 1; # End of package "Header"