]> git.ipfire.org Git - people/pmueller/ipfire-2.x.git/blame - html/cgi-bin/wirelessclient.cgi
Hardcode theme to ipfire
[people/pmueller/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);
8186b372 46&General::readhash("/srv/web/ipfire/html/themes/ipfire/include/colors.txt", \%color);
61027579
MT
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'};
d95f3606
MT
327 } elsif ($config[3] eq "WPA3") {
328 $encryption_mode = $Lang::tr{'wlan client encryption wpa3'};
19f0fa56
MT
329 } elsif ($config[3] eq "EAP") {
330 $encryption_mode = $Lang::tr{'wlan client encryption eap'};
61027579
MT
331 }
332
19f0fa56
MT
333 if ($config[3] eq "EAP") {
334 if ($config[8] eq "PEAP") {
335 $encryption_mode .= " ($Lang::tr{'wlan client auth peap'})";
336 } elsif ($config[8] eq "TTLS") {
337 $encryption_mode .= " ($Lang::tr{'wlan client auth ttls'})";
338 } else {
339 $encryption_mode .= " ($Lang::tr{'wlan client auth auto'})";
340 }
341
342 $encryption_mode .= "<hr>";
343
344 if ($config[10]) {
345 $encryption_mode .= "<strong>$Lang::tr{'wlan client identity'}</strong>: ";
346 $encryption_mode .= $config[10];
347 }
348
349 # Anonymous identity
350 if ($config[9]) {
351 $encryption_mode .= "<br>";
352 $encryption_mode .= "<strong>$Lang::tr{'wlan client anonymous identity'}</strong>: ";
353 $encryption_mode .= $config[9];
354 }
355
356 } elsif (($config[3] eq "WPA") || ($config[3] eq "WPA2")) {
61027579
MT
357 my $wpa_pairwise = "$Lang::tr{'wlan client ccmp'} $Lang::tr{'wlan client and'} $Lang::tr{'wlan client tkip'}";
358 my $wpa_group = "$Lang::tr{'wlan client ccmp'} $Lang::tr{'wlan client and'} $Lang::tr{'wlan client tkip'}";
359
360 if ($config[4] eq "CCMP-CCMP") {
361 $wpa_pairwise = $Lang::tr{'wlan client ccmp'};
362 $wpa_group = $Lang::tr{'wlan client ccmp'};
363 } elsif ($config[4] eq "CCMP-TKIP") {
364 $wpa_pairwise = $Lang::tr{'wlan client ccmp'};
365 $wpa_group = $Lang::tr{'wlan client tkip'};
366 } elsif ($config[4] eq "TKIP-TKIP") {
367 $wpa_pairwise = $Lang::tr{'wlan client tkip'};
368 $wpa_group = $Lang::tr{'wlan client tkip'};
369 }
370
371 $encryption_mode .= "<hr>";
372 $encryption_mode .= "<strong>$Lang::tr{'wlan client pairwise key algorithm'}</strong>: ";
373 $encryption_mode .= $wpa_pairwise;
374 $encryption_mode .= "<br>";
375 $encryption_mode .= "<strong>$Lang::tr{'wlan client group key algorithm'}</strong>: ";
376 $encryption_mode .= $wpa_group;
377 }
378
379 print <<END;
d9a0d201
AM
380 <td align='center' $col>$config[5]</td>
381 <td align='center' $col>$encryption_mode</td>
382 <td align='center' $col>$config[7]</td>
383 <td align='center' width='5%' $col>
61027579
MT
384 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
385 <input type='hidden' name='ACTION' value='$Lang::tr{'toggle enable disable'}' />
386 <input type='image' name='$Lang::tr{'toggle enable disable'}' src='/images/$gif' alt='$gdesc' title='$gdesc' />
387 <input type='hidden' name='ID' value='$config[0]' />
388 </form>
389 </td>
d9a0d201 390 <td align='center' width='5%' $col>
61027579
MT
391 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
392 <input type='hidden' name='ACTION' value='$Lang::tr{'edit'}' />
393 <input type='image' name='$Lang::tr{'edit'}' src='/images/edit.gif' alt='$Lang::tr{'edit'}' title='$Lang::tr{'edit'}' />
394 <input type='hidden' name='ID' value='$config[0]' />
395 </form>
396 </td>
d9a0d201 397 <td align='center' width='5%' $col>
61027579
MT
398 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
399 <input type='hidden' name='ACTION' value='$Lang::tr{'remove'}' />
400 <input type='image' name='$Lang::tr{'remove'}' src='/images/delete.gif' alt='$Lang::tr{'remove'}' title='$Lang::tr{'remove'}' />
401 <input type='hidden' name='ID' value='$config[0]' />
402 </form>
403 </td>
404 </tr>
405END
406 $key++;
407 }
408 print "</table>";
409
410 # If table contains entries, print 'Key to action icons'
411 if ($key) {
412 print <<END;
413 <table>
414 <tr>
415 <td class='boldbase'>&nbsp;<b>$Lang::tr{'legend'}:&nbsp;</b></td>
416 <td><img src='/images/on.gif' alt='$Lang::tr{'click to disable'}' /></td>
417 <td class='base'>$Lang::tr{'click to disable'}</td>
418 <td>&nbsp;&nbsp;</td>
419 <td><img src='/images/off.gif' alt='$Lang::tr{'click to enable'}' /></td>
420 <td class='base'>$Lang::tr{'click to enable'}</td>
421 <td>&nbsp;&nbsp;</td>
422 <td><img src='/images/edit.gif' alt='$Lang::tr{'edit'}' /></td>
423 <td class='base'>$Lang::tr{'edit'}</td>
424 <td>&nbsp;&nbsp;</td>
425 <td><img src='/images/delete.gif' alt='$Lang::tr{'remove'}' /></td>
426 <td class='base'>$Lang::tr{'remove'}</td>
427 </tr>
428 </table>
429END
430 }
431
432 &Header::closebox();
433
434 # Show status box.
435 &ShowStatus();
436
437 &Header::closebigbox();
438 &Header::closepage();
439}
440
441sub showEditBox() {
442 &Header::openpage($Lang::tr{'wlan client configuration'}, 1, '');
443 &Header::openbigbox('100%', 'left', '', $errormessage);
444
445 if ($errormessage) {
446 &Header::openbox('100%', 'left', $Lang::tr{'error messages'});
447 print "<font class='base'>$errormessage&nbsp;</font>";
448 &Header::closebox();
449 }
450
451 my $buttontext = $Lang::tr{'add'};
452 if ($settings{'ID'} ne '') {
453 $buttontext = $Lang::tr{'update'};
454 &Header::openbox('100%', 'left', $Lang::tr{'wlan client edit entry'});
455 } else {
456 &Header::openbox('100%', 'left', $Lang::tr{'wlan client new entry'});
457 $settings{'ENABLED'} = 'on';
458 }
459 my $action = $buttontext;
460
461 my %checked = ();
462 $checked{'ENABLED'} = ($settings{'ENABLED'} ne 'on' ) ? '' : "checked='checked'";
463
464 my %selected = ();
465 $selected{'ENCRYPTION'} = ();
466 $selected{'ENCRYPTION'}{'NONE'} = '';
5addf347 467 $selected{'ENCRYPTION'}{'WPA3'} = '';
61027579
MT
468 $selected{'ENCRYPTION'}{'WPA2'} = '';
469 $selected{'ENCRYPTION'}{'WPA'} = '';
470 $selected{'ENCRYPTION'}{'WEP'} = '';
471 $selected{'ENCRYPTION'}{$settings{'ENCRYPTION'}} = "selected='selected'";
472
473 $selected{'WPA_MODE'} = ();
474 $selected{'WPA_MODE'}{''} = '';
475 $selected{'WPA_MODE'}{'CCMP-CCMP'} = '';
476 $selected{'WPA_MODE'}{'CCMP-TKIP'} = '';
477 $selected{'WPA_MODE'}{'TKIP-TKIP'} = '';
478 $selected{'WPA_MODE'}{$settings{'WPA_MODE'}} = "selected='selected'";
479
19f0fa56
MT
480 $selected{'AUTH'} = ();
481 $selected{'AUTH'}{''} = '';
482 $selected{'AUTH'}{'PEAP'} = '';
483 $selected{'AUTH'}{'TTLS'} = '';
484 $selected{'AUTH'}{$settings{'AUTH'}} = "selected='selected'";
485
61027579
MT
486 $selected{'PRIO'} = ();
487 $selected{'PRIO'}{'0'} = '';
488 $selected{'PRIO'}{'1'} = '';
489 $selected{'PRIO'}{'2'} = '';
490 $selected{'PRIO'}{'3'} = '';
491 $selected{'PRIO'}{'4'} = '';
492 $selected{'PRIO'}{$settings{'PRIO'}} = "selected='selected'";
493
494 print <<END;
495 <form method='POST' action='$ENV{'SCRIPT_NAME'}'>
496 <input type='hidden' name='ID' value='$settings{'ID'}'>
497
498 <table width='100%'>
499 <tr>
500 <td class='base' width='20%'>$Lang::tr{'wlan client ssid'}:</td>
cd6c59aa 501 <td width='40%'><input type='text' name='SSID' value="$settings{'SSID'}" size='25'/></td>
61027579
MT
502 <td class='base' width='10%'>$Lang::tr{'enabled'}</td>
503 <td width='30%'><input type='checkbox' name='ENABLED' $checked{'ENABLED'} /></td>
504 </tr>
505 <tr>
506 <td class='base' width='20%'>$Lang::tr{'wlan client encryption'}:</td>
507 <td width='40%'>
508 <select name='ENCRYPTION'>
509 <option value="NONE" $selected{'ENCRYPTION'}{'NONE'}>$Lang::tr{'wlan client encryption none'}</option>
19f0fa56 510 <option value="EAP" $selected{'ENCRYPTION'}{'EAP'}>$Lang::tr{'wlan client encryption eap'}</option>
5addf347 511 <option value="WPA3" $selected{'ENCRYPTION'}{'WPA3'}>$Lang::tr{'wlan client encryption wpa3'}</option>
61027579
MT
512 <option value="WPA2" $selected{'ENCRYPTION'}{'WPA2'}>$Lang::tr{'wlan client encryption wpa2'}</option>
513 <option value="WPA" $selected{'ENCRYPTION'}{'WPA'}>$Lang::tr{'wlan client encryption wpa'}</option>
5addf347 514 <option value="WEP" $selected{'ENCRYPTION'}{'WEP'}>$Lang::tr{'wlan client encryption wep'}</option>
61027579
MT
515 </select>
516 </td>
517 <td colspan="2" width='40%'></td>
518 </tr>
519 <tr>
520 <td class='base' width='20%'>$Lang::tr{'wlan client psk'}:&nbsp;</td>
cd6c59aa 521 <td width='40%'><input type='password' name='PSK' value="$settings{'PSK'}" size='25'/></td>
61027579
MT
522 <td colspan="2" width='40%'></td>
523 </tr>
524 </table>
525
526 <br>
527 <hr>
19f0fa56
MT
528
529 <strong>
530 $Lang::tr{'wlan client authentication settings'}:
531 </strong>
532
533 <table width='100%'>
534 <tr>
535 <td class='base' width='20%'>
536 $Lang::tr{'wlan client eap authentication method'}:
537 </td>
538 <td width='40%'>
539 <select name='AUTH'>
540 <option value="" $selected{'AUTH'}{''}>$Lang::tr{'wlan client auth auto'}</option>
541 <option value="PEAP" $selected{'AUTH'}{'PEAP'}>$Lang::tr{'wlan client auth peap'}</option>
542 <option value="TTLS" $selected{'AUTH'}{'TTLS'}>$Lang::tr{'wlan client auth ttls'}</option>
543 </select>
544 </td>
545 <td colspan="2" width='40%'></td>
546 </tr>
547 <tr>
548 <td class='base' width='20%'>
549 $Lang::tr{'wlan client anonymous identity'}:
550 </td>
551 <td width='40%'>
552 <input type="text" name="ANONYMOUS" value="$settings{"ANONYMOUS"}" size="25" />
553 </td>
554 <td colspan="2" width='40%'></td>
555 </tr>
556 <tr>
557 <td class='base' width='20%'>
558 $Lang::tr{'wlan client identity'}:
559 </td>
560 <td width='40%'>
561 <input type="text" name="IDENTITY" value="$settings{"IDENTITY"}" size="25" />
562 </td>
563 <td colspan="2" width='40%'></td>
564 </tr>
565 <tr>
566 <td class='base' width='20%'>
567 $Lang::tr{'wlan client password'}:
568 </td>
569 <td width='40%'>
570 <input type="password" name="PASSWORD" value="$settings{"PASSWORD"}" size="25" />
571 </td>
572 <td colspan="2" width='40%'></td>
573 </tr>
574 </table>
575
576 <br>
577 <hr>
578
61027579
MT
579
580 <strong>
581 $Lang::tr{'wlan client advanced settings'}:
582 </strong>
583
584 <table width='100%'>
585 <tr>
586 <td class='base' width='20%'>
587 $Lang::tr{'wlan client wpa mode'}:
588 </td>
589 <td width='40%'>
590 <select name='WPA_MODE'>
591 <option value="" $selected{'WPA_MODE'}{''}>$Lang::tr{'wlan client wpa mode all'}</option>
592 <option value="CCMP-CCMP" $selected{'WPA_MODE'}{'CCMP-CCMP'}>$Lang::tr{'wlan client wpa mode ccmp ccmp'}</option>
593 <option value="CCMP-TKIP" $selected{'WPA_MODE'}{'CCMP-TKIP'}>$Lang::tr{'wlan client wpa mode ccmp tkip'}</option>
594 <option value="TKIP-TKIP" $selected{'WPA_MODE'}{'TKIP-TKIP'}>$Lang::tr{'wlan client wpa mode tkip tkip'}</option>
595 </select>
596 </td>
597 <td colspan="2" width='40%'>
598 <em>($Lang::tr{'wlan client pairwise key group key'})</em>
599 </td>
600 </tr>
601 <tr>
602 <td class='base' width='20%'>
603 $Lang::tr{'priority'}:
604 </td>
605 <td width='40%'>
606 <select name='PRIO'>
f90b0f24 607 <option value="0" $selected{'PRIO'}{'0'}>0 ($Lang::tr{'least preferred'})</option>
61027579
MT
608 <option value="1" $selected{'PRIO'}{'1'}>1</option>
609 <option value="2" $selected{'PRIO'}{'2'}>2</option>
610 <option value="3" $selected{'PRIO'}{'3'}>3</option>
f90b0f24 611 <option value="4" $selected{'PRIO'}{'4'}>4 ($Lang::tr{'most preferred'})</option>
61027579
MT
612 </select>
613 </td>
614 <td colspan="2" width='40%'></td>
615 </tr>
616 </table>
617
618 <br>
619 <hr>
620
621 <table width='100%'>
622 <tr>
623 <td width='50%' align='center'>
624 <input type='hidden' name='ACTION' value='$action' />
625 <input type='submit' name='SUBMIT' value='$buttontext' />
626 </td>
627 </tr>
628 </table>
629 </form>
630END
631 &Header::closebox();
632
633 &Header::closebigbox();
634 &Header::closepage();
635}
636
637sub ShowStatus() {
638 my $device = $netsettings{'RED_DEV'};
639
640 # Exit if no device is configured.
641 return if ($device eq "");
642
643 # Exit if wpa_supplicant is not running on this interface.
644 #return if (! -e "/var/run/wpa_supplicant/$device");
645
646 open(FILE, "/usr/local/bin/wirelessclient status |");
647
648 my %status = ();
649 while (<FILE>) {
650 chomp($_);
651
652 my ($key, $value) = split("=", $_);
653 $status{$key} = $value;
654 }
655
656 close(FILE);
657
658 # End here, if no there is no input.
659 return if (!keys %status);
660
661 &Header::openbox('100%', 'left', $Lang::tr{'status'});
662
663 if ($status{'ssid'} eq "") {
664 print "<p>$Lang::tr{'wlan client disconnected'}</p>";
665
666 } else {
667 print <<END;
668 <table width='100%'>
669 <tr>
670 <td width='20%'>
671 $Lang::tr{'wlan client ssid'}
672 </td>
673 <td width='80%'>
674 $status{'ssid'}
675 </td>
676 </tr>
677 <tr>
678 <td width='20%'>
679 $Lang::tr{'wlan client bssid'}
680 </td>
681 <td width='80%'>
682 $status{'bssid'}
683 </td>
684 </tr>
685END
686
e902ebe3
MT
687 if ($status{'pmf'} eq "1") {
688 print <<END;
689 <tr>
690 <td width='20%'>
691 $Lang::tr{'wlan client management frame protection'}
692 </td>
693 <td width='80%'>
694 $Lang::tr{'active'}
695 </td>
696 </tr>
697END
698 }
699
0628d956
MT
700 if ($status{'EAP state'}) {
701 my $selected_method = $status{'selectedMethod'};
702 $selected_method =~ s/\d+ \((.*)\)/$1/e;
703
704 print <<END;
705 <tr>
706 <td colspan='2'>
707 <strong>$Lang::tr{'wlan client encryption eap'}</strong>
708 </td>
709 </tr>
710 <tr>
711 <td width='20%'>
712 $Lang::tr{'wlan client eap state'}
713 </td>
714 <td width='80%'>
715 $status{'EAP state'}
716 </td>
717 </tr>
718 <tr>
719 <td width='20%'>
720 $Lang::tr{'wlan client method'}
721 </td>
722 <td width='80%'>
723 $selected_method
724 </td>
725 </tr>
726 <tr>
727 <td width='20%'>
728 $Lang::tr{'wlan client tls version'}
729 </td>
730 <td width='80%'>
731 $status{'eap_tls_version'}
732 </td>
733 </tr>
734 <tr>
735 <td width='20%'>
736 $Lang::tr{'wlan client tls cipher'}
737 </td>
738 <td width='80%'>
739 $status{'EAP TLS cipher'}
740 </td>
741 </tr>
742 <tr>
743 <td width='20%'>
744 $Lang::tr{'wlan client eap phase2 method'}
745 </td>
746 <td width='80%'>
747 $status{"${selected_method}v0 Phase2 method"}
748 </td>
749 </tr>
750END
751 }
752
61027579 753 if (($status{'pairwise_cipher'} ne "NONE") || ($status{'group_cipher'} ne "NONE")) {
5cdf3b8c
MT
754 if ($status{'key_mgmt'} eq "SAE") {
755 print <<END;
756 <tr>
757 <td colspan='2'>
758 <strong>$Lang::tr{'wlan client encryption wpa3'}</strong>
759 </td>
760 </tr>
761END
762 } else {
763 print <<END;
61027579
MT
764 <tr>
765 <td colspan='2'>
766 <strong>$Lang::tr{'wlan client encryption wpa'}</strong>
767 </td>
768 </tr>
5cdf3b8c
MT
769END
770 }
771
772 print <<END;
61027579
MT
773 <tr>
774 <td width='20%'>
775 $Lang::tr{'wlan client pairwise cipher'}
776 </td>
777 <td width='80%'>
778 $status{'pairwise_cipher'}
779 </td>
780 </tr>
781 <tr>
782 <td width='20%'>
783 $Lang::tr{'wlan client group cipher'}
784 </td>
785 <td width='80%'>
786 $status{'group_cipher'}
787 </td>
788 </tr>
789END
790 }
791
792 print "</table>";
793 }
794
795 &Header::closebox();
796}
797
798sub BuildConfiguration() {
799 system("/usr/local/bin/wirelessclient restart");
800}
801
802sub NextID() {
803 my $highest_id = 0;
804 foreach my $line (@configs) {
805 # Skip commented lines.
806 my $firstchar = substr($line, 0, 1);
807 next if ($firstchar eq "#");
808
809 my @config = split(/\,/, $line);
810 if ($config[0] > $highest_id) {
811 $highest_id = $config[0];
812 }
813 }
814
815 return $highest_id + 1;
816}
817
818sub DuplicateSSID($) {
819 my $ssid = shift;
820
821 foreach my $line (@configs) {
822 # Skip commented lines.
823 my $firstchar = substr($line, 0, 1);
824 next if ($firstchar eq "#");
825
826 my @config = split(/\,/, $line);
827 if ($config[5] eq $ssid) {
828 return 1;
829 }
830 }
831
832 return 0;
833}
834
835sub ValidKeyLength($$) {
836 my $algo = shift;
837 my $key = shift;
838
839 my $key_length = length($key);
840
841 if ($algo eq "WEP") {
842 # Key must be 13 or 26 characters.
843 if (($key_length == 13) || ($key_length == 26)) {
844 return 0;
845 }
846
847 return 1;
848
849 } elsif (($algo eq "WPA2") || ($algo eq "WPA")) {
850 # Key must be between 8 and 63 chars.
851 if (($key_length >= 8) && ($key_length <= 63)) {
852 return 0;
853 }
854
855 return 1;
856 }
857
858 # Say okay for all other algorithms.
859 return 0;
860}
861
862sub ValidateInput($) {
863 my $mode = shift;
864
865 # Check for duplicate SSIDs.
866 if (($mode eq "add") && (DuplicateSSID($settings{'SSID'}))) {
867 return "$Lang::tr{'wlan client duplicate ssid'}: $settings{'SSID'}";
868
869 # Check for invalid key length.
870 } elsif (ValidKeyLength($settings{'ENCRYPTION'}, $settings{'PSK'})) {
871 return "$Lang::tr{'wlan client invalid key length'}";
61027579
MT
872 }
873
874 # Reset WPA mode, if WPA(2) is not selected.
875 if (($settings{'ENCRYPTION'} ne "WPA") && ($settings{'ENCRYPTION'} ne "WPA2")) {
876 $settings{'WPA_MODE'} = '';
877 }
878
879 if ($settings{'ENABLED'} ne "") {
880 $settings{'ENABLED'} = 'on';
881 } else {
882 $settings{'ENABLED'} = 'off';
883 }
884
885 return;
886}