function updatesaveVPSData($param) { $sq = new Sqlite(null, "vps"); $list = $sq->getRowsWhere("syncserver = '{$this->nname}'", array("nname")); $list = get_namelist_from_arraylist($list); foreach ($list as $l) { $vps = new VPS(null, $this->nname, $l); $vps->get(); $data[$l] = $vps; } $this->__var_vpsdata = $data; $param['some_f'] = 'a'; return $param; }
// SolusVM's setting for this isn't great so we'll make our own. $sRequested["POST"]["numiptent"] = "80"; $sRequested["POST"]["ipaddresses"] = ""; $sRequested["POST"]["hostname"] = $sValue["hostname"]; $sRequested["POST"]["nameserver"] = "8.8.8.8"; $sRequested["POST"]["cpuunits"] = split_crap($sOpenVZData["vz_cpuunits"]); $sRequested["POST"]["cpulimit"] = split_crap($sOpenVZData["vz_cpus"]) * 100; $sRequested["POST"]["bandwidthlimit"] = $sValue["bandwidth"] / 1024 / 1024 / 1024; $sServerType = new $sServer->sType(); $sMethod = "database_{$sServer->sType}_create"; $sVPSId = $sServerType::$sMethod($sUser, $sRequested, 1); if (is_array($sVPSId)) { var_dump($sVPSId); die; } $sVPS = new VPS($sVPSId); echo "New VPS with ID: {$sVPSId}\n"; echo "Beginning IP assignment.\n"; if ($sIPData = $database->CachedQuery("SELECT * FROM `solusvm`.`ipaddresses` WHERE `vserverid` = :VServerId", array("VServerId" => $sValue["vserverid"]))) { foreach ($sIPData->data as $sIP) { if ($sSolusBlockData = $database->CachedQuery("SELECT * FROM `solusvm`.`ipblocks` WHERE `blockid` = :BlockId", array("BlockId" => $sIP["blockid"]))) { $sSolusBlockData = $sSolusBlockData->data[0]; if (!($sFeathurBlockData = $database->CachedQuery("SELECT * FROM blocks WHERE `gateway` = :Gateway", array("Gateway" => $sSolusBlockData["gateway"])))) { echo "Adding block because one doesn't exist for this range.\n"; $sBlock = new Block(0); $sBlock->uName = $sSolusBlockData["name"]; $sBlock->uGateway = $sSolusBlockData["gateway"]; $sBlock->uNetmask = $sSolusBlockData["mask"]; $sBlock->InsertIntoDatabase(); } else { echo "Using existing block for IPs\n";
if (is_array($sUser)) { echo json_encode($sUser); die; } } else { echo json_encode(array("json" => 1, "type" => "result", "result" => "The username and password can not be blank!")); die; } $sAction = $_POST['action']; if (empty($sAction)) { echo json_encode(array("json" => 1, "type" => "result", "result" => "You must submit an action!")); die; } if ($sUser->sPermissions == 7) { if ($sAction == 'listservers') { echo json_encode(VPS::array_servers()); die; } if ($sAction == 'createvps') { // Get server information if (!is_numeric($sRequested["POST"]["server"])) { if ($sServers = $database->CachedQuery("SELECT * FROM servers WHERE `ip_address` = :ServerIP", array(':ServerIP' => $_POST['server']))) { $sServer = new Server($sServers->data[0]["id"]); $sRequested["POST"]["server"] = $sServers->data[0]["id"]; } else { echo json_encode(array("result" => "Unfortunatly no server matches your query.")); die; } } // Get user information if ($sCheckUsers = $database->CachedQuery("SELECT * FROM accounts WHERE `email_address` = :UserEmail", array(':UserEmail' => $_POST['useremail']))) {
public function database_kvm_terminate($sUser, $sVPS, $sRequested) { global $database; $sUserPermissions = $sUser->sPermissions; if ($sUserPermissions == 7) { $sServer = new Server($sVPS->sServerId); $sSSH = Server::server_connect($sServer); $sCommandList .= "virsh autostart --disabled kvm{$sVPS->sContainerId}}"; $sCommandList .= "virsh destroy kvm{$sVPS->sContainerId};"; $sCommandList .= "rm -rf /var/feathur/configs/kvm{$sVPS->sContainerId}-vps.xml;rm -rf /var/feathur/configs/kvm{$sVPS->sContainerId}-dhcp.conf;"; $sCommandList .= "cat /var/feathur/configs/dhcpd.head /var/feathur/configs/*-dhcp.conf > /etc/dhcp/dhcpd.conf;service isc-dhcp-server restart;"; $sCommandList .= "dd if=/dev/zero of=/dev/{$sServer->sVolumeGroup}/kvm{$sVPS->sContainerId}_img;"; $sCommandList .= "lvremove -f /dev/{$sServer->sVolumeGroup}/kvm{$sVPS->sContainerId}_img;exit;"; $sCommandList = escapeshellarg($sCommandList); $sLog[] = array("command" => "VPS Termination via Screen", "result" => $sSSH->exec("screen -dm -S {$sVPS->sContainerId} bash -c {$sCommandList};")); $sSave = VPS::save_vps_logs($sLog, $sVPS); $sTerminate = $database->CachedQuery("DELETE FROM vps WHERE `id` = :VPSId", array('VPSId' => $sVPS->sId)); $sCleanIPs = $database->CachedQuery("UPDATE ipaddresses SET `vps_id` = 0 WHERE `vps_id` = :VPSId", array('VPSId' => $sVPS->sId)); return $sArray = array("json" => 1, "type" => "error", "result" => "This VPS has been terminated.", "reload" => 1); } else { return $sArray = array("json" => 1, "type" => "error", "result" => "Insufficient permissions for this action.", "reload" => 1); } }
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;
} $sPage = "templates"; $sPageType = "settings"; $sType = $_GET['type']; if ($sAction == addtemplate) { if (!empty($_GET['type']) && !empty($_GET['url'])) { $sAdd = VPS::add_template(VPS::localhost_connect(), $_GET['name'], $_GET['url'], $_GET['type']); if (is_array($sAdd)) { echo json_encode($sAdd); die; } } } if ($sAction == removetemplate) { if (!empty($_GET['id'])) { $sRemove = VPS::remove_template(VPS::localhost_connect(), $_GET['id']); if (is_array($sRemove)) { echo json_encode($sRemove); die; } } $sJson = 1; } if ($sAction == updatetemplate) { if (!empty($_GET['name']) && is_numeric($_GET['id'])) { $sUpdateTemplate = new Template($_GET['id']); $sUpdateTemplate->uName = $_GET['name']; $sUpdateTemplate->InsertIntoDatabase(); echo json_encode(array("result" => "Template name updated.", "type" => "success", "json" => "1")); die; } else {
public static function pull_status($sServer) { echo "Setting up prerequisites...\n"; $sTimestamp = time(); global $database; // Insert History $sHistory = new History(0); $sHistory->uServerId = $sServer; $sHistory->uTimestamp = $sTimestamp; $sHistory->uStatus = false; $sHistory->InsertIntoDatabase(); // Insert Statistics $sStatistics = new Statistics(0); $sStatistics->uServerId = $sServer; $sStatistics->uStatus = false; $sStatistics->uTimestamp = $sTimestamp; $sStatistics->InsertIntoDatabase(); // Connect to Server $sServer = new Server($sServer); $sSSH = Server::server_connect($sServer, "1"); if (is_array($sSSH)) { die; } // Setup and start anti-abuse script on node. if ($sServer->sType == 'openvz') { $sAbuse = escapeshellarg(file_get_contents('/var/feathur/Scripts/abuse.sh')); $sDumpCode = $sSSH->exec("mkdir -p /var/feathur/data;cd /var/feathur/data/;echo {$sAbuse} > abuse.sh;screen -dmS abuse bash -c \"cd /var/feathur/data/;bash abuse.sh;\";"); // Pull list of suspended users: $sSuspended = explode("\n", $sSSH->exec("cat /var/feathur/data/suspended.txt")); foreach ($sSuspended as $sValue) { $sValue = preg_replace('/[^0-9]/', '', $sValue); if (!empty($sValue) && $sValue >> 10) { try { $sVPS = new VPS($sValue); $sVPS->uSuspended = 2; $sVPS->InsertIntoDatabase(); } catch (Exception $e) { echo "Odd data in suspend tracker. Skipping"; } } } $sClean = $sSSH->exec("rm -rf /var/feathur/data/suspended.txt"); } // Pull system stats. echo "Connected to server...\n"; $sUptime = explode(' ', $sSSH->exec("cat /proc/uptime")); $sCPU = explode(' ', $sSSH->exec("cat /proc/loadavg")); $sUsedRAM = preg_replace('/[^0-9]/', '', $sSSH->exec("free | head -n 3 | tail -n 1 | awk '{print \$3}'")); $sTotalRAM = preg_replace('/[^0-9]/', '', $sSSH->exec("free | head -n 2 | tail -n 1 | awk '{print \$2}'")); $sDisk = $sSSH->exec("df"); $sDisk = explode("\n", trim($sDisk)); array_shift($sDisk); foreach ($sDisk as $sValue) { $sValue = explode(" ", preg_replace("/\\s+/", " ", $sValue)); if (is_numeric($sValue[2])) { $sDiskUsed = $sDiskUsed + $sValue[2]; $sDiskTotal = $sDiskTotal + $sValue[1]; } } $sDiskUsed = $sDiskUsed / 1048576; $sDiskTotal = $sDiskTotal / 1048576; $sPullBandwidth = explode("\n", $sSSH->exec("ifconfig {$interface} | grep 'RX bytes' | awk -F: '{print \$2,\$3}' | awk '{print \$1,\$6}'")); foreach ($sPullBandwidth as $sData) { if (empty($sNewBandwidth)) { $sData = explode(" ", $sData); $sData[0] = preg_replace('/[^0-9]/', '', $sData[0]); $sData[1] = preg_replace('/[^0-9]/', '', $sData[1]); $sNewBandwidth = round($sData[0] / 131072 + $sData[1] / 131072, 2); } } // Update server row. // Check to make sure that the current bandwidth is higher than last bandwidth. // If higher, update statuses, otherwise replace both values with current value. // This prevents bandwidth accounting from becoming negative. $sBandwidthNegative = $sServer->sBandwidth; if ($sNewBandwidth > $sBandwidthNegative) { $sServer->uPreviousCheck = $sServer->sLastCheck; $sServer->uLastCheck = $sTimestamp; $sServer->uLastBandwidth = $sServer->sBandwidth; $sServer->uBandwidth = $sNewBandwidth; } else { $sServer->uPreviousCheck = $sTimestamp; $sServer->uLastCheck = $sTimestamp; $sServer->uLastBandwidth = $sNewBandwidth; $sServer->uBandwidth = $sNewBandwidth; } $sServer->uLoadAverage = $sCPU[0]; $sServer->uHardDiskTotal = $sDiskTotal; $sServer->uHardDiskFree = $sDiskTotal - $sDiskUsed; $sServer->uTotalMemory = $sTotalRAM; $sServer->uFreeMemory = $sTotalRAM - $sUsedRAM; $sServer->uStatus = true; $sServer->uStatusWarning = false; $sServer->uHardwareUptime = $sUptime[0]; $sServer->InsertIntoDatabase(); // Update history $sHistory->uStatus = true; $sHistory->InsertIntoDatabase(); // Update statistics $sStatistics->uStatus = true; $sStatistics->uHardwareUptime = $sUptime[0]; $sStatistics->uTotalMemory = $sTotalRAM; $sStatistics->uFreeMemory = $sTotalRAM - $sUsedRAM; $sStatistics->uLoadAverage = $sCPU[0]; $sStatistics->uHardDiskTotal = $sDiskTotal; $sStatistics->uHardDiskFree = $sDiskTotal - $sDiskUsed; $sStatistics->uBandwidth = $sNewBandwidth; $sStatistics->InsertIntoDatabase(); // Cleanup unset($sPullBandwidth); echo "Server polling completed...\n"; // Bandwidth polling for each VPS on this server. $sBandwidthAccounting = Core::GetSetting('bandwidth_accounting'); echo "Beginning bandwidth accounting\n"; if ($sListVPS = $database->CachedQuery("SELECT * FROM `vps` WHERE `server_id` = :ServerId", array("ServerId" => $sServer->sId))) { foreach ($sListVPS->data as $sVPS) { $sVPS = new VPS($sVPS["id"]); if ($sServer->sType == 'openvz') { $sPullBandwidth = explode("\n", $sSSH->exec("vzctl exec {$sVPS->sContainerId} ifconfig {$interface} | grep 'RX bytes' | awk -F: '{print \$2,\$3}' | awk '{print \$1,\$6}';")); } if ($sServer->sType == 'kvm') { $sPullBandwidth = explode("\n", $sSSH->exec('for i in $(ip link show | grep kvm' . $sVPS->sContainerId . ' | awk \'{print $2}\' | awk -F: \'{print $1}\' | sort -u); do ifconfig $i | grep \'RX bytes\' | awk -F: \'{print $2,$3}\' | awk \'{print $1,$6}\'; done')); } foreach ($sPullBandwidth as $sData) { $sData = explode(" ", $sData); $sData[0] = round(preg_replace('/[^0-9]/', '', $sData[0]) / 1024 / 1024, 2); $sData[1] = round(preg_replace('/[^0-9]/', '', $sData[1]) / 1024 / 1024, 2); if ($sBandwidthAccounting->sValue == 'upload') { $sTotal = $sTotal + $sData[1]; } if ($sBandwidthAccounting->sValue == 'download') { $sTotal = $sTotal + $sData[2]; } if ($sBandwidthAccounting->sValue == 'both') { $sTotal = $sTotal + $sData[0] + $sData[1]; } } $sLastBandwidth = $sVPS->sLastBandwidth; if ($sLastBandwidth < $sTotal) { $sChange = round($sTotal - $sVPS->sLastBandwidth, 2); } else { if (!empty($sVPS->sBandwidthUsage)) { $sChange = round($sTotal, 2); } } echo "Bandwidth for: {$sVPS->sId} - Total: {$sTotal} - Change: +{$sChange}\n"; $sVPS->uBandwidthUsage = $sVPS->sBandwidthUsage + $sChange; $sVPS->uLastBandwidth = $sTotal; $sVPS->InsertIntoDatabase(); unset($sData); unset($sTotal); unset($sChange); } unset($sPullBandwidth); } echo "Completed.\n"; return true; }
$sRequested["POST"]["ram"] = "256"; $sRequested["POST"]["swap"] = "256"; $sRequested["POST"]["disk"] = "10"; $sRequested["POST"]["numproc"] = "128"; $sRequested["POST"]["numiptent"] = "80"; $sRequested["POST"]["ipaddresses"] = "0"; $sRequested["POST"]["hostname"] = $sVPS["nname"]; $sRequested["POST"]["nameserver"] = "8.8.8.8"; $sRequested["POST"]["password"] = random_string(12); $sRequested["POST"]["cpuunits"] = "1000"; $sRequested["POST"]["cpulimit"] = "100"; $sRequested["POST"]["bandwidthlimit"] = "512"; $sDatabase = $sStart->database_openvz_create($sUser, $sRequested); $sCreateVPS = $sStart->openvz_create($sUser, $sRequested); if (is_numeric($sCreateVPS["vps"])) { $sNewVPS = new VPS($sCreateVPS["vps"]); $sIPs = substr($sVPS["coma_vmipaddress_a"], 1); $sIPs = explode(",", $sIPs); if (empty($sAssignNewIP)) { $sAction = "assignip"; $sDBAction = "database_{$sNewVPS->sType}_{$sAction}"; $sServerAction = "{$sNewVPS->sType}_{$sAction}"; foreach ($sIPs as $sIP) { if (empty($sFirst)) { $sNewVPS->uPrimaryIP = $sIP; $sNewVPS->InsertIntoDatabase(); $sFirst = 1; } if (!empty($sIP)) { $sRequested["GET"]["ip"] = $sIP; $sDBResult = $sStart->{$sDBAction}($sUser, $sNewVPS, $sRequested);
public function database_openvz_terminate($sUser, $sVPS, $sRequested) { global $database; $sUserPermissions = $sUser->sPermissions; if ($sUserPermissions == 7) { $sServer = new Server($sVPS->sServerId); $sSSH = Server::server_connect($sServer); $sLog[] = array("command" => "vzctl stop {$sVPS->sContainerId}", "result" => $sSSH->exec("vzctl stop {$sVPS->sContainerId}")); $sLog[] = array("command" => "vzctl destroy {$sVPS->sContainerId}", "result" => $sSSH->exec("vzctl destroy {$sVPS->sContainerId}")); $sSave = VPS::save_vps_logs($sLog, $sVPS); $sTerminate = $database->CachedQuery("DELETE FROM vps WHERE `id` = :VPSId", array('VPSId' => $sVPS->sId)); $sCleanIPs = $database->CachedQuery("UPDATE ipaddresses SET `vps_id` = 0 WHERE `vps_id` = :VPSId", array('VPSId' => $sVPS->sId)); return $sArray = array("json" => 1, "type" => "error", "result" => "This VPS has been terminated.", "reload" => 1); } else { return $sArray = array("json" => 1, "type" => "error", "result" => "Insufficient permissions for this action.", "reload" => 1); } }