public static int AddSharePointUser(SystemUser item)
        {
            // check account
            int accountCheck = SecurityContext.CheckAccount(DemandAccount.NotDemo | DemandAccount.IsActive);
            if (accountCheck < 0) return accountCheck;

            // check package
            int packageCheck = SecurityContext.CheckPackage(item.PackageId, DemandPackage.IsActive);
            if (packageCheck < 0) return packageCheck;

            // check quota
            QuotaValueInfo quota = PackageController.GetPackageQuota(item.PackageId, Quotas.SHAREPOINT_USERS);
            if (quota.QuotaExhausted)
                return BusinessErrorCodes.ERROR_SHAREPOINT_USERS_RESOURCE_QUOTA_LIMIT;

            // check if mail resource is available
            int serviceId = PackageController.GetPackageServiceId(item.PackageId, ResourceGroups.SharePoint);
            if (serviceId == 0)
                return BusinessErrorCodes.ERROR_SHAREPOINT_RESOURCE_UNAVAILABLE;

            // check package items
            if (PackageController.GetPackageItemByName(item.PackageId, ResourceGroups.SharePoint, item.Name, typeof(SystemUser)) != null)
                return BusinessErrorCodes.ERROR_SHAREPOINT_USERS_PACKAGE_ITEM_EXISTS;

            // place log record
            TaskManager.StartTask("SHAREPOINT", "ADD_USER", item.Name);

            try
            {
                // check service items
                SharePointServer sps = GetSharePoint(serviceId);
                if (sps.UserExists(item.Name))
                    return BusinessErrorCodes.ERROR_SHAREPOINT_USERS_SERVICE_ITEM_EXISTS;

                // create service item
                item.FullName = item.Name;
                item.Description = "WebsitePanel System Account";
                item.AccountDisabled = false;
                item.PasswordCantChange = true;
                item.PasswordNeverExpires = true;

                // add service item
                sps.CreateUser(item);

                // save item
                item.Password = CryptoUtils.Encrypt(item.Password);
                item.ServiceId = serviceId;
                int itemId = PackageController.AddPackageItem(item);

                TaskManager.ItemId = itemId;

                return itemId;
            }
            catch (Exception ex)
            {
                throw TaskManager.WriteError(ex);
            }
            finally
            {
                TaskManager.CompleteTask();
            }
        }
Ejemplo n.º 2
0
        public virtual bool InstallFrontPage(string siteId, string username, string password)
        {
            if (SecurityUtils.UserExists(username, ServerSettings, UsersOU))
                return false;

            // create user account
            SystemUser user = new SystemUser();
            user.Name = username;
            user.FullName = username;
            user.Description = "WebsitePanel System Account";
            user.Password = password;
            user.PasswordCantChange = true;
            user.PasswordNeverExpires = true;
            user.AccountDisabled = false;
            user.System = true;

            // create in the system
            SecurityUtils.CreateUser(user, ServerSettings, UsersOU, GroupsOU);

            string cmdPath = null;
            string cmdArgs = null;

            // try to install FPSE2002 first
            if (IsFrontPage2002Installed())
            {
                // add registry key for anonymous group if not exists
                RegistryKey portsKey = Registry.LocalMachine.OpenSubKey(FRONTPAGE_ALLPORTS_REGLOC, true) ??
                                       Registry.LocalMachine.OpenSubKey(FRONTPAGE_ALLPORTS_REGLOC_X64, true);

                if (portsKey != null) portsKey.SetValue("anonusergroupprefix", "anonfp");

                // create anonymous group
                string groupName = "anonfp_" + siteId.Substring(siteId.IndexOf("/") + 1);

                int numberOfatempts = 0;

                while (!SecurityUtils.GroupExists(groupName, ServerSettings, GroupsOU) && numberOfatempts < 5)
                {
                    SystemGroup fpseGroup = new SystemGroup();
                    fpseGroup.Name = groupName;
                    fpseGroup.Description = "Anonymous FPSE group for " + siteId + " web site";
                    fpseGroup.Members = new string[] { username };
                    SecurityUtils.CreateGroup(fpseGroup, ServerSettings, UsersOU, GroupsOU);
                    numberOfatempts++;
                }

                // install FPSE 2002
                RegistryKey fpKey = Registry.LocalMachine.OpenSubKey(FRONTPAGE_2002_REGLOC) ??
                                    Registry.LocalMachine.OpenSubKey(FRONTPAGE_2002_REGLOC_X64);

                if (fpKey != null)
                {
                    string location = (string)fpKey.GetValue("Location");
                    cmdPath = location + @"\bin\owsadm.exe";
                }
                cmdArgs = String.Format("-o install -p /LM/{0} -type msiis -u {1}",
                    siteId, username);
            }
            else if (IsFrontPage2000Installed())
            {
                // install FPSE 2000
                RegistryKey fpKey = Registry.LocalMachine.OpenSubKey(FRONTPAGE_2000_REGLOC) ??
                                   Registry.LocalMachine.OpenSubKey(FRONTPAGE_2000_REGLOC_X64);

                if (fpKey != null)
                {
                    string location = (string)fpKey.GetValue("Location");
                    cmdPath = location + @"\bin\fpsrvadm.exe";
                }
                cmdArgs = String.Format("-o install -p /LM/{0} -type msiis -u {1}",
                    siteId, username);
            }

            if (cmdPath != null)
            {
                // launch system process
                string result = FileUtils.ExecuteSystemCommand(cmdPath, cmdArgs);
            }

            // update web site
            WebSite site = GetSite(siteId);
            if (site != null)
            {
                site.EnableWindowsAuthentication = true;
                UpdateSite(site);
            }

            return true;
        }
