web_config = $this->getModule('web_config')->getConfig(); } public function setUsers() { if(!$_SESSION['admin']) { return; } $all_users = $this->getModule('basic_webuser')->getAllUsers(); $users = array_keys($all_users); sort($users); $users_list = array(); $users_feature = (array_key_exists('users', $this->web_config) && is_array($this->web_config['users'])); for ($i = 0; $i < count($users); $i++) { $host = null; if ($users_feature && array_key_exists($users[$i], $this->web_config['users'])) { $host = $this->web_config['users'][$users[$i]]; } $users_list[] = array( 'user' => $users[$i], 'host' => $host, 'admin' => ($users[$i] === $this->web_config['baculum']['login']) ); } $this->UsersList->dataSource = $users_list; $this->UsersList->dataBind(); } public function initHosts($sender, $param) { $api_hosts = array_keys($this->getModule('host_config')->getConfig()); $sender->DataSource = array_combine($api_hosts, $api_hosts); $sender->dataBind(); } public function userAction($sender, $param) { if(!$_SESSION['admin']) { return; } $this->UsersList->ActiveControl->EnableUpdate = true; list($action, $user, $value) = explode(';', $param->CallbackParameter, 3); switch($action) { case 'newuser': case 'chpwd': { $admin = false; $valid = true; if ($user === $this->web_config['baculum']['login']) { $this->web_config['baculum']['password'] = $value; $valid = $this->getModule('web_config')->setConfig($this->web_config); $admin = true; } if ($valid === true) { $this->getModule('basic_webuser')->setUsersConfig($user, $value); } if ($admin === true) { // if admin password changed then try to auto-login by async request $http_protocol = isset($_SERVER['HTTPS']) && !empty($_SERVER['HTTPS']) ? 'https' : 'http'; $this->switchToUser($user, $value); exit(); } else { // if normal user's password changed then update users grid $this->setUsers(); } } break; case 'rmuser': { if ($user != $_SERVER['PHP_AUTH_USER']) { $this->getModule('basic_webuser')->removeUser($user); if (array_key_exists('users', $this->web_config) && array_key_exists($user, $this->web_config['users'])) { unset($this->web_config['users'][$user]); } $this->getModule('web_config')->setConfig($this->web_config); $this->setUsers(); } break; } case 'set_host': { if (empty($value) && array_key_exists($user, $this->web_config['users'])) { unset($this->web_config['users'][$user]); } else { $this->web_config['users'][$user] = $value; } $this->getModule('web_config')->setConfig($this->web_config); break; } } } }