user_cron.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314
  1. <script type="text/javascript" src="js/modules/cron.js"></script>
  2. <?php
  3. /*
  4. *
  5. * OGP - Open Game Panel
  6. * Copyright (C) 2008 - 2018 The OGP Development Team
  7. *
  8. * http://www.opengamepanel.org/
  9. *
  10. * This program is free software; you can redistribute it and/or
  11. * modify it under the terms of the GNU General Public License
  12. * as published by the Free Software Foundation; either version 2
  13. * of the License, or any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with this program; if not, write to the Free Software
  22. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  23. *
  24. */
  25. error_reporting(E_ALL);
  26. require_once('includes/lib_remote.php');
  27. require_once('modules/gamemanager/home_handling_functions.php');
  28. require_once('modules/config_games/server_config_parser.php');
  29. require_once('modules/cron/shared_cron_functions.php');
  30. function exec_ogp_module()
  31. {
  32. global $db, $view;
  33. $isAdmin = $db->isAdmin($_SESSION['user_id']);
  34. $boolShowedAdminLink = false;
  35. $homes = $db->getIpPortsForUser($_SESSION['user_id']);
  36. if(!$homes)
  37. {
  38. print_failure(get_lang('cron_no_servers_tied_to_account'));
  39. if($isAdmin){
  40. $boolShowedAdminLink = true;
  41. echo '<a href="home.php?m=cron&p=cron">' . get_lang('cron_admin_link_display_text') . '</a>';
  42. }
  43. return 0;
  44. }
  45. foreach( $homes as $home )
  46. {
  47. $id = $home['home_id']."_".$home['ip']."_".$home['port'];
  48. $server_homes[$id] = $home;
  49. $server_id = $home['remote_server_id'];
  50. $remote_servers[$server_id] = array("remote_server_id" => $home['remote_server_id'],
  51. "remote_server_name" => $home['remote_server_name'],
  52. "ogp_user" => $home['ogp_user'],
  53. "agent_ip" => $home['agent_ip'],
  54. "agent_port" => $home['agent_port'],
  55. "ftp_port" => $home['ftp_port'],
  56. "encryption_key" => $home['encryption_key'],
  57. "timeout" => $home['timeout'],
  58. "use_nat" => $home['use_nat'],
  59. "ftp_ip" => $home['ftp_ip']);
  60. }
  61. list($jobsArray, $remote_servers_offline) = reloadJobs($server_homes, $remote_servers);
  62. if( isset($_POST['addJob']) or isset($_POST['editJob']) )
  63. {
  64. if ( isset( $_POST['homeid_ip_port'] ) and isset($server_homes[$_POST['homeid_ip_port']]) )
  65. {
  66. $game_home = $server_homes[$_POST['homeid_ip_port']];
  67. $server_xml = read_server_config(SERVER_CONFIG_LOCATION."/".$game_home['home_cfg_file']);
  68. $remote = new OGPRemoteLibrary( $game_home['agent_ip'],
  69. $game_home['agent_port'],
  70. $game_home['encryption_key'],
  71. $game_home['timeout']);
  72. $home_id = $game_home['home_id'];
  73. $ip = $game_home['ip'];
  74. $port = $game_home['port'];
  75. $control_protocol = $server_xml->control_protocol;
  76. $control_password = $game_home['control_password'];
  77. $control_type = $server_xml->control_protocol_type;
  78. $home_path = $game_home['home_path'];
  79. $server_exe = $server_xml->server_exec_name;
  80. $run_dir = $server_xml->exe_location;
  81. $game_home['mods'][$game_home['mod_id']] = Array ("mod_cfg_id" => $game_home['mod_cfg_id'],
  82. "max_players" => $game_home['max_players'],
  83. "extra_params" => $game_home['extra_params'],
  84. "cpu_affinity" => $game_home['cpu_affinity'],
  85. "nice" => $game_home['nice'],
  86. "precmd" => $game_home['precmd'],
  87. "postcmd" => $game_home['postcmd'],
  88. "home_cfg_id" => $game_home['home_cfg_id'],
  89. "mod_key" => $game_home['mod_key'],
  90. "mod_name" => $game_home['mod_name'],
  91. "def_precmd" => $game_home['def_precmd'],
  92. "def_postcmd" => $game_home['def_postcmd']);
  93. $startup_cmd = get_start_cmd($remote,$server_xml,$game_home,$game_home['mod_id'],$game_home['ip'],$game_home['port'], $db);
  94. $cpu = $game_home['cpu_affinity'];
  95. $nice = $game_home['nice'];
  96. $panelURL = getOGPSiteURL();
  97. if($panelURL === false){
  98. print_failure('Failed to retrieve panel URL.');
  99. return 0;
  100. }
  101. switch ($_POST['action']) {
  102. case "stop":
  103. $command = "wget -qO- \"" . $panelURL . "/ogp_api.php?action=stopServer&homeid=" . $home_id . "&controlpass=" . $control_password . "\" --no-check-certificate > /dev/null 2>&1";
  104. break;
  105. case "start":
  106. $command = "wget -qO- \"" . $panelURL . "/ogp_api.php?action=startServer&homeid=" . $home_id . "&controlpass=" . $control_password . "\" --no-check-certificate > /dev/null 2>&1";
  107. break;
  108. case "restart":
  109. $command = "wget -qO- \"" . $panelURL . "/ogp_api.php?action=restartServer&homeid=" . $home_id . "&controlpass=" . $control_password . "\" --no-check-certificate > /dev/null 2>&1";
  110. break;
  111. case "steam_auto_update":
  112. $command = "wget -qO- \"" . $panelURL . "/ogp_api.php?action=autoUpdateSteamHome&homeid=" . $home_id . "&controlpass=" . $control_password . "\" --no-check-certificate > /dev/null 2>&1";
  113. break;
  114. }
  115. if (!checkCronInput($_POST['minute'], $_POST['hour'], $_POST['dayOfTheMonth'], $_POST['month'], $_POST['dayOfTheWeek'])) {
  116. print_failure(get_lang('OGP_LANG_bad_inputs'));
  117. $view->refresh('?m=cron&p=user_cron');
  118. return;
  119. }
  120. $job = $_POST['minute']." ".
  121. $_POST['hour']." ".
  122. $_POST['dayOfTheMonth']." ".
  123. $_POST['month']." ".
  124. $_POST['dayOfTheWeek']." ".
  125. $command;
  126. if( isset($_POST['editJob']) and isset($jobsArray[$_POST['r_server_id']][$_POST['job_id']]) )
  127. $remote->scheduler_edit_task($_POST['job_id'], $job);
  128. elseif( isset($_POST['addJob']) )
  129. $remote->scheduler_add_task($job);
  130. list($jobsArray, $remote_servers_offline) = reloadJobs($server_homes, $remote_servers);
  131. }
  132. }
  133. elseif( isset($_POST['removeJob']) and isset($remote_servers[$_POST['r_server_id']]) and isset($jobsArray[$_POST['r_server_id']][$_POST['job_id']]) )
  134. {
  135. $remote = new OGPRemoteLibrary( $remote_servers[$_POST['r_server_id']]['agent_ip'],
  136. $remote_servers[$_POST['r_server_id']]['agent_port'],
  137. $remote_servers[$_POST['r_server_id']]['encryption_key'],
  138. $remote_servers[$_POST['r_server_id']]['timeout'] );
  139. $remote->scheduler_del_task($_POST['job_id']);
  140. list($jobsArray, $remote_servers_offline) = reloadJobs($server_homes, $remote_servers);
  141. }
  142. echo "<h2>" . get_lang("schedule_new_job") . "</h2>";
  143. require_once("includes/refreshed.php");
  144. $refresh = new refreshed();
  145. $homeid_ip_port = isset($_POST['homeid_ip_port']) ? $_POST['homeid_ip_port'] : key($server_homes);
  146. $r_server_id = $server_homes[$homeid_ip_port]['remote_server_id'];
  147. $curtime = $refresh->add( "home.php?m=cron&p=thetime&r_server_id=$r_server_id&type=cleared" );
  148. echo "<pre class='log' ><table><tr><td>" . get_lang("now") .
  149. "&nbsp;</td><td><form action='' method='POST' >" . get_server_selector($server_homes, $homeid_ip_port, TRUE) .
  150. "</form></td></tr></table> <b style='font-size:1.4em;'>" . $refresh->getdiv($curtime) . "</b></pre>";
  151. ?>
  152. <form method="POST" >
  153. <table class="center hundred">
  154. <tr>
  155. <th>
  156. <?php echo get_lang("minute"); ?>
  157. </th>
  158. <th>
  159. <?php echo get_lang("hour"); ?>
  160. </th>
  161. <th>
  162. <?php echo get_lang("day"); ?>
  163. </th>
  164. <th>
  165. <?php echo get_lang("month"); ?>
  166. </th>
  167. <th>
  168. <?php echo get_lang("day_of_the_week"); ?>
  169. </th>
  170. <th>
  171. <?php echo get_lang("action"); ?>
  172. </th>
  173. <th>
  174. <?php echo get_lang("user_games"); ?>
  175. </th>
  176. </tr>
  177. <tr>
  178. <td style="width: 35px;" >
  179. <input style="width: 30px;" type="text" name="minute" value="*" />
  180. </td>
  181. <td style="width: 35px;" >
  182. <input style="width: 30px;" type="text" name="hour" value="*" />
  183. </td>
  184. <td style="width: 35px;" >
  185. <input style="width: 30px;" type="text" name="dayOfTheMonth" value="*" />
  186. </td>
  187. <td style="width: 35px;" >
  188. <input style="width: 30px;" type="text" name="month" value="*" />
  189. </td>
  190. <td style="width: 35px;" >
  191. <input style="width: 30px;" type="text" name="dayOfTheWeek" value="*" />
  192. </td>
  193. <td>
  194. <?php echo get_action_selector();?>
  195. </td>
  196. <td>
  197. <?php echo get_server_selector($server_homes, $homeid_ip_port);?>
  198. </td>
  199. <td style="width: 132px;">
  200. <input style="" type="submit" name="addJob" value="<?php echo get_lang("add"); ?>" />
  201. </td>
  202. </tr>
  203. </table>
  204. </form>
  205. <br>
  206. <h2><?php echo get_lang("scheduled_jobs");?></h2>
  207. <?php
  208. if ( !empty($jobsArray) )
  209. {
  210. ?>
  211. <table class="center hundred">
  212. </tr>
  213. <tr>
  214. <th>
  215. <?php echo get_lang("minute"); ?>
  216. </th>
  217. <th>
  218. <?php echo get_lang("hour"); ?>
  219. </th>
  220. <th>
  221. <?php echo get_lang("day"); ?>
  222. </th>
  223. <th>
  224. <?php echo get_lang("month"); ?>
  225. </th>
  226. <th>
  227. <?php echo get_lang("day_of_the_week"); ?>
  228. </th>
  229. <th>
  230. <?php echo get_lang("action"); ?>
  231. </th>
  232. <th>
  233. <?php echo get_lang("user_games"); ?>
  234. </th>
  235. </tr>
  236. <?php
  237. $user_jobs = "";
  238. foreach( $jobsArray as $remote_server_id => $jobs )
  239. {
  240. foreach($jobs as $jobId => $job)
  241. {
  242. if(isset($job['action']))
  243. {
  244. if(array_key_exists('home_id', $job) && array_key_exists('ip', $job) && array_key_exists('port', $job) && hasValue($job['home_id']) && hasValue($job['ip']) && hasValue($job['port'])){
  245. $uniqueStr = $job['home_id']."_".$job['ip']."_".$job['port'];
  246. }else if(hasValue($job['home_id'])){
  247. $uniqueStr = $job['home_id'];
  248. }
  249. if(hasValue(@$uniqueStr)){
  250. $user_jobs .= '<tr>
  251. <td style="width: 35px;" >
  252. <form method="POST" >
  253. <input style="width: 30px;" type="text" name="minute" value="'.$job['minute'].'" />
  254. </td>
  255. <td style="width: 35px;" >
  256. <input style="width: 30px;" type="text" name="hour" value="'.$job['hour'].'" />
  257. </td>
  258. <td style="width: 35px;" >
  259. <input style="width: 30px;" type="text" name="dayOfTheMonth" value="'.$job['dayOfTheMonth'].'" />
  260. </td>
  261. <td style="width: 35px;" >
  262. <input style="width: 30px;" type="text" name="month" value="'.$job['month'].'" />
  263. </td>
  264. <td style="width: 35px;" >
  265. <input style="width: 30px;" type="text" name="dayOfTheWeek" value="'.$job['dayOfTheWeek'].'" />
  266. </td>
  267. <td>
  268. '.get_action_selector($job['action'])."</td><td>".
  269. get_server_selector($server_homes, $uniqueStr).'
  270. </td>
  271. <td style="width: 132px;">
  272. <input type="hidden" name="job_id" value=\''.$jobId.'\' />
  273. <input type="hidden" name="r_server_id" value=\''.$remote_server_id.'\' />
  274. <input style="" type="submit" name="editJob" value="'. get_lang("edit") .'" />
  275. <input style="" type="submit" name="removeJob" value="'. get_lang("remove") .'" />
  276. </form>
  277. </td>
  278. </tr>';
  279. }
  280. }
  281. }
  282. }
  283. echo $user_jobs;
  284. ?>
  285. </table>
  286. <?php
  287. }
  288. else
  289. echo "<h3>". get_lang("there_are_no_scheduled_jobs") ."</h3>";
  290. ?>
  291. <table class='center hundred' ><tr><td><a href='javascript:history.go(-1)' > << <?php echo get_lang("back") ?></a><?php if(!$boolShowedAdminLink && $isAdmin){ echo '&nbsp; &nbsp; | &nbsp; &nbsp; ' . '<a href="home.php?m=cron&p=cron">' . get_lang('cron_admin_link_display_text') . '</a>'; }?></td></tr></table>
  292. <script type="text/javascript">
  293. $(document).ready(function()
  294. {
  295. <?php echo $refresh->build("1000"); ?>
  296. }
  297. );
  298. </script>
  299. <?php
  300. }
  301. ?>