Exemple #1
0
		public virtual void CreateAccount(FtpAccount account)
		{
            Log.WriteInfo("GetFileZillaConfig");
			XmlDocument doc = GetFileZillaConfig();


            Log.WriteInfo("Find users nodes");
			// find users node
			XmlNode nodeUsers = doc.SelectSingleNode("/FileZillaServer/Users");
            
            XmlElement nodeUser = doc.CreateElement("User");
		    if (nodeUsers != null) nodeUsers.AppendChild(nodeUser);

		    // set properties
			nodeUser.SetAttribute("Name", account.Name);
			SetOption(nodeUser, "Pass", MD5(account.Password));
			SetOption(nodeUser, "Group", "");
			SetOption(nodeUser, "Bypass server userlimit", "0");
			SetOption(nodeUser, "User Limit", "0");
			SetOption(nodeUser, "IP Limit", "0");
			SetOption(nodeUser, "Enabled", BoolToString(account.Enabled));
			SetOption(nodeUser, "Comments", "");
			SetOption(nodeUser, "ForceSsl", "0");

			// IP filter
			XmlElement nodeIPFilter = doc.CreateElement("IpFilter");
			nodeUser.AppendChild(nodeIPFilter);

			XmlElement nodeDisallowed = doc.CreateElement("Disallowed");
			nodeIPFilter.AppendChild(nodeDisallowed);

			XmlElement nodeAllowed = doc.CreateElement("Allowed");
			nodeIPFilter.AppendChild(nodeAllowed);

			// folder
			XmlElement nodePermissions = doc.CreateElement("Permissions");
			nodeUser.AppendChild(nodePermissions);

			XmlElement nodePermission = doc.CreateElement("Permission");
			nodePermissions.AppendChild(nodePermission);

			// folder settings
			nodePermission.SetAttribute("Dir", account.Folder);
			SetOption(nodePermission, "FileRead", BoolToString(account.CanRead));
			SetOption(nodePermission, "FileWrite", BoolToString(account.CanWrite));
			SetOption(nodePermission, "FileDelete", BoolToString(account.CanWrite));
			SetOption(nodePermission, "DirCreate", BoolToString(account.CanWrite));
			SetOption(nodePermission, "DirDelete", BoolToString(account.CanWrite));
			SetOption(nodePermission, "DirList", BoolToString(account.CanRead));
			SetOption(nodePermission, "DirSubdirs", BoolToString(account.CanRead));
			SetOption(nodePermission, "IsHome", "1");
			SetOption(nodePermission, "AutoCreate", "0");

			// speed limits
			XmlElement nodeSpeedLimits = doc.CreateElement("SpeedLimits");
			nodeUser.AppendChild(nodeSpeedLimits);
			nodeSpeedLimits.SetAttribute("DlType", "0");
			nodeSpeedLimits.SetAttribute("DlLimit", "10");
			nodeSpeedLimits.SetAttribute("ServerDlLimitBypass", "0");
			nodeSpeedLimits.SetAttribute("UlType", "0");
			nodeSpeedLimits.SetAttribute("UlLimit", "10");
			nodeSpeedLimits.SetAttribute("ServerUlLimitBypass", "0");

			XmlElement nodeDownload = doc.CreateElement("Download");
			nodeSpeedLimits.AppendChild(nodeDownload);

			XmlElement nodeUpload = doc.CreateElement("Upload");
			nodeSpeedLimits.AppendChild(nodeUpload);

			// save document
			doc.Save(GetFileZillaConfigPath());

			// reload config
			ReloadFileZillaConfig();
		}
Exemple #2
0
		private FtpAccount CreateAccountFromXmlNode(XmlNode nodeUser, bool excludeDetails)
		{
			FtpAccount account = new FtpAccount();
			account.Name = nodeUser.Attributes["Name"].Value;

			if (!excludeDetails)
			{
				account.Password = nodeUser.SelectSingleNode("Option[@Name='Pass']").InnerText;
				account.Enabled = (nodeUser.SelectSingleNode("Option[@Name='Enabled']").InnerText == "1");
				XmlNode nodeFolder = nodeUser.SelectSingleNode("Permissions/Permission");
				if (nodeFolder != null)
				{
					account.Folder = nodeFolder.Attributes["Dir"].Value;
					account.CanRead = (nodeFolder.SelectSingleNode("Option[@Name='FileRead']").InnerText == "1");
					account.CanWrite = (nodeFolder.SelectSingleNode("Option[@Name='FileWrite']").InnerText == "1");
				}
			}

			return account;
		}