Ejemplo n.º 3
0
 public void UpdateUser(SystemUser user)
 {
     this.Invoke("UpdateUser", new object[] {
                 user});
 }
Ejemplo n.º 4
0
 /// <remarks/>
 public void UpdateUserAsync(SystemUser user)
 {
     this.UpdateUserAsync(user, null);
 }
Ejemplo n.º 5
0
        public static SystemUser GetUser(string username, RemoteServerSettings serverSettings, string usersOU)
        {
            try
            {
                if (serverSettings.ADEnabled)
                {
                    // get user entry
                    //DirectoryEntry objUser = FindUserObject(username, serverSettings, usersOU);
					DirectoryEntry objUser = GetUserObject(username, serverSettings, usersOU);
                    if (objUser == null)
                        return null;

                    // fill user
                    SystemUser user = new SystemUser();
                    user.Name = GetObjectProperty(objUser, "cn").ToString();
                    user.FullName = GetObjectProperty(objUser, "givenName").ToString() + " " +
                        GetObjectProperty(objUser, "sn").ToString();
                    user.Description = GetObjectProperty(objUser, "description").ToString();

                    ADAccountOptions userFlags = (ADAccountOptions)objUser.Properties["userAccountControl"].Value;
                    user.PasswordCantChange = ((userFlags & ADAccountOptions.UF_PASSWD_CANT_CHANGE) != 0);
                    user.PasswordNeverExpires = ((userFlags & ADAccountOptions.UF_DONT_EXPIRE_PASSWD) != 0);
                    user.AccountDisabled = ((userFlags & ADAccountOptions.UF_ACCOUNTDISABLE) != 0);

                    // get user groups
                    user.MemberOf = GetUserGroups(objUser);

                    return user;
                }
                else
                {
                    // LOCAL mode
                    SystemUser userInfo = null;
                    DirectoryEntry computer = new DirectoryEntry(
                        String.Format("WinNT://{0}", Environment.MachineName));

                    // get user entry
                    DirectoryEntry user = null;

                    try
                    {
                        user = computer.Children.Find(username, "user");
                    }
                    catch
                    {
                        return userInfo; // user doesn't exist
                    }

                    if (user == null)
                        return userInfo; // user doesn't exist

                    // get user properties
                    userInfo = new SystemUser();

                    userInfo.Name = username;
                    userInfo.FullName = (string)user.Properties["FullName"].Value;
                    userInfo.Description = (string)user.Properties["Description"].Value;

                    ADAccountOptions userFlags = (ADAccountOptions)user.Properties["UserFlags"].Value;
                    userInfo.PasswordCantChange = ((userFlags & ADAccountOptions.UF_PASSWD_CANT_CHANGE) != 0);
                    userInfo.PasswordNeverExpires = ((userFlags & ADAccountOptions.UF_DONT_EXPIRE_PASSWD) != 0);
                    userInfo.AccountDisabled = ((userFlags & ADAccountOptions.UF_ACCOUNTDISABLE) != 0);

                    // get user groups
                    List<string> userGroups = new List<string>();
                    object groups = user.Invoke("Groups", null);
                    foreach (object nGroup in (IEnumerable)groups)
                    {
                        DirectoryEntry objGroup = new DirectoryEntry(nGroup);
                        userGroups.Add(objGroup.Name);
                    }

                    userInfo.MemberOf = userGroups.ToArray();

                    return userInfo;
                }
            }
            catch (Exception ex)
            {
                throw new Exception("Could not get system user properties", ex);
            }
        }
