2016-07-27 20:43:40 +00:00
|
|
|
<?php
|
2016-08-05 14:50:05 +00:00
|
|
|
|
2020-06-07 16:17:16 +00:00
|
|
|
require_once 'includes/wifi_functions.php';
|
2020-06-07 16:25:11 +00:00
|
|
|
require_once 'includes/config.php';
|
2016-08-05 14:50:05 +00:00
|
|
|
|
2020-06-07 16:17:16 +00:00
|
|
|
getWifiInterface();
|
2020-06-07 13:23:40 +00:00
|
|
|
|
2016-07-27 20:43:40 +00:00
|
|
|
/**
|
2020-12-04 21:41:10 +00:00
|
|
|
* Initialize hostapd values, display interface
|
2020-02-15 17:57:46 +00:00
|
|
|
*
|
|
|
|
*/
|
2018-10-03 12:40:55 +00:00
|
|
|
function DisplayHostAPDConfig()
|
|
|
|
{
|
2023-09-16 09:46:11 +00:00
|
|
|
$status = new \RaspAP\Messages\StatusMessage;
|
2021-08-31 14:43:44 +00:00
|
|
|
$system = new \RaspAP\System\Sysinfo;
|
2022-06-22 10:50:00 +00:00
|
|
|
$operatingSystem = $system->operatingSystem();
|
2019-04-10 08:37:35 +00:00
|
|
|
$arrConfig = array();
|
2019-08-01 21:01:31 +00:00
|
|
|
$arr80211Standard = [
|
|
|
|
'a' => '802.11a - 5 GHz',
|
|
|
|
'b' => '802.11b - 2.4 GHz',
|
|
|
|
'g' => '802.11g - 2.4 GHz',
|
2019-12-26 06:17:27 +00:00
|
|
|
'n' => '802.11n - 2.4 GHz',
|
2023-03-20 19:00:28 +00:00
|
|
|
'ac' => '802.11ac - 5 GHz'
|
2020-02-15 17:57:46 +00:00
|
|
|
];
|
2023-11-04 19:09:55 +00:00
|
|
|
$languageCode = strtok($_SESSION['locale'], '_');
|
|
|
|
$countryCodes = getCountryCodes($languageCode);
|
|
|
|
|
2019-04-10 08:37:35 +00:00
|
|
|
$arrSecurity = array(1 => 'WPA', 2 => 'WPA2', 3 => 'WPA+WPA2', 'none' => _("None"));
|
|
|
|
$arrEncType = array('TKIP' => 'TKIP', 'CCMP' => 'CCMP', 'TKIP CCMP' => 'TKIP+CCMP');
|
2021-04-20 14:19:00 +00:00
|
|
|
$arrTxPower = getDefaultNetOpts('txpower','dbm');
|
2019-12-13 14:05:41 +00:00
|
|
|
$managedModeEnabled = false;
|
2019-04-10 08:37:35 +00:00
|
|
|
exec("ip -o link show | awk -F': ' '{print $2}'", $interfaces);
|
2021-04-01 22:35:19 +00:00
|
|
|
sort($interfaces);
|
|
|
|
|
2023-11-05 16:52:09 +00:00
|
|
|
$reg_domain = shell_exec("iw reg get | grep -o 'country [A-Z]\{2\}' | awk 'NR==1{print $2}'");
|
2019-04-10 08:37:35 +00:00
|
|
|
|
2021-04-20 16:53:09 +00:00
|
|
|
$cmd = "iw dev ".$_SESSION['ap_interface']." info | awk '$1==\"txpower\" {print $2}'";
|
|
|
|
exec($cmd, $txpower);
|
|
|
|
$txpower = intval($txpower[0]);
|
|
|
|
|
2023-09-03 07:47:51 +00:00
|
|
|
if (isset($_POST['interface'])) {
|
|
|
|
$interface = escapeshellarg($_POST['interface']);
|
|
|
|
}
|
2020-02-14 02:38:46 +00:00
|
|
|
if (!RASPI_MONITOR_ENABLED) {
|
|
|
|
if (isset($_POST['SaveHostAPDSettings'])) {
|
2023-11-05 16:52:09 +00:00
|
|
|
SaveHostAPDConfig($arrSecurity, $arrEncType, $arr80211Standard, $interfaces, $reg_domain, $status);
|
2020-03-23 12:41:06 +00:00
|
|
|
}
|
|
|
|
}
|
2023-09-03 07:47:51 +00:00
|
|
|
$arrHostapdConf = parse_ini_file(RASPI_CONFIG.'/hostapd.ini');
|
2020-03-23 12:41:06 +00:00
|
|
|
|
|
|
|
if (!RASPI_MONITOR_ENABLED) {
|
|
|
|
if (isset($_POST['StartHotspot']) || isset($_POST['RestartHotspot'])) {
|
2020-02-14 02:38:46 +00:00
|
|
|
$status->addMessage('Attempting to start hotspot', 'info');
|
2020-03-12 21:02:26 +00:00
|
|
|
if ($arrHostapdConf['BridgedEnable'] == 1) {
|
2023-10-21 14:43:49 +00:00
|
|
|
exec('sudo '.RASPI_CONFIG.'/hostapd/servicestart.sh --interface br0 --seconds 2', $return);
|
2020-03-12 21:02:26 +00:00
|
|
|
} elseif ($arrHostapdConf['WifiAPEnable'] == 1) {
|
2023-10-21 14:43:49 +00:00
|
|
|
exec('sudo '.RASPI_CONFIG.'/hostapd/servicestart.sh --interface uap0 --seconds 2', $return);
|
2020-02-14 02:38:46 +00:00
|
|
|
} else {
|
2023-10-21 14:43:49 +00:00
|
|
|
exec('sudo '.RASPI_CONFIG.'/hostapd/servicestart.sh --seconds 2', $return);
|
2020-02-14 02:38:46 +00:00
|
|
|
}
|
|
|
|
foreach ($return as $line) {
|
|
|
|
$status->addMessage($line, 'info');
|
|
|
|
}
|
|
|
|
} elseif (isset($_POST['StopHotspot'])) {
|
|
|
|
$status->addMessage('Attempting to stop hotspot', 'info');
|
|
|
|
exec('sudo /bin/systemctl stop hostapd.service', $return);
|
|
|
|
foreach ($return as $line) {
|
|
|
|
$status->addMessage($line, 'info');
|
|
|
|
}
|
2019-04-10 08:37:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
exec('cat '. RASPI_HOSTAPD_CONFIG, $hostapdconfig);
|
2024-02-24 09:35:35 +00:00
|
|
|
if (isset($_SESSION['wifi_client_interface'])) {
|
|
|
|
exec('iwgetid '.$_SESSION['wifi_client_interface']. ' -r', $wifiNetworkID);
|
2023-09-03 07:47:51 +00:00
|
|
|
if (!empty($wifiNetworkID[0])) {
|
|
|
|
$managedModeEnabled = true;
|
|
|
|
}
|
2019-12-13 14:05:41 +00:00
|
|
|
}
|
2020-02-01 11:07:54 +00:00
|
|
|
$hostapdstatus = $system->hostapdStatus();
|
2019-11-01 09:10:24 +00:00
|
|
|
$serviceStatus = $hostapdstatus[0] == 0 ? "down" : "up";
|
2016-07-27 20:43:40 +00:00
|
|
|
|
2019-04-10 08:37:35 +00:00
|
|
|
foreach ($hostapdconfig as $hostapdconfigline) {
|
|
|
|
if (strlen($hostapdconfigline) === 0) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if ($hostapdconfigline[0] != "#") {
|
2020-02-15 17:57:46 +00:00
|
|
|
$arrLine = explode("=", $hostapdconfigline);
|
2019-04-10 08:37:35 +00:00
|
|
|
$arrConfig[$arrLine[0]]=$arrLine[1];
|
|
|
|
}
|
|
|
|
};
|
2020-09-11 18:03:14 +00:00
|
|
|
// assign beacon_int boolean if value is set
|
|
|
|
if (isset($arrConfig['beacon_int'])) {
|
|
|
|
$arrConfig['beacon_interval_bool'] = 1;
|
|
|
|
}
|
|
|
|
// assign disassoc_low_ack boolean if value is set
|
|
|
|
if (isset($arrConfig['disassoc_low_ack'])) {
|
|
|
|
$arrConfig['disassoc_low_ack_bool'] = 1;
|
2023-10-28 16:00:34 +00:00
|
|
|
} else {
|
|
|
|
$arrConfig['disassoc_low_ack_bool'] = 0;
|
2020-09-11 18:03:14 +00:00
|
|
|
}
|
2023-11-05 16:52:09 +00:00
|
|
|
|
2020-07-10 17:28:28 +00:00
|
|
|
// assign country_code from iw reg if not set in config
|
2022-01-05 10:19:40 +00:00
|
|
|
if (empty($arrConfig['country_code']) && isset($country_code[0])) {
|
2020-07-10 17:28:28 +00:00
|
|
|
$arrConfig['country_code'] = $country_code[0];
|
|
|
|
}
|
2023-11-05 16:52:09 +00:00
|
|
|
|
2021-04-20 16:53:09 +00:00
|
|
|
// set txpower with iw if value is non-default ('auto')
|
2023-09-03 07:47:51 +00:00
|
|
|
if (isset($_POST['txpower'])) {
|
|
|
|
if ($_POST['txpower'] != 'auto') {
|
|
|
|
$txpower = intval($_POST['txpower']);
|
|
|
|
$sdBm = $txpower * 100;
|
|
|
|
exec('sudo /sbin/iw dev '.$interface.' set txpower fixed '.$sdBm, $return);
|
|
|
|
$status->addMessage('Setting transmit power to '.$_POST['txpower'].' dBm.', 'success');
|
|
|
|
$txpower = $_POST['txpower'];
|
|
|
|
} elseif ($_POST['txpower'] == 'auto') {
|
|
|
|
exec('sudo /sbin/iw dev '.$interface.' set txpower auto', $return);
|
|
|
|
$status->addMessage('Setting transmit power to '.$_POST['txpower'].'.', 'success');
|
|
|
|
$txpower = $_POST['txpower'];
|
|
|
|
}
|
2021-04-20 16:53:09 +00:00
|
|
|
}
|
2020-07-10 17:28:28 +00:00
|
|
|
|
2023-03-20 19:14:01 +00:00
|
|
|
$selectedHwMode = $arrConfig['hw_mode'];
|
|
|
|
if (isset($arrConfig['ieee80211n'])) {
|
|
|
|
if (strval($arrConfig['ieee80211n']) === '1') {
|
|
|
|
$selectedHwMode = 'n';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (isset($arrConfig['ieee80211ac'])) {
|
|
|
|
if (strval($arrConfig['ieee80211ac']) === '1') {
|
|
|
|
$selectedHwMode = 'ac';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (isset($arrConfig['ieee80211w'])) {
|
|
|
|
if (strval($arrConfig['ieee80211w']) === '2') {
|
|
|
|
$selectedHwMode = 'w';
|
|
|
|
}
|
|
|
|
}
|
2024-09-26 08:36:13 +00:00
|
|
|
|
2023-11-28 10:05:06 +00:00
|
|
|
exec('sudo /bin/chmod o+r '.RASPI_HOSTAPD_LOG);
|
|
|
|
$logdata = getLogLimited(RASPI_HOSTAPD_LOG);
|
2023-03-20 19:14:01 +00:00
|
|
|
|
2020-02-15 17:57:46 +00:00
|
|
|
echo renderTemplate(
|
|
|
|
"hostapd", compact(
|
|
|
|
"status",
|
|
|
|
"serviceStatus",
|
|
|
|
"hostapdstatus",
|
|
|
|
"managedModeEnabled",
|
|
|
|
"interfaces",
|
|
|
|
"arrConfig",
|
|
|
|
"arr80211Standard",
|
|
|
|
"selectedHwMode",
|
|
|
|
"arrSecurity",
|
|
|
|
"arrEncType",
|
2021-04-20 14:19:00 +00:00
|
|
|
"arrTxPower",
|
2021-04-20 16:53:09 +00:00
|
|
|
"txpower",
|
2022-06-22 10:50:00 +00:00
|
|
|
"arrHostapdConf",
|
2023-03-20 19:14:01 +00:00
|
|
|
"operatingSystem",
|
|
|
|
"selectedHwMode",
|
2023-11-28 10:05:06 +00:00
|
|
|
"countryCodes",
|
|
|
|
"logdata"
|
2020-02-15 17:57:46 +00:00
|
|
|
)
|
|
|
|
);
|
2016-07-27 20:43:40 +00:00
|
|
|
}
|
2016-07-27 20:48:27 +00:00
|
|
|
|
2020-12-04 21:41:10 +00:00
|
|
|
/**
|
|
|
|
* Validate user input, save configs for hostapd, dnsmasq & dhcp
|
|
|
|
*
|
|
|
|
* @param array $wpa_array
|
|
|
|
* @param array $enc_types
|
|
|
|
* @param array $modes
|
|
|
|
* @param string $interface
|
2023-11-05 16:52:09 +00:00
|
|
|
* @param string $reg_domain
|
2020-12-04 21:41:10 +00:00
|
|
|
* @param object $status
|
|
|
|
* @return boolean
|
|
|
|
*/
|
2023-11-05 16:52:09 +00:00
|
|
|
function SaveHostAPDConfig($wpa_array, $enc_types, $modes, $interfaces, $reg_domain, $status)
|
2019-04-10 08:37:35 +00:00
|
|
|
{
|
2023-09-03 07:47:51 +00:00
|
|
|
// It should not be possible to send bad data for these fields.
|
|
|
|
// If wpa fields are absent, return false and log securely.
|
2020-02-15 17:57:46 +00:00
|
|
|
if (!(array_key_exists($_POST['wpa'], $wpa_array)
|
|
|
|
&& array_key_exists($_POST['wpa_pairwise'], $enc_types)
|
|
|
|
&& array_key_exists($_POST['hw_mode'], $modes))
|
|
|
|
) {
|
2023-09-03 07:47:51 +00:00
|
|
|
$err = "Attempting to set hostapd config with wpa='".escapeshellarg($_POST['wpa']);
|
|
|
|
$err .= "', wpa_pairwise='".$escapeshellarg(_POST['wpa_pairwise']);
|
|
|
|
$err .= "and hw_mode='".$escapeshellarg(_POST['hw_mode'])."'";
|
|
|
|
error_log($err);
|
2019-04-10 08:37:35 +00:00
|
|
|
return false;
|
|
|
|
}
|
2020-10-25 07:48:41 +00:00
|
|
|
// Validate input
|
|
|
|
$good_input = true;
|
2018-08-03 23:58:34 +00:00
|
|
|
|
2019-04-10 08:37:35 +00:00
|
|
|
if (!filter_var($_POST['channel'], FILTER_VALIDATE_INT)) {
|
2020-10-25 07:48:41 +00:00
|
|
|
$status->addMessage('Attempting to set channel to invalid number.', 'danger');
|
|
|
|
$good_input = false;
|
2019-04-10 08:37:35 +00:00
|
|
|
}
|
2023-11-07 14:06:57 +00:00
|
|
|
if (intval($_POST['channel']) < 1 || intval($_POST['channel']) > RASPI_5GHZ_CHANNEL_MAX) {
|
2020-10-25 07:48:41 +00:00
|
|
|
$status->addMessage('Attempting to set channel outside of permitted range', 'danger');
|
|
|
|
$good_input = false;
|
2019-04-10 08:37:35 +00:00
|
|
|
}
|
2020-12-15 10:45:27 +00:00
|
|
|
$arrHostapdConf = parse_ini_file('/etc/raspap/hostapd.ini');
|
2020-12-15 22:01:23 +00:00
|
|
|
|
2020-03-10 08:42:08 +00:00
|
|
|
// Check for Bridged AP mode checkbox
|
|
|
|
$bridgedEnable = 0;
|
|
|
|
if ($arrHostapdConf['BridgedEnable'] == 0) {
|
|
|
|
if (isset($_POST['bridgedEnable'])) {
|
|
|
|
$bridgedEnable = 1;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (isset($_POST['bridgedEnable'])) {
|
|
|
|
$bridgedEnable = 1;
|
|
|
|
}
|
|
|
|
}
|
2020-03-12 21:02:26 +00:00
|
|
|
// Check for WiFi client AP mode checkbox
|
|
|
|
$wifiAPEnable = 0;
|
|
|
|
if ($bridgedEnable == 0) { // enable client mode actions when not bridged
|
|
|
|
if ($arrHostapdConf['WifiAPEnable'] == 0) {
|
|
|
|
if (isset($_POST['wifiAPEnable'])) {
|
|
|
|
$wifiAPEnable = 1;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (isset($_POST['wifiAPEnable'])) {
|
|
|
|
$wifiAPEnable = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-04-10 08:37:35 +00:00
|
|
|
// Check for Logfile output checkbox
|
|
|
|
$logEnable = 0;
|
|
|
|
if ($arrHostapdConf['LogEnable'] == 0) {
|
|
|
|
if (isset($_POST['logEnable'])) {
|
|
|
|
$logEnable = 1;
|
2020-06-07 13:23:40 +00:00
|
|
|
exec('sudo '.RASPI_CONFIG.'/hostapd/enablelog.sh');
|
2019-04-10 08:37:35 +00:00
|
|
|
} else {
|
2020-06-07 13:23:40 +00:00
|
|
|
exec('sudo '.RASPI_CONFIG.'/hostapd/disablelog.sh');
|
2019-04-10 08:37:35 +00:00
|
|
|
}
|
2019-03-11 23:47:09 +00:00
|
|
|
} else {
|
2019-04-10 08:37:35 +00:00
|
|
|
if (isset($_POST['logEnable'])) {
|
|
|
|
$logEnable = 1;
|
2020-06-07 13:23:40 +00:00
|
|
|
exec('sudo '.RASPI_CONFIG.'/hostapd/enablelog.sh');
|
2019-04-10 08:37:35 +00:00
|
|
|
} else {
|
2020-06-07 13:23:40 +00:00
|
|
|
exec('sudo '.RASPI_CONFIG.'/hostapd/disablelog.sh');
|
2019-04-10 08:37:35 +00:00
|
|
|
}
|
2019-03-11 23:47:09 +00:00
|
|
|
}
|
2020-12-05 09:14:07 +00:00
|
|
|
// set AP interface default, override for ap-sta & bridged options
|
2021-02-02 07:36:28 +00:00
|
|
|
$ap_iface = $_POST['interface']; // the hostap AP interface
|
|
|
|
$cli_iface = $_POST['interface']; // the wifi client interface
|
|
|
|
$session_iface = $_POST['interface']; // the interface that the UI needs to monitor for data usage etc.
|
|
|
|
if ($wifiAPEnable) { // for AP-STA we monitor the uap0 interface, which is always the ap interface.
|
|
|
|
$ap_iface = 'uap0';
|
|
|
|
$session_iface = 'uap0';
|
|
|
|
}
|
|
|
|
if ($bridgedEnable) { // for bridged mode we monitor the bridge, but keep the selected interface as AP.
|
|
|
|
$session_iface = 'br0';
|
|
|
|
$cli_iface = 'br0';
|
|
|
|
}
|
2020-03-12 21:02:26 +00:00
|
|
|
|
2020-12-04 22:36:54 +00:00
|
|
|
// persist user options to /etc/raspap
|
2019-04-10 08:37:35 +00:00
|
|
|
$cfg = [];
|
2021-02-02 07:36:28 +00:00
|
|
|
$cfg['WifiInterface'] = $ap_iface;
|
2019-04-10 08:37:35 +00:00
|
|
|
$cfg['LogEnable'] = $logEnable;
|
2020-03-12 21:02:26 +00:00
|
|
|
// Save previous Client mode status when Bridged
|
2020-12-04 21:41:10 +00:00
|
|
|
$cfg['WifiAPEnable'] = ($bridgedEnable == 1 ? $arrHostapdConf['WifiAPEnable'] : $wifiAPEnable);
|
2020-03-10 08:42:08 +00:00
|
|
|
$cfg['BridgedEnable'] = $bridgedEnable;
|
2021-02-02 07:36:28 +00:00
|
|
|
$cfg['WifiManaged'] = $cli_iface;
|
2020-06-07 13:23:40 +00:00
|
|
|
write_php_ini($cfg, RASPI_CONFIG.'/hostapd.ini');
|
2021-02-02 07:36:28 +00:00
|
|
|
$_SESSION['ap_interface'] = $session_iface;
|
2019-04-10 08:37:35 +00:00
|
|
|
|
|
|
|
// Verify input
|
|
|
|
if (empty($_POST['ssid']) || strlen($_POST['ssid']) > 32) {
|
|
|
|
$status->addMessage('SSID must be between 1 and 32 characters', 'danger');
|
|
|
|
$good_input = false;
|
2019-03-11 23:47:09 +00:00
|
|
|
}
|
2019-03-06 18:42:13 +00:00
|
|
|
|
2021-05-07 10:33:17 +00:00
|
|
|
# NB: A pass-phrase is a sequence of between 8 and 63 ASCII-encoded characters (IEEE Std. 802.11i-2004)
|
|
|
|
# Each character in the pass-phrase must have an encoding in the range of 32 to 126 (decimal). (IEEE Std. 802.11i-2004, Annex H.4.1)
|
|
|
|
if ($_POST['wpa'] !== 'none' && (strlen($_POST['wpa_passphrase']) < 8 || strlen($_POST['wpa_passphrase']) > 63)) {
|
2019-04-10 08:37:35 +00:00
|
|
|
$status->addMessage('WPA passphrase must be between 8 and 63 characters', 'danger');
|
|
|
|
$good_input = false;
|
2021-05-07 10:33:17 +00:00
|
|
|
} elseif (!ctype_print($_POST['wpa_passphrase'])) {
|
|
|
|
$status->addMessage('WPA passphrase must be comprised of printable ASCII characters', 'danger');
|
|
|
|
$good_input = false;
|
2019-04-10 08:37:35 +00:00
|
|
|
}
|
2019-03-11 23:47:09 +00:00
|
|
|
|
2019-04-10 08:37:35 +00:00
|
|
|
if (isset($_POST['hiddenSSID'])) {
|
|
|
|
if (!is_int((int)$_POST['hiddenSSID'])) {
|
|
|
|
$status->addMessage('Parameter hiddenSSID not a number.', 'danger');
|
|
|
|
$good_input = false;
|
|
|
|
} elseif ((int)$_POST['hiddenSSID'] < 0 || (int)$_POST['hiddenSSID'] >= 3) {
|
|
|
|
$status->addMessage('Parameter hiddenSSID contains invalid configuratie value.', 'danger');
|
|
|
|
$good_input = false;
|
|
|
|
} else {
|
|
|
|
$ignore_broadcast_ssid = $_POST['hiddenSSID'];
|
|
|
|
}
|
2019-03-11 23:47:09 +00:00
|
|
|
} else {
|
2019-04-10 08:37:35 +00:00
|
|
|
$ignore_broadcast_ssid = '0';
|
2019-03-11 23:47:09 +00:00
|
|
|
}
|
|
|
|
|
2019-04-10 08:37:35 +00:00
|
|
|
if (! in_array($_POST['interface'], $interfaces)) {
|
|
|
|
$status->addMessage('Unknown interface '.htmlspecialchars($_POST['interface'], ENT_QUOTES), 'danger');
|
|
|
|
$good_input = false;
|
2019-03-11 23:47:09 +00:00
|
|
|
}
|
2019-04-10 08:37:35 +00:00
|
|
|
if (strlen($_POST['country_code']) !== 0 && strlen($_POST['country_code']) != 2) {
|
|
|
|
$status->addMessage('Country code must be blank or two characters', 'danger');
|
|
|
|
$good_input = false;
|
2023-11-05 16:52:09 +00:00
|
|
|
} else {
|
|
|
|
$country_code = $_POST['country_code'];
|
2019-04-10 08:37:35 +00:00
|
|
|
}
|
2020-09-11 18:03:14 +00:00
|
|
|
if (isset($_POST['beaconintervalEnable'])) {
|
|
|
|
if (!is_numeric($_POST['beacon_interval'])) {
|
|
|
|
$status->addMessage('Beacon interval must be a numeric value', 'danger');
|
|
|
|
$good_input = false;
|
|
|
|
} elseif ($_POST['beacon_interval'] < 15 || $_POST['beacon_interval'] > 65535) {
|
|
|
|
$status->addMessage('Beacon interval must be between 15 and 65535', 'danger');
|
|
|
|
$good_input = false;
|
|
|
|
}
|
|
|
|
}
|
2019-08-01 20:32:44 +00:00
|
|
|
$_POST['max_num_sta'] = (int) $_POST['max_num_sta'];
|
|
|
|
$_POST['max_num_sta'] = $_POST['max_num_sta'] > 2007 ? 2007 : $_POST['max_num_sta'];
|
|
|
|
$_POST['max_num_sta'] = $_POST['max_num_sta'] < 1 ? null : $_POST['max_num_sta'];
|
|
|
|
|
2019-04-10 08:37:35 +00:00
|
|
|
if ($good_input) {
|
2021-02-02 07:36:28 +00:00
|
|
|
$return = updateHostapdConfig($ignore_broadcast_ssid,$wifiAPEnable,$bridgedEnable);
|
2019-04-10 08:37:35 +00:00
|
|
|
|
2023-11-05 16:52:09 +00:00
|
|
|
if (trim($country_code) != trim($reg_domain)) {
|
|
|
|
$return = iwRegSet($country_code, $status);
|
|
|
|
}
|
|
|
|
|
2019-11-04 09:40:23 +00:00
|
|
|
// Fetch dhcp-range, lease time from system config
|
2020-12-01 22:52:15 +00:00
|
|
|
$syscfg = parse_ini_file(RASPI_DNSMASQ_PREFIX.$ap_iface.'.conf', false, INI_SCANNER_RAW);
|
2019-09-08 15:28:01 +00:00
|
|
|
|
2019-04-10 08:37:35 +00:00
|
|
|
if ($wifiAPEnable == 1) {
|
2020-12-05 09:14:07 +00:00
|
|
|
// Enable uap0 configuration for ap-sta mode
|
|
|
|
// Set dhcp-range from system config, fallback to default if undefined
|
|
|
|
$dhcp_range = ($syscfg['dhcp-range'] == '') ? getDefaultNetValue('dnsmasq','uap0','dhcp-range') : $syscfg['dhcp-range'];
|
2020-12-01 22:52:15 +00:00
|
|
|
$config = [ '# RaspAP uap0 configuration' ];
|
|
|
|
$config[] = 'interface=lo,uap0 # Enable uap0 interface for wireless client AP mode';
|
|
|
|
$config[] = 'bind-dynamic # Hybrid between --bind-interfaces and default';
|
|
|
|
$config[] = 'server=8.8.8.8 # Forward DNS requests to Google DNS';
|
|
|
|
$config[] = 'domain-needed # Don\'t forward short names';
|
|
|
|
$config[] = 'bogus-priv # Never forward addresses in the non-routed address spaces';
|
|
|
|
$config[] = 'dhcp-range='.$dhcp_range;
|
|
|
|
if (!empty($syscfg['dhcp-option'])) {
|
|
|
|
$config[] = 'dhcp-option='.$syscfg['dhcp-option'];
|
2019-11-04 09:40:23 +00:00
|
|
|
}
|
2020-12-04 14:40:54 +00:00
|
|
|
$config[] = PHP_EOL;
|
|
|
|
scanConfigDir('/etc/dnsmasq.d/','uap0',$status);
|
|
|
|
$config = join(PHP_EOL, $config);
|
|
|
|
file_put_contents("/tmp/dnsmasqdata", $config);
|
|
|
|
system('sudo cp /tmp/dnsmasqdata '.RASPI_DNSMASQ_PREFIX.$ap_iface.'.conf', $return);
|
|
|
|
} elseif ($bridgedEnable !==1) {
|
2023-11-09 18:32:34 +00:00
|
|
|
$dhcp_range = ($syscfg['dhcp-range'] =='') ? getDefaultNetValue('dnsmasq',$ap_iface,'dhcp-range') : $syscfg['dhcp-range'];
|
2020-12-01 22:52:15 +00:00
|
|
|
$config = [ '# RaspAP '.$_POST['interface'].' configuration' ];
|
|
|
|
$config[] = 'interface='.$_POST['interface'];
|
|
|
|
$config[] = 'domain-needed';
|
|
|
|
$config[] = 'dhcp-range='.$dhcp_range;
|
|
|
|
if (!empty($syscfg['dhcp-option'])) {
|
|
|
|
$config[] = 'dhcp-option='.$syscfg['dhcp-option'];
|
2019-11-04 09:40:23 +00:00
|
|
|
}
|
2020-12-04 14:40:54 +00:00
|
|
|
$config[] = PHP_EOL;
|
|
|
|
$config = join(PHP_EOL, $config);
|
|
|
|
file_put_contents("/tmp/dnsmasqdata", $config);
|
|
|
|
system('sudo cp /tmp/dnsmasqdata '.RASPI_DNSMASQ_PREFIX.$ap_iface.'.conf', $return);
|
2019-04-10 08:37:35 +00:00
|
|
|
}
|
|
|
|
|
2020-12-01 22:52:15 +00:00
|
|
|
// Set dhcp values from system config, fallback to default if undefined
|
2020-12-05 09:14:07 +00:00
|
|
|
$jsonData = json_decode(getNetConfig($ap_iface), true);
|
2020-12-06 17:31:03 +00:00
|
|
|
$ip_address = ($jsonData['StaticIP'] == '') ? getDefaultNetValue('dhcp',$ap_iface,'static ip_address') : $jsonData['StaticIP'];
|
2023-11-09 18:32:34 +00:00
|
|
|
$domain_name_server = ($jsonData['StaticDNS'] =='') ? getDefaultNetValue('dhcp',$ap_iface,'static domain_name_server') : $jsonData['StaticDNS'];
|
2020-12-06 17:31:03 +00:00
|
|
|
$routers = ($jsonData['StaticRouters'] == '') ? getDefaultNetValue('dhcp',$ap_iface,'static routers') : $jsonData['StaticRouters'];
|
|
|
|
$netmask = ($jsonData['SubnetMask'] == '' || $jsonData['SubnetMask'] == '0.0.0.0') ? getDefaultNetValue('dhcp',$ap_iface,'subnetmask') : $jsonData['SubnetMask'];
|
2023-11-10 09:29:49 +00:00
|
|
|
if (isset($ip_address) && !preg_match('/.*\/\d+/', $ip_address)) {
|
|
|
|
$ip_address.='/'.mask2cidr($netmask);
|
|
|
|
}
|
2020-12-06 17:31:03 +00:00
|
|
|
|
2020-03-10 08:42:08 +00:00
|
|
|
if ($bridgedEnable == 1) {
|
2021-04-20 14:19:00 +00:00
|
|
|
$config = array_keys(getDefaultNetOpts('dhcp','options'));
|
2020-12-04 14:40:54 +00:00
|
|
|
$config[] = PHP_EOL.'# RaspAP br0 configuration';
|
2020-03-10 08:42:08 +00:00
|
|
|
$config[] = 'denyinterfaces eth0 wlan0';
|
2021-02-21 10:28:55 +00:00
|
|
|
$config[] = 'interface br0';
|
2020-12-04 14:40:54 +00:00
|
|
|
$config[] = PHP_EOL;
|
2020-03-10 08:42:08 +00:00
|
|
|
} elseif ($wifiAPEnable == 1) {
|
2021-04-20 14:19:00 +00:00
|
|
|
$config = array_keys(getDefaultNetOpts('dhcp','options'));
|
2020-12-04 14:40:54 +00:00
|
|
|
$config[] = PHP_EOL.'# RaspAP uap0 configuration';
|
|
|
|
$config[] = 'interface uap0';
|
2020-02-28 17:51:33 +00:00
|
|
|
$config[] = 'static ip_address='.$ip_address;
|
|
|
|
$config[] = 'nohook wpa_supplicant';
|
2020-12-04 14:40:54 +00:00
|
|
|
$config[] = PHP_EOL;
|
2019-04-10 08:37:35 +00:00
|
|
|
} else {
|
2020-05-12 07:10:54 +00:00
|
|
|
$def_ip = array();
|
2022-01-04 18:02:12 +00:00
|
|
|
$config = [ '# RaspAP '.$ap_iface.' configuration' ];
|
|
|
|
$config[] = 'interface '.$ap_iface;
|
2020-02-28 17:51:33 +00:00
|
|
|
$config[] = 'static ip_address='.$ip_address;
|
2020-12-01 22:52:15 +00:00
|
|
|
$config[] = 'static routers='.$routers;
|
2020-02-28 17:51:33 +00:00
|
|
|
$config[] = 'static domain_name_server='.$domain_name_server;
|
2020-12-04 14:40:54 +00:00
|
|
|
if (! is_null($jsonData['Metric'])) { $config[] = 'metric '.$jsonData['Metric']; }
|
2020-05-12 07:10:54 +00:00
|
|
|
}
|
2020-11-19 12:34:55 +00:00
|
|
|
$dhcp_cfg = file_get_contents(RASPI_DHCPCD_CONFIG);
|
2023-11-10 09:29:49 +00:00
|
|
|
|
2024-09-26 08:36:13 +00:00
|
|
|
$skip_dhcp = false;
|
2023-11-10 09:29:49 +00:00
|
|
|
if (preg_match('/wlan[2-9]\d*|wlan[1-9]\d+/', $ap_iface)) {
|
2024-09-26 08:36:13 +00:00
|
|
|
$skip_dhcp = true;
|
2023-11-10 09:29:49 +00:00
|
|
|
} elseif ($bridgedEnable == 1 || $wifiAPEnable == 1) {
|
2020-12-04 14:40:54 +00:00
|
|
|
$dhcp_cfg = join(PHP_EOL, $config);
|
2023-11-10 09:29:49 +00:00
|
|
|
$status->addMessage(sprintf(_('DHCP configuration for %s enabled.'), $ap_iface), 'success');
|
2020-12-04 14:40:54 +00:00
|
|
|
} elseif (!preg_match('/^interface\s'.$ap_iface.'$/m', $dhcp_cfg)) {
|
2020-12-01 22:52:15 +00:00
|
|
|
$config[] = PHP_EOL;
|
|
|
|
$config= join(PHP_EOL, $config);
|
2020-12-04 14:40:54 +00:00
|
|
|
$dhcp_cfg = removeDHCPIface($dhcp_cfg,'br0');
|
|
|
|
$dhcp_cfg = removeDHCPIface($dhcp_cfg,'uap0');
|
2020-12-01 22:52:15 +00:00
|
|
|
$dhcp_cfg .= $config;
|
2023-11-10 09:29:49 +00:00
|
|
|
$status->addMessage(sprintf(_('DHCP configuration for %s added.'), $ap_iface), 'success');
|
2020-12-01 22:52:15 +00:00
|
|
|
} else {
|
|
|
|
$config = join(PHP_EOL, $config);
|
2020-12-04 14:40:54 +00:00
|
|
|
$dhcp_cfg = removeDHCPIface($dhcp_cfg,'br0');
|
|
|
|
$dhcp_cfg = removeDHCPIface($dhcp_cfg,'uap0');
|
2020-12-01 22:52:15 +00:00
|
|
|
$dhcp_cfg = preg_replace('/^#\sRaspAP\s'.$ap_iface.'\s.*?(?=\s*^\s*$)/ms', $config, $dhcp_cfg, 1);
|
2023-11-10 09:29:49 +00:00
|
|
|
$status->addMessage(sprintf(_('DHCP configuration for %s updated.'), $ap_iface), 'success');
|
2020-12-01 22:52:15 +00:00
|
|
|
}
|
2023-11-10 09:29:49 +00:00
|
|
|
if (!$skip_dhcp) {
|
|
|
|
file_put_contents("/tmp/dhcpddata", $dhcp_cfg);
|
|
|
|
system('sudo cp /tmp/dhcpddata '.RASPI_DHCPCD_CONFIG, $return);
|
|
|
|
if ($return == 0) {
|
|
|
|
$status->addMessage('Wifi Hotspot settings saved', 'success');
|
|
|
|
} else {
|
|
|
|
$status->addMessage('Unable to save wifi hotspot settings', 'danger');
|
|
|
|
}
|
2019-04-10 08:37:35 +00:00
|
|
|
} else {
|
2023-11-10 09:29:49 +00:00
|
|
|
$status->addMessage(sprintf(_('Interface %s has no default settings.'), $ap_iface), 'warning');
|
|
|
|
$status->addMessage(('Configure settings in <strong>DHCP Server</strong> before starting AP.'), 'warning');
|
|
|
|
$status->addMessage('Wifi Hotspot settings saved', 'success');
|
2019-04-10 08:37:35 +00:00
|
|
|
}
|
2016-08-05 20:38:02 +00:00
|
|
|
} else {
|
2019-04-10 08:37:35 +00:00
|
|
|
$status->addMessage('Unable to save wifi hotspot settings', 'danger');
|
|
|
|
return false;
|
2016-07-27 20:48:27 +00:00
|
|
|
}
|
2019-04-10 08:37:35 +00:00
|
|
|
return true;
|
2016-07-27 20:48:27 +00:00
|
|
|
}
|
2020-12-04 22:36:54 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Updates a hostapd configuration
|
|
|
|
*
|
|
|
|
* @return boolean $result
|
|
|
|
*/
|
2021-01-06 07:48:46 +00:00
|
|
|
function updateHostapdConfig($ignore_broadcast_ssid,$wifiAPEnable,$bridgedEnable)
|
2020-12-04 22:36:54 +00:00
|
|
|
{
|
|
|
|
// Fixed values
|
|
|
|
$country_code = $_POST['country_code'];
|
|
|
|
$config = 'driver=nl80211'.PHP_EOL;
|
|
|
|
$config.= 'ctrl_interface='.RASPI_HOSTAPD_CTRL_INTERFACE.PHP_EOL;
|
|
|
|
$config.= 'ctrl_interface_group=0'.PHP_EOL;
|
|
|
|
$config.= 'auth_algs=1'.PHP_EOL;
|
|
|
|
$config.= 'wpa_key_mgmt=WPA-PSK'.PHP_EOL;
|
|
|
|
if (isset($_POST['beaconintervalEnable'])) {
|
|
|
|
$config.= 'beacon_int='.$_POST['beacon_interval'].PHP_EOL;
|
|
|
|
}
|
|
|
|
if (isset($_POST['disassoc_low_ackEnable'])) {
|
|
|
|
$config.= 'disassoc_low_ack=0'.PHP_EOL;
|
|
|
|
}
|
|
|
|
$config.= 'ssid='.$_POST['ssid'].PHP_EOL;
|
|
|
|
$config.= 'channel='.$_POST['channel'].PHP_EOL;
|
2023-11-06 07:28:50 +00:00
|
|
|
|
|
|
|
// Set VHT center frequency segment value
|
2023-11-07 14:06:57 +00:00
|
|
|
if ((int)$_POST['channel'] < RASPI_5GHZ_CHANNEL_MIN) {
|
2023-11-06 07:28:50 +00:00
|
|
|
$vht_freq_idx = 42;
|
|
|
|
} else {
|
|
|
|
$vht_freq_idx = 155;
|
|
|
|
}
|
|
|
|
|
2020-12-04 22:36:54 +00:00
|
|
|
if ($_POST['hw_mode'] === 'n') {
|
|
|
|
$config.= 'hw_mode=g'.PHP_EOL;
|
|
|
|
$config.= 'ieee80211n=1'.PHP_EOL;
|
|
|
|
// Enable basic Quality of service
|
|
|
|
$config.= 'wmm_enabled=1'.PHP_EOL;
|
|
|
|
} elseif ($_POST['hw_mode'] === 'ac') {
|
|
|
|
$config.= 'hw_mode=a'.PHP_EOL.PHP_EOL;
|
|
|
|
$config.= '# N'.PHP_EOL;
|
|
|
|
$config.= 'ieee80211n=1'.PHP_EOL;
|
|
|
|
$config.= 'require_ht=1'.PHP_EOL;
|
|
|
|
$config.= 'ht_capab=[MAX-AMSDU-3839][HT40+][SHORT-GI-20][SHORT-GI-40][DSSS_CCK-40]'.PHP_EOL.PHP_EOL;
|
|
|
|
$config.= '# AC'.PHP_EOL;
|
|
|
|
$config.= 'ieee80211ac=1'.PHP_EOL;
|
|
|
|
$config.= 'require_vht=1'.PHP_EOL;
|
|
|
|
$config.= 'ieee80211d=0'.PHP_EOL;
|
|
|
|
$config.= 'ieee80211h=0'.PHP_EOL;
|
|
|
|
$config.= 'vht_capab=[MAX-AMSDU-3839][SHORT-GI-80]'.PHP_EOL;
|
|
|
|
$config.= 'vht_oper_chwidth=1'.PHP_EOL;
|
2023-11-06 07:28:50 +00:00
|
|
|
$config.= 'vht_oper_centr_freq_seg0_idx='.$vht_freq_idx.PHP_EOL.PHP_EOL;
|
2020-12-04 22:36:54 +00:00
|
|
|
} elseif ($_POST['hw_mode'] === 'w') {
|
|
|
|
$config.= 'ieee80211w=2'.PHP_EOL;
|
|
|
|
$config.= 'wpa_key_mgmt=WPA-EAP-SHA256'.PHP_EOL;
|
|
|
|
} else {
|
|
|
|
$config.= 'hw_mode='.$_POST['hw_mode'].PHP_EOL;
|
|
|
|
$config.= 'ieee80211n=0'.PHP_EOL;
|
|
|
|
}
|
|
|
|
if ($_POST['wpa'] !== 'none') {
|
|
|
|
$config.= 'wpa_passphrase='.$_POST['wpa_passphrase'].PHP_EOL;
|
|
|
|
}
|
|
|
|
if ($wifiAPEnable == 1) {
|
|
|
|
$config.= 'interface=uap0'.PHP_EOL;
|
|
|
|
} elseif ($bridgedEnable == 1) {
|
|
|
|
$config.='interface='.$_POST['interface'].PHP_EOL;
|
|
|
|
$config.= 'bridge=br0'.PHP_EOL;
|
|
|
|
} else {
|
2020-12-20 16:46:57 +00:00
|
|
|
$config.= 'interface='.$_SESSION['ap_interface'].PHP_EOL;
|
2020-12-04 22:36:54 +00:00
|
|
|
}
|
|
|
|
$config.= 'wpa='.$_POST['wpa'].PHP_EOL;
|
|
|
|
$config.= 'wpa_pairwise='.$_POST['wpa_pairwise'].PHP_EOL;
|
|
|
|
$config.= 'country_code='.$_POST['country_code'].PHP_EOL;
|
|
|
|
$config.= 'ignore_broadcast_ssid='.$ignore_broadcast_ssid.PHP_EOL;
|
|
|
|
if (isset($_POST['max_num_sta'])) {
|
|
|
|
$config.= 'max_num_sta='.$_POST['max_num_sta'].PHP_EOL;
|
|
|
|
}
|
2024-09-26 08:36:13 +00:00
|
|
|
|
2024-09-26 11:17:34 +00:00
|
|
|
$config.= parseUserHostapdCfg();
|
2024-09-26 08:36:13 +00:00
|
|
|
|
2020-12-04 22:36:54 +00:00
|
|
|
file_put_contents("/tmp/hostapddata", $config);
|
|
|
|
system("sudo cp /tmp/hostapddata " . RASPI_HOSTAPD_CONFIG, $result);
|
|
|
|
return $result;
|
|
|
|
}
|
|
|
|
|
2023-11-05 16:52:09 +00:00
|
|
|
/**
|
|
|
|
* Executes iw to set the specified ISO 2-letter country code
|
|
|
|
*
|
|
|
|
* @param string $country_code
|
|
|
|
* @param object $status
|
|
|
|
* @return boolean $result
|
|
|
|
*/
|
|
|
|
function iwRegSet(string $country_code, $status)
|
|
|
|
{
|
2023-11-06 17:14:18 +00:00
|
|
|
$country_code = escapeshellarg($country_code);
|
|
|
|
$result = shell_exec("sudo iw reg set $country_code");
|
|
|
|
$status->addMessage(sprintf(_('Setting wireless regulatory domain to %s'), $country_code, 'success'));
|
|
|
|
return $result;
|
2023-11-05 16:52:09 +00:00
|
|
|
}
|
|
|
|
|
2024-09-26 11:17:34 +00:00
|
|
|
/**
|
|
|
|
* Parses optional /etc/hostapd/hostapd.conf.users file
|
|
|
|
*
|
|
|
|
* @return string $tmp
|
|
|
|
*/
|
|
|
|
function parseUserHostapdCfg()
|
|
|
|
{
|
|
|
|
if (file_exists(RASPI_HOSTAPD_CONFIG . '.users')) {
|
|
|
|
exec('cat '. RASPI_HOSTAPD_CONFIG . '.users', $hostapdconfigusers);
|
|
|
|
foreach ($hostapdconfigusers as $hostapdconfigusersline) {
|
|
|
|
if (strlen($hostapdconfigusersline) === 0) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if ($hostapdconfigusersline[0] != "#") {
|
|
|
|
$arrLine = explode("=", $hostapdconfigusersline);
|
|
|
|
$tmp.= $arrLine[0]."=".$arrLine[1].PHP_EOL;;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $tmp;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|