本文整理汇总了PHP中IP::InsertIntoDatabase方法的典型用法代码示例。如果您正苦于以下问题:PHP IP::InsertIntoDatabase方法的具体用法?PHP IP::InsertIntoDatabase怎么用?PHP IP::InsertIntoDatabase使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IP
的用法示例。
在下文中一共展示了IP::InsertIntoDatabase方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: Block
echo "Using existing block for IPs\n";
$sBlock = new Block($sFeathurBlockData->data["0"]["id"]);
}
}
if (!($sIPExists = $database->CachedQuery("SELECT * FROM `ipaddresses` WHERE `ip_address` = :IP", array('IP' => $sIP["ipaddress"])))) {
echo "Adding IP to database.\n";
$sIPAdd = new IP(0);
$sIPAdd->uIPAddress = $sIP["ipaddress"];
$sIPAdd->uVPSId = $sVPS->sId;
$sIPAdd->uBlockId = $sBlock->sId;
$sIPAdd->InsertIntoDatabase();
} 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->InsertIntoDatabase();
echo "Moving VPS configs to new ID...\n";
$sCommandList = "vzctl chkpnt {$sValue["ctid"]} --dumpfile /tmp/Dump.{$sValue["ctid"]};";
$sCommandList .= "mv /etc/vz/conf/{$sValue["ctid"]}.conf /etc/vz/conf/{$sVPS->sContainerId}.conf;";
$sCommandList .= "mv /vz/private/{$sValue["ctid"]} /vz/private/{$sVPS->sContainerId};";
$sCommandList .= "mv /vz/root/{$sValue["ctid"]} /vz/root/{$sVPS->sContainerId};";
$sCommandList .= "vzctl restore {$sVPS->sContainerId} --dumpfile /tmp/Dump.{$sValue["ctid"]};";
$sServerConnect = $sServer->server_connect($sServer);
$sUpdate = $sServerConnect->exec($sCommandList);
$sStatus = $sServerConnect->exec("vzctl status {$sVPS->sContainerId};");
示例2: database_openvz_assignip
public function database_openvz_assignip($sUser, $sVPS, $sRequested)
{
$sUserPermissions = $sUser->sPermissions;
$sVPSUser = new User($sVPS->sUserId);
if ($sUserPermissions == 7) {
global $database;
$sServer = new Server($sVPS->sServerId);
$sSSH = Server::server_connect($sServer);
$sIP = $sRequested["GET"]["ip"];
$sCheckExisting = $database->CachedQuery("SELECT * FROM ipaddresses WHERE `ip_address` = :IPAddress", array('IPAddress' => $sIP));
if (!empty($sCheckExisting)) {
foreach ($sCheckExisting->data as $value) {
if (empty($value["vps_id"])) {
$sIPList[] = array("id" => $value["id"], "ip_address" => $value["ip_address"]);
}
$sTotalIPs++;
}
}
$sAvailableIPs = count($sIPList);
if ($sAvailableIPs == 1) {
$sUpdate = $database->CachedQuery("UPDATE ipaddresses SET `vps_id` = :VPSId WHERE `id` = :Id", array('VPSId' => $sVPS->sId, 'Id' => $sIPList[0]["id"]));
$sIPs = $database->CachedQuery("SELECT * FROM ipaddresses WHERE `vps_id` = :VPSId", array('VPSId' => $sVPS->sId));
foreach ($sIPs->data as $subvalue) {
$sCommand .= "vzctl set {$sVPS->sContainerId} --ipadd {$subvalue["ip_address"]} --save;";
$sTotal++;
}
$sLog[] = array("command" => $sCommand, "result" => $sSSH->exec($sCommand));
$sVariable = array("ip" => urlencode($sIP));
return $sArray = array("json" => 1, "type" => "success", "result" => "The IP {$sIP} was added to this VPS.", "reload" => 1);
} elseif (empty($sTotalIPs) && empty($sAvailableIPs)) {
$sIPExpand = explode(".", $sIP);
if ($sFindBlock = $database->CachedQuery("SELECT * FROM ipaddresses WHERE `ip_address` LIKE :IPAddress", array('IPAddress' => "%{$sIPExpand[0]}.{$sIPExpand[1]}.{$sIPExpand[2]}%"))) {
$sIPAdd = new IP(0);
$sIPAdd->uIPAddress = $sIP;
$sIPAdd->uVPSId = $sVPS->sId;
$sIPAdd->uBlockId = $sFindBlock->data[0]["block_id"];
$sIPAdd->InsertIntoDatabase();
$sIPs = $database->CachedQuery("SELECT * FROM ipaddresses WHERE `vps_id` = :VPSId", array('VPSId' => $sVPS->sId));
foreach ($sIPs->data as $subvalue) {
$sCommand .= "vzctl set {$sVPS->sContainerId} --ipadd {$subvalue["ip_address"]} --save;";
$sTotal++;
}
$sLog[] = array("command" => $sCommand, "result" => $sSSH->exec($sCommand));
$sVariable = array("ip" => urlencode($sIP));
return $sArray = array("json" => 1, "type" => "success", "result" => "The IP {$sIP} was added to this VPS.", "reload" => 1);
} else {
$sIPAdd = new IP(0);
$sIPAdd->uIPAddress = $sIP;
$sIPAdd->uVPSId = $sVPS->sId;
$sIPAdd->uBlockId = 0;
$sIPAdd->InsertIntoDatabase();
$sIPs = $database->CachedQuery("SELECT * FROM ipaddresses WHERE `vps_id` = :VPSId", array('VPSId' => $sVPS->sId));
foreach ($sIPs->data as $subvalue) {
$sCommand .= "vzctl set {$sVPS->sContainerId} --ipadd {$subvalue["ip_address"]} --save;";
$sTotal++;
}
$sLog[] = array("command" => $sCommand, "result" => $sSSH->exec($sCommand));
$sVariable = array("ip" => urlencode($sIP));
return $sArray = array("json" => 1, "type" => "success", "result" => "The IP {$sIP} was added to this VPS.", "reload" => 1);
}
} elseif (!empty($sTotalIPs) && $sAvailableIPs != 1) {
return $sArray = array("json" => 1, "type" => "error", "result" => "The IP you gave is assigned to a VPS!");
} else {
return $sArray = array("json" => 1, "type" => "error", "result" => "An unknown error occured!");
}
} else {
return $sArray = array("json" => 1, "type" => "error", "result" => "Insufficient permissions for this action.");
}
}
示例3: database_kvm_assignip
public function database_kvm_assignip($sUser, $sVPS, $sRequested)
{
$sUserPermissions = $sUser->sPermissions;
$sVPSUser = new User($sVPS->sUserId);
if ($sUserPermissions == 7) {
global $database;
$sIP = $sRequested["GET"]["ip"];
$sCheckExisting = $database->CachedQuery("SELECT * FROM ipaddresses WHERE `ip_address` = :IPAddress", array('IPAddress' => $sIP));
if (!empty($sCheckExisting)) {
foreach ($sCheckExisting->data as $value) {
if (empty($value["vps_id"])) {
$sIPList[] = array("id" => $value["id"], "ip_address" => $value["ip_address"]);
}
$sTotalIPs++;
}
}
$sAvailableIPs = count($sIPList);
if ($sAvailableIPs == 1) {
$sUpdate = $database->CachedQuery("UPDATE ipaddresses SET `vps_id` = :VPSId WHERE `id` = :Id", array('VPSId' => $sVPS->sId, 'Id' => $sIPList[0]["id"]));
return true;
} elseif (empty($sTotalIPs) && empty($sAvailableIPs)) {
$sIPExpand = explode(".", $sIP);
if ($sFindBlock = $database->CachedQuery("SELECT * FROM ipaddresses WHERE `ip_address` LIKE :IPAddress", array('IPAddress' => "%{$sIPExpand[0]}.{$sIPExpand[1]}.{$sIPExpand[2]}%"))) {
$sIPAdd = new IP(0);
$sIPAdd->uIPAddress = $sIP;
$sIPAdd->uVPSId = $sVPS->sId;
$sIPAdd->uBlockId = $sFindBlock->data[0]["block_id"];
$sIPAdd->InsertIntoDatabase();
return true;
} else {
$sIPAdd = new IP(0);
$sIPAdd->uIPAddress = $sIP;
$sIPAdd->uVPSId = $sVPS->sId;
$sIPAdd->uBlockId = 0;
$sIPAdd->InsertIntoDatabase();
return true;
}
} elseif (!empty($sTotalIPs) && $sAvailableIPs != 1) {
return $sArray = array("json" => 1, "type" => "error", "result" => "The IP you gave is assigned to a VPS!");
} else {
return $sArray = array("json" => 1, "type" => "error", "result" => "An unknown error occured!");
}
} else {
return $sArray = array("json" => 1, "type" => "error", "result" => "Insufficient permissions for this action.");
}
}
示例4: add_ipv4_range
public static function add_ipv4_range($sRequested)
{
global $database;
if (filter_var($sRequested["GET"]["start"], FILTER_VALIDATE_IP) && filter_var($sRequested["GET"]["end"], FILTER_VALIDATE_IP)) {
if (is_numeric($sRequested["GET"]["pool"])) {
$sStart = ip2long($sRequested["GET"]["start"]);
$sEnd = ip2long($sRequested["GET"]["end"]);
$sTotalIPs = $sEnd - $sStart;
if ($sTotalIPs < 256 && $sTotalIPs > 0) {
$sCurrent = $sStart;
while ($sCurrent <= $sEnd) {
if (!($sIPExists = $database->CachedQuery("SELECT * FROM `ipaddresses` WHERE `ip_address` = :IP", array('IP' => long2ip($sCurrent))))) {
$sIP = new IP(0);
$sIP->uIPAddress = long2ip($sCurrent);
$sIP->uVPSId = 0;
$sIP->uBlockId = $sRequested["GET"]["pool"];
$sIP->InsertIntoDatabase();
unset($sIP);
}
$sCurrent++;
}
return $sSuccess = array("content" => "The IPs have been added to the pool.");
} else {
return $sError = array("red" => "You must specify a valid range or IP!");
}
} else {
return $sError = array("red" => "Invalid block. Please reload and try again!");
}
} else {
return $sError = array("red" => "You must specify a valid range or IP!");
}
}