]> git.ipfire.org Git - ipfire-2.x.git/blame - config/cfgroot/header.pl
GeƤndert:
[ipfire-2.x.git] / config / cfgroot / header.pl
CommitLineData
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
12package Header;
13
14use CGI();
15use Socket;
16use Time::Local;
17
18$|=1; # line buffering
19
3ea75603
MT
20$Header::revision = 'final';
21$Header::swroot = '/var/ipfire';
22$Header::pagecolour = '#ffffff';
23#$Header::tablecolour = '#a0a0a0';
24$Header::tablecolour = '#FFFFFF';
25$Header::bigboxcolour = '#F6F4F4';
26$Header::boxcolour = '#EAE9EE';
27$Header::bordercolour = '#000000';
28$Header::table1colour = '#E0E0E0';
29$Header::table2colour = '#F0F0F0';
30$Header::colourred = '#993333';
31$Header::colourorange = '#FF9933';
32$Header::colouryellow = '#FFFF00';
33$Header::colourgreen = '#339933';
34$Header::colourblue = '#333399';
6d4147d2 35$Header::colourovpn = '#339999';
3ea75603
MT
36$Header::colourfw = '#000000';
37$Header::colourvpn = '#990099';
38$Header::colourerr = '#FF0000';
39$Header::viewsize = 150;
40$Header::errormessage = '';
41my %menuhash = ();
42my $menu = \%menuhash;
43%settings = ();
44%ethsettings = ();
45@URI = ();
46$Header::supported=0;
47
48### Make sure this is an SSL request
49if ($ENV{'SERVER_ADDR'} && $ENV{'HTTPS'} ne 'on') {
50 print "Status: 302 Moved\r\n";
51 print "Location: https://$ENV{'SERVER_ADDR'}:10443/$ENV{'PATH_INFO'}\r\n\r\n";
52 exit 0;
53}
54
55### Initialize environment
56&readhash("${swroot}/main/settings", \%settings);
57&readhash("${swroot}/ethernet/settings", \%ethsettings);
58$language = $settings{'LANGUAGE'};
59$hostname = $settings{'HOSTNAME'};
60$hostnameintitle = 0;
61
62### Initialize language
63if ($language =~ /^(\w+)$/) {$language = $1;}
64
65### Read English Files
66if ( -d "/var/ipfire/langs/en/" ) {
67 opendir(DIR, "/var/ipfire/langs/en/");
68 @names = readdir(DIR) or die "Cannot Read Directory: $!\n";
69 foreach $name(@names) {
70 next if ($name eq ".");
71 next if ($name eq "..");
72 next if (!($name =~ /\.pl$/));
73 require "${swroot}/langs/en/${name}";
74 };
75};
76
77
78### Enable Language Files
79if ( -d "/var/ipfire/langs/${language}/" ) {
80 opendir(DIR, "/var/ipfire/langs/${language}/");
81 @names = readdir(DIR) or die "Cannot Read Directory: $!\n";
82 foreach $name(@names) {
83 next if ($name eq ".");
84 next if ($name eq "..");
85 next if (!($name =~ /\.pl$/));
86 require "${swroot}/langs/${language}/${name}";
87 };
88};
89
7476f476
HS
90### Read IPFire Buildversion
91$FIREBUILD = "Datei firebuild nicht gefunden\n";
92if (open(MYFile, "<${swroot}/firebuild")) {
93 $FIREBUILD = <MYFile>;
94 $FIREBUILD = "(Build: $FIREBUILD)";
95 close(_File);
96};
3ea75603
MT
97
98require "${swroot}/langs/en.pl";
99require "${swroot}/langs/${language}.pl";
100
101sub orange_used () {
102 if ($ethsettings{'CONFIG_TYPE'} =~ /^[1357]$/) {
103 return 1;
104 }
105 return 0;
106}
107
108sub blue_used () {
109 if ($ethsettings{'CONFIG_TYPE'} =~ /^[4567]$/) {
110 return 1;
111 }
112 return 0;
113}
114
115sub is_modem {
116 if ($ethsettings{'CONFIG_TYPE'} =~ /^[0145]$/) {
117 return 1;
118 }
119 return 0;
120}
121
122### Initialize menu
123sub genmenu {
124 my %subsystemhash = ();
125 my $subsystem = \%subsystemhash;
126
60cbd6e7 127 $subsystem->{'10.home'} = {
6d4147d2
MT
128 'caption' => $tr{'alt home'},
129 'uri' => '/cgi-bin/index.cgi',
130 'title' => "$tr{'alt home'}",
131 'enabled' => 1,
132 };
60cbd6e7 133 $subsystem->{'20.passwords'} = {
6d4147d2
MT
134 'caption' => $tr{'sspasswords'},
135 'uri' => '/cgi-bin/changepw.cgi',
136 'title' => "$tr{'sspasswords'}",
137 'enabled' => 1,
138 };
60cbd6e7 139 $subsystem->{'30.ssh'} = {
6d4147d2
MT
140 'caption' => $tr{'ssh access'},
141 'uri' => '/cgi-bin/remote.cgi',
142 'title' => "$tr{'ssh access'}",
143 'enabled' => 1,
144 };
60cbd6e7 145 $subsystem->{'40.gui'} = {
6d4147d2
MT
146 'caption' => $tr{'gui settings'},
147 'uri' => '/cgi-bin/gui.cgi',
148 'title' => "$tr{'gui settings'}",
149 'enabled' => 1,
150 };
60cbd6e7 151 $subsystem->{'50.shutdown'} = {
6d4147d2
MT
152 'caption' => $tr{'shutdown'},
153 'uri' => '/cgi-bin/shutdown.cgi',
154 'title' => "$tr{'shutdown'} / $tr{'reboot'}",
155 'enabled' => 1,
156 };
157 $subsystem->{'99.credits'} = {
158 'caption' => $tr{'credits'},
159 'uri' => '/cgi-bin/credits.cgi',
160 'title' => "$tr{'credits'}",
161 'enabled' => 1,
3ea75603 162 };
3ea75603
MT
163
164 my %substatushash = ();
165 my $substatus = \%substatushash;
60cbd6e7 166 $substatus->{'10.systemstatus'} = {
3ea75603
MT
167 'caption' => $tr{'sssystem status'},
168 'uri' => '/cgi-bin/status.cgi',
6c666a3b 169 'title' => "$tr{'sssystem status'}",
3ea75603
MT
170 'enabled' => 1,
171 };
60cbd6e7 172 $substatus->{'20.networkstatus'} = {
6d4147d2
MT
173 'caption' => $tr{'ssnetwork status'},
174 'uri' => '/cgi-bin/netstatus.cgi',
6c666a3b 175 'title' => "$tr{'ssnetwork status'}",
6d4147d2
MT
176 'enabled' => 1,
177 };
60cbd6e7 178 $substatus->{'30.systemgraphs'} = {
6d4147d2
MT
179 'caption' => $tr{'system graphs'},
180 'uri' => '/cgi-bin/graphs.cgi',
181 'novars' => 1,
182 'title' => "$tr{'system graphs'}",
183 'enabled' => 1,
184 };
60cbd6e7 185 $substatus->{'40.trafficgraphs'} = {
6d4147d2
MT
186 'caption' => $tr{'sstraffic graphs'},
187 'uri' => '/cgi-bin/graphs.cgi',
188 'vars' => 'graph=network',
6c666a3b 189 'title' => "$tr{'sstraffic graphs'}",
6d4147d2
MT
190 'enabled' => 1,
191 };
60cbd6e7 192 $substatus->{'50.proxygraphs'} = {
6d4147d2
MT
193 'caption' => $tr{'ssproxy graphs'},
194 'uri' => '/cgi-bin/proxygraphs.cgi',
6c666a3b 195 'title' => "$tr{'ssproxy graphs'}",
6d4147d2
MT
196 'enabled' => 1,
197 };
60cbd6e7 198 $substatus->{'60.fwhits'} = {
986e08d9 199 'caption' => 'Firewall-Diagramme',
6c666a3b 200 'uri' => '/cgi-bin/fwhits.cgi',
986e08d9 201 'title' => "Firewall-Diagramme",
6c666a3b
MT
202 'enabled' => 1,
203 };
60cbd6e7 204 $substatus->{'70.hddtemp'} = {
a68fedca 205 'caption' => "$tr{'harddisk temperature graphs'}",
60cbd6e7 206 'uri' => '/cgi-bin/hddgraph.cgi',
a68fedca 207 'title' => "$tr{'harddisk temperature graphs'}",
60cbd6e7
MT
208 'enabled' => 1,
209 };
210 $substatus->{'80.connections'} = {
6d4147d2
MT
211 'caption' => $tr{'connections'},
212 'uri' => '/cgi-bin/connections.cgi',
213 'title' => "$tr{'connections'}",
214 'enabled' => 1,
215 };
60cbd6e7 216 $substatus->{'90.nettraf'} = {
6c666a3b
MT
217 'caption' => $tr{'sstraffic'},
218 'uri' => '/cgi-bin/traffic.cgi',
219 'title' => "$tr{'sstraffic'}",
220 'enabled' => 1,
221 };
a68fedca
MT
222 $substatus->{'99.iptable'} = {
223 'caption' => $tr{'iptable rules'},
224 'uri' => '/cgi-bin/iptables.cgi',
225 'title' => "$tr{'iptable rules'}",
6d4147d2
MT
226 'enabled' => 1,
227 };
3ea75603
MT
228
229 my %subnetworkhash = ();
230 my $subnetwork = \%subnetworkhash;
231
60cbd6e7 232 $subnetwork->{'10.proxy'} = {'caption' => 'Webproxy',
6c666a3b
MT
233 'uri' => '/cgi-bin/proxy.cgi',
234 'title' => "Webproxy",
235 'enabled' => 1,
236 };
60cbd6e7 237 $subnetwork->{'20.urlfilter'} = {'caption' => 'URL-Filter',
6c666a3b
MT
238 'uri' => '/cgi-bin/urlfilter.cgi',
239 'title' => "URL-Filter",
240 'enabled' => 1,
241 };
60cbd6e7 242 $subnetwork->{'30.dhcp'} = {'caption' => $tr{'dhcp server'},
6c666a3b
MT
243 'uri' => '/cgi-bin/dhcp.cgi',
244 'title' => "$tr{'dhcp server'}",
245 'enabled' => 1,
246 };
60cbd6e7 247 $subnetwork->{'40.dialup'} = {
3ea75603
MT
248 'caption' => $tr{'alt dialup'},
249 'uri' => '/cgi-bin/pppsetup.cgi',
6c666a3b 250 'title' => "$tr{'alt dialup'}",
6d4147d2 251 'enabled' => 1,
3ea75603 252 };
60cbd6e7 253 $subnetwork->{'50.hosts'} = {
3ea75603
MT
254 'caption' => $tr{'edit hosts'},
255 'uri' => '/cgi-bin/hosts.cgi',
6c666a3b 256 'title' => "$tr{'edit hosts'}",
3ea75603
MT
257 'enabled' => 1,
258 };
60cbd6e7 259 $subnetwork->{'60.upload'} = {
3ea75603
MT
260 'caption' => $tr{'upload'},
261 'uri' => '/cgi-bin/upload.cgi',
6c666a3b 262 'title' => "$tr{'upload'}",
3ea75603
MT
263 'enabled' => 0,
264 };
60cbd6e7 265 $subnetwork->{'70.aliases'} = {
3ea75603
MT
266 'caption' => $tr{'aliases'},
267 'uri' => '/cgi-bin/aliases.cgi',
6c666a3b 268 'title' => "$tr{'aliases'}",
a68fedca 269 'enabled' => 0,
3ea75603 270 };
3ea75603
MT
271
272 my %subserviceshash = ();
273 my $subservices = \%subserviceshash;
274
6c666a3b 275
60cbd6e7 276 $subservices->{'10.openvpn'} = {
6c666a3b
MT
277 'caption' => 'OpenVPN',
278 'uri' => '/cgi-bin/ovpnmain.cgi',
279 'title' => "$tr{'virtual private networking'}",
280 'enabled' => 1,
281 };
60cbd6e7 282 $subservices->{'20.ipsec'} = {
6c666a3b
MT
283 'caption' => 'IPSec',
284 'uri' => '/cgi-bin/vpnmain.cgi',
285 'title' => "$tr{'virtual private networking'}",
286 'enabled' => 1,
287 };
60cbd6e7 288 $subservices->{'30.dyndns'} = {'caption' => $tr{'dynamic dns'},
6d4147d2 289 'uri' => '/cgi-bin/ddns.cgi',
6c666a3b 290 'title' => "$tr{'dynamic dns'}",
6d4147d2
MT
291 'enabled' => 1,
292 };
60cbd6e7 293 $subservices->{'40.time'} = {'caption' => $tr{'time server'},
6d4147d2
MT
294 'uri' => '/cgi-bin/time.cgi',
295 'title' => "$tr{'time server'}",
296 'enabled' => 1,
297 };
60cbd6e7 298 $subservices->{'50.qos'} = {'caption' => 'Quality of Service',
6d4147d2 299 'uri' => '/cgi-bin/qos.cgi',
6c666a3b 300 'title' => "Quality of Service",
6d4147d2
MT
301 'enabled' => 1,
302 };
60cbd6e7 303 $subservices->{'60.ids'} = {'caption' => $tr{'intrusion detection'},
3ea75603
MT
304 'enabled' => 1,
305 'uri' => '/cgi-bin/ids.cgi',
986e08d9 306 'title' => "$tr{'intrusion detection system'}",
3ea75603
MT
307 };
308
309
6c666a3b 310
3ea75603
MT
311 my %subfirewallhash = ();
312 my $subfirewall = \%subfirewallhash;
313
314
60cbd6e7 315 $subfirewall->{'10.dnat'} = {
3ea75603
MT
316 'caption' => $tr{'ssport forwarding'},
317 'uri' => '/cgi-bin/portfw.cgi',
6c666a3b 318 'title' => "$tr{'ssport forwarding'}",
3ea75603
MT
319 'enabled' => 1,
320 };
60cbd6e7 321 $subfirewall->{'20.xtaccess'} = {
3ea75603
MT
322 'caption' => $tr{'external access'},
323 'uri' => '/cgi-bin/xtaccess.cgi',
6c666a3b 324 'title' => "$tr{'external access'}",
3ea75603
MT
325 'enabled' => 1,
326 };
60cbd6e7 327 $subfirewall->{'30.wireless'} = {
c980f4d2
MT
328 'caption' => $tr{'blue access'},
329 'uri' => '/cgi-bin/wireless.cgi',
330 'title' => "$tr{'blue access'}",
331 'enabled' => 1,
332 };
60cbd6e7 333 $subfirewall->{'40.dmz'} = {
3ea75603
MT
334 'caption' => $tr{'ssdmz pinholes'},
335 'uri' => '/cgi-bin/dmzholes.cgi',
986e08d9 336 'title' => "$tr{'dmz pinhole configuration'}",
3ea75603
MT
337 'enabled' => 1,
338 };
60cbd6e7 339 $subfirewall->{'50.outgoing'} = {
6d4147d2
MT
340 'caption' => $tr{'outgoing firewall'},
341 'uri' => '/cgi-bin/outgoingfw.cgi',
342 'title' => "$tr{'outgoing firewall'}",
343 'enabled' => 1,
344 };
60cbd6e7 345 $subfirewall->{'60.fwopts'} = {
6c666a3b
MT
346 'caption' => $tr{'options fw'},
347 'uri' => '/cgi-bin/optionsfw.cgi',
348 'title' => "$tr{'options fw'}",
349 'enabled' => 1,
350 };
3ea75603 351
3ea75603
MT
352 my %sublogshash = ();
353 my $sublogs = \%sublogshash;
354
60cbd6e7 355 $sublogs->{'10.summary'} = {'caption' => $tr{'log summary'},
3ea75603
MT
356 'uri' => '/cgi-bin/logs.cgi/summary.dat',
357 'title' => "$tr{'log summary'}",
358 'enabled' => 1
359 };
60cbd6e7 360 $sublogs->{'20.settings'} = {'caption' => $tr{'log settings'},
3ea75603
MT
361 'uri' => '/cgi-bin/logs.cgi/config.dat',
362 'title' => "$tr{'log settings'}",
363 'enabled' => 1
364 };
60cbd6e7 365 $sublogs->{'30.proxy'} = {'caption' => $tr{'proxy logs'},
3ea75603 366 'uri' => '/cgi-bin/logs.cgi/proxylog.dat',
986e08d9 367 'title' => "$tr{'proxy logs'}",
3ea75603
MT
368 'enabled' => 1
369 };
60cbd6e7 370 $sublogs->{'40.firewall'} = {'caption' => $tr{'firewall logs'},
3ea75603 371 'uri' => '/cgi-bin/logs.cgi/firewalllog.dat',
6c666a3b 372 'title' => "$tr{'firewall logs'}",
3ea75603
MT
373 'enabled' => 1
374 };
60cbd6e7 375 $sublogs->{'50.ids'} = {'caption' => $tr{'ids logs'},
6d4147d2 376 'uri' => '/cgi-bin/logs.cgi/ids.dat',
6c666a3b 377 'title' => "$tr{'ids logs'}",
6d4147d2
MT
378 'enabled' => 1
379 };
60cbd6e7 380 $sublogs->{'60.urlfilter'} = {
6d4147d2
MT
381 'caption' => $tr{'urlfilter log'},
382 'uri' => '/cgi-bin/logs.cgi/urlfilter.dat',
383 'title' => "$tr{'urlfilter log'}",
384 'enabled' => 1,
385 };
60cbd6e7 386 $sublogs->{'70.openvpn'} = {'caption' => $tr{'openvpn log'},
6d4147d2
MT
387 'uri' => '/cgi-bin/logs.cgi/openvpn.dat',
388 'title' => "$tr{'openvpn log'}",
389 'enabled' => 1
390 };
60cbd6e7 391 $sublogs->{'80.system'} = {'caption' => $tr{'system logs'},
6d4147d2 392 'uri' => '/cgi-bin/logs.cgi/log.dat',
986e08d9 393 'title' => "$tr{'system logs'}",
6d4147d2
MT
394 'enabled' => 1
395 };
60cbd6e7 396 $sublogs->{'90.userlog'} = {'caption' => $tr{'user proxy logs'},
6d4147d2 397 'uri' => '/cgi-bin/logs.cgi/userlog.dat',
6c666a3b 398 'title' => "$tr{'user log'}",
6d4147d2
MT
399 'enabled' => 1
400 };
3ea75603
MT
401
402 my %subipfirehash = ();
403 my $subipfire = \%subipfirehash;
60cbd6e7 404 $subipfire->{'10.pakfire'} = {'caption' => 'Pakfire',
3ea75603 405 'uri' => '/cgi-bin/pakfire.cgi',
986e08d9 406 'title' => "Pakfire",
3ea75603
MT
407 'enabled' => 1,
408 };
60cbd6e7 409 $subipfire->{'20.asterisk'} = {'caption' => 'Asterisk',
10a04d70 410 'uri' => '/cgi-bin/asterisk.cgi',
986e08d9 411 'title' => "Asterisk",
10a04d70
MT
412 'enabled' => 1,
413 };
60cbd6e7 414 $subipfire->{'30.samba'} = {'caption' => 'Samba',
3ea75603 415 'uri' => '/cgi-bin/samba.cgi',
986e08d9 416 'title' => "Samba",
3ea75603
MT
417 'enabled' => 1,
418 };
10a04d70
MT
419 $subipfire->{'99.help'} = {'caption' => $tr{'help'},
420 'uri' => '/cgi-bin/help.cgi',
421 'title' => "$tr{'help'}",
422 'enabled' => 1,
423 };
3ea75603
MT
424
425
426
427 $menu->{'01.system'} = {'caption' => $tr{'alt system'},
6d4147d2
MT
428 'enabled' => 1,
429 'subMenu' => $subsystem
430 };
3ea75603 431 $menu->{'02.status'} = {'caption' => $tr{'status'},
6d4147d2
MT
432 'enabled' => 1,
433 'subMenu' => $substatus
434 };
3ea75603 435 $menu->{'03.network'} = {'caption' => $tr{'network'},
6d4147d2
MT
436 'enabled' => 1,
437 'subMenu' => $subnetwork
438 };
3ea75603 439 $menu->{'04.services'} = {'caption' => $tr{'alt services'},
6d4147d2
MT
440 'enabled' => 1,
441 'subMenu' => $subservices
442 };
3ea75603 443 $menu->{'05.firewall'} = {'caption' => $tr{'firewall'},
6d4147d2
MT
444 'enabled' => 1,
445 'subMenu' => $subfirewall
446 };
3ea75603 447 $menu->{'06.proxy'} = {'caption' => $tr{'alt proxy'},
6d4147d2
MT
448 'enabled' => 1,
449 'subMenu' => $subproxy
450 };
10a04d70 451 $menu->{'07.ipfire'} = {'caption' => 'IPFire',
6d4147d2
MT
452 'enabled' => 1,
453 'subMenu' => $subipfire
454 };
3ea75603 455 $menu->{'08.logs'} = {'caption' => $tr{'alt logs'},
6d4147d2
MT
456 'enabled' => 1,
457 'subMenu' => $sublogs
458 };
3ea75603
MT
459
460 if (! blue_used() && ! orange_used()) {
a68fedca 461 $menu->{'05.firewall'}{'subMenu'}->{'40.dmz'}{'enabled'} = 0;
c980f4d2
MT
462 }
463 if (! blue_used()) {
a68fedca 464 $menu->{'05.firewall'}{'subMenu'}->{'30.wireless'}{'enabled'} = 0;
c980f4d2
MT
465 }
466 if (! $ethsettings{'CONFIG_TYPE'} =~ /^(2|3|6|7)$/ && $ethsettings{'RED_TYPE'} eq 'STATIC' ) {
a68fedca 467 $menu->{'03.network'}{'subMenu'}->{'70.aliases'}{'enabled'} = 1;
3ea75603 468 }
3ea75603
MT
469}
470
471sub showhttpheaders
472{
473 print "Pragma: no-cache\n";
474 print "Cache-control: no-cache\n";
475 print "Connection: close\n";
476 print "Content-type: text/html\n\n";
477}
478
479sub is_menu_visible($) {
480 my $link = shift;
481 $link =~ s#\?.*$##;
482 return (-e $ENV{'DOCUMENT_ROOT'}."/../$link");
483}
484
485
486sub getlink($) {
487 my $root = shift;
488 if (! $root->{'enabled'}) {
489 return '';
490 }
491 if ($root->{'uri'} !~ /^$/) {
492 my $vars = '';
493 if ($root->{'vars'} !~ /^$/) {
494 $vars = '?'. $root->{'vars'};
495 }
496 if (! is_menu_visible($root->{'uri'})) {
497 return '';
498 }
499 return $root->{'uri'}.$vars;
500 }
501 my $submenus = $root->{'subMenu'};
502 if (! $submenus) {
503 return '';
504 }
505 foreach my $item (sort keys %$submenus) {
506 my $link = getlink($submenus->{$item});
507 if ($link ne '') {
508 return $link;
509 }
510 }
511 return '';
512}
513
514
515sub compare_url($) {
516 my $conf = shift;
517
518 my $uri = $conf->{'uri'};
519 my $vars = $conf->{'vars'};
520 my $novars = $conf->{'novars'};
521
522 if ($uri eq '') {
523 return 0;
524 }
525 if ($uri ne $URI[0]) {
526 return 0;
527 }
528 if ($novars) {
529 if ($URI[1] !~ /^$/) {
530 return 0;
531 }
532 }
533 if (! $vars) {
534 return 1;
535 }
536 return ($URI[1] eq $vars);
537}
538
539
540sub gettitle($) {
541 my $root = shift;
542
543 if (! $root) {
544 return '';
545 }
546 foreach my $item (sort keys %$root) {
547 my $val = $root->{$item};
548 if (compare_url($val)) {
549 $val->{'selected'} = 1;
550 if ($val->{'title'} !~ /^$/) {
551 return $val->{'title'};
552 }
553 return 'EMPTY TITLE';
554 }
555
556 my $title = gettitle($val->{'subMenu'});
557 if ($title ne '') {
558 $val->{'selected'} = 1;
559 return $title;
560 }
561 }
562 return '';
563}
564
565
566sub showmenu() {
567 print <<EOF
568 <div id="menu-top">
569 <ul>
570EOF
571;
572 foreach my $k1 ( sort keys %$menu ) {
573 if (! $menu->{$k1}{'enabled'}) {
574 next;
575 }
576
577 my $link = getlink($menu->{$k1});
578 if ($link eq '') {
579 next;
580 }
581 if (! is_menu_visible($link)) {
582 next;
583 }
584 if ($menu->{$k1}->{'selected'}) {
585 print '<li class="selected">';
586 } else {
587 print '<li>';
588 }
589
590 print <<EOF
591 <div class="rcorner">
592 <a href="$link">$menu->{$k1}{'caption'}</a>
593 </div>
594 </li>
595EOF
596;
597 }
598
599 print <<EOF
600 </ul>
601 </div>
602EOF
603;
604}
605
606sub getselected($) {
607 my $root = shift;
608 if (!$root) {
609 return 0;
610 }
611
612 foreach my $item (%$root) {
613 if ($root->{$item}{'selected'}) {
614 return $root->{$item};
615 }
616 }
617}
618
619sub showsubsection($$) {
620 my $root = shift;
621 my $id = shift;
622 if ($id eq '') {
623 $id = 'menu-left';
624 }
625
626 if (! $root) {
627 return;
628 }
629 my $selected = getselected($root);
630 if (! $selected) {
631 return;
632 }
633 my $submenus = $selected->{'subMenu'};
634 if (! $submenus) {
635 return;
636 }
637
638 print <<EOF
639 <div id="$id">
640 <ul>
641EOF
642;
643 foreach my $item (sort keys %$submenus) {
644 my $hash = $submenus->{$item};
645 if (! $hash->{'enabled'}) {
646 next;
647 }
648
649 my $link = getlink($hash);
650 if ($link eq '') {
651 next;
652 }
653 if (! is_menu_visible($link)) {
654 next;
655 }
656 if ($hash->{'selected'}) {
657 print '<li class="selected">';
658 } else {
659 print '<li>';
660 }
661
662 print <<EOF
663 <a href="$link">$hash->{'caption'}</a>
664 </li>
665EOF
666;
667 }
668
669 print <<EOF
670 </ul>
671 </div>
672EOF
673;
674
675}
676
677
678sub showsubsubsection($) {
679 my $root = shift;
680 if (!$root) {
681 return;
682 }
683 my $selected = getselected($root);
684 if (! $selected) {
685 return
686 }
687 if (! $selected->{'subMenu'}) {
688 return
689 }
690
691 showsubsection($selected->{'subMenu'}, 'menu-subtop');
692}
693
694
695sub get_helpuri() {
696 my $helpfile = '';
697 if ($URI[0] =~ /.*\/([^\/]+)\.cgi/) {
698 $helpfile = $1;
699 } else {
700 return '';
701 }
702 $helpfile .= '.help.html';
703
704 my $helpuri = '/doc/'.$language.'/'.$helpfile;
705 if (! -e $ENV{'DOCUMENT_ROOT'}.$helpuri) {
706 return '';
707 }
708 return $helpuri;
709}
710
711
712sub openpage {
713 my $title = shift;
714 my $boh = shift;
715 my $extrahead = shift;
716
717 @URI=split ('\?', $ENV{'REQUEST_URI'} );
718 &readhash("${swroot}/main/settings", \%settings);
719 &genmenu();
720
721 my $h2 = gettitle($menu);
722 my $helpuri = get_helpuri();
723
6693216e 724 $title = "IPFire - $title";
3ea75603
MT
725 if ($settings{'WINDOWWITHHOSTNAME'} eq 'on') {
726 $title = "$settings{'HOSTNAME'}.$settings{'DOMAINNAME'} - $title";
727 }
728
729 print <<END
730<!DOCTYPE html
731 PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
732 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
733
734<html>
735 <head>
736 <title>$title</title>
737
738 $extrahead
739 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
6693216e
MT
740END
741;
742 if ($settings{'FX'} eq 'on') {
e57bc1fd 743 print <<END
78331e30
MT
744 <meta http-equiv="Page-Enter" content="blendTrans(Duration=0.5,Transition=12)">
745 <meta http-equiv="Page-Exit" content="blendTrans(Duration=0.5,Transition=12)">
e57bc1fd
MT
746END
747;
6693216e 748 }
e57bc1fd 749 print <<END
3ea75603
MT
750 <link rel="shortcut icon" href="/favicon.ico" />
751 <style type="text/css">\@import url(/include/style.css);</style>
752 <style type="text/css">\@import url(/include/menu.css);</style>
753 <style type="text/css">\@import url(/include/content.css);</style>
3ea75603
MT
754 <script language="javascript" type="text/javascript">
755
756 function swapVisibility(id) {
757 el = document.getElementById(id);
758 if(el.style.display != 'block') {
759 el.style.display = 'block'
760 }
761 else {
762 el.style.display = 'none'
763 }
764 }
765 </script>
766
767 </head>
768 <body>
769<!-- IPFIRE HEADER -->
770
771<div id="main">
772
773<div id="header">
774 <img id="logo-product" src="/images/logo_ipfire.gif">
775 <div id="header-icons">
c980f4d2 776 <a href="http://users.ipfire.eu/" target="_blank"><img border="0" src="/images/help.gif"></a>
3ea75603
MT
777 </div>
778</div>
779
780END
781;
782
783 &showmenu();
784
785print <<END
786<div id="content">
787 <table width="90%">
788 <tr>
789 <td valign="top">
790END
791;
792
793 &showsubsection($menu);
794
795 print <<END
39a7cc11 796 <p><center><img src="/images/iptux.png" width='160px' height='160px'></center></p>
3ea75603
MT
797 </td>
798 <td width="100%" valign="top">
799 <div id="page-content">
800 <h2>$h2</h2>
801END
802 ;
803
804 &showsubsubsection($menu);
805
806 eval {
807 require 'ipfire-network.pl';
808 $supported = check_support();
809 warn_unsupported($supported);
810 };
811}
812
813sub closepage () {
814 my $status = &connectionstatus();
815 $uptime = `/usr/bin/uptime`;
816
817 print <<END
818 <div align="center">
819 <p>
6693216e 820 <div style="font-size: 9px"><b>Status:</b> $status <b>Uptime:</b>$uptime <b>Version:</b> $FIREBUILD</div>
3ea75603 821 </p>
3ea75603
MT
822 </div>
823 </body>
3ea75603
MT
824</html>
825END
826;
827}
828
829sub openbigbox
830{
831 my $width = $_[0];
832 my $align = $_[1];
833 my $sideimg = $_[2];
834
835 if ($errormessage) {
836 $bgcolor = "style='background-color: $colourerr;'";
837 } else {
838 $bgcolor = '';
839 }
840}
841
842sub closebigbox
843{
844# print "</td></tr></table></td></tr></table>\n"
845}
846
847sub openbox
848{
849 $width = $_[0];
850 $align = $_[1];
851 $caption = $_[2];
852
853 if ($caption) { print "<h3>$caption</h3>\n"; } else { print "&nbsp;"; }
854
855 print "<table class=\"list\"><tr><td align=\"$align\">\n";
856}
857
858sub closebox
859{
860 print "</td></tr></table><br><br>";
861}
862
863sub writehash
864{
865 my $filename = $_[0];
866 my $hash = $_[1];
867
868 # write cgi vars to the file.
869 open(FILE, ">${filename}") or die "Unable to write file $filename";
870 flock FILE, 2;
871 foreach $var (keys %$hash)
872 {
873 $val = $hash->{$var};
874 # Darren Critchley Jan 17, 2003 added the following because when submitting with a graphic, the x and y
875 # location of the mouse are submitted as well, this was being written to the settings file causing
876 # some serious grief! This skips the variable.x and variable.y
877 if (!($var =~ /(.x|.y)$/)) {
878 if ($val =~ / /) {
879 $val = "\'$val\'"; }
880 if (!($var =~ /^ACTION/)) {
881 print FILE "${var}=${val}\n"; }
882 }
883 }
884 close FILE;
885}
886
887sub readhash
888{
889 my $filename = $_[0];
890 my $hash = $_[1];
891 my ($var, $val);
892
893 open(FILE, $filename) or die "Unable to read file $filename";
894
895 while (<FILE>)
896 {
897 chop;
898 ($var, $val) = split /=/, $_, 2;
899 if ($var)
900 {
901 $val =~ s/^\'//g;
902 $val =~ s/\'$//g;
903
904 # Untaint variables read from hash
905 $var =~ /([A-Za-z0-9_-]*)/; $var = $1;
906 $val =~ /([\w\W]*)/; $val = $1;
907 $hash->{$var} = $val;
908 }
909 }
910 close FILE;
911}
912
913sub getcgihash {
914 my ($hash, $params) = @_;
915 my $cgi = CGI->new ();
916 $hash->{'__CGI__'} = $cgi;
917 return if ($ENV{'REQUEST_METHOD'} ne 'POST');
918 if (!$params->{'wantfile'}) {
919 $CGI::DISABLE_UPLOADS = 1;
920 $CGI::POST_MAX = 512 * 1024;
921 } else {
922 $CGI::POST_MAX = 10 * 1024 * 1024;
923 }
924
925 $cgi->referer() =~ m/^https?\:\/\/([^\/]+)/;
926 my $referer = $1;
927 $cgi->url() =~ m/^https?\:\/\/([^\/]+)/;
928 my $servername = $1;
929 return if ($referer ne $servername);
930
931 ### Modified for getting multi-vars, split by |
932 %temp = $cgi->Vars();
933 foreach my $key (keys %temp) {
934 $hash->{$key} = $temp{$key};
935 $hash->{$key} =~ s/\0/|/g;
936 $hash->{$key} =~ s/^\s*(.*?)\s*$/$1/;
937 }
938
939 if (($params->{'wantfile'})&&($params->{'filevar'})) {
940 $hash->{$params->{'filevar'}} = $cgi->upload
941 ($params->{'filevar'});
942 }
943 return;
944}
945
946sub log
947{
948 my $logmessage = $_[0];
949 $logmessage =~ /([\w\W]*)/;
950 $logmessage = $1;
951 system('/usr/bin/logger', '-t', 'ipfire', $logmessage);
952}
953
954sub age
955{
956 my ($dev, $ino, $mode, $nlink, $uid, $gid, $rdev, $size,
957 $atime, $mtime, $ctime, $blksize, $blocks) = stat $_[0];
958 my $now = time;
959
960 my $totalsecs = $now - $mtime;
961 my $days = int($totalsecs / 86400);
962 my $totalhours = int($totalsecs / 3600);
963 my $hours = $totalhours % 24;
964 my $totalmins = int($totalsecs / 60);
965 my $mins = $totalmins % 60;
966 my $secs = $totalsecs % 60;
967
968 return "${days}d ${hours}h ${mins}m ${secs}s";
969}
970
971sub validip
972{
973 my $ip = $_[0];
974
975 if (!($ip =~ /^(\d+)\.(\d+)\.(\d+)\.(\d+)$/)) {
976 return 0; }
977 else
978 {
979 @octets = ($1, $2, $3, $4);
980 foreach $_ (@octets)
981 {
982 if (/^0./) {
983 return 0; }
984 if ($_ < 0 || $_ > 255) {
985 return 0; }
986 }
987 return 1;
988 }
989}
990
991sub validmask
992{
993 my $mask = $_[0];
994
995 # secord part an ip?
996 if (&validip($mask)) {
997 return 1; }
998 # second part a number?
999 if (/^0/) {
1000 return 0; }
1001 if (!($mask =~ /^\d+$/)) {
1002 return 0; }
1003 if ($mask >= 0 && $mask <= 32) {
1004 return 1; }
1005 return 0;
1006}
1007
1008sub validipormask
1009{
1010 my $ipormask = $_[0];
1011
1012 # see if it is a IP only.
1013 if (&validip($ipormask)) {
1014 return 1; }
1015 # split it into number and mask.
1016 if (!($ipormask =~ /^(.*?)\/(.*?)$/)) {
1017 return 0; }
1018 $ip = $1;
1019 $mask = $2;
1020 # first part not a ip?
1021 if (!(&validip($ip))) {
1022 return 0; }
1023 return &validmask($mask);
1024}
1025
1026sub validipandmask
1027{
1028 my $ipandmask = $_[0];
1029
1030 # split it into number and mask.
1031 if (!($ipandmask =~ /^(.*?)\/(.*?)$/)) {
1032 return 0; }
1033 $ip = $1;
1034 $mask = $2;
1035 # first part not a ip?
1036 if (!(&validip($ip))) {
1037 return 0; }
1038 return &validmask($mask);
1039}
1040
1041sub validport
1042{
1043 $_ = $_[0];
1044
1045 if (!/^\d+$/) {
1046 return 0; }
1047 if (/^0./) {
1048 return 0; }
1049 if ($_ >= 1 && $_ <= 65535) {
1050 return 1; }
1051 return 0;
1052}
1053
1054sub validmac
1055{
1056 my $checkmac = $_[0];
1057 my $ot = '[0-9a-f]{2}'; # 2 Hex digits (one octet)
1058 if ($checkmac !~ /^$ot:$ot:$ot:$ot:$ot:$ot$/i)
1059 {
1060 return 0;
1061 }
1062 return 1;
1063}
1064
1065sub validhostname
1066{
1067 # Checks a hostname against RFC1035
1068 my $hostname = $_[0];
1069
1070 # Each part should be at least two characters in length
1071 # but no more than 63 characters
1072 if (length ($hostname) < 2 || length ($hostname) > 63) {
1073 return 0;}
1074 # Only valid characters are a-z, A-Z, 0-9 and -
1075 if ($hostname !~ /^[a-zA-Z0-9-]*$/) {
1076 return 0;}
1077 # First character can only be a letter or a digit
1078 if (substr ($hostname, 0, 1) !~ /^[a-zA-Z0-9]*$/) {
1079 return 0;}
1080 # Last character can only be a letter or a digit
1081 if (substr ($hostname, -1, 1) !~ /^[a-zA-Z0-9]*$/) {
1082 return 0;}
1083 return 1;
1084}
1085
1086sub validdomainname
1087{
1088 # Checks a domain name against RFC1035
1089 my $domainname = $_[0];
1090 my @parts = split (/\./, $domainname); # Split hostname at the '.'
1091
1092 foreach $part (@parts) {
1093 # Each part should be at least two characters in length
1094 # but no more than 63 characters
1095 if (length ($part) < 2 || length ($part) > 63) {
1096 return 0;}
1097 # Only valid characters are a-z, A-Z, 0-9 and -
1098 if ($part !~ /^[a-zA-Z0-9-]*$/) {
1099 return 0;}
1100 # First character can only be a letter or a digit
1101 if (substr ($part, 0, 1) !~ /^[a-zA-Z0-9]*$/) {
1102 return 0;}
1103 # Last character can only be a letter or a digit
1104 if (substr ($part, -1, 1) !~ /^[a-zA-Z0-9]*$/) {
1105 return 0;}
1106 }
1107 return 1;
1108}
1109
1110sub validfqdn
1111{
1112 # Checks a fully qualified domain name against RFC1035
1113 my $fqdn = $_[0];
1114 my @parts = split (/\./, $fqdn); # Split hostname at the '.'
1115 if (scalar(@parts) < 2) { # At least two parts should
1116 return 0;} # exist in a FQDN
1117 # (i.e. hostname.domain)
1118 foreach $part (@parts) {
1119 # Each part should be at least two characters in length
1120 # but no more than 63 characters
1121 if (length ($part) < 2 || length ($part) > 63) {
1122 return 0;}
1123 # Only valid characters are a-z, A-Z, 0-9 and -
1124 if ($part !~ /^[a-zA-Z0-9-]*$/) {
1125 return 0;}
1126 # First character can only be a letter or a digit
1127 if (substr ($part, 0, 1) !~ /^[a-zA-Z0-9]*$/) {
1128 return 0;}
1129 # Last character can only be a letter or a digit
1130 if (substr ($part, -1, 1) !~ /^[a-zA-Z0-9]*$/) {
1131 return 0;}
1132 }
1133 return 1;
1134}
1135
1136sub validportrange # used to check a port range
1137{
1138 my $port = $_[0]; # port values
1139 $port =~ tr/-/:/; # replace all - with colons just in case someone used -
1140 my $srcdst = $_[1]; # is it a source or destination port
1141
1142 if (!($port =~ /^(\d+)\:(\d+)$/)) {
1143
1144 if (!(&validport($port))) {
1145 if ($srcdst eq 'src'){
1146 return $tr{'source port numbers'};
1147 } else {
1148 return $tr{'destination port numbers'};
1149 }
1150 }
1151 }
1152 else
1153 {
1154 @ports = ($1, $2);
1155 if ($1 >= $2){
1156 if ($srcdst eq 'src'){
1157 return $tr{'bad source range'};
1158 } else {
1159 return $tr{'bad destination range'};
1160 }
1161 }
1162 foreach $_ (@ports)
1163 {
1164 if (!(&validport($_))) {
1165 if ($srcdst eq 'src'){
1166 return $tr{'source port numbers'};
1167 } else {
1168 return $tr{'destination port numbers'};
1169 }
1170 }
1171 }
1172 return;
1173 }
1174}
1175
1176# Test if IP is within a subnet
1177# Call: IpInSubnet (Addr, Subnet, Subnet Mask)
1178# Subnet can be an IP of the subnet: 10.0.0.0 or 10.0.0.1
1179# Everything in dottted notation
1180# Return: TRUE/FALSE
1181sub IpInSubnet
1182{
1183 $ip = unpack('N', inet_aton(shift));
1184 $start = unpack('N', inet_aton(shift));
1185 $mask = unpack('N', inet_aton(shift));
1186 $start &= $mask; # base of subnet...
1187 $end = $start + ~$mask;
1188 return (($ip >= $start) && ($ip <= $end));
1189}
1190
1191sub validemail {
1192 my $mail = shift;
1193 return 0 if ( $mail !~ /^[0-9a-zA-Z\.\-\_]+\@[0-9a-zA-Z\.\-]+$/ );
1194 return 0 if ( $mail =~ /^[^0-9a-zA-Z]|[^0-9a-zA-Z]$/);
1195 return 0 if ( $mail !~ /([0-9a-zA-Z]{1})\@./ );
1196 return 0 if ( $mail !~ /.\@([0-9a-zA-Z]{1})/ );
1197 return 0 if ( $mail =~ /.\.\-.|.\-\..|.\.\..|.\-\-./g );
1198 return 0 if ( $mail =~ /.\.\_.|.\-\_.|.\_\..|.\_\-.|.\_\_./g );
1199 return 0 if ( $mail !~ /\.([a-zA-Z]{2,3})$/ );
1200 return 1;
1201}
1202
1203sub readhasharray {
1204 my ($filename, $hash) = @_;
1205
1206 open(FILE, $filename) or die "Unable to read file $filename";
1207
1208 while (<FILE>) {
1209 my ($key, $rest, @temp);
1210 chomp;
1211 ($key, $rest) = split (/,/, $_, 2);
1212 if ($key =~ /^[0-9]+$/ && $rest) {
1213 @temp = split (/,/, $rest);
1214 $hash->{$key} = \@temp;
1215 }
1216 }
1217 close FILE;
1218 return;
1219}
1220
1221sub writehasharray {
1222 my ($filename, $hash) = @_;
1223 my ($key, @temp);
1224
1225 open(FILE, ">$filename") or die "Unable to write to file $filename";
1226
1227 foreach $key (keys %$hash) {
1228 if ( $hash->{$key} ) {
1229 print FILE "$key";
1230 foreach $i (0 .. $#{$hash->{$key}}) {
1231 print FILE ",$hash->{$key}[$i]";
1232 }
1233 }
1234 print FILE "\n";
1235 }
1236 close FILE;
1237 return;
1238}
1239
1240sub findhasharraykey {
1241 foreach my $i (1 .. 1000000) {
1242 if ( ! exists $_[0]{$i}) {
1243 return $i;
1244 }
1245 }
1246}
1247
1248sub cleanhtml
1249{
1250 my $outstring =$_[0];
1251 $outstring =~ tr/,/ / if not defined $_[1] or $_[1] ne 'y';
1252 $outstring =~ s/&/&amp;/g;
1253 $outstring =~ s/\'/&#039;/g;
1254 $outstring =~ s/\"/&quot;/g;
1255 $outstring =~ s/</&lt;/g;
1256 $outstring =~ s/>/&gt;/g;
1257 return $outstring;
1258}
986e08d9 1259
3ea75603
MT
1260sub connectionstatus
1261{
986e08d9
MT
1262 my %pppsettings = ();
1263 my %netsettings = ();
1264 my $iface='';
1265
1266 $pppsettings{'PROFILENAME'} = 'None';
1267 &General::readhash("${General::swroot}/ppp/settings", \%pppsettings);
1268 &General::readhash("${General::swroot}/ethernet/settings", \%netsettings);
1269
1270 my $profileused='';
1271 if ( ! ( $netsettings{'CONFIG_TYPE'} =~ /^(2|3|6|7)$/ && $netsettings{'RED_TYPE'} =~ /^(DHCP|STATIC)$/ ) ) {
1272 $profileused="- $pppsettings{'PROFILENAME'}";
1273 }
1274
1275 if ( ( $pppsettings{'METHOD'} eq 'DHCP' && $netsettings{'RED_TYPE'} ne 'PPTP')
1276 || $netsettings{'RED_TYPE'} eq 'DHCP' ) {
1277 if (open(IFACE, "${General::swroot}/red/iface")) {
1278 $iface = <IFACE>;
1279 close IFACE;
1280 chomp ($iface);
1281 $iface =~ /([a-zA-Z0-9]*)/; $iface = $1;
1282 }
1283 }
1284
1285 my ($timestr, $connstate);
1286 if ($netsettings{'CONFIG_TYPE'} =~ /^(0|1|4|5)$/ && $pppsettings{'TYPE'} =~ /^isdn/) {
1287 # Count ISDN channels
1288 my ($idmap, $chmap, $drmap, $usage, $flags, $phone);
1289 my @phonenumbers;
1290 my $count=0;
1291
1292 open (FILE, "/dev/isdninfo");
1293
1294 $idmap = <FILE>; chop $idmap;
1295 $chmap = <FILE>; chop $chmap;
1296 $drmap = <FILE>; chop $drmap;
1297 $usage = <FILE>; chop $usage;
1298 $flags = <FILE>; chop $flags;
1299 $phone = <FILE>; chop $phone;
1300
1301 $phone =~ s/^phone(\s*):(\s*)//;
1302
1303 @phonenumbers = split / /, $phone;
1304
1305 foreach (@phonenumbers) {
1306 if ($_ ne '???') {
1307 $count++;
1308 }
1309 }
1310 close (FILE);
1311
1312 ## Connection status
1313 my $number;
1314 if ($count == 0) {
1315 $number = 'none!';
1316 } elsif ($count == 1) {
1317 $number = 'single';
1318 } else {
1319 $number = 'dual';
1320 }
1321
1322 if (-e "${General::swroot}/red/active") {
1323 $timestr = &General::age("${General::swroot}/red/active");
1324 $connstate = "<span class='ipcop_StatusBig'>$Lang::tr{'connected'} - $number channel (<span class='ipcop_StatusBigRed'>$timestr</span>) $profileused</span>";
1325 } else {
1326 if ($count == 0) {
1327 if (-e "${General::swroot}/red/dial-on-demand") {
1328 $connstate = "<span class='ipcop_StatusBig'>$Lang::tr{'dod waiting'} $profileused</span>";
1329 } else {
1330 $connstate = "<span class='ipcop_StatusBig'>$Lang::tr{'idle'} $profileused</span>";
1331 }
1332 } else {
1333 $connstate = "<span class='ipcop_StatusBig'>$Lang::tr{'connecting'} $profileused</span>";
1334 }
1335 }
1336 } elsif ($netsettings{'RED_TYPE'} eq "STATIC" || $pppsettings {'METHOD'} eq 'STATIC') {
1337 if (-e "${General::swroot}/red/active") {
1338 $timestr = &General::age("${General::swroot}/red/active");
1339 $connstate = "<span class='ipcop_StatusBig'>$Lang::tr{'connected'} (<span class='ipcop_StatusBigRed'>$timestr</span>) $profileused</span>";
1340 } else {
1341 $connstate = "<span class='ipcop_StatusBig'>$Lang::tr{'idle'} $profileused</span>";
1342 }
1343 } elsif ( ( (-e "${General::swroot}/dhcpc/dhcpcd-$iface.pid") && $netsettings{'RED_TYPE'} ne 'PPTP' ) ||
1344 !system("/bin/ps -ef | /bin/grep -q '[p]ppd'") || !system("/bin/ps -ef | /bin/grep -q '[c]onnectioncheck'")) {
1345 if (-e "${General::swroot}/red/active") {
1346 $timestr = &General::age("${General::swroot}/red/active");
1347 if ($pppsettings{'TYPE'} =~ /^(modem|bewanadsl|conexantpciadsl|eagleusbadsl)$/) {
1348 my $speed;
1349 if ($pppsettings{'TYPE'} eq 'modem') {
1350 open(CONNECTLOG, "/var/log/connect.log");
1351 while (<CONNECTLOG>) {
1352 if (/CONNECT/) {
1353 $speed = (split / /)[6];
1354 }
1355 }
1356 close (CONNECTLOG);
1357 } elsif ($pppsettings{'TYPE'} eq 'bewanadsl') {
1358 $speed = `/usr/bin/unicorn_status | /bin/grep Rate | /usr/bin/cut -f2 -d ':'`;
1359 } elsif ($pppsettings{'TYPE'} eq 'conexantpciadsl') {
1360 $speed = `/bin/cat /proc/net/atm/CnxAdsl:* | /bin/grep 'Line Rates' | /bin/sed -e 's+Line Rates: Receive+Rx+' -e 's+Transmit+Tx+'`;
1361 } elsif ($pppsettings{'TYPE'} eq 'eagleusbadsl') {
1362 $speed = `/usr/sbin/eaglestat | /bin/grep Rate`;
1363 }
1364 $connstate = "<span class='ipcop_StatusBig'>$Lang::tr{'connected'} (<span class='ipcop_StatusBigRed'>$timestr</span>) $profileused (\@$speed)</span>";
1365 } else {
1366 $connstate = "<span class='ipcop_StatusBig'>$Lang::tr{'connected'} (<span class='ipcop_StatusBigRed'>$timestr</span>) $profileused</span>";
1367 }
1368 } else {
1369 if (-e "${General::swroot}/red/dial-on-demand") {
1370 $connstate = "<span class='ipcop_StatusBig'>$Lang::tr{'dod waiting'} $profileused</span>";
1371 } else {
1372 $connstate = "<span class='ipcop_StatusBig'>$Lang::tr{'connecting'} $profileused</span>";
1373 }
1374 }
1375 } else {
1376 $connstate = "<span class='ipcop_StatusBig'>$Lang::tr{'idle'} $profileused</span>";
1377 }
3ea75603
MT
1378 return $connstate;
1379}
1380
1381sub srtarray
1382# Darren Critchley - darrenc@telus.net - (c) 2003
1383# &srtarray(SortOrder, AlphaNumeric, SortDirection, ArrayToBeSorted)
1384# This subroutine will take the following parameters:
1385# ColumnNumber = the column which you want to sort on, starts at 1
1386# AlphaNumberic = a or n (lowercase) defines whether the sort should be alpha or numberic
1387# SortDirection = asc or dsc (lowercase) Ascending or Descending sort
1388# ArrayToBeSorted = the array that wants sorting
1389#
1390# Returns an array that is sorted to your specs
1391#
1392# If SortOrder is greater than the elements in array, then it defaults to the first element
1393#
1394{
1395 my ($colno, $alpnum, $srtdir, @tobesorted) = @_;
1396 my @tmparray;
1397 my @srtedarray;
1398 my $line;
1399 my $newline;
1400 my $ttlitems = scalar @tobesorted; # want to know the number of rows in the passed array
1401 if ($ttlitems < 1){ # if no items, don't waste our time lets leave
1402 return (@tobesorted);
1403 }
1404 my @tmp = split(/\,/,$tobesorted[0]);
1405 $ttlitems = scalar @tmp; # this should be the number of elements in each row of the passed in array
1406
1407 # Darren Critchley - validate parameters
1408 if ($colno > $ttlitems){$colno = '1';}
1409 $colno--; # remove one from colno to deal with arrays starting at 0
1410 if($colno < 0){$colno = '0';}
1411 if ($alpnum ne '') { $alpnum = lc($alpnum); } else { $alpnum = 'a'; }
1412 if ($srtdir ne '') { $srtdir = lc($srtdir); } else { $srtdir = 'src'; }
1413
1414 foreach $line (@tobesorted)
1415 {
1416 chomp($line);
1417 if ($line ne '') {
1418 my @temp = split(/\,/,$line);
1419 # Darren Critchley - juggle the fields so that the one we want to sort on is first
1420 my $tmpholder = $temp[0];
1421 $temp[0] = $temp[$colno];
1422 $temp[$colno] = $tmpholder;
1423 $newline = "";
1424 for ($ctr=0; $ctr < $ttlitems ; $ctr++) {
1425 $newline=$newline . $temp[$ctr] . ",";
1426 }
1427 chop($newline);
1428 push(@tmparray,$newline);
1429 }
1430 }
1431 if ($alpnum eq 'n') {
1432 @tmparray = sort {$a <=> $b} @tmparray;
1433 } else {
1434 @tmparray = (sort @tmparray);
1435 }
1436 foreach $line (@tmparray)
1437 {
1438 chomp($line);
1439 if ($line ne '') {
1440 my @temp = split(/\,/,$line);
1441 my $tmpholder = $temp[0];
1442 $temp[0] = $temp[$colno];
1443 $temp[$colno] = $tmpholder;
1444 $newline = "";
1445 for ($ctr=0; $ctr < $ttlitems ; $ctr++){
1446 $newline=$newline . $temp[$ctr] . ",";
1447 }
1448 chop($newline);
1449 push(@srtedarray,$newline);
1450 }
1451 }
1452
1453 if ($srtdir eq 'dsc') {
1454 @tmparray = reverse(@srtedarray);
1455 return (@tmparray);
1456 } else {
1457 return (@srtedarray);
1458 }
1459}
1460
1461sub speedtouchversion
1462{
1463 if (-f "/proc/bus/usb/devices")
1464 {
1465 $speedtouch=`/bin/cat /proc/bus/usb/devices | /bin/grep 'Vendor=06b9 ProdID=4061' | /usr/bin/cut -d ' ' -f6`;
1466 if ($speedtouch eq '') {
1467 $speedtouch= $tr{'connect the modem'};
1468 }
1469 } else {
1470 $speedtouch='USB '.$tr{'not running'};
1471 }
1472 return $speedtouch
1473}
1474
1475sub CheckSortOrder {
1476#Sorting of allocated leases
1477 if ($ENV{'QUERY_STRING'} =~ /^IPADDR|^ETHER|^HOSTNAME|^ENDTIME/ ) {
1478 my $newsort=$ENV{'QUERY_STRING'};
1479 &readhash("${swroot}/dhcp/settings", \%dhcpsettings);
1480 $act=$dhcpsettings{'SORT_LEASELIST'};
1481 #Reverse actual ?
1482 if ($act =~ $newsort) {
1483 if ($act !~ 'Rev') {$Rev='Rev'};
1484 $newsort.=$Rev
1485 };
1486
1487 $dhcpsettings{'SORT_LEASELIST'}=$newsort;
1488 &writehash("${swroot}/dhcp/settings", \%dhcpsettings);
1489 $dhcpsettings{'ACTION'} = 'SORT'; # avoid the next test "First lauch"
1490 }
1491
1492}
1493
1494sub PrintActualLeases
1495{
1496 &openbox('100%', 'left', $tr{'current dynamic leases'});
1497 print <<END
1498<table width='100%'>
1499<tr>
1500<td width='25%' align='center'><a href='$ENV{'SCRIPT_NAME'}?IPADDR'><b>$tr{'ip address'}</b></a></td>
1501<td width='25%' align='center'><a href='$ENV{'SCRIPT_NAME'}?ETHER'><b>$tr{'mac address'}</b></a></td>
1502<td width='20%' align='center'><a href='$ENV{'SCRIPT_NAME'}?HOSTNAME'><b>$tr{'hostname'}</b></a></td>
1503<td width='30%' align='center'><a href='$ENV{'SCRIPT_NAME'}?ENDTIME'><b>$tr{'lease expires'} (local time d/m/y)</b></a></td>
1504</tr>
1505END
1506 ;
1507
986e08d9 1508 open(LEASES,"/var/state/dhcp/dhcpd.leases") or die "Can't open dhcpd.leases";
3ea75603
MT
1509 while ($line = <LEASES>) {
1510 next if( $line =~ /^\s*#/ );
1511 chomp($line);
1512 @temp = split (' ', $line);
1513
1514 if ($line =~ /^\s*lease/) {
1515 $ip = $temp[1];
1516 #All field are not necessarily read. Clear everything
1517 $endtime = 0;
1518 $ether = "";
1519 $hostname = "";
1520 }
1521
1522 if ($line =~ /^\s*ends/) {
1523 $line =~ /(\d+)\/(\d+)\/(\d+) (\d+):(\d+):(\d+)/;
1524 $endtime = timegm($6, $5, $4, $3, $2 - 1, $1 - 1900);
1525 }
1526
1527 if ($line =~ /^\s*hardware ethernet/) {
1528 $ether = $temp[2];
1529 $ether =~ s/;//g;
1530 }
1531
1532 if ($line =~ /^\s*client-hostname/) {
1533 $hostname = "$temp[1] $temp[2] $temp[3]";
1534 $hostname =~ s/;//g;
1535 $hostname =~ s/\"//g;
1536 }
1537
1538 if ($line eq "}") {
1539 @record = ('IPADDR',$ip,'ENDTIME',$endtime,'ETHER',$ether,'HOSTNAME',$hostname);
1540 $record = {}; # create a reference to empty hash
1541 %{$record} = @record; # populate that hash with @record
1542 $entries{$record->{'IPADDR'}} = $record; # add this to a hash of hashes
1543 }
1544 }
1545 close(LEASES);
1546
1547 my $id = 0;
1548 foreach my $key (sort leasesort keys %entries) {
1549
1550 my $hostname = &cleanhtml($entries{$key}->{HOSTNAME},"y");
1551
1552 if ($id % 2) {
1553 print "<tr bgcolor='$table1colour'>";
1554 }
1555 else {
1556 print "<tr bgcolor='$table2colour'>";
1557 }
1558
1559 print <<END
1560<td align='center'>$entries{$key}->{IPADDR}</td>
1561<td align='center'>$entries{$key}->{ETHER}</td>
1562<td align='center'>&nbsp;$hostname </td>
1563<td align='center'>
1564END
1565 ;
1566
1567 ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $dst) = localtime ($entries{$key}->{ENDTIME});
1568 $enddate = sprintf ("%02d/%02d/%d %02d:%02d:%02d",$mday,$mon+1,$year+1900,$hour,$min,$sec);
1569
1570 if ($entries{$key}->{ENDTIME} < time() ){
1571 print "<strike>$enddate</strike>";
1572 } else {
1573 print "$enddate";
1574 }
1575 print "</td></tr>";
1576 $id++;
1577 }
1578
1579 print "</table>";
1580 &closebox();
1581}
1582
1583
1584# This sub is used during display of actives leases
1585sub leasesort {
1586 if (rindex ($dhcpsettings{'SORT_LEASELIST'},'Rev') != -1)
1587 {
1588 $qs=substr ($dhcpsettings{'SORT_LEASELIST'},0,length($dhcpsettings{'SORT_LEASELIST'})-3);
1589 if ($qs eq 'IPADDR') {
1590 @a = split(/\./,$entries{$a}->{$qs});
1591 @b = split(/\./,$entries{$b}->{$qs});
1592 ($b[0]<=>$a[0]) ||
1593 ($b[1]<=>$a[1]) ||
1594 ($b[2]<=>$a[2]) ||
1595 ($b[3]<=>$a[3]);
1596 }else {
1597 $entries{$b}->{$qs} cmp $entries{$a}->{$qs};
1598 }
1599 }
1600 else #not reverse
1601 {
1602 $qs=$dhcpsettings{'SORT_LEASELIST'};
1603 if ($qs eq 'IPADDR') {
1604 @a = split(/\./,$entries{$a}->{$qs});
1605 @b = split(/\./,$entries{$b}->{$qs});
1606 ($a[0]<=>$b[0]) ||
1607 ($a[1]<=>$b[1]) ||
1608 ($a[2]<=>$b[2]) ||
1609 ($a[3]<=>$b[3]);
1610 }else {
1611 $entries{$a}->{$qs} cmp $entries{$b}->{$qs};
1612 }
1613 }
1614}
1615
1616sub get_uplinks() {
1617 my @uplinks = ();
1618 opendir(DIR, "${swroot}/uplinks/") || return \@uplinks;
1619 foreach my $dir (readdir(DIR)) {
1620 next if ($dir =~ /^\./);
1621 next if (-f "${swroot}/uplinks/$dir");
1622 push(@uplinks, $dir);
1623 }
1624 closedir(DIR);
1625 return \@uplinks;
1626}
1627
1628sub get_iface($) {
1629 my $filename = shift;
1630 chomp($filename);
1631 open (F, $filename) || return "";
1632 my $iface = <F>;
1633 close(F);
1634 chomp($iface);
1635 return $iface;
1636}
1637
1638sub get_red_ifaces_by_type($) {
1639 my $type=shift;
1640 my @gottypeiface = ();
1641 my @gottypeuplink = ();
1642 my @gottype = ();
1643
1644 my $ref=get_uplinks();
1645 my @uplinks=@$ref;
1646 my %set = ();
1647 foreach my $link (@uplinks) {
1648 eval {
1649 &readhash("${swroot}/uplinks/$link/settings", \%set);
1650 };
1651 push(@gottype, $link);
1652
1653 my $iface = $set{'RED_DEV'};
1654 if (!$iface) {
1655 $iface = get_iface("${swroot}/uplinks/$link/interface");
1656 }
1657 next if (!$iface);
1658
1659 if ($set{'RED_TYPE'} eq $type) {
1660 push(@gottypeiface, $iface);
1661 push(@gottypeuplink, $link);
1662 }
1663 }
1664 return (\@gottypeiface, \@gottypeuplink, \@gottype);
1665}
1666
1667sub get_red_ifaces() {
1668 return `cat ${swroot}/uplinks/*/interface 2>/dev/null`;
1669}
1670
1671sub get_zone_devices($) {
1672 my $bridge = shift;
1673 my @ifaces = ();
1674 open (FILE, "${swroot}/ethernet/$bridge") || return "";
1675 foreach my $line (<FILE>) {
1676 chomp($line);
1677 next if (!$line);
1678 push(@ifaces, $line);
1679 }
1680 close(FILE);
1681 return \@ifaces;
1682}