public static function prepare() { if (FajrConfig::get('URL.Path')) { $_get = array_merge(FajrRouter::pathToParams(FajrUtils::pathInfo()), $_GET); } else { $_get = $_GET; } $_post = $_POST; // podla pola definujeceho vstupne parametre overim ich platnost foreach (self::$allowedParamters as $input => $params) { foreach ($params as $name => $type) { if (isset(${$input}[$name])) { $checker = self::$conditions[$type]['cond']; if (!Validator::$checker(${$input}[$name], self::$conditions[$type]['options'])) { throw new Exception(str_replace('%%NAME%%', $name, self::$conditions[$type]['message'])); } self::$inputParameters[$name] = ${$input}[$name]; self::${$input}[$name] = ${$input}[$name]; } } } // budeme pouzivat uz len Input unset($_GET); unset($_POST); }
/** * Configure injection of SessionInitializer.class * * @param sfServiceContainerBuilder $container Symfony container to configure */ public function configure(sfServiceContainerBuilder $container) { $container->register('SessionInitializer.class', 'fajr\\SessionInitializer')->addArgument('%session.life_time_sec%')->addArgument('%session.save_path%')->addArgument('%session.path%')->addArgument('%session.domain%'); $parameters = array('session.life_time_sec' => 36000, 'session.save_path' => FajrConfig::getDirectory('Path.Temporary.Sessions'), 'session.path' => '/', 'session.domain' => '.' . $_SERVER['HTTP_HOST']); // Note, we can't use setParameters as it will destroy previous values! $container->addParameters($parameters); }
public static function buildUrl($params, $file = null) { if ($file === null) { if (!empty($params['_file'])) { $file = $params['_file']; unset($params['_file']); } else { $file = 'fajr.php'; } } $path = ''; if (FajrConfig::get('URL.Path')) { $path = FajrRouter::paramsToPath($params); } $query = http_build_query($params); if (strlen($query) > 0) { $query = '?' . $query; } $base = ''; if (!FajrConfig::get('URL.Rewrite') || $file != 'fajr.php' || $path == '' || $path == '/') { $base = $file; if (strlen($path) > 0) { $base .= '/'; } } return self::basePath() . $base . $path . $query; }
/** * Configure injection of DisplayManager.class * * @param sfServiceContainerBuilder $container Symfony container to configure */ public function configure(sfServiceContainerBuilder $container) { $container->register('DisplayManager.class', '\\fajr\\DisplayManager')->addArgument(new sfServiceReference('Twig_Environment.class')); $container->register('Twig_Loader_Filesystem.class', 'Twig_Loader_Filesystem')->addArgument('%Twig.Template.Directory%'); $container->register('Twig_Environment.class', 'Twig_Environment')->addArgument(new sfServiceReference('Twig_Loader_Filesystem.class'))->addArgument('%Twig.Environment.options%')->addMethodCall('addExtension', array(new Twig_Extension_Escaper()))->addMethodCall('addExtension', array(new Extension())); $container->setParameter('Twig.Template.Directory', FajrConfig::getDirectory('Template.Directory')); $container->setParameter('Twig.Environment.options', array('base_template_class' => '\\fajr\\rendering\\Template', 'strict_variables' => true)); }
/** * Configures Trace.class for injection. * * @param sfServiceContainer $container Container to configure */ public function configure(sfServiceContainerBuilder $container) { if (FajrConfig::get('Debug.Trace') === true) { $container->register('Trace.class', 'fajr\\ArrayTrace')->addArgument(new sfServiceReference('Timer.class'))->addArgument('--Trace--'); } else { $container->register('Trace.class', 'fajr\\libfajr\\pub\\base\\NullTrace'); } }
/** * Return instance of object given its name. * * Note that the scope of the object (singleton/per call) depends on * how the object is configured by injector modules. * * @returns mixed instance of whatever is asked for */ public function getInstance($name) { Preconditions::checkIsString($name, '$name should be string.'); if (FajrConfig::get('Debug.Exception.ShowStacktrace')) { return $this->container->getService($name); } else { return @$this->container->getService($name); } }
/** * Configure CurlConnection.options * * @param sfServiceContainerBuilder $container Symfony container to configure */ public function configure(sfServiceContainerBuilder $container) { $options = array(CURLOPT_FORBID_REUSE => false, CURLOPT_FOLLOWLOCATION => true, CURLOPT_VERBOSE => false, CURLOPT_SSL_VERIFYPEER => true, CURLOPT_SSL_VERIFYHOST => true, CURLOPT_USERAGENT => FajrConfig::get('Connection.UserAgent')); // overridnutie adresara pre certifikaty if (FajrConfig::get('SSL.CertificatesDir')) { $options[CURLOPT_CAPATH] = FajrConfig::get('SSL.CertificatesDir'); } $container->setParameter('CurlConnection.options', $options); }
/** * Configure injection of SessionInitializer.class * * @param sfServiceContainerBuilder $container Symfony container to configure */ public function configure(sfServiceContainerBuilder $container) { $lifeTimeSec = 36000; $options = array('session_cookie_lifetime' => $lifeTimeSec, 'session_cookie_path' => '/', 'session_cookie_domain' => '.' . $_SERVER['HTTP_HOST'], 'session_cookie_secure' => FajrConfig::get('SSL.Require'), 'session_cookie_httponly' => true, 'session_name' => 'fajr_session_id'); // cache expire, server ini_set("session.gc_maxlifetime", $lifeTimeSec); ini_set("session.cookie_lifetime", $lifeTimeSec); // custom cache expire is possible only for custom session directory session_save_path(FajrConfig::getDirectory('Path.Temporary.Sessions')); // Note, we can't use setParameters as it will destroy previous values! $container->setParameter('session.options', $options); $container->register('Session.Storage.class', 'sfSessionStorage')->addArgument('%session.options%')->setShared(true); }
/** * Configures Trace.class for injection. * * @param sfServiceContainer $container Container to configure */ public function configure(sfServiceContainerBuilder $container) { if (FajrConfig::get('Debug.Trace') === true) { $debugFile = FajrConfig::getDirectory('Debug.Trace.File'); if ($debugFile !== null) { $container->setParameter('Debug.Trace.File', $debugFile); $container->setParameter('Debug.Trace.File.Mode', 'a'); $container->register('Debug.Trace.File.class', 'fajr\\util\\PHPFile')->addArgument('%Debug.Trace.File%')->addArgument('%Debug.Trace.File.Mode%'); $container->register('Trace.class', 'fajr\\FileTrace')->addArgument(new sfServiceReference('Timer.class'))->addArgument(new sfServiceReference('Debug.Trace.File.class'))->addArgument(0)->addArgument('--Trace--'); } else { $container->register('Trace.class', 'fajr\\ArrayTrace')->addArgument(new sfServiceReference('Timer.class'))->addArgument('--Trace--'); } } else { $container->register('Trace.class', 'fajr\\libfajr\\pub\\base\\NullTrace'); } }
/** * Generate a page content * @param Response $response response data to use to generate output * @return string Generated output to be sent to the browser */ public function display(Response $response) { if ($response->getTemplate() === null) { return; } $templateDir = FajrConfig::getDirectory('Template.Directory'); $loader = new Twig_Loader_Filesystem($templateDir); $twig = new Twig_Environment($loader, array('base_template_class' => '\\fajr\\rendering\\Template', 'strict_variables' => true)); $twig->addExtension(new Twig_Extension_Escaper()); // Register fajr's rendering extension $twig->addExtension(new Extension()); $templateName = 'pages/' . $response->getTemplate() . '.xhtml'; $template = $twig->loadTemplate($templateName); $output = $template->render($response->getData()); return $output; }
public function prepare() { if (self::$prepared) { throw new IllegalStateException("Input::prepare should be called only once per request."); } self::$prepared = true; if (FajrConfig::get('URL.Path')) { $_get = array_merge(FajrRouter::pathToParams(FajrUtils::pathInfo()), $_GET); } else { $_get = $_GET; } $_post = $_POST; // budeme pouzivat uz len Input unset($_GET); unset($_POST); $this->_get = $this->_prepare_array($_get, $this->allowed_get); $this->_post = $this->_prepare_array($_post, $this->allowed_post); $this->inputParameters = array_merge($this->_get, $this->_post); }
konfiguračných volieb by mali byť vhodné pre väčšinu inštalácií, no napriek tomu ponúkame možnosť ich pohodlne zmeniť na jednom mieste - v tomto súbore. </p> <p> <strong>Dôležité:</strong> Pred používaním aplikácie je ešte nutné správne nastaviť skupinu na <code>www-data</code> (alebo pod čím beží webserver) a práva na adresáre <code>./temp</code>, <code>./temp/cookies</code> a <code>./temp/sessions</code> (alebo na tie, čo ste nastavili v konfigurácii), tak, aby boli nastavené práva len na zapisovanie a použitie , t.j. <code>d----wx---</code>. </p> '); } if (FajrConfig::get('SSL.Require') && !FajrUtils::isHTTPS()) { fajr_bootstrap_error(' <p> Pre túto inštanciu fajr-u je vyžadované HTTPS spojenie. Prosím skontrolujte prepisovacie pravidlá v <code>.htaccess</code> (alebo konfigurácii web servera), ktoré presmerovávajú HTTP spojenia na HTTPS. Ak nechcete vyžadovať SSL spojenie, je možné túto kontrolu vypnúť v konfiguračnom súbore, <strong>avšak na produkčných inštaláciách, alebo inštaláciách s funkčným SSL sa neodporúča túto kontrolu vypínať. </strong> </p> '); } // bootstrapping whole application $modules = array(new TimerModule($startTime), new StatisticsModule(), new ContextModule(), new ControllerModule(), new DisplayManagerModule(), new CurlConnectionOptionsModule(), new SessionModule(), new TraceModule(), new LoginFactoryModule(), new InputModule()); $injector = new Injector($modules);
* @param string $key * @returns string absolute path for the directory specified in configuration * or null if this option was not specified and does not have * a default value * @see FajrConfig::$defaultOptions * @see FajrConfig::$directoriesRelativeTo * @see configuration.example.php */ public static function getDirectory($key) { self::assertInitialized(); $dir = self::get($key); if ($dir === null) { return null; } if (FajrUtils::isAbsolutePath($dir)) { return $dir; } // default resolve relative $relativeTo = FajrUtils::joinPath(dirname(__FILE__), '..'); $parameters = self::getParameterDescription(); assert(array_key_exists($key, $parameters)); $param = $parameters[$key]; if (array_key_exists('relativeTo', $param)) { $relativeTo = self::getDirectory($param['relativeTo']); } return FajrUtils::joinPath($relativeTo, $dir); } } FajrConfig::load();
#!/usr/bin/php <?php use fajr\FajrConfig; // register our autoloader require_once __DIR__ . '/../src/libfajr/libfajr.php'; Loader::register(); Loader::searchForClasses(__DIR__ . '/../src', true); if (!FajrConfig::isConfigured()) { echo 'Chyba: Fajr nie je nakonfigurovany' . "\n"; return; } if (!FajrConfig::get('Template.Cache')) { echo 'Info: Template cache je vypnuta, nema zmysel ju mazat' . "\n"; return; } $path = FajrConfig::getDirectory('Template.Cache.Path'); echo 'Info: Template cache je ' . $path . "\n"; foreach (new DirectoryIterator($path) as $fileInfo) { if (!$fileInfo->isDot() && $fileInfo->isFile()) { unlink($fileInfo->getPathname()); } }
date_default_timezone_set('Europe/Bratislava'); mb_internal_encoding("UTF-8"); // register Symfony autoloader first, because ours will eat the loading instead. require_once '../third_party/symfony_di/lib/sfServiceContainerAutoloader.php'; sfServiceContainerAutoloader::register(); // register Twig autoloader require_once '../third_party/twig/lib/Twig/Autoloader.php'; Twig_Autoloader::register(); // register our autoloader require_once 'libfajr/libfajr.php'; Loader::register(); Loader::searchForClasses(dirname(__FILE__), true); // TODO(ppershing): move this to libfajr/Loader.php as that is the right place for it require_once 'libfajr/Assert.php'; // is there configuration.php file present? if (!FajrConfig::isConfigured()) { fajr_bootstrap_error(' <p> Fajr nie je nakonfigurovaný, prosím skopírujte súbor <code>config/configuration.example.php</code> do <code>config/configuration.php</code>. Prednastavené hodnoty konfiguračných volieb by mali byť vhodné pre väčšinu inštalácií, no napriek tomu ponúkame možnosť ich pohodlne zmeniť na jednom mieste - v tomto súbore. </p> <p> <strong>Dôležité:</strong> Pred používaním aplikácie je ešte nutné správne nastaviť skupinu na <code>www-data</code> (alebo pod čím beží webserver) a práva na adresáre <code>./temp</code>, <code>./temp/cookies</code> a <code>./temp/sessions</code> (alebo na tie, čo ste nastavili v
/** * Configure injection of SessionInitializer.class * * @param sfServiceContainer $container Symfony container to configure */ public function configure(sfServiceContainer $container) { $container->register('SessionInitializer.class', 'fajr\\SessionInitializer')->addArgument('%session.life_time_sec%')->addArgument('%session.save_path%')->addArgument('%session.path%')->addArgument('%session.domain%'); $container->setParameters(array('session.life_time_sec' => 36000, 'session.save_path' => FajrConfig::getDirectory('Path.Temporary.Sessions'), 'session.path' => '/', 'session.domain' => '.' . $_SERVER['HTTP_HOST'])); }
public function runLogic(Trace $trace, HttpConnection $connection) { $serverConnection = new AIS2ServerConnection($connection, new AIS2ServerUrlMap(FajrConfig::get('AIS2.ServerName'))); $timer = new SystemTimer(); if (Input::get('logout') !== null) { FajrUtils::logout($serverConnection); // TODO(anty): fix this in a better way if (FajrConfig::get('Login.Type') == 'cosign') { // location header set in CosignProxyLogin // but we can't exit there because // the session wouldn't get dropped exit; } FajrUtils::redirect(array(), 'index.php'); } $loggedIn = FajrUtils::isLoggedIn($serverConnection); $cosignLogin = $this->provideLogin(); if (!$loggedIn && $cosignLogin != null) { FajrUtils::login($trace->addChild("logging in"), $cosignLogin, $serverConnection); $loggedIn = true; } if ($loggedIn) { DisplayManager::addContent('<div class=\'logout\'><a class="button negative" href="' . FajrUtils::linkUrl(array('logout' => true)) . '"> <img src="images/door_in.png" alt=""/>Odhlásiť</a></div>'); $screenFactory = new VSES017\VSES017_factory($serverConnection); $adminStudia = $screenFactory->newAdministraciaStudiaScreen($trace); if (Input::get('studium') === null) { Input::set('studium', 0); } $zoznamStudii = $adminStudia->getZoznamStudii($trace->addChild("Get Zoznam Studii:")); $zoznamStudiiTable = new Table(TableDefinitions::zoznamStudii(), 'studium', array('tab' => Input::get('tab'))); $zoznamStudiiTable->addRows($zoznamStudii->getData()); $zoznamStudiiTable->setOption('selected_key', Input::get('studium')); $zoznamStudiiTable->setOption('collapsed', true); $zoznamStudiiCollapsible = new Collapsible(new HtmlHeader('Zoznam štúdií'), $zoznamStudiiTable, true); DisplayManager::addContent($zoznamStudiiCollapsible->getHtml()); $zapisneListy = $adminStudia->getZapisneListy($trace->addChild('getZapisneListy'), Input::get('studium')); $zapisneListyTable = new Table(TableDefinitions::zoznamZapisnychListov(), 'list', array('studium' => Input::get('studium'), 'tab' => Input::get('tab'))); if (Input::get('list') === null) { $tmp = $zapisneListy->getData(); $lastList = end($tmp); Input::set('list', $lastList['index']); } $zapisneListyTable->addRows($zapisneListy->getData()); $zapisneListyTable->setOption('selected_key', Input::get('list')); $zapisneListyTable->setOption('collapsed', true); $zapisneListyCollapsible = new Collapsible(new HtmlHeader('Zoznam zápisných listov'), $zapisneListyTable, true); DisplayManager::addContent($zapisneListyCollapsible->getHtml()); $terminyHodnotenia = $screenFactory->newTerminyHodnoteniaScreen($trace, $adminStudia->getZapisnyListIdFromZapisnyListIndex($trace, Input::get('list')), $adminStudia->getStudiumIdFromZapisnyListIndex($trace, Input::get('list'))); if (Input::get('tab') === null) { Input::set('tab', 'TerminyHodnotenia'); } $tabs = new TabManager('tab', array('studium' => Input::get('studium'), 'list' => Input::get('list'))); // FIXME: chceme to nejak refaktorovat, aby sme nevytvarali zbytocne // objekty, ktore v konstruktore robia requesty $hodnoteniaScreen = $screenFactory->newHodnoteniaPriemeryScreen($trace, $adminStudia->getZapisnyListIdFromZapisnyListIndex($trace, Input::get('list'))); $tabs->addTab('TerminyHodnotenia', 'Moje skúšky', new MojeTerminyHodnoteniaCallback($trace, $terminyHodnotenia, $hodnoteniaScreen)); $tabs->addTab('ZapisSkusok', 'Prihlásenie na skúšky', new ZoznamTerminovCallback($trace, $terminyHodnotenia, $hodnoteniaScreen)); $tabs->addTab('ZapisnyList', 'Zápisný list', new ZapisanePredmetyCallback($trace, $terminyHodnotenia)); $tabs->addTab('Hodnotenia', 'Hodnotenia/Priemery', new HodnoteniaCallback($trace, $hodnoteniaScreen)); $tabs->setActive(Input::get('tab')); DisplayManager::addContent($tabs->getHtml()); $version = '<div>Fajr verzia ' . hescape(Version::getVersionString()) . '</div>'; DisplayManager::addContent($version); $statistics = "<div> Fajr made " . $this->statsConnection->getTotalCount() . " requests and downloaded " . $this->rawStatsConnection->getTotalSize() . " bytes (" . $this->statsConnection->getTotalSize() . " bytes uncompressed) of data from AIS2 in " . sprintf("%.3f", $this->statsConnection->getTotalTime()) . " seconds. It took " . sprintf("%.3f", $timer->getElapsedTime()) . " seconds to generate this page.</div>"; DisplayManager::addContent($statistics); } else { if (FajrConfig::get('Login.Type') == 'password') { DisplayManager::addContent('loginBox', true); } else { if (FajrConfig::get('Login.Type') == 'cosign') { DisplayManager::addContent('cosignLoginBox', true); } else { throw new Exception('Nespravna hodnota konfiguracnej volby Login.Type'); } } DisplayManager::addContent('warnings', true); DisplayManager::addContent('terms', true); DisplayManager::addContent('credits', true); $version = "<div class='version prepend-1 span-21 last increase-line-height'>\n<strong>Verzia fajru:</strong> \n"; $version .= hescape(Version::getVersionString()); $version .= '</div>'; DisplayManager::addContent($version); DisplayManager::addContent(Version::getChangelog(), false); } }
/** * Returns a cookie file path for current session. * * Cookie file name is not the same as session_id() so that if one * configures the same path for cookie and session directories, * the filenames do not clash. * * @returns string file path to use to store cookies into. */ public static function getCookieFile() { return self::joinPath(FajrConfig::getDirectory('Path.Temporary.Cookies'), 'cookie_' . session_id()); }
public function runLogic(Trace $trace, HttpConnection $connection) { $response = $this->context->getResponse(); $response->set('version', new Version()); $response->set('banner_debug', FajrConfig::get('Debug.Banner')); // TODO(anty): toto by chcelo nastavovat nejako lepsie $response->set('banner_beta', FajrConfig::get('AIS2.ServerName') == 'ais2-beta.uniba.sk'); $response->set('google_analytics', FajrConfig::get('GoogleAnalytics.Account')); $response->set('serverName', FajrConfig::get('AIS2.ServerName')); $response->set('cosignCookieName', FajrConfig::get('Login.Cosign.CookieName')); $response->set('instanceName', FajrConfig::get('AIS2.InstanceName')); $serverConnection = new AIS2ServerConnection($connection, new AIS2ServerUrlMap(FajrConfig::get('AIS2.ServerName'))); $this->context->setAisConnection($serverConnection); $action = $this->context->getRequest()->getParameter('action', 'studium.MojeTerminyHodnotenia'); if ($action == 'logout') { FajrUtils::logout($serverConnection); // TODO(anty): fix this in a better way if (FajrConfig::get('Login.Type') == 'cosign') { // location header set in CosignProxyLogin // but we can't exit there because // the session wouldn't get dropped exit; } FajrUtils::redirect(array(), 'index.php'); } else { if ($action == 'termsOfUse') { $response->setTemplate('termsOfUse'); return; } } $loggedIn = FajrUtils::isLoggedIn($serverConnection); $cosignLogin = $this->provideLogin(); if (!$loggedIn && $cosignLogin != null) { FajrUtils::login($trace->addChild("logging in"), $cosignLogin, $serverConnection); $loggedIn = true; } if ($loggedIn) { $controller = $this->injector->getInstance('Controller.class'); $response->set("action", $action); $controller->invokeAction($trace, $action, $this->context); $response->set('statistics', $this->statistics); } else { if (FajrConfig::get('Login.Type') == 'password') { $response->setTemplate('welcome'); } else { $response->setTemplate('welcomeCosign'); } } }
private function setResponseFields(Response $response) { $response = $this->context->getResponse(); $response->set('version', new Version()); $response->set('banner_debug', FajrConfig::get('Debug.Banner')); $response->set('google_analytics', FajrConfig::get('GoogleAnalytics.Account')); $response->set('base', FajrUtils::basePath()); $response->set('language', 'sk'); $response->set('availableServers', array()); $response->set('currentServer', array('isBeta' => false, 'instanceName' => 'Chyba')); $server = $this->getServer(); $serverList = FajrConfig::get('AIS2.ServerList'); $response->set('availableServers', $serverList); $response->set('currentServer', $server); $response->set('aisVersion', null); $response->set('aisVersionIncompatible', false); }
private function setResponseFields(Response $response) { $response = $this->context->getResponse(); $response->set('version', new Version()); $response->set('banner_debug', FajrConfig::get('Debug.Banner')); $response->set('google_analytics', FajrConfig::get('GoogleAnalytics.Account')); $response->set('instanceName', FajrConfig::get('AIS2.InstanceName')); $response->set('base', FajrUtils::basePath()); $response->set('language', 'sk'); $server = $this->getServer(); $serverList = FajrConfig::get('AIS2.ServerList'); $response->set('availableServers', $serverList); $response->set('currentServer', $server); // $response->set('serverName', $server->getServerName()); // $response->set('banner_beta', $server->isBeta()); // $response->set('cosignCookieName', $server->getCosignCookieName()); }