Exemplo n.º 1
0
        private static object CleanupSsh(dynamic parm)
        {
            string userRegex = parm["user_regex"].Value;
            string userName = userRegex.Remove(0, 1);
            userName = userName.Remove(userName.Length - 1, 1);
            SshResult sshResult = new SshResult();
            sshResult.Command = "cleanup";
            Logger.Info("Cleaning up SSH");

            try
            {
                WindowsVCAPUsers.DeleteUser(userName);
                File.Delete(Path.Combine(Config.BaseDir, "bosh", "salt", userName + ".salt"));
                Logger.Info("Deleted salt file");
                sshResult.Status = "success";
                Logger.Info("Deleted user for SSH");
                SshdMonitor.StopSshd();
            }
            catch (Exception ex)
            {
                Logger.Error("Failed to delete user " + ex.ToString());
                sshResult.Status = "failed";
            }

            sshResult.IP = null;
            return sshResult;
        }
Exemplo n.º 2
0
        private static object SetupSsh(dynamic parameters)
        {
            string userName = parameters["user"].Value;

            //Needed to enforce windows password rules
            string password = string.Format(CultureInfo.InvariantCulture, "{0}!", parameters["password"].Value);
            SaveSaltInFile(userName, password.Substring(0, 2));

            Logger.Info("Setting up SSH with user:"******" and password: "******"setup";
            try
            {
                Uhuru.Utilities.WindowsVCAPUsers.CreateUser(userName, password);
                Uhuru.Utilities.WindowsUsersAndGroups.AddUserToGroup(userName, "Administrators");
                sshResult.Status = "success";
                Logger.Info("Created user for SSH");
                SshdMonitor.StartSshd();

            }
            catch (Exception ex)
            {
                Logger.Error("Failed to create user " + ex.ToString());
                sshResult.Status = "failed";
            }
            sshResult.IP = Config.DefaultIP;

            return sshResult;
        }