コード例 #1
0
 public function toHtml()
 {
     $topPanel = new TopPanelControl(null, 'debugTopPanel');
     $topPanel->setCaption('
             <div class="debug-block">
                 <span class="glyphicon glyphicon-flash"></span> &nbsp;&nbsp;' . QueryLog::count() . '
             </div>
             <div class="debug-block">
                 <span class="glyphicon glyphicon-time"></span> &nbsp;&nbsp;' . Profiler::getTotalTime() . ' ms
             </div>
             <div class="debug-block">
                 <span class="glyphicon glyphicon-oil"></span> &nbsp;&nbsp;' . round(memory_get_peak_usage() / 1024 / 1024, 1) . ' MB
             </div>
             ')->setOpened(Logging::isError());
     if ($this->mode === self::MODE_LARGE) {
         $tabControl = new TabControl(null, 'debugTabControl');
         $tabControl->addTab('Log (' . count(Logging::getLogItems()) . ')')->add($this->showLog());
         $tabControl->addTab('SQL-Queries (' . QueryLog::count() . ')')->add($this->showQueryLog());
         $tabControl->addTab('Request')->add($this->showNfsRequest());
         $tabControl->addTab('REQUEST-Array (' . count($_REQUEST) . ')')->add($this->showRequest());
         if (Configuration::get('logging.showServerVar') === 'true') {
             $tabControl->addTab('SERVER-Array (' . count($_SERVER) . ')')->add($this->showServer());
         }
         $tabControl->addTab('FILES-Array (' . count($_FILES) . ')')->add($this->showFiles());
         $tabControl->addTab('Profiler')->add($this->showProfilerInfo());
         $tabControl->addTab('Cache')->add($this->showTabInfo());
         $tabControl->addTab('Debug')->add($this->showDebugTab());
         $topPanel->add($tabControl);
     }
     Javascript::addJs($topPanel->getJavascript());
     return $topPanel->toHtml();
 }
コード例 #2
0
 /**
  * Diese Methode erzeugt aus den übergebenen Parameteren ein Request-Objekt
  * Könnte man vielleicht noch aufhübschen
  *
  * @return Request
  *
  */
 public function route()
 {
     Profiler::startSection('Routing.route');
     // TODO: Bei Get und im Pathinfo können wir sehr viel
     // schärfere Sicherheitsrichtlinien durchsetzen. Da kann
     // und darf nie HTML kommen (XSS)
     $request = new Request();
     if (array_key_exists('REQUEST_METHOD', $_SERVER)) {
         $request->methode = $_SERVER['REQUEST_METHOD'];
     } else {
         $request->method = 'get';
     }
     $request->admin = isset($_GET['admin']);
     Logging::info('Methode ' . $request->method);
     // Falls es ein Pathinfo gibt, dieses aufbereiten
     $pathInfo = getenv('PATH_INFO');
     if (array_key_exists('pathinfo', $_GET) && isset($_GET['pathinfo'])) {
         $pathInfo = '/' . $_GET['pathinfo'];
     }
     Logging::info('Pathinfo is: ' . $pathInfo);
     $request->pathinfo = $pathInfo;
     if (isset($pathInfo)) {
         // Der Pathinfo fängt mit einem Slash an! (z.B. /cms/showKategorie)
         $pathInfo = substr($pathInfo, 1);
         $this->fillRequestByPathinfo($request, $pathInfo);
     }
     foreach ($_REQUEST as $key => $value) {
         $request->{$key} = $value;
     }
     $request->sanitize();
     Profiler::endSection('Routing.route');
     $this->postRoute($request);
     return $request;
 }
コード例 #3
0
 public function toHtml()
 {
     $outer = Html::create('div');
     $totalTime = Profiler::getTotalTime();
     $this->createTotal('Total', $totalTime)->addTo($outer);
     foreach (Profiler::getSections() as $key => $value) {
         $this->createInner($key, $value, $totalTime)->addTo($outer);
     }
     return $outer->render();
 }
コード例 #4
0
 /**
  * Diese Methode liest die Konfigurationsdatei ein. Wird ein Name einer Konfiguration übergeben,
  * so wird dieser geladen. Wenn nicht geht es nach dem enthaltenen URL-Pattern
  *
  * @param string $name Name der Konfiguration oder null
  * @throws \RuntimeException
  */
 public function readConfig($name = null)
 {
     Profiler::endSection('config.load');
     $isWebserver = isset($_SERVER['SERVER_NAME']);
     if ($name !== null) {
         $this->readConfigByName($name);
     } elseif (!$isWebserver) {
         $this->readTestConfig();
     } else {
         $this->readConfigByServerUri();
     }
     Profiler::endSection('config.load');
 }
コード例 #5
0
 /**
  * Zeigt die Debug-Console an
  */
 public static function showDebugConsole()
 {
     if (Configuration::get('logging.debug') !== 'true') {
         return;
     }
     // TODO: Localhost!
     $allowed = ['92.217.151.126', '213.188.124.2', '94.219.179.56', '::1', '127.0.0.1', '92.217.158.188', '188.97.199.247', '94.219.93.70'];
     if (!in_array($_SERVER['REMOTE_ADDR'], $allowed)) {
         return;
     }
     Profiler::endAll();
     $debugConsole = new DebugConsoleControl(null, 'dbg');
     $html = $debugConsole->toHtml();
     echo $html;
 }
コード例 #6
0
 /**
  * Rahmen zum Ausführen einer Funktion. Konkrete Ausführeung wird
  * von abstrakter Methode executeAction ausgeführt
  * @param $request
  * @return Response
  * @throws Exception
  */
 public function execute($request)
 {
     // Der Response wird direkt am Anfang erzeugt und auch in der Application-Klasse
     // hinterlegt. Das muss aus Gründen der Abwärtskompatibilität sein. In den Controller
     // Methiden wird oft auf Application::currentResponse zurückgegriffen. Das muss an
     // dieser Stelle also gefüllt sein.
     Logging::info("Ausführen von [{$this->request->module}:{$this->request->action}]");
     Profiler::startSection($this->request->module . '.' . $this->request->action);
     $this->request = $request;
     $this->response = new Response();
     Application::getInstance()->setResponse($this->response);
     $this->currentAction = $this->module->getAction($this->request->action);
     // Abbrechen, wenn Aktion nicht gefunden werden konnte
     if ($this->currentAction === null) {
         throw new \DomainException("Aktion '{$this->request->action}' in Modul '{$this->request->module}' nicht gefunden");
     } else {
         // Verhindern, dass von einem Angreifer eine beliebige Seite aufgerufen werden
         // kann
         $this->request->view = null;
         // Response mit den Standard-Daten füllen
         $this->response->setContent($this->currentAction->getDefaultNext($this));
         $result = $this->innerExecute();
         if ($result !== null) {
             $this->response = $result;
         }
         // Jetzt kann sich unter Umständen der View geändert haben
         if ($this->request->view !== null) {
             Logging::warning('anderen View laden');
             $this->response->setContent($this->module->loadView($this->request->view, $this));
         }
         // Überschreiben der eigentlichen Aktion durch eine, die bei der Ausführung der Funktion
         // gesetzt wurde
         if ($this->request->action !== $this->currentAction->name) {
             Logging::warning('Andere Action ausführen');
             $this->response->setContent($this->module->getAction($this->request->action));
         }
         Profiler::endSection($this->request->module . '.' . $this->request->action);
         return $this->response;
     }
 }
コード例 #7
0
 /**
  * Query auf Datenbank ausführen und die entsprechenden Bindings durchführen.
  * ACHTUNG: Funktion fängt derzeit nicht ab, wenn Leerzeichn im Feldnamen
  * stehen, aber das sollte man sowieso nicht machen.
  * @param string $sql
  * @param array|null $params
  * @return $this
  */
 public function query($sql, $params = null)
 {
     if (!$this->connected) {
         $this->connect();
     }
     // Falls noch ein Statement aktiv ist, dieses abbrechen
     if ($this->statement !== null) {
         $this->closeStatement();
     }
     // TODO
     if ($this->engine === self::DB_MSSQL) {
         $sql = str_replace('CURDATE()', 'Convert(date, getdate())', $sql);
         $sql = str_replace('curdate()', 'Convert(date, getdate())', $sql);
     }
     $startTime = microtime(true);
     $this->prepareQueryAndBindParameter($sql, $params);
     $prepareTime = microtime(true);
     Profiler::startSection('database.execute', $sql);
     $errorMsg = '';
     try {
         $success = $this->statement->execute();
     } catch (Exception $e) {
         $errorMsg = $e->getMessage();
         $success = false;
     }
     $executeTime = microtime(true);
     Profiler::endSection('database.execute');
     if ($this->logQueries || !$success) {
         if ($success) {
             QueryLog::success($sql, $params, round(($executeTime - $prepareTime) * 1000), round(($prepareTime - $startTime) * 1000));
         } else {
             $info = $this->statement->errorInfo();
             Logging::error('Query konnte nicht ausgeführt werden: ' . $info[2] . $errorMsg . $sql);
             //error_log("Query konnte nicht ausgeführt werden: " . $info[2] . "\n" . $errorMsg . "\n" . $sql . "\n" . print_r(debug_backtrace(~DEBUG_BACKTRACE_PROVIDE_OBJECT), true));
             QueryLog::fail($sql, $params, round(($executeTime - $prepareTime) * 1000), round(($prepareTime - $startTime) * 1000), $info[2] . $errorMsg);
         }
     }
     return $this;
 }
コード例 #8
0
 /**
  * Sendet eine Mail über den in der Konfiguration hinterlegten SMTP Account.
  * @param string $empfaenger Empfängeradresse / Wird automatisch von UTF-8 nach ANSI gewandelt
  * @param string $betreff Empfängeradresse / Wird automatisch von UTF-8 nach ANSI gewandelt
  * @param string $nachricht Nachricht als Plaintext
  * @param string $html Nachricht als HTML
  * @param string $attachment Pfad und Dateiname eines Anhangs
  * @return boolean
  */
 public function sendMail($empfaenger, $betreff, $nachricht, $html = null, $attachment = null)
 {
     if (Configuration::get('mail.from') === '') {
         Logging::warning('Kein Absender in der Konfiguration eingetragen. E-Mail wird nicht versendet');
         return false;
     }
     if ($empfaenger === '') {
         Logging::warning('Keine E-Mail Adresse übergeben');
         return false;
     }
     $empfaenger = trim($empfaenger);
     Profiler::startSection('Mailer::sendMail');
     try {
         $message = Swift_Message::newInstance();
         $message->setSubject($betreff);
         $message->setFrom(array(Configuration::get('mail.from')));
         $message->setTo(array(utf8_decode($empfaenger)));
         $message->setBody(strip_tags($nachricht));
         if ($html !== null) {
             $templatePath = Environment::get()->srcDir . '/site/mails/template.html';
             if (file_exists($templatePath)) {
                 $html = str_replace('{mail}', $html, file_get_contents($templatePath));
             }
             $message->addPart($html, 'text/html');
         }
         if ($attachment !== null) {
             $message->attach(Swift_Attachment::fromPath($attachment));
         }
         if ($this->transport === null) {
             $this->transport = Swift_SmtpTransport::newInstance(Configuration::get('mail.smtp_host'), Configuration::get('mail.smtp_port'))->setUsername(Configuration::get('mail.smtp_user'))->setPassword(Configuration::get('mail.smtp_pass'));
             $this->mailer = Swift_Mailer::newInstance($this->transport);
         }
         Logging::debug('Versende Mail per SMTP an ' . $empfaenger . ' über ' . Configuration::get('mail.smtp_host') . ':' . Configuration::get('mail.smtp_port') . ' / ' . Configuration::get('mail.smtp_user') . ' / ' . Configuration::get('mail.smtp_pass'));
         $result = $this->mailer->send($message);
         Logging::debug('Result des Mails ' . print_r($result, true));
         Profiler::endSection('Mailer::sendMail');
         return $result;
     } catch (Exception $ex) {
         Logging::error('Exception beim Senden einer Mail ' . $ex->getMessage());
         Profiler::endSection('Mailer::sendMail');
         return false;
     }
 }
コード例 #9
0
 /**
  * Callback-Funktion für das Template.
  * Wird aus dem Tempalte aufgerufen und füngt an dieser Stelle des
  * Hauptviews ein.
  */
 public function displayMain()
 {
     Profiler::startSection('Application.displayMain');
     $this->flashMessagesAusgeben();
     // Das es keinen View gibt wird schon in display abgefangen
     $this->view->display();
     Profiler::endSection('Application.displayMain');
 }
コード例 #10
0
use NewFrontiers\Framework\Events\FrameworkEvents;
use Nostromo\Contracts\Facades\Events;
use Nostromo\Contracts\Facades\Logging;
use Nostromo\Contracts\Facades\Profiler;
use Nostromo\Contracts\Facades\Security;
use Symfony\Component\EventDispatcher\Event;
Profiler::startSection('initApplication');
// Listener, der als Login-Gate fungiert
// TODO: In eigene Klasse
Events::addListener(FrameworkEvents::REQUEST_BEFORE, function (\NewFrontiers\Framework\Events\RequestEvent $event) {
    $request = $event->getRequest();
    // Nur Admin schützen
    if (!$request->admin) {
        return;
    }
    // API ausnhemen (pauschal)
    if ($request->module == 'api' || $request->module == 'Api') {
        return;
    }
    $allowedActions = array('showLogin', 'login', 'loginFailure', 'logout', 'password', 'doPassword', 'reset', 'doReset');
    if (!Security::isAuthenticated() && !in_array($request->action, $allowedActions)) {
        $request->followUpModule = $request->module;
        $request->followUpAction = $request->action;
        $request->module = 'defaultMod';
        $request->action = 'showLogin';
        Logging::warning('Action not allowed. User was sent to Login-Screen');
    } else {
    }
});
Profiler::endSection('initApplication');
コード例 #11
0
                    <span class="icon-bar"></span>
                </button>
                <!--<a class="navbar-brand" href="#"><img src="http://pixw.net/p3/themes/p3-bootstrap/img/p3.png" style="margin-top: -4px"></a>-->
            </div>


            <!-- Collect the nav links, forms, and other content for toggling -->
            <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">


                <?php 
    Profiler::startSection('Template.siteMenuControl');
    $menu = new NewFrontiers\Modules\Site\Controls\SiteMenuControl(null, 'menuMain1');
    $menu->addCssClass('navbar-nav');
    $menu->display();
    Profiler::endSection('Template.siteMenuControl');
    ?>


                <!-- Logged-in Control -->
                <ul class="nav navbar-nav navbar-right">
                    <li class="dropdown">
                        <a href="#" class="dropdown-toggle" data-toggle="dropdown"><?php 
    echo $_SESSION['name'];
    ?>
<b
                                class="caret"></b></a>
                        <ul class="dropdown-menu">

                            <!--// TODO: Berechtigung für Anmelden als...-->
                            <?php 
コード例 #12
0
 public function postRoute(&$request)
 {
     // Das normale Routing hat etwas ergeben
     if (isset($request->module, $request->action)) {
         return;
     }
     Profiler::startSection('Routing.postRoute');
     // Default-Page, falls nichts gefunden
     Logging::info('[Post-Route] Default-Page wird angezeigt');
     $defaultId = Configuration::get('site.defaultPageId');
     if ($defaultId <= 0) {
         throw new \Exception('Keine Defaultseite gesetzt!');
     }
     $default = new Page($defaultId);
     $this->setCurrentPage($request, $default);
     Profiler::endSection('Routing.postRoute');
 }
コード例 #13
0
 /**
  * Lädt das Modul mit dem übergebenen Namen
  * @param $name
  * @return Module|null
  */
 public function getModule($name)
 {
     if ($name === '') {
         Logging::warning('Leeres Modul sollte geladen werden.');
         return null;
     }
     $name = ucfirst($name);
     // Aus dem Cache holen
     $cacheId = 'module.' . $name;
     if (array_key_exists($cacheId, $this->internalCache)) {
         return $this->internalCache[$cacheId];
     }
     $result = Cache::get($cacheId, null);
     if ($result !== null) {
         $this->internalCache[$cacheId] = $result;
         return $result;
     }
     Profiler::startSection('module.load', $name);
     Logging::debug("Modul '{$name}' wird geladen");
     // Generieren der Klassendefinition für den Controller um dann via
     // Reflection die Datei und damit das Verzeichnis herauszubekommen.
     $naming = new ModuleNaming();
     $classOfController = $naming->getControllerClassFromCamelCase($name);
     if (class_exists($classOfController)) {
         $reflector = new ReflectionClass($classOfController);
         $directory = dirname($reflector->getFileName());
         $filename = $directory . '/Module.xml';
         if (file_exists($filename)) {
             $file = simplexml_load_file($filename);
             $result = $this->createByXml($file, $directory);
             unset($file);
         } else {
             Logging::error("Modul [{$name}] konnte in Pfad {$directory} nicht gefunden werden");
         }
     } else {
         Logging::warning("Controller für Modul [{$name}] konnte nicht gefunden werden [{$classOfController}]");
     }
     Cache::set($cacheId, $result);
     $this->internalCache[$cacheId] = $result;
     Profiler::endSection('module.load');
     return $result;
 }
コード例 #14
0
 public function render()
 {
     Profiler::startSection(get_called_class());
     $this->createControls();
     $mainControl = $this->controls;
     if ($this->formControl !== null) {
         $mainControl = $this->formControl;
         $this->formControl->add($this->controls);
     }
     $temp = $mainControl->toHtml();
     Javascript::addJs($mainControl->getJavascript());
     Profiler::endSection(get_called_class());
     return $temp;
 }
コード例 #15
0
 /**
  * Erstellt die Unterobjekte für die einzelnen Menüs
  */
 protected function loadMenuItems()
 {
     Profiler::startSection('SiteMenuControl.loadMenuItems');
     $this->loadRootPage();
     try {
         $pages = $this->rootPage->loadChildrenForCurrentUser();
     } catch (\Exception $e) {
         Logging::error('Fehler beim Laden der Children für die Root-Page des SiteMenuControls ' . $e->getMessage());
         $pages = [];
     }
     foreach ($pages as $page) {
         $itemControl = new MenuItemControl($this, 'page' . $page->id);
         $itemControl->setPage($page);
         $itemControl->setRenderChildren($this->renderChildren);
     }
     Profiler::endSection('SiteMenuControl.loadMenuItems');
 }