Ejemplo n.º 6
0
        public static void UpdateUser(SystemUser user, RemoteServerSettings serverSettings, string usersOU, string groupsOU)
        {
            try
            {
                if (serverSettings.ADEnabled)
                {
                    // AD mode
                    // get user entry
                    //DirectoryEntry objUser = FindUserObject(user.Name, serverSettings, usersOU);
					DirectoryEntry objUser = GetUserObject(user.Name, serverSettings, usersOU);
                    if (objUser == null)
                        return;

                    // get original user groups
                    string[] origGroups = GetUserGroups(objUser);

                    // remove user from original groups
                    foreach (string origGroupName in origGroups)
                        RemoveUserFromGroup(objUser, origGroupName, serverSettings, groupsOU);
               
                    // change properties
                    int spaceIdx = user.FullName.IndexOf(' ');
                    if (spaceIdx == -1)
                    {
                        objUser.Properties["givenName"].Value = user.FullName;
                        objUser.Properties["sn"].Value = user.FullName;
                    }
                    else
                    {
                        objUser.Properties["givenName"].Value = user.FullName.Substring(0, spaceIdx);
                        objUser.Properties["sn"].Value = user.FullName.Substring(spaceIdx + 1);
                    }
					
					objUser.Properties["description"].Value = String.IsNullOrEmpty(user.Description) ? "WebsitePanel System Account" : user.Description;

                    ADAccountOptions userFlags = ADAccountOptions.UF_NORMAL_ACCOUNT;

                    if (user.PasswordCantChange)
                        userFlags |= ADAccountOptions.UF_PASSWD_CANT_CHANGE;

                    if (user.PasswordNeverExpires)
                        userFlags |= ADAccountOptions.UF_DONT_EXPIRE_PASSWD;

                    if (user.AccountDisabled)
                        userFlags |= ADAccountOptions.UF_ACCOUNTDISABLE;

                    objUser.Properties["userAccountControl"].Value = userFlags;
                    
                    objUser.CommitChanges();

                    // add user to groups
                    foreach (string groupName in user.MemberOf)
                        AddUserToGroup(objUser, groupName, serverSettings, groupsOU);

                    // set password if required
                    if (!String.IsNullOrEmpty(user.Password))
                        objUser.Invoke("SetPassword", new object[] { user.Password });

                    objUser.Close();
                }
                else
                {
                    // LOCAL mode
                    // get user entry
                    DirectoryEntry computer = new DirectoryEntry(
                        String.Format("WinNT://{0}", Environment.MachineName));

                    // get group entry
                    DirectoryEntry objUser = computer.Children.Find(user.Name, "user");

                    // change user properties
                    objUser.Properties["FullName"].Add(user.FullName);
                    objUser.Properties["Description"].Add(user.Description);
                    objUser.Properties["UserFlags"].Add(BuildUserFlags(
                        user.PasswordCantChange,
                        user.PasswordNeverExpires,
                        user.AccountDisabled));

                    // save account
                    objUser.CommitChanges();

                    // remove user from all assigned groups
                    object groups = objUser.Invoke("Groups", null);
                    foreach (object nGroup in (IEnumerable)groups)
                    {
                        DirectoryEntry objGroup = new DirectoryEntry(nGroup);
                        objGroup.Invoke("Remove", new object[] { objUser.Path });
                    }

                    // add user to groups
                    foreach (String groupName in user.MemberOf)
                    {
                        DirectoryEntry group = computer.Children.Find(groupName, "group");
                        if (group != null)
                            group.Invoke("Add", new object[] { objUser.Path.ToString() });
                        group.CommitChanges();

                    }

                    // change password if required
                    if (!String.IsNullOrEmpty(user.Password))
                        objUser.Invoke("SetPassword", new object[] { user.Password });
                }
            }
            catch (Exception ex)
            {
                throw new Exception("Could not update system user", ex);
            }
        }
 public int UpdateSharePointUser(SystemUser item)
 {
     object[] results = this.Invoke("UpdateSharePointUser", new object[] {
                 item});
     return ((int)(results[0]));
 }
