wirelessclient.cgi: fix handling of "'" 2nd try.
[people/teissler/ipfire-2.x.git] / html / cgi-bin / wirelessclient.cgi
1 #!/usr/bin/perl
2 ###############################################################################
3 # #
4 # IPFire.org - A linux based firewall #
5 # Copyright (C) 2012 IPFire Team <info@ipfire.org> #
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
22 # DEVICE,ENABLED,MODE,WPA_MODE,SSID,PSK,PRIO
23 # wlan0,on,WPA2,,Use This One Mum,ThisIsTheKey,2
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'});
135
136 # Add the new configuration and write all the stuff to the configuration file.
137 my $line = join(',', @config) . "\n";
138 push(@configs, $line);
139
140 # Save updated configuration settings.
141 open(FILE, ">$datafile") or die 'wlan client datafile error';
142 print FILE @configs;
143 close(FILE);
144
145 # Update configuration files.
146 &BuildConfiguration();
147
148 # Reset ACTION.
149 $settings{'ACTION'} = '';
150 }
151 }
152
153 if ($settings{'ACTION'} eq $Lang::tr{'edit'}) {
154 foreach my $line (@configs) {
155 chomp($line);
156 my @config = split(/\,/, $line);
157
158 if ($config[0] eq $settings{'ID'}) {
159 $settings{'ID'} = $config[0];
160 $settings{'INTERFACE'} = $config[1];
161 $settings{'ENABLED'} = $config[2];
162 $settings{'ENCRYPTION'} = $config[3];
163 $settings{'WPA_MODE'} = $config[4];
164 $settings{'SSID'} = $config[5];
165 $settings{'PSK'} = $config[6];
166 $settings{'PRIO'} = $config[7];
167 }
168 }
169 }
170
171 if ($settings{'ACTION'} eq $Lang::tr{'update'}) {
172 $errormessage = ValidateInput("update");
173
174 unless ($errormessage) {
175 my @update;
176 foreach my $line (@configs) {
177 chomp($line);
178 my @config = split(/\,/, $line);
179
180 # Update the entry with the matching ID.
181 if ($config[0] eq $settings{'ID'}) {
182 # Update all configuration settings.
183 # ID and INTERFACE cannot be changed.
184 $config[2] = $settings{'ENABLED'};
185 $config[3] = $settings{'ENCRYPTION'};
186 $config[4] = $settings{'WPA_MODE'};
187 $config[5] = $settings{'SSID'};
188 $config[6] = $settings{'PSK'};
189 $config[7] = $settings{'PRIO'};
190
191 $line = join(',', @config);
192 }
193
194 push(@update, $line."\n");
195 }
196
197 # Save updated configuration settings.
198 open(FILE, ">$datafile") or die 'wlan client datafile error';
199 print FILE @update;
200 close(FILE);
201
202 @configs = @update;
203
204 # Update configuration files.
205 &BuildConfiguration();
206
207 # Reset ACTION.
208 $settings{'ACTION'} = '';
209 }
210 }
211
212 if ($settings{'ACTION'} eq $Lang::tr{'remove'}) {
213 my @update;
214
215 foreach my $line (@configs) {
216 chomp($line);
217 my @config = split(/\,/, $line);
218
219 # Skip the to be removed entry.
220 if ($config[0] eq $settings{'ID'}) {
221 next;
222 }
223
224 push(@update, $line."\n");
225 }
226
227 # Save updated configuration settings.
228 open(FILE, ">$datafile") or die 'wlan client datafile error';
229 print FILE @update;
230 close(FILE);
231
232 @configs = @update;
233
234 # Update configuration files.
235 &BuildConfiguration();
236
237 # Reset ACTION.
238 $settings{'ACTION'} = '';
239 }
240
241 if ($settings{'ACTION'} eq '') { # First launch from GUI
242 &showMainBox();
243 } else {
244 # Action has been set, so show the edit box.
245 &showEditBox();
246 }
247
248 sub showMainBox() {
249 &Header::openpage($Lang::tr{'wlan client configuration'}, 1, '');
250 &Header::openbigbox('100%', 'left', '', $errormessage);
251
252 &Header::openbox('100%', 'left', $Lang::tr{'wlan client configuration'});
253
254 print <<END;
255 <form method='POST' action='$ENV{'SCRIPT_NAME'}' style='text-align: center;'>
256 <input type='submit' name='ACTION' value='$Lang::tr{'wlan client new network'}' />
257 </form>
258
259 <br><hr><br>
260
261 <table width="100%">
262 <tr>
263 <th align='center'>$Lang::tr{'wlan client ssid'}</th>
264 <th align='center'>$Lang::tr{'wlan client encryption'}</th>
265 <th align='center'>$Lang::tr{'priority'}</th>
266 </tr>
267 END
268
269 #
270 # Print each line of @configs list
271 #
272
273 my $key = 0;
274 foreach my $line (@configs) {
275 # Skip commented lines.
276 my $firstchar = substr($line, 0, 1);
277 next if ($firstchar eq "#");
278
279 chomp($line);
280 my @config = split(/\,/,$line);
281
282 #Choose icon for checkbox
283 my $gif = '';
284 my $gdesc = '';
285 if ($config[2] eq 'on' ) {
286 $gif = 'on.gif';
287 $gdesc = $Lang::tr{'click to disable'};
288 } else {
289 $gif = 'off.gif';
290 $gdesc = $Lang::tr{'click to enable'};
291 }
292
293 # Colorize each line
294 if ($key % 2) {
295 print "<tr bgcolor='$color{'color22'}'>";
296 } else {
297 print "<tr bgcolor='$color{'color20'}'>";
298 }
299
300 my $encryption_mode = $Lang::tr{'unknown'};
301 if ($config[3] eq "NONE") {
302 $encryption_mode = $Lang::tr{'wlan client encryption none'};
303 } elsif ($config[3] eq "WEP") {
304 $encryption_mode = $Lang::tr{'wlan client encryption wep'};
305 } elsif ($config[3] eq "WPA") {
306 $encryption_mode = $Lang::tr{'wlan client encryption wpa'};
307 } elsif ($config[3] eq "WPA2") {
308 $encryption_mode = $Lang::tr{'wlan client encryption wpa2'};
309 }
310
311 if (($config[3] eq "WPA") || ($config[3] eq "WPA2")) {
312 my $wpa_pairwise = "$Lang::tr{'wlan client ccmp'} $Lang::tr{'wlan client and'} $Lang::tr{'wlan client tkip'}";
313 my $wpa_group = "$Lang::tr{'wlan client ccmp'} $Lang::tr{'wlan client and'} $Lang::tr{'wlan client tkip'}";
314
315 if ($config[4] eq "CCMP-CCMP") {
316 $wpa_pairwise = $Lang::tr{'wlan client ccmp'};
317 $wpa_group = $Lang::tr{'wlan client ccmp'};
318 } elsif ($config[4] eq "CCMP-TKIP") {
319 $wpa_pairwise = $Lang::tr{'wlan client ccmp'};
320 $wpa_group = $Lang::tr{'wlan client tkip'};
321 } elsif ($config[4] eq "TKIP-TKIP") {
322 $wpa_pairwise = $Lang::tr{'wlan client tkip'};
323 $wpa_group = $Lang::tr{'wlan client tkip'};
324 }
325
326 $encryption_mode .= "<hr>";
327 $encryption_mode .= "<strong>$Lang::tr{'wlan client pairwise key algorithm'}</strong>: ";
328 $encryption_mode .= $wpa_pairwise;
329 $encryption_mode .= "<br>";
330 $encryption_mode .= "<strong>$Lang::tr{'wlan client group key algorithm'}</strong>: ";
331 $encryption_mode .= $wpa_group;
332 }
333
334 print <<END;
335 <td align='center'>$config[5]</td>
336 <td align='center'>$encryption_mode</td>
337 <td align='center'>$config[7]</td>
338 <td align='center' width='5%'>
339 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
340 <input type='hidden' name='ACTION' value='$Lang::tr{'toggle enable disable'}' />
341 <input type='image' name='$Lang::tr{'toggle enable disable'}' src='/images/$gif' alt='$gdesc' title='$gdesc' />
342 <input type='hidden' name='ID' value='$config[0]' />
343 </form>
344 </td>
345 <td align='center' width='5%'>
346 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
347 <input type='hidden' name='ACTION' value='$Lang::tr{'edit'}' />
348 <input type='image' name='$Lang::tr{'edit'}' src='/images/edit.gif' alt='$Lang::tr{'edit'}' title='$Lang::tr{'edit'}' />
349 <input type='hidden' name='ID' value='$config[0]' />
350 </form>
351 </td>
352 <td align='center' width='5%'>
353 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
354 <input type='hidden' name='ACTION' value='$Lang::tr{'remove'}' />
355 <input type='image' name='$Lang::tr{'remove'}' src='/images/delete.gif' alt='$Lang::tr{'remove'}' title='$Lang::tr{'remove'}' />
356 <input type='hidden' name='ID' value='$config[0]' />
357 </form>
358 </td>
359 </tr>
360 END
361 $key++;
362 }
363 print "</table>";
364
365 # If table contains entries, print 'Key to action icons'
366 if ($key) {
367 print <<END;
368 <table>
369 <tr>
370 <td class='boldbase'>&nbsp;<b>$Lang::tr{'legend'}:&nbsp;</b></td>
371 <td><img src='/images/on.gif' alt='$Lang::tr{'click to disable'}' /></td>
372 <td class='base'>$Lang::tr{'click to disable'}</td>
373 <td>&nbsp;&nbsp;</td>
374 <td><img src='/images/off.gif' alt='$Lang::tr{'click to enable'}' /></td>
375 <td class='base'>$Lang::tr{'click to enable'}</td>
376 <td>&nbsp;&nbsp;</td>
377 <td><img src='/images/edit.gif' alt='$Lang::tr{'edit'}' /></td>
378 <td class='base'>$Lang::tr{'edit'}</td>
379 <td>&nbsp;&nbsp;</td>
380 <td><img src='/images/delete.gif' alt='$Lang::tr{'remove'}' /></td>
381 <td class='base'>$Lang::tr{'remove'}</td>
382 </tr>
383 </table>
384 END
385 }
386
387 &Header::closebox();
388
389 # Show status box.
390 &ShowStatus();
391
392 &Header::closebigbox();
393 &Header::closepage();
394 }
395
396 sub showEditBox() {
397 &Header::openpage($Lang::tr{'wlan client configuration'}, 1, '');
398 &Header::openbigbox('100%', 'left', '', $errormessage);
399
400 if ($errormessage) {
401 &Header::openbox('100%', 'left', $Lang::tr{'error messages'});
402 print "<font class='base'>$errormessage&nbsp;</font>";
403 &Header::closebox();
404 }
405
406 my $buttontext = $Lang::tr{'add'};
407 if ($settings{'ID'} ne '') {
408 $buttontext = $Lang::tr{'update'};
409 &Header::openbox('100%', 'left', $Lang::tr{'wlan client edit entry'});
410 } else {
411 &Header::openbox('100%', 'left', $Lang::tr{'wlan client new entry'});
412 $settings{'ENABLED'} = 'on';
413 }
414 my $action = $buttontext;
415
416 my %checked = ();
417 $checked{'ENABLED'} = ($settings{'ENABLED'} ne 'on' ) ? '' : "checked='checked'";
418
419 my %selected = ();
420 $selected{'ENCRYPTION'} = ();
421 $selected{'ENCRYPTION'}{'NONE'} = '';
422 $selected{'ENCRYPTION'}{'WPA2'} = '';
423 $selected{'ENCRYPTION'}{'WPA'} = '';
424 $selected{'ENCRYPTION'}{'WEP'} = '';
425 $selected{'ENCRYPTION'}{$settings{'ENCRYPTION'}} = "selected='selected'";
426
427 $selected{'WPA_MODE'} = ();
428 $selected{'WPA_MODE'}{''} = '';
429 $selected{'WPA_MODE'}{'CCMP-CCMP'} = '';
430 $selected{'WPA_MODE'}{'CCMP-TKIP'} = '';
431 $selected{'WPA_MODE'}{'TKIP-TKIP'} = '';
432 $selected{'WPA_MODE'}{$settings{'WPA_MODE'}} = "selected='selected'";
433
434 $selected{'PRIO'} = ();
435 $selected{'PRIO'}{'0'} = '';
436 $selected{'PRIO'}{'1'} = '';
437 $selected{'PRIO'}{'2'} = '';
438 $selected{'PRIO'}{'3'} = '';
439 $selected{'PRIO'}{'4'} = '';
440 $selected{'PRIO'}{$settings{'PRIO'}} = "selected='selected'";
441
442 print <<END;
443 <form method='POST' action='$ENV{'SCRIPT_NAME'}'>
444 <input type='hidden' name='ID' value='$settings{'ID'}'>
445
446 <table width='100%'>
447 <tr>
448 <td class='base' width='20%'>$Lang::tr{'wlan client ssid'}:</td>
449 <td width='40%'><input type='text' name='SSID' value="$settings{'SSID'}" size='25'/></td>
450 <td class='base' width='10%'>$Lang::tr{'enabled'}</td>
451 <td width='30%'><input type='checkbox' name='ENABLED' $checked{'ENABLED'} /></td>
452 </tr>
453 <tr>
454 <td class='base' width='20%'>$Lang::tr{'wlan client encryption'}:</td>
455 <td width='40%'>
456 <select name='ENCRYPTION'>
457 <option value="NONE" $selected{'ENCRYPTION'}{'NONE'}>$Lang::tr{'wlan client encryption none'}</option>
458 <option value="WPA2" $selected{'ENCRYPTION'}{'WPA2'}>$Lang::tr{'wlan client encryption wpa2'}</option>
459 <option value="WPA" $selected{'ENCRYPTION'}{'WPA'}>$Lang::tr{'wlan client encryption wpa'}</option>
460 <option value="WEP" $selected{'ENCRYPTION'}{'WEP'}>$Lang::tr{'wlan client encryption wep'}</option>
461 </select>
462 </td>
463 <td colspan="2" width='40%'></td>
464 </tr>
465 <tr>
466 <td class='base' width='20%'>$Lang::tr{'wlan client psk'}:&nbsp;</td>
467 <td width='40%'><input type='password' name='PSK' value="$settings{'PSK'}" size='25'/></td>
468 <td colspan="2" width='40%'></td>
469 </tr>
470 </table>
471
472 <br>
473 <hr>
474
475 <strong>
476 $Lang::tr{'wlan client advanced settings'}:
477 </strong>
478
479 <table width='100%'>
480 <tr>
481 <td class='base' width='20%'>
482 $Lang::tr{'wlan client wpa mode'}:
483 </td>
484 <td width='40%'>
485 <select name='WPA_MODE'>
486 <option value="" $selected{'WPA_MODE'}{''}>$Lang::tr{'wlan client wpa mode all'}</option>
487 <option value="CCMP-CCMP" $selected{'WPA_MODE'}{'CCMP-CCMP'}>$Lang::tr{'wlan client wpa mode ccmp ccmp'}</option>
488 <option value="CCMP-TKIP" $selected{'WPA_MODE'}{'CCMP-TKIP'}>$Lang::tr{'wlan client wpa mode ccmp tkip'}</option>
489 <option value="TKIP-TKIP" $selected{'WPA_MODE'}{'TKIP-TKIP'}>$Lang::tr{'wlan client wpa mode tkip tkip'}</option>
490 </select>
491 </td>
492 <td colspan="2" width='40%'>
493 <em>($Lang::tr{'wlan client pairwise key group key'})</em>
494 </td>
495 </tr>
496 <tr>
497 <td class='base' width='20%'>
498 $Lang::tr{'priority'}:
499 </td>
500 <td width='40%'>
501 <select name='PRIO'>
502 <option value="0" $selected{'PRIO'}{'0'}>0 ($Lang::tr{'most preferred'})</option>
503 <option value="1" $selected{'PRIO'}{'1'}>1</option>
504 <option value="2" $selected{'PRIO'}{'2'}>2</option>
505 <option value="3" $selected{'PRIO'}{'3'}>3</option>
506 <option value="4" $selected{'PRIO'}{'4'}>4 ($Lang::tr{'least preferred'})</option>
507 </select>
508 </td>
509 <td colspan="2" width='40%'></td>
510 </tr>
511 </table>
512
513 <br>
514 <hr>
515
516 <table width='100%'>
517 <tr>
518 <td width='50%' align='center'>
519 <input type='hidden' name='ACTION' value='$action' />
520 <input type='submit' name='SUBMIT' value='$buttontext' />
521 </td>
522 </tr>
523 </table>
524 </form>
525 END
526 &Header::closebox();
527
528 &Header::closebigbox();
529 &Header::closepage();
530 }
531
532 sub ShowStatus() {
533 my $device = $netsettings{'RED_DEV'};
534
535 # Exit if no device is configured.
536 return if ($device eq "");
537
538 # Exit if wpa_supplicant is not running on this interface.
539 #return if (! -e "/var/run/wpa_supplicant/$device");
540
541 open(FILE, "/usr/local/bin/wirelessclient status |");
542
543 my %status = ();
544 while (<FILE>) {
545 chomp($_);
546
547 my ($key, $value) = split("=", $_);
548 $status{$key} = $value;
549 }
550
551 close(FILE);
552
553 # End here, if no there is no input.
554 return if (!keys %status);
555
556 &Header::openbox('100%', 'left', $Lang::tr{'status'});
557
558 if ($status{'ssid'} eq "") {
559 print "<p>$Lang::tr{'wlan client disconnected'}</p>";
560
561 } else {
562 print <<END;
563 <table width='100%'>
564 <tr>
565 <td width='20%'>
566 $Lang::tr{'wlan client ssid'}
567 </td>
568 <td width='80%'>
569 $status{'ssid'}
570 </td>
571 </tr>
572 <tr>
573 <td width='20%'>
574 $Lang::tr{'wlan client bssid'}
575 </td>
576 <td width='80%'>
577 $status{'bssid'}
578 </td>
579 </tr>
580 END
581
582 if (($status{'pairwise_cipher'} ne "NONE") || ($status{'group_cipher'} ne "NONE")) {
583 print <<END;
584 <tr>
585 <td colspan='2'>
586 <strong>$Lang::tr{'wlan client encryption wpa'}</strong>
587 </td>
588 </tr>
589 <tr>
590 <td width='20%'>
591 $Lang::tr{'wlan client pairwise cipher'}
592 </td>
593 <td width='80%'>
594 $status{'pairwise_cipher'}
595 </td>
596 </tr>
597 <tr>
598 <td width='20%'>
599 $Lang::tr{'wlan client group cipher'}
600 </td>
601 <td width='80%'>
602 $status{'group_cipher'}
603 </td>
604 </tr>
605 END
606 }
607
608 print "</table>";
609 }
610
611 &Header::closebox();
612 }
613
614 sub BuildConfiguration() {
615 system("/usr/local/bin/wirelessclient restart");
616 }
617
618 sub NextID() {
619 my $highest_id = 0;
620 foreach my $line (@configs) {
621 # Skip commented lines.
622 my $firstchar = substr($line, 0, 1);
623 next if ($firstchar eq "#");
624
625 my @config = split(/\,/, $line);
626 if ($config[0] > $highest_id) {
627 $highest_id = $config[0];
628 }
629 }
630
631 return $highest_id + 1;
632 }
633
634 sub DuplicateSSID($) {
635 my $ssid = shift;
636
637 foreach my $line (@configs) {
638 # Skip commented lines.
639 my $firstchar = substr($line, 0, 1);
640 next if ($firstchar eq "#");
641
642 my @config = split(/\,/, $line);
643 if ($config[5] eq $ssid) {
644 return 1;
645 }
646 }
647
648 return 0;
649 }
650
651 sub ValidKeyLength($$) {
652 my $algo = shift;
653 my $key = shift;
654
655 my $key_length = length($key);
656
657 if ($algo eq "WEP") {
658 # Key must be 13 or 26 characters.
659 if (($key_length == 13) || ($key_length == 26)) {
660 return 0;
661 }
662
663 return 1;
664
665 } elsif (($algo eq "WPA2") || ($algo eq "WPA")) {
666 # Key must be between 8 and 63 chars.
667 if (($key_length >= 8) && ($key_length <= 63)) {
668 return 0;
669 }
670
671 return 1;
672 }
673
674 # Say okay for all other algorithms.
675 return 0;
676 }
677
678 sub ValidateInput($) {
679 my $mode = shift;
680
681 # Check for duplicate SSIDs.
682 if (($mode eq "add") && (DuplicateSSID($settings{'SSID'}))) {
683 return "$Lang::tr{'wlan client duplicate ssid'}: $settings{'SSID'}";
684
685 # Check for invalid key length.
686 } elsif (ValidKeyLength($settings{'ENCRYPTION'}, $settings{'PSK'})) {
687 return "$Lang::tr{'wlan client invalid key length'}";
688
689 }
690
691 # Reset WPA mode, if WPA(2) is not selected.
692 if (($settings{'ENCRYPTION'} ne "WPA") && ($settings{'ENCRYPTION'} ne "WPA2")) {
693 $settings{'WPA_MODE'} = '';
694 }
695
696 if ($settings{'ENABLED'} ne "") {
697 $settings{'ENABLED'} = 'on';
698 } else {
699 $settings{'ENABLED'} = 'off';
700 }
701
702 return;
703 }