Example #1
0
function printProperty($class, $type)
{
    $r = new ReflectionClass($class);
    foreach ($r->getProperties() as $s) {
        if ($type === 'action') {
            $istr = "__acdesc_";
            if (!csb($s->name, "__acdesc_")) {
                continue;
            }
        }
        if ($type === 'property') {
            $istr = "__desc_";
            if (!csb($s->name, "__desc_")) {
                continue;
            }
        }
        $descr = get_classvar_description($class, $s->name);
        $name = strfrom($s->name, $istr);
        if (csa($descr[0], "q")) {
            continue;
        }
        if (cse($name, "_f")) {
            continue;
        }
        if (cse($name, "_l")) {
            continue;
        }
        if (cse($name, "_o")) {
            continue;
        }
        printf("%30s %s\n", $name, $descr['help']);
    }
}
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;
}
Example #3
0
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;
}
 static function mail_parse($file)
 {
     $fp = fopen($file, "r");
     $ret['header'] = null;
     $name = str_replace(",", "_s_coma_s_", $file);
     $name = str_replace(":", "_s_colon_s_", $name);
     $ret['nname'] = $name;
     while (!feof($fp)) {
         $l = fgets($fp);
         if ($l === "\n") {
             fclose($fp);
             break;
         }
         if (csb($l, "From:")) {
             $ret['from'] = strfrom($l, "From:");
         }
         if (csb($l, "Subject:")) {
             $ret['subject'] = strfrom($l, "Subject:");
         }
         if (csb($l, "Date:")) {
             $ret['date'] = strfrom($l, "Date:");
         }
         $ret['location'] = basename(dirname(dirname($file)));
         $ret['header'] .= $l;
     }
     if (!isset($ret['subject'])) {
         $ret['subject'] = '[no subject]';
     }
     return $ret;
 }
 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;
 }
Example #6
0
 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 __xenimport_parsedisk(&$ret, $val)
{
    preg_match("/\\['phy:([^']*)'.*'phy:([^']*)'\\]/i", $val, $matches);
    $ret['type'] = 'lvm';
    if (!isset($matches[0])) {
        $ret['type'] = 'file';
        preg_match("/\\['file:([^']*)'.*'file:([^']*)'\\]/i", $val, $matches);
    }
    if (!isset($matches[0])) {
        throw new lxException("could_not_parse_disk_string");
    }
    $diskstring = $matches[1];
    $disk = explode(",", $matches[1]);
    if (csb($disk[0], "/dev/")) {
        $disk[0] = strfrom($disk[0], "/dev/");
    }
    if ($ret['type'] === 'file') {
        $location = "/home/xen";
        $mdn = explode("/", $disk[0]);
        $maindiskname = array_pop($mdn);
    } else {
        list($location, $maindiskname) = explode("/", $disk[0]);
    }
    $ret['location'] = $location;
    $ret['maindiskname'] = $maindiskname;
    $swap = explode(",", $matches[2]);
    if (csb($swap[0], "/dev/")) {
        $swap[0] = strfrom($swap[0], "/dev/");
    }
    if ($ret['type'] === 'file') {
        $location = "/home/xen";
        $swp = explode("/", $swap[0]);
        $swapdiskname = array_pop($swp);
    } else {
        list($location, $swapdiskname) = explode("/", $swap[0]);
    }
    if ($location !== $ret['location']) {
        throw new lxException("swap_disk_location_not_same", 'nname', "{$ret['name']}: {$ret['location']}");
    }
    $ret['swapdiskname'] = $swapdiskname;
}
Example #8
0
 function createShowPropertyList(&$alist)
 {
     global $gbl, $sgbl, $login, $ghtml;
     return null;
     if ($this->getTrueParentO()->isClass('mailaccount') && !$this->getTrueParentO()->isLogin()) {
         $this->getTrueParentO()->createShowPropertyList($alist);
         foreach ($alist['property'] as &$__a) {
             if (!$ghtml->is_special_url($__a)) {
                 $__a = strfrom($__a, "goback=2&");
                 $__a = "goback=3&{$__a}";
             }
         }
     } else {
         if ($this->getTrueParentO()->isClass('mmail')) {
             $alist['property'][] = 'goback=2&a=show';
             $alist['property'][] = 'goback=1&a=list&c=mailaccount';
             $alist['property'][] = 'goback=2&a=show&sa=config';
         } else {
             $alist['property'][] = 'a=show';
         }
     }
     //$alist['property'][] = 'a=list&c=wlist_a';
     //$alist['property'][] = 'a=list&c=blist_a';
 }
Example #9
0
 function middlepart($web_home, $domain, $dirp)
 {
     global $gbl, $sgbl, $login, $ghtml;
     $string = null;
     foreach ($this->main->customerror_b as $k => $v) {
         if (csb($k, "url_") && $v) {
             $num = strfrom($k, "url_");
             if (csb($v, "http:/")) {
                 $nv = $v;
             } else {
                 $nv = remove_extra_slash("/{$v}");
             }
             $string .= "\tErrorDocument {$num} {$nv}\n";
         }
     }
     $string .= $this->enablePhp();
     $string .= $this->getDirprotect('');
     return $string;
 }
