Example #1
0
 /**
  * @param $data
  * @param Server $server
  * @return \Rocker\Object\User\UserInterface|null
  */
 public function rc4Auth($data, $server)
 {
     $conf = $server->config('application.auth');
     $parts = explode(':', RC4Cipher::decrypt($conf['secret'], base64_decode($data)));
     if (count($parts) == 2 && !is_numeric($parts[0])) {
         // don't allow to login using user id
         $user = $this->userFactory->load($parts[0]);
         if ($user !== null && $user->hasPassword($parts[1])) {
             return $user;
         }
     }
     return null;
 }
Example #2
0
 /**
  * @inheritdoc
  */
 public function call($args, $flags)
 {
     // Check version and operations on remote server
     if (in_array('-c', $flags)) {
         $client = self::loadClient($args);
         \cli\line('%_Base URI:%n ' . $client->getBaseURI());
         \cli\line('%_Version:%n ' . $client->serverVersion());
         \cli\line('%_Operations:%n');
         $table = new \cli\Table();
         $table->setHeaders(array('Class', 'Methods', 'Path'));
         foreach ($client->request('GET', 'operations')->body as $data) {
             $table->addRow(array_values((array) $data));
         }
         $table->display();
     } elseif (isset($args['-r'])) {
         $servers = $this->loadStoredServerInfo();
         if (isset($servers[$args['-r']])) {
             unset($servers[$args['-r']]);
             file_put_contents($this->infoFile, serialize($servers));
             \cli\line('Server removed (add flag -l to list servers)');
         }
     } elseif (in_array('-l', $flags)) {
         $servers = $this->loadStoredServerInfo();
         $this->listServers($servers);
     } elseif (isset($args['-d'])) {
         $servers = $this->loadStoredServerInfo();
         if (empty($servers[$args['-d']])) {
             \cli\line('Server does not exist....');
             $this->listServers($servers);
         } else {
             $servers['__default'] = $args['-d'];
             file_put_contents($this->infoFile, serialize($servers));
             \cli\line('%gServer "' . $args['-d'] . '" set as default %n');
         }
     } else {
         \cli\line('Add remote server');
         \cli\line('--------------------');
         $name = \cli\prompt('Server name (any name of your choice)');
         $address = rtrim(\cli\prompt('Server address'), '/') . '/';
         $user = \cli\prompt('Admin e-mail');
         $pass = Utils::promptPassword('Admin password: '******'Secret (leave empty if not used)'));
         try {
             // Try to request server
             $auth = $user . ':' . $pass;
             if ($secret) {
                 $auth = 'RC4 ' . base64_encode(RC4Cipher::encrypt($secret, $auth));
             } else {
                 $auth = 'Basic ' . base64_encode($auth);
             }
             $client = new Client($address);
             $client->setAuthString($auth);
             $user = $client->me();
             // just to check that auth is correct
             if (!$user) {
                 throw new \Exception('Could not authenticate');
             }
             $version = $client->serverVersion();
             $this->addServer($name, $address, $auth);
             \cli\line('%gSuccessfully added server "' . $name . '" (v' . $version . ')%n');
             \cli\line('... add flag -l to list all added servers');
         } catch (\Exception $e) {
             \cli\err('Failed adding server with message "' . $e->getMessage() . '"');
         }
     }
 }
Example #3
0
 /**
  * @inheritDoc
  */
 public function setUser($user, $pass, $secret = false)
 {
     if ($secret) {
         $this->setAuthString('RC4 ' . base64_encode(RC4Cipher::encrypt($secret, $user . ':' . $pass)));
     } else {
         $this->setAuthString('Basic ' . base64_encode($user . ':' . $pass));
     }
 }