From 58bd439b4dfd8b1177f3d6c0e1d4a697b766ed7d Mon Sep 17 00:00:00 2001 From: Joe Haig Date: Sat, 22 Oct 2016 22:02:39 +0100 Subject: [PATCH] Replace /etc.init.d with service --- README.md | 11 ++++++----- includes/dhcp.php | 4 ++-- includes/functions.php | 8 ++++---- includes/hostapd.php | 4 ++-- installers/common.sh | 10 +++++----- 5 files changed, 19 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index d37dbfb2..e595f0b7 100644 --- a/README.md +++ b/README.md @@ -40,11 +40,12 @@ The installer will complete the steps in the manual installation (below) for you Start off by installing lighttpd, php5 and hostapd. ```sh $ sudo apt-get install lighttpd php5-cgi hostapd +$ sudo apt-get install rfkill zd1211-firmware hostap-utils iw dnsmasq ``` After that, enable PHP for lighttpd and restart it for the settings to take effect. ```sh sudo lighty-enable-mod fastcgi-php -sudo /etc/init.d/lighttpd restart +sudo service lighttpd restart ``` Now comes the fun part. For security reasons, the `www-data` user which lighttpd runs under is not allowed to start or stop daemons, or run commands like ifdown and ifup, all of which we want our page to do. So what I have done is added the `www-data` user to the sudoers file, but with restrictions on what commands the user can run. @@ -59,10 +60,10 @@ www-data ALL=(ALL) NOPASSWD:/sbin/wpa_cli scan_results www-data ALL=(ALL) NOPASSWD:/sbin/wpa_cli scan www-data ALL=(ALL) NOPASSWD:/sbin/wpa_cli reconfigure www-data ALL=(ALL) NOPASSWD:/bin/cp /tmp/hostapddata /etc/hostapd/hostapd.conf -www-data ALL=(ALL) NOPASSWD:/etc/init.d/hostapd start -www-data ALL=(ALL) NOPASSWD:/etc/init.d/hostapd stop -www-data ALL=(ALL) NOPASSWD:/etc/init.d/dnsmasq start -www-data ALL=(ALL) NOPASSWD:/etc/init.d/dnsmasq stop +www-data ALL=(ALL) NOPASSWD:service hostapd start +www-data ALL=(ALL) NOPASSWD:service hostapd stop +www-data ALL=(ALL) NOPASSWD:service dnsmasq start +www-data ALL=(ALL) NOPASSWD:service dnsmasq stop www-data ALL=(ALL) NOPASSWD:/bin/cp /tmp/dhcpddata /etc/dnsmasq.conf www-data ALL=(ALL) NOPASSWD:/sbin/shutdown -h now www-data ALL=(ALL) NOPASSWD:/sbin/reboot diff --git a/includes/dhcp.php b/includes/dhcp.php index d173547a..2de9ab8f 100755 --- a/includes/dhcp.php +++ b/includes/dhcp.php @@ -35,7 +35,7 @@ function DisplayDHCPConfig() { if ($dnsmasq_state) { $status->addMessage('dnsmasq already running', 'info'); } else { - exec('sudo /etc/init.d/dnsmasq start', $dnsmasq, $return); + exec('sudo service dnsmasq start', $dnsmasq, $return); if ($return == 0) { $status->addMessage('Successfully started dnsmasq', 'success'); $dnsmasq_state = true; @@ -49,7 +49,7 @@ function DisplayDHCPConfig() { } elseif( isset($_POST['stopdhcpd'] ) ) { if (CSRFValidate()) { if ($dnsmasq_state) { - exec('sudo /etc/init.d/dnsmasq stop', $dnsmasq, $return); + exec('sudo service dnsmasq stop', $dnsmasq, $return); if ($return == 0) { $status->addMessage('Successfully stopped dnsmasq', 'success'); $dnsmasq_state = false; diff --git a/includes/functions.php b/includes/functions.php index f391e461..d5cb0b35 100755 --- a/includes/functions.php +++ b/includes/functions.php @@ -412,25 +412,25 @@ function SaveTORAndVPNConfig(){ // TODO } elseif( isset($_POST['StartOpenVPN']) ) { echo "Attempting to start openvpn"; - exec( 'sudo /etc/init.d/openvpn start', $return ); + exec( 'sudo service openvpn start', $return ); foreach( $return as $line ) { echo $line."
"; } } elseif( isset($_POST['StopOpenVPN']) ) { echo "Attempting to stop openvpn"; - exec( 'sudo /etc/init.d/openvpn stop', $return ); + exec( 'sudo service openvpn stop', $return ); foreach( $return as $line ) { echo $line."
"; } } elseif( isset($_POST['StartTOR']) ) { echo "Attempting to start TOR"; - exec( 'sudo /etc/init.d/tor start', $return ); + exec( 'sudo service tor start', $return ); foreach( $return as $line ) { echo $line."
"; } } elseif( isset($_POST['StopTOR']) ) { echo "Attempting to stop TOR"; - exec( 'sudo /etc/init.d/tor stop', $return ); + exec( 'sudo service tor stop', $return ); foreach( $return as $line ) { echo $line."
"; } diff --git a/includes/hostapd.php b/includes/hostapd.php index bd9e3c4b..0b9c65ea 100755 --- a/includes/hostapd.php +++ b/includes/hostapd.php @@ -26,7 +26,7 @@ function DisplayHostAPDConfig(){ } elseif( isset($_POST['StartHotspot']) ) { if (CSRFValidate()) { $status->addMessage('Attempting to start hotspot', 'info'); - exec( 'sudo /etc/init.d/hostapd start', $return ); + exec( 'sudo service hostapd start', $return ); foreach( $return as $line ) { $status->addMessage($line, 'info'); } @@ -36,7 +36,7 @@ function DisplayHostAPDConfig(){ } elseif( isset($_POST['StopHotspot']) ) { if (CSRFValidate()) { $status->addMessage('Attempting to stop hotspot', 'info'); - exec( 'sudo /etc/init.d/hostapd stop', $return ); + exec( 'sudo service hostapd stop', $return ); foreach( $return as $line ) { $status->addMessage($line, 'info'); } diff --git a/installers/common.sh b/installers/common.sh index a7dad944..53b4a917 100644 --- a/installers/common.sh +++ b/installers/common.sh @@ -58,7 +58,7 @@ function enable_php_lighttpd() { install_log "Enabling PHP for lighttpd" sudo lighty-enable-mod fastcgi-php || install_error "Cannot enable fastcgi-php for lighttpd" - sudo /etc/init.d/lighttpd restart || install_error "Unable to restart lighttpd" + sudo service lighttpd restart || install_error "Unable to restart lighttpd" } # Verifies existence and permissions of RaspAP directory @@ -121,10 +121,10 @@ function patch_system_files() { sudo_add '/sbin/wpa_cli scan' sudo_add '/sbin/wpa_cli reconfigure' sudo_add '/bin/cp /tmp/hostapddata /etc/hostapd/hostapd.conf' - sudo_add '/etc/init.d/hostapd start' - sudo_add '/etc/init.d/hostapd stop' - sudo_add '/etc/init.d/dnsmasq start' - sudo_add '/etc/init.d/dnsmasq stop' + sudo_add 'service hostapd start' + sudo_add 'service hostapd stop' + sudo_add 'service dnsmasq start' + sudo_add 'service dnsmasq stop' sudo_add '/bin/cp /tmp/dhcpddata /etc/dnsmasq.conf' sudo_add '/sbin/shutdown -h now' sudo_add '/sbin/reboot'