Example #10
0
 function print_information($place, $type, $class, $extr, $vlist = null)
 {
     global $gbl, $sgbl, $login, $ghtml;
     global $g_language_mes;
     $pinfo = null;
     if ($vlist) {
         $info = $vlist;
     } else {
         $info = implode("_", array($class, $type, $extr, $place));
     }
     if (isset($g_language_mes->__commonhelp[$info])) {
         $info = $g_language_mes->__commonhelp[$info];
     }
     if ($place !== 'post') {
         if (isset($g_language_mes->__information[$info])) {
             $pinfo = $g_language_mes->__information[$info];
         }
     } else {
         dprint($info);
         print "<table cellpadding=0 cellspacing=0> <tr height=10> <td > </td> </tr> </table> ";
     }
     if (!$pinfo) {
         $info = implode("_", array($type, $extr, $place));
         if ($place !== 'post') {
             if (isset($g_language_mes->__information[$info])) {
                 $pinfo = $g_language_mes->__information[$info];
             }
         } else {
             dprint($info);
         }
     }
     if (!$pinfo) {
         return;
     }
     $pinfo = str_replace("<%program%>", $sgbl->__var_program_name, $pinfo);
     $pinfo = explode("\n", $pinfo);
     $skip = false;
     foreach ($pinfo as $p) {
         $p = trim($p);
         if (csb($p, "<%ifblock:")) {
             $name = strfrom($p, "<%ifblock:");
             $name = strtil($name, "%>");
             $forward = true;
             if ($name[0] === '!') {
                 $forward = false;
                 $name = strfrom($name, "!");
             }
             if (method_exists($login, $name)) {
                 if ($forward) {
                     if (!$login->{$name}()) {
                         $skip = true;
                     }
                 } else {
                     if ($login->{$name}()) {
                         $skip = true;
                     }
                 }
             } else {
                 $skip = true;
             }
             continue;
         }
         if ($p === "</%ifblock%>") {
             $skip = false;
             continue;
         }
         if ($skip) {
             continue;
         }
         $out[] = $p;
     }
     $pinfo = implode("\n", $out);
     $fontcolor = "#000000";
     if ($sgbl->isBlackBackground()) {
         $fontcolor = "#999999";
     }
     $this->print_curvy_table_start();
     $pinfo = str_replace("\n", "<br>", $pinfo);
     $pinfo = str_replace("[b]", "<font style='font-weight: bold'>", $pinfo);
     $pinfo = str_replace("[/b]", "</font>", $pinfo);
     $ret = preg_match("/<url:([^>]*)>([^<]*)<\\/url>/", $pinfo, $matches);
     if ($ret) {
         $fullurl = $this->getFullUrl(trim($matches[1]));
         $pinfo = preg_replace("/<url:([^>]*)>([^<]*)<\\/url>/", "<a class=insidelist href={$fullurl}> {$matches['2']} </a>", $pinfo);
     }
     if ($sgbl->isBlackBackground()) {
         print "<font color=#999999>";
     }
     print $pinfo;
     if ($sgbl->isBlackBackground()) {
         print "</font> ";
     }
     $this->print_curvy_table_end();
 }
Example #11
0
function os_get_allips()
{
    $out = lxshell_output("ifconfig");
    $list = explode("\n", $out);
    foreach ($list as $l) {
        $l = trim($l);
        if (!csa($l, "inet addr:")) {
            continue;
        }
        $ip = strfrom($l, "inet addr:");
        $ip = strtilfirst($ip, " ");
        if (csb($ip, "127.0")) {
            continue;
        }
        $iplist[] = $ip;
    }
    return $iplist;
}
Example #12
0
 function getSyncClass($master, $syncserver, $class)
 {
     global $gbl, $sgbl, $login, $ghtml;
     if (!$login) {
         return;
     }
     if (isLocalhost($master)) {
         $master = 'localhost';
     }
     if ($login->isSuperadmin() && $master === 'localhost') {
         return null;
     }
     if (isLocalhost($syncserver)) {
         $syncserver = 'localhost';
     }
     //Dynamically load the syncserver info....
     if (!isset($this->driver) || !isset($this->driver[$master])) {
         $this->loaddriverappInfo($master);
     }
     if (!isset($this->driver[$master][$syncserver])) {
         $this->loaddriverappInfo($master);
     }
     $class_var = strtolower("pg_" . $class);
     //debugBacktrace();
     $pgm = $this->driver[$master][$syncserver]->driver_b;
     if (isset($pgm->{$class_var})) {
         $str = $pgm->{$class_var};
         if (csb($str, "__v_")) {
             $class_var = "pg_" . strtolower(strfrom($str, "__v_"));
         }
         return $pgm->{$class_var};
     }
     return null;
 }
