mirror of
https://github.com/billz/raspap-webgui.git
synced 2025-03-01 10:31:47 +00:00
Initial commit to enable logging for hostapd
This commit is contained in:
@@ -1,47 +1,4 @@
|
||||
<?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();
|
||||
include_once('../../includes/config.php');
|
||||
include_once('../../includes/functions.php');
|
||||
|
Reference in New Issue
Block a user