Ejemplo n.º 1
5
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     try {
         $helper = $this->getHelper('question');
         $question = new Question('Please enter the login : '******'');
         $login = $helper->ask($input, $output, $question);
         if ($login == "") {
             throw new \Exception("you must specify login");
         }
         // récupération de la config securité
         $values = \Parameters::get('security');
         $class = $values['security']['classes'];
         $ss = new $class(new Session(), new Request());
         // get user instance
         $user = $ss->userFromLogin($login);
         if ($user == null) {
             throw new \Exception("User {$login} doesn't exist");
         }
         $iduser = $user->id;
         // get all roles
         $roles = $ss->getRoles();
         $strRole = "[";
         foreach ($roles as $role) {
             if ($strRole != "[") {
                 $strRole .= ",";
             }
             $strRole .= $role->role;
         }
         $strRole .= "]";
         $question = new Question('Add roles for ' . $login . ' ' . $strRole . ', type role separated by comma : ', '');
         $roles = $helper->ask($input, $output, $question);
         $output->writeln('Add roles to user');
         if ($roles != "" && $iduser != null) {
             $rolea = \Stringy\Stringy::create($roles)->split(",");
             foreach ($rolea as $role) {
                 $roles = $ss->getRolesFromName(array($role));
                 $role1 = $roles->first();
                 $ss->addUserToRole($iduser, $role1->id);
             }
         }
     } catch (\Exception $e) {
         $output->writeln('Error : ' . $e->getMessage());
     }
     $output->writeln('finished');
 }
Ejemplo n.º 2
2
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     try {
         $helper = $this->getHelper('question');
         $question = new Question('Please enter the login : '******'');
         $login = $helper->ask($input, $output, $question);
         if ($login == "") {
             throw new \Exception("you must specify login");
         }
         $question = new Question('Please enter the mail : ', '');
         $email = $helper->ask($input, $output, $question);
         if ($email == "") {
             throw new \Exception("you must specify a mail");
         }
         $question = new Question('Please enter the password : '******'');
         $password = $helper->ask($input, $output, $question);
         if ($password == "") {
             throw new \Exception("you must specify a password");
         }
         // récupération de la config securité
         $values = \Parameters::get('security');
         $class = $values['security']['classes'];
         $ss = new $class(new Session(), new Request());
         if ($ss->emailExist($email)) {
             throw new \Exception("Email already exists.");
         }
         if ($ss->loginExist($login)) {
             throw new \Exception("Login already exists.");
         }
         // get all roles
         $roles = $ss->getRoles();
         $strRole = "[";
         foreach ($roles as $role) {
             if ($strRole != "[") {
                 $strRole .= ",";
             }
             $strRole .= $role->role;
         }
         $strRole .= "]";
         $question = new Question('Add roles for this user ' . $strRole . ', type role separated by comma : ', '');
         $roles = $helper->ask($input, $output, $question);
         $output->writeln('Create user');
         $ret = $ss->userCreate($login, $email, $password);
         if ($roles != "" && $ret != null) {
             $rolea = \Stringy\Stringy::create($roles)->split(",");
             foreach ($rolea as $role) {
                 $roles = $ss->getRolesFromName(array($role));
                 $role1 = $roles->first();
                 $ss->addUserToRole($ret, $role1->id);
             }
         }
     } catch (\Exception $e) {
         $output->writeln('Error : ' . $e->getMessage());
     }
     $output->writeln('finished');
 }
Ejemplo n.º 3
0
 public function testInstantiate()
 {
     $params = new Parameters($_SERVER);
     $this->assertEquals($_SERVER['PATH'], $params->get('PATH'));
     $this->assertEquals($_SERVER, $params->getData());
     $this->assertEquals(null, $params->get('THE_KEY_NOT_EXISTS'));
     $this->assertEquals('default-value', $params->get('THE_KEY_NOT_EXISTS', 'default-value'));
 }
Ejemplo n.º 4
0
 /**
  * Get current route parameters in array 
  * @return array (controller,action,parameters and _route)
  */
 function getCurrentRoute()
 {
     $ret = null;
     $inst = null;
     $url = null;
     if ($this->_request->get('url')) {
         $url = $this->_request->get('url');
     }
     $url = '/' . $url;
     $parameters = \Parameters::get('router');
     $classes = "GL\\Core\\Routing\\Router";
     if (isset($parameters["classes"])) {
         $classes = $parameters["classes"];
     }
     try {
         Assertion::classExists($classes);
         $inst = new $classes();
         $ret = $inst->route($url);
         $args = $inst->getArgs();
         $ret = array();
         $ret["controller"] = $inst->getController();
         $ret["action"] = $inst->getMethod();
         $ret["_route"] = $inst->getRoute();
         $ret = array_merge($ret, $args);
     } catch (AssertionFailedException $e) {
         $ret = null();
     }
     return $ret;
 }
