예제 #1
0
 static function getTimeFromString($line)
 {
     ///2006-03-10 07:00:01
     $line = trimSpaces($line);
     $list = explode(" ", $line);
     return $list[0];
 }
예제 #2
0
 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;
 }
예제 #3
0
 static function getPackages($nocache = false)
 {
     $cmd = self::getYumCommand();
     $file = fix_nname_to_be_variable(implode(" ", $cmd));
     $file = "__path_program_root/cache/{$file}";
     if ($nocache) {
         $val = `{$cmd}`;
     } else {
         $val = get_with_cache($file, $cmd);
     }
     $list = explode("\n", $val);
     dprintr($list);
     $match = false;
     $res = null;
     foreach ($list as $l) {
         $l = trim($l);
         if (strstr($l, "---------------------")) {
             $match = true;
             continue;
         }
         if ($match) {
             if (!$l) {
                 break;
             }
         }
         if (!$match) {
             continue;
         }
         $l = trimSpaces($l);
         $l = trim($l);
         if (!$l) {
             continue;
         }
         $v = explode(" ", $l);
         $out['nname'] = $v[0];
         //$out['arch'] = $v[1];
         $out['update_version'] = $v[1];
         $out['kloxo_status'] = 'dull';
         if ($v[3] === 'lxlabs-updates') {
             $out['kloxo_status'] = 'on';
         }
         $out['repo'] = $v[3];
         $res[] = $out;
     }
     //dprintr($res);
     return $res;
 }
예제 #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;
}
예제 #5
0
 static function getAuthorizedKey($username)
 {
     $v = self::readAuthorizedKey($username);
     $list = explode("\n", $v);
     foreach ($list as $l) {
         $l = trim($l);
         if (!$l) {
             continue;
         }
         $l = trimSpaces($l);
         $vv = explode(" ", $l);
         $r['nname'] = fix_nname_to_be_variable_without_lowercase($vv[1]);
         $r['full_key'] = $l;
         $r['key'] = substr($vv[1], 0, 50);
         $r['key'] .= " .....";
         $r['hostname'] = $vv[2];
         $r['username'] = $username;
         $r['type'] = $vv[0];
         $res[$r['nname']] = $r;
     }
     return $res;
 }
예제 #6
0
파일: weblib.php 프로젝트: zseand/kloxo
 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;
 }
예제 #7
0
function get_vpsid_from_ipaddress($ip)
{
    static $res;
    if (!$res) {
        $res = lxshell_output('vzlist', '-H', '-o', 'vpsid,ip');
    }
    $list = explode("\n", $res);
    foreach ($list as $l) {
        $l = trimSpaces($l);
        if (csa($l, $ip)) {
            list($vpsid) = explode(" ", $l);
            return $vpsid;
        }
    }
    return 0;
}
예제 #8
0
 /**
  * Get the bytes for a given interface.
  *
  * Recollect the bytes column (incoming and outgoing) from
  * the file /proc/net/dev for a given interface on a machine.
  *
  * @author Anonymous <*****@*****.**>
  * @author Ángel Guzmán Maeso <*****@*****.**>
  * 
  * @param string $interface The interface name. NULL by default.
  * @return array[integer] total, incoming, outgoing
  */
 public static function get_bytes_for_interface($interface = NULL)
 {
     static $networks;
     // Make a cache with the networks available
     // Recollect the data for first time if not cached
     if (!isset($networks) || empty($networks)) {
         $networks = lfile_get_contents('/proc/net/dev');
         $networks = explode(PHP_EOL, $networks);
     }
     foreach ($networks as $network) {
         $vif_interface = 'vif' . $interface . ':';
         $network = trimSpaces($network);
         if (!char_search_beg($network, $vif_interface)) {
             continue;
         }
         // Parse the data for get total/incoming/outgoing
         $network = strfrom($network, $vif_interface);
         $network = trimSpaces($network);
         $network_bytes = explode(' ', $network);
         $total_incoming = $network_bytes[8];
         $total_outgoing = $network_bytes[0];
         $total = $total_outgoing + $total_incoming;
         // 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' => $total_incoming, 'outgoing' => $total_outgoing);
     }
     return 0;
     // Return 0 bytes
 }
예제 #9
0
 function getBlockIP()
 {
     global $gbl, $sgbl, $login, $ghtml;
     $t = trimSpaces($this->main->text_blockip);
     $t = trim($t);
     if (!$t) {
         return;
     }
     $t = str_replace(".*", "", $t);
     $string = null;
     $string .= "\t<Location />\n";
     $string .= "\t\tOrder allow,deny\n";
     $string .= "\t\tdeny from {$t}\n";
     $string .= "\t\tallow from all\n";
     $string .= "\t</Location>\n\n";
     return $string;
 }
예제 #10
0
파일: lib.php 프로젝트: lonelywoolf/hypervm
function find_hop($l)
{
    global $global_dontlogshell;
    $global_dontlogshell = true;
    $out = lxshell_output("ping -c 1 {$l}");
    $list = explode("\n", $out);
    foreach ($list as $l) {
        $l = trim($l);
        if (csb($l, "rtt")) {
            continue;
        }
        $l = trimSpaces($l);
        $ll = explode(" ", $l);
        $lll = explode("/", $ll[3]);
        return round($lll[1], 1);
    }
}
예제 #11
0
파일: linuxfslib.php 프로젝트: zseand/kloxo
function lxfile_get_uncompressed_size($file)
{
    global $global_dontlogshell;
    $tmp = $global_dontlogshell;
    $global_dontlogshell = true;
    $out = lxshell_output("gzip", "-l", $file);
    if (csa($out, "not in")) {
        return 0;
    }
    $out = trim($out);
    if (!$out) {
        return 0;
    }
    $out = explode("\n", $out);
    $out = trimSpaces($out[1]);
    $out = explode(" ", $out);
    $global_dontlogshell = $tmp;
    return $out[1];
}
예제 #12
0
파일: linuxlib.php 프로젝트: zseand/kloxo
function os_get_default_ethernet()
{
    $res = lxshell_output("route", "-n");
    $re = explode("\n", $res);
    foreach ($re as $r) {
        if (csb($r, "0.0.0.0")) {
            $r = trimSpaces($r);
            $o = explode(" ", $r);
            return trim($o[7]);
        }
    }
    return null;
}
예제 #13
0
function getTimeFromSysLogString($line)
{
    $line = trimSpaces($line);
    $year = @date('Y');
    list($month, $day, $time) = explode(" ", $line);
    $month = get_num_for_month($month);
    list($hour, $min, $sec) = explode(':', $time);
    //$s  =  mktime($hour , $min , $sec , monthToInt($month), str_pad($day , 2, 0, STR_PAD_LEFT) , $year);
    $s = @mktime($hour, $min, $sec, $month, $day, $year);
    //dprint(" $date $time $hour, $min $sec $month, $day , $year, Time: $s\n");
    // Return date and size. The size param is not important. Our aim is to find the right position.
    return $s;
}
예제 #14
0
 static function parse_data($data)
 {
     foreach ($data as $d) {
         $d = trimSpaces($d);
         $d = str_replace(":", "", $d);
         $rval = explode(" ", $d);
         $res[strtolower($rval[0])] = $rval[1];
     }
     return $res;
 }
예제 #15
0
 function getBlockIP()
 {
     global $gbl, $sgbl, $login, $ghtml;
     $t = trimSpaces($this->main->text_blockip);
     $t = trim($t);
     if (!$t) {
         return;
     }
     $t = str_replace(".*", "", $t);
     $t = str_replace(" ", "|", $t);
     $string = "\$HTTP[\"remoteip\"] =~ \"{$t}\" {\n";
     $string .= "url.access-deny = ( \"\" )\n";
     $string .= "}\n";
     return $string;
 }
예제 #16
0
<?php

include_once "htmllib/lib/include.php";
if ($sgbl->isHyperVm()) {
    exit(10);
}
if (lxfile_exists("/proc/user_beancounters")) {
    $list = lfile("/proc/user_beancounters");
    foreach ($list as $l) {
        $l = trimSpaces($l);
        if (!csb($l, "privvmpages")) {
            continue;
        }
        $d = explode(" ", $l);
        $mem = $d[3] / 256;
    }
    exit(11);
} else {
    if (lxfile_exists("/proc/xen")) {
        exit(11);
    } else {
        $mem = pserver__linux::getTotalMemory();
        $mem += 200;
    }
}
if ($mem < 180) {
    exit(15);
}
exit(11);