1
0
mirror of https://github.com/billz/raspap-webgui.git synced 2023-10-10 13:37:24 +02:00

Merge pull request #164 from rmarshall31/priority

preserve priority in wpa_supplicant.conf
This commit is contained in:
Bill Zimmerman 2018-02-25 22:00:43 +01:00 committed by GitHub
commit 659e21f00b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -41,6 +41,9 @@ function DisplayWPAConfig(){
$network['protocol'] = 'Open'; $network['protocol'] = 'Open';
} }
break; break;
case 'priority':
$network['priority'] = trim($lineArr[1], '"');
break;
} }
} }
} }
@ -63,6 +66,9 @@ function DisplayWPAConfig(){
'passphrase' => $_POST['passphrase' . $post_match[1]], 'passphrase' => $_POST['passphrase' . $post_match[1]],
'configured' => true 'configured' => true
); );
if (array_key_exists('priority' . $post_match[1], $_POST)) {
$tmp_networks[$_POST['ssid' . $post_match[1]]]['priority'] = $_POST['priority' . $post_match[1]];
}
} }
} }
@ -72,22 +78,30 @@ function DisplayWPAConfig(){
fwrite($wpa_file, "network={".PHP_EOL); fwrite($wpa_file, "network={".PHP_EOL);
fwrite($wpa_file, "\tssid=\"".$ssid."\"".PHP_EOL); fwrite($wpa_file, "\tssid=\"".$ssid."\"".PHP_EOL);
fwrite($wpa_file, "\tkey_mgmt=NONE".PHP_EOL); fwrite($wpa_file, "\tkey_mgmt=NONE".PHP_EOL);
if (array_key_exists('priority', $network)) {
fwrite($wpa_file, "\tpriority=".$network['priority'].PHP_EOL);
}
fwrite($wpa_file, "}".PHP_EOL); fwrite($wpa_file, "}".PHP_EOL);
} else { } else {
if (strlen($network['passphrase']) >=8 && strlen($network['passphrase']) <= 63) { if (strlen($network['passphrase']) >=8 && strlen($network['passphrase']) <= 63) {
unset($wpa_passphrase); unset($wpa_passphrase);
unset($line); unset($line);
exec( 'wpa_passphrase '.escapeshellarg($ssid). ' ' . escapeshellarg($network['passphrase']),$wpa_passphrase ); exec( 'wpa_passphrase '.escapeshellarg($ssid). ' ' . escapeshellarg($network['passphrase']),$wpa_passphrase );
foreach($wpa_passphrase as $line) { foreach($wpa_passphrase as $line) {
fwrite($wpa_file, $line.PHP_EOL); if (preg_match('/^\s*}\s*$/', $line)) {
if (array_key_exists('priority', $network)) {
fwrite($wpa_file, "\tpriority=".$network['priority'].PHP_EOL);
}
fwrite($wpa_file, $line.PHP_EOL);
} else {
fwrite($wpa_file, $line.PHP_EOL);
}
} }
} else { } else {
$status->addMessage('WPA passphrase must be between 8 and 63 characters', 'danger'); $status->addMessage('WPA passphrase must be between 8 and 63 characters', 'danger');
$ok = false; $ok = false;
} }
} }
} }
if ($ok) { if ($ok) {
@ -118,7 +132,7 @@ function DisplayWPAConfig(){
// display output // display output
foreach( $scan_return as $network ) { foreach( $scan_return as $network ) {
$arrNetwork = preg_split("/[\t]+/",$network); $arrNetwork = preg_split("/[\t]+/",$network);
if (array_key_exists($arrNetwork[4], $networks)) { if (array_key_exists(4, $arrNetwork) && array_key_exists($arrNetwork[4], $networks)) {
$networks[$arrNetwork[4]]['visible'] = true; $networks[$arrNetwork[4]]['visible'] = true;
$networks[$arrNetwork[4]]['channel'] = ConvertToChannel($arrNetwork[1]); $networks[$arrNetwork[4]]['channel'] = ConvertToChannel($arrNetwork[1]);
// TODO What if the security has changed? // TODO What if the security has changed?
@ -150,9 +164,9 @@ function DisplayWPAConfig(){
<div class="panel-body"> <div class="panel-body">
<p><?php $status->showMessages(); ?></p> <p><?php $status->showMessages(); ?></p>
<h4>Client settings for interface <?php echo RASPI_WIFI_CLIENT_INTERFACE ?></h4> <h4>Client settings for interface <?php echo RASPI_WIFI_CLIENT_INTERFACE ?></h4>
<div class="btn-group btn-block"> <div class="btn-group btn-block">
<a href=".?<?php echo $_SERVER['QUERY_STRING']; ?>" style="padding:10px;float: right;display: block;position: relative;margin-top: -55px;" class="col-md-2 btn btn-info" id="update">Rescan</a> <a href=".?<?php echo $_SERVER['QUERY_STRING']; ?>" style="padding:10px;float: right;display: block;position: relative;margin-top: -55px;" class="col-md-2 btn btn-info" id="update">Rescan</a>
</div> </div>
<form method="POST" action="?page=wpa_conf" name="wpa_conf_form"> <form method="POST" action="?page=wpa_conf" name="wpa_conf_form">
<?php CSRFToken() ?> <?php CSRFToken() ?>
<input type="hidden" name="client_settings" ?> <input type="hidden" name="client_settings" ?>
@ -172,7 +186,7 @@ function DisplayWPAConfig(){
<?php if ($network['configured']) { ?> <?php if ($network['configured']) { ?>
<i class="fa fa-check-circle fa-fw"></i> <i class="fa fa-check-circle fa-fw"></i>
<?php } ?> <?php } ?>
<?php if ($network['connected']) { ?> <?php if (array_key_exists('connected', $network) && $network['connected']) { ?>
<i class="fa fa-exchange fa-fw"></i> <i class="fa fa-exchange fa-fw"></i>
<?php } ?> <?php } ?>
</td> </td>
@ -180,12 +194,17 @@ function DisplayWPAConfig(){
<input type="hidden" name="ssid<?php echo $index ?>" value="<?php echo htmlentities($ssid) ?>" /> <input type="hidden" name="ssid<?php echo $index ?>" value="<?php echo htmlentities($ssid) ?>" />
<?php echo $ssid ?> <?php echo $ssid ?>
</td> </td>
<?php if ($network['visible']) { ?> <?php if (array_key_exists('visible', $network) && $network['visible']) { ?>
<td><?php echo $network['channel'] ?></td> <td><?php echo $network['channel'] ?></td>
<?php } else { ?> <?php } else { ?>
<td><span class="label label-warning">X</span></td> <td><span class="label label-warning">X</span></td>
<?php } ?> <?php } ?>
<td><input type="hidden" name="protocol<?php echo $index ?>" value="<?php echo $network['protocol'] ?>" /><?php echo $network['protocol'] ?></td> <td>
<?php if (array_key_exists('priority', $network)) { ?>
<input type="hidden" name="priority<?php echo $index ?>" value="<?php echo $network['priority'] ?>" />
<?php } ?>
<input type="hidden" name="protocol<?php echo $index ?>" value="<?php echo $network['protocol'] ?>" /><?php echo $network['protocol'] ?>
</td>
<?php if ($network['protocol'] === 'Open') { ?> <?php if ($network['protocol'] === 'Open') { ?>
<td><input type="hidden" name="passphrase<?php echo $index ?>" value="" />---</td> <td><input type="hidden" name="passphrase<?php echo $index ?>" value="" />---</td>
<?php } else { ?> <?php } else { ?>