]>
git.ipfire.org Git - people/pmueller/ipfire-2.x.git/blob - config/cfgroot/header.pl
3 # This code is distributed under the terms of the GPL
5 # (c) The SmoothWall Team
6 # Copyright (C) 2002 Alex Hudson - getcgihash() rewrite
7 # Copyright (C) 2002 Bob Grant <bob@cache.ucr.edu> - validmac()
8 # Copyright (c) 2002/04/13 Steve Bootes - add alias section, helper functions
9 # Copyright (c) 2002/08/23 Mark Wormgoor <mark@wormgoor.com> validfqdn()
10 # Copyright (c) 2003/09/11 Darren Critchley <darrenc@telus.net> srtarray()
18 $|=1; # line buffering
20 $Header::revision
= 'final';
21 $Header::swroot
= '/var/ipfire';
22 $Header::graphdir
='/srv/web/ipfire/html/graphs';
23 $Header::pagecolour
= '#ffffff';
24 #$Header::tablecolour = '#a0a0a0';
25 $Header::tablecolour
= '#FFFFFF';
26 $Header::bigboxcolour
= '#F6F4F4';
27 $Header::boxcolour
= '#EAE9EE';
28 $Header::bordercolour
= '#000000';
29 $Header::table1colour
= '#E0E0E0';
30 $Header::table2colour
= '#F0F0F0';
31 $Header::colourred
= '#993333';
32 $Header::colourorange
= '#FF9933';
33 $Header::colouryellow
= '#FFFF00';
34 $Header::colourgreen
= '#339933';
35 $Header::colourblue
= '#333399';
36 $Header::colourovpn
= '#339999';
37 $Header::colourfw
= '#000000';
38 $Header::colourvpn
= '#990099';
39 $Header::colourerr
= '#FF0000';
40 $Header::viewsize
= 150;
41 $Header::errormessage
= '';
43 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'}:444/$ENV{'PATH_INFO'}\r\n\r\n";
55 ### Initialize environment
56 &General
::readhash
("${swroot}/main/settings", \
%settings);
57 &General
::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 = "File not found: firebuild\n";
92 if (open(MYFile
, "<${swroot}/firebuild")) {
93 $FIREBUILD = <MYFile
>;
95 $FIREBUILD = "(Build: $FIREBUILD)";
99 require "${swroot}/langs/en.pl";
100 require "${swroot}/langs/${language}.pl";
101 eval `/bin/cat /srv/web/ipfire/html/themes/$settings{'THEME'}/include/functions.pl`;
104 if ($ethsettings{'CONFIG_TYPE'} =~ /^[24]$/) {
111 if ($ethsettings{'CONFIG_TYPE'} =~ /^[34]$/) {
118 if ($ethsettings{'CONFIG_TYPE'} =~ /^[0]$/) {
127 my %subsystemhash = ();
128 my $subsystem = \
%subsystemhash;
130 my %substatushash = ();
131 my $substatus = \
%substatushash;
133 my %subnetworkhash = ();
134 my $subnetwork = \
%subnetworkhash;
136 my %subserviceshash = ();
137 my $subservices = \
%subserviceshash;
139 my %subfirewallhash = ();
140 my $subfirewall = \
%subfirewallhash;
142 my %subipfirehash = ();
143 my $subipfire = \
%subipfirehash;
145 my %sublogshash = ();
146 my $sublogs = \
%sublogshash;
148 eval `/bin/cat /var/ipfire/menu.d/*.menu`;
149 eval `/bin/cat /var/ipfire/menu.d/*.main`;
151 if (! blue_used
() && ! orange_used
()) {
152 $menu->{'05.firewall'}{'subMenu'}->{'40.dmz'}{'enabled'} = 0;
155 $menu->{'05.firewall'}{'subMenu'}->{'30.wireless'}{'enabled'} = 0;
157 if ( $ethsettings{'CONFIG_TYPE'} =~ /^(1|2|3|4)$/ && $ethsettings{'RED_TYPE'} eq 'STATIC' ) {
158 $menu->{'03.network'}{'subMenu'}->{'70.aliases'}{'enabled'} = 1;
164 print "Pragma: no-cache\n";
165 print "Cache-control: no-cache\n";
166 print "Connection: close\n";
167 print "Content-type: text/html\n\n";
170 sub is_menu_visible
($) {
173 return (-e
$ENV{'DOCUMENT_ROOT'}."/../$link");
179 if (! $root->{'enabled'}) {
182 if ($root->{'uri'} !~ /^$/) {
184 if ($root->{'vars'} !~ /^$/) {
185 $vars = '?'. $root->{'vars'};
187 if (! is_menu_visible
($root->{'uri'})) {
190 return $root->{'uri'}.$vars;
192 my $submenus = $root->{'subMenu'};
196 foreach my $item (sort keys %$submenus) {
197 my $link = getlink
($submenus->{$item});
209 my $uri = $conf->{'uri'};
210 my $vars = $conf->{'vars'};
211 my $novars = $conf->{'novars'};
216 if ($uri ne $URI[0]) {
220 if ($URI[1] !~ /^$/) {
227 return ($URI[1] eq $vars);
237 foreach my $item (sort keys %$root) {
238 my $val = $root->{$item};
239 if (compare_url
($val)) {
240 $val->{'selected'} = 1;
241 if ($val->{'title'} !~ /^$/) {
242 return $val->{'title'};
244 return 'EMPTY TITLE';
247 my $title = gettitle
($val->{'subMenu'});
249 $val->{'selected'} = 1;
257 my ($hash, $params) = @_;
258 my $cgi = CGI
->new ();
259 $hash->{'__CGI__'} = $cgi;
260 return if ($ENV{'REQUEST_METHOD'} ne 'POST');
261 if (!$params->{'wantfile'}) {
262 $CGI::DISABLE_UPLOADS
= 1;
263 $CGI::POST_MAX
= 512 * 1024;
265 $CGI::POST_MAX
= 10 * 1024 * 1024;
268 $cgi->referer() =~ m/^https?\:\/\
/([^\/]+)/;
270 $cgi->url() =~ m/^https?\:\/\
/([^\/]+)/;
272 return if ($referer ne $servername);
274 ### Modified for getting multi-vars, split by |
275 %temp = $cgi->Vars();
276 foreach my $key (keys %temp) {
277 $hash->{$key} = $temp{$key};
278 $hash->{$key} =~ s/\0/|/g;
279 $hash->{$key} =~ s/^\s*(.*?)\s*$/$1/;
282 if (($params->{'wantfile'})&&($params->{'filevar'})) {
283 $hash->{$params->{'filevar'}} = $cgi->upload
284 ($params->{'filevar'});
290 # Test if IP is within a subnet
291 # Call: IpInSubnet (Addr, Subnet, Subnet Mask)
292 # Subnet can be an IP of the subnet: 10.0.0.0 or 10.0.0.1
293 # Everything in dottted notation
297 $ip = unpack('N', inet_aton
(shift));
298 $start = unpack('N', inet_aton
(shift));
299 $mask = unpack('N', inet_aton
(shift));
300 $start &= $mask; # base of subnet...
301 $end = $start + ~$mask;
302 return (($ip >= $start) && ($ip <= $end));
307 my $outstring =$_[0];
308 $outstring =~ tr/,/ / if not defined $_[1] or $_[1] ne 'y';
309 $outstring =~ s/&/&/g;
310 $outstring =~ s/\'/'/g;
311 $outstring =~ s/\"/"/g;
312 $outstring =~ s/</</g;
313 $outstring =~ s/>/>/g;
319 my %pppsettings = ();
320 my %netsettings = ();
323 $pppsettings{'PROFILENAME'} = 'None';
324 &General
::readhash
("${General::swroot}/ppp/settings", \
%pppsettings);
325 &General
::readhash
("${General::swroot}/ethernet/settings", \
%netsettings);
328 if ( ! ( $netsettings{'CONFIG_TYPE'} =~ /^(1|2|3|4)$/ && $netsettings{'RED_TYPE'} =~ /^(DHCP|STATIC)$/ ) ) {
329 $profileused="- $pppsettings{'PROFILENAME'}";
332 if ( ( $pppsettings{'METHOD'} eq 'DHCP' && $netsettings{'RED_TYPE'} ne 'PPTP')
333 || $netsettings{'RED_TYPE'} eq 'DHCP' ) {
334 if (open(IFACE
, "${General::swroot}/red/iface")) {
338 $iface =~ /([a-zA-Z0-9]*)/; $iface = $1;
342 my ($timestr, $connstate);
343 if ($netsettings{'CONFIG_TYPE'} =~ /^(0|1|2|3|4)$/ && $pppsettings{'TYPE'} =~ /^isdn/) {
344 # Count ISDN channels
345 my ($idmap, $chmap, $drmap, $usage, $flags, $phone);
349 open (FILE
, "/dev/isdninfo");
351 $idmap = <FILE
>; chop $idmap;
352 $chmap = <FILE
>; chop $chmap;
353 $drmap = <FILE
>; chop $drmap;
354 $usage = <FILE
>; chop $usage;
355 $flags = <FILE
>; chop $flags;
356 $phone = <FILE
>; chop $phone;
358 $phone =~ s/^phone(\s*):(\s*)//;
360 @phonenumbers = split / /, $phone;
362 foreach (@phonenumbers) {
373 } elsif ($count == 1) {
379 if (-e
"${General::swroot}/red/active") {
380 $timestr = &General
::age
("${General::swroot}/red/active");
381 $connstate = "<span class='ipcop_StatusBig'>$Lang::tr{'connected'} - $number channel (<span class='ipcop_StatusBigRed'>$timestr</span>) $profileused</span>";
384 if (-e
"${General::swroot}/red/dial-on-demand") {
385 $connstate = "<span class='ipcop_StatusBig'>$Lang::tr{'dod waiting'} $profileused</span>";
387 $connstate = "<span class='ipcop_StatusBig'>$Lang::tr{'idle'} $profileused</span>";
390 $connstate = "<span class='ipcop_StatusBig'>$Lang::tr{'connecting'} $profileused</span>";
393 } elsif ($netsettings{'RED_TYPE'} eq "STATIC" || $pppsettings {'METHOD'} eq 'STATIC') {
394 if (-e
"${General::swroot}/red/active") {
395 $timestr = &General
::age
("${General::swroot}/red/active");
396 $connstate = "<span class='ipcop_StatusBig'>$Lang::tr{'connected'} (<span class='ipcop_StatusBigRed'>$timestr</span>) $profileused</span>";
398 $connstate = "<span class='ipcop_StatusBig'>$Lang::tr{'idle'} $profileused</span>";
400 } elsif ( ( (-e
"${General::swroot}/dhcpc/dhcpcd-$iface.pid") && $netsettings{'RED_TYPE'} ne 'PPTP' ) ||
401 !system("/bin/ps -ef | /bin/grep -q '[p]ppd'") || !system("/bin/ps -ef | /bin/grep -q '[c]onnectioncheck'")) {
402 if (-e
"${General::swroot}/red/active") {
403 $timestr = &General
::age
("${General::swroot}/red/active");
404 if ($pppsettings{'TYPE'} =~ /^(modem|bewanadsl|conexantpciadsl|eagleusbadsl)$/) {
406 if ($pppsettings{'TYPE'} eq 'modem') {
407 open(CONNECTLOG
, "/var/log/connect.log");
408 while (<CONNECTLOG
>) {
410 $speed = (split / /)[6];
414 } elsif ($pppsettings{'TYPE'} eq 'bewanadsl') {
415 $speed = `/usr/bin/unicorn_status | /bin/grep Rate | /usr/bin/cut -f2 -d ':'`;
416 } elsif ($pppsettings{'TYPE'} eq 'conexantpciadsl') {
417 $speed = `/bin/cat /proc/net/atm/CnxAdsl:* | /bin/grep 'Line Rates' | /bin/sed -e 's+Line Rates: Receive+Rx+' -e 's+Transmit+Tx+'`;
418 } elsif ($pppsettings{'TYPE'} eq 'eagleusbadsl') {
419 $speed = `/usr/sbin/eaglestat | /bin/grep Rate`;
421 $connstate = "$Lang::tr{'connected'} ($timestr) $profileused (\@$speed)";
423 $connstate = "$Lang::tr{'connected'} ($timestr) $profileused";
426 if (-e
"${General::swroot}/red/dial-on-demand") {
427 $connstate = "$Lang::tr{'dod waiting'} $profileused";
429 $connstate = "$Lang::tr{'connecting'} $profileused";
433 $connstate = "$Lang::tr{'idle'} $profileused";
439 #Sorting of allocated leases
440 if ($ENV{'QUERY_STRING'} =~ /^IPADDR|^ETHER|^HOSTNAME|^ENDTIME/ ) {
441 my $newsort=$ENV{'QUERY_STRING'};
442 &readhash
("${swroot}/dhcp/settings", \
%dhcpsettings);
443 $act=$dhcpsettings{'SORT_LEASELIST'};
445 if ($act =~ $newsort) {
446 if ($act !~ 'Rev') {$Rev='Rev'};
450 $dhcpsettings{'SORT_LEASELIST'}=$newsort;
451 &writehash
("${swroot}/dhcp/settings", \
%dhcpsettings);
452 $dhcpsettings{'ACTION'} = 'SORT'; # avoid the next test "First lauch"
457 sub PrintActualLeases
459 &openbox
('100%', 'left', $tr{'current dynamic leases'});
463 <td width='25%' align='center'><a href='$ENV{'SCRIPT_NAME'}?IPADDR'><b>$tr{'ip address'}</b></a></td>
464 <td width='25%' align='center'><a href='$ENV{'SCRIPT_NAME'}?ETHER'><b>$tr{'mac address'}</b></a></td>
465 <td width='20%' align='center'><a href='$ENV{'SCRIPT_NAME'}?HOSTNAME'><b>$tr{'hostname'}</b></a></td>
466 <td width='25%' align='center'><a href='$ENV{'SCRIPT_NAME'}?ENDTIME'><b>$tr{'lease expires'} (local time d/m/y)</b></a></td>
467 <td width='5%' align='center'><b>Add to fix leases<b></td>
472 open(LEASES
,"/var/state/dhcp/dhcpd.leases") or die "Can't open dhcpd.leases";
473 while ($line = <LEASES
>) {
474 next if( $line =~ /^\s*#/ );
476 @temp = split (' ', $line);
478 if ($line =~ /^\s*lease/) {
480 #All field are not necessarily read. Clear everything
486 if ($line =~ /^\s*ends/) {
487 $line =~ /(\d+)\/(\d
+)\
/(\d+) (\d+):(\d+):(\d+)/;
488 $endtime = timegm
($6, $5, $4, $3, $2 - 1, $1 - 1900);
491 if ($line =~ /^\s*hardware ethernet/) {
496 if ($line =~ /^\s*client-hostname/) {
497 $hostname = "$temp[1] $temp[2] $temp[3]";
499 $hostname =~ s/\"//g;
503 @record = ('IPADDR',$ip,'ENDTIME',$endtime,'ETHER',$ether,'HOSTNAME',$hostname);
504 $record = {}; # create a reference to empty hash
505 %{$record} = @record; # populate that hash with @record
506 $entries{$record->{'IPADDR'}} = $record; # add this to a hash of hashes
512 foreach my $key (sort leasesort
keys %entries) {
513 print "<form method='post' action='/cgi-bin/dhcp.cgi'>\n";
514 my $hostname = &cleanhtml
($entries{$key}->{HOSTNAME
},"y");
517 print "<tr bgcolor='$table1colour'>";
520 print "<tr bgcolor='$table2colour'>";
524 <td align='center'><input type='hidden' name='FIX_ADDR' value='$entries{$key}->{IPADDR}' />$entries{$key}->{IPADDR}</td>
525 <td align='center'><input type='hidden' name='FIX_MAC' value='$entries{$key}->{ETHER}' />$entries{$key}->{ETHER}</td>
526 <td align='center'><input type='hidden' name='FIX_REMARK' value='$hostname' /> $hostname</td>
527 <td align='center'><input type='hidden' name='FIX_ENABLED' value='on' />
531 ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $dst) = localtime ($entries{$key}->{ENDTIME
});
532 $enddate = sprintf ("%02d/%02d/%d %02d:%02d:%02d",$mday,$mon+1,$year+1900,$hour,$min,$sec);
534 if ($entries{$key}->{ENDTIME
} < time() ){
535 print "<strike>$enddate</strike>";
540 <td><input type='hidden' name='ACTION' value='$Lang::tr{'add'}2' /><input type='submit' name='SUBMIT' value='$Lang::tr{'add'}' />
541 </td></td></tr></form>
552 # This sub is used during display of actives leases
554 if (rindex ($dhcpsettings{'SORT_LEASELIST'},'Rev') != -1)
556 $qs=substr ($dhcpsettings{'SORT_LEASELIST'},0,length($dhcpsettings{'SORT_LEASELIST'})-3);
557 if ($qs eq 'IPADDR') {
558 @a = split(/\./,$entries{$a}->{$qs});
559 @b = split(/\./,$entries{$b}->{$qs});
565 $entries{$b}->{$qs} cmp $entries{$a}->{$qs};
570 $qs=$dhcpsettings{'SORT_LEASELIST'};
571 if ($qs eq 'IPADDR') {
572 @a = split(/\./,$entries{$a}->{$qs});
573 @b = split(/\./,$entries{$b}->{$qs});
579 $entries{$a}->{$qs} cmp $entries{$b}->{$qs};