user_cron.php 9.5 KB

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