Esempio n. 1
0
function apache_get_config($type, $file, $software, $counter)
{
    $file_json_encoded = json_encode($file);
    /////////////////////////////////////////////////////////
    // Apache error files are not the same on 2.2 and 2.4 //
    /////////////////////////////////////////////////////////
    if ($type == 'error') {
        // Write a line of log and try to guess the format
        $remain = 10;
        $test = 0;
        error_log('Pimp my Log has been successfully configured with Apache');
        foreach (LogParser::getLinesFromBottom($file, 10) as $line) {
            $test = @preg_match('|^\\[(.*) (.*) (.*) (.*):(.*):(.*)\\.(.*) (.*)\\] \\[(.*):(.*)\\] \\[pid (.*)\\] .*\\[client (.*):(.*)\\] (.*)(, referer: (.*))*$|U', $line);
            if ($test === 1) {
                break;
            }
            $remain--;
            if ($remain <= 0) {
                break;
            }
        }
        /////////////////////
        // Error 2.4 style //
        /////////////////////
        if ($test === 1) {
            return <<<EOF
\t\t"{$software}{$counter}": {
\t\t\t"display" : "Apache Error #{$counter}",
\t\t\t"path"    : {$file_json_encoded},
\t\t\t"refresh" : 5,
\t\t\t"max"     : 10,
\t\t\t"notify"  : true,
\t\t\t"format"  : {
\t\t\t\t"type"         : "HTTPD 2.4",
\t\t\t\t"regex"        : "|^\\\\[(.*) (.*) (.*) (.*):(.*):(.*)\\\\.(.*) (.*)\\\\] \\\\[(.*):(.*)\\\\] \\\\[pid (.*)\\\\] .*\\\\[client (.*):(.*)\\\\] (.*)(, referer: (.*))*\$|U",
\t\t\t\t"export_title" : "Log",
\t\t\t\t"match"        : {
\t\t\t\t\t"Date"    : {
\t\t\t\t\t\t"M" : 2,
\t\t\t\t\t\t"d" : 3,
\t\t\t\t\t\t"H" : 4,
\t\t\t\t\t\t"i" : 5,
\t\t\t\t\t\t"s" : 6,
\t\t\t\t\t\t"Y" : 8
\t\t\t\t\t},
\t\t\t\t\t"IP"       : 12,
\t\t\t\t\t"Log"      : 14,
\t\t\t\t\t"Severity" : 10,
\t\t\t\t\t"Referer"  : 16
\t\t\t\t},
\t\t\t\t"types": {
\t\t\t\t\t"Date"     : "date:H:i:s",
\t\t\t\t\t"IP"       : "ip:http",
\t\t\t\t\t"Log"      : "preformatted",
\t\t\t\t\t"Severity" : "badge:severity",
\t\t\t\t\t"Referer"  : "link"
\t\t\t\t},
\t\t\t\t"exclude": {
\t\t\t\t\t"Log": ["\\/PHP Stack trace:\\/", "\\/PHP *[0-9]*\\\\. \\/"]
\t\t\t\t}
\t\t\t}
\t\t}
EOF;
        } else {
            return <<<EOF
\t\t"{$software}{$counter}": {
\t\t\t"display" : "Apache Error #{$counter}",
\t\t\t"path"    : {$file_json_encoded},
\t\t\t"refresh" : 5,
\t\t\t"max"     : 10,
\t\t\t"notify"  : true,
\t\t\t"format"  : {
\t\t\t\t"type"         : "HTTPD 2.2",
\t\t\t\t"regex"        : "|^\\\\[(.*)\\\\] \\\\[(.*)\\\\] (\\\\[client (.*)\\\\] )*((?!\\\\[client ).*)(, referer: (.*))*\$|U",
\t\t\t\t"export_title" : "Log",
\t\t\t\t"match"        : {
\t\t\t\t\t"Date"     : 1,
\t\t\t\t\t"IP"       : 4,
\t\t\t\t\t"Log"      : 5,
\t\t\t\t\t"Severity" : 2,
\t\t\t\t\t"Referer"  : 7
\t\t\t\t},
\t\t\t\t"types": {
\t\t\t\t\t"Date"     : "date:H:i:s",
\t\t\t\t\t"IP"       : "ip:http",
\t\t\t\t\t"Log"      : "preformatted",
\t\t\t\t\t"Severity" : "badge:severity",
\t\t\t\t\t"Referer"  : "link"
\t\t\t\t},
\t\t\t\t"exclude": {
\t\t\t\t\t"Log": ["\\/PHP Stack trace:\\/", "\\/PHP *[0-9]*\\\\. \\/"]
\t\t\t\t}
\t\t\t}
\t\t}
EOF;
        }
    } else {
        if ($type == 'access') {
            return <<<EOF
\t\t"{$software}{$counter}": {
\t\t\t"display" : "Apache Access #{$counter}",
\t\t\t"path"    : {$file_json_encoded},
\t\t\t"refresh" : 0,
\t\t\t"max"     : 10,
\t\t\t"notify"  : false,
\t\t\t"format"  : {
\t\t\t\t"type"         : "NCSA",
\t\t\t\t"regex"        : "|^((\\\\S*) )*(\\\\S*) (\\\\S*) (\\\\S*) \\\\[(.*)\\\\] \\"(\\\\S*) (.*) (\\\\S*)\\" ([0-9]*) (.*)( \\"(.*)\\" \\"(.*)\\"( [0-9]*/([0-9]*))*)*\$|U",
\t\t\t\t"export_title" : "URL",
\t\t\t\t"match"        : {
\t\t\t\t\t"Date"    : 6,
\t\t\t\t\t"IP"      : 3,
\t\t\t\t\t"CMD"     : 7,
\t\t\t\t\t"URL"     : 8,
\t\t\t\t\t"Code"    : 10,
\t\t\t\t\t"Size"    : 11,
\t\t\t\t\t"Referer" : 13,
\t\t\t\t\t"UA"      : 14,
\t\t\t\t\t"User"    : 5,
\t\t\t\t\t"\\u03bcs" : 16
\t\t\t\t},
\t\t\t\t"types": {
\t\t\t\t\t"Date"    : "date:H:i:s",
\t\t\t\t\t"IP"      : "ip:geo",
\t\t\t\t\t"URL"     : "txt",
\t\t\t\t\t"Code"    : "badge:http",
\t\t\t\t\t"Size"    : "numeral:0b",
\t\t\t\t\t"Referer" : "link",
\t\t\t\t\t"UA"      : "ua:{os.name} {os.version} | {browser.name} {browser.version}\\/100",
\t\t\t\t\t"\\u03bcs" : "numeral:0,0"
\t\t\t\t},
\t\t\t\t"exclude": {
\t\t\t\t\t"URL": ["\\/favicon.ico\\/", "\\/\\\\.pml\\\\.php.*\$\\/"],
\t\t\t\t\t"CMD": ["\\/OPTIONS\\/"]
\t\t\t\t}
\t\t\t}
\t\t}
EOF;
        }
    }
}