/**
  * Zatvorí danú "aplikáciu" v AISe,
  */
 public function closeIfNeeded(Trace $trace)
 {
     if (!$this->inUse) {
         return;
     }
     assert($this->openedDialog === null);
     $trace->tlog('closing screen ' . get_class($this));
     $this->inUse = false;
 }
 public function getOptions(Trace $trace, DOMElement $element)
 {
     $options = array();
     $list = $element->getElementsByTagName('option');
     foreach ($list as $node) {
         $value = $this->fixNbsp($node->textContent);
         $options[] = $value;
     }
     $trace->tlogVariable("options", $options);
     return $options;
 }
 /**
  * Zatvorí danú "aplikáciu" v AISe
  */
 public function closeIfNeeded(Trace $trace)
 {
     if (!$this->inUse) {
         return;
     }
     if (!$this->terminated) {
         $trace->tlog('closing dialog ' . get_class($this));
     }
     $this->inUse = false;
     $this->parent->closeDialog($this->uid);
 }
Beispiel #4
0
 public function warnWrongTableStructure(Trace $trace, $tableName, array $expectedDefinition, array $definition)
 {
     Preconditions::checkIsString($tableName);
     if ($expectedDefinition != $definition) {
         $message = array('type' => 'unexpectedTableStructure', 'tableName' => $tableName);
         $this->addWarning($message);
         $child = $trace->addChild("Differences in data table " . $tableName);
         list($del, $both, $ins) = FajrUtils::compareArrays($expectedDefinition, $definition);
         $child->tlogVariable('deleted', $del);
         $child->tlogVariable('unchanged', $both);
         $child->tlogVariable('inserted', $ins);
         $child->tlogVariable('expectedDefinition', $expectedDefinition);
         $child->tlogVariable('definition', $definition);
     }
 }
Beispiel #5
0
 public function runLogin(Trace $trace, Request $request)
 {
     $server = $this->serverManager->getActiveServer();
     try {
         $this->loginManager->login($trace->addChild("Logging in..."), $server);
         // Ak sa niekedy odoberie nasledovny redirect,
         // treba mat na pamati, ze login() moze skoncit s true, false, alebo
         // vynimkou
         return new RedirectResponse($this->generateUrl('homepage', array(), true));
     } catch (LoginException $e) {
         try {
             $this->loginManager->logout($trace);
         } catch (LoginException $e) {
             // do nothing
         }
         throw $e;
     }
 }
 /**
  * Parse a file for cosign proxy cookies
  *
  * @param Trace  $trace trace object
  * @param string $filename
  * @returns array Array of parsed service cookies indexed by name
  */
 public function parseFile(Trace $trace, $filename)
 {
     Preconditions::checkIsString($filename, '$filename should be string.');
     $cookies = array();
     $subTrace = $trace->addChild('Parsing cosign proxy file');
     $subTrace->tlogVariable('filename', $filename);
     @($file = file($filename));
     if ($file === false) {
         $subTrace->tlog('failed');
         throw new ParseException('Cannot read proxy file');
     }
     foreach ($file as $lineContent) {
         $parsed = $this->parseString($subTrace, trim($lineContent));
         if (isset($cookies[$parsed->getName()])) {
             throw new ParseException('Duplicate proxy service entry found ' . 'while parsing proxy cookies');
         }
         $cookies[$parsed->getName()] = $parsed;
     }
     return $cookies;
 }
