Merged in feature/MAW-855-import-code-into-aws (pull request #2)
code import from pantheon * code import from pantheon
This commit is contained in:
@@ -17,8 +17,7 @@ class wfWAFStorageFile implements wfWAFStorageInterface {
|
||||
return true;
|
||||
}
|
||||
|
||||
$sapi = @php_sapi_name();
|
||||
if ($sapi == "cli") {
|
||||
if (wfWAFUtils::isCli()) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
||||
@@ -1098,13 +1098,12 @@ class wfWAFUtils {
|
||||
$offset = wfWAF::getInstance()->getStorageEngine()->getConfig('timeoffset_ntp', false, 'synced');
|
||||
if ($offset === false) {
|
||||
$offset = wfWAF::getInstance()->getStorageEngine()->getConfig('timeoffset_wf', false, 'synced');
|
||||
if ($offset === false) { $offset = 0; }
|
||||
}
|
||||
}
|
||||
catch (Exception $e) {
|
||||
//Ignore
|
||||
}
|
||||
return time() + $offset;
|
||||
return time() + ((int) $offset);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1164,17 +1163,30 @@ class wfWAFUtils {
|
||||
'pass' => 'DB_PASSWORD',
|
||||
'database' => 'DB_NAME',
|
||||
'host' => 'DB_HOST',
|
||||
'charset' => 'DB_CHARSET',
|
||||
'collation' => 'DB_COLLATE'
|
||||
'charset' => array('constant' => 'DB_CHARSET', 'default' => ''),
|
||||
'collation' => array('constant' => 'DB_COLLATE', 'default' => ''),
|
||||
);
|
||||
$constants += $optionalConstants;
|
||||
foreach ($constants as $key => $constant) {
|
||||
unset($defaultValue);
|
||||
if (is_array($constant)) {
|
||||
$defaultValue = $constant['default'];
|
||||
$constant = $constant['constant'];
|
||||
}
|
||||
|
||||
if (array_key_exists($key, $return)) {
|
||||
continue;
|
||||
} else if (array_key_exists($constant, $parsedConstants)) {
|
||||
}
|
||||
else if (array_key_exists($constant, $parsedConstants)) {
|
||||
$return[$key] = $parsedConstants[$constant];
|
||||
} else if (!array_key_exists($key, $optionalConstants)){
|
||||
return ($return = false);
|
||||
}
|
||||
else if (!array_key_exists($key, $optionalConstants)){
|
||||
if (isset($defaultValue)) {
|
||||
$return[$key] = $defaultValue;
|
||||
}
|
||||
else {
|
||||
return ($return = false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1229,6 +1241,9 @@ class wfWAFUtils {
|
||||
public static function isVersionBelow($target, $compared) {
|
||||
return $compared === null || version_compare($compared, $target, '<');
|
||||
}
|
||||
|
||||
|
||||
public static function isCli() {
|
||||
return (@php_sapi_name()==='cli') || !array_key_exists('REQUEST_METHOD', $_SERVER);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -328,6 +328,11 @@ auEa+7b+FGTKs7dUo2BNGR7OVifK4GZ8w/ajS0TelhrSRi3BBQCGXLzUO/UURUAh
|
||||
public function loadRules() {
|
||||
$storageEngine = $this->getStorageEngine();
|
||||
if ($storageEngine instanceof wfWAFStorageFile) {
|
||||
$logLevel = error_reporting();
|
||||
if (wfWAFUtils::isCli()) { //Done to suppress errors from WP-CLI when the WAF is run on environments that have a server level constant to use the MySQLi storage engine that is not in place when running from the CLI
|
||||
error_reporting(0);
|
||||
}
|
||||
|
||||
// Acquire lock on this file so we're not including it while it's being written in another process.
|
||||
$handle = fopen($storageEngine->getRulesFile(), 'r');
|
||||
$locked = $handle !== false && flock($handle, LOCK_SH);
|
||||
@@ -337,6 +342,10 @@ auEa+7b+FGTKs7dUo2BNGR7OVifK4GZ8w/ajS0TelhrSRi3BBQCGXLzUO/UURUAh
|
||||
flock($handle, LOCK_UN);
|
||||
if ($handle !== false)
|
||||
fclose($handle);
|
||||
|
||||
if (wfWAFUtils::isCli()) {
|
||||
error_reporting($logLevel);
|
||||
}
|
||||
} else {
|
||||
$wafRules = $storageEngine->getRules();
|
||||
if (is_array($wafRules)) {
|
||||
|
||||
Reference in New Issue
Block a user