edit_home.php 33 KB

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