bool CWsPackageProcessEx::onAddPackage(IEspContext &context, IEspAddPackageRequest &req, IEspAddPackageResponse &resp) { resp.updateStatus().setCode(0); StringAttr target(req.getTarget()); StringAttr name(req.getPackageMap()); if (target.isEmpty()) throw MakeStringExceptionDirect(PKG_MISSING_PARAM, "Target cluster parameter required"); if (name.isEmpty()) throw MakeStringExceptionDirect(PKG_MISSING_PARAM, "PackageMap name parameter required"); DBGLOG("%s adding packagemap %s to target %s", context.queryUserId(), name.str(), target.str()); StringBuffer pmid; if (!req.getGlobalScope()) pmid.append(target).append("::"); pmid.append(name.get()); bool activate = req.getActivate(); unsigned updateFlags = 0; if (req.getOverWrite()) updateFlags |= (DALI_UPDATEF_PACKAGEMAP | DALI_UPDATEF_REPLACE_FILE | DALI_UPDATEF_CLONE_FROM | DALI_UPDATEF_SUPERFILES); if (req.getReplacePackageMap()) updateFlags |= DALI_UPDATEF_PACKAGEMAP; if (req.getUpdateCloneFrom()) updateFlags |= DALI_UPDATEF_CLONE_FROM; if (req.getUpdateSuperFiles()) updateFlags |= DALI_UPDATEF_SUPERFILES; if (req.getAppendCluster()) updateFlags |= DALI_UPDATEF_APPEND_CLUSTER; StringAttr processName(req.getProcess()); Owned<IUserDescriptor> userdesc; const char *user = context.queryUserId(); const char *password = context.queryPassword(); if (user && *user && *password && *password) { userdesc.setown(createUserDescriptor()); userdesc->set(user, password); } StringBuffer srcCluster; StringBuffer daliip; StringBuffer prefix; splitDerivedDfsLocation(req.getDaliIp(), srcCluster, daliip, prefix, req.getSourceProcess(), req.getSourceProcess(), NULL, NULL); StringBuffer pkgSetId; buildPkgSetId(pkgSetId, processName.get()); StringArray filesNotFound; addPackageMapInfo(updateFlags, req.getInfo(), filesNotFound, processName, target, pmid, pkgSetId, daliip, srcCluster, prefix, activate, userdesc, req.getAllowForeignFiles(), req.getPreloadAllPackages()); resp.setFilesNotFound(filesNotFound); StringBuffer msg; msg.append("Successfully loaded ").append(name.get()); resp.updateStatus().setDescription(msg.str()); return true; }
bool CWsPackageProcessEx::onAddPackage(IEspContext &context, IEspAddPackageRequest &req, IEspAddPackageResponse &resp) { PackageMapUpdater updater; updater.setFlag(PKGADD_MAP_CREATE); updater.setFlag(PKGADD_MAP_ACTIVATE, req.getActivate()); updater.setFlag(PKGADD_MAP_REPLACE, req.getOverWrite()); updater.setFlag(PKGADD_ALLOW_FOREIGN, req.getAllowForeignFiles()); updater.setFlag(PKGADD_PRELOAD_ALL, req.getPreloadAllPackages()); updater.setPMID(req.getTarget(), req.getPackageMap(), req.getGlobalScope()); updater.setProcess(req.getProcess()); updater.setUser(context.queryUserId(), context.queryPassword()); updater.setDerivedDfsLocation(req.getDaliIp(), req.getSourceProcess()); unsigned updateFlags = 0; if (req.getOverWrite()) updateFlags |= (DALI_UPDATEF_PACKAGEMAP | DALI_UPDATEF_REPLACE_FILE | DALI_UPDATEF_CLONE_FROM | DALI_UPDATEF_SUPERFILES); if (req.getReplacePackageMap()) updateFlags |= DALI_UPDATEF_PACKAGEMAP; if (req.getUpdateCloneFrom()) updateFlags |= DALI_UPDATEF_CLONE_FROM; if (req.getUpdateSuperFiles()) updateFlags |= DALI_UPDATEF_SUPERFILES; if (req.getAppendCluster()) updateFlags |= DALI_UPDATEF_APPEND_CLUSTER; StringArray filesNotFound; updater.create(req.getPackageMap(), req.getInfo(), updateFlags, filesNotFound); resp.setFilesNotFound(filesNotFound); resp.updateStatus().setCode(0); resp.updateStatus().setDescription(StringBuffer("Successfully loaded ").append(req.getPackageMap())); return true; }
bool CWSESPControlEx::onSetLogging(IEspContext& context, IEspSetLoggingRequest& req, IEspSetLoggingResponse& resp) { try { #ifdef _USE_OPENLDAP CLdapSecManager* secmgr = dynamic_cast<CLdapSecManager*>(context.querySecManager()); if(secmgr && !secmgr->isSuperUser(context.queryUser())) { context.setAuthStatus(AUTH_STATUS_NOACCESS); throw MakeStringException(ECLWATCH_SUPER_USER_ACCESS_DENIED, "Failed to change log settings. Permission denied."); } #endif if (!m_container) throw MakeStringException(ECLWATCH_INTERNAL_ERROR, "Failed to access container."); if (!req.getLoggingLevel_isNull()) m_container->setLogLevel(req.getLoggingLevel()); if (!req.getLogRequests_isNull()) m_container->setLogRequests(req.getLogRequests()); if (!req.getLogResponses_isNull()) m_container->setLogResponses(req.getLogResponses()); resp.setStatus(0); resp.setMessage("Logging settings are updated."); } catch(IException* e) { FORWARDEXCEPTION(context, e, ECLWATCH_INTERNAL_ERROR); } return true; }
bool CWSESPControlEx::onCleanSession(IEspContext& context, IEspCleanSessionRequest& req, IEspCleanSessionResponse& resp) { try { #ifdef _USE_OPENLDAP CLdapSecManager* secmgr = dynamic_cast<CLdapSecManager*>(context.querySecManager()); if(secmgr && !secmgr->isSuperUser(context.queryUser())) { context.setAuthStatus(AUTH_STATUS_NOACCESS); throw MakeStringException(ECLWATCH_SUPER_USER_ACCESS_DENIED, "Failed to clean session. Permission denied."); } #endif StringBuffer id, userID, fromIP; bool allSessions = req.getAllSessions(); if (!allSessions) { id.set(req.getID()); userID.set(req.getUserID()); fromIP.set(req.getFromIP()); if ((id.trim().isEmpty()) && (userID.trim().isEmpty()) && (fromIP.trim().isEmpty())) throw MakeStringException(ECLWATCH_INVALID_INPUT, "ID, userID or FromIP has to be specified."); } cleanSessions(allSessions, id.str(), userID.str(), fromIP.str()); resp.setStatus(0); resp.setMessage("Session is cleaned."); } catch(IException* e) { FORWARDEXCEPTION(context, e, ECLWATCH_INTERNAL_ERROR); } return true; }
bool CWsDfuXRefEx::onDFUXRefCleanDirectories(IEspContext &context, IEspDFUXRefCleanDirectoriesRequest &req, IEspDFUXRefCleanDirectoriesResponse &resp) { try { if (!context.validateFeatureAccess(FEATURE_URL, SecAccess_Write, false)) throw MakeStringException(ECLWATCH_DFU_XREF_ACCESS_DENIED, "Failed to clean Xref Directories. Permission denied."); StringBuffer username; context.getUserID(username); DBGLOG("CWsDfuXRefEx::onDFUXRefDirectories User=%s",username.str()); if (!req.getCluster() || !*req.getCluster()) throw MakeStringExceptionDirect(ECLWATCH_INVALID_INPUT, "Cluster not defined."); Owned<IXRefNode> xRefNode = XRefNodeManager->getXRefNode(req.getCluster()); if (xRefNode.get() == 0) return false; StringBuffer buf; xRefNode->removeEmptyDirectories(buf); DBGLOG("xRefNode->removeEmptyDirectories result=%s",buf.str()); resp.setRedirectUrl(StringBuffer("/WsDFUXRef/DFUXRefDirectories?Cluster=").append(req.getCluster())); } catch(IException* e) { FORWARDEXCEPTION(context, e, ECLWATCH_INTERNAL_ERROR); } return true; }
bool CWsDfuXRefEx::onDFUXRefMessages(IEspContext &context, IEspDFUXRefMessagesQueryRequest &req, IEspDFUXRefMessagesQueryResponse &resp) { try { if (!context.validateFeatureAccess(FEATURE_URL, SecAccess_Read, false)) throw MakeStringException(ECLWATCH_DFU_XREF_ACCESS_DENIED, "Failed to get Xref Messages. Permission denied."); StringBuffer username; context.getUserID(username); DBGLOG("CWsDfuXRefEx::onDFUXRefMessages User=%s",username.str()); if (!req.getCluster() || !*req.getCluster()) throw MakeStringExceptionDirect(ECLWATCH_INVALID_INPUT, "Cluster not defined."); Owned<IXRefNode> xRefNode = XRefNodeManager->getXRefNode(req.getCluster()); if (xRefNode.get() == 0) return false; StringBuffer buf; xRefNode->serializeMessages(buf); resp.setDFUXRefMessagesQueryResult(buf.str()); } catch(IException* e) { FORWARDEXCEPTION(context, e, ECLWATCH_INTERNAL_ERROR); } return true; }
bool CLogThread::queueLog(IEspContext & context,const char* serviceName, const char* request, const char* response) { IProperties* pProperties = context.queryRequestParameters(); StringBuffer UserID, UserRealm, UserReference, peer; if(pProperties != NULL && pProperties->hasProp("userid_")) UserID.appendf("%s",pProperties->queryProp("userid_")); else context.getUserID(UserID); if(pProperties != NULL && pProperties->hasProp("fqdn_")) UserRealm.appendf("%s",pProperties->queryProp("fqdn_")); else context.getRealm(UserRealm); Owned<IPropertyTree> pLogTreeInfo = createPTreeFromXMLString(request, ipt_none, ptr_none); IArrayOf<IEspLogInfo> LogArray; addLogInfo(LogArray, *pLogTreeInfo.get()); if(pProperties != NULL && pProperties->hasProp("referencecode_")) { //lets manually add the reference number.... IClientLogInfo& LogInfoTransaction = addLogInfoElement(LogArray); LogInfoTransaction.setName("referencenumber"); LogInfoTransaction.setValue(pProperties->queryProp("referencecode_")); } LOG_INFO _LogStruct(serviceName,-1,false); return queueLog(UserID.str(), UserRealm.str() , context.getPeer(peer).str(),_LogStruct, LogArray ); }
bool CWsLoggingServiceEx::onUpdateLog(IEspContext& context, IEspUpdateLogRequest& req, IEspUpdateLogResponse& resp) { try { context.ensureFeatureAccess(WSLOGGING_ACCESS, SecAccess_Write, EspLoggingErrors::WSLoggingAccessDenied, "WsLoggingService::UpdateLog: Permission denied."); context.addTraceSummaryTimeStamp(LogMin, "startQLog"); for (unsigned int x = 0; x < loggingAgentThreads.size(); x++) { IUpdateLogThread* loggingThread = loggingAgentThreads[x]; if (!loggingThread->hasService(LGSTUpdateLOG)) continue; loggingThread->queueLog(&req); } context.addTraceSummaryTimeStamp(LogMin, "endQLog"); resp.setStatusCode(0); resp.setStatusMessage("Log will be updated."); } catch (IException* e) { StringBuffer errorStr; e->errorMessage(errorStr); OERRLOG("Failed to update log: cannot add to log queue: %s",errorStr.str()); resp.setStatusCode(-1); resp.setStatusMessage(errorStr.str()); e->Release(); } return true; }
bool CWsDfuXRefEx::onDFUXRefList(IEspContext &context, IEspDFUXRefListRequest &req, IEspDFUXRefListResponse &resp) { try { if (!context.validateFeatureAccess(FEATURE_URL, SecAccess_Read, false)) throw MakeStringException(ECLWATCH_DFU_XREF_ACCESS_DENIED, "Failed to access Xref. Permission denied."); StringBuffer username; context.getUserID(username); DBGLOG("CWsDfuXRefEx::onDFUXRefList User=%s",username.str()); //Firstly we need to get a list of the available Thor Cluster.... IArrayOf<IEspTpCluster> clusters; CTpWrapper _topology; _topology.getClusterProcessList(eqThorCluster,clusters,false,true); ///_topology.getClusterList(eqRoxieCluster,clusters,false,true); Owned<IPropertyTree> pXRefNodeTree = createPTree("XRefNodes"); //DBGLOG("CWsDfuXRefEx::onDFUXRefList1\n"); for (unsigned x=0;x<=clusters.ordinality();x++) { IPropertyTree* XRefTreeNode = pXRefNodeTree->addPropTree("XRefNode", createPTree(ipt_caseInsensitive)); IEspTpCluster* cluster = x<clusters.ordinality()?&clusters.item(x):NULL; const char *clustername = cluster?cluster->getName():"SuperFiles"; XRefTreeNode->setProp("Name",clustername); //create the node if it doesn;t exist Owned<IXRefNode> xRefNode = XRefNodeManager->getXRefNode(clustername); if (xRefNode == 0) { XRefTreeNode->setProp("Modified",""); XRefTreeNode->setProp("Status","Not Run"); } else { StringBuffer buf; XRefTreeNode->setProp("Modified",xRefNode->getLastModified(buf).str()); buf.clear(); XRefTreeNode->setProp("Status",xRefNode->getStatus(buf).str()); } } StringBuffer buf; resp.setDFUXRefListResult(toXML(pXRefNodeTree, buf).str()); } catch(IException* e) { FORWARDEXCEPTION(context, e, ECLWATCH_INTERNAL_ERROR); } return true; }
bool CWSESPControlEx::onSetSessionTimeout(IEspContext& context, IEspSetSessionTimeoutRequest& req, IEspSetSessionTimeoutResponse& resp) { try { #ifdef _USE_OPENLDAP CLdapSecManager* secmgr = dynamic_cast<CLdapSecManager*>(context.querySecManager()); if(secmgr && !secmgr->isSuperUser(context.queryUser())) { context.setAuthStatus(AUTH_STATUS_NOACCESS); throw MakeStringException(ECLWATCH_SUPER_USER_ACCESS_DENIED, "Failed to set session timeout. Permission denied."); } #endif StringBuffer id, userID, fromIP; bool allSessions = req.getAllSessions(); if (!allSessions) { id.set(req.getID()); userID.set(req.getUserID()); fromIP.set(req.getFromIP()); if ((id.trim().isEmpty()) && (userID.trim().isEmpty()) && (fromIP.trim().isEmpty())) throw MakeStringException(ECLWATCH_INVALID_INPUT, "ID, userID or FromIP has to be specified."); } int timeoutMinutes = req.getTimeoutMinutes_isNull() ? 0 : req.getTimeoutMinutes(); if (timeoutMinutes <= 0) cleanSessions(allSessions, id.str(), userID.str(), fromIP.str()); else { StringBuffer searchPath; setSessionXPath(allSessions, id.str(), userID.str(), fromIP.str(), searchPath); Owned<IRemoteConnection> globalLock = querySDSConnectionForESPSession(RTM_LOCK_WRITE, SESSION_SDS_LOCK_TIMEOUT); Owned<IPropertyTreeIterator> iter = globalLock->queryRoot()->getElements("*"); ForEach(*iter) { Owned<IPropertyTreeIterator> iter1 = iter->query().getElements(searchPath.str()); ForEach(*iter1) setSessionTimeout(timeoutMinutes, iter1->query()); } } resp.setStatus(0); resp.setMessage("Session timeout is updated."); } catch(IException* e) { FORWARDEXCEPTION(context, e, ECLWATCH_INTERNAL_ERROR); } return true; }
void CEspBinding::getNavigationData(IEspContext &context, IPropertyTree & data) { IEspWsdlSections *wsdl = dynamic_cast<IEspWsdlSections *>(this); if (wsdl) { StringBuffer serviceName, params; wsdl->getServiceName(serviceName); if (!getUrlParams(context.queryRequestParameters(), params)) { if (context.getClientVersion()>0) params.appendf("%cver_=%g", params.length()?'&':'?', context.getClientVersion()); } StringBuffer encodedparams; if (params.length()) encodeUtf8XML(params.str(), encodedparams, 0); if (params.length()) params.setCharAt(0,'&'); //the entire params string will follow the initial param: "?form" VStringBuffer folderpath("Folder[@name='%s']", serviceName.str()); IPropertyTree *folder = data.queryPropTree(folderpath.str()); if(!folder) { folder=createPTree("Folder"); folder->addProp("@name", serviceName.str()); folder->addProp("@info", serviceName.str()); folder->addProp("@urlParams", encodedparams); if (showSchemaLinks()) folder->addProp("@showSchemaLinks", "true"); folder->addPropBool("@isDynamicBinding", isDynamicBinding()); folder->addPropBool("@isBound", isBound()); data.addPropTree("Folder", folder); } MethodInfoArray methods; wsdl->getQualifiedNames(context, methods); ForEachItemIn(idx, methods) { CMethodInfo &method = methods.item(idx); IPropertyTree *link=createPTree("Link"); link->addProp("@name", method.m_label.str()); link->addProp("@info", method.m_label.str()); StringBuffer path; path.appendf("../%s/%s?form%s", serviceName.str(), method.m_label.str(),params.str()); link->addProp("@path", path.str()); folder->addPropTree("Link", link); } }
bool CWsLoggingServiceEx::onGetTransactionSeed(IEspContext& context, IEspGetTransactionSeedRequest& req, IEspGetTransactionSeedResponse& resp) { bool bRet = false; try { if (!context.validateFeatureAccess(WSLOGGING_ACCESS, SecAccess_Write, false)) throw MakeStringException(EspLoggingErrors::WSLoggingAccessDenied, "Failed to get transaction seed. Permission denied."); LOGServiceType serviceType = LGSTGetTransactionSeed; for (unsigned int x = 0; x < loggingAgentThreads.size(); x++) { IUpdateLogThread* loggingThread = loggingAgentThreads[x]; if (!loggingThread->hasService(serviceType)) continue; IEspLogAgent* loggingAgent = loggingThread->getLogAgent(); bRet = loggingAgent->getTransactionSeed(req, resp); break; } } catch (IException* e) { StringBuffer errorStr; e->errorMessage(errorStr); errorStr.insert(0, "Failed to get Transaction Seed: "); ERRLOG("%s", errorStr.str()); resp.setStatusCode(-1); resp.setStatusMessage(errorStr.str()); e->Release(); } return bRet; }
virtual void getNavigationData(IEspContext &context, IPropertyTree & data) { #ifdef _USE_OPENLDAP bool isFF = false; StringBuffer browserUserAgent; context.getUseragent(browserUserAgent); if ((browserUserAgent.length() > 0) && strstr(browserUserAgent.str(), "Firefox")) isFF = true; IPropertyTree *folder = ensureNavFolder(data, "My Account", "My Account"); const char* build_level = getBuildLevel(); if (!stricmp(m_authType.str(), "none") || !stricmp(m_authType.str(), "local")) { ensureNavLink(*folder, "Change Password", "/Ws_Access/SecurityNotEnabled?form_", "Change Password", NULL, NULL, 0, true);//Force the menu to use this setting if (!isFF) ensureNavLink(*folder, "Relogin", "/Ws_Access/SecurityNotEnabled?form_", "Relogin", NULL, NULL, 0, true);//Force the menu to use this setting else ensureNavLink(*folder, "Relogin", "/Ws_Access/FirefoxNotSupport?form_", "Relogin", NULL, NULL, 0, true);//Force the menu to use this setting ensureNavLink(*folder, "Who Am I", "/Ws_Access/SecurityNotEnabled?form_", "WhoAmI", NULL, NULL, 0, true);//Force the menu to use this setting } else { ensureNavLink(*folder, "Change Password", "/Ws_Account/UpdateUserInput", "Change Password", NULL, NULL, 0, true);//Force the menu to use this setting if (!isFF) ensureNavLink(*folder, "Relogin", "/Ws_Account/LogoutUser", "Relogin", NULL, NULL, 0, true);//Force the menu to use this setting else ensureNavLink(*folder, "Relogin", "/Ws_Access/FirefoxNotSupport?form_", "Relogin", NULL, NULL, 0, true);//Force the menu to use this setting ensureNavLink(*folder, "Who Am I", "/Ws_Account/WhoAmI", "WhoAmI", NULL, NULL, 0, true);//Force the menu to use this setting } #endif }
bool Cws_accountEx::onMyAccount(IEspContext &context, IEspMyAccountRequest &req, IEspMyAccountResponse &resp) { try { ISecUser* user = context.queryUser(); if(user != NULL) { CDateTime dt; user->getPasswordExpiration(dt); StringBuffer sb; if (dt.isNull()) sb.append("Never"); else { dt.getString(sb); sb.replace('T', (char)0);//chop off timestring } resp.setPasswordExpiration(sb.str()); resp.setPasswordDaysRemaining(user->getPasswordDaysRemaining()); resp.setFirstName(user->getFirstName()); resp.setLastName(user->getLastName()); resp.setUsername(user->getName()); } } catch(IException* e) { FORWARDEXCEPTION(context, e, ECLWATCH_INTERNAL_ERROR); } return true; }
bool CWsPackageProcessEx::onAddPackage(IEspContext &context, IEspAddPackageRequest &req, IEspAddPackageResponse &resp) { resp.updateStatus().setCode(0); StringAttr target(req.getTarget()); StringAttr name(req.getPackageMap()); if (target.isEmpty()) throw MakeStringExceptionDirect(PKG_MISSING_PARAM, "Target cluster parameter required"); if (name.isEmpty()) throw MakeStringExceptionDirect(PKG_MISSING_PARAM, "PackageMap name parameter required"); StringBuffer pmid; if (!req.getGlobalScope()) pmid.append(target).append("::"); pmid.append(name.get()); bool activate = req.getActivate(); bool overWrite = req.getOverWrite(); StringAttr processName(req.getProcess()); Owned<IUserDescriptor> userdesc; const char *user = context.queryUserId(); const char *password = context.queryPassword(); if (user && *user && *password && *password) { userdesc.setown(createUserDescriptor()); userdesc->set(user, password); } StringBuffer srcCluster; StringBuffer daliip; StringBuffer prefix; splitDerivedDfsLocation(req.getDaliIp(), srcCluster, daliip, prefix, req.getSourceProcess(), req.getSourceProcess(), NULL, NULL); StringBuffer pkgSetId; buildPkgSetId(pkgSetId, processName.get()); StringArray filesNotFound; addPackageMapInfo(req.getInfo(), filesNotFound, processName, target, pmid, pkgSetId, daliip, srcCluster, prefix, activate, overWrite, userdesc, req.getAllowForeignFiles(), req.getPreloadAllPackages()); resp.setFilesNotFound(filesNotFound); StringBuffer msg; msg.append("Successfully loaded ").append(name.get()); resp.updateStatus().setDescription(msg.str()); return true; }
bool Cws_machineEx::onStartStopBegin( IEspContext &context, IEspStartStopBeginRequest &req, IEspStartStopBeginResponse &resp) { throw MakeStringException(ECLWATCH_INTERNAL_ERROR, "StartStopBegin feature not supported."); //following code is no longer accessible but will remain for reference try { if (!context.validateFeatureAccess(EXEC_FEATURE_URL, SecAccess_Full, false)) throw MakeStringException(ECLWATCH_EXECUTION_ACCESS_DENIED, "Permission denied."); StringBuffer addresses; StringArray& addresses0 = req.getAddresses(); for(unsigned i = 0; i < addresses0.length(); i++) { StringBuffer addrStr; const char* address = addresses0.item(i); updatePathInAddress(address, addrStr); if (i > 0) addresses.appendf("|Addresses_i%d=%s", i+1, addrStr.str()); else addresses.appendf("Addresses_i1=%s", addrStr.str()); } resp.setAddresses(addresses); resp.setKey1(req.getKey1()); resp.setKey2(req.getKey2()); resp.setStop(req.getStop()); double version = context.getClientVersion(); if (version > 1.07) { resp.setAutoRefresh( req.getAutoRefresh() ); resp.setMemThreshold(req.getMemThreshold()); resp.setDiskThreshold(req.getDiskThreshold()); resp.setCpuThreshold(req.getCpuThreshold()); resp.setMemThresholdType(req.getMemThresholdType()); resp.setDiskThresholdType(req.getDiskThresholdType()); } } catch(IException* e) { FORWARDEXCEPTION(context, e, ECLWATCH_INTERNAL_ERROR); } return true; }
bool CWSESPControlEx::onSessionInfo(IEspContext& context, IEspSessionInfoRequest& req, IEspSessionInfoResponse& resp) { try { #ifdef _USE_OPENLDAP CLdapSecManager* secmgr = dynamic_cast<CLdapSecManager*>(context.querySecManager()); if(secmgr && !secmgr->isSuperUser(context.queryUser())) { context.setAuthStatus(AUTH_STATUS_NOACCESS); throw MakeStringException(ECLWATCH_SUPER_USER_ACCESS_DENIED, "Failed to get session information. Permission denied."); } #endif StringBuffer id = req.getID(); if (id.trim().isEmpty()) throw MakeStringException(ECLWATCH_INVALID_INPUT, "ID not specified."); unsigned port = 8010; if (!req.getPort_isNull()) port = req.getPort(); Owned<IRemoteConnection> globalLock; VStringBuffer xpath("/%s/%s[@name='%s']/%s[@port='%d']/%s*[%s='%s']", PathSessionRoot, PathSessionProcess, espProcess.get(), PathSessionApplication, port, PathSessionSession, PropSessionExternalID, id.str()); try { globalLock.setown(querySDSConnection(xpath.str(), RTM_LOCK_READ, SESSION_SDS_LOCK_TIMEOUT)); } catch(IException* e) { VStringBuffer msg("Failed to get session info for id %s on port %u: ", id.str(), port); e->errorMessage(msg); e->Release(); throw MakeStringException(ECLWATCH_INVALID_INPUT, "%s", msg.str()); } setSessionInfo(globalLock->queryRoot(), port, &resp.updateSession()); } catch(IException* e) { FORWARDEXCEPTION(context, e, ECLWATCH_INTERNAL_ERROR); } return true; }
bool CWSESPControlEx::onSessionQuery(IEspContext& context, IEspSessionQueryRequest& req, IEspSessionQueryResponse& resp) { try { #ifdef _USE_OPENLDAP CLdapSecManager* secmgr = dynamic_cast<CLdapSecManager*>(context.querySecManager()); if(secmgr && !secmgr->isSuperUser(context.queryUser())) { context.setAuthStatus(AUTH_STATUS_NOACCESS); throw MakeStringException(ECLWATCH_SUPER_USER_ACCESS_DENIED, "Failed to query session. Permission denied."); } #endif StringBuffer xpath; setSessionXPath(false, nullptr, req.getUserID(), req.getFromIP(), xpath); IArrayOf<IEspSession> sessions; Owned<IRemoteConnection> globalLock = querySDSConnectionForESPSession(RTM_LOCK_READ, SESSION_SDS_LOCK_TIMEOUT); Owned<IPropertyTreeIterator> iter = globalLock->queryRoot()->getElements("*"); ForEach(*iter) { IPropertyTree& appSessionTree = iter->query(); unsigned port = appSessionTree.getPropInt("@port"); Owned<IPropertyTreeIterator> iter1 = appSessionTree.getElements(xpath.str()); ForEach(*iter1) { IPropertyTree& sessionTree = iter1->query(); Owned<IEspSession> s = createSession(); setSessionInfo(&sessionTree, port, s); sessions.append(*s.getLink()); } } resp.setSessions(sessions); } catch(IException* e) { FORWARDEXCEPTION(context, e, ECLWATCH_INTERNAL_ERROR); } return true; }
bool CWsDfuXRefEx::onDFUXRefBuildCancel(IEspContext &context, IEspDFUXRefBuildCancelRequest &req, IEspDFUXRefBuildCancelResponse &resp) { try { if (!context.validateFeatureAccess(FEATURE_URL, SecAccess_Full, false)) throw MakeStringException(ECLWATCH_DFU_XREF_ACCESS_DENIED, "Failed to cancel Xref Build. Permission denied."); StringBuffer username; context.getUserID(username); DBGLOG("CWsDfuXRefEx::onDFUXRefBuildCancel User=%s",username.str()); m_XRefbuilder->Cancel(); StringBuffer returnStr; returnStr.appendf("<Message><Value>All Queued items have been cleared. The current running job will continue to execute.</Value><href>/WsDFUXRef/DFUXRefList</href></Message>"); resp.setDFUXRefBuildCancelResult(returnStr.str()); } catch(IException* e) { FORWARDEXCEPTION(context, e, ECLWATCH_INTERNAL_ERROR); } return true; }
void CEspBinding::getNavigationData(IEspContext &context, IPropertyTree & data) { IEspWsdlSections *wsdl = dynamic_cast<IEspWsdlSections *>(this); if (wsdl) { StringBuffer serviceName, params; wsdl->getServiceName(serviceName); if (!getUrlParams(context.queryRequestParameters(), params)) { if (context.getClientVersion()>0) params.appendf("&ver_=%g", context.getClientVersion()); } if (params.length()) params.setCharAt(0,'&'); IPropertyTree *folder=createPTree("Folder"); folder->addProp("@name", serviceName.str()); folder->addProp("@info", serviceName.str()); folder->addProp("@urlParams", params.str()); if (showSchemaLinks()) folder->addProp("@showSchemaLinks", "true"); MethodInfoArray methods; wsdl->getQualifiedNames(context, methods); ForEachItemIn(idx, methods) { CMethodInfo &method = methods.item(idx); IPropertyTree *link=createPTree("Link"); link->addProp("@name", method.m_label.str()); link->addProp("@info", method.m_label.str()); StringBuffer path; path.appendf("../%s/%s?form%s", serviceName.str(), method.m_label.str(),params.str()); link->addProp("@path", path.str()); folder->addPropTree("Link", link); } data.addPropTree("Folder", folder); }
bool CWsDfuXRefEx::onDFUXRefBuild(IEspContext &context, IEspDFUXRefBuildRequest &req, IEspDFUXRefBuildResponse &resp) { try { if (!context.validateFeatureAccess(FEATURE_URL, SecAccess_Full, false)) throw MakeStringException(ECLWATCH_DFU_XREF_ACCESS_DENIED, "Failed to build Xref. Permission denied."); StringBuffer username; context.getUserID(username); DBGLOG("CWsDfuXRefEx::onDFUXRefBuild User=%s",username.str()); if (!req.getCluster() || !*req.getCluster()) throw MakeStringExceptionDirect(ECLWATCH_INVALID_INPUT, "Cluster not defined."); //create the node if it doesn;t exist Owned<IXRefNode> xRefNode = XRefNodeManager->getXRefNode(req.getCluster()); if (xRefNode.get() == 0) { xRefNode.setown( XRefNodeManager->CreateXRefNode(req.getCluster())); } StringBuffer returnStr; if (m_XRefbuilder->IsQueued(req.getCluster()) ) appendReplyMessage(returnStr,"/WsDFUXRef/DFUXRefList","An XRef build for cluster %s is in process. Click here to return to the main XRef List.",req.getCluster()); else if (!m_XRefbuilder->IsRunning()) appendReplyMessage(returnStr,"/WsDFUXRef/DFUXRefList","Running XRef Process. Click here to return to the main XRef List."); else appendReplyMessage(returnStr,"/WsDFUXRef/DFUXRefList","someone is currently running a Xref build. Your request will be added to the queue. Please click here to return to the main page."); m_XRefbuilder->QueueRequest(xRefNode,req.getCluster()); resp.setDFUXRefActionResult(returnStr.str()); } catch(IException* e) { FORWARDEXCEPTION(context, e, ECLWATCH_INTERNAL_ERROR); } return true; }
bool Cws_accountEx::onUpdateUserInput(IEspContext &context, IEspUpdateUserInputRequest &req, IEspUpdateUserInputResponse &resp) { try { ISecUser* user = context.queryUser(); if(user != NULL) { resp.setUsername(user->getName()); } } catch(IException* e) { FORWARDEXCEPTION(context, e, ECLWATCH_INTERNAL_ERROR); } return true; }
int CFileSpraySoapBindingEx::onFinishUpload(IEspContext &ctx, CHttpRequest* request, CHttpResponse* response, const char *service, const char *method, StringArray& fileNames, StringArray& files, IMultiException *me) { if (!me || (me->ordinality()==0)) { if (ctx.getResponseFormat()==ESPSerializationANY) { StringBuffer newUrl, netAddress, path; request->getParameter("NetAddress", netAddress); request->getParameter("Path", path); newUrl.appendf("/FileSpray/DropZoneFiles?NetAddress=%s&Path=%s", netAddress.str(), path.str()); response->redirect(*request, newUrl.str()); } else { IArrayOf<IEspDFUActionResult> results; Owned<CUploadFilesResponse> esp_response = new CUploadFilesResponse("FileSpray"); ForEachItemIn(i, fileNames) { const char* fileName = fileNames.item(i); Owned<IEspDFUActionResult> res = createDFUActionResult("", ""); res->setID(fileName); res->setAction("Upload File"); res->setResult("Success"); results.append(*res.getLink()); } if (!results.length()) { Owned<IEspDFUActionResult> res = createDFUActionResult("", ""); res->setID("<N/A>"); res->setAction("Upload File"); res->setResult("No file uploaded"); results.append(*res.getLink()); } esp_response->setUploadFileResults(results); MemoryBuffer content; StringBuffer mimetype; esp_response->appendContent(&ctx,content, mimetype); response->setContent(content.length(), content.toByteArray()); response->setContentType(mimetype.str()); response->send(); } } else {
bool Cws_machineEx::onStartStop( IEspContext &context, IEspStartStopRequest &req, IEspStartStopResponse &resp) { try { if (!context.validateFeatureAccess(EXEC_FEATURE_URL, SecAccess_Full, false)) throw MakeStringException(ECLWATCH_EXECUTION_ACCESS_DENIED, "Permission denied."); char* userName = (char*) m_sTestStr1.str(); char* password = (char*) m_sTestStr2.str(); doStartStop(context, req.getAddresses(), userName, password, req.getStop(), resp); } catch(IException* e) { FORWARDEXCEPTION(context, e, ECLWATCH_INTERNAL_ERROR); } return true; }
virtual void getNavigationData(IEspContext &context, IPropertyTree & data) { bool isFF = false; StringBuffer browserUserAgent; context.getUseragent(browserUserAgent); if ((browserUserAgent.length() > 0) && strstr(browserUserAgent.str(), "Firefox")) isFF = true; IPropertyTree *folder = ensureNavFolder(data, "My Account", "My Account"); StringBuffer path = "/WsSMC/NotInCommunityEdition?form_"; if (m_portalURL.length() > 0) path.appendf("&EEPortal=%s", m_portalURL.str()); ensureNavLink(*folder, "Change Password", path.str(), "Change Password"); if (!isFF) ensureNavLink(*folder, "Relogin", path.str(), "Relogin"); ensureNavLink(*folder, "Who Am I", path.str(), "WhoAmI"); }
bool CWsPackageProcessEx::onEcho(IEspContext &context, IEspEchoRequest &req, IEspEchoResponse &resp) { StringBuffer respMsg; ISecUser* user = context.queryUser(); if(user != NULL) { const char* name = user->getName(); if (name && *name) respMsg.appendf("%s: ", name); } const char* reqMsg = req.getRequest(); if (reqMsg && *reqMsg) respMsg.append(reqMsg); else respMsg.append("??"); resp.setResponse(respMsg.str()); return true; }
int CEclDirectSoapBindingEx::sendRunEclExForm(IEspContext &context, CHttpRequest* request, CHttpResponse* response) { StringBuffer xml; xml.append("<RunEclEx clientVersion='").append(context.getClientVersion()).append("'>"); appendXMLTag(xml, "UseEclRepository", (supportRepository) ? "Yes" : "No"); appendXMLTag(xml, "Redirect", (redirect) ? "Yes" : "No"); appendXMLTag(xml, "IncludeResults", (redirect) ? "No" : "Yes"); ForEachItemIn(i, clusters) appendXMLTag(xml, "Cluster", clusters.item(i)); xml.append("</RunEclEx>"); StringBuffer xslt(getCFD()); xslt.append("./smc_xslt/run_ecl.xslt"); StringBuffer html; xsltTransform(xml.str(), xslt.str(), NULL, html); response->setContent(html.str()); response->setContentType(HTTP_TYPE_TEXT_HTML_UTF8); response->send(); return 0; }
inline void FORWARDEXCEPTION(IEspContext &context, IException *e, unsigned codeNew) { if (!e) return; time_t tNow; struct tm timeStruct; char timeString[32]; StringBuffer eMsg; int err = e->errorCode(); e->errorMessage(eMsg); e->Release(); context.setException(err); //set time stamp in the result for this machine time(&tNow); gmtime_r(&tNow, &timeStruct); strftime(timeString, 32, "%Y-%m-%d %H:%M:%S GMT", &timeStruct); throw MakeStringException(err, "%s: %s", timeString, eMsg.str()); return; }
int onGetInstantQuery(IEspContext &context, CHttpRequest* request, CHttpResponse* response, const char *service, const char *method) { if(!stricmp(method, "LogoutUser")||!stricmp(method, "LogoutUserRequest")) { CEspCookie* logincookie = request->queryCookie("RELOGIN"); if(logincookie == NULL || stricmp(logincookie->getValue(), "1") == 0) { response->addCookie(new CEspCookie("RELOGIN", "0")); StringBuffer content( "<html xmlns=\"http://www.w3.org/1999/xhtml\">" "<head>" "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"/>" "<title>Enterprise Services Platform</title>" "</head>" "<body onLoad=\"location.href='/ws_account/LogoutUserCancel'\">" "</body>" "</html>"); response->sendBasicChallenge("ESP", content.str()); } else { response->addCookie(new CEspCookie("RELOGIN", "1")); response->setContentType("text/html; charset=UTF-8"); StringBuffer content( "<html xmlns=\"http://www.w3.org/1999/xhtml\">" "<head>" "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"/>" "<title>Enterprise Services Platform</title>" "</head>" "<body>" "<br/><b>Relogin successful, you're now logged in as "); content.append(context.queryUserId()).append( "</b>" "</body>" "</html>"); response->setContent(content.str()); response->send(); } return 0; } else if(!stricmp(method, "LogoutUserCancel")||!stricmp(method, "LogoutUserRequest")) { CEspCookie* logincookie = request->queryCookie("RELOGIN"); response->addCookie(new CEspCookie("RELOGIN", "1")); response->setContentType("text/html; charset=UTF-8"); StringBuffer content( "<html xmlns=\"http://www.w3.org/1999/xhtml\">" "<head>" "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"/>" "<title>Enterprise Services Platform</title>" "<script type='text/javascript'>" "function closeWin() { top.opener=top; top.close(); }" "</script>" "</head>" "<body onload=\"javascript:closeWin();\">" "<br/><b>Relogin canceled, you're now still logged in as "); content.append(context.queryUserId()).append( "</b>" "</body>" "</html>"); response->setContent(content.str()); response->send(); return 0; } else return Cws_accountSoapBinding::onGetInstantQuery(context, request, response, service, method); }
bool Cws_accountEx::onUpdateUser(IEspContext &context, IEspUpdateUserRequest & req, IEspUpdateUserResponse & resp) { try { CLdapSecManager* secmgr = dynamic_cast<CLdapSecManager*>(context.querySecManager()); if(secmgr == NULL) { throw MakeStringException(ECLWATCH_INVALID_SEC_MANAGER, "Security manager can't be converted to LdapSecManager. Only LdapSecManager supports this function."); } ISecUser* user = context.queryUser(); if(user == NULL) { resp.setRetcode(-1); resp.setMessage("Can't find user in esp context. Please check if the user was properly logged in."); return false; } if(req.getUsername() == NULL || strcmp(req.getUsername(), user->getName()) != 0) { resp.setRetcode(-1); resp.setMessage("Username/password don't match."); return false; } const char* oldpass = req.getOldpass(); if(oldpass == NULL || strcmp(oldpass, user->credentials().getPassword()) != 0) { resp.setRetcode(-1); resp.setMessage("Username/password don't match."); return false; } const char* newpass1 = req.getNewpass1(); const char* newpass2 = req.getNewpass2(); if(newpass1 == NULL || newpass2 == NULL || strlen(newpass1) < 4 || strlen(newpass2) < 4) { resp.setRetcode(-1); resp.setMessage("New password must be 4 characters or longer."); return false; } if(strcmp(newpass1, newpass2) != 0) { resp.setRetcode(-1); resp.setMessage("Password and retype don't match."); return false; } if(strcmp(oldpass, newpass1) == 0) { resp.setRetcode(-1); resp.setMessage("New password can't be the same as current password."); return false; } const char* pwscheme = secmgr->getPasswordStorageScheme(); bool isCrypt = pwscheme && (stricmp(pwscheme, "CRYPT") == 0); if(isCrypt && strncmp(oldpass, newpass1, 8) == 0) { resp.setRetcode(-1); resp.setMessage("The first 8 characters of the new password must be different from before."); return false; } bool ok = false; try { ok = secmgr->updateUserPassword(*user, newpass1, oldpass); } catch(IException* e) { StringBuffer emsg; e->errorMessage(emsg); resp.setRetcode(-1); resp.setMessage(emsg.str()); return false; } catch(...) { ok = false; } if(!ok) { throw MakeStringException(ECLWATCH_CANNOT_CHANGE_PASSWORD, "Failed in changing password."); } resp.setRetcode(0); if(isCrypt && strlen(newpass1) > 8) resp.setMessage("Your password has been changed successfully, however, only the first 8 chars are effective."); else resp.setMessage("Your password has been changed successfully."); } catch(IException* e) { FORWARDEXCEPTION(context, e, ECLWATCH_INTERNAL_ERROR); } return true; }