function __xenimport_parse_config($file)
{
    $list = lfile_trim($file);
    foreach ($list as $l) {
        if (!csa($l, "=")) {
            continue;
        }
        list($var, $val) = explode("=", $l);
        $var = trim($var);
        $val = trim($val);
        switch ($var) {
            case "memory":
                $ret['memory'] = $val;
                break;
            case "name":
                $val = strfrom($val, 'vm');
                $ret['name'] = strtolower(strtil($val, '"'));
                break;
            case "#ip":
                $val = strfrom($val, '"');
                $ret['ipaddress'] = strtil($val, '"');
                break;
            case "disk":
                __xenimport_parsedisk($ret, $val);
                break;
        }
    }
    return $ret;
}
function __xenimport_parsedisk(&$ret, $val)
{
    preg_match("/\\['file:([^']*)'.*'file:([^']*)'\\]/i", $val, $matches);
    $ret['type'] = 'file';
    if (!isset($matches[0])) {
        throw new lxException("could_not_parse_disk_string");
    }
    $diskstring = $matches[1];
    $disk = explode(",", $matches[1]);
    $disk[0] = trim($disk[0], "/");
    $location = strtil($disk[0], "/");
    $maindiskname = strfrom($disk[0], $location);
    $maindiskname = trim($maindiskname, "/");
    $ret['location'] = $location;
    $ret['maindiskname'] = $maindiskname;
    $swap = explode(",", $matches[2]);
    $swap[0] = trim($swap[0], "/");
    $location = strtil($swap[0], "/");
    $swapdiskname = strfrom($swap[0], $location);
    $swapdiskname = trim($swapdiskname, "/");
    if ($location !== $ret['location']) {
        throw new lxException("swap_disk_location_not_same", 'nname', "{$ret['name']}: {$ret['location']}");
    }
    $ret['location'] = "/{$ret['location']}";
    $ret['swapdiskname'] = $swapdiskname;
}
Exemple #3
0
 static function check_first_last_ip($param)
 {
     $first = strtil($param['firstip'], ".");
     $last = strtil($param['lastip'], ".");
     if ($first !== $last) {
         throw new lxException("first_and_last_should_be_same_network", 'lastip');
     }
 }
Exemple #4
0
 function display($var)
 {
     /*
     	if ($var === 'nname') {
     		return ucfirst($this->$var);
     	}
     */
     if ($var === 'resourceplan_used_f') {
         return strtil($this->resourceplan_used, "___");
     }
     return parent::display($var);
 }
 static function readProcessList()
 {
     $list = lscandir("/proc");
     foreach ($list as $pid) {
         if (is_numeric($pid) && $pid[0] != ".") {
             $cmdlinearr = lfile("/proc/" . $pid . "/cmdline");
             $return[$pid]['nname'] = $pid;
             if (!$cmdlinearr) {
                 unset($return[$pid]);
                 continue;
             }
             $cmdline = $cmdlinearr[0];
             $cmdline = preg_replace('+\\0+i', " ", $cmdline);
             $return[$pid]["command"] = substr($cmdline, 0, 100);
             if (csa($cmdline, "display.php") && csa($cmdline, "kloxo")) {
                 unset($return[$pid]);
                 continue;
             }
             $arr = lfile("/proc/" . $return[$pid]["nname"] . "/status");
             foreach ($arr as $a) {
                 if (csb($a, "State:")) {
                     $a = trim($a);
                     $a = strtil($a, "(");
                     $a = strfrom($a, "State:");
                     $a = trim($a);
                     $return[$pid]["state"] = $a;
                     $return[$pid]["state"] = $return[$pid]["state"] === "S" ? "ZZ" : $return[$pid]["state"];
                 }
                 if (csa($a, "Uid")) {
                     $uidarr = explode(":", $a);
                     $value = trimSpaces($uidarr[1]);
                     $uidarr2 = explode(" ", $value);
                     $uid = trim($uidarr2[1]);
                     $pwd = posix_getpwuid($uid);
                     $username = $pwd['name'];
                     $return[$pid]["username"] = $username;
                 }
                 if (csa($a, "VmSize")) {
                     $uidarr = explode(":", $a);
                     $uidarr = trimSpaces($uidarr[1]);
                     $uidarr = strtilfirst($uidarr, " ");
                     $return[$pid]['memory'] = round($uidarr / 1024, 2);
                 }
             }
         }
     }
     return $return;
 }
 static function add($parent, $class, $param)
 {
     global $gbl, $sgbl, $login, $ghtml;
     if ($login->isAdmin() && isset($param['nomodifyname']) && $param['nomodifyname'] === 'on') {
     } else {
         if (!$parent->isAdmin()) {
             $param['nname'] = self::getDbName($parent->nname, $param['nname']);
         } else {
             $param['nname'] = substr($param['nname'], 0, 15);
         }
     }
     $param['username'] = $param['nname'];
     $param['dbname'] = $param['nname'];
     $param['dbtype'] = strtil($class, "db");
     /*
     	if (!check_if_many_server()) {
     		$param['syncserver'] = 'localhost';
     	}
     */
     return $param;
 }
 static function createDhcpConfFile($slist)
 {
     $list = os_get_allips();
     foreach ($list as $l) {
         $base = strtil($l, ".");
         $subnet[$base] = null;
     }
     $string = null;
     $string .= "ddns-update-style interim;\n";
     $string .= "ignore client-updates;\n\n\n";
     $string .= self::getSubnetString($k, $slist);
     /*
     	foreach($subnet as $k => $v) {
     		$string .= self::getSubnetString($k, $slist);
     	}
     */
     foreach ($slist as $s) {
         $string .= self::getHostString($s);
     }
     lfile_put_contents("/etc/dhcpd.conf", $string);
     createRestartFile("dhcpd");
 }
