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