/** * */ public function truncate() { $defaultHeader = $this->getDefaultHeader(); $this->close(); if (WFWAF_IS_WINDOWS) { file_put_contents($this->getFile(), $defaultHeader, LOCK_EX); } else { wfWAFStorageFile::atomicFilePutContents($this->getFile(), $defaultHeader, 'attack'); } $this->header = array(); $this->offsetTable = array(); $this->open(); }
/** * @param $rules * @param bool|int $updateLastUpdatedTimestamp * @throws wfWAFBuildRulesException */ public function updateRuleSet($rules, $updateLastUpdatedTimestamp = true) { try { if (is_string($rules)) { $ruleString = $rules; $parser = new wfWAFRuleParser(new wfWAFRuleLexer($rules), $this); $rules = $parser->parse(); } if (!is_writable($this->getCompiledRulesFile())) { throw new wfWAFBuildRulesException('Rules file not writable.'); } wfWAFStorageFile::atomicFilePutContents($this->getCompiledRulesFile(), sprintf(<<<PHP <?php if (!defined('WFWAF_VERSION')) { \texit('Access denied'); } /* \tThis file is generated automatically. Any changes made will be lost. */ %s?> PHP , $this->buildRuleSet($rules)), 'rules'); if (!empty($ruleString) && !WFWAF_DEBUG) { wfWAFStorageFile::atomicFilePutContents($this->getStorageEngine()->getRulesDSLCacheFile(), $ruleString, 'rules'); } if ($updateLastUpdatedTimestamp) { $this->getStorageEngine()->setConfig('rulesLastUpdated', is_int($updateLastUpdatedTimestamp) ? $updateLastUpdatedTimestamp : time()); } } catch (wfWAFBuildRulesException $e) { // Do something. throw $e; } }