]> git.ipfire.org Git - ipfire-2.x.git/blob - config/cfgroot/header.pl
git-svn-id: http://svn.ipfire.org/svn/ipfire/IPFire/source@16 ea5c0bd1-69bd-2848...
[ipfire-2.x.git] / config / cfgroot / header.pl
1 # SmoothWall CGIs
2 #
3 # This code is distributed under the terms of the GPL
4 #
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()
11 #
12 # $Id: header.pl,v 1.34.2.67 2005/10/03 20:01:05 gespinasse Exp $
13 #
14
15 package Header;
16
17 use strict;
18 use CGI();
19 use Time::Local;
20
21 # enable only the following on debugging purpose
22 #use warnings;
23 #use CGI::Carp 'fatalsToBrowser';
24
25
26 $Header::pagecolour = '#ffffff'; # never used, will be removed
27 $Header::tablecolour = '#FFFFFF'; # never used, will be removed
28 $Header::bigboxcolour = '#F6F4F4'; # never used, will be removed
29 $Header::boxcolour = '#EAE9EE'; # only header.pl, ? move in css ?
30 $Header::bordercolour = '#000000'; # never used, will be removed
31 $Header::table1colour = '#C0C0C0';
32 $Header::table2colour = '#F2F2F2';
33 $Header::colourred = '#993333';
34 $Header::colourorange = '#FF9933';
35 $Header::colouryellow = '#FFFF00';
36 $Header::colourgreen = '#339933';
37 $Header::colourblue = '#333399';
38 $Header::colourfw = '#000000'; # only connections.cgi
39 $Header::colourvpn = '#990099'; # only connections.cgi
40 $Header::colourerr = '#FF0000'; # only header.pl, many scripts use colourred for warnings messages
41 $Header::viewsize = 150;
42 my %menu = ();
43 my $hostnameintitle = 0;
44 our $javascript = 1;
45
46 ### Initialize menu
47 sub genmenu
48 {
49 ### Initialize environment
50 my %ethsettings = ();
51 &General::readhash("${General::swroot}/ethernet/settings", \%ethsettings);
52
53 %{$menu{'1.system'}}=(
54 'contents' => $Lang::tr{'alt system'},
55 'uri' => '',
56 'statusText' => "IPCop $Lang::tr{'alt system'}",
57 'subMenu' => [[ $Lang::tr{'alt home'} , '/cgi-bin/index.cgi', "IPCop $Lang::tr{'alt home'}" ],
58 [ $Lang::tr{'updates'} , '/cgi-bin/updates.cgi', "IPCop $Lang::tr{'updates'}" ],
59 [ $Lang::tr{'sspasswords'} , '/cgi-bin/changepw.cgi', "IPCop $Lang::tr{'sspasswords'}" ],
60 [ $Lang::tr{'ssh access'} , '/cgi-bin/remote.cgi', "IPCop $Lang::tr{'ssh access'}" ],
61 [ $Lang::tr{'gui settings'} , '/cgi-bin/gui.cgi', "IPCop $Lang::tr{'gui settings'}" ],
62 [ $Lang::tr{'backup'} , '/cgi-bin/backup.cgi', "IPCop $Lang::tr{'backup'} / $Lang::tr{'restore'}" ],
63 [ $Lang::tr{'shutdown'} , '/cgi-bin/shutdown.cgi', "IPCop $Lang::tr{'shutdown'} / $Lang::tr{'reboot'}" ],
64 [ $Lang::tr{'credits'} , '/cgi-bin/credits.cgi', "IPCop $Lang::tr{'credits'}" ]]
65 );
66 %{$menu{'2.status'}}=(
67 'contents' => $Lang::tr{'status'},
68 'uri' => '',
69 'statusText' => "IPCop $Lang::tr{'status information'}",
70 'subMenu' => [[ $Lang::tr{'sssystem status'} , '/cgi-bin/status.cgi', "IPCop $Lang::tr{'system status information'}" ],
71 [ $Lang::tr{'ssnetwork status'} , '/cgi-bin/netstatus.cgi', "IPCop $Lang::tr{'network status information'}" ],
72 [ $Lang::tr{'system graphs'} , '/cgi-bin/graphs.cgi', "IPCop $Lang::tr{'system graphs'}" ],
73 [ $Lang::tr{'sstraffic graphs'} , '/cgi-bin/graphs.cgi?graph=network', "IPCop $Lang::tr{'network traffic graphs'}" ],
74 [ $Lang::tr{'ssproxy graphs'} , '/cgi-bin/proxygraphs.cgi', "IPCop $Lang::tr{'proxy access graphs'}" ],
75 [ $Lang::tr{'connections'} , '/cgi-bin/connections.cgi', "IPCop $Lang::tr{'connections'}" ]]
76 );
77 %{$menu{'3.network'}}=(
78 'contents' => $Lang::tr{'network'},
79 'uri' => '',
80 'statusText' => "IPCop $Lang::tr{'network configuration'}",
81 'subMenu' => [[ $Lang::tr{'alt dialup'} , '/cgi-bin/pppsetup.cgi', "IPCop $Lang::tr{'dialup settings'}" ],
82 [ $Lang::tr{'upload'} , '/cgi-bin/upload.cgi', $Lang::tr{'firmware upload'} ],
83 [ $Lang::tr{'modem'} , '/cgi-bin/modem.cgi', "IPCop $Lang::tr{'modem configuration'}" ],
84 [ $Lang::tr{'aliases'} , '/cgi-bin/aliases.cgi', "IPCop $Lang::tr{'external aliases configuration'}" ]]
85 );
86 %{$menu{'4.services'}}=(
87 'contents' => $Lang::tr{'alt services'},
88 'uri' => '',
89 'statusText' => "IPCop $Lang::tr{'alt services'}",
90 'subMenu' => [[ $Lang::tr{'proxy'} , '/cgi-bin/proxy.cgi', "IPCop $Lang::tr{'web proxy configuration'}" ],
91 [ $Lang::tr{'dhcp server'} , '/cgi-bin/dhcp.cgi', "IPCop $Lang::tr{'dhcp configuration'}" ],
92 [ $Lang::tr{'dynamic dns'} , '/cgi-bin/ddns.cgi', "IPCop $Lang::tr{'dynamic dns client'}" ],
93 [ $Lang::tr{'edit hosts'} , '/cgi-bin/hosts.cgi', "IPCop $Lang::tr{'host configuration'}" ],
94 [ $Lang::tr{'time server'} , '/cgi-bin/time.cgi', "IPCop $Lang::tr{'time server'}" ],
95 [ $Lang::tr{'traffic shaping'} , '/cgi-bin/shaping.cgi', "IPCop $Lang::tr{'traffic shaping settings'}" ],
96 [ $Lang::tr{'intrusion detection'} , '/cgi-bin/ids.cgi', "IPCop $Lang::tr{'intrusion detection system'} (Snort)" ]]
97 );
98 %{$menu{'5.firewall'}}=(
99 'contents' => $Lang::tr{'firewall'},
100 'uri' => '',
101 'statusText' => "IPCop $Lang::tr{'firewall'}",
102 'subMenu' => [[ $Lang::tr{'ssport forwarding'} , '/cgi-bin/portfw.cgi', "IPCop $Lang::tr{'port forwarding configuration'}" ],
103 [ $Lang::tr{'external access'} , '/cgi-bin/xtaccess.cgi', "IPCop $Lang::tr{'external access configuration'}" ],
104 [ $Lang::tr{'ssdmz pinholes'} , '/cgi-bin/dmzholes.cgi', "IPCop $Lang::tr{'dmz pinhole configuration'}" ],
105 [ $Lang::tr{'blue access'} , '/cgi-bin/wireless.cgi', "IPCop $Lang::tr{'blue access'}" ]
106 ,[ $Lang::tr{'options fw'} , '/cgi-bin/optionsfw.cgi', "IPCop $Lang::tr{'options fw'}" ]
107 ]
108 );
109 %{$menu{'6.vpns'}}=(
110 'contents' => $Lang::tr{'alt vpn'},
111 'uri' => '',
112 'statusText' => "IPCop $Lang::tr{'virtual private networking'}",
113 'subMenu' => [[ $Lang::tr{'alt vpn'} , '/cgi-bin/vpnmain.cgi', "IPCop $Lang::tr{'virtual private networking'}"]]
114 );
115 %{$menu{'7.mainlogs'}}=(
116 'contents' => $Lang::tr{'alt logs'},
117 'uri' => '',
118 'statusText' => "IPCop $Lang::tr{'alt logs'}",
119 'subMenu' => [[ $Lang::tr{'log settings'} , '/cgi-bin/logs.cgi/config.dat', "IPCop $Lang::tr{'log settings'}" ],
120 [ $Lang::tr{'log summary'} , '/cgi-bin/logs.cgi/summary.dat', "IPCop $Lang::tr{'log summary'}" ],
121 [ $Lang::tr{'proxy logs'} , '/cgi-bin/logs.cgi/proxylog.dat', "IPCop $Lang::tr{'proxy log viewer'}" ],
122 [ $Lang::tr{'firewall logs'} , '/cgi-bin/logs.cgi/firewalllog.dat', "IPCop $Lang::tr{'firewall log viewer'}" ],
123 [ $Lang::tr{'ids logs'} , '/cgi-bin/logs.cgi/ids.dat', "IPCop $Lang::tr{'intrusion detection system log viewer'}" ],
124 [ $Lang::tr{'system logs'} , '/cgi-bin/logs.cgi/log.dat', "IPCop $Lang::tr{'system log viewer'}" ]]
125 );
126 if (! $ethsettings{'BLUE_DEV'}) {
127 splice (@{$menu{'5.firewall'}{'subMenu'}}, 3, 1);
128 }
129 if (! $ethsettings{'BLUE_DEV'} && ! $ethsettings{'ORANGE_DEV'}) {
130 splice (@{$menu{'5.firewall'}{'subMenu'}}, 2, 1);
131 }
132 unless ( $ethsettings{'CONFIG_TYPE'} =~ /^(2|3|6|7)$/ && $ethsettings{'RED_TYPE'} eq 'STATIC' ) {
133 splice (@{$menu{'3.network'}{'subMenu'}}, 3, 1);
134 }
135 if ( ! -e "${General::swroot}/snort/enable" && ! -e "${General::swroot}/snort/enable_blue" &&
136 ! -e "${General::swroot}/snort/enable_green" && ! -e "${General::swroot}/snort/enable_orange") {
137 splice (@{$menu{'7.mainlogs'}{'subMenu'}}, 4, 1);
138 }
139 if ( ! -e "${General::swroot}/proxy/enable" && ! -e "${General::swroot}/proxy/enable_blue" ) {
140 splice (@{$menu{'2.status'}{'subMenu'}}, 4, 1);
141 splice (@{$menu{'7.mainlogs'}{'subMenu'}}, 2, 1);
142 }
143 }
144
145 sub showhttpheaders
146 {
147 ### Make sure this is an SSL request
148 if ($ENV{'SERVER_ADDR'} && $ENV{'HTTPS'} ne 'on') {
149 print "Status: 302 Moved\r\n";
150 print "Location: https://$ENV{'SERVER_ADDR'}:445/$ENV{'PATH_INFO'}\r\n\r\n";
151 exit 0;
152 } else {
153 print "Pragma: no-cache\n";
154 print "Cache-control: no-cache\n";
155 print "Connection: close\n";
156 print "Content-type: text/html\n\n";
157 }
158 }
159
160 sub showjsmenu
161 {
162 my $c1 = 1;
163
164 print " <script type='text/javascript'>\n";
165 print " domMenu_data.setItem('domMenu_main', new domMenu_Hash(\n";
166
167 foreach my $k1 ( sort keys %menu ) {
168 my $c2 = 1;
169 if ($c1 > 1) {
170 print " ),\n";
171 }
172 print " $c1, new domMenu_Hash(\n";
173 print "\t'contents', '" . &cleanhtml($menu{$k1}{'contents'}) . "',\n";
174 print "\t'uri', '$menu{$k1}{'uri'}',\n";
175 $menu{$k1}{'statusText'} =~ s/'/\\\'/g;
176 print "\t'statusText', '$menu{$k1}{'statusText'}',\n";
177 foreach my $k2 ( @{$menu{$k1}{'subMenu'}} ) {
178 print "\t $c2, new domMenu_Hash(\n";
179 print "\t\t'contents', '" . &cleanhtml(@{$k2}[0]) . "',\n";
180 print "\t\t'uri', '@{$k2}[1]',\n";
181 @{$k2}[2] =~ s/'/\\\'/g;
182 print "\t\t'statusText', '@{$k2}[2]'\n";
183 if ( $c2 <= $#{$menu{$k1}{'subMenu'}} ) {
184 print "\t ),\n";
185 } else {
186 print "\t )\n";
187 }
188 $c2++;
189 }
190 $c1++;
191 }
192 print " )\n";
193 print " ));\n\n";
194
195 print <<EOF
196 domMenu_settings.setItem('domMenu_main', new domMenu_Hash(
197 'menuBarWidth', '0%',
198 'menuBarClass', 'ipcop_menuBar',
199 'menuElementClass', 'ipcop_menuElement',
200 'menuElementHoverClass', 'ipcop_menuElementHover',
201 'menuElementActiveClass', 'ipcop_menuElementHover',
202 'subMenuBarClass', 'ipcop_subMenuBar',
203 'subMenuElementClass', 'ipcop_subMenuElement',
204 'subMenuElementHoverClass', 'ipcop_subMenuElementHover',
205 'subMenuElementActiveClass', 'ipcop_subMenuElementHover',
206 'subMenuMinWidth', 'auto',
207 'distributeSpace', false,
208 'openMouseoverMenuDelay', 0,
209 'openMousedownMenuDelay', 0,
210 'closeClickMenuDelay', 0,
211 'closeMouseoutMenuDelay', -1
212 ));
213 </script>
214 EOF
215 ;
216 }
217
218 sub showmenu
219 {
220 if ($javascript) {print "<noscript>";}
221 print "<table cellpadding='0' cellspacing='0' border='0'>\n";
222 print "<tr>\n";
223
224 foreach my $k1 ( sort keys %menu ) {
225 print "<td class='ipcop_menuElementTD'><a href='" . @{@{$menu{$k1}{'subMenu'}}[0]}[1] . "' class='ipcop_menuElementNoJS'>";
226 print $menu{$k1}{'contents'} . "</a></td>\n";
227 }
228 print "</tr></table>\n";
229 if ($javascript) {print "</noscript>";}
230 }
231
232 sub showsubsection
233 {
234 my $location = $_[0];
235 my $c1 = 0;
236
237 if ($javascript) {print "<noscript>";}
238 print "<table width='100%' cellspacing='0' cellpadding='5' border='0'>\n";
239 print "<tr><td style='background-color: $Header::boxcolour;' width='53'><img src='/images/null.gif' width='43' height='1' alt='' /></td>\n";
240 print "<td style='background-color: $Header::boxcolour;' align='left' width='100%'>";
241 my @URI=split ('\?', $ENV{'REQUEST_URI'} );
242
243 foreach my $k1 ( keys %menu ) {
244
245 if ($menu{$k1}{'contents'} eq $location) {
246 foreach my $k2 ( @{$menu{$k1}{'subMenu'}} ) {
247 if ($c1 > 0) {
248 print " | ";
249 }
250 if (@{$k2}[1] eq "$URI[0]\?$URI[1]" || (@{$k2}[1] eq $URI[0] && length($URI[1]) == 0)) {
251 #if (@{$k2}[1] eq "$URI[0]") {
252 print "<b>@{$k2}[0]</b>";
253 } else {
254 print "<a href='@{$k2}[1]'>@{$k2}[0]</a>";
255 }
256 $c1++;
257 }
258 }
259 }
260 print "</td></tr></table>\n";
261 if ($javascript) { print "</noscript>";}
262 }
263
264 sub openpage
265 {
266 my $title = $_[0];
267 my $menu = $_[1];
268 my $extrahead = $_[2];
269
270 ### Initialize environment
271 my %settings = ();
272 &General::readhash("${General::swroot}/main/settings", \%settings);
273
274 if ($settings{'JAVASCRIPT'} eq 'off') {
275 $javascript = 0;
276 } else {
277 $javascript = 1;
278 }
279
280 if ($settings{'WINDOWWITHHOSTNAME'} eq 'on') {
281 $hostnameintitle = 1;
282 } else {
283 $hostnameintitle = 0;
284 }
285
286 print <<END
287 <!DOCTYPE html
288 PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
289 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
290
291 <html><head>
292 END
293 ;
294 print " <title>";
295 if ($hostnameintitle) {
296 print "$settings{'HOSTNAME'}.$settings{'DOMAINNAME'} - $title";
297 } else {
298 print "IPCop - $title";
299 }
300 print "</title>\n";
301
302 print <<END
303 $extrahead
304 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
305 <link rel="shortcut icon" href="/favicon.ico" />
306 <style type="text/css">\@import url(/include/ipcop.css);</style>
307 END
308 ;
309 if ($javascript) {
310 print "<script type='text/javascript' src='/include/domMenu.js'></script>\n";
311 &genmenu();
312 &showjsmenu();
313 } else {
314 &genmenu();
315 }
316
317 my $location = '';
318 my $sublocation = '';
319 my @URI=split ('\?', $ENV{'REQUEST_URI'} );
320 foreach my $k1 ( keys %menu ) {
321 my $temp = $menu{$k1}{'contents'};
322 foreach my $k2 ( @{$menu{$k1}{'subMenu'}} ) {
323 if ( @{$k2}[1] eq $URI[0] ) {
324 $location = $temp;
325 $sublocation = @{$k2}[0];
326 }
327 }
328 }
329
330 my @cgigraphs = split(/graph=/,$ENV{'QUERY_STRING'});
331 if (defined ($cgigraphs[1])){
332 if ($cgigraphs[1] =~ /(GREEN|BLUE|ORANGE|RED|network)/) {
333 $location = $Lang::tr{'status'};
334 $sublocation = $Lang::tr{'sstraffic graphs'};
335 }
336 if ($cgigraphs[1] =~ /(cpu|memory|swap|disk)/) {
337 $location = $Lang::tr{'status'};
338 $sublocation = $Lang::tr{'system graphs'};
339 }
340 }
341 if ($ENV{'QUERY_STRING'} =~ /(ip)/) {
342 $location = $Lang::tr{'alt logs'};
343 $sublocation = "WHOIS";
344 }
345
346 if ($javascript) {
347 print <<END
348 <script type="text/javascript">
349 document.onmouseup = function()
350 {
351 domMenu_deactivate('domMenu_main');
352 }
353 </script>
354 </head>
355
356 <body onload="domMenu_activate('domMenu_main');">
357 END
358 ;
359 } else {
360 print "</head>\n\n<body>\n";
361 }
362
363 print <<END
364 <!-- IPCOP HEADER -->
365 <table width='100%' cellpadding='0' cellspacing='0'>
366 <col width='53' />
367 <col />
368 <tr><td><img src='/images/null.gif' width='53' height='27' alt='' /></td>
369 <td valign='bottom'><table width='100%' cellspacing='0' border='0'>
370 <col width='5' />
371 <col width='175' />
372 <col />
373 <tr><td><img src='/images/null.gif' width='5' height='1' alt='' /></td>
374 <td class="ipcop_menuLocationMain" valign='bottom'>$location</td>
375 <td class="ipcop_menuLocationSub" valign='bottom'>$sublocation</td>
376 </tr></table>
377 </td></tr>
378 <tr><td valign='bottom' class='ipcop_Version'>
379 <img src='/images/null.gif' width='1' height='29' alt='' />${General::version}</td>
380 <td valign='bottom'>
381 END
382 ;
383 if ($menu == 1) {
384 if ($javascript) {
385 print "<div id='domMenu_main'></div>\n";
386 }
387 &showmenu();
388 }
389 print " </td></tr></table>\n";
390 &showsubsection($location);
391 print "<!-- IPCOP CONTENT -->\n";
392 }
393
394 sub closepage
395 {
396 print <<END
397 <!-- IPCOP FOOTER -->
398 <table width='100%' border='0'>
399 <tr><td valign='bottom'><img src='/images/bounceback.png' width='248' height='80' alt='' /></td>
400 <td align='center' valign='bottom'>
401 END
402 ;
403 my $status = &connectionstatus();
404 print "$status<br />\n";
405 print `/usr/bin/uptime`;
406
407 print <<END
408 </td>
409 <td valign='bottom'><a href='http://sf.net/projects/ipcop/' target='_blank'><img src='/images/sflogo.png' width='88' height='31' alt='Sourceforge logo' /></a></td>
410 </tr></table>
411 </body></html>
412 END
413 ;
414 }
415
416 sub openbigbox
417 {
418 my $width = $_[0];
419 my $align = $_[1];
420 my $sideimg = $_[2];
421 my $errormessage = $_[3];
422 my $bgcolor;
423
424 if ($errormessage) {
425 $bgcolor = "style='background-color: $Header::colourerr;'";
426 } else {
427 $bgcolor = '';
428 }
429
430 print "<table width='100%' border='0'>\n";
431 if ($sideimg) {
432 print "<tr><td valign='top'><img src='/images/$sideimg' width='65' height='345' alt='' /></td>\n";
433 } else {
434 print "<tr>\n";
435 }
436 print "<td valign='top' align='center'><table width='$width' $bgcolor cellspacing='0' cellpadding='10' border='0'>\n";
437 print "<tr><td><img src='/images/null.gif' width='1' height='365' alt='' /></td>\n";
438 print "<td align='$align' valign='top'>\n";
439 }
440
441 sub closebigbox
442 {
443 print "</td></tr></table></td></tr></table>\n"
444 }
445
446 sub openbox
447 {
448 my $width = $_[0];
449 my $align = $_[1];
450 my $caption = $_[2];
451
452 print <<END
453 <table cellspacing="0" cellpadding="0" width="$width" border="0">
454 <col width='12' />
455 <col width='18' />
456 <col width='100%' />
457 <col width='152' />
458 <col width='11' />
459
460 <tr><td width='12' ><img src='/images/null.gif' width='12' height='1' alt='' /></td>
461 <td width='18' ><img src='/images/null.gif' width='18' height='1' alt='' /></td>
462 <td width='100%'><img src='/images/null.gif' width='400' height='1' alt='' /></td>
463 <td width='152' ><img src='/images/null.gif' width='152' height='1' alt='' /></td>
464 <td width='11' ><img src='/images/null.gif' width='11' height='1' alt='' /></td></tr>
465 <tr><td colspan='2' ><img src='/images/boxtop1.png' width='30' height='53' alt='' /></td>
466 <td style='background: url(/images/boxtop2.png);'>
467 END
468 ;
469 if ($caption) { print "<b>$caption</b>\n"; } else { print "&nbsp;"; }
470 print <<END
471 </td>
472 <td colspan='2'><img src='/images/boxtop3.png' width='163' height='53' alt='' /></td></tr>
473 <tr><td style='background: url(/images/boxleft.png);'><img src='/images/null.gif' width='12' height='1' alt='' /></td>
474 <td colspan='3' style='background-color: $Header::boxcolour;'>
475 <table width='100%' cellpadding='5'><tr><td align="$align" valign='top'>
476 END
477 ;
478 }
479
480 sub closebox
481 {
482 print <<END
483 </td></tr></table></td>
484 <td style='background: url(/images/boxright.png);'><img src='/images/null.gif' width='11' height='1' alt='' /></td></tr>
485 <tr><td style='background: url(/images/boxbottom1.png);background-repeat:no-repeat;'><img src='/images/null.gif' width='12' height='14' alt='' /></td>
486 <td style='background: url(/images/boxbottom2.png);background-repeat:repeat-x;' colspan='3'><img src='/images/null.gif' width='1' height='14' alt='' /></td>
487 <td style='background: url(/images/boxbottom3.png);background-repeat:no-repeat;'><img src='/images/null.gif' width='11' height='14' alt='' /></td></tr>
488 </table>
489 END
490 ;
491 }
492
493 sub getcgihash {
494 my ($hash, $params) = @_;
495 my $cgi = CGI->new ();
496 return if ($ENV{'REQUEST_METHOD'} ne 'POST');
497 if (!$params->{'wantfile'}) {
498 $CGI::DISABLE_UPLOADS = 1;
499 $CGI::POST_MAX = 512 * 1024;
500 } else {
501 $CGI::POST_MAX = 10 * 1024 * 1024;
502 }
503
504 $cgi->referer() =~ m/^https?\:\/\/([^\/]+)/;
505 my $referer = $1;
506 $cgi->url() =~ m/^https?\:\/\/([^\/]+)/;
507 my $servername = $1;
508 return if ($referer ne $servername);
509
510 ### Modified for getting multi-vars, split by |
511 my %temp = $cgi->Vars();
512 foreach my $key (keys %temp) {
513 $hash->{$key} = $temp{$key};
514 $hash->{$key} =~ s/\0/|/g;
515 $hash->{$key} =~ s/^\s*(.*?)\s*$/$1/;
516 }
517
518 if (($params->{'wantfile'})&&($params->{'filevar'})) {
519 $hash->{$params->{'filevar'}} = $cgi->upload
520 ($params->{'filevar'});
521 }
522 return;
523 }
524
525 sub cleanhtml
526 {
527 my $outstring =$_[0];
528 $outstring =~ tr/,/ / if not defined $_[1] or $_[1] ne 'y';
529 $outstring =~ s/&/&amp;/g;
530 $outstring =~ s/\'/&#039;/g;
531 $outstring =~ s/\"/&quot;/g;
532 $outstring =~ s/</&lt;/g;
533 $outstring =~ s/>/&gt;/g;
534 return $outstring;
535 }
536
537 sub connectionstatus
538 {
539 my %pppsettings = ();
540 my %netsettings = ();
541 my $iface='';
542
543 $pppsettings{'PROFILENAME'} = 'None';
544 &General::readhash("${General::swroot}/ppp/settings", \%pppsettings);
545 &General::readhash("${General::swroot}/ethernet/settings", \%netsettings);
546
547 my $profileused='';
548 if ( ! ( $netsettings{'CONFIG_TYPE'} =~ /^(2|3|6|7)$/ && $netsettings{'RED_TYPE'} =~ /^(DHCP|STATIC)$/ ) ) {
549 $profileused="- $pppsettings{'PROFILENAME'}";
550 }
551
552 if ( ( $pppsettings{'METHOD'} eq 'DHCP' && $netsettings{'RED_TYPE'} ne 'PPTP')
553 || $netsettings{'RED_TYPE'} eq 'DHCP' ) {
554 if (open(IFACE, "${General::swroot}/red/iface")) {
555 $iface = <IFACE>;
556 close IFACE;
557 chomp ($iface);
558 $iface =~ /([a-zA-Z0-9]*)/; $iface = $1;
559 }
560 }
561
562 my ($timestr, $connstate);
563 if ($netsettings{'CONFIG_TYPE'} =~ /^(0|1|4|5)$/ && $pppsettings{'TYPE'} =~ /^isdn/) {
564 # Count ISDN channels
565 my ($idmap, $chmap, $drmap, $usage, $flags, $phone);
566 my @phonenumbers;
567 my $count=0;
568
569 open (FILE, "/dev/isdninfo");
570
571 $idmap = <FILE>; chop $idmap;
572 $chmap = <FILE>; chop $chmap;
573 $drmap = <FILE>; chop $drmap;
574 $usage = <FILE>; chop $usage;
575 $flags = <FILE>; chop $flags;
576 $phone = <FILE>; chop $phone;
577
578 $phone =~ s/^phone(\s*):(\s*)//;
579
580 @phonenumbers = split / /, $phone;
581
582 foreach (@phonenumbers) {
583 if ($_ ne '???') {
584 $count++;
585 }
586 }
587 close (FILE);
588
589 ## Connection status
590 my $number;
591 if ($count == 0) {
592 $number = 'none!';
593 } elsif ($count == 1) {
594 $number = 'single';
595 } else {
596 $number = 'dual';
597 }
598
599 if (-e "${General::swroot}/red/active") {
600 $timestr = &General::age("${General::swroot}/red/active");
601 $connstate = "<span class='ipcop_StatusBig'>$Lang::tr{'connected'} - $number channel (<span class='ipcop_StatusBigRed'>$timestr</span>) $profileused</span>";
602 } else {
603 if ($count == 0) {
604 if (-e "${General::swroot}/red/dial-on-demand") {
605 $connstate = "<span class='ipcop_StatusBig'>$Lang::tr{'dod waiting'} $profileused</span>";
606 } else {
607 $connstate = "<span class='ipcop_StatusBig'>$Lang::tr{'idle'} $profileused</span>";
608 }
609 } else {
610 $connstate = "<span class='ipcop_StatusBig'>$Lang::tr{'connecting'} $profileused</span>";
611 }
612 }
613 } elsif ($netsettings{'RED_TYPE'} eq "STATIC" || $pppsettings {'METHOD'} eq 'STATIC') {
614 if (-e "${General::swroot}/red/active") {
615 $timestr = &General::age("${General::swroot}/red/active");
616 $connstate = "<span class='ipcop_StatusBig'>$Lang::tr{'connected'} (<span class='ipcop_StatusBigRed'>$timestr</span>) $profileused</span>";
617 } else {
618 $connstate = "<span class='ipcop_StatusBig'>$Lang::tr{'idle'} $profileused</span>";
619 }
620 } elsif ( ( (-e "${General::swroot}/dhcpc/dhcpcd-$iface.pid") && $netsettings{'RED_TYPE'} ne 'PPTP' ) ||
621 !system("/bin/ps -ef | /bin/grep -q '[p]ppd'") || !system("/bin/ps -ef | /bin/grep -q '[c]onnectioncheck'")) {
622 if (-e "${General::swroot}/red/active") {
623 $timestr = &General::age("${General::swroot}/red/active");
624 if ($pppsettings{'TYPE'} =~ /^(modem|bewanadsl|conexantpciadsl|eagleusbadsl)$/) {
625 my $speed;
626 if ($pppsettings{'TYPE'} eq 'modem') {
627 open(CONNECTLOG, "/var/log/connect.log");
628 while (<CONNECTLOG>) {
629 if (/CONNECT/) {
630 $speed = (split / /)[6];
631 }
632 }
633 close (CONNECTLOG);
634 } elsif ($pppsettings{'TYPE'} eq 'bewanadsl') {
635 $speed = `/usr/bin/unicorn_status | /bin/grep Rate | /usr/bin/cut -f2 -d ':'`;
636 } elsif ($pppsettings{'TYPE'} eq 'conexantpciadsl') {
637 $speed = `/bin/cat /proc/net/atm/CnxAdsl:* | /bin/grep 'Line Rates' | /bin/sed -e 's+Line Rates: Receive+Rx+' -e 's+Transmit+Tx+'`;
638 } elsif ($pppsettings{'TYPE'} eq 'eagleusbadsl') {
639 $speed = `/usr/sbin/eaglestat | /bin/grep Rate`;
640 }
641 $connstate = "<span class='ipcop_StatusBig'>$Lang::tr{'connected'} (<span class='ipcop_StatusBigRed'>$timestr</span>) $profileused (\@$speed)</span>";
642 } else {
643 $connstate = "<span class='ipcop_StatusBig'>$Lang::tr{'connected'} (<span class='ipcop_StatusBigRed'>$timestr</span>) $profileused</span>";
644 }
645 } else {
646 if (-e "${General::swroot}/red/dial-on-demand") {
647 $connstate = "<span class='ipcop_StatusBig'>$Lang::tr{'dod waiting'} $profileused</span>";
648 } else {
649 $connstate = "<span class='ipcop_StatusBig'>$Lang::tr{'connecting'} $profileused</span>";
650 }
651 }
652 } else {
653 $connstate = "<span class='ipcop_StatusBig'>$Lang::tr{'idle'} $profileused</span>";
654 }
655 return $connstate;
656 }
657
658 sub speedtouchversion
659 {
660 my $speedtouch;
661 if (-f "/proc/bus/usb/devices")
662 {
663 $speedtouch=`/bin/cat /proc/bus/usb/devices | /bin/grep 'Vendor=06b9 ProdID=4061' | /usr/bin/cut -d ' ' -f6`;
664 if ($speedtouch eq '') {
665 $speedtouch= $Lang::tr{'connect the modem'};
666 }
667 } else {
668 $speedtouch='USB '.$Lang::tr{'not running'};
669 }
670 return $speedtouch
671 }
672
673 #Sorting of allocated leases
674 sub CheckSortOrder {
675 my %dhcpsettings = ();
676 &General::readhash("${General::swroot}/dhcp/settings", \%dhcpsettings);
677
678 if ($ENV{'QUERY_STRING'} =~ /^IPADDR|^ETHER|^HOSTNAME|^ENDTIME/ ) {
679 my $newsort=$ENV{'QUERY_STRING'};
680 my $act=$dhcpsettings{'SORT_LEASELIST'};
681 #Default sort if unspecified
682 $act='IPADDRRev' if !defined ($act);
683 #Reverse actual ?
684 if ($act =~ $newsort) {
685 my $Rev='';
686 if ($act !~ 'Rev') {$Rev='Rev'};
687 $newsort.=$Rev
688 };
689
690 $dhcpsettings{'SORT_LEASELIST'}=$newsort;
691 &General::writehash("${General::swroot}/dhcp/settings", \%dhcpsettings);
692 }
693 }
694
695 sub PrintActualLeases
696 {
697 our %dhcpsettings = ();
698 our %entries = ();
699
700 sub leasesort {
701 my $qs ='';
702 if (rindex ($dhcpsettings{'SORT_LEASELIST'},'Rev') != -1)
703 {
704 $qs=substr ($dhcpsettings{'SORT_LEASELIST'},0,length($dhcpsettings{'SORT_LEASELIST'})-3);
705 if ($qs eq 'IPADDR') {
706 my @a = split(/\./,$entries{$a}->{$qs});
707 my @b = split(/\./,$entries{$b}->{$qs});
708 ($b[0]<=>$a[0]) ||
709 ($b[1]<=>$a[1]) ||
710 ($b[2]<=>$a[2]) ||
711 ($b[3]<=>$a[3]);
712 }else {
713 $entries{$b}->{$qs} cmp $entries{$a}->{$qs};
714 }
715 }
716 else #not reverse
717 {
718 $qs=$dhcpsettings{'SORT_LEASELIST'};
719 if ($qs eq 'IPADDR') {
720 my @a = split(/\./,$entries{$a}->{$qs});
721 my @b = split(/\./,$entries{$b}->{$qs});
722 ($a[0]<=>$b[0]) ||
723 ($a[1]<=>$b[1]) ||
724 ($a[2]<=>$b[2]) ||
725 ($a[3]<=>$b[3]);
726 }else {
727 $entries{$a}->{$qs} cmp $entries{$b}->{$qs};
728 }
729 }
730 }
731
732 &Header::openbox('100%', 'left', $Lang::tr{'current dynamic leases'});
733 print <<END
734 <table width='100%'>
735 <tr>
736 <td width='25%' align='center'><a href='$ENV{'SCRIPT_NAME'}?IPADDR'><b>$Lang::tr{'ip address'}</b></a></td>
737 <td width='25%' align='center'><a href='$ENV{'SCRIPT_NAME'}?ETHER'><b>$Lang::tr{'mac address'}</b></a></td>
738 <td width='20%' align='center'><a href='$ENV{'SCRIPT_NAME'}?HOSTNAME'><b>$Lang::tr{'hostname'}</b></a></td>
739 <td width='30%' align='center'><a href='$ENV{'SCRIPT_NAME'}?ENDTIME'><b>$Lang::tr{'lease expires'} (local time d/m/y)</b></a></td>
740 </tr>
741 END
742 ;
743
744 my ($ip, $endtime, $ether, $hostname, @record, $record);
745 open(LEASES,"/var/state/dhcp/dhcpd.leases") or die "Can't open dhcpd.leases";
746 while (my $line = <LEASES>) {
747 next if( $line =~ /^\s*#/ );
748 chomp($line);
749 my @temp = split (' ', $line);
750
751 if ($line =~ /^\s*lease/) {
752 $ip = $temp[1];
753 #All field are not necessarily read. Clear everything
754 $endtime = 0;
755 $ether = "";
756 $hostname = "";
757 } elsif ($line =~ /^\s*ends never;/) {
758 $endtime = 'never';
759 } elsif ($line =~ /^\s*ends/) {
760 $line =~ /(\d+)\/(\d+)\/(\d+) (\d+):(\d+):(\d+)/;
761 $endtime = timegm($6, $5, $4, $3, $2 - 1, $1 - 1900);
762 } elsif ($line =~ /^\s*hardware ethernet/) {
763 $ether = $temp[2];
764 $ether =~ s/;//g;
765 } elsif ($line =~ /^\s*client-hostname/) {
766 shift (@temp);
767 $hostname = join (' ',@temp);
768 $hostname =~ s/;//g;
769 $hostname =~ s/\"//g;
770 } elsif ($line eq "}") {
771 @record = ('IPADDR',$ip,'ENDTIME',$endtime,'ETHER',$ether,'HOSTNAME',$hostname);
772 $record = {}; # create a reference to empty hash
773 %{$record} = @record; # populate that hash with @record
774 $entries{$record->{'IPADDR'}} = $record; # add this to a hash of hashes
775 } #unknown format line...
776 }
777 close(LEASES);
778
779 #Get sort method
780 $dhcpsettings{'SORT_LEASELIST'}='IPADDR'; #default
781 &General::readhash("${General::swroot}/dhcp/settings", \%dhcpsettings); #or maybe saved !
782 my $id = 0;
783 foreach my $key (sort leasesort keys %entries) {
784
785 my $hostname = &Header::cleanhtml($entries{$key}->{HOSTNAME},"y");
786
787 if ($id % 2) {
788 print "<tr bgcolor='$Header::table1colour'>";
789 }
790 else {
791 print "<tr bgcolor='$Header::table2colour'>";
792 }
793
794 print <<END
795 <td align='center'>$entries{$key}->{IPADDR}</td>
796 <td align='center'>$entries{$key}->{ETHER}</td>
797 <td align='center'>&nbsp;$hostname </td>
798 <td align='center'>
799 END
800 ;
801
802 if ($entries{$key}->{ENDTIME} eq 'never') {
803 print "$Lang::tr{'no time limit'}";
804 } else {
805 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $dst);
806 ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $dst) = localtime ($entries{$key}->{ENDTIME});
807 my $enddate = sprintf ("%02d/%02d/%d %02d:%02d:%02d",$mday,$mon+1,$year+1900,$hour,$min,$sec);
808
809 if ($entries{$key}->{ENDTIME} < time() ){
810 print "<strike>$enddate</strike>";
811 } else {
812 print "$enddate";
813 }
814 }
815 print "</td></tr>";
816 $id++;
817 }
818
819 print "</table>";
820 &Header::closebox();
821 }
822
823 1;