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":
                $ret['name'] = strtolower(trim($val, '"'));
                break;
            case "ipaddr":
                $val = trim($val, '"');
                $ret['ipaddress'] = trim($val);
                break;
            case "hostname":
                $val = trim($val, '"');
                $ret['hostname'] = trim($val);
                break;
            case "disk":
                __xenimport_parsedisk($ret, $val);
                break;
        }
    }
    return $ret;
}
Example #2
0
function os_fix_fstab()
{
    $list = lfile_trim("/etc/fstab");
    foreach ($list as $l) {
        $nl = trimSpaces($l);
        $n = explode(" ", $nl);
        if ($n[1] !== "/home" && $n[1] !== '/') {
            $out[] = $l;
            continue;
        }
        if (!csa($n[3], "usrquota")) {
            $mount[] = $n[1];
            $n[3] = "{$n['3']},usrquota,grpquota";
        }
        $o = implode("\t", $n);
        $out[] = $o;
    }
    $out = implode("\n", $out);
    $out .= "\n";
    dprint($out);
    lfile_put_contents("/etc/fstab", $out);
    dprintr($mount);
    foreach ($mount as $m) {
        system("mount {$m} -o remount");
    }
}
Example #3
0
 static function getShellList()
 {
     global $gbl, $sgbl, $login, $ghtml;
     $shell_file = "__path_real_etc_root/shells";
     $newcont = lfile_trim($shell_file);
     $newcont = array_remove($newcont, $sgbl->__var_noaccess_shell);
     $shells = add_disabled($newcont);
     return $shells;
 }
Example #4
0
function parse_etc_mime()
{
    $list = lfile_trim("/etc/mime.types");
    foreach ($list as $s) {
        if (!$s) {
            continue;
        }
        if ($s[0] === '#') {
            continue;
        }
        $s = trimSpaces($s);
        $s = explode(" ", $s);
        $type = array_shift($s);
        foreach ($s as $ss) {
            $res[$ss] = $type;
        }
    }
    return $res;
}
Example #5
0
function interfacetraffic_main()
{
    global $gbl, $sgbl, $login, $ghtml;
    if (!lxfile_exists("__path_program_etc/xeninterface.list")) {
        return;
    }
    $list = lfile_trim("__path_program_etc/xeninterface.list");
    if (!lxfile_exists("__path_program_etc/newxeninterfacebw.data")) {
        foreach ($list as $k) {
            $total[$k] = get_bytes_for_interface($k);
        }
        dprintr($total);
        lfile_put_contents("__path_program_etc/newxeninterfacebw.data", serialize($total));
        return;
    }
    $data = unserialize(lfile_get_contents("__path_program_etc/newxeninterfacebw.data"));
    $total = null;
    foreach ($list as $k) {
        $total[$k] = get_bytes_for_interface($k);
        if (isset($data[$k])) {
            if ($total[$k]['total'] < $data[$k]['total']) {
                $v = $total[$k]['total'];
                $vinc = $total[$k]['incoming'];
                $vout = $total[$k]['outgoing'];
            } else {
                $v = $total[$k]['total'] - $data[$k]['total'];
                $vinc = $total[$k]['incoming'] - $data[$k]['incoming'];
                $vout = $total[$k]['outgoing'] - $data[$k]['outgoing'];
            }
        } else {
            $v = $total[$k]['total'];
            $vinc = $total[$k]['incoming'];
            $vout = $total[$k]['outgoing'];
        }
        execRrdTraffic("xen-{$k}", $v, "-{$vinc}", $vout);
        $stringa[] = time() . " " . date("d-M-Y:H:i") . " {$k} {$v} {$vinc} {$vout}";
    }
    dprintr($total);
    $string = implode("\n", $stringa);
    lfile_put_contents("/var/log/lxinterfacetraffic.log", "{$string}\n", FILE_APPEND);
    lfile_put_contents("__path_program_etc/newxeninterfacebw.data", serialize($total));
}
Example #6
0
function add_line_to_secondary_mycnf($master, $slavepass)
{
    global $gbl, $sgbl, $login, $ghtml;
    if (!lxfile_exists("/etc/secondary_master.copy.my.cnf")) {
        lxfile_cp("/etc/my.cnf", "/etc/secondary_master.copy.my.cnf");
    }
    $list = lfile_trim("/etc/my.cnf");
    foreach ($list as $k => $l) {
        if (check_if_skip($l)) {
            continue;
        }
        $ll[] = $l;
        if ($l == '[mysqld]') {
            $ll[] = "server-id=2";
            $ll[] = "master-host={$master}";
            $ll[] = "master-user=lxlabsslave";
            $ll[] = "master-password={$slavepass}";
        }
    }
    lfile_put_contents("/etc/my.cnf", implode("\n", $ll));
    system("service mysqld restart");
}
function add_line_to_master_mycnf()
{
    global $gbl, $sgbl, $login, $ghtml;
    $dbf = $sgbl->__var_dbf;
    if (!lxfile_exists("/etc/primary_master.copy.my.cnf")) {
        lxfile_cp("/etc/my.cnf", "/etc/primary_master.copy.my.cnf");
    }
    $v = lfile_get_contents("/etc/my.cnf");
    if (csa($v, "binlog-do-db")) {
        print "Line already exists in /etc/my.cnf\n";
        return;
    }
    $list = lfile_trim("/etc/my.cnf");
    foreach ($list as $k => $l) {
        $ll[] = $l;
        if ($l == '[mysqld]') {
            $ll[] = "log-bin=mysql-bin";
            $ll[] = "binlog-do-db={$dbf}";
            $ll[] = "server-id=1";
        }
    }
    lfile_put_contents("/etc/my.cnf", implode("\n", $ll));
    system("service mysqld restart");
}
Example #8
0
 function updatepermalink($param)
 {
     $name = $param['lighty_pretty_app_f'];
     $path = $param['lighty_pretty_path_f'];
     $list = lfile_trim("../file/prettyurl/{$name}");
     $list[0] = trimSpaces($list[0]);
     list($t, $type, $typen) = explode(" ", $list[0]);
     array_shift($list);
     if ($type === '404' || $typen === '404') {
         $this->customerror_b->url_404 = str_replace("<%lxpath%>", $path, $list[0]);
         array_shift($list);
     }
     if ($type === 'rewrite' || $typen === 'rewrite') {
         $string = implode("\n", $list);
         $this->text_lighty_rewrite = str_replace("<%lxpath%>", $path, $string);
     }
     return $param;
 }
Example #9
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;
 }
Example #10
0
function remove_scpid($cont)
{
    $home = os_get_home_dir("root");
    $file = "{$home}/.ssh/authorized_keys2";
    $list = lfile_trim($file);
    foreach ($list as $l) {
        if (!$l) {
            continue;
        }
        if ($l === $cont) {
            continue;
        }
        $nlist[] = $l;
    }
    lfile_put_contents($file, implode("\n", $nlist) . "\n");
}