Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for custom hostapd.conf.users file #1666

Merged
merged 2 commits into from
Sep 27, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 28 additions & 1 deletion includes/hostapd.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ function DisplayHostAPDConfig()
$selectedHwMode = 'w';
}
}

exec('sudo /bin/chmod o+r '.RASPI_HOSTAPD_LOG);
$logdata = getLogLimited(RASPI_HOSTAPD_LOG);

Expand Down Expand Up @@ -395,8 +396,9 @@ function SaveHostAPDConfig($wpa_array, $enc_types, $modes, $interfaces, $reg_dom
}
$dhcp_cfg = file_get_contents(RASPI_DHCPCD_CONFIG);

$skip_dhcp = false;
if (preg_match('/wlan[2-9]\d*|wlan[1-9]\d+/', $ap_iface)) {
$skip_dhcp = true;;
$skip_dhcp = true;
} elseif ($bridgedEnable == 1 || $wifiAPEnable == 1) {
$dhcp_cfg = join(PHP_EOL, $config);
$status->addMessage(sprintf(_('DHCP configuration for %s enabled.'), $ap_iface), 'success');
Expand Down Expand Up @@ -508,6 +510,9 @@ function updateHostapdConfig($ignore_broadcast_ssid,$wifiAPEnable,$bridgedEnable
if (isset($_POST['max_num_sta'])) {
$config.= 'max_num_sta='.$_POST['max_num_sta'].PHP_EOL;
}

$config.= parseUserHostapdCfg();

file_put_contents("/tmp/hostapddata", $config);
system("sudo cp /tmp/hostapddata " . RASPI_HOSTAPD_CONFIG, $result);
return $result;
Expand All @@ -528,3 +533,25 @@ function iwRegSet(string $country_code, $status)
return $result;
}

/**
* 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;
}
}

Loading