parseIwList -> parseIwInfo() + formatting

This commit is contained in:
billz 2023-11-05 14:29:44 +00:00
parent 7a612592c2
commit 25cc92b593
2 changed files with 17 additions and 16 deletions

View File

@ -7,13 +7,7 @@ if (isset($_POST['interface'])) {
$iface = escapeshellcmd($_POST['interface']);
$parser = new \RaspAP\Parsers\IwParser($iface);
$supportedFrequencies = $parser->parseIwList($iface);
# debug
#foreach ($supportedFrequencies as $frequency) {
# echo "<br>Frequency: {$frequency['MHz']} MHz, Channel: {$frequency['Channel']}, dBm: {$frequency['dBm']}\n";
#}
$supportedFrequencies = $parser->parseIwInfo($iface);
echo json_encode($supportedFrequencies);
}

View File

@ -13,26 +13,33 @@ declare(strict_types=1);
namespace RaspAP\Parsers;
class IwParser {
class IwParser
{
private $iw_output;
public function __construct(string $interface = 'wlan0') {
public function __construct(string $interface = 'wlan0')
{
// Resolve physical device for selected interface
$iface = escapeshellarg($interface);
exec("iw dev | awk -v iface=".$iface." '/^phy#/ { phy = $0 } $1 == \"Interface\" { interface = $2 } interface == iface { print phy }'", $return);
$pattern = "iw dev | awk -v iface=".$iface." '/^phy#/ { phy = $0 } $1 == \"Interface\" { interface = $2 } interface == iface { print phy }'";
exec($pattern, $return);
$phy = $return[0];
// Fetch 'iw info' output for phy
$this->iw_output = shell_exec("iw $phy info");
}
public function parseIwList() {
/**
* (no IR): the AP won't Initiate Radiation until a DFS scan (or similar) is complete on these bands.
* (radar detection): the specified channels are shared with radar equipment.
* (disabled): self-explanatory.
*/
/**
* Parses raw output of 'iw info' command, filtering supported frequencies.
*
* Frequencies with the following regulatory restrictions are excluded:
* (no IR): the AP won't Initiate Radiation until a DFS scan (or similar) is complete on these bands.
* (radar detection): the specified channels are shared with radar equipment.
* (disabled): self-explanatory.
*/
public function parseIwInfo()
{
$excluded = array(
"(no IR, radar detection)",
"(radar detection)",