Merge branch 'master' into add_manufacturer_model_to_monitors

This commit is contained in:
Isaac Connor 2021-11-15 09:47:34 -05:00
commit 71c29afa7b
5 changed files with 42 additions and 22 deletions

View File

@ -103,7 +103,7 @@ Event::Event(
// Copy it in case opening the mp4 doesn't work we can set it to another value // Copy it in case opening the mp4 doesn't work we can set it to another value
save_jpegs = monitor->GetOptSaveJPEGs(); save_jpegs = monitor->GetOptSaveJPEGs();
Storage * storage = monitor->getStorage(); Storage *storage = monitor->getStorage();
if (monitor->GetOptVideoWriter() != 0) { if (monitor->GetOptVideoWriter() != 0) {
container = monitor->OutputContainer(); container = monitor->OutputContainer();
if ( container == "auto" || container == "" ) { if ( container == "auto" || container == "" ) {
@ -133,22 +133,21 @@ Event::Event(
); );
id = zmDbDoInsert(sql); id = zmDbDoInsert(sql);
if ( !SetPath(storage) ) { if (!SetPath(storage)) {
// Try another // Try another
Warning("Failed creating event dir at %s", storage->Path()); Warning("Failed creating event dir at %s", storage->Path());
sql = stringtf("SELECT `Id` FROM `Storage` WHERE `Id` != %u", storage->Id()); sql = stringtf("SELECT `Id` FROM `Storage` WHERE `Id` != %u", storage->Id());
if ( monitor->ServerId() ) if (monitor->ServerId())
sql += stringtf(" AND ServerId=%u", monitor->ServerId()); sql += stringtf(" AND ServerId=%u", monitor->ServerId());
Debug(1, "%s", sql.c_str());
storage = nullptr; storage = nullptr;
MYSQL_RES *result = zmDbFetch(sql); MYSQL_RES *result = zmDbFetch(sql);
if ( result ) { if (result) {
for ( int i = 0; MYSQL_ROW dbrow = mysql_fetch_row(result); i++ ) { for (int i = 0; MYSQL_ROW dbrow = mysql_fetch_row(result); i++) {
storage = new Storage(atoi(dbrow[0])); storage = new Storage(atoi(dbrow[0]));
if ( SetPath(storage) ) if (SetPath(storage))
break; break;
delete storage; delete storage;
storage = nullptr; storage = nullptr;
@ -156,18 +155,18 @@ Event::Event(
mysql_free_result(result); mysql_free_result(result);
result = nullptr; result = nullptr;
} }
if ( !storage ) { if (!storage) {
Info("No valid local storage area found. Trying all other areas."); Info("No valid local storage area found. Trying all other areas.");
// Try remote // Try remote
sql = "SELECT `Id` FROM `Storage` WHERE ServerId IS NULL"; sql = "SELECT `Id` FROM `Storage` WHERE ServerId IS NULL";
if ( monitor->ServerId() ) if (monitor->ServerId())
sql += stringtf(" OR ServerId != %u", monitor->ServerId()); sql += stringtf(" OR ServerId != %u", monitor->ServerId());
result = zmDbFetch(sql); result = zmDbFetch(sql);
if ( result ) { if (result) {
for ( int i = 0; MYSQL_ROW dbrow = mysql_fetch_row(result); i++ ) { for ( int i = 0; MYSQL_ROW dbrow = mysql_fetch_row(result); i++ ) {
storage = new Storage(atoi(dbrow[0])); storage = new Storage(atoi(dbrow[0]));
if ( SetPath(storage) ) if (SetPath(storage))
break; break;
delete storage; delete storage;
storage = nullptr; storage = nullptr;
@ -176,7 +175,7 @@ Event::Event(
result = nullptr; result = nullptr;
} }
} }
if ( !storage ) { if (!storage) {
storage = new Storage(); storage = new Storage();
Warning("Failed to find a storage area to save events."); Warning("Failed to find a storage area to save events.");
} }
@ -218,6 +217,8 @@ Event::Event(
Debug(1, "Video file is %s", video_file.c_str()); Debug(1, "Video file is %s", video_file.c_str());
} }
} // end if GetOptVideoWriter } // end if GetOptVideoWriter
if (storage != monitor->getStorage())
delete storage;
} }
Event::~Event() { Event::~Event() {

View File

@ -43,11 +43,11 @@ Logger::IntMap Logger::smSyslogPriorities;
void Logger::usrHandler(int sig) { void Logger::usrHandler(int sig) {
Logger *logger = fetch(); Logger *logger = fetch();
if ( sig == SIGUSR1 ) if (sig == SIGUSR1)
logger->level(logger->level()+1); logger->level(logger->level()+1);
else if ( sig == SIGUSR2 ) else if (sig == SIGUSR2)
logger->level(logger->level()-1); logger->level(logger->level()-1);
Info("Logger - Level changed to %d", logger->level()); Info("Logger - Level changed to %d %s", logger->level(), smCodes[logger->level()].c_str());
} }
Logger::Logger() : Logger::Logger() :
@ -296,23 +296,23 @@ const std::string &Logger::id(const std::string &id) {
} }
Logger::Level Logger::level(Logger::Level level) { Logger::Level Logger::level(Logger::Level level) {
if ( level > NOOPT ) { if (level > NOOPT) {
mLevel = limit(level); mLevel = limit(level);
mEffectiveLevel = NOLOG; mEffectiveLevel = NOLOG;
if ( mTerminalLevel > mEffectiveLevel ) if (mTerminalLevel > mEffectiveLevel)
mEffectiveLevel = mTerminalLevel; mEffectiveLevel = mTerminalLevel;
if ( mDatabaseLevel > mEffectiveLevel ) if (mDatabaseLevel > mEffectiveLevel)
mEffectiveLevel = mDatabaseLevel; mEffectiveLevel = mDatabaseLevel;
if ( mFileLevel > mEffectiveLevel ) if (mFileLevel > mEffectiveLevel)
mEffectiveLevel = mFileLevel; mEffectiveLevel = mFileLevel;
if ( mSyslogLevel > mEffectiveLevel ) if (mSyslogLevel > mEffectiveLevel)
mEffectiveLevel = mSyslogLevel; mEffectiveLevel = mSyslogLevel;
if ( mEffectiveLevel > mLevel) if (mEffectiveLevel > mLevel)
mEffectiveLevel = mLevel; mEffectiveLevel = mLevel;
// DEBUG levels should flush // DEBUG levels should flush
if ( mLevel > INFO ) if (mLevel > INFO)
mFlush = true; mFlush = true;
} }
return mLevel; return mLevel;

View File

@ -650,6 +650,23 @@ class Event extends ZM_Object {
} }
return false; return false;
} }
function canEdit($u=null) {
global $user;
if (!$u) $u=$user;
if (!$u) {
# auth turned on and not logged in
return false;
}
if (!empty($u['MonitorIds']) ) {
if (!in_array($this->{'MonitorId'}, explode(',', $u['MonitorIds']))) {
return false;
}
}
if ($u['Events'] != 'Edit') {
return false;
}
return true;
}
} # end class } # end class
?> ?>

View File

@ -150,6 +150,7 @@ if ( $Event->Id() and !file_exists($Event->Path()) )
<button id="editBtn" class="btn btn-normal" data-toggle="tooltip" data-placement="top" title="<?php echo translate('Edit') ?>" disabled><i class="fa fa-pencil"></i></button> <button id="editBtn" class="btn btn-normal" data-toggle="tooltip" data-placement="top" title="<?php echo translate('Edit') ?>" disabled><i class="fa fa-pencil"></i></button>
<button id="exportBtn" class="btn btn-normal" data-toggle="tooltip" data-placement="top" title="<?php echo translate('Export') ?>"><i class="fa fa-external-link"></i></button> <button id="exportBtn" class="btn btn-normal" data-toggle="tooltip" data-placement="top" title="<?php echo translate('Export') ?>"><i class="fa fa-external-link"></i></button>
<a id="downloadBtn" class="btn btn-normal" href="<?php echo $Event->getStreamSrc(array('mode'=>'mp4'),'&amp;')?>" <a id="downloadBtn" class="btn btn-normal" href="<?php echo $Event->getStreamSrc(array('mode'=>'mp4'),'&amp;')?>"
title="<?php echo translate('Download'). ' ' . $Event->DefaultVideo() ?>"
download download
<?php echo $Event->DefaultVideo() ? '' : 'style="display:none;"' ?> <?php echo $Event->DefaultVideo() ? '' : 'style="display:none;"' ?>
><i class="fa fa-download"></i></a> ><i class="fa fa-download"></i></a>

View File

@ -657,6 +657,7 @@ function getFrameResponse(respObj, respText) {
function frameQuery(eventId, frameId, loadImage) { function frameQuery(eventId, frameId, loadImage) {
var data = {}; var data = {};
if (auth_hash) data.auth = auth_hash;
data.loopback = loadImage; data.loopback = loadImage;
data.id = {eventId, frameId}; data.id = {eventId, frameId};