Ejemplo n.º 8
0
        public override bool InstallFrontPage(string siteId, string username, string password)
        {
			// Ensure requested user account doesn't exist
			if (SecurityUtils.UserExists(username, ServerSettings, UsersOU))
				return false;
			// Ensure a web site exists
			if (!SiteExists(siteId))
				return false;
			// create user account
			SystemUser user = new SystemUser
			{
				Name = username,
				FullName = username,
				Description = "WebsitePanel System Account",
				Password = password,
				PasswordCantChange = true,
				PasswordNeverExpires = true,
				AccountDisabled = false,
				System = true,
			};

			// create in the system
			SecurityUtils.CreateUser(user, ServerSettings, UsersOU, GroupsOU);

			try
			{
				string cmdPath = null;
				string cmdArgs = null;
				//
				string m_webSiteId = webObjectsSvc.GetWebSiteIdFromIIS(siteId, null);

				// try to install FPSE2002
				// add registry key for anonymous group if not exists
				RegistryKey portsKey = Registry.LocalMachine.OpenSubKey(FRONTPAGE_ALLPORTS_REGLOC, true);
				portsKey.SetValue("anonusergroupprefix", "anonfp");

				#region Create anonymous group to get FPSE work

				string groupName = "anonfp_" + m_webSiteId;
				if (!SecurityUtils.GroupExists(groupName, ServerSettings, GroupsOU))
				{
					SystemGroup fpseGroup = new SystemGroup();
					fpseGroup.Name = groupName;
					fpseGroup.Description = "Anonymous FPSE group for " + siteId + " web site";
					fpseGroup.Members = new string[] { username };
					SecurityUtils.CreateGroup(fpseGroup, ServerSettings, UsersOU, GroupsOU);
				}

				#endregion

				#region Install FPSE 2002 to the website by owsadm.exe install command

				cmdPath = Environment.ExpandEnvironmentVariables(FPSE2002_OWSADM_PATH);
				cmdArgs = String.Format("-o install -p /LM/W3SVC/{0} -u {1}", m_webSiteId, username);
				Log.WriteInfo("Command path: " + cmdPath);
				Log.WriteInfo("Command path: " + cmdArgs);
				Log.WriteInfo("FPSE2002 Install Log: " + FileUtils.ExecuteSystemCommand(cmdPath, cmdArgs));
				
				#endregion

				#region Enable Windows Authentication mode
				
				winAuthSvc.SetEnabled(siteId, true);

				#endregion
			}
			catch (Exception ex)
			{
				Log.WriteError(ex);
				// Signal to the client installation request has been failed.
				return false;
			}

			return true;
        }
 /// <remarks/>
 public void AddSharePointUserAsync(SystemUser item)
 {
     this.AddSharePointUserAsync(item, null);
 }
Ejemplo n.º 10
0
 /// <remarks/>
 public void AddSharePointUserAsync(SystemUser item, object userState)
 {
     if ((this.AddSharePointUserOperationCompleted == null))
     {
         this.AddSharePointUserOperationCompleted = new System.Threading.SendOrPostCallback(this.OnAddSharePointUserOperationCompleted);
     }
     this.InvokeAsync("AddSharePointUser", new object[] {
                 item}, this.AddSharePointUserOperationCompleted, userState);
 }
 public void UpdateUser(SystemUser user)
 {
     try
     {
         Log.WriteStart("'{0}' UpdateUser", ProviderSettings.ProviderName);
         SPS.UpdateUser(user);
         Log.WriteEnd("'{0}' UpdateUser", ProviderSettings.ProviderName);
     }
     catch (Exception ex)
     {
         Log.WriteError(String.Format("'{0}' UpdateUser", ProviderSettings.ProviderName), ex);
         throw;
     }
 }
Ejemplo n.º 12
0
	    public virtual void CreateAccount(FtpAccount account)
	    {
		    // create user account
		    SystemUser user = new SystemUser();
		    user.Name = account.Name;
		    user.FullName = account.Name;
            if (user.FullName.Length > 20)
            {
				Exception ex = new Exception("WEBSITEPANEL_ERROR@FTP_USERNAME_MAX_LENGTH_EXCEEDED@");
                throw ex;
            }
		    user.Description = "WebsitePanel System Account";
		    user.MemberOf = new string[] { FtpGroupName };
		    user.Password = account.Password;
		    user.PasswordCantChange = true;
		    user.PasswordNeverExpires = true;
		    user.AccountDisabled = !account.Enabled;
		    user.System = true;

		    // create in the system
		    SecurityUtils.CreateUser(user, ServerSettings, UsersOU, GroupsOU);

		    // prepare home folder
		    EnsureUserHomeFolderExists(account.Folder, account.Name, account.CanRead, account.CanWrite);

		    // create account in FTP
		    ManagementObject objDir = wmi.GetClass("IIsFtpVirtualDir").CreateInstance();
		    ManagementObject objDirSetting = wmi.GetClass("IIsFtpVirtualDirSetting").CreateInstance();

		    string accId = GetAccountPath(SiteId, account.Name);

		    objDir.Properties["Name"].Value = accId;

		    objDirSetting.Properties["Name"].Value = accId;
		    objDirSetting.Properties["Path"].Value = account.Folder;
		    objDirSetting.Properties["AccessRead"].Value = account.CanRead;
		    objDirSetting.Properties["AccessWrite"].Value = account.CanWrite;
		    objDirSetting.Properties["AccessScript"].Value = false;
		    objDirSetting.Properties["AccessSource"].Value = false;
		    objDirSetting.Properties["AccessExecute"].Value = false;
			// UNC Path (Connect As)
			FillWmiObjectUNCFromFtpAccount(objDirSetting, account);

		    // save account
		    objDir.Put();
		    objDirSetting.Put();
	    }
        public static int UpdateSharePointUser(SystemUser item)
        {
            // check account
            int accountCheck = SecurityContext.CheckAccount(DemandAccount.NotDemo | DemandAccount.IsActive);
            if (accountCheck < 0) return accountCheck;

            // load original meta item
            SystemUser origItem = (SystemUser)PackageController.GetPackageItem(item.Id);
            if (origItem == null)
                return BusinessErrorCodes.ERROR_SHAREPOINT_USERS_PACKAGE_ITEM_NOT_FOUND;

            // check package
            int packageCheck = SecurityContext.CheckPackage(origItem.PackageId, DemandPackage.IsActive);
            if (packageCheck < 0) return packageCheck;

            // place log record
            TaskManager.StartTask("SHAREPOINT", "UPDATE_USER", origItem.Name, item.Id);

            try
            {
                // get service
                SharePointServer sps = GetSharePoint(origItem.ServiceId);

                item.Name = origItem.Name;
                item.FullName = origItem.Name;
                item.Description = "WebsitePanel System Account";
                item.AccountDisabled = false;
                item.PasswordCantChange = true;
                item.PasswordNeverExpires = true;

                // update service item
                sps.UpdateUser(item);

                // update meta item
                if (item.Password != "")
                {
                    item.Password = CryptoUtils.Encrypt(item.Password);
                    PackageController.UpdatePackageItem(item);
                }

                return 0;
            }
            catch (Exception ex)
            {
                throw TaskManager.WriteError(ex);
            }
            finally
            {
                TaskManager.CompleteTask();
            }
        }
