accesslog.blade.php 8.22 KB
<?php
use App\Models\Accesslog;
use App\Jobs\KHRMSLib;

$wakka = new KHRMSLib();

if($wakka->IsAdmin())
{
	if(Input::get("logdetail")==1)
	{
		if(Input::has("getpostdata"))
		{
			$logdata=Accesslog::find(Input::get('getpostdata'));

			$tpostdata=json_decode($logdata->postdata,true);
			echo "<label>URL:</label>".$logdata->url."<br><br>";
			
			$queries=json_decode($logdata->queries,true);
			if(is_array($queries))
			{
				echo "<textarea style='width:100%;height:250px'>";
				foreach($queries as $querie)
				{
					if(is_array($querie[0]))$querie[0]=implode(",",$querie[0]);
					echo "".round($querie[2],4).": ".substr(strip_tags($querie[0]),0,3000)." ".$querie[1]."\n\n";
				}
				echo "</textarea>";
			}
			echo "<br><br>";
			
			if(is_array($tpostdata))foreach($tpostdata as $var=>$val)
			{
				if(is_array($val))$val=implode(",",$val);
				if($var!="")if(!stristr("_token,password",$var))echo "<label>$var:</label><b>".htmlentities($val)."</b><br>";
			}
		}
		return;
	}


if(isset($_GET['logdate']))$logdate=strtotime($_GET['logdate']." 00:00:00");
else $logdate=strtotime(date('Y-m-d')." 00:00:00");


$alist=false;
if(isset($_GET["query"]))$alist=Accesslog::where('postdata','like','%'.Input::get("query").'%');
else 
{
    $alist=Accesslog::where('starttime','>=',$logdate)->where('starttime','<=',($logdate+24*60*60));
    
    if(Input::get('sort')=='cpu')$alist=$alist->orderBy("duration","DESC");
    else $alist=$alist->orderBy("id","DESC");
}
$alist=$alist->get();


$i=sizeof($alist);if(!empty($_GET['sort']))$i=1;
$totaltime=0;$ttlovr10=0;$ttlovr5=0;$ttlovr1=0;$ttlovr0=0;$outstr="";$usrcnt=1;
$actionarr=array();
foreach($alist as $aline)
{
  $postdata='';$j=0;
  $tpostdata=json_decode($aline->postdata,true);
  if(is_array($tpostdata))foreach($tpostdata as $var=>$val)
  {
    if($j++>3)break;
    if(is_array($val))$val=implode(",",$val);
    if(!stristr("_token,password,memusages",$var))$postdata.="$var:".substr($val,0,50)."|";
  }

  $tqueries=json_decode($aline->queries,true);$querystr='';
  if(is_array($tqueries))foreach ($tqueries as $query)
  {
    $querystr+=$query[2];// $query['query'].' ('.$query['time'].')<br />'."\n";
  }
  $querystr=round($querystr,2);
  
  
  $fulldate=date("Y-m-d H:i:s",$aline->starttime-(Auth::user()->timezone*60));
  $outstr.= "<tr onclick='showExtraPost($aline->id);'><td>".$i."</td><td title='$fulldate'>".date("H:i:s",$aline->starttime-(Auth::user()->timezone*60))."</td><td>".round($aline->duration,2)."</td><td>$aline->user</td><td>$aline->action</td><td>".substr($aline->url,0,60)."</td><td>$aline->ip</td><td title='$querystr SQL mSec'>".round($aline->memory/1024/1024,2)."</td><td>".htmlentities(substr($postdata,0,55))."</td></tr>";

  
  
    if($aline->duration>10)$ttlovr10++;
    else if($aline->duration>5)$ttlovr5++;
    else if($aline->duration>1)$ttlovr1++;
    else if($aline->duration>0)$ttlovr0++;
    
    $totaltime+=$aline->duration;
    $usrcnt++;
    
    $turl=substr($aline['url'],0,50);
    $actionarr[$turl]['cnt']++;
    $actionarr[$turl]['time']+=$aline->duration;

  if(!empty($_GET['sort']))$i++;else $i--;
}
?>


<div class="layout-app"><!-- row-app -->
    <div class="row row-app">

    <div class="col-md-12">
      
        <div class="col-separator col-separator-first col-unscrollable box">
            <div class=innerAll>
          
    


<style>#logtable.td{vertical-align:top;}#logtable.tr{height:28px;overflow-y:hidden;}</style>
<script>
function showExtraPost(varstr)
{
  doAjax("admin/accesslog?logdetail=1","getpostdata="+varstr,"dialoglog","admin_log","singlefail","GET");

  $('#dialoglog').dialog('open');
  return false;
}

$(document).ready(function()
{
	if(!$('#dialoglog').length)
	{
		$("#dialoglog_c").html("<div id=dialoglog></div>");
		$('#dialoglog').dialog({
			autoOpen: false,
			width: '70%',
			buttons: {
				"Ok": function() { 
				$(this).dialog("close"); 
				}, 
				"Cancel": function() { 
				$(this).dialog("close"); 
				} 
			}
		});
	}

  waitKeyUpRun("filter",function() { filter2(document.getElementById('filter'), 'logtable') },"2000");
  $('#modfrom').datepicker({dateFormat: 'yy-mm-dd',inline: true,changeYear: true,selectOtherMonths: true,yearRange: '<?php echo (date('Y')-70).":".(date('Y')+5); ?>'});
});
</script>
<div style="float:left;width:50%">Search <input id=filter name="filter" type="text"> Date : <input size=10 id='modfrom' name='modfrom' type='text' value='<?php echo date("Y-m-d",$logdate); ?>' onchange='userLogReloadFun("");' /> <a href=# onclick="menuAction('admin/accesslog');return false;">Reload</a> <?php echo "(Time Stats <b>".round($totaltime,2)." / $usrcnt => ".(round($totaltime/$usrcnt,2))." - </b> $ttlovr10 | $ttlovr5 | $ttlovr1 | $ttlovr0)"; ?></div>
<!--<div style="float:left;width:50%">
	Query: <input type=text name=query> <input type=submit class=button value=Search>
</div>-->
<div style="clear:both"></div>


<?php 
$categories=array();$avgarr=array();$cntarr=array();
foreach($actionarr as $act=>$actarr)
{
  if($actarr['cnt']>sizeof($alist)/150)
  {
    //echo "<label>$act</label> ".round($actarr['time']/$actarr['cnt'],2)." [".round($actarr[time],1)."/$actarr[cnt]]<br>";
  
    $categories[]="'$act'";
    $avgarr[]=-round($actarr['time']*1000/$actarr['cnt'],2);
    $cntarr[]=$actarr['cnt'];
  }
}

array_multisort($cntarr,$avgarr,$categories);
?>
<div id=userlogschart1 style='min-height:300px;height:<?php echo sizeof($categories)*18; ?>px;width:100%'></div>
<script>
$(function () {
    var categories = [<?php echo implode(",",$categories); ?>];
    $(document).ready(function () {
        var userchart1=new Highcharts.Chart({
            chart: {
            renderTo: 'userlogschart1',
                type: 'bar'
            },
            title: {
                text: 'User Actions by Avg time and Usages'
            },
            xAxis: [{
                categories: categories,
                reversed: false,
                labels: {
                    step: 1
                }
            }, { // mirror axis on right side
                opposite: true,
                reversed: false,
                categories: categories,
                linkedTo: 0,
                labels: {
                    step: 1
                }
            }],
            yAxis: {
//                 title: {
//                     text: null
//                 },
//                 labels: {
//                     formatter: function () {
//                         return (Math.abs(this.value) / 1000000) + 'M';
//                     }
//                 },
//                 min: -4000000,
//                 max: 4000000
            },

            plotOptions: {
                series: {
                    stacking: 'normal'
                }
            },

            tooltip: {
                formatter: function () {
                    return '<b>' + this.series.name + ' ' + this.point.category + '</b><br/>' +
                        'Val: ' + Highcharts.numberFormat(Math.abs(this.point.y), 0);
                }
            },

            series: [{
                name: 'Avg Time',
                data: [<?php echo implode(",",$avgarr); ?>]
            }, {
                name: 'Count',
                data: [<?php echo implode(",",$cntarr); ?>]
            }]
        });
    });

});

function userLogReloadFun(sortby)
{
    var sortstr='';if(sortby!="")sortstr="&sort="+sortby
    menuAction('admin/accesslog?logdate='+$("#modfrom").val()+sortstr);return false;
}
</script>





<table id=logtable class='footable table table-striped table-bordered table-white table-primary footable-loaded' style='font-size:12px'>
<thead>
  <tr>
    <th>#</th>
    <th>Start</th>
    <th onclick='userLogReloadFun("cpu");return false;'>Length</th>
    <th>User</th>    
    <th>Action</th>
    <th>URL</th>
    <th>IP</th>
    <th>Memory</th>
    <th>PostVars</th>
  </tr>
</thead>
<?php echo $outstr; ?>
</table>

<?php
function convert($size)
{
    $unit=array('b','kb','mb','gb','tb','pb');
    return @round($size/pow(1024,($i=floor(log($size,1024)))),2).' '.$unit[$i];
}

echo "<br>".convert(memory_get_peak_usage(true)); // 123 kb

}
else
{
  echo "<h1>LOL!! You are not an Admin</h1>";
}
?>
<div id=dialoglog_c></div>

                
                
                
                
            </div>
        </div>
    </div>
    
    </div>
</div><!-- // END row-app -->