]>
Commit | Line | Data |
---|---|---|
3ea75603 MT |
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 | # | |
3ea75603 MT |
12 | package Header; |
13 | ||
14 | use CGI(); | |
802d7954 | 15 | use File::Basename; |
8b33e596 | 16 | use HTML::Entities(); |
3ea75603 MT |
17 | use Socket; |
18 | use Time::Local; | |
19 | ||
a84b9ed2 AB |
20 | our %color = (); |
21 | &General::readhash("/srv/web/ipfire/html/themes/ipfire/include/colors.txt", \%color); | |
22 | ||
3ea75603 MT |
23 | $|=1; # line buffering |
24 | ||
3ea75603 MT |
25 | $Header::revision = 'final'; |
26 | $Header::swroot = '/var/ipfire'; | |
0d909a4a | 27 | $Header::graphdir='/srv/web/ipfire/html/graphs'; |
3ea75603 | 28 | $Header::pagecolour = '#ffffff'; |
dbf1d163 MT |
29 | $Header::bordercolour = '#363636'; |
30 | $Header::table1colour = '#f5f5f5'; | |
31 | $Header::table2colour = '#fafafa'; | |
3ea75603 MT |
32 | $Header::colourred = '#993333'; |
33 | $Header::colourorange = '#FF9933'; | |
34 | $Header::colouryellow = '#FFFF00'; | |
35 | $Header::colourgreen = '#339933'; | |
36 | $Header::colourblue = '#333399'; | |
6d4147d2 | 37 | $Header::colourovpn = '#339999'; |
3ea75603 MT |
38 | $Header::colourfw = '#000000'; |
39 | $Header::colourvpn = '#990099'; | |
40 | $Header::colourerr = '#FF0000'; | |
41 | $Header::viewsize = 150; | |
42 | $Header::errormessage = ''; | |
de4dea96 AB |
43 | $Header::extraHead = <<END |
44 | <style> | |
d3aec718 | 45 | .color20 { |
de4dea96 AB |
46 | background-color: $color{'color20'}; |
47 | } | |
d3aec718 | 48 | .color22 { |
de4dea96 AB |
49 | background-color: $color{'color22'}; |
50 | } | |
d3aec718 | 51 | .colouryellow { |
de4dea96 AB |
52 | background-color: $Header::colouryellow; |
53 | } | |
d3aec718 | 54 | .orange { |
de4dea96 | 55 | background-color: orange; |
b52a84dd | 56 | } |
d3aec718 | 57 | .red { |
b52a84dd | 58 | background-color: red; |
de4dea96 | 59 | } |
14051bfe AB |
60 | .table1colour { |
61 | background-color: $Header::table1colour; | |
62 | } | |
63 | .table2colour { | |
64 | background-color: $Header::table2colour; | |
65 | } | |
66 | .percent-box { | |
67 | border-style: solid; | |
68 | border-width: 1px; | |
69 | border-color: #a0a0a0; | |
70 | width: 100px; | |
71 | height: 10px; | |
72 | } | |
73 | .percent-bar { | |
74 | background-color: #a0a0a0; | |
75 | border-style: solid; | |
76 | border-width: 1px; | |
77 | border-color: #e2e2e2; | |
78 | } | |
79 | .percent-space { | |
80 | background-color: #e2e2e2; | |
81 | border-style: solid; | |
82 | border-width: 1px; | |
83 | border-color: #e2e2e2; | |
84 | } | |
de4dea96 AB |
85 | </style> |
86 | END | |
87 | ; | |
3ea75603 MT |
88 | my %menuhash = (); |
89 | my $menu = \%menuhash; | |
90 | %settings = (); | |
91 | %ethsettings = (); | |
d4af74b7 | 92 | %pppsettings = (); |
c13060fd | 93 | my @URI = split('\?', $ENV{'REQUEST_URI'}); |
3ea75603 MT |
94 | |
95 | ### Make sure this is an SSL request | |
96 | if ($ENV{'SERVER_ADDR'} && $ENV{'HTTPS'} ne 'on') { | |
97 | print "Status: 302 Moved\r\n"; | |
f8e080ef | 98 | print "Location: https://$ENV{'SERVER_ADDR'}:444/$ENV{'PATH_INFO'}\r\n\r\n"; |
3ea75603 MT |
99 | exit 0; |
100 | } | |
101 | ||
102 | ### Initialize environment | |
6be4dd24 CS |
103 | &General::readhash("${swroot}/main/settings", \%settings); |
104 | &General::readhash("${swroot}/ethernet/settings", \%ethsettings); | |
d4af74b7 | 105 | &General::readhash("${swroot}/ppp/settings", \%pppsettings); |
3ea75603 MT |
106 | $hostname = $settings{'HOSTNAME'}; |
107 | $hostnameintitle = 0; | |
108 | ||
109 | ### Initialize language | |
b02ba841 MT |
110 | require "${swroot}/lang.pl"; |
111 | $language = &Lang::FindWebLanguage($settings{"LANGUAGE"}); | |
3ea75603 MT |
112 | |
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}"; | |
122 | }; | |
123 | }; | |
124 | ||
125 | ||
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}"; | |
135 | }; | |
136 | }; | |
137 | ||
b0323d19 LAH |
138 | ### Initialize user manual |
139 | my %manualpages = (); | |
64db1faf | 140 | &_read_manualpage_hash("${General::swroot}/main/manualpages"); |
935f311e | 141 | |
b0323d19 | 142 | ### Load selected language and theme functions |
3ea75603 MT |
143 | require "${swroot}/langs/en.pl"; |
144 | require "${swroot}/langs/${language}.pl"; | |
8186b372 | 145 | eval `/bin/cat /srv/web/ipfire/html/themes/ipfire/include/functions.pl`; |
3ea75603 | 146 | |
080e79f1 MT |
147 | sub green_used() { |
148 | if ($ethsettings{'GREEN_DEV'} && $ethsettings{'GREEN_DEV'} ne "") { | |
149 | return 1; | |
150 | } | |
151 | ||
152 | return 0; | |
153 | } | |
154 | ||
3ea75603 | 155 | sub orange_used () { |
6be4dd24 | 156 | if ($ethsettings{'CONFIG_TYPE'} =~ /^[24]$/) { |
3ea75603 MT |
157 | return 1; |
158 | } | |
159 | return 0; | |
160 | } | |
161 | ||
162 | sub blue_used () { | |
6be4dd24 | 163 | if ($ethsettings{'CONFIG_TYPE'} =~ /^[34]$/) { |
3ea75603 MT |
164 | return 1; |
165 | } | |
166 | return 0; | |
167 | } | |
168 | ||
169 | sub is_modem { | |
6be4dd24 | 170 | if ($ethsettings{'CONFIG_TYPE'} =~ /^[0]$/) { |
3ea75603 MT |
171 | return 1; |
172 | } | |
173 | return 0; | |
174 | } | |
175 | ||
176 | ### Initialize menu | |
177 | sub genmenu { | |
24249567 | 178 | |
3ea75603 MT |
179 | my %subsystemhash = (); |
180 | my $subsystem = \%subsystemhash; | |
181 | ||
3ea75603 MT |
182 | my %substatushash = (); |
183 | my $substatus = \%substatushash; | |
3ea75603 MT |
184 | |
185 | my %subnetworkhash = (); | |
186 | my $subnetwork = \%subnetworkhash; | |
187 | ||
3ea75603 MT |
188 | my %subserviceshash = (); |
189 | my $subservices = \%subserviceshash; | |
190 | ||
3ea75603 MT |
191 | my %subfirewallhash = (); |
192 | my $subfirewall = \%subfirewallhash; | |
193 | ||
3ea75603 MT |
194 | my %subipfirehash = (); |
195 | my $subipfire = \%subipfirehash; | |
3ea75603 | 196 | |
24249567 MT |
197 | my %sublogshash = (); |
198 | my $sublogs = \%sublogshash; | |
3ea75603 | 199 | |
b2161869 AF |
200 | if ( -e "/var/ipfire/main/gpl_accepted") { |
201 | ||
24249567 MT |
202 | eval `/bin/cat /var/ipfire/menu.d/*.menu`; |
203 | eval `/bin/cat /var/ipfire/menu.d/*.main`; | |
3ea75603 | 204 | |
c980f4d2 | 205 | if (! blue_used()) { |
a615cab3 | 206 | $menu->{'05.firewall'}{'subMenu'}->{'60.wireless'}{'enabled'} = 0; |
c980f4d2 | 207 | } |
6be4dd24 | 208 | if ( $ethsettings{'CONFIG_TYPE'} =~ /^(1|2|3|4)$/ && $ethsettings{'RED_TYPE'} eq 'STATIC' ) { |
a68fedca | 209 | $menu->{'03.network'}{'subMenu'}->{'70.aliases'}{'enabled'} = 1; |
3ea75603 | 210 | } |
61027579 MT |
211 | |
212 | if (&General::RedIsWireless()) { | |
213 | $menu->{'01.system'}{'subMenu'}->{'21.wlan'}{'enabled'} = 1; | |
214 | } | |
c5e3d520 | 215 | |
d4af74b7 | 216 | if ( $ethsettings{'RED_TYPE'} eq "PPPOE" && $pppsettings{'MONPORT'} ne "" ) { |
c5e3d520 MT |
217 | $menu->{'02.status'}{'subMenu'}->{'74.modem-status'}{'enabled'} = 1; |
218 | } | |
dc845b6c | 219 | |
9db81dc9 LAH |
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; | |
224 | } | |
225 | ||
46b0f9ab MT |
226 | # Disbale unusable things in cloud environments |
227 | if (&General::running_in_cloud()) { | |
dc845b6c MT |
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; | |
231 | } | |
b2161869 | 232 | } |
3ea75603 MT |
233 | } |
234 | ||
235 | sub showhttpheaders | |
236 | { | |
c43ae64f | 237 | print "Cache-control: private\n"; |
1d795ec5 | 238 | print "Content-type: text/html; charset=UTF-8\n\n"; |
3ea75603 MT |
239 | } |
240 | ||
241 | sub is_menu_visible($) { | |
242 | my $link = shift; | |
243 | $link =~ s#\?.*$##; | |
244 | return (-e $ENV{'DOCUMENT_ROOT'}."/../$link"); | |
245 | } | |
246 | ||
247 | ||
248 | sub getlink($) { | |
249 | my $root = shift; | |
250 | if (! $root->{'enabled'}) { | |
251 | return ''; | |
252 | } | |
253 | if ($root->{'uri'} !~ /^$/) { | |
254 | my $vars = ''; | |
255 | if ($root->{'vars'} !~ /^$/) { | |
256 | $vars = '?'. $root->{'vars'}; | |
257 | } | |
258 | if (! is_menu_visible($root->{'uri'})) { | |
259 | return ''; | |
260 | } | |
261 | return $root->{'uri'}.$vars; | |
262 | } | |
263 | my $submenus = $root->{'subMenu'}; | |
264 | if (! $submenus) { | |
265 | return ''; | |
266 | } | |
267 | foreach my $item (sort keys %$submenus) { | |
268 | my $link = getlink($submenus->{$item}); | |
269 | if ($link ne '') { | |
270 | return $link; | |
271 | } | |
272 | } | |
273 | return ''; | |
274 | } | |
275 | ||
276 | ||
277 | sub compare_url($) { | |
278 | my $conf = shift; | |
279 | ||
280 | my $uri = $conf->{'uri'}; | |
281 | my $vars = $conf->{'vars'}; | |
282 | my $novars = $conf->{'novars'}; | |
283 | ||
284 | if ($uri eq '') { | |
285 | return 0; | |
286 | } | |
287 | if ($uri ne $URI[0]) { | |
288 | return 0; | |
289 | } | |
290 | if ($novars) { | |
291 | if ($URI[1] !~ /^$/) { | |
292 | return 0; | |
293 | } | |
294 | } | |
295 | if (! $vars) { | |
296 | return 1; | |
297 | } | |
298 | return ($URI[1] eq $vars); | |
299 | } | |
300 | ||
301 | ||
302 | sub gettitle($) { | |
303 | my $root = shift; | |
304 | ||
305 | if (! $root) { | |
306 | return ''; | |
307 | } | |
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'}; | |
314 | } | |
315 | return 'EMPTY TITLE'; | |
316 | } | |
317 | ||
318 | my $title = gettitle($val->{'subMenu'}); | |
319 | if ($title ne '') { | |
320 | $val->{'selected'} = 1; | |
321 | return $title; | |
322 | } | |
323 | } | |
324 | return ''; | |
325 | } | |
326 | ||
3ea75603 MT |
327 | sub getcgihash { |
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; | |
cc26ba71 | 334 | $CGI::POST_MAX = 1024 * 1024; |
3ea75603 MT |
335 | } else { |
336 | $CGI::POST_MAX = 10 * 1024 * 1024; | |
337 | } | |
338 | ||
339 | $cgi->referer() =~ m/^https?\:\/\/([^\/]+)/; | |
340 | my $referer = $1; | |
341 | $cgi->url() =~ m/^https?\:\/\/([^\/]+)/; | |
342 | my $servername = $1; | |
343 | return if ($referer ne $servername); | |
344 | ||
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/; | |
351 | } | |
352 | ||
353 | if (($params->{'wantfile'})&&($params->{'filevar'})) { | |
354 | $hash->{$params->{'filevar'}} = $cgi->upload | |
355 | ($params->{'filevar'}); | |
356 | } | |
357 | return; | |
358 | } | |
359 | ||
8b33e596 MT |
360 | sub escape($) { |
361 | my $s = shift; | |
362 | return HTML::Entities::encode_entities($s); | |
363 | } | |
364 | ||
365 | sub cleanhtml { | |
3ea75603 MT |
366 | my $outstring =$_[0]; |
367 | $outstring =~ tr/,/ / if not defined $_[1] or $_[1] ne 'y'; | |
8b33e596 MT |
368 | |
369 | return escape($outstring); | |
3ea75603 | 370 | } |
986e08d9 | 371 | |
3ea75603 MT |
372 | sub connectionstatus |
373 | { | |
986e08d9 MT |
374 | my %pppsettings = (); |
375 | my %netsettings = (); | |
376 | my $iface=''; | |
377 | ||
378 | $pppsettings{'PROFILENAME'} = 'None'; | |
379 | &General::readhash("${General::swroot}/ppp/settings", \%pppsettings); | |
380 | &General::readhash("${General::swroot}/ethernet/settings", \%netsettings); | |
381 | ||
382 | my $profileused=''; | |
2fc53b15 | 383 | unless ( $netsettings{'RED_TYPE'} =~ /^(DHCP|STATIC)$/ ) { |
986e08d9 MT |
384 | $profileused="- $pppsettings{'PROFILENAME'}"; |
385 | } | |
386 | ||
986e08d9 | 387 | my ($timestr, $connstate); |
986e08d9 | 388 | |
7f9f8516 | 389 | my $connstate = "<span>$Lang::tr{'idle'} $profileused</span>"; |
986e08d9 | 390 | |
2fc53b15 MT |
391 | if (-e "${General::swroot}/red/active") { |
392 | $timestr = &General::age("${General::swroot}/red/active"); | |
7f9f8516 | 393 | $connstate = "<span>$Lang::tr{'connected'} - (<span>$timestr</span>) $profileused</span>"; |
2fc53b15 | 394 | } else { |
7f9f8516 CS |
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>"; | |
986e08d9 | 399 | } else { |
7f9f8516 | 400 | $connstate = "<span>$Lang::tr{'connecting'} $profileused</span>" if (system("ps -ef | grep -q '[p]ppd'")); |
986e08d9 | 401 | } |
986e08d9 | 402 | } |
2fc53b15 | 403 | |
3ea75603 MT |
404 | return $connstate; |
405 | } | |
406 | ||
3ea75603 MT |
407 | sub CheckSortOrder { |
408 | #Sorting of allocated leases | |
409 | if ($ENV{'QUERY_STRING'} =~ /^IPADDR|^ETHER|^HOSTNAME|^ENDTIME/ ) { | |
6be4dd24 | 410 | my $newsort=$ENV{'QUERY_STRING'}; |
cab84d3a | 411 | &General::readhash("${swroot}/dhcp/settings", \%dhcpsettings); |
3ea75603 MT |
412 | $act=$dhcpsettings{'SORT_LEASELIST'}; |
413 | #Reverse actual ? | |
414 | if ($act =~ $newsort) { | |
415 | if ($act !~ 'Rev') {$Rev='Rev'}; | |
416 | $newsort.=$Rev | |
417 | }; | |
418 | ||
419 | $dhcpsettings{'SORT_LEASELIST'}=$newsort; | |
cab84d3a | 420 | &General::writehash("${swroot}/dhcp/settings", \%dhcpsettings); |
3ea75603 MT |
421 | $dhcpsettings{'ACTION'} = 'SORT'; # avoid the next test "First lauch" |
422 | } | |
423 | ||
424 | } | |
425 | ||
426 | sub PrintActualLeases | |
427 | { | |
4c19f215 | 428 | &openbox('100%', 'left', $Lang::tr{'current dynamic leases'}); |
3ea75603 | 429 | print <<END |
52ca3c80 | 430 | <table width='100%' class='tbl'> |
3ea75603 | 431 | <tr> |
4c19f215 LAH |
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> | |
3ea75603 MT |
437 | </tr> |
438 | END | |
52ca3c80 | 439 | ; |
3ea75603 | 440 | |
986e08d9 | 441 | open(LEASES,"/var/state/dhcp/dhcpd.leases") or die "Can't open dhcpd.leases"; |
934a3769 LAH |
442 | while (my $line = <LEASES>) { |
443 | next if( $line =~ /^\s*#/ ); | |
444 | chomp($line); | |
445 | @temp = split (' ', $line); | |
446 | ||
447 | if ($line =~ /^\s*lease/) { | |
448 | $ip = $temp[1]; | |
449 | #All field are not necessarily read. Clear everything | |
450 | $endtime = 0; | |
c27b8825 LAH |
451 | $endtime_print = ""; |
452 | $expired = 0; | |
934a3769 LAH |
453 | $ether = ""; |
454 | $hostname = ""; | |
455 | } | |
3ea75603 | 456 | |
934a3769 LAH |
457 | if ($line =~ /^\s*ends/) { |
458 | $line =~ /(\d+)\/(\d+)\/(\d+) (\d+):(\d+):(\d+)/; | |
459 | $endtime = timegm($6, $5, $4, $3, $2 - 1, $1 - 1900); | |
c27b8825 LAH |
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(); | |
934a3769 | 463 | } |
3ea75603 | 464 | |
934a3769 LAH |
465 | if ($line =~ /^\s*hardware ethernet/) { |
466 | $ether = $temp[2]; | |
467 | $ether =~ s/;//g; | |
468 | } | |
3ea75603 | 469 | |
934a3769 LAH |
470 | if ($line =~ /^\s*client-hostname/) { |
471 | $hostname = "$temp[1] $temp[2] $temp[3]"; | |
c27b8825 | 472 | $hostname =~ s/\"|[;\s]+?$//g; # remove quotes, trim semicolon and white space |
934a3769 | 473 | } |
3ea75603 | 474 | |
934a3769 | 475 | if ($line eq "}") { |
c27b8825 | 476 | @record = ('IPADDR',$ip,'ENDTIME',$endtime,'ETHER',$ether,'HOSTNAME',$hostname,'endtime_print',$endtime_print,'expired',$expired); |
934a3769 LAH |
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 | |
480 | } | |
3ea75603 MT |
481 | } |
482 | close(LEASES); | |
483 | ||
484 | my $id = 0; | |
934a3769 | 485 | my $col = ""; |
c27b8825 | 486 | my $divider_printed = 0; |
3ea75603 | 487 | foreach my $key (sort leasesort keys %entries) { |
934a3769 | 488 | my $hostname = &cleanhtml($entries{$key}->{HOSTNAME},"y"); |
c27b8825 LAH |
489 | my $hostname_print = $hostname; |
490 | if($hostname_print eq "") { #print blank space if no hostname is found | |
491 | $hostname_print = " "; | |
492 | } | |
493 | ||
494 | # separate active and expired leases with a horizontal line | |
495 | if(($entries{$key}->{expired}) && ($divider_printed == 0)) { | |
496 | $divider_printed = 1; | |
497 | if ($id % 2) { | |
498 | print "<tr><td colspan='5' bgcolor='$table1colour'><hr size='1'></td></tr>\n"; | |
499 | } else { | |
500 | print "<tr><td colspan='5' bgcolor='$table2colour'><hr size='1'></td></tr>\n"; | |
501 | } | |
502 | $id++; | |
503 | } | |
504 | ||
505 | print "<form method='post' action='/cgi-bin/dhcp.cgi'><tr>\n"; | |
934a3769 | 506 | if ($id % 2) { |
934a3769 LAH |
507 | $col="bgcolor='$table1colour'"; |
508 | } else { | |
934a3769 LAH |
509 | $col="bgcolor='$table2colour'"; |
510 | } | |
c27b8825 LAH |
511 | |
512 | if($entries{$key}->{expired}) { | |
513 | print <<END | |
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> | |
518 | END | |
519 | ; | |
520 | } else { | |
521 | print <<END | |
52ca3c80 AM |
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> | |
c27b8825 LAH |
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> | |
3ea75603 | 526 | END |
52ca3c80 | 527 | ; |
934a3769 | 528 | } |
c27b8825 | 529 | |
934a3769 | 530 | print <<END |
c27b8825 LAH |
531 | <td $col><input type='hidden' name='ACTION' value='$Lang::tr{'add'}2' /><input type='submit' name='SUBMIT' value='$Lang::tr{'add'}' /></td> |
532 | </tr></form> | |
32fdd7d9 | 533 | END |
52ca3c80 | 534 | ; |
934a3769 | 535 | $id++; |
3ea75603 MT |
536 | } |
537 | ||
538 | print "</table>"; | |
539 | &closebox(); | |
540 | } | |
541 | ||
542 | ||
543 | # This sub is used during display of actives leases | |
544 | sub leasesort { | |
934a3769 LAH |
545 | if (rindex ($dhcpsettings{'SORT_LEASELIST'},'Rev') != -1) |
546 | { | |
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}); | |
c27b8825 | 551 | $entries{$a}->{'expired'} <=> $entries{$b}->{'expired'} || # always sort by expiration first |
934a3769 LAH |
552 | ($b[0]<=>$a[0]) || |
553 | ($b[1]<=>$a[1]) || | |
554 | ($b[2]<=>$a[2]) || | |
555 | ($b[3]<=>$a[3]); | |
556 | } else { | |
c27b8825 | 557 | $entries{$a}->{'expired'} <=> $entries{$b}->{'expired'} || |
934a3769 LAH |
558 | $entries{$b}->{$qs} cmp $entries{$a}->{$qs}; |
559 | } | |
560 | } | |
561 | else #not reverse | |
562 | { | |
563 | $qs=$dhcpsettings{'SORT_LEASELIST'}; | |
564 | if ($qs eq 'IPADDR') { | |
565 | @a = split(/\./,$entries{$a}->{$qs}); | |
566 | @b = split(/\./,$entries{$b}->{$qs}); | |
c27b8825 | 567 | $entries{$a}->{'expired'} <=> $entries{$b}->{'expired'} || |
934a3769 LAH |
568 | ($a[0]<=>$b[0]) || |
569 | ($a[1]<=>$b[1]) || | |
570 | ($a[2]<=>$b[2]) || | |
571 | ($a[3]<=>$b[3]); | |
572 | } else { | |
c27b8825 | 573 | $entries{$a}->{'expired'} <=> $entries{$b}->{'expired'} || |
934a3769 LAH |
574 | $entries{$a}->{$qs} cmp $entries{$b}->{$qs}; |
575 | } | |
3ea75603 | 576 | } |
3ea75603 | 577 | } |
1ddefbbd CS |
578 | |
579 | sub colorize { | |
580 | my $string = $_[0]; | |
581 | my @array = split(/\//,$string); | |
582 | my $string2 = $array[0]; | |
583 | ||
584 | if ( $string eq "*" or $string eq "" ){ | |
585 | return $string; | |
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>"; | |
56d37c8d | 592 | } elsif ( $string =~ $ethsettings{'GREEN_DEV'} or &General::IpInSubnet($string2,$ethsettings{'GREEN_NETADDRESS'},$ethsettings{'GREEN_NETMASK'}) ){ |
1ddefbbd CS |
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>"; | |
56d37c8d | 596 | } elsif ( $ethsettings{'CONFIG_TYPE'}>1 and ( $string =~ $ethsettings{'BLUE_DEV'} or &General::IpInSubnet($string2,$ethsettings{'BLUE_NETADDRESS'},$ethsettings{'BLUE_NETMASK'}) )){ |
1ddefbbd | 597 | return "<font color='".${Header::colourblue}."'>".$string."</font>"; |
56d37c8d | 598 | } elsif ( $ethsettings{'CONFIG_TYPE'}>2 and ( $string =~ $ethsettings{'ORANGE_DEV'} or &General::IpInSubnet($string2,$ethsettings{'ORANGE_NETADDRESS'},$ethsettings{'ORANGE_NETMASK'}) )){ |
1ddefbbd CS |
599 | return "<font color='".${Header::colourorange}."'>".$string."</font>"; |
600 | } else { | |
601 | return $string; | |
602 | } | |
603 | } | |
b0323d19 | 604 | |
64db1faf LAH |
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 | |
b0323d19 | 608 | sub get_manualpage_url() { |
64db1faf LAH |
609 | my ($cgifile) = @_; |
610 | $cgifile //= substr($ENV{'SCRIPT_NAME'}, 9); # remove fixed "/cgi-bin/" path | |
b0323d19 LAH |
611 | |
612 | # Ensure base url is configured | |
613 | return unless($manualpages{'BASE_URL'}); | |
614 | ||
615 | # Return URL | |
64db1faf LAH |
616 | if($cgifile && defined($manualpages{$cgifile})) { |
617 | return "$manualpages{'BASE_URL'}/$manualpages{$cgifile}"; | |
b0323d19 LAH |
618 | } |
619 | ||
620 | # No manual page configured, return nothing | |
621 | return; | |
622 | } | |
c13060fd | 623 | |
64db1faf LAH |
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() { | |
627 | my ($filename) = @_; | |
628 | ||
629 | open(my $file, "<", $filename) or return; # Fail silent | |
630 | while(my $line = <$file>) { | |
631 | chomp($line); | |
632 | next if(substr($line, 0, 1) eq '#'); # Skip comments | |
633 | next if(index($line, '=', 1) == -1); # Skip incomplete lines | |
634 | ||
635 | my($left, $value) = split(/=/, $line, 2); | |
636 | if($left =~ /^([[:alnum:]\/._-]+)$/) { | |
637 | my $key = $1; | |
638 | $manualpages{$key} = $value; | |
639 | } | |
640 | } | |
641 | close($file); | |
642 | } | |
643 | ||
c13060fd | 644 | 1; # End of package "Header" |