Beispiel #7
0
 /**
  * Parses ais html into DOM.
  *
  * @param Trace $trace
  * @param string $html
  *
  * @returns DOMDocument parsed DOM
  * @throws ParseException on failure
  */
 public static function createDomFromHtml(Trace $trace, $html)
 {
     Preconditions::checkIsString($html);
     $dom = new DOMDocument();
     $trace->tlog("Loading html to DOM");
     $loaded = @$dom->loadHTML($html);
     if (!$loaded) {
         throw new ParseException("Problem parsing html to DOM.");
     }
     $trace->tlog('Fixing id attributes in the DOM');
     ParserUtils::fixIdAttributes($trace, $dom);
     return $dom;
 }
 public function getInformacnyList(Trace $trace, $kodPredmetu, $akRok = null)
 {
     // TODO(anty): moze sa tu robit aj tento request? (t.j. ten pri otvoreni okna???)
     $response = $this->executor->requestContent($trace->addChild("get content"));
     $options = $this->cbParser->getOptionsFromHtml($trace, $response, 'akRokComboBox');
     // zistime, ktory je aktualny akademicky rok (nemusi byt nutne najnovsi)
     // default je prvy v tabulke
     $akRokIndex = 0;
     if ($akRok !== null) {
         foreach ($options as $k => $v) {
             $akRokIndex = array_search($akRok, $options);
             if ($akRokIndex === false) {
                 throw new Exception("Zadaný akad. rok sa v zozname nenachádza");
             }
         }
     }
     $data = $this->executor->doRequest($trace->addChild("Requesting data:"), array('compName' => 'zobrazitPredmetyAction', 'embObj' => array('skratkaPredmetuTextField' => array('text' => $kodPredmetu), 'akRokComboBox' => array('dataView' => array('selectedIndexes' => $akRokIndex)))));
     $table = $this->parser->createTableFromHtml($trace->addChild("Parsing table"), $data, 'VSST060_RegisterPredmetovDlg0_zoznamPredmetovTable_dataView');
     if (count($table->getData()) == 0) {
         throw new ParseException("Daný kód predmetu sa v zozname nenachádza.");
         return;
     }
     // TODO: nikde nevyberame, ktoreho vrateneho riadku informacny list chceme...
     // asi sa defaultne pouzije prvy - je to OK?
     $data = $this->executor->doRequest($trace->addChild("Requesting data:"), array('compName' => 'informacnyListAction'));
     if (!preg_match("@dm\\(\\)\\.openDialog\\(" . "\"CM017_SpravaSablonDlg1\"@", $data)) {
         throw new Exception("Problém pri sťahovaní: " . "Neočakávaná odozva od AISu");
     }
     $data = $this->executor->doRequest($trace->addChild("Requesting data:"), array('compName' => 'enterAction', 'dlgName' => 'CM017_SpravaSablonDlg1', 'embObj' => array('sablonyTable' => array('dataView' => array('selectedIndexes' => 0), 'editMode' => 'false'))));
     if (!preg_match("@dm\\(\\)\\.closeDialog\\(" . "\"CM017_SpravaSablonDlg1\"\\);@", $data)) {
         throw new Exception("Problém pri sťahovaní: " . "Neočakávaná odozva od AISu");
     }
     $data = $this->executor->doRequest($trace->addChild("Requesting data:"), array('events' => false, 'app' => false, 'dlgName' => false, 'changedProperties' => array('confirmResult' => '-1')));
     if (!preg_match('@shellExec@', $data)) {
         throw new Exception("Problém pri sťahovaní: " . "Neočakávaná odozva od AISu");
     }
     return $this->executor->doFilesRequest($trace, array('file' => '', 'contentType' => ''));
 }
Beispiel #9
0
 /**
  * Update comboBox from aisResponse
  *
  * @param Trace $trace for creating logs, tracking activity
  * @param DOMDocument $aisResponse AIS2 html parsed reply
  * @param boolean $init if it is first opening of window
  */
 public function updateComponentFromResponse(Trace $trace, DOMDocument $aisResponse, $formName, $init = null)
 {
     Preconditions::checkNotNull($aisResponse);
     if ($init) {
         $element = $aisResponse->getElementById($this->comboBoxName);
     } else {
         $element = $aisResponse->getElementById($formName . $this->comboBoxName);
     }
     if ($element === null) {
         if ($init) {
             throw new ParseException("Problem parsing ais2 response: Element '{$comboBoxName}' not found");
         } else {
             return;
         }
     }
     $dom = new DOMDocument();
     $dom->appendChild($dom->importNode($element, true));
     // ok, now we have restricted document
     $this->options = $this->getOptionsFromDom($trace->addChild("Getting comboBox options from DOM."), $dom);
     // we don't know what's selected. the first call to selectOption() should always cause sending XML.
     if ($init) {
         $this->oldSelectedOption = $this->selectedOption = -1;
     }
 }
 private function check(Trace $trace, $url, $response)
 {
     $matches = array();
     if (preg_match(self::INTERNAL_ERROR_PATTERN, $response, $matches)) {
         $trace->tlog("Expection encountered");
         throw $this->newException($matches[1], $url);
     }
     if (preg_match(self::APACHE_ERROR_PATTERN, $response, $matches)) {
         $trace->tlog("Expection encountered");
         throw $this->newException($matches[1], $url);
     }
     if (preg_match(self::UNAUTHORIZED, $response)) {
         $trace->tlog("Exception encountered");
         throw new LoginException("AIS hlási neautorizovaný prístup - má užívateľ prístup k aplikácii?");
     }
     return $response;
 }
