-
-
Client settings
-
-
-
- 2 ) {
- exec( 'wpa_passphrase '.$ssid. ' ' . $psk,$network );
- foreach($network as $b) {
- $config .= "$b
-";
- }
- }
- }
- exec( "echo '$config' > /tmp/wifidata", $return );
- system( 'sudo cp /tmp/wifidata ' . RASPI_WPA_SUPPLICANT_CONFIG, $returnval );
- if( $returnval == 0 ) {
- echo '
Wifi settings updated successfully
- ×
';
- } else {
- echo '
Wifi settings failed to be updated
- ×
';
- }
-
- // scan networks
- } elseif( isset($_POST['Scan']) ) {
- $return = '';
- exec( 'sudo wpa_cli scan',$return );
- sleep(3);
- exec( 'sudo wpa_cli scan_results',$return );
- for( $shift = 0; $shift < 4; $shift++ ) {
- array_shift($return);
- }
- // display output
- echo '
';
- } else {
- $status = '
HostAPD is running
- ×
';
- }
-
- $arrConfig = array();
- $arrChannel = array('a','b','g');
- $arrSecurity = array( 1 => 'WPA', 2 => 'WPA2',3=> 'WPA+WPA2');
- $arrEncType = array('TKIP' => 'TKIP', 'CCMP' => 'CCMP', 'TKIP CCMP' => 'TKIP+CCMP');
-
- foreach( $return as $a ) {
- if( $a[0] != "#" ) {
- $arrLine = explode( "=",$a) ;
- $arrConfig[$arrLine[0]]=$arrLine[1];
- }
- };
- ?>
-
-
-
-
Configure hotspot
-
-
-
-
-
-
-
-
-
-
-
-
Basic settings
-
-
-
- Interface
-
- '.$int.'';
- }
- ?>
-
-
-
-
-
-
- Wireless Mode
-
- '.$Mode.'';
- }
- ?>
-
-
-
-
-
- Channel
- '
- '.$channel.'';
- }
- ?>
-
-
-
-
-
-
Security settings
-
-
- Security type
-
- $SecMode ) {
- $select = '';
- if( $SecVal == $arrConfig['wpa'] ) {
- $select = ' selected';
- }
- echo ''.$SecMode.' ';
- }
- ?>
-
-
-
-
-
- Encryption Type
-
- $Enc ) {
- $select = '';
- if( $Enc == $arrConfig['wpa_pairwise'] ) {
- $select = ' selected';
- }
- echo ''.$Enc.' ';
- } ?>
-
-
-
-
-
-
-
-
- ';
- } else {
- echo '
';
- };
- ?>
-
-
-
-
-
-
-Dnsmasq is not running
× ';
- } else {
- $status = '
Dnsmasq is running×
';
- }
- ?>
-
-
-
-
Configure DHCP
-
-
-
-
-
-
-
-
-
-
DHCP server settings
-
-
-
- Interface
-
- '.$int.'';
- }
- ?>
-
-
-
-
-
- Starting IP Address
-
-
-
-
-
-
- Ending IP Address
-
-
-
-
-
-
- Lease Time
-
-
-
- Interval
- >Minutes >Hours >Days Infinite
-
-
-
-
- ';
- } else {
- echo ' ';
- }
- ?>
-
-
-
-
-
Client list
-
-
-
- Active DHCP leases
-
-
-
-
-
-
-
- Expire time
- MAC Address
- IP Address
- Host name
- Client ID
-
-
-
-
- ' . $lease_item . '';
- }
- echo ' ';
- };
- ?>
-
-
-
-
-
-
-
'
- /tmp/dhcpddata',$temp );
- system( 'sudo cp /tmp/dhcpddata '. RASPI_DNSMASQ_CONFIG, $return );
-
- if( $return == 0 ) {
- echo "Dnsmasq configuration updated successfully";
- } else {
- echo "Dnsmasq configuration failed to be updated";
- }
- }
-
- if( isset( $_POST['startdhcpd'] ) ) {
- $line = system('sudo /etc/init.d/dnsmasq start',$return);
- echo "Attempting to start dnsmasq";
- }
-
- if( isset($_POST['stopdhcpd'] ) ) {
- $line = system('sudo /etc/init.d/dnsmasq stop',$return);
- echo "Stopping dnsmasq";
- }
- ?>
-
-
-
-
-
-
-
-', $options);
+ }
}
/**
@@ -989,170 +405,35 @@ function DisplayTorProxyConfig(){
*
*
*/
-function DisplaySystem(){
-
- // hostname
- exec("hostname -f", $hostarray);
- $hostname = $hostarray[0];
-
- // uptime
- $uparray = explode(" ", exec("cat /proc/uptime"));
- $seconds = round($uparray[0], 0);
- $minutes = $seconds / 60;
- $hours = $minutes / 60;
- $days = floor($hours / 24);
- $hours = floor($hours - ($days * 24));
- $minutes = floor($minutes - ($days * 24 * 60) - ($hours * 60));
- $uptime= '';
- if ($days != 0) { $uptime .= $days . ' day' . (($days > 1)? 's ':' '); }
- if ($hours != 0) { $uptime .= $hours . ' hour' . (($hours > 1)? 's ':' '); }
- if ($minutes != 0) { $uptime .= $minutes . ' minute' . (($minutes > 1)? 's ':' '); }
-
- // mem used
- exec("free -m | awk '/Mem:/ { total=$2 } /buffers\/cache/ { used=$3 } END { print used/total*100}'", $memarray);
- $memused = floor($memarray[0]);
- if ($memused > 90) { $memused_status = "danger"; }
- elseif ($memused > 75) { $memused_status = "warning"; }
- elseif ($memused > 0) { $memused_status = "success"; }
-
- // cpu load
- $cores = exec("grep -c ^processor /proc/cpuinfo");
- $loadavg = exec("awk '{print $1}' /proc/loadavg");
- $cpuload = floor(($loadavg * 100) / $cores);
- if ($cpuload > 90) { $cpuload_status = "danger"; }
- elseif ($cpuload > 75) { $cpuload_status = "warning"; }
- elseif ($cpuload > 0) { $cpuload_status = "success"; }
-
- ?>
-
-
-
-
System
-
-
- System Rebooting Now!
';
- $result = shell_exec("sudo /sbin/reboot");
- }
- if (isset($_POST['system_shutdown'])) {
- echo '
System Shutting Down Now!
';
- $result = shell_exec("sudo /sbin/shutdown -h now");
- }
- ?>
-
-
-
-
-
-
System Information
-
Hostname
-
Uptime
-
Memory Used
-
-
CPU Load
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- /tmp/hostapddata", $return );
- system( "sudo cp /tmp/hostapddata " . RASPI_HOSTAPD_CONFIG, $return );
-
- if( $return == 0 ) {
- echo "Wifi Hotspot settings saved";
- } else {
- echo "Wifi Hotspot settings failed to be saved";
- }
- } elseif( isset($_POST['SaveOpenVPNSettings']) ) {
- // TODO
- } elseif( isset($_POST['SaveTORProxySettings']) ) {
- // TODO
- } elseif( isset($_POST['StartHotspot']) ) {
- echo "Attempting to start hotspot";
- exec( 'sudo /etc/init.d/hostapd start', $return );
- foreach( $return as $line ) {
- echo $line."
";
- }
- } elseif( isset($_POST['StopHotspot']) ) {
- echo "Attempting to stop hotspot";
- exec( 'sudo /etc/init.d/hostapd stop', $return );
- foreach( $return as $line ) {
- echo $line."
";
- }
- } elseif( isset($_POST['StartOpenVPN']) ) {
- echo "Attempting to start openvpn";
- exec( 'sudo /etc/init.d/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 );
- foreach( $return as $line ) {
- echo $line."
";
- }
- } elseif( isset($_POST['StartTOR']) ) {
- echo "Attempting to start TOR";
- exec( 'sudo /etc/init.d/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 );
- foreach( $return as $line ) {
- echo $line."
";
- }
- }
+function SaveTORAndVPNConfig(){
+ if( isset($_POST['SaveOpenVPNSettings']) ) {
+ // TODO
+ } elseif( isset($_POST['SaveTORProxySettings']) ) {
+ // TODO
+ } elseif( isset($_POST['StartOpenVPN']) ) {
+ echo "Attempting to start openvpn";
+ exec( 'sudo /etc/init.d/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 );
+ foreach( $return as $line ) {
+ echo $line."
";
+ }
+ } elseif( isset($_POST['StartTOR']) ) {
+ echo "Attempting to start TOR";
+ exec( 'sudo /etc/init.d/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 );
+ foreach( $return as $line ) {
+ echo $line."
";
+ }
+ }
}
?>
-
diff --git a/includes/hostapd.php b/includes/hostapd.php
new file mode 100755
index 00000000..9d35785b
--- /dev/null
+++ b/includes/hostapd.php
@@ -0,0 +1,227 @@
+ 'WPA', 2 => 'WPA2',3=> 'WPA+WPA2');
+ $arrEncType = array('TKIP' => 'TKIP', 'CCMP' => 'CCMP', 'TKIP CCMP' => 'TKIP+CCMP');
+ exec("ip -o link show | awk -F': ' '{print $2}'", $interfaces);
+
+
+ if( isset($_POST['SaveHostAPDSettings']) ) {
+ if (CSRFValidate()) {
+ SaveHostAPDConfig($arrSecurity, $arrEncType, $arrChannel, $interfaces, $status);
+ } 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->addMessage('HostAPD is not running', 'warning');
+ } else {
+ $status->addMessage('HostAPD is running', 'success');
+ }
+
+ foreach( $return as $a ) {
+ if( $a[0] != "#" ) {
+ $arrLine = explode( "=",$a) ;
+ $arrConfig[$arrLine[0]]=$arrLine[1];
+ }
+ };
+ ?>
+
+
+
+
Configure hotspot
+
+
+
+
+
+
+
+
+
showMessages(); ?>
+
+
+
Basic settings
+
+
+
+
+
+
+
+
Security settings
+
+
+
+ Encryption Type
+
+
+
+
+
+
+
+
+ ';
+ } else {
+ echo '
';
+ };
+ ?>
+
+
+
+
+
+ 14) {
+ error_log("Attempting to set channel to '".$_POST['channel']."'");
+ return false;
+ }
+
+ $good_input = true;
+
+ // Verify input
+ if (strlen($_POST['ssid']) == 0 || strlen($_POST['ssid']) > 32) {
+ // Not sure of all the restrictions of SSID
+ $status->addMessage('SSID must be between 1 and 32 characters', 'danger');
+ $good_input = false;
+ }
+ if (strlen($_POST['wpa_passphrase']) < 8 || strlen($_POST['wpa_passphrase']) > 63) {
+ $status->addMessage('WPA passphrase must be between 8 and 63 characters', 'danger');
+ $good_input = false;
+ }
+ if (! in_array($_POST['interface'], $interfaces)) {
+ // The user is probably up to something here but it may also be a
+ // genuine error.
+ $status->addMessage('Unknown interface '.$_POST['interface'], 'danger');
+ $good_input = false;
+ }
+ if (strlen($_POST['country_code']) != 0 && strlen($_POST['country_code']) != 2) {
+ $status->addMessage('Country code must be blank or two characters', 'danger');
+ $good_input = false;
+ }
+
+ if ($good_input) {
+ if ($tmp_file = fopen('/tmp/hostapddata', 'w')) {
+ // Fixed values
+ fwrite($tmp_file, 'driver=nl80211'.PHP_EOL);
+ fwrite($tmp_file, 'ctrl_interface='.RASPI_HOSTAPD_CTRL_INTERFACE.PHP_EOL);
+ fwrite($tmp_file, 'ctrl_interface_group=0'.PHP_EOL);
+ fwrite($tmp_file, 'beacon_int=100'.PHP_EOL);
+ fwrite($tmp_file, 'auth_algs=1'.PHP_EOL);
+ fwrite($tmp_file, 'wpa_key_mgmt=WPA-PSK'.PHP_EOL);
+
+ fwrite($tmp_file, 'ssid='.$_POST['ssid'].PHP_EOL);
+ fwrite($tmp_file, 'channel='.$_POST['channel'].PHP_EOL);
+ fwrite($tmp_file, 'hw_mode='.$_POST['hw_mode'].PHP_EOL);
+ fwrite($tmp_file, 'wpa_passphrase='.$_POST['wpa_passphrase'].PHP_EOL);
+ fwrite($tmp_file, 'interface='.$_POST['interface'].PHP_EOL);
+ fwrite($tmp_file, 'wpa='.$_POST['wpa'].PHP_EOL);
+ fwrite($tmp_file, 'wpa_pairwise='.$_POST['wpa_pairwise'].PHP_EOL);
+ fwrite($tmp_file, 'country_code='.$_POST['country_code'].PHP_EOL);
+ fclose($tmp_file);
+
+ system( "sudo cp /tmp/hostapddata " . RASPI_HOSTAPD_CONFIG, $return );
+ if( $return == 0 ) {
+ $status->addMessage('Wifi Hotspot settings saved', 'success');
+ } else {
+ $status->addMessage('Unable to save wifi hotspot settings', 'danger');
+ }
+ } else {
+ $status->addMessage('Unable to save wifi hotspot settings', 'danger');
+ return false;
+ }
+ }
+ return true;
+}
+?>
diff --git a/includes/status_messages.php b/includes/status_messages.php
new file mode 100644
index 00000000..aa87df33
--- /dev/null
+++ b/includes/status_messages.php
@@ -0,0 +1,22 @@
+'.$message;
+ if ($dismissable) $status .= '
x ';
+ $status .= '
';
+
+ array_push($this->messages, $status);
+ }
+
+ public function showMessages($clear = true) {
+ foreach($this->messages as $message) {
+ echo $message;
+ }
+ if ( $clear ) $this->messages = array();
+ }
+}
+?>
diff --git a/includes/system.php b/includes/system.php
new file mode 100755
index 00000000..005110be
--- /dev/null
+++ b/includes/system.php
@@ -0,0 +1,139 @@
+ 'Model B Revision 1.0',
+ '0003' => 'Model B Revision 1.0 + ECN0001',
+ '0004' => 'Model B Revision 2.0 (256 MB)',
+ '0005' => 'Model B Revision 2.0 (256 MB)',
+ '0006' => 'Model B Revision 2.0 (256 MB)',
+ '0007' => 'Model A',
+ '0008' => 'Model A',
+ '0009' => 'Model A',
+ '000d' => 'Model B Revision 2.0 (512 MB)',
+ '000e' => 'Model B Revision 2.0 (512 MB)',
+ '000f' => 'Model B Revision 2.0 (512 MB)',
+ '0010' => 'Model B+',
+ '0013' => 'Model B+',
+ '0011' => 'Compute Module',
+ '0012' => 'Model A+',
+ 'a01041' => 'a01041',
+ 'a21041' => 'a21041',
+ '900092' => 'PiZero',
+ 'a02082' => 'Pi 3 Model B',
+ 'a22082' => 'Pi 3 Model B'
+ );
+ exec('cat /proc/cpuinfo', $cpuinfo_array);
+ $rev = trim(array_pop(explode(':',array_pop(preg_grep("/^Revision/", $cpuinfo_array)))));
+ if (array_key_exists($rev, $revisions)) {
+ return $revisions[$rev];
+ } else {
+ return 'Unknown Pi';
+ }
+}
+
+/**
+*
+*
+*/
+function DisplaySystem(){
+
+ // hostname
+ exec("hostname -f", $hostarray);
+ $hostname = $hostarray[0];
+
+ // uptime
+ $uparray = explode(" ", exec("cat /proc/uptime"));
+ $seconds = round($uparray[0], 0);
+ $minutes = $seconds / 60;
+ $hours = $minutes / 60;
+ $days = floor($hours / 24);
+ $hours = floor($hours - ($days * 24));
+ $minutes = floor($minutes - ($days * 24 * 60) - ($hours * 60));
+ $uptime= '';
+ if ($days != 0) { $uptime .= $days . ' day' . (($days > 1)? 's ':' '); }
+ if ($hours != 0) { $uptime .= $hours . ' hour' . (($hours > 1)? 's ':' '); }
+ if ($minutes != 0) { $uptime .= $minutes . ' minute' . (($minutes > 1)? 's ':' '); }
+
+ // mem used
+ exec("free -m | awk '/Mem:/ { total=$2 } /buffers\/cache/ { used=$3 } END { print used/total*100}'", $memarray);
+ $memused = floor($memarray[0]);
+ if ($memused > 90) { $memused_status = "danger"; }
+ elseif ($memused > 75) { $memused_status = "warning"; }
+ elseif ($memused > 0) { $memused_status = "success"; }
+
+ // cpu load
+ $cores = exec("grep -c ^processor /proc/cpuinfo");
+ $loadavg = exec("awk '{print $1}' /proc/loadavg");
+ $cpuload = floor(($loadavg * 100) / $cores);
+ if ($cpuload > 90) { $cpuload_status = "danger"; }
+ elseif ($cpuload > 75) { $cpuload_status = "warning"; }
+ elseif ($cpuload > 0) { $cpuload_status = "success"; }
+
+ ?>
+
+
+
+
System
+
+
+ System Rebooting Now!
';
+ $result = shell_exec("sudo /sbin/reboot");
+ }
+ if (isset($_POST['system_shutdown'])) {
+ echo '
System Shutting Down Now!
';
+ $result = shell_exec("sudo /sbin/shutdown -h now");
+ }
+ ?>
+
+
+
+
+
+
System Information
+
Hostname
+
Pi Revision
+
Uptime
+
Memory Used
+
+
CPU Load
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/index.php b/index.php
index bf204237..3eeb5289 100755
--- a/index.php
+++ b/index.php
@@ -38,18 +38,33 @@ define('RASPI_OPENVPN_ENABLED', false );
define('RASPI_TORPROXY_ENABLED', false );
include_once( RASPI_CONFIG.'/raspap.php' );
+include_once( 'includes/functions.php' );
+include_once( 'includes/dashboard.php' );
include_once( 'includes/authenticate.php' );
include_once( 'includes/admin.php' );
-include_once( 'includes/functions.php' );
+include_once( 'includes/dhcp.php' );
+include_once( 'includes/hostapd.php' );
+include_once( 'includes/system.php' );
+include_once( 'includes/configure_client.php' );
$output = $return = 0;
$page = $_GET['page'];
+
+session_start();
+if (empty($_SESSION['csrf_token'])) {
+ if (function_exists('mcrypt_create_iv')) {
+ $_SESSION['csrf_token'] = bin2hex(mcrypt_create_iv(32, MCRYPT_DEV_URANDOM));
+ } else {
+ $_SESSION['csrf_token'] = bin2hex(openssl_random_pseudo_bytes(32));
+ }
+}
+$csrf_token = $_SESSION['csrf_token'];
?>
-
-
+
+
@@ -85,106 +100,106 @@ $page = $_GET['page'];
-
-
+
+
-
-
-
-
-
+
+
+
+
+
-
-
-
-
-
+
+
+
-
-
+
-
-
+
+
+
+
+
@@ -206,5 +221,5 @@ $page = $_GET['page'];
-
+
diff --git a/installers/common.sh b/installers/common.sh
index 127fa6c1..701405ac 100644
--- a/installers/common.sh
+++ b/installers/common.sh
@@ -106,7 +106,7 @@ function move_config_file() {
function patch_system_files() {
install_log "Patching system sudoers file"
# patch /etc/sudoers file
- sudo bash -c 'echo "www-data ALL=(ALL) NOPASSWD:/sbin/ifdown wlan0,/sbin/ifup wlan0,/bin/cat /etc/wpa_supplicant/wpa_supplicant.conf,/bin/cp /tmp/wifidata /etc/wpa_supplicant/wpa_supplicant.conf,/sbin/wpa_cli scan_results, /sbin/wpa_cli scan,/bin/cp /tmp/hostapddata /etc/hostapd/hostapd.conf, /etc/init.d/hostapd start,/etc/init.d/hostapd stop,/etc/init.d/dnsmasq start, /etc/init.d/dnsmasq stop,/bin/cp /tmp/dhcpddata /etc/dnsmasq.conf, /sbin/shutdown -h now, /sbin/reboot" | (EDITOR="tee -a" visudo)' \
+ sudo bash -c 'echo "www-data ALL=(ALL) NOPASSWD:/sbin/ifdown wlan0,/sbin/ifup wlan0,/bin/cat /etc/wpa_supplicant/wpa_supplicant.conf,/bin/cp /tmp/wifidata /etc/wpa_supplicant/wpa_supplicant.conf,/sbin/wpa_cli scan_results, /sbin/wpa_cli scan,/sbin/wpa_cli reconfigure:/bin/cp /tmp/hostapddata /etc/hostapd/hostapd.conf, /etc/init.d/hostapd start,/etc/init.d/hostapd stop,/etc/init.d/dnsmasq start, /etc/init.d/dnsmasq stop,/bin/cp /tmp/dhcpddata /etc/dnsmasq.conf, /sbin/shutdown -h now, /sbin/reboot" | (EDITOR="tee -a" visudo)' \
|| install_error "Unable to patch /etc/sudoers"
}
@@ -133,4 +133,4 @@ function install_raspap() {
move_config_file
patch_system_files
install_complete
-}
\ No newline at end of file
+}