]>
git.ipfire.org Git - ipfire-2.x.git/blob - html/cgi-bin/wirelessclient.cgi
2 ###############################################################################
4 # IPFire.org - A linux based firewall #
5 # Copyright (C) 2012 IPFire Team <info@ipfire.org> #
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. #
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. #
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/>. #
20 ###############################################################################
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
27 # enable only the following on debugging purpose
29 use CGI
::Carp
'fatalsToBrowser';
31 require '/var/ipfire/general-functions.pl';
32 require "${General::swroot}/lang.pl";
33 require "${General::swroot}/header.pl";
35 #workaround to suppress a warning when a variable is used only once
36 my @dummy = ( ${Header
::colouryellow
} );
40 my $setting = "${General::swroot}/main/settings";
41 our $datafile = "${General::swroot}/ethernet/wireless";
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);
49 our %netsettings = ();
52 $settings{'INTERFACE'} = '';
53 $settings{'ENABLED'} = '';
54 $settings{'ENCRYPTION'} = '';
55 $settings{'WPA_MODE'} = '';
56 $settings{'SSID'} = '';
57 $settings{'PSK'} = '';
58 $settings{'PRIO'} = '';
60 $settings{'ACTION'} = ''; # add/edit/remove
61 $settings{'ID'} = ''; # point record for ACTION
63 my $errormessage = '';
66 &Header
::showhttpheaders
();
69 &Header
::getcgihash
(\
%settings);
73 if (open(FILE
, "$datafile")) {
78 &General
::readhash
("${General::swroot}/main/settings", \
%settings);
79 &General
::readhash
("${General::swroot}/ethernet/settings", \
%netsettings);
81 # Toggle enable/disable field.
82 if ($settings{'ACTION'} eq $Lang::tr
{'toggle enable disable'}) {
85 foreach my $line (@configs) {
87 my @config = split(/\,/, $line);
89 # Update the entry with the matching ID.
90 if ($config[0] eq $settings{'ID'}) {
91 # Toggle enabled/disabled status.
93 if ($config[2] eq 'on') {
99 $line = join(',', @config);
102 push(@update, $line."\n");
105 # Save updated configuration settings.
106 open(FILE
, ">$datafile") or die 'wlan client datafile error';
112 # Update configuration files.
113 &BuildConfiguration
();
116 $settings{'ACTION'} = '';
119 if ($settings{'ACTION'} eq $Lang::tr
{'add'}) {
120 # Validate input data.
121 $errormessage = ValidateInput
("add");
123 unless ($errormessage) {
124 # Search for the next free id.
125 my $next_id = NextID
();
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 push(@config, $settings{'AUTH'});
136 push(@config, $settings{'ANONYMOUS'});
137 push(@config, $settings{'IDENTITY'});
138 push(@config, $settings{'PASSWORD'});
140 # Add the new configuration and write all the stuff to the configuration file.
141 my $line = join(',', @config) . "\n";
142 push(@configs, $line);
144 # Save updated configuration settings.
145 open(FILE
, ">$datafile") or die 'wlan client datafile error';
149 # Update configuration files.
150 &BuildConfiguration
();
153 $settings{'ACTION'} = '';
157 if ($settings{'ACTION'} eq $Lang::tr
{'edit'}) {
158 foreach my $line (@configs) {
160 my @config = split(/\,/, $line);
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];
171 $settings{'AUTH'} = $config[8];
172 $settings{'ANONYMOUS'} = $config[9];
173 $settings{'IDENTITY'} = $config[10];
174 $settings{'PASSWORD'} = $config[11];
179 if ($settings{'ACTION'} eq $Lang::tr
{'update'}) {
180 $errormessage = ValidateInput
("update");
182 unless ($errormessage) {
184 foreach my $line (@configs) {
186 my @config = split(/\,/, $line);
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.
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'};
203 $line = join(',', @config);
206 push(@update, $line."\n");
209 # Save updated configuration settings.
210 open(FILE
, ">$datafile") or die 'wlan client datafile error';
216 # Update configuration files.
217 &BuildConfiguration
();
220 $settings{'ACTION'} = '';
224 if ($settings{'ACTION'} eq $Lang::tr
{'remove'}) {
227 foreach my $line (@configs) {
229 my @config = split(/\,/, $line);
231 # Skip the to be removed entry.
232 if ($config[0] eq $settings{'ID'}) {
236 push(@update, $line."\n");
239 # Save updated configuration settings.
240 open(FILE
, ">$datafile") or die 'wlan client datafile error';
246 # Update configuration files.
247 &BuildConfiguration
();
250 $settings{'ACTION'} = '';
253 if ($settings{'ACTION'} eq '') { # First launch from GUI
256 # Action has been set, so show the edit box.
261 &Header
::openpage
($Lang::tr
{'wlan client configuration'}, 1, '');
262 &Header
::openbigbox
('100%', 'left', '', $errormessage);
264 &Header
::openbox
('100%', 'left', $Lang::tr
{'wlan client configuration'});
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'}' />
273 <table width="100%" class='tbl'>
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>
285 # Print each line of @configs list
290 foreach my $line (@configs) {
291 # Skip commented lines.
292 my $firstchar = substr($line, 0, 1);
293 next if ($firstchar eq "#");
296 my @config = split(/\,/,$line);
298 #Choose icon for checkbox
301 if ($config[2] eq 'on' ) {
303 $gdesc = $Lang::tr
{'click to disable'};
306 $gdesc = $Lang::tr
{'click to enable'};
312 $col="bgcolor='$color{'color20'}'";
315 $col="bgcolor='$color{'color22'}'";
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'};
327 } elsif ($config[3] eq "EAP") {
328 $encryption_mode = $Lang::tr
{'wlan client encryption eap'};
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'})";
337 $encryption_mode .= " ($Lang::tr{'wlan client auth auto'})";
340 $encryption_mode .= "<hr>";
343 $encryption_mode .= "<strong>$Lang::tr{'wlan client identity'}</strong>: ";
344 $encryption_mode .= $config[10];
349 $encryption_mode .= "<br>";
350 $encryption_mode .= "<strong>$Lang::tr{'wlan client anonymous identity'}</strong>: ";
351 $encryption_mode .= $config[9];
354 } elsif (($config[3] eq "WPA") || ($config[3] eq "WPA2")) {
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'}";
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'};
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;
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>
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]' />
388 <td align='center' width='5%' $col>
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]' />
395 <td align='center' width='5%' $col>
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]' />
408 # If table contains entries, print 'Key to action icons'
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>
435 &Header
::closebigbox
();
436 &Header
::closepage
();
440 &Header
::openpage
($Lang::tr
{'wlan client configuration'}, 1, '');
441 &Header
::openbigbox
('100%', 'left', '', $errormessage);
444 &Header
::openbox
('100%', 'left', $Lang::tr
{'error messages'});
445 print "<font class='base'>$errormessage </font>";
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'});
454 &Header
::openbox
('100%', 'left', $Lang::tr
{'wlan client new entry'});
455 $settings{'ENABLED'} = 'on';
457 my $action = $buttontext;
460 $checked{'ENABLED'} = ($settings{'ENABLED'} ne 'on' ) ?
'' : "checked='checked'";
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'";
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'";
477 $selected{'AUTH'} = ();
478 $selected{'AUTH'}{''} = '';
479 $selected{'AUTH'}{'PEAP'} = '';
480 $selected{'AUTH'}{'TTLS'} = '';
481 $selected{'AUTH'}{$settings{'AUTH'}} = "selected='selected'";
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'";
492 <form method='POST' action='$ENV{'SCRIPT_NAME'}'>
493 <input type='hidden' name='ID' value='$settings{'ID'}'>
497 <td class='base' width='20%'>$Lang::tr{'wlan client ssid'}:</td>
498 <td width='40%'><input type='text' name='SSID' value="$settings{'SSID'}" size='25'/></td>
499 <td class='base' width='10%'>$Lang::tr{'enabled'}</td>
500 <td width='30%'><input type='checkbox' name='ENABLED' $checked{'ENABLED'} /></td>
503 <td class='base' width='20%'>$Lang::tr{'wlan client encryption'}:</td>
505 <select name='ENCRYPTION'>
506 <option value="NONE" $selected{'ENCRYPTION'}{'NONE'}>$Lang::tr{'wlan client encryption none'}</option>
507 <option value="EAP" $selected{'ENCRYPTION'}{'EAP'}>$Lang::tr{'wlan client encryption eap'}</option>
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>
513 <td colspan="2" width='40%'></td>
516 <td class='base' width='20%'>$Lang::tr{'wlan client psk'}: </td>
517 <td width='40%'><input type='password' name='PSK' value="$settings{'PSK'}" size='25'/></td>
518 <td colspan="2" width='40%'></td>
526 $Lang::tr{'wlan client authentication settings'}:
531 <td class='base' width='20%'>
532 $Lang::tr{'wlan client eap authentication method'}:
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>
541 <td colspan="2" width='40%'></td>
544 <td class='base' width='20%'>
545 $Lang::tr{'wlan client anonymous identity'}:
548 <input type="text" name="ANONYMOUS" value="$settings{"ANONYMOUS"}" size="25" />
550 <td colspan="2" width='40%'></td>
553 <td class='base' width='20%'>
554 $Lang::tr{'wlan client identity'}:
557 <input type="text" name="IDENTITY" value="$settings{"IDENTITY"}" size="25" />
559 <td colspan="2" width='40%'></td>
562 <td class='base' width='20%'>
563 $Lang::tr{'wlan client password'}:
566 <input type="password" name="PASSWORD" value="$settings{"PASSWORD"}" size="25" />
568 <td colspan="2" width='40%'></td>
577 $Lang::tr{'wlan client advanced settings'}:
582 <td class='base' width='20%'>
583 $Lang::tr{'wlan client wpa mode'}:
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>
593 <td colspan="2" width='40%'>
594 <em>($Lang::tr{'wlan client pairwise key group key'})</em>
598 <td class='base' width='20%'>
599 $Lang::tr{'priority'}:
603 <option value="0" $selected{'PRIO'}{'0'}>0 ($Lang::tr{'most preferred'})</option>
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>
607 <option value="4" $selected{'PRIO'}{'4'}>4 ($Lang::tr{'least preferred'})</option>
610 <td colspan="2" width='40%'></td>
619 <td width='50%' align='center'>
620 <input type='hidden' name='ACTION' value='$action' />
621 <input type='submit' name='SUBMIT' value='$buttontext' />
629 &Header
::closebigbox
();
630 &Header
::closepage
();
634 my $device = $netsettings{'RED_DEV'};
636 # Exit if no device is configured.
637 return if ($device eq "");
639 # Exit if wpa_supplicant is not running on this interface.
640 #return if (! -e "/var/run/wpa_supplicant/$device");
642 open(FILE
, "/usr/local/bin/wirelessclient status |");
648 my ($key, $value) = split("=", $_);
649 $status{$key} = $value;
654 # End here, if no there is no input.
655 return if (!keys %status);
657 &Header
::openbox
('100%', 'left', $Lang::tr
{'status'});
659 if ($status{'ssid'} eq "") {
660 print "<p>$Lang::tr{'wlan client disconnected'}</p>";
667 $Lang::tr{'wlan client ssid'}
675 $Lang::tr{'wlan client bssid'}
683 if ($status{'EAP state'}) {
684 my $selected_method = $status{'selectedMethod'};
685 $selected_method =~ s/\d+ \((.*)\)/$1/e;
690 <strong>$Lang::tr{'wlan client encryption eap'}</strong>
695 $Lang::tr{'wlan client eap state'}
703 $Lang::tr{'wlan client method'}
711 $Lang::tr{'wlan client tls version'}
714 $status{'eap_tls_version'}
719 $Lang::tr{'wlan client tls cipher'}
722 $status{'EAP TLS cipher'}
727 $Lang::tr{'wlan client eap phase2 method'}
730 $status{"${selected_method}v0 Phase2 method"}
736 if (($status{'pairwise_cipher'} ne "NONE") || ($status{'group_cipher'} ne "NONE")) {
740 <strong>$Lang::tr{'wlan client encryption wpa'}</strong>
745 $Lang::tr{'wlan client pairwise cipher'}
748 $status{'pairwise_cipher'}
753 $Lang::tr{'wlan client group cipher'}
756 $status{'group_cipher'}
768 sub BuildConfiguration
() {
769 system("/usr/local/bin/wirelessclient restart");
774 foreach my $line (@configs) {
775 # Skip commented lines.
776 my $firstchar = substr($line, 0, 1);
777 next if ($firstchar eq "#");
779 my @config = split(/\,/, $line);
780 if ($config[0] > $highest_id) {
781 $highest_id = $config[0];
785 return $highest_id + 1;
788 sub DuplicateSSID
($) {
791 foreach my $line (@configs) {
792 # Skip commented lines.
793 my $firstchar = substr($line, 0, 1);
794 next if ($firstchar eq "#");
796 my @config = split(/\,/, $line);
797 if ($config[5] eq $ssid) {
805 sub ValidKeyLength
($$) {
809 my $key_length = length($key);
811 if ($algo eq "WEP") {
812 # Key must be 13 or 26 characters.
813 if (($key_length == 13) || ($key_length == 26)) {
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)) {
828 # Say okay for all other algorithms.
832 sub ValidateInput
($) {
835 # Check for duplicate SSIDs.
836 if (($mode eq "add") && (DuplicateSSID
($settings{'SSID'}))) {
837 return "$Lang::tr{'wlan client duplicate ssid'}: $settings{'SSID'}";
839 # Check for invalid key length.
840 } elsif (ValidKeyLength
($settings{'ENCRYPTION'}, $settings{'PSK'})) {
841 return "$Lang::tr{'wlan client invalid key length'}";
845 # Reset WPA mode, if WPA(2) is not selected.
846 if (($settings{'ENCRYPTION'} ne "WPA") && ($settings{'ENCRYPTION'} ne "WPA2")) {
847 $settings{'WPA_MODE'} = '';
850 if ($settings{'ENABLED'} ne "") {
851 $settings{'ENABLED'} = 'on';
853 $settings{'ENABLED'} = 'off';