From 33f240b616f16e7f853261da4db401be9c889adb Mon Sep 17 00:00:00 2001 From: Alvin Schiller <103769832+AlvinSchiller@users.noreply.github.com> Date: Tue, 19 Mar 2024 10:18:21 +0100 Subject: [PATCH] NetworkManager Support (#2261) * 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 --- .../test_docker_debian_codename_sub.yml | 4 +- ci/Dockerfile.debian | 1 + htdocs/inc.setWifi.php | 183 ++++----- htdocs/userScripts.php | 2 +- ...ot.service.stretch-default2-Hotspot.sample | 9 - .../autohotspot/NetworkManager/autohotspot | 353 ++++++++++++++++++ .../NetworkManager/autohotspot.service | 11 + .../NetworkManager/autohotspot.timer | 10 + .../dhcpcd/autohotspot} | 55 +-- .../dhcpcd/autohotspot-daemon.service | 10 + .../autohotspot/dhcpcd/autohotspot.service | 11 + .../autohotspot/dhcpcd/autohotspot.timer | 10 + .../dhcpcd/dnsmasq.conf} | 2 +- .../dhcpcd/hostapd} | 0 .../dhcpcd/hostapd.conf} | 2 +- ...hcpcd.conf.buster-default-noHotspot.sample | 4 +- ...ault.sample => wpa_supplicant.conf.sample} | 6 - packages-autohotspot_NetworkManager.txt | 4 + ...pot.txt => packages-autohotspot_dhcpcd.txt | 0 scripts/helperscripts/inc.networkHelper.sh | 123 ++++++ scripts/helperscripts/setup_autohotspot.sh | 228 +++++++---- scripts/installscripts/install-jukebox.sh | 98 ++--- ...installation_autohotspot_NetworkManager.sh | 54 +++ .../run_installation_autohotspot_dhcpcd.sh | 54 +++ ...n_tests.sh => run_installation_classic.sh} | 43 ++- .../tests/run_installation_staticip_dhcpcd.sh | 60 +++ .../tests/run_installation_tests2.sh | 40 +- .../tests/run_installation_tests3.sh | 45 ++- .../installscripts/tests/test_installation.sh | 200 +++++++--- scripts/playout_controls.sh | 12 +- scripts/userscripts/addhotspot.sh | 14 - scripts/userscripts/placeholder | 0 32 files changed, 1274 insertions(+), 374 deletions(-) delete mode 100755 misc/sampleconfigs/autohotspot.service.stretch-default2-Hotspot.sample create mode 100644 misc/sampleconfigs/autohotspot/NetworkManager/autohotspot create mode 100644 misc/sampleconfigs/autohotspot/NetworkManager/autohotspot.service create mode 100644 misc/sampleconfigs/autohotspot/NetworkManager/autohotspot.timer rename misc/sampleconfigs/{autohotspot.sh.stretch-default2-Hotspot.sample => autohotspot/dhcpcd/autohotspot} (86%) create mode 100644 misc/sampleconfigs/autohotspot/dhcpcd/autohotspot-daemon.service create mode 100644 misc/sampleconfigs/autohotspot/dhcpcd/autohotspot.service create mode 100644 misc/sampleconfigs/autohotspot/dhcpcd/autohotspot.timer rename misc/sampleconfigs/{dnsmasq.conf.stretch-default2-Hotspot.sample => autohotspot/dhcpcd/dnsmasq.conf} (86%) rename misc/sampleconfigs/{hostapd.stretch-default2-Hotspot.sample => autohotspot/dhcpcd/hostapd} (100%) mode change 100755 => 100644 rename misc/sampleconfigs/{hostapd.conf.stretch-default2-Hotspot.sample => autohotspot/dhcpcd/hostapd.conf} (93%) mode change 100755 => 100644 rename misc/sampleconfigs/{wpa_supplicant.conf.buster-default.sample => wpa_supplicant.conf.sample} (59%) mode change 100755 => 100644 create mode 100644 packages-autohotspot_NetworkManager.txt rename packages-autohotspot.txt => packages-autohotspot_dhcpcd.txt (100%) create mode 100644 scripts/helperscripts/inc.networkHelper.sh create mode 100644 scripts/installscripts/tests/run_installation_autohotspot_NetworkManager.sh create mode 100644 scripts/installscripts/tests/run_installation_autohotspot_dhcpcd.sh rename scripts/installscripts/tests/{run_installation_tests.sh => run_installation_classic.sh} (56%) create mode 100644 scripts/installscripts/tests/run_installation_staticip_dhcpcd.sh delete mode 100644 scripts/userscripts/addhotspot.sh create mode 100644 scripts/userscripts/placeholder diff --git a/.github/workflows/test_docker_debian_codename_sub.yml b/.github/workflows/test_docker_debian_codename_sub.yml index f804784ef..95e94a2ee 100644 --- a/.github/workflows/test_docker_debian_codename_sub.yml +++ b/.github/workflows/test_docker_debian_codename_sub.yml @@ -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: diff --git a/ci/Dockerfile.debian b/ci/Dockerfile.debian index eb545e6b3..15384e782 100644 --- a/ci/Dockerfile.debian +++ b/ci/Dockerfile.debian @@ -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 ./ diff --git a/htdocs/inc.setWifi.php b/htdocs/inc.setWifi.php index a7a77987f..691e8a247 100755 --- a/htdocs/inc.setWifi.php +++ b/htdocs/inc.setWifi.php @@ -1,112 +1,83 @@ $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); + ?> -
'> +'>
@@ -127,16 +98,19 @@