function ScanFiles()
{
    $GLOBALS["UUIDS"] = array();
    $pids = $GLOBALS["CLASS_UNIX"]->PIDOF_PATTERN_ALL(basename(__FILE__));
    $MaxInstances = round($GLOBALS["LogFileDeamonMaxInstances"] * 2);
    $GLOBALS["PREFIX_LOGSTATS"] = "Instances " . count($pids) . "/{$MaxInstances}";
    if (count($pids) > $MaxInstances) {
        events("Running instances:" . count($pids) . " " . @implode(",", $pids) . " Too many instances agains {$GLOBALS["LogFileDeamonMaxInstances"]}*1.7={$MaxInstances} SKIP TASK");
        while (list($xpid, $ligne) = each($pids)) {
            $cmdline = @file_get_contents("/proc/{$xpid}/cmdline");
            events("Running instance:{$xpid} {$cmdline}");
        }
        return;
    }
    $Files = $GLOBALS["CLASS_UNIX"]->DirFiles("/home/artica/squid/META_EVENTS_QUEUE");
    $MAX = count($Files);
    if ($GLOBALS["VERBOSE"]) {
        echo "{$MAX} files\n";
    }
    $c = 0;
    while (list($filename, $none) = each($Files)) {
        $path = "/home/artica/squid/META_EVENTS_QUEUE/{$filename}";
        $LOCK_FILE = "/home/artica/squid/META_EVENTS_QUEUE/{$filename}.LCK";
        $Time = $GLOBALS["CLASS_UNIX"]->file_time_sec($path);
        $c++;
        if (preg_match("#\\.LCK\$#", $filename)) {
            $filenameB = str_replace(".LCK", "", $filename);
            if (!is_file("/home/artica/squid/META_EVENTS_QUEUE/{$filenameB}")) {
                @unlink($path);
            }
            continue;
        }
        if (isLocked($path)) {
            continue;
        }
        @file_put_contents($LOCK_FILE, getmypid());
        meta_events("PARSING {$path}");
        if (!ParseFile($path)) {
            meta_events("*** PARSE {$path} FAILED ****");
            if ($GLOBALS["VERBOSE"]) {
                echo "*** PARSE {$path} FAILED ****\n";
            }
            @unlink($LOCK_FILE);
            continue;
        }
        @unlink($path);
        @unlink($LOCK_FILE);
    }
    meta_events(count($GLOBALS["UUIDS"]) . " uuid to analyze");
    while (list($uuid, $rows) = each($GLOBALS["UUIDS"])) {
        hourly_to_daily($uuid);
        daily_to_monthly($uuid);
    }
}
Ejemplo n.º 2
0
 public function submit()
 {
     $user = new User_model();
     if (!$user->loadPropertiesFromPrimaryKey($_SESSION['UserID'])) {
         redirect('Login/logout');
     }
     if (!$user->isAdmin()) {
         header("Content-type: text/plain", true, 401);
         echo "Unauthorized access";
         return;
     }
     // Check $_FILES['upfile']['error'] value.
     switch ($_FILES['boss_file']['error']) {
         case UPLOAD_ERR_OK:
             break;
         case UPLOAD_ERR_NO_FILE:
             header("Content-type: text/plain", true, 400);
             echo "No file sent";
             return;
         case UPLOAD_ERR_INI_SIZE:
         case UPLOAD_ERR_FORM_SIZE:
             header("Content-type: text/plain", true, 400);
             echo "Exceeded file size limit";
             return;
         default:
             header("Content-type: text/plain", true, 500);
             echo "Unknown error occurred";
             return;
     }
     // You should also check filesize here.
     if ($_FILES['boss_file']['size'] > self::MAX_FILE_SIZE) {
         header("Content-type: text/plain", true, 400);
         echo "Exceeded file size limit";
         return;
     }
     $file_name = hash("md5", time() . $_FILES['boss_file']['tmp_name']);
     $file_path = self::UPLOAD_FILE_DIR . "/" . $file_name . ".txt";
     if (!move_uploaded_file($_FILES['boss_file']['tmp_name'], $file_path)) {
         header("Content-type: text/plain", true, 500);
         echo "Failed to move uploaded file";
         return;
     }
     include_once 'application/libraries/boss_import/ParserServerTest.php';
     $result = ParseFile($file_path);
     // In future, possibly check to make sure file was successfully deleted here
     unlink($file_path);
     if ($result == null) {
         header("Content-type: text/plain", true, 200);
         echo "Success";
     } else {
         header("Content-type: text/plain", true, 400);
         echo $result;
     }
 }
