public static function setup(PWECore $pwe, array &$registerData) { if (!is_dir(self::getHTMLDirectory($pwe))) { PWELogger::info("Creating HTML directory: %s", self::getHTMLDirectory($pwe)); mkdir(self::getHTMLDirectory($pwe), null, true); } }
public function getPypiInfo() { $fname = $this->PWE->getTempDirectory() . "/bzt-pypi.json"; if (!file_exists($fname) || time() - filemtime($fname) > 60 * 60) { $url = "https://pypi.python.org/pypi/bzt/json"; \PWE\Core\PWELogger::info("Refresh PyPi cache: %s", $url); file_put_contents($fname, fopen($url, 'r')); } return json_decode(file_get_contents($fname), true); }
function __construct($message, $code = HTTP3xxException::REDIRECT) { parent::__construct($message, $code); PWELogger::info("Redirect to address %s: %s", $message, $this); if ($code == 301 || $code == 302) { if (!headers_sent()) { // TODO: use full URI since http 1.1 require it header("Location: {$message}"); } else { PWELogger::warn("Cannot send headers to redirect to %s", $message); } } }
/** * @param \PWE\Core\PWECore $pwe * @return PWEUserAuthController */ public static function getAuthControllerInstance(PWECore $pwe) { try { $node = $pwe->getNode(); } catch (HTTP5xxException $e) { PWELogger::warn('Failed to get pwe node in auth controller: %s', $e); } if (!isset($node['!i']['authController']) || $node['!i']['authController'] == 'none') { return new NoneAuthController($pwe); } if ($node['!i']['authController'] != NoneAuthController::getClassName()) { PWELogger::info('Page requires auth: %s', $node['!i']['authController']); } return new $node['!i']['authController']($pwe); }
public function test_directory_sorted() { $pwe = new UnitTestPWECore(); $pwe->setURL('/'); $tmp = $pwe->getTempDirectory(); $pwe->setRootDirectory($tmp); $pwe->setTempDirectory($tmp); PWELogger::info("Create dir " . $tmp); file_put_contents($tmp . '/first', time()); file_put_contents($tmp . '/second', time()); PWELogger::debug("File 1 " . file_get_contents($tmp . '/first')); PWELogger::debug("File 2 " . file_get_contents($tmp . '/second')); $node =& $pwe->getNode(); $node['!a']['files_base'] = '.'; $obj = new FileDownloads($pwe); $res = $obj->getDirectoryBlock('.'); PWELogger::debug("DIR: " . $res); $this->assertGreaterThan(strpos($res, 'second'), strpos($res, 'first')); }
private function preprocess_file_gen($filename, $dst, $tagType, $ext) { $startTag = "<{$tagType} "; $endTag = "</{$tagType}>"; $orig = file_get_contents($filename); $origSize = strlen($orig); $result = ""; $pos = 0; $prevPos = 0; while (($pos = strpos($orig, $startTag, $pos)) !== false) { $pos_end = strpos($orig, $endTag, $pos); if ($pos_end !== FALSE) { $result .= substr($orig, $prevPos, $pos - $prevPos); $cand = substr($orig, $pos, $pos_end - $pos + strlen($endTag)); $marker = $this->getPreprocessMarker($cand, $tagType); if ($marker) { PWELogger::info("Found block to write into: %s%s", $marker, $ext); $dst_file = $dst . '/' . $marker . $ext; $inner = $this->getInner($cand, $filename); if ($inner) { file_put_contents($dst_file, "/* {$filename} */\n" . $inner . "\n\n", FILE_APPEND); } $pos += strlen($cand); } } $prevPos = $pos; $pos++; if ($pos > $origSize) { break; } } $result .= substr($orig, $prevPos, strlen($orig) - $prevPos); if ($result != $orig) { copy($filename, $filename . $ext . ".bak"); file_put_contents($filename, $result); } }
protected function saveRegistry() { if (!$this->registryFile) { PWELogger::warn("No registry file set, won't try to save registry"); return; } try { PWEXML::cleanEmptyNodes($this->registryArray['registry'][0]); } catch (PHPFatalException $e) { PWELogger::warn("Failed cleaning empty nodes: %s", $e); } PWELogger::info("Saving registry file: %s", $this->registryFile); $XML = new PWEXML($this->PWE->getTempDirectory()); $XML->ArrayToFile($this->registryArray, $this->registryFile); $XML->FileToArray($this->registryFile, $this->registryArray); }
public function soakFile(Connection $DB, $filename) { PWELogger::info('Processing SQL-file: %s', $filename); $sql = file_get_contents($filename); $splitter = strstr($sql, ";\r\n") ? ";\r\n" : ";\n"; $sqls = explode($splitter, $sql); foreach ($sqls as $sql) { if (strlen(trim($sql))) { $DB->query($sql); } } }
public function testInfo() { PWELogger::info("informing"); }
/** * Jump to first child feature */ private function jumpToFirstChild() { $eg_node = $this->getNode(); if (isset($eg_node['!a']['class']) || sizeof($this->URL->getParamsAsArray()) || !isset($eg_node['!c']['url'])) { return; } foreach ($eg_node['!c']['url'] as $v) { PWELogger::info('Jump To First Сhild: %s', $v['!a']['link']); $jumpTo = $v['!a']['link'] . '/'; if (isset($_SERVER["QUERY_STRING"]) && strlen($_SERVER["QUERY_STRING"])) { $jumpTo .= '?' . $_SERVER["QUERY_STRING"]; } throw new HTTP3xxException($jumpTo, HTTP3xxException::REDIRECT); } }
$PWECore = new PWECore(); PWEAutoloader::setPWE($PWECore); $uri = $_SERVER['REDIRECT_URL'] ? $_SERVER['REDIRECT_URL'] : $_SERVER['REQUEST_URI']; $started = microtime(true); try { require_once dirname($_SERVER['SCRIPT_FILENAME']) . '/cfg.php'; echo $PWECore->process($uri); PWELogger::debug('Response headers: %s', headers_list()); } catch (\Exception $e) { try { if ($e->getCode() >= 500 || $e->getCode() <= 100) { PWELogger::error('Exception occured at page %s: %s', $uri, $e); } elseif ($e->getCode() >= 400) { PWELogger::info('Exception occured at page %s: %s', $uri, $e); } $PWECore->sendHTTPHeader("Content-Type: text/html"); $PWECore->sendHTTPStatusCode($e->getCode()); echo $PWECore->getErrorPage($e); } catch (\Exception $e2) { echo "<textarea cols='100' rows='25' readonly='readonly'>"; echo $e2->__toString(); echo "</textarea><br>"; echo "<p>Caused by:</p>"; echo "<textarea cols='100' rows='25' readonly='readonly'>"; echo $e->__toString(); echo "</textarea><br>"; die($e2->getMessage()); } } PWELogger::info('Done %s %s in %s', php_sapi_name(), $uri, microtime(true) - $started); }
/** * @param $args * @param $ext * @param $dir * @return string */ private function getRenderedPage($args, $ext, $dir) { if (pathinfo($args[0], PATHINFO_EXTENSION) != $ext) { $args[0] .= '.' . $ext; } else { throw new HTTP3xxException(substr($args[0], 0, strlen($args[0]) - strlen($ext) - 1)); } $file = $dir . '/' . str_replace(':', DIRECTORY_SEPARATOR, $args[0]); $real_file = realpath($file); $pos = strpos($real_file, realpath($dir) . DIRECTORY_SEPARATOR); PWELogger::debug("Test path for sanity: %s ; %s ; %s", $file, $real_file, $pos); if ($pos === false) { PWELogger::warn("Possible injection attempt: %s", $file); throw new HTTP4xxException("Wrong wiki page specified", HTTP4xxException::NOT_FOUND); } PWELogger::info("Wiki file to show: %s", $file); if (!is_file($file)) { PWELogger::error("Not found wiki file: %s", $file); throw new HTTP4xxException("Wiki page not found", HTTP4xxException::NOT_FOUND); } $contents = $this->renderPage($file); return $contents; }
public static function fsys_copydir($from, $to, $is_deep = true, $move = false) { if (!is_dir($from)) { PWELogger::warn("Source directory not exists for copy: %s", $from); return false; } PWELogger::debug("Copying %s to %s", $from, $to); if (strrchr($from, '/') != '/') { $from .= '/'; } if (strrchr($to, '/') != '/') { $to .= '/'; } $files = self::fsys_readdir($from, $is_deep); if (!is_dir($to)) { if (!self::fsys_mkdir($to)) { PWELogger::error("Unable to create destination directory: %s", $to); return false; } if (!is_dir(preg_replace('!/\\w+/$!', '/', $to))) { PWELogger::error("Unable to use destination directory: %s", $to); return false; } } if (!is_writable($to)) { PWELogger::error("Destination dir '%s' is not writable", $to); return false; } foreach ($files as $file => $is_dir) { if (!is_readable($from . $file)) { PWELogger::error("Source '%s.%s' is not readable", $from, $file); return false; } if ($move && !is_writable($from . $file)) { PWELogger::error("Source '%s.%s' is not writable for move", $from, $file); return false; } } $existed_files = self::fsys_readdir($to); $copied = true; foreach ($files as $path => $is_dir) { $newpath = $to . $path; $oldpath = $from . $path; if ($is_dir) { if ($is_deep && !is_dir($newpath)) { $copied = self::fsys_mkdir($newpath); if (!$copied) { break; } } } else { $copied = copy($oldpath, $newpath); PWELogger::debug("Copy file %s %s -> %s", $copied ? 'success' : 'FAILED', $oldpath, $newpath); if (!$copied && (!file_exists($newpath) || filesize($oldpath) > 0)) { break; } } } if (!$copied) { PWELogger::info("Rolling back..."); self::fsys_removedir($to, $is_deep, $existed_files); return false; } if ($move && !self::fsys_removedir($from, $is_deep)) { return false; } return true; }