function dump($s) { if (is_array($s)) { foreach ($s as $value) { dump($value); } } else { echo '<pre>' . hescape($s) . '</pre><hr/>'; } }
private function check($url, $response) { $matches = array(); if (preg_match(self::INTERNAL_ERROR_PATTERN, $response, $matches)) { throw new Exception('<b>Nastala chyba pri requeste.</b><br/>Zdôvodnenie od AISu: ' . hescape($matches[1]) . '<br/>Požadovaná url: ' . hescape($url)); } if (preg_match(self::APACHE_ERROR_PATTERN, $response, $matches)) { throw new Exception('<b>Nastala chyba pri requeste.</b><br/>Zdôvodnenie od AISu: ' . nl2br(hescape($matches[1])) . '<br/>Požadovaná url: ' . hescape($url)); } return $response; }
private function getStatusString() { $caller = $this->getCallerData(2); $class = isset($caller['class']) ? $caller['class'] : ""; $class = preg_replace("@.*\\\\@", "", $class); $function = $caller['function']; $caller = $this->getCallerData(1); $file = $caller['file']; $line = $caller['line']; $snippet = CodeSnippet::getCodeSnippet($file, $line, 5); $tooltipHtml = sprintf("<span class='trace_tooltip'>Function %s::%s()<br/>\n" . "Line: %s<br/>\n" . "File: '%s'<br/>\n" . "<br/>Code snippet:<pre>%s</pre></span>", hescape($class), hescape($function), hescape($line), hescape($file), hescape($snippet)); return sprintf("<span class='trace_s'>%+0.2fs %s</span>", $this->timer->getElapsedTime(), $tooltipHtml); }
public static function dumpRequests($requests) { $html = '<div class="debug">'; foreach ($requests as $request) { $html .= '<div class="debug_connection">'; $html .= '<div class="debug_connection_header"><span class="debug_connection_method">' . hescape($request['method']) . '</span> ' . hescape($request['url']) . '</div>'; $html .= '<div class="debug_connection_auxinfo">' . sprintf("%.3f", $request['startTime']); $html .= 's - ' . sprintf("%.3f", $request['endTime']) . 's ('; $html .= sprintf("%.3f", $request['endTime'] - $request['startTime']); $html .= 's)</div>'; if (isset($request['requestData'])) { $html .= '<div class="debug_connection_block"><div class="debug_connection_block_title">Request data:</div><pre>'; foreach ($request['requestData'] as $name => $value) { $html .= hescape($name) . ': ' . hescape($value); } $html .= '</pre></div>'; } if (isset($request['responseData'])) { $html .= '<div class="debug_connection_block"><div class="debug_connection_block_title">Response data:</div><pre>'; $html .= hescape($request['responseData']); $html .= '</pre></div>'; } if (isset($request['exception'])) { $html .= '<div class="debug_connection_block"><div class="debug_connection_block_title">Response data:</div><pre>'; $html .= hescape($request['exception']->getTraceAsString()); $html .= '</pre></div>'; } $html .= '</div>'; } $html .= '</div>'; self::addContent($html); }
private function newException($reason, $url) { return new Exception('<b>Nastala chyba pri requeste.</b><br/>Zdôvodnenie od AISu:' . nl2br(hescape($reason)) . '<br/>Požadovaná url: ' . hescape($url)); }
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); } }
public function getHtml() { return "<h2>" . hescape($this->text) . "</h2>"; }
public function run() { $timer = new SystemTimer(); $connection = null; $statsConnection = null; $rawStatsConnection = null; $trace = new NullTrace(); if (FajrConfig::get('Debug.Trace') === true) { $trace = new HtmlTrace($timer, "--Trace--"); } try { Input::prepare(); $login = Input::get('login'); Input::set('login', null); $krbpwd = Input::get('krbpwd'); Input::set('krbpwd', null); $cosignCookie = Input::get('cosignCookie'); Input::set('cosignCookie', null); // FIXME this should be refactored if ($login !== null && $krbpwd !== null || $cosignCookie !== null) { // we are going to log in, so we get a clean session // this needs to be done before a connection // is created, because we pass cookie file name // that contains session_id into AIS2CurlConnection // If we regenerated the session id afterwards, // we could not find the cookie file after a redirect FajrUtils::dropSession(); } $connection = new connection\CurlConnection(FajrUtils::getCookieFile()); $rawStatsConnection = new connection\StatsConnection($connection, new SystemTimer()); $connection = $rawStatsConnection; $connection = new connection\GzipDecompressingConnection($connection, FajrConfig::getDirectory('Path.Temporary')); $connection = new connection\AIS2ErrorCheckingConnection($connection); $statsConnection = new connection\StatsConnection($connection, new SystemTimer()); $connection = $statsConnection; $simpleConnection = new connection\HttpToSimpleConnectionAdapter($connection); AIS2Utils::connection($simpleConnection); // toto tu je docasne if (Input::get('logout') !== null) { FajrUtils::logout($connection); FajrUtils::redirect(); } if ($login !== null && $krbpwd !== null) { $loggedIn = FajrUtils::login(new CosignLogin($login, $krbpwd), $connection); $login = null; $krbpwd = null; } else { if ($cosignCookie !== null) { $loggedIn = FajrUtils::login(new AIS2CookieLogin($cosignCookie), $connection); $cosignCookie = null; } else { $loggedIn = FajrUtils::isLoggedIn(); } } 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>'); $adminStudia = new VSES017\AdministraciaStudiaScreen($trace, $simpleConnection); 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 = new VSES017\TerminyHodnoteniaScreen($trace, $simpleConnection, $adminStudia->getIdZapisnyList($trace, Input::get('list')), $adminStudia->getIdStudium($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 = new VSES017\HodnoteniaPriemeryScreen($trace, $simpleConnection, $adminStudia->getIdZapisnyList($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 " . $statsConnection->getTotalCount() . " requests and downloaded " . $rawStatsConnection->getTotalSize() . " bytes (" . $statsConnection->getTotalSize() . " bytes uncompressed) of data from AIS2 in " . sprintf("%.3f", $statsConnection->getTotalTime()) . " seconds. It took " . sprintf("%.3f", $timer->getElapsedTime()) . " seconds to generate this page.</div>"; DisplayManager::addContent($statistics); } else { DisplayManager::addContent('loginBox', true); 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); } } catch (AIS2LoginException $e) { if ($connection) { FajrUtils::logout($connection); } DisplayManager::addException($e); } catch (Exception $e) { DisplayManager::addException($e); } DisplayManager::setBase(hescape(FajrUtils::basePath())); $trace->tlog("everything done, generating html"); if (FajrConfig::get('Debug.Trace') === true) { $traceHtml = $trace->getHtml(); DisplayManager::addContent('<div class="span-24">' . $traceHtml . '<div> Trace size:' . sprintf("%.2f", strlen($traceHtml) / 1024.0 / 1024.0) . ' MB</div></div>'); } echo DisplayManager::display(); }
public static function addException($ex) { $stackTrace = ''; if (FajrConfig::get('Debug.Exception.ShowStacktrace')) { $stackTrace = "\n<b>Stacktrace:</b>\n" . hescape($ex->getTraceAsString()); $stackTrace = nl2br($stackTrace); } $info = '<h2>Pri spracúvaní požiadavky nastala chyba:</h2>'; $info .= nl2br(hescape($ex->getMessage())); self::addContent('<div class="error">' . $info . $stackTrace . '</div>'); }
/** * creates htmlescaped url */ public static function linkUrl($params) { return hescape(self::buildUrl($params)); }
DisplayManager::addContent($tabs->getHtml()); $timeDiff = microtime(true) - $startTime; $version = '<div>Fajr verzia ' . hescape(Version::getVersionString()) . '</div>'; DisplayManager::addContent($version); $statistics = "<div> Fajr made " . $statsConnection->getTotalCount() . " requests and downloaded " . $rawStatsConnection->getTotalSize() . " bytes (" . $statsConnection->getTotalSize() . " bytes uncompressed) of data from AIS2 in " . sprintf("%.3f", $statsConnection->getTotalTime()) . " seconds. It took " . sprintf("%.3f", $timeDiff) . " seconds to generate this page.</div>"; DisplayManager::addContent($statistics); } else { DisplayManager::addContent('loginBox', true); 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); } } catch (AIS2LoginException $e) { if ($connection) { FajrUtils::logout($connection); } DisplayManager::addException($e); } catch (Exception $e) { DisplayManager::addException($e); } if ($debugConnection) { DisplayManager::dumpRequests($debugConnection->getRequests()); } DisplayManager::setBase(hescape(FajrUtils::basePath())); echo DisplayManager::display(); session_write_close();