Skip to content

Commit

Permalink
set active connection readonly
Browse files Browse the repository at this point in the history
  • Loading branch information
AlvinSchiller committed Mar 8, 2024
1 parent 197cb08 commit b96aa34
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 31 deletions.
26 changes: 11 additions & 15 deletions htdocs/inc.setWifi.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@
$temp_prio = trim($network_conf[2]);

if(isset($temp_ssid) && $temp_ssid != "" && isset($temp_pass) && $temp_pass != "") {
if(!isset($temp_prio) || !is_numeric($temp_prio)) {
$temp_prio = 0;
}
$networks[] = array($temp_ssid, $temp_pass, $temp_prio);
}
}
Expand Down Expand Up @@ -91,25 +94,24 @@
$WIFIssid = $WIFIconf[0];
$WIFIpass = $WIFIconf[1];
$WIFIprio = $WIFIconf[2];
$WIFIactive = isset($active_essid) && $WIFIssid == $active_essid;
?>
<li class="list-group-item">
<div class="row">

<!-- Text input-->
<div class="form-group">
<label class="col-md-4 control-label" for="WIFIssid_<?php print $WIFIindex; ?>"><?php
if(isset($WIFIssid) && isset($active_essid) && $WIFIssid == $active_essid) {
if($WIFIactive) {
print $lang['globalSSID']."*";
} else {
print $lang['globalSSID'];
}
?></label>
<div class="col-md-6">
<input value="<?php
if(isset($WIFIssid) && $WIFIssid != "") {
print $WIFIssid;
}
?>" id="WIFIssid_<?php print $WIFIindex; ?>" name="WIFIssid_<?php print $WIFIindex; ?>" placeholder="<?php print $lang['settingsWifiSsidPlaceholder']; ?>" class="form-control input-md" type="text">
print $WIFIssid;
?>" id="WIFIssid_<?php print $WIFIindex; ?>" name="WIFIssid_<?php print $WIFIindex; ?>" placeholder="<?php print $lang['settingsWifiSsidPlaceholder']; ?>" class="form-control input-md" type="text" <?php print $WIFIactive ? "readonly" : ""; ?>>
<span class="help-block"></span>
</div>
</div>
Expand All @@ -119,10 +121,8 @@
<label class="col-md-4 control-label" for="WIFIpass_<?php print $WIFIindex; ?>"><?php print $lang['globalPassword']; ?></label>
<div class="col-md-6">
<input value="<?php
if(isset($WIFIpass) && $WIFIpass != "") {
print $WIFIpass;
}
?>" id="WIFIpass_<?php print $WIFIindex; ?>" name="WIFIpass_<?php print $WIFIindex; ?>" placeholder="" class="form-control input-md" type="password" minlength="8" maxlength="63">
print $WIFIpass;
?>" id="WIFIpass_<?php print $WIFIindex; ?>" name="WIFIpass_<?php print $WIFIindex; ?>" placeholder="" class="form-control input-md" type="password" minlength="8" maxlength="63" <?php print $WIFIactive ? "readonly" : ""; ?>>
<span class="help-block"></span>
</div>
</div>
Expand All @@ -132,12 +132,8 @@
<label class="col-md-4 control-label" for="WIFIprio_<?php print $WIFIindex; ?>"><?php print $lang['globalPriority']; ?></label>
<div class="col-md-6">
<input value="<?php
if(isset($WIFIprio) && $WIFIprio != "") {
print $WIFIprio;
} else {
print 0;
}
?>" id="WIFIprio_<?php print $WIFIindex; ?>" name="WIFIprio_<?php print $WIFIindex; ?>" placeholder="" class="form-control input-md" type="number" min="0" max="100">
print $WIFIprio;
?>" id="WIFIprio_<?php print $WIFIindex; ?>" name="WIFIprio_<?php print $WIFIindex; ?>" placeholder="" class="form-control input-md" type="number" min="0" max="100" <?php print $WIFIactive ? "readonly" : ""; ?>>
<span class="help-block"></span>
</div>
</div>
Expand Down
36 changes: 20 additions & 16 deletions scripts/helperscripts/inc.networkHelper.sh
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ is_NetworkManager_enabled() {
WPA_CONF="/etc/wpa_supplicant/wpa_supplicant.conf"
clear_wireless_networks() {
if [[ $(is_dhcpcd_enabled) == true ]]; then
sudo sed -i '/^network={/,/^}/ d' $WPA_CONF
sudo sed -i -e '/^[[:space:]]*$/d' -e '/^network={/,/^}/d' $WPA_CONF
fi

if [[ $(is_NetworkManager_enabled) == true ]]; then
nmcli -g NAME,TYPE connection show | grep -F "wireless" | cut -d : -f 1 | \
nmcli -g NAME,TYPE,ACTIVE connection show | grep "^.*:.*:no$" | grep -F "wireless" | cut -d : -f 1 | \
while read name; do sudo nmcli connection delete "$name"; done
fi
}
Expand All @@ -49,22 +49,25 @@ add_wireless_network() {
local ssid="$2"
local pass="$3"
local prio="$4"

if [[ "${#pass}" -lt 64 ]]; then
pass=$(wpa_passphrase "$ssid" "$pass" | grep -vF '#psk' | grep -F "psk=" | cut -d = -f 2)
fi

if [[ $(is_dhcpcd_enabled) == true ]]; then
if ! sudo cat "$WPA_CONF" | grep -qF "ssid=\"${ssid}\"" ; then
local wpa_network=$(wpa_passphrase $ssid $pass)
if echo "$wpa_network" | grep -qF 'network='; then
wpa_network=$(echo "$wpa_network" | grep -v -F '#psk' | sed "/^}/i\\\tpriority=${prio}" )
local wpa_network_with_dummy_psk=$(wpa_passphrase "$ssid" "dummypsk")
if echo "$wpa_network_with_dummy_psk" | grep -qF 'network='; then
local wpa_network=$(echo "$wpa_network_with_dummy_psk" | sed -e '/#psk/d' -e "s/psk=.*$/psk=${pass}/" -e "/^}/i\\\tpriority=${prio}" )
sudo bash -c "echo '${wpa_network}' >> $WPA_CONF"
else
echo "Error while adding network config."
fi
fi
fi

if [[ $(is_NetworkManager_enabled) == true ]]; then
if ! nmcli -g NAME,TYPE connection show | grep -F "wireless" | grep -qwF "$ssid"; then
sudo nmcli connection add type wifi con-name "$ssid" ifname "$interface" autoconnect yes mode infrastructure ssid "$ssid"
sudo nmcli connection modify "$ssid" wifi-sec.key-mgmt wpa-psk wifi-sec.psk "$pass" conn.autoconnect-p "$prio"
sudo nmcli connection modify "$ssid" wifi-sec.key-mgmt wpa-psk wifi-sec.psk "$pass" conn.autoconnect-p "$prio"
fi
fi
}
Expand All @@ -74,13 +77,14 @@ get_all_wireless_networks() {
networks=()

if [[ $(is_dhcpcd_enabled) == true ]]; then
local network_profiles=$(wpa_cli -i wlan0 list_network | sed '1d' | cut -f 1)

for n in $network_profiles
local wpa_networks=$(sudo sed '/^network={/,/^}/!d' $WPA_CONF)
local wpa_networks_perline=$(echo "${wpa_networks//$'\n'/\\n}" | sed -e 's/[[:space:]]//g' -e 's/\\nnetwork=/\nnetwork=/g')
for wpa_network in $wpa_networks_perline
do
local ssid=$(wpa_cli -i wlan0 get_network $n ssid | grep -v "FAIL" | tr -d '"')
local pass=$(wpa_cli -i wlan0 get_network $n psk | grep -v "FAIL")
local prio=$(wpa_cli -i wlan0 get_network $n priority | grep -v "FAIL")
local wpa_network_multiline="${wpa_network//\\n/$'\n'}"
local ssid=$(echo "$wpa_network_multiline" | grep -F "ssid=" | cut -d = -f 2 | tr -d '"')
local pass=$(echo "$wpa_network_multiline" | grep -F "psk=" | cut -d = -f 2)
local prio=$(echo "$wpa_network_multiline" | grep -F "priority=" | cut -d = -f 2)

networks+=("$ssid":"$pass":"$prio")
done
Expand All @@ -89,9 +93,9 @@ get_all_wireless_networks() {
if [[ $(is_NetworkManager_enabled) == true ]]; then
local network_profiles=$(nmcli -g NAME,TYPE connection show | grep -F "wireless" | cut -d : -f 1)

for n in $network_profiles
for network_profile in $network_profiles
do
local result=$(nmcli -t -f 802-11-wireless.ssid,802-11-wireless-security.psk,connection.autoconnect-priority con show $n)
local result=$(sudo nmcli --show-secrets -t -f 802-11-wireless.ssid,802-11-wireless-security.psk,connection.autoconnect-priority con show $network_profile)
local ssid=$(echo "$result" | grep -F "802-11-wireless.ssid" | cut -d : -f 2)
local pass=$(echo "$result" | grep -F "802-11-wireless-security.psk" | cut -d : -f 2)
local prio=$(echo "$result" | grep -F "connection.autoconnect-priority" | cut -d : -f 2)
Expand Down

0 comments on commit b96aa34

Please sign in to comment.