static function getEachfileqouta($file, $domainname, $oldtime, $newtime)
 {
     $fp = @fopen($file, "r");
     print "Opening File name is :{$file}\n";
     error_reporting(0);
     if (!$fp) {
         return 0;
     }
     $fsize = filesize($file);
     print "Here U are in Mail log file Size is:{$fsize}\n";
     if ($fsize <= 5) {
         return 0;
     }
     $total = 0;
     $ret = FindRightPosition($fp, $fsize, $oldtime, $newtime, array("ftpusertraffic__pureftp", "getTimeFromString"));
     if ($ret < 0) {
         dprint("Could not find position\n");
         return null;
     }
     $total = 0;
     while (!feof($fp)) {
         $string = fgets($fp);
         if (csa($string, $domainname)) {
             $total += self::LogConvertString($string);
         }
         if (self::getTimeFromString($string) > $newtime) {
             break;
         }
     }
     $total = $total / (1024 * 1024);
     $total = round($total, 1);
     fclose($fp);
     dprint("Returning Total From OUT SIDE This File: for {$domainname} {$total} \n");
     return $total;
 }
Exemple #2
0
 static function convertfile($oldtime, $newtime)
 {
     global $gbl, $sgbl, $login, $ghtml;
     $file = '/var/log/kloxo/maillog';
     if (!lxfile_real($file)) {
         return null;
     }
     $fp = fopen($file, "r");
     $fsize = filesize($file);
     $ret = FindRightPosition($fp, $fsize, $oldtime, $newtime, array("mailtraffic", "getTimeFromOriginalQmailString"));
     if ($ret < 0) {
         dprint("Could not find position\n");
         return;
     }
     $totstring = null;
     $count = 0;
     while (!feof($fp)) {
         $count++;
         if ($count > 1000000) {
             break;
         }
         $string = fgets($fp);
         $totstring .= $string;
         if (self::getTimeFromOriginalQmailString($string) > $newtime) {
             break;
         }
     }
     fclose($fp);
     $convertfile = tempnam("/tmp/", "mail_log");
     $convertfile_source = tempnam("/tmp/", "mail_log_source");
     lfile_put_contents($convertfile_source, $totstring);
     system("perl {$sgbl->__path_kloxo_httpd_root}/awstats/tools/maillogconvert.pl standard < {$convertfile_source} > {$convertfile}");
     lunlink($convertfile_source);
     return $convertfile;
 }
 static function readSingleMail($name)
 {
     $ret['message'] = lxshell_output("__path_program_root/bin/misc/qmHandle", "-m{$name}");
     $oldtime = time() - 7200;
     $newtime = time() - 500;
     $fp = fopen("/var/log/kloxo/maillog", "r");
     $fsize = lxfile_size("/var/log/kloxo/maillog");
     $ot = date("Y-m-d:H-i");
     dprint("Start time: {$ot}\n");
     $res = FindRightPosition($fp, $fsize, $oldtime, $newtime, array("mailtraffic", "getTimeFromOriginalQmailString"));
     if ($res < 0) {
         $ret['log'] = null;
         return $ret;
     }
     //$s = fgets($fp);
     dprint("here {$s}\n");
     takeToStartOfLine($fp);
     takeToStartOfLine($fp);
     //$s = fgets($fp);
     dprint("here {$s}\n");
     $delivery = null;
     while (!feof($fp)) {
         $s = fgets($fp);
         if (!$delivery) {
             if (csa($s, "starting delivery") && csa($s, "msg {$name}")) {
                 $delivery = preg_replace("/.*delivery ([^:]*):.*/", "\$1", $s);
                 $delivery = trim($delivery);
                 dprint("Deliver num: {$delivery}*\n");
                 continue;
             }
         } else {
             dprint("{$s}\n");
             if (csa($s, "delivery {$delivery}:")) {
                 dprint("{$s}\n");
                 $ret['log'] = $s;
                 break;
             }
         }
     }
     return $ret;
 }
 static function getEachfileqouta($file, $iface, $oldtime, $newtime)
 {
     $fp = @fopen($file, "r");
     print "Opening File name is :{$file}\n";
     error_reporting(0);
     if (!$fp) {
         return 0;
     }
     $fsize = filesize($file);
     print "Here U are in Mail log file Size is:{$fsize}\n";
     if ($fsize <= 5) {
         return 0;
     }
     $total = 0;
     $ret = FindRightPosition($fp, $fsize, $oldtime, $newtime, array("vpstraffic__xen", "getTimeFromString"));
     if ($ret < 0) {
         dprint("Could not find position\n");
         return;
     }
     $total = 0;
     while (!feof($fp)) {
         $string = fgets($fp);
         if (csa($string, $iface)) {
             //$total += self::LogConvertString($string);
             $incoming += self::getFromString($string, 4);
             $outgoing += self::getFromString($string, 5);
             $total += self::getFromString($string, 5);
             $total += self::getFromString($string, 4);
         }
         if (self::getTimeFromString($string) > $newtime) {
             break;
         }
     }
     $incoming = self::roundupValue($incoming);
     $outgoing = self::roundupValue($outgoing);
     $total = self::roundupValue($total);
     fclose($fp);
     dprint("Returning Total From OUT SIDE This File: for {$iface} {$total} \n");
     return array('total' => $total, 'incoming' => $incoming, 'outgoing' => $outgoing);
 }
Exemple #5
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;
 }
