Пример #1
0
    [RPC] private void AddUserRPC(string username, string password, bool isAdmin, int vsID, bool canLogin)
    {
        IGC_User user = new IGC_User(username, password, isAdmin, IGC_VirtualSystem.GetInstanceByID(vsID), canLogin);

        users.Add(user.name, user);
        CreateUserHomeDir(user);
    }
Пример #2
0
    public void BuildUsersList()
    {
        if (Network.peerType == NetworkPeerType.Client || (Network.peerType != NetworkPeerType.Client && virtualSystem.HasSaveData()))
        {
            BuildUsersFromUserString(virtualSystem.GetUsersString(virtualSystem.restoreData));
            virtualSystem.OnUsersReady();
            BuildGroupsFromGroupsString(virtualSystem.GetGroupsString(virtualSystem.restoreData));
            virtualSystem.OnGroupsReady();
        }
        else
        {
            //create system default users
            defaultUser = AddUser(new IGC_User(defaultUsername, defaultUserPassword, false, virtualSystem, true), systemUser);
            rootUser    = AddUser(new IGC_User("root", rootUserPassword, true, virtualSystem, true), systemUser);

            //encrypt editor specified user password
            for (int i = 0; i < usersList.Length; i++)
            {
                string [] userinfo = IGC_Utils.SplitString(":", usersList[i]);
                userinfo[1] = IGC_Utils.Md5Sum(userinfo[1]);

                usersList[i] = string.Join(":", userinfo);
            }

            BuildUsersFromUserString(string.Join("\n", usersList));
            BuildGroupsFromGroupsString(string.Join("\n", groupsList));
        }

        ready = true;
        virtualSystem.OnSystemReady();
    }
Пример #3
0
 public void MessageUser(IGC_User user, string message)
 {
     if (userRegistry.loggedInUsers.Contains(user))
     {
         user.terminal.shell.stdout(message);
     }
 }
Пример #4
0
    public bool RemoveUser(IGC_User user, IGC_User issuer)
    {
        if (!admins.Contains(issuer) && !issuer.isAdmin)
        {
            return(false);
        }

        if (!users.Contains(user))
        {
            return(false);
        }

        user.groups.Remove(this);
        this.users.Remove(user);

        if (admins.Contains(user))
        {
            admins.Remove(user);
        }

        if (user.virtualSystem.networkReady)
        {
            user.virtualSystem.gameObject.GetComponent <NetworkView>().RPC("UserRMGroupRPC", RPCMode.Others, this.name, user.name);
        }

        return(true);
    }
Пример #5
0
    public bool RMFile(IGC_URL url, IGC_User user)
    {
        if (FileExists(url.fullpath))
        {
            IGC_File file = GetFile(url.fullpath);
            if (!CanAccessFile(file, user))
            {
                return(false);
            }
            else
            {
                RemoveFileActions(file);

                if (virtualSystem.networkReady)
                {
                    GetComponent <NetworkView>().RPC("RemoveFileRPC", RPCMode.Others, url.fullpath);
                }

                return(true);
            }
        }
        else
        {
            return(false);
        }
    }
Пример #6
0
    public IGC_File CreateFile(IGC_URL url, IGC_User user, bool isDir)
    {
        if (FileExists(url.fullpath))
        {
            return(null);
        }

        IGC_File targetDir = GetFile(url.dirpath);

        if (targetDir != null && targetDir.isDir)
        {
            if (!CanAccessFile(targetDir, user))
            {
                return(null);
            }

            IGC_File file = CreateFileGameObject(url, user.name, isDir);

            if (virtualSystem.networkReady)
            {
                GetComponent <NetworkView>().RPC("CreateFileRPC", RPCMode.Others, url.fullpath, user.name, isDir);
            }

            return(file);
        }
        else
        {
            return(null);
        }
    }
Пример #7
0
    public override string command_function()
    {
        if (argv.Length == 2)
        {
            issuer.SetPassword(argv[1]);
            return("your new password has been set");
        }
        if (argv.Length == 3)
        {
            IGC_User user = virtualSystem.userRegistry.GetUser(argv[1]);

            if (user == null)
            {
                return("user does not exist");
            }

            if (!issuer.admin && user.name != issuer.name)
            {
                return("only admins can change other users' passwords");
            }

            user.SetPassword(argv[2]);

            if (virtualSystem.networkReady)
            {
                virtualSystem.GetComponent <NetworkView>().RPC("SetPasswordRPC", RPCMode.Others, user.name, argv[2]);
            }

            return(user.name + "'s new password has been set");
        }

        return(malformed_error + "\n" + usage);
    }
