mirror of
https://github.com/ElvishArtisan/rivendell.git
synced 2025-07-09 17:07:44 +02:00
2017-12-21 Fred Gleason <fredg@paravelsystems.com>
* Added log locking logic to the 'SaveLog' Web API call.
This commit is contained in:
parent
0224380581
commit
97a6045992
@ -16533,3 +16533,5 @@
|
|||||||
2017-12-20 Fred Gleason <fredg@paravelsystems.com>
|
2017-12-20 Fred Gleason <fredg@paravelsystems.com>
|
||||||
* Cleaned up 'log in use" messages in rdlogedit(1) and
|
* Cleaned up 'log in use" messages in rdlogedit(1) and
|
||||||
rdclilogedit(1).
|
rdclilogedit(1).
|
||||||
|
2017-12-21 Fred Gleason <fredg@paravelsystems.com>
|
||||||
|
* Added log locking logic to the 'SaveLog' Web API call.
|
||||||
|
@ -2980,6 +2980,18 @@
|
|||||||
Mandatory. String, 10 characters max.
|
Mandatory. String, 10 characters max.
|
||||||
</entry>
|
</entry>
|
||||||
</row>
|
</row>
|
||||||
|
<row>
|
||||||
|
<entry>
|
||||||
|
LOCK_GUID
|
||||||
|
</entry>
|
||||||
|
<entry>
|
||||||
|
The GUID string, obtained from the LockLog API call.
|
||||||
|
</entry>
|
||||||
|
<entry>
|
||||||
|
Optional. If not provided, the service will attempt to acquire
|
||||||
|
a lock before processing the save.
|
||||||
|
</entry>
|
||||||
|
</row>
|
||||||
<row>
|
<row>
|
||||||
<entry>
|
<entry>
|
||||||
DESCRIPTION
|
DESCRIPTION
|
||||||
|
@ -174,6 +174,26 @@ void RDLogLock::clearLock(const QString &guid)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool RDLogLock::validateLock(const QString &log_name,const QString &guid)
|
||||||
|
{
|
||||||
|
QString sql;
|
||||||
|
RDSqlQuery *q;
|
||||||
|
bool ret=false;
|
||||||
|
QDateTime now=QDateTime::currentDateTime();
|
||||||
|
|
||||||
|
sql=QString("select NAME from LOGS where ")+
|
||||||
|
"(NAME=\""+RDEscapeString(log_name)+"\")&&"+
|
||||||
|
"(LOCK_GUID=\""+RDEscapeString(guid)+"\")&&"+
|
||||||
|
"(LOCK_DATETIME>\""+RDEscapeString(now.addSecs(-RD_LOG_LOCK_TIMEOUT/1000).
|
||||||
|
toString("yyyy-MM-dd hh:mm:ss"))+"\")";
|
||||||
|
q=new RDSqlQuery(sql);
|
||||||
|
ret=q->first();
|
||||||
|
delete q;
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
QString RDLogLock::makeGuid(const QString &stationname)
|
QString RDLogLock::makeGuid(const QString &stationname)
|
||||||
{
|
{
|
||||||
return stationname+QDateTime::currentDateTime().
|
return stationname+QDateTime::currentDateTime().
|
||||||
|
@ -43,6 +43,7 @@ class RDLogLock : public QObject
|
|||||||
const QString &log_name,const QString &guid);
|
const QString &log_name,const QString &guid);
|
||||||
static void updateLock(const QString &log_name,const QString &guid);
|
static void updateLock(const QString &log_name,const QString &guid);
|
||||||
static void clearLock(const QString &guid);
|
static void clearLock(const QString &guid);
|
||||||
|
static bool validateLock(const QString &log_name,const QString &guid);
|
||||||
static QString makeGuid(const QString &stationname);
|
static QString makeGuid(const QString &stationname);
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
|
@ -246,6 +246,7 @@ void Xport::SaveLog()
|
|||||||
|
|
||||||
QString log_name;
|
QString log_name;
|
||||||
QString service_name;
|
QString service_name;
|
||||||
|
QString lock_guid;
|
||||||
QString description;
|
QString description;
|
||||||
QDate purge_date;
|
QDate purge_date;
|
||||||
bool auto_refresh;
|
bool auto_refresh;
|
||||||
@ -263,6 +264,7 @@ void Xport::SaveLog()
|
|||||||
XmlExit("Missing SERVICE_NAME",400,"logs.cpp",LINE_NUMBER);
|
XmlExit("Missing SERVICE_NAME",400,"logs.cpp",LINE_NUMBER);
|
||||||
}
|
}
|
||||||
GetLogService(service_name);
|
GetLogService(service_name);
|
||||||
|
xport_post->getValue("LOCK_GUID",&lock_guid);
|
||||||
if(!xport_post->getValue("DESCRIPTION",&description)) {
|
if(!xport_post->getValue("DESCRIPTION",&description)) {
|
||||||
XmlExit("Missing DESCRIPTION",400,"logs.cpp",LINE_NUMBER);
|
XmlExit("Missing DESCRIPTION",400,"logs.cpp",LINE_NUMBER);
|
||||||
}
|
}
|
||||||
@ -495,55 +497,46 @@ void Xport::SaveLog()
|
|||||||
if(!log->exists()) {
|
if(!log->exists()) {
|
||||||
XmlExit("No such log",404,"logs.cpp",LINE_NUMBER);
|
XmlExit("No such log",404,"logs.cpp",LINE_NUMBER);
|
||||||
}
|
}
|
||||||
log->setService(service_name);
|
if(lock_guid.isEmpty()) {
|
||||||
log->setDescription(description);
|
QString username=xport_user->name();
|
||||||
log->setPurgeDate(purge_date);
|
QString stationname=xport_remote_hostname;
|
||||||
log->setAutoRefresh(auto_refresh);
|
QHostAddress addr=xport_remote_address;
|
||||||
log->setStartDate(start_date);
|
lock_guid=RDLogLock::makeGuid(stationname);
|
||||||
log->setEndDate(end_date);
|
if(RDLogLock::tryLock(&username,&stationname,&addr,log_name,lock_guid)) {
|
||||||
log->setModifiedDatetime(QDateTime::currentDateTime());
|
log->setService(service_name);
|
||||||
|
log->setDescription(description);
|
||||||
logevt->save(xport_config);
|
log->setPurgeDate(purge_date);
|
||||||
|
log->setAutoRefresh(auto_refresh);
|
||||||
|
log->setStartDate(start_date);
|
||||||
|
log->setEndDate(end_date);
|
||||||
|
log->setModifiedDatetime(QDateTime::currentDateTime());
|
||||||
|
logevt->save(xport_config);
|
||||||
|
RDLogLock::clearLock(lock_guid);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
XmlExit("unable to get log lock",404);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
if(RDLogLock::validateLock(log_name,lock_guid)) {
|
||||||
|
log->setService(service_name);
|
||||||
|
log->setDescription(description);
|
||||||
|
log->setPurgeDate(purge_date);
|
||||||
|
log->setAutoRefresh(auto_refresh);
|
||||||
|
log->setStartDate(start_date);
|
||||||
|
log->setEndDate(end_date);
|
||||||
|
log->setModifiedDatetime(QDateTime::currentDateTime());
|
||||||
|
logevt->save(xport_config);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
XmlExit("invalid log lock",400);
|
||||||
|
}
|
||||||
|
}
|
||||||
XmlExit(QString().sprintf("OK Saved %d events",logevt->size()),
|
XmlExit(QString().sprintf("OK Saved %d events",logevt->size()),
|
||||||
200,"logs.cpp",LINE_NUMBER);
|
200,"logs.cpp",LINE_NUMBER);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
RDSvc *Xport::GetLogService(const QString &svc_name)
|
|
||||||
{
|
|
||||||
QString sql=QString("select SERVICE_NAME from USER_SERVICE_PERMS where ")+
|
|
||||||
"(USER_NAME=\""+RDEscapeString(xport_user->name())+"\")&&"+
|
|
||||||
"(SERVICE_NAME=\""+RDEscapeString(svc_name)+"\")";
|
|
||||||
RDSqlQuery *q=new RDSqlQuery(sql);
|
|
||||||
if(!q->first()) {
|
|
||||||
XmlExit("No such service",404,"logs.cpp",LINE_NUMBER);
|
|
||||||
}
|
|
||||||
delete q;
|
|
||||||
RDSvc *svc=new RDSvc(svc_name,xport_station,xport_config);
|
|
||||||
if(!svc->exists()) {
|
|
||||||
XmlExit("No such service",404,"logs.cpp",LINE_NUMBER);
|
|
||||||
}
|
|
||||||
|
|
||||||
return svc;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
bool Xport::ServiceUserValid(const QString &svc_name)
|
|
||||||
{
|
|
||||||
bool ret=false;
|
|
||||||
|
|
||||||
QString sql=QString("select SERVICE_NAME from USER_SERVICE_PERMS where ")+
|
|
||||||
"(SERVICE_NAME=\""+RDEscapeString(svc_name)+"\")&&"+
|
|
||||||
"(USER_NAME=\""+RDEscapeString(xport_user->name())+"\")";
|
|
||||||
RDSqlQuery *q=new RDSqlQuery(sql);
|
|
||||||
ret=q->first();
|
|
||||||
delete q;
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void Xport::LockLog()
|
void Xport::LockLog()
|
||||||
{
|
{
|
||||||
RDLog *log;
|
RDLog *log;
|
||||||
@ -628,6 +621,40 @@ void Xport::LockLog()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
RDSvc *Xport::GetLogService(const QString &svc_name)
|
||||||
|
{
|
||||||
|
QString sql=QString("select SERVICE_NAME from USER_SERVICE_PERMS where ")+
|
||||||
|
"(USER_NAME=\""+RDEscapeString(xport_user->name())+"\")&&"+
|
||||||
|
"(SERVICE_NAME=\""+RDEscapeString(svc_name)+"\")";
|
||||||
|
RDSqlQuery *q=new RDSqlQuery(sql);
|
||||||
|
if(!q->first()) {
|
||||||
|
XmlExit("No such service",404,"logs.cpp",LINE_NUMBER);
|
||||||
|
}
|
||||||
|
delete q;
|
||||||
|
RDSvc *svc=new RDSvc(svc_name,xport_station,xport_config);
|
||||||
|
if(!svc->exists()) {
|
||||||
|
XmlExit("No such service",404,"logs.cpp",LINE_NUMBER);
|
||||||
|
}
|
||||||
|
|
||||||
|
return svc;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool Xport::ServiceUserValid(const QString &svc_name)
|
||||||
|
{
|
||||||
|
bool ret=false;
|
||||||
|
|
||||||
|
QString sql=QString("select SERVICE_NAME from USER_SERVICE_PERMS where ")+
|
||||||
|
"(SERVICE_NAME=\""+RDEscapeString(svc_name)+"\")&&"+
|
||||||
|
"(USER_NAME=\""+RDEscapeString(xport_user->name())+"\")";
|
||||||
|
RDSqlQuery *q=new RDSqlQuery(sql);
|
||||||
|
ret=q->first();
|
||||||
|
delete q;
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
QString Xport::LogLockXml(bool result,const QString &log_name,
|
QString Xport::LogLockXml(bool result,const QString &log_name,
|
||||||
const QString &guid,const QString &username,
|
const QString &guid,const QString &username,
|
||||||
const QString &stationname,
|
const QString &stationname,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user