Exemplo n.º 1
0
        /// <summary>
        /// Load a user from the user registry
        /// </summary>
        /// <param name="name"></param>
        /// <param name="password"></param>
        /// <returns></returns>
        public static User Load(string name)
        {
            if (!Directory.Exists(RegistryPath))
            {
                Directory.CreateDirectory(RegistryPath);
            }

            FileStream userFile;

            try
            {
                userFile = File.OpenRead(RegistryPath + Path.DirectorySeparatorChar + name + "." + USER_FILE_EXT);
            }
            catch (IOException)
            {
#if DEBUG
                Console.Error.WriteLine(TAG + " Failed to find user file in \"" + RegistryPath + "\"");
#endif
                return(new User()
                {
                    Name = "user",
                    Environment = Executor.Build("user")
                });
            }

            BinaryFormatter formatter = new BinaryFormatter();
            User            u         = (User)formatter.Deserialize(userFile);
            userFile.Close();

            //HACK temporarily make an env for users
            u.Environment = Executor.Build(u.Name);

            return(u);
        }
Exemplo n.º 2
0
        public static void Main(string[] args)
        {
            Initialize(args);

            Executor.Init();
            User.RegistryPath = Assembly.GetEntryAssembly().CodeBase;
            env   = Executor.Build("user");
            redir = new ConsoleRedirector();
            env.SetOutput(redir);              //TODO executor redirect class
            env.SetInput(redir);

            Connect();
            client.Flow = Endpoint.FlowState.outgoing;

            //verify connection
            while (client.Connected)
            {
                Console.Write(addr.ToString() + "> ");

                string input;
                if (execMode != ExecutionMode.listen)
                {
                    input = Console.ReadLine();
                }
                else
                {
                    input = "listen -t all";
                }

                int commandResult = Executor.EXEC_FAILURE;

                //try to run the command locally first
                string[] parsedInput = env.ParseInput(input);
                commandResult = env.InvokeCommand(parsedInput);

                //didn't find command locally, send command to server
                if (commandResult == Executor.EXEC_NOTFOUND)
                {
                    client.Send(new Packet(Packet.DataType.command, input));
                    client.Flow = Endpoint.FlowState.incoming;

                    HandleResponses(ref commandResult);

                    client.Flow = Endpoint.FlowState.outgoing;
                }

                //some failure occured
                if (commandResult != 0)
                {
                    Console.WriteLine("Status: " + commandResult);
                    switch (commandResult)
                    {
                    case Executor.EXEC_SKIP:
                        Write("Command does not fulfill requirements; execution skipped", ConsoleColor.Yellow);
                        break;

                    case Executor.EXEC_FAILURE:
                        Write("Failed executing \"" + parsedInput[0] + "\"", ConsoleColor.Red);
                        break;

                    case Executor.EXEC_NOTFOUND:
                        Write("Command \"" + parsedInput[0] + "\" could not be found", ConsoleColor.Yellow);
                        break;

                    default:
                        Write("Unknown status", ConsoleColor.Magenta);
                        break;
                    }
                }
            }
#if DEBUG
            Console.WriteLine(DEBUG_TAG + " Exiting...");
#endif
        }