del_home.php 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  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. function logHandling($home_id, $action = 'delete', &$remote){
  25. $fileId = str_pad($home_id, 9, '0', STR_PAD_LEFT);
  26. $files = array(
  27. 'screenlogs/screenlog.OGP_HOME_'.$fileId => 'file',
  28. 'screenlogs/screenlog.OGP_UPDATE_'.$fileId => 'file',
  29. 'screenlogs/home_id_'.$home_id.'/' => 'dir',
  30. );
  31. if($action == 'backup'){
  32. $remote->exec('tar czf screenlogs/home_log_backup_'.$home_id.'.tar.gz '.implode(' ', array_keys($files)));
  33. }
  34. foreach($files as $file => $type){
  35. if($remote->rfile_exists($file)){
  36. if($type == 'file'){
  37. $remote->exec('rm '.$file);
  38. }
  39. if($type == 'dir'){
  40. $remote->exec('rm -r '.$file);
  41. }
  42. }
  43. }
  44. }
  45. function exec_ogp_module() {
  46. global $db, $view;
  47. require_once('includes/lib_remote.php');
  48. $home_id = $_GET['home_id'];
  49. $y = isset($_GET['y']) ? $_GET['y'] : "";
  50. $files = isset($_GET['files']) ? $_GET['files'] : "";
  51. $force = isset($_GET['force']) ? $_GET['force'] : "";
  52. $logAction = !empty($_GET['logAction']) ? $_GET['logAction'] : false;
  53. $home_info = $db->getGameHomeWithoutMods($home_id);
  54. if( $home_info === FALSE )
  55. {
  56. print_failure("User home_id $home_id not found.");
  57. $view->refresh("?m=user_games");
  58. return;
  59. }
  60. $remote = new OGPRemoteLibrary($home_info['agent_ip'], $home_info['agent_port'], $home_info['encryption_key'], $home_info['timeout']);
  61. $agent_online = $remote->status_chk() === 1;
  62. if($y != 'y')
  63. {
  64. echo "<p>".get_lang_f('sure_to_delete_serverid_from_remoteip_and_directory',
  65. $home_info['home_id'], $home_info['agent_ip'], $home_info['home_path'])."</p>";
  66. if($agent_online)
  67. {
  68. $r = $remote->rfile_exists($home_info['home_path']);
  69. if($r == 1)
  70. {
  71. echo "<p><a href=\"?m=user_games&amp;p=del&amp;y=y&amp;home_id=$home_id&amp;files=y\" id=\"deleteLink\">" .
  72. get_lang("yes_and_delete_the_files") . "</a> ";
  73. echo '<input type="checkbox" name="logAction" id="doBackup"><label for="doBackup">Delete and Backup Logs</label> |';
  74. }
  75. }
  76. else
  77. print_failure(get_lang("agent_offline") . " " . get_lang("remove_it_anyway") . "?");
  78. echo "<a href=\"?m=user_games&amp;p=del&amp;y=y&amp;home_id=$home_id\">".
  79. get_lang("yes") . "</a> | <a href=\"?m=user_games\">".
  80. get_lang("no") . "</a></p>";
  81. // Not the prettiest way to do this...
  82. echo '<script>
  83. $(function(){
  84. var linkElement = $("#deleteLink"),
  85. defaultLink = linkElement.attr("href"),
  86. newLink = linkElement.attr("href");
  87. $("#doBackup").change(function(){
  88. if($(this).is(":checked")){
  89. linkElement.attr("href", newLink + "&logAction=backup");
  90. }else{
  91. linkElement.attr("href", defaultLink);
  92. }
  93. });
  94. });
  95. </script>';
  96. return;
  97. }
  98. if ( $db->IsFtpEnabled($home_id) and $force != 'y' and $agent_online )
  99. {
  100. $ftp_login = isset($home_info['ftp_login']) ? $home_info['ftp_login'] : $home_id;
  101. if ( $remote->ftp_mgr("userdel", $ftp_login) === 0 )
  102. {
  103. $del_files = $files == 'y' ? '&amp;files=y' : '';
  104. print_failure(get_lang("failed_to_remove_ftp_account_from_remote_server"));
  105. echo "<p>" . get_lang("remove_it_anyway") . "<p>
  106. <a href=\"?m=user_games&amp;p=del&amp;y=y&amp;force=y&amp;home_id=$home_id$del_files\">".
  107. get_lang("yes") . "</a> | <a href=\"?m=user_games\">".
  108. get_lang("no") . "</a></p>";
  109. return;
  110. }
  111. }
  112. if($y == 'y')
  113. {
  114. if($agent_online)
  115. {
  116. $assigned = $db->getHomeIpPorts($home_id);
  117. if( !empty($assigned) )
  118. {
  119. foreach($assigned as $address)
  120. {
  121. if($remote->rfile_exists( "startups/".$address['ip']."-".$address['port'] ) === 1)
  122. {
  123. require_once("modules/gamemanager/home_handling_functions.php");
  124. require_once("modules/config_games/server_config_parser.php");
  125. exec_operation('stop', $home_id, FALSE, $address['ip'], $address['port']);
  126. break;
  127. }
  128. }
  129. if($logAction && is_numeric($home_id)){
  130. logHandling($home_id, $logAction, $remote);
  131. }
  132. }
  133. }
  134. // Delete cronjobs
  135. if(file_exists('modules/cron/shared_cron_functions.php')){
  136. require_once('modules/cron/shared_cron_functions.php');
  137. if(function_exists("deleteJobsByHomeServerID")){
  138. deleteJobsByHomeServerID($home_id);
  139. }
  140. }
  141. if ( $db->deleteGameHome($home_id) === FALSE )
  142. {
  143. print_failure(get_lang("failed_to_remove_gamehome_from_database"));
  144. return;
  145. }
  146. else
  147. {
  148. print_success(get_lang_f('successfully_deleted_game_server_with_id', $home_info['home_id']));
  149. $db->logger(get_lang_f('successfully_deleted_game_server_with_id', $home_info['home_id']));
  150. }
  151. }
  152. if($files == 'y' and $agent_online)
  153. {
  154. if($remote->remove_home($home_info['home_path']) == 1)
  155. {
  156. print_success(get_lang_f('sucessfully_deleted', $home_info['home_path']));
  157. $db->logger(get_lang_f('sucessfully_deleted', $home_info['home_path']));
  158. }
  159. else
  160. {
  161. print_failure(get_lang_f('the_agent_had_a_problem_deleting', $home_info['home_path']));
  162. }
  163. }
  164. $view->refresh("?m=user_games");
  165. }
  166. ?>