示例#1
0
 public function database_kvm_addip($sUser, $sVPS, $sRequested)
 {
     $sUserPermissions = $sUser->sPermissions;
     if ($sUserPermissions == 7) {
         $sIPs = $sRequested["GET"]["ip"];
         global $database;
         if ($sBlocks = $database->CachedQuery("SELECT * FROM server_blocks WHERE `server_id` = :ServerId AND `ipv6` = 0", array('ServerId' => $sVPS->sServerId))) {
             foreach ($sBlocks->data as $key => $value) {
                 if ($sIP = $database->CachedQuery("SELECT * FROM ipaddresses WHERE `block_id` = :BlockId AND `vps_id` = 0", array('BlockId' => $value["block_id"]))) {
                     foreach ($sIP->data as $subvalue) {
                         if ($sCurrentIPs < $sIPs) {
                             $sUpdate = $database->CachedQuery("UPDATE ipaddresses SET `vps_id` = :VPSId WHERE `id` = :Id", array('VPSId' => $sVPS->sId, 'Id' => $subvalue["id"]));
                             if (empty($sVPS->sPrimaryIP) || !($sData = $database->CachedQuery("SELECT * FROM ipaddresses WHERE `vps_id` = :VPSId AND `ip_address` = :PrimaryIP", array('VPSId' => $sVPS->sId, 'PrimaryIP' => $sVPS->sPrimaryIP)))) {
                                 $sVPS->uPrimaryIP = $subvalue["ip_address"];
                                 $sVPS->InsertIntoDatabase();
                             }
                             $sMacTotal = count(explode(",", $sVPS->sMac));
                             $sIPList = VPS::list_ipspace($sVPS);
                             $sIPCount = count($sIPList);
                             if ($sIPCount > $sMacTotal) {
                                 $sMac = generate_mac();
                                 $sCurrentMac = $sVPS->sMac;
                                 if (empty($sCurrentMac)) {
                                     $sVPS->uMac = $sMac;
                                 } else {
                                     $sVPS->uMac = $sVPS->sMac . "," . $sMac;
                                 }
                                 $sVPS->InsertIntoDatabase();
                             }
                             $sCurrentIPs++;
                         }
                     }
                 }
             }
             if (empty($sCurrentIPs)) {
                 return $sArray = array("json" => 1, "type" => "error", "result" => "Unfortunatly there are 0 free IPs!");
             }
             return true;
         } else {
             return $sResult = array("result" => "Unfortunatly there are no blocks assigned to this server?", "json" => 1, "type" => "error");
         }
     } else {
         return $sArray = array("json" => 1, "type" => "error", "result" => "Insufficient permissions for this action.");
     }
 }
示例#2
0
if (!empty($sAction)) {
    set_time_limit(100);
    $sStart = new $sVPS->sType();
    $sDBAction = "database_{$sVPS->sType}_{$sAction}";
    $sServerAction = "{$sVPS->sType}_{$sAction}";
    if (method_exists($sStart, $sDBAction) === true && method_exists($sStart, $sServerAction) === true) {
        $sDBResult = $sStart->{$sDBAction}($sUser, $sVPS, $sRequested);
        if (is_array($sDBResult)) {
            echo json_encode($sDBResult);
            die;
        }
        $sServerResult = $sStart->{$sServerAction}($sUser, $sVPS, $sRequested);
        if (!empty($sServerResult["json"])) {
            echo json_encode($sServerResult);
            die;
        }
    } else {
        echo json_encode(array("json" => 1, "type" => "error", "result" => "Invalid action requested. Please try again.", "reload" => 1));
        die;
    }
}
// Check to make sure VPS isn't rebuilding.
if ($sVPS->sRebuilding == 1) {
    $sUserView .= Templater::AdvancedParse($sTemplate->sValue . '/rebuild', $locale->strings, array("VPS" => array("data" => $sVPS->uData)));
    echo Templater::AdvancedParse($sTemplate->sValue . '/master', $locale->strings, array("Content" => $sUserView, "Page" => "main"));
    die;
}
$sVPSOwner = new User($sVPS->sUserId);
$sUserView .= Templater::AdvancedParse($sTemplate->sValue . '/' . $sVPS->sType . '.view', $locale->strings, array("VPS" => array("data" => $sVPS->uData), "IPs" => VPS::list_ipspace($sVPS), "Templates" => VPS::list_templates($sVPS), "Servers" => VPS::list_servers($sVPS), "User" => array("data" => $sVPSOwner->uData), "UserVPSList" => VPS::list_uservps($sVPS)));
echo Templater::AdvancedParse($sTemplate->sValue . '/master', $locale->strings, array("Content" => $sUserView, "Page" => "main"));
die;