コード例 #1
0
 public function match($url)
 {
     $ok = preg_match($this->reg, $url, $match);
     Log::getLogger()->info('Rewrite.Rule.match reg: %s url: %s, matchCount: %s', $this->reg, $url, $ok);
     if (!$ok) {
         $match = null;
     }
     return $match;
 }
コード例 #2
0
 public static function init($root, $encoding = 'utf-8', array $opt = array())
 {
     Mock::$logger = Log::getLogger();
     $root = Util::normalizePath($root);
     Mock::$wwwRoot = $root;
     Mock::$testPath = $root . '/test';
     //set encoding
     Mock::setEncoding($encoding);
 }
コード例 #3
0
ファイル: auth.php プロジェクト: yashodhank/Monitoring
 function logout()
 {
     if (isset($_SESSION["username"])) {
         Log::getLogger()->write(Log::LOG_VERBOSE, "User " . $_SESSION["username"] . " is logged off");
     }
     unset($_SESSION["connected"]);
     unset($_SESSION["username"]);
     unset($_SESSION["user_id"]);
     session_destroy();
     // Redirect automatically to the Profile page.
     $_SESSION["message"] = array("type" => "success", "title" => "Déconnexion terminée", "descr" => "Vous êtes maintenant déconnecté");
     header('Location: ' . '/monitoring/?v=dashboard');
 }
コード例 #4
0
ファイル: ErrorHandler.php プロジェクト: lknight/habrometr
 /**
  * Handler for uncatched exceptions.
  *
  * @param Exception $exception
  */
 public static function exceptionHandler($exception)
 {
     error_log("Unhandled exception: Code {$exception->getCode()}; Message: {$exception->getMessage()}");
     if (class_exists('Log') && !is_null(Log::getLogger())) {
         Log::err(sprintf('Lpf_ExceptionHandler: Unhandled exception [%s] `%s`', $exception->getCode(), $exception->getMessage()));
     }
     if (Config::DEBUG_MODE) {
         echo "[Debug mode] Unhandled exception: Code {$exception->getCode()}; Message: {$exception->getMessage()}\r\n";
         echo $exception->getTraceAsString();
         exit;
     } else {
         if ($exception->getCode() == 404) {
             header("HTTP/1.0 404 Not Found", true, 404);
             die('<h1 style="text-align:center;">Error 404: Page Not Found</h1>');
         } else {
             header("HTTP/1.0 500 Internal Server Error", true, 500);
             die('<h1 style="text-align:center;">Error 500: Internal Server Error</h1>');
         }
     }
 }
コード例 #5
0
ファイル: LogTest.php プロジェクト: hebaoxia/simplify-log
 /**
  * @covers Log::getLogger
  * @author mr2longly
  */
 public function testGetLogger()
 {
     $logger = Log::getLogger('myLogger');
     $this->assertTrue($logger instanceof Log);
 }
コード例 #6
0
<?php

define('WWW_ROOT', __DIR__);
require __DIR__ . '/../log/Log.class.php';
require __DIR__ . '/Rewrite.class.php';
Log::getLogger(array('level' => Log::ALL));
class Render implements RewriteHandle
{
    public function process($file)
    {
        echo file_get_contents($file);
    }
}
$rewrite = new Rewrite(__DIR__ . '/test');
$rewrite->addConfigFile('home.conf');
$rewrite->addConfigFile('common.conf');
$rewrite->addRewriteHandle('tpl', new Render());
$rewrite->dispatch('/home/test');
コード例 #7
0
ファイル: dashboard.php プロジェクト: yashodhank/Monitoring
 function assignCategoryLogs($tpl)
 {
     $logs = Log::getLogger()->tail(100);
     $logs = preg_replace("/[\r\n]/", "<br/>", $logs);
     $logs = str_replace('\\t', "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;", $logs);
     $tpl->assign('logs', $logs);
     $tpl->assign('view', 'view_dashboard_logs');
 }
コード例 #8
0
ファイル: security.php プロジェクト: yashodhank/Monitoring
 private function __syncSuperAdminIfNeeded()
 {
     if (!isset($_SESSION["user_id"]) || $_SESSION["user_id"] != -1) {
         return;
     }
     try {
         $dsn = "mysql:host=" . DB_HOST . ";dbname=" . DB_AUTH_DBNAME . "";
         $pdo = new PDO($dsn, DB_AUTH_USERNAME, DB_AUTH_PASSWORD);
         $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
         $pdo->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
         $sth = $pdo->prepare("UPDATE users SET username = ?, password = ?, email = ?, email_active = ?, phone = ?, phone_active = ? WHERE id = -1");
         $res = $sth->execute(array(AC_SUPERADMIN_USERNAME, AC_SUPERADMIN_PASSWORD, AC_SUPERADMIN_EMAIL, AC_SUPERADMIN_EMAIL_ACTIVE, AC_SUPERADMIN_PHONE, AC_SUPERADMIN_PHONE_ACTIVE));
         if ($res == 0) {
             throw new Exception("Unable to sync the SuperAdmin user with the database.");
         }
     } catch (Exception $e) {
         Log::getLogger()->write(Log::LOG_ERROR, "Unable to sync the SuperAdmin user with the database.", $e);
     }
 }
