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