ogp_api.php 57 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770
  1. <?php
  2. /*
  3. ______________ Token Management
  4. ogp_api.php?token/create/{panel_user}/{panel_password}
  5. ogp_api.php?token/test/{token}
  6. ______________ Remote Servers
  7. ogp_api.php?server/list (POST/GET {token})
  8. ogp_api.php?server/status (POST/GET {token}{remote_server_id})
  9. ogp_api.php?server/restart (POST/GET {token}{remote_server_id})
  10. ogp_api.php?server/create (POST/GET {token}{agent_name}{agent_ip}{agent_port}{agent_user}{encryption_key}{ftp_ip}{ftp_port}{timeout}{use_nat}{display_public_ip})
  11. ogp_api.php?server/remove (POST/GET {token}{remote_server_id})
  12. ogp_api.php?server/add_ip (POST/GET {token}{remote_server_id}{ip})
  13. ogp_api.php?server/remove_ip (POST/GET {token}{remote_server_id}{ip})
  14. ogp_api.php?server/list_ips (POST/GET {token}{remote_server_id})
  15. ogp_api.php?server/edit_ip (POST/GET {token}{remote_server_id}{old_ip}{new_ip})
  16. ______________ Game Servers
  17. ogp_api.php?user_games/list_games (POST/GET {token}{system(windows|linux)}{architecture(32|64)})
  18. ogp_api.php?user_games/list_servers (POST/GET {token})
  19. ogp_api.php?user_games/create (POST/GET {token}{remote_server_id}{server_name}{home_cfg_id}{mod_cfg_id}{ip}{port}{control_password}{enable_ftp}{ftp_password}{slots}{affinity}{nice}{assign_to_username}{custom_user_login_homepath}) // {custom_user_login_homepath} is only used when a default_game_server_home_path_prefix setting is defined and used
  20. ogp_api.php?user_games/clone (POST/GET {token}{origin_home_id}{new_server_name}{new_ip}{new_port}{control_password}{enable_ftp}{ftp_password}{slots}{affinity}{nice}{assign_to_username}{custom_user_login_homepath}) // {custom_user_login_homepath} is only used when a default_game_server_home_path_prefix setting is defined and used
  21. ogp_api.php?user_games/set_expiration (POST/GET {token}{home_id}{timestamp})
  22. ______________ Users
  23. ogp_api.php?user_admin/list (POST/GET {token})
  24. ogp_api.php?user_admin/get (POST/GET {token}{email})
  25. ogp_api.php?user_admin/create (POST/GET {token}{email}{name}{password})
  26. ogp_api.php?user_admin/remove (POST/GET {token}{email})
  27. ogp_api.php?user_admin/set_expiration (POST/GET {token}{email}{timestamp})
  28. ogp_api.php?user_admin/list_assigned (POST/GET {token}{email})
  29. ogp_api.php?user_admin/assign (POST/GET {token}{email}{home_id}{timestamp})
  30. ogp_api.php?user_admin/remove_assign (POST/GET {token}{email}{home_id})
  31. ______________ Game Manager
  32. ogp_api.php?gamemanager/start (POST/GET {token}{ip}{port}{mod_key})
  33. ogp_api.php?gamemanager/stop (POST/GET {token}{ip}{port}{mod_key})
  34. ogp_api.php?gamemanager/restart (POST/GET {token}{ip}{port}{mod_key})
  35. ogp_api.php?gamemanager/rcon (POST/GET {token}{ip}{port}{mod_key}{command})
  36. ogp_api.php?gamemanager/update (POST/GET {token}{ip}{port}{mod_key}{type}{manual_url})
  37. ______________ Lite File Manager
  38. ogp_api.php?litefm/list (POST/GET {token}{ip}{port}{relative_path})
  39. ogp_api.php?litefm/get (POST/GET {token}{ip}{port}{relative_path})
  40. ogp_api.php?litefm/save (POST/GET {token}{ip}{port}{relative_path}{contents})
  41. ogp_api.php?litefm/remove (POST/GET {token}{ip}{port}{relative_path})
  42. ______________ Addons Manager
  43. ogp_api.php?addonsmanager/list (POST/GET {token})
  44. ogp_api.php?addonsmanager/install (POST/GET {token}{ip}{port}{mod_key}{addon_id})
  45. ______________ Steam Workshop
  46. ogp_api.php?steam_workshop/install (POST/GET {token}{ip}{port}{mods_list})
  47. */
  48. $main_request = key($_GET);
  49. $request = explode('/', $main_request);
  50. unset($_GET["$main_request"]);
  51. if(!empty($_GET))
  52. $_POST = array_merge($_POST,$_GET);
  53. // Allow json requests to the API as well
  54. $jsonData = file_get_contents('php://input');
  55. if(!empty($jsonData)){
  56. $jsonArr = json_decode($jsonData, true);
  57. }
  58. if(isset($jsonArr) && is_array($jsonArr) && !empty($jsonArr)){
  59. $_POST = array_merge($_POST, $jsonArr);
  60. }
  61. //Retirieve the function name
  62. $function = 'api_'.$request[0];
  63. //Remove the main function from the request
  64. array_splice($request, 0, 1);
  65. if(function_exists($function))
  66. {
  67. // Report only critical PHP errors
  68. error_reporting(E_ERROR);
  69. // Path definitions
  70. define("INCLUDES", "includes/");
  71. define("MODULES", "modules/");
  72. // require needed functions
  73. require_once INCLUDES.'functions.php';
  74. require_once INCLUDES.'helpers.php';
  75. require_once INCLUDES.'html_functions.php';
  76. require_once INCLUDES.'lib_remote.php';
  77. require_once INCLUDES.'config.inc.php';
  78. require_once MODULES.'config_games/server_config_parser.php';
  79. require_once INCLUDES.'api_functions.php';
  80. // API tokens table
  81. define("API_TABLE", $table_prefix."api_tokens");
  82. // Connect to the database server and select database.
  83. $db = createDatabaseConnection($db_type, $db_host, $db_user, $db_pass, $db_name, $table_prefix);
  84. $settings = $db->getSettings();
  85. if(!is_authorized())
  86. outputJSON(array("status" => '401', "message" => 'Unauthorized host'));
  87. $db->checkApiTable();
  88. $logged_in = false;
  89. if($function != 'api_token')
  90. {
  91. if(isset($_POST['token']))
  92. {
  93. $token = $_POST['token'];
  94. $query = "SELECT user_id FROM ".API_TABLE." WHERE `token` = '".$db->real_escape_string($token)."';";
  95. $result = $db->resultQuery($query);
  96. if(isset($result[0]['user_id']))
  97. {
  98. $user_info = $db->getUserById($result[0]['user_id']);
  99. if(isset($user_info['users_login']))
  100. $logged_in = true;
  101. }
  102. }
  103. else
  104. {
  105. outputJSON(array("status" => "300", "message" => "No token supplied"));
  106. }
  107. }
  108. if($logged_in or $function == 'api_token')
  109. {
  110. //call the function and output the returned data as json
  111. $func_req = str_replace('api_','',$function)."/".$request[0];
  112. if($main_request == "all")
  113. outputJSON(array("status" => "400", "message" => "BAD REQUEST"));
  114. else
  115. $function_args = get_function_args("$func_req");
  116. if(!$function_args)
  117. outputJSON(array("status" => "400", "message" => "BAD REQUEST"));
  118. elseif(!(($func_req == "token/test" and isset($request[1])) OR ($func_req == "token/create" and isset($request[1]) and isset($request[2]))))
  119. {
  120. foreach($function_args as $arg => $mandatory)
  121. {
  122. if($mandatory and !isset($_POST["$arg"]))
  123. {
  124. outputJSON(array("status" => "400", "message" => "BAD REQUEST", "fields_supplied" => $_POST, "fields_required" => $function_args));
  125. break;
  126. }
  127. }
  128. }
  129. outputJSON($function());
  130. }
  131. else
  132. {
  133. outputJSON(array("status" => "301", "message" => "Invalid Token"));
  134. }
  135. }
  136. else
  137. {
  138. outputJSON(array("status" => "400", "message" => "BAD REQUEST"));
  139. }
  140. function outputJSON($result){
  141. // Send JSON output
  142. header('Content-Type: application/json');
  143. echo json_encode($result);
  144. exit();
  145. }
  146. function isValidTimeStamp($timestamp)//https://stackoverflow.com/questions/2524680/check-whether-the-string-is-a-unix-timestamp
  147. {
  148. if(is_numeric($timestamp) and strtotime(date('d-m-Y H:i:s',$timestamp)) === (int)$timestamp)
  149. return true;
  150. return false;
  151. }
  152. function api_token()
  153. {
  154. global $request, $db;
  155. if($request[0] == "test")
  156. {
  157. $token = isset($request[1])?$request[1]:$_POST['token'];
  158. $query = "SELECT user_id FROM ".API_TABLE." WHERE `token` = '".$db->real_escape_string($token)."';";
  159. $result = $db->resultQuery($query);
  160. if(isset($result[0]['user_id']))
  161. {
  162. $user_info = $db->getUserById($result[0]['user_id']);
  163. if(isset($user_info['users_login']))
  164. {
  165. $status = "200";
  166. $message = $user_info['users_role'];
  167. }
  168. else
  169. {
  170. $status = "400";
  171. $message = "Invalid Token";
  172. }
  173. }
  174. else
  175. {
  176. $status = "400";
  177. $message = "Invalid Token";
  178. }
  179. }
  180. if($request[0] == "create")
  181. {
  182. $user = isset($request[1])?urldecode($request[1]):$_POST['user'];
  183. $password = isset($request[2])?urldecode($request[2]):$_POST['password'];
  184. $userInfo = $db->getUser($user);
  185. if(isset($userInfo['users_passwd']) && md5($password) == $userInfo['users_passwd'])
  186. {
  187. $token = bin2hex(openssl_random_pseudo_bytes(32));
  188. $old_token = $db->currentApiToken($userInfo['user_id']);
  189. // Update cronjob passwords in the URLs
  190. if($old_token and file_exists('modules/cron/shared_cron_functions.php')){
  191. require_once('modules/cron/shared_cron_functions.php');
  192. updateCronJobTokens($old_token, $token);
  193. }
  194. $query ="INSERT INTO ".API_TABLE.
  195. " (user_id, token)".
  196. " VALUES".
  197. " ('".$userInfo['user_id']."', '".$db->realEscapeSingle($token)."')".
  198. " ON DUPLICATE KEY UPDATE".
  199. " user_id = VALUES(user_id),".
  200. " token = VALUES(token);";
  201. if($db->query($query))
  202. {
  203. $status = "200";
  204. $message = $token;
  205. }
  206. else
  207. {
  208. $status = "500";
  209. $message = "database failure";
  210. }
  211. }
  212. else
  213. {
  214. $status = "400";
  215. $message = "Invalid login information";
  216. }
  217. }
  218. return array("status" => $status, "message" => $message);
  219. }
  220. function api_server()
  221. {
  222. global $request, $db, $user_info, $settings;
  223. if($user_info['users_role'] != "admin")
  224. return array("status" => '350', "message" => "This function is restricted to administrator accounts.");
  225. if($request[0] == "list")
  226. {
  227. $status = "200";
  228. $message = $db->getRemoteServers();
  229. }
  230. if($request[0] == "status")
  231. {
  232. $remote_server_id = $_POST['remote_server_id'];
  233. $remote_server = $db->getRemoteServer($remote_server_id);
  234. $remote = new OGPRemoteLibrary($remote_server['agent_ip'],$remote_server['agent_port'],$remote_server['encryption_key'],$remote_server['timeout']);
  235. $status = "200";
  236. $message = $remote->status_chk() == 1?'online':'offline';
  237. }
  238. if($request[0] == "restart")
  239. {
  240. $remote_server_id = $_POST['remote_server_id'];
  241. $remote_server = $db->getRemoteServer($remote_server_id);
  242. $remote = new OGPRemoteLibrary($remote_server['agent_ip'],$remote_server['agent_port'],$remote_server['encryption_key'],$remote_server['timeout']);
  243. $remote->agent_restart();
  244. $status = "200";
  245. $message = "success";
  246. }
  247. if($request[0] == "create")
  248. {
  249. $agent_name = $_POST['agent_name'];
  250. $agent_ip = $_POST['agent_ip'];
  251. $agent_port = $_POST['agent_port'];
  252. $agent_user = $_POST['agent_user'];
  253. $encryption_key = $_POST['encryption_key'];
  254. $ftp_ip = $_POST['ftp_ip'];
  255. $ftp_port = $_POST['ftp_port'];
  256. $timeout = $_POST['timeout'];
  257. $use_nat = $_POST['use_nat'];
  258. $display_public_ip = $_POST['display_public_ip'];
  259. $remote_server_id = $db->addRemoteServer($agent_ip,$agent_name,$agent_user,$agent_port,$ftp_ip,$ftp_port,$encryption_key,$timeout,$use_nat,$display_public_ip);
  260. $status = "200";
  261. $message = $remote_server_id;
  262. }
  263. if($request[0] == "remove")
  264. {
  265. $remote_server_id = $_POST['remote_server_id'];
  266. $status = "200";
  267. $message = $db->removeRemoteServer($remote_server_id);
  268. }
  269. if($request[0] == "add_ip")
  270. {
  271. $remote_server_id = $_POST['remote_server_id'];
  272. $ip = $_POST['ip'];
  273. $status = "200";
  274. $message = $db->addRemoteServerIP($remote_server_id, $ip);
  275. }
  276. if($request[0] == "remove_ip")
  277. {
  278. $remote_server_id = $_POST['remote_server_id'];
  279. $ip = $_POST['ip'];
  280. $ip_infos = $db->getRemoteServerIPs($remote_server_id);
  281. foreach($ip_infos as $ip_info)
  282. {
  283. if($ip_info['ip'] == $ip)
  284. {
  285. $message = $db->removeRemoteServerIPs($ip_info['ip_id']);
  286. break;
  287. }
  288. }
  289. $status = "200";
  290. }
  291. if($request[0] == "list_ips")
  292. {
  293. $remote_server_id = $_POST['remote_server_id'];
  294. $message = $db->getRemoteServerIPs($remote_server_id);
  295. $status = "200";
  296. }
  297. if($request[0] == "edit_ip")
  298. {
  299. $remote_server_id = $_POST['remote_server_id'];
  300. $old_ip = $_POST['old_ip'];
  301. $new_ip = $_POST['new_ip'];
  302. $ip_infos = $db->getRemoteServerIPs($remote_server_id);
  303. foreach($ip_infos as $ip_info)
  304. {
  305. if($ip_info['ip'] == $old_ip)
  306. {
  307. $message = $db->editRemoteServerIPs($ip_info['ip_id'], $new_ip);
  308. break;
  309. }
  310. }
  311. $status = "200";
  312. }
  313. return array("status" => $status, "message" => $message);
  314. }
  315. function api_user_games()
  316. {
  317. global $request, $db, $user_info, $settings;
  318. if($user_info['users_role'] != "admin")
  319. return array("status" => '350', "message" => "This function is restricted to administrator accounts.");
  320. if($request[0] == "list_games")
  321. {
  322. $system = strtolower($_POST['system']);
  323. if(!preg_match('/^(linux|windows)$/', $system))
  324. {
  325. $status = "302";
  326. $message = "list games: Incorrect system, valid options: windows, linux";
  327. return array("status" => $status, "message" => $message);
  328. }
  329. $architecture = strtolower($_POST['architecture']);
  330. if(!preg_match('/^(32|64)$/', $architecture))
  331. {
  332. $status = "303";
  333. $message = "list games: Incorrect architecture, valid options: 32, 64";
  334. return array("status" => $status, "message" => $message);
  335. }
  336. $games = $db->getGameCfgs();
  337. foreach($games as $key => $game)
  338. {
  339. $games[$key]['mods'] = $db->getCfgMods($game['home_cfg_id']);
  340. preg_match("/^([a-z0-9_-]+)_(linux|win)(32|64)?$/i",$game['game_key'],$matches);
  341. if(count($matches) == 4)
  342. list($game_key, $game_clean, $os, $arch) = $matches;
  343. else
  344. {
  345. list($game_key, $game_clean, $os) = $matches;
  346. $arch = "32";
  347. }
  348. if(strtolower($os) == 'linux')
  349. $sorted_games['linux'][$arch][] = $games[$key];
  350. elseif(strtolower($os) == 'win')
  351. $sorted_games['windows'][$arch][] = $games[$key];
  352. }
  353. $status = "200";
  354. $message = $sorted_games[$system][$architecture];
  355. }
  356. if($request[0] == "list_servers")
  357. {
  358. $status = "200";
  359. $message = $db->getGameHomes();
  360. }
  361. if($request[0] == "create")
  362. {
  363. $remote_server_id = $_POST['remote_server_id'];
  364. $server_name = $_POST['server_name'];
  365. $home_cfg_id = $_POST['home_cfg_id'];
  366. $mod_cfg_id = $_POST['mod_cfg_id'];
  367. $ip = $_POST['ip'];
  368. $port = $_POST['port'];
  369. $control_password = $_POST['control_password'];
  370. $enable_ftp = $_POST['enable_ftp'];
  371. $ftp_password = $_POST['ftp_password'];
  372. $slots = $_POST['slots'];
  373. $affinity = $_POST['affinity'];
  374. $nice = $_POST['nice'];
  375. $homeForUser = $user_info['users_login'];
  376. if(array_key_exists('custom_user_login_homepath', $_POST) && !empty($_POST['custom_user_login_homepath'])){
  377. $homeForUser = $_POST['custom_user_login_homepath'];
  378. }
  379. $assignGameServerToUserId = $user_info['user_id'];
  380. if(array_key_exists('assign_to_username', $_POST) && !empty($_POST['assign_to_username'])){
  381. $assignToAccountUser = $_POST['assign_to_username'];
  382. $userInfo = $db->getUser($assignToAccountUser);
  383. if($userInfo){
  384. $assignGameServerToUserId = $userInfo['user_id'];
  385. }
  386. }
  387. $remote_server = $db->getRemoteServer($remote_server_id);
  388. if($remote_server === FALSE)
  389. return array("status" => '304', "message" => "Remote Server ID#$remote_server_id does not exists");
  390. $game_cfg = $db->getGameCfg($home_cfg_id);
  391. if($game_cfg === FALSE)
  392. return array("status" => '305', "message" => "No game configuration found for home_cfg_id #" . $home_cfg_id . ".");
  393. $cfg_mods = $db->getCfgMods($home_cfg_id);
  394. $mod_key = FALSE;
  395. if($cfg_mods === FALSE)
  396. return array("status" => '306', "message" => "No game mods found for home_cfg_id #" . $home_cfg_id . ".");
  397. else
  398. {
  399. foreach($cfg_mods as $cfg_mod)
  400. {
  401. if($cfg_mod['mod_cfg_id'] == $mod_cfg_id)
  402. {
  403. $mod_key = $cfg_mod['mod_key'];
  404. break;
  405. }
  406. }
  407. }
  408. if($mod_key === FALSE)
  409. return array("status" => '307', "message" => "The mod_cfg_id #" . $mod_cfg_id . " does not belong to the game configuration for home_cfg_id #" . $home_cfg_id . ".");
  410. $ip_info = $db->resultQuery( "SELECT ip,ip_id FROM OGP_DB_PREFIXremote_server_ips WHERE ip='".$db->real_escape_string($ip)."' AND remote_server_id=".$db->real_escape_string($remote_server_id));
  411. if($ip_info === FALSE)
  412. return array("status" => '308', "message" => "The given IP address does not belongs to the given remote server.");
  413. $port = (int)(trim($port));
  414. if(!isPortValid($port))
  415. return array("status" => '309', "message" => "The given port is not a valid port.");
  416. $remote = new OGPRemoteLibrary($remote_server['agent_ip'],$remote_server['agent_port'],$remote_server['encryption_key'],$remote_server['timeout']);
  417. $host_stat = $remote->status_chk();
  418. if($host_stat !== 1)
  419. return array("status" => '310', "message" => "The remote server is offline.");
  420. // Game path logic
  421. $skipId = false;
  422. if(hasValue($settings["default_game_server_home_path_prefix"]))
  423. {
  424. // Replace some user supported variables with actual value.
  425. $game_path = str_replace("{USERNAME}", $homeForUser, $settings["default_game_server_home_path_prefix"]);
  426. if(stripos($game_path, "{SKIPID}") !== false){
  427. $game_path = str_replace("{SKIPID}", "", $game_path);
  428. $skipId = true;
  429. }
  430. $game_path = str_replace("{GAMEKEY}", strtolower(substr($game_cfg['game_key'], 0, stripos($game_cfg['game_key'], "_"))), $game_path);
  431. // Make sure the path ends with forward slash
  432. if($game_path[strlen($game_path)-1] != "/"){
  433. $game_path .= "/";
  434. }
  435. }
  436. else
  437. $game_path = "/home/".$remote_server['ogp_user']."/OGP_User_Files/"; // Default
  438. $game_path = clean_path($game_path); // Clean it
  439. $home_id = $db->addGameHome($remote_server_id, $assignGameServerToUserId, $home_cfg_id, $game_path, $server_name, $control_password, $ftp_password, $skipId);
  440. if($home_id === FALSE)
  441. return array("status" => '311', "message" => "Server could not be added to the database.");
  442. if($db->addGameIpPort($home_id, $ip_info[0]['ip_id'], $port) === FALSE)
  443. {
  444. $db->deleteGameHome($home_id);
  445. return array("status" => '312', "message" => "The given IP:Port is already in use.");
  446. }
  447. if($db->addModToGameHome($home_id, $mod_cfg_id) === FALSE )
  448. {
  449. $db->deleteGameHome($home_id);
  450. return array("status" => '313', "message" => "Failed to assing mod.");
  451. }
  452. if($db->updateGameModParams($slots, '', $affinity, $nice, $home_id, $mod_cfg_id) === FALSE)
  453. {
  454. $db->deleteGameHome($home_id);
  455. return array("status" => '314', "message" => "Maxplayers, affinity or nice could not be configured.");
  456. }
  457. // Create new home directory if it doesn't already exist
  458. $game_path = $game_path . (!$skipId ? $home_id : "");
  459. $remote->exec("mkdir -p " . $game_path);
  460. if($enable_ftp == "1")
  461. {
  462. $remote->ftp_mgr("useradd", $home_id, $ftp_password, $game_path);
  463. $db->changeFtpStatus('enabled',$home_id);
  464. }
  465. $status = "200";
  466. $message = $home_id;
  467. }
  468. if($request[0] == "clone")
  469. {
  470. $home_id = $_POST['origin_home_id'];
  471. $server_name = $_POST['new_server_name'];
  472. $ip = $_POST['new_ip'];
  473. $port = $_POST['new_port'];
  474. $control_password = $_POST['control_password'];
  475. $enable_ftp = $_POST['enable_ftp'];
  476. $ftp_password = $_POST['ftp_password'];
  477. $slots = $_POST['slots'];
  478. $affinity = $_POST['affinity'];
  479. $nice = $_POST['nice'];
  480. $homeForUser = $user_info['users_login'];
  481. if(array_key_exists('custom_user_login_homepath', $_POST) && !empty($_POST['custom_user_login_homepath'])){
  482. $homeForUser = $_POST['custom_user_login_homepath'];
  483. }
  484. $game_home = $db->getGameHome($home_id);
  485. if($game_home === FALSE)
  486. return array("status" => '315', "message" => "There is no game home with home_id #" . $home_id . ".");
  487. $assignGameServerToUserId = $game_home['user_id_main'];
  488. if(array_key_exists('assign_to_username', $_POST) && !empty($_POST['assign_to_username'])){
  489. $assignToAccountUser = $_POST['assign_to_username'];
  490. $userInfo = $db->getUser($assignToAccountUser);
  491. if($userInfo){
  492. $assignGameServerToUserId = $userInfo['user_id'];
  493. }
  494. }
  495. $remote = new OGPRemoteLibrary($game_home['agent_ip'],$game_home['agent_port'],$game_home['encryption_key'],$game_home['timeout']);
  496. $host_stat = $remote->status_chk();
  497. if($host_stat !== 1)
  498. return array("status" => '310', "message" => "The remote server is offline.");
  499. $ip_info = $db->resultQuery("SELECT ip,ip_id FROM OGP_DB_PREFIXremote_server_ips WHERE ip='".$db->real_escape_string($ip)."' AND remote_server_id=".$db->real_escape_string($game_home['remote_server_id']));
  500. if($ip_info === FALSE)
  501. return array("status" => '308', "message" => "The given IP address does not belongs to the given remote server.");
  502. $port = (int)(trim($port));
  503. if(!isPortValid($port))
  504. return array("status" => '309', "message" => "The given port is not a valid port.");
  505. // Game path logic
  506. $skipId = false;
  507. if(hasValue($settings["default_game_server_home_path_prefix"]))
  508. {
  509. // Replace some user supported variables with actual value.
  510. $game_path = str_replace("{USERNAME}", $homeForUser, $settings["default_game_server_home_path_prefix"]);
  511. if(stripos($game_path, "{SKIPID}") !== false){
  512. $game_path = str_replace("{SKIPID}", "", $game_path);
  513. $skipId = true;
  514. }
  515. $game_path = str_replace("{GAMEKEY}", strtolower(substr($game_home['game_key'], 0, stripos($game_home['game_key'], "_"))), $game_path);
  516. // Make sure the path ends with forward slash
  517. if($game_path[strlen($game_path)-1] != "/"){
  518. $game_path .= "/";
  519. }
  520. }
  521. else
  522. $game_path = "/home/".$game_home['ogp_user']."/OGP_User_Files/"; // Default
  523. $game_path = clean_path($game_path); // Clean it
  524. $clone_home_id = $db->addGameHome($game_home['remote_server_id'], $assignGameServerToUserId,
  525. $game_home['home_cfg_id'], $game_path, $server_name, $control_password, $ftp_password, $skipId);
  526. if ($clone_home_id === FALSE)
  527. return array("status" => '311', "message" => "Server could not be added to the database.");
  528. if($db->addGameIpPort($clone_home_id, $ip_info[0]['ip_id'], $port) === FALSE)
  529. {
  530. $db->deleteGameHome($clone_home_id);
  531. return array("status" => '312', "message" => "The given IP:Port is already in use.");
  532. }
  533. foreach ($game_home['mods'] as $mod_info)
  534. if($db->addModToGameHome($clone_home_id, $mod_info['mod_cfg_id']) !== FALSE)
  535. $db->updateGameModParams($slots, $mod_info['extra_params'], $affinity, $nice, $clone_home_id, $mod_info['mod_cfg_id']);
  536. // Create new home directory if it doesn't already exist
  537. $game_path = $game_path . (!$skipId ? $clone_home_id : "");
  538. $remote->exec("mkdir -p " . $game_path);
  539. if($enable_ftp == "1")
  540. {
  541. $remote->ftp_mgr("useradd", $clone_home_id, $ftp_password, $game_path);
  542. $db->changeFtpStatus('enabled', $clone_home_id);
  543. }
  544. $user_group = get_user_uid_gid_from_passwd(explode("\n", $remote->sudo_exec('cat /etc/passwd')), $game_home['ogp_user']);
  545. $status = "200";
  546. $message = array("clone_home_id" => $clone_home_id, "cloning_status" => $remote->clone_home($game_home['home_path'], $game_path, $user_group));
  547. }
  548. if($request[0] == "set_expiration")
  549. {
  550. $home_id = $_POST['home_id'];
  551. $date = date('d/m/Y H:i:s', $_POST['timestamp']);
  552. if($db->updateExpirationDate($home_id, $date, 'server') === TRUE)
  553. {
  554. $status = "200";
  555. $message = "Expiration date changed";
  556. }
  557. else
  558. {
  559. $status = "316";
  560. $message = "Expiration date could not be changed";
  561. }
  562. }
  563. return array("status" => $status, "message" => $message);
  564. }
  565. function api_user_admin()
  566. {
  567. global $request, $db, $user_info, $settings;
  568. if($user_info['users_role'] != "admin")
  569. return array("status" => '350', "message" => "This function is restricted to administrator accounts.");
  570. if($request[0] == "list")
  571. {
  572. $status = "200";
  573. $message = $db->getUserList();
  574. }
  575. if($request[0] == "get")
  576. {
  577. $email = $_POST['email'];
  578. $account = $db->getUserByEmail($email);
  579. if($account === FALSE)
  580. {
  581. $status = "317";
  582. $message = "There is no account with the given email address.";
  583. }
  584. else
  585. {
  586. $status = "200";
  587. $message = $account;
  588. }
  589. }
  590. if($request[0] == "create")
  591. {
  592. $name = $_POST['name'];
  593. $email = $_POST['email'];
  594. $password = $_POST['password'];
  595. if($db->addUser($name,$password,'user',$email) === FALSE)
  596. {
  597. $status = "318";
  598. $message = "Failed to create account, name or email already in use.";
  599. }
  600. else
  601. {
  602. $status = "200";
  603. $message = "Account created";
  604. }
  605. }
  606. if($request[0] == "remove")
  607. {
  608. $email = $_POST['email'];
  609. $account = $db->getUserByEmail($email);
  610. if($account === FALSE)
  611. {
  612. $status = "319";
  613. $message = "Failed to remove account, there is no account with the given email address ($email).";
  614. }
  615. else
  616. {
  617. $db->delUser($account['user_id']);
  618. $status = "200";
  619. $message = "Account removed successfully";
  620. }
  621. }
  622. if($request[0] == "set_expiration")
  623. {
  624. $email = $_POST['email'];
  625. $account = $db->getUserByEmail($email);
  626. if($account === FALSE)
  627. {
  628. $status = "319";
  629. $message = "There is no account with the given email address ($email).";
  630. }
  631. else
  632. {
  633. $date = (strtoupper($_POST['timestamp']) == 'X' or $_POST['timestamp'] == '') ? 'X': $date;
  634. if($date != 'X' and !isValidTimeStamp($_POST['timestamp']))
  635. {
  636. $status = "321";
  637. $message = "The given timestamp is not valid";
  638. }
  639. else
  640. {
  641. if($date != 'X')
  642. $date = $_POST['timestamp'];
  643. $account['user_expires'] = $date;
  644. if ($db->editUser($account, $account['user_id']) == FALSE)
  645. {
  646. $status = "316";
  647. $message = "Expiration date could not be changed";
  648. }
  649. else
  650. {
  651. $status = "200";
  652. $message = "Expiration date changed";
  653. }
  654. }
  655. }
  656. }
  657. if($request[0] == "list_assigned")
  658. {
  659. $email = $_POST['email'];
  660. $account = $db->getUserByEmail($email);
  661. if($account === FALSE)
  662. {
  663. $status = "319";
  664. $message = "There is no account with the given email address ($email).";
  665. }
  666. else
  667. {
  668. $game_homes = $db->getHomesFor('user',$account['user_id']);
  669. if(empty($game_homes))
  670. {
  671. $status = "323";
  672. $message = "There are no game homes assigned for the given user.";
  673. }
  674. else
  675. {
  676. $status = "200";
  677. $message = $game_homes;
  678. }
  679. }
  680. }
  681. if($request[0] == "assign")
  682. {
  683. $email = $_POST['email'];
  684. $home_id = $_POST['home_id'];
  685. $access_rights = strtolower($_POST['access_rights']);
  686. $game_home = $db->getGameHome($home_id);
  687. if($game_home === FALSE)
  688. return array("status" => '315', "message" => "There is no game home with home_id #" . $home_id . ".");
  689. if(!preg_match("/^u?f?p?e?t?c?$/", $access_rights))
  690. return array("status" => "324", "message" => "Ivalid string for access rights");
  691. $account = $db->getUserByEmail($email);
  692. if($account === FALSE)
  693. {
  694. $status = "319";
  695. $message = "There is no account with the given email address ($email).";
  696. }
  697. else
  698. {
  699. $date = (strtoupper($_POST['timestamp']) == 'X' or $_POST['timestamp'] == '') ? 'X': $date;
  700. if($date != 'X' and !isValidTimeStamp($_POST['timestamp']))
  701. {
  702. $status = "321";
  703. $message = "The given timestamp is not valid";
  704. }
  705. else
  706. {
  707. if($date != 'X')
  708. $date = date('d/m/Y H:i:s', $_POST['timestamp']);
  709. if ( $db->assignHomeTo('user', $account['user_id'], $home_id, $access_rights) === TRUE )
  710. {
  711. $db->updateExpirationDate($game_home['home_id'], $date, 'user', $account['user_id']);
  712. $status = "200";
  713. $message = "Home assigned successfully";
  714. }
  715. else
  716. {
  717. $status = "325";
  718. $message = "Home id#$home_id could not be assigned to $email.";
  719. }
  720. }
  721. }
  722. }
  723. if($request[0] == "remove_assign")
  724. {
  725. $email = $_POST['email'];
  726. $home_id = $_POST['home_id'];
  727. $game_home = $db->getGameHome($home_id);
  728. if($game_home === FALSE)
  729. return array("status" => '315', "message" => "There is no game home with home_id #" . $home_id . ".");
  730. $account = $db->getUserByEmail($email);
  731. if($account === FALSE)
  732. {
  733. $status = "319";
  734. $message = "There is no account with the given email address ($email).";
  735. }
  736. else
  737. {
  738. if ($db->unassignHomeFrom("user",$account['user_id'],$game_home['home_id']) === TRUE)
  739. {
  740. $status = "200";
  741. $message = "Home id#$game_home[home_id] has been unnassigned from $email successfully.";
  742. }
  743. else
  744. {
  745. $status = "326";
  746. $message = "Home id#$home_id was not assigned to $email.";
  747. }
  748. }
  749. }
  750. return array("status" => $status, "message" => $message);
  751. }
  752. function api_gamemanager_admin()
  753. {
  754. global $request, $db, $user_info, $settings;
  755. $isAdmin = $db->isAdmin($user_info['user_id']);
  756. if($request[0] == "reorder")
  757. {
  758. if($isAdmin){
  759. $data = json_decode(file_get_contents('php://input'), true);
  760. if(array_key_exists("order", $data) && is_array($data["order"])){
  761. $updatedOrder = $db->saveGameServerOrder($data["order"]);
  762. if($updatedOrder){
  763. $status = "200";
  764. $message = "Game server order was successfully saved.";
  765. }else{
  766. $status = "335";
  767. $message = "Game server order was NOT saved.";
  768. }
  769. }else{
  770. $status = "335";
  771. $message = "Invalid inputs.";
  772. }
  773. }else{
  774. $status = "335";
  775. $message = "Only admin users can save the game server display order.";
  776. }
  777. }
  778. return array("status" => $status, "message" => $message);
  779. }
  780. function api_gamemanager()
  781. {
  782. global $request, $db, $user_info, $settings;
  783. $ip = trim($_POST['ip']);
  784. $port = (int) trim($_POST['port']);
  785. $mod_key = isset($_POST['mod_key'])?trim($_POST['mod_key']):'';
  786. if(!isPortValid($port))
  787. return array("status" => '309', "message" => "The given port is not a valid port.");
  788. if(!preg_match("/[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}/",$ip))
  789. return array("status" => '327', "message" => "The given IP ($ip) is not a valid IP address.");
  790. $home_info = $db->getGameHomeByIP($ip, $port);
  791. if($home_info === FALSE)
  792. return array("status" => '328', "message" => "There is no game server with the given address ($ip:$port).");
  793. $mod_id = key($home_info['mods']);
  794. if($mod_key != '')
  795. {
  796. foreach($home_info['mods'] as $home_mod)
  797. {
  798. if($mod_key == $home_mod['mod_key'])
  799. {
  800. $mod_id = $home_mod['mod_id'];
  801. break;
  802. }
  803. }
  804. }
  805. $isAdmin = $db->isAdmin($user_info['user_id']);
  806. if($isAdmin)
  807. {
  808. $access_rights = 'ufpetc';
  809. }
  810. else
  811. {
  812. $game_home = $db->getUserGameHome($user_info['user_id'], $home_info['home_id']);
  813. if($game_home === FALSE)
  814. return array("status" => '329', "message" => "The given address ($ip:$port) does not belong to your account.");
  815. $access_rights = $game_home['access_rights'];
  816. }
  817. $server_xml = read_server_config(SERVER_CONFIG_LOCATION."/".$home_info['home_cfg_file']);
  818. if($server_xml === FALSE)
  819. return array("status" => '305', "message" => "No game configuration found for home_cfg_id #" . $home_cfg_id . ".");
  820. $remote = new OGPRemoteLibrary($home_info['agent_ip'],$home_info['agent_port'],$home_info['encryption_key'],$home_info['timeout']);
  821. $host_stat = $remote->status_chk();
  822. if($host_stat !== 1)
  823. return array("status" => '310', "message" => "The remote server is offline.");
  824. $os = $remote->what_os();
  825. if($request[0] == "start")
  826. {
  827. $start_cmd = get_start_cmd($user_info,$remote,$server_xml,$home_info,$mod_id,$ip,$port,$db);
  828. if(isset($server_xml->lgsl_query_name))
  829. require_once('protocol/lgsl/lgsl_protocol.php');
  830. // Do text replacements in cfg file
  831. if($server_xml->replace_texts)
  832. {
  833. foreach($home_info['mods'][$mod_id] as $key => $value)
  834. {
  835. $home_info[$key] = $value;
  836. }
  837. $server_home = $home_info;
  838. require_once(MODULES."gamemanager/cfg_text_replace.php");
  839. }
  840. // Run pre-start commands
  841. if(isset($server_xml->pre_start) && !empty($server_xml->pre_start)){
  842. $preStart = trim($server_xml->pre_start);
  843. }else{
  844. $preStart = "";
  845. }
  846. // Environment variables
  847. if(isset($server_xml->environment_variables) && !empty($server_xml->environment_variables)){
  848. $envVars = trim($server_xml->environment_variables);
  849. }else{
  850. $envVars = "";
  851. }
  852. // Additional files to lock
  853. if(isset($server_xml->lock_files) && !empty($server_xml->lock_files)){
  854. $lockFiles = trim($server_xml->lock_files);
  855. }else{
  856. $lockFiles = "";
  857. }
  858. if(!empty($lockFiles)){
  859. // Linux only call
  860. if(preg_match("/Linux/", $os)){
  861. $lockedFilesStatus = $remote->lock_additional_home_files($home_info['home_path'], $lockFiles, "lock");
  862. }
  863. }
  864. $start_retval = $remote->universal_start($home_info['home_id'],
  865. $home_info['home_path'],
  866. $server_xml->server_exec_name,
  867. $server_xml->exe_location,
  868. $start_cmd, $port, $ip,
  869. $home_info['mods'][$mod_id]['cpu_affinity'],
  870. $home_info['mods'][$mod_id]['nice'],
  871. $preStart,
  872. $envVars,
  873. $server_xml->game_key,
  874. (isset( $server_xml->console_log ) ? $server_xml->console_log : "")
  875. );
  876. if( $start_retval == AGENT_ERROR_NOT_EXECUTABLE)
  877. return array("status" => '330', "message" => "The server executable does not have execution permission.");
  878. elseif($start_retval <= 0)
  879. return array("status" => '331', "message" => "The server could not be started, already running.");
  880. else
  881. {
  882. $firewall_settings = $db->getFirewallSettings($home_info['remote_server_id']);
  883. if ($firewall_settings['status'] == "enable")
  884. {
  885. if ($server_xml->protocol == "gameq")
  886. {
  887. $query_port = get_query_port($server_xml, $port);
  888. }
  889. elseif ($server_xml->protocol == "lgsl")
  890. {
  891. $get_ports = lgsl_port_conversion((string)$server_xml->lgsl_query_name, $port, "", "");
  892. $query_port = $get_ports['1'];
  893. }
  894. elseif ($server_xml->protocol == "teamspeak3")
  895. {
  896. $query_port = $port + 24;
  897. }
  898. set_firewall($remote, $firewall_settings, 'allow', $port, $ip);
  899. if(isset($query_port) and $query_port != "" and $query_port != $port)
  900. set_firewall($remote, $firewall_settings, 'allow', $query_port, $ip);
  901. }
  902. $db->delServerStatusCache($home_info['ip_id'],$port);
  903. $status = "200";
  904. $message = "The server has been started.";
  905. }
  906. }
  907. if($request[0] == "stop")
  908. {
  909. $remote_retval = $remote->remote_stop_server($home_info['home_id'],
  910. $ip, $port, $server_xml->control_protocol,
  911. $home_info['control_password'],$server_xml->control_protocol_type, $home_info['home_path']);
  912. if($remote_retval === -1)
  913. return array("status" => '332', "message" => "The server could not be stopped.");
  914. elseif($remote_retval === -2)
  915. return array("status" => '332', "message" => "The server could not be stopped.");
  916. else
  917. {
  918. $firewall_settings = $db->getFirewallSettings($home_info['remote_server_id']);
  919. if ($firewall_settings['status'] == "enable")
  920. {
  921. if ($server_xml->protocol == "gameq")
  922. {
  923. $query_port = get_query_port($server_xml, $port);
  924. }
  925. elseif ($server_xml->protocol == "lgsl")
  926. {
  927. require('protocol/lgsl/lgsl_protocol.php');
  928. $get_ports = lgsl_port_conversion((string)$server_xml->lgsl_query_name, $port, "", "");
  929. $query_port = $get_ports['1'];
  930. }
  931. elseif ($server_xml->protocol == "teamspeak3")
  932. {
  933. $query_port = $port + 24;
  934. }
  935. set_firewall($remote, $firewall_settings, 'deny', $port, $ip);
  936. if(isset($query_port) and $query_port != "" and $query_port != $port)
  937. set_firewall($remote, $firewall_settings, 'deny', $query_port, $ip);
  938. }
  939. $status = "200";
  940. $message = "The server has been stopped.";
  941. }
  942. }
  943. if($request[0] == "restart")
  944. {
  945. $start_cmd = get_start_cmd($user_info,$remote,$server_xml,$home_info,$mod_id,$ip,$port,$db);
  946. // Do text replacements in cfg file
  947. if( $server_xml->replace_texts )
  948. {
  949. foreach($home_info['mods'][$mod_id] as $key => $value)
  950. {
  951. $home_info[$key] = $value;
  952. }
  953. $server_home = $home_info;
  954. if(isset($server_xml->lgsl_query_name))
  955. require_once('protocol/lgsl/lgsl_protocol.php');
  956. require_once(MODULES."gamemanager/cfg_text_replace.php");
  957. }
  958. // Run pre-start commands
  959. if(isset($server_xml->pre_start) && !empty($server_xml->pre_start)){
  960. $preStart = trim($server_xml->pre_start);
  961. }else{
  962. $preStart = "";
  963. }
  964. // Environment variables
  965. if(isset($server_xml->environment_variables) && !empty($server_xml->environment_variables)){
  966. $envVars = trim($server_xml->environment_variables);
  967. }else{
  968. $envVars = "";
  969. }
  970. // Additional files to lock
  971. if(isset($server_xml->lock_files) && !empty($server_xml->lock_files)){
  972. $lockFiles = trim($server_xml->lock_files);
  973. }else{
  974. $lockFiles = "";
  975. }
  976. if(!empty($lockFiles)){
  977. // Linux only call
  978. if(preg_match("/Linux/", $os)){
  979. $lockedFilesStatus = $remote->lock_additional_home_files($home_info['home_path'], $lockFiles, "lock");
  980. }
  981. }
  982. $remote_retval = $remote->remote_restart_server($home_info['home_id'],$ip,$port,$server_xml->control_protocol,
  983. $home_info['control_password'],$server_xml->control_protocol_type,$home_info['home_path'],
  984. $server_xml->server_exec_name,$server_xml->exe_location,$start_cmd,
  985. $home_info['mods'][$mod_id]['cpu_affinity'],
  986. $home_info['mods'][$mod_id]['nice'],
  987. $preStart,
  988. $envVars,
  989. $server_xml->game_key,
  990. (isset( $server_xml->console_log ) ? $server_xml->console_log : ""));
  991. if($remote_retval === -1)
  992. return array("status" => '333', "message" => "The server could not be restarted.");
  993. elseif($remote_retval === -2)
  994. return array("status" => '333', "message" => "The server could not be restarted.");
  995. else
  996. {
  997. $ip_id = $db->getIpIdByIp($ip);
  998. $db->delServerStatusCache($home_info['ip_id'],$port);
  999. $status = "200";
  1000. $message = "The server has been restarted.";
  1001. }
  1002. }
  1003. if($request[0] == "rcon")
  1004. {
  1005. $command = $_POST['command'];
  1006. $response = send_rcon_command($command, $remote, $server_xml, $home_info, $home_info['home_id'], $ip, $port);
  1007. if($response === FALSE)
  1008. {
  1009. $status = "334";
  1010. $message = "The command could not be sent";
  1011. }
  1012. else
  1013. {
  1014. $status = "200";
  1015. $message = $response;
  1016. }
  1017. }
  1018. if($request[0] == "update")
  1019. {
  1020. if(!strstr($access_rights,'u'))
  1021. return array("status" => '352', "message" => "You don't have access right to update the server at $ip:$port.");
  1022. if($_POST['type'] == "steam")
  1023. {
  1024. if($server_xml->installer == "steamcmd")
  1025. {
  1026. $exec_folder_path = clean_path($home_info['home_path'] . "/" . $server_xml->exe_location);
  1027. $exec_path = clean_path($exec_folder_path . "/" . $server_xml->server_exec_name);
  1028. $mod_xml = xml_get_mod($server_xml, $home_info['mods'][$mod_id]['mod_key']);
  1029. $installer_name = $mod_xml->installer_name;
  1030. $modkey = $home_info['mods'][$mod_id]['mod_key'];
  1031. // Some games like L4D2 require anonymous login
  1032. if($mod_xml->installer_login){
  1033. $login = $mod_xml->installer_login;
  1034. $pass = '';
  1035. }else{
  1036. $login = $settings['steam_user'];
  1037. $pass = $settings['steam_pass'];
  1038. }
  1039. $modname = ( $installer_name == '90' and !preg_match("/(cstrike|valve)/", $modkey) ) ? $modkey : '';
  1040. $betaname = isset($mod_xml->betaname) ? $mod_xml->betaname : '';
  1041. $betapwd = isset($mod_xml->betapwd) ? $mod_xml->betapwd : '';
  1042. preg_match("/(win|linux)(32|64)?$/", $server_xml->game_key, $matches);
  1043. $os = strtolower($matches[1]) == 'linux'? 'linux':'windows';
  1044. $arch = isset($matches[2])?$matches[2]:'32';
  1045. $preInstallCMD = "";
  1046. if(isset($server_xml->post_install))
  1047. $preInstallCMD .= $server_xml->pre_install;
  1048. $postInstallCMD = "";
  1049. if(isset($server_xml->post_install))
  1050. $postInstallCMD .= $server_xml->post_install;
  1051. $postInstallCMD .= "\n{OGP_LOCK_FILE} " . $home_info['home_path'] . "/" . ($server_xml->exe_location ? $server_xml->exe_location . "/" : "") . $server_xml->server_exec_name;
  1052. $remote->steam_cmd($home_info['home_id'],$home_info['home_path'],$installer_name,$modname,
  1053. $betaname,$betapwd,$login,$pass,$settings['steam_guard'],
  1054. $exec_folder_path,$exec_path,$preInstallCMD,$postInstallCMD,$os,'',$arch);
  1055. $status = "200";
  1056. $message = "Steam installation started";
  1057. }
  1058. else
  1059. {
  1060. $status = "335";
  1061. $message = 'This game is not supported by Steam installation.';
  1062. }
  1063. }
  1064. if($_POST['type'] == "rsync")
  1065. {
  1066. if(isset($server_xml->lgsl_query_name))
  1067. {
  1068. $rs_name = $server_xml->lgsl_query_name;
  1069. if($rs_name == "quake3" and $server_xml->game_name == "Quake 3")
  1070. $rs_name = "q3";
  1071. }
  1072. elseif(isset($server_xml->gameq_query_name))
  1073. {
  1074. $rs_name = $server_xml->gameq_query_name;
  1075. if($rs_name == "minecraft")
  1076. {
  1077. if($server_xml->game_name == "Minecraft Tekkit")
  1078. $rs_name = "tekkit";
  1079. elseif($server_xml->game_name == "Minecraft Bukkit")
  1080. $rs_name = "bukkit";
  1081. }
  1082. }
  1083. elseif(isset($server_xml->protocol))
  1084. $rs_name = $server_xml->protocol;
  1085. else
  1086. $rs_name = $server_xml->mods->mod['key'];
  1087. $rsync_available = isset($settings['rsync_available']) ? $settings['rsync_available'] : "1";
  1088. $remote_sites = MODULES."gamemanager/rsync_sites.list";
  1089. $local_sites = MODULES."gamemanager/rsync_sites_local.list";
  1090. $rsync_sites = array();
  1091. switch ($rsync_available) {
  1092. case "0":
  1093. if(file_exists($remote_sites))
  1094. {
  1095. $sites = file($remote_sites);
  1096. if($sites !== FALSE)
  1097. $rsync_sites = array_merge($rsync_sites, $sites);
  1098. }
  1099. if(file_exists($local_sites))
  1100. {
  1101. $sites = file($local_sites);
  1102. if($sites !== FALSE)
  1103. $rsync_sites = array_merge($rsync_sites, $sites);
  1104. }
  1105. break;
  1106. case "1":
  1107. if(file_exists($remote_sites))
  1108. {
  1109. $sites = file($remote_sites);
  1110. if($sites !== FALSE)
  1111. $rsync_sites = array_merge($rsync_sites, $sites);
  1112. }
  1113. break;
  1114. case "2":
  1115. if(file_exists($local_sites))
  1116. {
  1117. $sites = file($local_sites);
  1118. if($sites !== FALSE)
  1119. $rsync_sites = array_merge($rsync_sites, $sites);
  1120. }
  1121. break;
  1122. }
  1123. if(empty($rsync_sites))
  1124. return array("status" => '336', "message" => "No sync sites found, check the panel settings (Available rsync sites).");
  1125. $url = get_faster_rsync($rsync_sites);
  1126. $sync_list_file = MODULES."gamemanager/rsync.list";
  1127. if(!file_exists($sync_list_file))
  1128. return array("status" => '336', "message" => "The sync list file doesn't exists ($sync_list_file).");
  1129. $sync_list = file($sync_list_file, FILE_IGNORE_NEW_LINES);
  1130. if(!$sync_list or empty($sync_list))
  1131. return array("status" => '337', "message" => "Failed to read sync list file ($sync_list_file).");
  1132. if(in_array($rs_name, $sync_list))
  1133. {
  1134. $exec_folder_path = clean_path($home_info['home_path'] . "/" . $server_xml->exe_location);
  1135. $exec_path = clean_path($exec_folder_path . "/" . $server_xml->server_exec_name);
  1136. preg_match("/(win|linux)(32|64)?$/", $server_xml->game_key, $matches);
  1137. $os = strtolower($matches[1]) == 'linux'? 'linux':'windows';
  1138. $full_url = "$url/ogp_game_installer/$rs_name/$os/";
  1139. $preInstallCMD = "";
  1140. if(isset($server_xml->post_install))
  1141. $preInstallCMD .= $server_xml->pre_install;
  1142. $postInstallCMD = "";
  1143. if(isset($server_xml->post_install))
  1144. $postInstallCMD .= $server_xml->post_install;
  1145. $postInstallCMD .= "\n{OGP_LOCK_FILE} " . $home_info['home_path'] . "/" . ($server_xml->exe_location ? $server_xml->exe_location . "/" : "") . $server_xml->server_exec_name;
  1146. $remote->start_rsync_install($home_id,$home_info['home_path'],"$full_url",$exec_folder_path,$exec_path,$preInstallCMD,$postInstallCMD);
  1147. $status = "200";
  1148. $message = "Rsync installation started";
  1149. }
  1150. else
  1151. {
  1152. $status = "335";
  1153. $message = 'This game is not supported by Rsync installation.';
  1154. }
  1155. }
  1156. if($_POST['type'] == "manual")
  1157. {
  1158. $manual_url = trim($_POST['manual_url']);
  1159. $filename = get_download_filename($manual_url);
  1160. if($filename)
  1161. {
  1162. $postInstallCMD = "";
  1163. if(isset($server_xml->post_install))
  1164. $postInstallCMD .= $server_xml->post_install;
  1165. $postInstallCMD .= "\n{OGP_LOCK_FILE} " . $home_info['home_path'] . "/" . ($server_xml->exe_location ? $server_xml->exe_location . "/" : "") . $server_xml->server_exec_name;
  1166. $remote->start_file_download($manual_url,$home_info['home_path'],$filename,"uncompress",$postInstallCMD);
  1167. $status = "200";
  1168. $message = "Manual installation started";
  1169. }
  1170. else
  1171. {
  1172. $status = "335";
  1173. $message = 'The URL for manual installation is empty or invalid.';
  1174. }
  1175. }
  1176. if($_POST['type'] == "master")
  1177. {
  1178. $ms_home_id = $db->getMasterServer($home_info['remote_server_id'], $home_info['home_cfg_id']);
  1179. if($ms_home_id !== FALSE)
  1180. {
  1181. $exec_folder_path = clean_path($home_info['home_path'] . "/" . $server_xml->exe_location );
  1182. $exec_path = clean_path($exec_folder_path . "/" . $server_xml->server_exec_name );
  1183. $ms_info = $db->getGameHome($ms_home_id);
  1184. $preInstallCMD = "";
  1185. if(isset($server_xml->post_install))
  1186. $preInstallCMD .= $server_xml->pre_install;
  1187. $postInstallCMD = "";
  1188. if(isset($server_xml->post_install))
  1189. $postInstallCMD .= $server_xml->post_install;
  1190. $postInstallCMD .= "\n{OGP_LOCK_FILE} " . $home_info['home_path'] . "/" . ($server_xml->exe_location ? $server_xml->exe_location . "/" : "") . $server_xml->server_exec_name;
  1191. $remote->masterServerUpdate($home_id,$home_info['home_path'],$ms_home_id,$ms_info['home_path'],$exec_folder_path,$exec_path,$preInstallCMD,$postInstallCMD);
  1192. $status = "200";
  1193. $message = "Installation from master server ($home_info[home_name]) started";
  1194. }
  1195. else
  1196. {
  1197. $status = "335";
  1198. $message = 'There is no master server assigned for this game.';
  1199. }
  1200. }
  1201. }
  1202. return array("status" => $status, "message" => $message);
  1203. }
  1204. function api_litefm()
  1205. {
  1206. global $request, $db, $user_info, $settings;
  1207. $ip = $_POST['ip'];
  1208. $port = $_POST['port'];
  1209. $relative_path = $_POST['relative_path'];
  1210. $home_info = $db->getGameHomeByIP($ip, $port);
  1211. if($home_info === FALSE)
  1212. return array("status" => '328', "message" => "There is no game server with the given address ($ip:$port).");
  1213. $isAdmin = $db->isAdmin($user_info['user_id']);
  1214. if($isAdmin)
  1215. {
  1216. $access_rights = 'ufpetc';
  1217. }
  1218. else
  1219. {
  1220. $game_home = $db->getUserGameHome($user_info['user_id'], $home_info['home_id']);
  1221. if($game_home === FALSE)
  1222. return array("status" => '329', "message" => "The given address ($ip:$port) does not belong to your account.");
  1223. $access_rights = $game_home['access_rights'];
  1224. }
  1225. if(!strstr($access_rights,'f'))
  1226. return array("status" => '351', "message" => "You don't have access right for file management in server at $ip:$port.");
  1227. $server_xml = read_server_config(SERVER_CONFIG_LOCATION."/".$home_info['home_cfg_file']);
  1228. if($server_xml === FALSE)
  1229. return array("status" => '305', "message" => "No game configuration found for home_cfg_id #" . $home_cfg_id . ".");
  1230. $remote = new OGPRemoteLibrary($home_info['agent_ip'],$home_info['agent_port'],$home_info['encryption_key'],$home_info['timeout']);
  1231. $host_stat = $remote->status_chk();
  1232. if($host_stat !== 1)
  1233. return array("status" => '310', "message" => "The remote server is offline.");
  1234. $relative_path = preg_replace("/(\.\.)(\\\|\/)+/", '/', $relative_path);
  1235. $path = clean_path($home_info['home_path'].'/'.$relative_path);
  1236. if($request[0] != "save" and $remote->rfile_exists($path) === 0)
  1237. return array("status" => '338', "message" => "$path does not exists.");
  1238. if($request[0] == "list")
  1239. {
  1240. $status = "200";
  1241. $message = $remote->remote_dirlistfm($path);
  1242. }
  1243. if($request[0] == "get")
  1244. {
  1245. $remote->remote_readfile($path, $data);
  1246. $status = "200";
  1247. $message = $data;
  1248. }
  1249. if($request[0] == "save")
  1250. {
  1251. $contents = $_POST['contents'];
  1252. if($remote->remote_writefile($path, $contents) === 1)
  1253. {
  1254. $status = "200";
  1255. $message = "File $path written successfully";
  1256. }
  1257. else
  1258. {
  1259. $status = "339";
  1260. $message = "Could not write to the file.";
  1261. }
  1262. }
  1263. if($request[0] == "remove")
  1264. {
  1265. $remote->shell_action('remove_recursive', $path);
  1266. if($remote->rfile_exists($path) === 0)
  1267. {
  1268. $status = '200';
  1269. $message = "$path removed successfully.";
  1270. }
  1271. else
  1272. {
  1273. $status = '340';
  1274. $message = "$path could not be removed.";
  1275. }
  1276. }
  1277. return array("status" => $status, "message" => $message);
  1278. }
  1279. function api_addonsmanager()
  1280. {
  1281. global $request, $db, $user_info;
  1282. if($db->isModuleInstalled('addonsmanager') === FALSE)
  1283. return array("status" => '349', "message" => "This function is not available because the module is not installed.");
  1284. if($request[0] == "list")
  1285. {
  1286. $addons_rows = $db->resultQuery("SELECT * FROM OGP_DB_PREFIXaddons");
  1287. $status = "200";
  1288. $message = $addons_rows;
  1289. }
  1290. if($request[0] == "install")
  1291. {
  1292. $ip = $_POST['ip'];
  1293. $port = (int)$_POST['port'];
  1294. $mod_key = isset($_POST['mod_key'])?trim($_POST['mod_key']):'';
  1295. $addon_id = (int)$_POST['addon_id'];
  1296. $home_info = $db->getGameHomeByIP($ip, $port);
  1297. if($home_info === FALSE)
  1298. return array("status" => '328', "message" => "There is no game server with the given address ($ip:$port).");
  1299. $isAdmin = $db->isAdmin($user_info['user_id']);
  1300. if(!$isAdmin and $db->getUserGameHome($user_info['user_id'], $home_info['home_id']) === FALSE)
  1301. return array("status" => '329', "message" => "The given address ($ip:$port) does not belong to your account.");
  1302. $server_xml = read_server_config(SERVER_CONFIG_LOCATION."/".$home_info['home_cfg_file']);
  1303. if($server_xml === FALSE)
  1304. return array("status" => '305', "message" => "No game configuration found for home_cfg_id #" . $home_cfg_id . ".");
  1305. $remote = new OGPRemoteLibrary($home_info['agent_ip'],$home_info['agent_port'],$home_info['encryption_key'],$home_info['timeout']);
  1306. $host_stat = $remote->status_chk();
  1307. if($host_stat !== 1)
  1308. return array("status" => '310', "message" => "The remote server is offline.");
  1309. $mod_id = key($home_info['mods']);
  1310. if($mod_key != '')
  1311. {
  1312. foreach($home_info['mods'] as $home_mod)
  1313. {
  1314. if($mod_key == $home_mod['mod_key'])
  1315. {
  1316. $mod_id = $home_mod['mod_id'];
  1317. break;
  1318. }
  1319. }
  1320. }
  1321. else
  1322. $mod_key = $home_info['mods'][$mod_id]['mod_key'];
  1323. $query_groups = "";
  1324. if(!$isAdmin)
  1325. {
  1326. $groups = $db->getUsersGroups($user_info['user_id']);
  1327. $query_groups .= " AND (";
  1328. foreach($groups as $group)
  1329. $query_groups .= "group_id=".$group['group_id']." OR ";
  1330. $query_groups .= "group_id=0 OR group_id IS NULL)";
  1331. }
  1332. $addons_rows = $db->resultQuery("SELECT * FROM OGP_DB_PREFIXaddons WHERE home_cfg_id=".$home_info['home_cfg_id']." AND addon_id=".$addon_id.$query_groups);
  1333. if($addons_rows === FALSE)
  1334. return array("status" => '341', "message" => "Invalid addon id #" . $addon_id . ".");
  1335. $addon_info = $addons_rows[0];
  1336. $url = $addon_info['url'];
  1337. $filename = basename($url);
  1338. if($addon_info['post_script'] != "")
  1339. {
  1340. $addon_info['post_script'] = strip_real_escape_string($addon_info['post_script']);
  1341. if( isset($server_xml->gameq_query_name) )
  1342. {
  1343. $home_info['query_port'] = get_query_port($server_xml, $home_info['port']);
  1344. }
  1345. elseif( isset($server_xml->lgsl_query_name) )
  1346. {
  1347. require_once('protocol/lgsl/lgsl_protocol.php');
  1348. $get_q_and_s = lgsl_port_conversion((string)$server_xml->lgsl_query_name, $home_info['port'], "", "");
  1349. $home_info['query_port'] = $get_q_and_s['1'];
  1350. }
  1351. elseif ($server_xml->protocol == "teamspeak3")
  1352. {
  1353. $query_port = $port + 24;
  1354. }
  1355. $home_info["incremental"] = $db->incrementalNumByHomeId($home_info['home_id'], $home_info['mods'][$mod_id]['mod_cfg_id'], $home_info['remote_server_id']);
  1356. $post_script = preg_replace( "/\%home_path\%/i", $home_info['home_path'], $addon_info['post_script']);
  1357. $post_script = preg_replace( "/\%home_name\%/i", $home_info['home_name'], $post_script);
  1358. $post_script = preg_replace( "/\%control_password\%/i", $home_info['control_password'], $post_script);
  1359. $post_script = preg_replace( "/\%max_players\%/i", $home_info['mods'][$mod_id]['max_players'], $post_script);
  1360. $post_script = preg_replace( "/\%ip\%/i", $home_info['ip'], $post_script);
  1361. $post_script = preg_replace( "/\%port\%/i", $home_info['port'], $post_script);
  1362. $post_script = preg_replace( "/\%query_port\%/i", $home_info['query_port'], $post_script);
  1363. $post_script = preg_replace( "/\%incremental\%/i", $home_info['incremental'], $post_script);
  1364. }
  1365. $pid = $remote->start_file_download($addon_info['url'], $home_info['home_path']."/".$addon_info['path'], $filename, "uncompress", $post_script);
  1366. if($pid > 0)
  1367. {
  1368. $status = "200";
  1369. $message = "Addon installation started with process id #".$pid;
  1370. }
  1371. else
  1372. {
  1373. $status = "342";
  1374. $message = "Addon installation failed, file download could not be started.($retval)";
  1375. }
  1376. }
  1377. return array("status" => $status, "message" => $message);
  1378. }
  1379. function api_steam_workshop()
  1380. {
  1381. global $request, $db, $user_info, $settings;
  1382. if($db->isModuleInstalled('steam_workshop') === FALSE)
  1383. return array("status" => '349', "message" => "This function is not available because the module is not installed.");
  1384. define('CONFIGS', "modules/steam_workshop/game_configs/");
  1385. if($request[0] == "install")
  1386. {
  1387. $ip = $_POST['ip'];
  1388. $port = (int)$_POST['port'];
  1389. $mod_key = isset($_POST['mod_key'])?trim($_POST['mod_key']):'';
  1390. $mods_list = $_POST['mods_list'];
  1391. $home_info = $db->getGameHomeByIP($ip, $port);
  1392. if($home_info === FALSE)
  1393. return array("status" => '328', "message" => "There is no game server with the given address ($ip:$port).");
  1394. $isAdmin = $db->isAdmin($user_info['user_id']);
  1395. if(!$isAdmin and $db->getUserGameHome($user_info['user_id'], $home_info['home_id']) === FALSE)
  1396. return array("status" => '329', "message" => "The given address ($ip:$port) does not belong to your account.");
  1397. $server_xml = read_server_config(SERVER_CONFIG_LOCATION."/".$home_info['home_cfg_file']);
  1398. if($server_xml === FALSE)
  1399. return array("status" => '305', "message" => "No game configuration found for home_cfg_id #" . $home_cfg_id . ".");
  1400. $remote = new OGPRemoteLibrary($home_info['agent_ip'],$home_info['agent_port'],$home_info['encryption_key'],$home_info['timeout']);
  1401. $host_stat = $remote->status_chk();
  1402. if($host_stat !== 1)
  1403. return array("status" => '310', "message" => "The remote server is offline.");
  1404. require_once(MODULES.'steam_workshop/functions.php');
  1405. if(preg_match('/^([0-9]+,?)+$/', $mods_list))
  1406. {
  1407. $mod_id = key($home_info['mods']);
  1408. if($mod_key != '')
  1409. {
  1410. foreach($home_info['mods'] as $home_mod)
  1411. {
  1412. if($mod_key == $home_mod['mod_key'])
  1413. {
  1414. $mod_id = $home_mod['mod_id'];
  1415. break;
  1416. }
  1417. }
  1418. }
  1419. $mod_xml = xml_get_mod($server_xml, $home_info['mods'][$mod_id]['mod_key']);
  1420. if($mod_xml == FALSE)
  1421. return array("status" => '344', "message" => "mod_key not found from game xml.");
  1422. preg_match('/(linux|win)(32|64)?/i', $home_info['game_key'], $matches);
  1423. if(strtolower($matches[1]) == 'linux')
  1424. $os = "Linux";
  1425. elseif(strtolower($matches[1]) == 'win')
  1426. $os = "Windows";
  1427. $xml_file = CONFIGS.$mod_xml->installer_name."_".$os.".xml";
  1428. if(!file_exists($xml_file))
  1429. return array("status" => '344', "message" => "No Steam workshop xml file could be found for the game installed in the given ip:port.");
  1430. $dom = new DOMDocument();
  1431. if ( @$dom->load($xml_file) === FALSE )
  1432. return array("status" => '345', "message" => "The Steam workshop xml file for this game has bad format.");
  1433. $xml = simplexml_load_file($xml_file);
  1434. $mod_id_array = explode(',', $mods_list);
  1435. foreach($mod_id_array as $workshop_mod_id)
  1436. {
  1437. $exist = false;
  1438. foreach($xml->mods->mod as $mod)
  1439. {
  1440. if($mod['id'] == $workshop_mod_id)
  1441. {
  1442. $exist = true;
  1443. break;
  1444. }
  1445. }
  1446. if(belongs_to_workshop($workshop_mod_id, $xml->workshop_id))
  1447. {
  1448. if(!$exist)
  1449. {
  1450. list($mod_title, $mod_description, $mod_image_url, $download_url, $filename, $file_size) = get_mod_info($workshop_mod_id);
  1451. //add mods to the xml
  1452. $mod = new SimpleXMLElement('<mod/>');
  1453. $mod->addAttribute('id', $workshop_mod_id);
  1454. $mod->addChild('name', $mod_title);
  1455. $mod->addChild('description', base64_encode($mod_description));
  1456. $mod->addChild('image_url', $mod_image_url);
  1457. $mod->addChild('download_url', $download_url);
  1458. $mod->addChild('filename', $filename);
  1459. $mod->addChild('file_size', $file_size);
  1460. $moddom = dom_import_simplexml($mod)->ownerDocument;
  1461. $moddom->formatOutput = true;
  1462. $mod_string = $moddom->saveXML($moddom->documentElement);
  1463. $dom = dom_import_simplexml($xml)->ownerDocument;
  1464. $dom->formatOutput = true;
  1465. $mods = $dom->getElementsByTagName('mods')->item(0);
  1466. $f = $dom->createDocumentFragment();
  1467. $f->appendXML($mod_string."\n");
  1468. $mods->appendChild($f);
  1469. file_put_contents($xml_file, $dom->saveXML());
  1470. $xml = simplexml_load_file($xml_file);
  1471. }
  1472. }
  1473. else
  1474. {
  1475. break;
  1476. return array("status" => '346', "message" => "Mod $workshop_mod_id does not belong to workshop ".$xml->workshop_id.".");
  1477. }
  1478. }
  1479. $config = $xml->config;
  1480. $anonymous_login = $xml->anonymous_login;
  1481. $download_method = $xml->download_method;
  1482. $user = $settings['steam_user'];
  1483. $pass = $settings['steam_pass'];
  1484. $regex = $config->regex;
  1485. $mods_backreference_index = (int)$config->mods_backreference_index;
  1486. $variable = $config->variable;
  1487. $place_after = $config->place_after;
  1488. $mod_string = $config->mod_string;
  1489. $string_separator = $config->string_separator;
  1490. $config_file_path = clean_path($home_info['home_path']."/".$config->filepath);
  1491. $post_install = $xml->post_install;
  1492. $mod_names_list = get_mod_names_list($mods_list, $xml->mods->mod);
  1493. $mods_full_path = clean_path($home_info['home_path'].'/'.$xml->mods_path);
  1494. $workshop_id = $xml->workshop_id;
  1495. $url_list = "";
  1496. $filename_list = "";
  1497. if($download_method == "steamapi")
  1498. {
  1499. foreach($mod_id_array as $workshop_mod_id)
  1500. {
  1501. foreach($xml->mods->mod as $mod)
  1502. {
  1503. if($mod['id'] == $workshop_mod_id)
  1504. {
  1505. $separator = $url_list == ""?"":",";
  1506. $url_list .= $separator.$mod->download_url;
  1507. $filename_list .= $separator.$mod->filename;
  1508. }
  1509. }
  1510. }
  1511. }
  1512. if($remote->steam_workshop( $home_info['home_id'],$mods_full_path,$workshop_id,$mods_list,$regex,$mods_backreference_index,
  1513. $variable,$place_after,$mod_string,$string_separator,$config_file_path,$post_install,
  1514. $mod_names_list,$anonymous_login,$user,$pass,$download_method,$url_list,$filename_list ) == 1)
  1515. {
  1516. $status = "200";
  1517. $message = "Mods installation started successfully";
  1518. }
  1519. else
  1520. {
  1521. $status = '347';
  1522. $message = "The installation could not be started on the remote server.";
  1523. }
  1524. }
  1525. else
  1526. {
  1527. $status = '348';
  1528. $message = "The mods list has bad format ($mods_list), must be a list of mod ids separated by coma with no spaces, or only one mod id.";
  1529. }
  1530. }
  1531. return array("status" => $status, "message" => $message);
  1532. }
  1533. ?>