function parseQueue()
{
    $unix = new unix();
    $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid";
    $pid = $unix->get_pid_from_file($pidfile);
    $sock = new sockets();
    if ($unix->process_exists($pid, basename(__FILE__))) {
        $pidTime = $unix->PROCCESS_TIME_MIN($pid);
        events("Already process PID: {$pid} running since {$pidTime} minutes", __FUNCTION__, __FILE__, __LINE__, "postfix-stats");
        return;
    }
    @file_put_contents($pidfile, getmypid());
    if (system_is_overloaded(basename(__FILE__))) {
        events("Overloaded system, aborting", __FUNCTION__, __FILE__, __LINE__, "postfix-stats");
        return;
    }
    $EnableArticaSMTPStatistics = $sock->GET_INFO("EnableArticaSMTPStatistics");
    if (!is_numeric($EnableArticaSMTPStatistics)) {
        $EnableArticaSMTPStatistics = 0;
    }
    $directory = "/var/log/artica-mail";
    if (!is_dir($directory)) {
        return;
    }
    if (!($handle = @opendir($directory))) {
        return;
    }
    $q = new mysql_postfix_builder();
    $q->CheckTables();
    events("open {$directory}");
    while (false !== ($filename = readdir($handle))) {
        if ($EnableArticaSMTPStatistics == 0) {
            @unlink("{$directory}/{$filename}");
            continue;
        }
        if (!preg_match("#(.+?)\\.[0-9]+\\.aws#", $filename, $re)) {
            continue;
        }
        $instancename = $re[1];
        ParseFile("{$directory}/{$filename}");
        if (system_is_overloaded(basename(__FILE__))) {
            system_admin_events("Overloaded system, aborting", __FUNCTION__, __FILE__, __LINE__, "postfix-stats");
            return;
        }
    }
}
Ejemplo n.º 4
0
        $Sort[$i] = $Data[$i];
    }
}
rsort($Sort);
for ($i = 0; $i < count($Sort); $i++) {
    $InData = GetPage($Sort[$i]);
    if ($InData["priority"] == "high") {
        $Sorted[] = $Sort[$i];
    }
}
for ($i = 0; $i < count($Sort); $i++) {
    $InData = GetPage($Sort[$i]);
    if ($InData["priority"] == "standard") {
        $Sorted[] = $Sort[$i];
    }
}
for ($i = 0; $i < count($Sorted); $i++) {
    $InData = GetPage($Sorted[$i]);
    $Pagetext .= "<h2>{$InData["title"]}<span>{$InData["date"]} {$InData["time"]}</span></h2>\n";
    $Line = explode("\n", rtrim(file_get_contents("page/{$Sorted[$i]}/{$InData["filename"]}"), "\n"));
    if (count($Line) < 5) {
        $cnt = count($Line);
    } else {
        $cnt = 5;
    }
    for ($s = 0; $s < $cnt; $s++) {
        $Pagetext .= ParseFile($InData["type"], $Line[$s] . "\n");
    }
    $Pagetext .= "<br>\n";
    $Pagetext .= "<a href=\"index.php?q={$Sorted[$i]}\">Read more...</a>";
}
Ejemplo n.º 5
0
         }
     }
     foreach ($items as $itemno => $amount) {
         if (strlen($itemno) != 4) {
             continue;
         }
         print $itemno . " : " . $amount . "(Ave:" . $amount / $userAmount . ")<br>";
     }
 } else {
     if ($_POST["UserIpShow"]) {
         include GLOBAL_PHP;
         $userFileList = glob(USER . "*");
         $ipList = array();
         foreach ($userFileList as $user) {
             $file = $user . "/data.dat";
             if (!($data = ParseFile($file))) {
                 continue;
             }
             $html .= "<tr><td>" . $data["id"] . "</td><td>" . $data["name"] . "</td><td>" . $data["ip"] . "</td></tr>\n";
             $ipList[$data["ip"] ? $data["ip"] : "*UnKnown"]++;
         }
         // 重複リスト
         print "<p>IP重複リスト</p>\n";
         foreach ($ipList as $ip => $amount) {
             if (1 < $amount) {
                 print "{$ip} : {$amount}<br>\n";
             }
         }
         print "<table border=\"1\">\n";
         print $tags = "<tr><td>ID</td><td>NAME</td><td>IP</td></tr>\n";
         print $html;
Ejemplo n.º 6
0
include "./class/class.char.php";
include "./class/global.php";
$folder = glob("./user/*");
//print("<pre>".print_r($folder,1)."</pre>");
foreach ($folder as $val) {
    $UserFile = glob($val . "/*.dat");
    foreach ($UserFile as $FileName) {
        $file = basename($FileName, ".dat");
        if (is_numeric($file)) {
            $chars[] = $FileName;
        }
    }
    //print("<pre>".print_r($UserFile,1)."</pre>");
}
print '<table border="0" cellspacing="1"><tbody>';
foreach ($chars as $file) {
    $char = new char(ParseFile($file));
    print "<tr><td>";
    $char->ShowImage();
    print "</td><td>";
    print $char->Name(bold);
    print "</td><td>";
    print "Lv:" . $char->level;
    print "</td><td>";
    print "Str:{$char->str}<br />Int:{$char->int}<br />Dex:{$char->dex}<br />Spd:{$char->spd}";
    print "</td></tr>";
}
print "</tbody></table>";
?>
</body>
</html>
Ejemplo n.º 7
0
function parse_logs()
{
    $unix = new unix();
    $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid";
    $pidTime = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".time";
    if (!$GLOBALS["VERBOSE"]) {
        if ($unix->file_time_min($pidTime) < 45) {
            return;
        }
    }
    $pid = $unix->get_pid_from_file($pidfile);
    if ($unix->process_exists($pid, basename(__FILE__))) {
        $time = $unix->PROCCESS_TIME_MIN($pid);
        return;
    }
    @file_put_contents($pidfile, getmypid());
    @unlink($pidTime);
    @file_put_contents($pidTime, time());
    $sock = new sockets();
    $EnableNginxStats = $sock->GET_INFO("EnableNginxStats");
    if (!is_numeric($EnableNginxStats)) {
        $EnableNginxStats = 0;
    }
    if ($EnableNginxStats == 0) {
        return;
    }
    if (system_is_overloaded(basename(__FILE__))) {
        events("Overloaded system: {$GLOBALS["SYSTEM_INTERNAL_LOAD"]} aborting", __FUNCTION__, __LINE__);
        return;
    }
    $nice = EXEC_NICE();
    $sock = new sockets();
    $kill = $unix->find_program("kill");
    $NginxWorkLogsDir = $sock->GET_INFO("NginxWorkLogsDir");
    if ($NginxWorkLogsDir == null) {
        $NginxWorkLogsDir = "/home/nginx/logsWork";
    }
    $sys = new mysql_storelogs();
    $files = $unix->DirFiles($NginxWorkLogsDir, "-([0-9\\-]+)\\.log");
    while (list($filename, $line) = each($files)) {
        if (!preg_match("#^(.+?)-[0-9]+-[0-9]+-[0-9]+-[0-9]+\\.log\$#", $filename, $re)) {
            if ($GLOBALS["VERBOSE"]) {
                echo "{$filename}, skip\n";
            }
            continue;
        }
        $servername = $re[1];
        $fullpath = "{$NginxWorkLogsDir}/{$filename}";
        ParseFile($servername, $fullpath);
    }
    $php = $unix->LOCATE_PHP5_BIN();
    $nohup = $unix->find_program("nohup");
    shell_exec("{$nohup} {$php} " . __FILE__ . " --hosts >/dev/null 2>&1 &");
    shell_exec("{$nohup} {$php} " . dirname(__FILE__) . "/exec.nginx-stats-day.php >/dev/null 2>&1 &");
}