Example #13
0
 static function readMaillog()
 {
     $date = time() - 24 * 3600 * 2;
     $logfile = "/var/log/kloxo/maillog";
     $fp = fopen($logfile, "r");
     $fsize = lxfile_size($logfile);
     FindRightPosition($fp, $fsize, $date, time(), array("mailtraffic", "getTimeFromOriginalQmailString"));
     while (!feof($fp)) {
         $s = fgets($fp);
         $s = trim($s);
         if (!csa($s, "lx-sending")) {
             continue;
         }
         $v = strfrom($s, "mail for");
         $id = $v;
         if (!isset($total[$id])) {
             $total[$id] = 1;
         } else {
             $total[$id]++;
         }
     }
     return $total;
 }
Example #14
0
 function replace_keywords($text, $object)
 {
     global $gbl, $sgbl, $login, $ghtml;
     $text = str_replace("%name%", "{$object->nname}\n", $text);
     $text = str_replace("%clientname%", $object->getParentName() . "\n", $text);
     $text = str_replace("%password%", $object->realpass, $text);
     if ($sgbl->isKloxo()) {
         $text = str_replace("%default_domain%", $object->default_domain, $text);
     }
     if (csa($text, "%ipaddress%")) {
         $db = new Sqlite($this->__masterserver, 'ipaddress');
         $iplist = $db->getRowsWhere("syncserver = 'localhost'");
         $text = str_replace("%ipaddress%", getFQDNforServer('localhost'), $text);
     }
     if (csa($text, "%masterserver%")) {
         $db = new Sqlite($this->__masterserver, 'ipaddress');
         $iplist = $db->getRowsWhere("syncserver = 'localhost'");
         $text = str_replace("%masterserver%", getFQDNforServer('localhost'), $text);
     }
     $string = null;
     foreach ($this->priv as $k => $v) {
         if ($this->isQuotaVariable($k)) {
             $var = get_v_descr($this, $k);
             $var = get_form_variable_name($var);
             $string .= "{$var}: {$v}\n";
         }
     }
     $text = str_replace("%quota%", $string, $text);
     $tlist = explode("\n", $text);
     $inside = false;
     $match = false;
     foreach ($tlist as $tl) {
         $tl = trim($tl);
         if (csb($tl, "<%class:")) {
             $inside = true;
             $classname = strfrom($tl, "<%class:");
             $classname = strtil($classname, "%>");
             if ($classname === $this->get__table()) {
                 $match = true;
             }
             continue;
         }
         if ($inside) {
             if (csb($tl, "<%/class%>")) {
                 if ($match) {
                     $total[] = $object->fillWelcomeMessage(implode("\n", $textinside));
                 }
                 $inside = false;
                 $textinside = null;
             } else {
                 $textinside[] = $tl;
             }
             continue;
         }
         $total[] = $tl;
     }
     return implode("\n", $total);
 }
