include_once "htmllib/lib/include.php"; initProgram('admin'); $slave = $argv[1]; $sq = new Sqlite(null, 'pserver'); if (!$sq->getRowsWhere("nname = '{$slave}'")) { print "No slave by {$slave}\n"; exit; } $driverapp = $gbl->getSyncClass(null, $slave, 'vps'); if ($driverapp !== 'openvz') { print "driver for {$slave} not openvz\n"; exit; } $shift = $argv[2]; if (!$shift) { $shift = 1000; } $sq = new Sqlite(null, 'vps'); $res = $sq->getRowsWhere("syncserver = '{$slave}'", array('nname')); $list = get_namelist_from_arraylist($res); foreach ($list as $l) { $o = new Vps(null, $slave, $l); $o->get(); $param['vpsid'] = $o->vpsid + $shift; print "Moving {$o->nname} from {$o->vpsid} to {$param['vpsid']}\n"; $o->updatechangeVPSid($param); $o->vpsid = $param['vpsid']; $o->setUpdateSubaction('changevpsid'); $o->was(); }
function filltraffictable() { global $gbl, $login, $ghtml; initProgram('admin'); $t = ""; // Fake domain to store the time the last stats finding was done. $laccessdom = new Vps(null, null, '__last_access_domain_'); try { $laccess = $laccessdom->getFromList('vpstraffic', '__last_access_domain_'); } catch (exception $e) { dprint("not getting\n"); $laccess = null; } if (!$laccess) { $laccess = new Vpstraffic(null, null, '__last_access_domain_'); $oldtime = 0; $laccess->parent_clname = 'vps-__last_access_domain_'; $laccess->dbaction = 'add'; } else { $oldtime = $laccess->timestamp; } if ($oldtime && time() - $oldtime > 5 * 3600 * 24) { $oldtime = time() - 5 * 3600 * 24; $laccess->timestamp = $oldtime; $laccess->setUpdateSubaction(); $laccess->write(); } $flag = 0; if ($oldtime == 0) { // 8 days back $oldtime = @mktime(00, 01, 00, date("n"), date("j") - 2, date("Y")); // Start of Jan //$oldtime = mktime( 00 , 01, 00 , 1 ,1, date("Y")); $flag = 1; } // $newtime = mktime( 00 , 01, 00 , date("n") , date("j") ,date("Y")); $newtime = time(); $old = $oldtime; $new = $newtime; if ($newtime - $oldtime <= 19 * 60 * 60) { dprint("Less than a day:"); dprint("\n\n\n\n"); return; } $j = 0; for ($i = $newtime; $i >= $oldtime; $i -= 24 * 60 * 60) { if ($j > 0) { $timearray[] = $new . "-" . $i; } $new = $i; $j++; } if ($flag != 1) { $timearray[] = $new . "-" . $oldtime; } $timearray = array_reverse($timearray); foreach ($timearray as $t1) { $t = explode("-", $t1); $newtime = $t[0]; $oldtime = $t[1]; if ($newtime - $oldtime < 4 * 60 * 60) { continue; } $o = @strftime("%c", $oldtime); $n = @strftime("%c", $newtime); print "\n\n{$o} to ... {$n}\n\n"; findtraffic($oldtime, $newtime); // Write every time, otherwise, the traffic calculation breaks off in the middle, it will be left inconsistent. $laccess->timestamp = $newtime; $laccess->setUpdateSubaction(); $laccess->write(); } // This is the time at which this was run last time. $laccess->timestamp = time(); $laccess->setUpdateSubaction(); $laccess->write(); }
function trafficperslave($slave, $oldtime, $newtime) { global $gbl, $sgbl, $login, $ghtml; $sq = new Sqlite(null, 'vps'); $res = $sq->getRowswhere("syncserver = '{$slave}'", array('nname')); if (!$res) { return; } foreach ($res as $r) { $vps = new Vps(null, null, $r['nname']); $vps->get(); $vpslist[] = $vps; } $list = null; foreach ($vpslist as $d) { $rt = new Remote(); if ($d->isXen()) { $rt->viflist = $d->getViflist(); } else { $rt->vpsid = $d->vpsid; } $rt->nname = $d->nname; $list[$d->nname] = $rt; } $driverapp = $gbl->getSyncClass(null, $slave, 'vps'); try { $vps_usage = rl_exec_get(null, $slave, array("vpstraffic__{$driverapp}", 'findTotaltrafficUsage'), array($list, $oldtime, $newtime)); } catch (exception $e) { exit; } dprintr($vps_usage); $res = ""; foreach ($vpslist as $d) { $res['nname'] = "{$d->nname}:{$oldtime}:{$newtime}"; $domt = new Vpstraffic(null, null, $res['nname']); $res['timestamp'] = @strftime("%c", $newtime); $res['oldtimestamp'] = @strftime("%c", $oldtime); $res['ddate'] = time(); $res['comment'] = null; $res['parent_list'] = null; $res['parent_clname'] = $d->getClName(); $res['traffic_usage'] = $vps_usage[$d->nname]['total']; $res['incoming_usage'] = $vps_usage[$d->nname]['incoming']; $res['outgoing_usage'] = $vps_usage[$d->nname]['outgoing']; // print_r($res); $domt->create($res); $domt->was(); } $firstofmonth = @mktime(00, 01, 00, @date("n"), 1, @date("Y")); $today = time() + 2 * 24 * 60 * 60; if ($vpslist) { foreach ($vpslist as $vps) { $vpst = $vps->getList("vpstraffic"); $list = get_namelist_from_objectlist($vpst); $tu = trafficGetIndividualObjectTotal($vpst, $firstofmonth, $today, $vps->nname); $sq->rawQuery("update vps set used_q_traffic_usage = '{$tu}' where nname = '{$vps->nname}'"); list($month, $year) = get_last_month_and_year(); $tlu = VpstrafficHistory::getMonthTotal($vpst, $month, $year, null); $tlu = $tlu['traffic_usage']; $sq->rawQuery("update vps set used_q_traffic_last_usage = '{$tlu}' where nname = '{$vps->nname}'"); /* try { $sgbl->__var_backupdisk_usage[$vps->getClName()] = rl_exec_get(null, $vps->syncserver, array("vps", "getBackupDiskSize"), array($vps->nname)); } catch (Exception $e) { $sgbl->__var_backupdisk_usage[$vps->getClName()] = null; } */ } } }