Пример #1
0
 public function runInformacnyList(Trace $trace, Request $request)
 {
     $searchCode = $request->getParameter('code');
     $format = $request->getParameter('format');
     Preconditions::check(!empty($searchCode), "Nezadaný kód predmetu!");
     // Zistime aktualny akad rok.
     $akadRok = FajrUtils::getAcademicYear();
     $content = $this->registerPredmetovScreen->getInformacnyList($trace, $searchCode, $akadRok);
     // Docasny fix, vrati PDF s informacnym listom
     $response = new \Symfony\Component\HttpFoundation\Response($content, 200);
     $response->headers->set('Content-Type', 'application/pdf');
     return $response;
     $ip = new InformacnyListParser();
     $list = $ip->parse($trace, $content);
     $params = array();
     $params['list'] = $list->getAllAttributes();
     $params['code'] = $searchCode;
     $name = $list->getAttribute('nazov');
     $code = $list->getAttribute('kod');
     if ($code === false) {
         $code = $searchCode;
     } else {
         $code = $code['values'][0];
     }
     if ($name === false) {
         $name = 'Predmet ' . $code;
     } else {
         $name = $name['values'][0];
     }
     $params['subjectName'] = $name;
     return $this->renderResponse('predmety/informacnyList', $params, $format == 'json' ? 'json' : 'html');
 }
Пример #2
0
 /**
  * Returns a securely generated random *bytes* using the supplied providers.
  * Providers will be queried in the same order as the were given to constructor
  * and first which will return random bytes will be used.
  *
  * @param int $count number of random bytes to be generated
  *
  * @returns bytes generated bytes
  * @throws RuntimeException if any error occurs (or no provider returns random bytes)
  *    Warning: Never catch and ignore exceptions from this function!
  */
 public function randomBytes($count)
 {
     Preconditions::check(is_int($count));
     Preconditions::check($count > 0);
     // TODO(ppershing): verify following claim
     // Try the OpenSSL method first. This is the strongest.
     $output = false;
     foreach ($this->providers as $provider) {
         $output = $provider->randomBytes($count);
         if ($output !== false) {
             break;
         }
     }
     // No method was able to generate random bytes.
     // Do not ignore this and throw security error as
     // caller may forgot to check return value.
     if ($output == false) {
         throw new RuntimeException("Unable to generate random bytes.");
     }
     // internal check on sanity
     if (strlen($output) != $count) {
         throw new Exception("Wrong number random bytes were generated. " . "This may be a severe internal error in secure random.");
     }
     return $output;
 }
Пример #3
0
 /**
  * Invoke an action given its name
  *
  * This function checks if public non-abstract non-static runAction method
  * exists in this object and calls it in such a case with request and response
  * parameters
  *
  * @param Trace $trace trace object
  * @param string $action action name
  * @param Request $request incoming request
  */
 public function invokeAction(Trace $trace, $action, Request $request)
 {
     Preconditions::checkIsString($action);
     Preconditions::checkMatchesPattern('@^[A-Z][a-zA-Z]*$@', $action, '$action must start with capital letter and ' . 'contain only letters.');
     $methodName = 'run' . $action;
     if (!method_exists($this, $methodName)) {
         throw new Exception('Action method ' . $methodName . ' does not exist');
     }
     $method = new ReflectionMethod($this, $methodName);
     if (!$method->isPublic()) {
         throw new Exception('Action method ' . $methodName . ' is not public');
     }
     if ($method->isAbstract()) {
         throw new Exception('Action method ' . $methodName . ' is abstract');
     }
     if ($method->isStatic()) {
         throw new Exception('Action method ' . $methodName . ' is static');
     }
     if ($method->isConstructor()) {
         throw new Exception('Action method ' . $methodName . ' is constructor');
     }
     if ($method->isDestructor()) {
         throw new Exception('Action method ' . $methodName . ' is destructor');
     }
     return $method->invoke($this, $trace, $request);
 }
Пример #4
0
 /**
  * @param string $proxyDir path to directory containing cosign proxy files
  */
 public function __construct($proxyDir, $proxyCookieName)
 {
     Preconditions::checkIsString($proxyDir, '$proxyDir should be string.');
     Preconditions::checkIsString($proxyCookieName, '$proxyCookieName should be string');
     $this->proxyDir = $proxyDir;
     $this->proxyCookieName = $proxyCookieName;
 }
