Skip to content

Commit

Permalink
reorder active connection to front.
Browse files Browse the repository at this point in the history
use uuid for iteration.
  • Loading branch information
AlvinSchiller committed Mar 8, 2024
1 parent b96aa34 commit db7acf9
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 18 deletions.
36 changes: 22 additions & 14 deletions htdocs/inc.setWifi.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,25 +42,33 @@
/*
* get all configured wifis
*/
$network_confs_shell = shell_exec("sudo bash -c 'source ".$conf['scripts_abs']."/helperscripts/inc.networkHelper.sh && get_all_wireless_networks'");
$network_confs_shell = shell_exec("sudo bash -c 'source ".$conf['scripts_abs']."/helperscripts/inc.networkHelper.sh && get_wireless_networks'");
$network_confs = explode(' ',$network_confs_shell);

$networks = array();
foreach($network_confs as $line){
unset($temp_ssid);
unset($temp_pass);
unset($temp_prio);
unset($temp_active);

$network_conf = explode(':',$line);
$temp_ssid = trim($network_conf[0]);
$temp_pass = trim($network_conf[1]);
$temp_prio = trim($network_conf[2]);
$temp_active = isset($active_essid) && $temp_ssid == $active_essid;

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);
$temp_entry = array($temp_ssid => [ $temp_pass, $temp_prio, $temp_active ]);
# use different methods to have the same behavior: the data of the first appearance are kept, following will be ignored
if($temp_active) {
$networks = array_merge($temp_entry, $networks);
} else {
$networks = $networks + $temp_entry;
}
}
}
unset($temp_ssid);
Expand Down Expand Up @@ -89,12 +97,12 @@
?>
<ul class="list-group">
<?php
$network_count = count($networks);
foreach ( $networks as $WIFIindex => $WIFIconf ) {
$WIFIssid = $WIFIconf[0];
$WIFIpass = $WIFIconf[1];
$WIFIprio = $WIFIconf[2];
$WIFIactive = isset($active_essid) && $WIFIssid == $active_essid;
$network_index = 0;
foreach ( $networks as $WIFIssid => $WIFIconf ) {
$WIFIpass = $WIFIconf[0];
$WIFIprio = $WIFIconf[1];
$WIFIactive = $WIFIconf[2];
$WIFIindex = $network_index++;
?>
<li class="list-group-item">
<div class="row">
Expand Down Expand Up @@ -146,27 +154,27 @@
<div class="row">
<!-- Text input-->
<div class="form-group">
<label class="col-md-4 control-label" for="WIFIssid_<?php print $network_count; ?>"><?php print $lang['globalSSID']; ?></label>
<label class="col-md-4 control-label" for="WIFIssid_<?php print $network_index; ?>"><?php print $lang['globalSSID']; ?></label>
<div class="col-md-6">
<input value="" id="WIFIssid_<?php print $network_count; ?>" name="WIFIssid_<?php print $network_count; ?>" placeholder="<?php print $lang['settingsWifiSsidPlaceholder']; ?>" class="form-control input-md" type="text">
<input value="" id="WIFIssid_<?php print $network_index; ?>" name="WIFIssid_<?php print $network_index; ?>" placeholder="<?php print $lang['settingsWifiSsidPlaceholder']; ?>" class="form-control input-md" type="text">
<span class="help-block"><?php print $lang['settingsWifiSsidHelp']; ?></span>
</div>
</div>

<!-- Text input-->
<div class="form-group">
<label class="col-md-4 control-label" for="WIFIpass_<?php print $network_count; ?>"><?php print $lang['globalPassword']; ?></label>
<label class="col-md-4 control-label" for="WIFIpass_<?php print $network_index; ?>"><?php print $lang['globalPassword']; ?></label>
<div class="col-md-6">
<input value="" id="WIFIpass_<?php print $network_count; ?>" name="WIFIpass_<?php print $network_count; ?>" placeholder="" class="form-control input-md" type="password" minlength="8" maxlength="63">
<input value="" id="WIFIpass_<?php print $network_index; ?>" name="WIFIpass_<?php print $network_index; ?>" placeholder="" class="form-control input-md" type="password" minlength="8" maxlength="63">
<span class="help-block"><?php print $lang['settingsWifiPassHelp']; ?></span>
</div>
</div>

<!-- Text input-->
<div class="form-group">
<label class="col-md-4 control-label" for="WIFIprio_<?php print $network_count; ?>"><?php print $lang['globalPriority']; ?></label>
<label class="col-md-4 control-label" for="WIFIprio_<?php print $network_index; ?>"><?php print $lang['globalPriority']; ?></label>
<div class="col-md-6">
<input value="0" id="WIFIprio_<?php print $network_count; ?>" name="WIFIprio_<?php print $network_count; ?>" placeholder="" class="form-control input-md" type="number" min="0" max="100">
<input value="0" id="WIFIprio_<?php print $network_index; ?>" name="WIFIprio_<?php print $network_index; ?>" placeholder="" class="form-control input-md" type="number" min="0" max="100">
<span class="help-block"><?php print $lang['settingsWifiPrioHelp']; ?></span>
</div>
</div>
Expand Down
8 changes: 4 additions & 4 deletions scripts/helperscripts/inc.networkHelper.sh
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ clear_wireless_networks() {
fi

if [[ $(is_NetworkManager_enabled) == true ]]; then
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
nmcli -g UUID,TYPE,ACTIVE connection show | grep "^.*:.*:no$" | grep -F "wireless" | cut -d : -f 1 | \
while read uuid; do sudo nmcli connection delete "$uuid"; done
fi
}

Expand Down Expand Up @@ -73,7 +73,7 @@ add_wireless_network() {
}

# gets the configured wireless networks. Returns an array with the format "ssid:pass:prio ssid:pass:prio".
get_all_wireless_networks() {
get_wireless_networks() {
networks=()

if [[ $(is_dhcpcd_enabled) == true ]]; then
Expand All @@ -91,7 +91,7 @@ get_all_wireless_networks() {
fi

if [[ $(is_NetworkManager_enabled) == true ]]; then
local network_profiles=$(nmcli -g NAME,TYPE connection show | grep -F "wireless" | cut -d : -f 1)
local network_profiles=$(nmcli -g UUID,TYPE connection show | grep -F "wireless" | cut -d : -f 1)

for network_profile in $network_profiles
do
Expand Down

0 comments on commit db7acf9

Please sign in to comment.