Skip to content
Snippets Groups Projects
Commit 13ada6d8 authored by Andreas Åkre Solberg's avatar Andreas Åkre Solberg
Browse files

Adding logpeek module that allows read access to log file

git-svn-id: https://simplesamlphp.googlecode.com/svn/trunk@1174 44740490-163a-0410-bde0-09ae8108e29a
parent 1244c497
No related branches found
No related tags found
No related merge requests found
<?php
/*
* Configuration for the module logpeek.
*
* $Id $
*/
$config = array (
'logfile' => '/var/log/simplesamlphp.log',
'lines' => 1500,
);
?>
<?php
/**
* Hook to add the logpeek module to the frontpage.
*
* @param array &$links The links on the frontpage, split into sections.
*/
function logpeek_hook_frontpage(&$links) {
assert('is_array($links)');
assert('array_key_exists("links", $links)');
$links['links'][] = array(
'href' => SimpleSAML_Module::getModuleURL('logpeek/'),
'text' => array('en' => 'SimpleSAMLphp logs access (Log peek)', 'no' => 'Vis simpleSAMLphp log'),
);
}
?>
\ No newline at end of file
<?php
$this->data['header'] = 'Log peek';
$this->includeAtTemplateBase('includes/header.php');
?>
<div id="content">
<h2>SimpleSAMLphp logs (admin utility)</h2>
<form method="get" action="?">
<input type="text" name="tag" value="<?php echo $this->data['trackid']; ?>" />
<input type="submit" value="Show logs" />
</form>
<pre style="background: #eee; border: 1px solid #666; padding: 1em; margin: .4em; overflow: scroll">
<?php
if (!empty($this->data['results'])) {
foreach($this->data['results'] AS $line) {
echo $line;
}
}
?>
</pre>
<?php $this->includeAtTemplateBase('includes/footer.php'); ?>
\ No newline at end of file
<?php
$config = SimpleSAML_Configuration::getInstance();
$session = SimpleSAML_Session::getInstance();
if (!$session->isValid('login-admin') ) {
SimpleSAML_Utilities::redirect('/' . $config->getBaseURL() . 'auth/login-admin.php',
array('RelayState' => SimpleSAML_Utilities::selfURL())
);
}
$logpeekconfig = $config->copyFromBase('logpeek', 'module_logpeek.php');
$logfile = $logpeekconfig->getValue('logfile', '/var/simplesamlphp.log');
function grepLog($logfile, $tag, $lines) {
if (!is_readable($logfile)) throw new Exception('Log file [' . $logfile . '] is not readable. Consider checking the file permissions');
if (!preg_match('/^[a-f0-9]{10}$/', $tag)) throw new Exception('Invalid search tag');
$results = array();
$i=0 ;
$line = '';
$fp = fopen($logfile,"r") ;
if(is_resource($fp)){
fseek($fp,0,SEEK_END) ;
$a = ftell($fp) ;
while($i <= $lines){
if(fgetc($fp) == "\n"){
$line = fgets($fp);
$i++ ;
if (strstr($line, '[' . $tag . ']'))
$results[] = $line;
}
fseek($fp,$a);
$a-- ;
}
}
$results[] = 'Start search line (' . $lines . ' lines back): ' . substr($line,0,40) . '...';
$results = array_reverse($results);
return $results;
}
$results = NULL;
if (isset($_REQUEST['tag'])) {
$results = grepLog($logfile, $_REQUEST['tag'], $logpeekconfig->getValue('lines', 500));
// echo('<pre>log:');
// print_r($results);
}
$t = new SimpleSAML_XHTML_Template($config, 'logpeek:logpeek.php');
$t->data['results'] = $results;
$t->data['trackid'] = $session->getTrackID();
$t->show();
exit;
?>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment