Advertisement
iaretechnician

cron-shop.php

Aug 19th, 2019
520
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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.  
  25. chdir(realpath(dirname(__FILE__))); /* Change to the current file path */
  26. chdir("../.."); /* Base path to ogp web files */
  27. // Report all PHP errors
  28. //error_reporting(E_ALL);
  29. // Path definitions
  30. define("CONFIG_FILE","includes/config.inc.php");
  31. //Requiere
  32. require_once("includes/functions.php");
  33. require_once("includes/helpers.php");
  34. require_once("includes/html_functions.php");
  35. require_once("modules/config_games/server_config_parser.php");
  36. require_once("includes/lib_remote.php");
  37. require_once CONFIG_FILE;
  38. // Connect to the database server and select database.
  39. $db = createDatabaseConnection($db_type, $db_host, $db_user, $db_pass, $db_name, $table_prefix);
  40.  
  41. $panel_settings = $db->getSettings();
  42. if( isset($panel_settings['time_zone']) && $panel_settings['time_zone'] != "" )
  43.     date_default_timezone_set($panel_settings['time_zone']);
  44.  
  45. //set the dates to compare to db end_dates
  46. $today=date('YmdHi');
  47. //7 days from today if server expires (end_date)
  48. $invoice_date = date('YmdHi',strtotime('+ 7 days'));
  49. //suspend the server on the end_date by comparing to finish_date which is +5
  50. $suspend_date = date('YmdHi',strtotime('+ 5 days'));
  51. //5 days ago server expired(finish_date)
  52. $removal_date = date('YmdHi',strtotime(' -5 days'));
  53.  
  54. //Create invoice 7 days before server expires.
  55. $user_homes = $db->resultQuery( "SELECT *
  56.                                  FROM " . $table_prefix .  "billing_orders  
  57.                                  WHERE end_date>0 AND end_date<".$invoice_date);
  58.                                  
  59. if (!is_array($user_homes))
  60. {
  61.     echo "Nothing to do\n";
  62. }
  63. else
  64. {
  65.     foreach($user_homes as $user_home)
  66.     {
  67.        
  68.         // Reset the invoice end date -1 so cart.php will create an invoice
  69.         $db->query( "UPDATE " . $table_prefix . "billing_orders
  70.                      SET end_date=-1
  71.                      WHERE order_id=".$db->realEscapeSingle($user_home['order_id']));
  72.                      
  73.         echo "Invoice enabled for ". $user_home['home_id']." \n";
  74.     }
  75. }
  76.  
  77. //Order has expired. Suspend the server
  78. $user_homes = $db->resultQuery( "SELECT *
  79.                                  FROM " . $table_prefix .  "billing_orders  
  80.                                  WHERE end_date=-1 AND finish_date<".$suspend_date);
  81.                                  
  82. if (!is_array($user_homes))
  83. {
  84.     echo "Nothing to do\n";
  85. }
  86. else
  87. {
  88.     foreach($user_homes as $user_home)
  89.     {
  90.         $user_id = $user_home['user_id'];
  91.         $home_id = $user_home['home_id'];
  92.         $home_info = $db->getGameHomeWithoutMods($home_id);
  93.         $server_info = $db->getRemoteServerById($home_info['remote_server_id']);
  94.         $remote = new OGPRemoteLibrary($server_info['agent_ip'], $server_info['agent_port'], $server_info['encryption_key'],$server_info['timeout']);
  95.         $ftp_login = isset($home_info['ftp_login']) ? $home_info['ftp_login'] : $home_id;
  96.         $remote->ftp_mgr("userdel", $ftp_login);
  97.         $db->changeFtpStatus('disabled',$home_id);
  98.         $server_xml = read_server_config(SERVER_CONFIG_LOCATION."/".$home_info['home_cfg_file']);
  99.         if(isset($server_xml->control_protocol_type))$control_type = $server_xml->control_protocol_type; else $control_type = "";
  100.         $addresses = $db->getHomeIpPorts($home_id);
  101.         foreach($addresses as $address)
  102.         {  
  103.             $remote->remote_stop_server($home_id,$address['ip'],$address['port'],$server_xml->control_protocol,$home_info['control_password'],$control_type,$home_info['home_path']);
  104.         }
  105.         $db->unassignHomeFrom("user", $user_id, $home_id);
  106.                              
  107.         // Reset the invoice end date
  108.         $db->query( "UPDATE " . $table_prefix . "billing_orders
  109.                      SET end_date=-1
  110.                      WHERE order_id=".$db->realEscapeSingle($user_home['order_id']));
  111.                      
  112.         echo "Server Expired $home_id unassigned succesfully\n";
  113.     }
  114. }
  115.  
  116. //5 days after expiration we remove the server
  117. $user_homes = $db->resultQuery( "SELECT *
  118.                                  FROM " . $table_prefix .  "billing_orders  
  119.                                  WHERE end_date=-1 AND finish_date>0 AND finish_date<".$removal_date );
  120.                                  
  121. if (!is_array($user_homes))
  122. {
  123.     echo "No servers finished\n";
  124. }
  125. else
  126. {
  127.     foreach($user_homes as $user_home)
  128.     {
  129.         $user_id = $user_home['user_id'];
  130.         $home_id = $user_home['home_id'];
  131.         $home_info = $db->getGameHomeWithoutMods($home_id);
  132.         $server_info = $db->getRemoteServerById($home_info['remote_server_id']);
  133.         $remote = new OGPRemoteLibrary($server_info['agent_ip'], $server_info['agent_port'], $server_info['encryption_key'],$server_info['timeout']);
  134.                
  135.         // Remove the game home from db
  136.         $db->deleteGameHome($home_id);
  137.        
  138.         // Remove the game home files from remote server
  139.         $remote->remove_home($home_info['home_path']);
  140.        
  141.         // Set order as not installed
  142.         $db->query( "UPDATE " . $table_prefix . "billing_orders
  143.                      SET home_id=0
  144.                      WHERE cart_id=".$db->realEscapeSingle($user_home['cart_id']));
  145.                      
  146.         // Reset the invoice end date
  147.         $db->query( "UPDATE " . $table_prefix . "billing_orders
  148.                      SET end_date=-2
  149.                      WHERE order_id=".$db->realEscapeSingle($user_home['order_id']));
  150.                      
  151.         $db->query( "UPDATE " . $table_prefix . "billing_orders
  152.                      SET finish_date=-2
  153.                      WHERE order_id=".$db->realEscapeSingle($user_home['order_id']));
  154.                      
  155.         echo "Server $home_id removed completely";
  156.     }
  157. }
  158. ?>
Advertisement
RAW Paste Data Copied
Advertisement