Пример #5
0
 /**
  * Create a new ArrayTrace at the insertion point
  * @param string $message text of the message
  * @param array $tags
  * @return ArrayTrace child trace object
  */
 public function addChild($message, array $tags = null)
 {
     Preconditions::checkIsString($message, '$message should be string');
     $child = new ArrayTrace($this->timer, $message);
     $this->children[] = array('info' => $this->getInfoArray(), 'type' => 'trace', 'trace' => $child);
     return $child;
 }
Пример #6
0
 public function invokeAction(Trace $trace, $action, Request $request)
 {
     Preconditions::checkIsString($action);
     if (!$this->loginManager->isLoggedIn()) {
         throw new AuthenticationRequiredException();
     }
     return parent::invokeAction($trace, $action, $request);
 }
Пример #7
0
 public function __construct(array $options, $cookieFile)
 {
     Preconditions::checkIsString($cookieFile, '$cookieFile should be string');
     $this->options = $options;
     $this->cookieFile = $cookieFile;
     $this->_curlInit();
     $this->stats = new RequestStatisticsImpl();
 }
Пример #8
0
 public function closeDialog($dialogUid)
 {
     Preconditions::checkContainsInteger($dialogUid);
     if ($this->openedDialog != $dialogUid) {
         throw new IllegalStateException("Zatváram zlý dialóg!");
     }
     $this->openedDialog = null;
 }
Пример #9
0
 /**
  * Parses the AIS2 version from html page.
  *
  * @param string $html AIS2 html reply to be parsed
  *
  * @returns AIS2Version AIS2 version
  * @throws ParseException on error
  */
 public function parseVersionStringFromMainPage($html)
 {
     Preconditions::checkIsString($html);
     $data = StrUtil::matchAll(self::VERSION_PATTERN, $html);
     if ($data === false) {
         throw new ParseException("Cannot parse AIS version from response.");
     }
     return new AIS2Version(2, $data['major'], $data['minor'], $data['patch']);
 }
Пример #10
0
 /**
  * Parses user name from AIS2 start page
  *
  * @param string $html AIS2 html reply to be parsed
  *
  * @returns AIS2Version AIS2 version
  * @throws ParseException on error
  */
 public function parseUserNameFromMainPage($html)
 {
     Preconditions::checkIsString($html);
     $data = StrUtil::matchAll(self::USERNAME_PATTERN, $html);
     if ($data === false) {
         throw new ParseException("Cannot parse username from response.");
     }
     return $data['username'];
 }
Пример #11
0
 /**
  * Get a value of a given key
  * @param string $key
  * @returns mixed value of a given key
  * @throws InvalidArgumentException if the key does not exist
  */
 public function get($key)
 {
     Preconditions::checkIsString($key);
     // Note: isset() returns false if the item value is null
     if (!array_key_exists($key, $this->config)) {
         throw new InvalidArgumentException('Unknown configuration parameter: ' . $key);
     }
     return $this->config[$key];
 }
 public function getZoznamTerminovDialog(Trace $trace, $predmetIndex)
 {
     Preconditions::checkContainsInteger($predmetIndex);
     $data = $this->executor->readTable(array(), 'zapisanePredmety');
     if (!array_key_exists($predmetIndex, $data)) {
         throw new Exception("Zadaný predmet neexistuje!");
     }
     return new FakeTerminyDialogImpl($trace, $this, array('predmet' => $predmetIndex));
 }
Пример #13
0
 /**
  * Deserialize previously serialized value.
  *
  * @param string $data
  *
  * @returns mixed deserialized value
  */
 public static function deserialize($data)
 {
     Preconditions::checkIsString($data);
     $result = @unserialize($data);
     if ($result == false || !array_key_exists('value', $result)) {
         throw new InvalidArgumentException("Invalid data to deserialize.");
     }
     return $result['value'];
 }
