edit_home.php 33 KB

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