Merge branch 'master' into feat/net-activity-led

This commit is contained in:
billz
2025-04-25 00:40:23 -07:00
7 changed files with 54 additions and 22 deletions

View File

@@ -823,6 +823,23 @@ function loadFooterScripts($extraFooterScripts)
}
}
/**
* Validate whether the given network interface exists on the system.
* This function retrieves all currently available network interfaces using the `ip link show` command
* and checks if the provided interface name is in the list.
*/
function validateInterface($interface)
{
// Retrieve all available network interfaces
$valid_interfaces = shell_exec('ip -o link show | awk -F": " \'{print $2}\'');
// Convert to array (one interface per line)
$valid_interfaces = explode("\n", trim($valid_interfaces));
// Check if the provided interface exists in the list
return in_array($interface, $valid_interfaces, true);
}
/**
* Returns ISO standard 2-letter country codes
*

View File

@@ -34,7 +34,7 @@ function DisplayHostAPDConfig()
$reg_domain = shell_exec("iw reg get | grep -o 'country [A-Z]\{2\}' | awk 'NR==1{print $2}'");
$cmd = "iw dev ".$_SESSION['ap_interface']." info | awk '$1==\"txpower\" {print $2}'";
$cmd = "iw dev ".escapeshellarg($_SESSION['ap_interface'])." info | awk '$1==\"txpower\" {print $2}'";
exec($cmd, $txpower);
$txpower = intval($txpower[0]);
@@ -76,7 +76,7 @@ function DisplayHostAPDConfig()
}
exec('cat '. RASPI_HOSTAPD_CONFIG, $hostapdconfig);
if (isset($_SESSION['wifi_client_interface'])) {
exec('iwgetid '.$_SESSION['wifi_client_interface']. ' -r', $wifiNetworkID);
exec('iwgetid '.escapeshellarg($_SESSION['wifi_client_interface']). ' -r', $wifiNetworkID);
if (!empty($wifiNetworkID[0])) {
$managedModeEnabled = true;
}
@@ -249,17 +249,18 @@ function SaveHostAPDConfig($wpa_array, $enc_types, $modes, $interfaces, $reg_dom
exec('sudo '.RASPI_CONFIG.'/hostapd/disablelog.sh');
}
}
// set AP interface default, override for ap-sta & bridged options
$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.
$iface = validateInterface($_POST['interface']) ? $_POST['interface'] : RASPI_WIFI_AP_INTERFACE;
$ap_iface = $iface; // the hostap AP interface
$cli_iface = $iface; // the wifi client interface
$session_iface = $iface; // 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';
$ap_iface = $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';
$cli_iface = $session_iface = 'br0';
}
// persist user options to /etc/raspap

View File

@@ -165,6 +165,10 @@ function getWifiInterface()
$iface = $_SESSION['ap_interface'] = $arrHostapdConf['WifiInterface'] ?? RASPI_WIFI_AP_INTERFACE;
if (!validateInterface($iface)) {
$iface = RASPI_WIFI_AP_INTERFACE;
}
// check for 2nd wifi interface -> wifi client on different interface
exec("iw dev | awk '$1==\"Interface\" && $2!=\"$iface\" {print $2}'", $iface2);
$client_iface = $_SESSION['wifi_client_interface'] = empty($iface2) ? $iface : trim($iface2[0]);

View File

@@ -11,13 +11,14 @@ function DisplayWireGuardConfig()
$parseFlag = true;
if (!RASPI_MONITOR_ENABLED) {
$optRules = isset($_POST['wgRules']) ? $_POST['wgRules'] : null;
$optInterface = isset($_POST['wgInterface']) ? $_POST['wgInterface'] : null;
$optConf = isset($_POST['wgCnfOpt']) ? $_POST['wgCnfOpt'] : null;
$optSrvEnable = isset($_POST['wgSrvEnable']) ? $_POST['wgSrvEnable'] : null;
$optLogEnable = isset($_POST['wgLogEnable']) ? $_POST['wgLogEnable'] : null;
if (isset($_POST['savewgsettings']) && $optConf == 'manual' && $optSrvEnable == 1 ) {
SaveWireGuardConfig($status);
} elseif (isset($_POST['savewgsettings']) && $optConf == 'upload' && is_uploaded_file($_FILES["wgFile"]["tmp_name"])) {
SaveWireGuardUpload($status, $_FILES['wgFile'], $optRules);
SaveWireGuardUpload($status, $_FILES['wgFile'], $optRules, $optInterface);
} elseif (isset($_POST['savewgsettings']) && isset($_POST['wg_penabled']) ) {
SaveWireGuardConfig($status);
} elseif (isset($_POST['startwg'])) {
@@ -77,12 +78,17 @@ function DisplayWireGuardConfig()
}
$peer_id = $peer_id ?? "1";
// fetch available interfaces
exec("ip -o link show | awk -F': ' '{print $2}'", $interfaces);
sort($interfaces);
echo renderTemplate(
"wireguard", compact(
"status",
"wg_state",
"serviceStatus",
"public_ip",
"interfaces",
"optRules",
"optLogEnable",
"peer_id",
@@ -110,9 +116,10 @@ function DisplayWireGuardConfig()
* @param object $status
* @param object $file
* @param boolean $optRules
* @param string $optInterface
* @return object $status
*/
function SaveWireGuardUpload($status, $file, $optRules)
function SaveWireGuardUpload($status, $file, $optRules, $optInterface)
{
define('KB', 1024);
$tmp_destdir = '/tmp/';
@@ -147,7 +154,7 @@ function SaveWireGuardUpload($status, $file, $optRules)
$rules[] = 'PostDown = '.getDefaultNetValue('wireguard','server','PostDown');
$rules[] = '';
$rules = join(PHP_EOL, $rules);
$rules = preg_replace('/wlan0/m', $_SESSION['ap_interface'], $rules);
$rules = preg_replace('/wlan0/m', $optInterface, $rules);
$tmp_contents = preg_replace('/^\s*$/ms', $rules, $tmp_contents, 1);
file_put_contents($tmp_wgconfig, $tmp_contents);
}

