Skip to content

Commit

Permalink
NetworkManager Support (#2261)
Browse files Browse the repository at this point in the history
* moved config files in subdir

* renamed autohotspot resources.

* updates from v3.
change crontab to timer service

* refactored config file handling to functions.
Added interfaces conf file handling.

* add service enablement check

* update tests

* add uninstall before installation on updates

* fix tests

* add support for NetworkManager

* fix tests

* add tests for network management

* fix mpd test if not installed

* start service instead of script.

* remove wpa_cli references (not needed).

* updated installation wifi setup

* updated wifi ui

* changed order of logic to always get the current file state

* simplify ui wifi logic

* set active connection readonly

* reorder active connection to front.
use uuid for iteration.

* remove unneccary comment

* test added. some changes needed

* fixed ci var definition

* changed test order

* updated logs for network settings

* extracted get passphrase function. use also in tests

* restored dhcpcd wpa conf setup. fixed tests

* fix autohotspot setup

* update ci tests scripts. renamed

* improve readability and update tests parameter

* removed log output

* change default for wifi/staticip setup to "no"

* removed hotstpot userscript.

* only show *.sh files as userscripts
  • Loading branch information
AlvinSchiller authored Mar 19, 2024
1 parent 61fc395 commit 33f240b
Show file tree
Hide file tree
Showing 32 changed files with 1,274 additions and 374 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/test_docker_debian_codename_sub.yml
Original file line number Diff line number Diff line change
Expand Up @@ -144,10 +144,10 @@ jobs:
fail-fast: false
matrix:
username: ['pi']
test_script: ['run_installation_tests.sh', 'run_installation_tests2.sh', 'run_installation_tests3.sh']
test_script: ['run_installation_classic.sh', 'run_installation_tests2.sh', 'run_installation_tests3.sh', 'run_installation_staticip_dhcpcd.sh', 'run_installation_autohotspot_dhcpcd.sh', 'run_installation_autohotspot_NetworkManager.sh']
include:
- username: 'hans'
test_script: 'run_installation_tests.sh'
test_script: 'run_installation_classic.sh'


steps:
Expand Down
1 change: 1 addition & 0 deletions ci/Dockerfile.debian
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ FROM test-user as test-code
ARG GIT_BRANCH
ARG GIT_URL

ENV CI_RUNNING=true
ENV GIT_BRANCH=$GIT_BRANCH GIT_URL=$GIT_URL

COPY --chown=root:$TEST_USER_GROUP --chmod=770 packages.txt packages-raspberrypi.txt ./
Expand Down
183 changes: 74 additions & 109 deletions htdocs/inc.setWifi.php
Original file line number Diff line number Diff line change
@@ -1,112 +1,83 @@
<?php
/*
* read ssid and password from /etc/wpa_supplicant/wpa_supplicant.conf
*/
$wpaconf = file_get_contents("/etc/wpa_supplicant/wpa_supplicant.conf");
/*
* get the lines we need
*/
$networks = array();
$priorities = array();
unset($temp_ssid);
unset($temp_pass);
unset($temp_prio);
foreach(preg_split("/((\r?\n)|(\r\n?))/", $wpaconf) as $line){
unset($temp);

$line = trim($line);
if(substr($line, 0, 7) == "network") {
unset($temp_ssid);
unset($temp_pass);
unset($temp_prio);
continue;
}

$temp = explode("=", $line);

if(count($temp) != 2) {
continue;
}

$key = trim($temp[0]);
$value = trim(trim($temp[1]), '"');

if($key == "ssid") {
$temp_ssid = $value;
} else if($key == "psk") {
$temp_pass = $value;
} else if($key == "priority") {
$temp_prio = $value;
}

if(isset($temp_ssid)) {
if(isset($temp_pass)) {
$networks[$temp_ssid] = $temp_pass;
}
if(isset($temp_prio)) {
$priorities[$temp_ssid] = $temp_prio;
}
}
}
unset($temp_ssid);
unset($temp_pass);
unset($temp_prio);



unset($exec);
$exec="iwconfig wlan0 | grep ESSID | cut -d ':' -f 2";
$active_essid = trim(exec($exec),'"');

$active_essid = trim(exec("iwconfig wlan0 | grep ESSID | cut -d ':' -f 2"),'"');
/*
* Now we need to check if we need to create a new wpa_supplicant.conf
* Reconfigure all entries from UI
*/
unset($exec);
if(isset($_POST["submitWifi"]) && $_POST["submitWifi"] == "submit") {
$networks=array(); //clear
$priorities=array(); //clear
// make multiline bash
$exec = "bash -e <<'END'\n";
$exec .= "source ".$conf['scripts_abs']."/helperscripts/inc.networkHelper.sh\n";
$exec .= "clear_wireless_networks\n";

foreach ( $_POST as $post_key => $post_value ) {
$tempPOST = $_POST;
$_POST=array(); //clear
foreach ( $tempPOST as $post_key => $post_value ) {
unset($temp_ssid);
unset($temp_pass);
unset($temp_prio);
if ( substr(trim($post_key), 0, 9) == "WIFIssid_" ) {
$WIFIssid = trim($post_value);
$temp_ssid = trim($post_value);
$post_key = "WIFIpass_".substr(trim($post_key), 9);
$post_value = $_POST[$post_key];
$WIFIpass = trim($post_value);
$post_value = $tempPOST[$post_key];
$temp_pass = trim($post_value);
$post_key = "WIFIprio_".substr(trim($post_key), 9);
$post_value = $_POST[$post_key];
$WIFIprio = trim($post_value);
$post_value = $tempPOST[$post_key];
$temp_prio = trim($post_value);

if ( isset($WIFIssid) && $WIFIssid != "") {
if(isset($WIFIpass) && strlen($WIFIpass) >= 8) {
$networks[$WIFIssid] = $WIFIpass;
}
if(isset($WIFIprio) && $WIFIprio != "") {
$priorities[$WIFIssid] = $WIFIprio;
if (isset($temp_ssid) && $temp_ssid != "" && isset($temp_pass) && strlen($temp_pass) >= 8) {
if(!isset($temp_prio) || !is_numeric($temp_prio)) {
$temp_prio = 0;
}
$exec .= "add_wireless_network wlan0 ".$temp_ssid." ".$temp_pass." ".$temp_prio."\n";
}
}
}
$_POST=array(); //clear

// make multiline bash
$exec = "bash -e <<'END'\n";
$exec .= "echo 'ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev\nupdate_config=1\ncountry=DE\n\n' | sudo tee /etc/wpa_supplicant/wpa_supplicant.conf\n";
foreach ( $networks as $WIFIssid => $WIFIpass ) {
$WIFIprio = $priorities[$WIFIssid];
if (strlen($WIFIpass) < 64) {
$WIFIpass = trim(exec("wpa_passphrase '".$WIFIssid."' '".$WIFIpass."' | grep -v -F '#psk' | grep -F 'psk' | cut -d= -f2"));
$exec .= "END\n";
exec("sudo bash -c '". $exec . "'");
}

/*
* get all configured wifis
*/
$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;
}
$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;
}
$exec .= "echo 'network={\n\tssid=\"".$WIFIssid."\"\n\tpsk=".$WIFIpass."\n\tpriority=".$WIFIprio."\n}' | sudo tee -a /etc/wpa_supplicant/wpa_supplicant.conf\n";
}

$exec .= "sudo chown root:netdev /etc/wpa_supplicant/wpa_supplicant.conf\n";
$exec .= "sudo chmod 664 /etc/wpa_supplicant/wpa_supplicant.conf\n";
$exec .= "END\n";
exec($exec);
}
unset($temp_ssid);
unset($temp_pass);
unset($temp_prio);

?>

<form name='volume' method='post' action='<?php print $_SERVER['PHP_SELF']; ?>'>
<form name='wifi' method='post' action='<?php print $_SERVER['PHP_SELF']; ?>'>
<fieldset>
<!-- Form Name -->
<legend><?php print $lang['globalWifiNetwork']; ?></legend>
Expand All @@ -127,62 +98,56 @@
<ul class="list-group">
<?php
$network_index = 0;
foreach ( $networks as $WIFIssid => $WIFIpass ) {
$WIFIprio = $priorities[$WIFIssid];
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">

<!-- Text input-->
<div class="form-group">
<label class="col-md-4 control-label" for="WIFIssid_<?php print $network_index; ?>"><?php
if(isset($WIFIssid) && isset($active_essid) && $WIFIssid == $active_essid) {
<label class="col-md-4 control-label" for="WIFIssid_<?php print $WIFIindex; ?>"><?php
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 $network_index; ?>" name="WIFIssid_<?php print $network_index; ?>" 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>

<!-- Text input-->
<div class="form-group">
<label class="col-md-4 control-label" for="WIFIpass_<?php print $network_index; ?>"><?php print $lang['globalPassword']; ?></label>
<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 $network_index; ?>" name="WIFIpass_<?php print $network_index; ?>" 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>

<!-- Text input-->
<div class="form-group">
<label class="col-md-4 control-label" for="WIFIprio_<?php print $network_index; ?>"><?php print $lang['globalPriority']; ?></label>
<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 $network_index; ?>" name="WIFIprio_<?php print $network_index; ?>" 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>
</div>
</li>
<?php
$network_index++;
}
?>
<li class="list-group-item">
Expand Down
2 changes: 1 addition & 1 deletion htdocs/userScripts.php
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@
<option value="false"><?php print $lang['cardFormYTSelectDefault']; ?></option>
<?php
// read the subfolders of $Audio_Folders_Path
$audiofolders = array_filter(glob($conf['scripts_abs'].'/userscripts/*'), 'is_file');
$audiofolders = array_filter(glob($conf['scripts_abs'].'/userscripts/*.sh'), 'is_file');
usort($audiofolders, 'strcasecmp');


Expand Down

This file was deleted.

Loading

0 comments on commit 33f240b

Please sign in to comment.