Advertisement
Guest User

Untitled

a guest
Sep 6th, 2016
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 19.61 KB | None | 0 0
  1. <?php
  2. require_once("xmlapi.php");
  3. require_once("conexao.php");
  4.  
  5. error_reporting(E_ALL & ~E_NOTICE & ~E_DEPRECATED & ~E_WARNING);
  6. ini_set('display_errors', 0);
  7. header('Content-Type: text/html; charset=utf-8');
  8.  
  9. class lib {
  10. function __construct() {
  11. $this->con = new conexao();
  12. $this->pdo = $this->con->Connect();
  13. }
  14. function gerar_senha($tamanho, $maiusculas, $minusculas, $numeros, $simbolos){
  15. $ma = "ABCDEFGHIJKLMNOPQRSTUVYXWZ"; // $ma contem as letras maiusculas
  16. $mi = "abcdefghijklmnopqrstuvyxwz"; // $mi contem as letras minusculas
  17. $nu = "0123456789"; // $nu contem os numeros
  18. $si = "!@#$%¨&*()_+="; // $si contem os sibolos
  19. $senha = "";
  20.  
  21. if ($maiusculas){
  22. // se $maiusculas for "true", a variavel $ma é embaralhada e adicionada para a variavel $senha
  23. $senha .= str_shuffle($ma);
  24. }
  25.  
  26. if ($minusculas){
  27. // se $minusculas for "true", a variavel $mi é embaralhada e adicionada para a variavel $senha
  28. $senha .= str_shuffle($mi);
  29. }
  30.  
  31. if ($numeros){
  32. // se $numeros for "true", a variavel $nu é embaralhada e adicionada para a variavel $senha
  33. $senha .= str_shuffle($nu);
  34. }
  35.  
  36. if ($simbolos){
  37. // se $simbolos for "true", a variavel $si é embaralhada e adicionada para a variavel $senha
  38. $senha .= str_shuffle($si);
  39. }
  40.  
  41. // retorna a senha embaralhada com "str_shuffle" com o tamanho definido pela variavel $tamanho
  42. return substr(str_shuffle($senha),0,$tamanho);
  43. }
  44. function encrypt($string) {
  45. global $cc_encryption_hash;
  46.  
  47. $key = md5(md5($cc_encryption_hash)) . md5($cc_encryption_hash);
  48. $hash_key = $this->_hash($key);
  49. $hash_length = strlen($hash_key);
  50. $iv = $this->_generate_iv();
  51. $out = "";
  52. $c = 0;
  53.  
  54. while ($c < $hash_length) {
  55. $out .= chr(ord($iv[$c]) ^ ord($hash_key[$c]));
  56. ++$c;
  57. }
  58.  
  59. $key = $iv;
  60. $c = 0;
  61.  
  62. while ($c < strlen($string)) {
  63. if ($c != 0 && $c % $hash_length == 0) {
  64. $key = _hash($key . substr($string, $c - $hash_length, $hash_length));
  65. }
  66.  
  67. $out .= chr(ord($key[$c % $hash_length]) ^ ord($string[$c]));
  68. ++$c;
  69. }
  70.  
  71. $out = base64_encode($out);
  72. return $out;
  73. }
  74. function _generate_iv() {
  75. global $cc_encryption_hash;
  76.  
  77. srand((double)microtime() * 1000000);
  78. $iv = md5(strrev(substr($cc_encryption_hash, 13)) . substr($cc_encryption_hash, 0, 13));
  79. $iv .= rand(0, getrandmax());
  80. $iv .= serialize(array("key" => md5(md5($cc_encryption_hash)) . md5($cc_encryption_hash)));
  81. return $this->_hash($iv);
  82. }
  83. function _hash ($string){
  84. if (function_exists ('sha1'))
  85. {
  86. $hash = sha1 ($string);
  87. }
  88. else
  89. {
  90. $hash = md5 ($string);
  91. }
  92. $out = '';
  93. $c = 0;
  94. while ($c < strlen ($hash))
  95. {
  96. $out .= chr (hexdec ($hash[$c] . $hash[$c + 1]));
  97. $c += 2;
  98. }
  99. return $out;
  100. }
  101. function dadospainel_2($tabela){
  102. try {
  103. $stmt = $this->pdo->query("SELECT * FROM config");
  104. while ($linha = $stmt->fetch(PDO::FETCH_ASSOC)) {
  105. return "{$linha[$tabela]}";
  106. }
  107.  
  108. } catch (PDOException $ex) {
  109. echo "Erro: {$ex->getMessage()}, consulte um administrador";
  110. }
  111. }
  112.  
  113. function re_cp($pacote, $username, $password, $dominio, $email){
  114.  
  115. $ip_cp = $this->dadospainel_2("ipwhm");
  116. $login_cp = $this->dadospainel_2("loginwhm");
  117. $senha_cp = $this->dadospainel_2("senhawhm");
  118.  
  119. $xmlapi = new xmlapi($ip_cp);
  120. $xmlapi->set_port( 2086 );
  121. $xmlapi->password_auth($login_cp,$senha_cp);
  122. $xmlapi->set_debug(1);
  123.  
  124. $acct = array( plan => "$pacote", username => "$username", password => "$password", domain => "$dominio", contactemail => "$email");
  125. print $xmlapi->createacct($acct);
  126.  
  127. return true;
  128. }
  129. function enviar_ssh($comando){
  130. $hostname = $this->dadospainel_2("ipwhm");
  131. $senha_root = $this->dadospainel_2("senhawhm");
  132. if($ssh = ssh2_connect($hostname, "22")){
  133. }
  134. if(ssh2_auth_password ($ssh, 'root', $senha_root)){
  135. }
  136. $stream = ssh2_exec($ssh, $comando);
  137. stream_set_blocking ($stream, true);
  138. fclose($stream);
  139. return true;
  140. }
  141. function criadb($login, $senha, $dbnome){
  142. $ipcp = $this->dadospainel_2("ipwhm");
  143.  
  144. $xmlapi = new xmlapi($ipcp);
  145. $xmlapi->set_port( 2082 );
  146. $xmlapi->password_auth($login,$senha);
  147. $xmlapi->set_debug(1);
  148.  
  149.  
  150. $args5 = array(
  151. 'db' => $dbnome,
  152. );
  153.  
  154. $xmlapi->api2_query("usuario","MysqlFE","deletedb",$args5);
  155.  
  156.  
  157.  
  158.  
  159. $xmlapi->api1_query('usuario', 'Mysql', 'adddb', array('db'));
  160. }
  161. function extract_cms($cms, $login, $senha){
  162. $ipcp = $this->dadospainel_2("ipwhm");
  163.  
  164. $xmlapi = new xmlapi($ipcp);
  165. $xmlapi->set_port( 2082 );
  166. $xmlapi->password_auth($login,$senha);
  167. $xmlapi->set_debug(1);
  168.  
  169.  
  170.  
  171. $args1 = array(
  172. 'destfiles'=>'/public_html/',
  173. 'sourcefiles'=>'/public_html/'.$cms.'',
  174. 'op'=>'extract',
  175. 'doubledecode'=>'0',
  176. 'metadata'=>''
  177. );
  178.  
  179. $xmlapi->api2_query("usuario","Fileman","fileop",$args1);
  180.  
  181. $args2 = array(
  182. 'sourcefiles'=>'/public_html/'.$cms.'',
  183. 'op'=>'unlink',
  184. 'doubledecode'=>'0',
  185. 'metadata'=>''
  186. );
  187.  
  188. $xmlapi->api2_query("usuario","Fileman","fileop",$args2);
  189. }
  190. function re_db($login, $senha, $dbnome){
  191. $ipcp = $this->dadospainel_2("ipwhm");
  192.  
  193. $senha_root = $this->dadospainel_2("senhawhm");
  194. $this->criadb($login, $senha, $dbnome);
  195. $this->enviar_ssh('cd /home/sql; mysql -h localhost -u '.$login.' -p'.$senha.' -D '.$dbnome.' < plus.sql');
  196. return true;
  197. }
  198. function re_emu($ip_cp, $ip_emu, $login, $senha, $dbnome, $tcp, $mus){
  199. function removeTree($rootDir){
  200. if (!is_dir($rootDir))
  201. {
  202. return false;
  203. }
  204.  
  205. if (!preg_match("/\\/$/", $rootDir))
  206. {
  207. $rootDir .= '/';
  208. }
  209. }
  210.  
  211. $dir = 'C:/wamp/www/servidores/'.$login.'';
  212. removeTree($dir);
  213. $pastad = "C:/wamp/www/servidores/$login";//Criar pasta do emulador
  214. if(!is_dir($pastad)){//verifica se existe a pasta de destino
  215. mkdir($pastad,0777);//cria a pasta
  216. chmod($pastad,0777);//muda a perma
  217. }
  218. $dir = 'C:/VertrigoServ/www/'.$login.'';
  219. removeTree($dir);
  220. $pastad = "C:/VertrigoServ/www/$login";//Criar pasta do emulador
  221. if(!is_dir($pastad)){//verifica se existe a pasta de destino
  222. mkdir($pastad,0777);//cria a pasta
  223. chmod($pastad,0777);//muda a perma
  224. }
  225.  
  226. $zip = new ZipArchive;
  227. $res = $zip->open('C:/wamp/www/servidores/dlsak/plus.zip');
  228. if ($res === TRUE) {
  229. $zip->extractTo('C:/wamp/www/servidores/'.$login.'/');
  230. $zip->close();
  231. }
  232.  
  233. $zip = new ZipArchive;
  234. $res = $zip->open('C:/VertrigoServ/www/zak.zip');
  235. if ($res === TRUE) {
  236. $zip->extractTo('C:/VertrigoServ/www/'.$login.'/');
  237. $zip->close();
  238. }
  239.  
  240. // Configura o arquivo configuration.ini
  241. $nomearquivo = "C:/wamp/www/servidores/$login/config.ini";
  242. $conteudo = "## uberEmulator System Configuration File
  243. ## Must be edited for the server to work
  244.  
  245.  
  246. ## MySQL Configuration
  247. db.hostname=$ip_cp
  248. db.port=3306
  249. db.username=$login
  250. db.password=$senha
  251. db.name=$dbnome
  252.  
  253. ## MySQL pooling setup (controls amount of connections)
  254. db.pool.minsize=10
  255. db.pool.maxsize=250
  256.  
  257. ## Game TCP/IP Configuration
  258. game.tcp.bindip=$ip_emu
  259. game.tcp.port=$tcp
  260. game.tcp.conlimit=100000
  261. game.tcp.conperip=2
  262. game.tcp.enablenagles=true
  263.  
  264. ## MUS TCP/IP Configuration
  265. mus.tcp.bindip=$ip_emu
  266. mus.tcp.port=$mus
  267. mus.tcp.allowedaddr=$ip_emu;localhost;$ip_emu
  268.  
  269. # Camera configuration
  270. camera.path.preview=
  271. camera.path.purchased=
  272. camera.preview.maxcache=1000
  273.  
  274.  
  275. ## Client configuration
  276. client.ping.enabled=1
  277. client.ping.interval=20000
  278. client.maxrequests=300
  279.  
  280. ";
  281.  
  282. $fp = fopen("$nomearquivo", "w");
  283. $escreve = fwrite($fp, "$conteudo");
  284. fclose($fp);
  285.  
  286. $fp = fopen("C:/wamp/www/servidores/$login/allandesign.ini", "w");
  287. $escreve = fwrite($fp, "[AllanDesign]
  288. Emulador=$login.Emulator.exe");
  289. fclose($fp);
  290.  
  291. $cd = "CD C:/wamp/www/servidores/".$login;
  292.  
  293. $fp = fopen("C:/VertrigoServ/www/$login/desligar.bat", "w");
  294. $string = ''.$cd.''.PHP_EOL;
  295. $string .= 'TASKKILL /IM '.$login.'.Emulator.exe -f'.PHP_EOL;
  296. $escreve = fwrite($fp,$string);
  297. fclose($fp);
  298.  
  299. $ligapainelemulador = $login."painel";
  300.  
  301. $fp = fopen("C:/VertrigoServ/www/$login/ligar.bat", "w");
  302. $string = ''.$cd.''.PHP_EOL;
  303. $string .= 'start '.$ligapainelemulador.'.exe'.PHP_EOL;
  304. $escreve = fwrite($fp, $string);
  305. fclose($fp);
  306.  
  307. rename ("C:/wamp/www/servidores/$login/Paineldoemulador.exe", "C:/wamp/www/servidores/$login/$ligapainelemulador.exe");
  308. rename ("C:/wamp/www/servidores/$login/Plus Emulator.exe", "C:/wamp/www/servidores/$login/$login.Emulator.exe");
  309. rename ("C:/wamp/www/servidores/$login/Plus Emulator.exe.config", "C:/wamp/www/servidores/$login/$login.Emulator.exe.config");
  310. rename ("C:/wamp/www/servidores/$login/Plus Emulator.vshost.exe", "C:/wamp/www/servidores/$login/$login.Emulator.vshost.exe");
  311. rename ("C:/wamp/www/servidores/$login/Plus Emulator.pdb", "C:/wamp/www/servidores/$login/$login.Emulator.pdb");
  312. rename ("C:/wamp/www/servidores/$login/Plus Emulator.vshost.exe.config", "C:/wamp/www/servidores/$login/$login.Emulator.vshost.exe.config");
  313. rename ("C:/wamp/www/servidores/$login/Plus Emulator.vshost.exe.manifest", "C:/wamp/www/servidores/$login/$login.Emulator.vshost.exe.manifest");
  314.  
  315. }
  316. function liberar(){
  317.  
  318. $date = date('Y-m-d H:i');
  319. echo 'Atualizado pela ultima vez em '.$date.'';
  320.  
  321. if(!defined("MYSQL_HOST")){
  322. define('MYSQL_HOST', '149.56.69.7');
  323. }
  324. if(!defined("MYSQL_USER")){
  325. define('MYSQL_USER', 'meuhp');
  326. }
  327. if(!defined("MYSQL_PASSWORD")){
  328. define('MYSQL_PASSWORD', 'md68IaB1hp9c');
  329. }
  330. if(!defined("MYSQL_DB_NAME")){
  331. define('MYSQL_DB_NAME', 'meuhp_whmcs');
  332. }
  333.  
  334.  
  335. $username = $this->gerar_senha(8, false, true, false, false);
  336. $password = $this->gerar_senha(10, true, true, true, false);
  337. $dbnome = $username."_db";
  338.  
  339. $ip_cp = $this->dadospainel_2("ipwhm");
  340. $ip_emu = $this->dadospainel_2("ipemu");
  341.  
  342. $cc_encryption_hash='CVXf9P4oqyi1ilqITVNQoARkOauJOO9gzWmzChNSGWKO80nSM0z0qgb4hwEWaE2A';
  343.  
  344. $password_encripted = $this->encrypt ($password, $cc_encryption_hash);
  345.  
  346. $remote = new PDO('mysql:host=' . MYSQL_HOST . ';dbname=' . MYSQL_DB_NAME, MYSQL_USER, MYSQL_PASSWORD);
  347. $remote->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  348. $remote->exec("SET CHARACTER SET utf8");
  349.  
  350. $consulta = $remote->query("SELECT * FROM tblhosting WHERE sfp='ativar'");
  351. while ($ativar = $consulta->fetch(PDO::FETCH_ASSOC)){
  352. $dominio = "{$ativar['domain']}";
  353. $pacote = "{$ativar['packageid']}";
  354. $consulta_2 = $remote->query("SELECT * FROM tblinvoices WHERE id={$ativar['orderid']} and status='Paid'");
  355. while ($pago = $consulta_2->fetch(PDO::FETCH_ASSOC)){
  356. $remote->query("UPDATE tblhosting SET sfp='ativo' WHERE userid={$pago['userid']} and orderid='{$pago['id']}'");
  357. $remote->query("UPDATE tblhosting SET domainstatus='Active' WHERE userid={$pago['userid']} and orderid='{$pago['id']}'");
  358. $remote->query("UPDATE tblhosting SET username='$username' WHERE userid={$pago['userid']} and orderid='{$pago['id']}'");
  359. $remote->query("UPDATE tblhosting SET password='$password_encripted' WHERE userid={$pago['userid']} and orderid='{$pago['id']}'");
  360. $remote->query("UPDATE tblorders SET status='Active' WHERE userid={$pago['userid']} and invoiceid='{$pago['id']}'");
  361.  
  362. $consulta_3 = $remote->query("SELECT * FROM tblclients WHERE id={$pago['userid']}");
  363. while ($dados = $consulta_3->fetch(PDO::FETCH_ASSOC)){
  364. $email = "{$dados['email']}";
  365.  
  366. $consulta_4 = $stmt = $this->pdo->query("SELECT * FROM servidores ORDER BY `id` DESC LIMIT 1");
  367. while ($porta = $consulta_4->fetch(PDO::FETCH_ASSOC)){
  368. $tcp_h = $porta['tcp'];
  369. $mus_h = $porta['mus'];
  370. }
  371. $soma = "1";
  372. $tcp_h = $mus_h+$soma;
  373. $mus_h = $tcp_h+$soma;
  374. if($tcp_h == "1"){
  375. $tcp_h = "500";
  376. $mus_h = "501";
  377. }
  378. //Criar cPanel
  379. $this->re_cp($pacote, $username, $password, $dominio, $email);
  380. //Enviar CMS
  381. $this->enviar_ssh('cp /fpanel/heluar.zip /home/'.$username.'/public_html');
  382. //Extrair CMS
  383. $this->extract_cms("heluar.zip", $username, $password);
  384. //Reinstalar DB
  385. $this->re_db($username, $password, $dbnome);
  386. //Criar pasta temporaria
  387. $pastad = "./temp/$username";
  388. if(!is_dir($pastad)){
  389. mkdir($pastad,0777);
  390. chmod($pastad,0777);
  391. }
  392. //Enviar arquivo config da cms
  393. $nomearquivo = "./temp/$username/config.php";
  394.  
  395. $fp = fopen("$nomearquivo", "w");
  396.  
  397. $string = '<?php'.PHP_EOL;
  398. $string .= 'error_reporting(0);'.PHP_EOL;
  399. $string .= 'if(!defined("IN_INDEX")) { die("Sorry, you cannot access this file."); }'.PHP_EOL;
  400. $string .= 'date_default_timezone_set("America/Sao_Paulo");'.PHP_EOL;
  401. $string .= '$_CONFIG["mysql"]["connection_type"] = "pconnect";'.PHP_EOL;
  402. $string .= '$_CONFIG["mysql"]["hostname"] = "localhost";'.PHP_EOL;
  403. $string .= '$_CONFIG["mysql"]["username"] = "'.$username.'";'.PHP_EOL;
  404. $string .= '$_CONFIG["mysql"]["password"] = "'.$password.'";'.PHP_EOL;
  405. $string .= '$_CONFIG["mysql"]["database"] = "'.$dbnome.'";'.PHP_EOL;
  406. $string .= '$_CONFIG["mysql"]["port"] = "3306"; //MySQL"s port'.PHP_EOL;
  407. $string .= '$_CONFIG["hotel"]["server_ip"] = "'.$tcp_h.'";'.PHP_EOL;
  408. $string .= '$_CONFIG["hotel"]["url"] = "http://'.$dominio.'";'.PHP_EOL;
  409. $string .= '$_CONFIG["hotel"]["name"] = "Habbo";'.PHP_EOL;
  410. $string .= '$_CONFIG["hotel"]["desc"] = "Crie seu Quarto, Converse e faça novos amigos!";'.PHP_EOL;
  411. $string .= '$_CONFIG["hotel"]["email"] = "help@myhotel.net";'.PHP_EOL;
  412. $string .= '$_CONFIG["hotel"]["in_maint"] = false; // manutenção? se sim, coloque true, se não deixe false'.PHP_EOL;
  413. $string .= '$_CONFIG["hotel"]["motto"] = "I <3 " . $_CONFIG["hotel"]["name"];'.PHP_EOL;
  414. $string .= '$_CONFIG["hotel"]["credits"] = 5000; //moedas iniciais'.PHP_EOL;
  415. $string .= '$_CONFIG["hotel"]["pixels"] = 3500; //duckets/pixels iniciais'.PHP_EOL;
  416. $string .= '$_CONFIG["hotel"]["figure"] = "hd-180-7.wa-2007-0.sh-305-62.ha-1002-70.lg-270-79.ch-215-66.hr-100-0";'.PHP_EOL;
  417. $string .= '$_CONFIG["hotel"]["web_build"] = "9901";'.PHP_EOL;
  418. $string .= '$_CONFIG["hotel"]["external_vars"] = "a";'.PHP_EOL;
  419. $string .= '$_CONFIG["hotel"]["external_texts"] = "a";'.PHP_EOL;
  420. $string .= '$_CONFIG["hotel"]["product_data"] = "a";'.PHP_EOL;
  421. $string .= '$_CONFIG["hotel"]["furni_data"] = "a"; '.PHP_EOL;
  422. $string .= '$_CONFIG["hotel"]["swf_folder"] = "a";'.PHP_EOL;
  423. $string .= '$_CONFIG["template"]["style"] = "Habbo";'.PHP_EOL;
  424. $string .= '$_CONFIG["template"]["theme"] = "Habbo";'.PHP_EOL;
  425. $string .= '$_CONFIG["thehabbos"]["username"] = "Kryptos";'.PHP_EOL;
  426. $string .= '$_CONFIG["retro_top"]["user"] = "Kryptos";'.PHP_EOL;
  427. $string .= '$_CONFIG["recaptcha"]["priv_key"] = "6LcZ58USAAAAABSV5px9XZlzvIPaBOGA6rQP2G43";'.PHP_EOL;
  428. $string .= '$_CONFIG["recaptcha"]["pub_key"] = "6LcZ58USAAAAAAQ6kquItHl4JuTBWs-5cSKzh6DD";'.PHP_EOL;
  429. $string .= '$_CONFIG["social"]["twitter"] = "TwitterAccount"; //Hotel"s Twitter account'.PHP_EOL;
  430. $string .= '$_CONFIG["social"]["facebook"] = "FacebookAccount"; //Hotel"s Facebook account'.PHP_EOL;
  431. $string .= 'foreach($_REQUEST as $key => $value){'.PHP_EOL;
  432. $string .= '$_REQUEST[$key] = htmlspecialchars($value, ENT_QUOTES);'.PHP_EOL;
  433. $string .= '}'.PHP_EOL;
  434. $string .= '?>'.PHP_EOL;
  435.  
  436. $escreve = fwrite($fp,$string);
  437. fclose($fp);
  438.  
  439. //Enviar config da cms
  440. $file = 'temp/'.$username.'/config.php';//tobe uploaded
  441. $remote_file = '/public_html/app/management/config.php';
  442.  
  443. // set up basic connection
  444. $conn_id = ftp_connect($ip_cp);
  445.  
  446. // login with username and password
  447. $login_result = ftp_login($conn_id, $username, $password);
  448.  
  449. // upload a file
  450. if (ftp_put($conn_id, $remote_file, $file, FTP_ASCII));
  451. // close the connection
  452. ftp_close($conn_id);
  453. //Reinstalar emulador
  454. $this->re_emu($ip_cp, $ip_emu, $username, $password, $dbnome, $tcp_h, $mus_h);
  455.  
  456. $e = $this->pdo->query("INSERT INTO servidores (loginp, senhap, loginc, senhac, tituloh, versao, email, hostname, dbporta, dbnome, tcp, mus, siteurl, status, suspenso, ligado, pacote, dono, subconta) VALUES
  457. ('$username', '$password', '$username', '$password', 'Habbo', 'Plus', '$email', '$ip_cp', '3306', '$dbnome', '$tcp_h', '$mus_h', '$dominio', '0', '0', '', '$pacote', 'admin', '0')");
  458. $emulador = $e->fetch(PDO::FETCH_ASSOC);
  459.  
  460. $c = $this->pdo->query("INSERT INTO comandos (subconta, config, reinstalar, painel, backup, emulador, dono) VALUES
  461. ('1', '1', '1', '1', '1', '1', '$username')");
  462. $comandos = $c->fetch(PDO::FETCH_ASSOC);
  463.  
  464. $dir = './temp/'.$username.'';
  465. removeTree($dir);
  466. }
  467. }
  468. }
  469. }
  470. }
  471. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement