/// <summary> /// Default constructor. /// </summary> /// <param name="owner">Owner IPSecurityCollection collection that owns this object.</param> /// <param name="id">Security entry ID.</param> /// <param name="enabled">Specifies if security entry is enabled.</param> /// <param name="description">Security entry description text.</param> /// <param name="service">Specifies service for what security entry applies.</param> /// <param name="action">Specifies what action done if IP matches to security entry range.</param> /// <param name="startIP">Range start IP.</param> /// <param name="endIP">Range end IP.</param> internal IPSecurity(IPSecurityCollection owner, string id, bool enabled, string description, Service_enum service, IPSecurityAction_enum action, IPAddress startIP, IPAddress endIP) { m_pOwner = owner; m_ID = id; m_Enabled = enabled; m_Description = description; m_Service = service; m_Action = action; m_pStartIP = startIP; m_pEndIP = endIP; }
/// <summary> /// Default constructor. /// </summary> /// <param name="owner">Owner IPSecurityCollection collection that owns this object.</param> /// <param name="id">Security entry ID.</param> /// <param name="enabled">Specifies if security entry is enabled.</param> /// <param name="description">Security entry description text.</param> /// <param name="service">Specifies service for what security entry applies.</param> /// <param name="action">Specifies what action done if IP matches to security entry range.</param> /// <param name="startIP">Range start IP.</param> /// <param name="endIP">Range end IP.</param> internal IPSecurity(IPSecurityCollection owner,string id,bool enabled,string description,Service_enum service,IPSecurityAction_enum action,IPAddress startIP,IPAddress endIP) { m_pOwner = owner; m_ID = id; m_Enabled = enabled; m_Description = description; m_Service = service; m_Action = action; m_pStartIP = startIP; m_pEndIP = endIP; }
/// <summary> /// Adds new security enrty to collection. /// </summary> /// <param name="enabled">Specifies if security entry is enabled.</param> /// <param name="description">Security entry description text.</param> /// <param name="service">Specifies service for what security entry applies.</param> /// <param name="action">Specifies what action done if IP matches to security entry range.</param> /// <param name="startIP">Range start IP.</param> /// <param name="endIP">Range end IP.</param> /// <returns></returns> public IPSecurity Add(bool enabled, string description, Service_enum service, IPSecurityAction_enum action, IPAddress startIP, IPAddress endIP) { /* AddIPSecurityEntry <virtualServerID> "<securityEntryID>" enabled "<description>" <service> <action> "<startIP>" "<endIP>" * Responses: +OK * -ERR <errorText> */ string id = Guid.NewGuid().ToString(); // Call TCP AddIPSecurityEntry m_pVirtualServer.Server.TcpClient.TcpStream.WriteLine("AddIPSecurityEntry " + m_pVirtualServer.VirtualServerID + " " + TextUtils.QuoteString(id) + " " + enabled + " " + TextUtils.QuoteString(description) + " " + (int)service + " " + (int)action + " " + TextUtils.QuoteString(startIP.ToString()) + " " + TextUtils.QuoteString(endIP.ToString()) ); string response = m_pVirtualServer.Server.ReadLine(); if (!response.ToUpper().StartsWith("+OK")) { throw new Exception(response); } IPSecurity entry = new IPSecurity( this, id, enabled, description, service, action, startIP, endIP ); m_pEntries.Add(entry); return(entry); }
/// <summary> /// Adds new security enrty to collection. /// </summary> /// <param name="enabled">Specifies if security entry is enabled.</param> /// <param name="description">Security entry description text.</param> /// <param name="service">Specifies service for what security entry applies.</param> /// <param name="action">Specifies what action done if IP matches to security entry range.</param> /// <param name="startIP">Range start IP.</param> /// <param name="endIP">Range end IP.</param> /// <returns></returns> public IPSecurity Add(bool enabled,string description,Service_enum service,IPSecurityAction_enum action,IPAddress startIP,IPAddress endIP) { /* AddIPSecurityEntry <virtualServerID> "<securityEntryID>" enabled "<description>" <service> <action> "<startIP>" "<endIP>" Responses: +OK -ERR <errorText> */ string id = Guid.NewGuid().ToString(); // Call TCP AddIPSecurityEntry m_pVirtualServer.Server.TcpClient.TcpStream.WriteLine("AddIPSecurityEntry " + m_pVirtualServer.VirtualServerID + " " + TextUtils.QuoteString(id) + " " + enabled + " " + TextUtils.QuoteString(description) + " " + (int)service + " " + (int)action + " " + TextUtils.QuoteString(startIP.ToString()) + " " + TextUtils.QuoteString(endIP.ToString()) ); string response = m_pVirtualServer.Server.ReadLine(); if(!response.ToUpper().StartsWith("+OK")){ throw new Exception(response); } IPSecurity entry = new IPSecurity( this, id, enabled, description, service, action, startIP, endIP ); m_pEntries.Add(entry); return entry; }
/// <summary> /// Adds new IP security entry. /// </summary> /// <param name="id">IP security entry ID.</param> /// <param name="enabled">Specifies if IP security entry is enabled.</param> /// <param name="description">IP security entry description text.</param> /// <param name="service">Specifies service for what security entry applies.</param> /// <param name="action">Specifies what action done if IP matches to security entry range.</param> /// <param name="startIP">Range start IP.</param> /// <param name="endIP">Range end IP.</param> public void AddSecurityEntry(string id,bool enabled,string description,Service_enum service,IPSecurityAction_enum action,IPAddress startIP,IPAddress endIP) { if(id.Length == 0){ throw new Exception("You must specify securityID"); } using(WSqlCommand sqlCmd = new WSqlCommand(m_ConStr,"lspr_AddSecurityEntry")){ sqlCmd.AddParameter("_id" ,NpgsqlDbType.Varchar,id); sqlCmd.AddParameter("_enabled" ,NpgsqlDbType.Boolean,enabled); sqlCmd.AddParameter("_description" ,NpgsqlDbType.Varchar,description); sqlCmd.AddParameter("_service" ,NpgsqlDbType.Integer,(int)service); sqlCmd.AddParameter("_action" ,NpgsqlDbType.Integer,(int)action); sqlCmd.AddParameter("_startIP" ,NpgsqlDbType.Varchar,startIP.ToString()); sqlCmd.AddParameter("_endIP" ,NpgsqlDbType.Varchar,endIP.ToString()); DataSet ds = sqlCmd.Execute(); } }
/// <summary> /// Updates IP security entry. /// </summary> /// <param name="id">IP security entry ID.</param> /// <param name="enabled">Specifies if IP security entry is enabled.</param> /// <param name="description">IP security entry description text.</param> /// <param name="service">Specifies service for what security entry applies.</param> /// <param name="action">Specifies what action done if IP matches to security entry range.</param> /// <param name="startIP">Range start IP.</param> /// <param name="endIP">Range end IP.</param> public void UpdateSecurityEntry(string id,bool enabled,string description,Service_enum service,IPSecurityAction_enum action,IPAddress startIP,IPAddress endIP) { using(WSqlCommand sqlCmd = new WSqlCommand(m_ConStr,"lspr_UpdateSecurityEntry")){ sqlCmd.AddParameter("_id" ,NpgsqlDbType.Varchar,id); sqlCmd.AddParameter("_enabled" ,NpgsqlDbType.Boolean,enabled); sqlCmd.AddParameter("_description" ,NpgsqlDbType.Varchar,description); sqlCmd.AddParameter("_service" ,NpgsqlDbType.Integer,(int)service); sqlCmd.AddParameter("_action" ,NpgsqlDbType.Integer,(int)action); sqlCmd.AddParameter("_startIP" ,NpgsqlDbType.Varchar,startIP.ToString()); sqlCmd.AddParameter("_endIP" ,NpgsqlDbType.Varchar,endIP.ToString()); DataSet ds = sqlCmd.Execute(); } }
public void UpdateSecurityEntry(string id, bool enabled, string description, Service_enum service, IPSecurityAction_enum action, IPAddress startIP, IPAddress endIP) { this.m_UpdSync.BeginUpdate(); try { foreach (DataRow dataRow in this.dsSecurity.Tables["IPSecurity"].Rows) { if (dataRow["ID"].ToString().ToLower() == id) { dataRow["ID"] = id; dataRow["Enabled"] = enabled; dataRow["Description"] = description; dataRow["Service"] = service; dataRow["Action"] = action; dataRow["StartIP"] = startIP.ToString(); dataRow["EndIP"] = endIP.ToString(); this.dsSecurity.WriteXml(this.m_DataPath + "IPSecurity.xml", XmlWriteMode.IgnoreSchema); return; } } throw new Exception("Security entry with specified ID '" + id + "' doesn't exist !"); } catch (Exception ex) { throw ex; } finally { this.m_UpdSync.EndUpdate(); } }
public void AddSecurityEntry(string id, bool enabled, string description, Service_enum service, IPSecurityAction_enum action, IPAddress startIP, IPAddress endIP) { if (id.Length == 0) { throw new Exception("You must specify id"); } this.m_UpdSync.BeginUpdate(); try { if (this.ContainsID(this.dsSecurity.Tables["IPSecurity"], "ID", id)) { throw new Exception("Security entry with specified ID '" + id + "' already exists !"); } DataRow dataRow = this.dsSecurity.Tables["IPSecurity"].NewRow(); dataRow["ID"] = id; dataRow["Enabled"] = enabled; dataRow["Description"] = description; dataRow["Service"] = service; dataRow["Action"] = action; dataRow["StartIP"] = startIP.ToString(); dataRow["EndIP"] = endIP.ToString(); this.dsSecurity.Tables["IPSecurity"].Rows.Add(dataRow); this.dsSecurity.WriteXml(this.m_DataPath + "IPSecurity.xml", XmlWriteMode.IgnoreSchema); } catch (Exception ex) { throw ex; } finally { this.m_UpdSync.EndUpdate(); } }
/// <summary> /// Adds new IP security entry. /// </summary> /// <param name="id">IP security entry ID.</param> /// <param name="enabled">Specifies if IP security entry is enabled.</param> /// <param name="description">IP security entry description text.</param> /// <param name="service">Specifies service for what security entry applies.</param> /// <param name="action">Specifies what action done if IP matches to security entry range.</param> /// <param name="startIP">Range start IP.</param> /// <param name="endIP">Range end IP.</param> public void AddSecurityEntry(string id,bool enabled,string description,Service_enum service,IPSecurityAction_enum action,IPAddress startIP,IPAddress endIP) { if(id.Length == 0){ throw new Exception("You must specify securityID"); } using(WSqlCommand sqlCmd = new WSqlCommand(m_ConStr,"lspr_AddSecurityEntry")){ sqlCmd.AddParameter("@id" ,SqlDbType.NVarChar,id); sqlCmd.AddParameter("@enabled" ,SqlDbType.BigInt,enabled); sqlCmd.AddParameter("@description" ,SqlDbType.NVarChar,description); sqlCmd.AddParameter("@service" ,SqlDbType.Int,(int)service); sqlCmd.AddParameter("@Action" ,SqlDbType.Int,(int)action); sqlCmd.AddParameter("@StartIP" ,SqlDbType.NVarChar,startIP.ToString()); sqlCmd.AddParameter("@EndIP" ,SqlDbType.NVarChar,endIP.ToString()); DataSet ds = sqlCmd.Execute(); ds.Tables[0].TableName = "IPSecurity"; if(ds.Tables["IPSecurity"].Rows.Count > 0 && ds.Tables["IPSecurity"].Rows[0]["ErrorText"].ToString().Length > 0){ throw new Exception(ds.Tables["IPSecurity"].Rows[0]["ErrorText"].ToString()); } } }
/// <summary> /// Checks if specified service access is allowed for specified IP. /// </summary> /// <param name="service">SMTP or POP3 or IMAP.</param> /// <param name="ip"></param> /// <returns>Returns true if allowed.</returns> public bool IsAccessAllowed(Service_enum service,IPAddress ip) { using(DataView dv = m_pApi.GetSecurityList()){ // Check if ip is denied foreach(DataRowView drV in dv){ if(Convert.ToBoolean(drV["Enabled"]) && Convert.ToInt32(drV["Service"]) == (int)service && Convert.ToInt32(drV["Action"]) == (int)IPSecurityAction_enum.Deny){ // See if IP matches range if(Core.CompareIP(IPAddress.Parse(drV["StartIP"].ToString()),ip) >= 0 && Core.CompareIP(IPAddress.Parse(drV["EndIP"].ToString()),ip) <= 0){ return false; } } } // Check if ip is allowed foreach(DataRowView drV in dv){ if(Convert.ToBoolean(drV["Enabled"]) && Convert.ToInt32(drV["Service"]) == (int)service && Convert.ToInt32(drV["Action"]) == (int)IPSecurityAction_enum.Allow){ // See if IP matches range if(Core.CompareIP(IPAddress.Parse(drV["StartIP"].ToString()),ip) >= 0 && Core.CompareIP(IPAddress.Parse(drV["EndIP"].ToString()),ip) <= 0){ return true; } } } } return false; }