Ejemplo n.º 14
0
        public virtual string CreateSite(WebSite site)
        {
            // anonymous user groups
            List<string> webGroups = new List<string>();
            webGroups.Add(WebGroupName);

            // create web site anonymous account
            SystemUser user = new SystemUser();
            user.Name = site.AnonymousUsername;
            user.FullName = site.AnonymousUsername;
            user.Description = "WebsitePanel System Account";
            user.MemberOf = webGroups.ToArray();
            user.Password = site.AnonymousUserPassword;
            user.PasswordCantChange = true;
            user.PasswordNeverExpires = true;
            user.AccountDisabled = false;
            user.System = true;

            // create in the system
            try
            {
                SecurityUtils.CreateUser(user, ServerSettings, UsersOU, GroupsOU);
            }
            catch (Exception ex)
            {
                // the possible reason the account already exists
                // check this
                if (SecurityUtils.UserExists(user.Name, ServerSettings, UsersOU))
                {
                    // yes
                    // try to give it original name
                    for (int i = 2; i < 99; i++)
                    {
                        string username = user.Name + i.ToString();
                        if (!SecurityUtils.UserExists(username, ServerSettings, UsersOU))
                        {
                            user.Name = username;
                            site.AnonymousUsername = username;

                            // try to create again
                            SecurityUtils.CreateUser(user, ServerSettings, UsersOU, GroupsOU);
                            break;
                        }
                    }
                }
                else
                {
                    throw ex;
                }
            }

			// Grant IIS_WPG group membership to site's anonymous account
			SecurityUtils.GrantLocalGroupMembership(site.AnonymousUsername, IIS_WPG_GROUP, ServerSettings);

			// Build names for dedicated pools
			string poolName1 = site.Name + DEDICATED_POOL_SUFFIX_ASPNET1;
			string poolName2 = site.Name + DEDICATED_POOL_SUFFIX_ASPNET2;
			string poolName4 = site.Name + DEDICATED_POOL_SUFFIX_ASPNET4;

			//
			bool dedicatedPool = site.DedicatedApplicationPool;

			// Check if we need to create a separate application pool
            if (dedicatedPool)
            {
                // Create dedicated pools
                CreateApplicationPool(poolName1, site.AnonymousUsername, site.AnonymousUserPassword);
                CreateApplicationPool(poolName2, site.AnonymousUsername, site.AnonymousUserPassword);
				CreateApplicationPool(poolName4, site.AnonymousUsername, site.AnonymousUserPassword);
            }

			// Assign application pool
			switch (site.AspNetInstalled)
			{
				case ASPNET_11:
					site.ApplicationPool = (dedicatedPool) ? poolName1 : Asp11Pool;
					break;
				case ASPNET_20:
					site.ApplicationPool = (dedicatedPool) ? poolName2 : Asp20Pool;
					break;
				case ASPNET_40:
					site.ApplicationPool = (dedicatedPool) ? poolName4 : Asp40Pool;
					break;
				default:
					break;
			}
            
            // set folder permissions
            SetWebFolderPermissions(site.ContentPath, site.AnonymousUsername,
                site.EnableWritePermissions, site.DedicatedApplicationPool);

            // set DATA folder permissions
            SetWebFolderPermissions(site.DataPath, site.AnonymousUsername,
                true, site.DedicatedApplicationPool);

            // create logs folder if not exists
            if (!FileUtils.DirectoryExists(site.LogsPath))
                FileUtils.CreateDirectory(site.LogsPath);

            //SecurityUtils.GrantNtfsPermissionsBySid(site.LogFileDirectory,
            //    SystemSID.NETWORK_SERVICE, NTFSPermission.Modify, true, true);

            // create Web site
            ManagementObject objService = wmi.GetObject(String.Format("IIsWebService='{0}'", IIS_SERVICE_ID));

            ManagementBaseObject methodParams = objService.GetMethodParameters("CreateNewSite");

            // create server bindings
            ManagementClass clsBinding = wmi.GetClass("ServerBinding");
            ManagementObject[] objBinings = new ManagementObject[site.Bindings.Length];

            for (int i = 0; i < objBinings.Length; i++)
            {
                objBinings[i] = clsBinding.CreateInstance();
                objBinings[i]["Hostname"] = site.Bindings[i].Host;
                objBinings[i]["IP"] = site.Bindings[i].IP;
                objBinings[i]["Port"] = site.Bindings[i].Port;
            }

            methodParams["ServerBindings"] = objBinings;
            methodParams["ServerComment"] = site.Name;
            methodParams["PathOfRootVirtualDir"] = site.ContentPath;

            ManagementBaseObject objResult = objService.InvokeMethod("CreateNewSite", methodParams, new InvokeMethodOptions());

            // get WEB settings
            string siteId = ((string)objResult["returnValue"]).Remove(0, "IIsWebServer='".Length).Replace("'", "");

            // update site properties
            ManagementObject objSite = wmi.GetObject(String.Format("IIsWebServerSetting='{0}'", siteId));
            ManagementObject objVirtDir = wmi.GetObject(
                String.Format("IIsWebVirtualDirSetting='{0}'", GetVirtualDirectoryPath(siteId, "")));

            if (site.LogsPath != null && site.LogsPath != "")
                objSite.Properties["LogFileDirectory"].Value = site.LogsPath;

            FillWmiObjectFromVirtualDirectory(objSite, site, false);
            objSite.Put();

            FillWmiObjectFromVirtualDirectory(objVirtDir, site, false);
            FillWmiObjectFromVirtualDirectoryRest(objVirtDir, site);
			// UNC Share
			ManagementObject objVirtDirUnc = wmi.GetObject(
				String.Format("IIsWebVirtualDir='{0}'", GetVirtualDirectoryPath(siteId, "")));
			FillWmiObjectUNCSettingsFromVirtualDirectory(objVirtDir, site);
			objVirtDirUnc.Put();

            objVirtDir.Put();

            // CGI-BIN folder
            UpdateCgiBinFolder(siteId, site.ContentPath, site.CgiBinInstalled);

            // start web site
            try
            {
                ChangeSiteState(siteId, ServerState.Started);
            }
            catch
            {
                // just skip an error
            }

            return siteId;
        }
