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
save_jpegs = monitor->GetOptSaveJPEGs();
Storage * storage = monitor->getStorage();
Storage *storage = monitor->getStorage();
if (monitor->GetOptVideoWriter() != 0) {
container = monitor->OutputContainer();
if ( container == "auto" || container == "" ) {
@ -133,22 +133,21 @@ Event::Event(
);
id = zmDbDoInsert(sql);
if ( !SetPath(storage) ) {
if (!SetPath(storage)) {
// Try another
Warning("Failed creating event dir at %s", storage->Path());
sql = stringtf("SELECT `Id` FROM `Storage` WHERE `Id` != %u", storage->Id());
if ( monitor->ServerId() )
if (monitor->ServerId())
sql += stringtf(" AND ServerId=%u", monitor->ServerId());
Debug(1, "%s", sql.c_str());
storage = nullptr;
MYSQL_RES *result = zmDbFetch(sql);
if ( result ) {
for ( int i = 0; MYSQL_ROW dbrow = mysql_fetch_row(result); i++ ) {
if (result) {
for (int i = 0; MYSQL_ROW dbrow = mysql_fetch_row(result); i++) {
storage = new Storage(atoi(dbrow[0]));
if ( SetPath(storage) )
if (SetPath(storage))
break;
delete storage;
storage = nullptr;
@ -156,18 +155,18 @@ Event::Event(
mysql_free_result(result);
result = nullptr;
}
if ( !storage ) {
if (!storage) {
Info("No valid local storage area found. Trying all other areas.");
// Try remote
sql = "SELECT `Id` FROM `Storage` WHERE ServerId IS NULL";
if ( monitor->ServerId() )
if (monitor->ServerId())
sql += stringtf(" OR ServerId != %u", monitor->ServerId());
result = zmDbFetch(sql);
if ( result ) {
if (result) {
for ( int i = 0; MYSQL_ROW dbrow = mysql_fetch_row(result); i++ ) {
storage = new Storage(atoi(dbrow[0]));
if ( SetPath(storage) )
if (SetPath(storage))
break;
delete storage;
storage = nullptr;
@ -176,7 +175,7 @@ Event::Event(
result = nullptr;
}
}
if ( !storage ) {
if (!storage) {
storage = new Storage();
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());
}
} // end if GetOptVideoWriter
if (storage != monitor->getStorage())
delete storage;
}
Event::~Event() {

View File

@ -43,11 +43,11 @@ Logger::IntMap Logger::smSyslogPriorities;
void Logger::usrHandler(int sig) {
Logger *logger = fetch();
if ( sig == SIGUSR1 )
if (sig == SIGUSR1)
logger->level(logger->level()+1);
else if ( sig == SIGUSR2 )
else if (sig == SIGUSR2)
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() :
@ -296,23 +296,23 @@ const std::string &Logger::id(const std::string &id) {
}
Logger::Level Logger::level(Logger::Level level) {
if ( level > NOOPT ) {
if (level > NOOPT) {
mLevel = limit(level);
mEffectiveLevel = NOLOG;
if ( mTerminalLevel > mEffectiveLevel )
if (mTerminalLevel > mEffectiveLevel)
mEffectiveLevel = mTerminalLevel;
if ( mDatabaseLevel > mEffectiveLevel )
if (mDatabaseLevel > mEffectiveLevel)
mEffectiveLevel = mDatabaseLevel;
if ( mFileLevel > mEffectiveLevel )
if (mFileLevel > mEffectiveLevel)
mEffectiveLevel = mFileLevel;
if ( mSyslogLevel > mEffectiveLevel )
if (mSyslogLevel > mEffectiveLevel)
mEffectiveLevel = mSyslogLevel;
if ( mEffectiveLevel > mLevel)
if (mEffectiveLevel > mLevel)
mEffectiveLevel = mLevel;
// DEBUG levels should flush
if ( mLevel > INFO )
if (mLevel > INFO)
mFlush = true;
}
return mLevel;

View File

@ -650,6 +650,23 @@ class Event extends ZM_Object {
}
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
?>

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="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;')?>"
title="<?php echo translate('Download'). ' ' . $Event->DefaultVideo() ?>"
download
<?php echo $Event->DefaultVideo() ? '' : 'style="display:none;"' ?>
><i class="fa fa-download"></i></a>

View File

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