示例#1
0
        /// <summary>
        /// Installs Ftp7 provider.
        /// </summary>
        /// <returns>Error messages.</returns>
        public override string[] Install()
        {
            List <string> messages = new List <string>();

            FtpSite site          = null;
            string  folder        = FileUtils.EvaluateSystemVariables(DefaultFtpSiteFolder);
            string  logsDirectory = FileUtils.EvaluateSystemVariables(DefaultFtpSiteLogsFolder);

            // Create site folder.
            if (!FileUtils.DirectoryExists(folder))
            {
                FileUtils.CreateDirectory(folder);
            }
            // Create logs folder.
            if (!FileUtils.DirectoryExists(logsDirectory))
            {
                FileUtils.CreateDirectory(logsDirectory);
            }

            site = new FtpSite();

            site.Name        = this.SiteId;
            site.SiteId      = this.SiteId;
            site.ContentPath = DefaultFtpSiteFolder;
            site.Bindings    = new ServerBinding[1];
            // set default log directory
            site.LogFileDirectory = DefaultFtpSiteLogsFolder;
            // set default logging fields
            site[FtpSite.MSFTP7_LOG_EXT_FILE_FIELDS] = DEFAULT_LOG_EXT_FILE_FIELDS;

            if (!String.IsNullOrEmpty(this.SharedIP))
            {
                site.Bindings[0] = new ServerBinding(this.SharedIP, "21", String.Empty);
            }
            else
            {
                site.Bindings[0] = new ServerBinding("*", "21", "*");
                //// Get information on local server.
                //IPHostEntry localServerHostEntry = Dns.GetHostEntry(Dns.GetHostName());
                //foreach (IPAddress address in localServerHostEntry.AddressList)
                //{
                //    if (address.AddressFamily == AddressFamily.InterNetwork)
                //    {
                //        site.Bindings[0] = new ServerBinding(address.ToString(), "21", String.Empty);
                //    }
                //}
            }

            if (this.IsFtpServerBindingsInUse(site))
            {
                messages.Add("Cannot create ftp site because requested bindings are already in use.");
                return(messages.ToArray());
            }

            try
            {
                SecurityUtils.EnsureOrganizationalUnitsExist(ServerSettings, UsersOU, GroupsOU);
            }
            catch (Exception ex)
            {
                messages.Add(String.Format("Could not check/create Organizational Units: {0}", ex.Message));
                return(messages.ToArray());
            }

            // create folder if it not exists
            if (String.IsNullOrEmpty(SiteId))
            {
                messages.Add("Please, select FTP site to create accounts on");
            }
            else
            {
                // create FTP group name
                if (String.IsNullOrEmpty(FtpGroupName))
                {
                    messages.Add("FTP Group can not be blank");
                }
                else
                {
                    try
                    {
                        // create group
                        if (!SecurityUtils.GroupExists(FtpGroupName, ServerSettings, GroupsOU))
                        {
                            SystemGroup group = new SystemGroup();
                            group.Name        = FtpGroupName;
                            group.Members     = new string[] { };
                            group.Description = "WebsitePanel System Group";

                            SecurityUtils.CreateGroup(group, ServerSettings, UsersOU, GroupsOU);
                        }
                    }
                    catch (Exception ex)
                    {
                        messages.Add(String.Format("There was an error while adding '{0}' group: {1}",
                                                   FtpGroupName, ex.Message));
                        return(messages.ToArray());
                    }
                }

                if (!this.ftpSitesService.SiteExists(this.SiteId))
                {
                    this.CreateSite(site);
                }
                else
                {
                    this.UpdateSite(site);
                }

                try
                {
                    // set permissions on the site root
                    SecurityUtils.GrantNtfsPermissions(site.ContentPath, FtpGroupName,
                                                       NTFSPermission.Read, true, true, ServerSettings,
                                                       UsersOU, GroupsOU);
                }
                catch (Exception ex)
                {
                    messages.Add(String.Format("Can not set permissions on '{0}' folder: {1}",
                                               site.ContentPath, ex.Message));
                    return(messages.ToArray());
                }
            }
            return(messages.ToArray());
        }
示例#2
0
        public override string[] Install()
        {
            List <string> messages = new List <string>();

            try
            {
                SecurityUtils.EnsureOrganizationalUnitsExist(ServerSettings, UsersOU, GroupsOU);
            }
            catch (Exception ex)
            {
                messages.Add(String.Format("Could not check/create Organizational Units: {0}", ex.Message));
                return(messages.ToArray());
            }

            // create folder if it not exists
            if (String.IsNullOrEmpty(SiteId))
            {
                messages.Add("Please, select FTP site to create accounts on");
            }
            else
            {
                // create FTP group name
                if (String.IsNullOrEmpty(FtpGroupName))
                {
                    messages.Add("FTP Group can not be blank");
                }
                else
                {
                    try
                    {
                        // create group
                        if (!SecurityUtils.GroupExists(FtpGroupName, ServerSettings, GroupsOU))
                        {
                            SystemGroup group = new SystemGroup();
                            group.Name        = FtpGroupName;
                            group.Members     = new string[] { };
                            group.Description = "SolidCP System Group";

                            SecurityUtils.CreateGroup(group, ServerSettings, UsersOU, GroupsOU);
                        }
                    }
                    catch (Exception ex)
                    {
                        messages.Add(String.Format("There was an error while adding '{0}' group: {1}",
                                                   FtpGroupName, ex.Message));
                        return(messages.ToArray());
                    }
                }

                FtpSite site = GetSite(SiteId);
                try
                {
                    // set permissions on the site root
                    SecurityUtils.GrantNtfsPermissions(site.ContentPath, FtpGroupName,
                                                       NTFSPermission.Read, true, true, ServerSettings,
                                                       UsersOU, GroupsOU);
                }
                catch (Exception ex)
                {
                    messages.Add(String.Format("Can not set permissions on '{0}' folder: {1}",
                                               site.ContentPath, ex.Message));
                    return(messages.ToArray());
                }
            }
            return(messages.ToArray());
        }
示例#3
0
 public virtual void CreateGroup(SystemGroup group)
 {
     SecurityUtils.CreateGroup(group, ServerSettings, UsersOU, GroupsOU);
 }