Ejemplo n.º 5
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     try {
         $helper = $this->getHelper('question');
         $question = new Question('Please enter the role key : ', '');
         $role = $helper->ask($input, $output, $question);
         if ($role == "") {
             throw new \Exception("you must specify role key");
         }
         $roles = \Stringy\Stringy::create($role)->slugify();
         $question = new Question('Please enter the role description : ', '');
         $description = $helper->ask($input, $output, $question);
         if ($description == "") {
             throw new \Exception("you must specify a description");
         }
         // récupération de la config securité
         $values = \Parameters::get('security');
         $class = $values['security']['classes'];
         $ss = new $class(new Session(), new Request());
         $output->writeln('Create role');
         $ss->roleCreate($roles, $description);
     } catch (\Exception $e) {
         $output->writeln('Error : ' . $e->getMessage());
     }
     $output->writeln('finished');
 }
Ejemplo n.º 6
0
 public function __construct()
 {
     $this->addCollector(new MessagesCollector());
     $this->addCollector(new RequestDataCollector());
     $this->addCollector(new TimeDataCollector());
     $this->addCollector(new RouteDataCollector());
     $this->addCollector(new ExceptionsCollector());
     $values = \Parameters::get('redis');
     $redis_enable = isset($values['default']['enable']) ? $values['default']['enable'] : 0;
     if ($redis_enable != 0) {
         $this->addCollector(new RedisDataCollector());
     }
     try {
         $conn = Capsule::connection("default");
         if ($conn != null) {
             $db = $conn->getPdo();
             $pdo = new TraceablePDO($db);
             $this->addCollector(new PDOCollector($pdo));
         }
     } catch (\Illuminate\Contracts\Container\BindingResolutionException $ex) {
         $this['exceptions']->addException($ex);
     } catch (\PDOException $e) {
         $this['exceptions']->addException($e);
     }
 }
Ejemplo n.º 7
0
 private function createContainer()
 {
     $container = new ContainerBuilder();
     // retrieve security class
     $values = \Parameters::get('security');
     $class = $values['security']['classes'];
     $session_name = $values['session']['name'];
     // test if class exist and implement interface
     try {
         Assertion::ClassExists($class);
         Assertion::implementsInterface($class, '\\GL\\Core\\Security\\AuthenticationServiceInterface');
     } catch (AssertionFailedException $e) {
         echo $e->getMessage();
         die;
     }
     // Inject mailer
     $container->register('mailer', 'GL\\Core\\Tools\\Mailer');
     // Inject Request
     $container->register('request', 'Symfony\\Component\\HttpFoundation\\Request')->setFactory("Symfony\\Component\\HttpFoundation\\Request::createFromGlobals");
     // Inject Request helper
     $container->register('request_helper', 'GL\\Core\\Helpers\\RequestHelper')->addMethodCall('setRequest', array(new Reference('request')));
     // Inject Twig Service
     $container->register('template', 'GL\\Core\\Templating\\TemplateProvider');
     // Inject RouteCollection
     $container->register('routes', 'Symfony\\Component\\Routing\\RouteCollection')->setFactory("GL\\Core\\Routing\\RouteProvider::GetRouteCollection");
     if (class_exists("\\PHPExcel")) {
         // Inject PHPExcel Wrapper
         $container->register('excel', 'GL\\Core\\Tools\\Excel');
     }
     if (class_exists("\\TCPDF")) {
         // Inject FPDF Wrapper
         $container->register('pdf', 'GL\\Core\\Tools\\PDF');
     }
     // Inject Session
     $container->register('session', 'Symfony\\Component\\HttpFoundation\\Session\\Session')->addMethodCall('setName', array($session_name))->addMethodCall('start');
     // Inject Crsf verifier
     $container->register('crsf', 'GL\\Core\\Security\\FormCrsf')->addArgument(new Reference('session'))->addArgument(new Reference('request'));
     // Inject translator service
     $container->register('translator', 'GL\\Core\\Config\\Translator');
     // Inject Security Service
     $container->register('security', $class)->addArgument(new Reference('session'))->addArgument(new Reference('request'))->addMethodCall('autologin');
     // Inject DebugBar
     $container->register('debug', 'GL\\Core\\Debug\\KLDebugBar');
     // Inject Pdo Object
     $container->register('pdo', 'PDO')->setFactory("GL\\Core\\Helpers\\DbHelper::getPdo");
     // Inject Config
     $container->register('config', 'GL\\Core\\Config\\Config');
     // Inject DbHelper
     $container->register('db', 'GL\\Core\\Helpers\\DbHelper');
     // Inject Redis
     $container->register('redis', 'GL\\Core\\Tools\\Redis');
     // Inject services defined in config/services.yml
     $loader = new YamlFileLoader($container, new FileLocator(SERVICEPATH));
     $loader->load('services.yml');
     $container->compile();
     return $container;
 }
 public function actionDelete()
 {
     if (!Parameters::hasParam('type')) {
         throw new APIException('Invalid resource TYPE (parameter name: \'type\')', APIResponseCode::API_INVALID_METHOD_PARAMS);
     }
     if (!Parameters::hasParam('id')) {
         throw new APIException('Invalid resource IDENTIFICATOR (parameter name: \'id\')', APIResponseCode::API_INVALID_METHOD_PARAMS);
     }
     $type = Parameters::get('type');
     $id = Parameters::get('id');
     return $this->dataAccessor->delete($type, $id);
 }