Пример #14
0
 /**
  * Removes data from this storage.
  *
  * @param string $key key to the data
  *
  * @returns mixed data associated with the key
  */
 public function remove($key)
 {
     Preconditions::checkIsString($key);
     $retval = null;
     if (array_key_exists($key, $this->data)) {
         $retval = $this->data[$key];
         unset($this->data[$key]);
     }
     return $retval;
 }
Пример #15
0
 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;
 }
Пример #16
0
 public function __construct($ais, $major, $minor, $patch)
 {
     Preconditions::checkContainsInteger($ais);
     Preconditions::checkContainsInteger($major);
     Preconditions::checkContainsInteger($minor);
     Preconditions::checkContainsInteger($patch);
     $this->ais = $ais;
     $this->major = $major;
     $this->minor = $minor;
     $this->patch = $patch;
 }
Пример #17
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;
 }
Пример #18
0
 public function createTableFromHtml(Trace $trace, $aisResponseHtml, $dataViewName)
 {
     Preconditions::checkIsString($aisResponseHtml);
     Preconditions::checkIsString($dataViewName);
     $html = $this->fixProblematicTags($trace->addChild("Fixing html for better DOM parsing."), $aisResponseHtml);
     $domWholeHtml = $this->createDomFromHtml($trace, $html);
     $element = $this->findEnclosingElement($trace, $domWholeHtml, $dataViewName);
     $dom = new DOMDocument();
     $dom->appendChild($dom->importNode($element, true));
     // ok, now we have restricted document
     $headers = $this->getTableDefinition($trace->addChild("Get table definition"), $dom);
     $data = $this->getTableData($trace->addChild("Get table data"), $dom);
     return new DataTableImpl($headers, $data);
 }
 /**
  * Returns a securely generated random bytes from windows cryptoapi.
  *
  * Warning: use SecureRandom::random() instead
  *
  * @param int $count number of random bytes to be generated
  *
  * @returns bytes|false generated bytes or false on error
  */
 public function randomBytes($count)
 {
     Preconditions::check(is_int($count));
     Preconditions::check($count > 0);
     if (!self::isAvailable()) {
         return false;
     }
     $util = new COM(self::CRYPTOAPI_COM);
     $base64 = $util->GetRandom($count, 0);
     // default encoding is base64
     $output = base64_decode($base64, true);
     // be strict
     return $output;
 }
Пример #20
0
 public function validate($data)
 {
     Preconditions::checkIsString($data, '$data should be string.');
     if (strlen($data) > 0 && $data[0] == '-' && $this->signed) {
         $data = substr($data, 1);
     }
     if (!ctype_digit($data)) {
         throw new ValidationException("Číslo obsahuje neplatné znaky.");
     }
     if (strlen($data) >= 9) {
         throw new ValidationException("Číslo je príliš dlhé.");
     }
     return true;
 }
Пример #21
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);
     }
 }
Пример #22
0
 /**
  * Returns a securely generated random bytes from linux random.
  *
  * Warning: use SecureRandom::random() instead
  *
  * @param int $count number of random bytes to be generated
  *
  * @returns bytes|false generated bytes or false on error
  */
 public function randomBytes($count)
 {
     Preconditions::check(is_int($count));
     Preconditions::check($count > 0);
     if (!self::isAvailable()) {
         return false;
     }
     $handle = @fopen(self::RANDOM_FILE, 'rb');
     $output = @fread($handle, $count);
     @fclose($handle);
     if (strlen($output) !== $count) {
         return false;
         // oops, some problem reading required number of bytes
     }
     return $output;
 }
