Skip to content

Commit 20ce710

Browse files
authored
Merge pull request #1666 from RaspAP/feat/hostapd-userconf
Add support for custom hostapd.conf.users file
2 parents 56e5f6f + 5b88728 commit 20ce710

File tree

1 file changed

+28
-1
lines changed

1 file changed

+28
-1
lines changed

includes/hostapd.php

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ function DisplayHostAPDConfig()
135135
$selectedHwMode = 'w';
136136
}
137137
}
138+
138139
exec('sudo /bin/chmod o+r '.RASPI_HOSTAPD_LOG);
139140
$logdata = getLogLimited(RASPI_HOSTAPD_LOG);
140141

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

399+
$skip_dhcp = false;
398400
if (preg_match('/wlan[2-9]\d*|wlan[1-9]\d+/', $ap_iface)) {
399-
$skip_dhcp = true;;
401+
$skip_dhcp = true;
400402
} elseif ($bridgedEnable == 1 || $wifiAPEnable == 1) {
401403
$dhcp_cfg = join(PHP_EOL, $config);
402404
$status->addMessage(sprintf(_('DHCP configuration for %s enabled.'), $ap_iface), 'success');
@@ -508,6 +510,9 @@ function updateHostapdConfig($ignore_broadcast_ssid,$wifiAPEnable,$bridgedEnable
508510
if (isset($_POST['max_num_sta'])) {
509511
$config.= 'max_num_sta='.$_POST['max_num_sta'].PHP_EOL;
510512
}
513+
514+
$config.= parseUserHostapdCfg();
515+
511516
file_put_contents("/tmp/hostapddata", $config);
512517
system("sudo cp /tmp/hostapddata " . RASPI_HOSTAPD_CONFIG, $result);
513518
return $result;
@@ -528,3 +533,25 @@ function iwRegSet(string $country_code, $status)
528533
return $result;
529534
}
530535

536+
/**
537+
* Parses optional /etc/hostapd/hostapd.conf.users file
538+
*
539+
* @return string $tmp
540+
*/
541+
function parseUserHostapdCfg()
542+
{
543+
if (file_exists(RASPI_HOSTAPD_CONFIG . '.users')) {
544+
exec('cat '. RASPI_HOSTAPD_CONFIG . '.users', $hostapdconfigusers);
545+
foreach ($hostapdconfigusers as $hostapdconfigusersline) {
546+
if (strlen($hostapdconfigusersline) === 0) {
547+
continue;
548+
}
549+
if ($hostapdconfigusersline[0] != "#") {
550+
$arrLine = explode("=", $hostapdconfigusersline);
551+
$tmp.= $arrLine[0]."=".$arrLine[1].PHP_EOL;;
552+
}
553+
}
554+
return $tmp;
555+
}
556+
}
557+

0 commit comments

Comments
 (0)