function getFreeIp($num) { if (!$num) { return; } if (!$this->isOn('freeflag')) { return null; } $res = null; $list = $this->getIndividualIpList(); $sq = new Sqlite(null, 'tmpipassign'); $ctime = time(); $ctime -= 100; $sq->rawQuery("delete from tmpipassign where (ddate + 0) < {$ctime}"); $pingip = null; foreach ($list as $l) { $p = $sq->getRowsWhere("nname = '{$l}'"); if ($p) { continue; } if (ippool::checkIfAlreadyAssigned('vps', $l)) { //log_log("ip_pool", "$l is already assigned skipping...\n"); continue; } if ($num <= 100) { try { full_validate_ipaddress($l); } catch (exception $e) { log_log("ip_pool", "Can ping {$l}... Skipping...\n"); $pingip[] = $l; continue; } } $res[] = $l; if (count($res) >= $num) { return $res; } } $writeflag = false; if (!$res) { $this->freeflag = 'dull'; $writeflag = true; } if ($pingip) { $writeflag = true; foreach ($pingip as $p) { $op = new ippoolpingip_a(null, null, $p); $this->ippoolpingip_a[$p] = $op; } } if ($writeflag) { $this->setUpdateSubaction(); $this->write(); } return $res; }
function createShowPropertyList(&$alist) { global $gbl, $sgbl, $login, $ghtml; if ($ghtml->frm_subaction === 'forcedeletepserver') { $alist['property'] = pserver::createListAlist($this, 'pserver'); return; } if ($ghtml->frm_subaction === 'deleteorphanedvps') { $alist['property'] = vps::createListAlist($this, 'pserver'); return; } if ($ghtml->frm_subaction === 'ippool') { $alist['property'] = ippool::createListAlist($this, 'ippool'); } else { $alist['property'][] = "a=show"; $alist['property'][] = "o=sp_specialplay&a=updateform&sa=skin"; } }
<?php include_once "htmllib/lib/include.php"; initProgram('admin'); $list = $login->getList('ippool'); $sq = new Sqlite(null, 'tmpipassign'); $res = $sq->getTable(); foreach ($res as $r) { if (!ippool::checkIfAlreadyAssigned('vps', $r['nname'])) { $sq->rawQuery("delete from tmpipassign where nname = '{$r['nname']}';"); continue; } if (time() - $r['ddate'] > 40) { $sq->rawQuery("delete from tmpipassign where nname = '{$r['nname']}';"); } } foreach ($list as $l) { $l->freeflag = 'on'; $fip = $l->getFreeIp(10000); if ($fip) { $l->freeflag = 'on'; } else { $l->freeflag = 'dull'; } $l->setUpdateSubaction(); $l->write(); }
function postAdd() { global $gbl, $sgbl, $login, $ghtml; $parent = $this->getParentO(); $this->cpstatus = 'on'; $this->status = 'create'; $this->state = 'ok'; $this->kloxo_flag = 'on'; $this->rootpassword = $this->realpass; $this->username = str_replace(".", "", $this->nname); if ($this->isOn('use_resourceplan_f')) { $template = getFromAny(array($login, $parent), 'resourceplan', $this->resourceplan_f); if (!$template) { throw new lxexception("the_plan_doesnt_exist", 'resourceplan_f', $this->resourceplan_f); } $this->resourceplan_used = $this->resourceplan_f; $this->priv = clone $template->priv; $this->fixPrivUnset(); $this->changePlanSpecific($template); } if ($this->one_ipaddress_f) { full_validate_ipaddress($this->one_ipaddress_f); } $this->rootpassword_changed = 'on'; if ($this->one_ipaddress_f) { $ipadd = new vmipaddress_a(null, $this->syncserver, $this->one_ipaddress_f); $this->vmipaddress_a[$ipadd->nname] = $ipadd; } $syncs = new Pserver(null, $this->syncserver, $this->syncserver); $syncs->get(); if (is_unlimited($this->priv->vmipaddress_a_num)) { $this->priv->vmipaddress_a_num = 2; } if ($this->num_ipaddress_f) { $netinfo = $syncs->getIpPool($this->num_ipaddress_f); $totallist = $netinfo['ip']; if (!$this->nameserver) { $this->nameserver = $netinfo['nameserver']; } $this->networkgateway = $netinfo['networkgateway']; $this->networknetmask = $netinfo['networknetmask']; if ($totallist) { foreach ($totallist as $ip) { $ipadd = new vmipaddress_a(null, $this->syncserver, $ip); $this->vmipaddress_a[$ipadd->nname] = $ipadd; ippool::addToTmpIpAssign($l); } } } $this->used->vmipaddress_a_num = count($this->vmipaddress_a); if (!$this->hostname) { $this->hostname = strtil($this->nname, ".vm"); } $this->createSyncClass(); $this->createPublicPrivate($sslvar); // hack hack convert listpriv into a differnet object. $driverapp = $gbl->getSyncClass($this->__masterserver, $this->syncserver, 'vps'); $this->ttype = $driverapp; $this->getBestLocation(); $func = "postadd_{$driverapp}"; $this->{$func}(); // $this->distributeChildQuota(); //////////////////// /* if (exists_in_db($this->__masterserver, "uuser", $uuser->nname)) { throw new lxexception('user_exists_in_db', 'uuser'); } */ $this->setUpOsTemplateDownloadParam(); $backup = new LxBackup($this->__masterserver, $this->__readserver, $this->getClName()); $backup->initThisDef(); $this->AddObject('lxbackup', $backup); $this->lxclientpostAdd(); }