Exemplo n.º 1
0
function budgetvm_AdminServicesTabFields($params)
{
    $powerStatus = new BudgetVM_Api($params['serverpassword']);
    $getP->post->service = $params['customfields']['BudgetVM Service ID'];
    $powerStatus = $powerStatus->call("v2", "device", "power", "get", $getP);
    switch ($powerStatus->result) {
        case "on":
        case "online":
            $power = "<strong>Powered On</strong>";
            break;
        case "off":
        case "offline":
            $power = "<strong>Powered Off</strong>";
            break;
        default:
            $power = "<strong>Unknown</strong>";
            break;
    }
    $fieldsarray["Power Status"] = $power;
    $fieldsarray["Power Management"] = "<input type=\"button\" value=\"Power On\" class=\"btn\" onclick=\"runModuleCommand('custom','adminPowerOn')\"> <input type=\"button\" value=\"Power Off\" class=\"btn\" onclick=\"runModuleCommand('custom','adminPowerOff')\"> <input type=\"button\" value=\"Power Cycle\" class=\"btn\" onclick=\"runModuleCommand('custom','adminPowerReboot')\">";
    $type = new BudgetVM_Api($params['serverpassword']);
    $info->post->service = $params['customfields']['BudgetVM Service ID'];
    $type = $type->call("v2", "device", "type", "get", $info);
    if ($type->result == "dedicated") {
        $fieldsarray["IPMI Controller"] = "<input type='button' style='width: 135px' class='searchinput' value='Launch KVM' onclick=\"window.open('../modules/servers/budgetvm/ipmi.php?id=" . base64_encode($params['customfields']['BudgetVM Service ID']) . "&apikey=" . base64_encode($params['serverpassword']) . "', '_blank','width=600,height=200,status=no,location=no,toolbar=no,scrollbars=1,menubar=no')\"> <input type=\"button\" value=\"Reset IPMI Controller\" class=\"btn\" onclick=\"runModuleCommand('custom','adminResetIPMI')\">";
    }
    if ($type->result == "vps") {
        $getConsole = new BudgetVM_Api($params['serverpassword']);
        $var->post->service = $params['customfields']['BudgetVM Service ID'];
        $console = $getConsole->call("v2", "device", "console", "get", $var);
        if (empty($console->result->user) && !empty($console->result->pass)) {
            $fieldsarray["VNC Host"] = $console->result->host . ":" . $console->result->port;
            $fieldsarray["VNC Password"] = $console->result->pass;
        } else {
            $fieldsarray["Console Username"] = $console->result->user;
            $fieldsarray["Console Password"] = $console->result->pass;
            $fieldsarray["Out of Band Console"] = "<input type='button' style='width: 135px' class='searchinput' value='Launch Console' onclick=\"window.open('" . $console->result->host . "', '_blank','width=800,height=600,status=no,location=no,toolbar=no,scrollbars=1,menubar=no')\">";
        }
    }
    $displayNetwork = "";
    $bandwidth = new BudgetVM_Api($params['serverpassword']);
    $var->post->service = $params['customfields']['BudgetVM Service ID'];
    if ($type->result == "dedicated") {
        $var->post->start = strtotime("last Month");
        $var->post->end = strtotime("now");
        $bandwidth = $bandwidth->call("v2", "network", "bandwidth", "post", $var);
        foreach ($bandwidth->result as $server) {
            foreach ($server as $switch => $port) {
                foreach ($port as $id => $info) {
                    $displayNetwork .= "<h2>" . $info->name . "</h2>";
                    $displayNetwork .= '<img src="data:image/png;base64, ' . $info->graph . '">';
                }
            }
        }
    } else {
        $bandwidth = $bandwidth->call("v2", "network", "bandwidth", "post", $var);
        if ($bandwidth->success == true) {
            $displayNetwork .= '<img src="data:image/png;base64, ' . $bandwidth->result->graph . '">';
        }
    }
    $fieldsarray["Network Information"] = $displayNetwork;
    return $fieldsarray;
}
Exemplo n.º 2
0
/**
 * Client area output logic handling.
 *
 * This function is used to define module specific client area output. It should
 * return an array consisting of a template file and optional additional
 * template variables to make available to that template.
 *
 * The template file you return can be one of two types:
 *
 * * tabOverviewModuleOutputTemplate - The output of the template provided here
 *   will be displayed as part of the default product/service client area
 *   product overview page.
 *
 * * tabOverviewReplacementTemplate - Alternatively using this option allows you
 *   to entirely take control of the product/service overview page within the
 *   client area.
 *
 * Whichever option you choose, extra template variables are defined in the same
 * way. This demonstrates the use of the full replacement.
 *
 * Please Note: Using tabOverviewReplacementTemplate means you should display
 * the standard information such as pricing and billing details in your custom
 * template or they will not be visible to the end user.
 *
 * @param array $params common module parameters
 *
 * @see http://docs.whmcs.com/Provisioning_Module_SDK_Parameters
 *
 * @return array
 */