Binary file not shown.

View File

@@ -1355,14 +1355,14 @@ msgstr "Upload a WireGuard config"
msgid "This option uploads and installs an existing WireGuard <code>.conf</code> file on this device."
msgstr "This option uploads and installs an existing WireGuard <code>.conf</code> file on this device."
msgid "Apply iptables rules for AP interface"
msgstr "Apply iptables rules for AP interface"
msgid "Apply iptables rules to the selected interface"
msgstr "Apply iptables rules to the selected interface"
msgid "Recommended if you wish to forward network traffic from the wg0 interface to clients connected on the AP interface."
msgstr "Recommended if you wish to forward network traffic from the wg0 interface to clients connected on the AP interface."
msgid "Recommended if you wish to forward network traffic from the wg0 interface to clients connected on a desired interface. The active AP interface is the default."
msgstr "Recommended if you wish to forward network traffic from the wg0 interface to clients connected on a desired interface. The active AP interface is the default."
msgid "This option adds <strong>iptables</strong> <code>Postup</code> and <code>PostDown</code> rules for the configured AP interface (%s)."
msgstr "This option adds <strong>iptables</strong> <code>Postup</code> and <code>PostDown</code> rules for the configured AP interface (%s)."
msgid "This option adds <strong>iptables</strong> <code>Postup</code> and <code>PostDown</code> rules for the interface selected below."
msgstr "This option adds <strong>iptables</strong> <code>Postup</code> and <code>PostDown</code> rules for the interface selected below."
msgid "Select WireGuard configuration file (.conf)"
msgstr "Select WireGuard configuration file (.conf)"

View File

@@ -35,17 +35,20 @@
<div class="form-check form-switch">
<?php $checked = $optRules == 1 ? 'checked="checked"' : '' ?>
<input class="form-check-input" id="chxwgrules" name="wgRules" type="checkbox" value="1" <?php echo $checked ?> />
<label class="form-check-label" for="chxwgrules"><?php echo _("Apply iptables rules for AP interface"); ?></label>
<i class="fas fa-question-circle text-muted" data-bs-toggle="tooltip" data-bs-placement="auto" title="<?php echo _("Recommended if you wish to forward network traffic from the wg0 interface to clients connected on the AP interface."); ?>"></i>
<label class="form-check-label" for="chxwgrules"><?php echo _("Apply iptables rules to the selected interface"); ?></label>
<i class="fas fa-question-circle text-muted" data-bs-toggle="tooltip" data-bs-placement="auto" title="<?php echo _("Recommended if you wish to forward network traffic from the wg0 interface to clients connected on a desired interface. The active AP interface is the default."); ?>"></i>
<p id="wg-description">
<small><?php printf(_("This option adds <strong>iptables</strong> <code>Postup</code> and <code>PostDown</code> rules for the configured AP interface (%s)."), $_SESSION['ap_interface']) ?></small>
<small><?php echo _("This option adds <strong>iptables</strong> <code>Postup</code> and <code>PostDown</code> rules for the interface selected below."); ?></small>
<div class="col-sm-6">
<?php SelectorOptions('wgInterface', $interfaces, $_SESSION['ap_interface'], 'cbxinterface'); ?>
</div>
</p>
</div>
</div>
<div class="mb-3">
<h5 class="panel-title"><?php echo _("Configuration File"); ?></h4>
<div class="custom-file">
<div class="col-sm-8 custom-file">
<input type="file" class="form-control" name="wgFile" id="wgFile">
<label class="form-label" for="wgFile"><?php echo _("Select WireGuard configuration file (.conf)"); ?></label>
</div>