mirror of
https://github.com/ElvishArtisan/rivendell.git
synced 2025-10-11 00:53:53 +02:00
2017-12-20 Fred Gleason <fredg@paravelsystems.com>
* Added a 'LOGS.LOCK_GUID' field to the database. * Incremented the database version to 274. * Added a 'LockLog' call to the Web API.
This commit is contained in:
@@ -24,18 +24,19 @@
|
||||
#include <fcntl.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <rdconf.h>
|
||||
#include <rdcreate_log.h>
|
||||
#include <rddb.h>
|
||||
#include <rdescape_string.h>
|
||||
#include <rdformpost.h>
|
||||
#include <rdweb.h>
|
||||
#include <rduser.h>
|
||||
#include <rdlog.h>
|
||||
#include <rdlog_event.h>
|
||||
#include <rdlog_line.h>
|
||||
#include <rdconf.h>
|
||||
#include <rdescape_string.h>
|
||||
#include <rdloglock.h>
|
||||
#include <rduser.h>
|
||||
#include <rdweb.h>
|
||||
|
||||
#include <rdxport.h>
|
||||
#include "rdxport.h"
|
||||
|
||||
void Xport::AddLog()
|
||||
{
|
||||
@@ -541,3 +542,115 @@ bool Xport::ServiceUserValid(const QString &svc_name)
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
void Xport::LockLog()
|
||||
{
|
||||
RDLog *log;
|
||||
QString log_name="";
|
||||
Xport::LockLogOperation op_type=Xport::LockLogClear;
|
||||
QString op_string;
|
||||
QString lock_guid;
|
||||
QString username;
|
||||
QString stationname;
|
||||
QHostAddress addr;
|
||||
|
||||
//
|
||||
// Get Options
|
||||
//
|
||||
if(!xport_post->getValue("LOG_NAME",&log_name)) {
|
||||
XmlExit("Missing LOG_NAME",400,"logs.cpp",LINE_NUMBER);
|
||||
}
|
||||
if(!xport_post->getValue("OPERATION",&op_string)) {
|
||||
XmlExit("Missing OPERATION",400,"logs.cpp",LINE_NUMBER);
|
||||
}
|
||||
if(op_string.lower()=="create") {
|
||||
op_type=Xport::LockLogCreate;
|
||||
}
|
||||
else {
|
||||
if(op_string.lower()=="update") {
|
||||
op_type=Xport::LockLogUpdate;
|
||||
}
|
||||
else {
|
||||
if(op_string.lower()=="clear") {
|
||||
op_type=Xport::LockLogClear;
|
||||
}
|
||||
else {
|
||||
XmlExit("Unrecognized OPERATION type",400,"logs.cpp",LINE_NUMBER);
|
||||
}
|
||||
}
|
||||
}
|
||||
if(!xport_post->getValue("LOCK_GUID",&lock_guid)) {
|
||||
XmlExit("Missing LOCK_GUID",400,"logs.cpp",LINE_NUMBER);
|
||||
}
|
||||
|
||||
//
|
||||
// Verify that log exists
|
||||
//
|
||||
log=new RDLog(log_name);
|
||||
if((!ServiceUserValid(log->service()))||(!log->exists())) {
|
||||
delete log;
|
||||
XmlExit("No such log",404,"logs.cpp",LINE_NUMBER);
|
||||
}
|
||||
|
||||
printf("Content-type: application/xml\n");
|
||||
printf("Status: 200\n\n");
|
||||
switch(op_type) {
|
||||
case Xport::LockLogCreate:
|
||||
username=xport_user->name();
|
||||
stationname=xport_remote_hostname;
|
||||
addr=xport_remote_address;
|
||||
lock_guid=RDLogLock::makeGuid(xport_remote_hostname);
|
||||
if(RDLogLock::tryLock(&username,&stationname,&addr,log_name,lock_guid)) {
|
||||
printf("%s",(const char *)LogLockXml(true,log_name,lock_guid,"","",addr));
|
||||
}
|
||||
else {
|
||||
printf("%s",(const char *)LogLockXml(false,log_name,"",username,
|
||||
stationname,addr));
|
||||
}
|
||||
Exit(0);
|
||||
break;
|
||||
|
||||
case Xport::LockLogUpdate:
|
||||
RDLogLock::updateLock(log_name,lock_guid);
|
||||
printf("%s",(const char *)LogLockXml(true,log_name,lock_guid,"","",addr));
|
||||
Exit(0);
|
||||
break;
|
||||
|
||||
case Xport::LockLogClear:
|
||||
RDLogLock::clearLock(lock_guid);
|
||||
printf("%s",(const char *)LogLockXml(true,log_name,lock_guid,"","",addr));
|
||||
Exit(0);
|
||||
break;
|
||||
}
|
||||
|
||||
XmlExit("Unexpected exit",500);
|
||||
}
|
||||
|
||||
|
||||
QString Xport::LogLockXml(bool result,const QString &log_name,
|
||||
const QString &guid,const QString &username,
|
||||
const QString &stationname,
|
||||
const QHostAddress addr) const
|
||||
{
|
||||
QString xml="";
|
||||
|
||||
xml+="<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n";
|
||||
xml+="<logLock>\n";
|
||||
xml+=RDXmlField("result",result);
|
||||
xml+=RDXmlField("logName",log_name);
|
||||
if(!guid.isEmpty()) {
|
||||
xml+=RDXmlField("lockGuid",guid);
|
||||
}
|
||||
if(!username.isEmpty()) {
|
||||
xml+=RDXmlField("userName",username);
|
||||
}
|
||||
if(!stationname.isEmpty()) {
|
||||
xml+=RDXmlField("stationName",stationname);
|
||||
}
|
||||
xml+=RDXmlField("address",addr.toString());
|
||||
xml+=RDXmlField("lockTimeout",RD_LOG_LOCK_TIMEOUT);
|
||||
xml+="</logLock>\n";
|
||||
|
||||
return xml;
|
||||
}
|
||||
|
@@ -119,6 +119,15 @@ Xport::Xport(QObject *parent)
|
||||
db->removeDatabase(xport_config->mysqlDbname());
|
||||
Exit(0);
|
||||
}
|
||||
if(getenv("REMOTE_ADDR")!=NULL) {
|
||||
xport_remote_address.setAddress(getenv("REMOTE_ADDR"));
|
||||
}
|
||||
if(getenv("REMOTE_HOST")!=NULL) {
|
||||
xport_remote_hostname=getenv("REMOTE_HOST");
|
||||
}
|
||||
if(xport_remote_hostname.isEmpty()) {
|
||||
xport_remote_hostname=xport_remote_address.toString();
|
||||
}
|
||||
|
||||
//
|
||||
// Load System Settings
|
||||
@@ -272,6 +281,10 @@ Xport::Xport(QObject *parent)
|
||||
ListSystemSettings();
|
||||
break;
|
||||
|
||||
case RDXPORT_COMMAND_LOCKLOG:
|
||||
LockLog();
|
||||
break;
|
||||
|
||||
case RDXPORT_COMMAND_REHASH:
|
||||
Rehash();
|
||||
break;
|
||||
|
@@ -39,6 +39,7 @@
|
||||
class Xport : public QObject
|
||||
{
|
||||
public:
|
||||
enum LockLogOperation {LockLogCreate=0,LockLogUpdate=1,LockLogClear=2};
|
||||
Xport(QObject *parent=0);
|
||||
|
||||
private:
|
||||
@@ -80,6 +81,10 @@ class Xport : public QObject
|
||||
void ListCartSchedCodes();
|
||||
void ListServices();
|
||||
void ListSystemSettings();
|
||||
void LockLog();
|
||||
QString LogLockXml(bool result,const QString &log_name,const QString &guid,
|
||||
const QString &username,const QString &stationname,
|
||||
const QHostAddress addr) const;
|
||||
void Exit(int code);
|
||||
void XmlExit(const QString &msg,int code,
|
||||
const QString &srcfile="",int line=-1,
|
||||
@@ -89,6 +94,8 @@ class Xport : public QObject
|
||||
RDConfig *xport_config;
|
||||
RDSystem *xport_system;
|
||||
RDStation *xport_station;
|
||||
QString xport_remote_hostname;
|
||||
QHostAddress xport_remote_address;
|
||||
};
|
||||
|
||||
|
||||
|
@@ -51,6 +51,7 @@ install-exec-am:
|
||||
cp listschedcodes.html $(DESTDIR)@libexecdir@
|
||||
cp listservices.html $(DESTDIR)@libexecdir@
|
||||
cp listsystemsettings.html $(DESTDIR)@libexecdir@
|
||||
cp locklog.html $(DESTDIR)@libexecdir@
|
||||
cp rehash.html $(DESTDIR)@libexecdir@
|
||||
cp removecart.html $(DESTDIR)@libexecdir@
|
||||
cp removecut.html $(DESTDIR)@libexecdir@
|
||||
@@ -89,6 +90,7 @@ uninstall-local:
|
||||
rm -f $(DESTDIR)@libexecdir@/listschedcodes.html
|
||||
rm -f $(DESTDIR)@libexecdir@/listservices.html
|
||||
rm -f $(DESTDIR)@libexecdir@/listsystemsettings.html
|
||||
rm -f $(DESTDIR)@libexecdir@/locklog.html
|
||||
rm -f $(DESTDIR)@libexecdir@/rehash.html
|
||||
rm -f $(DESTDIR)@libexecdir@/removecart.html
|
||||
rm -f $(DESTDIR)@libexecdir@/removecut.html
|
||||
@@ -126,6 +128,7 @@ EXTRA_DIST = addcart.html\
|
||||
listschedcodes.html\
|
||||
listservices.html\
|
||||
listsystemsettings.html\
|
||||
locklog.html\
|
||||
rehash.html\
|
||||
removecart.html\
|
||||
removecut.html\
|
||||
|
48
web/tests/locklog.html
Normal file
48
web/tests/locklog.html
Normal file
@@ -0,0 +1,48 @@
|
||||
<html>
|
||||
<head>
|
||||
<title>Rivendell LOCKLOG Service Test Harness</title>
|
||||
<body>
|
||||
<form action="/rd-bin/rdxport.cgi" method="post" enctype="multipart/form-data">
|
||||
<input type="hidden" name="COMMAND" value="34">
|
||||
<table cellpadding="0" cellspacing="2" border="0">
|
||||
<tr>
|
||||
<td align="right">LOGIN NAME:</td>
|
||||
<td><input type="text" name="LOGIN_NAME" size="20" maxlength="255"></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="right">PASSWORD:</td>
|
||||
<td><input type="password" name="PASSWORD" size="20" maxlength="32"></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="right">TICKET:</td>
|
||||
<td><input type="text" name="TICKET" size="40" maxlength="40"></td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td align="right">OPERATION:</td>
|
||||
<td>
|
||||
<select name="OPERATION">
|
||||
<option value="CREATE">CREATE</option>
|
||||
<option value="UPDATE">UPDATE</option>
|
||||
<option value="CLEAR">CLEAR</option>
|
||||
</select>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="right">LOG_NAME:</td>
|
||||
<td><input type="text" name="LOG_NAME" size="40" maxlength="64"></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="right">LOCK_GUID:</td>
|
||||
<td><input type="text" name="LOCK_GUID" size="40" maxlength="82"></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td colspan="2" align="right"> </td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td colspan="2" align="right"><input type="submit" value="OK"></td>
|
||||
</tr>
|
||||
</table>
|
||||
</form>
|
||||
</body>
|
||||
</html>
|
Reference in New Issue
Block a user