/**
  * Nadviaže spojenie, spustí danú "aplikáciu" v AISe
  * a natiahne prvotné dáta do atribútu $data.
  */
 public function requestOpen(Trace $trace, ScreenData $data)
 {
     $trace->tlog("open screen");
     $url = $this->requestBuilder->getAppInitializationUrl($data);
     $response = $this->connection->request($trace->addChild("get app id"), $url);
     $this->appId = $this->parseAppIdFromResponse($response);
     $response = $this->doRequest($trace->addChild("Init command"), array('eventClass' => 'avc.ui.event.AVCComponentEvent', 'command' => 'INIT'));
     $this->formName = $this->parseFormNameFromResponse($response);
 }
 public function getOptionsFromHtml(Trace $trace, $aisResponseHtml, $elementId)
 {
     Preconditions::checkIsString($aisResponseHtml);
     Preconditions::checkIsString($elementId);
     $html = $this->fixProblematicTags($trace->addChild("Fixing html for better DOM parsing."), $aisResponseHtml);
     $domWholeHtml = $this->createDomFromHtml($trace, $html);
     $element = $this->findEnclosingElement($trace, $domWholeHtml, $elementId);
     // ok, now we have restricted document
     $options = $this->getOptions($trace->addChild("Get options"), $element);
     return $options;
 }
Beispiel #3
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 #4
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;
 }
 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 #7
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;
     }
 }
 /**
  * Parses <b> element, as after <b> elements occur data, that needs to
  * be extracted.
  *
  * @param DOMElement $final
  * @param array $pole
  *
  * @returns array with parsed data
  */
 private function spracujB(Trace $trace, DOMElement $final)
 {
     //do attribue_names pridam element, podla ktoreho parsujem
     $attributeName = ParserUtils::fixNbsp($final->nodeValue);
     $this->attribute_names[] = $attributeName;
     $child = $trace->addChild("Parsing attribute '{$attributeName}'");
     $sused = $final->nextSibling;
     if ($sused == NULL) {
         $child->tlog("No value to parse");
         return;
     }
     if ($sused->nextSibling == NULL) {
         // je textNode
         $child->tlog("Attribute is text node");
         $child->tlogVariable("Parsed attribute:", $sused->nodeValue);
         $values = array(self::fixAttributeValue($sused->nodeValue));
         $this->setAttribute($trace, $attributeName, $values);
         return;
     }
     $textSused = $sused->nextSibling;
     if ($textSused->nodeType != \XML_ELEMENT_NODE) {
         $child->tlog("Nothing to parse here");
         return;
     }
     if ($textSused->tagName == 'p') {
         $child->tlog("Parsing <p> tags");
         $values = array();
         for (; $textSused != null; $textSused = $textSused->nextSibling) {
             if ($textSused->nodeType != \XML_ELEMENT_NODE || $textSused->tagName != 'p') {
                 continue;
             }
             $values[] = self::fixAttributeValue($textSused->nodeValue);
         }
         $child->tlogVariable("Parsed attribute:", $values);
         $this->setAttribute($trace, $attributeName, $values);
     } else {
         $child->tlog("Parsing other tags");
         $child->tlogVariable("Parsed attribute:", $sused->nodeValue);
         $values = array(self::fixAttributeValue($sused->nodeValue));
         $this->setAttribute($trace, $attributeName, $values);
     }
 }
Beispiel #9
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 #10
0
 /**
  * Update Table from aisResponse
  *
  * @param Trace $trace for creating logs, tracking activity
  * @param DOMDocument $aisResponse AIS2 html parsed reply
  * @param boolean $init if init is true, table must find data and definition
  */
 public function updateComponentFromResponse(Trace $trace, DOMDocument $aisResponse, $formName, $init = null)
 {
     Preconditions::checkNotNull($aisResponse);
     if ($init) {
         $element = $aisResponse->getElementById($this->dataViewName);
     } else {
         $element = $aisResponse->getElementById($formName . '_' . $this->dataViewName);
     }
     if ($element === null) {
         if ($init) {
             throw new ParseException("Problem parsing ais2 response: Element '{$dataViewName}' not found");
         } else {
             return;
         }
     }
     $dom = new DOMDocument();
     $dom->appendChild($dom->importNode($element, true));
     // ok, now we have restricted document
     //informacia ci sa jedna o update, append...
     $element2 = $dom->getElementById("dataTabBodies");
     if ($element2 === null) {
         throw new ParseException("Problem parsing ais2 response: Element dataTabBodies not found");
     }
     if ($init) {
         $this->definition = $this->getDefinitionFromDom($trace->addChild("Getting table definition from DOM."), $dom);
     }
     $tdata = $this->getTableDataFromDom($trace->addChild("Getting table data from DOM."), $dom);
     // use column name as array key instead of column index
     assert(is_array($tdata));
     $this->data = array();
     foreach ($tdata as $rowKey => $tableRow) {
         $myRow = array();
         $myRow['index'] = $rowKey;
         assert(count($this->definition) == count($tableRow));
         foreach ($tableRow as $key => $value) {
             assert(is_numeric($key));
             assert(isset($this->definition[$key]));
             $myRow[$this->definition[$key]] = $value;
         }
         $this->data[$rowKey] = $myRow;
     }
 }
Beispiel #11
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 #12
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 #13
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 #14
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;
 }