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"
13 #include "otsdaq/SupervisorInfo/AllSupervisorInfo.h"
18 #define __MF_SUBJECT__ "RemoteWebUsers"
96 RemoteWebUsers::RemoteWebUsers(xdaq::Application* application,
97 XDAQ_CONST_CALL xdaq::ApplicationDescriptor* gatewaySupervisorDescriptor)
99 , gatewaySupervisorDescriptor_(gatewaySupervisorDescriptor)
101 ActiveUserLastUpdateTime_ = 0;
102 ActiveUserList_ =
"";
109 bool RemoteWebUsers::xmlRequestToGateway(
114 WebUsers::initializeRequestUserInfo(cgi, userInfo);
116 XDAQ_CONST_CALL xdaq::ApplicationDescriptor* gatewaySupervisor;
119 xoap::MessageReference retMsg;
133 if(allSupervisorInfo.isWizardMode())
136 std::string sequence = CgiDataUtilities::getOrPostData(cgi,
"sequence");
138 if(!sequence.length())
140 __COUT_ERR__ <<
"Invalid access attempt (@" << userInfo.ip_ <<
")." << std::endl;
141 *out << WebUsers::REQ_NO_LOGIN_RESPONSE;
143 goto HANDLE_ACCESS_FAILURE;
148 gatewaySupervisor = allSupervisorInfo.getWizardInfo().getDescriptor();
149 if(!gatewaySupervisor)
151 __COUT_ERR__ <<
"Missing wizard supervisor." << std::endl;
152 *out << WebUsers::REQ_NO_LOGIN_RESPONSE;
154 goto HANDLE_ACCESS_FAILURE;
157 parameters.addParameter(
"sequence", sequence);
158 parameters.addParameter(
"IPAddress", userInfo.ip_);
159 retMsg = SOAPMessenger::sendWithSOAPReply(gatewaySupervisor,
"SupervisorSequenceCheck", parameters);
161 parameters.addParameter(
"Permissions");
162 SOAPUtilities::receive(retMsg, parameters);
164 userInfo.setGroupPermissionLevels(parameters.getValue(
"Permissions"));
166 if(WebUsers::checkRequestAccess(cgi, out, xmldoc, userInfo,
true , sequence))
169 goto HANDLE_ACCESS_FAILURE;
192 gatewaySupervisor = allSupervisorInfo.getGatewayInfo().getDescriptor();
194 if(!gatewaySupervisor)
196 __COUT_ERR__ <<
"Missing gateway supervisor." << std::endl;
197 *out << WebUsers::REQ_NO_LOGIN_RESPONSE;
198 goto HANDLE_ACCESS_FAILURE;
204 parameters.addParameter(
"CookieCode", userInfo.cookieCode_);
205 parameters.addParameter(
"RefreshOption", userInfo.automatedCommand_ ?
"0" :
"1");
206 parameters.addParameter(
"IPAddress", userInfo.ip_);
208 retMsg = SOAPMessenger::sendWithSOAPReply(gatewaySupervisor,
"SupervisorCookieCheck", parameters);
211 parameters.addParameter(
"CookieCode");
212 parameters.addParameter(
"Permissions");
213 parameters.addParameter(
"UserGroups");
214 parameters.addParameter(
"UserWithLock");
215 parameters.addParameter(
"Username");
216 parameters.addParameter(
"DisplayName");
217 parameters.addParameter(
"ActiveSessionIndex");
218 SOAPUtilities::receive(retMsg, parameters);
224 userInfo.setGroupPermissionLevels(parameters.getValue(
"Permissions"));
225 userInfo.cookieCode_ = parameters.getValue(
"CookieCode");
226 userInfo.username_ = parameters.getValue(
"Username");
227 userInfo.displayName_ = parameters.getValue(
"DisplayName");
228 userInfo.usernameWithLock_ = parameters.getValue(
"UserWithLock");
229 userInfo.activeUserSessionIndex_ = strtoul(parameters.getValue(
"ActiveSessionIndex").c_str(), 0, 0);
231 if(!WebUsers::checkRequestAccess(cgi, out, xmldoc, userInfo))
232 goto HANDLE_ACCESS_FAILURE;
239 HANDLE_ACCESS_FAILURE:
242 if(!userInfo.automatedCommand_)
243 __COUT_ERR__ <<
"Failed request (requestType = " << userInfo.requestType_ <<
"): " << out->str() << __E__;
251 std::string RemoteWebUsers::getActiveUserList()
253 if(time(0) - ActiveUserLastUpdateTime_ > ACTIVE_USERS_UPDATE_THRESHOLD)
255 __COUT__ <<
"Need to update " << std::endl;
257 xoap::MessageReference retMsg = ots::SOAPMessenger::sendWithSOAPReply(
258 gatewaySupervisorDescriptor_,
"SupervisorGetActiveUsers");
261 SOAPUtilities::receive(retMsg, retParameters);
263 ActiveUserLastUpdateTime_ = time(0);
264 return (ActiveUserList_ = retParameters.getValue(
"UserList"));
267 return ActiveUserList_;
276 std::pair<std::string ,
TableGroupKey> RemoteWebUsers::getLastTableGroup(
const std::string& actionOfLastGroup,
277 std::string& actionTimeString)
279 actionTimeString =
"";
280 xoap::MessageReference retMsg =
281 ots::SOAPMessenger::sendWithSOAPReply(
282 gatewaySupervisorDescriptor_,
283 "SupervisorLastTableGroupRequest",
288 retParameters.addParameter(
"GroupName");
289 retParameters.addParameter(
"GroupKey");
290 retParameters.addParameter(
"GroupAction");
291 retParameters.addParameter(
"GroupActionTime");
292 SOAPUtilities::receive(retMsg, retParameters);
295 if(retParameters.getValue(
"GroupAction") != actionOfLastGroup)
297 __COUT_WARN__ <<
"Returned group action '" << retParameters.getValue(
"GroupAction") <<
"' does not match requested group action '" << actionOfLastGroup
298 <<
".'" << std::endl;
303 theGroup.first = retParameters.getValue(
"GroupName");
304 theGroup.second = strtol(retParameters.getValue(
"GroupKey").c_str(), 0, 0);
305 actionTimeString = retParameters.getValue(
"GroupActionTime");
313 void RemoteWebUsers::sendSystemMessage(
const std::string& toUser,
const std::string& message,
bool doEmail )
315 sendSystemMessage(toUser,
"" , message, doEmail);
322 void RemoteWebUsers::sendSystemMessage(
const std::string& toUser,
const std::string& subject,
const std::string& message,
bool doEmail )
325 parameters.addParameter(
"ToUser", toUser);
326 parameters.addParameter(
"Subject", subject);
327 parameters.addParameter(
"Message", message);
328 parameters.addParameter(
"DoEmail", doEmail?
"1":
"0");
330 xoap::MessageReference retMsg = SOAPMessenger::sendWithSOAPReply(
331 gatewaySupervisorDescriptor_,
"SupervisorSystemMessage", parameters);
339 void RemoteWebUsers::makeSystemLogbookEntry(
const std::string& entryText)
342 parameters.addParameter(
"EntryText", entryText);
344 xoap::MessageReference retMsg = SOAPMessenger::sendWithSOAPReply(
345 gatewaySupervisorDescriptor_,
"SupervisorSystemLogbookEntry", parameters);