edit_home.php 34 KB

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