Beispiel #11
0
 public function getTableDefinition(Trace $trace, DOMDocument $dom)
 {
     $child = $trace->addChild("finding table definition element");
     $child->tlogVariable("dom", $dom->saveXML());
     $element = $dom->getElementById('dataTabColGroup');
     if ($element == null) {
         throw new ParseException("Can't find table headers");
     }
     $list = $element->getElementsByTagName('col');
     $columns = array();
     foreach ($list as $node) {
         assert($node->hasAttribute('shortname'));
         $columns[] = $node->getAttribute('shortname');
     }
     $child = $trace->addChild("Parsed columns");
     $child->tlogVariable("Parsed columns:", $columns);
     return $columns;
 }
 /**
  * Parses div tag. If it contains <b> element, it calls method spracujB,
  * which parses element <b>.
  *
  * @param domNode $final
  *
  * @returns array
  */
 public function parseDiv(Trace $trace, $final)
 {
     $final2 = $final->childNodes;
     foreach ($final2 as $key) {
         if ($key->nodeType != \XML_ELEMENT_NODE) {
             continue;
         }
         if ($key->tagName == 'b') {
             $trace->tlog("Parsing node with tag name 'b' inside 'div' tag");
             $this->spracujB($trace, $key);
         }
     }
 }
Beispiel #13
0
 private function prepareResponse(Trace $trace, $html)
 {
     // fixing html code, so DOMDocumet it can parse
     Preconditions::checkIsString($html);
     $html = str_replace("<!--", "", $html);
     $html = str_replace("-->", "", $html);
     // just first javascript code contain data which we want
     $count = 1;
     $html = str_replace("type='application/javascript'", "id='init-data'", $html, $count);
     $html = str_replace("script", "div", $html);
     $html = $this->fixNbsp($html);
     $trace->tlogVariable("Fixed html", $html);
     // creating DOMDocument
     $dom = new DOMDocument();
     $trace->tlog("Loading html to DOM");
     $loaded = @$dom->loadHTML($html);
     if (!$loaded) {
         throw new ParseException("Problem parsing html to DOM.");
     }
     //fixing id atributes
     $trace->tlog('Fixing id attributes in the DOM');
     $xpath = new DOMXPath($dom);
     $nodes = $xpath->query("//*[@id]");
     foreach ($nodes as $node) {
         // Note: do not erase next line. @see
         // http://www.navioo.com/php/docs/function.dom-domelement-setidattribute.php
         // for explanation!
         $node->setIdAttribute('id', false);
         $node->setIdAttribute('id', true);
     }
     return $dom;
 }
Beispiel #14
0
 /**
  * Find an element with specified id in $dom.
  *
  * @param Trace $trace
  * @param DOMDocument $dom document to search
  * @param string $elementId id of element to find
  *
  * @returns DOMElement element
  * @throws ParseException if not found
  */
 public function findEnclosingElement(Trace $trace, DOMDocument $dom, $elementId)
 {
     Preconditions::checkIsString($elementId);
     $trace->tlog("Finding element with id '{$elementId}'");
     $element = $dom->getElementById($elementId);
     if ($element === null) {
         throw new ParseException("Problem parsing ais2 response: Element not found");
     }
     $trace->tlog("Element found");
     $child = $trace->addChild("Element xml content (pretty formatted)");
     $child->tlogVariable("content", $this->prettyFormatXml($element));
     return $element;
 }
Beispiel #15
0
 /**
  * Extract Table data from DOMDocument
  *
  * @param Trace $trace for creating logs, tracking activity
  * @param $dom DOMDocument part of ais2ResponseHTML which contain Table
  * @returns array(string=>array(string)) Returns rows of Table, where index is rowId
  */
 private function getTableDataFromDom(Trace $trace, DOMDocument $dom)
 {
     Preconditions::checkNotNull($dom);
     $tdata = array();
     $trace->tlog("Finding element with id dataTabBody0");
     $element = $dom->getElementById('dataTabBody0');
     if ($element == null) {
         throw new ParseException("Can't find table data");
     }
     $trace->tlog("Element found");
     foreach ($element->childNodes as $aisRow) {
         assert($aisRow->tagName == "tr");
         assert($aisRow->hasAttribute("id"));
         assert($aisRow->hasChildNodes());
         // TODO: asserty prerobit na exceptiony
         $row = array();
         $trace->tlog("Extracting row id.");
         $rowId = $aisRow->getAttribute("id");
         $index = StrUtil::match('@^row_([0-9]+)$@', $rowId);
         if ($index === false) {
             throw new ParseException("Unexpected row id format");
         }
         $trace->tlog("Extraction is correct.");
         $index = intval($index);
         foreach ($aisRow->childNodes as $ais_td) {
             assert($ais_td->tagName == "td");
             $row[] = $this->getCellContent($ais_td);
         }
         $tdata[$index] = $row;
     }
     return $tdata;
 }
 /**
  * Add a serial number to the xml request and make this requset happen
  *
  * @param DOMDocument $action xml request withou serial number
  */
 public function doActionRequest(Trace $trace, $action)
 {
     $finalRequest = new DOMDocument();
     $request = $finalRequest->createElement('request');
     $serialNumber = $this->requestBuilder->newSerial();
     $serial = $finalRequest->createElement('serial', $serialNumber);
     $request->appendChild($serial);
     $finalRequest->appendChild($request);
     foreach ($action->childNodes as $element) {
         $element = $finalRequest->importNode($element, true);
         $finalRequest->documentElement->appendChild($element);
     }
     $data = array('xml_spec' => $finalRequest->saveXML($finalRequest->documentElement));
     $trace->tlogVariable('xml req', $data['xml_spec']);
     return $this->connection->request($trace, $this->getRequestUrl(), $data);
 }