Пример #8
0
 public void SetPrevUser(IGC_User user)
 {
     this.previousUser = user;
     if (networkReady)
     {
         GetComponent <NetworkView>().RPC("SyncPrevUserRPC", RPCMode.Others, user.name);
     }
 }
Пример #9
0
    void Awake()
    {
        virtualSystem       = gameObject.GetComponent <IGC_VirtualSystem>();
        systemUser          = new IGC_User("system", "generate a better one later", true, virtualSystem, false); //system user is needed even if everything else is loaded from a statestring
        systemUser.terminal = gameObject.GetComponent <InGameComputer> ();

        if (string.IsNullOrEmpty(rootUserPassword) || string.IsNullOrEmpty(defaultUserPassword))        //can't let the editor vals slide
        {
            Debug.LogError("UserRegistry (virtualSystem:" + virtualSystem.IP + "): default rootuser and defaultuser password cannot be left empty in the editor");
        }
    }
Пример #10
0
    private void CreateUserHomeDir(IGC_User user)
    {
        IGC_File homeDir = virtualSystem.fileSystem.CreateFile(virtualSystem.fileSystem.ParseURL(user.homedir, user.cwd), systemUser, true);

        if (homeDir == null)        //if it exists, createfile will return null
        {
            homeDir = virtualSystem.fileSystem.files["/home/" + user.name];
        }

        homeDir.fileOwner = user.name;
    }
Пример #11
0
    public override string command_function()
    {
        IGC_UserRegistry ur = virtualSystem.userRegistry;

        if (argv.Length > 2)
        {
            if (!ur.users.ContainsKey(argv[1]))
            {
                return("user '" + argv[1] + "' does not exist");
            }

            InGameComputer terminal = issuer == null ? virtualSystem.terminal : issuer.terminal;

            IGC_User checkLoggedIn = ur.GetUser(argv[1]);

            if (ur.loggedInUsers.Contains(checkLoggedIn))
            {
                return(argv[1] + " is already logged in");
            }

            if (issuer != null)
            {
                if (issuer.terminal != null)
                {
                    if (issuer.terminal.currentUser != null)
                    {
                        if (issuer.loggedInRemotely)
                        {
                            ur.loggedInUsers.Remove(issuer);                             //the logout function will bounce the user back to their own terminal so here, if remotelogged, we will keep things simple
                        }
                        else
                        {
                            virtualSystem.userRegistry.Logout(issuer.terminal.currentUser);
                        }
                    }
                }
            }

            IGC_User user = ur.Login(argv [1], argv [2], terminal);

            if (user != null)
            {
                return("welcome, " + user.name);
            }
            else
            {
                return("password incorrect, try again");
            }
        }
        else
        {
            return("error: command malformed\n" + usage);
        }
    }
Пример #12
0
    private void BounceToPreviousUser(IGC_User user)
    {
        IGC_VirtualSystem localVS  = user.terminal.transform.GetComponent <IGC_VirtualSystem>();
        IGC_User          prevUser = user.terminal.previousUser;

        user.loggedInRemotely = false;
        user.terminal.SwapVirtualSystem(ref localVS);
        //log in previous user on local terminal
        user.terminal.currentUser  = prevUser;
        user.terminal.previousUser = null;
    }
Пример #13
0
    public bool RemoveUser(IGC_User user)
    {
        if (users.ContainsKey(user.name))
        {
            users.Remove(user.name);

            if (virtualSystem.networkReady)
            {
                GetComponent <NetworkView>().RPC("RemoveUserRPC", RPCMode.Others, user.name);
            }

            return(true);
        }
        return(false);
    }
Пример #14
0
    [RPC] private void LogoutRPC(string username)
    {
        IGC_User user = users[username];

        user.terminal.currentUser = null;
        user.terminal.shell.Reset();

        if (user.loggedInRemotely)
        {
            BounceToPreviousUser(user);
        }

        user.terminal.UpdateInfoLine();
        loggedInUsers.Remove(user);
    }
