Beispiel #1
0
        public static IEnumerable <BindConfig.LineModel> AssignAcl(string input)
        {
            var acls    = new List <BindConfig.LineModel>();
            var str     = $"[^#]acl[\\s]*[\"]*([\\w\\d.\\-_]*)[\"]*[\\s]*{{[\\s]*((?!(acl[\\s]*)|(include))[\\w\\d\\s;\"/_.}}{{-])*;";
            var regex   = new Regex(str);
            var matches = regex.Matches(input);

            for (int i = 0; i < matches.Count; i++)
            {
                var aclDataString = matches[i].Value.Trim();
                var keyData       = new Regex("acl.*{").Matches(aclDataString)[0].Value.Trim();
                var key           = keyData.Split(new[] { " " }, StringSplitOptions.RemoveEmptyEntries)[1].Replace("{", "").Trim();
                var value         = new Regex("{[\\s\\w\\d./;]*").Matches(aclDataString)[0].Value.Replace("\t", "").Replace("{", "").Replace("}", "").Trim();
                var acl           = new BindConfig.LineModel()
                {
                    Key          = key,
                    Value        = value,
                    Type         = ServiceDataType.StringArray,
                    BooleanVerbs = new KeyValuePair <string, string>(";", ";")
                };
                acls.Add(acl);
            }
            return(acls);
        }
Beispiel #2
0
        public static IEnumerable <BindConfig.OptionModel> AssignZone(string input)
        {
            var options = new List <BindConfig.OptionModel>();
            var str     = $"[^#]zone[\\s]*[\"]*([\\w\\d.\\-_]*)[\"]*[\\s]*{{[\\s]*((?!(zone[\\s]*)|(include))[\\w\\d\\s;\"/_.}}{{-])*;";
            var regex   = new Regex(str);
            var matches = regex.Matches(input);

            for (int i = 0; i < matches.Count; i++)
            {
                var zoneDataString      = matches[i].Value.Trim();
                var zoneDataStringSplit = zoneDataString.Split(new[] { "{" }, StringSplitOptions.RemoveEmptyEntries);
                var zoneName            = (zoneDataStringSplit.Length > 0) ? zoneDataStringSplit[0].Replace("zone", "").Replace("\"", "").Trim() : "";
                var data     = (zoneDataStringSplit.Length > 1) ? zoneDataStringSplit[1].TrimEnd(';').TrimEnd('}').Trim() : "";
                var dataList = new List <BindConfig.LineModel>();
                if (data.Length > 0)
                {
                    var txt = data.Replace("zone {", "");
                    var simpleDataMatches = new Regex($"(?!([\\w\\d\\s-\"/._*;]*}})|(;))[\\w\\d\\s-/._\"*]*[;]").Matches(txt);
                    for (int x = 0; x < simpleDataMatches.Count; x++)
                    {
                        var split = simpleDataMatches[x].Value.Replace("\t", " ").Trim().Split(new[] { " " }, StringSplitOptions.RemoveEmptyEntries).ToArray();
                        if (split.Length > 1 && !split[0].StartsWith("//"))
                        {
                            var k   = split[0];
                            var v   = split[1].Replace(";", "").Replace("\"", "");
                            var ddd = new BindConfig.LineModel()
                            {
                                Key          = k,
                                Value        = v,
                                Type         = Helper.ServiceData.SupposeDataType(v),
                                BooleanVerbs = Helper.ServiceData.SupposeBooleanVerbs(v),
                                FilePath     = ""
                            };
                            dataList.Add(ddd);
                        }
                    }
                    var multipleDataMatches = new Regex($"[\\w\\d\\s-\"/._*]*{{[\\w\\d\\s-\"/._*;]*}};").Matches(txt);
                    for (int y = 0; y < multipleDataMatches.Count; y++)
                    {
                        var split = multipleDataMatches[y].Value.Replace("\t", " ").Trim().Split(new[] { " {" }, StringSplitOptions.RemoveEmptyEntries).ToArray();
                        if (split.Length > 1)
                        {
                            var k           = split[0];
                            var v           = split[1].Replace("};", "").Replace("\t", " ").Replace("\n", " ").Trim();
                            var splitValue  = v.Split(new[] { ";" }, StringSplitOptions.None).ToArray();
                            var splitValue2 = splitValue[0].Trim().Split(new[] { " " }, StringSplitOptions.RemoveEmptyEntries).ToArray();
                            var type        = (splitValue2.Length > 1) ? ServiceDataType.DataArray : ServiceDataType.StringArray;
                            var ddd         = new BindConfig.LineModel()
                            {
                                Key          = k,
                                Value        = v,
                                Type         = type,
                                BooleanVerbs = new KeyValuePair <string, string>(";", ";"),
                                FilePath     = ""
                            };
                            dataList.Add(ddd);
                        }
                    }
                }
                var option = new BindConfig.OptionModel()
                {
                    Name             = zoneName,
                    StringDefinition = data,
                    Data             = dataList
                };
                options.Add(option);
            }
            return(options);
        }