Ejemplo n.º 9
0
 /**
  * Start this script.
  *
  * @return int Exit code.
  */
 public function start()
 {
     try {
         $this->params = $this->initParams();
         if (!$this->params instanceof Parameters) {
             $this->params = new Parameters();
             $this->params->ignoreRegisteredOptions = true;
         }
         $this->params->registerOption('help', null, Parameters::VALUE_NO, 'Show help');
         $this->params->parse();
         if ($this->params->get('help')) {
             $this->showHelp($this->params);
         } else {
             $this->run();
         }
         return 0;
     } catch (\Exception $ex) {
         $this->handleException($ex);
         return 1;
     }
 }
Ejemplo n.º 10
0
 public function actionView()
 {
     if (!Parameters::hasParam('id')) {
         throw new APIException('Invalid resource IDENTIFICATOR (parameter name: \'id\')', APIResponseCode::API_INVALID_METHOD_PARAMS);
     }
     $id = Parameters::get('id');
     $result = ARUser::model()->findByPk($id);
     if (is_null($result)) {
         throw new APIException('Invalid ID value', APIResponseCode::API_INVALID_ID);
     }
     $coder = new CJSON();
     $response = $coder->encode($result);
     echo $response;
 }
Ejemplo n.º 11
0
 public function loadConfig()
 {
     try {
         $value = \Parameters::get('security');
         $this->config = $value;
         $this->users_tablename = isset($this->config['security']['users_table']) ? $this->config['security']['users_table'] : 'users';
         $this->roles_tablename = isset($this->config['security']['roles_table']) ? $this->config['security']['roles_table'] : 'roles';
         $this->usersroles_tablename = isset($this->config['security']['usersroles_table']) ? $this->config['security']['usersroles_table'] : 'usersroles';
         $this->tokensalt = $this->config['cookie']['token'];
         $this->cookiename = $this->config['cookie']['name'];
         $this->cookieduration = $this->config['cookie']['duration'];
     } catch (Exception $e) {
     }
 }
Ejemplo n.º 12
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     try {
         // récupération de la config securité
         $values = \Parameters::get('security');
         $class = $values['security']['classes'];
         $ss = new $class(new Session(), new Request());
         $output->writeln('Create users table and model');
         $ss->createTables();
     } catch (\Exception $e) {
         $output->writeln('Error : ' . $e->getMessage());
     }
     $output->writeln('finished');
 }
Ejemplo n.º 13
0
 private function init()
 {
     $this->commands = array();
     $values = \Parameters::get('redis');
     $enable = isset($values['default']['enable']) ? $values['default']['enable'] : 0;
     $pwd = isset($values['default']['password']) ? $values['default']['password'] : "";
     $this->client = null;
     if ($enable == 1) {
         $params = ['scheme' => 'tcp', 'host' => $values['default']['server'], 'port' => $values['default']['port']];
         if (trim($pwd) != "") {
             $params['password'] = $pwd;
         }
         $this->client = new \Predis\Client($params);
     }
 }
Ejemplo n.º 14
0
 public function loadFile()
 {
     $ret = false;
     try {
         $value = \Parameters::get('templates');
         foreach ($value as $name => $th) {
             $this->arr[$name] = $th['class'];
         }
     } catch (IOException $e) {
         $ret = false;
     } catch (Exception $e) {
         $ret = false;
     }
     return $ret;
 }
Ejemplo n.º 15
0
 private function dispatchCall($controllerName, $method)
 {
     $format = Parameters::hasParam('format') ? Parameters::get('format') : 'json';
     try {
         $controller = $this->getFactory()->createObject($controllerName);
         if (is_null($controller) || !isset($controller)) {
             throw new APIException('Invalid controller name', APIResponseCode::API_INVALID_CLASSNAME);
         }
         if (!method_exists($controller, $method)) {
             throw new APIException('Controller have not the method with specified name', APIResponseCode::API_INVALID_METHOD);
         }
         $controller->{$method}();
     } catch (APIException $ex) {
         Yii::trace($ex, 'apps.APIController');
         die($ex->getResponse($format));
     }
 }
