function os_fix_fstab() { $list = lfile_trim("/etc/fstab"); foreach ($list as $l) { $nl = trimSpaces($l); $n = explode(" ", $nl); if ($n[1] !== "/home" && $n[1] !== '/') { $out[] = $l; continue; } if (!csa($n[3], "usrquota")) { $mount[] = $n[1]; $n[3] = "{$n['3']},usrquota,grpquota"; } $o = implode("\t", $n); $out[] = $o; } $out = implode("\n", $out); $out .= "\n"; dprint($out); lfile_put_contents("/etc/fstab", $out); dprintr($mount); foreach ($mount as $m) { system("mount {$m} -o remount"); } }
function storeinGblvariables() { global $gbl, $sgbl, $login, $ghtml; return; $firstofmonth = @mktime(00, 01, 00, @date("n"), 1, @date("Y")); $today = time() + 2 * 24 * 60 * 60; $vpslist = $login->loadAllVps(); $vpslist = $login->getList('vps'); if ($vpslist) { foreach ($vpslist as $vps) { $vpst = $vps->getList("vpstraffic"); $list = get_namelist_from_objectlist($vpst); $total[$vps->getClName()] = trafficGetIndividualObjectTotal($vpst, $firstofmonth, $today, $vps->nname); list($month, $year) = get_last_month_and_year(); $last_traffic = VpstrafficHistory::getMonthTotal($vpst, $month, $year, null); if (!isset($sgbl->__var_traffic_last_usage)) { $sgbl->__var_traffic_last_usage = null; } $sgbl->__var_traffic_last_usage[$vps->getClName()] = $last_traffic['traffic_usage']; /* 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; } */ } } //dprintr($sgbl->__var_backupdisk_usage); $sgbl->__var_traffic_usage = $total; dprintr($sgbl->__var_traffic_last_usage); }
function createExtraVariables() { global $gbl, $sgbl, $login, $ghtml; $revc = $login->getObject('general')->reversedns_b; if (!$revc->dns_slave_list) { throw new lxexception("dns_params_not_configured", '', ""); } $this->syncserver = implode(",", $revc->dns_slave_list); $rdrlist = $this->getList('rdnsrange'); $rdrange = null; foreach ($rdrlist as $k => $v) { list($base, $first) = self::getBaseEnd($v->firstip); list($base, $last) = self::getBaseEnd($v->lastip); $rdrange[] = array($base, $first, $last); } $this->__var_rdnsrange = $rdrange; dprintr($this->__var_rdnsrange); $sq = new Sqlite(null, 'reversedns'); $res = $sq->getTable(); foreach ($res as $r) { list($base, $last) = self::getBaseEnd($r['nname'], $this->__var_rdnsrange); $total[$base][] = array('nname' => $r['nname'], 'end' => $last, 'reversename' => $r['reversename']); } $this->__var_revdns1 = $revc->primarydns; $this->__var_revdns2 = $revc->secondarydns; $this->__var_reverse_list = $total; }
function updateUpdate($param) { foreach ($param as $k => $v) { $param[$k] = self::fixListVariable($v); } dprintr($param); return $param; }
function createExtraVariables() { $pserver = $this->getParentO(); $hdb = new Sqlite($this->__masterserver, 'hostdeny'); $string = "syncserver = '{$pserver->nname}' "; $hlist = $hdb->getRowsWhere($string); $this->__var_hostlist = $hlist; dprintr($this->__var_hostlist); }
function dbactionAdd() { dprintr($this); $ret = self::checkIfUserExists($this->main->nname, $this->main->getParentName()); if ($ret) { return true; } $this->createUser(); $this->shellModify(); $this->toggleStatus(); }
function switchserver_main() { global $argc, $argv; global $gbl, $sgbl, $login, $ghtml; //sleep(60); initProgram("admin"); if ($argc === 1) { print "Usage: {$argv['0']} --class= --name= --v-syncserver= \n"; exit; } try { $opt = parse_opt($argv); $param = get_variable($opt); dprintr($param); $class = $opt['class']; $name = $opt['name']; if (lx_core_lock("{$class}-{$name}.switchserver")) { exit; } $object = new $class(null, 'localhost', $name); $object->get(); if ($object->dbaction === 'add') { throw new lxException("no_object", '', ''); exit; } if (!$object->syncserver) { print "No_synserver...\n"; throw new lxException("no_syncserver", '', ''); exit; } if ($param['syncserver'] === $object->syncserver) { print "No Change...\n"; throw new lxException("no_change", '', ''); exit; } $driverapp_old = $gbl->getSyncClass('localhost', $object->syncserver, $object->get__table()); $driverapp_new = $gbl->getSyncClass('localhost', $param['syncserver'], $object->get__table()); if ($driverapp_new !== $driverapp_old) { //throw new lxException ("the_drivers_are_different_in_two_servers", '', ''); } $object->doupdateSwitchserver($param); } catch (exception $e) { print $e->getMessage(); /// hcak ahck... Chnage only the olddelete variable which is the mutex used for locking in the process of switch. The problem is we want to totally bail out if the switchserver fails. The corect way would be save after reverting the syncserve to the old value, but that's a bit risky. So we just use a hack to change only the olddeleteflag; Not a real hack.. This is the better way. $message = "{$e->getMessage()}"; write_to_object($object, $message, $param['syncserver']); $fullmesage = "Switch of {$object->get__table()}:{$object->nname} to {$object->syncserver} failed due to {$e->getMessage()}"; log_switch($fullmesage); mail($login->contactemail, "Switch Failed:", "{$fullmesage}\n"); print "\n"; exit; } mail($login->contactemail, "Switch Succeeded", "Switch Succeeded {$object->get__table()}:{$object->nname} to {$param['syncserver']}\n"); }
static function getSizeForAll($list) { foreach ($list as $l) { if (csa($l, "lvm:")) { $ret[$l] = vg_diskfree($l); } else { $ret[$l] = lxfile_disk_free_space($l); } } dprintr($ret); return $ret; }
function __xenimport_get_data() { lxfile_mkdir("/home/oldxenconfig-hypervm"); $list = lscandir_without_dot("/etc/xen/oldxen"); foreach ($list as $l) { $vm[] = __xenimport_parse_config("/etc/xen/oldxen/{$l}"); //lxfile_mv("/etc/xen/$l", "/home/oldxenconfig-hypervm"); lunlink("/etc/xen/auto/{$l}"); } dprintr($vm); return $vm; }
function __xenimport_get_data() { lxfile_mkdir("/home/oldxenconfig-hypervm"); $list = lscandir_without_dot("/home/xen"); foreach ($list as $l) { if (!cse($l, ".vm")) { continue; } $vm[] = __xenimport_parse_config("/home/xen/{$l}/{$l}.cfg"); //lxfile_mv("/etc/xen/$l", "/home/oldxenconfig-hypervm"); } dprintr($vm); return $vm; }
static function getDnsTemplateList($parent) { $res = $parent->dnstemplate_list; dprintr($res); if (!$res) { $sq = new Sqlite(null, "dnstemplate"); $res = $sq->getTable(); $res = get_namelist_from_arraylist($res); } if (!$res) { throw new lxException("err_no_dns_template", '', ''); } return $res; }
function dbactionAdd() { global $gbl, $sgbl, $login; if (if_demo()) { return; } $_filepath = "__path_home_root/lxguard/hostdeny.info"; $result = $this->main->__var_hostlist; $result = merge_array_object_not_deleted($result, $this->main); $list = get_namelist_from_arraylist($result, 'hostname', 'hostname'); dprintr($list); lfile_put_serialize($_filepath, $list); lxshell_return("__path_php_path", "../bin/common/lxguard.php"); }
static function getPackages($nocache = false) { $cmd = self::getYumCommand(); $file = fix_nname_to_be_variable(implode(" ", $cmd)); $file = "__path_program_root/cache/{$file}"; if ($nocache) { $val = `{$cmd}`; } else { $val = get_with_cache($file, $cmd); } $list = explode("\n", $val); dprintr($list); $match = false; $res = null; foreach ($list as $l) { $l = trim($l); if (strstr($l, "---------------------")) { $match = true; continue; } if ($match) { if (!$l) { break; } } if (!$match) { continue; } $l = trimSpaces($l); $l = trim($l); if (!$l) { continue; } $v = explode(" ", $l); $out['nname'] = $v[0]; //$out['arch'] = $v[1]; $out['update_version'] = $v[1]; $out['kloxo_status'] = 'dull'; if ($v[3] === 'lxlabs-updates') { $out['kloxo_status'] = 'on'; } $out['repo'] = $v[3]; $res[] = $out; } //dprintr($res); return $res; }
function __xenimport_get_data() { lxfile_mkdir("/home/oldxenconfig-hypervm"); $list = lscandir_without_dot("/etc/hypervm/"); foreach ($list as $l) { if (!csb($l, "xm")) { continue; } if (csb($l, "xmexample")) { continue; } $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 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 interfacetraffic_main() { global $gbl, $sgbl, $login, $ghtml; if (!lxfile_exists("__path_program_etc/xeninterface.list")) { return; } $list = lfile_trim("__path_program_etc/xeninterface.list"); if (!lxfile_exists("__path_program_etc/newxeninterfacebw.data")) { foreach ($list as $k) { $total[$k] = get_bytes_for_interface($k); } dprintr($total); lfile_put_contents("__path_program_etc/newxeninterfacebw.data", serialize($total)); return; } $data = unserialize(lfile_get_contents("__path_program_etc/newxeninterfacebw.data")); $total = null; foreach ($list as $k) { $total[$k] = get_bytes_for_interface($k); if (isset($data[$k])) { if ($total[$k]['total'] < $data[$k]['total']) { $v = $total[$k]['total']; $vinc = $total[$k]['incoming']; $vout = $total[$k]['outgoing']; } else { $v = $total[$k]['total'] - $data[$k]['total']; $vinc = $total[$k]['incoming'] - $data[$k]['incoming']; $vout = $total[$k]['outgoing'] - $data[$k]['outgoing']; } } else { $v = $total[$k]['total']; $vinc = $total[$k]['incoming']; $vout = $total[$k]['outgoing']; } execRrdTraffic("xen-{$k}", $v, "-{$vinc}", $vout); $stringa[] = time() . " " . date("d-M-Y:H:i") . " {$k} {$v} {$vinc} {$vout}"; } dprintr($total); $string = implode("\n", $stringa); lfile_put_contents("/var/log/lxinterfacetraffic.log", "{$string}\n", FILE_APPEND); lfile_put_contents("__path_program_etc/newxeninterfacebw.data", serialize($total)); }
static function getFtpList($username = null) { $list = process__linux::readProcessList(); $ret = null; foreach ($list as $l) { if (!csa($l['command'], "pure-ftp")) { continue; } dprintr($l); $r['pid'] = $l['nname']; $r['nname'] = $r['pid']; if ($username && $username !== $l['username']) { continue; } $r['account'] = $username; $r['state'] = $l['state']; $ret[] = $r; } return $ret; }
function findNextVersion($lastversion = null) { global $gbl, $sgbl, $login, $ghtml; $maj = $sgbl->__ver_major; $thisversion = $sgbl->__ver_major_minor_release; $upgrade = null; $nlist = getVersionList($lastversion); dprintr($nlist); $k = 0; foreach ($nlist as $l) { if (version_cmp($thisversion, $l) === -1) { $upgrade = $l; break; } $k++; } if (!$upgrade) { return 0; } print "Updating from {$thisversion} to {$upgrade}\n"; return $upgrade; }
function lxinstall_package($package) { $oldir = getcwd(); chdir("/usr/local/kloxo/src/{$package}-current"); include_once "./lxconfigure.php"; print "Install/Upgrade {$package}\n"; $pre_func = "{$package}_lxconfigure_pre"; if (function_exists($pre_func)) { $pre_func(); } dprintr($gl_execute_cmd); if ($gl_execute_cmd) { foreach ($gl_execute_cmd as $cmd) { system($cmd); } } $post_func = "{$package}_lxconfigure_post"; if (function_exists($post_func)) { $post_func(); } chdir($oldir); }
function changeAdminPass() { if ($this->main->nname === 'admin') { $newp = client::createDbPass($this->main->realpass); //exec("mysqladmin -u kloxo -p$oldpass password $newp 2>&1", $out, $return); $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); dprint("i am here <br> \n"); dprintr($return); dprint("i am here <br> \n"); if ($return) { log_log("admin_error", "mysql change password Failed . {$out}"); throw new lxException("could_not_change_admin_pass", ''); } $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", ''); } } }
function getAndUnzipSkeleton($ip, $filepass, $dir) { $oldir = getcwd(); // File may be a variable path. dprintr($filepass); $file = $filepass['file']; // The thing is this needs to be executed even on secondary master and then the primary master would be down. // So if we cannot connect back, we just continue. Skeleton is not an important thing. try { getFromFileserv($ip, $filepass, "{$dir}/{$file}"); } catch (exception $e) { return; } lxfile_generic_chown("{$dir}/{$file}", $this->username); lxshell_unzip($this->username, $dir, "{$dir}/{$file}"); lunlink("{$dir}/{$file}"); $this->replaceVariables("{$dir}/index.html"); // --- also copy /home/kloxo/httpd/user-logo.png to each domain path if (lxfile_exists("../file/user-logo.png")) { lxfile_cp("../file/user-logo.png", "{$dir}/images/logo.png"); } }
function backup_main() { global $argc, $argv; global $gbl, $login, $ghtml; $gbl->__restore_flag = true; if ($argc === 1) { print "Usage: {$argv['0']} --restore/--list --accounts='domain-<domain1.com>,client-<client1>,domain-<domain2.com>' <backup-file> [--switchserverlist='oldserver1:newserver1,oldserver2:newserver2']\n Use --accounts=all to restore everything.\n"; exit; } initProgram("admin"); $object = $login; $opt = parse_opt($argv); if (isset($opt['class']) && isset($opt['name'])) { $object = new $opt['class'](null, null, $opt['name']); $object->get(); if ($object->dbaction === 'add') { log_error("{$opt['class']} doesnt exist"); print "{$opt['class']} doesnt exist\n"; exit; } } $class = $opt['class']; $name = $opt['name']; if (lx_core_lock("{$class}-{$name}.restore")) { print "Another Restore for the same class is happening..\n"; exit; } $backup = $object->getObject('lxbackup'); if (isset($opt['switchserverlist'])) { $sq = new Sqlite(null, "pserver"); $serverlist = $sq->getTable(); $serverlist = get_namelist_from_arraylist($serverlist); $server = $opt['switchserverlist']; $list = explode(",", $server); foreach ($list as $l) { if (!$l) { continue; } $q = explode(":", $l); $rlist[$q[0]] = $q[1]; if (!array_search_bool($q[1], $serverlist)) { print "The server {$q[1]} doesn't exist in the server system here\n"; exit; } } $param['switchserverlist'] = $rlist; dprint("\n"); } else { $param['switchserverlist'] = null; } /* if (!testAllServersWithMessage()) { $backup->restorestage = "Failed due to: could not connect to slave servers"; clearLxbackup($backup); exit; } */ $file = $opt['final']; //$param = get_variable($opt); if (isset($opt['list'])) { $gbl->__var_list_flag = true; $param['_accountselect'] = null; } else { if (isset($opt['restore'])) { $gbl->__var_list_flag = false; if (!isset($opt['accounts'])) { print "Restore option needs accounts that are to be restored. --accounts='domain-domain.com,client:clientname'... Use --list to find out all the domain/clients in the backup archive.\n"; clearLxbackup($backup); exit; } $account = $opt['accounts']; //$account = str_replace(":", "_s_vv_p_", $account); $account = str_replace(":", "-", $account); $accountlist = explode(",", $account); $param['_accountselect'] = $accountlist; } else { print "Usage: {$argv['0']} <--list/--restore --accounts=> <filename>\n"; clearLxbackup($backup); exit; } } if (isset($opt['priority']) && $opt['priority'] === 'low') { sleep(20); } dprintr($param); //dprint($file); try { $backup->doUpdateRestore($file, $param); $backup->restorestage = 'done'; } catch (exception $e) { log_error("Restore Failed. Reason: {$e->__full_message} \n"); print "Restore Failed. Reason: {$e->__full_message} \n"; $mess = $e->__full_message; mail($object->contactemail, "Restore Failed..", "Restore Failed for {$object->nname} with the Message {$mess}"); $backup->restorestage = "Restore failed due to {$mess}"; } clearLxbackup($backup); }
function uploadDirect() { $filename = "{$this->main->getFullPath()}/{$this->main->upload_file_name}"; check_file_if_owned_by_and_throw($filename, $this->main->__username_o); dprintr($this->main->upload_overwrite_f); if (lfile_exists($filename)) { if (!$this->main->isOn('upload_overwrite_f')) { throw new lxexception('file_exists_upload', 'upload_name_f'); } else { lxfile_rm($filename); } } dprintr($this->main); getFromFileserv($this->main->__var_upload_tmp_server, $this->main->__var_upload_filepass, $filename); return $filename; }
function updateAutores($param) { $v = $param['autores_name']; //$autores = $this->getFromList('autoresponder', "{$v}___{$this->getClName()}"); $autores = $this->getFromList('autoresponder', $v); $this->__var_autores_message = $autores->text_message; $this->__var_autores_subject = $autores->reply_subject; dprintr($this->__var_autores_message); return $param; }
function updateform($subaction, $param) { global $gbl, $sgbl, $login, $ghtml; switch ($subaction) { case "installatron": $vlist['__v_button'] = array(); return $vlist; case "ostemplatelist": getResourceOstemplate($vlist, 'all'); $vlist['__v_updateall_button'] = array(); return $vlist; case "createinvoice_m": $vlist['month'] = null; return $vlist; case "createinvoice_s": $vlist['month'] = array('s', $this->getInvoiceMonthList()); return $vlist; case "search_engine": $vlist['se_url'] = array('M', "http://"); $vlist['se_email'] = null; return $vlist; case "cron_mailto": $vlist['cron_mailto'] = null; return $vlist; case "default_domain": $vlist['default_domain'] = array('s', add_disabled(get_namelist_from_objectlist($this->getList('domain')))); return $vlist; case "shell_access": $res[] = "/bin/bash"; $res[] = "/usr/bin/lxjailshell"; $res = add_disabled($res); $vlist['nname'] = array('M', null); $vlist['disable_system_flag'] = null; $vlist['shell'] = array('s', $res); $vlist['__v_updateall_button'] = array(); return $vlist; case "generate_csr": include "lib/countrycode.inc"; foreach ($gl_country_code as $key => $name) { $temp[$key] = $name; } $s = new sslcert(null, null, null); $this->ssl_data_b = new ssl_data_b(null, null, null); $vlist['contactemail'] = array('M', null); $vlist["ssl_data_b_s_commonName_r"] = null; $vlist["ssl_data_b_s_emailAddress_r"] = null; $vlist["ssl_data_b_s_countryName_r"] = array('A', $temp); $vlist["ssl_data_b_s_stateOrProvinceName_r"] = null; $vlist["ssl_data_b_s_localityName_r"] = null; $vlist["ssl_data_b_s_organizationName_r"] = null; $vlist["ssl_data_b_s_organizationalUnitName_r"] = null; return $vlist; case "domainpserver": if ($this->isAdmin()) { $parent = $this; } else { $parent = $this->getParentO(); } self::getDomainServerVlist($parent, $this, $vlist); return $vlist; case "forcedeletepserver": if_not_admin_complain_and_exit(); $list = get_namelist_from_objectlist($this->getList('pserver')); $vlist['pserver_delete_f'] = array('s', array_remove($list, "localhost")); return $vlist; case "deleteorphanedvps": $sq = new Sqlite(null, 'vps'); $slist = get_namelist_from_objectlist($this->getList('pserver')); $res = $sq->getTable(array('nname', 'syncserver', 'parent_clname')); $list = null; foreach ($res as $r) { if (!array_search_bool($r['syncserver'], $slist)) { $list[$r['nname']] = "{$r['nname']} ({$r['syncserver']}) (orphaned)"; } } if ($list) { $vlist['vps_delete_f'] = array('A', $list); } else { $vlist['vps_delete_f'] = array('M', 'No Orphaned vm'); } return $vlist; case "multivpscreate": $vlist['vps_basename_f'] = null; $vlist['vps_admin_password_f'] = null; $vlist['vps_count_f'] = null; $vlist['vps_template_name_f'] = array('s', get_namelist_from_objectlist($this->getList('vpstemplate'))); return $vlist; case "disable_url": $vlist['disable_url'] = array('m', array('pretext' => 'http://')); return $vlist; case "message": $vlist['wall_from_f'] = array('M', $login->nname); $vlist['send_to_f'] = array('M', $this->nname); $vlist['wall_subject_f'] = null; $vlist['wall_message_f'] = null; $vlist['__v_button'] = 'Send'; return $vlist; case "skeleton": $vlist['skeletonarchive'] = array('M', null); $vlist['skeletonarchive_f'] = null; return $vlist; case "wall": $vlist['wall_from_f'] = array('M', $this->nname); //Can't do this. If he has 10000 client, this itelf will hang the machine. //$vlist['send_to_f'] = array('M', $namlist); $vlist['wall_subject_f'] = null; $vlist['wall_message_f'] = null; $vlist['__v_button'] = 'Send'; return $vlist; case "dnstemplatelist": $parent = $this->getParentO(); $nlist = domain::getDnsTemplateList($parent); $vlist['dnstemplate_list'] = array('U', $nlist); $vlist['__v_updateall_button'] = array(); return $vlist; case "information": $vlist['nname'] = array('M', $this->nname); if ($this->isAdmin()) { $gen = $login->getObject('general'); $this->disable_admin = $gen->disable_admin; $vlist['disable_admin'] = null; } if ($this->isLogin()) { $vlist['cttype'] = array('M', $this->cttype); } else { $parent = $this->getParentO(); $res = null; if (check_if_many_server()) { $ctlist = array('reseller', 'customer', 'wholesale'); } else { $ctlist = array('reseller', 'customer'); } foreach ($ctlist as $v) { if ($parent->isGte($v)) { continue; } $res[] = $v; } if ($res) { $vlist['cttype'] = array('s', $res); } else { $vlist['cttype'] = array('M', $this->cttype); } } $vlist['ddate'] = array('M', @date('d-m-Y', $this->ddate)); if (!$this->isAdmin()) { $vlist['parent_name_f'] = array('M', $this->getParentName()); } $vlist['contactemail'] = ""; if (!$this->isLogin()) { $vlist['text_comment'] = null; } return $vlist; case "license": $lic = $login->getObject('license')->licensecom_b; if ($login->isAdmin()) { $vlist['lic_pserver_num_f'] = array('M', $lic->lic_pserver_num); $vlist['lic_client_num_f'] = array('M', $lic->lic_client_num); $vlist['lic_maindomain_num_f'] = array('M', $lic->lic_maindomain_num); } else { $vlist['lic_node_num_f'] = array('M', $lic->node_num); } $vlist['lic_live_support_f'] = array('M', $lic->lic_live_support); //$vlist['lic_ipaddress_f'] = array('M', $lic->lic_ipaddress); $vlist['lic_client_f'] = array('M', $lic->lic_client); //$vlist['lic_current_f'] = array('t', lfile_get_contents('__path_program_etc/license.txt')); $vlist['license_upload_f'] = null; return $vlist; case "ipaddress": $parent = $this->getParentO(); if ($this->isLogin() || !$this->isRightParent()) { $vlist['ipaddress_list'] = array('M', $this->getIpaddress($this->listpriv->webpserver_list)); $vlist['__v_button'] = array(); } else { if (check_if_many_server()) { dprintr($this->listpriv->webpserver_list); $iplist = $parent->getIpaddress($this->listpriv->webpserver_list); } else { $iplist = $parent->getIpaddress(array('localhost')); } dprintr($iplist); $vlist['ipaddress_list'] = array('Q', $iplist); } return $vlist; case "pserver_s": $parent = $this->getParentO(); $list = null; $serverlist = client::getPserverListPriv(); if ($this->isLogin() || !$this->isRightParent()) { foreach ($serverlist as $s) { $slist = "{$s}_list"; $vlist["{$s}_list"] = array('M', $this->listpriv->{$slist}); } $vlist['__v_button'] = array(); //$vlist['dbtype_list'] = array('M', $this->listpriv->dbtype_list); return $vlist; } else { $vlist['server_detail_f'] = null; foreach ($serverlist as $s) { $slist = "{$s}_list"; // Hack.. Actually, admin's listpriv should be empty so that the __get inside the listpriv will get automatically called. if ($parent->isAdmin()) { unset($parent->listpriv->{$slist}); } $vlist["{$s}_list"] = null; $list = lx_array_merge(array($list, $parent->getServerList(strtilfirst($s, "pserver")))); } $sinfo = pservercore::createServerInfo($list); $sinfo = get_warning_for_server_info($parent, $sinfo); $vlist['server_detail_f'] = array('M', $sinfo); //$vlist['dbtype_list'] = null; return $vlist; } case "description": $vlist['description'] = null; //$vlist['share_status'] = null; if (!$this->isRightParent()) { $this->convertToUnmodifiable($vlist); } return $vlist; } return parent::updateform($subaction, $param); }
static function getLeastId($parent, $devname) { global $gbl, $sgbl, $login, $ghtml; print " this is the devname u passed -{$devname} "; // I have removed the sorting from getlist, and here earlier, the result was sorted according to 'nname'. this is needed only when you add a new device, so ignoring now. $list1 = $parent->getList("ipaddress"); $llist = get_namelist_from_objectlist($list1, "devname"); dprintr($llist); for ($i = 0; $i < 1000000; $i++) { $name = "{$devname}:{$i}"; if (!array_search_bool($name, $llist)) { return "{$devname}-{$i}"; } } }
function do_root_main($data) { dprintr("Remote: "); dprintr($data); return do_remote($data); }
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); }
<?php include_once "htmllib/lib/include.php"; if (!isset($argv[1])) { print "Need file name\n"; exit; } $sq = new Sqlite(null, "vps"); $list = $sq->getTable(array("vpsid", "nname", "contactemail", "password", "rootpassword")); foreach ($list as $l) { $nlist[$l['vpsid']] = $l; } lfile_put_serialize($argv[1], $nlist); dprintr($nlist);
function setCustomError() { $iis = new lxCOM("IIS://localhost/W3SVC/{$this->main->iisid}"); print $this->main->iisid; // print($iis); $err = array("400", "401", "403", "404", "500"); $objlist = $iis->Get('HttpErrors'); $cm = $this->main->customerror_b; foreach ($objlist as $o) { $arr[] = "{$o}"; } foreach ($err as $e) { $v = "url_{$e}"; $match = false; foreach ($arr as &$_a) { if (preg_match("/{$e},([^,]*),/i", $_a, &$match)) { if ($cm->{$v}) { $_a = "{$e},{$match[1]},URL,{$cm->{$v}}"; } $match = true; } } if (!$match && $cm->{$v}) { $v = "url_{$e}"; $arr[] = "{$e},*,URL,{$cm->{$v}}"; } } dprintr($arr); //$iis->Put("HttpErrors", $arr); $iis->setInfo(); }