Exemple #3
0
        public virtual FtpAccount GetAccount(string accountName)
        {
                string accountPath = GetUserSettingsPath(SiteId, accountName);
                if (!File.Exists(accountPath))
                    return null;

                // load account settings
                NameValueCollection dict = ReadSettingsFile(accountPath);
                if (dict == null)
                    return null;

                FtpAccount account = new FtpAccount();
                account.Name = accountName;

                // acccess rights
                string acr = dict["AccessList0"];
                if (acr != null)
                {
                    string[] acrParts = acr.Split(',');
                    account.Folder = acrParts[1];
                    account.CanRead = (acrParts[2][0] == 'R' && acrParts[3][0] == 'F');
                    account.CanWrite = (acrParts[2][1] == 'W');
                }
                account.Enabled = (dict["Enabled"] == "-1");
                return account;
        }
Exemple #4
0
        public virtual void UpdateAccount(FtpAccount account)
        {
            // load account settings
            NameValueCollection dict = ReadSettingsFile(GetUserSettingsPath(SiteId, account.Name));
            if (dict == null)
                return;

            // update account properties
            dict["AccessList0"] = BildAccountAccessList(account);

            // change password if required
            if (!String.IsNullOrEmpty(account.Password))
                dict["Password"] = "******" + MD5(account.Password);

            dict["Enabled"] = account.Enabled ? "-1" : "0";

            // save account settings
            SaveSettingsFile(GetUserSettingsPath(SiteId, account.Name), "Account", dict);

            // fluch cache
            FlushCache();
        }
 /// <remarks/>
 public System.IAsyncResult BeginUpdateFtpAccount(FtpAccount item, System.AsyncCallback callback, object asyncState) {
     return this.BeginInvoke("UpdateFtpAccount", new object[] {
                 item}, callback, asyncState);
 }
 /// <remarks/>
 public void UpdateFtpAccountAsync(FtpAccount item, object userState) {
     if ((this.UpdateFtpAccountOperationCompleted == null)) {
         this.UpdateFtpAccountOperationCompleted = new System.Threading.SendOrPostCallback(this.OnUpdateFtpAccountOperationCompleted);
     }
     this.InvokeAsync("UpdateFtpAccount", new object[] {
                 item}, this.UpdateFtpAccountOperationCompleted, userState);
 }
Exemple #7
0
    	/// <summary>
		/// Fills ftp account from iis configuration.
		/// </summary>
		/// <param name="ftpAccount">Ftp account to fill.</param>
		private void FillFtpAccountFromIis(FtpAccount ftpAccount)
		{
            //
			ftpAccount.Folder = this.ftpSitesService.GetSitePhysicalPath(this.SiteId, String.Format("/{0}", ftpAccount.Name));

			AuthorizationRuleCollection authRulesCollection = this.ftpSitesService.GetAuthorizationRuleCollection(String.Format("{0}/{1}", this.SiteId, ftpAccount.Name));
			ftpAccount.CanRead = false;
			ftpAccount.CanWrite = false;
			foreach(AuthorizationRule rule in authRulesCollection)
			{
				if (rule.AccessType == AuthorizationRuleAccessType.Allow)
				{
					foreach(string userName in rule.Users.Split(','))
					{
						if (String.Compare(userName, ftpAccount.Name, true) == 0)
						{
							ftpAccount.CanWrite = (rule.Permissions & PermissionsFlags.Write) == PermissionsFlags.Write;
							ftpAccount.CanRead = (rule.Permissions & PermissionsFlags.Read) == PermissionsFlags.Read;
						}
					}
				}
			}

			// Load user account.
			SystemUser user = SecurityUtils.GetUser(ftpAccount.Name, ServerSettings, UsersOU);
			if (user != null)
			{
				ftpAccount.Enabled = !user.AccountDisabled;
			}
		}
 /// <remarks/>
 public void CreateAccountAsync(FtpAccount account)
 {
     this.CreateAccountAsync(account, null);
 }
Exemple #9
0
		/// <summary>
		/// Updates ftp account.
		/// </summary>
		/// <param name="account">Accoun to update.</param>
        public void UpdateAccount(FtpAccount account)
        {
			// Change user account state and password (if required).
			SystemUser user = SecurityUtils.GetUser(account.Name, ServerSettings, UsersOU);
			user.Password = account.Password;
			user.AccountDisabled = !account.Enabled;
			SecurityUtils.UpdateUser(user, ServerSettings, UsersOU, GroupsOU);
			// Update iis configuration.
			this.FillIisFromFtpAccount(account);
        }
