function reconnect() { global $gbl, $sgbl, $login, $ghtml; $this->__readserver = 'localhost'; $user = $sgbl->__var_admin_user; $db = $sgbl->__var_dbf; $pass = getAdminDbPass(); $readserver = $this->__readserver; $fdbvar = "__fdb_" . $this->__readserver; log_log("database_reconnect", "Reconnecting again"); if ($sgbl->__var_database_type === 'mysql') { $gbl->{$fdbvar} = mysql_connect($readserver, $user, $pass); mysql_select_db($db); self::$__database = 'mysql'; } else { if ($sgbl->__var_database_type === 'mssql') { //print("$user, $pass <br> \n"); //$gbl->$fdbvar = mssql_connect('\\.\pipe\MSSQL$LXLABS\sql\query'); $gbl->{$fdbvar} = mssql_pconnect("{$readserver},{$sgbl->__var_mssqlport}"); mssql_select_db($db); self::$__database = 'mssql'; } else { $gbl->{$fdbvar} = new PDO("sqlite:{$db}"); self::$__database = 'sqlite'; } } }
function updatecleanup_main() { global $argc, $argv; global $gbl, $sgbl, $login, $ghtml; $program = $sgbl->__var_program_name; $opt = parse_opt($argv); if ($opt['type'] === 'master') { initProgram('admin'); $flg = "__path_program_start_vps_flag"; if (!lxfile_exists($flg)) { set_login_skin_to_feather(); } } else { $login = new Client(null, null, 'update'); } print "Executing UpdateCleanup. This can take a long time. Please be patient\n"; log_log("update", "Executing Updatecleanup"); // // Cleanup old lxlabs.repo file // print "Fixing Repo's\n"; if (lxfile_exists("/etc/yum.repos.d/lxcenter.repo")) { if (lxfile_exists("/etc/yum.repos.d/lxlabs.repo")) { lxfile_mv("/etc/yum.repos.d/lxlabs.repo", "/etc/yum.repos.d/lxlabs.repo.lxsave"); system("rm -f /etc/yum.repos.d/lxlabs.repo"); } } if (lxfile_exists("CVS")) { print "Found Development version, we just go on.\n"; // exit; } if ($opt['type'] === 'master') { $sgbl->slave = false; if (!is_secondary_master()) { print "Update database\n"; updateDatabaseProperly(); print "Fix Extra database issues\n"; fixExtraDB(); print "Update extra issues\n"; doUpdateExtraStuff(); print "Get Driver info\n"; lxshell_return("__path_php_path", "../bin/common/driverload.php"); } print "Starting Update all slaves\n"; update_all_slave(); print "Fix main {$program} databasefile\n"; cp_dbfile(); } else { $sgbl->slave = true; } if (!is_secondary_master()) { print "Starting update cleanups\n"; updatecleanup(); } lxfile_touch("__path_program_start_vps_flag"); }
static function checkAndThrow($publickey, $privatekey, $throwname = null) { global $gbl, $sgbl, $login, $ghtml; if (!self::checkKeyCert($publickey, $privatekey)) { if ($gbl->__restore_flag) { log_log("restore", "certificate_key_file_corrupted"); } else { throw new lxException("certificate_key_file_corrupted", '', $throwname); } } //dprint("Succeesffully tested <br> <br> "); }
function updatecleanup_main() { global $argc, $argv; global $gbl, $sgbl, $login, $ghtml; $prognameNice = $sgbl->__var_program_name_nice; $opt = parse_opt($argv); if ($opt['type'] === 'master') { initProgram('admin'); $flg = "__path_program_start_vps_flag"; if (!lxfile_exists($flg)) { set_login_skin_to_feather(); } } else { $login = new Client(null, null, 'update'); } print "Executing UpdateCleanup. This can take a long time. Please be patient\n"; log_log("update", "Executing Updatecleanup"); // Do things that is needed before the cleanup starts. print "########################################\n"; print "## Executing PreCleanup ##\n"; print "########################################\n"; doBeforeUpdate(); print "########################################\n"; print "## Finished PreCleanup ##\n"; print "########################################\n"; if ($opt['type'] === 'master') { $sgbl->slave = false; if (!is_secondary_master()) { print "Update database (if needed)\n"; updateDatabaseProperly(); if (call_with_flag("fixExtraDB")) { print "- Fixed\n"; } print "Update extra issues (if any)\n"; doUpdateExtraStuff(); print "Get Driver info\n"; lxshell_return("__path_php_path", "../bin/common/driverload.php"); } print "Starting Update all slaves\n"; update_all_slave(); print "Fix main {$prognameNice} databasefile\n"; cp_dbfile(); } else { $sgbl->slave = true; } if (!is_secondary_master()) { print "Starting update cleanups\n"; cleanupUpdate(); } if (!lxfile_exists($flg)) { lxfile_touch($flg); } }
function setQuota() { if ($this->main->ftp_disk_usage > 0) { lxshell_return("pure-pw", "usermod", $this->main->nname, "-N", $this->main->ftp_disk_usage, "-m"); } else { // This is because the shell_return cannot send '' to the program. $cmd = "pure-pw usermod {$this->main->nname} -N '' -m"; log_log("shell_exec", $cmd); system($cmd); //lxshell_return("pure-pw", "usermod", $this->main->nname, "-N", "", "-m"); } }
function changeSuperAdminPass() { if ($this->nname === 'superadmin') { $oldpass = getAdminDbPass(); $newp = client::createDbPass($this->realpass); $return = lfile_put_contents("__path_super_pass", $newp); if (!$return) { log_log("admin_error", "Admin pass change failed {$last_error}"); throw new lxException("could_not_change_superadmin_pass", ''); } $return = $sql->setPassword($newp); if ($return) { $return = lfile_put_contents("__path_super_pass", $oldpass); log_log("admin_error", "mysqladmin Failed . {$out}"); throw new lxException("could_not_change_superadmin_pass", ''); } } }
function cron_exec($hour, $minute, $func) { static $localvar; //dprint("in Cron exec\n"); //dprintr($localvar); $time = mktime($hour, $minute, 0, date('n'), date('j'), date("Y")); $now = time(); if (isset($localvar[$func]) && $localvar[$func]) { //dprint("Already execed \n"); if ($now > $time + 2 * 60) { $localvar[$func] = false; } return; } if ($now > $time && $now < $time + 2 * 60) { $localvar[$func] = true; log_log("cron_exec", "Execing {$func}"); $func(); } }
static function createPaymentDetail($list) { $ret['amount'] = $list['mc_gross']; $ret['info'] = $list['payer_email']; $ret['transactionid'] = $list['txn_id']; $id = $list['item_name']; if (!csb($id, "lx_")) { log_log("paypal_billing", "Not lx_, skipping... {$id}\n"); return; } $cllist = explode("_", $id); $ret['month'] = $cllist[1]; array_shift($cllist); array_shift($cllist); $ret['client'] = implode("_", $cllist); if (!$ret['client']) { log_log("paypal_billing", "No client for transactionid {$ret['transactionid']}.. Exiting...\n"); return; } $ret['ddate'] = time(); return $ret; }
static function run_awstats($statsprog, $list) { global $gbl, $sgbl, $login, $ghtml; global $global_dontlogshell; log_log("run_stats", "In awstats"); $global_dontlogshell = true; foreach ($list as $p) { log_log("run_stats", "In awstats for {$p->nname} {$statsprog}"); if ($p->priv->isOn('awstats_flag')) { lxfile_mkdir("__path_httpd_root/{$p->nname}/webstats/"); $name = $p->nname; web::createstatsConf($p->nname, $p->stats_username, $p->stats_password); if (is_disabled($statsprog)) { continue; } log_log("run_stats", "Execing {$statsprog}"); //system("rm /home/httpd/$p->nname/webstats/*"); if ($statsprog === 'webalizer') { print "webalizer: {$p->nname}\n"; lxshell_return("nice", "-n", "15", "webalizer", "-n", $p->nname, "-t", $p->nname, "-c", "__path_real_etc_root/webalizer/webalizer.{$p->nname}.conf"); } else { print "awstats: {$p->nname}\n"; putenv("GATEWAY_INTERFACE="); //system("nice -n 15 perl /home/kloxo/httpd/awstats/wwwroot/cgi-bin/awstats.pl -update -config=$name > /tmp/test 2>&1"); lxshell_return("nice", "-n", "15", "perl", "__path_kloxo_httpd_root/awstats/wwwroot/cgi-bin/awstats.pl", "-update", "-config={$name}"); //lxshell_return("__path_kloxo_httpd_root/awstats/tools/awstats_buildstaticpages.pl", "-awstatsprog=$sgbl->__path_kloxo_httpd_root/awstats/wwwroot/cgi-bin/awstats.pl", "-dir=$sgbl->__path_httpd_root/$name/webstats/", "-config=$name"); //lxfile_cp("__path_httpd_root/$name/webstats/awstats.$name.html", "__path_httpd_root/$name/webstats/index.html"); } } } /// Needed to get the domain list from the files in the /etc/awstats directory. /* $list = lscandir_without_dot("__path_real_etc_root/awstats"); foreach($list as $l) { $p = preg_replace("/awstats\.(.*)\.conf/", "$1", $l); dprint($p); dprint("\n"); */ }
public function send_email($toEmail, $subject, $template, $params = array()) { include 'Mail.php'; include 'Mail/mime.php'; log_log('Email Function Started', 'START:'); ob_start(); include EMAILTEMPLATEDIR . '/' . $template; $msg = ob_get_clean(); $text = strip_tags($msg); $html = $msg; $crlf = "\n"; $hdrs = array('From' => FROM_EMAIL, 'Subject' => $subject); $mime = new Mail_mime($crlf); $mime->setTXTBody($text); $mime->setHTMLBody($html); $body = $mime->get(); $hdrs = $mime->headers($hdrs); log_log($toEmail, 'toEmail:'); log_log(var_export($hdrs, 1), 'hdrs:'); log_log($body, 'body:'); $mail =& Mail::factory('mail'); $mail->send($toEmail, $hdrs, $body); log_log('Email Function Ended', 'END:'); }
function syncCreateConf() { global $gbl, $sgbl, $login, $ghtml; global $global_shell_error; if_demo_throw_exception('cron'); $conf_file = "__path_cron_root/{$this->main->username}"; $list = array('minute', 'hour', 'weekday', 'ddate', 'month'); $tfile = lx_tmp_file($conf_file); $cmd = null; if ($this->main->__var_mailto) { $cmd .= "MAILTO={$this->main->__var_mailto}\n"; } $result = $this->main->__var_cron_list; foreach ($result as &$__r) { foreach ($list as $l) { $__r[$l] = unserialize(base64_decode($__r["ser_{$l}"])); } } $result = merge_array_object_not_deleted($result, $this->main); //dprintr($result); foreach ((array) $result as $v) { if ($v['ttype'] === 'simple') { $v['weekday'] = array('--all--'); $v['month'] = array('--all--'); $v['ddate'] = array('--all--'); if ($v['simple_cron'] === 'every-day') { $v['hour'] = $v['cron_day_hour']; $v['minute'] = 0; } if ($v['simple_cron'] === 'every-hour') { $v['hour'] = array('--all--'); $v['minute'] = 0; } if ($v['simple_cron'] === 'every-minute') { $v['hour'] = array('--all--'); $v['minute'] = array('--all--'); } } else { foreach ($v["weekday"] as &$___tq) { if (is_numeric($___tq)) { $___tq -= 1; } } } foreach ($list as $l) { $v[$l] = $this->getCronString($v[$l]); } if (!$v['minute']) { $v['minute'] = 0; } $cmd .= implode("\t", array($v['minute'], $v['hour'], $v['ddate'], $v['month'], $v['weekday'], $v['command'])); $cmd .= "\n"; } lfile_put_contents($tfile, $cmd); if (!posix_getpwnam($this->main->username)) { lxfile_rm("/var/spool/cron/{$this->main->username}"); return; } $ret = lxshell_return("crontab", "-u", $this->main->username, $tfile); if ($ret) { // Why exactly was a throw removed? backup/restore? //throw new lxException("adding_cron_failed", "", $global_shell_error); $gbl->setWarning('adding_cron_failed', '', $global_shell_error); $data = lfile_get_contents($tfile); log_log("cron_error", $data); } lunlink($tfile); }
if (!$fp) { sleep(3); } $fp = fsockopen('www.paypal.com', 80, $errno, $errstr, 30); if (!$fp) { sleep(3); } $fp = fsockopen('www.paypal.com', 80, $errno, $errstr, 30); if (!$fp) { log_log("paypal_billing", "Could not connect to paypal"); // HTTP ERROR } else { fputs($fp, $header . $req); while (!feof($fp)) { $res = fgets($fp, 1024); if (strcmp($res, "VERIFIED") == 0) { paymentDetail::process_paypal($_POST); // check the payment_status is Completed // check that txn_id has not been previously processed // check that receiver_email is your Primary PayPal email // check that payment_amount/payment_currency are correct // process payment } else { if (strcmp($res, "INVALID") == 0) { // log for manual investigation log_log("paypal_billing", "Fake confirmation " . var_export($_POST, true)); } } } fclose($fp); }
function dbactionUpdate($subaction) { global $gbl, $sgbl, $login, $ghtml; if (!$this->main->customer_name) { log_log("critical", "Lack customername for web: {$this->main->nname}"); return; } switch ($subaction) { case "full_update": $this->fullUpdate(); $this->main->doStatsPageProtection(); break; case "add_subweb_a": $this->AddSubWeb($this->main->__t_new_subweb_a_list); $this->createConffile(); break; case "delete_subweb_a": $this->DeleteSubWeb(); $this->createConffile(); break; case "changeowner": $this->main->webChangeOwner(); $this->createConffile(); break; case "create_config": case "addondomain": $this->createConffile(); break; case "add_delete_dirprotect": case "extra_tag": case "add_dirprotect": case "custom_error": case "dirindex": case "docroot": case "ipaddress": case "blockip": case "add_redirect_a": case "delete_redirect_a": case "delete_redirect_a": case "add_webindexdir_a": case "delete_webindexdir_a": case "add_server_alias_a": case "delete_server_alias_a": case "configure_misc": $this->createConffile(); break; case "redirect_domain": $this->createConffile(); break; case "add_forward_alias_a": case "delete_forward_alias_a": case "fixipdomain": $this->createConffile(); $this->updateMainConfFile(); self::createSSlConf($this->main->__var_ipssllist, $this->main->__var_domainipaddress); break; case "enable_php_manage_flag": $this->createConffile(); $this->updateMainConfFile(); break; case "toggle_status": $this->createConffile(); break; case "hotlink_protection": $this->createHotlinkHtaccess(); break; case "enable_php_flag": case "enable_cgi_flag": case "enable_inc_flag": case "enable_ssl_flag": $this->createConffile(); break; case "stats_protect": $this->main->doStatsPageProtection(); $this->createConffile(); break; case "default_domain": $this->main->setupDefaultDomain(); break; case "graph_webtraffic": return rrd_graph_single("webtraffic (bytes)", $this->main->nname, $this->main->rrdtime); break; case "run_stats": $this->main->runStats(); break; case "static_config_update": self::createCpConfig(); self::createWebDefaultConfig(); $this->updateMainConfFile(); break; } }
function print_redirect_back($message, $variable, $value = null) { global $gbl, $sgbl, $login; $vstring = null; if ($value) { $value = htmlspecialchars($value); $vstring = "&frm_m_emessage_data={$value}"; } $parm = "frm_emessage={$message}{$vstring}"; if ($variable) { $parm .= "&frm_ev_list={$variable}"; } $last_page = $gbl->getSessionV("lx_http_referer"); if (!$last_page) { $last_page = "/display.php?frm_action=show"; } $current_url = $this->get_get_from_current_post(null); if ($last_page === $current_url) { log_log("redirect_error", "{$last_page} is same as the current url...\n"); $last_page = "/display.php?frm_action=show"; } $this->get_post_from_get($last_page, $path, $post); $get = $this->get_get_from_post(array("frm_ev_list"), $post); $this->print_redirect("{$path}?{$get}&{$parm}"); }
<?php include_once "htmllib/lib/include.php"; debug_for_backend(); print_time("gettraffic"); gettraffic_main(); $val = print_time("gettraffic", "Get Traffic "); log_log("get_traffic", $val); function gettraffic_main() { global $argc, $argv; $list = parse_opt($argv); if (isset($list['delete-table']) && $list['delete-table'] === 'yes') { print "clearing Traffic Table\n"; clearTrafficTable(); filltraffictable(); } else { filltraffictable(); } } //testFunc(); function clearTrafficTable() { $sql = new Sqlite(null, "vpstraffic"); $sql->rawquery("delete from vpstraffic;"); } function filltraffictable() { global $gbl, $login, $ghtml; initProgram('admin'); $t = "";
/** * Writes a string to a file * * @param string $username file owner * @param string $file path to the file * @param mixed $data the data to write * @param int $flag */ function lxuser_put_contents($username, $file, $data, $flag = 0) { $file = expand_real_root($file); dprint("Debug: filename is: " . $file . "\n"); if (is_soft_or_hardlink($file)) { log_log("link_error", "{$file} is hard or symlink. Not writing\n"); return false; } if (!lxuser_mkdir($username, dirname($file))) { return false; } if ($flag == FILE_APPEND) { $mode = 'a'; } else { $mode = 'w'; } $f = fopen($file, $mode); if (!$f) { return false; } else { if (flock($f, LOCK_EX)) { $bytes = fwrite($f, $data); lxfile_generic_chown($file, $username); flock($f, LOCK_UN); fclose($f); return $bytes; } else { return false; } } }
static function checkOwnership($username, $path) { // When creating new files, must not check owner if (!lfile_exists($path)) { return true; } $owner = posix_getpwuid(fileowner(expand_real_root($path))); if ($owner['name'] !== $username) { log_log("fileacc_hacking", "{$username} tried to access {$owner['name']}'s file: {$path}"); throw new lxexception('file_bad_owner_logged', ''); } return true; }
function checkRestart() { if (if_demo()) { return; } log_log("cron_exec", "Check service restarts...\n"); $res = lscandir_without_dot("__path_program_etc/.restart"); if ($res === false) { dprint(".restart does not exist... Creating\n"); lxfile_mkdir("__path_program_etc/.restart"); lxfile_generic_chown("__path_program_etc/.restart", "lxlabs"); } foreach ((array) $res as $r) { if (csb($r, "._restart_")) { $cmd = strfrom($r, "._restart_"); } lunlink("__path_program_etc/.restart/{$r}"); dprint("Restarting {$cmd}\n"); switch ($cmd) { case 'lxcollectquota': log_log("cron_exec", "Start collecting Quota's\n"); exec_justdb_collectquota(); break; case 'openvz_tc': log_log("cron_exec", "Start openvz_tc script\n"); exec_openvz_tc(); break; default: log_log("cron_exec", "Restarting {$cmd}\n"); exec_with_all_closed("/etc/init.d/{$cmd} restart"); break; } } }
function do_serve_file($fd, $rem) { $file = $rem->filename; $file = basename($file); $file = "__path_serverfile/{$file}"; if (!lxfile_exists($file)) { log_log("servfile", "datafile {$file} dosn't exist, exiting"); print_or_write($fd, "fFile Doesn't {$file} Exist...\n\n\n\n"); return false; } $array = lfile_get_unserialize($file); lunlink($file); $realfile = $array['filename']; $pass = $array['password']; if ($fd) { dprint("Got request for {$file}, realfile: {$realfile}\n"); } log_log("servfile", "Got request for {$file} realfile {$realfile}"); if (!($pass && $pass === $rem->password)) { print_or_write($fd, "fPassword doesn't match\n\n"); return false; } if (is_dir($realfile)) { // This should neverhappen. The directories are zipped at cp-fileserv and tar_to_filserved then itself. $b = basename($realfile); lxfile_mkdir("__path_serverfile/tmp/"); $tfile = tempnam("__path_serverfile/tmp/", "{$b}.tar"); $list = lscandir_without_dot($realfile); lxshell_tar($realfile, $tfile, $list); $realfile = $tfile; } $fpr = lfopen($realfile, "rb"); if (!$fpr) { print_or_write($fd, "fCouldn't open {$realfile}\n\n"); return false; } print_or_write($fd, "s"); while (!feof($fpr)) { $written = print_or_write($fd, fread($fpr, 8092)); if ($written <= 0) { break; } } // Just send a newline so that the fgets will break after reading. This has to be removed after the file is read. print_or_write($fd, "\n"); fclose($fpr); fileserv_unlink_if_tmp($realfile); return true; }
function do_exec_system($username, $dir, $cmd, &$out, &$err, &$ret, $input) { //dprint("<hr>$dir <hr> "); global $gbl, $sgbl, $login, $ghtml; global $global_shell_out, $global_shell_error, $global_shell_ret; global $global_dontlogshell; $path = "{$sgbl->__path_lxmisc}"; $fename = tempnam($sgbl->__path_tmp, "system_errr"); $execcmd = null; if ($username !== '__system__') { $execcmd = "{$path} -u {$username}"; chmod($path, 0700); } $oldpath = null; if ($dir) { lxfile_mkdir($dir); $oldpath = getcwd(); chdir($dir); } $descriptorspec = array(0 => array("pipe", "r"), 1 => array("pipe", "w"), 2 => array("file", $fename, "a")); os_set_path(); $process = proc_open("{$cmd}", $descriptorspec, $pipes); $out = null; if (is_resource($process)) { // $pipes now looks like this: // 0 => writeable handle connected to child stdin // 1 => readable handle connected to child stdout // Any error output will be appended to $fename if ($input) { fwrite($pipes[0], $input); } fclose($pipes[0]); while (!feof($pipes[1])) { $out .= fgets($pipes[1], 1024); } fclose($pipes[1]); // It is important that you close any pipes before calling // proc_close in order to avoid a deadlock $ret = proc_close($process); } $err = lfile_get_contents($fename); unlink($fename); $tcwd = getcwd(); if ($ret) { log_shell_error("{$err}: [({$username}:{$tcwd}) {$cmd}]"); } if ($global_dontlogshell) { log_log("other_cmd", "{$ret}: {$err} [({$username}:{$tcwd}) {$cmd}]"); } else { log_shell("{$ret}: {$err} [({$username}:{$tcwd}) {$cmd}]"); } $global_shell_ret = $ret; $global_shell_out = $out; $global_shell_error = $err; if ($oldpath) { chdir($oldpath); } }
function change_db_pass() { global $gbl, $sgbl, $login, $ghtml; $pass = randomString(10); $newp = client::createDbPass($pass); $oldpass = lfile_get_contents("__path_admin_pass"); $username = $sgbl->__var_program_name; $sql = new Sqlite(null, "client"); //$sql->rawQuery("grant all on kloxo.* to kloxo@'localhost' identified by $newp"); //$sql->rawQuery("grant all on kloxo.* to kloxo@'%' identified by $newp"); //$return = $sql->setPassword($newp); //exec("mysqladmin -u $username -p$oldpass password $newp 2>&1", $out, $return); exec("echo 'set Password=Password(\"{$newp}\")' | mysql -u {$username} -p{$oldpass} 2>&1", $out, $return); if ($return) { $out = implode(" ", $out); log_log("admin_error", "mysql change password Failed {$out}"); throw new lxException("could_not_change_admin_pass", '', $out); } $return = lfile_put_contents("__path_admin_pass", $newp); if (!$return) { log_log("admin_error", "Admin pass change failed {$last_error}"); throw new lxException("could_not_change_admin_pass", '', $last_error); } }
public function setInternalParam($mountpoint) { $name = $this->main->ostemplate; if ($this->main->isWindows()) { return; } if (!$mountpoint) { return; } if ($name === 'unknown') { return; } $name = strtolower($name); $mountpoint = expand_real_root($mountpoint); $result = $this->getScriptS($name); dprint("Distro Name {$name}, Scripts: \n"); dprintr($result); $init = strtilfirst($name, "-"); dprint("File is {$init}.inittab\n"); if (lxfile_exists("../file/sysfile/inittab/{$init}.inittab")) { dprint("Copying {$init}.inittab\n"); $content = lfile_get_contents("../file/sysfile/inittab/{$init}.inittab"); if ($this->main->text_inittab) { $content .= "\n{$this->main->text_inittab}"; } lfile_put_contents("{$mountpoint}/etc/inittab", $content); } $iplist = get_namelist_from_objectlist($this->main->vmipaddress_a); if ($this->main->mainipaddress) { $main_ip = $this->main->mainipaddress; $iplist = array_remove($iplist, $main_ip); } else { $main_ip = array_shift($iplist); } if ($this->main->networknetmask) { $main_netmask = $this->main->networknetmask; } else { $main_netmask = "255.255.255.0"; } $iplist = implode(" ", $iplist); $ipadd = $result['ADD_IP']; $sethostname = $result['SET_HOSTNAME']; $setuserpass = $result['SET_USERPASS']; $ipdel = $result['DEL_IP']; if ($this->main->networkgateway) { $gw = $this->main->networkgateway; } else { $gw = os_get_network_gateway(); } $gwn = strtil($gw, '.') . '.0'; $hostname = $this->main->hostname; if (!$hostname) { $hostname = os_get_hostname(); } if ($result['STARTUP_SCRIPT'] != 'systemd') { $name = createTempDir("{$mountpoint}/tmp", 'xen-scripts'); lxfile_cp_rec("__path_program_root/bin/xen-dists/scripts/functions", $name); lxfile_cp_rec("__path_program_root/bin/xen-dists/scripts/{$ipadd}", $name); lxfile_cp_rec("__path_program_root/bin/xen-dists/scripts/{$sethostname}", $name); lxfile_cp_rec("__path_program_root/bin/xen-dists/scripts/{$setuserpass}", $name); lxfile_cp_rec("__path_program_root/bin/xen-dists/scripts/{$ipdel}", $name); $basepath = strfrom($name, $mountpoint); lfile_put_contents("{$name}/tmpfile.sh", "source /{$basepath}/functions\nsource /{$basepath}/{$ipdel}\n"); $delipstring = "IPDELALL=yes chroot {$mountpoint} bash /{$basepath}/tmpfile.sh"; log_shell($delipstring); log_shell(system($delipstring, $ret1) . ":return {$ret1}"); putenv("VE_STATE=stopped"); lfile_put_contents("{$name}/tmpfile.sh", "source /{$basepath}/functions\n source /{$basepath}/{$ipadd}\n"); $string = "IPDELALL=yes MAIN_NETMASK={$main_netmask} MAIN_IP_ADDRESS={$main_ip} IP_ADDR=\"{$iplist}\" NETWORK_GATEWAY={$gw} NETWORK_GATEWAY_NET={$gwn} chroot {$mountpoint} bash /{$basepath}/tmpfile.sh"; log_shell($string); log_shell(system($string, $ret1) . ":return {$ret1}"); lfile_put_contents("{$name}/tmpfile.sh", "source /{$basepath}/functions\n source /{$basepath}/{$sethostname}\n"); $string = "HOSTNM={$hostname} chroot {$mountpoint} bash /{$basepath}/tmpfile.sh"; log_shell($string); log_shell(system($string, $ret1) . ":return {$ret1}"); if ($this->main->subaction === 'rebuild' || $this->main->dbaction === 'add' || $this->main->isOn('__var_rootpassword_changed') && $this->main->rootpassword) { $rootpass = "******"; lfile_put_contents("{$name}/tmpfile.sh", "source /{$basepath}/functions\n source /{$basepath}/{$setuserpass}\n"); $string = "USERPW={$rootpass} chroot {$mountpoint} bash /{$basepath}/tmpfile.sh"; log_shell($string); log_shell(system($string)); } lxfile_rm_rec($name); } else { if ($result['STARTUP_SCRIPT'] == 'systemd') { $script_dir = createTempDir("{$mountpoint}", "hypervm-runonce"); lxfile_cp_rec("__path_program_root/bin/xen-dists/scripts/functions", $script_dir); lxfile_cp_rec("__path_program_root/bin/xen-dists/scripts/{$ipadd}", $script_dir); lxfile_cp_rec("__path_program_root/bin/xen-dists/scripts/{$sethostname}", $script_dir); lxfile_cp_rec("__path_program_root/bin/xen-dists/scripts/{$setuserpass}", $script_dir); lxfile_cp_rec("__path_program_root/bin/xen-dists/scripts/{$ipdel}", $script_dir); $basepath = strfrom($script_dir, $mountpoint); $startupdir = 'lib/systemd/system'; $startupscript = 'fedora-startup.service'; $setrootpass = ''; if ($this->main->subaction === 'rebuild' || $this->main->dbaction === 'add' || $this->main->isOn('__var_rootpassword_changed') && $this->main->rootpassword) { $rootpass = "******"; $setrootpass = "******"; } $run_once_script = "#!/bin/bash\n" . "source {$basepath}/functions\n" . '(' . "IPDELALL=yes source {$basepath}/{$ipdel}" . " & IPDELALL=yes VE_STATE=stopped MAIN_NETMASK={$main_netmask} MAIN_IP_ADDRESS={$main_ip} IP_ADDR=\"{$iplist}\" NETWORK_GATEWAY={$gw} NETWORK_GATEWAY_NET={$gwn} source {$basepath}/{$ipadd}" . " & HOSTNM={$hostname} source {$basepath}/{$sethostname}" . "{$setrootpass})\n" . "service fedora-startup disable\nrm -f /{$startupdir}/{$startupscript}\nrm -rf {$basepath}"; lfile_put_contents("{$script_dir}/hypervm-runonce.sh", $run_once_script); lxfile_cp_rec("__path_program_root/bin/xen-dists/scripts/{$startupscript}", "{$mountpoint}/{$startupdir}"); lfile_put_contents("{$mountpoint}/{$startupdir}/{$startupscript}", lfile_get_contents("{$mountpoint}/{$startupdir}/{$startupscript}") . "ExecStart={$basepath}/hypervm-runonce.sh\n"); system("ln -s /lib/systemd/system/fedora-startup.service {$mountpoint}/etc/systemd/system/multi-user.target.wants/fedora-startup.service"); system("chmod 755 {$script_dir}/hypervm-runonce.sh"); } } if ($this->main->nameserver) { $nlist = explode(" ", $this->main->nameserver); $nstring = null; foreach ($nlist as $l) { $nstring .= "nameserver {$l}\n"; } lfile_put_contents("{$mountpoint}/etc/resolv.conf", $nstring); } if ($this->main->timezone) { lxfile_rm("{$mountpoint}/etc/localtime"); $cmdstring = "ln -sf ../usr/share/zoneinfo/{$this->main->timezone} {$mountpoint}/etc/localtime"; log_log("localtime", $cmdstring); do_exec_system('__system__', "/", $cmdstring, $out, $err, $ret, null); //lxfile_cp("/usr/share/zoneinfo/{$this->main->timezone}", "$mountpoint/etc/localtime"); } lunlink("{$mountpoint}/etc/sysconfig/network-scripts/ifcfg-venet0"); lunlink("{$mountpoint}/etc/sysconfig/network-scripts/ifcfg-venet0:0"); $this->main->doKloxoInit($mountpoint); }
function sendNotification($noto, $obj, $subject, $txt, $parent = null) { if (!$obj->contactemail && !isset($obj->extra_email_f)) { log_log("mail_send", "No contactemail for {$obj->get__table()}:{$obj->nname}"); return; } log_log("mail_send", "Sending mail to object: {$obj->get__table()}:{$obj->nname}"); $from = null; if ($parent && $parent->contactemail) { $from = $parent->contactemail; } if ($noto->fromaddress) { $from = $noto->fromaddress; } callInBackground("lx_mail", array($from, $obj->contactemail, $subject, $txt)); if (isset($obj->extra_email_f) && $obj->extra_email_f) { callInBackground("lx_mail", array($from, $obj->extra_email_f, $subject, $txt)); } }
function createDir() { global $gbl, $sgbl, $login, $ghtml; if (!$this->customer_name) { log_log("critical", "Lack customername for web: {$this->nname}"); return; } $web_home = $sgbl->__path_httpd_root; $base_root = $sgbl->__path_httpd_root; $v_dir = "{$web_home}/{$this->nname}/conf"; $log_path = "{$web_home}/{$this->nname}/stats"; $cgi_path = "{$this->getFullDocRoot()}/cgi-bin/"; $log_path1 = "{$log_path}/"; $cust_log = "{$log_path1}/{$this->nname}-custom_log"; $err_log = "{$log_path1}/{$this->nname}-error_log"; $awstat_conf = "{$sgbl->__path_real_etc_root}/awstats/"; $awstat_dirdata = "{$sgbl->__path_kloxo_httpd_root}/awstats/"; $user_home = $this->getFullDocRoot(); if (!lxfile_exists("{$this->getCustomerRoot()}/public_html")) { lxfile_symlink($this->nname, "{$this->getCustomerRoot()}/public_html"); } $domname = $this->nname; /* print("+++++++++++++++++++++++++++++++++++++++++++++++++++++"); print("This is the Conf file Path $v_dir =" ); print("This is the LogPath $log_path = "); print("This is the LogPath $log_path1 ="); print("This is the Custom LogPath $cust_log =" ); print("This is the Error LoG Path $err_log = "); print("$stat_conf = "); print("This is THE User Home $user_home = "); print("+++++++++++++++++++++++++++++++++++++++++++++++++++"); */ // Protection for webstats. /* $new_user_dir = false; lxfile_mkdir($user_home); if ((count(lscandir_without_dot($user_home)) == 0) && isset($this->__var_skelfile) && $this->__var_skelfile) { $this->getAndUnzipSkeleton($this->__var_skelmachine, $this->__var_skelfile, "$user_home/"); $new_user_dir = true; } lxfile_mkdir("$web_home/$domname/webstats"); */ $wsstring = "Stats not yet generated\n"; lfile_put_contents("{$web_home}/{$domname}/webstats/index.html", $wsstring); lxfile_mkdir($cgi_path); lxfile_mkdir($user_home); // Sort of hack.. Changes the domain.com/domain.com to domain.com/httpdocs. // Which is easier to remember. Slowly we need to change all the code from dom/dom to dom/httpdocs.. // but for now, just create a symlink. lxfile_generic_chmod("{$web_home}/{$this->nname}", "0755"); lxfile_mkdir("{$user_home}/"); lxfile_generic_chmod($user_home, "0755"); lxfile_mkdir($v_dir); lxfile_mkdir($log_path); //lxfile_mkdir($log_path1); // issue #589 - Change httpd config structure // lxfile_mkdir("__path_apache_path/kloxo"); // lxfile_touch("__path_apache_path/kloxo/virtualhost.conf"); $parent_doc_root = $this->getParentFullDocRoot(); if ($user_home != $parent_doc_root) { lxfile_generic_chown_rec($parent_doc_root, "{$this->username}:{$this->username}"); } else { lxfile_generic_chown_rec($user_home, "{$this->username}:{$this->username}"); } /* // Issue #565 - Domain skeleton files chmodded to 0755 // latest info from William if ($new_user_dir) { lxfile_generic_chmod_rec($user_home, "755"); } system("find {$user_home} -type f -exec chmod 644 {} \;"); system("find {$user_home} -type d -exec chmod 755 {} \;"); */ // MR --- consistence with fix-chownchmod script // fixed 64bit slave (skeleton.zip always zero) // back to original because problem with suphp lxfile_generic_chown($user_home, "{$this->username}:apache"); lxfile_generic_chown("__path_customer_root/{$this->customer_name}", "{$this->username}:apache"); lxfile_generic_chmod("__path_customer_root/{$this->customer_name}", "750"); lxfile_generic_chown($log_path1, "apache:apache"); lxfile_generic_chmod($log_path1, "770"); lxfile_generic_chown("{$web_home}/{$this->nname}", "{$this->username}:apache"); if (!lxfile_exists("{$web_home}/{$this->nname}/httpdocs")) { //lxfile_mkdir("$sgbl->__path_customer_root/$this->customer_name/domain/$this->nname"); //lxfile_symlink("{$this->getFullDocRoot()}", "$sgbl->__path_customer_root/$this->customer_name/domain/$this->nname/www"); lxfile_symlink("{$this->getFullDocRoot()}", "{$web_home}/{$this->nname}/httpdocs"); //lxfile_symlink("$web_home/{$this->nname}/httpdocs", "$web_home/{$this->nname}/{$this->nname}"); } $this->createstatsConf($this->nname, $this->stats_username, $this->stats_password); /* print("This is the User Home : $user_home \n"); print("This is the certificate Pah : $sgbl->__path_ssl_root/certificate/\n"); print("This is the Private Key Pah: $sgbl->__path_ssl_root/privatekey/\n"); print("This is the Domain Name :$web_home/{$this->nname}\n"); print( "This is teh User Httpdocs :$user_home/www/"); print("GO to the User Dir (chmod 775"); print("Chown To The :{$this->username}:{$this->username}, $user_home\n"); print("This is the Vdir : $v_dir\n"); print("Creating log path :$log_path\n"); print("Creating Dir:$log_path1\n"); print("Touching :$sgbl->__path_apache_path/kloxo\n"); print("Touching Virtual hOPs$sgbl->__path_apache_path/kloxo/virtualhost.conf\n"); print("$err_log\n"); print("Install ALL : $install_all\n"); print("chown :{$this->username} , $web_home/{$this->nname}\n"); exit; */ // MR -- make guarantee the last process! // mod_php still possible not work (ftp issue) for tranfer skeleton.zip from master to slave $this->getAndUnzipSkeleton($this->__var_skelmachine, $this->__var_skelfile, "{$user_home}/"); dprint("end\n"); }
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; }
function send_to_some_stream_server($type, $size, $raddress, $var, $fd) { global $gbl, $sgbl, $login, $ghtml; $exitchar = $sgbl->__var_exit_char; $remotechar = $sgbl->__var_remote_char; $con = $sgbl->__var_connection_type; if ($raddress === "localhost") { $con = "tcp"; $port = $sgbl->__var_local_port; } else { $con = "ssl"; $port = $sgbl->__var_remote_port; } print_time('server'); print_time('serverstart'); $rraddress = $raddress; if (isLocalhost($raddress)) { $rraddress = "127.0.0.1"; } $socket = stream_socket_client("{$con}://{$rraddress}:{$port}"); //$socket = fsockopen("$con://$raddress", $port); print_time('serverstart', "Fsockopen"); if ($socket <= 0) { if ($raddress === 'localhost' && !WindowsOs() && !$sgbl->isDebug()) { //20140131 OA: dont reenable this, Ive just removed. //lxshell_background("/usr/sbin/lxrestart", $sgbl->__var_program_name); throw new lxException('no_socket_connect_to_server', '', $raddress); throw new lxException('restarting_backend', '', $raddress); } else { throw new lxException('no_socket_connect_to_server', '', $raddress); } } stream_set_timeout($socket, 30000000000); //stream_context_set_option($socket, 'ssl', 'allow_self_signed', true); //stream_context_set_option($socket, 'ssl', 'verify_peer', false); $in = $var; fwrite($socket, $in); $in = "\n"; fwrite($socket, $in); $in = $exitchar; fwrite($socket, $in); $in = "\n"; fwrite($socket, $in); $totalout = null; $totalsize = 0; while (true) { $out = fgets($socket, 8092); if (!$out) { if (!$totalout) { dprint("Got Nothing\n"); } break; } if ($type === 'fileprint' || $type === 'file') { // The stream comes with a first and last character appended to it. if ($totalsize === 0 && $out[0] === 'f') { log_log("servfile", "Got failure from the servfile {$out}"); break; } if ($totalsize === 0) { $out = substr($out, 1); } $totalsize += strlen($out); if ($totalsize >= $size + 1) { $out = substr($out, 0, strlen($out) - 1); } print_or_write($fd, $out); if ($totalsize >= $size + 1) { break; } } else { //$out = trim($out); $totalout .= $out; if (csa($totalout, $exitchar)) { break; } } } fclose($socket); if ($type === 'file' || $type === 'fileprint') { return $totalsize; } if (!$totalout) { return null; } dprint("Got this much:" . strlen($totalout)); //dprint($totalout); $totalout = trim($totalout); $size = round(strlen($totalout) / 1024, 4); //dprint($totalout); //$ee = unserialize(base64_decode($totalout)); return $totalout; }
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 updateLimit($param) { if_demo_throw_exception('limit'); log_log("ajax", var_export($param, true)); global $gbl, $sgbl, $login, $ghtml; $gbl->__ajax_refresh = true; if ($this->isLogin()) { throw new lxException('cannot_change_own_limit', 'limit'); } $mstr = '(--Mod--)'; if (!csa($this->resourceplan_used, $mstr)) { $this->resourceplan_used = "{$mstr} {$this->resourceplan_used}"; } return $param; }
log_log($rsView); //echo $query_rsView; //pr($rsView); //getting rowCount $queryTotalRows = "SELECT COUNT(a.id) as cnt FROM {$tablename} as a LEFT JOIN google_auth as u ON a.uid = u.uid {$mutilselectFrom} {$tagsTable} WHERE a.module_id = " . $colname_rsModule . " {$searchCriteria} {$distanceWhere} {$tagsWhere} GROUP BY a.id"; if (isset($_GET['totalRows_rsView'])) { $totalRows_rsView = $_GET['totalRows_rsView']; } else { $rowCountResult = $modelGeneral->fetchAll($queryTotalRows, array(), $cacheTime); $totalRows_rsView = count($rowCountResult); } $totalPages_rsView = ceil($totalRows_rsView / $maxRows_rsView) - 1; //getString $get_rsViewRaw = getString(array('pageNum_rsView', 'totalRows_rsView')); $get_rsView = sprintf("&totalRows_rsView=%d%s", $totalRows_rsView, $get_rsViewRaw); log_log($get_rsView, 'get_rsView'); //getString Ends if (!empty($_GET['clear'])) { $modelGeneral->clearCache($query_limit_rsView, array()); $modelGeneral->clearCache($queryTotalRows, array()); $getURL = getString(array('totalRows_rsView', 'clear')); if ($my) { header("Location: " . $currentURL . '/auto/my?' . $getURL); } else { header("Location: " . $currentURL . '/auto/browse?' . $getURL); } exit; } //end browse //yelp, google, indeed, craigslist addition if ($resultModule['module_name'] == 'jobs') {
function syncCreateConf() { global $gbl, $sgbl, $login, $ghtml; // $host = `hostname`; $dlistv = "__var_domainlist_{$this->main->__var_syncserver}"; $result = $this->main->{$dlistv}; $nameduser = "******"; $dnsfile = "/var/tinydns/root/data"; //dprintr($result); $result = merge_array_object_not_deleted($result, $this->main); if (!$this->main->isDeleted()) { foreach ((array) $this->main->__var_addonlist as $d) { $result = merge_array_object_not_deleted($result, $d); } } $cdata = null; foreach ((array) $result as $value) { $cdata .= " {$value['nname']}.data "; } $cdata = trim($cdata); if ($cdata) { $cmd = "cd /var/tinydns/root/kloxo/ ; cat {$cdata} > ../data"; log_log("dns_log", $cmd); system($cmd); } else { system("rm /var/tinydns/root/data"); } lxfile_unix_chown($dnsfile, $nameduser); lxshell_directory("/var/tinydns/root/", "make"); lxshell_directory("/var/tinydns/root/", "tinydns-data"); }