/**
  * Invoke an action given its name
  *
  * This function requests information necessary to operate on
  * VSES017 AIS application
  *
  * @param Trace $trace trace object
  * @param string $action action name
  * @param Context $context fajr context
  */
 public function invokeAction(Trace $trace, $action, Context $context)
 {
     $request = $context->getRequest();
     $response = $context->getResponse();
     Preconditions::checkIsString($action);
     $this->screenFactory = new VSES017\VSES017_factory($context->getAisConnection());
     $this->adminStudia = $this->screenFactory->newAdministraciaStudiaScreen($trace);
     $this->studium = $request->getParameter('studium', '0');
     $this->zoznamStudii = $this->adminStudia->getZoznamStudii($trace->addChild("Get Zoznam Studii:"));
     $this->zapisneListy = $this->adminStudia->getZapisneListy($trace->addChild('getZapisneListy'), $this->studium);
     $this->zapisnyList = $request->getParameter('list');
     if (empty($this->zapisnyList)) {
         $tmp = $this->zapisneListy->getData();
         $lastList = end($tmp);
         $this->zapisnyList = $lastList['index'];
     }
     $this->terminyHodnoteniaScreen = $this->screenFactory->newTerminyHodnoteniaScreen($trace, $this->adminStudia->getZapisnyListIdFromZapisnyListIndex($trace, $this->zapisnyList), $this->adminStudia->getStudiumIdFromZapisnyListIndex($trace, $this->zapisnyList));
     // FIXME: chceme to nejak refaktorovat, aby sme nevytvarali zbytocne
     // objekty, ktore v konstruktore robia requesty
     $this->hodnoteniaScreen = $this->screenFactory->newHodnoteniaPriemeryScreen($trace, $this->adminStudia->getZapisnyListIdFromZapisnyListIndex($trace, $this->zapisnyList));
     $response->set('zoznamStudii', $this->zoznamStudii);
     $response->set('studium', $this->studium);
     $response->set('zapisneListy', $this->zapisneListy);
     $response->set('zapisnyList', $this->zapisnyList);
     parent::invokeAction($trace, $action, $context);
 }
Example #2
0
 /**
  * Create a new ArrayTrace at the insertion point
  * @param string $header text to use as header
  * @return ArrayTrace child trace object
  */
 public function addChild($header = "")
 {
     Preconditions::checkIsString($header, 'header');
     $child = new ArrayTrace($this->timer, $header);
     $this->children[] = array('info' => $this->getInfoArray(), 'type' => 'trace', 'trace' => $child);
     return $child;
 }
 public function __construct(array $options, $cookieFile)
 {
     Preconditions::checkIsString($cookieFile, '$cookieFile should be string');
     $this->options = $options;
     $this->cookieFile = $cookieFile;
     $this->_curlInit();
 }
 /**
  * @param string $proxyDir path to directory containing cosign proxy files
  */
 public function __construct($proxyDir, $proxyCookieName)
 {
     Preconditions::checkIsString($proxyDir, 'proxyDir');
     Preconditions::checkIsString($proxyDir, 'proxyCookieName');
     $this->proxyDir = $proxyDir;
     $this->proxyCookieName = $proxyCookieName;
 }
 /**
  * @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;
 }
 /**
  * Invoke an action given its name
  *
  * This function requests information necessary to operate on
  * VSES017 AIS application
  *
  * @param Trace $trace trace object
  * @param string $action action name
  * @param Context $context fajr context
  */
 public function invokeAction(Trace $trace, $action, Context $context)
 {
     Preconditions::checkIsString($action);
     $request = $context->getRequest();
     $response = $context->getResponse();
     $session = $context->getSessionStorage();
     // check access to application
     if (!in_array(AIS2ApplicationEnum::ADMINISTRACIA_STUDIA, $session->read('ais/aisApps'))) {
         $response->setTemplate('studium/notAvailable');
         return;
     }
     $screenFactory = $this->factory;
     $adminStudia = $screenFactory->newAdministraciaStudiaScreen($trace);
     $this->studium = $request->getParameter('studium', '0');
     $this->zoznamStudii = $adminStudia->getZoznamStudii($trace->addChild("Get Zoznam Studii:"));
     $this->zapisneListy = $adminStudia->getZapisneListy($trace->addChild('getZapisneListy'), $this->studium);
     FajrUtils::warnWrongTableStructure($response, 'zoznam studii', regression\ZoznamStudiiRegression::get(), $this->zoznamStudii->getTableDefinition());
     FajrUtils::warnWrongTableStructure($response, 'zoznam zapisnych listov', regression\ZoznamZapisnychListovRegression::get(), $this->zapisneListy->getTableDefinition());
     $this->zapisnyList = $request->getParameter('list');
     if ($this->zapisnyList === '') {
         $tmp = $this->zapisneListy->getData();
         $lastList = end($tmp);
         $this->zapisnyList = $lastList['index'];
     }
     $this->terminyHodnoteniaScreen = $screenFactory->newTerminyHodnoteniaScreen($trace, $adminStudia->getZapisnyListIdFromZapisnyListIndex($trace, $this->zapisnyList), $adminStudia->getStudiumIdFromZapisnyListIndex($trace, $this->zapisnyList));
     // FIXME: chceme to nejak refaktorovat, aby sme nevytvarali zbytocne
     // objekty, ktore v konstruktore robia requesty
     $this->hodnoteniaScreen = $screenFactory->newHodnoteniaPriemeryScreen($trace, $adminStudia->getZapisnyListIdFromZapisnyListIndex($trace, $this->zapisnyList));
     $response->set('zoznamStudii', $this->zoznamStudii);
     $response->set('studium', $this->studium);
     $response->set('zapisneListy', $this->zapisneListy);
     $response->set('zapisnyList', $this->zapisnyList);
     parent::invokeAction($trace, $action, $context);
 }
