internal static bool ParseSimplex(string pScopedTopic, TSM pMessage, TheQueuedSender pQSender) //, TheSessionState pSessionState, Action<TSM> pLocalCallback) { if (pMessage == null) { return(false); } #if !JC_COMMDEBUG try { #endif if (pMessage?.TXT?.Equals("CDE_DELETEORPHAN") == true) { TheQueuedSenderRegistry.RemoveOrphan(TheCommonUtils.CGuid(pMessage.PLS)); return(false); } if (pQSender == null) { TheBaseAssets.MySYSLOG.WriteToLog(291, TSM.L(eDEBUG_LEVELS.ESSENTIALS) ? null : new TSM("CoreComm", $"QSender not found! Received from ORG:{TheCommonUtils.GetDeviceIDML(pMessage?.ORG)}", eMsgLevel.l1_Error, pMessage?.PLS)); return(false); } //SECURITY-REVIEW: This cannot be permitted without extra tokens and Encryption! otherwise it can be used to change a nodes scope on the fly! //if ("CDE_UPDATESCOPE".Equals(pMessage.TXT)) //{ // pQSender.UpdateSubscriptionScope(TheBaseAssets.MyScopeManager.GetRealScopeID(pMessage.SID)); //GRSI: rare // return true; //} if (pQSender != null && pMessage.ENG?.StartsWith(eEngineName.ContentService) == true && pMessage?.TXT == "CDE_SERVICE_INFO" && pQSender.MyTargetNodeChannel?.RealScopeID == TheBaseAssets.MyScopeManager.GetRealScopeID(pMessage.SID)) { try { pQSender.SetNodeInfo(TheCommonUtils.DeserializeJSONStringToObject <TheNodeInfoClone>(pMessage?.PLS)); } catch (Exception e) { TheBaseAssets.MySYSLOG.WriteToLog(23056, TSM.L(eDEBUG_LEVELS.FULLVERBOSE) ? null : new TSM("CoreComm", $"Error decoding SystemInfo {pQSender?.MyTargetNodeChannel?.ToMLString()}", eMsgLevel.l1_Error, e.ToString())); } } if (pMessage.TXT?.Equals("CDE_SUBSCRIBE") == true || pMessage.TXT?.Equals("CDE_INITIALIZE") == true) //9-9-2012 CDEC Did not work right on CDE_INIT { TheBaseAssets.MySYSLOG.WriteToLog(292, TSM.L(eDEBUG_LEVELS.VERBOSE) ? null : new TSM("CoreComm", $"Parse-Simplex Subscribe from {pQSender?.MyTargetNodeChannel?.ToMLString()} Parsed: {pMessage?.PLS}", eMsgLevel.l7_HostDebugMessage)); if (pQSender?.MyISBlock != null && !TheBaseAssets.MyServiceHostInfo.IsCloudService) { TheBaseAssets.MySYSLOG.WriteToLog(292, TSM.L(eDEBUG_LEVELS.VERBOSE) ? null : new TSM("CoreComm", "Parse-Simplex Subscribe rejected for Custom ISBConnect", eMsgLevel.l7_HostDebugMessage)); return(true); } ParseSubscribe(pMessage.PLS, pQSender); if (pMessage.ENG.Equals("CLOUDSYNC")) { string[] tTopics = pMessage.PLS.Split(';'); foreach (string t in tTopics) { TSM.GetScrambledIDFromTopic(t, out string tEng); if (TheThingRegistry.IsEngineRegistered(tEng)) { IBaseEngine tsBase = TheThingRegistry.GetBaseEngine(tEng); tsBase?.GetBaseThing()?.FireEvent(eEngineEvents.NewSubscription, tsBase.GetBaseThing(), pQSender.MyTargetNodeChannel, true); } } return(true); } else { TheThing tBase2 = TheThingRegistry.GetBaseEngineAsThing(pMessage.ENG); if (tBase2 != null) { tBase2.FireEvent(eEngineEvents.NewSubscription, tBase2, pQSender.MyTargetNodeChannel, true); } } if (pMessage.TXT.Equals("CDE_SUBSCRIBE")) //NEW:2.06 Make sure Subscribe and Unsubscribe only go to first node { return(true); } else { return(false); } } if (pMessage.TXT?.Equals("CDE_UNSUBSCRIBE") == true) { TheBaseAssets.MySYSLOG.WriteToLog(292, TSM.L(eDEBUG_LEVELS.VERBOSE) ? null : new TSM("CoreComm", $"Parse-Simplex Unsubscribe from {pQSender.MyTargetNodeChannel?.ToMLString()} Parsed: {pMessage.PLS}", eMsgLevel.l7_HostDebugMessage)); ParseUnsubscribe(pMessage.PLS, pQSender); return(true); //NEW:2.06 Make sure Subscribe and Unsubscribe only go to first node } #if !JC_COMMDEBUG } catch (Exception ee) { TheBaseAssets.MySYSLOG.WriteToLog(316, TSM.L(eDEBUG_LEVELS.ESSENTIALS) ? null : new TSM("CoreComm", "Parse-Simplex", eMsgLevel.l1_Error, ee.ToString())); } #endif return(false); }
/// <summary> /// Processes incoming Messages /// If a Batch comes in, only the first message must have a valid NPA Path /// </summary> internal static void ProcessClientDeviceMessage(TheQueuedSender MyQSender, TheRequestData pRequestData, List <TheDeviceMessage> tDevList) { var toRemove = new List <TheDeviceMessage>(); foreach (TheDeviceMessage tDev in tDevList) { if (string.IsNullOrEmpty(tDev.NPA)) { return; // CODE REVIEW: Really stop processing all subsequent TDMs here (malformed TDM -> security)? } string NPA = tDev.NPA.Substring(4); if (NPA.EndsWith(".ashx", StringComparison.OrdinalIgnoreCase)) { NPA = NPA.Substring(0, NPA.Length - 5); } if (TheBaseAssets.MyScopeManager.ParseISBPath(NPA, out Guid? ttSessionID, out cdeSenderType tSenderType, out long tFID, out string tVersion)) { Guid tSessionID = TheCommonUtils.CGuid(ttSessionID); Guid tDeviceID = TheCommonUtils.CGuid(tDev.DID); lock (TheBaseAssets.MySession.GetLock()) //CODE-REVIEW: VERY expensive lock! Really necessary? { var myTargetNodeChannel = MyQSender.MyTargetNodeChannel; if (MyQSender.IsConnected && myTargetNodeChannel.MySessionState != null) //!=null new in 3.2 { if (!tSessionID.Equals(myTargetNodeChannel.MySessionState.cdeMID)) { Guid tOldID = myTargetNodeChannel.MySessionState.cdeMID; myTargetNodeChannel.MySessionState = TheBaseAssets.MySession.ValidateSEID(tSessionID); //Measure Frequency if (myTargetNodeChannel.MySessionState == null) { TheBaseAssets.MySYSLOG.WriteToLog(243, TSM.L(eDEBUG_LEVELS.OFF) ? null : new TSM("CoreComm", $"No exiting session for remote node found. Using new session (possible reason: fast cloud reconnect) ...new: {tSessionID} old: {tOldID}", eMsgLevel.l2_Warning), true); myTargetNodeChannel.MySessionState = pRequestData.SessionState; } else { TheBaseAssets.MySession.RemoveSessionByID(tOldID); } } } if (tDeviceID != Guid.Empty && tDeviceID != myTargetNodeChannel.cdeMID) { if (myTargetNodeChannel.SenderType == cdeSenderType.CDE_CUSTOMISB) { if (myTargetNodeChannel.TruDID != tDeviceID) { myTargetNodeChannel.TruDID = tDeviceID; TheBaseAssets.MySYSLOG.WriteToLog(243, TSM.L(eDEBUG_LEVELS.ESSENTIALS) ? null : new TSM("CoreComm", $"Custom ISB sets TruDID to: {TheCommonUtils.GetDeviceIDML(tDeviceID)} for MTNC: {myTargetNodeChannel.ToMLString()}", eMsgLevel.l4_Message), true); } } else { TheBaseAssets.MySYSLOG.WriteToLog(243, TSM.L(eDEBUG_LEVELS.ESSENTIALS) ? null : new TSM("CoreComm", $"Different DeviceIDs received ...new: {TheCommonUtils.GetDeviceIDML(tDeviceID)} old: {TheCommonUtils.GetDeviceIDML(myTargetNodeChannel.cdeMID)} {(myTargetNodeChannel.SenderType == cdeSenderType.CDE_CLOUDROUTE ? "For CloudRoute and Service normal" : "")}", eMsgLevel.l2_Warning), true); TheBaseAssets.MySession.RemoveSessionsByDeviceID(myTargetNodeChannel.cdeMID, Guid.Empty); TheQueuedSenderRegistry.UpdateQSenderID(myTargetNodeChannel.cdeMID, tDeviceID); myTargetNodeChannel.cdeMID = tDeviceID; if (pRequestData.DeviceID != tDeviceID) { TheBaseAssets.MySYSLOG.WriteToLog(243, TSM.L(eDEBUG_LEVELS.VERBOSE) ? null : new TSM("CoreComm", $"Different DeviceIDs in DID and Request ...DID: {TheCommonUtils.GetDeviceIDML(tDeviceID)} Request: {TheCommonUtils.GetDeviceIDML(myTargetNodeChannel.cdeMID)}", eMsgLevel.l2_Warning), true); pRequestData.DeviceID = tDeviceID; } switch (pRequestData.ResponseMimeType) { case "cde/mini": myTargetNodeChannel.SenderType = cdeSenderType.CDE_MINI; break; } } } if (myTargetNodeChannel.MySessionState == null) { myTargetNodeChannel.MySessionState = TheBaseAssets.MySession.GetOrCreateSessionState(tSessionID, pRequestData); } myTargetNodeChannel.MySessionState.SiteVersion = tVersion; myTargetNodeChannel.MySessionState.cdeMID = tSessionID; myTargetNodeChannel.MySessionState.CurrentURL = myTargetNodeChannel.TargetUrl; // Keep the RSA public key of the other party, so we can use it to encrypt data when sending to that party in the future if (!String.IsNullOrEmpty(tDev.RSA)) { myTargetNodeChannel.MySessionState.RSAPublicSend = tDev.RSA; } if (MyQSender.IsConnecting && !MyQSender.IsConnected) { MyQSender.IsConnected = true; if (myTargetNodeChannel.SenderType == cdeSenderType.CDE_CLOUDROUTE) { if (TheBaseAssets.MyServiceHostInfo.IsIsolated && TheBaseAssets.MyServiceHostInfo.MasterNode == Guid.Empty) { TheBaseAssets.MyServiceHostInfo.MasterNode = myTargetNodeChannel.cdeMID; TheQueuedSenderRegistry.SendMasterNodeQueue(); } MyQSender.StartHeartBeat(); TheBaseAssets.MySYSLOG.WriteToLog(23055, TSM.L(eDEBUG_LEVELS.OFF) ? null : new TSM("CoreComm", $"Cloud Route is back up to {myTargetNodeChannel.ToMLString()}", eMsgLevel.l4_Message)); if (TheQueuedSenderRegistry.eventCloudIsBackUp != null) { TheCommonUtils.cdeRunAsync("QS-StartEngineNU", true, o => { TheQueuedSenderRegistry.eventCloudIsBackUp(TheCDEngines.MyContentEngine, myTargetNodeChannel); }); } } if (MyQSender.eventConnected != null) { TheCommonUtils.cdeRunAsync("QueueConnected", true, (p) => { MyQSender.eventConnected(MyQSender, myTargetNodeChannel); }); } MyQSender.MyISBlock?.FireEvent("Connected"); } pRequestData.SessionState = myTargetNodeChannel.MySessionState; MyQSender?.SetLastHeartbeat(myTargetNodeChannel.MySessionState); } if (!string.IsNullOrEmpty(tDev.TOP) && tDev.TOP.StartsWith("CDE_CONNECT")) { string[] tP = TheCommonUtils.cdeSplit(tDev.TOP, ";:;", true, true); if (tP.Length > 1) { string tEngs = tP[1]; TheCommonUtils.cdeRunAsync("QS-StartEngineNU", false, o => { TheCDEngines.StartEngineWithNewUrl(MyQSender?.MyTargetNodeChannel, tEngs); }); } if (tDevList.Count > 1) { if (toRemove == null) { toRemove = new List <TheDeviceMessage>(); } toRemove.Add(tDev); continue; } else { return; } } if (string.IsNullOrEmpty(tDev.TOP) || tDev.TOP.StartsWith("CDE_PICKUP") || tDev.TOP.StartsWith("CDE_WSINIT")) { TheBaseAssets.MySYSLOG.WriteToLog(23056, TSM.L(eDEBUG_LEVELS.FULLVERBOSE) ? null : new TSM("CoreComm", $"Heartbeat received {MyQSender?.MyTargetNodeChannel?.ToMLString()}", eMsgLevel.l4_Message)); if (tDevList.Count > 1) { if (toRemove == null) { toRemove = new List <TheDeviceMessage>(); } toRemove.Add(tDev); continue; } else { return; } } break; //Found valid path and can go out } } if (toRemove != null) { foreach (var tDev in toRemove) { tDevList.Remove(tDev); } } TheCommonUtils.cdeRunAsync("QS-UpCo2Exec", false, o => { pRequestData.ResponseBuffer = null; DoExecuteCommand(null, MyQSender, false, pRequestData, tDevList); }, tDevList); }
internal static void DoExecuteCommand(string pInTopicBatch, TheQueuedSender pQSender, bool DoSendBackBuffer, TheRequestData pRequestData, List <TheDeviceMessage> pDevMessageList) { bool SendPulse = false; if (pDevMessageList != null && pDevMessageList.Count > 0) { foreach (TheDeviceMessage pDevMessage in pDevMessageList) { TSM recvMessage = null; string tTopic = ""; try { var tTargetNodeChannel = pQSender?.MyTargetNodeChannel; string pInTopic = pInTopicBatch; if (string.IsNullOrEmpty(pInTopic)) { pInTopic = pDevMessage.TOP; } recvMessage = pDevMessage.MSG; if (pQSender != null && tTargetNodeChannel != null && tTargetNodeChannel.SenderType == cdeSenderType.CDE_JAVAJASON && recvMessage != null && string.IsNullOrEmpty(recvMessage.ORG)) { recvMessage.ORG = tTargetNodeChannel.cdeMID.ToString(); } #region ChunkResassembly string[] CommandParts = null; if (!string.IsNullOrEmpty(pInTopic)) { CommandParts = TheCommonUtils.cdeSplit(pInTopic, ":,:", false, false); tTopic = CommandParts[0]; } TheCDEKPIs.IncrementKPI(eKPINames.CCTSMsReceived); if (CommandParts != null && CommandParts.Length == 4 && !CommandParts[2].Equals("1")) { if (!TheCommonUtils.ProcessChunkedMessage(CommandParts, recvMessage)) { SendPulse = true; continue; } } #endregion if (recvMessage != null) { if (((TheBaseAssets.MyServiceHostInfo.RejectIncomingSETP && recvMessage.TXT?.StartsWith("SETP:") == true) || TheBaseAssets.MyServiceHostInfo.DisableNMIMessages) && recvMessage.ENG?.StartsWith(eEngineName.NMIService) == true) { TheCDEKPIs.IncrementKPI(eKPINames.QSSETPRejected); continue; } var tTopicSens = tTopic.Split('@')[0]; //only topic - no ScopeID var tTopicParts = tTopic.Split(';'); if (tTargetNodeChannel.SenderType == cdeSenderType.CDE_JAVAJASON) { //4.209: JavaJason does no longer get the scope ID - hence telegrams coming from the browser have to be ammmended with SID here if (string.IsNullOrEmpty(recvMessage.SID) && !string.IsNullOrEmpty(pRequestData?.SessionState?.SScopeID)) { recvMessage.SID = pRequestData?.SessionState?.SScopeID; //Set the ScopeID in the SID of the message if (tTopic.StartsWith("CDE_SYSTEMWIDE")) { tTopic = $"{tTopicParts[0]}@{recvMessage.SID}"; if (tTopicParts.Length > 1) { tTopic += $";{tTopicParts[1]}"; //if a direct address is added use this too } } else if (!tTopic.Contains('@')) { tTopic += $"@{recvMessage.SID}"; } if (recvMessage.TXT == "CDE_SUBSCRIBE" || recvMessage.TXT == "CDE_INITIALIZE") { string MsgNoSID = null; recvMessage.PLS = TheBaseAssets.MyScopeManager.AddScopeID(recvMessage.PLS, recvMessage.SID, ref MsgNoSID, false, false); } } } if (tTopicParts.Length > 1) { tTopicSens += $";{tTopicParts[1]}"; //if a direct address is added use this too } if (TheQueuedSenderRegistry.WasTSMSeenBefore(recvMessage, pRequestData.SessionState.cdeMID, tTopicSens, tTargetNodeChannel?.RealScopeID)) //ATTENTION: RScope should come from pDevMessage { TheBaseAssets.MySYSLOG.WriteToLog(285, TSM.L(eDEBUG_LEVELS.VERBOSE) ? null : new TSM("CoreComm", $"EnterExecuteCommand: Message was seen before ORG:{TheCommonUtils.GetDeviceIDML(recvMessage?.ORG)} Topic:{tTopicSens}", eMsgLevel.l2_Warning)); //ORG-OK TheCDEKPIs.IncrementKPI(eKPINames.QSRejected); continue; } if (tTargetNodeChannel.cdeMID == Guid.Empty) { tTargetNodeChannel.cdeMID = recvMessage.GetLastRelay(); } if (tTargetNodeChannel.SenderType == cdeSenderType.NOTSET) { TheBaseAssets.MySYSLOG.WriteToLog(285, TSM.L(eDEBUG_LEVELS.ESSENTIALS) ? null : new TSM("CoreComm", "Sender Type for the QSender is not set! WE SHOULD NEVER GET HERE", eMsgLevel.l1_Error));//ORG-OK //3.218: Processing no longer allowed!!! return; } // Enable upper layers to do RSA decryption. Force overwrite for Browser even if SEID already set (may have been initialized to some other value) if (tTargetNodeChannel.SenderType == cdeSenderType.CDE_JAVAJASON || String.IsNullOrEmpty(recvMessage.SEID)) { recvMessage.SEID = pRequestData.SessionState.cdeMID.ToString(); } if (pRequestData.SessionState != null && string.IsNullOrEmpty(pRequestData.SessionState.RemoteAddress)) { pRequestData.SessionState.RemoteAddress = tTargetNodeChannel.cdeMID.ToString(); } //NEW: User ID Management in Message after first node if (string.IsNullOrEmpty(recvMessage.UID) && pRequestData.SessionState != null && pRequestData.SessionState.CID != Guid.Empty) { recvMessage.UID = TheCommonUtils.cdeEncrypt(pRequestData.SessionState.CID.ToByteArray(), TheBaseAssets.MySecrets.GetAI()); //3.083: Must be cdeAI } } } catch (Exception ee) { TheBaseAssets.MySYSLOG.WriteToLog(319, TSM.L(eDEBUG_LEVELS.OFF) ? null : new TSM("CoreComm", "Execute Command Pre-Parsing Error", eMsgLevel.l1_Error, ee.ToString())); } if (recvMessage == null) { TheBaseAssets.MySYSLOG.WriteToLog(286, TSM.L(eDEBUG_LEVELS.FULLVERBOSE) ? null : new TSM("CoreComm", $"No Message for Parsing: Topic:{tTopic} - {pRequestData.ResponseBufferStr}", eMsgLevel.l7_HostDebugMessage)); } else { if (recvMessage.PLB != null && recvMessage.PLB.Length > 0 && string.IsNullOrEmpty(recvMessage.PLS)) { try { recvMessage.PLS = TheCommonUtils.cdeDecompressToString(recvMessage.PLB); recvMessage.PLB = null; } catch (Exception) { TheBaseAssets.MySYSLOG.WriteToLog(286, TSM.L(eDEBUG_LEVELS.VERBOSE) ? null : new TSM("CoreComm", $"PLB to PLS decompress failed - Topic:{tTopic} Node:{pQSender?.MyTargetNodeChannel?.ToMLString()} ORG:{TheCommonUtils.GetDeviceIDML(recvMessage?.ORG)}", eMsgLevel.l7_HostDebugMessage, $"TXT:{recvMessage.TXT}"));//ORG-OK } } TheBaseAssets.MySYSLOG.WriteToLog(286, TSM.L(eDEBUG_LEVELS.FULLVERBOSE) ? null : new TSM("CoreComm", $"PLB to PLS parsing done - Topic:{tTopic} Node:{pQSender?.MyTargetNodeChannel?.ToMLString()} ORG:{TheCommonUtils.GetDeviceIDML(recvMessage?.ORG)}", eMsgLevel.l7_HostDebugMessage, $"TXT:{recvMessage.TXT}"));//ORG-OK if (!SendPulse) { SendPulse = recvMessage.SendPulse(); } TheCDEKPIs.IncrementKPI(eKPINames.CCTSMsEvaluated); } try { if (recvMessage != null && !string.IsNullOrEmpty(tTopic)) // tTopic != null) { if (!ParseSimplex(tTopic, recvMessage, pQSender)) //NEW:2.06 - No More Local Host processing here { if (TheBaseAssets.MyServiceHostInfo.MaximumHops == 0 || recvMessage.HobCount() < TheBaseAssets.MyServiceHostInfo.MaximumHops) { if (!tTopic.StartsWith("CDE_CONNECT") || !TheBaseAssets.MyServiceHostInfo.AllowMessagesInConnect) // Should never get here if AllowMessagesInConnect is false, but avoid global publish just in case... { TheCDEKPIs.IncrementKPI(eKPINames.CCTSMsRelayed); TheCommCore.PublishCentral(tTopic, recvMessage, false, null, false, pQSender?.MyTargetNodeChannel?.IsTrustedSender ?? false); } else { // Message is part of a CDE_CONNECT: Republish it to enable single-post message sending (i.e. MSB/Service Gateway scenario) TheCDEKPIs.IncrementKPI(eKPINames.CCTSMsRelayed); // TODO SHould we have a separate KPI for this TheCommCore.PublishCentral(recvMessage, true, pQSender.MyTargetNodeChannel.IsTrustedSender); } } } else { if (pQSender?.MyTargetNodeChannel != null && pQSender?.MyTargetNodeChannel?.SenderType != cdeSenderType.CDE_JAVAJASON) { SendPulse = true; } } } } catch (Exception ee) { TheBaseAssets.MySYSLOG.WriteToLog(319, TSM.L(eDEBUG_LEVELS.OFF) ? null : new TSM("CoreComm", "Execute Command Parsing Error", eMsgLevel.l1_Error, ee.ToString())); } TheBaseAssets.MySYSLOG.WriteToLog(286, TSM.L(eDEBUG_LEVELS.FULLVERBOSE) ? null : new TSM("CoreComm", $"Done with Do Execute Command for Topic:{tTopic}", eMsgLevel.l7_HostDebugMessage)); } } if (pRequestData.WebSocket == null) { if (DoSendBackBuffer) { SetResponseBuffer(pRequestData, pQSender.MyTargetNodeChannel, SendPulse, ""); } else if (SendPulse) { pQSender.SendPickupMessage(); //Pickup next message right away if pulse mode is on } } TheBaseAssets.MySYSLOG.WriteToLog(286, TSM.L(eDEBUG_LEVELS.FULLVERBOSE) ? null : new TSM("CoreComm", "Leave Do Execute Command", eMsgLevel.l7_HostDebugMessage)); }
public override string ToString() { return($"ORG:{TheCommonUtils.GetDeviceIDML(ORG)},TH:{TopicHash}, FID:{FID}, OUT:{IsOutgoing}, TIM:{TheCommonUtils.GetDateTimeString(SentTime, -1)}, ENG:{Engine}"); }
public string GetSessionLog() { string retString = $"<div class=\"cdeInfoBlock\" style=\"clear:both; max-width:1570px; width:initial; \"><div class=\"cdeInfoBlockHeader cdeInfoBlockHeaderText\" id=\"sessionLog\">Session Log: ({MySessionStates.Count}) "; retString += $"<a download =\"SessionLog_{TheCommonUtils.GetMyNodeName()}.csv\" href=\"#\" class=\'cdeExportLink\' onclick=\"return ExcellentExport.csv(this, 'sessionLogTable');\">(Export as CSV)</a></div>"; List <string> tSessions = MySessionStates.TheKeys; string tFont; int count = 0; foreach (string tKey in tSessions) { if (count == 0) { retString += $"<table class=\"cdeHilite\" style=\"width:95%; margin-left:1%;\" id=\"sessionLogTable\"><tr>"; retString += $"<th style=\"background-color:rgba(90,90,90, 0.25);font-size:x-small;min-width:175px; width:300px;\">SEID</th>"; retString += $"<th style=\"background-color:rgba(90,90,90, 0.25);font-size:x-small;min-width:80px; width:80px;\">DID</th>"; retString += $"<th style=\"background-color:rgba(90,90,90, 0.25);font-size:x-small;min-width:80px; width:150px;\">Last Access</th>"; retString += $"<th style=\"background-color:rgba(90,90,90, 0.25);font-size:x-small;min-width:80px; width:150px;\">End</th>"; retString += $"<th style=\"background-color:rgba(90,90,90, 0.25);font-size:x-small;width:100px;\">Browser</th>"; retString += $"<th style=\"background-color:rgba(90,90,90, 0.25);font-size:x-small;width:200px;\">Current Url</th>"; retString += $"<th style=\"background-color:rgba(90,90,90, 0.25);font-size:x-small;width:300px\">Remote Address</th>"; retString += $"<th style=\"background-color:rgba(90,90,90, 0.25);font-size:x-small;min-width:80px; width:80px;\">CID</th>"; retString += $"<th style=\"background-color:rgba(90,90,90, 0.25);font-size:x-small;min-width:80px; width:80px;\">SID</th>"; retString += $"<th style=\"background-color:rgba(90,90,90, 0.25);font-size:x-small;width:400px;\">User Agent</th>"; retString += "</tr>"; } count++; TheSessionState tSession = MySessionStates.MyMirrorCache.MyRecords[tKey]; if (tSession.MyDevice == Guid.Empty) { tFont = " style='color:lightgray'"; } else { tFont = ""; } retString += $"<tr {tFont}>"; retString += $"<td class=\"cdeClip cdeLogEntry\" style=\"text-align:left;\">{tSession.cdeMID}</td>"; retString += $"<td class=\"cdeClip cdeLogEntry\" style=\"text-align:left;\">{TheCommonUtils.GetDeviceIDML(tSession.MyDevice)}</td>"; retString += $"<td class=\"cdeClip cdeLogEntry\" style=\"text-align:center;\">{TheCommonUtils.GetDateTimeString(tSession.LastAccess,-1)}</td>"; retString += $"<td class=\"cdeClip cdeLogEntry\" style=\"text-align:center;\">{TheCommonUtils.GetDateTimeString(tSession.EndTime,-1)}</td>"; retString += $"<td class=\"cdeClip cdeLogEntry\" style=\"text-align:left;\">{tSession.Browser} {tSession.BrowserDesc}</td>"; retString += $"<td class=\"cdeClip cdeLogEntry\" style=\"max-width:200px; width: 200px;\"><div class=\"cdeClip\" style=\"max-height:100px; overflow-y:auto;\">{tSession.CurrentURL}</div></td>"; retString += $"<td class=\"cdeClip cdeLogEntry\" style=\"text-align:left;\">{tSession.RemoteAddress}</td>"; retString += $"<td class=\"cdeClip cdeLogEntry\" style=\"text-align:left;\">{(tSession.CID==Guid.Empty?"Not Set":tSession.CID.ToString().Substring(0,4))}</td>"; retString += $"<td class=\"cdeClip cdeLogEntry\" style=\"text-align:left;\">{(string.IsNullOrEmpty(tSession.SScopeID) ? "Not Set" : cdeStatus.GetSScopeHashML(tSession.SScopeID))}</td>"; retString += $"<td class=\"cdeClip cdeLogEntry\" style=\"max-width:400px; width: 400px;\"><div class=\"cdeClip\" style=\"max-height:100px; overflow-y:auto;\">{tSession.UserAgent}</div></td>"; retString += "</tr>"; } if (count > 0) { retString += "</table></div>"; return(retString); } return(""); }
internal void RemoveSession(TheSessionState SessionState) { if (SessionState == null) { return; } SessionState.HasExpired = true; SessionState.EndTime = DateTimeOffset.Now; SessionState.ARApp = Guid.Empty; TheBaseAssets.MySYSLOG.WriteToLog(1234, TSM.L(eDEBUG_LEVELS.VERBOSE) ? null : new TSM("SSM", $"Session killed at {TheCommonUtils.GetDateTimeString(DateTimeOffset.Now)} for RemoteAdr: {TheCommonUtils.GetDeviceIDML(SessionState.MyDevice)}", eMsgLevel.l3_ImportantMessage)); TheCommonUtils.cdeRunAsync("RemoveSession", true, (o) => MySessionStates.RemoveAnItem(SessionState, null)); //Do not block the main thread...take your time HasExpired is set :) }
/// <summary> /// Handles Messages sent from a host sub-engine to its clients /// </summary> public void HandleMessage(ICDEThing sender, object pIncoming) { if (!(pIncoming is TheProcessMessage pMsg)) { return; } switch (pMsg.Message.TXT) { case "CDE_INITIALIZED": TheBaseAssets.MySYSLOG.WriteToLog(888, TSM.L(eDEBUG_LEVELS.FULLVERBOSE) ? null : new TSM("MiniRelayService", $"BackChannel Updated - ORG:{TheCommonUtils.GetDeviceIDML(pMsg.Message.GetLastRelay())}", eMsgLevel.l3_ImportantMessage)); break; default: if (pMsg.Message.TXT.Equals("CDE_INITIALIZE")) { TSM tRelayMsg = new TSM(MyBaseEngine.GetEngineName(), "CDE_INITIALIZED") { QDX = 3, SID = pMsg.Message.SID }; tRelayMsg.SetNoDuplicates(true); TheBaseAssets.MySYSLOG.WriteToLog(888, TSM.L(eDEBUG_LEVELS.FULLVERBOSE) ? null : new TSM("MiniRelayService", $"Message Text {tRelayMsg.TXT} relayed - ORG:{TheCommonUtils.GetDeviceIDML(tRelayMsg.ORG)}", eMsgLevel.l3_ImportantMessage)); //ORG-OK TheCommCore.PublishCentral(MyBaseEngine.GetEngineName() + pMsg.Message?.AddScopeIDFromTSM(), tRelayMsg); } break; } }
internal static string InfoHeader(bool IsSmall) { //string ret = $"<h3>{TheBaseAssets.MyServiceHostInfo.MyAppPresenter}</h3><h1>{TheBaseAssets.MyServiceHostInfo.ApplicationTitle} V{TheBaseAssets.MyServiceHostInfo.CurrentVersion}</h1><h3>Hosted at: {TheBaseAssets.LocalHostQSender.MyTargetNodeChannel}<br/>NodeName: {TheBaseAssets.MyServiceHostInfo.NodeName}</br>AppName:{TheBaseAssets.MyServiceHostInfo.ApplicationName}<br/>lcd: {TheBaseAssets.MyServiceHostInfo.BaseDirectory}</br>CDE:V{TheBaseAssets.CurrentVersionInfo} Drop: {TheBaseAssets.BuildVersion}</br>Started:{TheCommonUtils.GetDateTimeString(TheBaseAssets.MyServiceHostInfo.cdeCTIM, -1)}"; string ret2 = $"<h3>{TheBaseAssets.MyServiceHostInfo.MyAppPresenter}</h3>"; //<div id=\"mainBox\" style=\"width-fixed:90%;display:flex; flex-flow: column wrap\"> ret2 += $"<h1 id=\"title\">{TheBaseAssets.MyServiceHostInfo.ApplicationTitle} V{TheBaseAssets.MyServiceHostInfo.CurrentVersion}</h1>"; if (TheBaseAssets.MyServiceHostInfo.ShowMarkupInLog) { ret2 += $"<script>var cdeCSOn; function cdeColorSpan(pContent, pColor) {{ var x = document.getElementsByClassName(\"cdeRSHash\");var i;for (i = 0; i < x.length; i++){{ if (!pContent) {{ if (!cdeCSOn) x[i].style.backgroundColor = \"transparent\"; }} else {{ if (pContent.innerText==x[i].innerText && !cdeCSOn) x[i].style.backgroundColor = pColor; }}}}}}</script>"; } ret2 += $"<div class=\"cdeInfoBlock\" style=\"width:750px;\"><div class=\"cdeInfoBlockHeader cdeInfoBlockHeaderText\" id=\"nodeInfo\">Node Info</div><table style=\"margin-left:2%\">"; ret2 += $"<tr><th scope=\"rowgroup;\" style=\"background-color:rgba(90,90,90, 0.15); padding:3px; text-align:right; min-width:200px;\">Hosted at:</th><td style=\"border-bottom:1px solid rgba(90, 90, 90, 0.25);padding:3px;text-align:left \">{TheBaseAssets.LocalHostQSender.MyTargetNodeChannel.ToMLString(true)}</td></tr>"; ret2 += $"<tr><th scope=\"rowgroup;\" style=\"background-color:rgba(90,90,90, 0.15); padding:3px; text-align:right\">Node ID:</th><td style=\"border-bottom:1px solid rgba(90, 90, 90, 0.25);padding:3px;text-align:left \">{TheCommonUtils.GetDeviceIDML(TheBaseAssets.MyServiceHostInfo.MyDeviceInfo.DeviceID)}</td><tr>"; ret2 += $"<tr><th scope=\"rowgroup;\" style=\"background-color:rgba(90,90,90, 0.15); padding:3px; text-align:right\">Node Name:</th><td style=\"border-bottom:1px solid rgba(90, 90, 90, 0.25);padding:3px;text-align:left \">{TheBaseAssets.MyServiceHostInfo.NodeName}</td><tr>"; ret2 += $"<tr><th scope=\"rowgroup;\" style=\"background-color:rgba(90,90,90, 0.15); padding:3px; text-align:right\">Station Name:</th><td style=\"border-bottom:1px solid rgba(90, 90, 90, 0.25);padding:3px;text-align:left \">{TheBaseAssets.MyServiceHostInfo.MyStationName}</td><tr>"; ret2 += $"<tr><th scope=\"rowgroup;\" style=\"background-color:rgba(90,90,90, 0.15); padding:3px; text-align:right\">Application Name:</th><td style=\"border-bottom:1px solid rgba(90, 90, 90, 0.25);padding:3px;text-align:left \">{TheBaseAssets.MyServiceHostInfo.ApplicationName}</td><tr>"; ret2 += $"<tr><th scope=\"rowgroup;\" style=\"background-color:rgba(90,90,90, 0.15); padding:3px; text-align:right\">OS Info:</th><td style=\"border-bottom:1px solid rgba(90, 90, 90, 0.25);padding:3px;text-align:left;word-wrap: break-word;max-width:540px \">{TheBaseAssets.MyServiceHostInfo.OSInfo}</td><tr>"; ret2 += $"<tr><th scope=\"rowgroup;\" style=\"background-color:rgba(90,90,90, 0.15); padding:3px; text-align:right\">Local Dir:</th><td style=\"border-bottom:1px solid rgba(90, 90, 90, 0.25);padding:3px;text-align:left \">{TheBaseAssets.MyServiceHostInfo.BaseDirectory}</td><tr>"; ret2 += $"<tr><th scope=\"rowgroup;\" style=\"background-color:rgba(90,90,90, 0.15); padding:3px; text-align:right\">CDE Info:</th><td style=\"border-bottom:1px solid rgba(90, 90, 90, 0.25);padding:3px;text-align:left \">{TheBaseAssets.CurrentVersionInfo}</td><tr>"; ret2 += $"<tr><th scope=\"rowgroup;\" style=\"background-color:rgba(90,90,90, 0.15); padding:3px; text-align:right\">CDE Drop:</th><td style=\"border-bottom:1px solid rgba(90, 90, 90, 0.25);padding:3px;text-align:left \">V{TheBaseAssets.BuildVersion}</td><tr>"; ret2 += $"<tr><th scope=\"rowgroup;\" style=\"background-color:rgba(90,90,90, 0.15); padding:3px; text-align:right\">CDE Crypto:</th><td style=\"border-bottom:1px solid rgba(90, 90, 90, 0.25);padding:3px;text-align:left \">{TheBaseAssets.MySecrets.CryptoVersion()}</td><tr>"; ret2 += $"<tr><th scope=\"rowgroup;\" style=\"background-color:rgba(90,90,90, 0.15); padding:3px; text-align:right\">Unique Meshes Connected:</th><td style=\"border-bottom:1px solid rgba(90, 90, 90, 0.25);padding:3px;text-align:left \">{TheQueuedSenderRegistry.GetUniqueMeshCount()}</td><tr>"; string tScope = ""; if (TheBaseAssets.MyScopeManager.IsScopingEnabled) { tScope = GetScopeHashML(TheBaseAssets.MyScopeManager.GetScopeHash(null)); } ret2 += $"<tr><th scope=\"rowgroup;\" style=\"background-color:rgba(90,90,90, 0.15); padding:3px; text-align:right\">Local Node-Scope:</th><td style=\"border-bottom:1px solid rgba(90, 90, 90, 0.25);padding:3px;text-align:left \">{(TheBaseAssets.MyScopeManager.IsScopingEnabled ? $"A local Scope is set. Hash: {tScope}" : "Scoping is disabled")}</td><tr>"; ret2 += $"<tr><th scope=\"rowgroup;\" style=\"background-color:rgba(90,90,90, 0.15); padding:3px; text-align:right\">Client Cert Thumbprint:</th><td style=\"border-bottom:1px solid rgba(90, 90, 90, 0.25);padding:3px;text-align:left \">{(TheBaseAssets.MyServiceHostInfo.ClientCertificateThumb?.Length > 3 ? $"{TheBaseAssets.MyServiceHostInfo.ClientCertificateThumb.Substring(0, 4)}" : $"No client certificate specified")}</td><tr>"; ret2 += $"<tr><th scope=\"rowgroup;\" style=\"background-color:rgba(90,90,90, 0.15); padding:3px; text-align:right\">Node Started at:</th><td style=\"border-bottom:1px solid rgba(90, 90, 90, 0.25);padding:3px;text-align:left \">{TheCommonUtils.GetDateTimeString(TheBaseAssets.MyServiceHostInfo.cdeCTIM, -1)}</td><tr>"; ret2 += $"<tr><th scope=\"rowgroup;\" style=\"background-color:rgba(90,90,90, 0.15); padding:3px; text-align:right\">Last Update at:</th><td style=\"border-bottom:1px solid rgba(90, 90, 90, 0.25);padding:3px;text-align:left \">{TheCommonUtils.GetDateTimeString(DateTimeOffset.Now, -1)}</td><tr>"; ret2 += "</table>"; if (!IsSmall) { ret2 += $"<h2>Service Routes:</h2><table style=\"margin-left:2%\">"; ret2 += $"<tr><th scope=\"rowgroup;\" style=\"background-color:rgba(90,90,90, 0.15); padding:3px; text-align:right; width:200px;\">Configured Routes:</th><td style=\"border-bottom:1px solid rgba(90, 90, 90, 0.25);padding:3px;text-align:left \">{(string.IsNullOrEmpty(TheBaseAssets.MyServiceHostInfo.ServiceRoute) ? "No Routes are configured" : $"{TheBaseAssets.MyServiceHostInfo.ServiceRoute}")}</td></tr>";