]> git.ipfire.org Git - ipfire-2.x.git/blame - html/cgi-bin/wirelessclient.cgi
ids.cgi: Rework "Enable IPS" section
[ipfire-2.x.git] / html / cgi-bin / wirelessclient.cgi
CommitLineData
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
25use strict;
26
27# enable only the following on debugging purpose
28use warnings;
29use CGI::Carp 'fatalsToBrowser';
30
31require '/var/ipfire/general-functions.pl';
32require "${General::swroot}/lang.pl";
33require "${General::swroot}/header.pl";
34
35#workaround to suppress a warning when a variable is used only once
36my @dummy = ( ${Header::colouryellow} );
37undef (@dummy);
38
39# Files used
40my $setting = "${General::swroot}/main/settings";
41our $datafile = "${General::swroot}/ethernet/wireless";
42
43my %color = ();
44my %mainsettings = ();
45&General::readhash("${General::swroot}/main/settings", \%mainsettings);
46&General::readhash("/srv/web/ipfire/html/themes/".$mainsettings{'THEME'}."/include/colors.txt", \%color);
47
48our %settings = ();
49our %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
63my $errormessage = '';
64my $warnmessage = '';
65
66&Header::showhttpheaders();
67
68#Get GUI values
69&Header::getcgihash(\%settings);
70
71# Load multiline data
72our @configs = ();
73if (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.
82if ($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
119if ($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
157if ($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
179if ($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
224if ($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
253if ($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
260sub 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>
282END
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>
403END
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'>&nbsp;<b>$Lang::tr{'legend'}:&nbsp;</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>&nbsp;&nbsp;</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>&nbsp;&nbsp;</td>
420 <td><img src='/images/edit.gif' alt='$Lang::tr{'edit'}' /></td>
421 <td class='base'>$Lang::tr{'edit'}</td>
422 <td>&nbsp;&nbsp;</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>
427END
428 }
429
430 &Header::closebox();
431
432 # Show status box.
433 &ShowStatus();
434
435 &Header::closebigbox();
436 &Header::closepage();
437}
438
439sub 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&nbsp;</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'} = '';
465 $selected{'ENCRYPTION'}{'WPA2'} = '';
466 $selected{'ENCRYPTION'}{'WPA'} = '';
467 $selected{'ENCRYPTION'}{'WEP'} = '';
468 $selected{'ENCRYPTION'}{$settings{'ENCRYPTION'}} = "selected='selected'";
469
470 $selected{'WPA_MODE'} = ();
471 $selected{'WPA_MODE'}{''} = '';
472 $selected{'WPA_MODE'}{'CCMP-CCMP'} = '';
473 $selected{'WPA_MODE'}{'CCMP-TKIP'} = '';
474 $selected{'WPA_MODE'}{'TKIP-TKIP'} = '';
475 $selected{'WPA_MODE'}{$settings{'WPA_MODE'}} = "selected='selected'";
476
19f0fa56
MT
477 $selected{'AUTH'} = ();
478 $selected{'AUTH'}{''} = '';
479 $selected{'AUTH'}{'PEAP'} = '';
480 $selected{'AUTH'}{'TTLS'} = '';
481 $selected{'AUTH'}{$settings{'AUTH'}} = "selected='selected'";
482
61027579
MT
483 $selected{'PRIO'} = ();
484 $selected{'PRIO'}{'0'} = '';
485 $selected{'PRIO'}{'1'} = '';
486 $selected{'PRIO'}{'2'} = '';
487 $selected{'PRIO'}{'3'} = '';
488 $selected{'PRIO'}{'4'} = '';
489 $selected{'PRIO'}{$settings{'PRIO'}} = "selected='selected'";
490
491 print <<END;
492 <form method='POST' action='$ENV{'SCRIPT_NAME'}'>
493 <input type='hidden' name='ID' value='$settings{'ID'}'>
494
495 <table width='100%'>
496 <tr>
497 <td class='base' width='20%'>$Lang::tr{'wlan client ssid'}:</td>
cd6c59aa 498 <td width='40%'><input type='text' name='SSID' value="$settings{'SSID'}" size='25'/></td>
61027579
MT
499 <td class='base' width='10%'>$Lang::tr{'enabled'}</td>
500 <td width='30%'><input type='checkbox' name='ENABLED' $checked{'ENABLED'} /></td>
501 </tr>
502 <tr>
503 <td class='base' width='20%'>$Lang::tr{'wlan client encryption'}:</td>
504 <td width='40%'>
505 <select name='ENCRYPTION'>
506 <option value="NONE" $selected{'ENCRYPTION'}{'NONE'}>$Lang::tr{'wlan client encryption none'}</option>
19f0fa56 507 <option value="EAP" $selected{'ENCRYPTION'}{'EAP'}>$Lang::tr{'wlan client encryption eap'}</option>
61027579
MT
508 <option value="WPA2" $selected{'ENCRYPTION'}{'WPA2'}>$Lang::tr{'wlan client encryption wpa2'}</option>
509 <option value="WPA" $selected{'ENCRYPTION'}{'WPA'}>$Lang::tr{'wlan client encryption wpa'}</option>
510 <option value="WEP" $selected{'ENCRYPTION'}{'WEP'}>$Lang::tr{'wlan client encryption wep'}</option>
511 </select>
512 </td>
513 <td colspan="2" width='40%'></td>
514 </tr>
515 <tr>
516 <td class='base' width='20%'>$Lang::tr{'wlan client psk'}:&nbsp;</td>
cd6c59aa 517 <td width='40%'><input type='password' name='PSK' value="$settings{'PSK'}" size='25'/></td>
61027579
MT
518 <td colspan="2" width='40%'></td>
519 </tr>
520 </table>
521
522 <br>
523 <hr>
19f0fa56
MT
524
525 <strong>
526 $Lang::tr{'wlan client authentication settings'}:
527 </strong>
528
529 <table width='100%'>
530 <tr>
531 <td class='base' width='20%'>
532 $Lang::tr{'wlan client eap authentication method'}:
533 </td>
534 <td width='40%'>
535 <select name='AUTH'>
536 <option value="" $selected{'AUTH'}{''}>$Lang::tr{'wlan client auth auto'}</option>
537 <option value="PEAP" $selected{'AUTH'}{'PEAP'}>$Lang::tr{'wlan client auth peap'}</option>
538 <option value="TTLS" $selected{'AUTH'}{'TTLS'}>$Lang::tr{'wlan client auth ttls'}</option>
539 </select>
540 </td>
541 <td colspan="2" width='40%'></td>
542 </tr>
543 <tr>
544 <td class='base' width='20%'>
545 $Lang::tr{'wlan client anonymous identity'}:
546 </td>
547 <td width='40%'>
548 <input type="text" name="ANONYMOUS" value="$settings{"ANONYMOUS"}" size="25" />
549 </td>
550 <td colspan="2" width='40%'></td>
551 </tr>
552 <tr>
553 <td class='base' width='20%'>
554 $Lang::tr{'wlan client identity'}:
555 </td>
556 <td width='40%'>
557 <input type="text" name="IDENTITY" value="$settings{"IDENTITY"}" size="25" />
558 </td>
559 <td colspan="2" width='40%'></td>
560 </tr>
561 <tr>
562 <td class='base' width='20%'>
563 $Lang::tr{'wlan client password'}:
564 </td>
565 <td width='40%'>
566 <input type="password" name="PASSWORD" value="$settings{"PASSWORD"}" size="25" />
567 </td>
568 <td colspan="2" width='40%'></td>
569 </tr>
570 </table>
571
572 <br>
573 <hr>
574
61027579
MT
575
576 <strong>
577 $Lang::tr{'wlan client advanced settings'}:
578 </strong>
579
580 <table width='100%'>
581 <tr>
582 <td class='base' width='20%'>
583 $Lang::tr{'wlan client wpa mode'}:
584 </td>
585 <td width='40%'>
586 <select name='WPA_MODE'>
587 <option value="" $selected{'WPA_MODE'}{''}>$Lang::tr{'wlan client wpa mode all'}</option>
588 <option value="CCMP-CCMP" $selected{'WPA_MODE'}{'CCMP-CCMP'}>$Lang::tr{'wlan client wpa mode ccmp ccmp'}</option>
589 <option value="CCMP-TKIP" $selected{'WPA_MODE'}{'CCMP-TKIP'}>$Lang::tr{'wlan client wpa mode ccmp tkip'}</option>
590 <option value="TKIP-TKIP" $selected{'WPA_MODE'}{'TKIP-TKIP'}>$Lang::tr{'wlan client wpa mode tkip tkip'}</option>
591 </select>
592 </td>
593 <td colspan="2" width='40%'>
594 <em>($Lang::tr{'wlan client pairwise key group key'})</em>
595 </td>
596 </tr>
597 <tr>
598 <td class='base' width='20%'>
599 $Lang::tr{'priority'}:
600 </td>
601 <td width='40%'>
602 <select name='PRIO'>
f3484435 603 <option value="0" $selected{'PRIO'}{'0'}>0 ($Lang::tr{'most preferred'})</option>
61027579
MT
604 <option value="1" $selected{'PRIO'}{'1'}>1</option>
605 <option value="2" $selected{'PRIO'}{'2'}>2</option>
606 <option value="3" $selected{'PRIO'}{'3'}>3</option>
f3484435 607 <option value="4" $selected{'PRIO'}{'4'}>4 ($Lang::tr{'least preferred'})</option>
61027579
MT
608 </select>
609 </td>
610 <td colspan="2" width='40%'></td>
611 </tr>
612 </table>
613
614 <br>
615 <hr>
616
617 <table width='100%'>
618 <tr>
619 <td width='50%' align='center'>
620 <input type='hidden' name='ACTION' value='$action' />
621 <input type='submit' name='SUBMIT' value='$buttontext' />
622 </td>
623 </tr>
624 </table>
625 </form>
626END
627 &Header::closebox();
628
629 &Header::closebigbox();
630 &Header::closepage();
631}
632
633sub ShowStatus() {
634 my $device = $netsettings{'RED_DEV'};
635
636 # Exit if no device is configured.
637 return if ($device eq "");
638
639 # Exit if wpa_supplicant is not running on this interface.
640 #return if (! -e "/var/run/wpa_supplicant/$device");
641
642 open(FILE, "/usr/local/bin/wirelessclient status |");
643
644 my %status = ();
645 while (<FILE>) {
646 chomp($_);
647
648 my ($key, $value) = split("=", $_);
649 $status{$key} = $value;
650 }
651
652 close(FILE);
653
654 # End here, if no there is no input.
655 return if (!keys %status);
656
657 &Header::openbox('100%', 'left', $Lang::tr{'status'});
658
659 if ($status{'ssid'} eq "") {
660 print "<p>$Lang::tr{'wlan client disconnected'}</p>";
661
662 } else {
663 print <<END;
664 <table width='100%'>
665 <tr>
666 <td width='20%'>
667 $Lang::tr{'wlan client ssid'}
668 </td>
669 <td width='80%'>
670 $status{'ssid'}
671 </td>
672 </tr>
673 <tr>
674 <td width='20%'>
675 $Lang::tr{'wlan client bssid'}
676 </td>
677 <td width='80%'>
678 $status{'bssid'}
679 </td>
680 </tr>
681END
682
0628d956
MT
683 if ($status{'EAP state'}) {
684 my $selected_method = $status{'selectedMethod'};
685 $selected_method =~ s/\d+ \((.*)\)/$1/e;
686
687 print <<END;
688 <tr>
689 <td colspan='2'>
690 <strong>$Lang::tr{'wlan client encryption eap'}</strong>
691 </td>
692 </tr>
693 <tr>
694 <td width='20%'>
695 $Lang::tr{'wlan client eap state'}
696 </td>
697 <td width='80%'>
698 $status{'EAP state'}
699 </td>
700 </tr>
701 <tr>
702 <td width='20%'>
703 $Lang::tr{'wlan client method'}
704 </td>
705 <td width='80%'>
706 $selected_method
707 </td>
708 </tr>
709 <tr>
710 <td width='20%'>
711 $Lang::tr{'wlan client tls version'}
712 </td>
713 <td width='80%'>
714 $status{'eap_tls_version'}
715 </td>
716 </tr>
717 <tr>
718 <td width='20%'>
719 $Lang::tr{'wlan client tls cipher'}
720 </td>
721 <td width='80%'>
722 $status{'EAP TLS cipher'}
723 </td>
724 </tr>
725 <tr>
726 <td width='20%'>
727 $Lang::tr{'wlan client eap phase2 method'}
728 </td>
729 <td width='80%'>
730 $status{"${selected_method}v0 Phase2 method"}
731 </td>
732 </tr>
733END
734 }
735
61027579
MT
736 if (($status{'pairwise_cipher'} ne "NONE") || ($status{'group_cipher'} ne "NONE")) {
737 print <<END;
738 <tr>
739 <td colspan='2'>
740 <strong>$Lang::tr{'wlan client encryption wpa'}</strong>
741 </td>
742 </tr>
743 <tr>
744 <td width='20%'>
745 $Lang::tr{'wlan client pairwise cipher'}
746 </td>
747 <td width='80%'>
748 $status{'pairwise_cipher'}
749 </td>
750 </tr>
751 <tr>
752 <td width='20%'>
753 $Lang::tr{'wlan client group cipher'}
754 </td>
755 <td width='80%'>
756 $status{'group_cipher'}
757 </td>
758 </tr>
759END
760 }
761
762 print "</table>";
763 }
764
765 &Header::closebox();
766}
767
768sub BuildConfiguration() {
769 system("/usr/local/bin/wirelessclient restart");
770}
771
772sub NextID() {
773 my $highest_id = 0;
774 foreach my $line (@configs) {
775 # Skip commented lines.
776 my $firstchar = substr($line, 0, 1);
777 next if ($firstchar eq "#");
778
779 my @config = split(/\,/, $line);
780 if ($config[0] > $highest_id) {
781 $highest_id = $config[0];
782 }
783 }
784
785 return $highest_id + 1;
786}
787
788sub DuplicateSSID($) {
789 my $ssid = shift;
790
791 foreach my $line (@configs) {
792 # Skip commented lines.
793 my $firstchar = substr($line, 0, 1);
794 next if ($firstchar eq "#");
795
796 my @config = split(/\,/, $line);
797 if ($config[5] eq $ssid) {
798 return 1;
799 }
800 }
801
802 return 0;
803}
804
805sub ValidKeyLength($$) {
806 my $algo = shift;
807 my $key = shift;
808
809 my $key_length = length($key);
810
811 if ($algo eq "WEP") {
812 # Key must be 13 or 26 characters.
813 if (($key_length == 13) || ($key_length == 26)) {
814 return 0;
815 }
816
817 return 1;
818
819 } elsif (($algo eq "WPA2") || ($algo eq "WPA")) {
820 # Key must be between 8 and 63 chars.
821 if (($key_length >= 8) && ($key_length <= 63)) {
822 return 0;
823 }
824
825 return 1;
826 }
827
828 # Say okay for all other algorithms.
829 return 0;
830}
831
832sub ValidateInput($) {
833 my $mode = shift;
834
835 # Check for duplicate SSIDs.
836 if (($mode eq "add") && (DuplicateSSID($settings{'SSID'}))) {
837 return "$Lang::tr{'wlan client duplicate ssid'}: $settings{'SSID'}";
838
839 # Check for invalid key length.
840 } elsif (ValidKeyLength($settings{'ENCRYPTION'}, $settings{'PSK'})) {
841 return "$Lang::tr{'wlan client invalid key length'}";
842
843 }
844
845 # Reset WPA mode, if WPA(2) is not selected.
846 if (($settings{'ENCRYPTION'} ne "WPA") && ($settings{'ENCRYPTION'} ne "WPA2")) {
847 $settings{'WPA_MODE'} = '';
848 }
849
850 if ($settings{'ENABLED'} ne "") {
851 $settings{'ENABLED'} = 'on';
852 } else {
853 $settings{'ENABLED'} = 'off';
854 }
855
856 return;
857}