Beispiel #1
0
 public function removeUser($serverId = NULL)
 {
     if (!$this->userId) {
         return false;
     }
     $user = $this->getUserInfo($this->userId);
     if (empty($user)) {
         return false;
     }
     $file = control('system')->file(control()->path('config') . '/front/scripts.php')->getData();
     if ($serverId === NULL) {
         //
         $server = \Mod\Server::i()->getServerByUser($this->userId);
         foreach ($server as $v) {
             //
             $pass = $this->decode($server['server_pass']);
             control()->database()->deleteRows('dev', array(array('dev_user=%s', $this->userId), array('dev_server=%s', $v['server_id'])));
             exec('sh ' . $file['removeUser'] . ' ' . $v['server_root'] . ' ' . $v['server_ip'] . ' ' . $pass . ' ' . $user['user_name'] . '&');
         }
         return true;
     }
     $server = \Mod\Server::i()->setId($serverId)->getServerById();
     if (empty($server)) {
         return false;
     }
     control()->database()->deleteRows('dev', array(array('dev_user=%s', $user['user_id']), array('dev_server=%s', $serverId)));
     $pass = $this->decode($server['server_pass']);
     exec('sh ' . $file['removeUser'] . ' ' . $server['server_root'] . ' ' . $server['server_ip'] . ' ' . $pass . ' ' . $user['user_name'] . '&');
     return true;
 }
Beispiel #2
0
 protected function addServer($data)
 {
     if (!isset($data['name']) || !trim($data['name'])) {
         $this->setMsg('Server name is required!', 'danger');
     }
     if (!isset($data['root']) || !trim($data['root'])) {
         $this->setMsg('Server username is invalid!', 'danger');
     }
     if (!isset($data['pass']) || !trim($data['pass'])) {
         $this->setMsg('Password is invalid', 'danger');
     }
     if (!isset($data['ip']) || !trim($data['ip'])) {
         $this->setMsg('Server IP is invalid!', 'danger');
     }
     $server = control()->database()->search('server')->filterByServerIp($data['ip'])->getRow();
     if (!empty($server)) {
         $this->setMsg('Server IP already exist!', 'danger');
     }
     $fields = array('server_name' => $data['name'], 'server_root' => $data['root'], 'server_pass' => \Mod\User::i()->encode($data['pass']), 'server_ip' => $data['ip']);
     control()->database()->insertRow('server', $fields);
     $id = control()->database()->getLastInsertedId();
     \Mod\Server::i()->setId($id)->addServer();
     $this->setMsg('Server added', 'success');
 }
Beispiel #3
0
 public function remove($id)
 {
     \Mod\Server::i()->removeServer($id);
     header('Location: /servers');
     exit;
 }