Exemple #8
0
 static function add($parent, $class, $param)
 {
     global $gbl, $sgbl, $login, $ghtml;
     if ($login->isAdmin() && isset($param['nomodifyname']) && $param['nomodifyname'] === 'on') {
     } else {
         if (!$parent->isAdmin()) {
             $param['nname'] = self::getDbName($parent->nname, $param['nname']);
         } else {
             $param['nname'] = substr($param['nname'], 0, 15);
         }
     }
     if (csa($param['dbpassword'], "'")) {
         throw new lxexception("password_cannot_contain_single_quote", '', "");
     }
     $param['username'] = $param['nname'];
     $param['dbname'] = $param['nname'];
     $param['dbtype'] = strtil($class, "db");
     /*
     	if (!check_if_many_server()) {
     		$param['syncserver'] = 'localhost';
     	}
     */
     return $param;
 }
Exemple #9
0
 function print_resourcelist($tree, $alist, $base)
 {
     global $gbl, $sgbl, $login, $ghtml;
     $image = null;
     $open = 'false';
     $help = null;
     $alt = null;
     /*
     print("$treename.add($total, $level, 'Main', '', '', 'mainframe', '$image', '$image', $open, '$help', '$alt');\n");
     $level = $total;
     */
     foreach ((array) $alist as $k => $a) {
         if (is_array($a)) {
             if ($k === 'home') {
                 continue;
             }
             if (csb($k, "__title")) {
                 $open = 'false';
                 $a = strtil($a, "(");
                 $a = strtil($a, "[");
                 $ttr = createTreeObject($name, $image, $a, '', $open, $help, $alt);
                 $tree->addToList($ttr);
                 //print("$treename.add($total, 1, '$a', '', '', 'mainframe', '', '', $open, '$help', '$alt');\n");
                 continue;
             }
             $desc = get_plural($k);
             $image = "/img/image/" . $login->getSpecialObject('sp_specialplay')->icon_name . "/button/browse.gif";
             $endimg = "/img/right_point.gif";
             $desc = "{$desc}";
             $open = 'false';
             $help = $desc;
             $alt = lx_strip_tags($help);
             $ttr = createTreeObject('name', $image, $desc, null, $open, $help, $alt);
             $tree->addToList('tree', $ttr);
             //print("$treename.add($total, $level, '$desc', '', '', 'mainframe', '$image', '$image', $open, '$help', '$alt');\n");
             foreach ($a as $nk => $nv) {
                 $nv = $this->getFullUrl($nv, $base);
                 $this->print_ressingle($ttr, $nv);
             }
         }
     }
     foreach ((array) $alist as $k => $a) {
         if ($k === 'home') {
             continue;
         }
         if (csb($k, "__title")) {
             $open = 'false';
             $a = strtil($a, "(");
             $a = strtil($a, "[");
             $a = strtil($a, ":");
             $a = strtil($a, ":");
             $ttr = createTreeObject('name', $image, $a, null, $open, $help, $alt);
             $tree->addToList('tree', $ttr);
             //print("$treename.add($total, 1, '$a', '', '', 'mainframe', '', '', $open, '$help', '$alt');\n");
             continue;
         }
         if (is_array($a)) {
         } else {
             // Hack hack...  NOt showing addforms in the top Menu... Also not showing in the tree view..
             /*
             	if (csa(strtolower($a), "addform")) {
             		continue;
             	}
             */
             if (!csb($k, "__v_")) {
                 $a = $this->getFullUrl($a, $base);
                 if (isset($ttr)) {
                     $this->print_ressingle($ttr, $a);
                 } else {
                     $this->print_ressingle($tree, $a);
                 }
             }
         }
     }
 }
Exemple #10
0
 function getToArray($object)
 {
     $col = $this->getColumnTypes();
     //dprint_r($array);
     foreach ($col as $key => $val) {
         if (csb($key, "coma_")) {
             $cvar = substr($key, 5);
             $value = $object->{$cvar};
             if (cse($key, "_list")) {
                 $namelist = $value;
             } else {
                 $namelist = get_namelist_from_objectlist($value);
             }
             $ret[$key] = implode(",", $namelist);
             dprint("in COma {$key} {$ret[$key]}<br> ");
             $ret[$key] = ",{$ret[$key]},";
         } else {
             if (csb($key, "ser_")) {
                 $cvar = substr($key, 4);
                 $value = $object->{$cvar};
                 if ($value && isset($value->driverApp)) {
                     unset($value->driverApp);
                 }
                 if (cse($key, "_a")) {
                     if ($value) {
                         foreach ($value as $kk => $vv) {
                             unset($value[$kk]->__parent_o);
                         }
                     }
                 }
                 $ret[$key] = base64_encode(serialize($object->{$cvar}));
                 //$ret[$key] = serialize($object->$cvar);
             } else {
                 if (csb($key, "priv_q_") || csb($key, "used_q_")) {
                     $qob = strtil($key, "_q_");
                     $qkey = strfrom($key, "_q_");
                     if ($object->get__table() === 'uuser') {
                     }
                     $ret[$key] = $object->{$qob}->{$qkey};
                 } else {
                     if (!isset($object->{$key})) {
                         $object->{$key} = null;
                     }
                     if (csb($key, "text_")) {
                         $string = str_replace("\\", '\\\\', $object->{$key});
                     } else {
                         $string = $object->{$key};
                     }
                     $ret[$key] = str_replace("'", "\\'", $string);
                     //$ret[$key] = $object->$key;
                 }
             }
         }
     }
     return $ret;
 }
Exemple #11
0
 function createNewcertificate()
 {
     global $gbl, $sgbl, $login, $ghtml;
     foreach ($this->ssl_data_b as $key => $value) {
         if (!cse($key, "_r")) {
             continue;
         }
         $nk = strtil($key, "_r");
         $temp[$nk] = $value;
     }
     foreach ($temp as $key => $t) {
         if ($key === "countryName") {
             $l = explode(":", $t);
             $name = $l[0];
         } else {
             $name = $t;
         }
         $ltemp[$key] = $name;
     }
     $config['private_key_bits'] = 1024;
     $privkey = openssl_pkey_new($config);
     openssl_pkey_export($privkey, $text_key_content);
     $csr = openssl_csr_new($ltemp, $privkey);
     openssl_csr_export($csr, $text_csr_content);
     $sscert = openssl_csr_sign($csr, null, $privkey, 3650);
     openssl_x509_export($sscert, $text_crt_content);
     $this->text_key_content = $text_key_content;
     $this->text_csr_content = $text_csr_content;
     $this->text_crt_content = $text_crt_content;
 }
