Example #1
0
        public static List <IisSiteRestriction> GetActiveSiteRestrictions()
        {
            var restrictions = ConfigDb.GetActiveRestrictions();

            if (restrictions == null)
            {
                return(new List <IisSiteRestriction>());
            }

            return((from DataRow row in restrictions.Rows
                    select new IisSiteRestriction
            {
                Site = new IisSite
                {
                    Group = row["Group"].ToString(),
                    Hostname = row["Hostname"].ToString(),
                    Sitename = row["SiteName"].ToString()
                },
                Restriction = new IisRestriction
                {
                    CreateMoment = (DateTime)row["CreateMoment"],
                    StartMoment = (DateTime)row["StartMoment"],
                    StopMoment = (DateTime)row["StopMoment"],
                    Rule = row["Rule"].ToString(),
                    Type = row["TypeName"].ToString()
                }
            }).ToList());
        }
Example #2
0
 public static int AddIisSite(IisSite site)
 {
     return(ConfigDb.IisSiteAdd(
                site.Sitename,
                site.Hostname,
                site.Group));
 }
Example #3
0
 public static int AddSiteRestriction(IisSiteRestriction siteRestriction)
 {
     return(ConfigDb.IisSiteRestrictionAdd(
                siteRestriction.Restriction.Type,
                siteRestriction.Restriction.StartMoment,
                siteRestriction.Restriction.StopMoment,
                siteRestriction.Restriction.Rule,
                siteRestriction.Site.Sitename,
                siteRestriction.Site.Hostname,
                siteRestriction.Site.Group));
 }
Example #4
0
        private void ApplyRestrictions()
        {
            try
            {
                var data = ConfigDb.GetRestrictionsToUpdate();

                // Nothing to do
                if (data == null)
                {
                    return;
                }

                foreach (DataRow restrictionRow in data.Rows)
                {
                    try
                    {
                        var info = new IisSite
                        {
                            Hostname = restrictionRow["Hostname"].ToString(),
                            Sitename = restrictionRow["Sitename"].ToString()
                        };

                        // Turn On/Off restriction
                        if ((bool)restrictionRow["Switch"])
                        {
                            IisConfigurator.AddRestriction(restrictionRow["TypeName"].ToString(), info, restrictionRow["Rule"].ToString());
                        }
                        else
                        {
                            IisConfigurator.RemoveRestriction(restrictionRow["TypeName"].ToString(), info, restrictionRow["Rule"].ToString());
                        }

                        // If no errors - update DB
                        ConfigDb.IisRestrictionTurnOff((int)restrictionRow["ID"], (bool)restrictionRow["Switch"]);
                    }
                    catch (Exception ex)
                    {
                        Logger.Log.Warn("Unable to apply rule id:[{0}], content:[{1}]. Error: {2}", restrictionRow["ID"], restrictionRow["Rule"], ex.Message);
                        ConfigDb.IisRestrictionReject((int)restrictionRow["ID"], ex.Message);
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.Log.Error("Connection to DB failed: {0}", ex.Message);
            }
        }
Example #5
0
        public static List <IisSite> GetSites()
        {
            var sites = ConfigDb.GetSites();

            if (sites == null)
            {
                return(new List <IisSite>());
            }

            return((from DataRow row in sites.Rows
                    select new IisSite
            {
                Group = row["Group"].ToString(),
                Hostname = row["Hostname"].ToString(),
                Sitename = row["SiteName"].ToString()
            }).ToList());
        }
Example #6
0
        public static List <int> AddGroupRestriction(IisGroupRestriction groupRestriction)
        {
            var restrictions = ConfigDb.IisGroupRestrictionAdd(
                groupRestriction.Restriction.Type,
                groupRestriction.Restriction.StartMoment,
                groupRestriction.Restriction.StopMoment,
                groupRestriction.Restriction.Rule,
                groupRestriction.Group);

            if (restrictions == null)
            {
                return(new List <int>());
            }

            return((from DataRow row in restrictions.Rows
                    select(int) row["ID"]).ToList());
        }
Example #7
0
        public static List <IisSiteRestrictionPlain> GetActiveSiteRestrictionsPlain()
        {
            var restrictions = ConfigDb.GetActiveRestrictions();

            return(DataTableToSiteRestrictionPlains(restrictions));
        }
Example #8
0
 public static void RejectRestriction(int id, string reason)
 {
     ConfigDb.IisRestrictionReject(id, reason);
 }