function budgetvm_ClientArea(array $params)
{
    // Determine the requested action and set service call parameters based on
    // the action.
    $requestedAction = isset($_REQUEST['customAction']) ? $_REQUEST['customAction'] : '';
    $service = $params['serviceid'];
    $bvmid = $params['customfields']['BudgetVM Service ID'];
    $var = new stdclass();
    $var->post = new stdclass();
    $var->post->service = $bvmid;
    $budgetvm->bvmid = $bvmid;
    $budgetvm->service = $service;
    $type = new BudgetVM_Api($params['serverpassword']);
    $type = $type->call("v2", "device", "type", "get", $var);
    $budgetvm->type = $type->result;
    if ($requestedAction == "manage") {
        $serviceAction = 'get_usage';
        $templateFile = 'templates/manage.tpl';
    } elseif ($requestedAction == 'reverse') {
        if ($_SERVER['REQUEST_METHOD'] == "POST" && is_array($_POST['update'])) {
            $update = new BudgetVM_Api($params['serverpassword']);
            $var->post->records = json_encode($_POST['update']);
            $budgetvm->return = $update->call("v2", "dns", "reverse", "put", $var);
            if (is_object($budgetvm->return->result)) {
                $fixed = "";
                foreach ($budgetvm->return->result as $ip => $ret) {
                    $fixed .= $ip . " - " . $ret . "<br>" . PHP_EOL;
                }
                $budgetvm->return->result = $fixed;
            }
        } else {
            $budgetvm->return = NULL;
        }
        $netblocks = new BudgetVM_Api($params['serverpassword']);
        $budgetvm->netblocks = $netblocks->call("v2", "network", "netblock", "get", $var);
        $serviceAction = 'get_usage';
        $templateFile = 'templates/rdns.tpl';
    } elseif ($requestedAction == 'network') {
        $bandwidth = new BudgetVM_Api($params['serverpassword']);
        if ($budgetvm->type == "dedicated") {
            if (isset($_GET['period'])) {
                switch ($_GET['period']) {
                    case "hour":
                        $var->post->start = strtotime("-1 hour");
                        break;
                    case "day":
                        $var->post->start = strtotime("-1 day");
                        break;
                    case "week":
                        $var->post->start = strtotime("-1 week");
                        break;
                    case "month":
                        $var->post->start = strtotime("-1 month");
                        break;
                    case "year":
                        $var->post->start = strtotime("-1 year");
                        break;
                    default:
                        $var->post->start = strtotime("-1 month");
                        break;
                }
            } else {
                $var->post->start = strtotime("last Month");
            }
            $var->post->end = strtotime("now");
            $budgetvm->bandwidth = $bandwidth->call("v2", "network", "bandwidth", "post", $var);
        } else {
            $budgetvm->bandwidth = $bandwidth->call("v2", "network", "bandwidth", "post", $var);
        }
        $serviceAction = 'get_usage';
        $templateFile = 'templates/network.tpl';
    } elseif ($requestedAction == 'power') {
        if ($_SERVER['REQUEST_METHOD'] == "POST") {
            if ($_POST['bootorder'] != "standard") {
                // Custom Boot Order was Requested
                $bootorder = new BudgetVM_Api($params['serverpassword']);
                $var->post->request = $_POST['bootorder'];
                $budgetvm->bootorder = $bootorder->call("v2", "device", "power", "put", $var);
            } else {
                $budgetvm->bootorder = NULL;
            }
            // Power Action
            $update = new BudgetVM_Api($params['serverpassword']);
            $var->post->action = $_POST['poweraction'];
            $budgetvm->return = $update->call("v2", "device", "power", "post", $var);
            if ($budgetvm->return->success == true) {
                if ($_POST['bootorder'] != "standard" && !empty($budgetvm->bootorder) && $budgetvm->bootorder->success == true) {
                    // Power Action with custom boot order
                    $budgetvm->return->result = $budgetvm->bootorder->result . " & " . $budgetvm->return->result;
                }
            }
        } else {
            $budgetvm->return = NULL;
        }
        $powerStatus = new BudgetVM_Api($params['serverpassword']);
        $budgetvm->powerStatus = $powerStatus->call("v2", "device", "power", "get", $var);
        $serviceAction = 'get_usage';
        $templateFile = 'templates/power.tpl';
    } elseif ($requestedAction == 'reinstall') {
        if ($_SERVER['REQUEST_METHOD'] == "POST") {
            $cancel = $_POST['cancel'];
            if (isset($cancel) && $cancel == true) {
                $stop = new BudgetVM_Api($params['serverpassword']);
                $budgetvm->return = $stop->call("v2", "device", "reload", "delete", $var);
            } else {
                $provision = new BudgetVM_Api($params['serverpassword']);
                $var->post->value = $_POST['profile'];
                $budgetvm->return = $provision->call("v2", "device", "reload", "post", $var);
                if ($budgetvm->return->success == true) {
                    if ($type->result == "dedicated") {
                        $budgetvm->return->result = "System Reinstall Started</br>Root Password: "******"dedicated") {
            $status = new BudgetVM_Api($params['serverpassword']);
            $budgetvm->status = $status->call("v2", "device", "reload", "put", $var)->result;
        } else {
            $budgetvm->status = NULL;
        }
        $profiles = new BudgetVM_Api($params['serverpassword']);
        $budgetvm->profiles = $profiles->call("v2", "device", "reload", "get", $var)->result;
        $serviceAction = 'get_usage';
        $templateFile = 'templates/reinstall.tpl';
    } elseif ($requestedAction == 'ipmi') {
        if ($_SERVER['REQUEST_METHOD'] == "POST") {
            if ($type->result == "dedicated") {
                if ($_POST['ipmi_reset'] == true) {
                    $reset_ipmi = new BudgetVM_Api($params['serverpassword']);
                    $budgetvm->return = $reset_ipmi->call("v2", "device", "console", "delete", $var);
                } elseif ($_POST['ipmi_launch'] == true) {
                    $launch_ipmi = new BudgetVM_Api($params['serverpassword']);
                    $budgetvm->return = $launch_ipmi->call("v2", "device", "console", "get", $var);
                    if ($budgetvm->return->success == true) {
                        $launch_ipmi->ipmiLaunch(base64_decode($budgetvm->return->result));
                        $budgetvm->return->result = "KVM Launched, File download started.";
                    }
                } elseif ($_POST['image_unmount'] == true) {
                    $unmount_image = new BudgetVM_Api($params['serverpassword']);
                    $budgetvm->return = $unmount_image->call("v2", "device", "iso", "delete", $var);
                } elseif ($_POST['image_mount'] == true) {
                    $mount_image = new BudgetVM_Api($params['serverpassword']);
                    $var->post->image = $_POST['profile'];
                    $budgetvm->return = $mount_image->call("v2", "device", "iso", "post", $var);
                    $mount_image = new BudgetVM_Api($params['serverpassword']);
                    $budgetvm->return = $mount_image->call("v2", "device", "iso", "put", $var);
                }
            } else {
                if ($_POST['ipmi_vm_launch'] == true) {
                    $ipmi_vm_launch = new BudgetVM_Api($params['serverpassword']);
                    $budgetvm->return = $ipmi_vm_launch->call("v2", "device", "console", "get", $var);
                    if ($budgetvm->return->success == true) {
                        $message = "<h4>Management Console</h4>";
                        $message .= "Username: "******"</br>" . PHP_EOL;
                        $message .= "Password: "******"</br>" . PHP_EOL;
                        $message .= "Host: <a href='" . $budgetvm->return->result->host . "' target='_blank'>" . $budgetvm->return->result->host . "</a>" . PHP_EOL;
                        $budgetvm->return->result = $message;
                    }
                }
            }
        } else {
            $budgetvm->return = NULL;
        }
        $images = new BudgetVM_Api($params['serverpassword']);
        $budgetvm->images = $images->call("v2", "device", "iso", "get", NULL);
        $status = new BudgetVM_Api($params['serverpassword']);
        $budgetvm->status = $status->call("v2", "device", "iso", "get", $var);
        $serviceAction = 'get_usage';
        $templateFile = 'templates/ipmi.tpl';
    } else {
        // Service Overview
        if ($type->success == true) {
            $budgetvm->type = $type->result;
            if ($type->result == "dedicated") {
                $device = new BudgetVM_Api($params['serverpassword']);
                $device = $device->call("v2", "device", "hardware", "get", $var);
                $network = new BudgetVM_Api($params['serverpassword']);
                $network = $network->call("v2", "network", "netblock", "get", $var);
                if ($network->result == true) {
                    $budgetvm->network = $network->result;
                }
            } else {
                $device = new BudgetVM_Api($params['serverpassword']);
                $device = $device->call("v2", "device", "stats", "get", $var);
            }
            if ($device->success == true) {
                $budgetvm->device = $device->result;
            }
        }
        $var->post->start = strtotime("last Month");
        $var->post->end = strtotime("now");
        $bandwidth = new BudgetVM_Api($params['serverpassword']);
        $budgetvm->bandwidth = $bandwidth->call("v2", "network", "bandwidth", "post", $var);
        $status = new BudgetVM_Api($params['serverpassword']);
        $status = $status->call("v2", "device", "power", "get", $var);
        if ($status->success == true && $status->success == true) {
            $budgetvm->status = $status->result;
        } else {
            $budgetvm->status = "Uknown";
        }
        $serviceAction = 'get_stats';
        $templateFile = 'templates/overview.tpl';
    }
    try {
        // Call the service's function based on the request action, using the
        // values provided by WHMCS in `$params`.
        return array('tabOverviewReplacementTemplate' => $templateFile, 'templateVariables' => array('budgetvm' => $budgetvm));
    } catch (Exception $e) {
        // Record the error in WHMCS's module log.
        logModuleCall('provisioningmodule', __FUNCTION__, $params, $e->getMessage(), $e->getTraceAsString());
        // In an error condition, display an error page.
        return array('tabOverviewReplacementTemplate' => 'error.tpl', 'templateVariables' => array('usefulErrorHelper' => $e->getMessage()));
    }
}
Exemplo n.º 3
0
<?php

define("CLIENTAREA", true);
//define("FORCESSL",true); // Uncomment to force the page to use https://
require "../../../init.php";
$ca = new WHMCS_ClientArea();
require dirname(__FILE__) . '/api.class.php';
if (!empty($_GET['id']) && !empty($_GET['apikey']) && isset($_SESSION['adminid']) && !empty($_SESSION['adminid']) && isset($_SESSION['adminpw']) && !empty($_SESSION['adminpw'])) {
    $launch_ipmi = new BudgetVM_Api(base64_decode($_GET['apikey']));
    $var->post->service = base64_decode($_GET['id']);
    $return = $launch_ipmi->call("v2", "device", "console", "get", $var);
    if ($return->success == true) {
        header('Content-Type: application/x-java-jnlp-file', true);
        header('Content-Disposition: attachment; filename="launch.jnlp"', true);
        header("Expires: Mon, 26 Jul 1997 05:00:00 GMT", true);
        header('Accept-Ranges: bytes', true);
        header("Cache-control: private", true);
        header('Pragma: private', true);
        echo base64_decode($return->result);
    }
}