/**
  * 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);
 }
Example #2
0
 /**
  * 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;
 }
Example #3
0
 /**
  * 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);
 }
 /**
  * Parse a line of proxy file in a string
  *
  * @param Trace  $trace trace object
  * @param string $line not including line termination characters
  * @returns array service, value and domain from parsed line, indexed by
  *                those strings or false if this is not correct proxy line
  */
 private function parseString(Trace $trace, $line)
 {
     Preconditions::checkIsString($line, '$line should be string.');
     $matches = array();
     if (!preg_match(self::PROXY_LINE_PATTERN, $line, $matches)) {
         $trace->tlog('Line did not match');
         $trace->tlogVariable('line', $line);
         throw new ParseException('Proxy file line does not match');
     }
     try {
         return new CosignServiceCookie($matches[1], $matches[2], $matches[3]);
     } catch (InvalidArgumentException $e) {
         throw new ParseException('Proxy file arguments are invalid', null, $e);
     }
 }
Example #5
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;
 }
 /**
  * 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);
         }
     }
 }
Example #7
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;
 }
Example #8
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;
 }
Example #9
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;
 }
 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;
 }
Example #11
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";
 }
Example #12
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;
 }
Example #13
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;
 }
Example #14
0
 public function getTableData(Trace $trace, DOMDocument $dom)
 {
     $data = array();
     $trace->tlog("finding tbody element");
     $element = $dom->getElementById('dataTabBody0');
     if ($element == null) {
         throw new ParseException("Can't find table data");
     }
     foreach ($element->childNodes as $aisRow) {
         assert($aisRow->tagName == "tr");
         assert($aisRow->hasAttribute("id"));
         assert($aisRow->hasChildNodes());
         // TODO: asserty prerobit na exceptiony
         $row = array();
         $rowId = $aisRow->getAttribute("id");
         $index = StrUtil::match('@^row_([0-9]+)$@', $rowId);
         if ($index === false) {
             throw new ParseException("Unexpected row id format");
         }
         foreach ($aisRow->childNodes as $ais_td) {
             assert($ais_td->tagName == "td");
             $row[] = $this->getCellContent($ais_td);
         }
         $data[$index] = $row;
     }
     $trace->tlogVariable("data", $data);
     return $data;
 }