コード例 #9
0
ファイル: setup.php プロジェクト: yashodhank/Monitoring
function __error_handler($error, $error_string, $filename, $line, $symbols)
{
    $string = "{$error_string} occured in file {$filename} line {$line}";
    Log::getLogger()->write(Log::LOG_DEBUG, $string, $error);
}
コード例 #10
0
ファイル: _ide_helper.php プロジェクト: ohworkit/Sirius
 /**
  * Register an error_log handler.
  *
  * @param string $level
  * @param integer $messageType
  * @return void
  * @static
  */
 public static function useErrorLog($level = 'debug', $messageType = 0)
 {
     \Log::getLogger()->useErrorLog($level, $messageType);
 }
コード例 #11
0
ファイル: Log.stest.php プロジェクト: enyo/rincewind
 public function testSanitizing()
 {
     Log::addLogger('some - LOGGER', 'aBcD');
     return $this->assertIdentical('some - LOGGER', Log::getLogger('AbCd'));
 }
コード例 #12
0
ファイル: dispatcher.php プロジェクト: yashodhank/Monitoring
 /** Display the requested page. */
 function displayPage($webPage)
 {
     setcookie("last-page", full_url($_SERVER));
     if (isset($_SESSION["message"])) {
         $message = $_SESSION["message"];
         $this->tpl->assign('message', $message);
         unset($_SESSION["message"]);
     }
     try {
         if (isset($this->pdo)) {
             $sth = $this->pdo->prepare("SELECT COUNT(alerts.id) AS c FROM alerts WHERE resolved = 0");
             $sth->execute();
             $countAlerts = $sth->fetch(PDO::FETCH_ASSOC);
             $countAlerts = $countAlerts["c"];
             $this->tpl->assign('countAlerts', $countAlerts);
         }
     } catch (Exception $e) {
         Log::getLogger()->write(Log::LOG_ERROR, "Unable to request DB", $e);
         $this->tpl->assign('countAlerts', 0);
     }
     try {
         switch ($webPage) {
             case CONTROLLER_DASHBOARD:
                 $c = new DashboardController($this->pdo);
                 $c->buildTemplate($this->tpl);
                 break;
             case CONTROLLER_ADMIN:
                 $c = new AdminController($this->pdo);
                 $c->buildTemplate($this->tpl);
                 break;
             case CONTROLLER_PROFILE:
                 $c = new ProfileController($this->pdo);
                 $c->buildTemplate($this->tpl);
                 break;
             case CONTROLLER_HELP:
                 $c = new HelpController($this->pdo);
                 $c->buildTemplate($this->tpl);
                 break;
             case CONTROLLER_LOGIN:
                 $c = new LoginController($this->pdo);
                 $c->buildTemplate($this->tpl);
                 break;
             case CONTROLLER_DEFAULT:
             default:
                 $this->tpl->display('controller_blank.tpl');
                 break;
         }
     } catch (SecurityAccessException $sae) {
         if ($this->tpl->getTemplateVars('message') == null) {
             $_SESSION["message"] = array("type" => "danger", "title" => "Accès interdit", "descr" => "Cette page est protégée. Veuillez vous connecter avec un compte ayant accès à cette page.");
             $this->tpl->assign('message', $_SESSION["message"]);
             unset($_SESSION["message"]);
         }
         // A Security Access Exception occurs when the user cannot see the asked page.
         // So in this case let's redirect to login page.
         $c = new LoginController($this->pdo);
         $c->buildTemplate($this->tpl);
     } catch (SecurityException $se) {
         // A Security Exception is more generic so display a message.
         Log::getLogger()->write(Log::LOG_ALERT, "Security Exception dropped on dispatcher", $se);
         $_SESSION["message"] = array("type" => "danger", "title" => "Erreur", "descr" => $se->getMessage());
         $this->tpl->assign('message', $_SESSION["message"]);
         unset($_SESSION["message"]);
         $this->tpl->display('controller_error.tpl');
     } catch (Exception $e) {
         Log::getLogger()->write(Log::LOG_ERROR, "Unknown Exception dropped on dispatcher", $e);
         // A very generic exception.
         $_SESSION["message"] = array("type" => "danger", "title" => "Erreur", "descr" => $e->getMessage());
         $this->tpl->assign('message', $_SESSION["message"]);
         unset($_SESSION["message"]);
         $this->tpl->display('controller_error.tpl');
     }
 }
コード例 #13
0
 public function dispatch($strUrl = null)
 {
     $url = $strUrl;
     if (isset($_SERVER['REQUEST_URI'])) {
         $url = $_SERVER['REQUEST_URI'];
     }
     if (!$url) {
         return;
     }
     foreach ($this->_rules as $rule) {
         if ($rule->match($url)) {
             $target = $rule->fill($url);
             if ($rule->type !== Rule::REDIRECT) {
                 $target = preg_replace('@\\?.*$@', '', $target);
             }
             Log::getLogger()->info('Rewirte.dispatch target %s', $target);
             if ($rule->type === Rule::REWRITE) {
                 $this->rewriteProcess(WWW_ROOT . '/' . $target);
             } else {
                 if ($rule->type === Rule::REDIRECT) {
                     header('Location: ' . $target);
                 } else {
                     if ($rule->type === Rule::RENDER) {
                         //@TODO ugly, it's old code
                         if (isset($this->_factoryHandles['tpl'])) {
                             $handle = $this->_factoryHandles['tpl'];
                             $handle->process($target);
                         } else {
                             Log::getLogger()->warn('Rewirte.dispatch Not found process handle of the tpl template file.');
                         }
                     }
                 }
             }
             exit;
         }
     }
 }