コード例 #1
0
ファイル: Server.php プロジェクト: NavalKishor/PHP-Rocker
 /**
  * @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() . '"');
         }
     }
 }
コード例 #2
0
ファイル: install.php プロジェクト: NavalKishor/PHP-Rocker
    } else {
        $obj->install();
        _('- installed ' . $class);
    }
}
$userFactory = new \Rocker\Object\User\UserFactory($db);
// todo: check if it exists an admin
$hasAdmin = $userFactory->metaSearch(array('admin' => 1))->getNumMatching() > 0;
// Ask for e-mail
_('## Create admin user');
while (empty($email)) {
    $email = Rocker\Console\Utils::promptAllowingEmpty('E-mail');
    if (empty($email) && !$hasAdmin) {
        _('%rYou must create an admin user%n');
    } elseif (empty($email) && $hasAdmin) {
        $email = 'skip';
    } else {
        if (filter_var($email, FILTER_VALIDATE_EMAIL) === false) {
            _('%rNot a valid e-mail%n');
            $email = null;
        }
    }
}
// Create admin user
if ($email != 'skip') {
    $nick = \cli\prompt('Nick name');
    $password = \Rocker\Console\Utils::promptPassword('Password: '******'%gRocker Server v' . \Rocker\Server::VERSION . ' was successfully installed :) %n');
コード例 #3
0
ファイル: Users.php プロジェクト: NavalKishor/PHP-Rocker
 /**
  * @inheritdoc
  */
 public function call($args, $flags)
 {
     $client = Server::loadClient($args);
     if (!$client) {
         return;
     }
     // Create user
     if (isset($args['-c'])) {
         $email = \cli\prompt('E-mail');
         $pass = Utils::promptPassword('Password: '******'Meta (query string)');
         $meta = array();
         foreach (explode('&', $metaData) as $data) {
             $parts = explode('=', $data);
             if (count($parts) == 2) {
                 $meta[trim($parts[0])] = trim($parts[1]);
             }
         }
         try {
             $user = $client->createUser($args['-c'], $email, $pass, $meta);
             self::displayUser($user);
         } catch (DuplicationException $e) {
             \cli\line('%rUser with given e-mail already exists%n');
         } catch (\InvalidArgumentException $e) {
             \cli\line('Invalid arguments, message: ' . $e->getMessage());
         }
     } elseif (isset($args['-l'])) {
         $user = $client->loadUser($args['-l']);
         if ($user) {
             self::displayUser($user);
         } else {
             \cli\line('-No user found');
         }
     } elseif (isset($args['-r'])) {
         $user = $client->loadUser($args['-r']);
         if ($user) {
             $yes = \cli\prompt('Do you really want to delete "' . $user->nick . '" (y/n)');
             if ($yes[0] == 'y') {
                 $client->deleteUser($args['-r']);
                 \cli\line('...user deleted');
             }
         } else {
             \cli\line('User not found');
         }
     } elseif (isset($args['-q'])) {
         $limit = isset($args['-lim']) ? $args['-lim'] : 50;
         $offset = isset($args['-off']) ? $args['-off'] : 0;
         $search = array();
         foreach (explode('&', $args['-q']) as $que) {
             $parts = explode('=', $que);
             $search[$parts[0]] = $parts[1];
         }
         $result = $client->search('user', $search, $offset, $limit);
         if (in_array('-v', $flags)) {
             print_r($result);
         }
         $this->displaySearchResult($result);
     } elseif (isset($args['-u'])) {
         $user = $client->loadUser($args['-u']);
         if ($user) {
             self::displayUser($user);
             \cli\line('Update user "%_' . $user->nick . '%n" (leave values empty if not wanting to change a property)');
             $nick = Utils::promptAllowingEmpty('New nick');
             $email = Utils::promptAllowingEmpty('New e-mail');
             $pass = Utils::promptPassword('New password: '******'Meta');
             $meta = array();
             foreach (explode('&', $metaData) as $data) {
                 $parts = explode('=', $data);
                 if (count($parts) == 2) {
                     $meta[trim($parts[0])] = trim($parts[1]);
                 }
             }
             $user = $client->updateUser($user->id, $nick, $email, $pass, $meta);
             \cli\line('%_%gUser updated%n');
             self::displayUser($user);
         } else {
             \cli\line('User not found');
         }
     } else {
         $this->help();
     }
 }