Exemple #6
0
function lxguard_main($clearflag = false)
{
    include_once "htmllib/lib/lxguardincludelib.php";
    lxfile_mkdir("__path_home_root/lxguard");
    $lxgpath = "__path_home_root/lxguard";
    $file = "/var/log/secure";
    $fp = fopen($file, "r");
    $fsize = filesize($file);
    $newtime = time();
    $oldtime = time() - 60 * 10;
    $rmt = lfile_get_unserialize("{$lxgpath}/hitlist.info");
    if ($rmt) {
        $oldtime = max((int) $oldtime, (int) $rmt->ddate);
    }
    $ret = FindRightPosition($fp, $fsize, $oldtime, $newtime, "getTimeFromSysLogString");
    $list = lfile_get_unserialize("{$lxgpath}/access.info");
    if ($ret) {
        parse_sshd_and_ftpd($fp, $list);
        lfile_put_serialize("{$lxgpath}/access.info", $list);
    }
    get_total($list, $total);
    //dprintr($list['192.168.1.11']);
    dprintr($total);
    $deny = get_deny_list($total);
    $hdn = lfile_get_unserialize("{$lxgpath}/hostdeny.info");
    $deny = lx_array_merge(array($deny, $hdn));
    $string = null;
    foreach ($deny as $k => $v) {
        if (csb($k, "127")) {
            continue;
        }
        $string .= "ALL : {$k}\n";
    }
    dprint($string);
    $stlist[] = "###Start Program Hostdeny config Area";
    $stlist[] = "###Start Lxdmin Area";
    $stlist[] = "###Start Kloxo Area";
    $stlist[] = "###Start Lxadmin Area";
    $endlist[] = "###End Program HostDeny config Area";
    $endlist[] = "###End Kloxo Area";
    $endlist[] = "###End Lxadmin Area";
    $startstring = $stlist[0];
    $endstring = $endlist[0];
    file_put_between_comments($stlist, $endlist, $startstring, $endstring, "/etc/hosts.deny", $string);
    if ($clearflag) {
        lxfile_rm("{$lxgpath}/access.info");
        $rmt = new Remote();
        $rmt->hl = $total;
        $rmt->ddate = time();
        lfile_put_serialize("{$lxgpath}/hitlist.info", $rmt);
    }
    return $list;
}
Exemple #7
0
 static function getEachwebfilequota($file, $oldtime, $newtime)
 {
     global $gbl, $sgbl, $login, $ghtml;
     $fp = @lfopen($file, "r");
     $total = 0;
     print "\n{$file}: " . @date('Y-m-d-H', $oldtime) . " " . @date('Y-m-d-H', $newtime) . "\n";
     if (!$fp) {
         print "File Does Not Exist:returning Zero";
         return 0;
     }
     $fsize = lfilesize($file);
     if ($fsize <= 10) {
         print "File Size is Less Than Zero and Returning Zero:\n";
         return 0;
     }
     print "File Size is :{$fsize}\n\n\n";
     $ret = FindRightPosition($fp, $fsize, $oldtime, $newtime, array("webtraffic", "getTimeFromString"));
     if ($ret < 0) {
         return;
     }
     print "Current Position " . ftell($fp) / $fsize * 100 . "\n";
     $total = 0;
     $count = 0;
     $break = 1000;
     while (!feof($fp)) {
         $count++;
         $line = fgets($fp);
         list($time, $size) = self::apacheLogConvertString($line);
         if ($time > $newtime) {
             break;
         }
         $total += $size;
         if ($count > 100000) {
             $break = 10000;
         }
         if (!($count % $break)) {
             print "Count {$count} {$newtime} {$time} {$total} {$size}\n";
         }
     }
     print "{$count} lines actually processed in {$file}\n";
     $total = $total / (1024 * 1024);
     $total = round($total, 1);
     fclose($fp);
     print "Returning Total From OUT SIDE This File: {$total} \n";
     return $total;
 }
 static function getEachfileqouta($file, $vpsid, $oldtime, $newtime)
 {
     $fp = @fopen($file, "r");
     print "Opening File name is :{$file}\n";
     error_reporting(0);
     if (!$fp) {
         return 0;
     }
     $fsize = filesize($file);
     print "Here U are in Mail log file Size is:{$fsize}\n";
     if ($fsize <= 5) {
         return 0;
     }
     $total = 0;
     $ret = FindRightPosition($fp, $fsize, $oldtime, $newtime, array("vpstraffic__openvz", "getTimeFromString"));
     if ($ret < 0) {
         dprint("Could not find position\n");
         return;
     }
     $total = 0;
     while (!feof($fp)) {
         $string = fgets($fp);
         //The space at the end is important. Otherwise 200 will match 2000.
         if (csa($string, "openvz-{$vpsid} ")) {
             $t = self::LogConvertString($string);
             if ($t > 10000014985) {
                 continue;
             }
             $total += self::LogConvertString($string);
             $incoming += self::getFromString($string, 4);
             $outgoing += self::getFromString($string, 5);
         }
         if (self::getTimeFromString($string) > $newtime) {
             break;
         }
     }
     $incoming = self::roundupValue($incoming);
     $outgoing = self::roundupValue($outgoing);
     $total = self::roundupValue($total);
     fclose($fp);
     dprint("Returning Total From OUT SIDE This File: for {$vpsid} {$total} {$incoming} {$outgoing} \n");
     return array('total' => $total, 'incoming' => $incoming, 'outgoing' => $outgoing);
 }