Exemple #12
0
function getFullVersionList($till = null)
{
    global $gbl, $sgbl, $login, $ghtml;
    $progname = $sgbl->__var_program_name;
    static $nlist;
    if ($nlist) {
        return $nlist;
    }
    $res = curl_get_file("{$progname}/version.txt");
    //dprintr($res);
    if (!$res) {
        throw new lxException('could_not_get_version_list', '');
    }
    foreach ($res as $k => $l) {
        // Skip lines that do not start with progname or one that contains 'current'
        if (!csb($l, "{$progname}")) {
            continue;
        }
        if (csa($l, "current")) {
            continue;
        }
        $upversion = strfrom($l, "{$progname}-");
        $upversion = strtil($upversion, ".zip");
        $list[] = $upversion;
        if ($till) {
            if ($upversion === $till) {
                break;
            }
        }
    }
    return $list;
}
Exemple #13
0
function check_file_if_owned_by($file, $user)
{
    if (!lxfile_exists($file)) {
        return true;
    }
    if (csa($user, ":")) {
        $ruser = strtil($user, ":");
    } else {
        $ruser = $user;
    }
    $stat = lxfile_stat($file, false);
    $uid = $stat['uid'];
    $name = os_get_user_from_uid($uid);
    if ($name === $ruser) {
        return true;
    }
    log_log("file_check", "{$file} not owned by {$ruser}");
    return false;
}
 static function readMailqueue()
 {
     lxfile_unix_chmod("__path_program_root/bin/misc/qmHandle", "0755");
     $res = lxshell_output("__path_program_root/bin/misc/qmHandle", "-l");
     $list = array('subject', 'to', 'from', 'date', 'size');
     //$res = lfile_get_contents("a.txt");
     $res = explode("\n", $res);
     //dprintr($res);
     $i = 0;
     foreach ($res as $r) {
         $r = trim($r);
         if (!$r) {
             $i++;
             continue;
         }
         if (is_numeric($r[0])) {
             list($nname, $s, $ss) = explode(" ", $r);
             $ret[$i]['nname'] = $nname;
             if (cse($ss, 'R)')) {
                 $ret[$i]['type'] = 'remote';
             } else {
                 $ret[$i]['type'] = 'local';
             }
             continue;
         }
         foreach ($list as $l) {
             $ul = ucfirst($l);
             if (csb($r, "{$ul}:")) {
                 $ret[$i][$l] = strfrom($r, "{$ul}:");
                 if ($l === 'size') {
                     $ret[$i][$l] = strtil($ret[$i][$l], " bytes");
                     $ret[$i][$l] = trim($ret[$i][$l]);
                 }
             }
         }
     }
     return $ret;
 }
Exemple #15
0
 function updateform($subaction, $param)
 {
     global $gbl, $sgbl, $login, $ghtml;
     $gen = $login->getObject('general')->generalmisc_b;
     switch ($subaction) {
         case "dialogsize":
             $vlist['dialogsize'] = null;
             return $vlist;
         case "boxposopen":
             $vlist['title_class'] = null;
             $vlist['title_open'] = null;
             $vlist['title_name'] = null;
             return $vlist;
         case "boxpos":
             $vlist['title_class'] = null;
             $vlist['title_open'] = null;
             $vlist['title_name'] = null;
             $vlist['page'] = null;
             return $vlist;
         case "addshortcut":
             $vlist['shortcut'] = null;
             return $vlist;
         case "resendwelcome":
             $vlist['extra_email_f'] = null;
             $vlist['password'] = null;
             $vlist['__v_updateall_button'] = array();
             return $vlist;
         case "disable_per":
             if ($this->islogin()) {
                 throw new lxException('you_cannot_set_your_own_limit', '');
             }
             $vlist['disable_per'] = array('s', array('off', '95', '100', '110', '120', '130'));
             return $vlist;
         case "miscinfo":
             $vlist['nname'] = array('M', $this->nname);
             $vlist['realname'] = "";
             $vlist['add_address'] = "";
             $vlist['add_city'] = "";
             $vlist['add_country'] = "";
             $vlist['add_telephone'] = "";
             $vlist['add_fax'] = "";
             return $vlist;
         case "limit_s":
         case "limit":
             if ($this->islogin()) {
                 throw new lxException('you_cannot_set_your_own_limit', '');
             }
             if (cse($this->get__table(), "template")) {
                 $class = strtil($this->get__table(), "template");
                 $vlist = getQuotaListForClass($class);
             } else {
                 $vlist = $this->getQuotaVariableList();
             }
             // This is patently wrong. In update, the object is inititialized properly and we are suppsed to get the quota for the specific type of object and not for the class.... Changing it to $this.
             $sgbl->method = 'post';
             //$vlist['__v_updateall_button'] = array();
             return $vlist;
         case "change_plan":
             $parent = $this->getParentO();
             $ttlist = $parent->getTemplateList("resourceplan", false);
             $this->newresourceplan = $this->resourceplan_used;
             if (!$ttlist) {
                 $vlist['newresourceplan'] = array("M", "No Plan in Parent");
             } else {
                 $vlist['newresourceplan'] = array("A", $ttlist);
             }
             //$vlist['__v_updateall_button'] = array();
             return $vlist;
         case "password":
             if ($this->isLogin() || $this->is__table('auxiliary') && $this->getParentO()->isAuxiliary()) {
                 $vlist['old_password_f'] = "";
             }
             $vlist['password'] = "";
             $vlist['__v_updateall_button'] = array();
             return $vlist;
     }
     return parent::updateform($subaction, $param);
 }
