load->database(); $this->load->model('users'); $this->lang->load('adm_servers'); $this->lang->load('server_control'); $this->lang->load('main'); $this->load->model('servers'); $this->load->model('servers/dedicated_servers'); $this->load->model('servers/games'); $this->load->model('servers/game_types'); $this->load->helper('string'); $this->load->helper('ds'); if ($this->users->check_user()) { //Base Template $this->tpl_data['title'] = lang('adm_servers_title_index'); $this->tpl_data['heading'] = lang('adm_servers_heading_index'); $this->tpl_data['content'] = ''; /* Есть ли у пользователя права */ if(!$this->users->auth_privileges['srv_global']) { redirect('admin'); } $this->load->model('servers'); $this->load->library('form_validation'); $this->load->helper('form'); $this->tpl_data['menu'] = $this->parser->parse('menu.html', $this->tpl_data, true); $this->tpl_data['profile'] = $this->parser->parse('profile.html', $this->users->tpl_userdata(), true); } else { redirect('auth'); } } // ----------------------------------------------------------- // Отображение информационного сообщения function _show_message($message = false, $link = false, $link_text = false) { if (!$message) { $message = lang('error'); } if (!$link) { $link = 'javascript:history.back()'; } if (!$link_text) { $link_text = lang('back'); } $local_tpl_data['message'] = $message; $local_tpl_data['link'] = $link; $local_tpl_data['back_link_txt'] = $link_text; $this->tpl_data['content'] = $this->parser->parse('info.html', $local_tpl_data, true); $this->parser->parse('main.html', $this->tpl_data); } // ----------------------------------------------------------------- /** * Проверка Telnet * * @param string * @param string * @param string * @return bool */ private function _check_telnet($telnet_host, $telnet_login, $telnet_password, $os = 'windows') { $this->load->driver('control'); if ($telnet_login == '' OR $telnet_password == '') { /* В Telnet не разрешены пустые логины или пароли */ return false; } // Разделяем на Host:Port $telnet_host = explode(':', $telnet_host); $telnet_host[1] = (isset($telnet_host[1])) ? (int)$telnet_host[1] : 23; $this->control->set_driver('telnet'); $this->control->set_data(array('os' => $os)); try { $this->control->connect($telnet_host[0], $telnet_host[1]); $this->control->auth($telnet_login, $telnet_password); return true; } catch (Exception $e) { return false; } } // ----------------------------------------------------------- /** * Проверка SSH * * @param string * @param string * @param string * @return bool */ function _check_ssh($ssh_host, $ssh_login, $ssh_password) { $this->load->driver('control'); // Разделяем на Host:Port $ssh_host = explode(':', $ssh_host); $ssh_host[1] = (isset($ssh_host[1])) ? (int)$ssh_host[1] : 22; $this->control->set_driver('ssh'); try { $this->control->connect($ssh_host[0], $ssh_host[1]); $this->control->auth($ssh_login, $ssh_password); return true; } catch (Exception $e) { return false; } } // ----------------------------------------------------------------- /** * Проверка FTP * * @param string * @param string * @param string * @return bool */ private function _check_ftp($ftp_host, $ftp_login, $ftp_password) { $this->load->driver('files'); // Разделяем на Host:Port $ftp_host = explode(':', $ftp_host); $ftp_host[1] = (isset($ftp_host[1])) ? (int)$ftp_host[1] : 21; $ftp_config['hostname'] = $ftp_host[0]; $ftp_config['port'] = $ftp_host[1]; $ftp_config['username'] = $ftp_login; $ftp_config['password'] = $ftp_password; $ftp_config['passive'] = false; try { $this->files->set_driver('ftp'); $this->files->connect($ftp_config); return true; } catch (Exception $e) { return false; } } // ----------------------------------------------------------------- /** * Поиск пути к server.sh/server.exe * Соединение с ftp сервером уже должно быть выполнено! */ private function _found_ftp_path($ftp_path = false) { try { return $this->files->search(array('server.sh', 'server.exe'), $ftp_path); } catch (Exception $e) { return false; } } // ----------------------------------------------------------------- /** * Поиск пути к server.sh/server.exe * Если sftp отключен, то вернет false */ private function _found_sftp_path($sftp_path = false, $sftp_config) { $this->load->driver('files'); // Исключаемые директории. В них поиск не ведется $exclude_dirs = array('bin', 'boot', 'build', 'cdrom', 'dev', 'etc', 'lib', 'lib32', 'lib64', 'proc', 'media', 'mnt', 'run', 'sbin', 'selinux', 'sys', 'tmp', ); $this->files->set_driver('sftp'); try { $this->files->connect($sftp_config); return $this->files->search(array('server.sh', 'server.exe'), $sftp_path, $exclude_dirs, 4); } catch (Exception $e) { // Сохраняем логи $log_data['type'] = 'sftp_search'; $log_data['command'] = 'search_file'; $log_data['server_id'] = 0; $log_data['msg'] = 'server.sh/server.exe not found'; $log_data['log_data'] = $e->getMessage() . "\nPath: " . $sftp_path; $this->panel_log->save_log($log_data); return false; } } // ----------------------------------------------------------------- /** * Данные по умолчанию для игрового сервера * * @param array - некоторые данные о сервере (такие как ОС, движок и др.) * @return array * */ function _gs_default_data($data) { $this->load->driver('installer'); if (!$this->dedicated_servers->ds_list) { $where = array('id' => $data['ds_id']); $this->dedicated_servers->get_ds_list($where, 1); } if (!$this->games->games_list) { $where = array('code' => $data['game']); $this->games->get_games_list($where, 1); } foreach ($this->dedicated_servers->ds_list as &$ds) { if ($ds['id'] == $data['ds_id']) { $os = strtolower($ds['os']); break; } else { $os = 'linux'; } } $this->installer->set_game_variables($this->games->games_list[0]['start_code'], $this->games->games_list[0]['engine'], $this->games->games_list[0]['engine_version'] ); $this->installer->set_os($os); $this->installer->server_data = $data; $data['aliases'] = json_encode($this->installer->get_default_parameters()); $data['start_command'] = $this->installer->get_start_command(); // Путь к картам $data['maps_path'] = $this->installer->get_maps_path(); // Список портов $ports = $this->installer->get_ports(); $data['query_port'] = $ports[1]; $data['rcon_port'] = $ports[2]; /* Присваиваем значения пути к картам и имя screen */ $data['screen_name'] = $data['game'] . '_' . random_string('alnum', 6) . '_' . $data['server_port']; $data['maps_path'] = $this->games->games_list[0]['start_code'] . '/maps'; return $data; } // ----------------------------------------------------------------- /** * * Обработка статистики */ function _stats_processing($stats) { $data = array(); if (!is_array($stats)) { return false; } foreach($stats as $arr) { if (!isset($arr['date']) OR !isset($arr['cpu_usage']) OR !isset($arr['memory_usage'])) { continue; } /* Показываем только за последние 3 часа */ if((time() - $arr['date']) > 10800) { continue; } // Оставляем от даты лишь время $data['data']['axis']['categories'][] = preg_replace('/(\d+)\-(\d+)\-(\d+) (\d+)\:(\d+)/i', '$4:$5', unix_to_human($arr['date'], false, 'eu')); $data['cpu_graph_data']['data'][] = $arr['cpu_usage']; $data['memory_graph_data']['data'][] = $arr['memory_usage']; } return $data; } // ----------------------------------------------------------------- /** * Получение данных фильтра для вставки в шаблон */ private function _get_gservers_tpl_filter($filter = false) { $this->load->model('servers'); if (!$filter) { $filter = $this->users->get_filter('servers_list'); } $this->servers->select_fields('game, server_ip'); $games_array = array(); $ip_array = array(); if ($servers_list = $this->servers->get_list()) { foreach($this->servers->get_list() as $server) { if (!in_array($server['game'], $games_array)) { $games_array[] = $server['game']; } if (!in_array($server['server_ip'], $ip_array)) { $ip_array[ $server['server_ip'] ] = $server['server_ip']; } } } if (empty($this->games->games_list)) { $this->games->get_active_games_list(); } foreach($this->games->games_list as &$game) { $games_option[ $game['code'] ] = $game['name']; } $tpl_data['filter_name'] = isset($filter['name']) ? $filter['name'] : ''; $tpl_data['filter_ip'] = isset($filter['ip']) ? $filter['ip'] : ''; $tpl_data['filter_ip_dropdown'] = form_multiselect('filter_ip[]', $ip_array, $tpl_data['filter_ip']); $default = isset($filter['game']) ? $filter['game'] : null; $tpl_data['filter_games_dropdown'] = form_multiselect('filter_game[]', $games_option, $default); return $tpl_data; } // ----------------------------------------------------------------- /** * * Функция получает IP адрес для игрового сервера, если он не указан */ private function _get_default_ip($ds_id = false) { if($ds_id) { foreach($this->dedicated_servers->ds_list as $array) { if($ds_id == $array['id']) { /* Первый IP из списка */ return $array['ip'][0]; } } } else { return '127.0.0.1'; } } // ----------------------------------------------------------------- //Главная public function index() { $this->parser->parse('main.html', $this->tpl_data); } // ----------------------------------------------------------------- /** * Просмотр списка * выделенных серверов * игровых серверов * игр * типов игр * * @param string - тип * dedicated_servers - выделенные серверы * game_servers - игровые серверы * games - игры * type_games - типы игр * * */ public function view($type = 'dedicated_servers', $id = false) { if($this->users->auth_id){ // Пользователь авторизован $local_tpl_data = array(); $error_msg = false; switch ($type) { case 'dedicated_servers': $this->load->model('servers/dedicated_servers'); $this->tpl_data['title'] = lang('adm_servers_title_ds'); $this->tpl_data['heading'] = lang('adm_servers_heading_ds'); $parse_list_file = 'adm_servers/dedicated_servers_list.html'; // Шаблон списка $local_tpl_data['ds_list'] = $this->dedicated_servers->tpl_data_ds(); break; case 'game_servers': $this->load->helper('games'); $this->tpl_data['title'] = lang('adm_servers_title_gs'); $this->tpl_data['heading'] = lang('adm_servers_heading_gs'); $parse_list_file = 'adm_servers/game_servers_list.html'; // Шаблон списка $filter = $this->users->get_filter('servers_list'); $local_tpl_data = $this->_get_gservers_tpl_filter(); $this->servers->set_filter($filter); $this->servers->get_server_list(false, false, array()); $local_tpl_data['games_list'] = servers_list_to_games_list($this->servers->servers_list); //~ $local_tpl_data['servers_list'] = $this->servers->tpl_data(); break; case 'games': $this->load->model('servers/game_types'); $this->load->model('servers/games'); $this->tpl_data['title'] = lang('adm_servers_title_gt'); $this->tpl_data['heading'] = lang('adm_servers_heading_gt'); $parse_list_file = 'adm_servers/games_list.html'; // Шаблон списка if (!$error_msg) { /* Получение игр */ if($games_list = $this->games->get_games_list()){ $num = 0; $tpl_data = array(); foreach ($games_list as $games) { //~ /* Если у игры нет модификаций, то не отображаем ее */ //~ if(!$this->game_types->get_gametypes_list($where)){ //~ continue; //~ } $tpl_data[$num]['gt_list'] = $this->game_types->tpl_data_game_types(array('game_code' => $games['code'])); $tpl_data[$num]['game_name'] = $games['name']; $tpl_data[$num]['game_code'] = $games['code']; $tpl_data[$num]['game_start_code'] = $games['start_code']; $tpl_data[$num]['game_engine'] = $games['engine']; $tpl_data[$num]['game_engine_version'] = $games['engine_version']; $num++; } $local_tpl_data['games_list'] = $tpl_data; } else { $error_msg .= '
' . lang('adm_servers_games_unavailable') . '
'; } } break; case 'game_types': redirect('/adm_servers/view/games'); break; default: redirect('/adm_servers/view/dedicated_servers'); break; } // Верхняя оболочка, в качестве меню if(isset($parse_file)){ $this->tpl_data['content'] .= $this->parser->parse($parse_file, $local_tpl_data, true); } /* Если ошибок никаких, то отображаем список */ if(!$error_msg){ $this->tpl_data['content'] .= $this->parser->parse($parse_list_file, $local_tpl_data, true); }else{ $this->tpl_data['content'] .= $error_msg; } }else{ redirect(); } $this->parser->parse('main.html', $this->tpl_data); } // ----------------------------------------------------------------- /** * Добавление * выделенных серверов * игровых серверов * игр * типов игр * * @param string - тип * dedicated_servers - выделенные серверы * game_servers - игровые серверы * games - игры * type_games - типы игр * * @param string - служит для передачи дополнительных параметров * @param string * * */ public function add($type = 'dedicated_servers', $param_1 = false, $param_2 = false) { if($this->users->auth_id) { // Пользователь авторизован $local_tpl_data = array(); $error_msg = false; /* Параметры для форм, задание правил проверки * title страниц, файлы шаблонов */ switch ($type) { case 'dedicated_servers': /* -------------------------------------------- */ /* Выделенные серверы */ /* -------------------------------------------- */ $this->load->model('servers/dedicated_servers'); // Добавление выделенного сервера $this->tpl_data['title'] = lang('adm_servers_title_add_ds'); $this->tpl_data['heading'] = lang('adm_servers_heading_add_ds'); $tpl_file_add = 'adm_servers/dedicated_servers_add.html'; /* Проверка формы */ $this->form_validation->set_rules('name', lang('name'), 'trim|required|max_length[64]|min_length[3]|xss_clean'); $this->form_validation->set_rules('os', lang('os'), 'trim|required|max_length[64]|min_length[3]|xss_clean'); $this->form_validation->set_rules('control_protocol', lang('adm_servers_control_protocol'), 'trim|max_length[8]|xss_clean'); $this->form_validation->set_rules('location', lang('adm_servers_location'), 'trim|required|max_length[64]|min_length[3]|xss_clean'); $this->form_validation->set_rules('provider', lang('adm_servers_provider'), 'trim|max_length[64]|min_length[3]|xss_clean'); $this->form_validation->set_rules('ip', lang('ip'), 'trim|required|xss_clean'); $this->form_validation->set_rules('ram', lang('adm_servers_ram'), 'trim|max_length[64]|xss_clean'); $this->form_validation->set_rules('cpu', lang('adm_servers_cpu'), 'trim|max_length[64]|xss_clean'); $this->form_validation->set_rules('steamcmd_path', lang('adm_servers_steamcmd_path'), 'trim|max_length[256]|xss_clean'); $this->form_validation->set_rules('script_path', lang('adm_servers_script_path'), 'trim|max_length[256]|xss_clean'); $this->form_validation->set_rules('ssh_host', lang('adm_servers_ssh_host'), 'trim|max_length[64]|xss_clean'); $this->form_validation->set_rules('ssh_login', 'SSH login', 'trim|max_length[64]|xss_clean'); $this->form_validation->set_rules('ssh_password', 'SSH password', 'trim|max_length[64]|xss_clean'); $this->form_validation->set_rules('ssh_path', lang('adm_servers_path_to_executable_file'), 'trim|max_length[256]|xss_clean'); $this->form_validation->set_rules('telnet_host', lang('adm_servers_telnet_host'), 'trim|max_length[64]|xss_clean'); $this->form_validation->set_rules('telnet_login', 'Telnet login', 'trim|max_length[64]|xss_clean'); $this->form_validation->set_rules('telnet_password', 'Telnet password', 'trim|max_length[64]|xss_clean'); $this->form_validation->set_rules('telnet_path', lang('adm_servers_path_to_executable_file'), 'trim|max_length[256]|xss_clean'); $this->form_validation->set_rules('ftp_host', lang('adm_servers_ftp_host'), 'trim|max_length[64]|xss_clean'); $this->form_validation->set_rules('ftp_login', 'FTP login', 'trim|max_length[64]|xss_clean'); $this->form_validation->set_rules('ftp_password', 'FTP password', 'trim|max_length[64]|xss_clean'); $this->form_validation->set_rules('ftp_path', lang('adm_servers_path_to_executable_file'), 'trim|max_length[256]|xss_clean'); break; case 'game_servers': redirect('adm_servers/install_game_server'); break; case 'games': /* -------------------------------------------- */ /* Игры */ /* -------------------------------------------- */ $this->load->model('servers/games'); $this->tpl_data['title'] = lang('adm_servers_title_add_game'); $this->tpl_data['heading'] = lang('adm_servers_heading_add_game'); $tpl_file_add = 'adm_servers/games_add.html'; $this->form_validation->set_rules('name', lang('name'), 'trim|required|max_length[32]|min_length[3]|xss_clean'); $this->form_validation->set_rules('code', lang('adm_servers_game_code'), 'trim|required|is_unique[games.code]|max_length[64]|min_length[2]|xss_clean'); $this->form_validation->set_rules('start_code', lang('adm_servers_game_start_code'), 'trim|required|max_length[32]|min_length[2]|xss_clean'); $this->form_validation->set_rules('engine', lang('adm_servers_engine'), 'trim|required|max_length[64]|min_length[3]|xss_clean'); $this->form_validation->set_rules('engine_version', lang('adm_servers_engine_version'), 'trim|numeric|max_length[11]|xss_clean'); $this->form_validation->set_rules('app_id', 'app_id', 'trim|integer|max_length[32]|xss_clean'); $this->form_validation->set_rules('app_set_config', 'app_set_config', 'trim|max_length[32]|xss_clean'); $this->form_validation->set_rules('local_repository', lang('adm_servers_local_repository'), 'trim|xss_clean'); $this->form_validation->set_rules('remote_repository', lang('adm_servers_remote_repository'), 'trim|xss_clean'); break; case 'game_types': /* -------------------------------------------- */ /* Игровые моды */ /* -------------------------------------------- */ $this->load->model('servers/game_types'); $this->load->model('servers/games'); $this->tpl_data['title'] = lang('adm_servers_title_add_game_type'); $this->tpl_data['heading'] = lang('adm_servers_heading_add_game_type'); $this->form_validation->set_rules('code', 'код игры', 'trim|required|max_length[64]|min_length[2]|xss_clean'); $this->form_validation->set_rules('name', 'название игры', 'trim|required|max_length[32]|min_length[2]|xss_clean'); if($tpl_list = $this->games->tpl_data_games()) { $local_tpl_data['games_list'] = $tpl_list; } if(empty($this->games->games_list)) { $this->_show_message(lang('adm_servers_empty_games_list', base_url() . 'adm_servers/add/games')); return false; } $tpl_file_add = 'adm_servers/game_types_add.html'; break; default: redirect(''); break; } /* Проверяем форму */ if ($this->form_validation->run() == false) { if (validation_errors()) { $this->_show_message(validation_errors()); return false; } if (!isset($tpl_file_add)) { $this->_show_message('', $link = 'javascript:history.back()'); return false; } else { $local_tpl_data['message'] = ''; $local_tpl_data['back_link_txt'] = lang('back'); $local_tpl_data['link'] = 'javascript:history.back()'; $this->tpl_data['content'] .= $this->parser->parse($tpl_file_add, $local_tpl_data, true); } } else { /* * Проверка пройдена * Подготовка данных и отправка их в базу * * Все данные проходят XSS фильтрацию, это указывается добавлением параметра * xss_clean при задании правил, либо через заданием true: * $this->input->post('name', true); * */ $local_tpl_data = array(); switch($type){ case 'dedicated_servers': /* -------------------------------------------- */ /* Выделенные серверы */ /* -------------------------------------------- */ $sql_data['name'] = $this->input->post('name'); $sql_data['os'] = strtolower($this->input->post('os')); $sql_data['control_protocol'] = strtolower($this->input->post('control_protocol')); $sql_data['location'] = $this->input->post('location'); $sql_data['provider'] = $this->input->post('provider'); /* Обработка списка IP адресов */ $ip_list = explode(',', str_replace(' ', '', $this->input->post('ip'))); $sql_data['ip'] = json_encode($ip_list); $sql_data['ram'] = (int)$this->input->post('ram'); $sql_data['cpu'] = (int)$this->input->post('cpu'); $sql_data['steamcmd_path'] = $this->input->post('steamcmd_path'); $sql_data['ssh_host'] = $this->input->post('ssh_host'); $sql_data['ssh_login'] = $this->input->post('ssh_login'); $sql_data['ssh_password'] = $this->input->post('ssh_password'); $sql_data['ssh_path'] = $this->input->post('script_path'); $sql_data['telnet_host'] = $this->input->post('telnet_host'); $sql_data['telnet_login'] = $this->input->post('telnet_login'); $sql_data['telnet_password'] = $this->input->post('telnet_password'); $sql_data['telnet_path'] = $this->input->post('script_path'); $sql_data['ftp_host'] = $this->input->post('ftp_host'); $sql_data['ftp_login'] = $this->input->post('ftp_login'); $sql_data['ftp_password'] = $this->input->post('ftp_password'); $sql_data['ftp_path'] = $this->input->post('ftp_path'); /* * Проверка указандых данных ssh, telnet, ftp * чтобы пароль подходил */ // Проверка данных SSH if (!empty($sql_data['ssh_host'])) { if (false == $this->_check_ssh($sql_data['ssh_host'], $sql_data['ssh_login'], $sql_data['ssh_password'])) { $this->_show_message(lang('adm_servers_ssh_data_unavailable'), 'javascript:history.back()'); return false; } $ssh_host = explode(':', $sql_data['ssh_host']); $ssh_host[1] = (isset($ssh_host[1])) ? (int)$ssh_host[1] : 22; $sftp_config['hostname'] = $ssh_host[0]; $sftp_config['port'] = $ssh_host[1]; $sftp_config['username'] = $sql_data['ssh_login']; $sftp_config['password'] = $sql_data['ssh_password']; $sftp_config['debug'] = false; // Ищем server.sh/server.exe if (isset($this->config->config['disable_sftp_search']) && $this->config->config['disable_sftp_search']) { if (!$sql_data['ssh_path'] = $this->_found_sftp_path($sql_data['ssh_path'], $sftp_config)) { $this->_show_message(lang('adm_servers_sftp_path_not_found'), 'javascript:history.back()'); return false; } } else { // Поиск sftp отключен, значит поле не должно быть пустым if (!$sql_data['ssh_path']) { $this->_show_message('Empty SFTP path.', 'javascript:history.back()'); return false; } } } // Проверка данных FTP, если указаны if(!empty($sql_data['ftp_host'])) { if (false == $this->_check_ftp($sql_data['ftp_host'], $sql_data['ftp_login'], $sql_data['ftp_password'])) { $this->_show_message(lang('adm_servers_ftp_data_unavailable'), 'javascript:history.back()'); return false; } // Ищем server.sh/server.exe if (!$sql_data['ftp_path'] = $this->_found_ftp_path($sql_data['ftp_path'])) { $this->_show_message(lang('adm_servers_ftp_path_not_found'), 'javascript:history.back()'); return false; } } // Проверка данных Telnet, если указаны if (!empty($sql_data['telnet_host'])) { if (false == $this->_check_telnet($sql_data['telnet_host'], $sql_data['telnet_login'], $sql_data['telnet_password'])) { $this->_show_message(lang('adm_servers_telnet_data_unavailable'), 'javascript:history.back()'); return false; } } // Определение протокола управления if (!$sql_data['control_protocol'] && $sql_data['os'] != 'windows') { $sql_data['control_protocol'] = 'ssh'; } elseif (!$sql_data['control_protocol']) { $sql_data['control_protocol'] = 'telnet'; } // Локальный сервер должен быть один if ($sql_data['control_protocol'] == 'local') { if (!$this->dedicated_servers->ds_live(array('control_protocol' => 'local'))) { $this->_show_message('adm_servers_must_be_one'); return false; } } // Добавление сервера if ($this->dedicated_servers->add_dedicated_server($sql_data)) { $local_tpl_data['message'] = lang('adm_servers_add_server_successful'); } else { $local_tpl_data['message'] = lang('adm_servers_add_server_failed'); } // Записываем логи $log_data['type'] = 'adm_servers'; $log_data['command'] = 'add_ds'; $log_data['server_id'] = 0; $log_data['user_name'] = $this->users->auth_login; $log_data['msg'] = $local_tpl_data['message']; $log_data['log_data'] = ''; $this->panel_log->save_log($log_data); $local_tpl_data['link'] = site_url('adm_servers/view/dedicated_servers'); $local_tpl_data['back_link_txt'] = lang('adm_servers_back_to_servers'); break; case 'game_servers': redirect('adm_servers/install_game_server'); break; case 'games': /* -------------------------------------------- */ /* Игры */ /* -------------------------------------------- */ $sql_data['code'] = $this->input->post('code'); $sql_data['start_code'] = $this->input->post('start_code'); $sql_data['name'] = $this->input->post('name'); $sql_data['engine'] = $this->input->post('engine'); $sql_data['engine_version'] = $this->input->post('engine_version'); $sql_data['app_id'] = $this->input->post('app_id'); $sql_data['app_set_config'] = $this->input->post('app_set_config'); $sql_data['local_repository'] = $this->input->post('local_repository'); $sql_data['remote_repository'] = $this->input->post('remote_repository'); /* Убираем кавычки из app_set_config */ $sql_data['app_set_config'] = str_replace('\'', '', $sql_data['app_set_config']); $sql_data['app_set_config'] = str_replace('"', '', $sql_data['app_set_config']); $sql_data['app_set_config'] = str_replace(' ', '', $sql_data['app_set_config']); if($this->games->add_game($sql_data)){ $local_tpl_data['message'] = lang('adm_servers_add_game_successful'); }else{ $local_tpl_data['message'] = lang('adm_servers_add_game_failed'); } // Записываем логи $log_data['type'] = 'adm_servers'; $log_data['command'] = 'add_game'; $log_data['server_id'] = 0; $log_data['user_name'] = $this->users->auth_login; $log_data['msg'] = $local_tpl_data['message']; $log_data['log_data'] = ''; $this->panel_log->save_log($log_data); $local_tpl_data['link'] = site_url('adm_servers/view/games'); $local_tpl_data['back_link_txt'] = lang('adm_servers_back_to_games'); break; case 'game_types': /* -------------------------------------------- */ /* Игровые модификации */ /* -------------------------------------------- */ $sql_data['game_code'] = $this->input->post('code'); $sql_data['name'] = $this->input->post('name'); if($this->game_types->add_game_type($sql_data)) { $local_tpl_data['message'] = lang('adm_servers_add_game_type_successful'); } else { $local_tpl_data['message'] = lang('adm_servers_add_game_type_failed'); } // Записываем логи $log_data['type'] = 'adm_servers'; $log_data['command'] = 'add_game_type'; $log_data['server_id'] = 0; $log_data['user_name'] = $this->users->auth_login; $log_data['msg'] = $local_tpl_data['message']; $log_data['log_data'] = ''; $this->panel_log->save_log($log_data); $local_tpl_data['link'] = site_url('adm_servers/edit/game_types/' . $this->db->insert_id()); $local_tpl_data['back_link_txt'] = 'Далее'; break; } $this->tpl_data['content'] = $this->parser->parse('info.html', $local_tpl_data, true); } } else { redirect(''); } $this->parser->parse('main.html', $this->tpl_data); } // ----------------------------------------------------------------- /** * Удаление * выделенных серверов * игровых серверов * игр * типов игр * * @param string - тип * dedicated_servers - выделенные серверы * game_servers - игровые серверы * games - игры * type_games - типы игр * * @param string - служит для передачи дополнительных параметров * @param string * * */ public function delete($type = 'dedicated_servers', $id = false, $confirm = false) { if($this->users->auth_id){ // Пользователь авторизован $local_tpl_data = array(); $error_msg = false; if ($confirm == $this->security->get_csrf_hash()) { /* Пользователь подтвердил удаление */ switch($type) { case 'dedicated_servers': /* -------------------------------------------- */ /* Выделенные серверы */ /* -------------------------------------------- */ $this->load->model('servers/dedicated_servers'); if (!$this->dedicated_servers->get_ds_list(array('id' => $id))) { $this->_show_message(lang('adm_servers_selected_ds_unavailable'), site_url('adm_servers/view/dedicated_servers')); return false; } if ($this->servers->get_server_list(false, false, array('ds_id' => $id))) { $this->_show_message(lang('adm_servers_ds_contains_game_servers'), site_url('adm_servers/view/dedicated_servers')); return false; } if ($this->dedicated_servers->del_dedicated_server($id)) { $local_tpl_data['message'] = lang('adm_servers_delete_server_successful'); } else { $local_tpl_data['message'] = lang('adm_servers_delete_server_failed'); } // Записываем логи $log_data['type'] = 'adm_servers'; $log_data['command'] = 'delete_ds'; $log_data['server_id'] = 0; $log_data['user_name'] = $this->users->auth_login; $log_data['msg'] = $local_tpl_data['message']; $log_data['log_data'] = 'ID: ' . $id; $this->panel_log->save_log($log_data); $local_tpl_data['link'] = site_url('adm_servers/view/dedicated_servers'); $local_tpl_data['back_link_txt'] = lang('adm_servers_back_to_servers'); break; case 'game_servers': /* -------------------------------------------- */ /* Игровые серверы */ /* -------------------------------------------- */ if(!$this->servers->get_server_data($id)) { $this->_show_message(lang('adm_servers_server_not_found'), site_url('adm_servers/view/game_servers')); return false; } // Остановка сервера try { send_command($this->servers->command_generate($this->servers->server_data, 'stop'), $server_data); } catch (Exception $e) { // Не удалось остановить сервер } // Для логов $files_deleted = 'false'; if ($this->input->post('delete_files') && !empty($this->servers->server_data['dir']) && $this->servers->server_data['dir'] != '/' && $this->servers->server_data['dir'] != '\\' ) { /* Удаление директории на выделенном сервере */ switch(strtolower($this->servers->server_data['os'])) { case 'windows': $command = 'rmdir /S /Q ' . str_replace('/', '\\', $this->servers->server_data['dir']); break; default: // Linux $command = 'rm -rf ' . $this->servers->server_data['dir']; break; } try { $result = send_command($command, $this->servers->server_data); // Для логов $files_deleted = 'true'; } catch (Exception $e) { // Для логов $files_deleted = 'false'; /* Сохраняем логи */ $log_data['type'] = 'server_files'; $log_data['command'] = 'delete_files'; $log_data['user_name'] = $this->users->auth_login; $log_data['server_id'] = $this->servers->server_data['id']; $log_data['msg'] = 'Delete files failure'; $log_data['log_data'] = 'Directory: ' . $this->servers->server_data['dir'] . "\n"; $this->panel_log->save_log($log_data); } } if ($this->servers->delete_game_server($id)) { $local_tpl_data['message'] = lang('adm_servers_delete_server_successful'); } else { $local_tpl_data['message'] = lang('adm_servers_delete_server_failed'); } // Записываем логи $log_data['type'] = 'adm_servers'; $log_data['command'] = 'delete_game_server'; $log_data['server_id'] = $id; $log_data['user_name'] = $this->users->auth_login; $log_data['msg'] = $local_tpl_data['message']; $log_data['log_data'] = 'ID: ' . $id . ' Files deleted: ' . $files_deleted; $this->panel_log->save_log($log_data); $local_tpl_data['link'] = site_url('adm_servers/view/game_servers'); $local_tpl_data['back_link_txt'] = lang('adm_servers_back_to_servers'); break; case 'games': /* -------------------------------------------- */ /* Игры */ /* -------------------------------------------- */ $this->load->model('servers/games'); if(!$this->games->get_games_list(array('code' => $id))) { $this->_show_message(lang('adm_servers_game_not_found'), site_url('adm_servers/view/games')); return false; } if($this->servers->get_server_list(false, false, array('game' => $id))) { $this->_show_message(lang('adm_servers_game_contains_game_servers'), site_url('adm_servers/view/games')); return false; } if($this->games->delete_game($id)){ $local_tpl_data['message'] = lang('adm_servers_delete_game_successful'); }else{ $local_tpl_data['message'] = lang('adm_servers_delete_game_failed'); } // Записываем логи $log_data['type'] = 'adm_servers'; $log_data['command'] = 'delete_game'; $log_data['server_id'] = 0; $log_data['user_name'] = $this->users->auth_login; $log_data['msg'] = $local_tpl_data['message']; $log_data['log_data'] = 'ID: ' . $id; $this->panel_log->save_log($log_data); $local_tpl_data['link'] = site_url('adm_servers/view/games'); $local_tpl_data['back_link_txt'] = lang('adm_servers_back_to_games'); break; case 'game_types': /* -------------------------------------------- */ /* Игровые модификации */ /* -------------------------------------------- */ $this->load->model('servers/game_types'); if(!$this->game_types->get_gametypes_list(array('id' => $id))) { $this->_show_message(lang('adm_servers_game_type_not_found'), site_url('adm_servers/view/game_types')); return false; } if($this->servers->get_server_list(false, false, array('game_type' => $id))) { $this->_show_message(lang('adm_servers_game_type_contains_game_servers'), site_url('adm_servers/view/game_types')); return false; } /* Удаление модификации */ if($this->game_types->delete_game_type($id)){ $local_tpl_data['message'] = lang('adm_servers_delete_game_type_successful'); }else{ $local_tpl_data['message'] = lang('adm_servers_delete_game_type_failed'); } // Записываем логи $log_data['type'] = 'adm_servers'; $log_data['command'] = 'delete_game_type'; $log_data['server_id'] = 0; $log_data['user_name'] = $this->users->auth_login; $log_data['msg'] = $local_tpl_data['message']; $log_data['log_data'] = 'ID: ' . $id; $this->panel_log->save_log($log_data); $local_tpl_data['link'] = site_url('adm_servers/view/game_types'); $local_tpl_data['back_link_txt'] = lang('adm_servers_back_to_game_types'); break; default: $local_tpl_data['message'] = lang('adm_servers_unknown_page'); $local_tpl_data['link'] = site_url('/adm_servers/view/game_types'); $local_tpl_data['back_link_txt'] = lang('adm_servers_back_to_game_types'); break; } // Отображаем инфо сообщение $this->tpl_data['content'] = $this->parser->parse('info.html', $local_tpl_data, true); } else { /* Пользователь не подвердил */ switch($type){ case 'dedicated_servers': $confirm_tpl['message'] = lang('adm_servers_delete_ds_confirm'); $confirm_tpl['confirmed_url'] = site_url('adm_servers/delete/dedicated_servers/'. $id . '/' . $this->security->get_csrf_hash()); break; case 'game_servers': $confirm_tpl['extra_checkbox'] = form_checkbox('delete_files', 'accept', true, 'id="extra"'); $confirm_tpl['extra_text'] = lang('adm_servers_delete_files'); $confirm_tpl['message'] = lang('adm_servers_delete_gs_confirm'); $confirm_tpl['confirmed_url'] = site_url('adm_servers/delete/game_servers/'. $id . '/' . $this->security->get_csrf_hash()); break; case 'games': $confirm_tpl['message'] = lang('adm_servers_delete_game_confirm'); $confirm_tpl['confirmed_url'] = site_url('adm_servers/delete/games/'. $id . '/' . $this->security->get_csrf_hash()); break; case 'game_types': $confirm_tpl['message'] = lang('adm_servers_delete_game_type_confirm'); $confirm_tpl['confirmed_url'] = site_url('adm_servers/delete/game_types/'. $id . '/' . $this->security->get_csrf_hash()); break; } $this->tpl_data['content'] .= $this->parser->parse('confirm.html', $confirm_tpl, true); } }else{ redirect(''); } $this->parser->parse('main.html', $this->tpl_data); } // ----------------------------------------------------------- /** * Редактирование * выделенных серверов * игровых серверов * игр * типов игр * * @param string - тип * dedicated_servers - выделенные серверы * game_servers - игровые серверы * games - игры * type_games - типы игр * * @param string - служит для передачи дополнительных параметров * @param string * * */ public function edit($type = 'dedicated_servers', $id = false, $param_2 = false) { $local_tpl_data = array(); $error_msg = false; switch($type) { case 'dedicated_servers': /* -------------------------------------------- */ /* Выделенные серверы */ /* -------------------------------------------- */ $this->load->model('servers/dedicated_servers'); if (!$this->dedicated_servers->get_ds_list(array('id' => $id), 1)) { $this->_show_message(lang('adm_servers_server_not_found'), site_url('adm_servers/view/dedicated_servers')); return false; } // Файл шаблона с формой $tpl_file_edit = 'adm_servers/dedicated_servers_control.html'; $tpl_list = $this->dedicated_servers->tpl_data_ds(); $local_tpl_data = $tpl_list[0]; //if(in_array('ssh2', get_loaded_extensions())); $options = array('ssh' => 'SSH', 'telnet' => 'Telnet'); if ($this->dedicated_servers->ds_list['0']['control_protocol'] == 'local') { // Поле Local отображается лишь для локального сервера // Однако можно вручную подменить значения в html коде, // но в этом нет ничего страшного $options['local'] = 'Local'; } $local_tpl_data['control_protocol'] = form_dropdown('control_protocol', $options, $this->dedicated_servers->ds_list['0']['control_protocol']); $local_tpl_data['script_path'] = $this->dedicated_servers->ds_list['0']['script_path']; $local_tpl_data['steamcmd_path'] = $this->dedicated_servers->ds_list['0']['steamcmd_path']; $local_tpl_data['ssh_host'] = $this->dedicated_servers->ds_list['0']['ssh_host']; $local_tpl_data['ssh_login'] = $this->dedicated_servers->ds_list['0']['ssh_login']; $local_tpl_data['ssh_path'] = $this->dedicated_servers->ds_list['0']['ssh_path']; $local_tpl_data['telnet_host'] = $this->dedicated_servers->ds_list['0']['telnet_host']; $local_tpl_data['telnet_login'] = $this->dedicated_servers->ds_list['0']['telnet_login']; $local_tpl_data['telnet_path'] = $this->dedicated_servers->ds_list['0']['telnet_path']; $local_tpl_data['ftp_host'] = $this->dedicated_servers->ds_list['0']['ftp_host']; $local_tpl_data['ftp_login'] = $this->dedicated_servers->ds_list['0']['ftp_login']; $local_tpl_data['ftp_path'] = $this->dedicated_servers->ds_list['0']['ftp_path']; // Получаем список серверов на DS $gs = $this->servers->get_game_servers_list(array('ds_id' => $id)); $local_tpl_data['servers_list'] = $this->servers->tpl_data(); /* * Правила для формы * * Документация: * http://cidocs.ru/213/libraries/form_validation.html * */ $this->form_validation->set_rules('name', 'название', 'trim|required|max_length[64]|min_length[3]|xss_clean'); $this->form_validation->set_rules('os', 'операционная система', 'trim|required|max_length[64]|min_length[3]|xss_clean'); $this->form_validation->set_rules('location', 'расположение', 'trim|required|max_length[64]|min_length[3]|xss_clean'); $this->form_validation->set_rules('provider', 'провайдер', 'trim|max_length[64]|min_length[3]|xss_clean'); $this->form_validation->set_rules('ip', 'IP', 'trim|required|xss_clean'); $this->form_validation->set_rules('ram', 'RAM', 'trim|max_length[64]|xss_clean'); $this->form_validation->set_rules('cpu', 'CPU', 'trim|max_length[64]|xss_clean'); // Редактирование данных доступа к серверу (пароли ftp, ssh) $this->form_validation->set_rules('steamcmd_path', lang('adm_servers_steamcmd_path'), 'trim|max_length[256]|xss_clean'); $this->form_validation->set_rules('script_path', lang('adm_servers_script_path'), 'trim|max_length[256]|xss_clean'); $this->form_validation->set_rules('ssh_host', 'SSH хост', 'trim|max_length[64]|xss_clean'); $this->form_validation->set_rules('ssh_login', 'SSH логин', 'trim|max_length[64]|xss_clean'); $this->form_validation->set_rules('ssh_password', 'SSH пароль', 'trim|max_length[64]|xss_clean'); $this->form_validation->set_rules('ssh_path', 'Путь SSH', 'trim|max_length[256]|xss_clean'); $this->form_validation->set_rules('telnet_host', 'Telnet хост', 'trim|max_length[64]|xss_clean'); $this->form_validation->set_rules('telnet_login', 'Telnet логин', 'trim|max_length[64]|xss_clean'); $this->form_validation->set_rules('telnet_password', 'Telnet пароль', 'trim|max_length[64]|xss_clean'); $this->form_validation->set_rules('telnet_path', 'Путь Telnet', 'trim|max_length[256]|xss_clean'); $this->form_validation->set_rules('ftp_host', 'FTP хост', 'trim|max_length[64]|xss_clean'); $this->form_validation->set_rules('ftp_login', 'FTP логин', 'trim|max_length[64]|xss_clean'); $this->form_validation->set_rules('ftp_password', 'FTP пароль', 'trim|max_length[64]|xss_clean'); $this->form_validation->set_rules('ftp_path', 'Путь FTP', 'trim|max_length[256]|xss_clean'); $this->form_validation->set_rules('control_protocol', 'Протокол управления', 'trim|min_length[3]|max_length[16]|xss_clean'); break; case 'game_servers': /* -------------------------------------------- */ /* Игровые серверы */ /* -------------------------------------------- */ $this->load->model('servers/dedicated_servers'); $this->load->model('servers/games'); $this->load->model('servers/game_types'); $this->load->helper('form'); //if(!$game_servers_list = $this->servers->get_game_servers_list(array('id' => $id), 1)){ // $this->_show_message('Сервера с таким ID не существует', '/adm_servers/view/game_servers'); // return false; //} if(!$this->servers->get_server_data($id)){ $this->_show_message(lang('adm_servers_server_not_found'), site_url('adm_servers/view/game_servers')); return false; } // Файл шаблона с формой $tpl_file_edit = 'adm_servers/game_servers_control.html'; $servers_list = $this->servers->tpl_data(); $local_tpl_data = $servers_list[0]; $local_tpl_data['information'] = array(); // Для tpl $local_tpl_data['screen_name'] = $this->servers->server_data['screen_name']; $local_tpl_data['su_user'] = $this->servers->server_data['su_user']; $local_tpl_data['server_dir'] = $this->servers->server_data['dir']; $local_tpl_data['game_type_id'] = $this->servers->server_data['game_type']; $local_tpl_data['server_start_code'] = $this->servers->server_data['start_code']; $local_tpl_data['start_command'] = $this->servers->server_data['start_command']; $local_tpl_data['query_port'] = $this->servers->server_data['query_port']; $local_tpl_data['rcon_port'] = $this->servers->server_data['rcon_port']; /* Получаем абсолютный путь к корневой директории с сервером и к исполняемым файлам */ $local_tpl_data['full_server_path'] = $this->servers->server_data['script_path'] . '/' . $this->servers->server_data['dir']; $local_tpl_data['script_path'] = $this->servers->server_data['script_path']; // Модификация $where = array('game_code' => $this->servers->server_data['game']); $gametypes_list = $this->game_types->get_gametypes_list($where); $options = array(); $i = 0; foreach($gametypes_list as $list) { $options[$list['id']] = $list['name']; /* Узнаем ключ в массиве модификации которой принадлежит этот сервер */ if ($list['id'] == $this->servers->server_data['game_type']) { $gt_key = $i; } $i ++; } $local_tpl_data['game_type_dropdown'] = array(); $local_tpl_data['aliases_list'] = array(); $server_aliases = json_decode($this->servers->server_data['aliases'], true); $local_tpl_data['game_type_dropdown'] = form_dropdown('game_type', $options, $this->servers->server_data['game_type']); $local_tpl_data['server_enabled_checkbox'] = form_checkbox('enabled', 'accept', $this->servers->server_data['enabled']); // Заменяем двойные кавычки на html символы $local_tpl_data['start_command'] = str_replace('"', '"', $local_tpl_data['start_command'] ); /* Информация о DS */ if ($this->servers->server_data['ds_id']) { $local_tpl_data['ds_name'] = $this->dedicated_servers->ds_list[0]['name']; $local_tpl_data['ds_id'] = $this->dedicated_servers->ds_list[0]['id']; $local_tpl_data['ds_location'] = $this->dedicated_servers->ds_list[0]['location']; $local_tpl_data['ds_provider'] = $this->dedicated_servers->ds_list[0]['provider']; } else { // Сервер локальный $local_tpl_data['ds_name'] = lang('adm_servers_local_server'); $local_tpl_data['ds_id'] = 0; } /* Получение последних действий с сервером * * количество получаемых логов = 50 * количество отображаемых логов = 10 * * Некоторые из получаемых логов могут не относиться к серверам, из-за этого * таблица может быть пустой * */ $where = array('server_id' => $id); $server_plogs = $this->panel_log->get_log($where, 100); // Логи сервера в админпанели $local_tpl_data['log_list'] = array(); $log_num = 0; $i = 0; $count_i = count($server_plogs); while($i < $count_i){ if($log_num == 15) { break; } $local_tpl_data['log_list'][$i]['log_id'] = $server_plogs[$i]['id']; $local_tpl_data['log_list'][$i]['log_date'] = unix_to_human($server_plogs[$i]['date'], true, 'eu'); $local_tpl_data['log_list'][$i]['log_server_id'] = $server_plogs[$i]['server_id']; $local_tpl_data['log_list'][$i]['log_user_name'] = $server_plogs[$i]['user_name']; $local_tpl_data['log_list'][$i]['log_command'] = $server_plogs[$i]['command']; /* Код действия на понятный язык */ switch($server_plogs[$i]['type']){ case 'server_rcon': $local_tpl_data['log_list'][$i]['log_type'] = lang('server_control_rcon_send'); $log_num ++; break; case 'server_command': $local_tpl_data['log_list'][$i]['log_type'] = lang('server_control_command'); $log_num ++; break; case 'server_update': $local_tpl_data['log_list'][$i]['log_type'] = lang('server_control_update'); $log_num ++; break; case 'server_task': $local_tpl_data['log_list'][$i]['log_type'] = lang('server_control_srv_task'); $log_num ++; break; case 'server_settings': $local_tpl_data['log_list'][$i]['log_type'] = lang('server_control_settings'); $log_num ++; break; case 'server_files': $local_tpl_data['log_list'][$i]['log_type'] = lang('server_control_file_operation'); $log_num ++; break; default: // Тип лога неизвестен, удаляем его из списка (не из базы) unset($local_tpl_data['log_list'][$i]); break; } $i ++; } /* ------------------------------ */ /* Различная информация о сервере */ /* ------------------------------ */ if ($this->servers->server_data['installed'] == '0') { $local_tpl_data['information'][]['text'] = lang('adm_servers_serv_not_installed') . '