/** * Schaltet den Cache ab * @return mixed */ public function disable() { Logging::warning('Cache deaktivert!'); $this->enabled = false; $this->clear(); return $this; }
/** * 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; } }
/** * Gibt ein Entity aus dem Datenmodell zurück. Shortcut-Methode * @param $name string * @return null */ public function getEntity($name) { if ($this->model !== null) { return $this->model->getEntity($name); } else { Logging::warning("Modul {$this->name} besitzt kein eigenes Datenmodell"); return null; } }
/** * Das eigentliche Ausführen eines Requests ohne den ganzen Kram * außenrum. * @return mixed|null * @throws Exception */ protected function innerExecute() { $result = null; // per Reflection, die passende Methode suchen und ausführen try { $class = new \ReflectionClass(get_class($this)); if ($class->hasMethod($this->currentAction->name)) { return $this->executeViaReflection($class->getMethod($this->currentAction->name)); } else { return $this->executeViaResource(); } } catch (Exception $e) { if ($e instanceof ReflectionException) { Logging::warning($e->getMessage()); } else { throw $e; } } return $result; }
/** * Gibt das HTML Markup aus. Die Funktion hinter dem Wrapper wird jetzt erst aufgerufen! * @return string * @throws Exception */ public function toHtml() { // Erzeugen des neuen Requests $request = Application::getCurrentRequest()->createSubRequest(); $request->module = $this->module; $request->action = $this->action; $request->embedded = true; $request->setViaArray($this->param); $module = Modules::getModule($this->module); if ($module == null) { throw new Exception("[Wrapper] Modul {$this->module} konnte nicht geladen werden"); } $controller = $module->createController($request); if ($controller->hatBerechtigung()) { $response = $controller->execute($request); Logging::warning((string) $response->getContent()); if ($response->getContent() instanceof View) { $result = '<div id="' . $this->id . '" class="wrapper">' . $response->getContent()->render() . '</div>'; } else { $result = 'NO VIEW'; } } else { $result = '<div class="alert alert-danger">Für diese Funktion haben Sie keine ausreichende Berechtigung</div>'; } // Ergebnis in einem Panel verpacken if ($this->showInPanel) { $panel = new CaptionedPanelControl(null, 'panel-' . $this->id); $panel->setCaption($this->panelCaption); $panel->setCollapsed($this->panelCollapsed); $html = new HtmlControl($panel); $html->setInnerHtml($result); $result = $panel->toHtml(); } return $result; }
/** * Wird angezeigt wenn versucht wird ohne entsprechende Berechtigung * auf eine Funktion zuzugreifen */ protected function showNoAccess() { Logging::warning('Zugriff wurde verweigert'); $request = new Request(); $request->module = 'DefaultMod'; $request->action = 'noaccess'; $this->handleRequest($request); }
use NewFrontiers\Framework\Core\Application; 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');
/** * @param $importId * @param $meldung */ public static function warning($importId, $meldung) { Logging::warning($meldung); self::neuerEintrag($importId, self::LEVEL_WARNING, $meldung); }
public function hatBerechtigung($recht, $user = null, $rolle = null) { if ($user != null && $rolle == null) { // Falls die Berechtigung für einen bestimmten User überprüft werden soll // TODO: $result = true; } elseif ($user == null && $rolle != null) { // Falls die Berechtigung für eine bestimmte Rolle überprüft werden soll $berechtigung = Database::select()->field('re_recht')->from('rechte')->where('re_element = :element', ['element' => $recht])->where('re_rolle = :rolle', ['rolle' => $rolle])->orderBy('re_id')->limit(1)->scalar(); $result = $berechtigung == 1; } else { // Aktuellen User prüfen $berechtigung = Database::select()->field('max(re_recht)')->from('rechte')->where('re_element = :element', ['element' => $recht])->where('re_rolle in ' . $_SESSION['rollen'])->scalar(); $result = $berechtigung > 0; } if (!$result) { // Das if dient dazu, keine Warnungen zu generieren wenn // SecurityCheckboxGroups angezeigt werden if ($user != null) { Logging::warning("Berechtigung nicht vorhanden!"); } } return $result; }
/** * Durchsucht ein Verzeichnis nach Modulen und gibt diese als Array zurück * @param $dir * @return \NewFrontiers\Framework\Modules\Module[] */ protected function getModulesInDir($dir) { Logging::info('Lese Module aus Verzeichnis ' . $dir); $result = []; if (!file_exists($dir)) { Logging::warning('Modul-Verzeichnis ' . $dir . ' existiert nicht'); return $result; } // TODO: Langsam wie Hölle! $dir_iterator = new RecursiveDirectoryIterator($dir); $iterator = new RecursiveIteratorIterator($dir_iterator, RecursiveIteratorIterator::SELF_FIRST); foreach ($iterator as $file) { if ($file->isFile() && $file->getFilename() === 'Module.xml') { $xml = simplexml_load_file($file); if (isset($xml->qualifiedName)) { $moduleName = (string) $xml->qualifiedName; } else { $moduleName = (string) $xml['name']; } if ($moduleName !== '%MODULE%') { $result[$moduleName] = $this->getModule($moduleName); } } } return $result; }
/** * Gibt eine Entity zurück * @param $name string Der Name der Entity * @return EntityDefinition */ public function getEntity($name) { if (array_key_exists($name, $this->entities)) { return $this->entities[$name]; } else { // Macht man hier einen Error dann greift das immer, wenn man eine // Entity neu anlegt Logging::warning("Entität {$name} nicht gefunden"); return null; } }
/** * @param BaseEntity $entity * @return boolean */ public function delete($entity) { if (!$entity->canDelete()) { Logging::warning('Datensatz kann nicht gelöscht werden ' . (string) $this); return false; } $entityName = Database::getEntityName($this->definition->name); Database::delete()->from($entityName)->where("{$this->definition->primaryKey} = {$entity->id}")->execute(); return true; }