Jump to content


Photo

Script Para Integrar Com Whm


  • Faça o login para participar
2 replies to this topic

#1 erloracc

erloracc

    Normal

  • Usuários
  • 117 posts
  • Sexo:Não informado
  • Localidade:Pernambuco/BRASIL

Posted 09/10/2006, 21:17

Olá pessoal mais uma vez vou recorrer a vcs!

É o seguite o que seria esse "accesshash" que pede para a conexão com o servidor. E outra coisa é como usar as funções.

Valeu!


<?php

$host = "localhost";
$user = "nome_usuario";
$accesshash = "";
$usessl = "";
$suspenduser = "";

global $cpanelaccterr;

// SUSPENDE CONTAS WHM
function suspend ($host,$user,$accesshash,$usessl,$suspenduser) {
$result = whmreq("/scripts/remote_suspend?user=${suspenduser}",$host,$user,$accesshash,$usessl);
if ($cpanelaccterr != "") { return; }
return $result;
}

// ATIVA CONTAS WHM
function unsuspend ($host,$user,$accesshash,$usessl,$suspenduser) {
$result = whmreq("/scripts/remote_unsuspend?user=${suspenduser}",$host,$user,$accesshash,$usessl);
if ($cpanelaccterr != "") { return; }
return $result;
}

// TERMINA UMA CONTA NO WHM
function killacct ($host,$user,$accesshash,$usessl,$killuser) {
$result = whmreq("/scripts/killacct?user=${killuser}&nohtml=1",$host,$user,$accesshash,$usessl);
if ($cpanelaccterr != "") { return; }
return $result;
}

// MOSTRA INFORMAÇÕES DE CONTAS
function showversion ($host,$user,$accesshash,$usessl) {
$result = whmreq("/scripts2/showversion",$host,$user,$accesshash,$usessl);
if ($cpanelaccterr != "") { return; }
return $result;
}


// CRIA UMA CONTA NO WHM
function createacct ($host,$user,$accesshash,$usessl,$acctdomain,$acctuser,$acctpass,$acctplan) {
$result = whmreq("/scripts/wwwacct?remote=1&nohtml=1&username=${acctuser}&password=${acctpass}&domain=${acctdomain}&plan=${acctplan}",$host,$user,$accesshash,$usessl);
if ($cpanelaccterr != "") { return; }
return $result;
}



// LISTA AS CONTAS
function listaccts ($host,$user,$accesshash,$usessl) {
$result = whmreq("/scripts2/listaccts?nohtml=1&viewall=1",$host,$user,$accesshash,$usessl);
if ($cpanelaccterr != "") { return; }

$page = split("\n",$result);
foreach ($page as $line) {
list($acct,$contents) = split("=", $line);
if ($acct != "") {
$allc = split(",", $contents);
$accts[$acct] = $allc;
}
}
return($accts);
}



// MOSTRA PACOTES
function listpkgs ($host,$user,$accesshash,$usessl) {
$result = whmreq("/scripts/remote_listpkg",$host,$user,$accesshash,$usessl);
if ($cpanelaccterr != "") { return; }


$page = split("\n",$result);
foreach ($page as $line) {
list($pkg,$contents) = split("=", $line);
if ($pkg != "") {
$allc = split(",", $contents);
$pkgs[$pkg] = $allc;
}
}
return($pkgs);
}
function whmreq ($request,$host,$user,$accesshash,$usessl) {


$cleanaccesshash = preg_replace("'(\r|\n)'","",$accesshash);
$authstr = $user . ":" . $cleanaccesshash;
$cpanelaccterr = "";


if (function_exists("curl_init")) {
$ch = curl_init();
if ($usessl) {
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST,0);
curl_setopt($ch, CURLOPT_URL, "https://${host}:2087" . $request);
} else {
curl_setopt($ch, CURLOPT_URL, "http://${host}:2086" . $request);
}
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
$curlheaders[0] = "Authorization: WHM $authstr";
curl_setopt($ch,CURLOPT_HTTPHEADER,$curlheaders);
$data=curl_exec ($ch);
curl_close ($ch);
} elseif (function_exists("socket_create")) {
if ($usessl) {
$cpanelaccterr = "SSL Support requires curl";
return;
}
$service_port = 2086;
$address = gethostbyname($host);
$socket = socket_create (AF_INET, SOCK_STREAM, 0);
if ($socket < 0) {
$cpanelaccterr = "socket_create() failed";
return;
}
$result = socket_connect ($socket, $address, $service_port);
if ($result < 0) {
$cpanelaccterr = "socket_connect() failed";
return;
}
$in = "GET $request HTTP/1.0\n";
socket_write($socket,$in,strlen($in));
$in = "Connection: close\n";
socket_write($socket,$in,strlen($in));
$in = "Authorization: WHM $authstr\n\n\n";
socket_write($socket,$in,strlen($in));

$inheader = 1;
while(($buf = socket_read($socket, 512)) != false) {
if (!$inheader) {
$data .= $buf;
}
if(preg_match("'\r\n\r\n$'s", $buf)) {
$inheader = 0;
}
if(preg_match("'\n\n$'s", $buf)) {
$inheader = 0;
}
if(preg_match("'\r\n$'s", $buf)) {
$inheader = 0;
}
}

} else {
$cpanelaccterr = "php not compiled with --enable-sockets OR curl";
return;
}