Exemple #16
0
 function updateUpdate($param)
 {
     validate_ipaddress_and_throw($param['firstip'], 'firstip');
     validate_ipaddress_and_throw($param['lastip'], 'lastip');
     if (isIPV6($param['firstip'])) {
         $separator = ':';
     } else {
         $separator = '.';
     }
     if (isIPV6($param['firstip'])) {
         $param['isipv6'] = true;
     } else {
         $param['isipv6'] = false;
     }
     $first = strtil($param['firstip'], $separator);
     $last = strtil($param['lastip'], $separator);
     if ($first !== $last) {
         throw new lxException("first_and_last_same_network", 'lastip');
     }
     $param['pserver_list'] = explode(',', $param['pserver_list']);
     return $param;
 }
Exemple #17
0
 function print_resourcelist($tree, $alist, $base)
 {
     global $gbl, $sgbl, $login, $ghtml;
     $image = null;
     $open = 'false';
     $help = null;
     $alt = null;
     foreach ((array) $alist as $k => $a) {
         if (is_array($a)) {
             if ($k === 'home') {
                 continue;
             }
             if (csb($k, "__title")) {
                 $open = 'false';
                 $a = strtil($a, "(");
                 $a = strtil($a, "[");
                 $ttr = createTreeObject($name, $image, $a, '', $open, $help, $alt);
                 $tree->addToList($ttr);
                 continue;
             }
             $desc = get_plural($k);
             $image = "/img/image/" . $login->getSpecialObject('sp_specialplay')->icon_name . "/button/browse.gif";
             $endimg = "/img/right_point.gif";
             $desc = "{$desc}";
             $open = 'false';
             $help = $desc;
             $alt = lx_strip_tags($help);
             $ttr = createTreeObject('name', $image, $desc, null, $open, $help, $alt);
             $tree->addToList('tree', $ttr);
             foreach ($a as $nk => $nv) {
                 $nv = $this->getFullUrl($nv, $base);
                 $this->print_ressingle($ttr, $nv);
             }
         }
     }
     foreach ((array) $alist as $k => $a) {
         if ($k === 'home') {
             continue;
         }
         if (csb($k, "__title")) {
             $open = 'false';
             $a = strtil($a, "(");
             $a = strtil($a, "[");
             $a = strtil($a, ":");
             $a = strtil($a, ":");
             $ttr = createTreeObject('name', $image, $a, null, $open, $help, $alt);
             $tree->addToList('tree', $ttr);
             continue;
         }
         if (is_array($a)) {
         } else {
             if (!csb($k, "__v_")) {
                 $a = $this->getFullUrl($a, $base);
                 if (isset($ttr)) {
                     $this->print_ressingle($ttr, $a);
                 } else {
                     $this->print_ressingle($tree, $a);
                 }
             }
         }
     }
 }
Exemple #18
0
 function updateUpdate($param)
 {
     validate_ipaddress_and_throw($param['firstip'], 'firstip');
     validate_ipaddress_and_throw($param['lastip'], 'lastip');
     $first = strtil($param['firstip'], ".");
     $last = strtil($param['lastip'], ".");
     if ($first !== $last) {
         throw new lxException("first_and_last_same_network", 'lastip');
     }
     $param['pserver_list'] = explode(',', $param['pserver_list']);
     return $param;
 }
Exemple #19
0
 function createShowInfoList($subaction)
 {
     global $gbl, $sgbl, $login, $ghtml;
     if ($subaction) {
         return;
     }
     $web = $this->getObject('web');
     $mmail = $this->getObject('mmail');
     $dns = $this->getObject('dns');
     $ilist['FTP User'] = "******";
     $ilist['Home'] = "/home/{$this->getRealClientParentO()->getPathFromName()}/";
     $url = "a=show&o=web&l[class]=ffile&l[nname]=/";
     $ilist['DocRoot'] = "_lxinurl:{$url}:/{$web->substr('docroot', 0, 32)}:";
     $resource = strtil($this->resourceplan_used, "___");
     if (check_if_many_server() && $login->isLte("reseller")) {
         $ilist['Web'] = $web->syncserver;
         $ilist['Mail'] = $mmail->syncserver;
         //$ilist['Mysql'] = $this->mysqldbsyncserver;
         $ilist['Dns'] = $dns->syncserver;
     }
     return $ilist;
 }
Exemple #20
0
 function postAdd()
 {
     global $gbl, $sgbl, $login, $ghtml;
     $parent = $this->getParentO();
     $this->cpstatus = 'on';
     $this->status = 'create';
     $this->state = 'ok';
     $this->kloxo_flag = 'on';
     $this->rootpassword = $this->realpass;
     $this->username = str_replace(".", "", $this->nname);
     if ($this->isOn('use_resourceplan_f')) {
         $template = getFromAny(array($login, $parent), 'resourceplan', $this->resourceplan_f);
         if (!$template) {
             throw new lxexception("the_plan_doesnt_exist", 'resourceplan_f', $this->resourceplan_f);
         }
         $this->resourceplan_used = $this->resourceplan_f;
         $this->priv = clone $template->priv;
         $this->fixPrivUnset();
         $this->changePlanSpecific($template);
     }
     if ($this->one_ipaddress_f) {
         full_validate_ipaddress($this->one_ipaddress_f);
     }
     $this->rootpassword_changed = 'on';
     if ($this->one_ipaddress_f) {
         $ipadd = new vmipaddress_a(null, $this->syncserver, $this->one_ipaddress_f);
         $this->vmipaddress_a[$ipadd->nname] = $ipadd;
     }
     $syncs = new Pserver(null, $this->syncserver, $this->syncserver);
     $syncs->get();
     if (is_unlimited($this->priv->vmipaddress_a_num)) {
         $this->priv->vmipaddress_a_num = 2;
     }
     if ($this->num_ipaddress_f) {
         $netinfo = $syncs->getIpPool($this->num_ipaddress_f);
         $totallist = $netinfo['ip'];
         if (!$this->nameserver) {
             $this->nameserver = $netinfo['nameserver'];
         }
         $this->networkgateway = $netinfo['networkgateway'];
         $this->networknetmask = $netinfo['networknetmask'];
         if ($totallist) {
             foreach ($totallist as $ip) {
                 $ipadd = new vmipaddress_a(null, $this->syncserver, $ip);
                 $this->vmipaddress_a[$ipadd->nname] = $ipadd;
                 ippool::addToTmpIpAssign($l);
             }
         }
     }
     $this->used->vmipaddress_a_num = count($this->vmipaddress_a);
     if (!$this->hostname) {
         $this->hostname = strtil($this->nname, ".vm");
     }
     $this->createSyncClass();
     $this->createPublicPrivate($sslvar);
     // hack hack convert listpriv into a differnet object.
     $driverapp = $gbl->getSyncClass($this->__masterserver, $this->syncserver, 'vps');
     $this->ttype = $driverapp;
     $this->getBestLocation();
     $func = "postadd_{$driverapp}";
     $this->{$func}();
     // $this->distributeChildQuota();
     ////////////////////
     /*
     	if (exists_in_db($this->__masterserver, "uuser", $uuser->nname)) {
     		throw new lxexception('user_exists_in_db', 'uuser');
     	}
     */
     $this->setUpOsTemplateDownloadParam();
     $backup = new LxBackup($this->__masterserver, $this->__readserver, $this->getClName());
     $backup->initThisDef();
     $this->AddObject('lxbackup', $backup);
     $this->lxclientpostAdd();
 }
