tackDataStorageFileEngineScanRowCallback {
/**
* @var int
*/
private $newerThan;
/**
* wfWAFStorageFileEngineScanRowAttackDataNewer constructor.
* @param int $newerThan
*/
public function __construct($newerThan) {
$this->newerThan = $newerThan;
}
/**
* @param resource $handle
* @param int $offset
* @param int $length
* @return bool
*/
public function scanRow($handle, $offset, $length) {
$attackLogTimeBin = fread($handle, 8);
list(, $attackLogSeconds, $attackLogMicroseconds) = @unpack('VV', $attackLogTimeBin);
$attackLogTime = $attackLogSeconds . '.' . $attackLogMicroseconds;
return $this->newerThan < $attackLogTime;
}
}
class wfWAFAttackDataStorageFileEngineScanRowAttackDataOlder implements wfWAFAttackDataStorageFileEngineScanRowCallback {
/**
* @var int
*/
private $olderThan;
/**
* wfWAFStorageFileEngineScanRowAttackDataNewer constructor.
* @param int $olderThan
*/
public function __construct($olderThan) {
$this->olderThan = $olderThan;
}
/**
* @param resource $handle
* @param int $offset
* @param int $length
* @return bool
*/
public function scanRow($handle, $offset, $length) {
$attackLogTimeBin = fread($handle, 8);
list(, $attackLogSeconds, $attackLogMicroseconds) = @unpack('VV', $attackLogTimeBin);
$attackLogTime = $attackLogSeconds . '.' . $attackLogMicroseconds;
return $this->olderThan > $attackLogTime;
}
}
class wfWAFAttackDataStorageFileEngineRow {
/**
* @param string $binary
* @return wfWAFAttackDataStorageFileEngineRow
*/
public static function unpack($binary) {
$attackLogTime = wfWAFAttackDataStorageFileEngine::unpackMicrotime(wfWAFUtils::substr($binary, 0, 8));
$data = wfWAFAttackDataStorageFileEngine::decompress(wfWAFUtils::substr($binary, 8));
return new self($attackLogTime, $data);
}
/**
* @var float|string
*/
private $timestamp;
/**
* @var string
*/
private $data;
/**
* @param float $timestamp
* @param string $data
*/
public function __construct($timestamp, $data) {
$this->timestamp = $timestamp;
$this->data = $data;
}
/**
* @return string
*/
public function pack() {
return wfWAFAttackDataStorageFileEngine::packMicrotime($this->getTimestamp()) . wfWAFAttackDataStorageFileEngine::compress($this->getData());
}
/**
* @return float|string
*/
public function getTimestamp() {
return $this->timestamp;
}
/**
* @param float|string $timestamp
*/
public function setTimestamp($timestamp) {
$this->timestamp = $timestamp;
}
/**
* @return string
*/
public function getData() {
return $this->data;
}
/**
* @param string $data
*/
public function setData($data) {
$this->data = $data;
}
}
abstract class wfWAFStorageFileCompressionAlgo {
abstract public function isUsable();
abstract public function compress($string);
abstract public function decompress($binary);
/**
* @param string $string
* @return bool
*/
public function testCompression($string) {
$compressed = $this->compress($string);
if ($string === $this->decompress($compressed)) {
return $compressed;
}
return false;
}
}
class wfWAFStorageFileCompressionGZDeflate extends wfWAFStorageFileCompressionAlgo {
public function isUsable() {
return function_exists('gzinflate') && function_exists('gzdeflate');
}
public function compress($string) {
return @gzdeflate($string);
}
public function decompress($binary) {
return @gzinflate($binary);
}
}
class wfWAFStorageFileCompressionGZCompress extends wfWAFStorageFileCompressionAlgo {
public function isUsable() {
return function_exists('gzuncompress') && function_exists('gzcompress');
}
public function compress($string) {
return @gzcompress($string);
}
public function decompress($binary) {
return @gzuncompress($binary);
}
}
class wfWAFStorageFileCompressionGZEncode extends wfWAFStorageFileCompressionAlgo {
public function isUsable() {
return function_exists('gzencode') && function_exists('gzdecode');
}
public function compress($string) {
return @gzencode($string);
}
public function decompress($binary) {
return @gzdecode($binary);
}
}
class wfWAFStorageFileException extends wfWAFException {
}
class wfWAFStorageFileConfigException extends wfWAFStorageFileException {
}
}