]>
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()
21 &General
::readhash
("/srv/web/ipfire/html/themes/ipfire/include/colors.txt", \
%color);
23 $|=1; # line buffering
25 $Header::revision
= 'final';
26 $Header::swroot
= '/var/ipfire';
27 $Header::graphdir
='/srv/web/ipfire/html/graphs';
28 $Header::pagecolour
= '#ffffff';
29 $Header::bordercolour
= '#363636';
30 $Header::table1colour
= '#f5f5f5';
31 $Header::table2colour
= '#fafafa';
32 $Header::colourred
= '#993333';
33 $Header::colourorange
= '#FF9933';
34 $Header::colouryellow
= '#FFFF00';
35 $Header::colourgreen
= '#339933';
36 $Header::colourblue
= '#333399';
37 $Header::colourovpn
= '#339999';
38 $Header::colourfw
= '#000000';
39 $Header::colourvpn
= '#990099';
40 $Header::colourerr
= '#FF0000';
41 $Header::viewsize
= 150;
42 $Header::errormessage
= '';
43 $Header::extraHead
= <<END
46 background-color: $color{'color20'};
49 background-color: $color{'color22'};
52 background-color: $Header::colouryellow;
55 background-color: orange;
58 background-color: red;
61 background-color: $Header::table1colour;
64 background-color: $Header::table2colour;
69 border-color: #a0a0a0;
74 background-color: #a0a0a0;
77 border-color: #e2e2e2;
80 background-color: #e2e2e2;
83 border-color: #e2e2e2;
89 my $menu = \
%menuhash;
93 my @URI = split('\?', $ENV{'REQUEST_URI'});
95 ### Make sure this is an SSL request
96 if ($ENV{'SERVER_ADDR'} && $ENV{'HTTPS'} ne 'on') {
97 print "Status: 302 Moved\r\n";
98 print "Location: https://$ENV{'SERVER_ADDR'}:444/$ENV{'PATH_INFO'}\r\n\r\n";
102 ### Initialize environment
103 &General
::readhash
("${swroot}/main/settings", \
%settings);
104 &General
::readhash
("${swroot}/ethernet/settings", \
%ethsettings);
105 &General
::readhash
("${swroot}/ppp/settings", \
%pppsettings);
106 $hostname = $settings{'HOSTNAME'};
107 $hostnameintitle = 0;
109 ### Initialize language
110 require "${swroot}/lang.pl";
111 $language = &Lang
::FindWebLanguage
($settings{"LANGUAGE"});
113 ### Read English Files
114 if ( -d
"/var/ipfire/langs/en/" ) {
115 opendir(DIR
, "/var/ipfire/langs/en/");
116 @names = readdir(DIR
) or die "Cannot Read Directory: $!\n";
117 foreach $name(@names) {
118 next if ($name eq ".");
119 next if ($name eq "..");
120 next if (!($name =~ /\.pl$/));
121 require "${swroot}/langs/en/${name}";
126 ### Enable Language Files
127 if ( -d
"/var/ipfire/langs/${language}/" ) {
128 opendir(DIR
, "/var/ipfire/langs/${language}/");
129 @names = readdir(DIR
) or die "Cannot Read Directory: $!\n";
130 foreach $name(@names) {
131 next if ($name eq ".");
132 next if ($name eq "..");
133 next if (!($name =~ /\.pl$/));
134 require "${swroot}/langs/${language}/${name}";
138 ### Initialize user manual
139 my %manualpages = ();
140 &_read_manualpage_hash
("${General::swroot}/main/manualpages");
142 ### Load selected language and theme functions
143 require "${swroot}/langs/en.pl";
144 require "${swroot}/langs/${language}.pl";
145 eval `/bin/cat /srv/web/ipfire/html/themes/ipfire/include/functions.pl`;
148 if ($ethsettings{'GREEN_DEV'} && $ethsettings{'GREEN_DEV'} ne "") {
156 if ($ethsettings{'CONFIG_TYPE'} =~ /^[24]$/) {
163 if ($ethsettings{'CONFIG_TYPE'} =~ /^[34]$/) {
170 if ($ethsettings{'CONFIG_TYPE'} =~ /^[0]$/) {
179 my %subsystemhash = ();
180 my $subsystem = \
%subsystemhash;
182 my %substatushash = ();
183 my $substatus = \
%substatushash;
185 my %subnetworkhash = ();
186 my $subnetwork = \
%subnetworkhash;
188 my %subserviceshash = ();
189 my $subservices = \
%subserviceshash;
191 my %subfirewallhash = ();
192 my $subfirewall = \
%subfirewallhash;
194 my %subipfirehash = ();
195 my $subipfire = \
%subipfirehash;
197 my %sublogshash = ();
198 my $sublogs = \
%sublogshash;
200 if ( -e
"/var/ipfire/main/gpl_accepted") {
202 eval `/bin/cat /var/ipfire/menu.d/*.menu`;
203 eval `/bin/cat /var/ipfire/menu.d/*.main`;
206 $menu->{'05.firewall'}{'subMenu'}->{'60.wireless'}{'enabled'} = 0;
208 if ( $ethsettings{'CONFIG_TYPE'} =~ /^(1|2|3|4)$/ && $ethsettings{'RED_TYPE'} eq 'STATIC' ) {
209 $menu->{'03.network'}{'subMenu'}->{'70.aliases'}{'enabled'} = 1;
212 if (&General
::RedIsWireless
()) {
213 $menu->{'01.system'}{'subMenu'}->{'21.wlan'}{'enabled'} = 1;
216 if ( $ethsettings{'RED_TYPE'} eq "PPPOE" && $pppsettings{'MONPORT'} ne "" ) {
217 $menu->{'02.status'}{'subMenu'}->{'74.modem-status'}{'enabled'} = 1;
220 # Disable the Dialup/PPPoE menu item when the RED interface is in IP mode
221 # (the "Network" module is loaded by general-functions.pl)
222 if(&Network
::is_red_mode_ip
()) {
223 $menu->{'01.system'}{'subMenu'}->{'20.dialup'}{'enabled'} = 0;
226 # Disbale unusable things in cloud environments
227 if (&General
::running_in_cloud
()) {
228 $menu->{'03.network'}{'subMenu'}->{'30.dhcp'}{'enabled'} = 0;
229 $menu->{'03.network'}{'subMenu'}->{'80.macadressmenu'}{'enabled'} = 0;
230 $menu->{'03.network'}{'subMenu'}->{'90.wakeonlan'}{'enabled'} = 0;
237 print "Cache-control: private\n";
238 print "Content-type: text/html; charset=UTF-8\n\n";
241 sub is_menu_visible
($) {
244 return (-e
$ENV{'DOCUMENT_ROOT'}."/../$link");
250 if (! $root->{'enabled'}) {
253 if ($root->{'uri'} !~ /^$/) {
255 if ($root->{'vars'} !~ /^$/) {
256 $vars = '?'. $root->{'vars'};
258 if (! is_menu_visible
($root->{'uri'})) {
261 return $root->{'uri'}.$vars;
263 my $submenus = $root->{'subMenu'};
267 foreach my $item (sort keys %$submenus) {
268 my $link = getlink
($submenus->{$item});
280 my $uri = $conf->{'uri'};
281 my $vars = $conf->{'vars'};
282 my $novars = $conf->{'novars'};
287 if ($uri ne $URI[0]) {
291 if ($URI[1] !~ /^$/) {
298 return ($URI[1] eq $vars);
308 foreach my $item (sort keys %$root) {
309 my $val = $root->{$item};
310 if (compare_url
($val)) {
311 $val->{'selected'} = 1;
312 if ($val->{'title'} !~ /^$/) {
313 return $val->{'title'};
315 return 'EMPTY TITLE';
318 my $title = gettitle
($val->{'subMenu'});
320 $val->{'selected'} = 1;
328 my ($hash, $params) = @_;
329 my $cgi = CGI
->new ();
330 $hash->{'__CGI__'} = $cgi;
331 return if ($ENV{'REQUEST_METHOD'} ne 'POST');
332 if (!$params->{'wantfile'}) {
333 $CGI::DISABLE_UPLOADS
= 1;
334 $CGI::POST_MAX
= 1024 * 1024;
336 $CGI::POST_MAX
= 10 * 1024 * 1024;
339 $cgi->referer() =~ m/^https?\:\/\
/([^\/]+)/;
341 $cgi->url() =~ m/^https?\:\/\
/([^\/]+)/;
343 return if ($referer ne $servername);
345 ### Modified for getting multi-vars, split by |
346 %temp = $cgi->Vars();
347 foreach my $key (keys %temp) {
348 $hash->{$key} = $temp{$key};
349 $hash->{$key} =~ s/\0/|/g;
350 $hash->{$key} =~ s/^\s*(.*?)\s*$/$1/;
353 if (($params->{'wantfile'})&&($params->{'filevar'})) {
354 $hash->{$params->{'filevar'}} = $cgi->upload
355 ($params->{'filevar'});
362 return HTML
::Entities
::encode_entities
($s);
366 my $outstring =$_[0];
367 $outstring =~ tr/,/ / if not defined $_[1] or $_[1] ne 'y';
369 return escape
($outstring);
374 my %pppsettings = ();
375 my %netsettings = ();
378 $pppsettings{'PROFILENAME'} = 'None';
379 &General
::readhash
("${General::swroot}/ppp/settings", \
%pppsettings);
380 &General
::readhash
("${General::swroot}/ethernet/settings", \
%netsettings);
383 unless ( $netsettings{'RED_TYPE'} =~ /^(DHCP|STATIC)$/ ) {
384 $profileused="- $pppsettings{'PROFILENAME'}";
387 my ($timestr, $connstate);
389 my $connstate = "<span>$Lang::tr{'idle'} $profileused</span>";
391 if (-e
"${General::swroot}/red/active") {
392 $timestr = &General
::age
("${General::swroot}/red/active");
393 $connstate = "<span>$Lang::tr{'connected'} - (<span>$timestr</span>) $profileused</span>";
395 if ((open(KEEPCONNECTED
, "</var/ipfire/red/keepconnected") == false
) && ($pppsettings{'RECONNECTION'} eq "persistent")) {
396 $connstate = "<span>$Lang::tr{'connection closed'} $profileused</span>";
397 } elsif (($pppsettings{'RECONNECTION'} eq "dialondemand") && ( -e
"${General::swroot}/red/dial-on-demand")) {
398 $connstate = "<span>$Lang::tr{'dod waiting'} $profileused</span>";
400 $connstate = "<span>$Lang::tr{'connecting'} $profileused</span>" if (system("ps -ef | grep -q '[p]ppd'"));
408 #Sorting of allocated leases
409 if ($ENV{'QUERY_STRING'} =~ /^IPADDR|^ETHER|^HOSTNAME|^ENDTIME/ ) {
410 my $newsort=$ENV{'QUERY_STRING'};
411 &General
::readhash
("${swroot}/dhcp/settings", \
%dhcpsettings);
412 $act=$dhcpsettings{'SORT_LEASELIST'};
414 if ($act =~ $newsort) {
415 if ($act !~ 'Rev') {$Rev='Rev'};
419 $dhcpsettings{'SORT_LEASELIST'}=$newsort;
420 &General
::writehash
("${swroot}/dhcp/settings", \
%dhcpsettings);
421 $dhcpsettings{'ACTION'} = 'SORT'; # avoid the next test "First lauch"
426 sub PrintActualLeases
428 &openbox
('100%', 'left', $Lang::tr
{'current dynamic leases'});
430 <table width='100%' class='tbl'>
432 <th width='25%' align='center'><a href='$ENV{'SCRIPT_NAME'}?IPADDR'><b>$Lang::tr{'ip address'}</b></a></th>
433 <th width='25%' align='center'><a href='$ENV{'SCRIPT_NAME'}?ETHER'><b>$Lang::tr{'mac address'}</b></a></th>
434 <th width='20%' align='center'><a href='$ENV{'SCRIPT_NAME'}?HOSTNAME'><b>$Lang::tr{'hostname'}</b></a></th>
435 <th width='25%' align='center'><a href='$ENV{'SCRIPT_NAME'}?ENDTIME'><b>$Lang::tr{'lease expires'} (local time d/m/y)</b></a></th>
436 <th width='5%' align='center'><b>$Lang::tr{'dhcp make fixed lease'}</b></th>
441 open(LEASES
,"/var/state/dhcp/dhcpd.leases") or die "Can't open dhcpd.leases";
442 while (my $line = <LEASES
>) {
443 next if( $line =~ /^\s*#/ );
445 @temp = split (' ', $line);
447 if ($line =~ /^\s*lease/) {
449 #All field are not necessarily read. Clear everything
457 if ($line =~ /^\s*ends/) {
458 $line =~ /(\d+)\/(\d
+)\
/(\d+) (\d+):(\d+):(\d+)/;
459 $endtime = timegm
($6, $5, $4, $3, $2 - 1, $1 - 1900);
460 ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $dst) = localtime($endtime);
461 $endtime_print = sprintf ("%02d/%02d/%d %02d:%02d:%02d",$mday,$mon+1,$year+1900,$hour,$min,$sec);
462 $expired = $endtime < time();
465 if ($line =~ /^\s*hardware ethernet/) {
470 if ($line =~ /^\s*client-hostname/) {
471 $hostname = "$temp[1] $temp[2] $temp[3]";
472 $hostname =~ s/\"|[;\s]+?$//g; # remove quotes, trim semicolon and white space
476 @record = ('IPADDR',$ip,'ENDTIME',$endtime,'ETHER',$ether,'HOSTNAME',$hostname,'endtime_print',$endtime_print,'expired',$expired);
477 $record = {}; # create a reference to empty hash
478 %{$record} = @record; # populate that hash with @record
479 $entries{$record->{'IPADDR'}} = $record; # add this to a hash of hashes
486 my $divider_printed = 0;
487 foreach my $key (sort leasesort
keys %entries) {
488 my $hostname = &cleanhtml
($entries{$key}->{HOSTNAME
},"y");
489 my $hostname_print = $hostname;
490 if($hostname_print eq "") { #print blank space if no hostname is found
491 $hostname_print = " ";
494 # separate active and expired leases with a horizontal line
495 if(($entries{$key}->{expired
}) && ($divider_printed == 0)) {
496 $divider_printed = 1;
498 print "<tr><td colspan='5' bgcolor='$table1colour'><hr size='1'></td></tr>\n";
500 print "<tr><td colspan='5' bgcolor='$table2colour'><hr size='1'></td></tr>\n";
505 print "<form method='post' action='/cgi-bin/dhcp.cgi'><tr>\n";
507 $col="bgcolor='$table1colour'";
509 $col="bgcolor='$table2colour'";
512 if($entries{$key}->{expired
}) {
514 <td align='center' $col><input type='hidden' name='FIX_ADDR' value='$entries{$key}->{IPADDR}' /><strike><i>$entries{$key}->{IPADDR}</i></strike></td>
515 <td align='center' $col><input type='hidden' name='FIX_MAC' value='$entries{$key}->{ETHER}' /><strike><i>$entries{$key}->{ETHER}</i></strike></td>
516 <td align='center' $col><input type='hidden' name='FIX_REMARK' value='$hostname' /><strike><i>$hostname_print<i><strike></td>
517 <td align='center' $col><input type='hidden' name='FIX_ENABLED' value='on' /><strike><i>$entries{$key}->{endtime_print}</i></strike></td>
522 <td align='center' $col><input type='hidden' name='FIX_ADDR' value='$entries{$key}->{IPADDR}' />$entries{$key}->{IPADDR}</td>
523 <td align='center' $col><input type='hidden' name='FIX_MAC' value='$entries{$key}->{ETHER}' />$entries{$key}->{ETHER}</td>
524 <td align='center' $col><input type='hidden' name='FIX_REMARK' value='$hostname' />$hostname_print</td>
525 <td align='center' $col><input type='hidden' name='FIX_ENABLED' value='on' />$entries{$key}->{endtime_print}</td>
531 <td $col><input type='hidden' name='ACTION' value='$Lang::tr{'add'}2' /><input type='submit' name='SUBMIT' value='$Lang::tr{'add'}' /></td>
543 # This sub is used during display of actives leases
545 if (rindex ($dhcpsettings{'SORT_LEASELIST'},'Rev') != -1)
547 $qs=substr ($dhcpsettings{'SORT_LEASELIST'},0,length($dhcpsettings{'SORT_LEASELIST'})-3);
548 if ($qs eq 'IPADDR') {
549 @a = split(/\./,$entries{$a}->{$qs});
550 @b = split(/\./,$entries{$b}->{$qs});
551 $entries{$a}->{'expired'} <=> $entries{$b}->{'expired'} || # always sort by expiration first
557 $entries{$a}->{'expired'} <=> $entries{$b}->{'expired'} ||
558 $entries{$b}->{$qs} cmp $entries{$a}->{$qs};
563 $qs=$dhcpsettings{'SORT_LEASELIST'};
564 if ($qs eq 'IPADDR') {
565 @a = split(/\./,$entries{$a}->{$qs});
566 @b = split(/\./,$entries{$b}->{$qs});
567 $entries{$a}->{'expired'} <=> $entries{$b}->{'expired'} ||
573 $entries{$a}->{'expired'} <=> $entries{$b}->{'expired'} ||
574 $entries{$a}->{$qs} cmp $entries{$b}->{$qs};
581 my @array = split(/\//,$string);
582 my $string2 = $array[0];
584 if ( $string eq "*" or $string eq "" ){
586 } elsif ( $string =~ "ipsec" ){
587 return "<font color='".${Header
::colourvpn
}."'>".$string."</font>";
588 } elsif ( $string =~ "tun" ){
589 return "<font color='".${Header
::colourovpn
}."'>".$string."</font>";
590 } elsif ( $string =~ "lo" or $string =~ "127.0.0.0" ){
591 return "<font color='".${Header
::colourfw
}."'>".$string."</font>";
592 } elsif ( $string =~ $ethsettings{'GREEN_DEV'} or &General
::IpInSubnet
($string2,$ethsettings{'GREEN_NETADDRESS'},$ethsettings{'GREEN_NETMASK'}) ){
593 return "<font color='".${Header
::colourgreen
}."'>".$string."</font>";
594 } elsif ( $string =~ "ppp0" or $string =~ $ethsettings{'RED_DEV'} or $string =~ "0.0.0.0" or $string =~ $ethsettings{'RED_ADDRESS'} ){
595 return "<font color='".${Header
::colourred
}."'>".$string."</font>";
596 } elsif ( $ethsettings{'CONFIG_TYPE'}>1 and ( $string =~ $ethsettings{'BLUE_DEV'} or &General
::IpInSubnet
($string2,$ethsettings{'BLUE_NETADDRESS'},$ethsettings{'BLUE_NETMASK'}) )){
597 return "<font color='".${Header
::colourblue
}."'>".$string."</font>";
598 } elsif ( $ethsettings{'CONFIG_TYPE'}>2 and ( $string =~ $ethsettings{'ORANGE_DEV'} or &General
::IpInSubnet
($string2,$ethsettings{'ORANGE_NETADDRESS'},$ethsettings{'ORANGE_NETMASK'}) )){
599 return "<font color='".${Header
::colourorange
}."'>".$string."</font>";
605 # Get user manual URL for a configuration page inside the "/cgi-bin/"
606 # (reads current page from the environment variables unless defined)
607 # Returns empty if no URL is available
608 sub get_manualpage_url
() {
610 $cgifile //= substr($ENV{'SCRIPT_NAME'}, 9); # remove fixed "/cgi-bin/" path
612 # Ensure base url is configured
613 return unless($manualpages{'BASE_URL'});
616 if($cgifile && defined($manualpages{$cgifile})) {
617 return "$manualpages{'BASE_URL'}/$manualpages{$cgifile}";
620 # No manual page configured, return nothing
624 # Private function to load a hash of configured user manual pages from file
625 # (run check_manualpages.pl to make sure the file is correct)
626 sub _read_manualpage_hash
() {
629 open(my $file, "<", $filename) or return; # Fail silent
630 while(my $line = <$file>) {
632 next if(substr($line, 0, 1) eq '#'); # Skip comments
633 next if(index($line, '=', 1) == -1); # Skip incomplete lines
635 my($left, $value) = split(/=/, $line, 2);
636 if($left =~ /^([[:alnum:]\/._
-]+)$/) {
638 $manualpages{$key} = $value;
644 1; # End of package "Header"