Example #15
0
function __ajax_desc_tree()
{
    global $gbl, $sgbl, $login, $ghtml;
    $object = $gbl->__c_object;
    $icondir = get_image_path('/button/');
    $rclist = $object->getResourceChildList();
    $cid = $ghtml->node;
    if ($object->hasFileResource()) {
        $u = "a=show&k[class]=ffile&k[nname]=/";
        $u = $ghtml->getFullUrl($u);
        $v = createClName('ffile', '/');
        $ret[] = array('text' => "File", 'icon' => "{$icondir}/ffile_show.gif", 'hrefTarget' => 'mainframe', 'href' => $u, 'id' => "{$cid}&{$v}");
    }
    if ($ghtml->__resource_class) {
        $c = strfrom($ghtml->__resource_class, "__resource_");
        if (cse($c, "_l")) {
            $clname = $object->getChildNameFromDes($c);
            $list = $object->getList($clname, $totalcount);
            foreach ($list as $o) {
                $u = "a=show&k[class]={$o->getClass()}&k[nname]={$o->nname}";
                $u = $ghtml->getFullUrl($u);
                $ret[] = array('text' => basename($o->nname), 'icon' => "{$icondir}/{$o->getClass()}_list.gif", 'hrefTarget' => 'mainframe', 'href' => $u, 'id' => "{$cid}&{$o->getClName()}");
            }
        } else {
            if (cse($c, "_o")) {
                $clname = $object->getChildNameFromDes($c);
                $o = $object->getObject($clname);
                $u = "a=show&o={$o->getClass()}";
                $u = $ghtml->getFullUrl($u);
                $ret[] = array('text' => $o->getClass(), 'icon' => "{$icondir}/{$o->getClass()}_show.gif", 'hrefTarget' => 'mainframe', 'href' => $u, 'id' => "{$cid}&{$o->getClass()}");
            }
        }
        return $ret;
    }
    if ($ghtml->__title_function) {
        $t = $ghtml->__title_function;
        $alist = $object->createShowAlist($alist);
        foreach ($alist as $k => $v) {
            if (csb($k, "__title")) {
                if ($k !== $t) {
                    if ($insidetitle) {
                        $insidetitle = false;
                        break;
                    }
                    continue;
                }
                $insidetitle = true;
                continue;
            }
            if ($insidetitle) {
                $url = $ghtml->getFullUrl($v);
                if ($ghtml->is_special_url($url)) {
                    continue;
                }
                $urlinfo = $ghtml->getUrlInfo($url);
                $ret[] = array('text' => $urlinfo['description']['desc'], 'icon' => $urlinfo['image'], 'hrefTarget' => 'mainframe', 'leaf' => true, 'href' => $url, 'id' => "&end");
            }
        }
        return $ret;
    }
    if ($object->hasFunctions()) {
        $alist = $object->createShowAlist($alist);
        foreach ($alist as $k => $v) {
            if (!csb($k, "__title")) {
                continue;
            }
            $title = strfrom($k, "__title_");
            if ($title === 'mailaccount') {
                continue;
            }
            if ($title === 'custom') {
                continue;
            }
            $icon = "{$icondir}/__title_{$title}.gif";
            if (!lxfile_exists("__path_program_htmlbase/{$icon}")) {
                //lfile_put_contents("title.img", "$title.gif\n", FILE_APPEND);
                $icon = null;
            }
            $ret[] = array('text' => $v, 'icon' => $icon, 'hrefTarget' => '', 'href' => null, 'id' => "{$cid}&{$k}");
        }
    }
    foreach ($rclist as $c) {
        $clname = $object->getChildNameFromDes($c);
        $desc = get_description($clname);
        $desc = get_plural($desc);
        $url = $ghtml->getFullUrl("a=list&c={$clname}");
        $ret[] = array('text' => $desc, 'icon' => "{$icondir}/{$clname}_list.gif", 'hrefTarget' => 'mainframe', 'href' => $url, 'id' => "{$cid}&__resource_{$c}");
    }
    return $ret;
}
Example #16
0
function lxfile_get_disk_usage($file)
{
    $file = expand_real_root($file);
    $res = lxshell_output("dumpe2fs", "-h", $file);
    $res = explode("\n", $res);
    foreach ($res as $r) {
        if (csb($r, "Block size:")) {
            $blocksize = trim(strfrom($r, "Block size:")) / 1024;
        }
    }
    foreach ($res as $r) {
        if (csb($r, "Block count:")) {
            $total = trim(strfrom($r, "Block count:")) * $blocksize;
        }
        if (csb($r, "Free blocks:")) {
            $free = trim(strfrom($r, "Free blocks:")) * $blocksize;
        }
    }
    $ret['total'] = round($total / 1024, 2);
    $ret['used'] = round(($total - $free) / 1024, 2);
    return $ret;
}
Example #17
0
function parse_sql_data()
{
    global $gbl, $sgbl, $argc, $argv;
    static $_quota_var, $_field_var;
    $_return_value = null;
    $majmin = $sgbl->__ver_major_minor;
    $trel = $sgbl->__ver_release;
    $rpath = "sql/full.lxsql";
    $pathc = "htmllib/sql/common.lxsql";
    include $rpath;
    include $pathc;
    $string = $gl_sql_string_common . "\n" . $gl_sql_string;
    $string = explode("\n", $string);
    foreach ($string as $__k => $res) {
        $res = trim($res);
        if (!$res) {
            continue;
        }
        if (char_search_beg($res, "//")) {
            continue;
        }
        $res = preg_replace('/\\s+/', " ", $res);
        if (csb($res, "#")) {
            $vl = explode(" ", $res);
            $name = array_shift($vl);
            $name = strfrom($name, "#");
            $nvl = null;
            $nnvl = null;
            foreach ($vl as $k => $qv) {
                if (csb($qv, "#")) {
                    $_t = strfrom($qv, "#");
                    $nvl = lx_array_merge(array($nvl, $_quota_var[$_t]));
                } else {
                    $nvl[] = $qv;
                }
            }
            foreach ($nvl as $qv) {
                $nnvl[] = "priv_q_" . $qv;
                $nnvl[] = "used_q_" . $qv;
            }
            $_quota_var[$name] = $nvl;
            $g_qvar[$name] = $nnvl;
            $list = get_class_for_table($name);
            foreach ((array) $list as $l) {
                $_quota_var[$l] = $nvl;
                $g_qvar[$l] = $nnvl;
            }
            continue;
        }
        if (csb($res, "%")) {
            $vl = explode(" ", $res);
            $name = array_shift($vl);
            $nnnnvl = null;
            foreach ($vl as $q) {
                if (csb($q, "%")) {
                    $nnnnvl = lx_array_merge(array($nnnnvl, $g_var[$q]));
                } else {
                    $nnnnvl[] = $q;
                }
            }
            $g_var[$name] = $nnnnvl;
            continue;
        }
        $list = explode(" ", $res);
        $nlist = null;
        foreach ($list as $k => $l) {
            if (csb($l, "%")) {
                $nlist = array_merge($nlist, $g_var[$l]);
            } else {
                $nlist[] = $l;
            }
        }
        //dprintr($list);
        $list = $nlist;
        $nlist = null;
        foreach ($list as $l) {
            if ($l === '__q_var') {
                if (isset($g_qvar[$list[0]])) {
                    $nlist = lx_array_merge(array($nlist, $g_qvar[$list[0]]));
                }
            } else {
                $nlist[] = $l;
            }
        }
        $list = $nlist;
        //dprintr($list);
        $name = array_shift($list);
        $fields = lx_array_merge(array(get_default_fields(), $list));
        if (array_search_bool("syncserver", $fields)) {
            $fields[] = 'oldsyncserver';
            $fields[] = 'olddeleteflag';
        }
        $fields = array_unique($fields);
        $_field_var[$name] = $fields;
        $_return_value[$name] = $fields;
    }
    foreach ($_quota_var as &$__tq) {
        $__tq = array_flip($__tq);
    }
    foreach ($_field_var as &$__tq) {
        $__tq = array_flip($__tq);
    }
    $var['quotavar'] = $_quota_var;
    $var['fieldvar'] = $_field_var;
    lfile_put_contents("__path_dbschema", serialize($var));
    return $_return_value;
}
Example #18
0
 function getSpecialObject($class)
 {
     global $gbl, $sgbl, $login, $ghtml;
     if (!$this->isLxclient()) {
         dprint("Special object called in nonclient {$this->get__table()}:{$this->nname}<br> \n");
         //debugBacktrace();
     }
     $objectname = $class . "_o";
     // Don't ever call get_classvar_description from here. That will create an infinite loop.
     $name = get_real_class_variable($class, "__special_class");
     if (!$name) {
         $name = strfrom($class, "sp_");
     }
     $bname = $name . "_b";
     if (isset($this->{$objectname})) {
         return $this->{$objectname}->{$bname};
     }
     $obj = new $class($this->__masterserver, null, $this->getClName());
     $obj->get();
     //$this->addObject($class, $obj);
     $this->{$objectname} = $obj;
     $obj->{$bname}->__parent_o = $this;
     return $obj->{$bname};
 }