Ejemplo n.º 15
0
 /// <remarks/>
 public System.IAsyncResult BeginUpdateSharePointUser(SystemUser item, System.AsyncCallback callback, object asyncState)
 {
     return this.BeginInvoke("UpdateSharePointUser", new object[] {
                 item}, callback, asyncState);
 }
Ejemplo n.º 16
0
 public virtual void UpdateUser(SystemUser user)
 {
     SecurityUtils.UpdateUser(user, ServerSettings, UsersOU, GroupsOU);
 }
Ejemplo n.º 17
0
 /// <remarks/>
 public void UpdateSharePointUserAsync(SystemUser item)
 {
     this.UpdateSharePointUserAsync(item, null);
 }
Ejemplo n.º 18
0
		private void CreateWebSiteAnonymousAccount(WebSite site)
		{
			// anonymous user groups
			List<string> webGroups = new List<string>();
			webGroups.Add(WebGroupName);

			// create web site anonymous account
			SystemUser user = new SystemUser();
			user.Name = GetNonQualifiedAccountName(site.AnonymousUsername);
			user.FullName = GetNonQualifiedAccountName(site.AnonymousUsername);

			// Fix. Import web site that runs under NETWORK_SERVICE identity fails.
			// WebsitePanel cannot create anonymous account.
			/*if (!user.Name.Contains(site.Name.Replace(".", "")))
			{
				user.Name = user.FullName = site.Name.Replace(".", "") + "_web";
			}*/

			//check is user name less than 20 symbols (Windows name length restriction)
			if (user.Name.Length > 20)
			{
				int separatorPlace = user.Name.IndexOf("_");
				user.Name = user.Name.Remove(separatorPlace - (user.Name.Length - 20), user.Name.Length - 20);
			}

			site.AnonymousUsername = user.Name;

			user.Description = "WebsitePanel System Account";
			user.MemberOf = webGroups.ToArray();

			//set new password for created Anonymous Account
			if (String.IsNullOrEmpty(site.AnonymousUserPassword))
			{
				site.AnonymousUserPassword = Guid.NewGuid().ToString();
			}

			user.Password = site.AnonymousUserPassword;
			user.PasswordCantChange = true;
			user.PasswordNeverExpires = true;
			user.AccountDisabled = false;
			user.System = true;
			// create in the system
			try
			{
				SecurityUtils.CreateUser(user, ServerSettings, UsersOU, GroupsOU);
			}
			catch (Exception ex)
			{
				// the possible reason the account already exists
				// check this
				if (SecurityUtils.UserExists(user.Name, ServerSettings, UsersOU))
				{
					// yes
					// try to give it original name
					for (int i = 2; i < 99; i++)
					{
						string username = user.Name + i.ToString();
						if (!SecurityUtils.UserExists(username, ServerSettings, UsersOU))
						{
							user.Name = username;
							site.AnonymousUsername = username;

							// try to create again
							SecurityUtils.CreateUser(user, ServerSettings, UsersOU, GroupsOU);
							break;
						}
					}
				}
				else
				{
					throw ex;
				}
			}
		}
