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