Example #19
0
 function getId()
 {
     if (isset($this->__var_extraid)) {
         return strfrom($this->__var_extraid, "__lx_");
     } else {
         if (csa($this->nname, "_s_vv_p_")) {
             return strfrom($this->nname, "_s_vv_p_");
         } else {
             $pdesc = get_classvar_description($this->getParentO()->getClass());
             return "{$pdesc['2']}: {$this->getParentO()->getId()} {$this->nname}";
         }
     }
 }
Example #20
0
function sshLogString($string, &$list)
{
    //'refuse' => "refused connection",
    $str = array('success' => "Accepted password", 'fail' => "Failed password");
    $match = false;
    foreach ($str as $k => $v) {
        if (!csa($string, "sshd")) {
            continue;
        }
        if (csa($string, $v)) {
            $match = true;
            $access = $k;
            break;
        }
    }
    if (!$match) {
        return;
    }
    $time = getTimeFromSysLogString($string);
    preg_match("/.*password for ([^ ]*) from ([^ ]*).*/", $string, $match);
    if (!$match) {
        return;
    }
    $ip = $match[2];
    if (csb($ip, "::ffff:")) {
        $ip = strfrom($ip, "::ffff:");
    }
    $user = $match[1];
    if (csb($ip, "127")) {
        return;
    }
    $list[$ip][$time] = array('service' => 'ssh', 'user' => $user, 'access' => $access);
}
Example #21
0
    function printSelectObjectTable($name_list, $parent, $class, $blist = array(), $display = null)
    {
        global $gbl, $sgbl, $login, $ghtml;
        print_time("{$class}.objecttable");
        if ($this->frm_accountselect !== null) {
            $sellist = explode(',', $this->frm_accountselect);
        } else {
            $sellist = null;
        }
        $classdesc = $this->get_class_description($class, $display);
        $unique_name = trim($parent->nname) . trim($class) . trim($display) . trim($classdesc[2]);
        $unique_name = fix_nname_to_be_variable($unique_name);
        $filtername = $parent->getFilterVariableForThis($class);
        $fil = $this->frm_hpfilter;
        $sortdir = null;
        $sortby = null;
        if (isset($fil[$filtername]['sortby'])) {
            $sortby = $fil[$filtername]['sortby'];
        }
        if (isset($fil[$filtername]['sortdir'])) {
            $sortdir = $fil[$filtername]['sortdir'];
        }
        $pagesize = '99999';
        $iconpath = get_image_path() . "/button";
        $nlcount = count($name_list) + 1;
        $imgheadleft = $login->getSkinDir() . "/top_lt.gif";
        $imgheadleft2 = $login->getSkinDir() . "/top_lt.gif";
        $imgheadright = $login->getSkinDir() . "/top_rt.gif";
        $imgheadbg = $login->getSkinDir() . "/top_bg.gif";
        $imgbtnbg = $login->getSkinDir() . "/btn_bg.gif";
        $imgtablerowhead = $login->getSkinDir() . "/tablerow_head.gif";
        $imgtablerowheadselect = $login->getSkinDir() . "/top_line_medium.gif";
        $imgbtncrv = $login->getSkinDir() . "/btn_crv.gif";
        $imgtopline = $login->getSkinDir() . "/top_line.gif";
        $classdesc = $this->get_class_description($class);
        $unique_name = trim($parent->nname) . trim($class) . trim($classdesc[2]);
        $unique_name = fix_nname_to_be_variable($unique_name);
        //dprint("-- ".$unique_name. " --", 2);
        ?>
<br />
      <script> var ckcount<?php 
        echo $unique_name;
        ?>
 ; </script>
<?php 
        $tsortby = $sortby;
        if (!$sortby) {
            $tsortby = exec_class_method($class, "defaultSort");
        }
        if (!$sortdir) {
            $sortdir = exec_class_method($class, "defaultSortDir");
        }
        //print_time("objecttable");
        $obj_list = $parent->getVirtualList($class, $total_num, $tsortby, $sortdir);
        //print_time("objecttable", 'objecttable');
        if (!$sellist) {
            //$total_num = $this->display_count($obj_list, $display) ;
        }
        ?>

    <table width=100%> <tr> <td align=center>
    <table cellspacing=2 cellpadding=2 width=97% align=center>
    <tr><td class=rowpoint></td><td colspan= <?php 
        echo $nlcount;
        ?>
>
    <table cellpadding=0 cellspacing=0 border=0 width=100%>
    <tr><td valign=bottom ></td>
    <td>
    <?php 
        if (isset($ghtml->__http_vars['frm_hpfilter'][$filtername]['pagenum'])) {
            $cgi_pagenum = $ghtml->__http_vars['frm_hpfilter'][$filtername]['pagenum'];
        } else {
            $cgi_pagenum = 1;
        }
        if (!$sellist) {
            $this->print_next_previous($parent, $class, "top", $cgi_pagenum, $total_num, $pagesize);
        }
        ?>
    </td>
    <td align=right valign=bottom >

    <?php 
        if (!$sellist) {
            ?>
            <table cellpadding="0" cellspacing="0" border="0" height="27" >

            <tr><td><img src="<?php 
            echo $imgheadleft;
            ?>
"></td><td nowrap valign=middle background="<?php 
            echo $imgheadbg;
            ?>
"><b><font color="#ffffff"><?php 
            echo get_plural($classdesc[2]);
            ?>
 under <?php 
            echo $parent->display("nname");
            ?>
 </b> <?php 
            echo $this->print_machine($parent);
            ?>
 <b>  (<?php 
            echo $total_num;
            ?>
)</b></font></td><td><img src="<?php 
            echo $imgheadright;
            ?>
"></td></tr>
            </table>
            </td>
            </tr>

            <tr><td colspan=3><table cellpadding=0 cellspacing=0 border=0 width=100% height=35 background="<?php 
            echo $imgbtnbg;
            ?>
">
            <tr><td><img src="<?php 
            echo $imgbtncrv;
            ?>
"></td><td width=80% align=left > <table width=100% cellpadding=0 cellspacing=0 border=0><tr><td valign=bottom><?php 
            $this->print_list_submit($class, $blist, $unique_name);
            ?>
</td></tr></table></td><td width=15% align=right><b><font color="#ffffff"><?php 
            $this->print_search($parent, $class);
            ?>
</font></b></td></tr>
            </table>
            </td></tr>
    </td></tr><tr><td height=2 colspan=2></td></tr></table>

        <?php 
        } else {
            $descr = $this->getActionDescr($_SERVER['PHP_SELF'], $this->__http_vars, $class, $var, $identity);
            ?>
<table cellpadding=0 cellspacing=0 border=0 width=100%><tr><td width=70% valign=bottom><table cellpadding=0 cellspacing=0 border=0 width=100%><tr><td width=100% height=2 background="<?php 
            echo $imgtopline;
            ?>
"></td></tr></table></td><td align=right><table cellpadding=0 cellspacing=0 border=0 width=100% ><tr><td><img src="<?php 
            echo $imgheadleft;
            ?>
"></td><td nowrap width=100% background="<?php 
            echo $imgheadbg;
            ?>
" ><b><font color="#ffffff">  Confirm <?php 
            echo $descr[1];
            ?>
:  </b><?php 
            echo get_plural($classdesc[2]);
            ?>
 from <?php 
            echo $parent->display("nname");
            ?>
</font></td><td><img src="<?php 
            echo $imgheadright;
            ?>
"></td></tr></table></td></tr></table>

    </td></tr><tr><td height=0 colspan=2></td></tr></table>

        <?php 
        }
        ?>

<!--    </td></tr><tr><td height=2 colspan=2></td></tr></table> -->
    <tr><td bgcolor="#ffffff"></td>
 <?php 
        $imguparrow = get_general_image_path() . "/button/uparrow.gif";
        $imgdownarrow = get_general_image_path() . "/button/downarrow.gif";
        foreach ($name_list as $name => $width) {
            $desc = "__desc_{$name}";
            $descr[$name] = get_classvar_description($class, $desc);
            if (!$descr[$name]) {
                print "Cannot access static variable {$class}::{$desc}";
                exit(0);
            }
            if (csa($descr[$name][2], ':')) {
                $_tlist = explode(':', $descr[$name][2]);
                $descr[$name][2] = $_tlist[0];
            }
            foreach ($descr[$name] as &$d) {
                if ($this->is_special_url($d)) {
                    continue;
                }
                if (strstr($d, "%v") !== false) {
                    $d = str_replace("[%v]", $classdesc[2], $d);
                }
            }
            if ($width === "100%") {
                $wrapstr = "wrap";
            } else {
                $wrapstr = "nowrap";
            }
            if ($sortby && $sortby === $name) {
                $wrapstr .= " background={$imgtablerowheadselect}";
                print "<td width={$width} {$wrapstr} ><table cellpadding=0 cellspacing=0 border=0> <tr> <td rowspan=2 {$wrapstr}>";
            } else {
                $wrapstr .= " background={$imgtablerowhead}";
                print "<td width={$width} {$wrapstr} class=col>";
            }
            ?>
        <b><?php 
            $this->print_sortby($parent, $class, $unique_name, $name, $descr[$name]);
            ?>
 </b></font>

        <?php 
            $imgarrow = $sortdir === "desc" ? $imgdownarrow : $imguparrow;
            if ($sortby && $sortby === $name) {
                print "</td> <td width=15><img src=" . $imgarrow . " ></td><td ></td></tr></table>";
            }
            ?>
 </td>

 <?php 
        }
        $count = 0;
        $rowcount = 0;
        ?>
    <td width=10 background=<?php 
        echo $imgtablerowhead;
        ?>
 >   <form name="formselectall<?php 
        echo $unique_name;
        ?>
" value=hello> <input type=checkbox name="selectall<?php 
        echo $unique_name;
        ?>
" value=on <?php 
        if ($sellist) {
            echo "checked disabled";
        }
        ?>
 onclick="javascript:calljselectall<?php 
        echo $unique_name;
        ?>
 ()"></form> </td>
    <?php 
        print "</tr> ";
        print_time('loop');
        $n = 1;
        foreach ((array) $obj_list as $okey => $obj) {
            $checked = '';
            // Fix This.
            if ($sellist) {
                $checked = "checked disabled";
                if (!array_search_bool($obj->nname, $sellist)) {
                    continue;
                }
            }
            $imgpointer = get_general_image_path() . "/button/pointer.gif";
            $imgblank = get_general_image_path() . "/button/blank.gif";
            ?>

        <script> loadImage('<?php 
            echo $imgpointer;
            ?>
') </script>
        <script> loadImage('<?php 
            echo $imgblank;
            ?>
') </script>

            <tr id=tr<?php 
            echo $unique_name . $rowcount;
            ?>
 class=tablerow<?php 
            echo $count;
            ?>
 onmouseover=" swapImage('imgpoint<?php 
            echo $rowcount;
            ?>
','','<?php 
            echo $imgpointer;
            ?>
',1);" onmouseout="swapImgRestore();">
        <td id=td<?php 
            echo $unique_name . $rowcount;
            ?>
 width=5 class=rowpoint><img name=imgpoint<?php 
            echo $rowcount;
            ?>
 src="<?php 
            echo $imgblank;
            ?>
"></td>
        <?php 
            $colcount = 1;
            foreach ($name_list as $name => $width) {
                $this->printObjectElement($parent, $class, $classdesc, $obj, $name, $width, $descr, $colcount . "_" . $rowcount);
                $colcount++;
            }
            $basename = basename($obj->nname);
            $selectshowbase = $this->frm_selectshowbase;
            // issue #609
            //      $ret = strfrom($parent->nname, $selectshowbase);
            $ret = str_replace('//', '/', strfrom($parent->nname, $selectshowbase));
            print " <td width=10 >";
            print "<a class=button href=\"javascript:callSetSelectFolder('/{$ret}/{$basename}')\">";
            print " Select </a>";
            print "</tr> ";
            if ($count === 0) {
                $count = 1;
            } else {
                $count = 0;
            }
            $rowcount++;
            if (!$sellist) {
                if ($n === $pagesize * $cgi_pagenum) {
                    break;
                }
            }
            $n++;
        }
        print_time('loop', "loop{$n}");
        print "<tr><td></td><td colspan={$nlcount}>";
        if (!$rowcount) {
            if ($ghtml->frm_searchstring) {
                ?>
            <table width=95%> <tr align=center> <td width=100%> <b>  No Matches Found  </b> </td> </tr> </table>
            <?php 
            } else {
                ?>
            <table width=95%> <tr align=center> <td width=100%> <b>  No <?php 
                echo get_plural($classdesc[2]);
                ?>
  under <?php 
                echo $parent->nname;
                ?>
   </b> </td> </tr> </table>
            <?php 
            }
        }
        print "</td></tr>";
        print "<tr><td class=rowpoint></td><td colspan=" . $nlcount . " >\n    <table cellpadding=0 cellspacing=0 border=0 width=100%>\n    <tr height=1 style='background:url({$imgtopline})'><td></td></tr>\n    <tr><td>";
        ?>
<script>ckcount<?php 
        echo $unique_name;
        ?>
 = <?php 
        echo $rowcount . ";  ";
        ?>
function calljselectall<?php 
        echo $unique_name;
        ?>
(){
    jselectall(document.formselectall<?php 
        echo $unique_name;
        ?>
.selectall<?php 
        echo $unique_name;
        ?>
,ckcount<?php 
        echo $unique_name;
        ?>
,'<?php 
        echo $unique_name;
        ?>
')
}
</script>


<?php 
        print "<table> <tr> <td >";
        print "<a class=button href=\"javascript:window.close()\"> Cancel </a> &nbsp; &nbsp;  ";
        print "</td> <td width=30> &nbsp; </td> <td >";
        print "</td> </tr> </table> ";
        print "</td></tr></table></tr></table></td> </tr> </table>";
        //else {
        //
        //      $this->print_list_submit($blist);
        //  }
        //print_time("$class.objecttable", "$class.objecttable");
        /// Important. This is to make sure that the session saving etc doesn't take place. We just need a plain and clean window without any saving. If this happens the current url gets added to the sessiona and redirection will screw up.
        exit;
    }
Example #22
0
function file_server($fd, $string)
{
    $string = strfrom($string, "__file::");
    $rem = unserialize(base64_decode($string));
    if (!$rem) {
        return;
    }
    return do_serve_file($fd, $rem);
}
Example #23
0
 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);
 }
Example #24
0
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;
        }
    }
}
Example #25
0
function get_bytes_for_interface($l)
{
    static $net;
    if (!$net) {
        $net = lfile_get_contents("/proc/net/dev");
        $net = explode("\n", $net);
    }
    foreach ($net as $n) {
        $n = trimSpaces($n);
        if (!csb($n, "vif-{$l}:")) {
            continue;
        }
        $n = strfrom($n, "vif-{$l}:");
        $n = trimSpaces($n);
        $b = explode(" ", $n);
        $total = $b[0] + $b[8];
        // It seems for xen it is the reverse. The input for the vif is the output for the virtual machine.
        return array('total' => $total, 'incoming' => $b[8], 'outgoing' => $b[0]);
    }
    return 0;
}
Example #26
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;
 }