Exemple #21
0
 function createIniFile()
 {
     $pclass = $this->main->getParentClass();
     $ver = find_php_version();
     $this->initString($ver);
     $header = lfile_get_contents("../file/phpini/php.ini.template-{$ver}");
     $cont = lfile_get_contents("../file/phpini/php.ini.temp");
     $htcont = lfile_get_contents("../file/phpini/htaccesstemp");
     $vlist = array("enable_zend_val", "enable_ioncube_val", "enable_xcache_val");
     $l1 = $this->main->getInheritedList();
     $l2 = $this->main->getLocalList();
     $l3 = $this->main->getExtraList();
     $ll = lx_array_merge(array($l1, $l2, $l3));
     $list = array_unique($ll);
     foreach ($list as $l) {
         $vl = strtil($l, "_flag") . "_val";
         if (array_search_bool($vl, $vlist)) {
             continue;
         }
         list($cont, $htcont) = $this->replacestr(array($cont, $htcont), $l);
     }
     foreach ($vlist as $vl) {
         list($cont) = $this->replacestr(array($cont), $vl);
     }
     $stlist[] = "###Start Kloxo PHP config Area";
     $stlist[] = "###Start Lxdmin Area";
     $stlist[] = "###Start Kloxo Area";
     $stlist[] = "###Start Lxadmin PHP config Area";
     $endlist[] = "###End Kloxo PHP config Area";
     $endlist[] = "###End Kloxo Area";
     $endlist[] = "###End Lxadmin PHP config Area";
     $endstring = $endlist[0];
     $startstring = $stlist[0];
     if ($pclass === 'pserver') {
         $file = "/etc/php.ini";
         if (!lxfile_exists("__path_kloxo_back_phpini")) {
             lxfile_cp("/etc/php.ini", "__path_kloxo_back_phpini");
         }
         $this->enableDisableModule("enable_xcache_flag", "xcache");
         $htfile = null;
         $extrafile = "/etc/custom.php.ini";
         if (lxfile_exists($extrafile)) {
             $extrastring = lfile_get_contents($extrafile);
             $cont = "{$extrastring}\n{$cont}";
         } else {
             $cont = "{$cont}";
         }
     } else {
         $dname = $this->main->getParentName();
         $elogfile = "/home/{$this->main->__var_customer_name}/__processed_stats/{$this->main->getParentName()}.phplog";
         $file = "__path_httpd_root/{$this->main->getParentName()}/php.ini";
         $extrafile = "__path_httpd_root/{$this->main->getParentName()}/custom.php.ini";
         if (lxfile_exists($extrafile)) {
             $extrastring = lfile_get_contents($extrafile);
         } else {
             $extrastring = "";
         }
         // ToDo #590 - disable appear on .htaccess
         // REVERT - back to enable because mod_php tend to share-based php.ini
         // and some parameters of domain specific must be declare inside .htaccess
         $htfile = "{$this->main->__var_docrootpath}/.htaccess";
         $ht1file = "/home/{$this->main->__var_customer_name}/kloxoscript/.htaccess";
         $htcont = "php_value error_log \"{$elogfile}\"\n{$htcont}";
         $htcont = str_replace("\n", "\n\t", $htcont);
         $htcont = str_replace($htcont, "\t" . $htcont, $htcont);
         $htcont = "\n<Ifmodule mod_php4.c>\n{$htcont}\n</Ifmodule>\n\n<Ifmodule mod_php5.c>\n{$htcont}\n</Ifmodule>\n";
         file_put_between_comments("{$this->main->__var_web_user}:apache", $stlist, $endlist, $startstring, $endstring, $htfile, $htcont);
         file_put_between_comments("{$this->main->__var_web_user}:apache", $stlist, $endlist, $startstring, $endstring, $ht1file, $htcont);
         lxfile_unix_chown($htfile, "{$this->main->__var_web_user}:apache");
         // MR --- set the same like AddOpenBaseDir() on web__apachelib.php
         $clname = $this->main->__var_customer_name;
         $adminbasedir = trim($this->main->__var_extrabasedir);
         if ($adminbasedir) {
             $adminbasedir .= ":";
         }
         if (!$this->main->isOn('__var_disable_openbasedir')) {
             $path = "{$adminbasedir}";
             $path .= "/home/{$clname}:";
             $path .= "/home/{$clname}/kloxoscript:";
             $path .= "/home/httpd/{$dname}:";
             $path .= "/home/httpd/{$dname}/httpdocs:";
             $path .= "/tmp:";
             $path .= "/usr/share/pear:";
             $path .= "/var/lib/php/session:";
             $path .= "/home/kloxo/httpd/script";
             $cont = "open_basedir = \"{$path}\"\n\n{$cont}";
         }
         $cont = "error_log = \"{$elogfile}\"\n{$cont}";
         $cont = "{$extrastring}\n{$cont}";
     }
     lxfile_rm($file);
     lfile_put_contents($file, "{$header}\n{$cont}\n");
     createRestartFile($this->main->__var_webdriver);
 }
