Пример #1
0
        public override void Execute(String args)
        {
            if (String.IsNullOrEmpty(args))
            {
                Helper.WriteLine("Either no or invalid arguments specified!");
                return;
            }

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

            String[] str = args.Split('/');
            if (str.Length > 1)
            {
                String fulldir = dir.FullName;
                for (int i = 0; i < str.Length - 1; i++)
                {
                    fulldir += str[i] + "/";
                }
                PulsarDirectory app = PulsarDirectory.GetDirectoryByFullName(fulldir);
                if (app != null && str[str.Length - 1] != null && str[str.Length - 1] != "")
                {
                    app.AddFile(str[str.Length - 1]);
                }
            }
            else
            {
                dir.AddFile(args);
            }
        }
Пример #2
0
        public static bool ProcessCommand(String cmd, String args)
        {
            CommandBase c = Find(cmd);

            if (c == null)
            {
                PulsarDirectory dir = PulsarDirectory.GetDirectoryByFullName(Pulsar.Environment.GlobalEnvironment.Current["CURRENTDIR"]);
                if (dir != null)
                {
                    PulsarFile fl = dir.GetFileByName(cmd);
                    if (fl != null)
                    {
                        Helper.WriteLine("Please make sure the file you have selected IS A BINARY or expect lots of crashes!");
                        if (Helper.Continue())
                        {
                            //Pulsar.Executables.BinaryLoader.CallRaw(fl.ReadAllBytes());
                            return(true);
                        }
                    }
                }
                return(false);
            }
            if (c.CanExecute(args))
            {
                c.Execute(args);
            }
            return(true);
        }
Пример #3
0
        public override void Execute(String args)
        {
            if (args == ".")
            {
                return;
            }
            else if (args == "..")
            {
                GlobalEnvironment.Current["CURRENTDIR"] = GetHomeDir(GlobalEnvironment.Current["CURRENTDIR"]);
            }
            else
            {
                var dir  = PulsarDirectory.GetDirectoryByFullName(GlobalEnvironment.Current["CURRENTDIR"]);
                var name = args;
                var d    = dir.GetDirectoryByName(name);

                if (d == null)
                {
                    d = PulsarDirectory.GetDirectoryByFullName(name);
                }

                if (d == null)
                {
                    Helper.WriteLine("Can't find path");
                }
                else
                {
                    GlobalEnvironment.Current["CURRENTDIR"] = d.FullName;
                }
            }
        }
Пример #4
0
        public override void Execute(String args)
        {
            var dir   = PulsarDirectory.GetDirectoryByFullName(GlobalEnvironment.Current["CURRENTDIR"]);
            var dirs  = dir.GetDirs();
            var files = dir.GetFiles();

            dirs.ForEeach(d => Helper.Write(d.ToString() + " ", ConsoleColor.Blue));
            files.ForEeach(f => Helper.Write(f.ToString() + " ", ConsoleColor.Green));
        }
Пример #5
0
 private static void CreateDirectoryAndVerify(string directory)
 {
     PulsarFileSystem.mFS.Root.AddDirectory(directory);
     sf = PulsarFileSystem.mFS.Root.GetDirectoryByName(directory);
     if (sf == null)
     {
         Helper.Error("Cannot create required files, aborting creation of " + directory);
         throw new Exception("Failed creation of directories.");
     }
 }
Пример #6
0
 public override void Execute(String args)
 {
     if (String.IsNullOrEmpty(args))
     {
         Helper.WriteLine("Either no or invalid arguments specified!");
     }
     else
     {
         String          file = args;
         PulsarDirectory dir  = PulsarDirectory.GetDirectoryByFullName(GlobalEnvironment.Current["CURRENTDIR"]);
         dir.RemoveFile(file);
         dir.RemoveDirectory(file);
     }
 }
Пример #7
0
        private static void CreateFileAndVerify(string file, string directory)
        {
            PulsarDirectory dir = PulsarFileSystem.mFS.Root.GetDirectoryByName(directory);

            if (dir != null)
            {
                dir.AddFile(file);
                PulsarFile nf = dir.GetFileByName(file);
                if (nf == null)
                {
                    throw new Exception("Could not create!");
                }
            }
            else
            {
                throw new ArgumentException("Bad directory");
            }
        }
Пример #8
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))
     {
         PulsarFile accfile = PulsarDirectory.GetFileByFullName("/etc/passwd");
         if (accfile == null)
         {
             PulsarFileSystem.mFS.Root.GetDirectoryByName("etc").AddFile("passwd");
             accfile = PulsarDirectory.GetFileByFullName("/etc/passwd");
         }
         hasher.Value = newpass;
         accfile.WriteAllText(newus + uspasssep + hasher.FingerPrint + usseparator);
         return(true);
     }
     else
     {
         return(false);
     }
 }
Пример #9
0
        /// <summary>
        /// Starts a new infinite loop that represents a simple shell
        /// </summary>
        public static void StartShell()
        {
            Helper.WriteLine("Starting Shell...", ConsoleColor.Green);
            PulsarFile motd = PulsarDirectory.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
            {
                Security.Account u           = new Security.Account(GlobalEnvironment.Current["USER"]);
                String           h           = GlobalEnvironment.Current["HOST"];
                PulsarDirectory  dir         = PulsarDirectory.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);
        }
Пример #10
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)
        {
            PulsarFile accfile = PulsarDirectory.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!");
            }
        }
Пример #11
0
        public override void Execute(String args)
        {
            if (String.IsNullOrEmpty(args))
            {
                Helper.WriteLine("target File non specified");
                return;
            }
            var        dir  = PulsarDirectory.GetDirectoryByFullName(GlobalEnvironment.Current["CURRENTDIR"]);
            PulsarFile file = dir.GetFileByName(args);

            if (file == null)
            {
                file = PulsarDirectory.GetFileByFullName(args);
            }
            if (file == null)
            {
                Helper.WriteLine("Can't find file");
            }
            else
            {
                String content = file.ReadAllText();
                Helper.WriteLine(content);
            }
        }