Пример #15
0
    public bool RemoveGroup(IGC_UserGroup group, IGC_User user)
    {
        //add perms stuff later
        if (groups.ContainsKey(group.name))
        {
            groups.Remove(group.name);

            if (virtualSystem.networkReady)
            {
                GetComponent <NetworkView>().RPC("RemoveGroupRPC", RPCMode.Others, group.name);
            }

            return(true);
        }
        return(false);
    }
Пример #16
0
    public IGC_UserGroup AddGroup(string groupname, IGC_User owner)
    {
        groupname = IGC_Utils.EscapeUserOrGroup(groupname);

        if (!groups.ContainsKey(groupname))
        {
            groups.Add(groupname, new IGC_UserGroup(groupname, owner));

            if (virtualSystem.networkReady)
            {
                GetComponent <NetworkView>().RPC("AddGroupRPC", RPCMode.Others, groupname, owner.name);
            }

            return(groups[groupname]);
        }
        return(null);
    }
Пример #17
0
    public IGC_User AddUser(IGC_User user, IGC_User requester)
    {
        user.name = IGC_Utils.EscapeUserOrGroup(user.name);

        if (!users.ContainsKey(user.name))
        {
            users.Add(user.name, user);

            CreateUserHomeDir(user);

            if (virtualSystem.networkReady)
            {
                GetComponent <NetworkView>().RPC("AddUserRPC", RPCMode.Others, user.name, user.password, user.isAdmin, virtualSystem.instanceID, user.canLogin);
            }

            return(user);
        }

        return(null);
    }
Пример #18
0
    public IGC_User AddUser(IGC_User user, bool asAdmin)
    {
        if (users.Contains(user))
        {
            return(user);
        }
        this.users.Add(user);
        user.groups.Add(this);

        if (asAdmin)
        {
            admins.Add(user);
        }

        if (user.virtualSystem.networkReady)
        {
            user.virtualSystem.gameObject.GetComponent <NetworkView>().RPC("UserAddGroupRPC", RPCMode.Others, this.name, user.name, asAdmin);
        }

        return(user);
    }
Пример #19
0
    private IEnumerator SetCurrenUserWhenURReady(IGC_UserRegistry ur, string currentuser, string prevuser)
    {
        while (!ur.ready)
        {
            yield return(null);
        }

        //set current user
        if (!string.IsNullOrEmpty(currentuser) && currentuser != "null")
        {
            currentUser          = virtualSystem.userRegistry.users[currentuser];
            currentUser.terminal = this;
            UpdateInfoLine();
        }

        //set prev user
        if (!string.IsNullOrEmpty(prevuser) && prevuser != "null")
        {
            this.previousUser = currentUser.terminal.gameObject.GetComponent <IGC_VirtualSystem>().userRegistry.users[prevuser];
        }
    }
Пример #20
0
    private string RemoveUserFromGroup()
    {
        if (argv.Length != 4)
        {
            return(malformed_error + "\n" + "usage: groups rmuser <group_name> <username>");
        }

        IGC_UserGroup group = registry.GetGroup(argv [2]);

        if (group == null)
        {
            return("group " + argv[2] + " does not exist");
        }

        IGC_User user = registry.GetUser(argv[3]);

        if (user == null)
        {
            return("user " + argv[3] + " does not exist");
        }

        if (!user.groups.Contains(group))
        {
            return(user.name + " is not in " + group.name);
        }

        if (!group.admins.Contains(issuer) && !issuer.isAdmin)
        {
            return("only system or group administrators can add or remove users");
        }

        if (group.RemoveUser(user, issuer))
        {
            return(user.name + " removed from group " + group.name);
        }
        else
        {
            return("insufficient privilages or user not in group.");
        }
    }
