restart.php 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. require_once('includes/lib_remote.php');
  25. function exec_ogp_module() {
  26. global $view;
  27. global $db;
  28. echo "<h2>". get_lang("restart") ."</h2>";
  29. $rhost_id = @$_REQUEST['rhost_id'];
  30. $remote_server = $db->getRemoteServer($rhost_id);
  31. $remote = new OGPRemoteLibrary($remote_server['agent_ip'], $remote_server['agent_port'], $remote_server['encryption_key'], $remote_server['timeout']);
  32. if(isset($_GET['refresh']))
  33. {
  34. $host_stat = $remote->status_chk();
  35. if($host_stat === 0)
  36. {
  37. echo get_lang("restarting"); # "Restarting agent... Please wait."
  38. $view->refresh("?m=server&p=restart&rhost_id=".$rhost_id."&refresh",5);
  39. }
  40. else
  41. {
  42. $remote->remote_readfile( "screenlogs/screenlog.agent_restart", $restart_log );
  43. echo "<pre class='log'><xmp>".$restart_log."</xmp></pre>";
  44. $remote->remote_readfile( "screenlogs/screenlog.ogp_agent", $agent_log );
  45. if($agent_log == "")
  46. {
  47. $view->refresh("?m=server&p=restart&rhost_id=".$rhost_id."&refresh",5);
  48. }
  49. else
  50. {
  51. echo "<pre class='log'><xmp>".$agent_log."</xmp></pre>";
  52. print_success( get_lang("restarted") );
  53. echo create_back_button($_GET['m']);
  54. $view->refresh("?m=server",15);
  55. }
  56. }
  57. }
  58. // Confirm user wants to reboot the server
  59. else if (!isset($_POST['re_check'])) {
  60. $ipAndName = $remote_server['remote_server_name'] . " " . "(" . $remote_server['agent_ip'] . ")";
  61. echo "<table class='center' style='width:100%;' ><tr>\n" . "<td>".
  62. get_lang_f('confirm_restart', $ipAndName) . "</td>" . "</tr><tr><td>".
  63. '<form method="post" >' . "\n" . '<input type="hidden" name="rhost_id" value="'.
  64. $rhost_id . '">' . "\n" . '<button name="re_check" value="yes" >'.
  65. get_lang("yes") . "</button>\n" . '<button name="re_check" value="no" >'.
  66. get_lang("no") . "</button>\n" . "</form>\n" . "</td>\n" . "</tr>\n" . "</table><br>\n";
  67. } else if($_POST['re_check'] == "yes") {
  68. // Confirmed... so restart the agent
  69. $remote->exec( "if [ -e 'screenlogs/screenlog.agent_restart' ]; then rm -f 'screenlogs/screenlog.agent_restart'; fi && ".
  70. "if [ -e 'screenlogs/screenlog.ogp_agent' ]; then rm -f 'screenlogs/screenlog.ogp_agent'; fi" );
  71. $file_info = $remote->agent_restart();
  72. // 5 seconds should be enough for the agent to come back up
  73. echo get_lang("restarting"); # "Restarting agent... Please wait."
  74. $view->refresh("?m=server&p=restart&rhost_id=".$rhost_id."&refresh", 5);
  75. } else if ($_POST['re_check'] == "no"){
  76. $view->refresh("?m=server",0);
  77. }
  78. }
  79. ?>