]>
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 | ||
20 | $|=1; # line buffering | |
21 | ||
3ea75603 MT |
22 | $Header::revision = 'final'; |
23 | $Header::swroot = '/var/ipfire'; | |
0d909a4a | 24 | $Header::graphdir='/srv/web/ipfire/html/graphs'; |
3ea75603 MT |
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'; | |
6d4147d2 | 38 | $Header::colourovpn = '#339999'; |
3ea75603 MT |
39 | $Header::colourfw = '#000000'; |
40 | $Header::colourvpn = '#990099'; | |
41 | $Header::colourerr = '#FF0000'; | |
42 | $Header::viewsize = 150; | |
43 | $Header::errormessage = ''; | |
44 | my %menuhash = (); | |
45 | my $menu = \%menuhash; | |
46 | %settings = (); | |
47 | %ethsettings = (); | |
d4af74b7 | 48 | %pppsettings = (); |
c13060fd | 49 | my @URI = split('\?', $ENV{'REQUEST_URI'}); |
3ea75603 MT |
50 | |
51 | ### Make sure this is an SSL request | |
52 | if ($ENV{'SERVER_ADDR'} && $ENV{'HTTPS'} ne 'on') { | |
53 | print "Status: 302 Moved\r\n"; | |
f8e080ef | 54 | print "Location: https://$ENV{'SERVER_ADDR'}:444/$ENV{'PATH_INFO'}\r\n\r\n"; |
3ea75603 MT |
55 | exit 0; |
56 | } | |
57 | ||
58 | ### Initialize environment | |
6be4dd24 CS |
59 | &General::readhash("${swroot}/main/settings", \%settings); |
60 | &General::readhash("${swroot}/ethernet/settings", \%ethsettings); | |
d4af74b7 | 61 | &General::readhash("${swroot}/ppp/settings", \%pppsettings); |
3ea75603 MT |
62 | $hostname = $settings{'HOSTNAME'}; |
63 | $hostnameintitle = 0; | |
64 | ||
65 | ### Initialize language | |
b02ba841 MT |
66 | require "${swroot}/lang.pl"; |
67 | $language = &Lang::FindWebLanguage($settings{"LANGUAGE"}); | |
3ea75603 MT |
68 | |
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}"; | |
78 | }; | |
79 | }; | |
80 | ||
81 | ||
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}"; | |
91 | }; | |
92 | }; | |
93 | ||
b0323d19 LAH |
94 | ### Initialize user manual |
95 | my %manualpages = (); | |
64db1faf | 96 | &_read_manualpage_hash("${General::swroot}/main/manualpages"); |
935f311e | 97 | |
b0323d19 | 98 | ### Load selected language and theme functions |
3ea75603 MT |
99 | require "${swroot}/langs/en.pl"; |
100 | require "${swroot}/langs/${language}.pl"; | |
8186b372 | 101 | eval `/bin/cat /srv/web/ipfire/html/themes/ipfire/include/functions.pl`; |
3ea75603 | 102 | |
080e79f1 MT |
103 | sub green_used() { |
104 | if ($ethsettings{'GREEN_DEV'} && $ethsettings{'GREEN_DEV'} ne "") { | |
105 | return 1; | |
106 | } | |
107 | ||
108 | return 0; | |
109 | } | |
110 | ||
3ea75603 | 111 | sub orange_used () { |
6be4dd24 | 112 | if ($ethsettings{'CONFIG_TYPE'} =~ /^[24]$/) { |
3ea75603 MT |
113 | return 1; |
114 | } | |
115 | return 0; | |
116 | } | |
117 | ||
118 | sub blue_used () { | |
6be4dd24 | 119 | if ($ethsettings{'CONFIG_TYPE'} =~ /^[34]$/) { |
3ea75603 MT |
120 | return 1; |
121 | } | |
122 | return 0; | |
123 | } | |
124 | ||
125 | sub is_modem { | |
6be4dd24 | 126 | if ($ethsettings{'CONFIG_TYPE'} =~ /^[0]$/) { |
3ea75603 MT |
127 | return 1; |
128 | } | |
129 | return 0; | |
130 | } | |
131 | ||
132 | ### Initialize menu | |
133 | sub genmenu { | |
24249567 | 134 | |
3ea75603 MT |
135 | my %subsystemhash = (); |
136 | my $subsystem = \%subsystemhash; | |
137 | ||
3ea75603 MT |
138 | my %substatushash = (); |
139 | my $substatus = \%substatushash; | |
3ea75603 MT |
140 | |
141 | my %subnetworkhash = (); | |
142 | my $subnetwork = \%subnetworkhash; | |
143 | ||
3ea75603 MT |
144 | my %subserviceshash = (); |
145 | my $subservices = \%subserviceshash; | |
146 | ||
3ea75603 MT |
147 | my %subfirewallhash = (); |
148 | my $subfirewall = \%subfirewallhash; | |
149 | ||
3ea75603 MT |
150 | my %subipfirehash = (); |
151 | my $subipfire = \%subipfirehash; | |
3ea75603 | 152 | |
24249567 MT |
153 | my %sublogshash = (); |
154 | my $sublogs = \%sublogshash; | |
3ea75603 | 155 | |
b2161869 AF |
156 | if ( -e "/var/ipfire/main/gpl_accepted") { |
157 | ||
24249567 MT |
158 | eval `/bin/cat /var/ipfire/menu.d/*.menu`; |
159 | eval `/bin/cat /var/ipfire/menu.d/*.main`; | |
3ea75603 | 160 | |
c980f4d2 | 161 | if (! blue_used()) { |
a615cab3 | 162 | $menu->{'05.firewall'}{'subMenu'}->{'60.wireless'}{'enabled'} = 0; |
c980f4d2 | 163 | } |
6be4dd24 | 164 | if ( $ethsettings{'CONFIG_TYPE'} =~ /^(1|2|3|4)$/ && $ethsettings{'RED_TYPE'} eq 'STATIC' ) { |
a68fedca | 165 | $menu->{'03.network'}{'subMenu'}->{'70.aliases'}{'enabled'} = 1; |
3ea75603 | 166 | } |
61027579 MT |
167 | |
168 | if (&General::RedIsWireless()) { | |
169 | $menu->{'01.system'}{'subMenu'}->{'21.wlan'}{'enabled'} = 1; | |
170 | } | |
c5e3d520 | 171 | |
d4af74b7 | 172 | if ( $ethsettings{'RED_TYPE'} eq "PPPOE" && $pppsettings{'MONPORT'} ne "" ) { |
c5e3d520 MT |
173 | $menu->{'02.status'}{'subMenu'}->{'74.modem-status'}{'enabled'} = 1; |
174 | } | |
dc845b6c | 175 | |
9db81dc9 LAH |
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; | |
180 | } | |
181 | ||
46b0f9ab MT |
182 | # Disbale unusable things in cloud environments |
183 | if (&General::running_in_cloud()) { | |
dc845b6c MT |
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; | |
187 | } | |
b2161869 | 188 | } |
3ea75603 MT |
189 | } |
190 | ||
191 | sub showhttpheaders | |
192 | { | |
c43ae64f | 193 | print "Cache-control: private\n"; |
1d795ec5 | 194 | print "Content-type: text/html; charset=UTF-8\n\n"; |
3ea75603 MT |
195 | } |
196 | ||
197 | sub is_menu_visible($) { | |
198 | my $link = shift; | |
199 | $link =~ s#\?.*$##; | |
200 | return (-e $ENV{'DOCUMENT_ROOT'}."/../$link"); | |
201 | } | |
202 | ||
203 | ||
204 | sub getlink($) { | |
205 | my $root = shift; | |
206 | if (! $root->{'enabled'}) { | |
207 | return ''; | |
208 | } | |
209 | if ($root->{'uri'} !~ /^$/) { | |
210 | my $vars = ''; | |
211 | if ($root->{'vars'} !~ /^$/) { | |
212 | $vars = '?'. $root->{'vars'}; | |
213 | } | |
214 | if (! is_menu_visible($root->{'uri'})) { | |
215 | return ''; | |
216 | } | |
217 | return $root->{'uri'}.$vars; | |
218 | } | |
219 | my $submenus = $root->{'subMenu'}; | |
220 | if (! $submenus) { | |
221 | return ''; | |
222 | } | |
223 | foreach my $item (sort keys %$submenus) { | |
224 | my $link = getlink($submenus->{$item}); | |
225 | if ($link ne '') { | |
226 | return $link; | |
227 | } | |
228 | } | |
229 | return ''; | |
230 | } | |
231 | ||
232 | ||
233 | sub compare_url($) { | |
234 | my $conf = shift; | |
235 | ||
236 | my $uri = $conf->{'uri'}; | |
237 | my $vars = $conf->{'vars'}; | |
238 | my $novars = $conf->{'novars'}; | |
239 | ||
240 | if ($uri eq '') { | |
241 | return 0; | |
242 | } | |
243 | if ($uri ne $URI[0]) { | |
244 | return 0; | |
245 | } | |
246 | if ($novars) { | |
247 | if ($URI[1] !~ /^$/) { | |
248 | return 0; | |
249 | } | |
250 | } | |
251 | if (! $vars) { | |
252 | return 1; | |
253 | } | |
254 | return ($URI[1] eq $vars); | |
255 | } | |
256 | ||
257 | ||
258 | sub gettitle($) { | |
259 | my $root = shift; | |
260 | ||
261 | if (! $root) { | |
262 | return ''; | |
263 | } | |
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'}; | |
270 | } | |
271 | return 'EMPTY TITLE'; | |
272 | } | |
273 | ||
274 | my $title = gettitle($val->{'subMenu'}); | |
275 | if ($title ne '') { | |
276 | $val->{'selected'} = 1; | |
277 | return $title; | |
278 | } | |
279 | } | |
280 | return ''; | |
281 | } | |
282 | ||
3ea75603 MT |
283 | sub getcgihash { |
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; | |
cc26ba71 | 290 | $CGI::POST_MAX = 1024 * 1024; |
3ea75603 MT |
291 | } else { |
292 | $CGI::POST_MAX = 10 * 1024 * 1024; | |
293 | } | |
294 | ||
295 | $cgi->referer() =~ m/^https?\:\/\/([^\/]+)/; | |
296 | my $referer = $1; | |
297 | $cgi->url() =~ m/^https?\:\/\/([^\/]+)/; | |
298 | my $servername = $1; | |
299 | return if ($referer ne $servername); | |
300 | ||
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/; | |
307 | } | |
308 | ||
309 | if (($params->{'wantfile'})&&($params->{'filevar'})) { | |
310 | $hash->{$params->{'filevar'}} = $cgi->upload | |
311 | ($params->{'filevar'}); | |
312 | } | |
313 | return; | |
314 | } | |
315 | ||
8b33e596 MT |
316 | sub escape($) { |
317 | my $s = shift; | |
318 | return HTML::Entities::encode_entities($s); | |
319 | } | |
320 | ||
321 | sub cleanhtml { | |
3ea75603 MT |
322 | my $outstring =$_[0]; |
323 | $outstring =~ tr/,/ / if not defined $_[1] or $_[1] ne 'y'; | |
8b33e596 MT |
324 | |
325 | return escape($outstring); | |
3ea75603 | 326 | } |
986e08d9 | 327 | |
3ea75603 MT |
328 | sub connectionstatus |
329 | { | |
986e08d9 MT |
330 | my %pppsettings = (); |
331 | my %netsettings = (); | |
332 | my $iface=''; | |
333 | ||
334 | $pppsettings{'PROFILENAME'} = 'None'; | |
335 | &General::readhash("${General::swroot}/ppp/settings", \%pppsettings); | |
336 | &General::readhash("${General::swroot}/ethernet/settings", \%netsettings); | |
337 | ||
338 | my $profileused=''; | |
2fc53b15 | 339 | unless ( $netsettings{'RED_TYPE'} =~ /^(DHCP|STATIC)$/ ) { |
986e08d9 MT |
340 | $profileused="- $pppsettings{'PROFILENAME'}"; |
341 | } | |
342 | ||
986e08d9 | 343 | my ($timestr, $connstate); |
986e08d9 | 344 | |
7f9f8516 | 345 | my $connstate = "<span>$Lang::tr{'idle'} $profileused</span>"; |
986e08d9 | 346 | |
2fc53b15 MT |
347 | if (-e "${General::swroot}/red/active") { |
348 | $timestr = &General::age("${General::swroot}/red/active"); | |
7f9f8516 | 349 | $connstate = "<span>$Lang::tr{'connected'} - (<span>$timestr</span>) $profileused</span>"; |
2fc53b15 | 350 | } else { |
7f9f8516 CS |
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>"; | |
986e08d9 | 355 | } else { |
7f9f8516 | 356 | $connstate = "<span>$Lang::tr{'connecting'} $profileused</span>" if (system("ps -ef | grep -q '[p]ppd'")); |
986e08d9 | 357 | } |
986e08d9 | 358 | } |
2fc53b15 | 359 | |
3ea75603 MT |
360 | return $connstate; |
361 | } | |
362 | ||
3ea75603 MT |
363 | sub CheckSortOrder { |
364 | #Sorting of allocated leases | |
365 | if ($ENV{'QUERY_STRING'} =~ /^IPADDR|^ETHER|^HOSTNAME|^ENDTIME/ ) { | |
6be4dd24 | 366 | my $newsort=$ENV{'QUERY_STRING'}; |
cab84d3a | 367 | &General::readhash("${swroot}/dhcp/settings", \%dhcpsettings); |
3ea75603 MT |
368 | $act=$dhcpsettings{'SORT_LEASELIST'}; |
369 | #Reverse actual ? | |
370 | if ($act =~ $newsort) { | |
371 | if ($act !~ 'Rev') {$Rev='Rev'}; | |
372 | $newsort.=$Rev | |
373 | }; | |
374 | ||
375 | $dhcpsettings{'SORT_LEASELIST'}=$newsort; | |
cab84d3a | 376 | &General::writehash("${swroot}/dhcp/settings", \%dhcpsettings); |
3ea75603 MT |
377 | $dhcpsettings{'ACTION'} = 'SORT'; # avoid the next test "First lauch" |
378 | } | |
379 | ||
380 | } | |
381 | ||
382 | sub PrintActualLeases | |
383 | { | |
4c19f215 | 384 | &openbox('100%', 'left', $Lang::tr{'current dynamic leases'}); |
3ea75603 | 385 | print <<END |
52ca3c80 | 386 | <table width='100%' class='tbl'> |
3ea75603 | 387 | <tr> |
4c19f215 LAH |
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> | |
3ea75603 MT |
393 | </tr> |
394 | END | |
52ca3c80 | 395 | ; |
3ea75603 | 396 | |
986e08d9 | 397 | open(LEASES,"/var/state/dhcp/dhcpd.leases") or die "Can't open dhcpd.leases"; |
934a3769 LAH |
398 | while (my $line = <LEASES>) { |
399 | next if( $line =~ /^\s*#/ ); | |
400 | chomp($line); | |
401 | @temp = split (' ', $line); | |
402 | ||
403 | if ($line =~ /^\s*lease/) { | |
404 | $ip = $temp[1]; | |
405 | #All field are not necessarily read. Clear everything | |
406 | $endtime = 0; | |
c27b8825 LAH |
407 | $endtime_print = ""; |
408 | $expired = 0; | |
934a3769 LAH |
409 | $ether = ""; |
410 | $hostname = ""; | |
411 | } | |
3ea75603 | 412 | |
934a3769 LAH |
413 | if ($line =~ /^\s*ends/) { |
414 | $line =~ /(\d+)\/(\d+)\/(\d+) (\d+):(\d+):(\d+)/; | |
415 | $endtime = timegm($6, $5, $4, $3, $2 - 1, $1 - 1900); | |
c27b8825 LAH |
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(); | |
934a3769 | 419 | } |
3ea75603 | 420 | |
934a3769 LAH |
421 | if ($line =~ /^\s*hardware ethernet/) { |
422 | $ether = $temp[2]; | |
423 | $ether =~ s/;//g; | |
424 | } | |
3ea75603 | 425 | |
934a3769 LAH |
426 | if ($line =~ /^\s*client-hostname/) { |
427 | $hostname = "$temp[1] $temp[2] $temp[3]"; | |
c27b8825 | 428 | $hostname =~ s/\"|[;\s]+?$//g; # remove quotes, trim semicolon and white space |
934a3769 | 429 | } |
3ea75603 | 430 | |
934a3769 | 431 | if ($line eq "}") { |
c27b8825 | 432 | @record = ('IPADDR',$ip,'ENDTIME',$endtime,'ETHER',$ether,'HOSTNAME',$hostname,'endtime_print',$endtime_print,'expired',$expired); |
934a3769 LAH |
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 | |
436 | } | |
3ea75603 MT |
437 | } |
438 | close(LEASES); | |
439 | ||
440 | my $id = 0; | |
934a3769 | 441 | my $col = ""; |
c27b8825 | 442 | my $divider_printed = 0; |
3ea75603 | 443 | foreach my $key (sort leasesort keys %entries) { |
934a3769 | 444 | my $hostname = &cleanhtml($entries{$key}->{HOSTNAME},"y"); |
c27b8825 LAH |
445 | my $hostname_print = $hostname; |
446 | if($hostname_print eq "") { #print blank space if no hostname is found | |
447 | $hostname_print = " "; | |
448 | } | |
449 | ||
450 | # separate active and expired leases with a horizontal line | |
451 | if(($entries{$key}->{expired}) && ($divider_printed == 0)) { | |
452 | $divider_printed = 1; | |
453 | if ($id % 2) { | |
454 | print "<tr><td colspan='5' bgcolor='$table1colour'><hr size='1'></td></tr>\n"; | |
455 | } else { | |
456 | print "<tr><td colspan='5' bgcolor='$table2colour'><hr size='1'></td></tr>\n"; | |
457 | } | |
458 | $id++; | |
459 | } | |
460 | ||
461 | print "<form method='post' action='/cgi-bin/dhcp.cgi'><tr>\n"; | |
934a3769 | 462 | if ($id % 2) { |
934a3769 LAH |
463 | $col="bgcolor='$table1colour'"; |
464 | } else { | |
934a3769 LAH |
465 | $col="bgcolor='$table2colour'"; |
466 | } | |
c27b8825 LAH |
467 | |
468 | if($entries{$key}->{expired}) { | |
469 | print <<END | |
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> | |
474 | END | |
475 | ; | |
476 | } else { | |
477 | print <<END | |
52ca3c80 AM |
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> | |
c27b8825 LAH |
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> | |
3ea75603 | 482 | END |
52ca3c80 | 483 | ; |
934a3769 | 484 | } |
c27b8825 | 485 | |
934a3769 | 486 | print <<END |
c27b8825 LAH |
487 | <td $col><input type='hidden' name='ACTION' value='$Lang::tr{'add'}2' /><input type='submit' name='SUBMIT' value='$Lang::tr{'add'}' /></td> |
488 | </tr></form> | |
32fdd7d9 | 489 | END |
52ca3c80 | 490 | ; |
934a3769 | 491 | $id++; |
3ea75603 MT |
492 | } |
493 | ||
494 | print "</table>"; | |
495 | &closebox(); | |
496 | } | |
497 | ||
498 | ||
499 | # This sub is used during display of actives leases | |
500 | sub leasesort { | |
934a3769 LAH |
501 | if (rindex ($dhcpsettings{'SORT_LEASELIST'},'Rev') != -1) |
502 | { | |
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}); | |
c27b8825 | 507 | $entries{$a}->{'expired'} <=> $entries{$b}->{'expired'} || # always sort by expiration first |
934a3769 LAH |
508 | ($b[0]<=>$a[0]) || |
509 | ($b[1]<=>$a[1]) || | |
510 | ($b[2]<=>$a[2]) || | |
511 | ($b[3]<=>$a[3]); | |
512 | } else { | |
c27b8825 | 513 | $entries{$a}->{'expired'} <=> $entries{$b}->{'expired'} || |
934a3769 LAH |
514 | $entries{$b}->{$qs} cmp $entries{$a}->{$qs}; |
515 | } | |
516 | } | |
517 | else #not reverse | |
518 | { | |
519 | $qs=$dhcpsettings{'SORT_LEASELIST'}; | |
520 | if ($qs eq 'IPADDR') { | |
521 | @a = split(/\./,$entries{$a}->{$qs}); | |
522 | @b = split(/\./,$entries{$b}->{$qs}); | |
c27b8825 | 523 | $entries{$a}->{'expired'} <=> $entries{$b}->{'expired'} || |
934a3769 LAH |
524 | ($a[0]<=>$b[0]) || |
525 | ($a[1]<=>$b[1]) || | |
526 | ($a[2]<=>$b[2]) || | |
527 | ($a[3]<=>$b[3]); | |
528 | } else { | |
c27b8825 | 529 | $entries{$a}->{'expired'} <=> $entries{$b}->{'expired'} || |
934a3769 LAH |
530 | $entries{$a}->{$qs} cmp $entries{$b}->{$qs}; |
531 | } | |
3ea75603 | 532 | } |
3ea75603 | 533 | } |
1ddefbbd CS |
534 | |
535 | sub colorize { | |
536 | my $string = $_[0]; | |
537 | my @array = split(/\//,$string); | |
538 | my $string2 = $array[0]; | |
539 | ||
540 | if ( $string eq "*" or $string eq "" ){ | |
541 | return $string; | |
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>"; | |
56d37c8d | 548 | } elsif ( $string =~ $ethsettings{'GREEN_DEV'} or &General::IpInSubnet($string2,$ethsettings{'GREEN_NETADDRESS'},$ethsettings{'GREEN_NETMASK'}) ){ |
1ddefbbd CS |
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>"; | |
56d37c8d | 552 | } elsif ( $ethsettings{'CONFIG_TYPE'}>1 and ( $string =~ $ethsettings{'BLUE_DEV'} or &General::IpInSubnet($string2,$ethsettings{'BLUE_NETADDRESS'},$ethsettings{'BLUE_NETMASK'}) )){ |
1ddefbbd | 553 | return "<font color='".${Header::colourblue}."'>".$string."</font>"; |
56d37c8d | 554 | } elsif ( $ethsettings{'CONFIG_TYPE'}>2 and ( $string =~ $ethsettings{'ORANGE_DEV'} or &General::IpInSubnet($string2,$ethsettings{'ORANGE_NETADDRESS'},$ethsettings{'ORANGE_NETMASK'}) )){ |
1ddefbbd CS |
555 | return "<font color='".${Header::colourorange}."'>".$string."</font>"; |
556 | } else { | |
557 | return $string; | |
558 | } | |
559 | } | |
b0323d19 | 560 | |
64db1faf LAH |
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 | |
b0323d19 | 564 | sub get_manualpage_url() { |
64db1faf LAH |
565 | my ($cgifile) = @_; |
566 | $cgifile //= substr($ENV{'SCRIPT_NAME'}, 9); # remove fixed "/cgi-bin/" path | |
b0323d19 LAH |
567 | |
568 | # Ensure base url is configured | |
569 | return unless($manualpages{'BASE_URL'}); | |
570 | ||
571 | # Return URL | |
64db1faf LAH |
572 | if($cgifile && defined($manualpages{$cgifile})) { |
573 | return "$manualpages{'BASE_URL'}/$manualpages{$cgifile}"; | |
b0323d19 LAH |
574 | } |
575 | ||
576 | # No manual page configured, return nothing | |
577 | return; | |
578 | } | |
c13060fd | 579 | |
64db1faf LAH |
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() { | |
583 | my ($filename) = @_; | |
584 | ||
585 | open(my $file, "<", $filename) or return; # Fail silent | |
586 | while(my $line = <$file>) { | |
587 | chomp($line); | |
588 | next if(substr($line, 0, 1) eq '#'); # Skip comments | |
589 | next if(index($line, '=', 1) == -1); # Skip incomplete lines | |
590 | ||
591 | my($left, $value) = split(/=/, $line, 2); | |
592 | if($left =~ /^([[:alnum:]\/._-]+)$/) { | |
593 | my $key = $1; | |
594 | $manualpages{$key} = $value; | |
595 | } | |
596 | } | |
597 | close($file); | |
598 | } | |
599 | ||
c13060fd | 600 | 1; # End of package "Header" |