Create a gist now

Instantly share code, notes, and snippets.

@sevir /log.php
Created Jan 31, 2015

What would you like to do?
CodeIgniter/Creamture Log Viewer
<?php
/**
* Enhaced Log viewer for CodeIgniter
* SeViR @2015
* based in old version of 2010
*/
class Viewer{
//Please for security set your external ip
private static $allow_ips = array(
'127.0.0.1',
'84.124.50.10'
);
//default logs path
private static $log_path = '../application/logs/';
private static $initialized = false;
public static $assets = array(
'error_icon' => 'data:image/gif;base64,R0lGODlhEAAQAPQfAOaQhNFiTfrUzPrq5vWEZ/KnmfN9YedxW+3FvPCXhOmJe8NPNuySheKmmctZQ/ePd+uBa/i0ovOypvSupO94Xviiifq8qPrAs+NgVN19b96hle+fkuuvov///+doWQAAACH5BAUAAB8ALAAAAAAQABAAQAWV4CeOZClSkUGtQue9XuGIw5NYBNF1hmEph8EIEVBMFC9FIbNAlAQPSCESKUAgAtKjUOkZdqsDI3EQSQ6Rw2uHaRcCjdKgEVgsHBqh6TO4PHIPF3okAgQ3FTkVFgwHWSIXEDgEXx0rKAccJxGTKzsHagcyIhAbCRSfGxMvGAoAATQHRi8MDG4ZDoMfRAEAGxuuTXvCJCEAOw%3D%3D',
'load_icon' => 'data:image/gif;base64,R0lGODlhEAAQAPQAAOvr6zIyMuDg4JWVldTU1GRkZImJiTIyMnFxcUtLS6+vr7u7u0BAQKOjozQ0NFhYWH19fQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACH/C05FVFNDQVBFMi4wAwEAAAAh/hpDcmVhdGVkIHdpdGggYWpheGxvYWQuaW5mbwAh+QQJCgAAACwAAAAAEAAQAAAFdyAgAgIJIeWoAkRCCMdBkKtIHIngyMKsErPBYbADpkSCwhDmQCBethRB6Vj4kFCkQPG4IlWDgrNRIwnO4UKBXDufzQvDMaoSDBgFb886MiQadgNABAokfCwzBA8LCg0Egl8jAggGAA1kBIA1BAYzlyILczULC2UhACH5BAkKAAAALAAAAAAQABAAAAV2ICACAmlAZTmOREE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Wbx8EuuwR/3vof7xsv3umP7yv/ziZv/24////////yH5BAEAAB8ALAAAAAAQAA8AAAVz4CeOn+eRKOklyZmqSdct7ustHcd1Ro16htyO4hsBhRxGoFIsDXIFC2NyKXqeuighsmn4PJAcIxqRZA61q5ixlTwEGLQI3GGwo2+BxnE62tt5CgoAfEABARMTGxkZGBoAkHwlFBUXDQcOCJqbaSaenyYiIQA7',
'info_icon' => 'data:image/gif;base64,R0lGODlhEAAQAPU/AD5xtKvE4Xqlx6bC3YWr0+Tr9LvL4mmVwz1XkZ282klhlI2qzZC00muYxVJronKdzGih1P7//1uc06K+3LLJ5ZuqyF2Esr3T6NDc6kaKxXahz3mk0maQvk2Rz1R7rZ674JKz2uPo78bd8vT3++bw+Up3tL3G2Yyy2fX4+5i001uKuVKQxZO41Juu0pe62GKKuWiTwWKXyH2p1tTg7miczTxco6HG5KTJ56jM6khmo3KWvnidxDyDwaC/4F6Rv////yH5BAUAAD8ALAAAAAAQABAAQAavwJ9wSCwKeRRNo3GYjThQWAAhJElOFNkmENBsJoRSYWioCRK7l0WXEiBMRZEE0uN+YpkLUfIBaR4PExNLDQQuDkIJPgEHMAYRERgWFikeFUUhFQ4ICA4VIUZVOBAdHRI2JEYiHScGHwQEIAEEAHpCNzQUGxoaIyiAGgMqLUIZug9LkI0wDQE1QisJBEwwTi/XOyyIPwUlBBMcLyqTFgsCCqBkORYsAwMMHgpwofRDQQA7',
'favicon' => 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAGAAAABgCAYAAADimHc4AAAABGdBTUEAALGPC/xhBQAAAAFzUkdCAK7OHOkAAAAgY0hSTQAAeiYAAICEAAD6AAAAgOgAAHUwAADqYAAAOpgAABdwnLpRPAAAAAZiS0dEAP8A/wD/oL2nkwAAAAlwSFlzAAALEwAACxMBAJqcGAAAAAl2cEFnAAAAYAAAAGAAeNvZ9AAAH1NJREFUeNrtnQl0VdX1xp9t13+1q9WqbVeXnTStlVVrrW3tqi6rKIptnS0qUMEJHI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Bq1btzZQr7tF2xnwxBNPqN1vf/U3v/lN6uXcWdPzmTlHDOARCczS0Ost1oqms1ZaAS1bPhLw8MMPB7Ro0QLc8tBDD/nx4IMPBtx///03q/xdL/Y/8rTLH/7wB48a1KMMepRJA9aVRQNlzzN06FA/hgwZ4hk8eLBn0KBBfgwcONAzYMAAg/79+5v/ItdCyfQoiR4lzw8t78w5gTbGowQaKIEeJdBAyfMEBQUZKIkeJdGj5HmUSD8CAwM9SqIfSqaBkulR43iUSI8azA8l0Fz7L37xi+//+te/fkFJSKkLCcw9ZdBOz+lVUgeowf9PPz2tWrXy6P4GSowfWvV49FgeJcPz05/+9H/7/09Ww3tuuumma26++eYfBgQEtFUS0i+HBCZ+IUXMSVKiy9Xwo9W7r2v6n6kvc4GEX/7ylz+85ZZb2isJWZdKgsqciQRIUD0v0++G6W++32TRy1yaNWvmueGGG675+c9/fr2S8LJGRvblJGYmAut6ser+yypp1zRZ9DKXa6+91qMRAL6lJNyokvSakpBrSbjzzjvN5C8mgTGcwbjSk08+KarporIjqvdMCNv4pz/96Q7dt8mgdV1+9atfuUnoqCTkuEn485//LH/7299MNFgiiAYl44hqf6frr7/+O01WvMKFSFACrlEp+ZGS8KqSkKQkVPzud78TrRJFvdxI0r333mumQyoRB1u2bPn+X//612v1N00GrI9FCfD87Gc/M5GghDyuFdJsrduzlYSjd9xxx4m77rrrmErSPo2GtUpEB42IH95zzz1NhrsKJFzzk5/85Htar9+s8vTorbfeGqQJe6BKUl9Fe5Wl22688cbvNG/e/IrO9f/DW3H+7TUXpgAAACV0RVh0ZGF0ZTpjcmVhdGUAMjAwOS0wOS0xM1QxNToxOTo1MyswMjowMFH2b6oAAAAldEVYdGRhdGU6bW9kaWZ5ADIwMDktMDktMTNUMTU6MTk6NTMrMDI6MDAgq9cWAAAAAElFTkSuQmCC'
);
private function __construct() {}
private static function initialize()
{
if (self::$initialized)
return;
self::disable_ob();
if (file_exists(dirname( __FILE__).'/system/logs/')){
self::$log_path = dirname( __FILE__).'/system/logs/';
}else if (file_exists(dirname( __FILE__).'/../application/logs/')){
self::$log_path = dirname( __FILE__).'/../application/logs/';
}
self::$initialized = true;
}
//reads all log file
public static function readLog($file){
self::initialize();
echo '<link href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css" rel="stylesheet">';
echo '<style>pre:empty, pre:nth-of-type(1){ display:none; }body{margin: 60px 20px 20px 20px;}</style>';
if(strpos($file, './') !== FALSE) die('invalid access');
if (file_exists(self::$log_path.$file)){
echo '<pre>'.str_replace(
array(
'ERROR -',
'INFO -',
'DEBUG -'
),
array(
'</pre><pre class="alert alert-warning"><img alt="error" src="'.self::$assets['error_icon'].'" />',
'</pre><pre class="info"><img alt="info" src="'.self::$assets['info_icon'].'" />',
'</pre><pre class="debug"><img alt="debug" src="'.self::$assets['debug_icon'].'" />',
),file_get_contents(self::$log_path.$file)
).'</pre>';
}
}
//Check if you access from a valid IP
public static function checkAccess(){
self::initialize();
return in_array($_SERVER['REMOTE_ADDR'], self::$allow_ips);
}
//rename the old logfile
public static function clearLog(){
self::initialize();
$the_file = 'log-'.date('Y-m-d').'.php';
if (file_exists(self::$log_path.$the_file)) rename(self::$log_path.$the_file,self::$log_path.str_replace('.php', '', $the_file).'_'.date('Gis').'.php');
header('Location: '.str_replace('?'.$_SERVER['QUERY_STRING'], '', $_SERVER['REQUEST_URI']));
}
//compress logs in a ZipFile and it removes them
public static function compressLogs(){
self::initialize();
$log_files = glob(self::$log_path.'*.php');
$zip = new ZipArchive();
$zip->open(self::$log_path.'backup_'.date('Y-m-d').'_'.date('Gis').'.zip',ZIPARCHIVE::OVERWRITE);
foreach($log_files as $file) {
$zip->addFile($file,str_replace(dirname($file), '', $file));
}
$zip->close();
foreach($log_files as $file) {
unlink($file);
}
header('Location: '.str_replace('?'.$_SERVER['QUERY_STRING'], '', $_SERVER['REQUEST_URI']));
}
//compress logs and download it
public static function downloadLogs(){
self::initialize();
$log_files = glob(self::$log_path.'*.php');
$zipname = self::$log_path.'backup_'.date('Y-m-d').'_'.date('Gis').'.zip';
$zip = new ZipArchive();
$zip->open($zipname,ZIPARCHIVE::OVERWRITE);
foreach($log_files as $file) {
$zip->addFile($file,str_replace(dirname($file), '', $file));
}
$zip->close();
header('Content-disposition: attachment; filename='.str_replace(dirname($zipname), '', $zipname));
header('Content-type: application/octet-stream');
readfile($zipname);
unlink($zipname);
}
//download a zip log backup file
public static function downloadFile($file){
self::initialize();
if((strpos($file, './') !== FALSE) || (strpos($file,'.zip') === FALSE)) die('invalid access');
header('Content-disposition: attachment; filename='.$file);
header('Content-type: application/octet-stream');
readfile(self::$log_path.$file);
}
//get list of logs and zip backups
public static function getFiles(){
$log_files = glob(self::$log_path.'*.php');
usort(
$log_files,
create_function('$a,$b', 'return filemtime($b) - filemtime($a);')
);
$backups_files = glob(self::$log_path.'*.zip');
usort(
$backups_files,
create_function('$a,$b', 'return filemtime($b) - filemtime($a);')
);
return array(
'logs'=> $log_files,
'backups'=> $backups_files
);
}
//hide progress
public static function stopProgress(){
?>
<script type="text/javascript">
window.top.document.getElementById('progress').style.display = 'none';
window.scrollTo(0,document.body.scrollHeight);
</script>
<?php
}
public static function disable_ob() {
// Turn off output buffering
ini_set('output_buffering', 'off');
// Turn off PHP output compression
ini_set('zlib.output_compression', false);
// Implicitly flush the buffer(s)
ini_set('implicit_flush', true);
ob_implicit_flush(true);
// Clear, and turn off output buffering
while (ob_get_level() > 0) {
// Get the curent level
$level = ob_get_level();
// End the buffering
ob_end_clean();
// If the current level has not changed, abort
if (ob_get_level() == $level) break;
}
// Disable apache output buffering/compression
if (function_exists('apache_setenv')) {
apache_setenv('no-gzip', '1');
apache_setenv('dont-vary', '1');
}
}
public static function realtime(){
echo '<link href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css" rel="stylesheet">';
?>
<style type="text/css">pre:empty, pre:nth-of-type(1){ display:none;}body{margin: 60px 20px 20px 20px;}</style>
<script type="text/javascript">
setInterval(function(){
window.scrollBy(0,200);
}, 300);
</script>
<?php
$the_file = self::$log_path.'log-'.date('Y-m-d').'.php';
if ( file_exists($the_file)){
ini_set('max_execution_time', 0);
$lastpos = 0;
while (true) {
usleep(300000); //0.3 s
clearstatcache(false, $the_file);
$len = filesize($the_file);
if ($len < $lastpos) {
//file deleted or reset
$lastpos = $len;
}
elseif ($len > $lastpos) {
$f = fopen($the_file, "rb");
if ($f === false)
die();
fseek($f, $lastpos);
while (!feof($f)) {
$buffer = fread($f, 4096);
echo '<pre>'.str_replace(
array(
'ERROR -',
'INFO -',
'DEBUG -'
),
array(
'</pre><pre class="alert alert-warning"><img alt="error" src="'.self::$assets['error_icon'].'" />',
'</pre><pre class="info"><img alt="info" src="'.self::$assets['info_icon'].'" />',
'</pre><pre class="debug"><img alt="debug" src="'.self::$assets['debug_icon'].'" />',
),$buffer
).'</pre>';
flush();
}
$lastpos = ftell($f);
fclose($f);
}
}
}else{
echo 'No today log found';
}
}
}
if (!Viewer::checkAccess()) die('Your IP ('.$_SERVER['REMOTE_ADDR'].') is not allowed');
if (isset($_GET['q'])){
$query = $_GET['q'];
switch ($query) {
case 'phpinfo':
echo '<style>body{margin: 60px 20px 20px 20px;}</style>';
phpinfo(); Viewer::stopProgress(); die();
break;
case 'file':
if(isset($_GET['f'])){
Viewer::readLog($_GET['f']);
}
Viewer::stopProgress();
die();
break;
case 'download':
if(isset($_GET['f'])){
Viewer::downloadFile($_GET['f']);
}
die();
break;
case 'clear':
Viewer::clearLog();
die();
break;
case 'downloadzip':
Viewer::downloadLogs();
die();
break;
case 'backup':
Viewer::compressLogs();
die();
break;
case 'realtime':
Viewer::realtime();
flush();
die();
break;
default:
echo "no action available";Viewer::stopProgress();die();
break;
}
}
$files = Viewer::getFiles();
//And now the main view
?>
<html>
<head>
<title>Log Viewer for CodeIgniter</title>
<link rel='icon' type='image/png' href='<?php echo Viewer::$assets['favicon'];?>'>
<link href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css" rel="stylesheet">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
<script src="//maxcdn.bootstrapcdn.com/bootstrap/3.3.2/js/bootstrap.min.js"></script>
<script>
$(function(){
$("a.action").click(function(){
$("#progress").show();
$("#content").attr('src', $(this).attr("data-href") );
});
$("#logfilter, #backupfilter").click(function(){
return false;
}).keyup(function(){
if(this.value==''){
$("#"+this.id+" div").show();
}else{
filtertext = this.value;
$("#"+$(this).attr("data-id")+" div").each(function(){
console.log($("a:first",this).html());
console.log(filtertext);
if($("a:first",this).html().indexOf(filtertext) > -1){
$(this).show();
}else{
$(this).hide();
}
});
}
});
});
</script>
<style>
.pr-info{
padding-top: 5px;
padding-left: 10px;
}
.pr-info span{
display: block;
font-size: 9px;
}
#backupfiles div, #logfiles div{
font-size: 10px;
margin-left: 10px;
}
#backupfiles, #logfiles{
max-height: 200px;
}
#content{
position:absolute;
width: 100%;
height: 100%;
border: none;
}
#progress{
display:none;
}
#logfilter, #backupfilter{
margin: 5px 10px;
font-size: 10px;
height: 25px;
}
body{
margin:0;
}
</style>
</head>
<body>
<nav class="navbar navbar-default navbar-fixed-top">
<div class="container-fluid">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" title="refresh" href="<?=$_SERVER['QUERY_STRING'].$_SERVER['REQUEST_URI']; ?>">Log Viewer for CodeIgniter</a>
</div>
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav navbar-fixed">
<li class="pr-info">
<span><strong><?php echo $_SERVER["SERVER_NAME"]?></strong></span>
<span>server ip: <?php echo gethostbyname ( $_SERVER["SERVER_NAME"] )?></span>
<span>my ip: <?php echo $_SERVER['REMOTE_ADDR'];?></span>
</li>
<!-- DEPRECATED
<li><a title="backup and clear this log file" href="<?php echo str_replace('?'.$_SERVER['QUERY_STRING'], '', $_SERVER['REQUEST_URI']).'?q=clear&f=';?>">Clear</a></li>
-->
<li><a title="rename today log and create a new" href="<?php echo str_replace('?'.$_SERVER['QUERY_STRING'], '', $_SERVER['REQUEST_URI']).'?q=clear';?>">Clear</a></li>
<li><a title="compress into a zip file and download all logs" target="_blank" href="<?php echo str_replace('?'.$_SERVER['QUERY_STRING'], '', $_SERVER['REQUEST_URI']).'?q=downloadzip';?>">Download</a></li>
<li><a title="backup into a zip file all logs and removes them" href="<?php echo str_replace('?'.$_SERVER['QUERY_STRING'], '', $_SERVER['REQUEST_URI']).'?q=backup';?>">Backup</a></li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false">Logs files<span class="caret"></span></a>
<ul class="dropdown-menu" role="menu">
<li>
<a href="#">Log files</a>
<div class="form-group">
<input id="logfilter" data-id="logfiles" type="text" class="form-control" placeholder="Filter for...">
</div><!-- /input-group -->
</li>
<li id="logfiles">
<?php foreach ($files['logs'] as $file): ?>
<div class="filelink"><a class="action log" href="#log" data-href="<?php echo str_replace('?'.$_SERVER['QUERY_STRING'], '', $_SERVER['REQUEST_URI']).'?q=file&f='.basename($file);?>"><?=basename($file)?></a></div>
<?php endforeach ?>
</li>
<li class="divider"></li>
<li>
<a href="#">Backup files</a>
<div class="form-group">
<input id="backupfilter" data-id="backupfiles" type="text" class="form-control" placeholder="Filter for..."/>
</div><!-- /input-group -->
</li>
<li id="backupfiles">
<?php foreach ($files['backups'] as $file): ?>
<div class="filelink"><a target="_blank" href="<?php echo str_replace('?'.$_SERVER['QUERY_STRING'], '', $_SERVER['REQUEST_URI']).'?q=download&f='.basename($file);?>"><?=basename($file)?></a></div>
<?php endforeach ?>
</li>
</ul>
</li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false">Extra info<span class="caret"></span></a>
<ul class="dropdown-menu" role="menu">
<li><a class="action" href="#phpinfo" data-href="<?php echo str_replace('?'.$_SERVER['QUERY_STRING'], '', $_SERVER['REQUEST_URI']).'?q=phpinfo'?>">Show phpinfo()</a></li>
</ul>
</li>
<li id="progress"><a href="#"><img src="<?php echo Viewer::$assets['load_icon'];?>"></a></li>
</ul>
</div><!-- /.navbar-collapse -->
</div><!-- /.container-fluid -->
</nav>
<div class="">
<iframe id="content" src="<?php echo str_replace('?'.$_SERVER['QUERY_STRING'], '', $_SERVER['REQUEST_URI']).'?q=realtime'?>"></iframe>
</div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment