mirror of
https://github.com/billz/raspap-webgui.git
synced 2023-10-10 13:37:24 +02:00
Initial commit to enable logging for hostapd
This commit is contained in:
parent
8d77295fd3
commit
7845c8908b
@ -1,47 +1,4 @@
|
|||||||
<?php
|
<?php
|
||||||
function mask2cidr($mask){
|
|
||||||
$long = ip2long($mask);
|
|
||||||
$base = ip2long('255.255.255.255');
|
|
||||||
return 32-log(($long ^ $base)+1,2);
|
|
||||||
}
|
|
||||||
|
|
||||||
function write_php_ini($array, $file) {
|
|
||||||
$res = array();
|
|
||||||
foreach($array as $key => $val) {
|
|
||||||
if(is_array($val)) {
|
|
||||||
$res[] = "[$key]";
|
|
||||||
foreach($val as $skey => $sval) $res[] = "$skey = ".(is_numeric($sval) ? $sval : '"'.$sval.'"');
|
|
||||||
}
|
|
||||||
else $res[] = "$key = ".(is_numeric($val) ? $val : '"'.$val.'"');
|
|
||||||
}
|
|
||||||
if(safefilerewrite($file, implode("\r\n", $res))) {
|
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function safefilerewrite($fileName, $dataToSave) {
|
|
||||||
if ($fp = fopen($fileName, 'w')) {
|
|
||||||
$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));
|
|
||||||
|
|
||||||
//file was locked so now we can store information
|
|
||||||
if ($canWrite) {
|
|
||||||
fwrite($fp, $dataToSave);
|
|
||||||
flock($fp, LOCK_UN);
|
|
||||||
}
|
|
||||||
fclose($fp);
|
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
session_start();
|
session_start();
|
||||||
include_once('../../includes/config.php');
|
include_once('../../includes/config.php');
|
||||||
include_once('../../includes/functions.php');
|
include_once('../../includes/functions.php');
|
||||||
|
5
dist/css/custom.css
vendored
5
dist/css/custom.css
vendored
@ -48,3 +48,8 @@
|
|||||||
height:100%;
|
height:100%;
|
||||||
min-height:500px;
|
min-height:500px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.logoutput {
|
||||||
|
width:100%;
|
||||||
|
height:300px;
|
||||||
|
}
|
||||||
|
@ -1,4 +1,52 @@
|
|||||||
<?php
|
<?php
|
||||||
|
/* Functions for Networking */
|
||||||
|
|
||||||
|
function mask2cidr($mask){
|
||||||
|
$long = ip2long($mask);
|
||||||
|
$base = ip2long('255.255.255.255');
|
||||||
|
return 32-log(($long ^ $base)+1,2);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Functions to write ini files */
|
||||||
|
|
||||||
|
function write_php_ini($array, $file) {
|
||||||
|
$res = array();
|
||||||
|
foreach($array as $key => $val) {
|
||||||
|
if(is_array($val)) {
|
||||||
|
$res[] = "[$key]";
|
||||||
|
foreach($val as $skey => $sval) $res[] = "$skey = ".(is_numeric($sval) ? $sval : '"'.$sval.'"');
|
||||||
|
}
|
||||||
|
else $res[] = "$key = ".(is_numeric($val) ? $val : '"'.$val.'"');
|
||||||
|
}
|
||||||
|
if(safefilerewrite($file, implode("\r\n", $res))) {
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function safefilerewrite($fileName, $dataToSave) {
|
||||||
|
if ($fp = fopen($fileName, 'w')) {
|
||||||
|
$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));
|
||||||
|
|
||||||
|
//file was locked so now we can store information
|
||||||
|
if ($canWrite) {
|
||||||
|
fwrite($fp, $dataToSave);
|
||||||
|
flock($fp, LOCK_UN);
|
||||||
|
}
|
||||||
|
fclose($fp);
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
@ -10,6 +10,8 @@ function DisplayHostAPDConfig(){
|
|||||||
|
|
||||||
$status = new StatusMessages();
|
$status = new StatusMessages();
|
||||||
|
|
||||||
|
$arrHostapdConf = parse_ini_file('/etc/raspap/hostapd.ini');
|
||||||
|
|
||||||
$arrConfig = array();
|
$arrConfig = array();
|
||||||
$arrChannel = array('a','b','g');
|
$arrChannel = array('a','b','g');
|
||||||
$arrSecurity = array( 1 => 'WPA', 2 => 'WPA2',3=> 'WPA+WPA2');
|
$arrSecurity = array( 1 => 'WPA', 2 => 'WPA2',3=> 'WPA+WPA2');
|
||||||
@ -74,6 +76,7 @@ function DisplayHostAPDConfig(){
|
|||||||
<li class="active"><a href="#basic" data-toggle="tab">Basic</a></li>
|
<li class="active"><a href="#basic" data-toggle="tab">Basic</a></li>
|
||||||
<li><a href="#security" data-toggle="tab">Security</a></li>
|
<li><a href="#security" data-toggle="tab">Security</a></li>
|
||||||
<li><a href="#advanced" data-toggle="tab">Advanced</a></li>
|
<li><a href="#advanced" data-toggle="tab">Advanced</a></li>
|
||||||
|
<li><a href="#logoutput" data-toggle="tab">Logfile Output</a></li>
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
<!-- Tab panes -->
|
<!-- Tab panes -->
|
||||||
@ -130,8 +133,28 @@ function DisplayHostAPDConfig(){
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="tab-pane fade" id="logoutput">
|
||||||
|
<?php
|
||||||
|
if($arrHostapdConf['LogEnable'] == 1) {
|
||||||
|
$log = file_get_contents('/tmp/hostapd.log');
|
||||||
|
echo 'Logfile contents:<br /><textarea class="logoutput">'.$log.'</textarea>';
|
||||||
|
} else {
|
||||||
|
echo "Logfile output not enabled";
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
</div>
|
||||||
<div class="tab-pane fade" id="advanced">
|
<div class="tab-pane fade" id="advanced">
|
||||||
<h4>Advanced settings</h4>
|
<h4>Advanced settings</h4>
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-md-4">
|
||||||
|
<div class="form-check">
|
||||||
|
<label class="form-check-label">
|
||||||
|
Enable Logging <?php $checked = ''; if($arrHostapdConf['LogEnable'] == 1) { $checked = 'checked'; } ?>
|
||||||
|
<input id="logEnable" name ="logEnable" type="checkbox" class="form-check-input" value="1" <?php echo $checked; ?> />
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="form-group col-md-4">
|
<div class="form-group col-md-4">
|
||||||
<label for="code">Country Code</label>
|
<label for="code">Country Code</label>
|
||||||
@ -431,6 +454,24 @@ function SaveHostAPDConfig($wpa_array, $enc_types, $modes, $interfaces, $status)
|
|||||||
|
|
||||||
$good_input = true;
|
$good_input = true;
|
||||||
|
|
||||||
|
// Check for Logging Checkbox
|
||||||
|
$logEnable = 0;
|
||||||
|
if($arrHostapdConf['LogEnable'] == 0) {
|
||||||
|
if(isset($_POST['logEnable'])) {
|
||||||
|
// Need code to enable logfile logging here
|
||||||
|
$logEnable = 1;
|
||||||
|
exec('sudo /bin/sed -i "\'"\'s|#DAEMON_OPTS=""|DAEMON_OPTS=" -f /tmp/hostapd.log"|\'"\'" /etc/default/hostapd');
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if(isset($_POST['logEnable'])) {
|
||||||
|
$logEnable = 1;
|
||||||
|
exec('sudo /bin/sed -i "\'"\'s|#DAEMON_OPTS=""|DAEMON_OPTS=" -f /tmp/hostapd.log"|\'"\'" /etc/default/hostapd');
|
||||||
|
} else {
|
||||||
|
exec('sudo /bin/sed -i "\'"\'s|DAEMON_OPTS=" -f /tmp/hostapd.log"|#DAEMON_OPTS=""|\'"\'" /etc/default/hostapd');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
write_php_ini(["LogEnable" => $logEnable],'/etc/raspap/hostapd.ini');
|
||||||
|
|
||||||
// Verify input
|
// Verify input
|
||||||
if (strlen($_POST['ssid']) == 0 || strlen($_POST['ssid']) > 32) {
|
if (strlen($_POST['ssid']) == 0 || strlen($_POST['ssid']) > 32) {
|
||||||
// Not sure of all the restrictions of SSID
|
// Not sure of all the restrictions of SSID
|
||||||
|
Loading…
Reference in New Issue
Block a user