// should be checked public string GetIP() { OperationContext context = OperationContext.Current; System.ServiceModel.Channels.MessageProperties properties = context.IncomingMessageProperties; System.ServiceModel.Channels.RemoteEndpointMessageProperty endpoint = properties[System.ServiceModel.Channels.RemoteEndpointMessageProperty.Name] as System.ServiceModel.Channels.RemoteEndpointMessageProperty; string address = string.Empty; if (properties.Keys.Contains(System.ServiceModel.Channels.HttpRequestMessageProperty.Name)) { System.ServiceModel.Channels.HttpRequestMessageProperty endpointLoadBalancer = properties[System.ServiceModel.Channels.HttpRequestMessageProperty.Name] as System.ServiceModel.Channels.HttpRequestMessageProperty; if (endpointLoadBalancer != null && endpointLoadBalancer.Headers["X-Forwarded-For"] != null) { address = endpointLoadBalancer.Headers["X-Forwarded-For"]; } } if (string.IsNullOrEmpty(address)) { address = endpoint.Address; } return(address); }
// should be checked public string GetIP2() { OperationContext oOperationContext = OperationContext.Current; System.ServiceModel.Channels.MessageProperties oMessageProperties = oOperationContext.IncomingMessageProperties; System.ServiceModel.Channels.RemoteEndpointMessageProperty oRemoteEndpointMessageProperty = (System.ServiceModel.Channels.RemoteEndpointMessageProperty)oMessageProperties[System.ServiceModel.Channels.RemoteEndpointMessageProperty.Name]; string szAddress = oRemoteEndpointMessageProperty.Address; int nPort = oRemoteEndpointMessageProperty.Port; return("IP " + szAddress + " Port " + nPort.ToString()); }
/// <summary> /// 该方法只能在服务端使用。 /// 获取请求的服务IP; /// </summary> /// <returns></returns> public static string GetRequestIP() { if (System.ServiceModel.OperationContext.Current == null) { int threadId = System.Threading.Thread.CurrentThread.ManagedThreadId; s_logger.Info("GetRequestIP() return [localhost]"); return("localhost" + threadId.ToString()); } try { var msgPropertys = System.ServiceModel.OperationContext.Current.IncomingMessageProperties; if (msgPropertys == null || !msgPropertys.ContainsKey(System.ServiceModel.Channels.RemoteEndpointMessageProperty.Name)) { s_logger.Info("GetRequestIP() return [localhost]"); return("localhost"); } string ipAddr = string.Empty; string ipInfo = string.Empty; ipAddr = GetClientIPAddress(out ipInfo); s_logger.Info(ipInfo); s_logger.InfoFormat("GetClientIPAddress(out ipInfo) return [{0}].", new object[] { ipAddr }); if (!string.IsNullOrEmpty(ipAddr)) { _LastGetClientIp = ipAddr; return(_LastGetClientIp); } System.ServiceModel.Channels.RemoteEndpointMessageProperty endPoint = msgPropertys[System.ServiceModel.Channels.RemoteEndpointMessageProperty.Name] as System.ServiceModel.Channels.RemoteEndpointMessageProperty; _LastGetClientIp = endPoint.Address; return(_LastGetClientIp); //只获取IPV4 格式 (影响性能,需要设计一个HashTable来缓存才可以) //if (remoteIP.IndexOf(":") < -1) { // IPAddress[] addresses = Dns.GetHostAddresses(remoteIP); // for (int i = 0; i < addresses.Length; i++) { // if (addresses[i].ToString().IndexOf(".") > -1) // return addresses[i].ToString(); // } // return remoteIP; //} else { // return remoteIP; //} } catch { return("*" + _LastGetClientIp + "*"); } }
private string GetClientIP() { try { System.ServiceModel.OperationContext context = System.ServiceModel.OperationContext.Current; System.ServiceModel.Channels.MessageProperties prop = context.IncomingMessageProperties; System.ServiceModel.Channels.RemoteEndpointMessageProperty endpoint = prop[System.ServiceModel.Channels.RemoteEndpointMessageProperty.Name] as System.ServiceModel.Channels.RemoteEndpointMessageProperty; return(endpoint.Address); } catch (Exception ex) { log.Error(ex); } return(""); }
public LoginInfo Login1(string userId, string password, bool quitOther = false) { LoginInfo loginInfo = new LoginInfo(); SqlBuilder builder = new SqlBuilder("axp.User"); string sql = builder.GetQuerySql(0, "A.Id,A.Name,A.UserImage", string.Format("A.Id={0} And A.Password={1} And A.ISUSE=1", LibStringBuilder.GetQuotString(userId), LibStringBuilder.GetQuotString(password))); LibDataAccess dataAccess = new LibDataAccess(); string roleId = string.Empty; bool exists = false; using (IDataReader reader = dataAccess.ExecuteDataReader(sql)) { if (reader.Read()) { loginInfo.Id = LibSysUtils.ToString(reader[0]); loginInfo.Name = LibSysUtils.ToString(reader[1]); loginInfo.UserImage = LibSysUtils.ToString(reader[2]); exists = true; } } if (exists) { LibHandle handle = LibHandleCache.Default.IsExistsHandle(LibHandeleType.PC, userId); if (handle != null) { //LibHandleCache.Default.RemoveHandle(handle.Handle); } if (!loginInfo.IsUsed) { string loginIp = string.Empty; //Zhangkj20161219 增加LoginIp System.ServiceModel.OperationContext context = System.ServiceModel.OperationContext.Current; //对于非WCF的访问context为null if (context != null) { System.ServiceModel.Channels.MessageProperties properties = context.IncomingMessageProperties; System.ServiceModel.Channels.RemoteEndpointMessageProperty endpoint = properties[System.ServiceModel.Channels.RemoteEndpointMessageProperty.Name] as System.ServiceModel.Channels.RemoteEndpointMessageProperty; loginIp = endpoint.Address + ":" + endpoint.Port.ToString(); } //创建新的Handle handle = LibHandleCache.Default.GetHandle(string.Empty, LibHandeleType.PC, userId, loginInfo.PersonId, loginInfo.PersonName, roleId, loginIp); if (handle != null) { loginInfo.Handle = handle.Handle; } } } return(loginInfo); }
public string GetQuickMonCoreVersion() { StringBuilder consoleOutPut = new StringBuilder(); string versionInfo = System.Reflection.Assembly.GetAssembly(typeof(MonitorPack)).GetName().Version.ToString(); consoleOutPut.AppendFormat("Version request response: {0}\r\n", versionInfo); try { OperationContext context = OperationContext.Current; System.ServiceModel.Channels.MessageProperties messageProperties = context.IncomingMessageProperties; System.ServiceModel.Channels.RemoteEndpointMessageProperty endpointProperty = messageProperties[System.ServiceModel.Channels.RemoteEndpointMessageProperty.Name] as System.ServiceModel.Channels.RemoteEndpointMessageProperty; consoleOutPut.AppendFormat("Requested from {0}:{1}\r\n", endpointProperty.Address, endpointProperty.Port); } catch (Exception ex) { consoleOutPut.AppendFormat("Error getting caller info: {0}\r\n", ex.Message); } consoleOutPut.AppendLine(new string('*', 79)); Console.WriteLine(consoleOutPut.ToString()); return(versionInfo); }
public LoginInfo Login(string userId, string password, bool quitOther = false) { LoginInfo loginInfo = new LoginInfo(); SqlBuilder builder = new SqlBuilder("axp.User"); string sql = builder.GetQuerySql(0, "A.PERSONID,A.PERSONNAME,A.ROLEID,A.WALLPAPER,A.WALLPAPERSTRETCH", string.Format("A.USERID={0} And A.USERPASSWORD={1} And A.ISUSE=1", LibStringBuilder.GetQuotString(userId), LibStringBuilder.GetQuotString(password))); LibDataAccess dataAccess = new LibDataAccess(); string roleId = string.Empty; bool exists = false; using (IDataReader reader = dataAccess.ExecuteDataReader(sql)) { if (reader.Read()) { loginInfo.PersonId = LibSysUtils.ToString(reader[0]); loginInfo.PersonName = LibSysUtils.ToString(reader[1]); roleId = LibSysUtils.ToString(reader[2]); loginInfo.Wallpaper = LibSysUtils.ToString(reader[3]); loginInfo.Stretch = LibSysUtils.ToBoolean(reader[4]); exists = true; } } if (exists) { LibHandle handle = LibHandleCache.Default.IsExistsHandle(LibHandeleType.PC, userId); if (handle != null) { if (quitOther) { LibHandleCache.Default.RemoveHandle(handle.Handle); } else { loginInfo.IsUsed = true; } } if (!loginInfo.IsUsed) { long currentCount = LibHandleCache.Default.GetCount(); long maxUserCount = (long)LibHandleCache.Default.MaxUserCount; if (maxUserCount != -1 && maxUserCount < currentCount) { loginInfo.IsOverUser = true; } else { string loginIp = string.Empty; //Zhangkj20161219 增加LoginIp System.ServiceModel.OperationContext context = System.ServiceModel.OperationContext.Current; //对于非WCF的访问context为null if (context != null) { System.ServiceModel.Channels.MessageProperties properties = context.IncomingMessageProperties; System.ServiceModel.Channels.RemoteEndpointMessageProperty endpoint = properties[System.ServiceModel.Channels.RemoteEndpointMessageProperty.Name] as System.ServiceModel.Channels.RemoteEndpointMessageProperty; loginIp = endpoint.Address + ":" + endpoint.Port.ToString(); } //创建新的Handle handle = LibHandleCache.Default.GetHandle(string.Empty, LibHandeleType.PC, userId, loginInfo.PersonId, loginInfo.PersonName, roleId, loginIp); if (handle != null) { loginInfo.Handle = handle.Handle; } } } } return(loginInfo); }
public LoginInfo AppLogin(string userId, string password, string clientId, int clientType, bool quitOther = false) { LoginInfo loginInfo = new LoginInfo(); //检查是否具有 AXPUSERAPP数据表,用于判定是否支持移动端App登录 LibSqlModel sqlModel = LibSqlModelCache.Default.GetSqlModel("axp.User"); bool hasAXPUSERAPP = false; if (sqlModel != null && sqlModel.Tables.Count > 1 && sqlModel.Tables[1].TableName.Equals("AXPUSERAPP")) { hasAXPUSERAPP = true; } if (hasAXPUSERAPP == false) { return(loginInfo);//如果没有需要的相关字段则直接返回 } SqlBuilder builder = new SqlBuilder("axp.User"); string sql = string.Format(@"SELECT A.PERSONID, A.ROLEID, A.WALLPAPER,A.WALLPAPERSTRETCH,B.PERSONNAME,B.PHONENO,B.CORNET,B.HEADPORTRAIT,B.MAIL FROM AXPUSER A LEFT JOIN COMPERSON B ON B.PERSONID=A.PERSONID WHERE A.USERID={0} and A.USERPASSWORD={1} AND A.ISUSE=1", LibStringBuilder.GetQuotString(userId), LibStringBuilder.GetQuotString(password)); //builder.GetQuerySql(0, "A.PERSONID,A.PERSONNAME,A.PHONENO,A.CORNET,A.HEADPORTRAIT,A.MAIL,A.ROLEID,A.WALLPAPER,A.WALLPAPERSTRETCH", string.Format("A.USERID={0} And A.USERPASSWORD={1} And A.ISUSE=1", LibStringBuilder.GetQuotString(userId), LibStringBuilder.GetQuotString(password))); LibDataAccess dataAccess = new LibDataAccess(); string roleId = string.Empty; bool exists = false; using (IDataReader reader = dataAccess.ExecuteDataReader(sql)) { if (reader.Read()) { loginInfo.PersonId = LibSysUtils.ToString(reader["PERSONID"]); loginInfo.PersonName = LibSysUtils.ToString(reader["PERSONNAME"]); roleId = LibSysUtils.ToString(reader["ROLEID"]); loginInfo.Wallpaper = LibSysUtils.ToString(reader["WALLPAPER"]); loginInfo.Stretch = LibSysUtils.ToBoolean(reader["WALLPAPERSTRETCH"]); //20170214 施卢威 增加头像 Email 短号信息 loginInfo.Headportrait = LibSysUtils.ToString(reader["HEADPORTRAIT"]); loginInfo.UserEMail = LibSysUtils.ToString(reader["MAIL"]); loginInfo.Cornet = LibSysUtils.ToString(reader["CORNET"]); loginInfo.UserPhone = LibSysUtils.ToString(reader["PHONENO"]); exists = true; } } if (exists) { #region 帐号与登录设备关联 string appSql = string.Empty; //查询帐号是否已有设备标识 int isAPPClient = LibSysUtils.ToInt32(dataAccess.ExecuteScalar(string.Format("SELECT COUNT(*) from AXPUSERAPP WHERE USERID = '{0}' and CLIENTTYPE={1}", userId, clientType))); if (isAPPClient > 0) { //更新设备标识信息 appSql = string.Format("UPDATE AXPUSERAPP SET CLIENTID={1} WHERE USERID={0} AND CLIENTTYPE={2}", LibStringBuilder.GetQuotString(userId), LibStringBuilder.GetQuotString(clientId), clientType); } else { int curMaxRowId = LibSysUtils.ToInt32(dataAccess.ExecuteScalar(string.Format("SELECT Max(ROW_ID) from AXPUSERAPP WHERE USERID='{0}'", userId))); //插入账户对应的App设备标识信息。 appSql = string.Format("insert into AXPUSERAPP(USERID,ROW_ID,ROWNO,CLIENTTYPE,CLIENTID) values('{0}',{1},{2},{3},'{4}')", userId, curMaxRowId + 1, curMaxRowId + 1, clientType, clientId, 1); } dataAccess.ExecuteNonQuery(appSql); #endregion LibHandle handle = LibHandleCache.Default.IsExistsHandle(LibHandeleType.PC, userId); if (handle != null) { if (quitOther) { LibHandleCache.Default.RemoveHandle(handle.Handle); } else { loginInfo.IsUsed = true; } } if (!loginInfo.IsUsed) { long currentCount = LibHandleCache.Default.GetCount(); long maxUserCount = (long)LibHandleCache.Default.MaxUserCount; if (maxUserCount != -1 && maxUserCount < currentCount) { loginInfo.IsOverUser = true; } else { string loginIp = string.Empty; //Zhangkj20161219 增加LoginIp System.ServiceModel.OperationContext context = System.ServiceModel.OperationContext.Current; //对于非WCF的访问context为null if (context != null) { System.ServiceModel.Channels.MessageProperties properties = context.IncomingMessageProperties; System.ServiceModel.Channels.RemoteEndpointMessageProperty endpoint = properties[System.ServiceModel.Channels.RemoteEndpointMessageProperty.Name] as System.ServiceModel.Channels.RemoteEndpointMessageProperty; loginIp = endpoint.Address + ":" + endpoint.Port.ToString(); handle = LibHandleCache.Default.GetHandle(string.Empty, LibHandeleType.PC, userId, loginInfo.PersonId, loginInfo.PersonName, roleId, loginIp); } else { handle = LibHandleCache.Default.GetHandle(string.Empty, LibHandeleType.PC, userId, loginInfo.PersonId, loginInfo.PersonName, roleId); } //创建新的Handle if (handle != null) { loginInfo.Handle = handle.Handle; } } } } return(loginInfo); }
public MonitorState GetState(QuickMon.RemoteCollectorHost entry) { StringBuilder consoleOutPut = new StringBuilder(); MonitorState monitorState = new MonitorState(); /*** For Console debugging **/ consoleOutPut.AppendFormat("{0}: Running collector host: {1}\r\n", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), entry.Name); try { OperationContext context = OperationContext.Current; System.ServiceModel.Channels.MessageProperties messageProperties = context.IncomingMessageProperties; System.ServiceModel.Channels.RemoteEndpointMessageProperty endpointProperty = messageProperties[System.ServiceModel.Channels.RemoteEndpointMessageProperty.Name] as System.ServiceModel.Channels.RemoteEndpointMessageProperty; consoleOutPut.AppendFormat(" Requested from {0}:{1}\r\n", endpointProperty.Address, endpointProperty.Port); } catch (Exception ex) { consoleOutPut.AppendFormat(" Error getting caller info: {0}\r\n", ex.Message); } consoleOutPut.AppendFormat("{0}\r\n", new string('*', 79)); Console.WriteLine(consoleOutPut.ToString()); consoleOutPut = new StringBuilder(); /*** For Console debugging **/ try { string collectorHostConfig = entry.ToCollectorHostXml(); string tempMonitorPack = "<monitorPack version=\"5.0.0.0\" name=\"\" typeName=\"\" enabled=\"True\" defaultNotifier=\"\" runCorrectiveScripts=\"False\" collectorStateHistorySize=\"1\" pollingFreqSecOverride=\"0\">" + "<collectorHosts>" + collectorHostConfig + "</collectorHosts>\r\n" + "<notifierHosts>\r\n" + "</notifierHosts>\r\n" + "</monitorPack>"; MonitorPack m = new MonitorPack(); m.LoadXml(tempMonitorPack); m.ApplicationUserNameCacheMasterKey = ApplicationUserNameCacheMasterKey; m.ApplicationUserNameCacheFilePath = ApplicationUserNameCacheFilePath; m.BlockedCollectorAgentTypes.AddRange(BlockedCollectorAgentTypes.ToArray()); m.ScriptsRepositoryDirectory = ScriptsRepositoryDirectory; if (m.CollectorHosts.Count == 1) { m.RefreshStates(); //Since there is only one CollectorHost CollectorHost ch = m.CollectorHosts[0]; monitorState = ch.CurrentState; monitorState.RanAs = ch.CurrentState.RanAs; } else { monitorState.CurrentValue = "There was a problem loading the Collector Host config on the remote host!"; monitorState.RawDetails = collectorHostConfig; monitorState.HtmlDetails = collectorHostConfig.EscapeXml(); monitorState.State = CollectorState.Error; } //If hosted in console test app consoleOutPut.AppendFormat("{0}: Results for collector host: {1}\r\n", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), entry.Name); consoleOutPut.AppendFormat(" State : {0}\r\n", monitorState.State); consoleOutPut.AppendFormat(" Ran as : {0}\r\n", monitorState.RanAs); consoleOutPut.AppendFormat(" Details : {0}\r\n", monitorState.ReadAllRawDetails()); } catch (Exception ex) { consoleOutPut.AppendFormat(" Error: {0}\r\n", ex); monitorState.CurrentValue = ex.Message; monitorState.State = CollectorState.Error; monitorState.RawDetails = ex.ToString(); monitorState.HtmlDetails = ex.ToString().EscapeXml(); } consoleOutPut.AppendLine(new string('*', 79)); Console.WriteLine(consoleOutPut.ToString()); monitorState.ExecutedOnHostComputer = System.Net.Dns.GetHostName(); return(monitorState); }