Example #7
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;
 }
 /**
  * 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 Context $context fajr context
  */
 public function invokeAction(Trace $trace, $action, Context $context)
 {
     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');
     }
     $method->invoke($this, $trace, $context);
 }
 public function closeDialog($dialogUid)
 {
     Preconditions::checkContainsInteger($dialogUid);
     if ($this->openedDialog != $dialogUid) {
         throw new IllegalStateException("Zatváram zlý dialóg!");
     }
     $this->openedDialog = null;
 }
Example #10
0
 public function write($string)
 {
     Preconditions::checkIsString($string, '$string must be string');
     $this->checkNotClosed();
     if (@fwrite($this->handle, $string) === false) {
         throw new Exception("Cannot write file");
     }
 }
 /**
  * Generate a page content
  * @param Response $response response data to use to generate output
  * @return string Generated output to be sent to the browser
  */
 public function display(Response $response)
 {
     Preconditions::checkNotNull($response->getTemplate(), "Template not set");
     $templateName = 'pages/' . $response->getTemplate() . '.xhtml';
     $template = $this->twig->loadTemplate($templateName);
     $output = $template->render($response->getData());
     return $output;
 }
Example #12
0
 /**
  * @param string $name name of the skin to retrieve
  *
  * @returns SkinConfig
  * @throws IllegalArgumentException
  */
 public function getSkinByName($name)
 {
     Preconditions::checkIsString($name);
     if (!in_array($name, array_keys($this->skins))) {
         throw new IllegalArgumentException("You must specify a valid skin!");
     }
     return $this->skins[$name];
 }
 /**
  * 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']);
 }
Example #14
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'];
 }
 /**
  * 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'];
 }
Example #16
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));
 }
 /**
  * Invoke an action given its name
  *
  * This function requests information necessary to operate on
  * VSES017 AIS application
  *
  * @param Trace $trace trace object
  * @param string $action action name
  * @param Context $context fajr context
  */
 public function invokeAction(Trace $trace, $action, Context $context)
 {
     Preconditions::checkIsString($action);
     $request = $context->getRequest();
     $response = $context->getResponse();
     $session = $context->getSessionStorage();
     Preconditions::checkNotNull($request);
     Preconditions::checkNotNull($response);
     Preconditions::checkNotNull($session);
     // check access to application
     $apps = $session->read('ais/aisApps');
     if (!is_array($apps)) {
         throw new Exception("Interná chyba - zoznam AIS aplikácii je nekorektný.");
     }
     if (!in_array(AIS2ApplicationEnum::ADMINISTRACIA_STUDIA, $apps)) {
         $response->setTemplate('studium/notAvailable');
         return;
     }
     $screenFactory = $this->factory;
     $adminStudia = $screenFactory->newAdministraciaStudiaScreen($trace);
     $this->administraciaStudiaScreen = $adminStudia;
     $this->studium = $request->getParameter('studium', '0');
     $this->zoznamStudii = $adminStudia->getZoznamStudii($trace->addChild("Get Zoznam Studii:"));
     $this->zapisneListy = $adminStudia->getZapisneListy($trace->addChild('getZapisneListy'), $this->studium);
     FajrUtils::warnWrongTableStructure($trace, $response, 'zoznam studii', regression\ZoznamStudiiRegression::get(), $this->zoznamStudii->getTableDefinition());
     FajrUtils::warnWrongTableStructure($trace, $response, 'zoznam zapisnych listov', regression\ZoznamZapisnychListovRegression::get(), $this->zapisneListy->getTableDefinition());
     $zapisneListyData = $this->zapisneListy->getData();
     if (count($zapisneListyData) == 0) {
         $this->zapisnyList = null;
         $this->terminyHodnoteniaScreen = null;
         $this->hodnoteniaScreen = null;
     } else {
         $this->zapisnyList = $request->getParameter('list');
         if ($this->zapisnyList === '') {
             $lastList = end($zapisneListyData);
             $this->zapisnyList = $lastList['index'];
         }
         $this->terminyHodnoteniaScreen = $screenFactory->newTerminyHodnoteniaScreen($trace, $adminStudia->getZapisnyListIdFromZapisnyListIndex($trace, $this->zapisnyList, VSES017\AdministraciaStudiaScreen::ACTION_TERMINY_HODNOTENIA), $adminStudia->getStudiumIdFromZapisnyListIndex($trace, $this->zapisnyList, VSES017\AdministraciaStudiaScreen::ACTION_TERMINY_HODNOTENIA));
         // FIXME: chceme to nejak refaktorovat, aby sme nevytvarali zbytocne
         // objekty, ktore v konstruktore robia requesty
         $this->hodnoteniaScreen = $screenFactory->newHodnoteniaPriemeryScreen($trace, $adminStudia->getZapisnyListIdFromZapisnyListIndex($trace, $this->zapisnyList, VSES017\AdministraciaStudiaScreen::ACTION_HODNOTENIA_PRIEMERY));
     }
     $response->set('zoznamStudii', $this->zoznamStudii);
     $response->set('studium', $this->studium);
     $response->set('zapisneListy', $this->zapisneListy);
     $response->set('zapisnyList', $this->zapisnyList);
     if (array_key_exists($action, $this->actionInfo)) {
         $info = $this->actionInfo[$action];
         if ($info['requiresZapisnyList'] && $this->zapisnyList == null) {
             $response->set('activeTab', $info['tabName']);
             $response->setTemplate('studium/chybaZapisnyList');
             return;
         }
     }
     parent::invokeAction($trace, $action, $context);
 }
