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