@ -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"