]>
Commit | Line | Data |
---|---|---|
61027579 MT |
1 | #!/usr/bin/perl |
2 | ############################################################################### | |
3 | # # | |
4 | # IPFire.org - A linux based firewall # | |
929b186c | 5 | # Copyright (C) 2012 IPFire Team <info@ipfire.org> # |
61027579 MT |
6 | # # |
7 | # This program is free software: you can redistribute it and/or modify # | |
8 | # it under the terms of the GNU General Public License as published by # | |
9 | # the Free Software Foundation, either version 3 of the License, or # | |
10 | # (at your option) any later version. # | |
11 | # # | |
12 | # This program is distributed in the hope that it will be useful, # | |
13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of # | |
14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # | |
15 | # GNU General Public License for more details. # | |
16 | # # | |
17 | # You should have received a copy of the GNU General Public License # | |
18 | # along with this program. If not, see <http://www.gnu.org/licenses/>. # | |
19 | # # | |
20 | ############################################################################### | |
21 | ||
19f0fa56 MT |
22 | # DEVICE,ENABLED,MODE,WPA_MODE,SSID,PSK,PRIO,AUTH,ANONYMOUS,IDENTITY,PASSWORD |
23 | # wlan0,on,WPA2,,Use This One Mum,ThisIsTheKey,2,TTLS,anonymous,username,password | |
61027579 MT |
24 | |
25 | use strict; | |
26 | ||
27 | # enable only the following on debugging purpose | |
28 | use warnings; | |
29 | use CGI::Carp 'fatalsToBrowser'; | |
30 | ||
31 | require '/var/ipfire/general-functions.pl'; | |
32 | require "${General::swroot}/lang.pl"; | |
33 | require "${General::swroot}/header.pl"; | |
34 | ||
35 | #workaround to suppress a warning when a variable is used only once | |
36 | my @dummy = ( ${Header::colouryellow} ); | |
37 | undef (@dummy); | |
38 | ||
39 | # Files used | |
40 | my $setting = "${General::swroot}/main/settings"; | |
41 | our $datafile = "${General::swroot}/ethernet/wireless"; | |
42 | ||
43 | my %color = (); | |
44 | my %mainsettings = (); | |
45 | &General::readhash("${General::swroot}/main/settings", \%mainsettings); | |
46 | &General::readhash("/srv/web/ipfire/html/themes/".$mainsettings{'THEME'}."/include/colors.txt", \%color); | |
47 | ||
48 | our %settings = (); | |
49 | our %netsettings = (); | |
50 | ||
51 | $settings{'ID'} = ''; | |
52 | $settings{'INTERFACE'} = ''; | |
53 | $settings{'ENABLED'} = ''; | |
54 | $settings{'ENCRYPTION'} = ''; | |
55 | $settings{'WPA_MODE'} = ''; | |
56 | $settings{'SSID'} = ''; | |
57 | $settings{'PSK'} = ''; | |
58 | $settings{'PRIO'} = ''; | |
59 | ||
60 | $settings{'ACTION'} = ''; # add/edit/remove | |
61 | $settings{'ID'} = ''; # point record for ACTION | |
62 | ||
63 | my $errormessage = ''; | |
64 | my $warnmessage = ''; | |
65 | ||
66 | &Header::showhttpheaders(); | |
67 | ||
68 | #Get GUI values | |
69 | &Header::getcgihash(\%settings); | |
70 | ||
71 | # Load multiline data | |
72 | our @configs = (); | |
73 | if (open(FILE, "$datafile")) { | |
74 | @configs = <FILE>; | |
75 | close (FILE); | |
76 | } | |
77 | ||
78 | &General::readhash("${General::swroot}/main/settings", \%settings); | |
79 | &General::readhash("${General::swroot}/ethernet/settings", \%netsettings); | |
80 | ||
81 | # Toggle enable/disable field. | |
82 | if ($settings{'ACTION'} eq $Lang::tr{'toggle enable disable'}) { | |
83 | my @update; | |
84 | ||
85 | foreach my $line (@configs) { | |
86 | chomp($line); | |
87 | my @config = split(/\,/, $line); | |
88 | ||
89 | # Update the entry with the matching ID. | |
90 | if ($config[0] eq $settings{'ID'}) { | |
91 | # Toggle enabled/disabled status. | |
92 | ||
93 | if ($config[2] eq 'on') { | |
94 | $config[2] = 'off'; | |
95 | } else { | |
96 | $config[2] = 'on'; | |
97 | } | |
98 | ||
99 | $line = join(',', @config); | |
100 | } | |
101 | ||
102 | push(@update, $line."\n"); | |
103 | } | |
104 | ||
105 | # Save updated configuration settings. | |
106 | open(FILE, ">$datafile") or die 'wlan client datafile error'; | |
107 | print FILE @update; | |
108 | close(FILE); | |
109 | ||
110 | @configs = @update; | |
111 | ||
112 | # Update configuration files. | |
113 | &BuildConfiguration(); | |
114 | ||
115 | # Reset ACTION. | |
116 | $settings{'ACTION'} = ''; | |
117 | } | |
118 | ||
119 | if ($settings{'ACTION'} eq $Lang::tr{'add'}) { | |
120 | # Validate input data. | |
121 | $errormessage = ValidateInput("add"); | |
122 | ||
123 | unless ($errormessage) { | |
124 | # Search for the next free id. | |
125 | my $next_id = NextID(); | |
126 | ||
127 | my @config = ($next_id); | |
128 | push(@config, $settings{'INTERFACE'}); | |
129 | push(@config, $settings{'ENABLED'}); | |
130 | push(@config, $settings{'ENCRYPTION'}); | |
131 | push(@config, $settings{'WPA_MODE'}); | |
132 | push(@config, $settings{'SSID'}); | |
133 | push(@config, $settings{'PSK'}); | |
134 | push(@config, $settings{'PRIO'}); | |
19f0fa56 MT |
135 | push(@config, $settings{'AUTH'}); |
136 | push(@config, $settings{'ANONYMOUS'}); | |
137 | push(@config, $settings{'IDENTITY'}); | |
138 | push(@config, $settings{'PASSWORD'}); | |
61027579 MT |
139 | |
140 | # Add the new configuration and write all the stuff to the configuration file. | |
141 | my $line = join(',', @config) . "\n"; | |
142 | push(@configs, $line); | |
143 | ||
144 | # Save updated configuration settings. | |
145 | open(FILE, ">$datafile") or die 'wlan client datafile error'; | |
146 | print FILE @configs; | |
147 | close(FILE); | |
148 | ||
149 | # Update configuration files. | |
150 | &BuildConfiguration(); | |
151 | ||
152 | # Reset ACTION. | |
153 | $settings{'ACTION'} = ''; | |
154 | } | |
155 | } | |
156 | ||
157 | if ($settings{'ACTION'} eq $Lang::tr{'edit'}) { | |
158 | foreach my $line (@configs) { | |
159 | chomp($line); | |
160 | my @config = split(/\,/, $line); | |
161 | ||
162 | if ($config[0] eq $settings{'ID'}) { | |
163 | $settings{'ID'} = $config[0]; | |
164 | $settings{'INTERFACE'} = $config[1]; | |
165 | $settings{'ENABLED'} = $config[2]; | |
166 | $settings{'ENCRYPTION'} = $config[3]; | |
167 | $settings{'WPA_MODE'} = $config[4]; | |
168 | $settings{'SSID'} = $config[5]; | |
169 | $settings{'PSK'} = $config[6]; | |
170 | $settings{'PRIO'} = $config[7]; | |
19f0fa56 MT |
171 | $settings{'AUTH'} = $config[8]; |
172 | $settings{'ANONYMOUS'} = $config[9]; | |
173 | $settings{'IDENTITY'} = $config[10]; | |
174 | $settings{'PASSWORD'} = $config[11]; | |
61027579 MT |
175 | } |
176 | } | |
177 | } | |
178 | ||
179 | if ($settings{'ACTION'} eq $Lang::tr{'update'}) { | |
180 | $errormessage = ValidateInput("update"); | |
181 | ||
182 | unless ($errormessage) { | |
183 | my @update; | |
184 | foreach my $line (@configs) { | |
185 | chomp($line); | |
186 | my @config = split(/\,/, $line); | |
187 | ||
188 | # Update the entry with the matching ID. | |
189 | if ($config[0] eq $settings{'ID'}) { | |
190 | # Update all configuration settings. | |
191 | # ID and INTERFACE cannot be changed. | |
19f0fa56 MT |
192 | $config[2] = $settings{'ENABLED'}; |
193 | $config[3] = $settings{'ENCRYPTION'}; | |
194 | $config[4] = $settings{'WPA_MODE'}; | |
195 | $config[5] = $settings{'SSID'}; | |
196 | $config[6] = $settings{'PSK'}; | |
197 | $config[7] = $settings{'PRIO'}; | |
198 | $config[8] = $settings{'AUTH'}; | |
199 | $config[9] = $settings{'ANONYMOUS'}; | |
200 | $config[10] = $settings{'IDENTITY'}; | |
201 | $config[11] = $settings{'PASSWORD'}; | |
61027579 MT |
202 | |
203 | $line = join(',', @config); | |
204 | } | |
205 | ||
206 | push(@update, $line."\n"); | |
207 | } | |
208 | ||
209 | # Save updated configuration settings. | |
210 | open(FILE, ">$datafile") or die 'wlan client datafile error'; | |
211 | print FILE @update; | |
212 | close(FILE); | |
213 | ||
214 | @configs = @update; | |
215 | ||
216 | # Update configuration files. | |
217 | &BuildConfiguration(); | |
218 | ||
219 | # Reset ACTION. | |
220 | $settings{'ACTION'} = ''; | |
221 | } | |
222 | } | |
223 | ||
224 | if ($settings{'ACTION'} eq $Lang::tr{'remove'}) { | |
225 | my @update; | |
226 | ||
227 | foreach my $line (@configs) { | |
228 | chomp($line); | |
229 | my @config = split(/\,/, $line); | |
230 | ||
231 | # Skip the to be removed entry. | |
232 | if ($config[0] eq $settings{'ID'}) { | |
233 | next; | |
234 | } | |
235 | ||
236 | push(@update, $line."\n"); | |
237 | } | |
238 | ||
239 | # Save updated configuration settings. | |
240 | open(FILE, ">$datafile") or die 'wlan client datafile error'; | |
241 | print FILE @update; | |
242 | close(FILE); | |
243 | ||
244 | @configs = @update; | |
245 | ||
246 | # Update configuration files. | |
247 | &BuildConfiguration(); | |
248 | ||
249 | # Reset ACTION. | |
250 | $settings{'ACTION'} = ''; | |
251 | } | |
252 | ||
253 | if ($settings{'ACTION'} eq '') { # First launch from GUI | |
254 | &showMainBox(); | |
255 | } else { | |
256 | # Action has been set, so show the edit box. | |
257 | &showEditBox(); | |
258 | } | |
259 | ||
260 | sub showMainBox() { | |
261 | &Header::openpage($Lang::tr{'wlan client configuration'}, 1, ''); | |
262 | &Header::openbigbox('100%', 'left', '', $errormessage); | |
263 | ||
264 | &Header::openbox('100%', 'left', $Lang::tr{'wlan client configuration'}); | |
265 | ||
266 | print <<END; | |
267 | <form method='POST' action='$ENV{'SCRIPT_NAME'}' style='text-align: center;'> | |
268 | <input type='submit' name='ACTION' value='$Lang::tr{'wlan client new network'}' /> | |
269 | </form> | |
270 | ||
271 | <br><hr><br> | |
272 | ||
d9a0d201 | 273 | <table width="100%" class='tbl'> |
61027579 MT |
274 | <tr> |
275 | <th align='center'>$Lang::tr{'wlan client ssid'}</th> | |
276 | <th align='center'>$Lang::tr{'wlan client encryption'}</th> | |
277 | <th align='center'>$Lang::tr{'priority'}</th> | |
d9a0d201 AM |
278 | <th></th> |
279 | <th></th> | |
280 | <th></th> | |
61027579 MT |
281 | </tr> |
282 | END | |
283 | ||
284 | # | |
285 | # Print each line of @configs list | |
286 | # | |
287 | ||
288 | my $key = 0; | |
d9a0d201 | 289 | my $col=""; |
61027579 MT |
290 | foreach my $line (@configs) { |
291 | # Skip commented lines. | |
292 | my $firstchar = substr($line, 0, 1); | |
293 | next if ($firstchar eq "#"); | |
294 | ||
295 | chomp($line); | |
296 | my @config = split(/\,/,$line); | |
297 | ||
298 | #Choose icon for checkbox | |
299 | my $gif = ''; | |
300 | my $gdesc = ''; | |
301 | if ($config[2] eq 'on' ) { | |
302 | $gif = 'on.gif'; | |
303 | $gdesc = $Lang::tr{'click to disable'}; | |
304 | } else { | |
305 | $gif = 'off.gif'; | |
306 | $gdesc = $Lang::tr{'click to enable'}; | |
307 | } | |
308 | ||
309 | # Colorize each line | |
310 | if ($key % 2) { | |
d9a0d201 AM |
311 | print "<tr>"; |
312 | $col="bgcolor='$color{'color20'}'"; | |
61027579 | 313 | } else { |
d9a0d201 AM |
314 | print "<tr>"; |
315 | $col="bgcolor='$color{'color22'}'"; | |
61027579 MT |
316 | } |
317 | ||
318 | my $encryption_mode = $Lang::tr{'unknown'}; | |
319 | if ($config[3] eq "NONE") { | |
320 | $encryption_mode = $Lang::tr{'wlan client encryption none'}; | |
321 | } elsif ($config[3] eq "WEP") { | |
322 | $encryption_mode = $Lang::tr{'wlan client encryption wep'}; | |
323 | } elsif ($config[3] eq "WPA") { | |
324 | $encryption_mode = $Lang::tr{'wlan client encryption wpa'}; | |
325 | } elsif ($config[3] eq "WPA2") { | |
326 | $encryption_mode = $Lang::tr{'wlan client encryption wpa2'}; | |
19f0fa56 MT |
327 | } elsif ($config[3] eq "EAP") { |
328 | $encryption_mode = $Lang::tr{'wlan client encryption eap'}; | |
61027579 MT |
329 | } |
330 | ||
19f0fa56 MT |
331 | if ($config[3] eq "EAP") { |
332 | if ($config[8] eq "PEAP") { | |
333 | $encryption_mode .= " ($Lang::tr{'wlan client auth peap'})"; | |
334 | } elsif ($config[8] eq "TTLS") { | |
335 | $encryption_mode .= " ($Lang::tr{'wlan client auth ttls'})"; | |
336 | } else { | |
337 | $encryption_mode .= " ($Lang::tr{'wlan client auth auto'})"; | |
338 | } | |
339 | ||
340 | $encryption_mode .= "<hr>"; | |
341 | ||
342 | if ($config[10]) { | |
343 | $encryption_mode .= "<strong>$Lang::tr{'wlan client identity'}</strong>: "; | |
344 | $encryption_mode .= $config[10]; | |
345 | } | |
346 | ||
347 | # Anonymous identity | |
348 | if ($config[9]) { | |
349 | $encryption_mode .= "<br>"; | |
350 | $encryption_mode .= "<strong>$Lang::tr{'wlan client anonymous identity'}</strong>: "; | |
351 | $encryption_mode .= $config[9]; | |
352 | } | |
353 | ||
354 | } elsif (($config[3] eq "WPA") || ($config[3] eq "WPA2")) { | |
61027579 MT |
355 | my $wpa_pairwise = "$Lang::tr{'wlan client ccmp'} $Lang::tr{'wlan client and'} $Lang::tr{'wlan client tkip'}"; |
356 | my $wpa_group = "$Lang::tr{'wlan client ccmp'} $Lang::tr{'wlan client and'} $Lang::tr{'wlan client tkip'}"; | |
357 | ||
358 | if ($config[4] eq "CCMP-CCMP") { | |
359 | $wpa_pairwise = $Lang::tr{'wlan client ccmp'}; | |
360 | $wpa_group = $Lang::tr{'wlan client ccmp'}; | |
361 | } elsif ($config[4] eq "CCMP-TKIP") { | |
362 | $wpa_pairwise = $Lang::tr{'wlan client ccmp'}; | |
363 | $wpa_group = $Lang::tr{'wlan client tkip'}; | |
364 | } elsif ($config[4] eq "TKIP-TKIP") { | |
365 | $wpa_pairwise = $Lang::tr{'wlan client tkip'}; | |
366 | $wpa_group = $Lang::tr{'wlan client tkip'}; | |
367 | } | |
368 | ||
369 | $encryption_mode .= "<hr>"; | |
370 | $encryption_mode .= "<strong>$Lang::tr{'wlan client pairwise key algorithm'}</strong>: "; | |
371 | $encryption_mode .= $wpa_pairwise; | |
372 | $encryption_mode .= "<br>"; | |
373 | $encryption_mode .= "<strong>$Lang::tr{'wlan client group key algorithm'}</strong>: "; | |
374 | $encryption_mode .= $wpa_group; | |
375 | } | |
376 | ||
377 | print <<END; | |
d9a0d201 AM |
378 | <td align='center' $col>$config[5]</td> |
379 | <td align='center' $col>$encryption_mode</td> | |
380 | <td align='center' $col>$config[7]</td> | |
381 | <td align='center' width='5%' $col> | |
61027579 MT |
382 | <form method='post' action='$ENV{'SCRIPT_NAME'}'> |
383 | <input type='hidden' name='ACTION' value='$Lang::tr{'toggle enable disable'}' /> | |
384 | <input type='image' name='$Lang::tr{'toggle enable disable'}' src='/images/$gif' alt='$gdesc' title='$gdesc' /> | |
385 | <input type='hidden' name='ID' value='$config[0]' /> | |
386 | </form> | |
387 | </td> | |
d9a0d201 | 388 | <td align='center' width='5%' $col> |
61027579 MT |
389 | <form method='post' action='$ENV{'SCRIPT_NAME'}'> |
390 | <input type='hidden' name='ACTION' value='$Lang::tr{'edit'}' /> | |
391 | <input type='image' name='$Lang::tr{'edit'}' src='/images/edit.gif' alt='$Lang::tr{'edit'}' title='$Lang::tr{'edit'}' /> | |
392 | <input type='hidden' name='ID' value='$config[0]' /> | |
393 | </form> | |
394 | </td> | |
d9a0d201 | 395 | <td align='center' width='5%' $col> |
61027579 MT |
396 | <form method='post' action='$ENV{'SCRIPT_NAME'}'> |
397 | <input type='hidden' name='ACTION' value='$Lang::tr{'remove'}' /> | |
398 | <input type='image' name='$Lang::tr{'remove'}' src='/images/delete.gif' alt='$Lang::tr{'remove'}' title='$Lang::tr{'remove'}' /> | |
399 | <input type='hidden' name='ID' value='$config[0]' /> | |
400 | </form> | |
401 | </td> | |
402 | </tr> | |
403 | END | |
404 | $key++; | |
405 | } | |
406 | print "</table>"; | |
407 | ||
408 | # If table contains entries, print 'Key to action icons' | |
409 | if ($key) { | |
410 | print <<END; | |
411 | <table> | |
412 | <tr> | |
413 | <td class='boldbase'> <b>$Lang::tr{'legend'}: </b></td> | |
414 | <td><img src='/images/on.gif' alt='$Lang::tr{'click to disable'}' /></td> | |
415 | <td class='base'>$Lang::tr{'click to disable'}</td> | |
416 | <td> </td> | |
417 | <td><img src='/images/off.gif' alt='$Lang::tr{'click to enable'}' /></td> | |
418 | <td class='base'>$Lang::tr{'click to enable'}</td> | |
419 | <td> </td> | |
420 | <td><img src='/images/edit.gif' alt='$Lang::tr{'edit'}' /></td> | |
421 | <td class='base'>$Lang::tr{'edit'}</td> | |
422 | <td> </td> | |
423 | <td><img src='/images/delete.gif' alt='$Lang::tr{'remove'}' /></td> | |
424 | <td class='base'>$Lang::tr{'remove'}</td> | |
425 | </tr> | |
426 | </table> | |
427 | END | |
428 | } | |
429 | ||
430 | &Header::closebox(); | |
431 | ||
432 | # Show status box. | |
433 | &ShowStatus(); | |
434 | ||
435 | &Header::closebigbox(); | |
436 | &Header::closepage(); | |
437 | } | |
438 | ||
439 | sub showEditBox() { | |
440 | &Header::openpage($Lang::tr{'wlan client configuration'}, 1, ''); | |
441 | &Header::openbigbox('100%', 'left', '', $errormessage); | |
442 | ||
443 | if ($errormessage) { | |
444 | &Header::openbox('100%', 'left', $Lang::tr{'error messages'}); | |
445 | print "<font class='base'>$errormessage </font>"; | |
446 | &Header::closebox(); | |
447 | } | |
448 | ||
449 | my $buttontext = $Lang::tr{'add'}; | |
450 | if ($settings{'ID'} ne '') { | |
451 | $buttontext = $Lang::tr{'update'}; | |
452 | &Header::openbox('100%', 'left', $Lang::tr{'wlan client edit entry'}); | |
453 | } else { | |
454 | &Header::openbox('100%', 'left', $Lang::tr{'wlan client new entry'}); | |
455 | $settings{'ENABLED'} = 'on'; | |
456 | } | |
457 | my $action = $buttontext; | |
458 | ||
459 | my %checked = (); | |
460 | $checked{'ENABLED'} = ($settings{'ENABLED'} ne 'on' ) ? '' : "checked='checked'"; | |
461 | ||
462 | my %selected = (); | |
463 | $selected{'ENCRYPTION'} = (); | |
464 | $selected{'ENCRYPTION'}{'NONE'} = ''; | |
5addf347 | 465 | $selected{'ENCRYPTION'}{'WPA3'} = ''; |
61027579 MT |
466 | $selected{'ENCRYPTION'}{'WPA2'} = ''; |
467 | $selected{'ENCRYPTION'}{'WPA'} = ''; | |
468 | $selected{'ENCRYPTION'}{'WEP'} = ''; | |
469 | $selected{'ENCRYPTION'}{$settings{'ENCRYPTION'}} = "selected='selected'"; | |
470 | ||
471 | $selected{'WPA_MODE'} = (); | |
472 | $selected{'WPA_MODE'}{''} = ''; | |
473 | $selected{'WPA_MODE'}{'CCMP-CCMP'} = ''; | |
474 | $selected{'WPA_MODE'}{'CCMP-TKIP'} = ''; | |
475 | $selected{'WPA_MODE'}{'TKIP-TKIP'} = ''; | |
476 | $selected{'WPA_MODE'}{$settings{'WPA_MODE'}} = "selected='selected'"; | |
477 | ||
19f0fa56 MT |
478 | $selected{'AUTH'} = (); |
479 | $selected{'AUTH'}{''} = ''; | |
480 | $selected{'AUTH'}{'PEAP'} = ''; | |
481 | $selected{'AUTH'}{'TTLS'} = ''; | |
482 | $selected{'AUTH'}{$settings{'AUTH'}} = "selected='selected'"; | |
483 | ||
61027579 MT |
484 | $selected{'PRIO'} = (); |
485 | $selected{'PRIO'}{'0'} = ''; | |
486 | $selected{'PRIO'}{'1'} = ''; | |
487 | $selected{'PRIO'}{'2'} = ''; | |
488 | $selected{'PRIO'}{'3'} = ''; | |
489 | $selected{'PRIO'}{'4'} = ''; | |
490 | $selected{'PRIO'}{$settings{'PRIO'}} = "selected='selected'"; | |
491 | ||
492 | print <<END; | |
493 | <form method='POST' action='$ENV{'SCRIPT_NAME'}'> | |
494 | <input type='hidden' name='ID' value='$settings{'ID'}'> | |
495 | ||
496 | <table width='100%'> | |
497 | <tr> | |
498 | <td class='base' width='20%'>$Lang::tr{'wlan client ssid'}:</td> | |
cd6c59aa | 499 | <td width='40%'><input type='text' name='SSID' value="$settings{'SSID'}" size='25'/></td> |
61027579 MT |
500 | <td class='base' width='10%'>$Lang::tr{'enabled'}</td> |
501 | <td width='30%'><input type='checkbox' name='ENABLED' $checked{'ENABLED'} /></td> | |
502 | </tr> | |
503 | <tr> | |
504 | <td class='base' width='20%'>$Lang::tr{'wlan client encryption'}:</td> | |
505 | <td width='40%'> | |
506 | <select name='ENCRYPTION'> | |
507 | <option value="NONE" $selected{'ENCRYPTION'}{'NONE'}>$Lang::tr{'wlan client encryption none'}</option> | |
19f0fa56 | 508 | <option value="EAP" $selected{'ENCRYPTION'}{'EAP'}>$Lang::tr{'wlan client encryption eap'}</option> |
5addf347 | 509 | <option value="WPA3" $selected{'ENCRYPTION'}{'WPA3'}>$Lang::tr{'wlan client encryption wpa3'}</option> |
61027579 MT |
510 | <option value="WPA2" $selected{'ENCRYPTION'}{'WPA2'}>$Lang::tr{'wlan client encryption wpa2'}</option> |
511 | <option value="WPA" $selected{'ENCRYPTION'}{'WPA'}>$Lang::tr{'wlan client encryption wpa'}</option> | |
5addf347 | 512 | <option value="WEP" $selected{'ENCRYPTION'}{'WEP'}>$Lang::tr{'wlan client encryption wep'}</option> |
61027579 MT |
513 | </select> |
514 | </td> | |
515 | <td colspan="2" width='40%'></td> | |
516 | </tr> | |
517 | <tr> | |
518 | <td class='base' width='20%'>$Lang::tr{'wlan client psk'}: </td> | |
cd6c59aa | 519 | <td width='40%'><input type='password' name='PSK' value="$settings{'PSK'}" size='25'/></td> |
61027579 MT |
520 | <td colspan="2" width='40%'></td> |
521 | </tr> | |
522 | </table> | |
523 | ||
524 | <br> | |
525 | <hr> | |
19f0fa56 MT |
526 | |
527 | <strong> | |
528 | $Lang::tr{'wlan client authentication settings'}: | |
529 | </strong> | |
530 | ||
531 | <table width='100%'> | |
532 | <tr> | |
533 | <td class='base' width='20%'> | |
534 | $Lang::tr{'wlan client eap authentication method'}: | |
535 | </td> | |
536 | <td width='40%'> | |
537 | <select name='AUTH'> | |
538 | <option value="" $selected{'AUTH'}{''}>$Lang::tr{'wlan client auth auto'}</option> | |
539 | <option value="PEAP" $selected{'AUTH'}{'PEAP'}>$Lang::tr{'wlan client auth peap'}</option> | |
540 | <option value="TTLS" $selected{'AUTH'}{'TTLS'}>$Lang::tr{'wlan client auth ttls'}</option> | |
541 | </select> | |
542 | </td> | |
543 | <td colspan="2" width='40%'></td> | |
544 | </tr> | |
545 | <tr> | |
546 | <td class='base' width='20%'> | |
547 | $Lang::tr{'wlan client anonymous identity'}: | |
548 | </td> | |
549 | <td width='40%'> | |
550 | <input type="text" name="ANONYMOUS" value="$settings{"ANONYMOUS"}" size="25" /> | |
551 | </td> | |
552 | <td colspan="2" width='40%'></td> | |
553 | </tr> | |
554 | <tr> | |
555 | <td class='base' width='20%'> | |
556 | $Lang::tr{'wlan client identity'}: | |
557 | </td> | |
558 | <td width='40%'> | |
559 | <input type="text" name="IDENTITY" value="$settings{"IDENTITY"}" size="25" /> | |
560 | </td> | |
561 | <td colspan="2" width='40%'></td> | |
562 | </tr> | |
563 | <tr> | |
564 | <td class='base' width='20%'> | |
565 | $Lang::tr{'wlan client password'}: | |
566 | </td> | |
567 | <td width='40%'> | |
568 | <input type="password" name="PASSWORD" value="$settings{"PASSWORD"}" size="25" /> | |
569 | </td> | |
570 | <td colspan="2" width='40%'></td> | |
571 | </tr> | |
572 | </table> | |
573 | ||
574 | <br> | |
575 | <hr> | |
576 | ||
61027579 MT |
577 | |
578 | <strong> | |
579 | $Lang::tr{'wlan client advanced settings'}: | |
580 | </strong> | |
581 | ||
582 | <table width='100%'> | |
583 | <tr> | |
584 | <td class='base' width='20%'> | |
585 | $Lang::tr{'wlan client wpa mode'}: | |
586 | </td> | |
587 | <td width='40%'> | |
588 | <select name='WPA_MODE'> | |
589 | <option value="" $selected{'WPA_MODE'}{''}>$Lang::tr{'wlan client wpa mode all'}</option> | |
590 | <option value="CCMP-CCMP" $selected{'WPA_MODE'}{'CCMP-CCMP'}>$Lang::tr{'wlan client wpa mode ccmp ccmp'}</option> | |
591 | <option value="CCMP-TKIP" $selected{'WPA_MODE'}{'CCMP-TKIP'}>$Lang::tr{'wlan client wpa mode ccmp tkip'}</option> | |
592 | <option value="TKIP-TKIP" $selected{'WPA_MODE'}{'TKIP-TKIP'}>$Lang::tr{'wlan client wpa mode tkip tkip'}</option> | |
593 | </select> | |
594 | </td> | |
595 | <td colspan="2" width='40%'> | |
596 | <em>($Lang::tr{'wlan client pairwise key group key'})</em> | |
597 | </td> | |
598 | </tr> | |
599 | <tr> | |
600 | <td class='base' width='20%'> | |
601 | $Lang::tr{'priority'}: | |
602 | </td> | |
603 | <td width='40%'> | |
604 | <select name='PRIO'> | |
f90b0f24 | 605 | <option value="0" $selected{'PRIO'}{'0'}>0 ($Lang::tr{'least preferred'})</option> |
61027579 MT |
606 | <option value="1" $selected{'PRIO'}{'1'}>1</option> |
607 | <option value="2" $selected{'PRIO'}{'2'}>2</option> | |
608 | <option value="3" $selected{'PRIO'}{'3'}>3</option> | |
f90b0f24 | 609 | <option value="4" $selected{'PRIO'}{'4'}>4 ($Lang::tr{'most preferred'})</option> |
61027579 MT |
610 | </select> |
611 | </td> | |
612 | <td colspan="2" width='40%'></td> | |
613 | </tr> | |
614 | </table> | |
615 | ||
616 | <br> | |
617 | <hr> | |
618 | ||
619 | <table width='100%'> | |
620 | <tr> | |
621 | <td width='50%' align='center'> | |
622 | <input type='hidden' name='ACTION' value='$action' /> | |
623 | <input type='submit' name='SUBMIT' value='$buttontext' /> | |
624 | </td> | |
625 | </tr> | |
626 | </table> | |
627 | </form> | |
628 | END | |
629 | &Header::closebox(); | |
630 | ||
631 | &Header::closebigbox(); | |
632 | &Header::closepage(); | |
633 | } | |
634 | ||
635 | sub ShowStatus() { | |
636 | my $device = $netsettings{'RED_DEV'}; | |
637 | ||
638 | # Exit if no device is configured. | |
639 | return if ($device eq ""); | |
640 | ||
641 | # Exit if wpa_supplicant is not running on this interface. | |
642 | #return if (! -e "/var/run/wpa_supplicant/$device"); | |
643 | ||
644 | open(FILE, "/usr/local/bin/wirelessclient status |"); | |
645 | ||
646 | my %status = (); | |
647 | while (<FILE>) { | |
648 | chomp($_); | |
649 | ||
650 | my ($key, $value) = split("=", $_); | |
651 | $status{$key} = $value; | |
652 | } | |
653 | ||
654 | close(FILE); | |
655 | ||
656 | # End here, if no there is no input. | |
657 | return if (!keys %status); | |
658 | ||
659 | &Header::openbox('100%', 'left', $Lang::tr{'status'}); | |
660 | ||
661 | if ($status{'ssid'} eq "") { | |
662 | print "<p>$Lang::tr{'wlan client disconnected'}</p>"; | |
663 | ||
664 | } else { | |
665 | print <<END; | |
666 | <table width='100%'> | |
667 | <tr> | |
668 | <td width='20%'> | |
669 | $Lang::tr{'wlan client ssid'} | |
670 | </td> | |
671 | <td width='80%'> | |
672 | $status{'ssid'} | |
673 | </td> | |
674 | </tr> | |
675 | <tr> | |
676 | <td width='20%'> | |
677 | $Lang::tr{'wlan client bssid'} | |
678 | </td> | |
679 | <td width='80%'> | |
680 | $status{'bssid'} | |
681 | </td> | |
682 | </tr> | |
683 | END | |
684 | ||
0628d956 MT |
685 | if ($status{'EAP state'}) { |
686 | my $selected_method = $status{'selectedMethod'}; | |
687 | $selected_method =~ s/\d+ \((.*)\)/$1/e; | |
688 | ||
689 | print <<END; | |
690 | <tr> | |
691 | <td colspan='2'> | |
692 | <strong>$Lang::tr{'wlan client encryption eap'}</strong> | |
693 | </td> | |
694 | </tr> | |
695 | <tr> | |
696 | <td width='20%'> | |
697 | $Lang::tr{'wlan client eap state'} | |
698 | </td> | |
699 | <td width='80%'> | |
700 | $status{'EAP state'} | |
701 | </td> | |
702 | </tr> | |
703 | <tr> | |
704 | <td width='20%'> | |
705 | $Lang::tr{'wlan client method'} | |
706 | </td> | |
707 | <td width='80%'> | |
708 | $selected_method | |
709 | </td> | |
710 | </tr> | |
711 | <tr> | |
712 | <td width='20%'> | |
713 | $Lang::tr{'wlan client tls version'} | |
714 | </td> | |
715 | <td width='80%'> | |
716 | $status{'eap_tls_version'} | |
717 | </td> | |
718 | </tr> | |
719 | <tr> | |
720 | <td width='20%'> | |
721 | $Lang::tr{'wlan client tls cipher'} | |
722 | </td> | |
723 | <td width='80%'> | |
724 | $status{'EAP TLS cipher'} | |
725 | </td> | |
726 | </tr> | |
727 | <tr> | |
728 | <td width='20%'> | |
729 | $Lang::tr{'wlan client eap phase2 method'} | |
730 | </td> | |
731 | <td width='80%'> | |
732 | $status{"${selected_method}v0 Phase2 method"} | |
733 | </td> | |
734 | </tr> | |
735 | END | |
736 | } | |
737 | ||
61027579 MT |
738 | if (($status{'pairwise_cipher'} ne "NONE") || ($status{'group_cipher'} ne "NONE")) { |
739 | print <<END; | |
740 | <tr> | |
741 | <td colspan='2'> | |
742 | <strong>$Lang::tr{'wlan client encryption wpa'}</strong> | |
743 | </td> | |
744 | </tr> | |
745 | <tr> | |
746 | <td width='20%'> | |
747 | $Lang::tr{'wlan client pairwise cipher'} | |
748 | </td> | |
749 | <td width='80%'> | |
750 | $status{'pairwise_cipher'} | |
751 | </td> | |
752 | </tr> | |
753 | <tr> | |
754 | <td width='20%'> | |
755 | $Lang::tr{'wlan client group cipher'} | |
756 | </td> | |
757 | <td width='80%'> | |
758 | $status{'group_cipher'} | |
759 | </td> | |
760 | </tr> | |
761 | END | |
762 | } | |
763 | ||
764 | print "</table>"; | |
765 | } | |
766 | ||
767 | &Header::closebox(); | |
768 | } | |
769 | ||
770 | sub BuildConfiguration() { | |
771 | system("/usr/local/bin/wirelessclient restart"); | |
772 | } | |
773 | ||
774 | sub NextID() { | |
775 | my $highest_id = 0; | |
776 | foreach my $line (@configs) { | |
777 | # Skip commented lines. | |
778 | my $firstchar = substr($line, 0, 1); | |
779 | next if ($firstchar eq "#"); | |
780 | ||
781 | my @config = split(/\,/, $line); | |
782 | if ($config[0] > $highest_id) { | |
783 | $highest_id = $config[0]; | |
784 | } | |
785 | } | |
786 | ||
787 | return $highest_id + 1; | |
788 | } | |
789 | ||
790 | sub DuplicateSSID($) { | |
791 | my $ssid = shift; | |
792 | ||
793 | foreach my $line (@configs) { | |
794 | # Skip commented lines. | |
795 | my $firstchar = substr($line, 0, 1); | |
796 | next if ($firstchar eq "#"); | |
797 | ||
798 | my @config = split(/\,/, $line); | |
799 | if ($config[5] eq $ssid) { | |
800 | return 1; | |
801 | } | |
802 | } | |
803 | ||
804 | return 0; | |
805 | } | |
806 | ||
807 | sub ValidKeyLength($$) { | |
808 | my $algo = shift; | |
809 | my $key = shift; | |
810 | ||
811 | my $key_length = length($key); | |
812 | ||
813 | if ($algo eq "WEP") { | |
814 | # Key must be 13 or 26 characters. | |
815 | if (($key_length == 13) || ($key_length == 26)) { | |
816 | return 0; | |
817 | } | |
818 | ||
819 | return 1; | |
820 | ||
821 | } elsif (($algo eq "WPA2") || ($algo eq "WPA")) { | |
822 | # Key must be between 8 and 63 chars. | |
823 | if (($key_length >= 8) && ($key_length <= 63)) { | |
824 | return 0; | |
825 | } | |
826 | ||
827 | return 1; | |
828 | } | |
829 | ||
830 | # Say okay for all other algorithms. | |
831 | return 0; | |
832 | } | |
833 | ||
834 | sub ValidateInput($) { | |
835 | my $mode = shift; | |
836 | ||
837 | # Check for duplicate SSIDs. | |
838 | if (($mode eq "add") && (DuplicateSSID($settings{'SSID'}))) { | |
839 | return "$Lang::tr{'wlan client duplicate ssid'}: $settings{'SSID'}"; | |
840 | ||
841 | # Check for invalid key length. | |
842 | } elsif (ValidKeyLength($settings{'ENCRYPTION'}, $settings{'PSK'})) { | |
843 | return "$Lang::tr{'wlan client invalid key length'}"; | |
61027579 MT |
844 | } |
845 | ||
846 | # Reset WPA mode, if WPA(2) is not selected. | |
847 | if (($settings{'ENCRYPTION'} ne "WPA") && ($settings{'ENCRYPTION'} ne "WPA2")) { | |
848 | $settings{'WPA_MODE'} = ''; | |
849 | } | |
850 | ||
851 | if ($settings{'ENABLED'} ne "") { | |
852 | $settings{'ENABLED'} = 'on'; | |
853 | } else { | |
854 | $settings{'ENABLED'} = 'off'; | |
855 | } | |
856 | ||
857 | return; | |
858 | } |