public override void Execute(String args)
        {
            if (String.IsNullOrEmpty(args))
            {
                Helper.WriteLine("target File non specified");
                return;
            }

            var dir = NoobDirectory.GetDirectoryByFullName(GlobalEnvironment.Current["CURRENTDIR"]);

            NoobFile file = dir.GetFileByName(args);

            if (file == null)
            {
                file = NoobDirectory.GetFileByFullName(args);
            }

            if (file == null)
            {
                Helper.WriteLine("Can't find file");
            }
            else
            {
                String content = file.ReadAllText();
                Helper.WriteLine(content);
            }
        }
Esempio n. 2
0
 /// <summary>
 /// Adds this new user to the Accounts file.
 /// </summary>
 /// <param name="newus">New Username</param>
 /// <param name="newpass">New Password</param>
 public static bool Add(String newus, String newpass)
 {
     if (!Utils.StringContains(newus, InvalidChars))
     {
         NoobFile accfile = NoobDirectory.GetFileByFullName("/etc/passwd");
         if (accfile == null)
         {
             NoobFileSystem.mFS.Root.GetDirectoryByName("etc").AddFile("passwd");
             accfile = NoobDirectory.GetFileByFullName("/etc/passwd");
         }
         hasher.Value = newpass;
         accfile.WriteAllText(newus + uspasssep + hasher.FingerPrint + usseparator);
         return(true);
     }
     else
     {
         return(false);
     }
 }
Esempio n. 3
0
        /// <summary>
        /// Starts a new infinite loop that represents a simple shell
        /// </summary>
        public static void StartShell()
        {
            Helper.WriteLine("Starting Shell...", ConsoleColor.Green);
            NoobFile motd = NoobDirectory.GetFileByFullName("/etc/motd");

            if (motd == null)
            {
                Helper.Error("MOTD not available. Please type touch /etc/motd in the command line!");
            }
            else
            {
                Helper.WriteLine(motd.ReadAllText());
            }
            String cmd = "";

            do
            {
                Account       u           = new Account(GlobalEnvironment.Current["USER"]);
                String        h           = GlobalEnvironment.Current["HOST"];
                NoobDirectory dir         = NoobDirectory.GetDirectoryByFullName(GlobalEnvironment.Current["CURRENTDIR"]);
                String        consoleline = u.Username + "@" + h + ":" + dir.FullName + "# ";
                Helper.Write(consoleline);

                cmd = Helper.ReadLine();
                String[] t = cmd.SplitAtFirstSpace();
                String   c = t[0];                               // Command
                String   a = t.Length > 1 ? t[1] : String.Empty; // Argument(s)

                Boolean p = CommandManager.ProcessCommand(c, a);

                if (!p)
                {
                    Helper.WriteLine("No such command found!");
                }

                if (!Helper.LastLineIsEmpty())
                {
                    Helper.WriteLine("");
                }
            }while (true);
        }
Esempio n. 4
0
        /// <summary>
        /// Account constructor method that check's the user credentials
        /// </summary>
        /// <param name="User">Username</param>
        /// <param name="Pass">Password</param>
        public Account(String User, String Pass)
        {
            NoobFile accfile = NoobDirectory.GetFileByFullName("/etc/passwd");

            if (accfile == null)
            {
                Helper.Error("/etc/passwd not available! Quitting.");
                this._OK = false;
            }
            hasher.Value = Pass;
            if (accfile.ReadAllText() == (User + uspasssep + hasher.FingerPrint + usseparator))
            {
                this._Username = User;
                this._HomeDir  = "/";
                this._OK       = true;
                Helper.WriteLine("Login Succeded!");
            }
            else
            {
                this._OK = false;
                Helper.Error("Login Failed! Verify user And Password!");
            }
        }