function arraySelect(&$arr, $select_name, $select_attribs, $selected, $translate = false, $filteruser = false) { global $AppUI; if (!is_array($arr)) { dprint(__FILE__, __LINE__, 0, 'arraySelect called with no array'); return ''; } reset($arr); $s = "\n" . '<select name="' . $select_name . '" ' . $select_attribs . '>'; $did_selected = 0; foreach ($arr as $k => $v) { if ($filteruser) { if ($AppUI->acl()->checkLogin($k) == false && $k > 0) { continue; } } if ($translate) { $v = @$AppUI->_($v); // This is supplied to allow some Hungarian characters to // be translated correctly. There are probably others. // As such a more general approach probably based upon an // array lookup for replacements would be a better approach. AJD. $v = str_replace('ű', '�', $v); $v = str_replace('ő', '�', $v); } $s .= "\n\t" . '<option value="' . $AppUI->___($k) . '"' . ($k == $selected && !$did_selected ? ' selected="selected"' : '') . ">" . ($translate ? $v : $AppUI->___($v)) . '</option>'; if ($k == $selected) { $did_selected = 1; } } $s .= "\n</select>\n"; return $s; }
function checkAttempt() { global $gbl, $sgbl, $login, $ghtml; $match = 0; try { $att = $gbl->getFromList("loginattempt", $ip); $att->count++; $att->dbaction = "update"; } catch (Exception $e) { $att = new Loginattempt(null, null, $ip); $att->count = 1; $att->dbaction = "add"; $gbl->addToList("loginattempt", $att); } if ($att->count >= 5) { $att->delete(); $bl = new BlockedIp(null, null, $ip); $bl->dbaction = "add"; try { $gbl->addToList("blockedip", $bl); } catch (Exception $e) { dprint("Blocked up already exists. This is weird\n"); } $ghtml->print_redirect("/login/?frm_emessage=blocked"); } else { $ghtml->print_redirect("/login/?frm_emessage=login_error"); } $gbl->was(); }
function updateSwitchProgram($param) { global $gbl, $sgbl, $login, $ghtml; if_demo_throw_exception('switchprog'); $this->web_driver = $gbl->getSyncClass($this->__masterserver, $this->nname, 'web'); $this->dns_driver = $gbl->getSyncClass($this->__masterserver, $this->nname, 'dns'); $this->spam_driver = $gbl->getSyncClass($this->__masterserver, $this->nname, 'spam'); $a['web'] = $this->web_driver; $a['dns'] = $this->dns_driver; $a['spam'] = $this->spam_driver; foreach ($param as $k => $v) { if ($this->{$k} === $v) { dprint("No change for {$k}: {$v}\n"); } else { $class = strtilfirst($k, "_"); $drstring = "{$class}_driver"; rl_exec_get(null, $this->nname, array($class, 'switchDriver'), array($class, $this->{$drstring}, $v)); changeDriver($this->nname, $class, $v); $fixc = $class; if ($class === 'spam') { $fixc = "mmail"; } lxshell_return("__path_php_path", "../bin/fix/fix{$fixc}.php", "--server={$this->nname}"); $a[$class] = $v; rl_exec_get(null, $this->nname, 'slave_save_db', array('driver', $a)); } } }
static function readsmtpLog() { $date = time() - 24 * 3600 * 2; $logfile = "/var/log/kloxo/smtp.log"; $fp = fopen($logfile, "r"); $fsize = lxfile_size($logfile); $pos = lxlabsFindRightPosition($fp, $fsize, $date, time()); if ($pos === -1) { return; } $s = fgets($fp); dprint("The correct pos here: {$s}\n"); while (!feof($fp)) { $s = fgets($fp); $s = trim($s); if (!csa($s, "client allowed to relay")) { continue; } $v = strfrom($s, "rcpt: from <"); $v = strtilfirst($v, ">"); $s = explode(":", $v); $id = $s[1]; if (!isset($total[$id])) { $total[$id] = 1; } else { $total[$id]++; } } return $total; }
function w2PsessionRead($id) { $q = new DBQuery(); $q->addTable('sessions'); $q->addQuery('session_data'); $q->addQuery('UNIX_TIMESTAMP() - UNIX_TIMESTAMP(session_created) as session_lifespan'); $q->addQuery('UNIX_TIMESTAMP() - UNIX_TIMESTAMP(session_updated) as session_idle'); $q->addWhere('session_id = \'' . $id . '\''); $qid =& $q->exec(); if (!$qid || $qid->EOF) { dprint(__FILE__, __LINE__, 11, 'Failed to retrieve session ' . $id); $data = ''; } else { $max = w2PsessionConvertTime('max_lifetime'); $idle = w2PsessionConvertTime('idle_time'); // dprint(__file__, __line__, 11, "Found session $id, max=$max/" . $qid->fields['session_lifespan'] . ", idle=$idle/" . $qid->fields['session_idle']); // If the idle time or the max lifetime is exceeded, trash the // session. if ($max < $qid->fields['session_lifespan'] || $idle < $qid->fields['session_idle']) { dprint(__FILE__, __LINE__, 11, "session {$id} expired"); w2PsessionDestroy($id); $data = ''; } else { $data = $qid->fields['session_data']; } } $q->clear(); return $data; }
public function read($id) { $q = new w2p_Database_Query(); $q->addTable('sessions'); $q->addQuery('session_data'); $q->addQuery('UNIX_TIMESTAMP() - UNIX_TIMESTAMP(session_created) as session_lifespan'); $q->addQuery('UNIX_TIMESTAMP() - UNIX_TIMESTAMP(session_updated) as session_idle'); $q->addWhere('session_id = \'' . $id . '\''); $qid =& $q->exec(); if (!$qid || $qid->EOF) { dprint(__FILE__, __LINE__, 11, 'Failed to retrieve session ' . $id); $data = ''; } else { $max = $this->convertTime('max_lifetime'); $idle = $this->convertTime('idle_time'); // If the idle time or the max lifetime is exceeded, trash the // session. if ($max < $qid->fields['session_lifespan'] || $idle < $qid->fields['session_idle']) { dprint(__FILE__, __LINE__, 11, "session {$id} expired"); $this->destroy($id); $data = ''; } else { $data = $qid->fields['session_data']; } } $q->clear(); return $data; }
static function getEachfileqouta($file, $domainname, $oldtime, $newtime) { $fp = @fopen($file, "r"); print "Opening File name is :{$file}\n"; error_reporting(0); if (!$fp) { return 0; } $fsize = filesize($file); print "Here U are in Mail log file Size is:{$fsize}\n"; if ($fsize <= 5) { return 0; } $total = 0; $ret = FindRightPosition($fp, $fsize, $oldtime, $newtime, array("ftpusertraffic__pureftp", "getTimeFromString")); if ($ret < 0) { dprint("Could not find position\n"); return null; } $total = 0; while (!feof($fp)) { $string = fgets($fp); if (csa($string, $domainname)) { $total += self::LogConvertString($string); } if (self::getTimeFromString($string) > $newtime) { break; } } $total = $total / (1024 * 1024); $total = round($total, 1); fclose($fp); dprint("Returning Total From OUT SIDE This File: for {$domainname} {$total} \n"); return $total; }
function dbactionUpdate($subaction) { $obj = new COM("winmgmts:{impersonationLevel=impersonate}//./root/cimv2"); $serv = $obj->execQuery("select * from Win32_Service where Name = '{$this->main->servicename}'"); switch ($subaction) { case "toggle_boot_state": if ($this->main->isOn('boot_state')) { foreach ($serv as $s) { $s->changeStartMode('Automatic'); } } else { foreach ($serv as $s) { $s->changeStartMode('Disabled'); } } break; case "toggle_state": if ($this->main->isOn('state')) { foreach ($serv as $s) { $s->startService(); } } else { foreach ($serv as $s) { dprint("{$s->Properties_("name")}\n"); $s->stopService(); } } break; } }
static function load_gd() { if (!extension_loaded("gd")) { dprint("Warning No gd <br> "); dl("gd." . PHP_SHLIB_SUFFIX); } }
function arraySelect(&$arr, $select_name, $select_attribs, $selected, $translate = false) { global $AppUI; if (!is_array($arr)) { dprint(__FILE__, __LINE__, 0, "arraySelect called with no array"); return ''; } reset($arr); $s = "\n<select name=\"{$select_name}\" {$select_attribs}>"; $did_selected = 0; foreach ($arr as $k => $v) { if ($translate) { $v = @$AppUI->_($v); // This is supplied to allow some Hungarian characters to // be translated correctly. There are probably others. // As such a more general approach probably based upon an // array lookup for replacements would be a better approach. AJD. $v = str_replace('ű', 'û', $v); $v = str_replace('ő', 'õ', $v); } $s .= "\n\t<option value=\"" . $k . "\"" . ($k == $selected && !$did_selected ? " selected=\"selected\"" : '') . ">" . $v . "</option>"; if ($k == $selected) { $did_selected = 1; } } $s .= "\n</select>\n"; return $s; }
function GetLocationsByDayByType($date, $type) { dprint("GetLocationsByDayByType() Start."); try { $db = new DatabaseTool(); if ($date == "") { $date = date("Y-m-d"); } // create the query $query = 'SELECT DISTINCT itemid,event,fulladdress,lat,lng FROM incidents JOIN eventtypes ON incidents.event = eventtypes.eventtype WHERE pubdate = ? AND lat <> "" AND lng <> "" AND eventtypes.eventtypeid = ? GROUP BY itemid ORDER BY pubtime DESC;'; $mysqli = $db->Connect(); $stmt = $mysqli->prepare($query); $stmt->bind_param("ss", $date, $type); // bind the varibale $results = $db->Execute($stmt); // create an array to put our results into $incidents = array(); // decode the rows foreach ($results as $result) { $incident = (object) array('itemid' => $result['itemid'], 'incident' => $result['event'], 'fulladdress' => $result['fulladdress'], 'lat' => $result['lat'], 'lng' => $result['lng']); $incidents[] = $incident; } // close our DB connection $db->Close($mysqli, $stmt); } catch (Exception $e) { dprint("Caught exception: " . $e->getMessage()); } dprint("GetLocationsByDayByType() Done."); return $incidents; }
function get_deny_list($total) { $lxgpath = "__path_home_root/lxguard"; $rmt = lfile_get_unserialize("{$lxgpath}/config.info"); $wht = lfile_get_unserialize("{$lxgpath}/whitelist.info"); $wht = $wht->data; $disablehit = null; if ($rmt) { $disablehit = $rmt->data['disablehit']; } if (!($disablehit > 0)) { $disablehit = 20; } $deny = null; foreach ($total as $k => $v) { if (array_search_bool($k, $wht)) { dprint("{$k} found in whitelist... not blocking..\n"); continue; } if ($v > $disablehit) { $deny[$k] = $v; } } return $deny; }
/** * postsave functions are only called after a succesful save. They are * used to perform database operations after the event. */ function resource_postsave() { global $other_resources; global $obj; $task_id = $obj->task_id; dprint(__FILE__, __LINE__, 5, "saving resources, {$other_resources}"); if (isset($other_resources)) { $value = array(); $reslist = explode(';', $other_resources); foreach ($reslist as $res) { if ($res) { list($resource, $perc) = explode('=', $res); $value[] = array($task_id, $resource, $perc); } } // first delete any elements already there, then replace with this // list. $q = new DBQuery(); $q->setDelete('resource_tasks'); $q->addWhere('task_id = ' . $obj->task_id); $q->exec(); $q->clear(); if (count($value)) { foreach ($value as $v) { $q->addTable('resource_tasks'); $q->addInsert('task_id,resource_id,percent_allocated', $v, true); $q->exec(); $q->clear(); } } } }
static function getTrafficInfo($name) { $oldtime = time() - 40 * 3600; $newtime = time(); $file = "__path_httpd_root/{$name}/stats/{$name}-custom_log"; $file = expand_real_root($file); $fp = @lfopen($file, "r"); $total = 0; dprint("\n{$file}: " . @date('Y-m-d-H-i-s', $oldtime) . " {$newtime} " . @date('Y-m-d-H-i-s', $newtime) . "\n"); if (!$fp) { dprint("File Does Not Exist:returning Zero"); return 0; } $fsize = lfilesize($file); if ($fsize <= 10) { dprint("File Size is Less Than Zero and Returning Zero:\n"); return ""; } dprint("File Size is :{$fsize}\n\n\n"); if ($fsize > 20 * 1024) { fseek($fp, -19 * 1024, SEEK_END); $line = fgets($fp); } $i = 3; $total = 0; $count = 0; while (!feof($fp)) { $count++; $line = fgets($fp); $res[] = webtraffic::apacheLogFullString($line); } $c = 0; foreach ($res as $k => $r) { $c++; if ($count - 50 > $c) { unset($res[$k]); } } $ncount = 0; foreach ($res as $r) { if (!$r['Time']) { continue; } $file = strfrom($r['Request'], " "); $file = strtil($file, "HTTP"); $time = trim($r['Time'], "[]"); $time = strtil($time, " "); $o['realtime'] = $r['realtime']; $o['time'] = $time; $o['nname'] = $ncount; $o['file'] = $file; $o['referer'] = $r['Referer']; $o['remote_host'] = $r['Remote-Host']; $out[] = $o; $ncount++; } return $out; }
function dbactionUpdate($subaction) { dprint("here\n"); switch ($subaction) { case "add_xen_location_a": $this->check_xen_dirlocation(); break; } }
function os_addto_iis() { global $gbl, $sgbl, $login, $ghtml; $progname = $sgbl->__var_program_name; $obj = new lxCOM("winmgmts://./root/WebAdministration"); $iiso = $obj->com_get("Site.Name='{$progname}'"); try { $obj->Get("ApplicationPool")->Create("kloxo"); } catch (exception $e) { } $uobj = new lxCOM("WinNT://."); try { $user = new lxCOM("WinNT://./lxlabs"); } catch (exception $e) { $user = $uobj->create("user", "lxlabs"); } $user->setPassword("hellfire"); $user->setInfo(); $app = $obj->com_get("ApplicationPool.Name='kloxo'"); $app->object_set("ProcessModel", "IdentityType", 3); $app->object_set("ProcessModel", "UserName", "lxlabs"); $app->object_set("ProcessModel", "Password", "hellfire"); $app->Put_(); if ($iiso->__notreal) { $iisdfn = $obj->get("Site"); $homedir = convertTobackSlash($sgbl->__path_program_htmlbase); $oBinding = $obj->get("BindingElement")->SpawnInstance_(); $oBinding->BindingInformation = "*:7778:"; $oBinding->Protocol = "http"; $sBinding = $obj->get("BindingElement")->SpawnInstance_(); $sBinding->BindingInformation = "*:7777:"; $sBinding->Protocol = "https"; $iisdfn->Create($progname, array($oBinding, $sBinding), $homedir); $iiso = $obj->com_get("Site.Name='{$progname}'"); } $iiso->object_set("ApplicationDefaults", "ApplicationPool", "kloxo"); $iiso->Put_(); $exec = "c:/Program Files/lxlabs/ext/php/php.exe"; $exec = convertTobackSlash($exec); $oHandler = $obj->Get("HandlerAction")->SpawnInstance_(); $oHandler->Name = "php"; $oHandler->Path = "*.php"; $oHandler->Verb = "GET,HEAD,POST,DEBUG"; $oHandler->ScriptProcessor = "\"{$exec}\""; $oHandler->ResourceType = 0; $oHandler->Modules = "CgiModule"; $oHandler->PreCondition = "*"; $handle = $iiso->lxcom_getSection("HandlersSection"); $handle->Add("Handlers", $oHandler); $handle->Refresh_(); //$newmap = lx_array_merge(array($ScriptMaps, $list)); dprint("\n"); foreach ($handle->Handlers as $h) { dprint("{$h->Name} {$h->Path} {$h->PreCondition} {$h->Verb} {$h->Modules} type: {$h->Type} rtype: {$h->ResourceType} \n"); } }
function log_error_messages($link, $throwflag = true) { if (mysqli_errno($link)) { dprint(mysqli_error($link)); log_error(mysqli_error($link)); if ($throwflag) { throw new lxException('mysql_error', '', mysqli_error($link)); } } }
function dbactionDelete() { $pwd = posix_getpwnam($this->main->nname); if ($pwd['uid'] > 500) { lxshell_return("userdel", "-r", $this->main->nname); lxshell_return("groupdel", $this->main->nname); } else { dprint("User Id Less then 500 " . $pwd['uid'] . " Cannot Delete the User {$this->main->nname} <br> \n"); } }
function Close($mysqli) { try { $mysqli->close(); //$stmt->close(); //dprint( "[DB_LAYER] Database Connection Closed." ); } catch (Exception $e) { dprint("Caught exception: " . $e->getMessage()); } }
function log_error_messages($throwflag = true) { if (mysql_errno()) { dprint(mysql_error()); if (mysql_errno() === 1007 && csa($this->main->dbname, "_")) { log_message("Mysql Db {$this->main->dbname} already exists. and also has an underscore... Will treat this as the main db.."); log_error(mysql_error()); return true; } if ($throwflag) { throw new lxException('mysql_error', '', mysql_error()); } } }
static function initThisList($parent, $class) { $parent->setUpdateSubaction('getBeancounter'); $res = rl_exec_set($parent->__masterserver, $parent->syncserver, $parent); $parent->dbaction = 'clean'; if ($res) { foreach ($res as &$__rt) { $__rt['syncserver'] = $parent->syncserver; $__rt['parent_clname'] = createParentName("vps", $parent->nname); } } dprint($res); return $res; }
static function doUpdate($list) { $cmd = self::getYumCommand(); $file = fix_nname_to_be_variable(implode(" ", $cmd)); $file = "__path_program_root/cache/{$file}"; $plist = implode(" ", $list); while (true) { system("up2date --nox --install --nosig {$plist}", $return_value); if (!$return_value) { break; } dprint("Got error from up2date...\n"); } lunlink($file); }
function __xenimport_get_data() { lxfile_mkdir("/home/oldxenconfig-hypervm"); $list = lscandir_without_dot("/etc/xen"); foreach ($list as $l) { if (isXencfgSkip($l)) { continue; } dprint("{$l}\n"); $vm[] = __xenimport_parse_config("/etc/xen/{$l}"); //lxfile_mv("/etc/xen/$l", "/home/oldxenconfig-hypervm"); lunlink("/etc/xen/auto/{$l}"); } dprintr($vm); return $vm; }
function __cmd_desc_simplelist($p) { global $gbl, $sgbl, $login, $ghtml; ob_start(); $resource = $p['resource']; $parent = null; if (!$parent) { if (isset($p['parent-class']) && isset($p['parent-name'])) { $parent = new $p['parent-class'](null, 'localhost', $p['parent-name']); dprint($parent->nname); $parent->get(); if ($parent->dbaction === 'add') { throw new lxException("parent_doesnt_exist", "nname", $p['parent-name']); } if (!$parent->checkIfSomeParent($login->getClName())) { throw new lxException("you_are_not_the_owner_of_parent", "", $p['parent-name']); } } else { $parent = $login; } } $list = $parent->getCommandResource($resource); if (!$list) { // Fix for WHMCS needing pserver in client. if (!$parent->isAdmin() && $sgbl->isKloxo() && $resource === 'pserver') { $list['localhost'] = 'localhost'; return $list; } $list = $parent->getList($resource); if (isset($p['v-filter'])) { list($var, $val) = explode(":", $p['v-filter']); foreach ($list as $k => $l) { if ($l->{$var} !== $val) { unset($list[$k]); } } } if (!$list) { json_print("error", $p, "__error_no_resource_for_{$resource}"); exit; } $list = get_namelist_from_objectlist($list, "nname", "nname"); } ob_end_clean(); return $list; }
function parse_mapping($root, $m, $parent_path) { $a = $m->children('http://apstandard.com/ns/1/php')->attributes(); $spath = $m->attributes()->url; $parent_path = "{$parent_path}/{$spath}"; if ($a) { dprintr($a); if ((string) $a->writable === 'true') { lxfile_generic_chmod("{$root}/{$parent_path}", "0775"); dprint("{$parent_path} Is writable\n"); } } else { dprint("{$parent_path} Not writable\n"); } foreach ($m->mapping as $mp) { parse_mapping($root, $mp, $parent_path); } }
function __call($m, $arg) { $strarg = var_export($arg, true); $strarg = str_replace("\n", " ", $strarg); $existing = var_export($this->__varlist, true); $existing = str_replace("\n", " ", $existing); $call = "{$m} {$strarg} on {$this->__name} (existing {$existing})"; if ($this->__notreal) { log_log("com_error", "unreal {$call}"); return; } $comerr = false; $retcom = false; if (csb($m, "com_")) { $m = strfrom($m, "com_"); $retcom = true; } try { //$ret = call_user_func_array(array($this->__com, $m), $arg); $string = null; for ($i = 0; $i < count($arg); $i++) { $string[] = "\$arg[{$i}]"; } if ($string) { $string = implode(", ", $string); } $func = "return \$this->__com->{$m}({$string});"; dprint("{$func} \n"); $ret = eval($func); } catch (exception $e) { log_log("com_error", "Exception: {$e->getMessage()}: {$call}"); $ret = null; $call = "Exception: {$call}"; $comerr = true; } if (!$comerr) { $call = "Success..: {$call}"; } log_log("com_call", $call); if ($retcom) { return create_lxcom($ret); } return $ret; }
static function addOneWatchdog($pserver, $service, $port, $command) { $v = new watchdog(null, $pserver, "{$service}___{$pserver}"); $v->get(); if ($v->dbaction !== 'add') { dprint("{$service} {$pserver} already exists...\n"); return; } $v->servicename = $service; $v->port = $port; $v->action = $command; $v->status = "on"; $v->added_by_system = "on"; $v->syncserver = $pserver; $v->parent_clname = createClName('pserver', $pserver); $v->dbaction = 'add'; $v->createExtraVariables(); $v->was(); }
function GetTotalStatusTypes() { dprint("GetTotalStatusTypes() Start."); try { $db = new DatabaseTool(); // create the query $query = "SELECT COUNT(*) AS count FROM statustypes"; $mysqli = $db->Connect(); $stmt = $mysqli->prepare($query); $results = $db->Execute($stmt); $count = $results[0]["count"]; // close our DB connection $db->Close($mysqli, $stmt); } catch (Exception $e) { dprint("Caught exception: " . $e->getMessage()); } dprint("GetTotalStatusTypes() Done."); // return the count return $count; }
static function readSingleMail($name) { $ret['message'] = lxshell_output("__path_program_root/bin/misc/qmHandle", "-m{$name}"); $oldtime = time() - 7200; $newtime = time() - 500; $fp = fopen("/var/log/kloxo/maillog", "r"); $fsize = lxfile_size("/var/log/kloxo/maillog"); $ot = date("Y-m-d:H-i"); dprint("Start time: {$ot}\n"); $res = FindRightPosition($fp, $fsize, $oldtime, $newtime, array("mailtraffic", "getTimeFromOriginalQmailString")); if ($res < 0) { $ret['log'] = null; return $ret; } //$s = fgets($fp); dprint("here {$s}\n"); takeToStartOfLine($fp); takeToStartOfLine($fp); //$s = fgets($fp); dprint("here {$s}\n"); $delivery = null; while (!feof($fp)) { $s = fgets($fp); if (!$delivery) { if (csa($s, "starting delivery") && csa($s, "msg {$name}")) { $delivery = preg_replace("/.*delivery ([^:]*):.*/", "\$1", $s); $delivery = trim($delivery); dprint("Deliver num: {$delivery}*\n"); continue; } } else { dprint("{$s}\n"); if (csa($s, "delivery {$delivery}:")) { dprint("{$s}\n"); $ret['log'] = $s; break; } } } return $ret; }
function print_time($var, $mess = null, $dbg = 2) { static $last; $now = microtime(true); if (!isset($last[$var])) { $last[$var] = $now; return; } $diff = round($now - $last[$var], 7); $now = round($now, 7); $last[$var] = $now; if (!$mess) { return; } $diff = round($diff, 2); if ($dbg <= -1) { } else { dprint("{$mess}: {$diff} <br> \n", $dbg); } return "{$mess}: {$diff} seconds"; }