cron-shop.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. <?php
  2. /*
  3. *
  4. * OGP - Open Game Panel
  5. * Copyright (C) 2008 - 2017 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. chdir(realpath(dirname(__FILE__))); /* Change to the current file path */
  25. chdir("../.."); /* Base path to ogp web files */
  26. // Report all PHP errors
  27. error_reporting(E_ALL);
  28. // Path definitions
  29. define("CONFIG_FILE","includes/config.inc.php");
  30. //Requiere
  31. require_once("includes/functions.php");
  32. require_once("includes/helpers.php");
  33. require_once("includes/html_functions.php");
  34. require_once("modules/config_games/server_config_parser.php");
  35. require_once("includes/lib_remote.php");
  36. require_once CONFIG_FILE;
  37. // Connect to the database server and select database.
  38. $db = createDatabaseConnection($db_type, $db_host, $db_user, $db_pass, $db_name, $table_prefix);
  39. $panel_settings = $db->getSettings();
  40. if( isset($panel_settings['time_zone']) && $panel_settings['time_zone'] != "" )
  41. date_default_timezone_set($panel_settings['time_zone']);
  42. $today=date('YmdHi');
  43. $user_homes = $db->resultQuery( "SELECT *
  44. FROM " . $table_prefix . "billing_orders
  45. WHERE end_date>0 AND end_date<".$today );
  46. if (!is_array($user_homes))
  47. {
  48. echo "Nothing to do.\n";
  49. }
  50. else
  51. {
  52. foreach($user_homes as $user_home)
  53. {
  54. $user_id = $user_home['user_id'];
  55. $home_id = $user_home['home_id'];
  56. $home_info = $db->getGameHomeWithoutMods($home_id);
  57. $server_info = $db->getRemoteServerById($home_info['remote_server_id']);
  58. $remote = new OGPRemoteLibrary($server_info['agent_ip'], $server_info['agent_port'], $server_info['encryption_key'],$server_info['timeout']);
  59. $ftp_login = isset($home_info['ftp_login']) ? $home_info['ftp_login'] : $home_id;
  60. $remote->ftp_mgr("userdel", $ftp_login);
  61. $db->changeFtpStatus('disabled',$home_id);
  62. $server_xml = read_server_config(SERVER_CONFIG_LOCATION."/".$home_info['home_cfg_file']);
  63. if(isset($server_xml->control_protocol_type))$control_type = $server_xml->control_protocol_type; else $control_type = "";
  64. $addresses = $db->getHomeIpPorts($home_id);
  65. foreach($addresses as $address)
  66. {
  67. $remote->remote_stop_server($home_id,$address['ip'],$address['port'],$server_xml->control_protocol,$home_info['control_password'],$control_type,$home_info['home_path']);
  68. }
  69. $db->unassignHomeFrom("user", $user_id, $home_id);
  70. // Reset the invoice end date
  71. $db->query( "UPDATE " . $table_prefix . "billing_orders
  72. SET end_date=-1
  73. WHERE order_id=".$db->realEscapeSingle($user_home['order_id']));
  74. echo "Home ID $home_id unassigned succesfull.";
  75. }
  76. }
  77. $user_homes = $db->resultQuery( "SELECT *
  78. FROM " . $table_prefix . "billing_orders
  79. WHERE end_date=-1 AND finish_date>0 AND finish_date<".$today );
  80. if (!is_array($user_homes))
  81. {
  82. echo "Any server finishes now.";
  83. }
  84. else
  85. {
  86. foreach($user_homes as $user_home)
  87. {
  88. $user_id = $user_home['user_id'];
  89. $home_id = $user_home['home_id'];
  90. $home_info = $db->getGameHomeWithoutMods($home_id);
  91. $server_info = $db->getRemoteServerById($home_info['remote_server_id']);
  92. $remote = new OGPRemoteLibrary($server_info['agent_ip'], $server_info['agent_port'], $server_info['encryption_key'],$server_info['timeout']);
  93. // Remove the game home from db
  94. $db->deleteGameHome($home_id);
  95. // Remove the game home files from remote server
  96. $remote->remove_home($home_info['home_path']);
  97. // Set order as not installed
  98. $db->query( "UPDATE " . $table_prefix . "billing_orders
  99. SET home_id=0
  100. WHERE cart_id=".$db->realEscapeSingle($ipn['item_number']));
  101. // Reset the invoice end date
  102. $db->query( "UPDATE " . $table_prefix . "billing_orders
  103. SET end_date=-2
  104. WHERE order_id=".$db->realEscapeSingle($user_home['order_id']));
  105. $db->query( "UPDATE " . $table_prefix . "billing_orders
  106. SET finish_date=-2
  107. WHERE order_id=".$db->realEscapeSingle($user_home['order_id']));
  108. echo "Home ID $home_id finished completely.";
  109. }
  110. }
  111. ?>