ogp_api.php 57 KB

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