Beispiel #17
0
 /**
  * Returns user's full name as reported by ais.
  *
  * @returns string
  */
 public function getFullUserName(Trace $trace)
 {
     $userNameParser = new AIS2UserNameParser();
     $simpleConn = $this->connection->getSimpleConnection();
     $urlMap = $this->connection->getUrlMap();
     $html = $simpleConn->request($trace->addChild('requesting AIS2 main page'), $urlMap->getStartPageUrl());
     $html = $this->convertEncoding($html);
     $username = $userNameParser->parseUserNameFromMainPage($html);
     $trace->tlogVariable('username', $username);
     return $username;
 }
Beispiel #18
0
 public function runLogic(Trace $trace)
 {
     try {
         $params = $this->router->routeCurrentRequest();
     } catch (ResourceNotFoundException $e) {
         return $this->displayManager->renderResponse('notfound', array(), 'html', 404);
     }
     $action = $params['_action'];
     $controllerClass = $params['_controller'];
     $session = SessionStorageProvider::getInstance();
     $loginManager = LoginManager::getInstance();
     // If we are going to log in, we need 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 ($action == 'Login') {
         $loginManager->destroySession();
     }
     $connection = ConnectionProvider::getInstance();
     $server = $this->serverManager->getActiveServer();
     $serverConnection = new AIS2ServerConnection($connection, new AIS2ServerUrlMap($server->getServerName()));
     $connService = LazyServerConnection::getInstance();
     $connService->setReal($serverConnection);
     $loggedIn = $loginManager->isLoggedIn($serverConnection);
     if (!$loggedIn) {
         try {
             $loggedIn = $loginManager->relogin();
         } catch (ReloginFailedException $ex) {
             $loginManager->destroySession();
             return new \Symfony\Component\HttpFoundation\RedirectResponse($this->router->generateUrl('homepage'));
         }
     }
     $this->displayManager->setDefaultParams(array('loggedIn' => $loggedIn));
     if ($loggedIn) {
         $backendFactory = BackendProvider::getInstance();
         $mainScreen = $backendFactory->newAIS2MainScreen();
         if (($aisVersion = $session->read('ais/aisVersion')) == null) {
             $aisVersion = $mainScreen->getAisVersion($trace->addChild('Get AIS version'));
             $session->write('ais/aisVersion', $aisVersion);
         }
         $this->displayManager->setDefaultParams(array('aisVersion' => $aisVersion, 'aisVersionIncompatible' => !($aisVersion >= regression\VersionRange::getMinVersion() && $aisVersion <= regression\VersionRange::getMaxVersion())));
         if (($aisApps = $session->read('ais/aisApps')) == null) {
             $aisModules = array('SP', 'LZ', 'ES', 'ST', 'RH', 'UB', 'AS', 'RP');
             $aisApps = $mainScreen->getAllAvailableApplications($trace->addChild('Get all applications'), $aisModules);
             $session->write('ais/aisApps', $aisApps);
         }
         if (($userName = $session->read('ais/aisUserName')) == null) {
             $userName = $mainScreen->getFullUserName($trace->addChild('Get user name'));
             $session->write('ais/aisUserName', $userName);
         }
         $this->displayManager->setDefaultParams(array('aisUserName' => $userName));
     }
     $controller = call_user_func(array($controllerClass, 'getInstance'));
     if (!$controller instanceof Controller) {
         throw new Exception('Class "' . $controllerClass . '" is not a controller');
     }
     try {
         $subTrace = $trace->addChild('Action ' . $controllerClass . '->' . $action);
         return $controller->invokeAction($subTrace, $action, $this->request);
     } catch (AuthenticationRequiredException $ex) {
         return new \Symfony\Component\HttpFoundation\RedirectResponse($this->router->generateUrl('homepage'));
     }
 }