Exemple #22
0
 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;
 }
Exemple #23
0
 function getId()
 {
     return strtil($this->nname, "___");
 }
Exemple #24
0
 public function getScriptS($name)
 {
     $v = $name;
     while (true) {
         $v = strtil($v, "-");
         if (!$v) {
             $v = 'default';
             break;
         }
         dprint("Checking for conf {$v}\n");
         if (lxfile_exists("__path_program_root/bin/xen-dists/{$v}.conf")) {
             break;
         }
         if (!csa($v, "-")) {
             $v = "default";
             break;
         }
     }
     $file = "__path_program_root/bin/xen-dists/{$v}.conf";
     $list = lfile_trim($file);
     foreach ($list as $l) {
         if (char_search_beg($l, "#")) {
             continue;
         }
         if (csa($l, "=")) {
             $v = explode("=", $l);
             $result[$v[0]] = $v[1];
         }
     }
     return $result;
 }
Exemple #25
0
 function top_level_simple_backup()
 {
     global $gbl, $sgbl, $login, $ghtml;
     $progname = $sgbl->__var_program_name;
     $dir = dirname($this->main->__var_bc_filename);
     $name = basename($this->main->__var_bc_filename);
     $firstname = strtil($name, "-");
     lxfile_mkdir($dir);
     $list = lscandir_without_dot($dir);
     $bc = $this->do_backup();
     $tmpdir = createTempDir("{$sgbl->__path_tmp}", "backupfile");
     lfile_put_contents("{$tmpdir}/{$progname}.file", $this->main->__var_bc_metafile);
     lfile_put_contents("{$tmpdir}/{$progname}.metadata", $this->main->__var_bc_metadata);
     $newarray = lx_array_merge(array($bc[1], array("{$tmpdir}/{$progname}.file", "{$tmpdir}/{$progname}.metadata")));
     if ($this->main->getZiptype() === 'zip') {
         lxshell_zip($bc[0], $this->main->__var_bc_filename, $newarray);
     } else {
         if ($this->main->getZiptype() === 'tar') {
             lxshell_tar($bc[0], $this->main->__var_bc_filename, $newarray);
         } else {
             lxshell_tgz($bc[0], $this->main->__var_bc_filename, $newarray);
         }
     }
     print_time("cpzip", "Copy and Zip");
     lxfile_tmp_rm_rec("{$tmpdir}");
     $this->do_backup_cleanup($bc);
 }
 function getTrafficRealObject()
 {
     return strtil($this->get__table(), "traffic");
 }