Exemple #10
0
		/// <summary>
		/// Fills iis configuration  from ftp account.
		/// </summary>
		/// <param name="ftpAccount">Ftp account to fill from.</param>
		private void FillIisFromFtpAccount(FtpAccount ftpAccount)
		{
			// Remove permissions if required.
			string currentPhysicalPath = this.ftpSitesService.GetSitePhysicalPath(this.SiteId, String.Format("/{0}", ftpAccount.Name));
			if (String.Compare(currentPhysicalPath, ftpAccount.Folder, true) != 0)
			{
				RemoveFtpFolderPermissions(currentPhysicalPath, ftpAccount.Name);
			}

			// Set new permissions
			EnsureUserHomeFolderExists(ftpAccount.Folder, ftpAccount.Name, ftpAccount.CanRead, ftpAccount.CanWrite);
			// Update physical path.
			this.ftpSitesService.SetSitePhysicalPath(this.SiteId, ftpAccount.VirtualPath, ftpAccount.Folder);
			
			// Configure connect as feature.
			this.ftpSitesService.ConfigureConnectAs(ftpAccount.Folder, this.SiteId, ftpAccount.VirtualPath, 
				this.GetQualifiedAccountName(ftpAccount.Name), ftpAccount.Password, false);

			// Update authorization rules.
			AuthorizationRuleCollection authRulesCollection = this.ftpSitesService.GetAuthorizationRuleCollection(String.Format("{0}/{1}", this.SiteId, ftpAccount.Name));
			AuthorizationRule realtedRule = null;
			foreach(AuthorizationRule rule in authRulesCollection)
			{
				IList<string> users = rule.Users.Split(',');
				if (users.Contains(ftpAccount.Name))
				{
					realtedRule = rule;
				}
			}
			if (realtedRule != null)
			{
				PermissionsFlags permissions = 0;
				if (ftpAccount.CanRead)
				{
					permissions |= PermissionsFlags.Read;
				}
				if (ftpAccount.CanWrite)
				{
					permissions |= PermissionsFlags.Write;
				}
				if (ftpAccount.CanRead || ftpAccount.CanWrite)
				{
					realtedRule.Permissions = permissions;
				}
			}

			this.ftpSitesService.CommitChanges();
		}
 /// <remarks/>
 public void UpdateAccountAsync(FtpAccount account)
 {
     this.UpdateAccountAsync(account, null);
 }
 /// <remarks/>
 public System.IAsyncResult BeginUpdateAccount(FtpAccount account, System.AsyncCallback callback, object asyncState)
 {
     return(this.BeginInvoke("UpdateAccount", new object[] {
         account
     }, callback, asyncState));
 }
 public void UpdateAccount(FtpAccount account)
 {
     this.Invoke("UpdateAccount", new object[] {
         account
     });
 }
        private void SaveItem()
        {
            if (!Page.IsValid)
                return;

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

            // get other props
            IFtpAccountEditControl ctrl = (IFtpAccountEditControl)providerControl.Controls[0];
            ctrl.SaveItem(item);

            if (PanelRequest.ItemID == 0)
            {
                try
                {
                    // new item
                    int result = ES.Services.FtpServers.AddFtpAccount(item);
                    if (result < 0)
                    {
                        ShowResultMessage(result);
                        return;
                    }
                }
                catch (Exception ex)
                {
                    
                    ShowErrorMessage("FTP_ADD_ACCOUNT", ex);
                    return;
                    
                }
            }
            else
            {
                try
                {
                    // existing item
                    int result = ES.Services.FtpServers.UpdateFtpAccount(item);
                    if (result < 0)
                    {
                        ShowResultMessage(result);
                        return;
                    }
                }
                catch (Exception ex)
                {
                    ShowErrorMessage("FTP_UPDATE_ACCOUNT", ex);
                    return;
                }
            }

            // return
            RedirectSpaceHomePage();
        }