Пример #23
0
 /**
  * Get the names of all available ais applications
  * from ais menu.
  *
  * @param Trace $trace
  * @param array(string) $modules module names to check
  *
  * @returns array(string) names of applications
  */
 public function getAllAvailableApplications(Trace $trace, array $modules)
 {
     foreach ($modules as $module) {
         Preconditions::checkIsString($module, '$modules must be an array of strings');
     }
     $trace->tlog('getting available applications');
     $moduleApps = array('ES' => array(AIS2ApplicationEnum::ADMINISTRACIA_STUDIA));
     $apps = array();
     foreach ($modules as $module) {
         if (array_key_exists($module, $moduleApps)) {
             $apps = array_merge($apps, $moduleApps[$module]);
         }
     }
     // remove duplicates
     return array_values($apps);
 }
 /**
  * Returns a securely generated random bytes from open SSL.
  *
  * Warning: use SecureRandom::random() instead
  *
  * @param int $count number of random bytes to be generated
  *
  * @returns bytes|false generated bytes or false on error
  */
 public function randomBytes($count)
 {
     Preconditions::check(is_int($count));
     Preconditions::check($count > 0);
     if (!self::isAvailable()) {
         return false;
     }
     // TODO(ppershing): check this on windows: from user comments in manual page:
     // FYI, openssl_random_pseudo_bytes() can be incredibly slow under Windows, to the point of being
     // unusable.
     $output = openssl_random_pseudo_bytes($count, $strong);
     if ($strong === true) {
         // openssl claim the random is strong
         return $output;
     }
     return false;
 }
Пример #25
0
 public function getFullPath(array $options, $tableName)
 {
     Preconditions::checkIsString($tableName);
     Preconditions::check($tableName != '', "Table name must be non-empty");
     $path = '';
     $options = array_merge($this->options, $options);
     foreach ($options as $key => $value) {
         $pathSegment = $key . $value;
         if (!preg_match(self::ALLOWED_CHARS_REGEX, $pathSegment)) {
             throw IllegalArgumentException('Invalid characters in options');
         }
         $path .= '/' . $pathSegment;
     }
     if (!preg_match(self::ALLOWED_CHARS_REGEX, $tableName)) {
         throw IllegalArgumentException('Invalid characters in tableName');
     }
     return $path .= '/' . $tableName;
 }
Пример #26
0
 /**
  * Returns xml request code just for this actionComponent
  *
  * Sample of xml:
  *
  * <events>
  *   <ev>
  *     <dlgName>VSES017_StudentZapisneListyDlg0</dlgName>
  *     <compName>nacitatDataAction</compName>
  *     <event class='avc.ui.event.AVCActionEvent'>
  *   </ev>
  * </events>
  *
  * @return DOMDocument XML object
  */
 public function getActionXML($dlgName)
 {
     Preconditions::checkIsString($dlgName);
     $xml_spec = new DOMDocument();
     $dlgName = $xml_spec->createElement('dlgName', $dlgName);
     $events = $xml_spec->createElement('events');
     $ev = $xml_spec->createElement('ev');
     $compName = $xml_spec->createElement('compName', $this->componentID);
     $event = $xml_spec->createElement('event');
     $atr = $xml_spec->createAttribute("class");
     $atr->value = 'avc.ui.event.AVCActionEvent';
     $event->appendChild($atr);
     $ev->appendChild($dlgName);
     $ev->appendChild($compName);
     $ev->appendChild($event);
     $events->appendChild($ev);
     $xml_spec->appendChild($events);
     return $xml_spec;
 }
Пример #27
0
 /**
  * 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 getPrehladKreditovDialog(Trace $trace, $studiumIndex)
 {
     Preconditions::checkContainsInteger($studiumIndex);
     $studiumId = $this->getStudiumIdFromIndex($studiumIndex);
     return new FakePrehladKreditovDialogImpl($trace, $this, array('studium' => $studiumId));
 }
Пример #29
0
 /**
  * Get table definitions from DOMDocument
  *
  * @param Trace $trace for creating logs, tracking activity
  * @param $dom DOMDocument from ais2ResponseHtml
  * @returns array(string) Definition of table
  */
 private function getOptionsFromDom(Trace $trace, DOMDocument $dom)
 {
     Preconditions::checkNotNull($dom);
     $optionElements = $dom->getElementsByTagName('option');
     if ($optionElements == null) {
         throw new ParseException("Can't find options!");
     }
     $options = array();
     foreach ($optionElements as $option) {
         $options[] = $option->nodeValue;
     }
     return $options;
 }
Пример #30
0
 /**
  * Sets value of parameter identified by $key
  *
  * @param string $key
  * @param mixed $value
  *
  * @returns void
  */
 public function setParameter($key, $value)
 {
     $this->assertInitialized();
     Preconditions::checkIsString($key);
     $this->inputParameters[$key] = $value;
 }