Exemple #1
0
        public static CommandModel Launch(string file, string args)
        {
            //#if WINDOWS
            //            Console.WriteLine("Windows.");
            //#else
            //            Console.WriteLine("Not Windows.");
            //#endif
            string output = string.Empty;
            string error = string.Empty;
            Process process = new Process {
                StartInfo = {
                    FileName = file,
                    Arguments = args,
                    RedirectStandardOutput = true,
                    RedirectStandardError = true,
                    UseShellExecute = false
                }
            };
            try {
                process.Start();
                using (StreamReader streamReader = process.StandardOutput) {
                    output = streamReader.ReadToEnd();
                }

                using (StreamReader streamReader = process.StandardError) {
                    error = streamReader.ReadToEnd();
                }
                process.WaitForExit();
                CommandModel command = new CommandModel {
                    input = new Tuple<string, string>(file, args),
                    date = DateTime.Now,
                    output = output,
                    outputTable = TextToList(output),
                    error = error,
                    errorTable = TextToList(error)
                };
                ConsoleLogger.Log("Launched {0} {1}", file, args);
                ConsoleLogger.Log("------------ Command output:");
                ConsoleLogger.Log("{0}", command.output);
                return command;
            }
            catch (Exception ex) {
                CommandModel command = new CommandModel {
                    error = ex.Message,
                    errorTable = TextToList(ex.Message)
                };
                Console.WriteLine("");
                ConsoleLogger.Warn("Launched {0} {1}", file, args);
                ConsoleLogger.Warn("------------ Error output:");
                ConsoleLogger.Warn("{0}", command.error);
                Console.WriteLine("");
                return command;
            }
        }
Exemple #2
0
        public ConsoleModule()
            : base("/console")
        {
            this.RequiresAuthentication();

            Get["/"] = x => {
                return(View["page-console"]);
            };

            Post["/"] = x => {
                string file = (string)this.Request.Form.File;
                string args = (string)this.Request.Form.Arguments;

                CommandModel command = Command.Launch(file, args);
                return(View["page-console", command]);
            };
        }
Exemple #3
0
        public static CommandModel Launch(string file, string args, string dir)
        {
            string  output  = string.Empty;
            string  error   = string.Empty;
            Process process = new Process {
                StartInfo =
                {
                    FileName  = file,
                    Arguments = args,
                    RedirectStandardOutput = true,
                    RedirectStandardError  = true,
                    UseShellExecute        = false,
                    WorkingDirectory       = dir.ToString()
                }
            };

            try {
                process.Start();

                using (StreamReader streamReader = process.StandardOutput) {
                    output = streamReader.ReadToEnd();
                }

                using (StreamReader streamReader = process.StandardError) {
                    error = streamReader.ReadToEnd();
                }
                process.WaitForExit();
                CommandModel command = new CommandModel {
                    input       = new Tuple <string, string>(file, args),
                    date        = DateTime.Now,
                    output      = output,
                    outputTable = TextToList(output),
                    error       = error,
                    errorTable  = TextToList(error)
                };
                return(command);
            }
            catch (Exception ex) {
                CommandModel command = new CommandModel {
                    error      = ex.Message,
                    errorTable = TextToList(ex.Message)
                };
                return(command);
            }
        }
Exemple #4
0
        public static string GetEther()
        {
            string       dir  = "/sys/devices";
            CommandModel find = Command.Launch("find", "./ -name address", dir);

            if (find.isError())
            {
                return(find.error);
            }
            else
            {
                string row = (from i in find.outputTable
                              where i.Contains("eth")
                              select i).FirstOrDefault();
                CommandModel cat = Command.Launch("cat", row.Replace("\"", ""), dir);
                return(cat.outputTable.FirstOrDefault());
            }
        }
