mirror of
https://github.com/billz/raspap-webgui.git
synced 2025-03-01 10:31:47 +00:00
Processed with phpcs for PSR-2 coding standard
This commit is contained in:
parent
89852cc633
commit
c0570b616e
5
includes/about.php
Normal file → Executable file
5
includes/about.php
Normal file → Executable file
@ -1,8 +1,9 @@
|
||||
<?php
|
||||
|
||||
include_once( 'includes/status_messages.php' );
|
||||
include_once('includes/status_messages.php');
|
||||
|
||||
function DisplayAbout() {
|
||||
function DisplayAbout()
|
||||
{
|
||||
/**
|
||||
*
|
||||
* Displays info about the RaspAP project
|
||||
|
@ -1,8 +1,9 @@
|
||||
<?php
|
||||
|
||||
include_once( 'includes/status_messages.php' );
|
||||
include_once('includes/status_messages.php');
|
||||
|
||||
function DisplayAuthConfig($username, $password){
|
||||
function DisplayAuthConfig($username, $password)
|
||||
{
|
||||
$status = new StatusMessages();
|
||||
if (isset($_POST['UpdateAdminPassword'])) {
|
||||
if (CSRFValidate()) {
|
||||
@ -10,7 +11,7 @@ function DisplayAuthConfig($username, $password){
|
||||
$new_username=trim($_POST['username']);
|
||||
if ($_POST['newpass'] !== $_POST['newpassagain']) {
|
||||
$status->addMessage('New passwords do not match', 'danger');
|
||||
} else if ($new_username == '') {
|
||||
} elseif ($new_username == '') {
|
||||
$status->addMessage('Username must not be empty', 'danger');
|
||||
} else {
|
||||
if (!file_exists(RASPI_ADMIN_DETAILS)) {
|
||||
|
@ -15,4 +15,3 @@ if (!$validated) {
|
||||
|
||||
exit('Not authorized'.PHP_EOL);
|
||||
}
|
||||
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
define('RASPI_VERSION', '1.4.1');
|
||||
define('RASPI_CONFIG', '/etc/raspap');
|
||||
define('RASPI_CONFIG_NETWORKING',RASPI_CONFIG.'/networking');
|
||||
define('RASPI_CONFIG_NETWORKING', RASPI_CONFIG.'/networking');
|
||||
define('RASPI_ADMIN_DETAILS', RASPI_CONFIG.'/raspap.auth');
|
||||
define('RASPI_WIFI_CLIENT_INTERFACE', 'wlan0');
|
||||
|
||||
@ -20,17 +20,16 @@ define('RASPI_OPENVPN_SERVER_CONFIG', '/etc/openvpn/server.conf');
|
||||
define('RASPI_TORPROXY_CONFIG', '/etc/tor/torrc');
|
||||
|
||||
// Optional services, set to true to enable.
|
||||
define('RASPI_WIFICLIENT_ENABLED', true );
|
||||
define('RASPI_HOTSPOT_ENABLED', true );
|
||||
define('RASPI_NETWORK_ENABLED', true );
|
||||
define('RASPI_DHCP_ENABLED', true );
|
||||
define('RASPI_OPENVPN_ENABLED', false );
|
||||
define('RASPI_TORPROXY_ENABLED', false );
|
||||
define('RASPI_CONFAUTH_ENABLED', true );
|
||||
define('RASPI_CHANGETHEME_ENABLED', true );
|
||||
define('RASPI_VNSTAT_ENABLED', true );
|
||||
define('RASPI_WIFICLIENT_ENABLED', true);
|
||||
define('RASPI_HOTSPOT_ENABLED', true);
|
||||
define('RASPI_NETWORK_ENABLED', true);
|
||||
define('RASPI_DHCP_ENABLED', true);
|
||||
define('RASPI_OPENVPN_ENABLED', false);
|
||||
define('RASPI_TORPROXY_ENABLED', false);
|
||||
define('RASPI_CONFAUTH_ENABLED', true);
|
||||
define('RASPI_CHANGETHEME_ENABLED', true);
|
||||
define('RASPI_VNSTAT_ENABLED', true);
|
||||
|
||||
// Locale settings
|
||||
define('LOCALE_ROOT', 'locale');
|
||||
define('LOCALE_DOMAIN', 'messages');
|
||||
|
||||
|
@ -4,7 +4,8 @@
|
||||
*
|
||||
*
|
||||
*/
|
||||
function DisplayWPAConfig(){
|
||||
function DisplayWPAConfig()
|
||||
{
|
||||
$status = new StatusMessages();
|
||||
$networks = array();
|
||||
|
||||
@ -14,7 +15,7 @@ function DisplayWPAConfig(){
|
||||
$network = null;
|
||||
$ssid = null;
|
||||
|
||||
foreach($known_return as $line) {
|
||||
foreach ($known_return as $line) {
|
||||
if (preg_match('/network\s*=/', $line)) {
|
||||
$network = array('visible' => false, 'configured' => true, 'connected' => false);
|
||||
} elseif ($network !== null) {
|
||||
@ -23,7 +24,7 @@ function DisplayWPAConfig(){
|
||||
$network = null;
|
||||
$ssid = null;
|
||||
} elseif ($lineArr = preg_split('/\s*=\s*/', trim($line))) {
|
||||
switch(strtolower($lineArr[0])) {
|
||||
switch (strtolower($lineArr[0])) {
|
||||
case 'ssid':
|
||||
$ssid = trim($lineArr[1], '"');
|
||||
break;
|
||||
@ -49,17 +50,16 @@ function DisplayWPAConfig(){
|
||||
}
|
||||
}
|
||||
|
||||
if ( isset($_POST['connect']) ) {
|
||||
if (isset($_POST['connect'])) {
|
||||
$result = 0;
|
||||
exec ( 'sudo wpa_cli -i ' . RASPI_WPA_CTRL_INTERFACE . ' select_network '.strval($_POST['connect'] ));
|
||||
}
|
||||
else if ( isset($_POST['client_settings']) && CSRFValidate() ) {
|
||||
exec('sudo wpa_cli -i ' . RASPI_WPA_CTRL_INTERFACE . ' select_network '.strval($_POST['connect']));
|
||||
} elseif (isset($_POST['client_settings']) && CSRFValidate()) {
|
||||
$tmp_networks = $networks;
|
||||
if ($wpa_file = fopen('/tmp/wifidata', 'w')) {
|
||||
fwrite($wpa_file, 'ctrl_interface=DIR=' . RASPI_WPA_CTRL_INTERFACE . ' GROUP=netdev' . PHP_EOL);
|
||||
fwrite($wpa_file, 'update_config=1' . PHP_EOL);
|
||||
|
||||
foreach(array_keys($_POST) as $post) {
|
||||
foreach (array_keys($_POST) as $post) {
|
||||
if (preg_match('/delete(\d+)/', $post, $post_match)) {
|
||||
unset($tmp_networks[$_POST['ssid' . $post_match[1]]]);
|
||||
} elseif (preg_match('/update(\d+)/', $post, $post_match)) {
|
||||
@ -77,7 +77,7 @@ function DisplayWPAConfig(){
|
||||
}
|
||||
|
||||
$ok = true;
|
||||
foreach($tmp_networks as $ssid => $network) {
|
||||
foreach ($tmp_networks as $ssid => $network) {
|
||||
if ($network['protocol'] === 'Open') {
|
||||
fwrite($wpa_file, "network={".PHP_EOL);
|
||||
fwrite($wpa_file, "\tssid=\"".$ssid."\"".PHP_EOL);
|
||||
@ -90,8 +90,8 @@ function DisplayWPAConfig(){
|
||||
if (strlen($network['passphrase']) >=8 && strlen($network['passphrase']) <= 63) {
|
||||
unset($wpa_passphrase);
|
||||
unset($line);
|
||||
exec( 'wpa_passphrase '.escapeshellarg($ssid). ' ' . escapeshellarg($network['passphrase']),$wpa_passphrase );
|
||||
foreach($wpa_passphrase as $line) {
|
||||
exec('wpa_passphrase '.escapeshellarg($ssid). ' ' . escapeshellarg($network['passphrase']), $wpa_passphrase);
|
||||
foreach ($wpa_passphrase as $line) {
|
||||
if (preg_match('/^\s*}\s*$/', $line)) {
|
||||
if (array_key_exists('priority', $network)) {
|
||||
fwrite($wpa_file, "\tpriority=".$network['priority'].PHP_EOL);
|
||||
@ -109,9 +109,9 @@ function DisplayWPAConfig(){
|
||||
}
|
||||
|
||||
if ($ok) {
|
||||
system( 'sudo cp /tmp/wifidata ' . RASPI_WPA_SUPPLICANT_CONFIG, $returnval );
|
||||
if( $returnval == 0 ) {
|
||||
exec('sudo wpa_cli -i ' . RASPI_WIFI_CLIENT_INTERFACE . ' reconfigure', $reconfigure_out, $reconfigure_return );
|
||||
system('sudo cp /tmp/wifidata ' . RASPI_WPA_SUPPLICANT_CONFIG, $returnval);
|
||||
if ($returnval == 0) {
|
||||
exec('sudo wpa_cli -i ' . RASPI_WIFI_CLIENT_INTERFACE . ' reconfigure', $reconfigure_out, $reconfigure_return);
|
||||
if ($reconfigure_return == 0) {
|
||||
$status->addMessage('Wifi settings updated successfully', 'success');
|
||||
$networks = $tmp_networks;
|
||||
@ -127,15 +127,15 @@ function DisplayWPAConfig(){
|
||||
}
|
||||
}
|
||||
|
||||
exec( 'sudo wpa_cli -i ' . RASPI_WIFI_CLIENT_INTERFACE . ' scan' );
|
||||
exec('sudo wpa_cli -i ' . RASPI_WIFI_CLIENT_INTERFACE . ' scan');
|
||||
sleep(3);
|
||||
exec( 'sudo wpa_cli -i ' . RASPI_WIFI_CLIENT_INTERFACE . ' scan_results',$scan_return );
|
||||
exec('sudo wpa_cli -i ' . RASPI_WIFI_CLIENT_INTERFACE . ' scan_results', $scan_return);
|
||||
|
||||
array_shift($scan_return);
|
||||
|
||||
// display output
|
||||
foreach( $scan_return as $network ) {
|
||||
$arrNetwork = preg_split("/[\t]+/",$network); // split result into array
|
||||
foreach ($scan_return as $network) {
|
||||
$arrNetwork = preg_split("/[\t]+/", $network); // split result into array
|
||||
|
||||
// Save RSSI
|
||||
if (array_key_exists(4, $arrNetwork)) {
|
||||
@ -159,9 +159,9 @@ function DisplayWPAConfig(){
|
||||
}
|
||||
}
|
||||
|
||||
exec( 'iwconfig ' . RASPI_WIFI_CLIENT_INTERFACE, $iwconfig_return );
|
||||
exec('iwconfig ' . RASPI_WIFI_CLIENT_INTERFACE, $iwconfig_return);
|
||||
foreach ($iwconfig_return as $line) {
|
||||
if (preg_match( '/ESSID:\"([^"]+)\"/i',$line,$iwconfig_ssid )) {
|
||||
if (preg_match('/ESSID:\"([^"]+)\"/i', $line, $iwconfig_ssid)) {
|
||||
$networks[$iwconfig_ssid[1]]['connected'] = true;
|
||||
}
|
||||
}
|
||||
@ -231,9 +231,13 @@ function DisplayWPAConfig(){
|
||||
<div class="col-xs-6 col-md-6">
|
||||
<?php echo htmlspecialchars($network['RSSI'], ENT_QUOTES);
|
||||
echo "dB (";
|
||||
if($network['RSSI'] >= -50) { echo 100; }
|
||||
else if($network['RSSI'] <= -100) { echo 0;}
|
||||
else {echo 2*($network['RSSI'] + 100); }
|
||||
if ($network['RSSI'] >= -50) {
|
||||
echo 100;
|
||||
} elseif ($network['RSSI'] <= -100) {
|
||||
echo 0;
|
||||
} else {
|
||||
echo 2*($network['RSSI'] + 100);
|
||||
}
|
||||
echo "%)";
|
||||
?>
|
||||
</div>
|
||||
|
@ -3,7 +3,8 @@
|
||||
/**
|
||||
* Show dashboard page.
|
||||
*/
|
||||
function DisplayDashboard(){
|
||||
function DisplayDashboard()
|
||||
{
|
||||
|
||||
$status = new StatusMessages();
|
||||
// Need this check interface name for proper shell execution.
|
||||
@ -23,7 +24,7 @@ function DisplayDashboard(){
|
||||
$stdoutIpAllLinesGlued = implode(" ", $stdoutIp);
|
||||
$stdoutIpWRepeatedSpaces = preg_replace('/\s\s+/', ' ', $stdoutIpAllLinesGlued);
|
||||
|
||||
preg_match('/link\/ether ([0-9a-f:]+)/i', $stdoutIpWRepeatedSpaces, $matchesMacAddr ) || $matchesMacAddr[1] = _('No MAC Address Found');
|
||||
preg_match('/link\/ether ([0-9a-f:]+)/i', $stdoutIpWRepeatedSpaces, $matchesMacAddr) || $matchesMacAddr[1] = _('No MAC Address Found');
|
||||
$macAddr = $matchesMacAddr[1];
|
||||
|
||||
$ipv4Addrs = '';
|
||||
@ -57,7 +58,7 @@ function DisplayDashboard(){
|
||||
}
|
||||
}
|
||||
|
||||
preg_match('/state (UP|DOWN)/i', $stdoutIpWRepeatedSpaces, $matchesState ) || $matchesState[1] = 'unknown';
|
||||
preg_match('/state (UP|DOWN)/i', $stdoutIpWRepeatedSpaces, $matchesState) || $matchesState[1] = 'unknown';
|
||||
$interfaceState = $matchesState[1];
|
||||
|
||||
// Because of table layout used in the ip output we get the interface statistics directly from
|
||||
@ -123,7 +124,7 @@ function DisplayDashboard(){
|
||||
$stdoutIwInfoAllLinesGlued = implode(' ', $stdoutIwInfo);
|
||||
$stdoutIpInfoWRepSpaces = preg_replace('/\s\s+/', ' ', $stdoutIwInfoAllLinesGlued);
|
||||
|
||||
preg_match('/txpower ([0-9\.]+ dBm)/i', $stdoutIpInfoWRepSpaces, $matchesTxPower ) || $matchesTxPower[1] = '';
|
||||
preg_match('/txpower ([0-9\.]+ dBm)/i', $stdoutIpInfoWRepSpaces, $matchesTxPower) || $matchesTxPower[1] = '';
|
||||
$txPower = $matchesTxPower[1];
|
||||
|
||||
// iw does not have the "Link Quality". This is a is an aggregate value,
|
||||
@ -150,7 +151,7 @@ function DisplayDashboard(){
|
||||
// Pressed stop button
|
||||
if ($interfaceState === 'UP') {
|
||||
$status->addMessage(sprintf(_('Interface is going %s.'), _('down')), 'warning');
|
||||
exec( 'sudo ip link set '.RASPI_WIFI_CLIENT_INTERFACE.' down' );
|
||||
exec('sudo ip link set '.RASPI_WIFI_CLIENT_INTERFACE.' down');
|
||||
$wlan0up = false;
|
||||
$status->addMessage(sprintf(_('Interface is now %s.'), _('down')), 'success');
|
||||
} elseif ($interfaceState === 'unknown') {
|
||||
@ -158,7 +159,7 @@ function DisplayDashboard(){
|
||||
} else {
|
||||
$status->addMessage(sprintf(_('Interface already %s.'), _('down')), 'warning');
|
||||
}
|
||||
} elseif( isset($_POST['ifup_wlan0']) ) {
|
||||
} elseif (isset($_POST['ifup_wlan0'])) {
|
||||
// Pressed start button
|
||||
if ($interfaceState === 'DOWN') {
|
||||
$status->addMessage(sprintf(_('Interface is going %s.'), _('up')), 'warning');
|
||||
@ -238,7 +239,7 @@ function DisplayDashboard(){
|
||||
<tbody>
|
||||
<?php
|
||||
exec('cat '.RASPI_DNSMASQ_LEASES.'| grep -E $(arp -i '.RASPI_WIFI_CLIENT_INTERFACE.' | grep -oE "(([0-9]|[a-f]|[A-F]){2}:){5}([0-9]|[a-f]|[A-F]){2}" | tr "\n" "\|" | sed "s/.$//")', $clients);
|
||||
foreach( $clients as $client ) {
|
||||
foreach ($clients as $client) {
|
||||
$client_items = explode(' ', $client);
|
||||
echo '<tr>'.PHP_EOL;
|
||||
echo '<td>'.htmlspecialchars($client_items[3], ENT_QUOTES).'</td>'.PHP_EOL;
|
||||
@ -258,11 +259,11 @@ foreach( $clients as $client ) {
|
||||
<div class="col-lg-12">
|
||||
<div class="row">
|
||||
<form action="?page=wlan0_info" method="POST">
|
||||
<?php if ( !$wlan0up ) {
|
||||
<?php if (!$wlan0up) {
|
||||
echo '<input type="submit" class="btn btn-success" value="'._("Start ").RASPI_WIFI_CLIENT_INTERFACE.'" name="ifup_wlan0" />';
|
||||
} else {
|
||||
} else {
|
||||
echo '<input type="submit" class="btn btn-warning" value="'._("Stop ").RASPI_WIFI_CLIENT_INTERFACE.'" name="ifdown_wlan0" />';
|
||||
}
|
||||
}
|
||||
?>
|
||||
<input type="button" class="btn btn-outline btn-primary" value="<?php echo _("Refresh"); ?>" onclick="document.location.reload(true)" />
|
||||
</form>
|
||||
|
@ -5,7 +5,7 @@
|
||||
*/
|
||||
function DisplayDataUsage(&$extraFooterScripts)
|
||||
{
|
||||
exec("ip -o link show | awk -F ': ' '{print $2}' | grep -v lo ", $interfacesWlo);
|
||||
exec("ip -o link show | awk -F ': ' '{print $2}' | grep -v lo ", $interfacesWlo);
|
||||
?>
|
||||
<div class="row">
|
||||
<div class="col-lg-12">
|
||||
|
@ -1,16 +1,17 @@
|
||||
<?php
|
||||
|
||||
include_once( 'includes/status_messages.php' );
|
||||
include_once('includes/status_messages.php');
|
||||
|
||||
/**
|
||||
*
|
||||
* Manage DHCP configuration
|
||||
*
|
||||
*/
|
||||
function DisplayDHCPConfig() {
|
||||
function DisplayDHCPConfig()
|
||||
{
|
||||
|
||||
$status = new StatusMessages();
|
||||
if( isset( $_POST['savedhcpdsettings'] ) ) {
|
||||
if (isset($_POST['savedhcpdsettings'])) {
|
||||
if (CSRFValidate()) {
|
||||
$errors = '';
|
||||
define('IFNAMSIZ', 16);
|
||||
@ -63,10 +64,10 @@ function DisplayDHCPConfig() {
|
||||
}
|
||||
}
|
||||
|
||||
exec( 'pidof dnsmasq | wc -l',$dnsmasq );
|
||||
exec('pidof dnsmasq | wc -l', $dnsmasq);
|
||||
$dnsmasq_state = ($dnsmasq[0] > 0);
|
||||
|
||||
if( isset( $_POST['startdhcpd'] ) ) {
|
||||
if (isset($_POST['startdhcpd'])) {
|
||||
if (CSRFValidate()) {
|
||||
if ($dnsmasq_state) {
|
||||
$status->addMessage('dnsmasq already running', 'info');
|
||||
@ -82,7 +83,7 @@ function DisplayDHCPConfig() {
|
||||
} else {
|
||||
error_log('CSRF violation');
|
||||
}
|
||||
} elseif( isset($_POST['stopdhcpd'] ) ) {
|
||||
} elseif (isset($_POST['stopdhcpd'])) {
|
||||
if (CSRFValidate()) {
|
||||
if ($dnsmasq_state) {
|
||||
exec('sudo /etc/init.d/dnsmasq stop', $dnsmasq, $return);
|
||||
@ -99,16 +100,16 @@ function DisplayDHCPConfig() {
|
||||
error_log('CSRF violation');
|
||||
}
|
||||
} else {
|
||||
if( $dnsmasq_state ) {
|
||||
if ($dnsmasq_state) {
|
||||
$status->addMessage('Dnsmasq is running', 'success');
|
||||
} else {
|
||||
$status->addMessage('Dnsmasq is not running', 'warning');
|
||||
}
|
||||
}
|
||||
|
||||
exec( 'cat '. RASPI_DNSMASQ_CONFIG, $return );
|
||||
exec('cat '. RASPI_DNSMASQ_CONFIG, $return);
|
||||
$conf = ParseConfig($return);
|
||||
$arrRange = explode( ",", $conf['dhcp-range'] );
|
||||
$arrRange = explode(",", $conf['dhcp-range']);
|
||||
$RangeStart = $arrRange[0];
|
||||
$RangeEnd = $arrRange[1];
|
||||
$RangeMask = $arrRange[2];
|
||||
@ -118,11 +119,11 @@ function DisplayDHCPConfig() {
|
||||
$mselected = '';
|
||||
$dselected = '';
|
||||
$infiniteselected = '';
|
||||
preg_match( '/([0-9]*)([a-z])/i', $leaseTime, $arrRangeLeaseTime );
|
||||
preg_match('/([0-9]*)([a-z])/i', $leaseTime, $arrRangeLeaseTime);
|
||||
if ($leaseTime === 'infinite') {
|
||||
$infiniteselected = ' selected="selected"';
|
||||
} else {
|
||||
switch( $arrRangeLeaseTime[2] ) {
|
||||
switch ($arrRangeLeaseTime[2]) {
|
||||
case 'h':
|
||||
$hselected = ' selected="selected"';
|
||||
break;
|
||||
@ -163,15 +164,15 @@ function DisplayDHCPConfig() {
|
||||
<?php
|
||||
exec("ip -o link show | awk -F': ' '{print $2}'", $interfaces);
|
||||
|
||||
foreach( $interfaces as $inet ) {
|
||||
foreach ($interfaces as $inet) {
|
||||
$select = '';
|
||||
if( $inet === $conf['interface'] ) {
|
||||
if ($inet === $conf['interface']) {
|
||||
$select = ' selected="selected"';
|
||||
}
|
||||
|
||||
echo ' <option value="'.htmlspecialchars($inet, ENT_QUOTES).'"'.
|
||||
$select.'>'.htmlspecialchars($inet, ENT_QUOTES).'</option>' , PHP_EOL;
|
||||
}
|
||||
}
|
||||
?>
|
||||
</select>
|
||||
</div>
|
||||
@ -209,12 +210,12 @@ function DisplayDHCPConfig() {
|
||||
<input type="submit" class="btn btn-outline btn-primary" value="<?php echo _("Save settings"); ?>" name="savedhcpdsettings" />
|
||||
<?php
|
||||
|
||||
if ( $dnsmasq_state ) {
|
||||
if ($dnsmasq_state) {
|
||||
echo '<input type="submit" class="btn btn-warning" value="' . _("Stop dnsmasq") . '" name="stopdhcpd" />';
|
||||
} else {
|
||||
echo'<input type="submit" class="btn btn-success" value="' . _("Start dnsmasq") . '" name="startdhcpd" />';
|
||||
}
|
||||
?>
|
||||
?>
|
||||
</form>
|
||||
</div><!-- /.tab-pane -->
|
||||
|
||||
@ -238,11 +239,11 @@ function DisplayDHCPConfig() {
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php
|
||||
exec( 'cat ' . RASPI_DNSMASQ_LEASES, $leases );
|
||||
foreach( $leases as $lease ) {
|
||||
exec('cat ' . RASPI_DNSMASQ_LEASES, $leases);
|
||||
foreach ($leases as $lease) {
|
||||
echo ' <tr>'.PHP_EOL;
|
||||
$lease_items = explode(' ', $lease);
|
||||
foreach( $lease_items as $lease_item ) {
|
||||
foreach ($lease_items as $lease_item) {
|
||||
echo ' <td>'.htmlspecialchars($lease_item, ENT_QUOTES).'</td>'.PHP_EOL;
|
||||
}
|
||||
echo ' </tr>'.PHP_EOL;
|
||||
|
@ -1,38 +1,46 @@
|
||||
<?php
|
||||
/* Functions for Networking */
|
||||
|
||||
function mask2cidr($mask){
|
||||
function mask2cidr($mask)
|
||||
{
|
||||
$long = ip2long($mask);
|
||||
$base = ip2long('255.255.255.255');
|
||||
return 32-log(($long ^ $base)+1,2);
|
||||
return 32-log(($long ^ $base)+1, 2);
|
||||
}
|
||||
|
||||
/* Functions to write ini files */
|
||||
|
||||
function write_php_ini($array, $file) {
|
||||
function write_php_ini($array, $file)
|
||||
{
|
||||
$res = array();
|
||||
foreach($array as $key => $val) {
|
||||
if(is_array($val)) {
|
||||
foreach ($array as $key => $val) {
|
||||
if (is_array($val)) {
|
||||
$res[] = "[$key]";
|
||||
foreach($val as $skey => $sval) $res[] = "$skey = ".(is_numeric($sval) ? $sval : '"'.$sval.'"');
|
||||
foreach ($val as $skey => $sval) {
|
||||
$res[] = "$skey = ".(is_numeric($sval) ? $sval : '"'.$sval.'"');
|
||||
}
|
||||
else $res[] = "$key = ".(is_numeric($val) ? $val : '"'.$val.'"');
|
||||
} else {
|
||||
$res[] = "$key = ".(is_numeric($val) ? $val : '"'.$val.'"');
|
||||
}
|
||||
if(safefilerewrite($file, implode("\r\n", $res))) {
|
||||
}
|
||||
if (safefilerewrite($file, implode("\r\n", $res))) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
function safefilerewrite($fileName, $dataToSave) {
|
||||
function safefilerewrite($fileName, $dataToSave)
|
||||
{
|
||||
if ($fp = fopen($fileName, 'w')) {
|
||||
$startTime = microtime(TRUE);
|
||||
$startTime = microtime(true);
|
||||
do {
|
||||
$canWrite = flock($fp, LOCK_EX);
|
||||
// If lock not obtained sleep for 0 - 100 milliseconds, to avoid collision and CPU load
|
||||
if(!$canWrite) usleep(round(rand(0, 100)*1000));
|
||||
} while ((!$canWrite)and((microtime(TRUE)-$startTime) < 5));
|
||||
if (!$canWrite) {
|
||||
usleep(round(rand(0, 100)*1000));
|
||||
}
|
||||
} while ((!$canWrite)and((microtime(true)-$startTime) < 5));
|
||||
|
||||
//file was locked so now we can store information
|
||||
if ($canWrite) {
|
||||
@ -46,16 +54,16 @@ function safefilerewrite($fileName, $dataToSave) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* Add CSRF Token to form
|
||||
*
|
||||
*/
|
||||
function CSRFToken() {
|
||||
function CSRFToken()
|
||||
{
|
||||
?>
|
||||
<input id="csrf_token" type="hidden" name="csrf_token" value="<?php echo htmlspecialchars($_SESSION['csrf_token'], ENT_QUOTES);; ?>" />
|
||||
<input id="csrf_token" type="hidden" name="csrf_token" value="<?php echo htmlspecialchars($_SESSION['csrf_token'], ENT_QUOTES);
|
||||
; ?>" />
|
||||
<?php
|
||||
}
|
||||
|
||||
@ -64,8 +72,9 @@ function CSRFToken() {
|
||||
* Validate CSRF Token
|
||||
*
|
||||
*/
|
||||
function CSRFValidate() {
|
||||
if ( hash_equals($_POST['csrf_token'], $_SESSION['csrf_token']) ) {
|
||||
function CSRFValidate()
|
||||
{
|
||||
if (hash_equals($_POST['csrf_token'], $_SESSION['csrf_token'])) {
|
||||
return true;
|
||||
} else {
|
||||
error_log('CSRF violation');
|
||||
@ -76,7 +85,8 @@ function CSRFValidate() {
|
||||
/**
|
||||
* Test whether array is associative
|
||||
*/
|
||||
function isAssoc($arr) {
|
||||
function isAssoc($arr)
|
||||
{
|
||||
return array_keys($arr) !== range(0, count($arr) - 1);
|
||||
}
|
||||
|
||||
@ -89,17 +99,18 @@ function isAssoc($arr) {
|
||||
* If $options is an associative array this should be the key
|
||||
*
|
||||
*/
|
||||
function SelectorOptions($name, $options, $selected = null, $id = null) {
|
||||
function SelectorOptions($name, $options, $selected = null, $id = null)
|
||||
{
|
||||
echo '<select class="form-control" name="'.htmlspecialchars($name, ENT_QUOTES).'"';
|
||||
if (isset($id)) {
|
||||
echo ' id="' . htmlspecialchars($id, ENT_QUOTES) .'"';
|
||||
}
|
||||
|
||||
echo '>' , PHP_EOL;
|
||||
foreach ( $options as $opt => $label) {
|
||||
foreach ($options as $opt => $label) {
|
||||
$select = '';
|
||||
$key = isAssoc($options) ? $opt : $label;
|
||||
if( $key == $selected ) {
|
||||
if ($key == $selected) {
|
||||
$select = ' selected="selected"';
|
||||
}
|
||||
|
||||
@ -118,8 +129,9 @@ function SelectorOptions($name, $options, $selected = null, $id = null) {
|
||||
* @param string $separator
|
||||
* @return $string
|
||||
*/
|
||||
function GetDistString( $input,$string,$offset,$separator ) {
|
||||
$string = substr( $input,strpos( $input,$string )+$offset,strpos( substr( $input,strpos( $input,$string )+$offset ), $separator ) );
|
||||
function GetDistString($input, $string, $offset, $separator)
|
||||
{
|
||||
$string = substr($input, strpos($input, $string)+$offset, strpos(substr($input, strpos($input, $string)+$offset), $separator));
|
||||
return $string;
|
||||
}
|
||||
|
||||
@ -128,12 +140,13 @@ function GetDistString( $input,$string,$offset,$separator ) {
|
||||
* @param array $arrConfig
|
||||
* @return $config
|
||||
*/
|
||||
function ParseConfig( $arrConfig ) {
|
||||
function ParseConfig($arrConfig)
|
||||
{
|
||||
$config = array();
|
||||
foreach( $arrConfig as $line ) {
|
||||
foreach ($arrConfig as $line) {
|
||||
$line = trim($line);
|
||||
if( $line != "" && $line[0] != "#" ) {
|
||||
$arrLine = explode( "=",$line );
|
||||
if ($line != "" && $line[0] != "#") {
|
||||
$arrLine = explode("=", $line);
|
||||
$config[$arrLine[0]] = ( count($arrLine) > 1 ? $arrLine[1] : true );
|
||||
}
|
||||
}
|
||||
@ -145,7 +158,8 @@ function ParseConfig( $arrConfig ) {
|
||||
* @param string $freq
|
||||
* @return $channel
|
||||
*/
|
||||
function ConvertToChannel( $freq ) {
|
||||
function ConvertToChannel($freq)
|
||||
{
|
||||
if ($freq >= 2412 && $freq <= 2484) {
|
||||
$channel = ($freq - 2407)/5;
|
||||
} elseif ($freq >= 4915 && $freq <= 4980) {
|
||||
@ -167,10 +181,11 @@ function ConvertToChannel( $freq ) {
|
||||
* @param string $security
|
||||
* @return string
|
||||
*/
|
||||
function ConvertToSecurity( $security ) {
|
||||
function ConvertToSecurity($security)
|
||||
{
|
||||
$options = array();
|
||||
preg_match_all('/\[([^\]]+)\]/s', $security, $matches);
|
||||
foreach($matches[1] as $match) {
|
||||
foreach ($matches[1] as $match) {
|
||||
if (preg_match('/^(WPA\d?)/', $match, $protocol_match)) {
|
||||
$protocol = $protocol_match[1];
|
||||
$matchArr = explode('-', $match);
|
||||
@ -196,13 +211,14 @@ function ConvertToSecurity( $security ) {
|
||||
*
|
||||
*
|
||||
*/
|
||||
function DisplayOpenVPNConfig() {
|
||||
function DisplayOpenVPNConfig()
|
||||
{
|
||||
|
||||
exec( 'cat '. RASPI_OPENVPN_CLIENT_CONFIG, $returnClient );
|
||||
exec( 'cat '. RASPI_OPENVPN_SERVER_CONFIG, $returnServer );
|
||||
exec( 'pidof openvpn | wc -l', $openvpnstatus);
|
||||
exec('cat '. RASPI_OPENVPN_CLIENT_CONFIG, $returnClient);
|
||||
exec('cat '. RASPI_OPENVPN_SERVER_CONFIG, $returnServer);
|
||||
exec('pidof openvpn | wc -l', $openvpnstatus);
|
||||
|
||||
if( $openvpnstatus[0] == 0 ) {
|
||||
if ($openvpnstatus[0] == 0) {
|
||||
$status = '<div class="alert alert-warning alert-dismissable">OpenVPN is not running
|
||||
<button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button></div>';
|
||||
} else {
|
||||
@ -211,17 +227,17 @@ function DisplayOpenVPNConfig() {
|
||||
}
|
||||
|
||||
// parse client settings
|
||||
foreach( $returnClient as $a ) {
|
||||
if( $a[0] != "#" ) {
|
||||
$arrLine = explode( " ",$a) ;
|
||||
foreach ($returnClient as $a) {
|
||||
if ($a[0] != "#") {
|
||||
$arrLine = explode(" ", $a) ;
|
||||
$arrClientConfig[$arrLine[0]]=$arrLine[1];
|
||||
}
|
||||
}
|
||||
|
||||
// parse server settings
|
||||
foreach( $returnServer as $a ) {
|
||||
if( $a[0] != "#" ) {
|
||||
$arrLine = explode( " ",$a) ;
|
||||
foreach ($returnServer as $a) {
|
||||
if ($a[0] != "#") {
|
||||
$arrLine = explode(" ", $a) ;
|
||||
$arrServerConfig[$arrLine[0]]=$arrLine[1];
|
||||
}
|
||||
}
|
||||
@ -305,7 +321,7 @@ function DisplayOpenVPNConfig() {
|
||||
</div>
|
||||
<input type="submit" class="btn btn-outline btn-primary" name="SaveOpenVPNSettings" value="Save settings" />
|
||||
<?php
|
||||
if($hostapdstatus[0] == 0) {
|
||||
if ($hostapdstatus[0] == 0) {
|
||||
echo '<input type="submit" class="btn btn-success" name="StartOpenVPN" value="Start OpenVPN" />' , PHP_EOL;
|
||||
} else {
|
||||
echo '<input type="submit" class="btn btn-warning" name="StopOpenVPN" value="Stop OpenVPN" />' , PHP_EOL;
|
||||
@ -324,12 +340,13 @@ function DisplayOpenVPNConfig() {
|
||||
*
|
||||
*
|
||||
*/
|
||||
function DisplayTorProxyConfig(){
|
||||
function DisplayTorProxyConfig()
|
||||
{
|
||||
|
||||
exec( 'cat '. RASPI_TORPROXY_CONFIG, $return );
|
||||
exec( 'pidof tor | wc -l', $torproxystatus);
|
||||
exec('cat '. RASPI_TORPROXY_CONFIG, $return);
|
||||
exec('pidof tor | wc -l', $torproxystatus);
|
||||
|
||||
if( $torproxystatus[0] == 0 ) {
|
||||
if ($torproxystatus[0] == 0) {
|
||||
$status = '<div class="alert alert-warning alert-dismissable">TOR is not running
|
||||
<button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button></div>';
|
||||
} else {
|
||||
@ -338,9 +355,9 @@ function DisplayTorProxyConfig(){
|
||||
}
|
||||
|
||||
$arrConfig = array();
|
||||
foreach( $return as $a ) {
|
||||
if( $a[0] != "#" ) {
|
||||
$arrLine = explode( " ",$a) ;
|
||||
foreach ($return as $a) {
|
||||
if ($a[0] != "#") {
|
||||
$arrLine = explode(" ", $a) ;
|
||||
$arrConfig[$arrLine[0]]=$arrLine[1];
|
||||
}
|
||||
}
|
||||
@ -446,7 +463,7 @@ function DisplayTorProxyConfig(){
|
||||
|
||||
<input type="submit" class="btn btn-outline btn-primary" name="SaveTORProxySettings" value="Save settings" />
|
||||
<?php
|
||||
if( $torproxystatus[0] == 0 ) {
|
||||
if ($torproxystatus[0] == 0) {
|
||||
echo '<input type="submit" class="btn btn-success" name="StartTOR" value="Start TOR" />' , PHP_EOL;
|
||||
} else {
|
||||
echo '<input type="submit" class="btn btn-warning" name="StopTOR" value="Stop TOR" />' , PHP_EOL;
|
||||
@ -466,33 +483,34 @@ function DisplayTorProxyConfig(){
|
||||
*
|
||||
*
|
||||
*/
|
||||
function SaveTORAndVPNConfig(){
|
||||
if( isset($_POST['SaveOpenVPNSettings']) ) {
|
||||
function SaveTORAndVPNConfig()
|
||||
{
|
||||
if (isset($_POST['SaveOpenVPNSettings'])) {
|
||||
// TODO
|
||||
} elseif( isset($_POST['SaveTORProxySettings']) ) {
|
||||
} elseif (isset($_POST['SaveTORProxySettings'])) {
|
||||
// TODO
|
||||
} elseif( isset($_POST['StartOpenVPN']) ) {
|
||||
} elseif (isset($_POST['StartOpenVPN'])) {
|
||||
echo "Attempting to start openvpn";
|
||||
exec( 'sudo /etc/init.d/openvpn start', $return );
|
||||
foreach( $return as $line ) {
|
||||
exec('sudo /etc/init.d/openvpn start', $return);
|
||||
foreach ($return as $line) {
|
||||
echo htmlspecialchars($line, ENT_QUOTES).'<br />' , PHP_EOL;
|
||||
}
|
||||
} elseif( isset($_POST['StopOpenVPN']) ) {
|
||||
} elseif (isset($_POST['StopOpenVPN'])) {
|
||||
echo "Attempting to stop openvpn";
|
||||
exec( 'sudo /etc/init.d/openvpn stop', $return );
|
||||
foreach( $return as $line ) {
|
||||
exec('sudo /etc/init.d/openvpn stop', $return);
|
||||
foreach ($return as $line) {
|
||||
echo htmlspecialchars($line, ENT_QUOTES).'<br />' , PHP_EOL;
|
||||
}
|
||||
} elseif( isset($_POST['StartTOR']) ) {
|
||||
} elseif (isset($_POST['StartTOR'])) {
|
||||
echo "Attempting to start TOR";
|
||||
exec( 'sudo /etc/init.d/tor start', $return );
|
||||
foreach( $return as $line ) {
|
||||
exec('sudo /etc/init.d/tor start', $return);
|
||||
foreach ($return as $line) {
|
||||
echo htmlspecialchars($line, ENT_QUOTES).'<br />' , PHP_EOL;
|
||||
}
|
||||
} elseif( isset($_POST['StopTOR']) ) {
|
||||
} elseif (isset($_POST['StopTOR'])) {
|
||||
echo "Attempting to stop TOR";
|
||||
exec( 'sudo /etc/init.d/tor stop', $return );
|
||||
foreach( $return as $line ) {
|
||||
exec('sudo /etc/init.d/tor stop', $return);
|
||||
foreach ($return as $line) {
|
||||
echo htmlspecialchars($line, ENT_QUOTES).'<br />' , PHP_EOL;
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
include_once( 'includes/status_messages.php' );
|
||||
include_once('includes/status_messages.php');
|
||||
|
||||
/**
|
||||
*
|
||||
@ -9,40 +9,38 @@ include_once( 'includes/status_messages.php' );
|
||||
function DisplayHostAPDConfig()
|
||||
{
|
||||
$status = new StatusMessages();
|
||||
|
||||
$arrHostapdConf = parse_ini_file('/etc/raspap/hostapd.ini');
|
||||
|
||||
$arrConfig = array();
|
||||
$arr80211Standard = array('a','b','g','n');
|
||||
$arrSecurity = array(1 => 'WPA', 2 => 'WPA2', 3 => 'WPA+WPA2', 'none' => _("None"));
|
||||
$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 (isset($_POST['SaveHostAPDSettings'])) {
|
||||
if (CSRFValidate()) {
|
||||
SaveHostAPDConfig($arrSecurity, $arrEncType, $arr80211Standard, $interfaces, $status);
|
||||
} else {
|
||||
error_log('CSRF violation');
|
||||
}
|
||||
} elseif( isset($_POST['StartHotspot']) ) {
|
||||
} elseif (isset($_POST['StartHotspot'])) {
|
||||
if (CSRFValidate()) {
|
||||
$status->addMessage('Attempting to start hotspot', 'info');
|
||||
if ($arrHostapdConf['WifiAPEnable'] == 1) {
|
||||
exec('sudo /etc/raspap/hostapd/servicestart.sh --interface uap0 --seconds 5', $return );
|
||||
exec('sudo /etc/raspap/hostapd/servicestart.sh --interface uap0 --seconds 5', $return);
|
||||
} else {
|
||||
exec( 'sudo /etc/raspap/hostapd/servicestart.sh --seconds 5', $return );
|
||||
exec('sudo /etc/raspap/hostapd/servicestart.sh --seconds 5', $return);
|
||||
}
|
||||
foreach( $return as $line ) {
|
||||
foreach ($return as $line) {
|
||||
$status->addMessage($line, 'info');
|
||||
}
|
||||
} else {
|
||||
error_log('CSRF violation');
|
||||
}
|
||||
} elseif( isset($_POST['StopHotspot']) ) {
|
||||
} 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 ) {
|
||||
exec('sudo /etc/init.d/hostapd stop', $return);
|
||||
foreach ($return as $line) {
|
||||
$status->addMessage($line, 'info');
|
||||
}
|
||||
} else {
|
||||
@ -50,21 +48,21 @@ function DisplayHostAPDConfig()
|
||||
}
|
||||
}
|
||||
|
||||
exec( 'cat '. RASPI_HOSTAPD_CONFIG, $hostapdconfig );
|
||||
exec( 'pidof hostapd | wc -l', $hostapdstatus);
|
||||
exec('cat '. RASPI_HOSTAPD_CONFIG, $hostapdconfig);
|
||||
exec('pidof hostapd | wc -l', $hostapdstatus);
|
||||
|
||||
if( $hostapdstatus[0] == 0 ) {
|
||||
if ($hostapdstatus[0] == 0) {
|
||||
$status->addMessage('HostAPD is not running', 'warning');
|
||||
} else {
|
||||
$status->addMessage('HostAPD is running', 'success');
|
||||
}
|
||||
|
||||
foreach( $hostapdconfig as $hostapdconfigline ) {
|
||||
foreach ($hostapdconfig as $hostapdconfigline) {
|
||||
if (strlen($hostapdconfigline) === 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($hostapdconfigline[0] != "#" ) {
|
||||
if ($hostapdconfigline[0] != "#") {
|
||||
$arrLine = explode("=", $hostapdconfigline) ;
|
||||
$arrConfig[$arrLine[0]]=$arrLine[1];
|
||||
}
|
||||
@ -111,26 +109,26 @@ function DisplayHostAPDConfig()
|
||||
<div class="form-group col-md-4">
|
||||
<label for="cbxhwmode"><?php echo _("Wireless Mode") ;?></label>
|
||||
<?php
|
||||
$selectedHwMode = $arrConfig['hw_mode'];
|
||||
if (isset($arrConfig['ieee80211n'])) {
|
||||
$selectedHwMode = $arrConfig['hw_mode'];
|
||||
if (isset($arrConfig['ieee80211n'])) {
|
||||
if (strval($arrConfig['ieee80211n']) === '1') {
|
||||
$selectedHwMode = 'n';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
SelectorOptions('hw_mode', $arr80211Standard, $selectedHwMode, 'cbxhwmode'); ?>
|
||||
SelectorOptions('hw_mode', $arr80211Standard, $selectedHwMode, 'cbxhwmode'); ?>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="form-group col-md-4">
|
||||
<label for="cbxchannel"><?php echo _("Channel"); ?></label>
|
||||
<?php
|
||||
$selectablechannels = range(1, 13);
|
||||
$countries_2_4Ghz_max11ch = array('AG', 'BS', 'BB', 'BZ', 'CR', 'CU', 'DM', 'DO', 'SV', 'GD', 'GT',
|
||||
$selectablechannels = range(1, 13);
|
||||
$countries_2_4Ghz_max11ch = array('AG', 'BS', 'BB', 'BZ', 'CR', 'CU', 'DM', 'DO', 'SV', 'GD', 'GT',
|
||||
'HT', 'HN', 'JM', 'MX', 'NI', 'PA', 'KN', 'LC', 'VC', 'TT',
|
||||
'US', 'CA', 'UZ', 'CO');
|
||||
$countries_2_4Ghz_max14ch = array('JA');
|
||||
if (in_array($arrConfig['country_code'], $countries_max11channels)) {
|
||||
$countries_2_4Ghz_max14ch = array('JA');
|
||||
if (in_array($arrConfig['country_code'], $countries_max11channels)) {
|
||||
// In North America till channel 11 is the maximum allowed wi-fi 2.4Ghz channel.
|
||||
// Except for the US that allows channel 12 & 13 in low power mode with additional restrictions.
|
||||
// Canada that allows channel 12 in low power mode. Because it's unsure if low powered mode
|
||||
@ -138,11 +136,11 @@ if (in_array($arrConfig['country_code'], $countries_max11channels)) {
|
||||
// source: https://en.wikipedia.org/wiki/List_of_WLAN_channels#Interference_concerns
|
||||
// Also Uzbekistan and Colombia allow to select till channel 11 as maximum channel on the 2.4Ghz wi-fi band.
|
||||
$selectablechannels = range(1, 11);
|
||||
} elseif (in_array($arrConfig['country_code'], $countries_2_4Ghz_max14ch)) {
|
||||
} elseif (in_array($arrConfig['country_code'], $countries_2_4Ghz_max14ch)) {
|
||||
if ($arrConfig['hw_mode'] === 'b') {
|
||||
$selectablechannels = range(1, 14);
|
||||
}
|
||||
}
|
||||
}
|
||||
SelectorOptions('channel', $selectablechannels, intval($arrConfig['channel']), 'cbxchannel'); ?>
|
||||
</div>
|
||||
</div>
|
||||
@ -173,7 +171,7 @@ if (in_array($arrConfig['country_code'], $countries_max11channels)) {
|
||||
<div class="row">
|
||||
<div class="form-group col-md-8">
|
||||
<?php
|
||||
if($arrHostapdConf['LogEnable'] == 1) {
|
||||
if ($arrHostapdConf['LogEnable'] == 1) {
|
||||
$log = file_get_contents('/tmp/hostapd.log');
|
||||
echo '<br /><textarea class="logoutput">'.htmlspecialchars($log, ENT_QUOTES).'</textarea>';
|
||||
} else {
|
||||
@ -499,7 +497,7 @@ for (var i = 0; i < ops.length; ++i) {
|
||||
</div><!-- /.panel-primary -->
|
||||
<input type="submit" class="btn btn-outline btn-primary" name="SaveHostAPDSettings" value="<?php echo _("Save settings"); ?>" />
|
||||
<?php
|
||||
if($hostapdstatus[0] == 0) {
|
||||
if ($hostapdstatus[0] == 0) {
|
||||
echo '<input type="submit" class="btn btn-success" name="StartHotspot" value="' . _("Start hotspot") . '"/>' , PHP_EOL;
|
||||
} else {
|
||||
echo '<input type="submit" class="btn btn-warning" name="StopHotspot" value="' . _("Stop hotspot") . '"/>' , PHP_EOL;
|
||||
@ -513,7 +511,8 @@ for (var i = 0; i < ops.length; ++i) {
|
||||
<?php
|
||||
}
|
||||
|
||||
function SaveHostAPDConfig($wpa_array, $enc_types, $modes, $interfaces, $status) {
|
||||
function SaveHostAPDConfig($wpa_array, $enc_types, $modes, $interfaces, $status)
|
||||
{
|
||||
// It should not be possible to send bad data for these fields so clearly
|
||||
// someone is up to something if they fail. Fail silently.
|
||||
if (!(array_key_exists($_POST['wpa'], $wpa_array) &&
|
||||
@ -537,27 +536,27 @@ function SaveHostAPDConfig($wpa_array, $enc_types, $modes, $interfaces, $status)
|
||||
|
||||
// Check for WiFi client AP mode checkbox
|
||||
$wifiAPEnable = 0;
|
||||
if($arrHostapdConf['WifiAPEnable'] == 0) {
|
||||
if(isset($_POST['wifiAPEnable'])) {
|
||||
if ($arrHostapdConf['WifiAPEnable'] == 0) {
|
||||
if (isset($_POST['wifiAPEnable'])) {
|
||||
$wifiAPEnable = 1;
|
||||
}
|
||||
} else {
|
||||
if(isset($_POST['wifiAPEnable'])) {
|
||||
if (isset($_POST['wifiAPEnable'])) {
|
||||
$wifiAPEnable = 1;
|
||||
}
|
||||
}
|
||||
|
||||
// Check for Logfile output checkbox
|
||||
$logEnable = 0;
|
||||
if($arrHostapdConf['LogEnable'] == 0) {
|
||||
if(isset($_POST['logEnable'])) {
|
||||
if ($arrHostapdConf['LogEnable'] == 0) {
|
||||
if (isset($_POST['logEnable'])) {
|
||||
$logEnable = 1;
|
||||
exec('sudo /etc/raspap/hostapd/enablelog.sh');
|
||||
} else {
|
||||
exec('sudo /etc/raspap/hostapd/disablelog.sh');
|
||||
}
|
||||
} else {
|
||||
if(isset($_POST['logEnable'])) {
|
||||
if (isset($_POST['logEnable'])) {
|
||||
$logEnable = 1;
|
||||
exec('sudo /etc/raspap/hostapd/enablelog.sh');
|
||||
} else {
|
||||
@ -567,7 +566,7 @@ function SaveHostAPDConfig($wpa_array, $enc_types, $modes, $interfaces, $status)
|
||||
$cfg = [];
|
||||
$cfg['LogEnable'] = $logEnable;
|
||||
$cfg['WifiAPEnable'] = $wifiAPEnable;
|
||||
write_php_ini($cfg,'/etc/raspap/hostapd.ini');
|
||||
write_php_ini($cfg, '/etc/raspap/hostapd.ini');
|
||||
|
||||
// Verify input
|
||||
if (empty($_POST['ssid']) || strlen($_POST['ssid']) > 32) {
|
||||
@ -639,7 +638,7 @@ function SaveHostAPDConfig($wpa_array, $enc_types, $modes, $interfaces, $status)
|
||||
$config.= 'ignore_broadcast_ssid='.$ignore_broadcast_ssid.PHP_EOL;
|
||||
|
||||
exec('echo "'.$config.'" > /tmp/hostapddata', $temp);
|
||||
system( "sudo cp /tmp/hostapddata " . RASPI_HOSTAPD_CONFIG, $return );
|
||||
system("sudo cp /tmp/hostapddata " . RASPI_HOSTAPD_CONFIG, $return);
|
||||
|
||||
if ($wifiAPEnable == 1) {
|
||||
// Enable uap0 configuration in dnsmasq for Wifi client AP mode
|
||||
@ -686,7 +685,7 @@ function SaveHostAPDConfig($wpa_array, $enc_types, $modes, $interfaces, $status)
|
||||
system('sudo cp /tmp/dhcpddata '.RASPI_DHCPCD_CONFIG, $return);
|
||||
|
||||
|
||||
if( $return == 0 ) {
|
||||
if ($return == 0) {
|
||||
$status->addMessage('Wifi Hotspot settings saved', 'success');
|
||||
} else {
|
||||
$status->addMessage('Unable to save wifi hotspot settings', 'danger');
|
||||
|
@ -1,11 +1,9 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Sets locale information for i18n support
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* Rudimentary language detection via the browser.
|
||||
* Accept-Language returns a list of weighted values with a quality (or 'q') parameter.
|
||||
@ -16,7 +14,7 @@
|
||||
*/
|
||||
if (empty($_SESSION['locale']) && strlen($_SERVER['HTTP_ACCEPT_LANGUAGE']) >= 2) {
|
||||
$lang = substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2);
|
||||
switch ($lang){
|
||||
switch ($lang) {
|
||||
case "de":
|
||||
$locale = "de_DE.UTF-8";
|
||||
break;
|
||||
@ -72,4 +70,3 @@ bindtextdomain(LOCALE_DOMAIN, LOCALE_ROOT);
|
||||
bind_textdomain_codeset(LOCALE_DOMAIN, 'UTF-8');
|
||||
|
||||
textdomain(LOCALE_DOMAIN);
|
||||
|
||||
|
@ -1,19 +1,20 @@
|
||||
<?php
|
||||
|
||||
include_once( 'includes/status_messages.php' );
|
||||
include_once('includes/status_messages.php');
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
*/
|
||||
function DisplayNetworkingConfig(){
|
||||
function DisplayNetworkingConfig()
|
||||
{
|
||||
|
||||
$status = new StatusMessages();
|
||||
|
||||
exec("ls /sys/class/net | grep -v lo", $interfaces);
|
||||
|
||||
foreach($interfaces as $interface) {
|
||||
exec("ip a show $interface",$$interface);
|
||||
foreach ($interfaces as $interface) {
|
||||
exec("ip a show $interface", $$interface);
|
||||
}
|
||||
|
||||
CSRFToken();
|
||||
@ -29,7 +30,7 @@ function DisplayNetworkingConfig(){
|
||||
<ul class="nav nav-tabs">
|
||||
<li role="presentation" class="active"><a href="#summary" aria-controls="summary" role="tab" data-toggle="tab"><?php echo _("Summary"); ?></a></li>
|
||||
<?php
|
||||
foreach($interfaces as $interface) {
|
||||
foreach ($interfaces as $interface) {
|
||||
echo '<li role="presentation"><a href="#'.htmlspecialchars($interface, ENT_QUOTES).'" aria-controls="'.htmlspecialchars($interface, ENT_QUOTES).'" role="tab" data-toggle="tab">'.htmlspecialchars($interface, ENT_QUOTES).'</a></li>';
|
||||
}
|
||||
?>
|
||||
@ -39,7 +40,7 @@ function DisplayNetworkingConfig(){
|
||||
<h4><?php echo _("Current settings"); ?></h4>
|
||||
<div class="row">
|
||||
<?php
|
||||
foreach($interfaces as $interface) {
|
||||
foreach ($interfaces as $interface) {
|
||||
echo '<div class="col-md-6">
|
||||
<div class="panel panel-default">
|
||||
<div class="panel-heading">'.htmlspecialchars($interface, ENT_QUOTES).'</div>
|
||||
@ -56,7 +57,7 @@ function DisplayNetworkingConfig(){
|
||||
</div><!-- /.col-lg-12 -->
|
||||
</div><!-- /.tab-pane -->
|
||||
<?php
|
||||
foreach($interfaces as $interface) {
|
||||
foreach ($interfaces as $interface) {
|
||||
echo '
|
||||
<div role="tabpanel" class="tab-pane fade in" id="'.htmlspecialchars($interface, ENT_QUOTES).'">
|
||||
<div class="row">
|
||||
@ -110,7 +111,7 @@ function DisplayNetworkingConfig(){
|
||||
</div>
|
||||
</div><!-- /.tab-panel -->
|
||||
</div>';
|
||||
}
|
||||
}
|
||||
?>
|
||||
</div><!-- /.tab-content -->
|
||||
</div><!-- /.panel-body -->
|
||||
|
@ -1,22 +1,30 @@
|
||||
<?php
|
||||
class StatusMessages {
|
||||
class StatusMessages
|
||||
{
|
||||
public $messages = array();
|
||||
|
||||
public function addMessage($message, $level='success', $dismissable=true) {
|
||||
public function addMessage($message, $level = 'success', $dismissable = true)
|
||||
{
|
||||
$status = '<div class="alert alert-'.$level;
|
||||
if ($dismissable) $status .= ' alert-dismissable';
|
||||
if ($dismissable) {
|
||||
$status .= ' alert-dismissable';
|
||||
}
|
||||
$status .= '">'. _($message);
|
||||
if ($dismissable) $status .= '<button type="button" class="close" data-dismiss="alert" aria-hidden="true">x</button>';
|
||||
if ($dismissable) {
|
||||
$status .= '<button type="button" class="close" data-dismiss="alert" aria-hidden="true">x</button>';
|
||||
}
|
||||
$status .= '</div>';
|
||||
|
||||
array_push($this->messages, $status);
|
||||
}
|
||||
|
||||
public function showMessages($clear = true) {
|
||||
foreach($this->messages as $message) {
|
||||
public function showMessages($clear = true)
|
||||
{
|
||||
foreach ($this->messages as $message) {
|
||||
echo $message;
|
||||
}
|
||||
if ( $clear ) $this->messages = array();
|
||||
if ($clear) {
|
||||
$this->messages = array();
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
include_once( 'includes/status_messages.php' );
|
||||
include_once('includes/status_messages.php');
|
||||
|
||||
/**
|
||||
*
|
||||
@ -9,7 +9,8 @@ include_once( 'includes/status_messages.php' );
|
||||
*
|
||||
*/
|
||||
|
||||
function RPiVersion() {
|
||||
function RPiVersion()
|
||||
{
|
||||
// Lookup table from http://www.raspberrypi-spy.co.uk/2012/09/checking-your-raspberry-pi-board-version/
|
||||
$revisions = array(
|
||||
'0002' => 'Model B Revision 1.0',
|
||||
@ -44,7 +45,7 @@ function RPiVersion() {
|
||||
|
||||
$cpuinfo_array = '';
|
||||
exec('cat /proc/cpuinfo', $cpuinfo_array);
|
||||
$rev = trim(array_pop(explode(':',array_pop(preg_grep("/^Revision/", $cpuinfo_array)))));
|
||||
$rev = trim(array_pop(explode(':', array_pop(preg_grep("/^Revision/", $cpuinfo_array)))));
|
||||
if (array_key_exists($rev, $revisions)) {
|
||||
return $revisions[$rev];
|
||||
} else {
|
||||
@ -56,13 +57,14 @@ function RPiVersion() {
|
||||
*
|
||||
*
|
||||
*/
|
||||
function DisplaySystem(){
|
||||
function DisplaySystem()
|
||||
{
|
||||
|
||||
$status = new StatusMessages();
|
||||
|
||||
if( isset($_POST['SaveLanguage']) ) {
|
||||
if (isset($_POST['SaveLanguage'])) {
|
||||
if (CSRFValidate()) {
|
||||
if(isset($_POST['locale'])) {
|
||||
if (isset($_POST['locale'])) {
|
||||
$_SESSION['locale'] = $_POST['locale'];
|
||||
$status->addMessage('Language setting saved', 'success');
|
||||
}
|
||||
@ -101,25 +103,39 @@ function DisplaySystem(){
|
||||
$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 ':' '); }
|
||||
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
|
||||
$memused_status = "primary";
|
||||
exec("free -m | awk '/Mem:/ { total=$2 ; 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"; }
|
||||
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"; }
|
||||
if ($cpuload > 90) {
|
||||
$cpuload_status = "danger";
|
||||
} elseif ($cpuload > 75) {
|
||||
$cpuload_status = "warning";
|
||||
} elseif ($cpuload > 0) {
|
||||
$cpuload_status = "success";
|
||||
}
|
||||
|
||||
?>
|
||||
<div class="row">
|
||||
@ -129,14 +145,14 @@ function DisplaySystem(){
|
||||
<div class="panel-body">
|
||||
|
||||
<?php
|
||||
if (isset($_POST['system_reboot'])) {
|
||||
if (isset($_POST['system_reboot'])) {
|
||||
echo '<div class="alert alert-warning">' . _("System Rebooting Now!") . '</div>';
|
||||
$result = shell_exec("sudo /sbin/reboot");
|
||||
}
|
||||
if (isset($_POST['system_shutdown'])) {
|
||||
}
|
||||
if (isset($_POST['system_shutdown'])) {
|
||||
echo '<div class="alert alert-warning">' . _("System Shutting Down Now!") . '</div>';
|
||||
$result = shell_exec("sudo /sbin/shutdown -h now");
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
||||
<div class="row">
|
||||
|
@ -3,13 +3,14 @@
|
||||
*
|
||||
*
|
||||
*/
|
||||
function DisplayThemeConfig(){
|
||||
function DisplayThemeConfig()
|
||||
{
|
||||
|
||||
$cselected = '';
|
||||
$hselected = '';
|
||||
$tselected = '';
|
||||
|
||||
switch( $_COOKIE['theme'] ) {
|
||||
switch ($_COOKIE['theme']) {
|
||||
case "custom.css":
|
||||
$cselected = ' selected="selected"';
|
||||
break;
|
||||
@ -21,7 +22,7 @@ function DisplayThemeConfig(){
|
||||
break;
|
||||
}
|
||||
|
||||
?>
|
||||
?>
|
||||
<div class="row">
|
||||
<div class="col-lg-12">
|
||||
<div class="panel panel-primary">
|
||||
@ -57,6 +58,6 @@ function DisplayThemeConfig(){
|
||||
</div><!-- /.panel-primary -->
|
||||
</div><!-- /.col-lg-12 -->
|
||||
</div><!-- /.row -->
|
||||
<?php
|
||||
<?php
|
||||
}
|
||||
|
||||
|
54
index.php
54
index.php
@ -20,21 +20,21 @@
|
||||
|
||||
session_start();
|
||||
|
||||
include_once( 'includes/config.php' );
|
||||
include_once( RASPI_CONFIG.'/raspap.php' );
|
||||
include_once( 'includes/locale.php');
|
||||
include_once( 'includes/functions.php' );
|
||||
include_once( 'includes/dashboard.php' );
|
||||
include_once( 'includes/authenticate.php' );
|
||||
include_once( 'includes/admin.php' );
|
||||
include_once( 'includes/dhcp.php' );
|
||||
include_once( 'includes/hostapd.php' );
|
||||
include_once( 'includes/system.php' );
|
||||
include_once( 'includes/configure_client.php' );
|
||||
include_once( 'includes/networking.php' );
|
||||
include_once( 'includes/themes.php' );
|
||||
include_once( 'includes/data_usage.php' );
|
||||
include_once( 'includes/about.php' );
|
||||
include_once('includes/config.php');
|
||||
include_once(RASPI_CONFIG.'/raspap.php');
|
||||
include_once('includes/locale.php');
|
||||
include_once('includes/functions.php');
|
||||
include_once('includes/dashboard.php');
|
||||
include_once('includes/authenticate.php');
|
||||
include_once('includes/admin.php');
|
||||
include_once('includes/dhcp.php');
|
||||
include_once('includes/hostapd.php');
|
||||
include_once('includes/system.php');
|
||||
include_once('includes/configure_client.php');
|
||||
include_once('includes/networking.php');
|
||||
include_once('includes/themes.php');
|
||||
include_once('includes/data_usage.php');
|
||||
include_once('includes/about.php');
|
||||
|
||||
$output = $return = 0;
|
||||
$page = $_GET['page'];
|
||||
@ -48,7 +48,7 @@ if (empty($_SESSION['csrf_token'])) {
|
||||
}
|
||||
$csrf_token = $_SESSION['csrf_token'];
|
||||
|
||||
if(!isset($_COOKIE['theme'])) {
|
||||
if (!isset($_COOKIE['theme'])) {
|
||||
$theme = "custom.css";
|
||||
} else {
|
||||
$theme = $_COOKIE['theme'];
|
||||
@ -122,47 +122,47 @@ $theme_url = 'dist/css/'.htmlspecialchars($theme, ENT_QUOTES);
|
||||
<li>
|
||||
<a href="index.php?page=wlan0_info"><i class="fa fa-dashboard fa-fw"></i> <?php echo _("Dashboard"); ?></a>
|
||||
</li>
|
||||
<?php if ( RASPI_WIFICLIENT_ENABLED ) : ?>
|
||||
<?php if (RASPI_WIFICLIENT_ENABLED) : ?>
|
||||
<li>
|
||||
<a href="index.php?page=wpa_conf"><i class="fa fa-wifi fa-fw"></i> <?php echo _("Configure WiFi client"); ?></a>
|
||||
</li>
|
||||
<?php endif; ?>
|
||||
<?php if ( RASPI_HOTSPOT_ENABLED ) : ?>
|
||||
<?php if (RASPI_HOTSPOT_ENABLED) : ?>
|
||||
<li>
|
||||
<a href="index.php?page=hostapd_conf"><i class="fa fa-dot-circle-o fa-fw"></i> <?php echo _("Configure hotspot"); ?></a>
|
||||
</li>
|
||||
<?php endif; ?>
|
||||
<?php if ( RASPI_NETWORK_ENABLED ) : ?>
|
||||
<?php if (RASPI_NETWORK_ENABLED) : ?>
|
||||
<li>
|
||||
<a href="index.php?page=network_conf"><i class="fa fa-sitemap fa-fw"></i> <?php echo _("Configure networking"); ?></a>
|
||||
</li>
|
||||
<?php endif; ?>
|
||||
<?php if ( RASPI_DHCP_ENABLED ) : ?>
|
||||
<?php if (RASPI_DHCP_ENABLED) : ?>
|
||||
<li>
|
||||
<a href="index.php?page=dhcpd_conf"><i class="fa fa-exchange fa-fw"></i> <?php echo _("Configure DHCP Server"); ?></a>
|
||||
</li>
|
||||
<?php endif; ?>
|
||||
<?php if ( RASPI_OPENVPN_ENABLED ) : ?>
|
||||
<?php if (RASPI_OPENVPN_ENABLED) : ?>
|
||||
<li>
|
||||
<a href="index.php?page=openvpn_conf"><i class="fa fa-lock fa-fw"></i> <?php echo _("Configure OpenVPN"); ?></a>
|
||||
</li>
|
||||
<?php endif; ?>
|
||||
<?php if ( RASPI_TORPROXY_ENABLED ) : ?>
|
||||
<?php if (RASPI_TORPROXY_ENABLED) : ?>
|
||||
<li>
|
||||
<a href="index.php?page=torproxy_conf"><i class="fa fa-eye-slash fa-fw"></i> <?php echo _("Configure TOR proxy"); ?></a>
|
||||
</li>
|
||||
<?php endif; ?>
|
||||
<?php if ( RASPI_CONFAUTH_ENABLED ) : ?>
|
||||
<?php if (RASPI_CONFAUTH_ENABLED) : ?>
|
||||
<li>
|
||||
<a href="index.php?page=auth_conf"><i class="fa fa-lock fa-fw"></i> <?php echo _("Configure Auth"); ?></a>
|
||||
</li>
|
||||
<?php endif; ?>
|
||||
<?php if ( RASPI_CHANGETHEME_ENABLED ) : ?>
|
||||
<?php if (RASPI_CHANGETHEME_ENABLED) : ?>
|
||||
<li>
|
||||
<a href="index.php?page=theme_conf"><i class="fa fa-wrench fa-fw"></i> <?php echo _("Change Theme"); ?></a>
|
||||
</li>
|
||||
<?php endif; ?>
|
||||
<?php if ( RASPI_VNSTAT_ENABLED ) : ?>
|
||||
<?php if (RASPI_VNSTAT_ENABLED) : ?>
|
||||
<li>
|
||||
<a href="index.php?page=data_use"><i class="fa fa-bar-chart fa-fw"></i> <?php echo _("Data usage"); ?></a>
|
||||
</li>
|
||||
@ -190,9 +190,9 @@ $theme_url = 'dist/css/'.htmlspecialchars($theme, ENT_QUOTES);
|
||||
</div><!-- /.row -->
|
||||
|
||||
<?php
|
||||
$extraFooterScripts = array();
|
||||
$extraFooterScripts = array();
|
||||
// handle page actions
|
||||
switch( $page ) {
|
||||
switch ($page) {
|
||||
case "wlan0_info":
|
||||
DisplayDashboard();
|
||||
break;
|
||||
|
@ -5,11 +5,10 @@ $config = array(
|
||||
'admin_pass' => '$2y$10$YKIyWAmnQLtiJAy6QgHQ.eCpY4m.HCEbiHaTgN6.acNC6bDElzt.i'
|
||||
);
|
||||
|
||||
if(file_exists(RASPI_CONFIG.'/raspap.auth')) {
|
||||
if ( $auth_details = fopen(RASPI_CONFIG.'/raspap.auth', 'r') ) {
|
||||
if (file_exists(RASPI_CONFIG.'/raspap.auth')) {
|
||||
if ($auth_details = fopen(RASPI_CONFIG.'/raspap.auth', 'r')) {
|
||||
$config['admin_user'] = trim(fgets($auth_details));
|
||||
$config['admin_pass'] = trim(fgets($auth_details));
|
||||
fclose($auth_details);
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
Loading…
x
Reference in New Issue
Block a user