Jump to content

Módulo WHMCS - Pegar IP e Hostname


AACHost
 Share

Recommended Posts

Estou há 1 dia criando / editando um módulo de servidor para WHMCS.

 

Ele já cria a conta normalmente no servidor remoto, desde que eu insira a CHAVE API  e a URL DO PAINEL direto no arquivo: módulo.php 

 

Porém, dessa forma, eu só consigo cadastrar um servidor.

 

 

E, para que eu pudesse cadastrar vários servidores usando o mesmo módulo, eu preciso pegar os campos:

 

Servidor: ************* 

IP: *************

 

Veja print
 

 

Sendo que, em servidor, eu vou usar uma url, exemplo: http://meu-domínio.com

e em IP, eu uma chave API que vem do servidor remoto

 

 

 

Veja abaixo o meu código:

 

$_srv['api'] = 'API DO SERVIDOR AQUI'; 
 $_srv['url_painel'] = 'URL DO PAINEL AQUI'; 
 
 
 
Só preciso pegar esses 2 campos mesmos, o restante é opcional para o cliente que vai usar
Link to comment
Share on other sites

 

Estou há 1 dia criando / editando um módulo de servidor para WHMCS.

 

Ele já cria a conta normalmente no servidor remoto, desde que eu insira a CHAVE API  e a URL DO PAINEL direto no arquivo: módulo.php 

 

Porém, dessa forma, eu só consigo cadastrar um servidor.

 

 

E, para que eu pudesse cadastrar vários servidores usando o mesmo módulo, eu preciso pegar os campos:

 

Servidor: ************* 

IP: *************

 

Veja print
 

 

Sendo que, em servidor, eu vou usar uma url, exemplo: http://meu-domínio.com

e em IP, eu uma chave API que vem do servidor remoto

 

 

 

Veja abaixo o meu código:

 

$_srv['api'] = 'API DO SERVIDOR AQUI'; 
 $_srv['url_painel'] = 'URL DO PAINEL AQUI'; 
 
 
 
Só preciso pegar esses 2 campos mesmos, o restante é opcional para o cliente que vai usar

 

 

Confira a documentação http://docs.whmcs.com/Provisioning_Module_Developer_Docs

Link to comment
Share on other sites

Documentação já olhada, até mesmo antes de tentar criar o módulo, mas mesmo assim eu não consegui.

 

Tentei pegar algo aqui do Módulo do WHMSonic, mas sem sucesso.

<?php
// API Version v2.0.5 - 21-12-2012

function whmsonic_ConfigOptions() {
$configarray = array(
 "Client Type" => array( "Type" => "dropdown", "Options" => "External,internal","Description" => "Notice: If Internal selected, please set the custom form field under the Custom Fields link, the client must enter cPanel username on the order page, that is also mean the client has already cPanel hosting account on the server. This option will not setup cPanel account! It will setup only radio under the provided cpanel user account."),
 "Max Listeners Limit" => array( "Type" => "text", "Size" => "3", ),
 "Max BitRate Limit" => array( "Type" => "dropdown", "Options" => "64,128,24,32,48,96"),
 "AutoDJ Feature" => array( "Type" => "yesno", "Description" => "If yes, the user will access to AutoDJ features in their cPanel WHMSonic." ),
 "Hosting Space" => array( "Type" => "text", "Size" => "25","Description" => "Hosting space is required by external clients only if autodj option is enabled to upload music files. Please enter a limit, ex: 100 = 100MB. Enter only numbers in this field." ),
  "Bandwidth Limit" => array( "Type" => "text", "Size" => "25", ),
);
return $configarray;
}

function whmsonic_CreateAccount($params) {

    // Get The Package Information
    $ctype = $params["configoption1"]; // Client Type
    $listeners = $params["configoption2"]; // Max Listeners Limit
    $radioip = $params["serverip"];
    $bitrate = $params["configoption3"]; // BitRate Limit
    $autodj = $params["configoption4"]; // AutoDJ Access - on/off
    $hspace = $params["configoption5"]; // Hosting Limit
    $bandwidth = $params["configoption6"]; // Bandwidth Limit

    // Get The General Information
    $serverp = $params["serverpassword"]; // Target Server root password
    $connection = $params["serverip"];
    $auth = "root:$serverp";
    $orderid = $params["serviceid"];
    if ($params["serversecure"]=="on") {$serverport="2087"; $ht="https";} else {$serverport="2086"; $ht="http";} // SSL Connection fix

    // Get The Client Information
    $client_email = $params["clientsdetails"]["email"];
    $client_name = $params["clientsdetails"]["firstname"];
    if ($params["configoption1"]=="internal") {
$radiousername = $params["customfields"]["cpanel username"];
} else {
// External user, create a custom WHMSonic username & password.
$chars = "abcdefghijkmnpqrstuvwxyz0123456789";
    srand((double)microtime()*1000000);
    $i = 0;
    $exu = '' ;
    while ($i <= 4) {
    $num = rand() % 33;
    $tmp = substr($chars, $num, 1);
    $exu = $exu . $tmp;
    $i++;}
    $radiousername = "sc_$exu";}
    $chars2 = "abcdefghijkmnopqrstuvwxyz023456789";
    srand((double)microtime()*1000000);
    $i = 0;
    $pass = '' ;
    while ($i <= 7) {
    $num = rand() % 33;
    $tmp = substr($chars2, $num, 1);
    $pass = $pass . $tmp;
    $i++;
}
// GO

// Update WHMCS db for the username, required for other actions.
$hostpass = encrypt($pass);
$query3 = "UPDATE tblhosting SET username='$radiousername', password='$hostpass' WHERE id='".$params["accountid"]."'";
$result3=mysql_query($query3);
// Update WHMCS db for the username, required for other actions.


$url = "$ht://$connection:$serverport/whmsonic/modules/api.php?";
$data = "cmd=setup&ctype=$ctype&ip=$radioip&bitrate=$bitrate&autodj=$autodj&bw=$bandwidth&limit=$listeners&cemail=$client_email&cname=$client_name&rad_username=$radiousername&pass=$pass&hspace=$hspace";
$ch = curl_init();
curl_setopt($ch, CURLAUTH_BASIC, CURLAUTH_ANY);
curl_setopt($ch, CURLOPT_USERPWD, $auth);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 59);
curl_setopt($ch, CURLOPT_URL, $url);
$retval = curl_exec($ch);
if (curl_errno($ch)) {
    $retval = "CURL Error: ".curl_errno($ch)." - ".curl_error($ch)." - Please check the radioIP in the package module configuration and check the root password in the servers settings of WHMCS.";
}
curl_close($ch);