Exemple #5
0
        public static CommandModel Launch(string file, string args, string dir)
        {
            string  output  = string.Empty;
            string  error   = string.Empty;
            Process process = new Process();

            process.StartInfo.FileName  = file;
            process.StartInfo.Arguments = args;
            process.StartInfo.RedirectStandardOutput = true;
            process.StartInfo.RedirectStandardError  = true;
            process.StartInfo.UseShellExecute        = false;
            process.StartInfo.WorkingDirectory       = dir.ToString();
            try {
                process.Start();

                using (StreamReader streamReader = process.StandardOutput) {
                    output = streamReader.ReadToEnd();
                }

                using (StreamReader streamReader = process.StandardError) {
                    error = streamReader.ReadToEnd();
                }
                process.WaitForExit();
                CommandModel command = new CommandModel();
                command.input       = new Tuple <string, string>(file, args);
                command.date        = DateTime.Now;
                command.output      = output;
                command.outputTable = TextToList(output);
                command.error       = error;
                command.errorTable  = TextToList(error);
                return(command);
            }
            catch (Exception ex) {
                CommandModel command = new CommandModel();
                command.error      = ex.Message;
                command.errorTable = TextToList(ex.Message);
                return(command);
            }
        }
Exemple #6
0
        public AnthillaASModule()
            : base("/anthillaas")
        {
            this.RequiresAuthentication();

            Get["/"] = x => {
                return(View["page-m-service-as"]);
            };

            Get["/unit/set/anthillaas"] = x => {
                CreateUnit.ForAnthillaAS();
                AnthillaAS.EnableAnthillaAS();
                return(Response.AsJson(true));
            };

            Get["/unit/set/anthillafirewall"] = x => {
                CreateUnit.ForAnthillaFirewall();
                AnthillaAS.EnableAnthillaFirewall();
                return(Response.AsJson(true));
            };

            Get["/unit/set/anthillastorage"] = x => {
                CreateUnit.ForAnthillaStorage();
                AnthillaAS.EnableAnthillaStorage();
                return(Response.AsJson(true));
            };

            Get["/unit/start/anthillaas"] = x => {
                CommandModel start = AnthillaAS.StartAnthillaAS();
                return(View["page-m-service-as", start]);
                //return Response.AsJson(start);
            };

            Get["/unit/start/anthillafirewall"] = x => {
                CommandModel start = AnthillaAS.StartAnthillaFirewall();
                return(View["page-m-service-as", start]);
                //return Response.AsJson(start);
            };

            Get["/unit/start/anthillastorage"] = x => {
                CommandModel start = AnthillaAS.StartAnthillaStorage();
                return(View["page-m-service-as", start]);
                //return Response.AsJson(start);
            };

            Get["/unit/stop/anthillaas"] = x => {
                CommandModel stop = AnthillaAS.StopAnthillaAS();
                return(View["page-m-service-as", stop]);
                //return Response.AsJson(stop);
            };

            Get["/unit/stop/anthillafirewall"] = x => {
                CommandModel stop = AnthillaAS.StopAnthillaFirewall();
                return(View["page-m-service-as", stop]);
                //return Response.AsJson(stop);
            };

            Get["/unit/stop/anthillastorage"] = x => {
                CommandModel stop = AnthillaAS.StopAnthillaStorage();
                return(View["page-m-service-as", stop]);
                //return Response.AsJson(stop);
            };

            Get["/unit/status/anthillaas"] = x => {
                CommandModel status = AnthillaAS.StatusAnthillaAS();
                return(View["page-m-service-as", status]);
                //return Response.AsJson(status);
            };

            Get["/unit/status/anthillafirewall"] = x => {
                CommandModel status = AnthillaAS.StatusAnthillaFirewall();
                return(View["page-m-service-as", status]);
                //return Response.AsJson(status);
            };

            Get["/unit/status/anthillastorage"] = x => {
                CommandModel status = AnthillaAS.StatusAnthillaStorage();
                return(View["page-m-service-as", status]);
                //return Response.AsJson(status);
            };
        }
Exemple #7
0
        public static CommandModel Launch(string file, string args, string dir)
        {
            string output = string.Empty;
            string error = string.Empty;
            Process process = new Process {
                StartInfo = {
                    FileName = file,
                    Arguments = args,
                    RedirectStandardOutput = true,
                    RedirectStandardError = true,
                    UseShellExecute = false,
                    WorkingDirectory = dir.ToString()
                }
            };
            try {
                process.Start();

                using (StreamReader streamReader = process.StandardOutput) {
                    output = streamReader.ReadToEnd();
                }

                using (StreamReader streamReader = process.StandardError) {
                    error = streamReader.ReadToEnd();
                }
                process.WaitForExit();
                CommandModel command = new CommandModel {
                    input = new Tuple<string, string>(file, args),
                    date = DateTime.Now,
                    output = output,
                    outputTable = TextToList(output),
                    error = error,
                    errorTable = TextToList(error)
                };
                return command;
            }
            catch (Exception ex) {
                CommandModel command = new CommandModel {
                    error = ex.Message,
                    errorTable = TextToList(ex.Message)
                };
                return command;
            }
        }
