예제 #1
0
        public void CreateMany(string userNamePrefix, int usernameSuffix, int teamId, string password, int port, string userGroupName, string userNames, bool disablepwchange, bool pwneverexpires)
        {
            GroupPrincipal group = GroupPrincipal.FindByIdentity(context, userGroupName);

                string[] studentNames = userNames.Replace(Environment.NewLine, "").Split(',').Select(x => x.Trim()).ToArray();
                string usernamePrefix = userNamePrefix.Replace(" ", "");
                string username = usernamePrefix + usernameSuffix;
                string description = "Bruger oprettet med UserHelper";
                string physicalPath = "C:\\inetpub\\wwwroot\\" + username + "\\";
                try
                {
                    for (int i = 0; i < studentNames.Length; i++)
                    {
                        UserPrincipal user = new UserPrincipal(context);
                        UserManagement management = new UserManagement(user, group);
                        //Create Windows User
                        management.CreateLocalWindowsAccount(username, password, username, description, disablepwchange, pwneverexpires, user);
                        management.AddUserToGroup(group, user);
                        //Create IIS Website
                        iis.CreateWebsite(username, "DefaultAppPool", "*:" + port + ":", physicalPath);

                        //Create FTP Virtual Directory
                        //txtStatusMessages.Text += iis.CreateFTPVDir("localhost", username, physicalPath, username);
                        iis.CreateVirtualDirectory("_FTP", username, physicalPath);

                        //create databases
                        sql.CreateSQLLoginUserAndDatabase(username, username, password);

                        Credentials cred = new Credentials();
                        cred.DatabaseUserName = username;
                        cred.DatabasePassword = password;
                        cred.FTPUserName = username;
                        cred.FTPPassword = password;
                        cred.WebsitePort = port;
                        cred.WindowsUserGroupName = group.Name;

                        Student student = new Student();
                        student.Name = studentNames[i];
                        student.Team = db.Teams.Find(teamId);
                        student.Credentials = cred;
                        db.Students.Add(student);

                        //Change username and port for next iteration
                        usernameSuffix++;
                        username = usernamePrefix + usernameSuffix;
                        physicalPath = "C:\\inetpub\\wwwroot\\" + username + "\\";
                        port++;

                    }

                    db.SaveChanges();

                    BatchState.State = UserProcessState.INITIAL;
                    //done
                }
                catch (Exception)
                {
                    throw;
                }
        }
예제 #2
0
        public ActionResult Create()
        {
            Student student = new Student();
            Credentials cred = new Credentials();
            student.Credentials = cred;
            ViewBag.StartPort = (db.Credentials.Max(x => x.WebsitePort)+1).ToString();
            SelectList list = new SelectList(db.Teams.ToList(), "TeamId", "Name");
            ViewBag.Teams = list;

            PrincipalSearchResult<Principal> groups = interaction.GetUserGroups();
            ViewBag.UserGroup = new SelectList(groups.ToList(),"Name","Name");

            return View(student);
        }
예제 #3
0
        public void CreateSingleUser(string userName, string password, int port, string name, int teamId, string userGroupName, bool disablepwchange, bool pwneverexpires)
        {
            UserPrincipal user = new UserPrincipal(context);
                GroupPrincipal group = GroupPrincipal.FindByIdentity(context, userGroupName);
                Repository rep = new Repository();
                UserManagement management = new UserManagement(user, group);
                string username = userName.Replace(" ", "");
                string description = "Bruger oprettet med UserHelper";
                string physicalPath = "C:\\inetpub\\wwwroot\\" + username + "\\";
                try
                {
                    //Create Windows User
                    management.CreateLocalWindowsAccount(username, password, username, description, disablepwchange, pwneverexpires, user);
                    management.AddUserToGroup(group, user);
                    //Create IIS Website
                    iis.CreateWebsite(username, "DefaultAppPool", "*:" + port + ":", physicalPath);

                    //Create FTP Virtual Directory
                    //txtStatusMessages.Text += iis.CreateFTPVDir("localhost", username, physicalPath, username);
                    iis.CreateVirtualDirectory("_FTP", username, physicalPath);

                    //Create database for user
                    sql.CreateSQLLoginUserAndDatabase(username, username, password);

                    Credentials cred = new Credentials();
                    cred.DatabaseUserName = username;
                    cred.DatabasePassword = password;
                    cred.FTPUserName = username;
                    cred.FTPPassword = password;
                    cred.WebsitePort = port;
                    cred.WindowsUserGroupName = group.Name;
                    Student student = new Student();
                    student.Name = name;
                    sql.InsertUserWithCredentialsOnTeam(student,cred,teamId);

                    BatchState.State = UserProcessState.INITIAL;
                    //done

                }
                catch (Exception)
                {
                    RollbackOnError(BatchState.State, username);
                    throw;
                }
        }
예제 #4
0
 public void InsertUserWithCredentialsOnTeam(Student student, Credentials cred, int teamId)
 {
     try
     {
         using (StudentsModel ctx = new StudentsModel())
         {
             student.Credentials = cred;
             student.TeamId = teamId;
             ctx.Students.Add(student);
             ctx.SaveChanges();
             BatchState.State = UserProcessState.SQL_INSERT_USER_DATA_OK;
         }
     }
     catch (Exception)
     {
         BatchState.State = UserProcessState.SQL_INSERT_USER_DATA_ERROR;
         throw;
     }
 }