Esempio n. 1
0
        public static void Save(NginxConfigurationModel model)
        {
            var text = JsonConvert.SerializeObject(model, Formatting.Indented);

            FileWithAcl.WriteAllText(CfgFile, text, "644", "root", "wheel");
            ConsoleLogger.Log("[nginx] configuration saved");
        }
Esempio n. 2
0
 public static NginxConfigurationModel ParseOptions(NginxConfigurationModel nginxConfigurationModel, string text)
 {
     nginxConfigurationModel.User      = CaptureGroup(text, "user[\\s]+([\\d\\w]+)");
     nginxConfigurationModel.Group     = CaptureGroup(text, "user[\\s]+[\\d\\w]+[\\s]+([\\d\\w]+);");
     nginxConfigurationModel.Processes = CaptureGroup(text, "worker_processes[\\s]+[\\d]+;");
     nginxConfigurationModel.FileLimit = CaptureGroup(text, "worker_rlimit_nofile[\\s]+[\\d]+;");
     nginxConfigurationModel.ErrorLog  = CaptureGroup(text, "error_log[\\s]+[\\w\\/.\\s\\d]+;");
     return(nginxConfigurationModel);
 }
Esempio n. 3
0
        //(events[\s]+{[\s]+[\w\s_;]+[\s]+})
        public static NginxConfigurationModel ParseEventsOptions(NginxConfigurationModel nginxConfigurationModel, string text)
        {
            var regex         = new Regex("(events[\\s]+{[\\s]+[\\w\\s_;]+[\\s]+})");
            var matchedGroups = regex.Match(text).Groups;
            var capturedText  = matchedGroups[1].Value;

            nginxConfigurationModel.EventsWorkerConnections = CaptureGroup(capturedText, "worker_connections[\\s]+[\\d]+;");
            nginxConfigurationModel.EventsMultiAccept       = CaptureGroup(capturedText, "multi_accept[\\s]+[\\w]+;");
            nginxConfigurationModel.EventsUse         = CaptureGroup(capturedText, "use[\\s]+[\\w]+;");
            nginxConfigurationModel.EventsAcceptMutex = CaptureGroup(capturedText, "accept_mutex[\\s]+[\\w]+;");
            return(nginxConfigurationModel);
        }
Esempio n. 4
0
        private static NginxConfigurationModel Parse(string text)
        {
            var model = new NginxConfigurationModel {
                IsActive = false
            };

            model = NginxParser.ParseOptions(model, text);
            model = NginxParser.ParseEventsOptions(model, text);
            var upstreams = NginxParser.ParseUpstream(text);

            model.Upstreams = upstreams;
            var http = NginxParser.ParseHttpProtocol(text);

            model.Http = http;
            var servers = NginxParser.ParseServer(text);

            model.Servers = servers;
            return(model);
        }