]> git.ipfire.org Git - people/pmueller/ipfire-2.x.git/blob - config/cfgroot/header.pl
suricata: Change midstream policy to "pass-flow"
[people/pmueller/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 package Header;
13
14 use CGI();
15 use File::Basename;
16 use HTML::Entities();
17 use Socket;
18 use Time::Local;
19
20 our %color = ();
21 &General::readhash("/srv/web/ipfire/html/themes/ipfire/include/colors.txt", \%color);
22
23 $|=1; # line buffering
24
25 $Header::revision = 'final';
26 $Header::swroot = '/var/ipfire';
27 $Header::graphdir='/srv/web/ipfire/html/graphs';
28 $Header::pagecolour = '#ffffff';
29 $Header::bordercolour = '#363636';
30 $Header::table1colour = '#f5f5f5';
31 $Header::table2colour = '#fafafa';
32 $Header::colourred = '#993333';
33 $Header::colourorange = '#FF9933';
34 $Header::colouryellow = '#FFFF00';
35 $Header::colourgreen = '#339933';
36 $Header::colourblue = '#333399';
37 $Header::colourovpn = '#339999';
38 $Header::colourfw = '#000000';
39 $Header::colourvpn = '#990099';
40 $Header::colourerr = '#FF0000';
41 $Header::viewsize = 150;
42 $Header::errormessage = '';
43 $Header::extraHead = <<END
44 <style>
45 .color20 {
46 background-color: $color{'color20'};
47 }
48 .color22 {
49 background-color: $color{'color22'};
50 }
51 .colouryellow {
52 background-color: $Header::colouryellow;
53 }
54 .orange {
55 background-color: orange;
56 }
57 .red {
58 background-color: red;
59 }
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 }
85 </style>
86 END
87 ;
88 my %menuhash = ();
89 my $menu = \%menuhash;
90 %settings = ();
91 %ethsettings = ();
92 %pppsettings = ();
93 my @URI = split('\?', $ENV{'REQUEST_URI'});
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";
98 print "Location: https://$ENV{'SERVER_ADDR'}:444/$ENV{'PATH_INFO'}\r\n\r\n";
99 exit 0;
100 }
101
102 ### Initialize environment
103 &General::readhash("${swroot}/main/settings", \%settings);
104 &General::readhash("${swroot}/ethernet/settings", \%ethsettings);
105 &General::readhash("${swroot}/ppp/settings", \%pppsettings);
106 $hostname = $settings{'HOSTNAME'};
107 $hostnameintitle = 0;
108
109 ### Initialize language
110 require "${swroot}/lang.pl";
111 $language = &Lang::FindWebLanguage($settings{"LANGUAGE"});
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
138 ### Initialize user manual
139 my %manualpages = ();
140 &_read_manualpage_hash("${General::swroot}/main/manualpages");
141
142 ### Load selected language and theme functions
143 require "${swroot}/langs/en.pl";
144 require "${swroot}/langs/${language}.pl";
145 eval `/bin/cat /srv/web/ipfire/html/themes/ipfire/include/functions.pl`;
146
147 sub green_used() {
148 if ($ethsettings{'GREEN_DEV'} && $ethsettings{'GREEN_DEV'} ne "") {
149 return 1;
150 }
151
152 return 0;
153 }
154
155 sub orange_used () {
156 if ($ethsettings{'CONFIG_TYPE'} =~ /^[24]$/) {
157 return 1;
158 }
159 return 0;
160 }
161
162 sub blue_used () {
163 if ($ethsettings{'CONFIG_TYPE'} =~ /^[34]$/) {
164 return 1;
165 }
166 return 0;
167 }
168
169 sub is_modem {
170 if ($ethsettings{'CONFIG_TYPE'} =~ /^[0]$/) {
171 return 1;
172 }
173 return 0;
174 }
175
176 ### Initialize menu
177 sub genmenu {
178
179 my %subsystemhash = ();
180 my $subsystem = \%subsystemhash;
181
182 my %substatushash = ();
183 my $substatus = \%substatushash;
184
185 my %subnetworkhash = ();
186 my $subnetwork = \%subnetworkhash;
187
188 my %subserviceshash = ();
189 my $subservices = \%subserviceshash;
190
191 my %subfirewallhash = ();
192 my $subfirewall = \%subfirewallhash;
193
194 my %subipfirehash = ();
195 my $subipfire = \%subipfirehash;
196
197 my %sublogshash = ();
198 my $sublogs = \%sublogshash;
199
200 if ( -e "/var/ipfire/main/gpl_accepted") {
201
202 eval `/bin/cat /var/ipfire/menu.d/*.menu`;
203 eval `/bin/cat /var/ipfire/menu.d/*.main`;
204
205 if (! blue_used()) {
206 $menu->{'05.firewall'}{'subMenu'}->{'60.wireless'}{'enabled'} = 0;
207 }
208 if ( $ethsettings{'CONFIG_TYPE'} =~ /^(1|2|3|4)$/ && $ethsettings{'RED_TYPE'} eq 'STATIC' ) {
209 $menu->{'03.network'}{'subMenu'}->{'70.aliases'}{'enabled'} = 1;
210 }
211
212 if (&General::RedIsWireless()) {
213 $menu->{'01.system'}{'subMenu'}->{'21.wlan'}{'enabled'} = 1;
214 }
215
216 if ( $ethsettings{'RED_TYPE'} eq "PPPOE" && $pppsettings{'MONPORT'} ne "" ) {
217 $menu->{'02.status'}{'subMenu'}->{'74.modem-status'}{'enabled'} = 1;
218 }
219
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
226 # Disbale unusable things in cloud environments
227 if (&General::running_in_cloud()) {
228 $menu->{'03.network'}{'subMenu'}->{'30.dhcp'}{'enabled'} = 0;
229 $menu->{'03.network'}{'subMenu'}->{'80.macadressmenu'}{'enabled'} = 0;
230 $menu->{'03.network'}{'subMenu'}->{'90.wakeonlan'}{'enabled'} = 0;
231 }
232 }
233 }
234
235 sub showhttpheaders
236 {
237 print "Cache-control: private\n";
238 print "Content-type: text/html; charset=UTF-8\n\n";
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
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;
334 $CGI::POST_MAX = 1024 * 1024;
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
360 sub escape($) {
361 my $s = shift;
362 return HTML::Entities::encode_entities($s);
363 }
364
365 sub cleanhtml {
366 my $outstring =$_[0];
367 $outstring =~ tr/,/ / if not defined $_[1] or $_[1] ne 'y';
368
369 return escape($outstring);
370 }
371
372 sub connectionstatus
373 {
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='';
383 unless ( $netsettings{'RED_TYPE'} =~ /^(DHCP|STATIC)$/ ) {
384 $profileused="- $pppsettings{'PROFILENAME'}";
385 }
386
387 my ($timestr, $connstate);
388
389 my $connstate = "<span>$Lang::tr{'idle'} $profileused</span>";
390
391 if (-e "${General::swroot}/red/active") {
392 $timestr = &General::age("${General::swroot}/red/active");
393 $connstate = "<span>$Lang::tr{'connected'} - (<span>$timestr</span>) $profileused</span>";
394 } else {
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>";
399 } else {
400 $connstate = "<span>$Lang::tr{'connecting'} $profileused</span>" if (system("ps -ef | grep -q '[p]ppd'"));
401 }
402 }
403
404 return $connstate;
405 }
406
407 sub CheckSortOrder {
408 #Sorting of allocated leases
409 if ($ENV{'QUERY_STRING'} =~ /^IPADDR|^ETHER|^HOSTNAME|^ENDTIME/ ) {
410 my $newsort=$ENV{'QUERY_STRING'};
411 &General::readhash("${swroot}/dhcp/settings", \%dhcpsettings);
412 $act=$dhcpsettings{'SORT_LEASELIST'};
413 #Reverse actual ?
414 if ($act =~ $newsort) {
415 if ($act !~ 'Rev') {$Rev='Rev'};
416 $newsort.=$Rev
417 };
418
419 $dhcpsettings{'SORT_LEASELIST'}=$newsort;
420 &General::writehash("${swroot}/dhcp/settings", \%dhcpsettings);
421 $dhcpsettings{'ACTION'} = 'SORT'; # avoid the next test "First lauch"
422 }
423
424 }
425
426 sub PrintActualLeases
427 {
428 &openbox('100%', 'left', $Lang::tr{'current dynamic leases'});
429 print <<END
430 <table width='100%' class='tbl'>
431 <tr>
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>
437 </tr>
438 END
439 ;
440
441 open(LEASES,"/var/state/dhcp/dhcpd.leases") or die "Can't open dhcpd.leases";
442 while (my $line = <LEASES>) {
443 next if( $line =~ /^\s*#/ );
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;
451 $endtime_print = "";
452 $expired = 0;
453 $ether = "";
454 $hostname = "";
455 }
456
457 if ($line =~ /^\s*ends/) {
458 $line =~ /(\d+)\/(\d+)\/(\d+) (\d+):(\d+):(\d+)/;
459 $endtime = timegm($6, $5, $4, $3, $2 - 1, $1 - 1900);
460 ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $dst) = localtime($endtime);
461 $endtime_print = sprintf ("%02d/%02d/%d %02d:%02d:%02d",$mday,$mon+1,$year+1900,$hour,$min,$sec);
462 $expired = $endtime < time();
463 }
464
465 if ($line =~ /^\s*hardware ethernet/) {
466 $ether = $temp[2];
467 $ether =~ s/;//g;
468 }
469
470 if ($line =~ /^\s*client-hostname/) {
471 $hostname = "$temp[1] $temp[2] $temp[3]";
472 $hostname =~ s/\"|[;\s]+?$//g; # remove quotes, trim semicolon and white space
473 }
474
475 if ($line eq "}") {
476 @record = ('IPADDR',$ip,'ENDTIME',$endtime,'ETHER',$ether,'HOSTNAME',$hostname,'endtime_print',$endtime_print,'expired',$expired);
477 $record = {}; # create a reference to empty hash
478 %{$record} = @record; # populate that hash with @record
479 $entries{$record->{'IPADDR'}} = $record; # add this to a hash of hashes
480 }
481 }
482 close(LEASES);
483
484 my $id = 0;
485 my $col = "";
486 my $divider_printed = 0;
487 foreach my $key (sort leasesort keys %entries) {
488 my $hostname = &cleanhtml($entries{$key}->{HOSTNAME},"y");
489 my $hostname_print = $hostname;
490 if($hostname_print eq "") { #print blank space if no hostname is found
491 $hostname_print = "&nbsp;&nbsp;&nbsp;";
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";
506 if ($id % 2) {
507 $col="bgcolor='$table1colour'";
508 } else {
509 $col="bgcolor='$table2colour'";
510 }
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
522 <td align='center' $col><input type='hidden' name='FIX_ADDR' value='$entries{$key}->{IPADDR}' />$entries{$key}->{IPADDR}</td>
523 <td align='center' $col><input type='hidden' name='FIX_MAC' value='$entries{$key}->{ETHER}' />$entries{$key}->{ETHER}</td>
524 <td align='center' $col><input type='hidden' name='FIX_REMARK' value='$hostname' />$hostname_print</td>
525 <td align='center' $col><input type='hidden' name='FIX_ENABLED' value='on' />$entries{$key}->{endtime_print}</td>
526 END
527 ;
528 }
529
530 print <<END
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>
533 END
534 ;
535 $id++;
536 }
537
538 print "</table>";
539 &closebox();
540 }
541
542
543 # This sub is used during display of actives leases
544 sub leasesort {
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});
551 $entries{$a}->{'expired'} <=> $entries{$b}->{'expired'} || # always sort by expiration first
552 ($b[0]<=>$a[0]) ||
553 ($b[1]<=>$a[1]) ||
554 ($b[2]<=>$a[2]) ||
555 ($b[3]<=>$a[3]);
556 } else {
557 $entries{$a}->{'expired'} <=> $entries{$b}->{'expired'} ||
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});
567 $entries{$a}->{'expired'} <=> $entries{$b}->{'expired'} ||
568 ($a[0]<=>$b[0]) ||
569 ($a[1]<=>$b[1]) ||
570 ($a[2]<=>$b[2]) ||
571 ($a[3]<=>$b[3]);
572 } else {
573 $entries{$a}->{'expired'} <=> $entries{$b}->{'expired'} ||
574 $entries{$a}->{$qs} cmp $entries{$b}->{$qs};
575 }
576 }
577 }
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>";
592 } elsif ( $string =~ $ethsettings{'GREEN_DEV'} or &General::IpInSubnet($string2,$ethsettings{'GREEN_NETADDRESS'},$ethsettings{'GREEN_NETMASK'}) ){
593 return "<font color='".${Header::colourgreen}."'>".$string."</font>";
594 } elsif ( $string =~ "ppp0" or $string =~ $ethsettings{'RED_DEV'} or $string =~ "0.0.0.0" or $string =~ $ethsettings{'RED_ADDRESS'} ){
595 return "<font color='".${Header::colourred}."'>".$string."</font>";
596 } elsif ( $ethsettings{'CONFIG_TYPE'}>1 and ( $string =~ $ethsettings{'BLUE_DEV'} or &General::IpInSubnet($string2,$ethsettings{'BLUE_NETADDRESS'},$ethsettings{'BLUE_NETMASK'}) )){
597 return "<font color='".${Header::colourblue}."'>".$string."</font>";
598 } elsif ( $ethsettings{'CONFIG_TYPE'}>2 and ( $string =~ $ethsettings{'ORANGE_DEV'} or &General::IpInSubnet($string2,$ethsettings{'ORANGE_NETADDRESS'},$ethsettings{'ORANGE_NETMASK'}) )){
599 return "<font color='".${Header::colourorange}."'>".$string."</font>";
600 } else {
601 return $string;
602 }
603 }
604
605 # Get user manual URL for a configuration page inside the "/cgi-bin/"
606 # (reads current page from the environment variables unless defined)
607 # Returns empty if no URL is available
608 sub get_manualpage_url() {
609 my ($cgifile) = @_;
610 $cgifile //= substr($ENV{'SCRIPT_NAME'}, 9); # remove fixed "/cgi-bin/" path
611
612 # Ensure base url is configured
613 return unless($manualpages{'BASE_URL'});
614
615 # Return URL
616 if($cgifile && defined($manualpages{$cgifile})) {
617 return "$manualpages{'BASE_URL'}/$manualpages{$cgifile}";
618 }
619
620 # No manual page configured, return nothing
621 return;
622 }
623
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
644 1; # End of package "Header"