edit_home.php 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939
  1. <?php
  2. /*
  3. *
  4. * OGP - Open Game Panel
  5. * Copyright (C) 2008 - 2018 The OGP Development Team
  6. *
  7. * http://www.opengamepanel.org/
  8. *
  9. * This program is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU General Public License
  11. * as published by the Free Software Foundation; either version 2
  12. * of the License, or any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, write to the Free Software
  21. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  22. *
  23. */
  24. require_once("modules/config_games/server_config_parser.php");
  25. function exec_ogp_module()
  26. {
  27. global $db;
  28. $isAdmin = $db->isAdmin( $_SESSION['user_id'] );
  29. $home_id = $_GET['home_id'];
  30. if( $isAdmin )
  31. $game_home['access_rights'] = "ufpetc";
  32. else
  33. $game_home = $db->getUserGameHome($_SESSION['user_id'],$home_id);
  34. if ( !$game_home and !$isAdmin )
  35. return;
  36. $submit = isset($_REQUEST['submit']) ? $_REQUEST['submit'] : "";
  37. $home_info = $db->getGameHomeWithoutMods($home_id);
  38. $servers_with_same_path = $db->getGameServersWithSamePath($home_info['remote_server_id'], $home_info['home_path']);
  39. $servers_with_same_path = (is_array($servers_with_same_path) ? count($servers_with_same_path) : 0);
  40. $home_id = $home_info['home_id'];
  41. $enabled_mods = $db->getHomeMods($home_id);
  42. if( $isAdmin and isset( $_POST['change_home_cfg_id'] ) )
  43. {
  44. if( !empty($enabled_mods) )
  45. {
  46. foreach ( $enabled_mods as $enabled_rows )
  47. {
  48. $db->delGameMod($enabled_rows['mod_id']);
  49. }
  50. }
  51. $home_cfg_id = $home_info['home_cfg_id'];
  52. $new_home_cfg_id = $_POST['home_cfg_id'];
  53. if($db->updateHomeCfgId($home_id, $new_home_cfg_id))
  54. {
  55. $json_message = array('result' => 'success', 'info' => get_lang("successfully_changed_game_server"));
  56. echo json_encode($json_message);
  57. $db->logger( get_lang("successfully_changed_game_server") ." HOME ID:$home_id - ". get_lang("change_game_type") .":old home_cfg_id:$home_cfg_id, new home_cfg_id:$new_home_cfg_id");
  58. }
  59. else
  60. echo json_encode(array('result' => 'failure', 'info' => 'Error while updating game type.'));
  61. return;
  62. }
  63. $server_xml = read_server_config(SERVER_CONFIG_LOCATION.$home_info['home_cfg_file']);
  64. include_once('includes/lib_remote.php');
  65. $remote = new OGPRemoteLibrary($home_info['agent_ip'],$home_info['agent_port'],$home_info['encryption_key'],$home_info['timeout']);
  66. $ftp_installed = $db->isModuleInstalled('ftp');
  67. if( isset($_REQUEST['change_name']) )
  68. {
  69. $server_name = strip_tags(strip_real_escape_string($_POST['server_name']));
  70. if ( $db->changeHomeName($home_id, $server_name) === TRUE )
  71. {
  72. echo json_encode(array('result' => 'success', 'info' => get_lang("successfully_changed_game_server")));
  73. $db->logger( get_lang("successfully_changed_game_server") ." HOME ID:$home_id - ". get_lang("game_server_name") .":$server_name");
  74. }
  75. else
  76. echo json_encode(array('result' => 'failure', 'info' => 'Name update failed.'));
  77. return;
  78. }
  79. elseif ( isset($_REQUEST['change_control_password']) )
  80. {
  81. $control_password = $_POST['control_password'];
  82. if($control_password != "")
  83. {
  84. $control_password = validate_login($control_password);
  85. if(!$control_password)
  86. {
  87. echo json_encode(array('result' => 'failure', 'info' => 'Not allowed characters'));
  88. return;
  89. }
  90. }
  91. if ( $db->changeHomeControlPassword($home_id, $control_password) === TRUE )
  92. {
  93. echo json_encode(array('result' => 'success', 'info' => get_lang("control_password_updated_successfully")));
  94. $db->logger( get_lang("control_password_updated_successfully") ." HOME ID:$home_id - ". get_lang("game_control_password") .":$control_password");
  95. }
  96. else
  97. echo json_encode(array('result' => 'failure', 'info' => get_lang("control_password_update_failed")));
  98. return;
  99. }
  100. elseif( isset($_REQUEST['change_ftp_login']) && preg_match("/t/",$game_home['access_rights']) > 0 )
  101. {
  102. // Is FTP Module Installed?
  103. if($ftp_installed){
  104. if ($db->IsFtpEnabled($home_id) OR $isAdmin)
  105. {
  106. $old_login = isset($home_info['ftp_login']) ? $home_info['ftp_login'] : $home_id;
  107. $post_ftp_login = $_POST['ftp_login'];
  108. if($post_ftp_login != "")
  109. {
  110. $post_ftp_login = validate_login($post_ftp_login);
  111. if(!$post_ftp_login)
  112. {
  113. echo json_encode(array('result' => 'failure', 'info' => 'Not allowed characters'));
  114. return;
  115. }
  116. }
  117. else
  118. {
  119. echo json_encode(array('result' => 'failure', 'info' => 'Empty input not permitted.'));
  120. return;
  121. }
  122. // Validation
  123. // Is the same user old and new?
  124. if($old_login == $post_ftp_login)
  125. {
  126. echo json_encode(array('result' => 'success', 'info' => ''));
  127. return;
  128. }
  129. if(strlen($post_ftp_login) > 32){
  130. echo json_encode(array('result' => 'failure', 'info' => get_lang("ftp_account_username_too_long")));
  131. return;
  132. }
  133. $host_stat = $remote->status_chk();
  134. $user_exists = FALSE;
  135. $old_login_exists = FALSE;
  136. $host_online = FALSE;
  137. if( $host_stat === 1 )
  138. {
  139. $host_online = TRUE;
  140. $ftp_accounts_list = $remote->ftp_mgr("list");
  141. $ftp_accounts = explode("\n",$ftp_accounts_list);
  142. foreach($ftp_accounts as $ftp_account)
  143. {
  144. if( $ftp_account != "" )
  145. {
  146. list($ftp_login, $ftp_path) = explode("\t",$ftp_account);
  147. $ftp_login = trim($ftp_login);
  148. if ($ftp_login == $old_login)
  149. $old_login_exists = TRUE;
  150. if ($ftp_login == $post_ftp_login)
  151. $user_exists = TRUE;
  152. }
  153. }
  154. }
  155. if( $host_online and ! $user_exists )
  156. {
  157. if($old_login_exists)
  158. $change_login_delete_old = $remote->ftp_mgr("userdel", $old_login);
  159. else
  160. $change_login_delete_old = 1;
  161. if ($change_login_delete_old !== 0)
  162. {
  163. $change_login_add_new = $remote->ftp_mgr("useradd", $post_ftp_login, $home_info['ftp_password'], $home_info['home_path']);
  164. }
  165. if (isset($change_login_add_new) and $change_login_add_new !== 0)
  166. {
  167. if ( $db->changeFtpLogin($home_id,$post_ftp_login) === TRUE )
  168. {
  169. echo json_encode(array('result' => 'success', 'info' => get_lang("successfully_changed_game_server")));
  170. $db->logger( get_lang("successfully_changed_game_server") ." HOME ID:$home_id - ". get_lang("server_ftp_login") .":$post_ftp_login");
  171. }
  172. }
  173. else
  174. {
  175. echo json_encode(array('result' => 'failure', 'info' => get_lang("error_ocurred_on_remote_server") .
  176. " " . get_lang("ftp_login_can_not_be_changed")));
  177. }
  178. }
  179. else
  180. {
  181. echo json_encode(array('result' => 'failure', 'info' => get_lang("error_ocurred_on_remote_server") .
  182. " " . get_lang("ftp_login_can_not_be_changed")));
  183. }
  184. }
  185. }
  186. return;
  187. }
  188. elseif( isset( $_REQUEST['change_ftp_password']) && preg_match("/t/",$game_home['access_rights']) > 0 )
  189. {
  190. // Is FTP Module Installed?
  191. if($ftp_installed){
  192. if ($db->IsFtpEnabled($home_id) OR $isAdmin)
  193. {
  194. $ftp_password = $_POST['ftp_password'];
  195. if($ftp_password != "")
  196. {
  197. $ftp_password = validate_login($ftp_password);
  198. if(!$ftp_password)
  199. {
  200. echo json_encode(array('result' => 'failure', 'info' => 'Not allowed characters'));
  201. return;
  202. }
  203. }
  204. else
  205. {
  206. echo json_encode(array('result' => 'failure', 'info' => 'Empty input not permitted.'));
  207. return;
  208. }
  209. // Validation
  210. // Is the same password old and new?
  211. if($home_info['ftp_password'] == $ftp_password)
  212. {
  213. echo json_encode(array('result' => 'success', 'info' => ''));
  214. return;
  215. }
  216. if(strlen($ftp_password) > 128){
  217. echo json_encode(array('result' => 'failure', 'info' => get_lang("ftp_account_password_too_long")));
  218. return;
  219. }
  220. $host_stat = $remote->status_chk();
  221. $current_login = isset($home_info['ftp_login']) ? $home_info['ftp_login'] : $home_id;
  222. $login_exists = FALSE;
  223. $host_online = FALSE;
  224. if( $host_stat === 1 )
  225. {
  226. $host_online = TRUE;
  227. $ftp_accounts_list = $remote->ftp_mgr("list");
  228. $ftp_accounts = explode("\n",$ftp_accounts_list);
  229. foreach($ftp_accounts as $ftp_account)
  230. {
  231. if( $ftp_account != "" )
  232. {
  233. list($ftp_login, $ftp_path) = explode("\t",$ftp_account);
  234. $ftp_login = trim($ftp_login);
  235. if ($ftp_login == $current_login)
  236. {
  237. $login_exists = TRUE;
  238. break;
  239. }
  240. }
  241. }
  242. }
  243. if($host_online)
  244. {
  245. if(!$login_exists)
  246. {
  247. if($remote->ftp_mgr("useradd", $current_login, $ftp_password, $home_info['home_path']) !== 0)
  248. {
  249. echo json_encode(array('result' => 'success', 'info' => get_lang("successfully_changed_game_server")));
  250. $db->logger( get_lang("successfully_changed_game_server") ." HOME ID:$home_id - ". get_lang("server_ftp_password") .":$ftp_password");
  251. }
  252. else
  253. {
  254. echo json_encode(array('result' => 'failure', 'info' => get_lang("error_ocurred_on_remote_server") .
  255. " " . get_lang("ftp_password_can_not_be_changed")));
  256. }
  257. return;
  258. }
  259. else
  260. {
  261. if ($remote->ftp_mgr("passwd", $current_login, $ftp_password) !== 0)
  262. {
  263. if ( $db->changeFtpPassword($home_id,clean_path($ftp_password)) === TRUE )
  264. {
  265. echo json_encode(array('result' => 'success', 'info' => get_lang("successfully_changed_game_server")));
  266. $db->logger( get_lang("successfully_changed_game_server") ." HOME ID:$home_id - ". get_lang("server_ftp_password") .":$ftp_password");
  267. }
  268. }
  269. else
  270. {
  271. echo json_encode(array('result' => 'failure', 'info' => get_lang("error_ocurred_on_remote_server") .
  272. " " . get_lang("ftp_password_can_not_be_changed")));
  273. }
  274. }
  275. }
  276. else
  277. echo json_encode(array('result' => 'failure', 'info' => get_lang("error_ocurred_on_remote_server") .
  278. " " . get_lang("ftp_password_can_not_be_changed")));
  279. }
  280. }
  281. return;
  282. }
  283. elseif (isset($_POST["force_mod_id"]))
  284. {
  285. $force_mod_id = $_POST['force_mod_id'];
  286. $ip_id = $_POST['ip_id'];
  287. $port = $_POST['port'];
  288. if ( $db->forceModAtAddress($ip_id, $port, $force_mod_id) )
  289. {
  290. echo json_encode(array('result' => 'success', 'info' => get_lang("successfully_assigned_mod_to_address")));
  291. $db->logger( get_lang("successfully_assigned_mod_to_address") );
  292. }
  293. else
  294. echo json_encode(array('result' => 'failure', 'info' => "Failed to assign mod to address."));
  295. return;
  296. }
  297. elseif ( $isAdmin )
  298. {
  299. if( isset( $_REQUEST['create_ftp']) )
  300. {
  301. $login = isset($home_info['ftp_login']) ? $home_info['ftp_login'] : $home_id;
  302. $success = true;
  303. if(strlen($login) > 32){
  304. $result = get_lang("ftp_account_username_too_long");
  305. $type = "failure";
  306. $success = false;
  307. }
  308. if($success){
  309. if ($remote->ftp_mgr("useradd", $login, $home_info['ftp_password'], $home_info['home_path']) === 0)
  310. {
  311. $result = get_lang("error_ocurred_on_remote_server") ." ". get_lang("ftp_can_not_be_switched_on");
  312. $type = "failure";
  313. }
  314. else
  315. {
  316. $db->changeFtpStatus('enabled',$home_id);
  317. $result = get_lang("successfully_changed_game_server");
  318. $type = "success";
  319. $db->logger( get_lang("successfully_changed_game_server") ." HOME ID:$home_id - ". get_lang("change_ftp_account_status") .":enabled");
  320. }
  321. }
  322. }
  323. else if( isset( $_REQUEST['delete_ftp']) )
  324. {
  325. $login = isset($home_info['ftp_login']) ? $home_info['ftp_login'] : $home_id;
  326. $host_stat = $remote->status_chk();
  327. $user_exists = FALSE;
  328. $host_online = FALSE;
  329. if( $host_stat === 1 )
  330. {
  331. $host_online = TRUE;
  332. $ftp_accounts_list = $remote->ftp_mgr("list");
  333. $ftp_accounts = explode("\n",$ftp_accounts_list);
  334. foreach($ftp_accounts as $ftp_account)
  335. {
  336. if( $ftp_account != "" )
  337. {
  338. list($ftp_login, $ftp_path) = explode("\t",$ftp_account);
  339. $ftp_login = trim($ftp_login);
  340. if ($ftp_login == $login)
  341. {
  342. $user_exists = TRUE;
  343. break;
  344. }
  345. }
  346. }
  347. }
  348. if($host_online and $ftp_accounts_list !== 0)
  349. {
  350. if( $user_exists )
  351. {
  352. $delete_ftp = $remote->ftp_mgr("userdel", $login);
  353. if ($delete_ftp === 0)
  354. {
  355. $result = get_lang("error_ocurred_on_remote_server") ." ". get_lang("ftp_can_not_be_switched_off");
  356. $type = "failure";
  357. }
  358. else
  359. {
  360. $db->changeFtpStatus('disabled',$home_id);
  361. $result = get_lang("successfully_changed_game_server");
  362. $type = "success";
  363. $db->logger( get_lang("successfully_changed_game_server") ." HOME ID:$home_id - ". get_lang("change_ftp_account_status") .":disabled");
  364. }
  365. }
  366. else
  367. {
  368. $db->changeFtpStatus('disabled',$home_id);
  369. $result = get_lang("successfully_changed_game_server");
  370. $type = "success";
  371. $db->logger( get_lang("successfully_changed_game_server") ." HOME ID:$home_id - ". get_lang("change_ftp_account_status") .":disabled");
  372. }
  373. }
  374. else
  375. {
  376. $result = get_lang("error_ocurred_on_remote_server") ." ". get_lang("ftp_can_not_be_switched_off");
  377. $type = "failure";
  378. }
  379. }
  380. else if( isset( $_REQUEST['change_user_id_main']) )
  381. {
  382. $user_id_main = $_POST['user_id_main'];
  383. $old_home = $db->getUserGameHome($home_info['user_id_main'],$home_id);
  384. if(isset($_POST['deleteoldassigns']))
  385. {
  386. $db->unassignHomeFrom("user",$home_info['user_id_main'],$home_id);
  387. $home_groups = $db->getGroupsForHome($home_info['home_id']);
  388. if( isset( $home_groups ) )
  389. {
  390. foreach($home_groups as $home_group)
  391. {
  392. $db->unassignHomeFrom("group",$home_group['group_id'],$home_id);
  393. }
  394. }
  395. }
  396. if ( $db->changeUserIdMain($home_id,$user_id_main) == TRUE )
  397. {
  398. $db->assignHomeTo("user",$user_id_main,$home_id,$old_home['access_rights']);
  399. echo json_encode(array('result' => 'success', 'info' => get_lang("successfully_changed_game_server")));
  400. $db->logger( get_lang("successfully_changed_game_server") ." HOME ID:$home_id - ". get_lang("change_user_id_main") .":$user_id_main");
  401. }
  402. else
  403. echo json_encode(array('result' => 'failure', 'info' => "Unable to change main user."));
  404. return;
  405. }
  406. else if( isset( $_REQUEST['change_home'] ) )
  407. {
  408. $home_path = strip_real_escape_string($_POST['home_path']);
  409. if(preg_match("/^[a-z]:\//i", $home_path))
  410. {
  411. $home_path = str_replace("/", "\\\\", $home_path);
  412. $home_path = rtrim($remote->exec("cygpath -u $home_path"));
  413. }
  414. if(preg_match("/^\//",$home_path))
  415. {
  416. if ( $db->changeHomePath($home_id,clean_path($home_path)) === TRUE )
  417. {
  418. $home_info = $db->getGameHomeWithoutMods($home_id);
  419. $servers_with_same_path = $db->getGameServersWithSamePath($home_info['remote_server_id'], $home_info['home_path']);
  420. $servers_with_same_path = (is_array($servers_with_same_path) ? count($servers_with_same_path) : 0);
  421. $success_json = array('result' => 'success', 'info' => get_lang("successfully_changed_game_server"));
  422. if($servers_with_same_path > 1){
  423. $success_json["warning_info"] = get_lang('other_servers_exist_with_path_please_change');
  424. }
  425. // Create new home directory if it doesn't already exist
  426. $remote->exec("mkdir -p " . clean_path($home_path));
  427. // If FTP is enabled, update the FTP info.
  428. if($ftp_installed){
  429. if ($db->IsFtpEnabled($home_id))
  430. {
  431. $login = isset($home_info['ftp_login']) ? $home_info['ftp_login'] : $home_id;
  432. $delte_old_ftp_account = $remote->ftp_mgr("userdel", $login);
  433. if ($delte_old_ftp_account !== 0)
  434. {
  435. $create_new_ftp_account = $remote->ftp_mgr("useradd", $login, $home_info['ftp_password'], $home_path);
  436. }
  437. if (isset($create_new_ftp_account) and $create_new_ftp_account !== 0)
  438. {
  439. echo json_encode($success_json);
  440. $db->logger( get_lang("successfully_changed_game_server") ." HOME ID:$home_id - ". get_lang("home_path") .":$home_path");
  441. }
  442. else
  443. {
  444. echo json_encode(array('result' => 'failure', 'info' => get_lang("error_ocurred_on_remote_server") .
  445. " " . get_lang("ftp_login_can_not_be_changed")));
  446. }
  447. }
  448. else
  449. {
  450. echo json_encode($success_json);
  451. $db->logger( get_lang("successfully_changed_game_server") ." HOME ID:$home_id - ". get_lang("home_path") .":$home_path");
  452. }
  453. }
  454. else
  455. {
  456. echo json_encode($success_json);
  457. $db->logger( get_lang("successfully_changed_game_server") ." HOME ID:$home_id - ". get_lang("home_path") .":$home_path");
  458. }
  459. }
  460. else
  461. echo json_encode(array('result' => 'failure', 'info' => get_lang("selected_path_already_in_use")));
  462. }
  463. else
  464. echo json_encode(array('result' => 'failure', 'info' => get_lang("invalid_path")));
  465. return;
  466. }
  467. else if( isset( $_REQUEST['master_server'] ) )
  468. {
  469. if ( isset( $_POST['add'] ) )
  470. $action = "add";
  471. else
  472. $action = "remove";
  473. if ( $db->setMasterServer($action, $home_id, $home_info['home_cfg_id'], $home_info['remote_server_id']) === TRUE )
  474. {
  475. $result = get_lang("successfully_changed_game_server");
  476. $type = "success";
  477. $db->logger( get_lang("successfully_changed_game_server") ." HOME ID:$home_id - ". get_lang("set_as_master_server") .":$action");
  478. }
  479. }
  480. if( isset($_REQUEST['add_mod']) )
  481. {
  482. $mod_cfg_id = $_POST['mod_cfg_id'];
  483. if ( $db->addModToGameHome($home_id,$mod_cfg_id) === FALSE )
  484. {
  485. $result = get_lang_f('failed_to_assing_mod_to_home',$mod_cfg_id);
  486. $type = "failure";
  487. }
  488. else
  489. {
  490. $result = get_lang_f('successfully_assigned_mod_to_home',$mod_cfg_id);
  491. $type = "success";
  492. $db->logger(get_lang_f('successfully_assigned_mod_to_home',$mod_cfg_id)." [HOME ID:$home_id]");
  493. }
  494. }
  495. else if($submit == "delete_mod")
  496. {
  497. $mod_id = $_GET['mod_id'];
  498. if ( $db->delGameMod($mod_id) === TRUE )
  499. {
  500. $result = get_lang("successfully_removed_mod");
  501. $type = "success";
  502. $db->logger( get_lang("successfully_removed_mod") ." [MOD ID:$mod_id HOME ID:$home_id]");
  503. }
  504. }
  505. else if(isset($_REQUEST['set_options']))
  506. {
  507. $maxplayers = 0 + @$_POST['maxplayers'];
  508. $cliopts = $_POST['cliopts'];
  509. // Get the total CPU count. and, if the agent is offline, set the CPU to NA.
  510. $remoteCpus = $remote->cpu_count();
  511. $validCpus = $remoteCpus === -1 ? 'NA' : $remoteCpus-1;
  512. if(isset($_POST['cpus']) && $validCpus !== 'NA')
  513. {
  514. $cpuArray = explode(',', $_POST['cpus']);
  515. // Check if a a valid core has been submitted. eg, the checkbox hasn't been manually edited.
  516. foreach($cpuArray as $cpu)
  517. {
  518. if($cpu > $validCpus || !is_numeric($cpu))
  519. {
  520. $cpus = 'NA';
  521. break;
  522. } else {
  523. $cpus[] = $cpu;
  524. }
  525. }
  526. // If $cpus is an array, seperate all the values with a comma. Otherwise, just pass $cpus to the query - which, as above, will be NA.
  527. $cpus = is_array($cpus) ? implode(',', $cpus) : $cpus;
  528. } else {
  529. $cpus = 'NA';
  530. }
  531. // If we're on Windows, and some cores have been selected...
  532. if (preg_match('/cygwin/i', $remote->what_os()) && $cpus !== 'NA') {
  533. $result = 0;
  534. $cores = explode(',', $cpus);
  535. foreach ($cores as $core) {
  536. $coreNum = intval($core);
  537. $result |= (1 << $coreNum);
  538. }
  539. $cpus = strtoupper(dechex($result));
  540. }
  541. $nice = isset($_POST['nice']) ? (int)$_POST['nice'] : 0;
  542. $mod_cfg_id = $_POST['mod_cfg_id'];
  543. if ( $db->updateGameModParams($maxplayers,$cliopts,$cpus,$nice,$home_id,$mod_cfg_id) === TRUE )
  544. {
  545. echo json_encode(array('result' => 'success', 'info' => get_lang("successfully_modified_mod")));
  546. $db->logger( get_lang("successfully_modified_mod") ." [MOD CFG ID:$mod_cfg_id HOME ID:$home_id]");
  547. }
  548. else
  549. echo json_encode(array('result' => 'failure', 'info' => "The mod could not be changed."));
  550. return;
  551. }
  552. else if( isset( $_REQUEST['set_expiration_date'] ) )
  553. {
  554. if ( $db->updateExpirationDate($home_id, $_POST['expiration_date'], 'server') === TRUE )
  555. {
  556. echo json_encode(array('result' => 'success', 'info' => get_lang('expiration_date_changed')));
  557. $db->logger( get_lang('expiration_date_changed') ." [ HOME ID:$home_id NEW DATE:" . $_POST['expiration_date'] ." ]");
  558. }
  559. else
  560. echo json_encode(array('result' => 'failure', 'info' => get_lang('expiration_date_could_not_be_changed')));
  561. return;
  562. }
  563. }
  564. ?>
  565. <link rel="stylesheet" type="text/css" href="js/datetimepicker/jquery.datetimepicker.min.css"/>
  566. <script src="js/datetimepicker/jquery.datetimepicker.full.min.js"></script>
  567. <script type="text/javascript" src="js/modules/user_games.js"></script>
  568. <?php
  569. echo "<h2>". get_lang("editing_home_called") ." \"".htmlentities($home_info['home_name'])."\"</h2><div id='result' >";
  570. if(isset($result))
  571. {
  572. if($type == 'success')
  573. print_success($result);
  574. elseif($type = 'failure')
  575. print_failure($result);
  576. }
  577. echo "</div>";
  578. $home_info = $db->getGameHomeWithoutMods($home_id);
  579. echo "<p>";
  580. echo "<a href='?m=gamemanager&p=game_monitor&home_id=$home_id'>&lt;&lt; ". get_lang("back_to_game_monitor") ."</a>";
  581. if ( $isAdmin )
  582. {
  583. echo " &nbsp; ";
  584. echo "<a href='?m=user_games'>&lt;&lt; ". get_lang("back_to_game_servers") ."</a>";
  585. }
  586. echo "</p>";
  587. echo "<table class='center' id='main_settings' >";
  588. if ( $isAdmin )
  589. {
  590. // Form to change game type
  591. echo "<tr><td rowspan='2' class='right'>". get_lang("game_type") .":</td><td class='left'>";
  592. echo "<form action='?m=user_games&p=edit&home_id=".$home_id."' method='post'>";
  593. $game_cfgs = $db->getGameCfgs();
  594. $host_stat = $remote->status_chk();
  595. if( $host_stat === 1)
  596. $os = $remote->what_os();
  597. else
  598. $os = "Unknown OS";
  599. echo "<select name='home_cfg_id' >";
  600. echo get_game_selector($os, $game_cfgs, $home_info['home_cfg_id']);
  601. echo "</select>";
  602. echo "<input type='submit' name='change_home_cfg_id' value='". get_lang("change_game_type") ."' />";
  603. echo "</form></td></tr>";
  604. echo "<tr><td colspan='2' class='info'>". get_lang("change_game_type_info") ."</td></tr>";
  605. // Form to edit main user.
  606. echo "<tr><td class='right'>". get_lang("user_id_main") .":</td><td class='left'>";
  607. echo "<form action='?m=user_games&p=edit&home_id=".$home_id."' method='post'>";
  608. echo "<input type='hidden' name='home_id' value=\"$home_id\" />\n";
  609. echo "<select name='user_id_main'>";
  610. $user = $db->getUserById($home_info['user_id_main']);
  611. echo "<option value='".$home_info['user_id_main']."'>".$user['users_login']."</option>\n";
  612. $users = $db->getUserList();
  613. foreach ( $users as $user ){
  614. // Only users and admins can be assigned homes... not subusers
  615. if(is_null($user['users_parent'])){
  616. if($home_info['user_id_main'] != $user['user_id']){
  617. echo "<option value='".$user['user_id']."'>".$user['users_login']."</option>\n";
  618. }
  619. }
  620. }
  621. echo "</select><br>";
  622. echo "<input type='checkbox' name='deleteoldassigns' id='deleteoldassigns' style='width:auto;' /><label for='deleteoldassigns' >". get_lang("Delete_old_user_assigned_homes") ."</label>";
  623. echo "<input type='submit' name='change_user_id_main' value='". get_lang("change_user_id_main") ."' />";
  624. echo "</form>";
  625. echo "</td></tr><tr><td colspan='2' class='info'>" . get_lang("change_user_id_main_info") ."</td></tr>";
  626. // Form to edit game path.
  627. echo "<tr><td class='right'>". get_lang("home_path") .":</td><td class='left'>".
  628. "<form action='?m=user_games&p=edit&home_id=".$home_id."' method='post'>".
  629. "<input type='hidden' name='home_id' value=\"$home_id\" />\n".
  630. "<input type='text' size='30' name='home_path' value=\"".str_replace('"', "&quot;", $home_info['home_path'])."\" />".
  631. "<input type='submit' name='change_home' value='". get_lang("change_home") ."' id='change_home_path' />".
  632. "</form><button data-path=\"".str_replace('"', "&quot;", $home_info['home_path'])."\" data-home-id='".$home_id."' id='browse'>".
  633. get_lang("browse") ."</button>";
  634. if($servers_with_same_path > 1){
  635. print_failure(get_lang('other_servers_exist_with_path_please_change'), "warning");
  636. }
  637. echo "</td></tr>".
  638. "<tr><td colspan='2' class='info'>". get_lang("change_home_info") ."</td></tr>";
  639. //Jquery path browser dialog
  640. echo "<div id='dialog".
  641. "' data-select_home_path='". get_lang("select_home_path") .
  642. "' data-set_this_path='". get_lang("set_this_path") .
  643. "' data-cancel='". get_lang("cancel") .
  644. "' ></div>";
  645. }
  646. // Form to edit game name
  647. echo "<tr><td class='right'>". get_lang("game_server_name") .":</td><td class='left'>";
  648. echo "<form action='?m=user_games&p=edit&home_id=".$home_id."' method='post'>";
  649. echo "<input type='hidden' name='home_id' value=\"$home_id\" />\n";
  650. echo "<input type='text' size='30' name='server_name' value=\"".str_replace('"', "&quot;", htmlentities($home_info['home_name']))."\" />";
  651. echo "<input type=submit name='change_name' value='". get_lang("change_name") ."' />";
  652. echo "</form></td></tr>";
  653. echo "<tr><td colspan='2' class='info'>". get_lang("change_name_info") ."</td></tr>";
  654. // Form to edit control password
  655. echo "<tr><td class='right'>". get_lang("game_control_password") .":</td><td class='left'>";
  656. echo "<form action='?m=user_games&p=edit&home_id=".$home_id."' method='post'>";
  657. echo "<input type='hidden' name='home_id' value=\"$home_id\" />\n";
  658. echo "<input type='text' size='30' name='control_password' value=\"".str_replace('"', "&quot;", $home_info['control_password'])."\" />";
  659. echo "<input type='submit' name='change_control_password' value='". get_lang("change_control_password") ."' />";
  660. echo "</form></td></tr>";
  661. echo "<tr><td colspan='2' class='info'>". get_lang("change_control_password_info") ."</td></tr>";
  662. if ( $isAdmin && $ftp_installed )
  663. {
  664. // Forms to enable/disable ftp account
  665. echo "<tr>";
  666. echo "<td class='right'>". get_lang("change_ftp_account_status") .":</td>";
  667. echo "<td class='left'>";
  668. if ( !$db->IsFtpEnabled( $home_id ) )
  669. {
  670. echo "<div style='display:block;float:left;' ><form action='?m=user_games&p=edit&home_id=".$home_id."' method='post'>";
  671. echo "<input type='submit' name='create_ftp' value='". get_lang("ftp_on") ."' />";
  672. echo "</form></div>";
  673. }
  674. else
  675. {
  676. echo "<div style='display:block;float:left;' ><form action='?m=user_games&p=edit&home_id=".$home_id."' method='post'>";
  677. echo "<input type='submit' name='delete_ftp' value='". get_lang("ftp_off") ."' />";
  678. echo "</form></div>";
  679. }
  680. echo "</td></tr>";
  681. echo "<tr><td colspan='2' class='info'>". get_lang("change_ftp_account_status_info") ."</td>";
  682. echo "</tr>";
  683. }
  684. if ( preg_match("/t/",$game_home['access_rights']) > 0 && $ftp_installed && $db->IsFtpEnabled($home_id) )
  685. {
  686. // Form to edit control ftp login
  687. $ftp_login = isset($home_info['ftp_login']) ? $home_info['ftp_login'] : $home_id;
  688. echo "<tr><td class='right'>". get_lang("server_ftp_login") .":</td><td class='left'>";
  689. echo "<form action='?m=user_games&p=edit&home_id=".$home_id."' method='post'>";
  690. echo "<input type='text' size='30' name='ftp_login' value=\"".str_replace('"', "&quot;", $ftp_login)."\" />";
  691. echo "<input type='submit' name='change_ftp_login' value='". get_lang("change_ftp_login") ."' />";
  692. echo "</form></td></tr>";
  693. echo "<tr><td colspan='2' class='info'>". get_lang("change_ftp_login_info") ."</td></tr>";
  694. // Form to edit control ftp password
  695. echo "<tr><td class='right'>". get_lang("server_ftp_password") .":</td><td class='left'>";
  696. echo "<form action='?m=user_games&p=edit&home_id=".$home_id."' method='post'>";
  697. echo "<input type='text' size='30' name='ftp_password' value=\"".str_replace('"', "&quot;", $home_info['ftp_password'])."\" />";
  698. echo "<input type='submit' name='change_ftp_password' value='". get_lang("change_ftp_password") ."' />";
  699. echo "</form></td></tr>";
  700. echo "<tr><td colspan='2' class='info'>". get_lang("change_ftp_password_info") ."</td></tr>";
  701. }
  702. if ( $isAdmin )
  703. {
  704. $master_server_home_id = $db->getMasterServer( $home_info['remote_server_id'], $home_info['home_cfg_id'] );
  705. $expiration_date = !empty($home_info['server_expiration_date']) && $home_info['server_expiration_date'] != 'X' ? date( "d/m/Y H:i:s", $home_info['server_expiration_date'] ) : '';
  706. if( $master_server_home_id != FALSE AND $master_server_home_id == $home_id )
  707. $checked = 'checked ="checked"';
  708. else
  709. $checked = "";
  710. // Form to enable/disable as master server for local update
  711. echo "</tr><tr><td class='right'>". get_lang("master_server_for_clon_update") .":</td><td class='left'>";
  712. echo "<form action='?m=user_games&p=edit&home_id=".$home_id."' method='post'>";
  713. echo "<input type='checkbox' name='add' $checked />";
  714. echo "<input type='submit' name='master_server' value='". get_lang("set_as_master_server") ."' />";
  715. echo "</form></td></tr>";
  716. echo "<tr><td colspan='2' class='info'>". get_lang("set_as_master_server_for_local_clon_update") .
  717. " (".get_lang_f( 'only_available_for', $server_xml->game_name, $home_info['remote_server_name']).")</td></tr>";
  718. // Expiration
  719. echo "<tr><td class='right'>".get_lang('server_expiration_date').":</td>\n".
  720. "<td class='left'><form action='?m=user_games&p=edit&home_id=".$home_id."' method='post'>".
  721. "<div id='datetimepicker' class='input-append date'>".
  722. "<input name='expiration_date' placeholder='dd/MM/yyyy hh:mm:ss' type='text' value='".$expiration_date.
  723. "' data-today='".date('d/m/Y H:i:s')."' >\n".
  724. "</div>".
  725. "<input type='submit' name='set_expiration_date' value='". get_lang("set_expiration_date") ."' />".
  726. "</form></td></tr>\n".
  727. "<tr><td colspan='2' class='info'>". get_lang("server_expiration_date_info") ."</td></tr>";
  728. }
  729. echo "</table>";
  730. if ( $isAdmin )
  731. {
  732. $avail_ips = $db->getRemoteServerIPs($home_info['remote_server_id']);
  733. $ip_array = array();
  734. if ( is_array($avail_ips) && !empty($avail_ips) )
  735. {
  736. echo "<h3>". get_lang("ips_and_ports") ."</h3>";
  737. $screen_running = $remote->is_screen_running(OGP_SCREEN_TYPE_HOME,$home_info['home_id']) === 1;
  738. if( ! $screen_running )
  739. {
  740. if( isset($_REQUEST['set_ip']) )
  741. {
  742. $ip_id = $db->real_escape_string($_POST['ip']);
  743. $ip_row = $db->resultQuery( "SELECT ip FROM OGP_DB_PREFIXremote_server_ips WHERE ip_id=".$ip_id );
  744. if($ip_row !== false){
  745. $ip = $ip_row['0']['ip'];
  746. $port = $_POST['port'];
  747. $port = (int)(trim($port));
  748. $home_id = $_POST['home_id'];
  749. if ( !isPortValid($port) )
  750. {
  751. print_failure( get_lang("port_range_error") );
  752. }
  753. else
  754. {
  755. if ( $db->addGameIpPort($home_id, $ip_id, $port) === FALSE )
  756. {
  757. print_failure(get_lang_f('ip_port_already_in_use', $ip, $port));
  758. }
  759. else {
  760. print_success(get_lang_f('successfully_assigned_ip_port_to_server_id', $ip, $port, $home_id));
  761. $db->logger(get_lang_f('successfully_assigned_ip_port_to_server_id', $ip, $port, $home_id));
  762. }
  763. }
  764. }
  765. }
  766. if (isset($_REQUEST["delete_ip"]))
  767. {
  768. $del_ip = $_GET['ip'];
  769. $del_port = $_GET['port'];
  770. if ( $db->delGameIpPort($home_id,$del_ip,$del_port) )
  771. {
  772. print_success( get_lang("successfully_assigned_ip_port") );
  773. $db->logger( get_lang("successfully_assigned_ip_port") ." [unassigned]");
  774. }
  775. else
  776. print_failure("Failed to unassign ip:port.");
  777. }
  778. echo "<form action='?m=user_games&p=edit&home_id=".$home_id."' method='post'>\n";
  779. echo "<input type='hidden' name='home_id' value=\"$home_id\" />\n";
  780. echo get_lang("ip") .":<select name='ip' onchange='this.form.submit();'>";
  781. foreach($avail_ips as $value)
  782. {
  783. $selected = ( isset($_POST['ip']) and $_POST['ip'] == $value['ip_id'] ) ? "selected='selected'" : "";
  784. echo "<option value='".$value['ip_id']."' $selected >".$value['ip']."</option>\n";
  785. }
  786. echo "</select>";
  787. $ip_id = isset($_POST['ip']) ? $_POST['ip'] : $avail_ips[0]['ip_id'];
  788. $port = $db->getNextAvailablePort($ip_id,$home_info['home_cfg_id']);
  789. echo " ". get_lang("port") .":<input type='text' name='port' value='".$port."' size='6' />";
  790. echo "<input type='submit' name='set_ip' value='". get_lang("set_ip") ."' />";
  791. echo "</form>";
  792. $assigned = $db->getHomeIpPorts($home_id);
  793. if( empty($assigned) )
  794. {
  795. print_failure( get_lang("no_ip_ports_assigned") );
  796. }
  797. else
  798. {
  799. foreach ( $assigned as $assigned_rows )
  800. {
  801. $force_mod = "";
  802. $align = "center";
  803. if( !empty($enabled_mods) and count($enabled_mods) > 1 )
  804. {
  805. $force_mod .= "<td align='left'>\n".
  806. "<form action='?m=user_games&p=edit&home_id=".$home_id."' method='post'>\n".
  807. "<input type='hidden' name='ip_id' value=".$assigned_rows['ip_id']." />".
  808. "<input type='hidden' name='port' value=".$assigned_rows['port']." />".
  809. "<select name='force_mod_id' onchange='this.form.submit();'>".
  810. "<option value='0' >". get_lang("force_mod_on_this_address") ."</option>";
  811. foreach($enabled_mods as $mod)
  812. {
  813. $selected = $mod['mod_id'] == $assigned_rows['force_mod_id'] ? "selected='selected'" : "";
  814. $force_mod .= "<option value='".$mod['mod_id']."' $selected>".$mod['mod_name']."</option>";
  815. }
  816. $force_mod .= "</select>\n</form>\n</td>\n";
  817. $align = "right";
  818. }
  819. echo "<table class='center'><tr><td align='$align'>".$assigned_rows['ip'].":".$assigned_rows['port'].
  820. " <a href='?m=user_games&p=edit&home_id=$home_id&delete_ip&ip=".
  821. $assigned_rows['ip_id']."&port=".$assigned_rows['port'].
  822. "'>[ ". get_lang("delete") ." ]</a></td>\n".
  823. $force_mod.
  824. "</tr>\n</table>\n";
  825. }
  826. }
  827. }
  828. else
  829. {
  830. print_failure( get_lang("server_is_running_change_addresses_not_available") );
  831. }
  832. }
  833. else
  834. {
  835. print_failure( get_lang("no_ip_addresses_configured") ."<a href='?m=server'>". get_lang("server_page") ."</a>." );
  836. }
  837. echo "<div id='mods'></div>";
  838. }
  839. else
  840. {
  841. $assigned = $db->getHomeIpPorts($home_id);
  842. if( !empty($assigned) and !empty($enabled_mods) and count($enabled_mods) > 1 )
  843. {
  844. echo "<table class='center'>\n".
  845. "<tr>\n".
  846. "<td colspan='2' align='center'>".
  847. "<h3>". get_lang("switch_mods") ."</h3>".
  848. "</td>\n".
  849. "</tr>\n";
  850. $force_mod = "";
  851. foreach ( $assigned as $assigned_rows )
  852. {
  853. $force_mod .= "<tr>\n<td align='right' style='width:50%' >".get_lang_f('switch_mod_for_address',$assigned_rows['ip'].":".$assigned_rows['port']).
  854. "</td>\n<td align='left' style='width:50%' >\n".
  855. "<form action='?m=user_games&p=edit&home_id=".$home_id."' method='post'>\n".
  856. "<input type='hidden' name='ip_id' value=".$assigned_rows['ip_id']." />".
  857. "<input type='hidden' name='port' value=".$assigned_rows['port']." />".
  858. "<select name='force_mod_id' onchange='this.form.submit();'>".
  859. "<option value='0' >". get_lang("force_mod_on_this_address") ."</option>";
  860. foreach($enabled_mods as $mod)
  861. {
  862. $selected = $mod['mod_id'] == $assigned_rows['force_mod_id'] ? "selected='selected'" : "";
  863. $force_mod .= "<option value='".$mod['mod_id']."' $selected>".$mod['mod_name']."</option>";
  864. }
  865. $force_mod .= "</select>\n</form>\n</td>\n</tr>\n";
  866. }
  867. echo $force_mod."</table>\n";
  868. }
  869. }
  870. }
  871. ?>