public void WriteSession(TheSessionState pSession) { if (pSession == null || pSession.HasExpired) //we should never write an expired Session { return; } try { pSession.LastAccess = DateTimeOffset.Now; pSession.cdeCTIM = DateTimeOffset.Now; pSession.PageHits++; MySessionStates.UpdateItem(pSession, null); #if CDE_LOGSESSIONS if (TheCDEngines.MyStorageService != null) { //LogSession(pSession.cdeMID, pSession.CurrentURL, pSession.Browser, pSession.BrowserDesc, pSession.InitReferer, pSession.CustomData); TheBaseAssets.MySYSLOG.WriteToLog(1236, TSM.L(eDEBUG_LEVELS.FULLVERBOSE) ? null : new TSM("SSM", "WriteRession: Writing ", eMsgLevel.l6_Debug, pSession.ToString())); } #endif } catch (Exception e) { TheBaseAssets.MySYSLOG.WriteToLog(1237, new TSM("SSM", "WriteRession: Exception occured:", eMsgLevel.l2_Warning, e.ToString())); } }
/// <summary> /// Encrypts a string against the RSA Key inside a session /// </summary> /// <param name="pSessionID">SEID of the session the RSA Key is used</param> /// <param name="val">string value to be encrypted</param> /// <returns></returns> public static byte[] cdeRSAEncrypt(Guid pSessionID, string val) { TheSessionState pSession = TheBaseAssets.MySession?.ValidateSEID(pSessionID); //Low Frequency if (pSession == null) { return(null); } if (string.IsNullOrEmpty(pSession.RSAKey)) { CreateRSAKeys(pSession); } if (pSession == null || (string.IsNullOrEmpty(pSession.RSAPublic) && string.IsNullOrEmpty(pSession.RSAPublicSend))) { return(null); } try { return(TheBaseAssets.MyCrypto.RSAEncrypt(val, string.IsNullOrEmpty(pSession.RSAPublicSend) ? pSession.RSAPublic : pSession.RSAPublicSend)); } catch (Exception e) { TheBaseAssets.MySYSLOG?.WriteToLog(new TSM("TheCommonUtils", "Error During cdeRSAEncrypt", eMsgLevel.l1_Error) { PLS = e.ToString() }, 5016); } return(null); }
/// <summary> /// Creates new RSA Keys /// </summary> /// <param name="PrivateKey"></param> /// <returns></returns> public static string cdeRSACreateKeys(out string PrivateKey) { TheSessionState tSess = new TheSessionState(); CreateRSAKeys(tSess, true); PrivateKey = tSess.RSAKey; return(tSess.RSAPublic); }
private void sinkNewConnection(TheSessionState arg1) { VisitorCount++; if (arg1?.SiteName == null || TheCommonUtils.CGuid(arg1.SiteName) != Guid.Empty || arg1.SiteName == "::1") { return; } MyVisitorLog?.LogVisitor(arg1.SiteName, arg1.InitReferer); }
internal void KillSession(TheSessionState SessionState) { if (SessionState == null) { return; } RemoveSession(SessionState); sinkExpired(SessionState); }
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 TheSessionState GetOrCreateSessionState(Guid pSessionID, TheRequestData pRequest) { TheSessionState tS = ValidateSEID(pSessionID); //Measure Frequency!! if (tS == null) { tS = CreateSession(pRequest, pSessionID); } return(tS); }
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 :) }
internal bool SetLastHeartbeat(TheSessionState pState) { if (TheCommonUtils.IsLocalhost(MyTargetNodeChannel.cdeMID)) { return(true); } if (MyTargetNodeChannel.MySessionState == null) { MyTargetNodeChannel.MySessionState = pState; } ResetHeartbeatTimer(false, MyTargetNodeChannel.MySessionState); return(true); }
/// <summary> /// Connect to a Custom URL via ISB Connect and a custom Scope /// </summary> /// <param name="pUrl">URL to connect to</param> /// <param name="pEasyScope">Easy ScopeID generator for the connection. If next parameter is true, this parameter will be interpreted as a scrambled ScopeID</param> /// <param name="pInitialSubscriptions">List of initial Subscriptions separated by ;</param> /// <param name="pIsScrambledID">If true, the EasyScopeID is a scrambled ScopeID</param> /// <returns></returns> public string Connect(string pUrl, string pEasyScope, string pInitialSubscriptions, bool pIsScrambledID) { if (string.IsNullOrEmpty(pUrl)) { ERR = "no url set!"; return(ERR); } if (string.IsNullOrEmpty(pEasyScope)) { ERR = "No scope set - unscoped connection not allowed"; return(ERR); } mURL = pUrl; mInitSubs = pInitialSubscriptions; TheSessionState tSessionState = TheBaseAssets.MySession.CreateSession(null, Guid.Empty); if (!string.IsNullOrEmpty(pEasyScope)) { if (pIsScrambledID) { mSScope = tSessionState.SScopeID = pEasyScope; RS = TheBaseAssets.MyScopeManager.GetRealScopeID(tSessionState.SScopeID); //GRSI: rare } else { RS = TheBaseAssets.MyScopeManager.GetRealScopeIDFromEasyID(pEasyScope); mSScope = tSessionState.SScopeID = TheBaseAssets.MyScopeManager.GetScrambledScopeID(RS, true); //GRSI: rare } } MyQSender = new TheQueuedSender { MyISBlock = this }; IS = TheBaseAssets.MyScopeManager.AddScopeID(pInitialSubscriptions, false, RS); if (MyQSender.StartSender(new TheChannelInfo(Guid.Empty, RS, cdeSenderType.CDE_CUSTOMISB, pUrl) { MySessionState = tSessionState }, null, false)) { FNI = MyQSender.MyTargetNodeChannel.cdeMID.ToString(); SID = tSessionState.SScopeID; OnThisNode = true; } else { ERR = "Qsender could not be created"; TheBaseAssets.MySYSLOG.WriteToLog(299, TSM.L(eDEBUG_LEVELS.VERBOSE) ? null : new TSM("CoreComm", $"CreateCustomSender: QueuedSender could not be created for Target:{pUrl}", eMsgLevel.l7_HostDebugMessage)); MyQSender = null; } return(ERR); }
internal bool UpdateSessionLCID(Guid pSessionID, int pLCID) { lock (GetLock()) //LOCK-REVIEW: This is more a logic lock then read/write MySessionStates.MyRecordsLock) //low impact { TheSessionState tSess = ValidateSEID(pSessionID); //Low Frequency if (tSess != null) { tSess.LCID = pLCID; MySessionStates.UpdateItem(tSess, null); return(true); } } return(false); }
internal static void CreateRSAKeys(TheSessionState pSession, bool createXMLKeyAlways = false) { if (TheBaseAssets.MyServiceHostInfo.DisableRSAToBrowser || pSession == null) { return; //RSA Not working } lock (pSession) { if (string.IsNullOrEmpty(pSession.RSAKey) && pSession.MyRSA == null) { TheBaseAssets.MySYSLOG?.WriteToLog(TSM.L(eDEBUG_LEVELS.ESSENTIALS) ? null : new TSM("SSM", $"CreateRSAKey at {GetDateTimeString(DateTimeOffset.Now)}", eMsgLevel.l6_Debug), 5010, true); pSession.MyRSA = TheBaseAssets.MyCrypto.CreateRSAKeys(out var tRSAKey, out var tRSAPublic, createXMLKeyAlways); pSession.RSAKey = tRSAKey; pSession.RSAPublic = tRSAPublic; TheBaseAssets.MySYSLOG?.WriteToLog(TSM.L(eDEBUG_LEVELS.OFF) ? null : new TSM("SSM", $"New Session {pSession.cdeMID} established and RSAKey created at {GetDateTimeString(DateTimeOffset.Now, 0)}", eMsgLevel.l6_Debug), 5011, true); } } }
internal void sinkExpired(TheSessionState pState) { if (pState != null) { if (pState.CID != Guid.Empty) { TheUserManager.RemoveTempUser(pState.CID); } TheQueuedSender tQSend = TheQueuedSenderRegistry.GetSenderBySEID(pState.cdeMID); if (tQSend != null) { tQSend.FireSenderProblem(new TheRequestData() { ErrorDescription = "1500:Session for this QSender expired" }); } } }
internal List <Guid> GetCurrentUsers() { List <Guid> tUsers = new List <Guid>(); List <string> tSessions = MySessionStates?.TheKeys; if (tSessions == null || tSessions.Count == 0) { return(null); } foreach (string tKey in tSessions) { TheSessionState tSession = MySessionStates.MyMirrorCache.MyRecords[tKey]; if (tSession.CID != Guid.Empty && !tUsers.Contains(tSession.CID)) { tUsers.Add(tSession.CID); } } return(tUsers); }
internal void ResetHeartbeatTimer(bool IsChangeRequest, TheSessionState pSession) { InitHeartbeatTimer(); if (MyTargetNodeChannel == null || MyTargetNodeChannel.SenderType == cdeSenderType.CDE_LOCALHOST) { return; } TheBaseAssets.MySession.WriteSession(pSession); if (string.IsNullOrEmpty(MyTargetNodeChannel.RealScopeID) && !string.IsNullOrEmpty(pSession.SScopeID) && MyISBlock == null) //RScope-OK: This should be super rare that a channel has no RScope but the SessionState has a Scope { UpdateSubscriptionScope(TheBaseAssets.MyScopeManager.GetRealScopeID(pSession.SScopeID)); //GRSI: rare } if (IsChangeRequest) { TheBaseAssets.MySYSLOG.WriteToLog(247, TSM.L(eDEBUG_LEVELS.FULLVERBOSE) ? null : new TSM("QueuedSender", $"{TheBaseAssets.MyServiceHostInfo.GetPrimaryStationURL(false)} received Heartbeat Change Request for {MyTargetNodeChannel.ToMLString()}", eMsgLevel.l6_Debug), true); } else { TheBaseAssets.MySYSLOG.WriteToLog(247, TSM.L(eDEBUG_LEVELS.FULLVERBOSE) ? null : new TSM("QueuedSender", $"{TheBaseAssets.MyServiceHostInfo.GetPrimaryStationURL(false)} received and reset Heartbeat for {MyTargetNodeChannel.ToMLString()}", eMsgLevel.l6_Debug), true); } }
public void LogSession(Guid pSessionID, string pUrl, string pBrowser, string pBrowserDesc, string pRef, string pCustomData) { if (TheCDEngines.MyIStorageService == null) { return; } TheSessionState pSess = new TheSessionState { cdeMID = pSessionID, CurrentURL = pUrl, Browser = pBrowser, LastAccess = DateTimeOffset.Now, BrowserDesc = pBrowserDesc, CustomData = pCustomData, RunID = pSessionID, InitReferer = pRef }; pSess.PageHits++; TheCDEngines.MyIStorageService.EdgeDataStoreOnly(pSess, null); }
/// <summary> /// Returns a decrypted string agains the RSA Key stored in the session /// </summary> /// <param name="pSessionID">SEID of the session the RSA Key is used</param> /// <param name="val">Envrypted byte array to be decrypted</param> /// <returns></returns> public static string cdeRSADecrypt(Guid pSessionID, byte[] val) { TheSessionState tSession = TheBaseAssets.MySession?.ValidateSEID(pSessionID); //Low Frequency if (tSession == null) { return(""); } try { return(TheBaseAssets.MyCrypto.RSADecrypt(val, tSession.MyRSA, tSession.RSAKey, tSession.RSAPublic)); } catch (Exception e) { TheBaseAssets.MySYSLOG?.WriteToLog(new TSM("TheCommonUtils", "Error During cdeRSADecrypt", eMsgLevel.l1_Error) { PLS = e.ToString() }, 5015); } return(""); }
internal void SetVer(TheRequestData pRequestData, bool tSessionReset, bool UpdateLog, Guid WPID) { TheSessionState pSession = pRequestData?.SessionState; if (pSession == null || pSession.HasExpired) { return; } try { if (tSessionReset) { lock (pSession.MySessionLock) { //pSession.CMember = sstrLocalMachine; pSession.MembUID = ""; pSession.MembPWD = ""; pSession.MembFullName = ""; pSession.Status = "N"; pSession.CID = Guid.Empty; pSession.Debug = 0; pSession.MembLevel = 0; pSession.PUIDHigh = 0; pSession.PUIDLow = 0; //<Fix>3.5.202,CM,5/20/2004,Vertical Application must be reset as well</Fix> pSession.CustomDataLng = 0; pSession.LCID = 0; WriteSession(pSession); } //TheSystemMessageLog.ToCo(string.Format("SESS: Reset Session {0}", pRequestData.SessionState)); } else { if (UpdateLog) { pSession.LastAccess = DateTimeOffset.Now; pSession.cdeCTIM = DateTimeOffset.Now; if (TheCommonUtils.cdeIsLocked(pSession.MySessionLock)) // Is writing already...dont do it again { return; } lock (pSession.MySessionLock) //CODE-REVIEW: Is this really necessarry? { pSession.CurrentWPID = WPID; pSession.Status = "A"; if (pRequestData.ServerTags != null) { pSession.InitReferer = pRequestData.ServerTags.cdeSafeGetValue("HTTP_REFERER"); } if (string.IsNullOrEmpty(pSession.InitReferer) && pRequestData.Header != null) { pSession.InitReferer = pRequestData.Header.cdeSafeGetValue("REFERER"); } if (string.IsNullOrEmpty(pSession.InitReferer) && !string.IsNullOrEmpty(pSession.CurrentURL)) { pSession.InitReferer = pSession.CurrentURL; } string gstrCurURL = pRequestData.RequestUri.LocalPath + "/" + pRequestData.RequestUri.Query; pSession.CurrentURL = gstrCurURL; if (string.IsNullOrEmpty(pSession.InitReferer)) { try { //CM:4.105 No idea why this exists - must be legacy code //if (pSession.StateCookies == null) pSession.StateCookies = new cdeConcurrentDictionary<string, string>(); //string tref = TheCommonUtils.cdeEncrypt(TheCommonUtils.CStr(gstrCurURL), TheBaseAssets.MySecrets.GetAI()); //3.083: Must use AI //pSession.StateCookies.TryAdd(MySite.cdeMID.ToString() + "CDEREF", TheCommonUtils.cdeEscapeString(tref)); pSession.InitReferer = TheCommonUtils.CStr(gstrCurURL); } catch { //ignored } } WriteSession(pSession); // TheSystemMessageLog.ToCo(string.Format("SESS: Updating Session {0}", pRequestData.SessionState)); } } } } catch (Exception e) { TheBaseAssets.MySYSLOG.WriteToLog(1235, new TSM("SSM", "<HR>SetVer: Exception occurred:", e.ToString())); } }
internal void UpdateSessionID(TheSessionState pState, Guid pNewID) { MySessionStates.UpdateID(pState.cdeMID, pNewID); }
internal string GetNodeLog(TheSessionState pSession, string InTopic, bool ShowLinks) { string outText = ""; if (!string.IsNullOrEmpty(InTopic)) { InTopic = TheCommonUtils.cdeUnescapeString(InTopic); } outText += $"<div class=\"cdeInfoBlock\" style=\"clear:both; width:initial; \"><div class=\"cdeInfoBlockHeader cdeInfoBlockHeaderText\" id=\"systemLog\">Current SystemLog <a download=\"cdeSysLog_{TheCommonUtils.GetMyNodeName()}.csv\" href=\"#\" class=\'cdeExportLink\' onclick=\"return ExcellentExport.csv(this, 'cdeSysLog');\">(Export as CSV)</a></div>"; try { outText += "<table class=\"cdeHilite\" id=\"cdeSysLog\" style=\"width:95%\">"; outText += "<tr><th style=\"background-color:rgba(90,90,90, 0.25);font-size:small;\">Serial</th>"; outText += "<th style=\"background-color:rgba(90,90,90, 0.25);font-size:small; \">LogID</th>"; outText += "<th style=\"background-color:rgba(90,90,90, 0.25);font-size:small; \">Entry Date</th>"; outText += "<th style=\"background-color:rgba(90,90,90, 0.25);font-size:small; \">Level</th>"; //outText += "<th style=\"background-color:rgba(90,90,90, 0.25);font-size:small; \">ORG</th>"; outText += "<th style=\"background-color:rgba(90,90,90, 0.25);font-size:small; \">Engine</th>"; outText += "<th style=\"background-color:rgba(90,90,90, 0.25);font-size:small; \">Text</th><tr>"; int MaxCnt = MyMessageLog.MyMirrorCache.Count; foreach (TheEventLogEntry tLogEntry in MyMessageLog.MyMirrorCache.MyRecords.Values.OrderByDescending(s => s.Serial).ToList()) //.cdeCTIM).ThenByDescending(s=>s.cdeCTIM.Millisecond).ToList()) { TSM tMsg = tLogEntry.Message; if (!string.IsNullOrEmpty(InTopic) && !tMsg.ENG.Equals(InTopic)) { continue; } if (tMsg.TXT == null) { tMsg.TXT = ""; } var tColor = "black"; if (tMsg.TXT.Contains("ORG:2;")) { tColor = "blue"; } else { if (tMsg.TXT.Contains("ORG:4;")) { tColor = "purple"; } else { if (tMsg.TXT.Contains("ORG:3;")) { tColor = "navy"; } else { if (tMsg.TXT.Contains("ORG:7;")) { tColor = "brown"; } else { if (tMsg.TXT.Contains("ORG:8;") || TheCommonUtils.DoesContainLocalhost(tMsg.TXT)) { tColor = "gray"; } } } } } switch (tMsg.LVL) { case eMsgLevel.l1_Error: tColor = "red"; break; case eMsgLevel.l2_Warning: tColor = "orange"; break; case eMsgLevel.l3_ImportantMessage: tColor = "green"; break; case eMsgLevel.l7_HostDebugMessage: tColor = "gray"; break; case eMsgLevel.l6_Debug: tColor = "gray"; break; } outText += $"<tr>"; outText += $"<td class=\"cdeLogEntry\" style=\"color:{tColor}\">{tLogEntry.Serial}</td>"; outText += $"<td class=\"cdeLogEntry\" style=\"color:{tColor}\">{tLogEntry.EventID}</td>"; outText += $"<td class=\"cdeLogEntry\" style=\"color:{tColor}\">{TheCommonUtils.GetDateTimeString(tMsg.TIM, 0, "yyyy-MM-dd HH:mm:ss.fff")}</td>"; outText += $"<td class=\"cdeLogEntry\" style=\"color:{tColor}\">{tMsg.LVL}{(TSM.L(eDEBUG_LEVELS.ESSENTIALS)?tMsg.GetHash().ToString():"")}</td>"; //outText += $"<td class=\"cdeLogEntry\" style=\"color:{tColor}\">{tMsg.ORG}</td>"; //ORG-OK if (ShowLinks && pSession != null) { outText += $"<td class=\"cdeLogEntry\"><SMALL><a href=\"/cdeStatus.aspx?Filter={TheCommonUtils.cdeEscapeString(tMsg.ENG)}\">{tMsg.ENG}</a></SMALL></td>"; } else { outText += $"<td class=\"cdeLogEntry\"><SMALL>{tMsg.ENG.Replace(".", " ")}</SMALL></td>"; } outText += $"<td class=\"cdeLogEntry\" style=\"color:{tColor}\">{tMsg.TXT}</td>"; outText += "</tr>"; if (!string.IsNullOrEmpty(tMsg.PLS)) { outText += $"<tr><td class=\"cdeLogEntry\" style=\"color:{tColor}\">{tLogEntry.Serial}</td><td class=\"cdeLogEntry\" colspan=\"7\" style=\"color:{tColor}\"><SMALL>{TheCommonUtils.cdeESCXMLwBR(TheCommonUtils.cdeSubstringMax(tMsg.PLS, 2000))}</SMALL></td></tr>"; //Find a better way. This does not work with the sorttable } MaxCnt--; } outText += "</tbody></table></div>"; } catch (Exception e) { outText += "Exception in Log: " + e; } return(outText); }
internal TheSessionState CreateSession(TheRequestData pRequest, Guid pSessionID) { string strAcceptLanguage = null; int strLCID = 0; string localIP = ""; try { if (pRequest != null && pRequest.ServerTags != null) { strAcceptLanguage = pRequest.ServerTags.cdeSafeGetValue("HTTP_ACCEPT_LANGUAGE"); } if (string.IsNullOrEmpty(strAcceptLanguage)) { strAcceptLanguage = "en-us"; } } catch //Exception e) { strAcceptLanguage = "en-us"; } try { localIP = Discovery.TheNetworkInfo.GetIPAddress(false).ToString(); } catch { //ignored } string tTRGTSRV = MySite.TrgtSrv; try { string debRGTSRV = MySite.DebTrgtSrv; if (!string.IsNullOrEmpty(debRGTSRV) && !string.IsNullOrEmpty(localIP) && (localIP.Substring(0, 7).Equals("192.168") || localIP.Substring(0, 5).Equals("127.0"))) { tTRGTSRV = debRGTSRV; } } catch { //ignored } if (strAcceptLanguage.Length > 10) { strAcceptLanguage = strAcceptLanguage.Substring(0, 10); } TheSessionState pSession = new TheSessionState(); if (pSessionID != Guid.Empty) { pSession.cdeMID = pSessionID; } try { if (pRequest != null) { if (pRequest.ServerTags != null) { pSession.InitReferer = pRequest.ServerTags.cdeSafeGetValue("HTTP_REFERER"); pSession.UserAgent = pRequest.ServerTags.cdeSafeGetValue("ALL_HTTP"); foreach (string t in s_HeaderItems) { pSession.SiteName = pRequest.ServerTags.cdeSafeGetValue(t); if (!string.IsNullOrEmpty(pSession.SiteName)) { break; } } } pSession.Browser = pRequest.BrowserType; pSession.BrowserDesc = pRequest.BrowserPlatform; pSession.ScreenWidth = pRequest.BrowserScreenWidth; if (!string.IsNullOrEmpty(pRequest.RemoteAddress)) { pSession.RemoteAddress = pRequest.RemoteAddress; } else { pSession.RemoteAddress = pRequest.DeviceID.ToString(); } if (string.IsNullOrEmpty(pSession.SiteName) && pRequest.DeviceID != Guid.Empty) { pSession.SiteName = pRequest.DeviceID.ToString(); } pSession.MyDevice = pRequest.DeviceID; if (string.IsNullOrEmpty(pSession.InitReferer) && pRequest.Header != null) { pSession.InitReferer = pRequest.Header.cdeSafeGetValue("Referer"); } } pSession.EntryTime = DateTimeOffset.Now; pSession.LastAccess = DateTimeOffset.Now; //pSession.CMember = sstrLocalMachine; pSession.PageHits = 1; pSession.TRGTSRV = tTRGTSRV; pSession.LCID = strLCID; pSession.BrowserLanguage = strAcceptLanguage.ToLower(); TheCommCore.eventNewSessionCreated?.Invoke(pSession); } catch (Exception obErr) { TheBaseAssets.MySYSLOG.WriteToLog(1232, new TSM("SSM", "<HR>Create-Session: Exception occured:", obErr.ToString())); } return(pSession); }