Example #27
0
 function createExtraVariables()
 {
     if (csb($this->subaction, 'graph_')) {
         $res = vps::findVpsGraph($this->nname, strfrom($this->subaction, "graph_"));
         $this->__var_graph_list = $res;
     }
 }
Example #28
0
function process_in_master($total)
{
    global $gbl, $sgbl, $login, $ghtml;
    $remotechar = $sgbl->__var_remote_char;
    $total = strfrom($total, "__master::");
    $rmt = unserialize(base64_decode($total));
    $res = new Remote();
    $res->message = "Master info";
    $res->exception = null;
    $vv = master_get_data($rmt->var);
    $res->ddata = $vv;
    $out = base64_encode(serialize($res));
    return $out;
}
Example #29
0
function checkRestart()
{
    if (if_demo()) {
        return;
    }
    $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");
        // THe 3,4 etc are the tcp ports of this program, and it should be closed, else some programs will grab it.
        //exec("/etc/init.d/$cmd restart  </dev/null >/dev/null 2>&1 3</dev/null 4</dev/null 5</dev/null 6</dev/null &");
        switch ($cmd) {
            case 'lxcollectquota':
                exec_justdb_collectquota();
                break;
            case 'openvz_tc':
                exec_openvz_tc();
                break;
            default:
                exec_with_all_closed("/etc/init.d/{$cmd} restart");
                break;
        }
    }
}
Example #30
0
function get_free_loop()
{
    global $global_shell_error, $global_shell_ret, $global_shell_out;
    lxfile_unix_chmod("__path_program_root/sbin/findfreeloop", "0755");
    $ret = lxshell_return("__path_program_root/sbin/findfreeloop");
    $loop = trim($global_shell_out);
    if (!$ret) {
        return $loop;
    }
    $num = strfrom($loop, "/dev/loop");
    if ($num >= 128) {
        throw new lxException("could_not_find_free_loop");
    }
    lxshell_return("mknod", "-m660", $loop, "b", "7", $num);
    return $loop;
}