Exemple #8
0
        public HomeModule()
        {
            this.RequiresAuthentication();

            Get["/"] = x => {
                return(Response.AsRedirect("/anthillasp"));
            };

            Get["/info"] = x => {
                return(View["page-info"]);
            };

            Get["/paramlist"] = x => {
                return(View["page-paramlist"]);
            };

            Get["/meminfo"] = x => {
                List <MeminfoModel> meminfo = Meminfo.GetModel();
                if (meminfo == null)
                {
                    return(View["page-meminfo"]);
                }
                return(View["page-meminfo", meminfo]);
            };

            Get["/meminfo/text"] = x => {
                var meminfo = Meminfo.GetText();
                return(Response.AsJson(meminfo));
            };

            Get["/network"] = x => {
                NetworkModel network = NetworkInfo.GetModel();
                if (network == null)
                {
                    return(View["page-network"]);
                }
                return(View["page-network", network]);
            };

            Post["/network"] = x => {
                string       hostname = (string)this.Request.Form.Hostname;
                NetworkModel network  = Antd.NetworkInfo.GetModel(hostname);
                if (network == null)
                {
                    return(View["page-network"]);
                }
                return(View["page-network", network]);
            };

            Get["/cpuinfo"] = x => {
                List <CpuinfoModel> cpuinfo = Cpuinfo.GetModel();
                if (cpuinfo == null)
                {
                    return(View["page-cpuinfo"]);
                }
                return(View["page-cpuinfo", cpuinfo]);
            };

            Get["/cpuinfo/text"] = x => {
                var cpuinfo = Cpuinfo.GetText();
                return(Response.AsJson(cpuinfo));
            };

            Get["/version"] = x => {
                VersionModel version = Version.GetModel();
                if (version == null)
                {
                    return(View["page-version"]);
                }
                return(View["page-version", version]);
            };

            Get["/version/text"] = x => {
                var version = Version.GetText();
                return(Response.AsJson(version));
            };

            Get["/dmidecode"] = x => {
                CommandModel command = Command.Launch("dmidecode", "");
                return(View["page-dmidecode", command]);
            };

            Get["/dmidecode/uuid"] = x => {
                CommandModel command = Command.Launch("dmidecode", "");
                string       uuid    = command.isError() ? null
                    : Dmidecode.GetUUID(command.outputTable);
                return(Response.AsJson(uuid));
            };

            Get["/dmidecode/text"] = x => {
                CommandModel command = Command.Launch("dmidecode", "");
                return(JsonConvert.SerializeObject(command.output));
            };

            Get["/ifconfig"] = x => {
                CommandModel command = Command.Launch("ifconfig", "");
                return(View["page-ifconfig", command]);
            };

            Get["/ifconfig/ether"] = x => {
                return(JsonConvert.SerializeObject(Ifconfig.GetEther()));
            };

            Get["/ifconfig/text"] = x => {
                CommandModel command = Command.Launch("ifconfig", "");
                return(JsonConvert.SerializeObject(command.output));
            };

            Get["/command"] = x => {
                return(View["page-command"]);
            };

            Post["/command"] = x => {
                string file = (string)this.Request.Form.File;
                string args = (string)this.Request.Form.Arguments;

                CommandModel command = Command.Launch(file, args);
                return(View["page-command", command]);
            };

            Get["/procs"] = x => {
                List <ProcModel> procs = Proc.All;
                return(View["page-procs", procs]);
            };

            Get["/procs/text"] = x => {
                CommandModel command = Command.Launch("ps", "-aef");
                return(JsonConvert.SerializeObject(command.output.Replace("\"", "")));
            };

            Post["/procs/kill"] = x => {
                string       pid     = (string)this.Request.Form.data;
                CommandModel command = Command.Launch("kill", pid);
                return(Response.AsRedirect("/procs"));
            };
        }