blib/lib/WWW/Kinghost/Painel.pm untested

filter: Statementstmt 0.0% 0 / 769 Branchbran 0.0% 0 / 224 Conditioncond 0.0% 0 / 99 MC/DCmcdc 0.0% 0 / 55 Subroutinesub 0.0% 0 / 35 Podpod 0.0% 0 / 25 totaltotal 0.0% 0 / 1207 CC 113 SCAR 43.2
CC
113
Cov
0%
transfereDominio
210.0
importaFTPExterno
132.0
novaCaixaEmail
110.0
CRAP 74.9
1 package WWW::Kinghost::Painel;
2  
3 use strict qw(vars);
4 use vars qw($VERSION) ;
5 use warnings 'all';
6 use utf8;
7 use WWW::Mechanize;
8 use HTML::TreeBuilder::XPath;
9 use HTML::Entities;
10 use JSON;
11 use DBI;
12 use Net::FTP;
13
14 $VERSION = '0.04' ;
15
16 my $statusLogin;
17 my $statusLoginV1;
18 my $statusLoginRegistro;
19 my $entitieschars;
20 my $mech;
21
22 sub new
23 {
24 my $class = shift;
25 my $self = {
26  
27 };
28
29 $statusLogin = 0;
30 $entitieschars = 'ÁÍÓÚÉÄÏÖÜËÀÌÒÙÈÃÕÂÎÔÛÊáíóúéäïöüëàìòùèãõâîôûêÇç';
31 $mech = WWW::Mechanize->new;
32 $mech->agent_alias( 'Windows IE 6' );
33
34 bless $self, $class;
35 return $self, $class;
36 }
37
38 sub erro
39 {
40 my($self, $strErro) = @_;
41 my %resposta = (
42 status => "erro",
43 resposta => $strErro,
44 );
45 my $json = \%resposta;
46 my $json_text = to_json($json, { utf8 => 1 });
47 print $json_text;
48 exit;
49 }
50
51 sub erroFTP
52 {
53 my($self, $strErro, $ftperror) = @_;
54 my %resposta = (
55 status => "erro",
56 resposta => $strErro,
57 msgftp => $ftperror,
58 );
59 my $json = \%resposta;
60 my $json_text = to_json($json, { utf8 => 1 });
61 return $json_text;
62 exit;
63 }
64
65 sub logar
66 {
67 my($self, $email, $senha) = @_;
68 my $html;
69 $mech->post("https://painel2.kinghost.net/login.php");
70 if($mech->success())
71 {
72 if($mech->status() == 200)
73 {
74 # loga no painel
75 $mech->submit_form(
76 form_id => "formLogin",
77 fields => {
78 email => $email,
79 senha => $senha,
80 }
81 );
82 $html = $mech->content;
83 $mech->update_html( $html );
84 my $tree = HTML::TreeBuilder::XPath->new;
85 $tree->parse( $html );
86 # resposta da tentiva de cadastro
87 my $respostaloga = $tree->findnodes( '//body' )->[0]->as_HTML;
88
89 if(index($respostaloga, "abaixo para acessar o Painel de Controle") == -1)
90 {
91 $statusLogin = 1;
92 return "logged";
93 }
94 else
95 {
96 return "invalid login";
97 }
98 }
99 elsif($mech->status() == 404)
100 {
101 return "not found";
102 }
103 else
104 {
105 return "unknow HTTP error";
106 }
107 }
108 else
109 {
110 return "connection error";
111 }
112 }
113
114
115 sub logarV1
116 {
117 my($self, $email, $senha) = @_;
118 my $html;
119 $mech->get("https://painel.kinghost.net/login.php");
120 if($mech->success())
121 {
122 if($mech->status() == 200)
123 {
124 # loga no painel
125 $mech->submit_form(
126 form_id => "formLogin",
127 fields => {
128 email => $email,
129 senha => $senha,
130 }
131 );
132 $html = $mech->content;
133 $mech->update_html( $html );
134 my $tree = HTML::TreeBuilder::XPath->new;
135 $tree->parse( $html );
136 # resposta da tentiva de cadastro
137 my $respostaloga = $tree->findnodes( '//body' )->[0]->as_HTML;
138
139 if(index($respostaloga, "abaixo para acessar o Painel de Controle") == -1)
140 {
141 $statusLoginV1 = 1;
142 return "logged";
143 }
144 else
145 {
146 return "invalid login";
147 }
148 }
149 elsif($mech->status() == 404)
150 {
151 return "not found";
152 }
153 else
154 {
155 return "unknow HTTP error";
156 }
157 }
158 else
159 {
160 return "connection error";
161 }
162 }
163
164
165 sub novoCliente
166 {
167 my($self, $empresa, $nome, $tipoPessoa, $cpfcnpj, $email, $emailcobranca, $senha, $senhaConfimacao, $telefone, $fax, $cep, $endereco, $cidade, $estado) = @_;
168 my %resposta;
169 if($statusLogin)
170 {
171 my $html;
172 my $table_rows;
173
174 # cria cliente
175 $mech->post("https://painel2.kinghost.net/cliente.php?editar");
176 $mech->submit_form(
177 form_id => "formEdit",
178 fields => {
179 acao => "sub_cliente",
180 subacao => "edita",
181 id_sub_cliente => 0,
182 'dados[TipoPessoa]' => $tipoPessoa,
183 'dados[CpfCnpj]' => $cpfcnpj,
184 'dados[Empresa]' => encode_entities($empresa, $entitieschars),
185 'dados[Nome]' => encode_entities($nome, $entitieschars),
186 'dados[Email]' => $email, # nao pode repetir
187 'dados[EmailCobranca]' => $emailcobranca, # nao pode repetir
188 'dados[SenhaPainel]' => $senha,
189 'senha1' => $senhaConfimacao,
190 'dados[Fone]' => $telefone,
191 'dados[Fax]' => $fax,
192 'dados[CEP]' => $cep,
193 'dados[Endereco]' => $endereco,
194 'dados[Cidade]' => $cidade,
195 'dados[Estado]' => $estado,
196 'dados[LimiteMapeamento]' => 1,
197 'dados[LimiteSubdominio]' => 1,
198 'dados[LimiteMysql]' => 1,
199 'dados[LimiteMssql]' => 0,
200 'dados[LimitePgsql]' => 1,
201 'dados[LimiteFirebird]' => 0,
202 'dados[LimiteFTPADD]' => 0,
203 'dados[UniBox]' => "INATIVO",
204 'dados[AcessoFTP]' => "INATIVO",
205 'dados[AcessoDownloadBackup]' => "INATIVO",
206 'dados[AcessoLogotipoWebmail]' => "INATIVO",
207 'dados[AcessoCupomGoogleAdwords]' => "ATIVO",
208 }
209 );
210 if($mech->success())
211 {
212 if($mech->status() == 200)
213 {
214 $html = $mech->content;
215 $mech->update_html( $html );
216 my $tree = HTML::TreeBuilder::XPath->new;
217 $tree->parse( $html );
218 # resposta da tentiva de cadastro
219 my $respostaSalvaCliente = $tree->findnodes( '//body' )->[0]->as_HTML;
220 # salvo
221 if(index($respostaSalvaCliente, "Cliente") != -1 && index($respostaSalvaCliente, "Salvo") != -1)
222 {
223 $mech->get("https://painel2.kinghost.net/cliente.php");
224 $html = $mech->content;
225 $mech->update_html( $html );
226
227 my $tree = HTML::TreeBuilder::XPath->new;
228 $tree->parse( $html );
229
230 $table_rows = $tree->findnodes( '//table[@class="default tralt"]/tr' );
231
232 foreach my $row ( $table_rows->get_nodelist )
233 {
234 my $tree_tr = HTML::TreeBuilder::XPath->new;
235 $tree_tr->parse( $row->as_HTML );
236
237 my $empresaR = $tree_tr->findvalue( '//td[1]' );
238 my $nomeR = $tree_tr->findvalue( '//td[2]' );
239 my $linkR = $tree_tr->findvalue( '//td[4]//a[1]' );
240 my $codigo = $row->as_HTML;
241 if(index($nomeR, $nome) != -1)
242 {
243 my @codigo = split(/f_cliente=/, $codigo);
244 @codigo = split(/"/, $codigo[1]); #"
245 %resposta = (
246 status => "sucesso",
247 resposta => "registrado",
248 codigo => $codigo[0],
249 nome => encode_entities($nome, $entitieschars),
250 );
251 }
252 $tree_tr->delete;
253 }
254 }
255 # e-mail em uso
256 elsif(index($respostaSalvaCliente, "existe") != -1 && index($respostaSalvaCliente, "cliente") != -1 && index($respostaSalvaCliente, "cadastrado") != -1 && index($respostaSalvaCliente, "e-mail") != -1)
257 {
258 %resposta = (
259 status => "erro",
260 resposta => "E-mail em uso",
261 );
262 }
263 else
264 {
265 # mostra resultado desconhecido
266 %resposta = (
267 status => "erro",
268 resposta => $respostaSalvaCliente,
269 );
270 }
271
272 my $json = \%resposta;
273 my $json_text = to_json($json, { utf8 => 1 });
274
275 return $json_text;
276 }
277 elsif($mech->status() == 404)
278 {
279 %resposta = (
280 status => "erro",
281 resposta => "not found",
282 url => $mech->uri(),
283 );
284 my $json = \%resposta;
285 my $json_text = to_json($json, { utf8 => 1 });
286 return $json_text;
287 }
288 else
289 {
290 %resposta = (
291 status => "erro",
292 resposta => "unknow HTTP error",
293 url => $mech->uri(),
294 );
295 my $json = \%resposta;
296 my $json_text = to_json($json, { utf8 => 1 });
297 return $json_text;
298 }
299 }
300 }
301 else
302 {
303 %resposta = (
304 status => "erro",
305 resposta => "efetue login primeiro",
306 );
307
308 my $json = \%resposta;
309 my $json_text = to_json($json, { utf8 => 1 });
310
311 return $json_text;
312 }
313 }
314
315
316 sub novoDominio
317 {
318 my($self, $plano, $cliente, $pagoate, $dominio, $senha, $plataforma, $webmail) = @_;
319 my %resposta;
320 if($statusLogin)
321 {
322 my $html;
323 my $table_rows;
324
325 # cria dominio
326 $mech->post("https://painel2.kinghost.net/painel.inserir.php");
327 $mech->submit_form(
328 form_id => "novoDominio",
329 fields => {
330 acao => "dominio",
331 subacao => "adicionar",
332 'dados[plano_id]' => "$plano",
333 'dados[id_sub_cliente]' => "$cliente",
334 'dados[pagoate]' => "$pagoate",
335 'dados[dominio]' => "$dominio",
336 'dados[senha]' => "$senha",
337 'dados[plataforma]' => "$plataforma",
338 'dados[webmail]' => "$webmail",
339 }
340 );
341 if($mech->success())
342 {
343 if($mech->status() == 200)
344 {
345 $html = $mech->content;
346 $mech->update_html( $html );
347 my $tree = HTML::TreeBuilder::XPath->new;
348 $tree->parse( $html );
349
350 # resposta da tentiva de cadastro
351 my $respostaSalvaDominio = $tree->findnodes( '//body' )->[0]->as_HTML;
352 # => alert##T##Dom%EDnio%20cadastrado%20com%20sucesso eval##T##window.location%3D%27%2Fdominio.lista.php%27%3B
353 # => alert##T##Este%20dom%EDnio%20j%E1%20est%E1%20em%20nosso%20sistema%20e%20n%E3o%20pode%20ser%20cadastrado%20novamente.
354 # ==> %20Favor%2C%20entre%20em%20contato%20com%20nosso%20atendimento%20para%20ver%20a%20situa%E7%E3o%20do%20mesmo.
355
356 if(index($respostaSalvaDominio, "cadastrado") != -1 && index($respostaSalvaDominio, "sucesso") != -1)
357 {
358 $mech->get("https://painel2.kinghost.net/dominio.lista.php");
359 $html = $mech->content;
360 $mech->update_html( $html );
361
362 my $tree = HTML::TreeBuilder::XPath->new;
363 $tree->parse( $html );
364
365 $table_rows = $tree->findnodes( '//table[@class="default tralt"]/tr' );
366
367 foreach my $row ( $table_rows->get_nodelist )
368 {
369 my $tree_tr = HTML::TreeBuilder::XPath->new;
370 $tree_tr->parse( $row->as_HTML );
371
372 my $td1 = $tree_tr->findvalue( '//td[1]' );
373
374 my $codigo = $row->as_HTML;
375
376 if(index($td1, $dominio) != -1)
377 {
378 my @codigo = split(/redir\(/, $codigo);
379 @codigo = split(/\)/, $codigo[1]); #"
380 %resposta = (
381 status => "sucesso",
382 resposta => "registrado",
383 codigo => $codigo[0],
384 dominio => $dominio,
385
386 );
387 }
388
389 $tree_tr->delete;
390 }
391 }
392 elsif(index($respostaSalvaDominio, "Este") != -1 && index($respostaSalvaDominio, "nosso") != -1 && index($respostaSalvaDominio, "sistema") != -1)
393 {
394 %resposta = (
395 status => "erro",
396 resposta => "dominio ja existe",
397 dominio => $dominio,
398 );
399 }
400 my $json = \%resposta;
401 my $json_text = to_json($json, { utf8 => 1 });
402 return $json_text;
403 }
404 elsif($mech->status() == 404)
405 {
406 %resposta = (
407 status => "erro",
408 resposta => "not found",
409 url => $mech->uri(),
410 );
411 my $json = \%resposta;
412 my $json_text = to_json($json, { utf8 => 1 });
413 return $json_text;
414 }
415 else
416 {
417 %resposta = (
418 status => "erro",
419 resposta => "unknow HTTP error",
420 url => $mech->uri(),
421 );
422 my $json = \%resposta;
423 my $json_text = to_json($json, { utf8 => 1 });
424 return $json_text;
425 }
426 }
427 }
428 else
429 {
430 %resposta = (
431 status => "erro",
432 resposta => "efetue login primeiro",
433 );
434
435 my $json = \%resposta;
436 my $json_text = to_json($json, { utf8 => 1 });
437
438 return $json_text;
439 }
440 }
441
442
443 sub novoPGSql
444 {
445 my($self, $idDominio, $senha) = @_;
446 my %resposta;
447 if($statusLogin)
448 {
449 my $html;
450 my $banco;
451 # cria pgsql
452 $mech->post("https://painel2.kinghost.net/site.pgsql.php?id_dominio=$idDominio");
453 if($mech->success())
454 {
455 if($mech->status() == 200)
456 {
457 $html = $mech->content;
458 $mech->update_html( $html );
459 my $tree = HTML::TreeBuilder::XPath->new;
460 $tree->parse( $html );
461 my $inputValueNBanco = $tree->findnodes( '//input[@id="usuario"]' )->[0]->as_HTML;
462 my @nomeBanco = split(/value="/, $inputValueNBanco); #"
463 @nomeBanco = split(/"/, $nomeBanco[1]); #"
464 $banco = $nomeBanco[0];
465 $mech->submit_form(
466 form_id => "add",
467 fields => {
468 control => "pgsql",
469 action => "add",
470 id_dominio => "$idDominio",
471 usuario => $banco,
472 db => $banco,
473 senha => "$senha",
474 csenha => "$senha",
475 'charset' => "UTF8",
476 }
477 );
478 if($mech->success())
479 {
480 if($mech->status() == 200)
481 {
482 $html = $mech->content;
483 $mech->update_html( $html );
484 my $tree = HTML::TreeBuilder::XPath->new;
485 $tree->parse( $html );
486 %resposta = (
487 status => "sucesso",
488 resposta => "banco criado",
489 banco => $banco,
490 );
491 my $json = \%resposta;
492 my $json_text = to_json($json, { utf8 => 1 });
493 return $json_text;
494 }
495 elsif($mech->status() == 404)
496 {
497 %resposta = (
498 status => "erro",
499 resposta => "not found",
500 url => $mech->uri(),
501 );
502 my $json = \%resposta;
503 my $json_text = to_json($json, { utf8 => 1 });
504 return $json_text;
505 }
506 else
507 {
508 %resposta = (
509 status => "erro",
510 resposta => "unknow HTTP error",
511 url => $mech->uri(),
512 );
513 my $json = \%resposta;
514 my $json_text = to_json($json, { utf8 => 1 });
515 return $json_text;
516 }
517 }
518 }
519 elsif($mech->status() == 404)
520 {
521 %resposta = (
522 status => "erro",
523 resposta => "not found",
524 url => $mech->uri(),
525 );
526 my $json = \%resposta;
527 my $json_text = to_json($json, { utf8 => 1 });
528 return $json_text;
529 }
530 else
531 {
532 %resposta = (
533 status => "erro",
534 resposta => "unknow HTTP error",
535 url => $mech->uri(),
536 );
537 my $json = \%resposta;
538 my $json_text = to_json($json, { utf8 => 1 });
539 return $json_text;
540 }
541 }
542 # cria pgsql
543 }
544 else
545 {
546 %resposta = (
547 status => "erro",
548 resposta => "efetue login primeiro",
549 );
550
551 my $json = \%resposta;
552 my $json_text = to_json($json, { utf8 => 1 });
553
554 return $json_text;
555 }
556 }
557
558
559 sub selecionaPgSQL
560 {
561 my($self, $idDominio, $novoservidor) = @_;
562 my %resposta;
563 if($statusLogin)
564 {
565 my $html;
566 my $banco;
567 # seleciona pg
568
569 $mech->get("https://painel2.kinghost.net/site.pgsql.php?id_dominio=$idDominio");
570 my %hashform = (
571 acao => 'pgsql',
572 subacao => "configura_servidor",
573 id_dominio => $idDominio,
574 novo_servidor => $novoservidor,
575 );
576 $mech->post("https://painel2.kinghost.net/conectorPainel.php?acao=pgsql&subacao=configura_servidor&id_dominio=$idDominio&novo_servidor=$novoservidor", \%hashform);
577
578 if($mech->status() == 200)
579 {
580 $html = $mech->content;
581 $mech->update_html( $html );
582 my $tree = HTML::TreeBuilder::XPath->new;
583 $tree->parse( $html );
584 my $paginaSeletor = $tree->findnodes( '//body' )->[0]->as_HTML;
585
586 if(index($paginaSeletor, "Servidor") != -1 && index($paginaSeletor, "configurado") != -1 && index($paginaSeletor, "sucesso") != -1)
587 {
588 %resposta = (
589 status => "sucesso",
590 resposta => "servidor selecionado com sucesso",
591 );
592 }
593 else
594 {
595 %resposta = (
596 status => "erro",
597 resposta => "erro ao selecionar servidor",
598 );
599 }
600 my $json = \%resposta;
601 my $json_text = to_json($json, { utf8 => 1 });
602 return $json_text;
603 }
604 elsif($mech->status() == 404)
605 {
606 %resposta = (
607 status => "erro",
608 resposta => "not found",
609 url => $mech->uri(),
610 );
611 my $json = \%resposta;
612 my $json_text = to_json($json, { utf8 => 1 });
613 return $json_text;
614 }
615 else
616 {
617 %resposta = (
618 status => "erro",
619 resposta => "unknow HTTP error",
620 url => $mech->uri(),
621 );
622 my $json = \%resposta;
623 my $json_text = to_json($json, { utf8 => 1 });
624 return $json_text;
625 }
626 #migra ftp
627 }
628 else
629 {
630 %resposta = (
631 status => "erro",
632 resposta => "efetue login primeiro",
633 );
634 my $json = \%resposta;
635 my $json_text = to_json($json, { utf8 => 1 });
636
637 return $json_text;
638 }
639 }
640
641 sub conectarPGSql()
642 {
643 my($self, $hostbanco, $nomebanco, $userbanco, $senhabanco) = @_;
644 my $dsn = "DRIVER={PostGreSQL UNICODE}; SERVER=$hostbanco; DATABASE=$nomebanco; UID=$userbanco; PWD=$senhabanco; OPTION=3; set lc_monetary=pt_BR; set lc_numeric=pt_BR; set lc_time=pt_BR; SET datestyle TO POSTGRES, DMY;";
645 my $conexao = DBI->connect("DBI:ADO:$dsn") or die "problema ao conectar ao pgsql";
646 return $conexao;
647 }
648
649 sub rodaScriptPGSql()
650 {
651 my($self, $hostbanco, $nomebanco, $userbanco, $senhabanco, $sql) = @_;
652
653 my $conexao = $self->conectarPGSql( $hostbanco, $nomebanco, $userbanco, $senhabanco );
654 my $dbh = $conexao->prepare($sql);
655 $dbh->execute() or die $conexao->errstr;
656 $dbh->finish;
657 $conexao->disconnect;
658
659 my %resposta = (
660 status => "sucesso",
661 resposta => "executado com sucesso",
662 );
663 my $json = \%resposta;
664 my $json_text = to_json($json, { utf8 => 1 });
665 print $json_text;
666 }
667
668 sub leScriptSQL
669 {
670 my($self, $arquivo, $path) = @_;
671 my $sql;
672 my $mudadir = chdir $path;
673 open(ARQUIVOSQL, "$arquivo") or die "Nao foi possivel abrir o arquivo para leitura: $!";
674 my @VetSQL = <ARQUIVOSQL>;
675 close ARQUIVOSQL;
676 my $i = 0;
677 foreach my $linha (@VetSQL)
678 {
679 if($i > 0)
680 {
681 $sql = $sql.$linha;
682 }
683 $i++;
684 };
685 return $sql;
686 }
687
688
689 sub novoMySQL
690 {
691 my($self, $idDominio, $senha) = @_;
692 my %resposta;
693 if($statusLogin)
694 {
695 my $html;
696 my $banco;
697
698 $mech->get("https://painel2.kinghost.net/painel.dominios.php?id_dominio=$idDominio");
699
700 # cria MySQL
701 $mech->post("https://painel2.kinghost.net/mysql.php?id_dominio=$idDominio");
702 if($mech->success())
703 {
704 if($mech->status() == 200)
705 {
706 $html = $mech->content;
707 $mech->update_html( $html );
708 my $tree = HTML::TreeBuilder::XPath->new;
709 $tree->parse( $html );
710 my $inputValueNBanco = $tree->findnodes( '//input[@id="db"]' )->[0]->as_HTML;
711 my @nomeBanco = split(/value="/, $inputValueNBanco); #"
712 @nomeBanco = split(/"/, $nomeBanco[1]); #"
713 $banco = $nomeBanco[0];
714 $mech->submit_form(
715 form_id => "formCria",
716 fields => {
717 acao => "mysql",
718 subacao => "cria",
719 id_dominio => "$idDominio",
720 senha => "$senha",
721 senha1 => "$senha",
722 }
723 );
724 if($mech->success())
725 {
726 if($mech->status() == 200)
727 {
728 $html = $mech->content;
729 $mech->update_html( $html );
730 my $tree = HTML::TreeBuilder::XPath->new;
731 $tree->parse( $html );
732 %resposta = (
733 status => "sucesso",
734 resposta => "banco criado",
735 banco => $banco,
736 );
737 my $json = \%resposta;
738 my $json_text = to_json($json, { utf8 => 1 });
739 return $json_text;
740 }
741 elsif($mech->status() == 404)
742 {
743 %resposta = (
744 status => "erro",
745 resposta => "not found",
746 url => $mech->uri(),
747 );
748 my $json = \%resposta;
749 my $json_text = to_json($json, { utf8 => 1 });
750 return $json_text;
751 }
752 else
753 {
754 %resposta = (
755 status => "erro",
756 resposta => "unknow HTTP error",
757 url => $mech->uri(),
758 );
759 my $json = \%resposta;
760 my $json_text = to_json($json, { utf8 => 1 });
761 return $json_text;
762 }
763 }
764 }
765 elsif($mech->status() == 404)
766 {
767 %resposta = (
768 status => "erro",
769 resposta => "not found",
770 url => $mech->uri(),
771 );
772 my $json = \%resposta;
773 my $json_text = to_json($json, { utf8 => 1 });
774 return $json_text;
775 }
776 else
777 {
778 %resposta = (
779 status => "erro",
780 resposta => "unknow HTTP error",
781 url => $mech->uri(),
782 );
783 my $json = \%resposta;
784 my $json_text = to_json($json, { utf8 => 1 });
785 return $json_text;
786 }
787 }
788 # cria MySQL
789 }
790 else
791 {
792 %resposta = (
793 status => "erro",
794 resposta => "efetue login primeiro",
795 );
796 my $json = \%resposta;
797 my $json_text = to_json($json, { utf8 => 1 });
798
799 return $json_text;
800 }
801 }
802
803 sub importaFTPExterno
804 {
805 my($self, $idDominio, $host, $user, $pass, $dirOrigem, $dirDestino) = @_;
806 my %resposta;
807 if($statusLogin)
808 {
809 my $html;
810 my $banco;
811 # migra ftp
812 $mech->post("https://painel2.kinghost.net/dominio.migra.ftp.php?id_dominio=$idDominio");
813 if($mech->success())
814 {
815 if($mech->status() == 200)
816 {
817 $mech->submit_form(
818 form_id => "formFTP",
819 fields => {
820 acao => "migracao_ftp",
821 subacao => "efetua_backup",
822 id_dominio => $idDominio,
823 host => $host,
824 user => $user,
825 pass => $pass,
826 baixar_subdir => "1",
827 dir_origem => '#personalizado#',
828 origem_input => $dirOrigem,
829 dir_destino => "3",
830 destino_input => $dirDestino,
831 }
832 );
833 # migra ftp
834 if($mech->success())
835 {
836 if($mech->status() == 200)
837 {
838 $html = $mech->content;
839 $mech->update_html( $html );
840 my $tree = HTML::TreeBuilder::XPath->new;
841 $tree->parse( $html );
842 my $paginaMigra = $tree->findnodes( '//body' )->[0]->as_HTML;
843 #print $paginaMigra;
844 # alert##T##Diret%F3rio%20de%20origem%20inv%E1lido%20%28www%26%2347%3Bimovelmanager%29
845 # erro ao acessar ftp remoto alert##T##Erro%20ao%20utilizar%20diret%F3rio%20destino%20no%20FTP%20remoto%20%28www%2Fimovelmanager%29
846 # sucesso eval##T##window.location%20%3D%20%27%2Fdominio.migra.ftp.php%3Fid_dominio%3D291076%26id_migracao%3D59981%27%3B
847 if(index($paginaMigra, "Diret") != -1 && index($paginaMigra, "origem") != -1 && index($paginaMigra, "lido") != -1)
848 {
849 %resposta = (
850 status => "erro",
851 resposta => "diretorio de origem invalido",
852 );
853 }
854 elsif(index($paginaMigra, "Erro") != -1 && index($paginaMigra, "utilizar") != -1 && index($paginaMigra, "destino") != -1)
855 {
856 %resposta = (
857 status => "erro",
858 resposta => "Erro de FTP. Verifique as credenciais de acesso ao FTP ou o diretório alvo no FTP remoto",
859 );
860 }
861 elsif(index($paginaMigra, "dominio.migra.ftp.php") != -1 && index($paginaMigra, "id_dominio") != -1 && index($paginaMigra, "id_migracao") != -1)
862 {
863 %resposta = (
864 status => "sucesso",
865 resposta => "Migracao em andamento. Quando a migracao terminar os arquivos estarao em seu site",
866 );
867 }
868 else
869 {
870 %resposta = (
871 status => "erro",
872 resposta => "$paginaMigra",
873 );
874 }
875
876 my $json = \%resposta;
877 my $json_text = to_json($json, { utf8 => 1 });
878 return $json_text;
879 }
880 elsif($mech->status() == 404)
881 {
882 %resposta = (
883 status => "erro",
884 resposta => "not found",
885 url => $mech->uri(),
886 );
887 my $json = \%resposta;
888 my $json_text = to_json($json, { utf8 => 1 });
889 return $json_text;
890 }
891 else
892 {
893 %resposta = (
894 status => "erro",
895 resposta => "unknow HTTP error",
896 url => $mech->uri(),
897 );
898 my $json = \%resposta;
899 my $json_text = to_json($json, { utf8 => 1 });
900 return $json_text;
901 }
902 }
903 }
904 elsif($mech->status() == 404)
905 {
906 %resposta = (
907 status => "erro",
908 resposta => "not found",
909 url => $mech->uri(),
910 );
911 my $json = \%resposta;
912 my $json_text = to_json($json, { utf8 => 1 });
913 return $json_text;
914 }
915 else
916 {
917 %resposta = (
918 status => "erro",
919 resposta => "unknow HTTP error",
920 url => $mech->uri(),
921 );
922 my $json = \%resposta;
923 my $json_text = to_json($json, { utf8 => 1 });
924 return $json_text;
925 }
926 }
927 # migra ftp
928 }
929 else
930 {
931 %resposta = (
932 status => "erro",
933 resposta => "efetue login primeiro",
934 );
935 my $json = \%resposta;
936 my $json_text = to_json($json, { utf8 => 1 });
937
938 return $json_text;
939 }
940 }
941
942
943 sub deletaArquivoFTP
944 {
945 my($self, $host, $user, $password, $dirTarget, $file) = @_;
946 my %resposta;
947
948 my $ftp = Net::FTP->new($host, Debug => 0) or $self->erro("impossivel conectar a $host: $@");
949 $ftp->login($user, $password) or die "impossivel logar ", $ftp->message;
950 $ftp->cwd($dirTarget) or die "impossivel mudar de diretorio ", $ftp->message;
951 $ftp->delete( $file ) or die "impossivel excluir arquivo ", $ftp->message;
952 $ftp->quit;
953  
954 my %resposta = (
955 status => "sucesso",
956 resposta => "$file excluído com sucesso",
957 );
958 my $json = \%resposta;
959 my $json_text = to_json($json, { utf8 => 1 });
960 return $json_text;
961 }
962
963 sub deletaArquivosFTP
964 {
965 my($self, $host, $user, $password, $dirTarget, @files) = @_;
966 my %resposta;
967 my $ftp = Net::FTP->new($host, Debug => 0) or $self->erroFTP("impossivel conectar a $host:", $@);
968 $ftp->login($user, $password) or $self->erroFTP("impossivel logar ", $ftp->message());
969 $ftp->cwd( $dirTarget) or $self->erroFTP("impossivel mudar de diretorio ", $ftp->message());
970 foreach my $file(@files)
971 {
972 $ftp->delete( $file ) or $self->erroFTP("impossivel excluir arquivo $file ", $ftp->message());
973 }
974 $ftp->quit;
975 my %resposta = (
976 status => "sucesso",
977 resposta => "Arquivos excluídos com sucesso",
978 );
979 my $json = \%resposta;
980 my $json_text = to_json($json, { utf8 => 1 });
981 return $json_text;
982 }
983
984
985 sub novoUserStats
986 {
987 my($self, $idDominio, $usuario, $senha) = @_;
988 my %resposta;
989 if($statusLogin)
990 {
991 my $html;
992 my $banco;
993 # novoUserStats
994 $mech->get("https://painel2.kinghost.net/stats.php?id_dominio=$idDominio");
995 if($mech->success())
996 {
997 if($mech->status() == 200)
998 {
999  
1000 $mech->submit_form(
1001 form_id => "formCria",
1002 fields => {
1003 acao => "stats",
1004 subacao => "adicionar_usuario",
1005 id_dominio => $idDominio,
1006 usuario => $usuario,
1007 senha => $senha,
1008 senha1 => $senha,
1009 }
1010 );
1011 if($mech->success())
1012 {
1013 if($mech->status() == 200)
1014 {
1015 $html = $mech->content;
1016 $mech->update_html( $html );
1017 my $tree = HTML::TreeBuilder::XPath->new;
1018 $tree->parse( $html );
1019 my $respostanovoUserStats = $tree->findnodes( '//body' )->[0]->as_HTML;
1020 # alert##T##usu%E1rio%20adicionado%20com%20sucesso eval##T##window.location%3D%27%2Fstats.php%3Fid_dominio%3D291348%27%3B
1021 if(index($respostanovoUserStats, "adicionado") != -1 && index($respostanovoUserStats, "sucesso") != -1 && index($respostanovoUserStats, "id_dominio") != -1)
1022 {
1023 %resposta = (
1024 status => "sucesso",
1025 resposta => "usuario do stats criado com sucesso",
1026 usuario => $usuario,
1027 senha => $senha,
1028 );
1029 }
1030 else
1031 {
1032 %resposta = (
1033 status => "erro",
1034 resposta => "$respostanovoUserStats",
1035 );
1036 }
1037
1038 my $json = \%resposta;
1039 my $json_text = to_json($json, { utf8 => 1 });
1040 return $json_text;
1041 }
1042 elsif($mech->status() == 404)
1043 {
1044 %resposta = (
1045 status => "erro",
1046 resposta => "not found",
1047 url => $mech->uri(),
1048 );
1049 my $json = \%resposta;
1050 my $json_text = to_json($json, { utf8 => 1 });
1051 return $json_text;
1052 }
1053 else
1054 {
1055 %resposta = (
1056 status => "erro",
1057 resposta => "unknow HTTP error",
1058 url => $mech->uri(),
1059 );
1060 my $json = \%resposta;
1061 my $json_text = to_json($json, { utf8 => 1 });
1062 return $json_text;
1063 }
1064 }
1065 }
1066 elsif($mech->status() == 404)
1067 {
1068 %resposta = (
1069 status => "erro",
1070 resposta => "not found",
1071 url => $mech->uri(),
1072 );
1073 my $json = \%resposta;
1074 my $json_text = to_json($json, { utf8 => 1 });
1075 return $json_text;
1076 }
1077 else
1078 {
1079 %resposta = (
1080 status => "erro",
1081 resposta => "unknow HTTP error",
1082 url => $mech->uri(),
1083 );
1084 my $json = \%resposta;
1085 my $json_text = to_json($json, { utf8 => 1 });
1086 return $json_text;
1087 }
1088 }
1089 # novoUserStats
1090 }
1091 else
1092 {
1093 %resposta = (
1094 status => "erro",
1095 resposta => "efetue login primeiro",
1096 );
1097 my $json = \%resposta;
1098 my $json_text = to_json($json, { utf8 => 1 });
1099
1100 return $json_text;
1101 }
1102 }
1103
1104
1105
1106 sub novaCaixaEmail
1107 {
1108 my($self, $idDominio, $caixa, $senha, $tamanho) = @_;
1109 my %resposta;
1110 if($statusLogin)
1111 {
1112 my $html;
1113 my $banco;
1114 # novaCaixaEmail
1115 $mech->get("https://painel2.kinghost.net/kingmail.php?id_dominio=$idDominio");
1116 if($mech->success())
1117 {
1118 if($mech->status() == 200)
1119 {
1120  
1121 $mech->submit_form(
1122 form_id => "addCaixa",
1123 fields => {
1124 acao => "addCaixaPostal",
1125 id_dominio => $idDominio,
1126 tipoAdd => "caixapostal",
1127 novaCaixa => $caixa,
1128 novaSenha => $senha,
1129 novaSenha2 => $senha,
1130 novaCaixaTamanho => $tamanho,
1131 }
1132 );
1133 if($mech->success())
1134 {
1135 if($mech->status() == 200)
1136 {
1137 $html = $mech->content;
1138 $mech->update_html( $html );
1139 my $tree = HTML::TreeBuilder::XPath->new;
1140 $tree->parse( $html );
1141 my $respostanovaCaixaEmail = $tree->findnodes( '//body' )->[0]->as_HTML;
1142 if(index($respostanovaCaixaEmail, "caixa postal adicionada com") != -1)
1143 {
1144 %resposta = (
1145 status => "sucesso",
1146 resposta => "caixa de e-mail criada com sucesso",
1147 usuario => $caixa,
1148 senha => $senha,
1149 );
1150 }
1151 elsif(index($respostanovaCaixaEmail, "Erro ao criar caixa postal") != -1)
1152 {
1153 %resposta = (
1154 status => "erro",
1155 resposta => "caixa postal ja existe",
1156 usuario => $caixa,
1157 );
1158 }
1159 else
1160 {
1161 %resposta = (
1162 status => "erro",
1163 resposta => "$respostanovaCaixaEmail",
1164 );
1165 }
1166
1167 my $json = \%resposta;
1168 my $json_text = to_json($json, { utf8 => 1 });
1169 return $json_text;
1170 }
1171 elsif($mech->status() == 404)
1172 {
1173 %resposta = (
1174 status => "erro",
1175 resposta => "not found",
1176 url => $mech->uri(),
1177 );
1178 my $json = \%resposta;
1179 my $json_text = to_json($json, { utf8 => 1 });
1180 return $json_text;
1181 }
1182 else
1183 {
1184 %resposta = (
1185 status => "erro",
1186 resposta => "unknow HTTP error",
1187 url => $mech->uri(),
1188 );
1189 my $json = \%resposta;
1190 my $json_text = to_json($json, { utf8 => 1 });
1191 return $json_text;
1192 }
1193 }
1194 }
1195 elsif($mech->status() == 404)
1196 {
1197 %resposta = (
1198 status => "erro",
1199 resposta => "not found",
1200 url => $mech->uri(),
1201 );
1202 my $json = \%resposta;
1203 my $json_text = to_json($json, { utf8 => 1 });
1204 return $json_text;
1205 }
1206 else
1207 {
1208 %resposta = (
1209 status => "erro",
1210 resposta => "unknow HTTP error",
1211 url => $mech->uri(),
1212 );
1213 my $json = \%resposta;
1214 my $json_text = to_json($json, { utf8 => 1 });
1215 return $json_text;
1216 }
1217 }
1218 # novaCaixaEmail
1219 }
1220 else
1221 {
1222 %resposta = (
1223 status => "erro",
1224 resposta => "efetue login primeiro",
1225 );
1226 my $json = \%resposta;
1227 my $json_text = to_json($json, { utf8 => 1 });
1228
1229 return $json_text;
1230 }
1231 }
1232
1233
1234 sub editaSenhaCaixaEmail
1235 {
1236 my($self, $idDominio, $email, $senha) = @_;
1237 my %resposta;
1238 if($statusLogin)
1239 {
1240 my $html;
1241 my $banco;
1242 # editaSenhaCaixaEmail
1243 $mech->get("https://painel2.kinghost.net/kingmail.php?id_dominio=$idDominio");
1244 if($mech->success())
1245 {
1246 if($mech->status() == 200)
1247 {
1248
1249 $mech->submit_form(
1250 form_id => "addCaixa",
1251 fields => {
1252 acao => "trocaSenha",
1253 id_dominio => $idDominio,
1254 mail => "$email",
1255 novaSenha => $senha,
1256 }
1257 );
1258 if($mech->success())
1259 {
1260 if($mech->status() == 200)
1261 {
1262 $html = $mech->content;
1263 $mech->update_html( $html );
1264 my $tree = HTML::TreeBuilder::XPath->new;
1265 $tree->parse( $html );
1266 my $respostaeditaSenhaCaixaEmail = $tree->findnodes( '//body' )->[0]->as_HTML;
1267 # BUG sempre responde a mesma coisa, mesma se a conta nao existir.
1268 if(index($respostaeditaSenhaCaixaEmail, "Senha do email") != -1 && index($respostaeditaSenhaCaixaEmail, "Alterada Com") != -1)
1269 {
1270 %resposta = (
1271 status => "sucesso",
1272 resposta => "senha alterada com sucesso",
1273 email => $email,
1274 );
1275 }
1276 else
1277 {
1278 %resposta = (
1279 status => "erro",
1280 resposta => "$respostaeditaSenhaCaixaEmail",
1281 );
1282 }
1283
1284 my $json = \%resposta;
1285 my $json_text = to_json($json, { utf8 => 1 });
1286 return $json_text;
1287 }
1288 elsif($mech->status() == 404)
1289 {
1290 %resposta = (
1291 status => "erro",
1292 resposta => "not found",
1293 url => $mech->uri(),
1294 );
1295 my $json = \%resposta;
1296 my $json_text = to_json($json, { utf8 => 1 });
1297 return $json_text;
1298 }
1299 else
1300 {
1301 %resposta = (
1302 status => "erro",
1303 resposta => "unknow HTTP error",
1304 url => $mech->uri(),
1305 );
1306 my $json = \%resposta;
1307 my $json_text = to_json($json, { utf8 => 1 });
1308 return $json_text;
1309 }
1310 }
1311 }
1312 elsif($mech->status() == 404)
1313 {
1314 %resposta = (
1315 status => "erro",
1316 resposta => "not found",
1317 url => $mech->uri(),
1318 );
1319 my $json = \%resposta;
1320 my $json_text = to_json($json, { utf8 => 1 });
1321 return $json_text;
1322 }
1323 else
1324 {
1325 %resposta = (
1326 status => "erro",
1327 resposta => "unknow HTTP error",
1328 url => $mech->uri(),
1329 );
1330 my $json = \%resposta;
1331 my $json_text = to_json($json, { utf8 => 1 });
1332 return $json_text;
1333 }
1334 }
1335 # editaSenhaCaixaEmail
1336 }
1337 else
1338 {
1339 %resposta = (
1340 status => "erro",
1341 resposta => "efetue login primeiro",
1342 );
1343 my $json = \%resposta;
1344 my $json_text = to_json($json, { utf8 => 1 });
1345
1346 return $json_text;
1347 }
1348 }
1349
1350
1351 sub listaCaixasEmail
1352 {
1353 my($self, $idDominio) = @_;
1354 my %resposta;
1355 if($statusLogin)
1356 {
1357 my $html;
1358 my $banco;
1359 # listaCaixasEmail
1360 $mech->get("https://painel2.kinghost.net/kingmail.php?id_dominio=$idDominio");
1361 if($mech->success())
1362 {
1363 if($mech->status() == 200)
1364 {
1365  
1366 $html = $mech->content;
1367 $mech->update_html( $html );
1368 my $tree = HTML::TreeBuilder::XPath->new;
1369 $tree->parse( $html );
1370 my $respostalistaCaixasEmail = $tree->findnodes( '//body' )->[0]->as_HTML;
1371
1372 my @codigo = split(/var contas = \[/, $respostalistaCaixasEmail);
1373 @codigo = split(/\]/, $codigo[1]);
1374
1375 my @objJSONs = split(/\}\,/, $codigo[0]);
1376
1377 my @caixas;
1378
1379 foreach my $objJSON(@objJSONs)
1380 {
1381 #$objJSON = ~ s[}},][]g;
1382
1383 #print $objJSON."},";
1384
1385 my @vetObJson = split(/,/, $objJSON);
1386
1387 my @vetEmail = split(/\'username\'\:\'/, $vetObJson[1]); #'
1388 @vetEmail = split(/\'/, $vetEmail[1]); #'
1389
1390 my @vetQuota = split(/\'quota\'\:\'/, $vetObJson[3]); #'
1391 @vetQuota = split(/\'/, $vetQuota[1]); #'
1392
1393 my @vetOcupado = split(/\'ocupado\'\:\'/, $vetObJson[4]); #'
1394 @vetOcupado = split(/\'/, $vetOcupado[1]); #'
1395
1396 my @vetTipo = split(/\'tipo\'\:\'/, $vetObJson[5]); #'
1397 @vetTipo = split(/\'/, $vetTipo[1]); #'
1398
1399
1400 #forma a caixa
1401 my $caixa = {
1402 caixa => $vetEmail[0],
1403 quota => $vetQuota[0],
1404 ocupado => $vetOcupado[0],
1405 tipo => $vetTipo[0],
1406 };
1407
1408 # poe a caixa na lista de caixas
1409 push @caixas, $caixa;
1410 }
1411
1412
1413
1414 %resposta = (
1415 status => "sucesso",
1416 caixas => [@caixas],
1417 );
1418
1419
1420 my $json = \%resposta;
1421 my $json_text = to_json($json, { utf8 => 1 });
1422 return $json_text;
1423  
1424 }
1425 elsif($mech->status() == 404)
1426 {
1427 %resposta = (
1428 status => "erro",
1429 resposta => "not found",
1430 url => $mech->uri(),
1431 );
1432 my $json = \%resposta;
1433 my $json_text = to_json($json, { utf8 => 1 });
1434 return $json_text;
1435 }
1436 else
1437 {
1438 %resposta = (
1439 status => "erro",
1440 resposta => "unknow HTTP error",
1441 url => $mech->uri(),
1442 );
1443 my $json = \%resposta;
1444 my $json_text = to_json($json, { utf8 => 1 });
1445 return $json_text;
1446 }
1447 }
1448 # editaSenhaCaixaEmail
1449 }
1450 else
1451 {
1452 %resposta = (
1453 status => "erro",
1454 resposta => "efetue login primeiro",
1455 );
1456 my $json = \%resposta;
1457 my $json_text = to_json($json, { utf8 => 1 });
1458
1459 return $json_text;
1460 }
1461 }
1462
1463
1464
1465 sub checaDisponibilidadeDominioRevenda
1466 {
1467 my($self, $dominio) = @_;
1468 my %resposta;
1469 if($statusLogin)
1470 {
1471 my $html;
1472 my $banco;
1473 $mech->get("https://painel2.kinghost.net/dominio.lista.php");
1474 if($mech->success())
1475 {
1476 if($mech->status() == 200)
1477 {
1478 $html = $mech->content;
1479 $mech->update_html( $html );
1480 my $tree = HTML::TreeBuilder::XPath->new;
1481 $tree->parse( $html );
1482 my $respostalistaDominios = $tree->findnodes( '//body' )->[0]->as_HTML;
1483
1484 if(index($respostalistaDominios, $dominio) != -1)
1485 {
1486 %resposta = (
1487 status => "erro",
1488 resposta => "em uso na Revenda",
1489 );
1490 }
1491 else
1492 {
1493 %resposta = (
1494 status => "sucesso",
1495 resposta => "liberado",
1496 )
1497 }
1498
1499
1500 my $json = \%resposta;
1501 my $json_text = to_json($json, { utf8 => 1 });
1502 return $json_text;
1503
1504
1505 }
1506 elsif($mech->status() == 404)
1507 {
1508 %resposta = (
1509 status => "erro",
1510 resposta => "not found",
1511 url => $mech->uri(),
1512 );
1513 my $json = \%resposta;
1514 my $json_text = to_json($json, { utf8 => 1 });
1515 return $json_text;
1516 }
1517 else
1518 {
1519 %resposta = (
1520 status => "erro",
1521 resposta => "unknow HTTP error",
1522 url => $mech->uri(),
1523 );
1524 my $json = \%resposta;
1525 my $json_text = to_json($json, { utf8 => 1 });
1526 return $json_text;
1527 }
1528 }
1529
1530 }
1531 else
1532 {
1533 %resposta = (
1534 status => "erro",
1535 resposta => "efetue login primeiro",
1536 );
1537 my $json = \%resposta;
1538 my $json_text = to_json($json, { utf8 => 1 });
1539
1540 return $json_text;
1541 }
1542 }
1543
1544 sub habilitaISAPIRewrite
1545 {
1546 my($self, $idDominio, $captcha) = @_;
1547 my %resposta;
1548 if($statusLogin)
1549 {
1550 my $html;
1551 my $banco;
1552 $mech->get("https://painel2.kinghost.net/painel.isapi_rewrite.php?id_dominio=$idDominio");
1553 $mech->submit_form(
1554 form_id => "configurarISAPIRewrite",
1555 fields => {
1556 acao => 'iis6',
1557 subacao => "isapi_rewrite",
1558 id_dominio => $idDominio,
1559 isapi_rewrite => "On",
1560 captcha => $captcha,
1561 }
1562 );
1563 if($mech->success())
1564 {
1565 if($mech->status() == 200)
1566 {
1567 $html = $mech->content;
1568 $mech->update_html( $html );
1569 my $tree = HTML::TreeBuilder::XPath->new;
1570 $tree->parse( $html );
1571 my $paginaISAPI = $tree->findnodes( '//body' )->[0]->as_HTML;
1572 if(index($paginaISAPI, "Palavra digitada") != -1 && index($paginaISAPI, "por favor tente novamente") != -1)
1573 {
1574 %resposta = (
1575 status => "erro",
1576 resposta => "captcha errada",
1577 );
1578 }
1579 elsif(index($paginaISAPI, "ISAPI Rewrite ativado com") != -1)#
1580 {
1581 %resposta = (
1582 status => "sucesso",
1583 resposta => "ISAPI Rewrite ativado com sucesso",
1584 );
1585 }
1586 my $json = \%resposta;
1587 my $json_text = to_json($json, { utf8 => 1 });
1588 return $json_text;
1589 }
1590 elsif($mech->status() == 404)
1591 {
1592 %resposta = (
1593 status => "erro",
1594 resposta => "not found",
1595 url => $mech->uri(),
1596 );
1597 my $json = \%resposta;
1598 my $json_text = to_json($json, { utf8 => 1 });
1599 return $json_text;
1600 }
1601 else
1602 {
1603 %resposta = (
1604 status => "erro",
1605 resposta => "unknow HTTP error",
1606 url => $mech->uri(),
1607 );
1608 my $json = \%resposta;
1609 my $json_text = to_json($json, { utf8 => 1 });
1610 return $json_text;
1611 }
1612 }
1613
1614 }
1615 else
1616 {
1617 %resposta = (
1618 status => "erro",
1619 resposta => "efetue login primeiro",
1620 );
1621 my $json = \%resposta;
1622 my $json_text = to_json($json, { utf8 => 1 });
1623
1624 return $json_text;
1625 }
1626 }
1627
1628
1629
1630 sub pegaServidorTemporario
1631 {
1632 my($self, $idDominio) = @_;
1633 my %resposta;
1634 if($statusLogin)
1635 {
1636 my $html;
1637 $mech->get("https://painel2.kinghost.net/painel.dominios.php?id_dominio=$idDominio");
1638 if($mech->success())
1639 {
1640 if($mech->status() == 200)
1641 {
1642 $html = $mech->content;
1643 $mech->update_html( $html );
1644 my $tree = HTML::TreeBuilder::XPath->new;
1645 $tree->parse( $html );
1646 my $respostaDominioInfo = $tree->findnodes( '//body' )->[0]->as_HTML;
1647
1648 my @vetTrata = split(/<td id="inf_url_alt">/, $respostaDominioInfo);
1649 @vetTrata = split(/target="_blank">/, $vetTrata[1]);
1650
1651 @vetTrata = split(/<\/a><\/td>/, $vetTrata[1]);
1652
1653 my $endereco = $vetTrata[0];
1654
1655 %resposta = (
1656 status => "sucesso",
1657 resposta => "$endereco",
1658 url => "$endereco",
1659 );
1660
1661 my $json = \%resposta;
1662 my $json_text = to_json($json, { utf8 => 1 });
1663 return $json_text;
1664
1665
1666 }
1667 elsif($mech->status() == 404)
1668 {
1669 %resposta = (
1670 status => "erro",
1671 resposta => "not found",
1672 url => $mech->uri(),
1673 );
1674 my $json = \%resposta;
1675 my $json_text = to_json($json, { utf8 => 1 });
1676 return $json_text;
1677 }
1678 else
1679 {
1680 %resposta = (
1681 status => "erro",
1682 resposta => "unknow HTTP error",
1683 url => $mech->uri(),
1684 );
1685 my $json = \%resposta;
1686 my $json_text = to_json($json, { utf8 => 1 });
1687 return $json_text;
1688 }
1689 }
1690
1691 }
1692 else
1693 {
1694 %resposta = (
1695 status => "erro",
1696 resposta => "efetue login primeiro",
1697 );
1698 my $json = \%resposta;
1699 my $json_text = to_json($json, { utf8 => 1 });
1700
1701 return $json_text;
1702 }
1703 }
1704
1705
1706 sub pegaServidorTemporarioAux
1707 {
1708 my($self, $idDominio) = @_;
1709 my %resposta;
1710 if($statusLogin)
1711 {
1712 my $html;
1713 $mech->get("https://painel2.kinghost.net/painel.dominios.php?id_dominio=$idDominio");
1714 if($mech->success())
1715 {
1716 if($mech->status() == 200)
1717 {
1718 $html = $mech->content;
1719 $mech->update_html( $html );
1720 my $tree = HTML::TreeBuilder::XPath->new;
1721 $tree->parse( $html );
1722 my $respostaDominioInfo = $tree->findnodes( '//body' )->[0]->as_HTML;
1723
1724 my @vetTrata = split(/<td id="inf_url_alt">/, $respostaDominioInfo);
1725 @vetTrata = split(/target="_blank">/, $vetTrata[1]);
1726
1727 @vetTrata = split(/<\/a><\/td>/, $vetTrata[1]);
1728
1729 my $endereco = $vetTrata[0];
1730
1731 return $endereco;
1732
1733
1734 }
1735 elsif($mech->status() == 404)
1736 {
1737 %resposta = (
1738 status => "erro",
1739 resposta => "not found",
1740 url => $mech->uri(),
1741 );
1742 my $json = \%resposta;
1743 my $json_text = to_json($json, { utf8 => 1 });
1744 return $json_text;
1745 }
1746 else
1747 {
1748 %resposta = (
1749 status => "erro",
1750 resposta => "unknow HTTP error",
1751 url => $mech->uri(),
1752 );
1753 my $json = \%resposta;
1754 my $json_text = to_json($json, { utf8 => 1 });
1755 return $json_text;
1756 }
1757 }
1758
1759 }
1760 else
1761 {
1762 %resposta = (
1763 status => "erro",
1764 resposta => "efetue login primeiro",
1765 );
1766 my $json = \%resposta;
1767 my $json_text = to_json($json, { utf8 => 1 });
1768
1769 return $json_text;
1770 }
1771 }
1772  
1773
1774 sub transfereDominio
1775 {
1776 my($self, $ID, $senha, $dominio, $idTec, $dns1, $dns2, $dns3, $dns4) = @_;
1777 my %resposta;
1778  
1779 my $html;
1780 my $idDominio;
1781 my $idCob;
1782
1783 if(! defined($idTec))
1784 {
1785 $idTec = "";
1786 }
1787 if(! defined($dns3))
1788 {
1789 $dns3 = "";
1790 }
1791 if(! defined($dns4))
1792 {
1793 $dns4 = "";
1794 }
1795  
1796
1797 $mech->get("https://registro.br/cgi-bin/nicbr/stini");
1798 $mech->submit_form(
1799 with_fields => {
1800 handle => $ID, # ID
1801 passwd => $senha, # senha do ID
1802 }
1803 );
1804 if($mech->success())
1805 {
1806 if($mech->status() == 200)
1807 {
1808
1809 $html = $mech->content;
1810 $mech->update_html( $html );
1811 my $tree = HTML::TreeBuilder::XPath->new;
1812 $tree->parse( $html );
1813 my $pagina = $tree->findnodes( '//body' )->[0]->as_HTML;
1814 if(index($pagina, "Senha Incorreta") != -1)
1815 {
1816 # ==> erro de login
1817 %resposta = (
1818 status => "erro",
1819 resposta => "Erro de login - Senha incorreta",
1820 );
1821 }
1822 elsif(index($pagina, "ID Inexistente") != -1)
1823 {
1824 # ==> erro de login
1825 %resposta = (
1826 status => "erro",
1827 resposta => "Erro de login - ID Inexistente",
1828 );
1829 }
1830 else
1831 {
1832 # ==> transfere domain
1833 my $pagina;
1834 my @links = $mech->links();
1835 foreach my $link (@links)
1836 {
1837 if($link->text() eq $dominio)
1838 {
1839 $mech->get("https://registro.br/" . $link->url());
1840 my @vetId = split(/id\=/, $link->url());
1841 $idDominio = $vetId[1];
1842
1843 $html = $mech->content;
1844 $mech->update_html( $html );
1845 my $tree = HTML::TreeBuilder::XPath->new;
1846 $tree->parse( $html );
1847 $pagina = $tree->findnodes( '//body' )->[0]->as_HTML;
1848
1849 my @vetPag = split(/name\=\"cob\" id\=\"bil\" value\=\"/, $pagina); #"
1850 @vetPag = split(/\"/, $vetPag[1]); #"
1851 $idCob = $vetPag[0];
1852
1853 my %hashform = (
1854 id => $idDominio,
1855 dominio => $dominio,
1856 tec => $idTec,
1857 cob => $idCob,
1858 host1 => $dns1,
1859 host2 => $dns2,
1860 host3 => $dns3,
1861 host4 => $dns4,
1862 );
1863
1864 $mech->post("https://registro.br/" . $link->url(), \%hashform);
1865
1866 $html = $mech->content;
1867 $mech->update_html( $html );
1868 my $tree = HTML::TreeBuilder::XPath->new;
1869 $tree->parse( $html );
1870 $pagina = $tree->findnodes( '//body' )->[0]->as_HTML;
1871 }
1872 }
1873 if(index($pagina, "Contatos de dom") != -1 && index($pagina, "nios") != -1)
1874 {
1875 %resposta = (
1876 status => "sucesso",
1877 resposta => "Transferência efetuada com sucesso",
1878 );
1879 }
1880 elsif(index($pagina, "Hostname inv") != -1 && index($pagina, "lido") != -1)
1881 {
1882 %resposta = (
1883 status => "erro",
1884 resposta => "Hostname inválido",
1885 );
1886 }
1887 elsif(index($pagina, "Servidor DNS Slave 1: N") != -1 && index($pagina, "nio j") != -1 && index($pagina, "o informado") != -1)
1888 {
1889 %resposta = (
1890 status => "erro",
1891 resposta => "Servidor DNS Slave 1: Não informado",
1892 );
1893 }
1894 elsif(index($pagina, "Servidor DNS Master: N") != -1 && index($pagina, "o informado") != -1)
1895 {
1896 %resposta = (
1897 status => "erro",
1898 resposta => "Servidor DNS Master: Não informado",
1899 );
1900 }
1901 else
1902 {
1903 %resposta = (
1904 status => "erro",
1905 resposta => "$pagina",
1906 )
1907 }
1908 # ==> transfere domain
1909 }
1910
1911
1912
1913 my $json = \%resposta;
1914 my $json_text = to_json($json, { utf8 => 1 });
1915 return $json_text;
1916 }
1917 elsif($mech->status() == 404)
1918 {
1919 %resposta = (
1920 status => "erro",
1921 resposta => "not found",
1922 url => $mech->uri(),
1923 );
1924 my $json = \%resposta;
1925 my $json_text = to_json($json, { utf8 => 1 });
1926 return $json_text;
1927 }
1928 else
1929 {
1930 %resposta = (
1931 status => "erro",
1932 resposta => "unknow HTTP error",
1933 url => $mech->uri(),
1934 );
1935 my $json = \%resposta;
1936 my $json_text = to_json($json, { utf8 => 1 });
1937 return $json_text;
1938 }
1939 }
1940 }
1941
1942
1943
1944
1945
1946 1;
1947  
1948 __END__