Merge branch 'master' of github.com:ZoneMinder/ZoneMinder

This commit is contained in:
Isaac Connor 2018-08-17 12:57:27 -04:00
commit 871e3807e6
3 changed files with 45 additions and 36 deletions

View File

@ -540,7 +540,13 @@ void Logger::logPrint( bool hex, const char * const filepath, const int line, co
if ( ! db_mutex.trylock() ) { if ( ! db_mutex.trylock() ) {
mysql_real_escape_string( &dbconn, escapedString, syslogStart, strlen(syslogStart) ); mysql_real_escape_string( &dbconn, escapedString, syslogStart, strlen(syslogStart) );
snprintf( sql, sizeof(sql), "insert into Logs ( TimeKey, Component, ServerId, Pid, Level, Code, Message, File, Line ) values ( %ld.%06ld, '%s', %d, %d, %d, '%s', '%s', '%s', %d )", timeVal.tv_sec, timeVal.tv_usec, mId.c_str(), staticConfig.SERVER_ID, tid, level, classString, escapedString, file, line ); snprintf(sql, sizeof(sql),
"INSERT INTO Logs "
"( TimeKey, Component, ServerId, Pid, Level, Code, Message, File, Line )"
" VALUES "
"( %ld.%06ld, '%s', %d, %d, %d, '%s', '%s', '%s', %d )",
timeVal.tv_sec, timeVal.tv_usec, mId.c_str(), staticConfig.SERVER_ID, tid, level, classString, escapedString, file, line
);
if ( mysql_query(&dbconn, sql) ) { if ( mysql_query(&dbconn, sql) ) {
Level tempDatabaseLevel = mDatabaseLevel; Level tempDatabaseLevel = mDatabaseLevel;
databaseLevel(NOLOG); databaseLevel(NOLOG);

View File

@ -59,7 +59,7 @@ switch ( $_REQUEST['task'] ) {
$sortField = $_REQUEST['sortField']; $sortField = $_REQUEST['sortField'];
} }
} }
$sortOrder = (isset($_REQUEST['sortOrder']) and $_REQUEST['sortOrder']) == 'asc' ? 'asc':'desc'; $sortOrder = (isset($_REQUEST['sortOrder']) and ($_REQUEST['sortOrder'] == 'asc')) ? 'asc' : 'desc';
$filter = isset($_REQUEST['filter']) ? $_REQUEST['filter'] : array(); $filter = isset($_REQUEST['filter']) ? $_REQUEST['filter'] : array();
$total = dbFetchOne('SELECT count(*) AS Total FROM Logs', 'Total'); $total = dbFetchOne('SELECT count(*) AS Total FROM Logs', 'Total');
@ -93,7 +93,10 @@ switch ( $_REQUEST['task'] ) {
$sql .= ' ORDER BY '.$sortField.' '.$sortOrder.' LIMIT '.$limit; $sql .= ' ORDER BY '.$sortField.' '.$sortOrder.' LIMIT '.$limit;
$logs = array(); $logs = array();
foreach ( dbFetchAll($sql, NULL, $values) as $log ) { foreach ( dbFetchAll($sql, NULL, $values) as $log ) {
$log['DateTime'] = preg_replace('/^\d+/', strftime('%Y-%m-%d %H:%M:%S', intval($log['TimeKey'])), $log['TimeKey']);
$log['DateTime'] = strftime('%Y-%m-%d %H:%M:%S', intval($log['TimeKey']));
Warning("TimeKey: " . $log['TimeKey'] . 'Intval:'.intval($log['TimeKey']).' DateTime:'.$log['DateTime']);
#$log['DateTime'] = preg_replace('/^\d+/', strftime('%Y-%m-%d %H:%M:%S', intval($log['TimeKey'])), $log['TimeKey']);
$log['Server'] = ( $log['ServerId'] and isset($servers_by_Id[$log['ServerId']]) ) ? $servers_by_Id[$log['ServerId']]->Name() : ''; $log['Server'] = ( $log['ServerId'] and isset($servers_by_Id[$log['ServerId']]) ) ? $servers_by_Id[$log['ServerId']]->Name() : '';
$log['Message'] = preg_replace('/[\x00-\x1F\x7F-\xFF]/', '', $log['Message']); $log['Message'] = preg_replace('/[\x00-\x1F\x7F-\xFF]/', '', $log['Message']);
foreach( $filterFields as $field ) { foreach( $filterFields as $field ) {
@ -347,7 +350,7 @@ switch ( $_REQUEST['task'] ) {
</logexport>' ); </logexport>' );
break; break;
} }
$exportExt = "xml"; $exportExt = 'xml';
break; break;
} }
fclose( $exportFP ); fclose( $exportFP );
@ -363,10 +366,10 @@ switch ( $_REQUEST['task'] ) {
ajaxError('Insufficient permissions to download logs'); ajaxError('Insufficient permissions to download logs');
if ( empty($_REQUEST['key']) ) if ( empty($_REQUEST['key']) )
Fatal( "No log export key given" ); Fatal('No log export key given');
$exportKey = $_REQUEST['key']; $exportKey = $_REQUEST['key'];
if ( empty($_REQUEST['format']) ) if ( empty($_REQUEST['format']) )
Fatal( "No log export format given" ); Fatal('No log export format given');
$format = $_REQUEST['format']; $format = $_REQUEST['format'];
switch( $format ) { switch( $format ) {
@ -389,15 +392,15 @@ switch ( $_REQUEST['task'] ) {
$exportFile = "zm-log.$exportExt"; $exportFile = "zm-log.$exportExt";
$exportPath = ZM_PATH_SWAP."/zm-log-$exportKey.$exportExt"; $exportPath = ZM_PATH_SWAP."/zm-log-$exportKey.$exportExt";
header( "Pragma: public" ); header('Pragma: public');
header( "Expires: 0" ); header('Expires: 0');
header( "Cache-Control: must-revalidate, post-check=0, pre-check=0" ); header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header( "Cache-Control: private", false ); // required by certain browsers header('Cache-Control: private', false ); // required by certain browsers
header( "Content-Description: File Transfer" ); header('Content-Description: File Transfer');
header('Content-Disposition: attachment; filename="'.$exportFile.'"' ); header('Content-Disposition: attachment; filename="'.$exportFile.'"' );
header( "Content-Transfer-Encoding: binary" ); header('Content-Transfer-Encoding: binary');
header( "Content-Type: application/force-download" ); header('Content-Type: application/force-download');
header( "Content-Length: ".filesize($exportPath) ); header('Content-Length: '.filesize($exportPath));
readfile($exportPath); readfile($exportPath);
exit(0); exit(0);
break; break;

View File

@ -199,7 +199,7 @@ if ( currentView != 'none' && currentView != 'login' ) {
console.log( "Request Failed: " + err ); console.log( "Request Failed: " + err );
// The idea is that this should only fail due to auth, so reload the page // The idea is that this should only fail due to auth, so reload the page
// which should go to login if it can't stay logged in. // which should go to login if it can't stay logged in.
window.location.href = thisUrl; window.location.href = thisUrl+'?view='+currentView;
}); });
} }