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

Change method of calculating channel and security

This commit is contained in:
Joe Haig 2016-08-12 17:29:56 +00:00
parent fe3b0e9513
commit c7ed97dd8b
2 changed files with 132 additions and 146 deletions

View File

@ -85,18 +85,12 @@ function ParseConfig( $arrConfig ) {
* @return $channel
*/
function ConvertToChannel( $freq ) {
$base = 2412;
$channel = 1;
for( $x = 0; $x < 13; $x++ ) {
if( $freq != $base ) {
$base = $base + 5;
$channel++;
} else {
$channel = ($freq - 2407)/5;
if ($channel > 0 && $channel < 14) {
return $channel;
} else {
return 'Invalid Channel';
}
}
return "Invalid Channel";
}
/**
@ -105,35 +99,27 @@ function ConvertToChannel( $freq ) {
* @return string
*/
function ConvertToSecurity( $security ) {
$options = array();
preg_match_all('/\[([^\]]+)\]/s', $security, $matches);
foreach($matches[1] as $match) {
if (preg_match('/^(WPA\d?)/', $match, $protocol_match)) {
$protocol = $protocol_match[1];
$matchArr = explode('-', $match);
if (count($matchArr) > 2) {
$options[] = $protocol . ' ('. $matchArr[2] .')';
} else {
$options[] = $protocol;
}
}
}
switch( $security ) {
case "[WPA2-PSK-CCMP][ESS]":
return "WPA2-PSK (AES)";
break;
case "[WPA2-PSK-TKIP][ESS]":
return "WPA2-PSK (TKIP)";
break;
case "[WPA2-PSK-CCMP][WPS][ESS]":
return "WPA/WPA2-PSK (TKIP/AES)";
break;
case "[WPA2-PSK-TKIP+CCMP][WPS][ESS]":
return "WPA2-PSK (TKIP/AES) with WPS";
break;
case "[WPA-PSK-TKIP+CCMP][WPS][ESS]":
return "WPA-PSK (TKIP/AES) with WPS";
break;
case "[WPA-PSK-TKIP][WPA2-PSK-CCMP][WPS][ESS]":
return "WPA/WPA2-PSK (TKIP/AES)";
break;
case "[WPA-PSK-TKIP+CCMP][WPA2-PSK-TKIP+CCMP][ESS]":
return "WPA/WPA2-PSK (TKIP/AES)";
break;
case "[WPA-PSK-TKIP][ESS]":
return "WPA-PSK (TKIP)";
break;
case "[WEP][ESS]":
return "WEP";
break;
if (count($options) === 0) {
// This could also be WEP but wpa_supplicant doesn't have a way to determine
// this.
// And you shouldn't be using WEP these days anyway.
return 'Open';
} else {
return implode('<br />', $options);
}
}