2011-06-21 17:19:10 +08:00
|
|
|
<?php
|
|
|
|
|
2016-12-09 02:31:44 +08:00
|
|
|
# Moved up here because it is used in several spots.
|
|
|
|
# These are the valid columns that you can filter on.
|
|
|
|
$filterFields = array( 'Component', 'ServerId', 'Pid', 'Level', 'File', 'Line' );
|
|
|
|
|
2018-05-18 21:03:01 +08:00
|
|
|
switch ( $_REQUEST['task'] ) {
|
|
|
|
case 'create' :
|
|
|
|
{
|
|
|
|
// Silently ignore bogus requests
|
|
|
|
if ( !empty($_POST['level']) && !empty($_POST['message']) ) {
|
|
|
|
logInit(array('id'=>'web_js'));
|
2011-06-21 17:19:10 +08:00
|
|
|
|
2018-05-18 21:03:01 +08:00
|
|
|
$string = $_POST['message'];
|
2014-11-13 22:17:54 +08:00
|
|
|
|
2019-01-22 00:12:17 +08:00
|
|
|
$file = !empty($_POST['file']) ? preg_replace( '/\w+:\/\/[\w.:]+\//', '', $_POST['file'] ) : '';
|
2018-05-18 21:03:01 +08:00
|
|
|
if ( !empty( $_POST['line'] ) )
|
|
|
|
$line = $_POST['line'];
|
|
|
|
else
|
|
|
|
$line = NULL;
|
2011-06-21 17:19:10 +08:00
|
|
|
|
2018-05-18 21:03:01 +08:00
|
|
|
$levels = array_flip(Logger::$codes);
|
|
|
|
if ( !isset($levels[$_POST['level']]) )
|
|
|
|
Panic("Unexpected logger level '".$_POST['level']."'");
|
|
|
|
$level = $levels[$_POST['level']];
|
2018-08-18 00:57:27 +08:00
|
|
|
Logger::fetch()->logPrint($level, $string, $file, $line);
|
2011-06-21 17:19:10 +08:00
|
|
|
}
|
2018-05-18 21:03:01 +08:00
|
|
|
ajaxResponse();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 'query' :
|
|
|
|
{
|
|
|
|
if ( !canView('System') )
|
|
|
|
ajaxError('Insufficient permissions to view log entries');
|
2011-06-21 17:19:10 +08:00
|
|
|
|
2018-09-08 04:31:11 +08:00
|
|
|
$servers = Server::find();
|
2018-05-18 21:03:01 +08:00
|
|
|
$servers_by_Id = array();
|
|
|
|
# There is probably a better way to do this.
|
|
|
|
foreach ( $servers as $server ) {
|
|
|
|
$servers_by_Id[$server->Id()] = $server;
|
|
|
|
}
|
2016-01-02 05:33:28 +08:00
|
|
|
|
2018-05-18 21:03:01 +08:00
|
|
|
$minTime = isset($_REQUEST['minTime'])?$_REQUEST['minTime']:NULL;
|
|
|
|
$maxTime = isset($_REQUEST['maxTime'])?$_REQUEST['maxTime']:NULL;
|
2017-07-06 23:42:04 +08:00
|
|
|
|
2018-05-18 21:03:01 +08:00
|
|
|
$limit = 100;
|
|
|
|
if ( isset($_REQUEST['limit']) ) {
|
2018-08-18 00:57:27 +08:00
|
|
|
if ( ( !is_integer($_REQUEST['limit']) and !ctype_digit($_REQUEST['limit']) ) ) {
|
|
|
|
Error('Invalid value for limit ' . $_REQUEST['limit']);
|
2018-05-18 21:03:01 +08:00
|
|
|
} else {
|
|
|
|
$limit = $_REQUEST['limit'];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$sortField = 'TimeKey';
|
|
|
|
if ( isset($_REQUEST['sortField']) ) {
|
2018-08-18 00:57:27 +08:00
|
|
|
if ( !in_array($_REQUEST['sortField'], $filterFields) and ( $_REQUEST['sortField'] != 'TimeKey' ) ) {
|
|
|
|
Error("Invalid sort field " . $_REQUEST['sortField']);
|
2018-05-18 21:03:01 +08:00
|
|
|
} else {
|
|
|
|
$sortField = $_REQUEST['sortField'];
|
|
|
|
}
|
|
|
|
}
|
2018-08-18 00:57:27 +08:00
|
|
|
$sortOrder = (isset($_REQUEST['sortOrder']) and ($_REQUEST['sortOrder'] == 'asc')) ? 'asc' : 'desc';
|
|
|
|
$filter = isset($_REQUEST['filter']) ? $_REQUEST['filter'] : array();
|
2011-06-21 17:19:10 +08:00
|
|
|
|
2018-05-18 21:03:01 +08:00
|
|
|
$total = dbFetchOne('SELECT count(*) AS Total FROM Logs', 'Total');
|
|
|
|
$sql = 'SELECT * FROM Logs';
|
|
|
|
$where = array();
|
|
|
|
$values = array();
|
|
|
|
if ( $minTime ) {
|
|
|
|
$where[] = 'TimeKey > ?';
|
|
|
|
$values[] = $minTime;
|
|
|
|
} elseif ( $maxTime ) {
|
|
|
|
$where[] = 'TimeKey < ?';
|
|
|
|
$values[] = $maxTime;
|
|
|
|
}
|
2016-12-09 02:31:44 +08:00
|
|
|
|
2018-05-18 21:03:01 +08:00
|
|
|
foreach ( $filter as $field=>$value ) {
|
|
|
|
if ( ! in_array($field, $filterFields) ) {
|
|
|
|
Error("$field is not in valid filter fields");
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if ( $field == 'Level' ){
|
|
|
|
$where[] = $field.' <= ?';
|
|
|
|
$values[] = $value;
|
|
|
|
} else {
|
|
|
|
$where[] = $field.' = ?';
|
|
|
|
$values[] = $value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$options = array();
|
|
|
|
if ( count($where) )
|
2018-08-18 00:57:27 +08:00
|
|
|
$sql.= ' WHERE '.join(' AND ', $where);
|
2018-05-18 21:03:01 +08:00
|
|
|
$sql .= ' ORDER BY '.$sortField.' '.$sortOrder.' LIMIT '.$limit;
|
|
|
|
$logs = array();
|
|
|
|
foreach ( dbFetchAll($sql, NULL, $values) as $log ) {
|
2018-08-18 00:57:27 +08:00
|
|
|
|
|
|
|
$log['DateTime'] = strftime('%Y-%m-%d %H:%M:%S', intval($log['TimeKey']));
|
2018-08-20 23:13:38 +08:00
|
|
|
#Warning("TimeKey: " . $log['TimeKey'] . 'Intval:'.intval($log['TimeKey']).' DateTime:'.$log['DateTime']);
|
2018-08-18 00:57:27 +08:00
|
|
|
#$log['DateTime'] = preg_replace('/^\d+/', strftime('%Y-%m-%d %H:%M:%S', intval($log['TimeKey'])), $log['TimeKey']);
|
2018-05-18 21:03:01 +08:00
|
|
|
$log['Server'] = ( $log['ServerId'] and isset($servers_by_Id[$log['ServerId']]) ) ? $servers_by_Id[$log['ServerId']]->Name() : '';
|
2018-08-18 00:57:27 +08:00
|
|
|
$log['Message'] = preg_replace('/[\x00-\x1F\x7F-\xFF]/', '', $log['Message']);
|
2018-05-18 21:03:01 +08:00
|
|
|
foreach( $filterFields as $field ) {
|
2018-08-18 00:57:27 +08:00
|
|
|
if ( !isset($options[$field]) )
|
2018-05-18 21:03:01 +08:00
|
|
|
$options[$field] = array();
|
|
|
|
$value = $log[$field];
|
2016-12-15 03:56:54 +08:00
|
|
|
|
2018-05-18 21:03:01 +08:00
|
|
|
if ( $field == 'Level' ) {
|
|
|
|
if ( $value <= Logger::INFO )
|
|
|
|
$options[$field][$value] = Logger::$codes[$value];
|
|
|
|
else
|
|
|
|
$options[$field][$value] = 'DB'.$value;
|
|
|
|
} else if ( $field == 'ServerId' ) {
|
|
|
|
$options['ServerId'][$value] = ( $value and isset($servers_by_Id[$value]) ) ? $servers_by_Id[$value]->Name() : '';
|
|
|
|
} else if ( isset($log[$field]) ) {
|
2018-09-10 04:36:09 +08:00
|
|
|
$options[$field][$log[$field]] = $value;
|
2011-06-21 17:19:10 +08:00
|
|
|
}
|
2018-05-18 21:03:01 +08:00
|
|
|
}
|
|
|
|
$logs[] = $log;
|
2011-06-21 17:19:10 +08:00
|
|
|
}
|
|
|
|
|
2018-05-18 21:03:01 +08:00
|
|
|
$available = count($logs);
|
|
|
|
ajaxResponse( array(
|
|
|
|
'updated' => preg_match('/%/', DATE_FMT_CONSOLE_LONG)?strftime(DATE_FMT_CONSOLE_LONG):date(DATE_FMT_CONSOLE_LONG),
|
|
|
|
'total' => $total,
|
2018-08-18 00:57:27 +08:00
|
|
|
'available' => isset($available) ? $available : $total,
|
2018-05-18 21:03:01 +08:00
|
|
|
'logs' => $logs,
|
|
|
|
'state' => logState(),
|
2018-09-10 04:36:09 +08:00
|
|
|
'options' => $options,
|
2018-05-18 21:03:01 +08:00
|
|
|
) );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 'export' :
|
|
|
|
{
|
|
|
|
if ( !canView('System') )
|
|
|
|
ajaxError('Insufficient permissions to export logs');
|
2011-06-21 17:19:10 +08:00
|
|
|
|
2018-05-18 21:03:01 +08:00
|
|
|
$minTime = isset($_POST['minTime'])?$_POST['minTime']:NULL;
|
|
|
|
$maxTime = isset($_POST['maxTime'])?$_POST['maxTime']:NULL;
|
|
|
|
if ( !is_null($minTime) && !is_null($maxTime) && $minTime > $maxTime ) {
|
|
|
|
$tempTime = $minTime;
|
|
|
|
$minTime = $maxTime;
|
|
|
|
$maxTime = $tempTime;
|
|
|
|
}
|
|
|
|
//$limit = isset($_POST['limit'])?$_POST['limit']:1000;
|
|
|
|
$filter = isset($_POST['filter'])?$_POST['filter']:array();
|
|
|
|
$sortField = 'TimeKey';
|
|
|
|
if ( isset($_POST['sortField']) ) {
|
|
|
|
if ( ! in_array( $_POST['sortField'], $filterFields ) and ( $_POST['sortField'] != 'TimeKey' ) ) {
|
|
|
|
Error("Invalid sort field " . $_POST['sortField'] );
|
|
|
|
} else {
|
|
|
|
$sortField = $_POST['sortField'];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$sortOrder = (isset($_POST['sortOrder']) and $_POST['sortOrder']) == 'asc' ? 'asc':'desc';
|
2015-12-31 23:13:25 +08:00
|
|
|
|
2018-09-08 04:31:11 +08:00
|
|
|
$servers = Server::find();
|
2018-05-18 21:03:01 +08:00
|
|
|
$servers_by_Id = array();
|
|
|
|
# There is probably a better way to do this.
|
|
|
|
foreach ( $servers as $server ) {
|
|
|
|
$servers_by_Id[$server->Id()] = $server;
|
|
|
|
}
|
|
|
|
|
|
|
|
$sql = 'SELECT * FROM Logs';
|
|
|
|
$where = array();
|
|
|
|
$values = array();
|
|
|
|
if ( $minTime ) {
|
2018-11-13 04:43:03 +08:00
|
|
|
Logger::Debug("MinTime: $minTime");
|
|
|
|
if ( preg_match('/(.+)(\.\d+)/', $minTime, $matches) ) {
|
|
|
|
# This handles sub second precision
|
|
|
|
$minTime = strtotime($matches[1]).$matches[2];
|
|
|
|
Logger::Debug("MinTime: $minTime");
|
|
|
|
} else {
|
|
|
|
$minTime = strtotime($minTime);
|
|
|
|
}
|
2018-05-18 21:03:01 +08:00
|
|
|
$where[] = 'TimeKey >= ?';
|
|
|
|
$values[] = $minTime;
|
|
|
|
}
|
|
|
|
if ( $maxTime ) {
|
2018-11-13 04:43:03 +08:00
|
|
|
if ( preg_match('/(.+)(\.\d+)/', $maxTime, $matches) ) {
|
|
|
|
$maxTime = strtotime($matches[1]).$matches[2];
|
|
|
|
} else {
|
|
|
|
$maxTime = strtotime($maxTime);
|
|
|
|
}
|
2018-05-18 21:03:01 +08:00
|
|
|
$where[] = 'TimeKey <= ?';
|
|
|
|
$values[] = $maxTime;
|
|
|
|
}
|
|
|
|
foreach ( $filter as $field=>$value ) {
|
|
|
|
if ( $value != '' ) {
|
|
|
|
if ( $field == 'Level' ) {
|
|
|
|
$where[] = $field.' <= ?';
|
|
|
|
$values[] = $value;
|
|
|
|
} else {
|
|
|
|
$where[] = $field.' = ?';
|
|
|
|
$values[] = $value;
|
2011-06-21 17:19:10 +08:00
|
|
|
}
|
2018-05-18 21:03:01 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if ( count($where) )
|
|
|
|
$sql.= ' WHERE '.join( ' AND ', $where );
|
|
|
|
$sql .= ' ORDER BY '.$sortField.' '.$sortOrder;
|
|
|
|
//$sql .= " limit ".dbEscape($limit);
|
|
|
|
$format = isset($_POST['format'])?$_POST['format']:'text';
|
|
|
|
switch( $format ) {
|
|
|
|
case 'text' :
|
|
|
|
$exportExt = 'txt';
|
|
|
|
break;
|
|
|
|
case 'tsv' :
|
|
|
|
$exportExt = 'tsv';
|
|
|
|
break;
|
|
|
|
case 'html' :
|
|
|
|
$exportExt = 'html';
|
|
|
|
break;
|
|
|
|
case 'xml' :
|
|
|
|
$exportExt = 'xml';
|
|
|
|
break;
|
|
|
|
default :
|
|
|
|
Fatal("Unrecognised log export format '$format'");
|
|
|
|
}
|
|
|
|
$exportKey = substr(md5(rand()),0,8);
|
|
|
|
$exportFile = "zm-log.$exportExt";
|
2018-11-13 04:43:03 +08:00
|
|
|
if ( ! file_exists(ZM_DIR_EXPORTS) ) {
|
|
|
|
Logger::Debug('Creating ' . ZM_DIR_EXPORTS);
|
|
|
|
if ( ! mkdir(ZM_DIR_EXPORTS) ) {
|
|
|
|
Fatal("Can't create exports dir at '".ZM_DIR_EXPORTS."'");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$exportPath = ZM_DIR_EXPORTS."/zm-log-$exportKey.$exportExt";
|
|
|
|
Logger::Debug("Exporting to $exportPath");
|
|
|
|
if ( !($exportFP = fopen($exportPath, 'w')) )
|
2018-05-18 21:03:01 +08:00
|
|
|
Fatal("Unable to open log export file $exportPath");
|
|
|
|
$logs = array();
|
2018-08-18 00:57:27 +08:00
|
|
|
foreach ( dbFetchAll($sql, NULL, $values) as $log ) {
|
|
|
|
$log['DateTime'] = preg_replace('/^\d+/', strftime( "%Y-%m-%d %H:%M:%S", intval($log['TimeKey']) ), $log['TimeKey']);
|
2018-05-18 21:03:01 +08:00
|
|
|
$log['Server'] = ( $log['ServerId'] and isset($servers_by_Id[$log['ServerId']]) ) ? $servers_by_Id[$log['ServerId']]->Name() : '';
|
|
|
|
$logs[] = $log;
|
|
|
|
}
|
2018-11-13 04:43:03 +08:00
|
|
|
Logger::Debug(count($logs)." lines being exported by $sql " . implode(',',$values));
|
|
|
|
|
2018-05-18 21:03:01 +08:00
|
|
|
switch( $format ) {
|
|
|
|
case 'text' :
|
|
|
|
{
|
|
|
|
foreach ( $logs as $log ) {
|
|
|
|
if ( $log['Line'] )
|
|
|
|
fprintf( $exportFP, "%s %s[%d].%s-%s/%d [%s]\n",
|
|
|
|
$log['DateTime'], $log['Component'], $log['Pid'], $log['Code'], $log['File'], $log['Line'], $log['Message'] );
|
|
|
|
else
|
|
|
|
fprintf( $exportFP, "%s %s[%d].%s-%s [%s]\n",
|
|
|
|
$log['DateTime'], $log['Component'], $log['Pid'], $log['Code'], $log['File'], $log['Message'] );
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 'tsv' :
|
|
|
|
{
|
|
|
|
# This line doesn't need fprintf, it could use fwrite
|
|
|
|
fprintf( $exportFP, join( "\t",
|
|
|
|
translate('DateTime'),
|
|
|
|
translate('Component'),
|
|
|
|
translate('Server'),
|
|
|
|
translate('Pid'),
|
|
|
|
translate('Level'),
|
|
|
|
translate('Message'),
|
|
|
|
translate('File'),
|
|
|
|
translate('Line')
|
|
|
|
)."\n" );
|
|
|
|
foreach ( $logs as $log ) {
|
|
|
|
fprintf( $exportFP, "%s\t%s\t%s\t%d\t%s\t%s\t%s\t%s\n", $log['DateTime'], $log['Component'], $log['Server'], $log['Pid'], $log['Code'], $log['Message'], $log['File'], $log['Line'] );
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 'html' :
|
|
|
|
{
|
|
|
|
fwrite( $exportFP,
|
|
|
|
'
|
|
|
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
|
|
|
<html xmlns="http://www.w3.org/1999/xhtml">
|
|
|
|
<head>
|
|
|
|
<title>'.translate('ZoneMinderLog').'</title>
|
|
|
|
<style type="text/css">
|
|
|
|
body, h3, p, table, td {
|
|
|
|
font-family: Verdana, Arial, Helvetica, sans-serif;
|
|
|
|
font-size: 11px;
|
|
|
|
}
|
|
|
|
table {
|
|
|
|
border-collapse: collapse;
|
|
|
|
width: 100%;
|
|
|
|
}
|
|
|
|
th {
|
|
|
|
font-weight: bold;
|
|
|
|
}
|
|
|
|
th, td {
|
|
|
|
border: 1px solid #888888;
|
|
|
|
padding: 1px 2px;
|
|
|
|
}
|
|
|
|
tr.log-fat td {
|
|
|
|
background-color:#ffcccc;
|
|
|
|
font-weight: bold;
|
|
|
|
font-style: italic;
|
|
|
|
}
|
|
|
|
tr.log-err td {
|
|
|
|
background-color:#ffcccc;
|
|
|
|
}
|
|
|
|
tr.log-war td {
|
|
|
|
background-color: #ffe4b5;
|
|
|
|
}
|
|
|
|
tr.log-dbg td {
|
|
|
|
color: #666666;
|
|
|
|
font-style: italic;
|
|
|
|
}
|
|
|
|
</style>
|
|
|
|
</head>
|
|
|
|
<body>
|
2015-05-10 21:10:30 +08:00
|
|
|
<h3>'.translate('ZoneMinderLog').'</h3>
|
2011-06-21 17:19:10 +08:00
|
|
|
<p>'.htmlspecialchars(preg_match( '/%/', DATE_FMT_CONSOLE_LONG )?strftime( DATE_FMT_CONSOLE_LONG ):date( DATE_FMT_CONSOLE_LONG )).'</p>
|
2015-05-10 21:10:30 +08:00
|
|
|
<p>'.count($logs).' '.translate('Logs').'</p>
|
2011-06-21 17:19:10 +08:00
|
|
|
<table>
|
2018-05-18 21:03:01 +08:00
|
|
|
<tbody>
|
|
|
|
<tr><th>'.translate('DateTime').'</th><th>'.translate('Component').'</th><th>'.translate('Server').'</th><th>'.translate('Pid').'</th><th>'.translate('Level').'</th><th>'.translate('Message').'</th><th>'.translate('File').'</th><th>'.translate('Line').'</th></tr>
|
|
|
|
' );
|
|
|
|
foreach ( $logs as $log ) {
|
|
|
|
$classLevel = $log['Level'];
|
|
|
|
if ( $classLevel < Logger::FATAL )
|
|
|
|
$classLevel = Logger::FATAL;
|
|
|
|
elseif ( $classLevel > Logger::DEBUG )
|
|
|
|
$classLevel = Logger::DEBUG;
|
|
|
|
$logClass = 'log-'.strtolower(Logger::$codes[$classLevel]);
|
|
|
|
fprintf( $exportFP, " <tr class=\"%s\"><td>%s</td><td>%s</td><td>%s</td><td>%d</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td></tr>\n", $logClass, $log['DateTime'], $log['Component'], $log['Server'], $log['Pid'], $log['Code'], $log['Message'], $log['File'], $log['Line'] );
|
|
|
|
}
|
|
|
|
fwrite( $exportFP,
|
|
|
|
' </tbody>
|
|
|
|
</table>
|
|
|
|
</body>
|
|
|
|
</html>' );
|
|
|
|
break;
|
2011-06-21 17:19:10 +08:00
|
|
|
}
|
2018-05-18 21:03:01 +08:00
|
|
|
case 'xml' :
|
2011-06-21 17:19:10 +08:00
|
|
|
{
|
2018-05-18 21:03:01 +08:00
|
|
|
fwrite( $exportFP,
|
|
|
|
'<?xml version="1.0" encoding="utf-8"?>
|
|
|
|
<logexport title="'.translate('ZoneMinderLog').'" date="'.htmlspecialchars(preg_match( '/%/', DATE_FMT_CONSOLE_LONG )?strftime( DATE_FMT_CONSOLE_LONG ):date( DATE_FMT_CONSOLE_LONG )).'">
|
|
|
|
<selector>'.$_POST['selector'].'</selector>' );
|
|
|
|
foreach ( $filter as $field=>$value )
|
|
|
|
if ( $value != '' )
|
|
|
|
fwrite( $exportFP,
|
|
|
|
' <filter>
|
|
|
|
<'.strtolower($field).'>'.htmlspecialchars($value).'</'.strtolower($field).'>
|
|
|
|
</filter>' );
|
|
|
|
fwrite( $exportFP,
|
|
|
|
' <columns>
|
|
|
|
<column field="datetime">'.translate('DateTime').'</column><column field="component">'.translate('Component').'</column><column field="'.translate('Server').'</column><column field="pid">'.translate('Pid').'</column><column field="level">'.translate('Level').'</column><column field="message">'.translate('Message').'</column><column field="file">'.translate('File').'</column><column field="line">'.translate('Line').'</column>
|
|
|
|
</columns>
|
|
|
|
<logs count="'.count($logs).'">
|
|
|
|
' );
|
|
|
|
foreach ( $logs as $log ) {
|
|
|
|
fprintf( $exportFP,
|
|
|
|
" <log>
|
|
|
|
<datetime>%s</datetime>
|
|
|
|
<component>%s</component>
|
|
|
|
<server>%s</server>
|
|
|
|
<pid>%d</pid>
|
|
|
|
<level>%s</level>
|
|
|
|
<message><![CDATA[%s]]></message>
|
|
|
|
<file>%s</file>
|
|
|
|
<line>%d</line>
|
|
|
|
</log>\n", $log['DateTime'], $log['Component'], $log['Server'], $log['Pid'], $log['Code'], utf8_decode( $log['Message'] ), $log['File'], $log['Line'] );
|
|
|
|
}
|
|
|
|
fwrite( $exportFP,
|
|
|
|
' </logs>
|
|
|
|
</logexport>' );
|
|
|
|
break;
|
|
|
|
}
|
2018-08-18 00:57:27 +08:00
|
|
|
$exportExt = 'xml';
|
2018-05-18 21:03:01 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
fclose( $exportFP );
|
|
|
|
ajaxResponse( array(
|
|
|
|
'key' => $exportKey,
|
|
|
|
'format' => $format,
|
|
|
|
) );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 'download' :
|
|
|
|
{
|
|
|
|
if ( !canView('System') )
|
|
|
|
ajaxError('Insufficient permissions to download logs');
|
2011-06-21 17:19:10 +08:00
|
|
|
|
2018-05-18 21:03:01 +08:00
|
|
|
if ( empty($_REQUEST['key']) )
|
2018-08-18 00:57:27 +08:00
|
|
|
Fatal('No log export key given');
|
2018-05-18 21:03:01 +08:00
|
|
|
$exportKey = $_REQUEST['key'];
|
|
|
|
if ( empty($_REQUEST['format']) )
|
2018-08-18 00:57:27 +08:00
|
|
|
Fatal('No log export format given');
|
2018-05-18 21:03:01 +08:00
|
|
|
$format = $_REQUEST['format'];
|
2011-06-21 17:19:10 +08:00
|
|
|
|
2018-05-18 21:03:01 +08:00
|
|
|
switch( $format ) {
|
|
|
|
case 'text' :
|
|
|
|
$exportExt = 'txt';
|
|
|
|
break;
|
|
|
|
case 'tsv' :
|
|
|
|
$exportExt = 'tsv';
|
|
|
|
break;
|
|
|
|
case 'html' :
|
|
|
|
$exportExt = 'html';
|
|
|
|
break;
|
|
|
|
case 'xml' :
|
|
|
|
$exportExt = 'xml';
|
|
|
|
break;
|
|
|
|
default :
|
|
|
|
Fatal("Unrecognised log export format '$format'");
|
2011-06-21 17:19:10 +08:00
|
|
|
}
|
|
|
|
|
2018-05-18 21:03:01 +08:00
|
|
|
$exportFile = "zm-log.$exportExt";
|
2018-11-13 04:43:03 +08:00
|
|
|
$exportPath = ZM_DIR_EXPORTS."/zm-log-$exportKey.$exportExt";
|
2011-06-21 17:19:10 +08:00
|
|
|
|
2018-08-18 00:57:27 +08:00
|
|
|
header('Pragma: public');
|
|
|
|
header('Expires: 0');
|
|
|
|
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
|
|
|
|
header('Cache-Control: private', false ); // required by certain browsers
|
|
|
|
header('Content-Description: File Transfer');
|
|
|
|
header('Content-Disposition: attachment; filename="'.$exportFile.'"' );
|
|
|
|
header('Content-Transfer-Encoding: binary');
|
|
|
|
header('Content-Type: application/force-download');
|
|
|
|
header('Content-Length: '.filesize($exportPath));
|
|
|
|
readfile($exportPath);
|
|
|
|
exit(0);
|
2018-05-18 21:03:01 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ajaxError('Unrecognised action or insufficient permissions');
|
2011-06-21 17:19:10 +08:00
|
|
|
?>
|