Ejemplo n.º 16
0
 private function getRouterInstance()
 {
     $parameters = \Parameters::get('router');
     $classes = "GL\\Core\\Routing\\Router";
     $inst = null;
     if (isset($parameters["classes"])) {
         $classes = $parameters["classes"];
     }
     try {
         Assertion::classExists($classes);
         $inst = new $classes();
     } catch (AssertionFailedException $e) {
         echo "Routing classes " . $classes . " does not exist";
         die;
     }
     return $inst;
 }
Ejemplo n.º 17
0
 public static function InitDatabase()
 {
     /**
      * Load database configuration from parameters.yml 
      */
     $value = \Parameters::get('database');
     $capsule = new Capsule();
     foreach ($value as $name => $conn) {
         $port = 3306;
         $connstr = $conn["server"];
         if (isset($conn["port"])) {
             $port = trim($conn["port"]);
         }
         $type = isset($conn["type"]) ? $conn["type"] : "mysql";
         $allowed = array('mysql', 'sqlite');
         if (!in_array($type, $allowed)) {
             echo $type . " database not allowed.";
             die;
         }
         $capsule->addConnection(array('driver' => $type, 'host' => $connstr, 'port' => $port, 'database' => $conn["database"], 'username' => $conn["user"], 'password' => $conn["password"], 'charset' => 'utf8', 'collation' => 'utf8_general_ci', 'prefix' => ''), $name);
     }
     $capsule->setAsGlobal();
     $capsule->bootEloquent();
 }
Ejemplo n.º 18
0
 private function getErrorController()
 {
     $error = \Parameters::get('error');
     $ctl = isset($error["controller"]) === true ? $error["controller"] : $this->getControllerName("error");
     return $ctl;
 }
Ejemplo n.º 19
0
 /**
  * Get all mail smtp parameters from config/mail.yml
  */
 private function getParams()
 {
     $arr = \Parameters::get('mail');
     if ($arr != null) {
         $this->_server = $arr["server"];
         $this->_port = $arr["port"];
         $this->_user = $arr["user"];
         $this->_password = $arr["password"];
         if (isset($arr["disable"])) {
             $this->_disable = $arr['disable'];
         }
         if (isset($arr["secure"])) {
             $this->_secure = $arr['secure'];
         }
         if (isset($arr["encryption"])) {
             $this->_encryption = $arr['encryption'];
         }
     }
 }
Ejemplo n.º 20
0
 public function actionDelete()
 {
     if (!Parameters::hasParam('id')) {
         throw new APIException('Invalid resource IDENTIFICATOR (parameter name: \'id\')', APIResponseCode::API_INVALID_METHOD_PARAMS);
     }
     try {
         $resource = DataModelFactory::createDataObjectWithType('resource');
         $resource->id = Parameters::get('id');
         $storage = new YiiResourceDataStorage();
         $storage->remove($resource);
     } catch (Exception $e) {
         throw new APIException('Can not save resource object', APIResponseCode::API_SHEMA_CREATE_ERROR);
     }
 }
Ejemplo n.º 21
0
 public function actionDelete()
 {
     if (!Parameters::hasParam('type')) {
         throw new APIException('Invalid resource TYPE (parameter name: \'type\')', APIResponseCode::API_INVALID_METHOD_PARAMS);
     }
     if (!Parameters::hasParam('id')) {
         throw new APIException('Invalid resource IDENTIFICATOR (parameter name: \'id\')', APIResponseCode::API_INVALID_METHOD_PARAMS);
     }
     $type = Parameters::get('type');
     $id = Parameters::get('id');
     $ar = $this->getActiveRecordClass($type);
     $record = $ar::model()->findByPk($id);
     if (!isset($record)) {
         throw new APIException('Invalid ID value', APIResponseCode::API_INVALID_ID);
     }
     if ($record->delete() !== 1) {
         throw new APIException('Could not delete resource object', APIResponseCode::API_SHEMA_DELETE_ERROR);
     }
 }
Ejemplo n.º 22
0
 public static function getUrlArgByName($param_name)
 {
     return Parameters::get($param_name);
 }
Ejemplo n.º 23
0
 /**
  * @depends testParse
  * @expectedException \Exception
  */
 public function testGetMandatory()
 {
     $params = new Parameters();
     $params->registerOption('name', null, Parameters::VALUE_YES);
     $_SERVER['argv'] = array('file.php');
     $params->get('name', true);
 }