Exemple #15
0
        public virtual FtpAccount[] GetAccounts()
        {
			List<FtpAccount> accounts = new List<FtpAccount>();

            string keyName = @"SOFTWARE\Cat Soft\Serv-U\Domains\" + DomainId + @"\UserList";
            RegistryKey key = Registry.LocalMachine.OpenSubKey(keyName);
            if (key == null)
				return accounts.ToArray();

            foreach (string name in key.GetValueNames())
            {
                string[] parts = key.GetValue(name).ToString().Split('|');

                FtpAccount acc = new FtpAccount();
                acc.Name = name;
                acc.Enabled = (parts[0] == "1");
                accounts.Add(acc);
            }
            return accounts.ToArray();
        }
 public void BindItem(FtpAccount item)
 {
     chkRead.Checked = item.CanRead;
     chkWrite.Checked = item.CanWrite;
 }
Exemple #17
0
        public virtual FtpAccount GetAccount(string accountName)
        {
            string keyName = @"SOFTWARE\Cat Soft\Serv-U\Domains\" + DomainId + @"\UserSettings\" + accountName;
            RegistryKey key = Registry.LocalMachine.OpenSubKey(keyName);
            if (key == null)
                return null;

            FtpAccount account = new FtpAccount();
            account.Name = accountName;

            // status
            RegistryKey usersKey = Registry.LocalMachine.OpenSubKey(
                @"SOFTWARE\Cat Soft\Serv-U\Domains\" + DomainId + @"\UserList");
            string[] parts = usersKey.GetValue(accountName).ToString().Split('|');
            account.Enabled = (parts[0] == "1");

            // path and permissions
            string path = (string)key.GetValue("Access1");
            if (path != null)
            {
                parts = path.Split('|');
                account.Folder = parts[0];
                account.CanRead = (parts[1].IndexOf("R") != -1);
                account.CanWrite = (parts[1].IndexOf("W") != -1);
            }

            // password
            account.Password = (string)key.GetValue("Password");

            return account;
        }
 public int UpdateFtpAccount(FtpAccount item) {
     object[] results = this.Invoke("UpdateFtpAccount", new object[] {
                 item});
     return ((int)(results[0]));
 }
Exemple #19
0
        public virtual void CreateAccount(FtpAccount account)
        {
            // add user to the list
            if (AccountExists(account.Name))
                return;

			RegistryKey domainKey = Registry.LocalMachine.OpenSubKey(
				@"SOFTWARE\Cat Soft\Serv-U\Domains\" + DomainId, true);

			RegistryKey usersKey = domainKey.OpenSubKey("UserList", true);
			if (usersKey == null)
				usersKey = domainKey.CreateSubKey("UserList");

            usersKey.SetValue(account.Name, BoolToString(account.Enabled) + "|0");

            // user details
			RegistryKey settingsKey = domainKey.OpenSubKey("UserSettings", true);
			if(settingsKey == null)
				settingsKey = domainKey.CreateSubKey("UserSettings");
			
			RegistryKey user = settingsKey.CreateSubKey(account.Name);

            // folder and permissions
            user.SetValue("Access1", account.Folder
                + "|" + BuildPermissionsString(account.CanRead, account.CanWrite));

            // enable
            if (!account.Enabled)
                user.SetValue("Enable", "0");

            // home folder
            user.SetValue("HomeDir", account.Folder);

            // password
            user.SetValue("Password", HashPassword(account.Password));
            user.SetValue("PasswordLastChange", "1170889819");

            // other props
            user.SetValue("RelPaths", "1");
            user.SetValue("SKEYValues", "");
            user.SetValue("TimeOut", "600");

            // reload config
            ReloadServUConfig();
        }
 /// <remarks/>
 public void UpdateFtpAccountAsync(FtpAccount item) {
     this.UpdateFtpAccountAsync(item, null);
 }
Exemple #21
0
        public virtual void UpdateAccount(FtpAccount account)
        {
            // edit status in the list
            RegistryKey usersKey = Registry.LocalMachine.OpenSubKey(
                @"SOFTWARE\Cat Soft\Serv-U\Domains\" + DomainId + @"\UserList", true);
            usersKey.SetValue(account.Name, BoolToString(account.Enabled) + "|0");

            // edit details
            RegistryKey user = Registry.LocalMachine.OpenSubKey(
                @"SOFTWARE\Cat Soft\Serv-U\Domains\" + DomainId + @"\UserSettings\" + account.Name, true);

            if (user == null)
                return;

            // folder and permissions
            user.SetValue("Access1", account.Folder
                + "|" + BuildPermissionsString(account.CanRead, account.CanWrite));

            if (user.GetValue("Enable") != null)
                user.DeleteValue("Enable");

            // enable
            if (!account.Enabled)
                user.SetValue("Enable", "0");

            // home folder
            user.SetValue("HomeDir", account.Folder);

            // password
            if (!String.IsNullOrEmpty(account.Password))
            {
                user.SetValue("Password", HashPassword(account.Password));
                user.SetValue("PasswordLastChange", "1170889819");
            }

            // reload config
            ReloadServUConfig();
        }
        public static PackageResult AddPackageWithResources(int userId, int planId, string spaceName,
            int statusId, bool sendLetter,
            bool createResources, string domainName, bool createInstantAlias, bool createWebSite,
            bool createFtpAccount, string ftpAccountName, bool createMailAccount)
        {
            try
            {
                TaskManager.StartTask("HOSTING_SPACE_WR", "ADD", spaceName);

                PackageResult result = new PackageResult();

                // check account
                result.Result = SecurityContext.CheckAccount(DemandAccount.NotDemo | DemandAccount.IsActive
                    | DemandAccount.IsReseller);
                if (result.Result < 0) return result;

                // check if domain exists
                result.Result = ServerController.CheckDomain(domainName);
                if (result.Result < 0)
                    return result;

                // load user info
                UserInfo user = UserController.GetUser(userId);

                if (createFtpAccount)
                {
                    // check if FTP account exists
                    if (String.IsNullOrEmpty(ftpAccountName))
                        ftpAccountName = user.Username;

                    if (FtpServerController.FtpAccountExists(ftpAccountName))
                    {
                        result.Result = BusinessErrorCodes.ERROR_ACCOUNT_WIZARD_FTP_ACCOUNT_EXISTS;
                        return result;
                    }
                }

                // load hosting plan
                HostingPlanInfo plan = PackageController.GetHostingPlan(planId);

                string packageName = spaceName;
                if (String.IsNullOrEmpty(packageName) || packageName.Trim() == "")
                    packageName = plan.PlanName;

                // create package
                int packageId = -1;
                try
                {
                    result = PackageController.AddPackage(
                        userId, planId, packageName, "", statusId, DateTime.Now, false);
                }
                catch (Exception ex)
                {
                    // error while adding package
                    throw ex;
                }

                if (result.Result < 0)
                    return result;

                packageId = result.Result;

                // create domain
                if (createResources)
                {
                    int domainId = 0;
                    if (!String.IsNullOrEmpty(domainName))
                    {
                        try
                        {
                            DomainInfo domain = new DomainInfo();
                            domain.PackageId = packageId;
                            domain.DomainName = domainName;
                            domain.HostingAllowed = false;
                            domainId = ServerController.AddDomain(domain, createInstantAlias);
                            if (domainId < 0)
                            {
                                result.Result = domainId;
                                DeletePackage(packageId);
                                return result;
                            }
                        }
                        catch (Exception ex)
                        {
                            // error while adding domain
                            DeletePackage(packageId);
                            throw new Exception("Could not add domain", ex);
                        }
                    }

                    if (createWebSite && !String.IsNullOrEmpty(domainName))
                    {
                        // create web site
                        try
                        {
                            int webSiteId = WebServerController.AddWebSite(
                                packageId, domainId, 0, true);
                            if (webSiteId < 0)
                            {
                                result.Result = webSiteId;
                                DeletePackage(packageId);
                                return result;
                            }
                        }
                        catch (Exception ex)
                        {
                            // error while creating web site
                            DeletePackage(packageId);
                            throw new Exception("Could not create web site", ex);
                        }
                    }

                    // create FTP account
                    if (createFtpAccount)
                    {
                        try
                        {
                            FtpAccount ftpAccount = new FtpAccount();
                            ftpAccount.PackageId = packageId;
                            ftpAccount.Name = ftpAccountName;
                            ftpAccount.Password = user.Password;
                            ftpAccount.Folder = "\\";
                            ftpAccount.CanRead = true;
                            ftpAccount.CanWrite = true;

                            int ftpAccountId = FtpServerController.AddFtpAccount(ftpAccount);
                            if (ftpAccountId < 0)
                            {
                                result.Result = ftpAccountId;
                                DeletePackage(packageId);
                                return result;
                            }
                        }
                        catch (Exception ex)
                        {
                            // error while creating ftp account
                            DeletePackage(packageId);
                            throw new Exception("Could not create FTP account", ex);
                        }
                    }

                    if (createMailAccount && !String.IsNullOrEmpty(domainName))
                    {
                        // create default mailbox
                        try
                        {
                            // load mail policy
                            UserSettings settings = UserController.GetUserSettings(userId, UserSettings.MAIL_POLICY);
                            string catchAllName = !String.IsNullOrEmpty(settings["CatchAllName"])
                                ? settings["CatchAllName"] : "mail";

                            MailAccount mailbox = new MailAccount();
                            mailbox.Name = catchAllName + "@" + domainName;
                            mailbox.PackageId = packageId;

                            // gather information from the form
                            mailbox.Enabled = true;

                            mailbox.ResponderEnabled = false;
                            mailbox.ReplyTo = "";
                            mailbox.ResponderSubject = "";
                            mailbox.ResponderMessage = "";

                            // password
                            mailbox.Password = user.Password;

                            // redirection
                            mailbox.ForwardingAddresses = new string[] { };
                            mailbox.DeleteOnForward = false;
                            mailbox.MaxMailboxSize = 0;

                            int mailAccountId = MailServerController.AddMailAccount(mailbox);

                            if (mailAccountId < 0)
                            {
                                result.Result = mailAccountId;
                                DeletePackage(packageId);
                                return result;
                            }

                            // set catch-all account
                            MailDomain mailDomain = MailServerController.GetMailDomain(packageId, domainName);
                            mailDomain.CatchAllAccount = catchAllName;
                            mailDomain.PostmasterAccount = "mail";
                            mailDomain.AbuseAccount = "mail";
                            MailServerController.UpdateMailDomain(mailDomain);

                            int mailDomainId = mailDomain.Id;

                            // set mail domain pointer
                            // load domain instant alias
                            string instantAlias = ServerController.GetDomainAlias(packageId, domainName);
                            DomainInfo instantDomain = ServerController.GetDomain(instantAlias);
                            if (instantDomain == null || instantDomain.MailDomainId > 0)
                                instantAlias = "";

                            if (!String.IsNullOrEmpty(instantAlias))
                                MailServerController.AddMailDomainPointer(mailDomainId, instantDomain.DomainId);
                        }
                        catch (Exception ex)
                        {
                            // error while creating mail account
                            DeletePackage(packageId);
                            throw new Exception("Could not create mail account", ex);
                        }
                    }
                }

                TaskManager.ItemId = result.Result;
                TaskManager.TaskParameters["SendLetter"] = sendLetter;

                return result;
            }
            catch (Exception ex)
            {
                throw TaskManager.WriteError(ex);
            }
            finally
            {
                TaskManager.CompleteTask();
            }
        }
 /// <remarks/>
 public System.IAsyncResult BeginCreateAccount(FtpAccount account, System.AsyncCallback callback, object asyncState) {
     return this.BeginInvoke("CreateAccount", new object[] {
                 account}, callback, asyncState);
 }
Exemple #24
0
        public virtual void CreateAccount(FtpAccount account)
        {
            // get default account settings
            DateTime created = DateTime.Now;

            NameValueCollection dict = GetAccountDefaultSettings();
            dict["AccessList0"] = BildAccountAccessList(account);
            dict["CreationDate"] = created.ToString("yyyy/MM/dd HH:mm:ss");
            dict["ExpirationDate"] = created.ToString("yyyy/MM/dd");
            dict["Password"] = "******" + MD5(account.Password);
            dict["Enabled"] = account.Enabled ? "-1" : "0";

            // save account settings
            SaveSettingsFile(GetUserSettingsPath(SiteId, account.Name), "Account", dict);

            // fluch cache
            FlushCache();
        }
 /// <remarks/>
 public void CreateAccountAsync(FtpAccount account) {
     this.CreateAccountAsync(account, null);
 }
Exemple #26
0
        private string BildAccountAccessList(FtpAccount account)
        {
            StringBuilder sb = new StringBuilder();
            sb.Append("/,")
            .Append(account.Folder).Append(",");

            // file permissions
            sb.Append(account.CanRead ? "R" : "-")
            .Append(account.CanWrite ? "W" : "-")
            .Append(account.CanWrite ? "D" : "-")
            .Append(account.CanWrite ? "A" : "-")
            .Append(",");

            // folder permissions
            sb.Append(account.CanRead ? "F" : "-")
            .Append(account.CanRead ? "D" : "-")
            .Append(account.CanWrite ? "M" : "-")
            .Append(account.CanWrite ? "R" : "-")
            .Append(account.CanRead ? "I" : "-")
            .Append("---,");

            return sb.ToString();
        }
 /// <remarks/>
 public void CreateAccountAsync(FtpAccount account, object userState) {
     if ((this.CreateAccountOperationCompleted == null)) {
         this.CreateAccountOperationCompleted = new System.Threading.SendOrPostCallback(this.OnCreateAccountOperationCompleted);
     }
     this.InvokeAsync("CreateAccount", new object[] {
                 account}, this.CreateAccountOperationCompleted, userState);
 }
Exemple #28
0
		public virtual void UpdateAccount(FtpAccount account)
		{
			XmlDocument doc = GetFileZillaConfig();
			XmlNode nodeUser = doc.SelectSingleNode("/FileZillaServer/Users/User[@Name='" + account.Name + "']");
			if (nodeUser == null)
				return;

			// update user
			if(!String.IsNullOrEmpty(account.Password))
				SetOption(nodeUser, "Pass", MD5(account.Password));
			SetOption(nodeUser, "Enabled", BoolToString(account.Enabled));

			// update folder
			XmlNode nodePermission = nodeUser.SelectSingleNode("Permissions/Permission");
			if (nodePermission != null)
			{
				((XmlElement)nodePermission).SetAttribute("Dir", account.Folder);
				SetOption(nodePermission, "FileRead", BoolToString(account.CanRead));
				SetOption(nodePermission, "FileWrite", BoolToString(account.CanWrite));
				SetOption(nodePermission, "FileDelete", BoolToString(account.CanWrite));
				SetOption(nodePermission, "DirCreate", BoolToString(account.CanWrite));
				SetOption(nodePermission, "DirDelete", BoolToString(account.CanWrite));
				SetOption(nodePermission, "DirList", BoolToString(account.CanRead));
				SetOption(nodePermission, "DirSubdirs", BoolToString(account.CanRead));
			}

			// save document
			doc.Save(GetFileZillaConfigPath());

			// reload config
			ReloadFileZillaConfig();
		}
 public void UpdateAccount(FtpAccount account) {
     this.Invoke("UpdateAccount", new object[] {
                 account});
 }
    	/// <summary>
		/// Creates virtual directory under site with given name and sets authorization rules.
		/// </summary>
		/// <param name="siteName">Site name.</param>
		/// <param name="account">Account information.</param>
		public void CreateFtpAccount(string siteName, FtpAccount account)
		{
			Site site = this.GetIisSite(siteName);
			if (site !=null)
			{
				Application application = site.Applications["/"];
				if (application != null)
				{
					VirtualDirectory accountDirectory = application.VirtualDirectories[account.Name];
					if (accountDirectory != null)
					{
						application.VirtualDirectories.Remove(accountDirectory);
					}
					VirtualDirectory createdVirtualDirectory = application.VirtualDirectories.Add(String.Format("/{0}", account.Name), account.Folder);


					AuthorizationRuleCollection authRulesCollection = this.GetAuthorizationRuleCollection(String.Format("{0}/{1}", siteName, account.Name));
					List<AuthorizationRule> rulesToRemove = new List<AuthorizationRule>();
					foreach (AuthorizationRule rule in authRulesCollection)
					{
						if (rule.AccessType == AuthorizationRuleAccessType.Allow && (rule.Users == "?" || rule.Users == "*"))
						{
							rulesToRemove.Add(rule);
						}
					}

					foreach(AuthorizationRule rule in rulesToRemove)
					{
						authRulesCollection.Remove(rule);
					}

					PermissionsFlags permissions = 0;
					if (account.CanRead)
					{
						permissions |= PermissionsFlags.Read;
					}
					if (account.CanWrite)
					{
						permissions |= PermissionsFlags.Write;
					}
					if (account.CanRead || account.CanWrite)
					{
						authRulesCollection.Add(AuthorizationRuleAccessType.Allow, account.Name, String.Empty, permissions);
					}
				}
			}
			this.CommitChanges();
		}
 /// <remarks/>
 public void UpdateAccountAsync(FtpAccount account) {
     this.UpdateAccountAsync(account, null);
 }
        private void BindItem()
        {
            try
            {
                if (!IsPostBack)
                {
                    // load item if required
                    if (PanelRequest.ItemID > 0)
                    {
                        // existing item
                        try
                        {
                            item = ES.Services.FtpServers.GetFtpAccount(PanelRequest.ItemID);
                        }
                        catch (Exception ex)
                        {
                            ShowErrorMessage("FTP_GET_ACCOUNT", ex);
                            return;
                        }

                        if (item != null)
                        {
                            // save package info
                            ViewState["PackageId"] = item.PackageId;
                            fileLookup.PackageId = item.PackageId;
                            passwordControl.SetPackagePolicy(item.PackageId, UserSettings.FTP_POLICY, "UserPasswordPolicy");
                        }
                        else
                            RedirectToBrowsePage();
                    }
                    else
                    {
                        // new item
                        ViewState["PackageId"] = PanelSecurity.PackageId;
                        fileLookup.PackageId = PanelSecurity.PackageId;
                        fileLookup.SelectedFile = "\\";
                        usernameControl.SetPackagePolicy(PanelSecurity.PackageId, UserSettings.FTP_POLICY, "UserNamePolicy");
                        passwordControl.SetPackagePolicy(PanelSecurity.PackageId, UserSettings.FTP_POLICY, "UserPasswordPolicy");
                    }
                }

                // load provider control
                LoadProviderControl((int)ViewState["PackageId"], "Ftp", providerControl, "EditAccount.ascx");

                if (!IsPostBack)
                {
                    // bind item to controls
                    if (item != null)
                    {
                        // bind item to controls
                        usernameControl.Text = item.Name;
                        usernameControl.EditMode = true;
                        passwordControl.EditMode = true;
                        fileLookup.SelectedFile = item.Folder;

                        // other controls
                        IFtpAccountEditControl ctrl = (IFtpAccountEditControl)providerControl.Controls[0];
                        ctrl.BindItem(item);
                    }
                }
            }
            catch
            {
                ShowWarningMessage("INIT_SERVICE_ITEM_FORM");
                DisableFormControls(this, btnCancel);
            }
        }
 /// <remarks/>
 public void AddFtpAccountAsync(FtpAccount item) {
     this.AddFtpAccountAsync(item, null);
 }
 public void SaveItem(FtpAccount item)
 {
     item.CanRead = chkRead.Checked;
     item.CanWrite = chkWrite.Checked;
 }
Exemple #35
0
        /// <summary>
        /// Updates ftp account.
        /// </summary>
        /// <param name="account">Accoun to update.</param>
        public void UpdateAccount(FtpAccount account)
        {
            var user = SecurityUtils.GetUser(account.Name, ServerSettings, UsersOU);

            switch (UserIsolationMode)
            {
            case Mode.ActiveDirectory:
                var ftpRoot = AdFtpRoot.ToLower();
                var ftpDir  = account.Folder.ToLower().Replace(ftpRoot, "");

                var oldDir = user.MsIIS_FTPDir;

                user.Password             = account.Password;
                user.PasswordCantChange   = true;
                user.PasswordNeverExpires = true;
                user.Description          = "WebsitePanel FTP Account with AD User Isolation";
                user.MemberOf             = new[] { FtpGroupName };
                user.AccountDisabled      = !account.Enabled;
                user.MsIIS_FTPRoot        = ftpRoot;
                user.MsIIS_FTPDir         = ftpDir;
                user.System = true;

                SecurityUtils.UpdateUser(user, ServerSettings, UsersOU, GroupsOU);

                // Set NTFS permissions
                var userPermission = GetUserPermission(account.Name, account.Folder);

                // Do we need to change the NTFS permissions? i.e. is users home dir changed or are permissions changed?
                if (oldDir != ftpDir || account.CanRead != userPermission.Read || account.CanWrite != userPermission.Write)
                {
                    // First get sid of user account
                    var sid = SecurityUtils.GetAccountSid(account.Name, ServerSettings, UsersOU, GroupsOU);

                    // Remove the permissions set for this account on previous folder
                    SecurityUtils.RemoveNtfsPermissionsBySid(Path.Combine(ftpRoot, oldDir), sid);

                    // If no permissions is to be set, exit
                    if (!account.CanRead && !account.CanWrite)
                    {
                        return;
                    }

                    // Add the new permissions
                    var ntfsPermissions = account.CanRead ? NTFSPermission.Read : NTFSPermission.Write;
                    if (account.CanRead && account.CanWrite)
                    {
                        ntfsPermissions = NTFSPermission.Modify;
                    }

                    SecurityUtils.GrantNtfsPermissionsBySid(account.Folder, sid, ntfsPermissions, true, true);
                }
                break;

            default:

                // Change user account state and password (if required).
                user.Password        = account.Password;
                user.AccountDisabled = !account.Enabled;
                SecurityUtils.UpdateUser(user, ServerSettings, UsersOU, GroupsOU);
                // Update iis configuration.
                this.FillIisFromFtpAccount(account);
                break;
            }
        }