1
0
mirror of https://github.com/billz/raspap-webgui.git synced 2023-10-10 13:37:24 +02:00

Fix /etc/sudoers entries

- symlink to hook wpa_supplicant if multiple wireless adapters. Otherwise, "wpa_cli" cmds fail if you have more than one wlan device
- set cmds array items to double quotes
- added entries for wlan1 interfaces, to be able to control more than one wireless adapter
- updated if statement checking the number of lines in /etc/sudoers
- added IFS in do loop, to handle spaces in array items properly (current method truncates the line if it finds a space)
This commit is contained in:
Joe 2018-02-16 07:31:04 -07:00 committed by GitHub
parent 75f6d53555
commit ba9d6cba59
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -214,40 +214,53 @@ function sudo_add() {
# Adds www-data user to the sudoers file with restrictions on what the user can execute # Adds www-data user to the sudoers file with restrictions on what the user can execute
function patch_system_files() { function patch_system_files() {
# add symlink to prevent wpa_cli cmds from breaking with multiple wlan interfaces
install_log "symlinked wpa_supplicant hooks for multiple wlan interfaces"
sudo ln -s /usr/share/dhcpcd/hooks/10-wpa_supplicant /etc/dhcp/dhclient-enter-hooks.d/
# Set commands array # Set commands array
cmds=( cmds=(
'/sbin/ifdown wlan0' "/sbin/ifdown"
'/sbin/ifup wlan0' "/sbin/ifup"
'/bin/cat /etc/wpa_supplicant/wpa_supplicant.conf' "/bin/cat /etc/wpa_supplicant/wpa_supplicant.conf"
'/bin/cp /tmp/wifidata /etc/wpa_supplicant/wpa_supplicant.conf' "/bin/cat /etc/wpa_supplicant/wpa_supplicant-wlan0.conf"
'/sbin/wpa_cli scan_results' "/bin/cat /etc/wpa_supplicant/wpa_supplicant-wlan1.conf"
'/sbin/wpa_cli scan' "/bin/cp /tmp/wifidata /etc/wpa_supplicant/wpa_supplicant.conf"
'/sbin/wpa_cli reconfigure' "/bin/cp /tmp/wifidata /etc/wpa_supplicant/wpa_supplicant-wlan0.conf"
'/bin/cp /tmp/hostapddata /etc/hostapd/hostapd.conf' "/bin/cp /tmp/wifidata /etc/wpa_supplicant/wpa_supplicant-wlan1.conf"
'/etc/init.d/hostapd start' "/sbin/wpa_cli scan_results"
'/etc/init.d/hostapd stop' "/sbin/wpa_cli scan"
'/etc/init.d/dnsmasq start' "/sbin/wpa_cli reconfigure"
'/etc/init.d/dnsmasq stop' "/bin/cp /tmp/hostapddata /etc/hostapd/hostapd.conf"
'/bin/cp /tmp/dhcpddata /etc/dnsmasq.conf' "/etc/init.d/hostapd start"
'/sbin/shutdown -h now' "/etc/init.d/hostapd stop"
'/sbin/reboot' "/etc/init.d/dnsmasq start"
'/sbin/ip link set wlan0 down' "/etc/init.d/dnsmasq stop"
'/sbin/ip link set wlan0 up' "/bin/cp /tmp/dhcpddata /etc/dnsmasq.conf"
'/sbin/ip -s a f label wlan0' "/sbin/shutdown -h now"
'/bin/cp /etc/raspap/networking/dhcpcd.conf /etc/dhcpcd.conf' "/sbin/reboot"
'/etc/raspap/hostapd/enablelog.sh' "/sbin/ip link set wlan0 down"
'/etc/raspap/hostapd/disablelog.sh' "/sbin/ip link set wlan0 up"
"/sbin/ip -s a f label wlan0"
"/sbin/ip link set wlan1 down"
"/sbin/ip link set wlan1 up"
"/sbin/ip -s a f label wlan1"
"/bin/cp /etc/raspap/networking/dhcpcd.conf /etc/dhcpcd.conf"
"/etc/raspap/hostapd/enablelog.sh"
"/etc/raspap/hostapd/disablelog.sh"
) )
# Check if sudoers needs patchin # Check if sudoers needs patching
if [ $(sudo grep -c www-data /etc/sudoers) -ne 15 ]; then if [ $(sudo grep -c www-data /etc/sudoers) -ne 28 ]
then
# Sudoers file has incorrect number of commands. Wiping them out. # Sudoers file has incorrect number of commands. Wiping them out.
install_log "Cleaning sudoers file" install_log "Cleaning sudoers file"
sudo sed -i '/www-data/d' /etc/sudoers sudo sed -i '/www-data/d' /etc/sudoers
install_log "Patching system sudoers file" install_log "Patching system sudoers file"
# patch /etc/sudoers file # patch /etc/sudoers file
for cmd in "${cmds[@]}"; do for cmd in "${cmds[@]}"
do
sudo_add $cmd sudo_add $cmd
IFS=$'\n'
done done
else else
install_log "Sudoers file already patched" install_log "Sudoers file already patched"