Пример #21
0
 public bool CanAccessFile(IGC_File file, IGC_User user)
 {
     if (user.isAdmin)
     {
         //Debug.Log("admins can access any file. ");
         return(true);
     }
     else
     {
         if (file.protectedFile)
         {
             //Debug.Log("not admin? if protected, no. ");
             return(false);
         }
         else
         {
             if (file.accessGroups.Count == 0)
             {
                 //Debug.Log("if not protected. if you own it, yes. ");
                 return(true);
             }
             else
             {
                 if (file.accessGroups.Count > 0)
                 {
                     foreach (IGC_UserGroup ag in file.accessGroups)
                     {
                         if (user.groups.Contains(ag))
                         {
                             //Debug.Log("if not... if you belong to one of its access groups, yes");
                             return(true);
                         }
                     }
                 }
             }
         }
     }
     //Debug.Log("FINAL NO");
     return(false);
 }
Пример #22
0
    private string RemoveUser()
    {
        if (argv.Length != 3)
        {
            return(malformed_error + "\n" + "usage: users rm <user_name>");
        }

        IGC_User user = registry.GetUser(argv [2]);

        if (user == null)
        {
            return("user " + argv[2] + " does not exist");
        }

        if (!issuer.isAdmin)
        {
            return("only administrators can delete users");
        }

        registry.RemoveUser(user);
        return("user " + user.name + " deleted. make sure to remove /home/" + user.name + "/ if you no longer need it");
    }
Пример #23
0
    public void BuildUsersFromUserString(string usersString)
    {
        if (usersString == "NONE" || usersString == "" || usersString == null)
        {
            return;
        }

        string[] userStringList = IGC_Utils.SplitString("\n", usersString);

        //foreach user in usersting
        for (int i = 0; i < userStringList.Length; i++)
        {
            string[] user = IGC_Utils.SplitString(":", userStringList[i]);

            int terminalID = user[4] == "-1"
                                ? System.Int32.Parse(user[4])
                                : gameObject.GetComponent <InGameComputer>().instanceID;

            string
                username = user[0],
                userCwd  = user[5];
            bool
                isAdmin        = user[2] == "True" ? true : false,
                loggedIn       = user[6] == "True" ? true : false,
                loggedRemotely = user[3] == "True" ? true : false;

            IGC_User newUser = AddUser(new IGC_User(username, "", isAdmin, virtualSystem, true), systemUser);

            newUser.password         = user[1];     //need to assign it directly since the user class encrypts whatever you hand to it
            newUser.loggedInRemotely = loggedRemotely;
            newUser.terminal         = InGameComputer.GetInstanceByID(terminalID);
            newUser.cwd = userCwd;

            if (loggedIn)
            {
                loggedInUsers.Add(newUser);
            }
        }
    }
Пример #24
0
    private string UserInfo()
    {
        if (argv.Length != 3)
        {
            return(malformed_error + "\n" + "usage: users info <user_name>");
        }

        IGC_User user = registry.GetUser(argv [2]);

        if (user != null)
        {
            string[] groups = new string[user.groups.Count];
            int      i      = 0;

            foreach (IGC_UserGroup group in user.groups)
            {
                groups[i++] = group.name;
            }

            return("ADMIN: " + user.isAdmin.ToString() + "\nGROUPS: " + string.Join(", ", groups) + "\nCWD: " + user.cwd);
        }
        return("user " + argv[2] + " does not exist");
    }
Пример #25
0
    private string AdminStatus()
    {
        if (argv.Length != 4)
        {
            return(malformed_error + "\n" + "usage: users admin <user_name> <y|n>");
        }

        if (!issuer.isAdmin)
        {
            return("you do not have permission to grant administrative privaleges");
        }

        bool     admin = argv [3] == "y" ? true : false;
        IGC_User user  = registry.GetUser(argv [2]);

        if (user == null)
        {
            return("user " + argv[2] + " does not exist");
        }

        user.Admin(admin);
        return("user " + argv[2] + " is " + (admin ? "now" : "no longer") + " an administrator");
    }
Пример #26
0
    public bool CanEditFile(IGC_File file, IGC_User user)
    {
        if (user.isAdmin)
        {
            return(true);
        }
        else
        {
            if (file.protectedFile)
            {
                return(false);
            }
        }
        if (file.editGroups.Count == 0)
        {
            if (file.accessGroups.Count == 0)
            {
                return(true);
            }
            foreach (IGC_UserGroup accessGroup in file.accessGroups)
            {
                if (user.groups.Contains(accessGroup))
                {
                    return(true);
                }
            }
        }

        foreach (IGC_UserGroup editGroup in file.editGroups)
        {
            if (user.groups.Contains(editGroup))
            {
                return(true);
            }
        }
        return(false);
    }