Ejemplo n.º 19
0
		/// <summary>
		/// Creates ftp account under root ftp site.
		/// </summary>
		/// <param name="account">Ftp account to create.</param>
        public void CreateAccount(FtpAccount account)
        {
			// Create user account.
			SystemUser user = new SystemUser();
			user.Name = account.Name;
			user.FullName = account.Name;
			user.Description = "WebsitePanel System Account";
			user.MemberOf = new string[] { FtpGroupName };
			user.Password = account.Password;
			user.PasswordCantChange = true;
			user.PasswordNeverExpires = true;
			user.AccountDisabled = !account.Enabled;
			user.System = true;

			// Create in the operating system.
			if (SecurityUtils.UserExists(user.Name, ServerSettings, UsersOU))
			{
				SecurityUtils.DeleteUser(user.Name, ServerSettings, UsersOU);
			}
			SecurityUtils.CreateUser(user, ServerSettings, UsersOU, GroupsOU);

			// Prepare account's home folder.
			this.EnsureUserHomeFolderExists(account.Folder, account.Name, account.CanRead, account.CanWrite);

			// Future account will be given virtual directory under default ftp web site.
			this.ftpSitesService.CreateFtpAccount(this.SiteId, account);
			//
			this.ftpSitesService.ConfigureConnectAs(account.Folder, this.SiteId, account.VirtualPath, 
				this.GetQualifiedAccountName(account.Name), account.Password, true);
		}
