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

            FileWithAcl.WriteAllText(CfgFile, text);
            ConsoleLogger.Log("[syslogng] configuration saved");
        }
Ejemplo n.º 2
0
        public void Save(SyslogNgConfigurationModel model)
        {
            var text = JsonConvert.SerializeObject(model, Formatting.Indented);

            if (File.Exists(_cfgFile))
            {
                File.Copy(_cfgFile, _cfgFileBackup, true);
            }
            File.WriteAllText(_cfgFile, text);
            ConsoleLogger.Log("[syslogng] configuration saved");
        }
Ejemplo n.º 3
0
 public SyslogNgConfiguration()
 {
     IoDir.CreateDirectory(Parameter.AntdCfgServices);
     if (!File.Exists(_cfgFile))
     {
         _serviceModel = new SyslogNgConfigurationModel();
     }
     else
     {
         try {
             var text = File.ReadAllText(_cfgFile);
             var obj  = JsonConvert.DeserializeObject <SyslogNgConfigurationModel>(text);
             _serviceModel = obj;
         }
         catch (Exception) {
             _serviceModel = new SyslogNgConfigurationModel();
         }
     }
 }
Ejemplo n.º 4
0
        public LogSyslogNgModule()
        {
            Get["/syslogng"] = x => {
                var syslogngConfiguration = new SyslogNgConfiguration();
                var syslogngIsActive      = syslogngConfiguration.IsActive();
                var model = new PageSyslogNgModel {
                    SyslogNgIsActive = syslogngIsActive,
                    SyslogNgOptions  = syslogngConfiguration.Get() ?? new SyslogNgConfigurationModel()
                };
                return(JsonConvert.SerializeObject(model));
            };

            Post["/syslogng/set"] = x => {
                var syslogngConfiguration = new SyslogNgConfiguration();
                syslogngConfiguration.Set();
                return(HttpStatusCode.OK);
            };

            Post["/syslogng/restart"] = x => {
                var syslogngConfiguration = new SyslogNgConfiguration();
                syslogngConfiguration.Start();
                return(HttpStatusCode.OK);
            };

            Post["/syslogng/stop"] = x => {
                var syslogngConfiguration = new SyslogNgConfiguration();
                syslogngConfiguration.Stop();
                return(HttpStatusCode.OK);
            };

            Post["/syslogng/enable"] = x => {
                var dhcpdConfiguration = new SyslogNgConfiguration();
                dhcpdConfiguration.Enable();
                dhcpdConfiguration.Start();
                return(HttpStatusCode.OK);
            };

            Post["/syslogng/disable"] = x => {
                var dhcpdConfiguration = new SyslogNgConfiguration();
                dhcpdConfiguration.Disable();
                dhcpdConfiguration.Stop();
                return(HttpStatusCode.OK);
            };

            Post["/syslogng/options"] = x => {
                string threaded          = Request.Form.Threaded;
                string chainHostname     = Request.Form.ChainHostname;
                string statsFrequency    = Request.Form.StatsFrequency;
                string markFrequency     = Request.Form.MarkFrequency;
                string checkHostname     = Request.Form.CheckHostname;
                string createDirectories = Request.Form.CreateDirectories;
                string dnsCache          = Request.Form.DnsCache;
                string keepHostname      = Request.Form.KeepHostname;
                string dirAcl            = Request.Form.DirAcl;
                string acl                  = Request.Form.Acl;
                string useDns               = Request.Form.UseDns;
                string useFqdn              = Request.Form.UseFqdn;
                string rootPath             = Request.Form.RootPath;
                string portLevelApplication = Request.Form.PortLevelApplication;
                string portLevelSecurity    = Request.Form.PortLevelSecurity;
                string portLevelSystem      = Request.Form.PortLevelSystem;
                var    model                = new SyslogNgConfigurationModel {
                    Threaded          = threaded,
                    ChainHostname     = chainHostname,
                    StatsFrequency    = statsFrequency,
                    MarkFrequency     = markFrequency,
                    CheckHostname     = checkHostname,
                    CreateDirectories = createDirectories,
                    DnsCache          = dnsCache,
                    KeepHostname      = keepHostname,
                    DirAcl            = dirAcl,
                    Acl                  = acl,
                    UseDns               = useDns,
                    UseFqdn              = useFqdn,
                    RootPath             = rootPath,
                    PortLevelApplication = portLevelApplication,
                    PortLevelSecurity    = portLevelSecurity,
                    PortLevelSystem      = portLevelSystem
                };
                var syslogngConfiguration = new SyslogNgConfiguration();
                syslogngConfiguration.Save(model);
                return(HttpStatusCode.OK);
            };
        }