if ($retval=="Complete") {
$result = "success";
} else {
if (strpos($retval,"Login Attempt Failed!") == true) {$result = "WHMSonic server($radioip) WHM root login failed! The root password is incorrect. Please check your WHMSonic server/connection settings in your script.";
} else {
$result = "$retval";
}}
return $result;
}


function whmsonic_TerminateAccount($params) {

    // Details
    $connection = $params["serverip"];
    $rad_username= $params["username"];
    $serverp = $params["serverpassword"]; // Target Server root password
    $auth = "root:$serverp";
    if ($params["serversecure"]=="on") {$serverport="2087"; $ht="https";} else {$serverport="2086"; $ht="http";} // SSL Connection fix

$url = "$ht://$connection:$serverport/whmsonic/modules/api.php?";
$data = "cmd=terminate&rad_username=$rad_username";
$ch = curl_init();
curl_setopt($ch, CURLAUTH_BASIC, CURLAUTH_ANY);
curl_setopt($ch, CURLOPT_USERPWD, $auth);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 59);
curl_setopt($ch, CURLOPT_URL, $url);
$retval = curl_exec($ch);
if (curl_errno($ch)) {
    $retval = "CURL Error: ".curl_errno($ch)." - ".curl_error($ch);
}
curl_close($ch);

if ($retval=="Complete") {
$result = "success";
} else {
$result = "<br>$retval";
}
return $result;
}

function whmsonic_SuspendAccount($params) {

    // Details
    $connection = $params["serverip"];
    $rad_username= $params["username"];
    $serverp = $params["serverpassword"]; // Target Server root password
    $auth = "root:$serverp";
    if ($params["serversecure"]=="on") {$serverport="2087"; $ht="https";} else {$serverport="2086"; $ht="http";} // SSL Connection fix

$url = "$ht://$connection:$serverport/whmsonic/modules/api.php?";
$data = "cmd=suspend&rad_username=$rad_username";
$ch = curl_init();
curl_setopt($ch, CURLAUTH_BASIC, CURLAUTH_ANY);
curl_setopt($ch, CURLOPT_USERPWD, $auth);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 59);
curl_setopt($ch, CURLOPT_URL, $url);
$retval = curl_exec($ch);
if (curl_errno($ch)) {
    $retval = "CURL Error: ".curl_errno($ch)." - ".curl_error($ch);
}
curl_close($ch);

if ($retval=="Complete") {
$result = "success";
} else {
$result = "<br>$retval";
}
return $result;

}

function whmsonic_UnsuspendAccount($params) {

    // Details
    $connection = $params["serverip"];
    $rad_username= $params["username"];
    $serverp = $params["serverpassword"]; // Target Server root password
    $auth = "root:$serverp";
    if ($params["serversecure"]=="on") {$serverport="2087"; $ht="https";} else {$serverport="2086"; $ht="http";} // SSL Connection fix

$url = "$ht://$connection:$serverport/whmsonic/modules/api.php?";
$data = "cmd=unsuspend&rad_username=$rad_username";
$ch = curl_init();
curl_setopt($ch, CURLAUTH_BASIC, CURLAUTH_ANY);
curl_setopt($ch, CURLOPT_USERPWD, $auth);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 59);
curl_setopt($ch, CURLOPT_URL, $url);
$retval = curl_exec($ch);
if (curl_errno($ch)) {
    $retval = "CURL Error: ".curl_errno($ch)." - ".curl_error($ch);
}
curl_close($ch);

if ($retval=="Complete") {
$result = "success";
} else {
$result = "<br>$retval";
}
return $result;

}

function whmsonic_ClientArea($params) {
$connection = $params["serverip"];
$code = "<form action=http://$connection/cpanel/ method=post target=_blank><input type=hidden name=ip value=$licenseip><input type=submit value=\"WHMSonic Login\"></form>";
return $code;
}
function whmsonic_AdminLink($params) {
    $connection = $params["serverip"];
$code = "<form action=http://$connection:2086/whmsonic/main.php method=post target=_blank><input type=hidden name=username value=\"".$params["serverusername"]."\"><input type=hidden name=password value=\"".$params["serverpassword"]."\"><input type=submit value=\"WHMSonic Root\"></form>";
return $code;
}
?>

 

 

 

 

 

 

 

Link to comment
Share on other sites

 

Documentação já olhada, até mesmo antes de tentar criar o módulo, mas mesmo assim eu não consegui.

 

Tentei pegar algo aqui do Módulo do WHMSonic, mas sem sucesso.


 

Se você leu a documentação certamente não entendeu o objetivo.

Link to comment
Share on other sites

Consegui, obrigado pela atenção de vocês, se quiser fechar o post e marcar como resolvido, agradeço!

Atenciosamente,

Ozivaldo

Se resolveu compartilhe a solução ou informe como foi resolvido. Esse não seria o objetivo do fórum?

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.

×
×
  • Create New...