public static void ExportNewFirewallConfiguration() { var template = $"{Parameter.RepoConfig}/antd.firewall.template.conf"; var text = Terminal.Terminal.Execute($"cat {template}"); foreach (var values in FirewallLists.GetAll()) { var replace = text.Replace(values.TemplateWord, ConfigManagement.SupposeCommandReplacement(values.ReplaceTemplateValues)); text = replace; } var newConfFile = GetLastFileName(); File.WriteAllText(newConfFile, text); }
public TerminalModule() { this.RequiresAuthentication(); Get["/terminal"] = x => View["page-terminal"]; Post["/terminal"] = x => Response.AsJson((string)(Request.Form.Directory == "" ? Terminal.Execute((string)Request.Form.Command) : Terminal.Execute(Request.Form.Command, Request.Form.Directory))); Post["/terminal/directory"] = x => { string directory = Request.Form.Directory; string result; if (Directory.Exists(directory)) { result = directory + " > "; } else { result = "0"; } return(Response.AsJson(result)); }; Post["/terminal/directory/parent"] = x => { string result; if (!Directory.Exists((string)Request.Form.Directory)) { result = "0"; } else { var parent = Directory.GetParent((string)Request.Form.Directory); if (Directory.Exists(parent.FullName)) { result = parent.FullName + " > "; } else { result = "0"; } } return(Response.AsJson(result)); }; Post["/terminal/api"] = x => { var cmds = Request.Form.Command.Split(new[] { Environment.NewLine }, StringSplitOptions.None); var result = Request.Form.Directory == "" ? Terminal.MultiLine.Execute((string[])cmds) : Terminal.MultiLine.Execute((string[])cmds, (string)Request.Form.Directory); return(Response.AsJson(result)); }; Post["/terminal/direct/post"] = x => { var inputCommand = (string)Request.Form.Command; var commandSplit = inputCommand.Split(new[] { "$nl" }, StringSplitOptions.None).Select(cmd => ConfigManagement.SupposeCommandReplacement(cmd.Replace("$'", "\""))).ToList(); foreach (var command in commandSplit) { ConfigManagement.AddCommandsBundle(command); } var result = Terminal.MultiLine.Execute(commandSplit); return(Response.AsJson(result)); }; Post["/terminal/direct"] = x => { var inputCommand = (string)Request.Form.Command; var commandSplit = inputCommand.Split(new[] { "$nl" }, StringSplitOptions.None).Select(cmd => ConfigManagement.SupposeCommandReplacement(cmd.Replace("$'", "\""))).ToList(); var result = Terminal.MultiLine.Execute(commandSplit); return(Response.AsJson(result)); }; }