Пример #27
0
    private string AddUserToGroup()
    {
        if (argv.Length != 5)
        {
            return(malformed_error + "\n" + "usage: groups adduser <group_name> <username> <group admin? y|n>");
        }

        IGC_User user = registry.GetUser(argv[3]);

        if (user == null)
        {
            return("user " + argv[3] + " does not exist");
        }

        IGC_UserGroup group = registry.GetGroup(argv [2]);

        if (group == null)
        {
            return("group " + argv[2] + " does not exist");
        }

        if (user.groups.Contains(group))
        {
            return(user.name + " is already in " + group.name);
        }

        if (!group.admins.Contains(issuer) && !issuer.isAdmin)
        {
            return("only system or group administrators can add or remove users");
        }

        bool asAdmin = argv [4] == "y" ? true : false;

        group.AddUser(user, asAdmin);

        return(user.name + " added to group " + group.name + (asAdmin ? " as admin" : ""));
    }
Пример #28
0
    public bool Logout(IGC_User user)
    {
        if (loggedInUsers.Contains(user))
        {
            loggedInUsers.Remove(user);
            user.terminal.currentUser = null;
            user.terminal.shell.Reset();

            if (user.loggedInRemotely)
            {
                BounceToPreviousUser(user);
            }

            user.terminal.UpdateInfoLine();

            if (virtualSystem.networkReady)
            {
                GetComponent <NetworkView>().RPC("LogoutRPC", RPCMode.Others, user.name);
            }

            return(true);
        }
        return(false);
    }
Пример #29
0
    public override string command_function()
    {
        if (argv.Length == 1)
        {
            return(this.usage + "\n" + this.help_text);
        }
        if (argv.Length != 2)
        {
            return(this.malformed_error + "\nusage: ssh remote_user:remote_user_password@Remote_address");
        }

        if (issuer.loggedInRemotely)
        {
            return("you are already logged in on a remote system. terminate the current connection before starting another ssh connection.");
        }

        string[]
        remoteAddress = argv [1].Split(new string[1] {
            "@"
        }, System.StringSplitOptions.RemoveEmptyEntries),
        userInfo = remoteAddress[0].Split(new string[1] {
            ":"
        }, System.StringSplitOptions.RemoveEmptyEntries);

        if (userInfo.Length != 2 || remoteAddress.Length != 2)
        {
            return("address " + argv[1] + " not understood");
        }

        string remoteIP = remoteAddress [1];

        GameObject r = GameObject.Find("Computer_" + remoteIP);

        if (r == null)
        {
            return("no host with that address");
        }
        if (!r.GetComponent <InGameComputer>().powerState)
        {
            return("no response. are you sure the machine you're trying to access is not off?");
        }

        if (r == issuer.terminal.gameObject)
        {
            return("you cannot create an ssh connection with the local system.");
        }

        IGC_VirtualSystem remotehost = r.GetComponent <IGC_VirtualSystem>();

        IGC_User remoteUser = remotehost.userRegistry.GetUser(userInfo[0]);

        if (remoteUser == null)
        {
            return(userInfo[0] + " does not exist on " + remoteIP);
        }


        if (remotehost.userRegistry.loggedInUsers.Contains(remoteUser))
        {
            return(remoteUser.name + " is already logged in");
        }

        if (!remoteUser.CheckPassword(userInfo[1]))
        {
            return("password incorrect");
        }

        issuer.terminal.SetPrevUser(issuer);
        issuer.terminal.SwapVirtualSystem(ref remotehost);

        issuer.terminal.virtualSystem.userRegistry.Login(userInfo [0], userInfo [1], issuer.terminal);
        //issuer.terminal.currentUser.loggedInRemotely = true;

        return("connected to " + remotehost.IP + " as " + remoteUser.name);
    }
Пример #30
0
 public IGC_UserGroup(string name, IGC_User groupCreator)
 {
     this.name    = name;
     this.creator = groupCreator.name;
     AddUser(groupCreator, true);
 }