コード例 #1
0
ファイル: response.php プロジェクト: marcbredt/kaese
//header('Transfer-Encoding: chunked');
// for IE's XDomainRequest instead of XMLHttpRequest
header('Access-Control-Allow-Origin: *');
// disable compression to immediately push data
@apache_setenv('no-gzip', 1);
@ini_set('zlib.output_compression', 0);
@ini_set('implicit_flush', 1);
// disable output buffering
while (@ob_end_flush()) {
}
ini_set('implicit_flush', 1);
ob_implicit_flush(1);
// for chrome to start processing progress events
echo str_repeat(' ', 2048);
//ob_flush(); flush();
$fl = new \core\util\log\FileLogger("response.php", "../response.log");
$fl->logge("query=%", array($_SERVER['QUERY_STRING']));
if (strncmp($_GET['action'], "read", 4) == 0) {
    // if the iptables logfile should be analyzed
    if (isset($_GET['stats_type']) && strncmp($_GET['stats_type'], "logfile", 7) == 0) {
        $fsr = new FileStreamReader();
        $fl->logge("streamer created");
        $fsr->read();
        $fl->logge("logfile state ended");
        // if the iptables command should be used
    } else {
        if (isset($_GET['stats_type']) && strncmp($_GET['stats_type'], "iptables", 7) == 0) {
            // check the command prefix
            //$cmd = "sudo /sbin/iptables -t filter -nvx --list input-dns"; // dummy
            $xd = null;
            $cmd = null;
コード例 #2
0
 /**
  * Tests the exceptions used by this class.
  * @small
  */
 public function testExceptions()
 {
     // get a logger instance pointing to the default logging file
     $fl = new \core\util\log\FileLogger("XMLDocumentTest");
     // XMLNotValidException
     // xml mimetype error
     $catched = false;
     $tf = tempnam("/tmp", "PHP");
     $tfh = fopen($tf, "w+");
     fwrite($tfh, "<root />");
     // without <?xml>-head mimetype is not application/xml
     fseek($tfh, 0);
     try {
         $this->xd = new \core\util\xml\XMLDocument($tf, "src/tests/core/util/xml/files/dtd/module-register.dtd");
     } catch (\core\exception\xml\XMLNotValidException $xnve) {
         $catched = true;
     }
     $this->xd = null;
     fclose($tfh);
     unlink($tf);
     if (!$catched) {
         // fail after temp file cleanage
         $this->fail('Failed asserting that exception of type ' . '"\\core\\exception\\xml\\XMLNotValidException [0]" is thrown.');
     }
     $line = $fl->getLastLine();
     $this->assertRegExp('/.* XMLDocument \\[error\\] core\\\\util\\\\log\\\\FileLogger core\\\\exception\\\\xml\\\\XMLNotValidException \\[0\\]/', $line);
     // xml file = null
     $catched = false;
     try {
         $this->xd = new \core\util\xml\XMLDocument(null, "src/tests/core/util/xml/files/dtd/module-register.dtd");
     } catch (\core\exception\xml\XMLNotValidException $xnve) {
         $catched = true;
     }
     $this->xd = null;
     if (!$catched) {
         // fail after temp file cleanage
         $this->fail('Failed asserting that exception of type ' . '"\\core\\exception\\xml\\XMLNotValidException [0]" is thrown.');
     }
     $line = $fl->getLastLine();
     $this->assertRegExp('/.* XMLDocument \\[error\\] core\\\\util\\\\log\\\\FileLogger core\\\\exception\\\\xml\\\\XMLNotValidException \\[0\\]/', $line);
     // xml file does not exist
     $catched = false;
     try {
         $this->xd = new \core\util\xml\XMLDocument("src/tests/core/util/xml/files/xml/" . bin2hex(mcrypt_create_iv(32, MCRYPT_DEV_URANDOM)) . ".xml", "src/tests/core/util/xml/files/dtd/module-register.dtd");
     } catch (\core\exception\xml\XMLNotValidException $xnve) {
         $catched = true;
     }
     $this->xd = null;
     if (!$catched) {
         // fail after temp file cleanage
         $this->fail('Failed asserting that exception of type ' . '"\\core\\exception\\xml\\XMLNotValidException [0]" is thrown.');
     }
     $line = $fl->getLastLine();
     $this->assertRegExp('/.* XMLDocument \\[error\\] core\\\\util\\\\log\\\\FileLogger core\\\\exception\\\\xml\\\\XMLNotValidException \\[0\\]/', $line);
     // validation failure
     $catched = false;
     $tf = tempnam("/tmp", "PHP");
     $tfh = fopen($tf, "w+");
     fwrite($tfh, "<!ELEMENT root EMPTY>");
     fseek($tfh, 0);
     try {
         $this->xd = new \core\util\xml\XMLDocument("src/tests/core/util/xml/files/xml/module-register.xml", $tf);
     } catch (\core\exception\xml\XMLNotValidException $xnve) {
         $catched = true;
     }
     $this->xd = null;
     fclose($tfh);
     unlink($tf);
     // fail after temp file cleanage
     if (!$catched) {
         $this->fail('Failed asserting that exception of type ' . '"\\core\\exception\\xml\\XMLNotValidException [2]" is thrown.');
     }
     $line = $fl->getLastLine();
     $this->assertRegExp('/.* XMLDocument \\[error\\] core\\\\util\\\\log\\\\FileLogger core\\\\exception\\\\xml\\\\XMLNotValidException \\[2\\]/', $line);
     // XMLNoValidDTDException
     $catched = false;
     try {
         $this->xd = new \core\util\xml\XMLDocument("src/tests/core/util/xml/files/xml/module-register.xml", "src/tests/core/util/xml/files/dtd/" . bin2hex(mcrypt_create_iv(32, MCRYPT_DEV_URANDOM)) . ".dtd");
     } catch (\core\exception\xml\XMLNoValidDTDException $xnvde) {
         $catched = true;
     }
     $this->xd = null;
     if (!$catched) {
         $this->fail('Failed asserting that exception of type ' . '"\\core\\exception\\xml\\XMLNoValidDTDException" is thrown.');
     }
     $line = $fl->getLastLine();
     $this->assertRegExp('/.* XMLDocument \\[error\\] core\\\\util\\\\log\\\\FileLogger core\\\\exception\\\\xml\\\\XMLNoValidDTDException \\[0\\]/', $line);
     // InvalidXPathExpression
     // query = null
     $catched = false;
     try {
         $this->xd = new \core\util\xml\XMLDocument("src/tests/core/util/xml/files/xml/module-register.xml", "src/tests/core/util/xml/files/dtd/module-register.dtd");
         $this->xd->xpath(null);
     } catch (\core\exception\xml\xpath\InvalidXPathExpressionException $ixee) {
         $catched = true;
     }
     $this->xd = null;
     if (!$catched) {
         $this->fail('Failed asserting that exception of type ' . '"\\core\\exception\\xml\\xpath\\InvalidXPathExpressionException" is thrown.');
     }
     $line = $fl->getLastLine();
     $this->assertRegExp('/.* XMLDocument \\[error\\] core\\\\util\\\\log\\\\FileLogger core\\\\exception\\\\xml\\\\xpath\\\\InvalidXPathExpressionException \\[1\\]: .*/', $line);
     // query empty
     $catched = false;
     try {
         $this->xd = new \core\util\xml\XMLDocument("src/tests/core/util/xml/files/xml/module-register.xml", "src/tests/core/util/xml/files/dtd/module-register.dtd");
         $this->xd->xpath('');
     } catch (\core\exception\xml\xpath\InvalidXPathExpressionException $ixee) {
         $catched = true;
     }
     $this->xd = null;
     if (!$catched) {
         $this->fail('Failed asserting that exception of type ' . '"\\core\\exception\\xml\\xpath\\InvalidXPathExpressionException" is thrown.');
     }
     $line = $fl->getLastLine();
     $this->assertRegExp('/.* XMLDocument \\[error\\] core\\\\util\\\\log\\\\FileLogger core\\\\exception\\\\xml\\\\xpath\\\\InvalidXPathExpressionException \\[2\\]: .*/', $line);
     // a malformed query
     $catched = false;
     try {
         $this->xd = new \core\util\xml\XMLDocument("src/tests/core/util/xml/files/xml/module-register.xml", "src/tests/core/util/xml/files/dtd/module-register.dtd");
         $this->xd->xpath(')');
     } catch (\core\exception\xml\xpath\InvalidXPathExpressionException $ixee) {
         $catched = true;
     }
     $this->xd = null;
     if (!$catched) {
         $this->fail('Failed asserting that exception of type ' . '"\\core\\exception\\xml\\xpath\\InvalidXPathExpressionException" is thrown.');
     }
     $line = $fl->getLastLine();
     $this->assertRegExp('/.* XMLDocument \\[error\\] core\\\\util\\\\log\\\\FileLogger core\\\\exception\\\\xml\\\\xpath\\\\InvalidXPathExpressionException \\[0\\]: .*/', $line);
     // UnresolvedXPathException
     // NOTE: as comments can be ignored, use the DOMComment class
     //       to cause such an exception
     $catched = false;
     try {
         $this->xd = new \core\util\xml\XMLDocument("src/tests/core/util/xml/files/xml/module-register.xml", "src/tests/core/util/xml/files/dtd/module-register.dtd");
         $this->xd->xpath('//comment()');
     } catch (\core\exception\xml\xpath\UnresolvedXPathException $uxe) {
         $catched = true;
     }
     $this->xd = NULL;
     if (!$catched) {
         $this->fail('Failed asserting that exception of type ' . '"\\core\\exception\\xml\\xpath\\UnresolvedXPathException" is thrown.');
     }
     $line = $fl->getLastLine();
     $this->assertRegExp('/.* XMLDocument \\[error\\] core\\\\util\\\\log\\\\FileLogger core\\\\exception\\\\xml\\\\xpath\\\\UnresolvedXPathException \\[0\\]: .*/', $line);
     // NOTE: the xpath function now contains a second parameter to
     //       test UnresolvedXPathException to be throuwn for unrecognized
     //       typed results of DOMXPath::evaluate
     //       e.g. null is a type (returned by an xpath expression) that
     //       is not necessary to capture, like DOMComment to
     //       fulfill tests on all lines (see 218/$unresolved in xpath)
     $catched = false;
     try {
         $this->xd = new \core\util\xml\XMLDocument("src/tests/core/util/xml/files/xml/module-register.xml", "src/tests/core/util/xml/files/dtd/module-register.dtd");
         $this->xd->xpath("/", true);
     } catch (\core\exception\xml\xpath\UnresolvedXPathException $uxe) {
         $catched = true;
     }
     $this->xd = NULL;
     if (!$catched) {
         $this->fail('Failed asserting that exception of type ' . '"\\core\\exception\\xml\\xpath\\UnresolvedXPathException" is thrown.');
     }
     $line = $fl->getLastLine();
     $this->assertRegExp('/.* XMLDocument \\[error\\] core\\\\util\\\\log\\\\FileLogger core\\\\exception\\\\xml\\\\xpath\\\\UnresolvedXPathException \\[0\\]: .*/', $line);
 }