diff --git a/includes/functions.php b/includes/functions.php index 20944244..20a44d2f 100755 --- a/includes/functions.php +++ b/includes/functions.php @@ -20,6 +20,35 @@ function CSRFValidate() { return hash_equals($_POST['csrf_token'], $_SESSION['csrf_token']); } +/** +* Test whether array is associative +*/ +function isAssoc($arr) { + return array_keys($arr) !== range(0, count($arr) - 1); +} + +/** +* +* Display a selector field for a form. Arguments are: +* $name: Field name +* $options: Array of options +* $selected: Selected option (optional) +* If $options is an associative array this should be the key +* +*/ +function SelectorOptions($name, $options, $selected = null) { + echo ""; +} + /** * * @param string $input diff --git a/includes/hostapd.php b/includes/hostapd.php index 1d7e1408..1eb4aa6b 100755 --- a/includes/hostapd.php +++ b/includes/hostapd.php @@ -1,19 +1,73 @@ /tmp/hostapddata", $return ); + system( "sudo cp /tmp/hostapddata " . RASPI_HOSTAPD_CONFIG, $return ); + + if( $return == 0 ) { + $status->addMessage('Wifi Hotspot settings saved', 'success'); + } else { + $status->addMessage('Wifi Hotspot settings failed to be saved', 'danger'); + } + } else { + error_log('CSRF violation'); + } + } elseif( isset($_POST['StartHotspot']) ) { + if (CSRFValidate()) { + $status->addMessage('Attempting to start hotspot', 'info'); + exec( 'sudo /etc/init.d/hostapd start', $return ); + foreach( $return as $line ) { + $status->addMessage($line, 'info'); + } + } else { + error_log('CSRF violation'); + } + } elseif( isset($_POST['StopHotspot']) ) { + if (CSRFValidate()) { + $status->addMessage('Attempting to stop hotspot', 'info'); + exec( 'sudo /etc/init.d/hostapd stop', $return ); + foreach( $return as $line ) { + $status->addMessage($line, 'info'); + } + } else { + error_log('CSRF violation'); + } + } + exec( 'cat '. RASPI_HOSTAPD_CONFIG, $return ); exec( 'pidof hostapd | wc -l', $hostapdstatus); if( $hostapdstatus[0] == 0 ) { - $status = '