diff --git a/includes/admin.php b/includes/admin.php index f9a8a4ff..7e7e900f 100755 --- a/includes/admin.php +++ b/includes/admin.php @@ -1,82 +1,74 @@ '.$message; - if ($dismissable) $status .= ''; - $status .= ''; - - return $status; -} +include_once( 'includes/status_messages.php' ); function DisplayAuthConfig($username, $password){ - $status = ''; - if (isset($_POST['UpdateAdminPassword'])) { - if (CSRFValidate()) { - if (password_verify($_POST['oldpass'], $password)) { - $new_username=trim($_POST['username']); - if ($_POST['newpass'] != $_POST['newpassagain']) { - $status = Status('New passwords do not match', 'danger'); - } else if ($new_username == '') { - $status = Status('Username must not be empty', 'danger'); - } else { - if ($auth_file = fopen(RASPI_ADMIN_DETAILS, 'w')) { - fwrite($auth_file, $new_username.PHP_EOL); - fwrite($auth_file, password_hash($_POST['newpass'], PASSWORD_BCRYPT).PHP_EOL); - fclose($auth_file); - $username = $new_username; - $status = Status('Admin password updated'); - } else { - $status = Status('Failed to update admin password', 'danger'); - } - } - } else { - $status = Status('Old password does not match', 'danger'); - } + $status = new StatusMessages(); + if (isset($_POST['UpdateAdminPassword'])) { + if (CSRFValidate()) { + if (password_verify($_POST['oldpass'], $password)) { + $new_username=trim($_POST['username']); + if ($_POST['newpass'] != $_POST['newpassagain']) { + $status->addMessage('New passwords do not match', 'danger'); + } else if ($new_username == '') { + $status->addMessage('Username must not be empty', 'danger'); + } else { + if ($auth_file = fopen(RASPI_ADMIN_DETAILS, 'w')) { + fwrite($auth_file, $new_username.PHP_EOL); + fwrite($auth_file, password_hash($_POST['newpass'], PASSWORD_BCRYPT).PHP_EOL); + fclose($auth_file); + $username = $new_username; + $status->addMessage('Admin password updated'); + } else { + $status->addMessage('Failed to update admin password', 'danger'); + } + } + } else { + $status->addMessage('Old password does not match', 'danger'); + } } else { - error_log('CSRF violation'); + error_log('CSRF violation'); } } ?> -
-
-
-
Configure Auth
-
-

-
- -
-
- - -
-
-
-
- - -
-
-
-
- - -
-
-
-
- - -
-
- -
-
-
-
-
+
+
+
+
Configure Auth
+
+

showMessages(); ?>

+
+ +
+
+ + +
+
+
+
+ + +
+
+
+
+ + +
+
+
+
+ + +
+
+ +
+
+
+
+
/tmp/dhcpddata',$temp ); + system( 'sudo cp /tmp/dhcpddata '. RASPI_DNSMASQ_CONFIG, $return ); + + if( $return == 0 ) { + $status->addMessage('Dnsmasq configuration updated successfully', 'success'); + } else { + $status->addMessage('Dnsmasq configuration failed to be updated', 'danger'); + } + } else { + error_log('CSRF violation'); + } + } + + exec( 'pidof dnsmasq | wc -l',$dnsmasq ); + $dnsmasq_state = ($dnsmasq[0] > 0); + + if( isset( $_POST['startdhcpd'] ) ) { + if (CSRFValidate()) { + if ($dnsmasq_state) { + $status->addMessage('dnsmasq already running', 'info'); + } else { + exec('sudo /etc/init.d/dnsmasq start', $dnsmasq, $return); + if ($return == 0) { + $status->addMessage('Successfully started dnsmasq', 'success'); + $dnsmasq_state = true; + } else { + $status->addMessage('Failed to start dnsmasq', 'danger'); + } + } + } else { + error_log('CSRF violation'); + } + } elseif( isset($_POST['stopdhcpd'] ) ) { + if (CSRFValidate()) { + if ($dnsmasq_state) { + exec('sudo /etc/init.d/dnsmasq stop', $dnsmasq, $return); + if ($return == 0) { + $status->addMessage('Successfully stopped dnsmasq', 'success'); + $dnsmasq_state = false; + } else { + $status->addMessage('Failed to stop dnsmasq', 'danger'); + } + } else { + $status->addMessage('dnsmasq already stopped', 'info'); + } + } else { + error_log('CSRF violation'); + } + } else { + if( $dnsmasq_state ) { + $status->addMessage('Dnsmasq is running', 'success'); + } else { + $status->addMessage('Dnsmasq is not running', 'warning'); + } + } + + exec( 'cat '. RASPI_DNSMASQ_CONFIG, $return ); + $conf = ParseConfig($return); + $arrRange = explode( ",", $conf['dhcp-range'] ); + $RangeStart = $arrRange[0]; + $RangeEnd = $arrRange[1]; + $RangeMask = $arrRange[2]; + preg_match( '/([0-9]*)([a-z])/i', $arrRange[3], $arrRangeLeaseTime ); + + switch( $arrRangeLeaseTime[2] ) { + case "h": + $hselected = " selected"; + break; + case "m": + $mselected = " selected"; + break; + case "d": + $dselected = " selected"; + break; + } + + ?> +
+
+
+
Configure DHCP +
+ +
+

showMessages(); ?>

+ + + +
+
+

DHCP server settings

+
+ +
+
+ + +
+
+
+
+ + +
+
+ +
+
+ + +
+
+ +
+
+ + +
+
+ + +
+
+ + + '; + } else { + echo''; + } + ?> +
+
+ +
+

Client list

+
+
+
+ Active DHCP leases +
+ +
+
+ + + + + + + + + + + + + ' . $lease_item . ''; + } + echo ''; + }; + ?> + + +
Expire timeMAC AddressIP AddressHost nameClient ID
+
+
+
+
+
+
+
+ +
+
+
+ + diff --git a/includes/functions.php b/includes/functions.php index bd32ec65..3e9f4ddb 100755 --- a/includes/functions.php +++ b/includes/functions.php @@ -551,188 +551,6 @@ function DisplayHostAPDConfig(){ Dnsmasq is not running'; - } else { - $status = '
Dnsmasq is running
'; - } - ?> -
-
-
-
Configure DHCP -
- -
- - - -
-

-
-

DHCP server settings

-
-
-
- - -
-
-
-
- - -
-
- -
-
- - -
-
- -
-
- - -
-
- - -
-
- - - '; - } else { - echo ''; - } - ?> -
-
- -
-

Client list

-
-
-
- Active DHCP leases -
- -
-
- - - - - - - - - - - - - ' . $lease_item . ''; - } - echo ''; - }; - ?> - - -
Expire timeMAC AddressIP AddressHost nameClient ID
-
-
-
-
- /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"; - } - ?> -
-
-
- -
-
-
-'.$message; + if ($dismissable) $status .= ''; + $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/index.php b/index.php index 535663e7..b53eec8c 100755 --- a/index.php +++ b/index.php @@ -38,9 +38,10 @@ define('RASPI_OPENVPN_ENABLED', false ); define('RASPI_TORPROXY_ENABLED', false ); include_once( RASPI_CONFIG.'/raspap.php' ); +include_once( 'includes/functions.php' ); include_once( 'includes/authenticate.php' ); include_once( 'includes/admin.php' ); -include_once( 'includes/functions.php' ); +include_once( 'includes/dhcp.php' ); $output = $return = 0; $page = $_GET['page'];