| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342 |
- <?php
- // This module sponsered by our good friends from wexcloud.com
- function vesta_ConfigOptions() {
- $configarray = array(
- "Package Name" => array( "Type" => "text", "Default" => "default"),
- "SSH Access" => array( "Type" => "yesno", "Description" => "Tick to grant access", ),
- "IP Address (optional)" => array( "Type" => "text" ),
- );
- return $configarray;
- }
- function vesta_CreateAccount($params) {
- // Execute only if there is assigned server
- if ($params["server"] == 1) {
- // Prepare variables
- $postvars = array(
- 'user' => $params["serverusername"],
- 'password' => $params["serverpassword"],
- 'hash' => $params["serveraccesshash"],
- 'cmd' => 'v-add-user',
- 'arg1' => $params["username"],
- 'arg2' => $params["password"],
- 'arg3' => $params["clientsdetails"]["email"],
- 'arg4' => $params["configoption1"],
- 'arg5' => $params["clientsdetails"]["firstname"],
- 'arg6' => $params["clientsdetails"]["lastname"],
- );
- $postdata = http_build_query($postvars);
- // Create user account
- $curl = curl_init();
- curl_setopt($curl, CURLOPT_URL, 'https://' . $params["serverhostname"] . ':8083/api/');
- curl_setopt($curl, CURLOPT_RETURNTRANSFER,true);
- curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
- curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
- curl_setopt($curl, CURLOPT_POST, true);
- curl_setopt($curl, CURLOPT_POSTFIELDS, $postdata);
- $answer = curl_exec($curl);
- // Enable ssh access
- if(($answer == 'OK') && ($params["configoption2"] == 'on')) {
- $postvars = array(
- 'user' => $params["serverusername"],
- 'password' => $params["serverpassword"],
- 'hash' => $params["serveraccesshash"],
- 'cmd' => 'v-change-user-shell',
- 'arg1' => $params["username"],
- 'arg2' => 'bash'
- );
- $postdata = http_build_query($postvars);
- $curl = curl_init();
- curl_setopt($curl, CURLOPT_URL, 'https://' . $params["serverhostname"] . ':8083/api/');
- curl_setopt($curl, CURLOPT_RETURNTRANSFER,true);
- curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
- curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
- curl_setopt($curl, CURLOPT_POST, true);
- curl_setopt($curl, CURLOPT_POSTFIELDS, $postdata);
- $answer = curl_exec($curl);
- }
- // Add domain
- if(($answer == 'OK') && (!empty($params["domain"]))) {
- $postvars = array(
- 'user' => $params["serverusername"],
- 'password' => $params["serverpassword"],
- 'hash' => $params["serveraccesshash"],
- 'cmd' => 'v-add-domain',
- 'arg1' => $params["username"],
- 'arg2' => $params["domain"],
- 'arg3' => $params["configoption3"],
- );
- $postdata = http_build_query($postvars);
- $curl = curl_init();
- curl_setopt($curl, CURLOPT_URL, 'https://' . $params["serverhostname"] . ':8083/api/');
- curl_setopt($curl, CURLOPT_RETURNTRANSFER,true);
- curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
- curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
- curl_setopt($curl, CURLOPT_POST, true);
- curl_setopt($curl, CURLOPT_POSTFIELDS, $postdata);
- $answer = curl_exec($curl);
- }
- }
- if($answer == 'OK') {
- $result = "success";
- } else {
- $result = $answer;
- }
- return $result;
- }
- function vesta_TerminateAccount($params) {
- // Execute only if there is assigned server
- if ($params["server"] == 1) {
- // Prepare variables
- $postvars = array(
- 'user' => $params["serverusername"],
- 'password' => $params["serverpassword"],
- 'hash' => $params["serveraccesshash"],
- 'cmd' => 'v-delete-user',
- 'arg1' => $params["username"]
- );
- $postdata = http_build_query($postvars);
- // Delete user account
- $curl = curl_init();
- curl_setopt($curl, CURLOPT_URL, 'https://' . $params["serverhostname"] . ':8083/api/');
- curl_setopt($curl, CURLOPT_RETURNTRANSFER,true);
- curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
- curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
- curl_setopt($curl, CURLOPT_POST, true);
- curl_setopt($curl, CURLOPT_POSTFIELDS, $postdata);
- $answer = curl_exec($curl);
- }
- if($answer == 'OK') {
- $result = "success";
- } else {
- $result = $answer;
- }
- return $result;
- }
- function vesta_SuspendAccount($params) {
- // Execute only if there is assigned server
- if ($params["server"] == 1) {
- // Prepare variables
- $postvars = array(
- 'user' => $params["serverusername"],
- 'password' => $params["serverpassword"],
- 'hash' => $params["serveraccesshash"],
- 'cmd' => 'v-suspend-user',
- 'arg1' => $params["username"]
- );
- $postdata = http_build_query($postvars);
- // Susupend user account
- $curl = curl_init();
- curl_setopt($curl, CURLOPT_URL, 'https://' . $params["serverhostname"] . ':8083/api/');
- curl_setopt($curl, CURLOPT_RETURNTRANSFER,true);
- curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
- curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
- curl_setopt($curl, CURLOPT_POST, true);
- curl_setopt($curl, CURLOPT_POSTFIELDS, $postdata);
- $answer = curl_exec($curl);
- }
- if($answer == 'OK') {
- $result = "success";
- } else {
- $result = $answer;
- }
- }
- function vesta_UnsuspendAccount($params) {
- // Execute only if there is assigned server
- if ($params["server"] == 1) {
- // Prepare variables
- $postvars = array(
- 'user' => $params["serverusername"],
- 'password' => $params["serverpassword"],
- 'hash' => $params["serveraccesshash"],
- 'cmd' => 'v-unsuspend-user',
- 'arg1' => $params["username"]
- );
- $postdata = http_build_query($postvars);
- // Unsusupend user account
- $curl = curl_init();
- curl_setopt($curl, CURLOPT_URL, 'https://' . $params["serverhostname"] . ':8083/api/');
- curl_setopt($curl, CURLOPT_RETURNTRANSFER,true);
- curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
- curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
- curl_setopt($curl, CURLOPT_POST, true);
- curl_setopt($curl, CURLOPT_POSTFIELDS, $postdata);
- $answer = curl_exec($curl);
- }
- if($answer == 'OK') {
- $result = "success";
- } else {
- $result = $answer;
- }
- }
- function vesta_ChangePassword($params) {
- // Execute only if there is assigned server
- if ($params["server"] == 1) {
- // Prepare variables
- $postvars = array(
- 'user' => $params["serverusername"],
- 'password' => $params["serverpassword"],
- 'hash' => $params["serveraccesshash"],
- 'cmd' => 'v-change-user-password',
- 'arg1' => $params["username"],
- 'arg2' => $params["password"]
- );
- $postdata = http_build_query($postvars);
- // Change user package
- $curl = curl_init();
- curl_setopt($curl, CURLOPT_URL, 'https://' . $params["serverhostname"] . ':8083/api/');
- curl_setopt($curl, CURLOPT_RETURNTRANSFER,true);
- curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
- curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
- curl_setopt($curl, CURLOPT_POST, true);
- curl_setopt($curl, CURLOPT_POSTFIELDS, $postdata);
- $answer = curl_exec($curl);
- }
- if($answer == 'OK') {
- $result = "success";
- } else {
- $result = $answer;
- }
- return $result;
- }
- function vesta_ChangePackage($params) {
- // Execute only if there is assigned server
- if ($params["server"] == 1) {
- // Prepare variables
- $postvars = array(
- 'user' => $params["serverusername"],
- 'password' => $params["serverpassword"],
- 'hash' => $params["serveraccesshash"],
- 'cmd' => 'v-change-user-package',
- 'arg1' => $params["username"],
- 'arg2' => $params["configoption1"]
- );
- $postdata = http_build_query($postvars);
- // Change user package
- $curl = curl_init();
- curl_setopt($curl, CURLOPT_URL, 'https://' . $params["serverhostname"] . ':8083/api/');
- curl_setopt($curl, CURLOPT_RETURNTRANSFER,true);
- curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
- curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
- curl_setopt($curl, CURLOPT_POST, true);
- curl_setopt($curl, CURLOPT_POSTFIELDS, $postdata);
- $answer = curl_exec($curl);
- }
- if($answer == 'OK') {
- $result = "success";
- } else {
- $result = $answer;
- }
- return $result;
- }
- function vesta_ClientArea($params) {
- $code = '<form action="https://'.$params["serverhostname"].':8083/login/" method="post" target="_blank">
- <input type="hidden" name="user" value="'.$params["username"].'" />
- <input type="hidden" name="password" value="'.$params["password"].'" />
- <input type="submit" value="Login to Control Panel" />
- <input type="button" value="Login to Webmail" onClick="window.open(\'http://'.$serverhostname.'/webmail\')" />
- </form>';
- return $code;
- }
- function vesta_AdminLink($params) {
- $code = '<form action="https://'.$params["serverhostname"].':8083/login/" method="post" target="_blank">
- <input type="hidden" name="user" value="'.$params["serverusername"].'" />
- <input type="hidden" name="password" value="'.$params["serverpassword"].'" />
- <input type="submit" value="Login to Control Panel" />
- </form>';
- return $code;
- }
- function vesta_LoginLink($params) {
- echo "<a href=\"https://".$params["serverhostname"].":8083/login/\" target=\"_blank\" style=\"color:#cc0000\">control panel</a>";
- }
- function vesta_UsageUpdate($params) {
- // Prepare variables
- $postvars = array(
- 'user' => $params["serverusername"],
- 'password' => $params["serverpassword"],
- 'hash' => $params["serveraccesshash"],
- 'cmd' => 'v-list-users',
- 'arg1' => 'json'
- );
- $postdata = http_build_query($postvars);
- // Get user stats
- $curl = curl_init();
- curl_setopt($curl, CURLOPT_URL, 'https://' . $params["serverhostname"] . ':8083/api/');
- curl_setopt($curl, CURLOPT_RETURNTRANSFER,true);
- curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
- curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
- curl_setopt($curl, CURLOPT_POST, true);
- curl_setopt($curl, CURLOPT_POSTFIELDS, $postdata);
- $answer = curl_exec($curl);
- // Decode json data
- $results = json_decode($answer, true);
- // Loop through results and update DB
- foreach ($results AS $user=>$values) {
- update_query("tblhosting",array(
- "diskusage"=>$values['U_DISK'],
- "disklimit"=>$values['DISK_QUOTA'],
- "bwusage"=>$values['U_BANDWIDTH'],
- "bwlimit"=>$values['BANDWIDTH'],
- "lastupdate"=>"now()",
- ),array("server"=>$params['serverid'], "username"=>$user));
- }
- }
- ?>
|