Exemplo n.º 1
0
        public ActionResult ExecuteScript(string command)
        {
            var engine = Ruby.CreateEngine();

            MemoryStream stream = new MemoryStream();
            engine.Runtime.IO.SetOutput(stream, new UTF8Encoding());

            foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies())
            {
                if (!(assembly.ManifestModule is System.Reflection.Emit.ModuleBuilder))
                {
                    engine.Runtime.LoadAssembly(assembly);
                }
            }

            var results = engine.Execute(command);

            stream.Position = 0;
            StreamReader reader = new StreamReader(stream);

            ResultBuilder builder = new ResultBuilder();

            while (!reader.EndOfStream)
            {
                builder.WriteLine(reader.ReadLine());
            }

            reader.Close();
            stream.Close();

            return builder.CreateResult(results);
        }
Exemplo n.º 2
0
        public ActionResult About(object args)
        {
            ResultBuilder builder = new ResultBuilder();

            builder.WriteLine("RedSpect 1.0 Copyright (c) Navitaire 2010");
            builder.WriteLine("Marc Vitalis (c) 2011");

            return builder.CreateResult(null);
        }
Exemplo n.º 3
0
        public ActionResult WriteValueOfX(object args)
        {
            ResultBuilder builder = new ResultBuilder();

            Injection.WriteForm(string.Format("The value of X is {0}", Injection.X));
            builder.WriteLine("Sent to target client.");

            return builder.CreateResult(null);
        }
Exemplo n.º 4
0
        public static ActionResult Connect(string connectionId, params string[] args)
        {
            ResultBuilder builder = new ResultBuilder();

            if (!IsConnected)
            {
                initializeConnection(connectionId, args);

                if (InspectProvider != null)
                {
                    builder.WriteLine(string.Format("Connected -> {0}", InspectProvider.HostDetails()));
                    _isConnected = true;
                }
                else
                {
                    return new ErrorResult("Error connecting to host.");
                }
            }
            else
            {
                builder.WriteLine("Already connected.");
            }

            return builder.CreateResult(null);
        }
Exemplo n.º 5
0
 private static void displayCommand(ResultBuilder builder, CommandDetail detail)
 {
     builder.WriteLine();
     builder.WriteLine(string.Format("COMMAND: {0}", detail.Name));
     builder.WriteLine(string.Format("   {0}", detail.Help));
     builder.WriteLine();
     builder.WriteLine(string.Format("USAGE: {0}", detail.Usage));
 }
Exemplo n.º 6
0
        public static ActionResult GetCommand()
        {
            ResultBuilder builder = new ResultBuilder();

            builder.WriteLine("Local Commands");
            builder.WriteLine("====================");
            foreach (string key in _commands.Keys)
            {
                var detail = _commands[key] as CommandDetail;

                if (detail != null)
                {
                    builder.WriteLine(string.Format("{0}# {1}", detail.Name.PadRight(20), detail.Help));
                }
            }

            if (IsConnected)
            {
                builder.WriteLine();
                builder.WriteLine("Remote Commands");
                builder.WriteLine("====================");
                var commands = InspectProvider.GetCommands();
                foreach (var command in commands)
                {
                    builder.WriteLine(string.Format("{0}# {1}", command.Name.PadRight(20), command.Help));
                }
            }

            return builder.CreateResult();
        }
Exemplo n.º 7
0
        public static ActionResult GetCommand(string commandName)
        {
            if (_commands.ContainsKey(commandName))
            {
                ResultBuilder builder = new ResultBuilder();

                var detail = _commands[commandName] as CommandDetail;

                if (detail != null)
                {
                    displayCommand(builder, detail);
                }

                return builder.CreateResult();
            }
            else if (IsConnected && InspectProvider.ContainsCommand(commandName))
            {
                ResultBuilder builder = new ResultBuilder();

                var commands = InspectProvider.GetCommands();

                var detail = commands.FirstOrDefault(command => command.Name.ToLower() == commandName);

                if (detail != null)
                {
                    displayCommand(builder, detail);
                }

                return builder.CreateResult();
            }
            else
            {
                return new ErrorResult("Command not found.");
            }
        }
Exemplo n.º 8
0
        public static ActionResult Disconnect()
        {
            ResultBuilder builder = new ResultBuilder();
            _isConnected = false;
            builder.WriteLine("Disconnected.");

            return builder.CreateResult(null);
        }
Exemplo n.º 9
0
 public ActionResult GetValueOfX(object args)
 {
     ResultBuilder builder = new ResultBuilder();
     return builder.CreateResult(Injection.X);
 }