Beispiel #19
0
 public function login(Trace $trace, ServerConfig $serverConfig)
 {
     $this->cachedLoggedIn = null;
     $login = $this->provideLogin($serverConfig, $this->request);
     if ($login === null) {
         return false;
     }
     $trace->tlog("logging in");
     if (!$login->login($this->connection)) {
         return false;
     }
     $trace->tlog("logged in correctly.");
     $this->session->write('login/login.class', $login);
     $this->session->write('server', $serverConfig);
     return true;
 }
Beispiel #20
0
 /**
  * Get the full name of the user.
  * Note: resulting string is not sanitized and shouldn't be
  * used by file/other access.
  *
  * @returns string
  */
 public function getFullUserName(Trace $trace)
 {
     $trace->tlog('getting ais username');
     return "Ing. Janko Hraško";
 }
Beispiel #21
0
 /**
  * Akcia ktora sa pokusi prihlasit cloveka na danu skusku
  *
  * @param Trace $trace trace object
  * @param Request $request
  */
 public function runPrihlasNaSkusku(Trace $trace, Request $request)
 {
     if ($this->terminyHodnoteniaScreen == null) {
         return $this->renderResponse('studium/terminyHodnoteniaNedostupne', $this->templateParams);
     }
     $predmetIndex = $request->getParameter("prihlasPredmetIndex");
     $terminIndex = $request->getParameter("prihlasTerminIndex");
     $predmety = $this->terminyHodnoteniaScreen->getPredmetyZapisnehoListu($trace->addChild('Predmety zapisneho listu'));
     $this->warnings->warnWrongTableStructure($trace, 'terminy hodnotenia - predmety', regression\ZapisanePredmetyRegression::get(), $predmety->getTableDefinition());
     $predmetyData = $predmety->getData();
     $predmetKey = -1;
     foreach ($predmetyData as $key => $row) {
         if ((string) $row[PredmetyFields::INDEX] === $predmetIndex) {
             $predmetKey = $key;
         }
     }
     $childTrace = $trace->addChild('Zoznam terminov');
     $terminyDialog = $this->terminyHodnoteniaScreen->getZoznamTerminovDialog($childTrace, $predmetIndex);
     $terminy = $terminyDialog->getZoznamTerminov($childTrace);
     $this->warnings->warnWrongTableStructure($trace, 'zoznam mojich terminov', regression\MojeTerminyRegression::getPrihlasovanie(), $terminy->getTableDefinition());
     $terminyData = $terminy->getData();
     $terminKey = -1;
     foreach ($terminyData as $key => $terminyRow) {
         if ((string) $terminyRow[TerminyFields::INDEX] === $terminIndex) {
             $terminKey = $key;
         }
     }
     if ($predmetKey == -1 || $terminKey == -1) {
         throw new Exception("Ooops, predmet/termín nenájdený. Pravdepodobne\n          zmena dát v AISe.");
     }
     $hash = StudiumUtils::hashNaPrihlasenie($predmetyData[$predmetKey][PredmetyFields::SKRATKA], $terminyData[$terminIndex]);
     if ($hash != $request->getParameter('hash')) {
         throw new Exception("Ooops, nesedia údaje o termíne. Pravdepodobne zmena\n          dát v AISe spôsobila posunutie tabuliek.");
     }
     if (!$terminyDialog->prihlasNaTermin($trace->addChild('prihlasujem na termin'), $terminIndex)) {
         throw new Exception('Na skúšku sa nepodarilo prihlásiť.');
     }
     return new RedirectResponse($this->generateUrl('studium_moje_skusky', array('studium' => $this->studium, 'list' => $this->zapisnyList), true));
 }
Beispiel #22
0
 private function exec(Trace $trace)
 {
     // read cookie file
     $this->_curlSetOption(CURLOPT_COOKIEFILE, $this->cookieFile);
     $output = curl_exec($this->curl);
     $response_code = curl_getinfo($this->curl, CURLINFO_HTTP_CODE);
     $content_type = curl_getinfo($this->curl, CURLINFO_CONTENT_TYPE);
     $tags = array('http-response-code' => $response_code, 'content-type' => $content_type);
     $trace->tlogVariable("Response", $output, $tags);
     $this->processStatistics($this->curl);
     if (curl_errno($this->curl)) {
         $trace->tlog("There was an error receiving data");
         throw new Exception("Chyba pri nadväzovaní spojenia:" . curl_error($this->curl));
     }
     // Do not forget to save current file content
     $this->_curlSetOption(CURLOPT_COOKIEJAR, $this->cookieFile);
     return $output;
 }