public static void Save(SshdConfigurationModel model) { var text = JsonConvert.SerializeObject(model, Formatting.Indented); FileWithAcl.WriteAllText(CfgFile, text, "644", "root", "wheel"); ConsoleLogger.Log("[sshd] configuration saved"); }
public void Save(SshdConfigurationModel model) { var text = JsonConvert.SerializeObject(model, Formatting.Indented); if (File.Exists(_cfgFile)) { File.Copy(_cfgFile, _cfgFileBackup, true); } File.WriteAllText(_cfgFile, text); ConsoleLogger.Log("[sshd] configuration saved"); }
public SshdConfiguration() { IoDir.CreateDirectory(Parameter.AntdCfgServices); if (!File.Exists(_cfgFile)) { _serviceModel = new SshdConfigurationModel(); } else { try { var text = File.ReadAllText(_cfgFile); var obj = JsonConvert.DeserializeObject <SshdConfigurationModel>(text); _serviceModel = obj; } catch (Exception) { _serviceModel = new SshdConfigurationModel(); } } }
public AntdSshdModule() { Get["/sshd"] = x => { var sshdIsActive = SshdConfiguration.IsActive(); var model = new PageSshdModel { SshdIsActive = sshdIsActive, SshdOptions = SshdConfiguration.Get() ?? new SshdConfigurationModel() }; return(JsonConvert.SerializeObject(model)); }; Post["/sshd/set"] = x => { SshdConfiguration.Set(); return(HttpStatusCode.OK); }; Post["/sshd/restart"] = x => { SshdConfiguration.Start(); return(HttpStatusCode.OK); }; Post["/sshd/stop"] = x => { SshdConfiguration.Stop(); return(HttpStatusCode.OK); }; Post["/sshd/enable"] = x => { SshdConfiguration.Enable(); SshdConfiguration.Start(); return(HttpStatusCode.OK); }; Post["/sshd/disable"] = x => { SshdConfiguration.Disable(); SshdConfiguration.Stop(); return(HttpStatusCode.OK); }; Post["/sshd/options"] = x => { string port = Request.Form.Port; string permitRootLogin = Request.Form.PermitRootLogin; string permitTunnel = Request.Form.PermitTunnel; string maxAuthTries = Request.Form.MaxAuthTries; string maxSessions = Request.Form.MaxSessions; string rsaAuthentication = Request.Form.RsaAuthentication; string pubkeyAuthentication = Request.Form.PubkeyAuthentication; string usePam = Request.Form.UsePam; var model = new SshdConfigurationModel { Port = port, PermitRootLogin = permitRootLogin, PermitTunnel = permitTunnel, MaxAuthTries = maxAuthTries, MaxSessions = maxSessions, RsaAuthentication = rsaAuthentication, PubkeyAuthentication = pubkeyAuthentication, UsePam = usePam }; SshdConfiguration.Save(model); return(HttpStatusCode.OK); }; }