return $data;
}

?>
Acesse Host
Portal Paulista Digital
www.paulistadigital.com.br
www.acessehost.com.br
MSN: leofernandes2004 [at] hotmail.com

#2 X-PHP

X-PHP

    Normal

  • Usuários
  • 106 posts
  • Sexo:Não informado

Posted 17/10/2006, 20:14

Olá,

Vou te dar uma pista,

<?php
function whmreq ($request,$host,$user,$accesshash,$usessl) {


$cleanaccesshash = preg_replace("'(\r|\n)'","",$accesshash);
$authstr = $user . ":" . $cleanaccesshash;
$cpanelaccterr = "";


if (function_exists("curl_init")) {
$ch = curl_init();
if ($usessl) {
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST,0);
curl_setopt($ch, CURLOPT_URL, "https://${host}:2087" . $request);
} else {
curl_setopt($ch, CURLOPT_URL, "http://${host}:2086" . $request);
}
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
$curlheaders[0] = "Authorization: WHM $authstr";
curl_setopt($ch,CURLOPT_HTTPHEADER,$curlheaders);
$data=curl_exec ($ch);
curl_close ($ch);
} elseif (function_exists("socket_create")) {
if ($usessl) {
$cpanelaccterr = "SSL Support requires curl";
return;
}
$service_port = 2086;
$address = gethostbyname($host);
$socket = socket_create (AF_INET, SOCK_STREAM, 0);
if ($socket < 0) {
$cpanelaccterr = "socket_create() failed";
return;
}
$result = socket_connect ($socket, $address, $service_port);
if ($result < 0) {
$cpanelaccterr = "socket_connect() failed";
return;
}
$in = "GET $request HTTP/1.0\n";
socket_write($socket,$in,strlen($in));
$in = "Connection: close\n";
socket_write($socket,$in,strlen($in));
$in = "Authorization: WHM $authstr\n\n\n";
socket_write($socket,$in,strlen($in));

$inheader = 1;
while(($buf = socket_read($socket, 512)) != false) {
if (!$inheader) {
$data .= $buf;
}
if(preg_match("'\r\n\r\n$'s", $buf)) {
$inheader = 0;
}
if(preg_match("'\n\n$'s", $buf)) {
$inheader = 0;
}
if(preg_match("'\r\n$'s", $buf)) {
$inheader = 0;
}
}

} else {
$cpanelaccterr = "php not compiled with --enable-sockets OR curl";
return;
}

return $data;
}
function listaccts ($host,$user,$accesshash,$usessl) {
$result = whmreq("/scripts2/listaccts?nohtml=1&viewall=1",$host,$user,$accesshash,$usessl);
if ($cpanelaccterr != "") { return; }

$page = split("\n",$result);
foreach ($page as $line) {
list($acct,$contents) = split("=", $line);
if ($acct != "") {
$allc = split(",", $contents);
$accts[$acct] = $allc;
}
}

return($accts);
}
$host = "localhost";
$user = ""; //login
$accesshash = ''; //chave de acesso "procure no whm por Cluster/Acesso Remoto e clique em "Gerar Chave de Acesso Remoto" e gere uma chave de acesso

$accts = listaccts($host,$user,$accesshash,0);
foreach($accts as $contas){
list($dominio, $login, $plano) = $contas;
print "Dominio: $dominio | Login: $login | Plano: $plano<br>";

}
?>


Aqui está a dica de ouro "chave de acesso "procure no whm por Cluster/Acesso Remoto e clique em "Gerar Chave de Acesso Remoto" e gere uma chave de acesso"

Tem como desenvolver mais ferramentas, basta editar o arquivo "/usr/local/cpanel/Cpanel/Accounting.php.inc"

Tb tem como desenvolver muito mais coisas, eu mesmo estou estudando e encontrei muitas coisas legais que da pra montar.

O script acima foi eu que montei, está meio tosco, pois por enquanto só estou estudando e vendo as possibilidades, mas já da pra ter uma ideía de como fazer.

O resto é com vc!!!

Abraços e T+ B)

#3 corvox

corvox

    That's No Easy Way Out

  • Usuários
  • 434 posts
  • Sexo:Masculino

Posted 26/06/2008, 21:29

Mas isso seria apenas possivel com acesso root correto ?




1 user(s) are reading this topic

0 membro(s), 1 visitante(s) e 0 membros anônimo(s)

IPB Skin By Virteq