Ejemplo n.º 20
0
        public static void CreateUser(SystemUser user, RemoteServerSettings serverSettings, string usersOU, string groupsOU)
        {
            try
            {
                if (serverSettings.ADEnabled)
                {

                    //check is user name less than 20 symbols
                    if (user.Name.Length > 20)
                    {
                        int separatorPlace = user.Name.IndexOf("_");
                        user.Name = user.Name.Remove(separatorPlace - (user.Name.Length - 20), user.Name.Length - 20);

                    }

                    // AD mode
                    // root entry
                    DirectoryEntry objRoot = GetUsersRoot(serverSettings, usersOU);

                    // add user
                    DirectoryEntry objUser = objRoot.Children.Add("CN=" + user.Name, "user");

                    int spaceIdx = user.FullName.IndexOf(' ');
                    if (spaceIdx == -1)
                    {
                        SetObjectProperty(objUser, "givenName", user.FullName);
                        SetObjectProperty(objUser, "sn", user.FullName);
                    }
                    else
                    {
                        SetObjectProperty(objUser, "givenName", user.FullName.Substring(0, spaceIdx));
                        SetObjectProperty(objUser, "sn", user.FullName.Substring(spaceIdx + 1));
                    }
                    SetObjectProperty(objUser, "description", user.Description);
                    SetObjectProperty(objUser, "UserPrincipalName", user.Name);
                    SetObjectProperty(objUser, "sAMAccountName", user.Name);
                    SetObjectProperty(objUser, "UserPassword", user.Password);
                    objUser.Properties["userAccountControl"].Value =
                        ADAccountOptions.UF_NORMAL_ACCOUNT | ADAccountOptions.UF_PASSWD_NOTREQD;
                    objUser.CommitChanges();
                    //myDirectoryEntry = GetUser(UserName);

                    // set password
                    objUser.Invoke("SetPassword", new object[] { user.Password });

                    ADAccountOptions userFlags = ADAccountOptions.UF_NORMAL_ACCOUNT;

                    if (user.PasswordCantChange)
                        userFlags |= ADAccountOptions.UF_PASSWD_CANT_CHANGE;

                    if (user.PasswordNeverExpires)
                        userFlags |= ADAccountOptions.UF_DONT_EXPIRE_PASSWD;

                    if (user.AccountDisabled)
                        userFlags |= ADAccountOptions.UF_ACCOUNTDISABLE;

                    objUser.Properties["userAccountControl"].Value = userFlags;
                    objUser.CommitChanges();

                    // add user to groups
                    foreach (string groupName in user.MemberOf)
                        AddUserToGroup(objUser, groupName, serverSettings, groupsOU);

                    objUser.CommitChanges();
                    objUser.Close();
                }
                else
                {
                    // LOCAL mode
                    DirectoryEntry computer = new DirectoryEntry(
                        String.Format("WinNT://{0}", Environment.MachineName));

                    //check is user name less than 20 symbols
                    if (user.Name.Length > 20)
                    {
                        int separatorPlace = user.Name.IndexOf("_");
                        user.Name = user.Name.Remove(separatorPlace - (user.Name.Length - 20), user.Name.Length - 20);

                    }

                    // create user
                    DirectoryEntry objUser = computer.Children.Add(user.Name, "user");
                    objUser.Invoke("SetPassword", new object[] { user.Password });
                    objUser.Properties["FullName"].Add(user.FullName);
                    objUser.Properties["Description"].Add(user.Description);
                    objUser.Properties["UserFlags"].Add(BuildUserFlags(
                        user.PasswordCantChange,
                        user.PasswordNeverExpires,
                        user.AccountDisabled));

                    // save account
                    objUser.CommitChanges();

                    // add user to groups
                    foreach (String groupName in user.MemberOf)
                    {
                        DirectoryEntry group = computer.Children.Find(groupName, "group");
                        if (group != null)
                            group.Invoke("Add", new object[] { objUser.Path.ToString() });
                        group.CommitChanges();
                    }
                }
            }
            catch (Exception ex)
            {
                throw new Exception("Could not create system user", ex);
            }
        }
        private void SaveItem()
        {
            if (!Page.IsValid)
                return;

            // get form data
            SystemUser item = new SystemUser();
            item.Id = PanelRequest.ItemID;
            item.PackageId = PanelSecurity.PackageId;
            item.Name = usernameControl.Text;
            item.Password = passwordControl.Password;

            List<string> memberOf = new List<string>();
            foreach (ListItem li in dlGroups.Items)
            {
                if (li.Selected)
                    memberOf.Add(li.Value);
            }
            item.MemberOf = memberOf.ToArray();

            if (PanelRequest.ItemID == 0)
            {
                // new item
                try
                {
                    int result = ES.Services.SharePointServers.AddSharePointUser(item);
                    if (result < 0)
                    {
                        ShowResultMessage(result);
                        return;
                    }
                }
                catch (Exception ex)
                {
                    ShowErrorMessage("SHAREPOINT_ADD_USER", ex);
                    return;
                }
            }
            else
            {
                // existing item
                try
                {
                    int result = ES.Services.SharePointServers.UpdateSharePointUser(item);
                    if (result < 0)
                    {
                        ShowResultMessage(result);
                        return;
                    }
                }
                catch (Exception ex)
                {
                    ShowErrorMessage("SHAREPOINT_UPDATE_USER", ex);
                    return;
                }
            }

            // return
            RedirectSpaceHomePage();
        }
Ejemplo n.º 22
0
 /// <remarks/>
 public void CreateUserAsync(SystemUser user)
 {
     this.CreateUserAsync(user, null);
 }
 public int AddSharePointUser(SystemUser item)
 {
     return SharePointServerController.AddSharePointUser(item); ;
 }
Ejemplo n.º 24
0
 /// <remarks/>
 public System.IAsyncResult BeginUpdateUser(SystemUser user, System.AsyncCallback callback, object asyncState)
 {
     return this.BeginInvoke("UpdateUser", new object[] {
                 user}, callback, asyncState);
 }
 public int UpdateSharePointUser(SystemUser item)
 {
     return SharePointServerController.UpdateSharePointUser(item);
 }
Ejemplo n.º 26
0
 /// <remarks/>
 public void UpdateUserAsync(SystemUser user, object userState)
 {
     if ((this.UpdateUserOperationCompleted == null))
     {
         this.UpdateUserOperationCompleted = new System.Threading.SendOrPostCallback(this.OnUpdateUserOperationCompleted);
     }
     this.InvokeAsync("UpdateUser", new object[] {
                 user}, this.UpdateUserOperationCompleted, userState);
 }
        public void ImportItem(int packageId, int itemTypeId, Type itemType,
			ResourceGroupInfo group, string itemName)
        {
            // get service id
            int serviceId = PackageController.GetPackageServiceId(packageId, group.GroupName);
            if (serviceId == 0)
                return;

            if (itemType == typeof(SystemUser))
            {
                // import user
                SystemUser user = new SystemUser();
                user.ServiceId = serviceId;
                user.PackageId = packageId;
                user.Name = itemName;
                user.Password = "";
                user.GroupName = group.GroupName;
                PackageController.AddPackageItem(user);
            }
            else if (itemType == typeof(SystemGroup))
            {
                // import group
                SystemGroup spGroup = new SystemGroup();
                spGroup.ServiceId = serviceId;
                spGroup.PackageId = packageId;
                spGroup.Name = itemName;
                spGroup.GroupName = group.GroupName;
                PackageController.AddPackageItem(spGroup);
            }
        }