1 #include "otsdaq/WebUsersUtilities/RemoteWebUsers.h"
3 #include "otsdaq/CgiDataUtilities/CgiDataUtilities.h"
4 #include "otsdaq/SOAPUtilities/SOAPCommand.h"
5 #include "otsdaq/SOAPUtilities/SOAPParameters.h"
6 #include "otsdaq/SOAPUtilities/SOAPUtilities.h"
7 #include "otsdaq/XmlUtilities/HttpXmlDocument.h"
14 #include "otsdaq/SupervisorInfo/AllSupervisorInfo.h"
19 #define __MF_SUBJECT__ "RemoteWebUsers"
31 xdaq::Application* application,
32 XDAQ_CONST_CALL xdaq::ApplicationDescriptor* gatewaySupervisorDescriptor)
34 , gatewaySupervisorDescriptor_(gatewaySupervisorDescriptor)
36 ActiveUserLastUpdateTime_ = 0;
45 std::ostringstream* out,
54 XDAQ_CONST_CALL xdaq::ApplicationDescriptor* gatewaySupervisor;
57 xoap::MessageReference retMsg;
65 if(allSupervisorInfo.
isWizardMode() || allSupervisorInfo.isMacroMakerMode())
68 std::string sequence =
71 if(!sequence.length())
73 __COUT_ERR__ <<
"Invalid access attempt (@" << userInfo.ip_ <<
")."
75 *out << WebUsers::REQ_NO_LOGIN_RESPONSE;
77 goto HANDLE_ACCESS_FAILURE;
83 gatewaySupervisor = allSupervisorInfo.getWizardInfo().
getDescriptor();
85 gatewaySupervisor = allSupervisorInfo.getAllMacroMakerTypeSupervisorInfo()
87 ->second.getDescriptor();
89 if(!gatewaySupervisor)
91 __COUT_ERR__ <<
"Missing gateway supervisor." << std::endl;
92 *out << WebUsers::REQ_NO_LOGIN_RESPONSE;
94 goto HANDLE_ACCESS_FAILURE;
97 parameters.addParameter(
"sequence", sequence);
98 parameters.addParameter(
"IPAddress", userInfo.ip_);
99 retMsg = SOAPMessenger::sendWithSOAPReply(
100 gatewaySupervisor,
"SupervisorSequenceCheck", parameters);
102 parameters.addParameter(
"Permissions");
103 SOAPUtilities::receive(retMsg, parameters);
108 cgi, out, xmldoc, userInfo,
true , sequence))
111 goto HANDLE_ACCESS_FAILURE;
116 gatewaySupervisor = allSupervisorInfo.getGatewayInfo().
getDescriptor();
118 if(!gatewaySupervisor)
120 __COUT_ERR__ <<
"Missing gateway supervisor." << std::endl;
121 *out << WebUsers::REQ_NO_LOGIN_RESPONSE;
122 goto HANDLE_ACCESS_FAILURE;
126 parameters.addParameter(
"CookieCode", userInfo.cookieCode_);
127 parameters.addParameter(
"RefreshOption", userInfo.automatedCommand_ ?
"0" :
"1");
128 parameters.addParameter(
"IPAddress", userInfo.ip_);
130 retMsg = SOAPMessenger::sendWithSOAPReply(
131 gatewaySupervisor,
"SupervisorCookieCheck", parameters);
134 parameters.addParameter(
"CookieCode");
135 parameters.addParameter(
"Permissions");
136 parameters.addParameter(
"UserGroups");
137 parameters.addParameter(
"UserWithLock");
138 parameters.addParameter(
"Username");
139 parameters.addParameter(
"DisplayName");
141 SOAPUtilities::receive(retMsg, parameters);
146 userInfo.cookieCode_ = parameters.getValue(
"CookieCode");
147 userInfo.username_ = parameters.getValue(
"Username");
148 userInfo.displayName_ = parameters.getValue(
"DisplayName");
149 userInfo.usernameWithLock_ = parameters.getValue(
"UserWithLock");
153 goto HANDLE_ACCESS_FAILURE;
160 HANDLE_ACCESS_FAILURE:
163 if(!userInfo.automatedCommand_)
164 __COUT_ERR__ <<
"Failed request (requestType = " << userInfo.requestType_
165 <<
"): " << out->str() << __E__;
175 if(time(0) - ActiveUserLastUpdateTime_ >
176 ACTIVE_USERS_UPDATE_THRESHOLD)
178 __COUTS__(2) <<
"Need to update active user list" << std::endl;
180 xoap::MessageReference retMsg = ots::SOAPMessenger::sendWithSOAPReply(
184 SOAPUtilities::receive(retMsg, retParameters);
186 ActiveUserLastUpdateTime_ = time(0);
187 return (ActiveUserList_ = retParameters.getValue(
"UserList"));
190 return ActiveUserList_;
200 std::map<std::string ,
201 std::tuple<std::string ,
203 std::string >>& theGroups)
205 xoap::MessageReference retMsg =
207 "SupervisorLastTableGroupRequest",
211 retParameters.addParameter(
"GroupName");
212 retParameters.addParameter(
"GroupKey");
213 retParameters.addParameter(
"GroupAction");
214 retParameters.addParameter(
"GroupActionTime");
215 SOAPUtilities::receive(retMsg, retParameters);
218 std::vector<std::string> groupNames =
220 std::vector<std::string> groupKeys =
222 std::vector<std::string> groupActions =
225 retParameters.getValue(
"GroupActionTime"), {
','});
227 if(groupNames.size() < 2)
230 __SS__ <<
"Failure in handling request for recent config group activity. "
231 "Response received was this: \n"
232 << SOAPUtilities::translate(retMsg) << __E__;
236 if(groupNames.size() != groupKeys.size() ||
237 groupNames.size() != groupActions.size() || groupNames.size() != groupTimes.size())
239 __SS__ <<
"Illegal list size mismatch while retrieving recent config group info. "
240 "Should not be possible! Notify admins."
245 for(
size_t i = 0; i < groupNames.size(); ++i)
247 theGroups[groupActions[i]] = std::make_tuple(
248 groupNames[i], strtol(groupKeys[i].c_str(), 0, 0), groupTimes[i]);
251 __COUTT__ <<
"Done with getLastTableGroups()" << __E__;
261 const std::string& actionOfLastGroup, std::string& actionTimeString)
263 actionTimeString =
"";
264 xoap::MessageReference retMsg = ots::SOAPMessenger::sendWithSOAPReply(
266 "SupervisorLastTableGroupRequest",
270 retParameters.addParameter(
"GroupName");
271 retParameters.addParameter(
"GroupKey");
272 retParameters.addParameter(
"GroupAction");
273 retParameters.addParameter(
"GroupActionTime");
274 SOAPUtilities::receive(retMsg, retParameters);
277 if(retParameters.getValue(
"GroupAction") !=
280 __SS__ <<
"Returned group action '" << retParameters.getValue(
"GroupAction")
281 <<
"' does not match requested group action '" << actionOfLastGroup <<
".'"
287 theGroup.first = retParameters.getValue(
"GroupName");
288 theGroup.second = strtol(retParameters.getValue(
"GroupKey").c_str(), 0, 0);
289 actionTimeString = retParameters.getValue(
"GroupActionTime");
298 const std::string& message,
309 const std::string& subject,
310 const std::string& message,
314 parameters.addParameter(
"ToUser", toUser);
315 parameters.addParameter(
"Subject", subject);
316 parameters.addParameter(
"Message", message);
317 parameters.addParameter(
"DoEmail", doEmail ?
"1" :
"0");
319 xoap::MessageReference retMsg = SOAPMessenger::sendWithSOAPReply(
331 parameters.addParameter(
"EntryText", entryText);
333 xoap::MessageReference retMsg = SOAPMessenger::sendWithSOAPReply(
bool isWizardMode(void) const
BOOLs.
static std::string getOrPostData(cgicc::Cgicc &cgi, const std::string &needle)
XDAQ_CONST_CALL xdaq::ApplicationDescriptor * gatewaySupervisorDescriptor_
void getLastTableGroups(std::map< std::string, std::tuple< std::string, TableGroupKey, std::string >> &theGroups)
RemoteWebUsers(xdaq::Application *application, XDAQ_CONST_CALL xdaq::ApplicationDescriptor *gatewaySupervisorDescriptor)
std::pair< std::string, TableGroupKey > getLastTableGroup(const std::string &actionOfLastGroup, std::string &returnedActionTimeString)
actionOfLastGroup = "Configured" or "Started", for example
std::string getActiveUserList(void)
void sendSystemMessage(const std::string &toUser, const std::string &message, bool doEmail=false)
void makeSystemLogEntry(const std::string &entryText)
bool xmlRequestToGateway(cgicc::Cgicc &cgi, std::ostringstream *out, HttpXmlDocument *xmldoc, const AllSupervisorInfo &allSupervisorInfo, WebUsers::RequestUserInfo &userInfo)
XDAQ_CONST_CALL xdaq::ApplicationDescriptor * getDescriptor(void) const
Getters ----------------—.
static bool checkRequestAccess(cgicc::Cgicc &cgi, std::ostringstream *out, HttpXmlDocument *xmldoc, WebUsers::RequestUserInfo &userInfo, bool isWizardMode=false, const std::string &wizardModeSequence="")
static void initializeRequestUserInfo(cgicc::Cgicc &cgi, WebUsers::RequestUserInfo &userInfo)
used by gateway and other supervisors to verify requests consistently
static void getVectorFromString(const std::string &inputString, std::vector< std::string > &listToReturn, const std::set< char > &delimiter={',', '|', '&'}, const std::set< char > &whitespace={' ', '\t', '\n', '\r'}, std::vector< char > *listOfDelimiters=0, bool decodeURIComponents=false)
bool setGroupPermissionLevels(const std::string &groupPermissionLevelsString)
end setGroupPermissionLevels()