Example #19
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;
 }
 public function runInformacnyList(Trace $trace, Context $context)
 {
     $request = $context->getRequest();
     $response = $context->getResponse();
     $code = $request->getParameter('code');
     Preconditions::check(!empty($code), "Nezadaný kód predmetu!");
     $content = $this->registerPredmetovScreen->getInformacnyList($trace, $code);
     $content = iconv("Windows-1250", "UTF-8", $content);
     $response->setTemplate('predmety/informacnyList');
     $response->set('content', $content);
 }
Example #21
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;
 }
Example #22
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 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;
 }
 /**
  * Generate a page content
  *
  * @param Response $response response data to use to generate output
  *
  * @returns string Generated output to be sent to the browser
  */
 public function display(Response $response)
 {
     Preconditions::checkNotNull($response->getTemplate(), "Template not set");
     if ($response->getSkin()) {
         $skin = $response->getSkin();
     } else {
         $skin = $this->defaultSkin;
     }
     $twig = $this->twigFactory->provideTwigForSkin($skin);
     $templateName = 'pages/' . $response->getTemplate() . '.xhtml';
     $template = $twig->loadTemplate($templateName);
     $output = $template->render($response->getData());
     return $output;
 }
 /**
  * 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;
 }
 /**
  * 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;
 }
 /**
  * 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;
 }
 /**
  * Invoke an action given its name
  *
  * This function lookups the controller to be used in a lookup table,
  * tries to instantiate it and dispatch the request
  *
  * @param Trace $trace trace object
  * @param string $action action name
  * @param Context $context fajr context
  */
 public function invokeAction(Trace $trace, $action, Context $context)
 {
     Preconditions::checkIsString($action);
     $parts = explode('.', $action, 2);
     if (count($parts) != 2) {
         throw new Exception('Action name does not contain "."');
     }
     if (empty($this->classNameTable[$parts[0]])) {
         throw new Exception('Could not find a mapping for action ' . $action);
     }
     $className = $this->classNameTable[$parts[0]];
     $instance = new $className();
     if (!$instance instanceof Controller) {
         throw new Exception('Class "' . $className . '" mapped to action "' . $action . '" is not a controller');
     }
     $instance->invokeAction($trace->addChild('Target action ' . $parts[1]), $parts[1], $context);
 }
 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;
 }