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

@ -503,17 +503,17 @@ void Logger::logPrint( bool hex, const char * const filepath, const int line, co
); );
char *syslogStart = logPtr; char *syslogStart = logPtr;
va_start( argPtr, fstring ); va_start(argPtr, fstring);
if ( hex ) { if ( hex ) {
unsigned char *data = va_arg( argPtr, unsigned char * ); unsigned char *data = va_arg(argPtr, unsigned char *);
int len = va_arg( argPtr, int ); int len = va_arg(argPtr, int);
int i; int i;
logPtr += snprintf( logPtr, sizeof(logString)-(logPtr-logString), "%d:", len ); logPtr += snprintf(logPtr, sizeof(logString)-(logPtr-logString), "%d:", len);
for ( i = 0; i < len; i++ ) { for ( i = 0; i < len; i++ ) {
logPtr += snprintf( logPtr, sizeof(logString)-(logPtr-logString), " %02x", data[i] ); logPtr += snprintf(logPtr, sizeof(logString)-(logPtr-logString), " %02x", data[i]);
} }
} else { } else {
logPtr += vsnprintf( logPtr, sizeof(logString)-(logPtr-logString), fstring, argPtr ); logPtr += vsnprintf(logPtr, sizeof(logString)-(logPtr-logString), fstring, argPtr);
} }
va_end(argPtr); va_end(argPtr);
char *syslogEnd = logPtr; char *syslogEnd = logPtr;
@ -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

@ -23,7 +23,7 @@ switch ( $_REQUEST['task'] ) {
if ( !isset($levels[$_POST['level']]) ) if ( !isset($levels[$_POST['level']]) )
Panic("Unexpected logger level '".$_POST['level']."'"); Panic("Unexpected logger level '".$_POST['level']."'");
$level = $levels[$_POST['level']]; $level = $levels[$_POST['level']];
Logger::fetch()->logPrint( $level, $string, $file, $line ); Logger::fetch()->logPrint($level, $string, $file, $line);
} }
ajaxResponse(); ajaxResponse();
break; break;
@ -45,22 +45,22 @@ switch ( $_REQUEST['task'] ) {
$limit = 100; $limit = 100;
if ( isset($_REQUEST['limit']) ) { if ( isset($_REQUEST['limit']) ) {
if ( ( !is_integer( $_REQUEST['limit'] ) and !ctype_digit($_REQUEST['limit']) ) ) { if ( ( !is_integer($_REQUEST['limit']) and !ctype_digit($_REQUEST['limit']) ) ) {
Error('Invalid value for limit ' . $_REQUEST['limit'] ); Error('Invalid value for limit ' . $_REQUEST['limit']);
} else { } else {
$limit = $_REQUEST['limit']; $limit = $_REQUEST['limit'];
} }
} }
$sortField = 'TimeKey'; $sortField = 'TimeKey';
if ( isset($_REQUEST['sortField']) ) { if ( isset($_REQUEST['sortField']) ) {
if ( ! in_array( $_REQUEST['sortField'], $filterFields ) and ( $_REQUEST['sortField'] != 'TimeKey' ) ) { if ( !in_array($_REQUEST['sortField'], $filterFields) and ( $_REQUEST['sortField'] != 'TimeKey' ) ) {
Error("Invalid sort field " . $_REQUEST['sortField'] ); Error("Invalid sort field " . $_REQUEST['sortField']);
} else { } else {
$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');
$sql = 'SELECT * FROM Logs'; $sql = 'SELECT * FROM Logs';
@ -89,15 +89,18 @@ switch ( $_REQUEST['task'] ) {
} }
$options = array(); $options = array();
if ( count($where) ) if ( count($where) )
$sql.= ' WHERE '.join( ' AND ', $where ); $sql.= ' WHERE '.join(' AND ', $where);
$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 ) {
if ( ! isset( $options[$field] ) ) if ( !isset($options[$field]) )
$options[$field] = array(); $options[$field] = array();
$value = $log[$field]; $value = $log[$field];
@ -119,7 +122,7 @@ switch ( $_REQUEST['task'] ) {
ajaxResponse( array( ajaxResponse( array(
'updated' => preg_match('/%/', DATE_FMT_CONSOLE_LONG)?strftime(DATE_FMT_CONSOLE_LONG):date(DATE_FMT_CONSOLE_LONG), 'updated' => preg_match('/%/', DATE_FMT_CONSOLE_LONG)?strftime(DATE_FMT_CONSOLE_LONG):date(DATE_FMT_CONSOLE_LONG),
'total' => $total, 'total' => $total,
'available' => isset($available)?$available:$total, 'available' => isset($available) ? $available : $total,
'logs' => $logs, 'logs' => $logs,
'state' => logState(), 'state' => logState(),
'options' => $options 'options' => $options
@ -210,8 +213,8 @@ switch ( $_REQUEST['task'] ) {
if ( !($exportFP = fopen( $exportPath, "w" )) ) if ( !($exportFP = fopen( $exportPath, "w" )) )
Fatal("Unable to open log export file $exportPath"); Fatal("Unable to open log export file $exportPath");
$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'] = 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() : '';
$logs[] = $log; $logs[] = $log;
} }
@ -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,17 +392,17 @@ 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;
}); });
} }