Beispiel #3
0
        public static IEnumerable <BindConfig.OptionModel> AssignManagedKeys(string input)
        {
            var managedKeys        = new List <BindConfig.OptionModel>();
            var managedKeysStr     = $"managed-keys[\\s]*{{[\\s]*((?!con|key|logg|opt|mast|lwr|statistics-ch)[\\w\\d\\s;=\"/_.}}{{\\-*])*;";
            var managedKeysRegex   = new Regex(managedKeysStr);
            var managedKeysMatches = managedKeysRegex.Matches(input);
            var data     = (managedKeysMatches.Count > 0) ? managedKeysMatches[0].Value : "";
            var dataList = new List <BindConfig.LineModel>();

            if (data.Length > 0)
            {
                var txt = data.Replace("managed-keys {", "");
                var simpleDataMatches = new Regex($"(?!([\\w\\d\\s-\"/._*;]*}})|(;))[\\w\\d\\s-/._\"*]*[;]").Matches(txt);
                for (int i = 0; i < simpleDataMatches.Count; i++)
                {
                    var split = simpleDataMatches[i].Value.Replace("\t", " ").Trim().Split(new[] { " " }, StringSplitOptions.RemoveEmptyEntries).ToArray();
                    if (split.Length > 1 && !split[0].StartsWith("//"))
                    {
                        var k   = split[0];
                        var v   = split[1].Replace(";", "").Replace("\"", "");
                        var ddd = new BindConfig.LineModel()
                        {
                            Key          = k,
                            Value        = v,
                            Type         = Helper.ServiceData.SupposeDataType(v),
                            BooleanVerbs = Helper.ServiceData.SupposeBooleanVerbs(v),
                            FilePath     = ""
                        };
                        dataList.Add(ddd);
                    }
                }
                var multipleDataMatches = new Regex($"[\\w\\d\\s-\"/._*]*{{[\\w\\d\\s-\"/._*;]*}};").Matches(txt);
                for (int i = 0; i < multipleDataMatches.Count; i++)
                {
                    var split = multipleDataMatches[i].Value.Replace("\t", " ").Trim().Split(new[] { " {" }, StringSplitOptions.RemoveEmptyEntries).ToArray();
                    if (split.Length > 1)
                    {
                        var k           = split[0];
                        var v           = split[1].Replace("};", "").Replace("\t", " ").Replace("\n", " ").Trim();
                        var splitValue  = v.Split(new[] { ";" }, StringSplitOptions.None).ToArray();
                        var splitValue2 = splitValue[0].Trim().Split(new[] { " " }, StringSplitOptions.RemoveEmptyEntries).ToArray();
                        var type        = (splitValue2.Length > 1) ? ServiceDataType.DataArray : ServiceDataType.StringArray;
                        var ddd         = new BindConfig.LineModel()
                        {
                            Key          = k,
                            Value        = v,
                            Type         = type,
                            BooleanVerbs = new KeyValuePair <string, string>(";", ";"),
                            FilePath     = ""
                        };
                        dataList.Add(ddd);
                    }
                }
            }
            var option = new BindConfig.OptionModel()
            {
                Name = "managedKeys",
                Data = dataList
            };

            managedKeys.Add(option);
            return(managedKeys);
        }