function __ac_desc_graph($object)
{
    global $gbl, $sgbl, $login, $ghtml;
    $subaction = $ghtml->frm_subaction;
    $selflist = $object->getSelfList();
    if (!$ghtml->frm_c_graph_time) {
        $ghtml->frm_c_graph_time = '1d';
    }
    $object->createShowPropertyList($alist);
    $object->createShowAlist($alist, $subaction);
    $nalist = null;
    if (!isset($alist['property'])) {
        $alist['property'] = array();
    }
    $nalist = lx_merge_good($nalist, $alist['property']);
    remove_if_older_than_a_minute_dir("__path_program_htmlbase/tmp/");
    $ghtml->print_tab_block($nalist);
    if ($selflist) {
        $ghtml->printShowSelectBox($selflist);
    }
    if (cse($ghtml->frm_subaction, 'base')) {
        $core = strtil($ghtml->frm_subaction, "base");
        $ghtml->__http_vars['frm_subaction'] = "{$core}traffic";
        $subaction = "{$core}traffic";
    }
    $galist = $object->createGraphList();
    $ghtml->print_tab_block($galist);
    $graphtlist = array('1h' => '1h', '12h' => '12h', '1d' => '1d', '2d' => '2d', '1week' => '1week', '1month' => '1month');
    $gtlistsec = array('1h' => 3600, '12h' => 12 * 3600, '1d' => 24 * 3600, '2d' => 2 * 24 * 3600, '1week' => 7 * 24 * 3600, '1month' => 30 * 24 * 3600, '1year' => 365 * 24 * 3600);
    $ghtml->printGraphSelect($graphtlist);
    lxfile_mkdir("__path_program_htmlbase/tmp");
    $tmpgraph = ltempnam("__path_program_htmlbase/tmp/", "graph");
    $object->setUpdateSubaction("graph_{$subaction}");
    $time = $ghtml->frm_c_graph_time;
    $object->rrdtime = $gtlistsec[$time];
    try {
        $object->createExtraVariables();
        $file = rl_exec_set(null, $object->syncserver, $object);
    } catch (lxException $e) {
        $ghtml->print_curvy_table_start();
        print "Graph Failed due to {$e->getMessage()} {$e->value}";
        $ghtml->print_curvy_table_end();
        $object->dbaction = 'clean';
        return;
    }
    $object->dbaction = 'clean';
    lfile_put_contents($tmpgraph, $file);
    $tmpgraph = basename($tmpgraph);
    print "<img src=/tmp/{$tmpgraph}>";
}
Exemple #28
0
function updateApplicableToSlaveToo()
{
    global $gbl, $sgbl, $login, $ghtml, $osversion;
    print "Download 3rdparty\n";
    // Fixes #303 and #304
    download_thirdparty();
    print "Installing binaries\n";
    lxfile_cp("__path_program_root/cexe/lxxen", "/usr/bin");
    lxfile_cp("__path_program_root/cexe/lxopenvz", "/usr/bin");
    print "Fixing binaries permissions\n";
    lxfile_generic_chmod("/usr/bin/lxopenvz", "6755");
    lxfile_generic_chmod("/usr/bin/lxxen", "6755");
    print "Install missing rpm packages if any";
    install_if_package_not_exist("rrdtool");
    print "-rrdtool-";
    install_if_package_not_exist("ntfsprogs");
    print "-ntfsprogs-";
    install_if_package_not_exist("parted");
    print "-parted-";
    install_if_package_not_exist("kpartx");
    print "-kpartx-";
    install_if_package_not_exist("dhcp");
    print "-dhcp-";
    install_if_package_not_exist("openssl");
    print "-openssl-";
    install_if_package_not_exist("openssl-devel");
    print "-openssl-devel-\n";
    system("chkconfig dhcpd on");
    print "Enable dhcpd at system startup\n";
    if (lxfile_exists("/etc/xen")) {
        lxfile_mkdir("/etc/xen/hypervm");
        if (!lxfile_exists("/boot/hypervm-xen-vmlinuz")) {
            system("cd /boot ; ln -sf vmlinuz-2.6-xen hypervm-xen-vmlinuz; ln -sf initrd-2.6-xen.img hypervm-xen-initrd.img");
        }
        $list = lscandir_without_dot("/etc/xen/auto");
        foreach ($list as $l) {
            $dir = strtil($l, ".cfg");
            lunlink("/etc/xen/auto/{$l}");
            if (lxfile_exists("/home/xen/{$dir}/{$l}")) {
                lxfile_symlink("/home/xen/{$dir}/{$l}", "/etc/xen/auto/{$l}");
            }
        }
    }
    if (lxfile_exists("/var/log/loadvg.log")) {
        lunlink("/var/log/loadvg.log");
    }
    if (lxfile_exists("/etc/vz")) {
        lxfile_cp("__path_program_root/file/sysfile/openvz/ve-vps.basic.conf-sample", "/etc/vz/conf");
        print "Set NEIGHBOUR_DEVS=all to vz.conf\n";
        vps__openvz::staticChangeConf("/etc/vz/vz.conf", "NEIGHBOUR_DEVS", "all");
    }
    print "Fixing openvz repo\n";
    // add openvz.repo
    lxfile_cp("../file/openvz.repo", "/etc/yum.repos.d/openvz.repo");
    print "Fixing lxcenter repo\n";
    // add lxcenter.repo
    $osversion = find_os_version();
    print "- Your OS {$osversion}\n";
    $cont = our_file_get_contents("../file/lxcenter.repo");
    $cont = str_replace("%distro%", $osversion, $cont);
    our_file_put_contents("/etc/yum.repos.d/lxcenter.repo", $cont);
    print "Fix RHN\n";
    fix_rhn_sources_file();
    print "Fix ipconntrack\n";
    fix_ipconntrack();
    if (lxfile_exists("/home/hypervm/xen/template")) {
        print "Check Xen windows-lxblank.img template\n";
        system("echo hypervm-windows > /home/hypervm/xen/template/windows-lxblank.img");
    }
    print "Fix memory graph\n";
    memoryGraphFix();
    print "Fix permission of closeallinput\n";
    lxfile_unix_chmod("../cexe/closeallinput", "0755");
    print "Fix LxEtc\n";
    installLxetc();
    print "Check binaries\n";
    system("cp ../sbin/lxrestart /usr/sbin/");
    system("chown root:root /usr/sbin/lxrestart");
    system("chmod 755 /usr/sbin/lxrestart");
    system("chmod ug+s /usr/sbin/lxrestart");
    system("chmod 777 /tmp");
    system("chmod o+t /tmp");
    print "Create script dir\n";
    copy_script();
    if (!lxfile_exists("/usr/local/lxlabs/kloxo/")) {
        print "Remove /usr/local/lxlabs/kloxo/ as it should not be here!\n";
        system("rmdir /usr/local/lxlabs/kloxo/httpdocs/ >/dev/null 2>&1");
        system("rmdir /usr/local/lxlabs/kloxo/ >/dev/null 2>&1");
    }
    if (!lxfile_exists("/var/named/chroot/etc/kloxo.named.conf")) {
        if (lxfile_exists("/var/named/chroot/etc/lxadmin.named.conf")) {
            remove_line("/var/named/chroot/etc/named.conf", "lxadmin.named.conf");
            $pattern = 'include "/etc/kloxo.named.conf";';
            $file = "/var/named/chroot/etc/named.conf";
            $comment = "//Kloxo";
            @addLineIfNotExistInside($file, $pattern, $comment);
            @lxfile_mv("/var/named/chroot/etc/lxadmin.named.conf", "/var/named/chroot/etc/kloxo.named.conf");
        }
    }
}
 function createIniFile()
 {
     $pclass = $this->main->getParentClass();
     $ver = find_php_version();
     //dprintr($this->main->phpini_flag_b);
     $this->initString($ver);
     //dprintr($this->main->phpini_flag_b);
     $header = lfile_get_contents("../file/phpini/php.ini.template-{$ver}");
     $cont = lfile_get_contents("../file/phpini/php.ini.temp");
     $htcont = lfile_get_contents("../file/phpini/htaccesstemp");
     $vlist = array("enable_zend_val", "enable_ioncube_val", "enable_xcache_val");
     $l1 = $this->main->getInheritedList();
     $l2 = $this->main->getLocalList();
     $l3 = $this->main->getExtraList();
     $ll = lx_array_merge(array($l1, $l2, $l3));
     $list = array_unique($ll);
     foreach ($list as $l) {
         $vl = strtil($l, "_flag") . "_val";
         if (array_search_bool($vl, $vlist)) {
             continue;
         }
         list($cont, $htcont) = $this->replacestr(array($cont, $htcont), $l);
     }
     foreach ($vlist as $vl) {
         list($cont) = $this->replacestr(array($cont), $vl);
     }
     /*
     list($cont) = $this->replacestr(array($cont), 'enable_zend_val');
     list($cont) = $this->replacestr(array($cont), 'enable_ioncube_val');
     list($cont) = $this->replacestr(array($cont), 'enable_xcache_val');
     
     
     list($cont, $htcont) = $this->replacestr(array($cont, $htcont), 'register_global_flag');
     list($cont, $htcont) = $this->replacestr(array($cont, $htcont), 'output_compression_flag');
     list($cont, $htcont) = $this->replacestr(array($cont, $htcont), 'display_error_flag');
     list($cont, $htcont) = $this->replacestr(array($cont, $htcont), 'file_uploads_flag');
     list($cont, $htcont) = $this->replacestr(array($cont, $htcont), 'upload_max_filesize');
     list($cont, $htcont) = $this->replacestr(array($cont, $htcont), 'log_errors_flag');
     list($cont, $htcont) = $this->replacestr(array($cont, $htcont), 'upload_tmp_dir_flag');
     list($cont, $htcont) = $this->replacestr(array($cont, $htcont), 'output_buffering_flag');
     list($cont, $htcont) = $this->replacestr(array($cont, $htcont), 'register_argc_argv_flag');
     list($cont, $htcont) = $this->replacestr(array($cont, $htcont), 'magic_quotes_gpc_flag');
     list($cont, $htcont) = $this->replacestr(array($cont, $htcont), 'variables_order_flag');
     list($cont, $htcont) = $this->replacestr(array($cont, $htcont), 'magic_quotes_runtime_flag');
     list($cont, $htcont) = $this->replacestr(array($cont, $htcont), 'magic_quotes_sybase_flag');
     list($cont, $htcont) = $this->replacestr(array($cont, $htcont), 'gpc_order_flag');
     list($cont, $htcont) = $this->replacestr(array($cont, $htcont), 'extension_dir_flag');
     list($cont, $htcont) = $this->replacestr(array($cont, $htcont), 'enable_dl_flag');
     list($cont, $htcont) = $this->replacestr(array($cont, $htcont), 'mysql_allow_persistent_flag');
     list($cont, $htcont) = $this->replacestr(array($cont, $htcont), 'disable_functions_flag');
     list($cont, $htcont) = $this->replacestr(array($cont, $htcont), 'max_execution_time_flag');
     list($cont, $htcont) = $this->replacestr(array($cont, $htcont), 'max_input_time_flag');
     list($cont, $htcont) = $this->replacestr(array($cont, $htcont), 'memory_limit_flag');
     list($cont, $htcont) = $this->replacestr(array($cont, $htcont), 'post_max_size_flag');
     list($cont, $htcont) = $this->replacestr(array($cont, $htcont), 'register_long_arrays_flag');
     list($cont, $htcont) = $this->replacestr(array($cont, $htcont), 'allow_url_fopen_flag');
     list($cont, $htcont) = $this->replacestr(array($cont, $htcont), 'allow_url_include_flag');
     list($cont, $htcont) = $this->replacestr(array($cont, $htcont), 'session_save_path_flag');
     list($cont, $htcont) = $this->replacestr(array($cont, $htcont), 'cgi_force_redirect_flag');
     list($cont, $htcont) = $this->replacestr(array($cont, $htcont), 'safe_mode_flag');
     */
     $stlist[] = "###Start Kloxo PHP config Area";
     $stlist[] = "###Start Lxdmin Area";
     $stlist[] = "###Start Kloxo Area";
     $stlist[] = "###Start Lxadmin PHP config Area";
     $endlist[] = "###End Kloxo PHP config Area";
     $endlist[] = "###End Kloxo Area";
     $endlist[] = "###End Lxadmin PHP config Area";
     $endstring = $endlist[0];
     $startstring = $stlist[0];
     if ($pclass === 'pserver') {
         $file = "/etc/php.ini";
         if (!lxfile_exists("__path_kloxo_back_phpini")) {
             lxfile_cp("/etc/php.ini", "__path_kloxo_back_phpini");
         }
         $this->enableDisableModule("enable_xcache_flag", "xcache");
         $htfile = null;
         $extrafile = "/etc/custom.php.ini";
         $extrastring = lfile_get_contents("/etc/custom.php.ini");
         $cont = "{$extrastring}\n{$cont}";
     } else {
         $dname = $this->main->getParentName();
         $elogfile = "/home/{$this->main->__var_customer_name}/__processed_stats/{$this->main->getParentName()}.phplog";
         $file = "__path_httpd_root/{$this->main->getParentName()}/php.ini";
         $extrafile = "__path_httpd_root/{$this->main->getParentName()}/custom.php.ini";
         $extrastring = lfile_get_contents($extrafile);
         $htfile = "{$this->main->__var_docrootpath}/.htaccess";
         $ht1file = "/home/httpd/{$this->main->getParentName()}/kloxoscript/.htaccess";
         $htcont = "php_value error_log {$elogfile}\n{$htcont}";
         $htcont = "<Ifmodule mod_php4.c>\n{$htcont}\n</Ifmodule>\n<Ifmodule mod_php5.c>\n{$htcont}\n</Ifmodule>\n";
         file_put_between_comments($stlist, $endlist, $startstring, $endstring, $htfile, $htcont);
         file_put_between_comments($stlist, $endlist, $startstring, $endstring, $ht1file, $htcont);
         lxfile_unix_chown($htfile, "{$this->main->__var_web_user}:apache");
         $adminbasedir = trim($this->main->__var_extrabasedir);
         if (!$this->main->isOn('__var_disable_openbasedir')) {
             $cont = "open_basedir = /home/{$this->main->__var_customer_name}:{$adminbasedir}:/tmp:/usr/share/pear:/home/httpd/{$dname}:/var/lib/php/session:/home/kloxo/httpd/script:/home/httpd/{$dname}/kloxoscript/\n{$cont}";
         }
         $cont = "error_log = {$elogfile}\n{$cont}";
         $cont = "{$extrastring}\n{$cont}";
     }
     lxfile_rm($file);
     lfile_put_contents($file, "{$header}\n{$cont}\n");
     createRestartFile($this->main->__var_webdriver);
 }