user_cron.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  1. <script type="text/javascript" src="js/modules/cron.js"></script>
  2. <?php
  3. /*
  4. *
  5. * OGP - Open Game Panel
  6. * Copyright (C) 2008 - 2017 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;
  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 -N \"" . $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 -N \"" . $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 -N \"" . $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 -N \"" . $panelURL . "/ogp_api.php?action=autoUpdateSteamHome&homeid=" . $home_id . "&controlpass=" . $control_password . "\" --no-check-certificate > /dev/null 2>&1";
  113. break;
  114. }
  115. $job = $_POST['minute']." ".
  116. $_POST['hour']." ".
  117. $_POST['dayOfTheMonth']." ".
  118. $_POST['month']." ".
  119. $_POST['dayOfTheWeek']." ".
  120. $command;
  121. if( isset($_POST['editJob']) and isset($jobsArray[$_POST['r_server_id']][$_POST['job_id']]) )
  122. $remote->scheduler_edit_task($_POST['job_id'], $job);
  123. elseif( isset($_POST['addJob']) )
  124. $remote->scheduler_add_task($job);
  125. list($jobsArray, $remote_servers_offline) = reloadJobs($server_homes, $remote_servers);
  126. }
  127. }
  128. elseif( isset($_POST['removeJob']) and isset($remote_servers[$_POST['r_server_id']]) and isset($jobsArray[$_POST['r_server_id']][$_POST['job_id']]) )
  129. {
  130. $remote = new OGPRemoteLibrary( $remote_servers[$_POST['r_server_id']]['agent_ip'],
  131. $remote_servers[$_POST['r_server_id']]['agent_port'],
  132. $remote_servers[$_POST['r_server_id']]['encryption_key'],
  133. $remote_servers[$_POST['r_server_id']]['timeout'] );
  134. $remote->scheduler_del_task($_POST['job_id']);
  135. list($jobsArray, $remote_servers_offline) = reloadJobs($server_homes, $remote_servers);
  136. }
  137. echo "<h2>" . schedule_new_job . "</h2>";
  138. require_once("includes/refreshed.php");
  139. $refresh = new refreshed();
  140. $homeid_ip_port = isset($_POST['homeid_ip_port']) ? $_POST['homeid_ip_port'] : key($server_homes);
  141. $r_server_id = $server_homes[$homeid_ip_port]['remote_server_id'];
  142. $curtime = $refresh->add( "home.php?m=cron&p=thetime&r_server_id=$r_server_id&type=cleared" );
  143. echo "<pre class='log' ><table><tr><td>" . now .
  144. "&nbsp;</td><td><form action='' method='POST' >" . get_server_selector($server_homes, $homeid_ip_port, TRUE) .
  145. "</form></td></tr></table> <b style='font-size:1.4em;'>" . $refresh->getdiv($curtime) . "</b></pre>";
  146. ?>
  147. <form method="POST" >
  148. <table class="center hundred">
  149. <tr>
  150. <th>
  151. <?php echo minute; ?>
  152. </th>
  153. <th>
  154. <?php echo hour; ?>
  155. </th>
  156. <th>
  157. <?php echo day; ?>
  158. </th>
  159. <th>
  160. <?php echo month; ?>
  161. </th>
  162. <th>
  163. <?php echo day_of_the_week; ?>
  164. </th>
  165. <th>
  166. <?php echo action; ?>
  167. </th>
  168. <th>
  169. <?php echo user_games; ?>
  170. </th>
  171. </tr>
  172. <tr>
  173. <td style="width: 35px;" >
  174. <input style="width: 30px;" type="text" name="minute" value="*" />
  175. </td>
  176. <td style="width: 35px;" >
  177. <input style="width: 30px;" type="text" name="hour" value="*" />
  178. </td>
  179. <td style="width: 35px;" >
  180. <input style="width: 30px;" type="text" name="dayOfTheMonth" value="*" />
  181. </td>
  182. <td style="width: 35px;" >
  183. <input style="width: 30px;" type="text" name="month" value="*" />
  184. </td>
  185. <td style="width: 35px;" >
  186. <input style="width: 30px;" type="text" name="dayOfTheWeek" value="*" />
  187. </td>
  188. <td>
  189. <?php echo get_action_selector();?>
  190. </td>
  191. <td>
  192. <?php echo get_server_selector($server_homes, $homeid_ip_port);?>
  193. </td>
  194. <td style="width: 132px;">
  195. <input style="" type="submit" name="addJob" value="<?php echo add; ?>" />
  196. </td>
  197. </tr>
  198. </table>
  199. </form>
  200. <br>
  201. <h2><?php echo scheduled_jobs;?></h2>
  202. <?php
  203. if ( !empty($jobsArray) )
  204. {
  205. ?>
  206. <table class="center hundred">
  207. </tr>
  208. <tr>
  209. <th>
  210. <?php echo minute; ?>
  211. </th>
  212. <th>
  213. <?php echo hour; ?>
  214. </th>
  215. <th>
  216. <?php echo day; ?>
  217. </th>
  218. <th>
  219. <?php echo month; ?>
  220. </th>
  221. <th>
  222. <?php echo day_of_the_week; ?>
  223. </th>
  224. <th>
  225. <?php echo action; ?>
  226. </th>
  227. <th>
  228. <?php echo user_games; ?>
  229. </th>
  230. </tr>
  231. <?php
  232. $user_jobs = "";
  233. foreach( $jobsArray as $remote_server_id => $jobs )
  234. {
  235. foreach($jobs as $jobId => $job)
  236. {
  237. if(isset($job['action']))
  238. {
  239. 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'])){
  240. $uniqueStr = $job['home_id']."_".$job['ip']."_".$job['port'];
  241. }else if(hasValue($job['home_id'])){
  242. $uniqueStr = $job['home_id'];
  243. }
  244. if(hasValue(@$uniqueStr)){
  245. $user_jobs .= '<tr>
  246. <td style="width: 35px;" >
  247. <form method="POST" >
  248. <input style="width: 30px;" type="text" name="minute" value="'.$job['minute'].'" />
  249. </td>
  250. <td style="width: 35px;" >
  251. <input style="width: 30px;" type="text" name="hour" value="'.$job['hour'].'" />
  252. </td>
  253. <td style="width: 35px;" >
  254. <input style="width: 30px;" type="text" name="dayOfTheMonth" value="'.$job['dayOfTheMonth'].'" />
  255. </td>
  256. <td style="width: 35px;" >
  257. <input style="width: 30px;" type="text" name="month" value="'.$job['month'].'" />
  258. </td>
  259. <td style="width: 35px;" >
  260. <input style="width: 30px;" type="text" name="dayOfTheWeek" value="'.$job['dayOfTheWeek'].'" />
  261. </td>
  262. <td>
  263. '.get_action_selector($job['action'])."</td><td>".
  264. get_server_selector($server_homes, $uniqueStr).'
  265. </td>
  266. <td style="width: 132px;">
  267. <input type="hidden" name="job_id" value=\''.$jobId.'\' />
  268. <input type="hidden" name="r_server_id" value=\''.$remote_server_id.'\' />
  269. <input style="" type="submit" name="editJob" value="'. edit .'" />
  270. <input style="" type="submit" name="removeJob" value="'. remove .'" />
  271. </form>
  272. </td>
  273. </tr>';
  274. }
  275. }
  276. }
  277. }
  278. echo $user_jobs;
  279. ?>
  280. </table>
  281. <?php
  282. }
  283. else
  284. echo "<h3>". there_are_no_scheduled_jobs ."</h3>";
  285. ?>
  286. <table class='center hundred' ><tr><td><a href='javascript:history.go(-1)' > << <?php echo 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>
  287. <script type="text/javascript">
  288. $(document).ready(function()
  289. {
  290. <?php echo $refresh->build("1000"); ?>
  291. }
  292. );
  293. </script>
  294. <?php
  295. }
  296. ?>