Beispiel #1
0
function generate_mac()
{
    global $database;
    while ($i <= 6) {
        $sGen[] = dechex(rand(0, 15));
        $i++;
    }
    $sMac = "00:16:3c:" . $sGen[0] . $sGen[1] . ":" . $sGen[2] . $sGen[3] . ":" . $sGen[4] . $sGen[5];
    if ($sExists = $database->CachedQuery("SELECT * FROM vps WHERE `mac` LIKE :Mac", array('Mac' => $sMac))) {
        return generate_mac();
    } else {
        return $sMac;
    }
}
         } else {
             echo "Using existing IP.\n";
             $sIPAdd = new IP($sIPExists->data[0]["id"]);
             $sIPAdd->uVPSId = $sVPS->sId;
             $sIPAdd->InsertIntoDatabase();
         }
         $sIPTotal++;
     }
 }
 $sVPS->uPrimaryIP = $sValue["mainipaddress"];
 $sVPS->uMac = $sKVMData["mac"];
 $sVPS->InsertIntoDatabase();
 $sTotalMacs = 1;
 $sMac = $sVPS->sMac;
 while ($sTotalMacs < $sIPTotal) {
     $sMac .= "," . generate_mac();
     $sTotalMacs++;
 }
 if ($sMac != $sVPS->sMac) {
     $sVPS->uMac = $sMac;
     $sVPS->InsertIntoDatabase();
 }
 echo "Generating new configs for VPS...\n";
 $sCreateConfig = $sServerType->kvm_config($sUser, $sVPS, $sRequested);
 $sCreateDHCP = $sServerType->kvm_dhcp($sUser, $sVPS, $sRequested);
 echo "Shutting down VPS under SolusVM's control, renaming LV...\n";
 $sServerConnect = $sServer->server_connect($sServer);
 $sShutdown = $sServerConnect->exec("virsh destroy kvm{$sKVMData["xid"]};lvrename {$sServer->sVolumeGroup} kvm{$sKVMData["xid"]}_img kvm{$sVPS->sContainerId}_img;");
 echo "Starting up VPS under Feathur's control.\n";
 $sBoot = $sServerType->kvm_boot($sUser, $sVPS, $sRequested);
 echo $sBoot['result'] . "\n";
 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.");
     }
 }