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; }
<?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(); }