Пример #1
0
        /// <summary>
        /// Gets a value which shows whether supplied site contains bindings that are already in use.
        /// </summary>
        /// <param name="site">Site to check.</param>
        /// <returns>true - if any of supplied bindinds is in use; false -otherwise.</returns>
        private bool IsFtpServerBindingsInUse(FtpSite site)
        {
            if (site == null)
            {
                throw new ArgumentNullException("site");
            }

            // check for server bindings
            foreach (FtpSite existentSite in this.GetSites())
            {
                if (existentSite.Name != site.Name)
                {
                    foreach (ServerBinding usedBinding in existentSite.Bindings)
                    {
                        foreach (ServerBinding requestedBinding in site.Bindings)
                        {
                            if (usedBinding.IP == requestedBinding.IP && usedBinding.Port == usedBinding.Port)
                            {
                                return(true);
                            }
                        }
                    }
                }
            }
            return(false);
        }
Пример #2
0
 /// <summary>
 /// Checks if bindings listed in given site already in use.
 /// </summary>
 /// <param name="site">Site to check.</param>
 /// <exception cref="InvalidOperationException">Is thrown in case supplied site contains bindings that are already in use.</exception>
 private void CheckFtpServerBindings(FtpSite site)
 {
     if (this.IsFtpServerBindingsInUse(site))
     {
         throw new InvalidOperationException("Some of ftp site's bindings are already in use.");
     }
 }
Пример #3
0
        public virtual void UpdateSite(FtpSite site)
        {
            // check server bindings
            CheckFtpServerBindings(site.Bindings);

            // update site properties
            ManagementObject objSettings = wmi.GetObject(
                String.Format("IIsFtpServerSetting='{0}'", site.SiteId));

            FillWmiObjectFromFtpSite(objSettings, site);

            // update 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;
            }

            objSettings.Properties["ServerBindings"].Value = objBinings;

            // save object
            objSettings.Put();
        }
Пример #4
0
        /// <summary>
        /// Fills iis configuration with information from ftp site.
        /// </summary>
        /// <param name="ftpSite">Ftp site that holds information.</param>
        private void FillIisFromFtpSite(FtpSite ftpSite)
        {
            IisFtpSite iisFtpSite       = this.ftpSitesService.GetIisFtpSite(ftpSite.SiteId);
            string     logExtFileFields = ftpSite[FtpSite.MSFTP7_LOG_EXT_FILE_FIELDS];

            if (iisFtpSite != null)
            {
                // Security settings.
                iisFtpSite.Security.Authentication.AnonymousAuthentication.Enabled  = ftpSite.AllowAnonymous;
                iisFtpSite.Security.Authentication.AnonymousAuthentication.UserName = ftpSite.AnonymousUsername;
                iisFtpSite.Security.Authentication.AnonymousAuthentication.Password = ftpSite.AnonymousUserPassword;
                // enable logging
                iisFtpSite.LogFile.Enabled = true;
                // set logging fields
                if (!String.IsNullOrEmpty(logExtFileFields))
                {
                    iisFtpSite.LogFile.LogExtFileFlags = (FtpLogExtFileFlags)Enum.Parse(typeof(FtpLogExtFileFlags), logExtFileFields);
                }
                // set log files directory
                if (!String.IsNullOrEmpty(ftpSite.LogFileDirectory))
                {
                    iisFtpSite.LogFile.Directory = ftpSite.LogFileDirectory;
                }
            }
            // Set new bindings.
            this.CheckFtpServerBindings(ftpSite);
            this.ftpSitesService.SetSiteBindings(ftpSite.Name, ftpSite.Bindings);
            // Physical path
            this.ftpSitesService.SetSitePhysicalPath(ftpSite.SiteId, "/", ftpSite.ContentPath);
        }
Пример #5
0
 public string CreateSite(FtpSite site)
 {
     object[] results = this.Invoke("CreateSite", new object[] {
         site
     });
     return((string)(results[0]));
 }
Пример #6
0
        /// <summary>
        /// Updates site with given information.
        /// </summary>
        /// <param name="site">Ftp site.</param>
        public void UpdateSite(FtpSite site)
        {
            // Check server bindings.
            CheckFtpServerBindings(site);

            this.FillIisFromFtpSite(site);

            this.ftpSitesService.CommitChanges();
        }
Пример #7
0
        public virtual void ChangeSiteState(string siteId, ServerState state)
        {
            // get original site state
            ServerState origState = ServerState.Started;
            FtpSite     site      = LoadDomain(siteId, out origState);

            // create site
            SaveDomain(site, state);
        }
Пример #8
0
 /// <remarks/>
 public void UpdateSiteAsync(FtpSite site, object userState)
 {
     if ((this.UpdateSiteOperationCompleted == null))
     {
         this.UpdateSiteOperationCompleted = new System.Threading.SendOrPostCallback(this.OnUpdateSiteOperationCompleted);
     }
     this.InvokeAsync("UpdateSite", new object[] {
         site
     }, this.UpdateSiteOperationCompleted, userState);
 }
Пример #9
0
        public virtual void UpdateSite(FtpSite site)
        {
            // get original site state
            ServerState state = ServerState.Started;

            LoadDomain(site.Name, out state);

            // create site
            SaveDomain(site, state);
        }
Пример #10
0
        public virtual FtpSite GetSite(string siteId)
        {
            FtpSite site = new FtpSite();

            ManagementObject objSite = wmi.GetObject(
                String.Format("IIsFtpServerSetting='{0}'", siteId));

            // fill properties
            FillFtpSiteFromWmiObject(site, objSite);

            return(site);
        }
Пример #11
0
        public virtual string CreateSite(FtpSite site)
        {
            // create folder if nessesary
            //if(!Directory.Exists(site.ContentPath))
            //	Directory.CreateDirectory(site.ContentPath);

            // create anonymous user account if required
            // blah blah blah

            // set account permissions
            // blah blah blah

            // check server bindings
            CheckFtpServerBindings(site.Bindings);

            // create FTP site
            ManagementObject objService = wmi.GetObject(String.Format("IIsFtpService='{0}'", FTP_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 objSite = objService.InvokeMethod("CreateNewSite", methodParams, new InvokeMethodOptions());

            // get FTP settings
            string siteId = ((string)objSite["returnValue"]).Remove(0, "IIsFtpServer='".Length).Replace("'", "");

            // update site properties
            ManagementObject objSettings = wmi.GetObject(
                String.Format("IIsFtpServerSetting='{0}'", siteId));

            FillWmiObjectFromFtpSite(objSettings, site);

            // start FTP site
            ChangeSiteState(siteId, ServerState.Started);
            return(siteId);
        }
Пример #12
0
        public virtual string CreateSite(FtpSite site)
        {
            // create site
            SaveDomain(site, ServerState.Started);

            // create "users" directory
            Directory.CreateDirectory(GetDomainPath(site.Name) + "\\users");

            // create "groups" directory
            Directory.CreateDirectory(GetDomainPath(site.Name) + "\\groups");

            return(site.Name);
        }
Пример #13
0
 private void FillWmiObjectFromFtpSite(ManagementBaseObject obj, FtpSite site)
 {
     obj.Properties["ServerComment"].Value     = site.Name;
     obj.Properties["AccessRead"].Value        = site.AllowReadAccess;
     obj.Properties["AccessScript"].Value      = site.AllowScriptAccess;
     obj.Properties["AccessSource"].Value      = site.AllowSourceAccess;
     obj.Properties["AccessWrite"].Value       = site.AllowWriteAccess;
     obj.Properties["AccessExecute"].Value     = site.AllowExecuteAccess;
     obj.Properties["AnonymousUserName"].Value = site.AnonymousUsername;
     obj.Properties["AnonymousUserPass"].Value = site.AnonymousUserPassword;
     obj.Properties["AllowAnonymous"].Value    = site.AllowAnonymous;
     obj.Properties["AnonymousOnly"].Value     = site.AnonymousOnly;
     obj.Properties["LogFileDirectory"].Value  = site.LogFileDirectory;
 }
Пример #14
0
        /// <summary>
        /// Gets ftp site with given name.
        /// </summary>
        /// <param name="siteId">Ftp site's name to get.</param>
        /// <returns>Ftp site.</returns>
        /// <exception cref="ArgumentException"> Is thrown in case site name is null or empty. </exception>
        public FtpSite GetSite(string siteId)
        {
            if (String.IsNullOrEmpty(siteId))
            {
                throw new ArgumentException("Site name is null or empty.");
            }

            FtpSite ftpSite = new FtpSite();

            ftpSite.SiteId = siteId;
            ftpSite.Name   = siteId;
            this.FillFtpSiteFromIis(ftpSite);

            return(ftpSite);
        }
Пример #15
0
        public override ServiceProviderItemBandwidth[] GetServiceItemsBandwidth(ServiceProviderItem[] items, DateTime since)
        {
            ServiceProviderItemBandwidth[] itemsBandwidth = new ServiceProviderItemBandwidth[items.Length];

            // calculate bandwidth for Default FTP Site
            FtpSite ftpSite  = GetSite(SiteId);
            string  siteId   = String.Concat("FTPSVC", ftpSite[FtpSite.MSFTP7_SITE_ID]);
            string  logsPath = Path.Combine(ftpSite.LogFileDirectory, siteId);

            // create parser object
            // and update statistics
            LogParser parser = new LogParser("Ftp", siteId, logsPath, "s-sitename", "cs-username");

            // Subscribe to the events because FTP 7.0 has several differences that should be taken into account
            // and processed in a specific way
            parser.ProcessKeyFields        += new ProcessKeyFieldsEventHandler(LogParser_ProcessKeyFields);
            parser.CalculateStatisticsLine += new CalculateStatsLineEventHandler(LogParser_CalculateStatisticsLine);
            //
            parser.ParseLogs();

            // update items with diskspace
            for (int i = 0; i < items.Length; i++)
            {
                ServiceProviderItem item = items[i];

                // create new bandwidth object
                itemsBandwidth[i]        = new ServiceProviderItemBandwidth();
                itemsBandwidth[i].ItemId = item.Id;
                itemsBandwidth[i].Days   = new DailyStatistics[0];

                if (item is FtpAccount)
                {
                    try
                    {
                        // get daily statistics
                        itemsBandwidth[i].Days = parser.GetDailyStatistics(since, new string[] { siteId, item.Name });
                    }
                    catch (Exception ex)
                    {
                        Log.WriteError(ex);
                    }
                }
            }
            return(itemsBandwidth);
        }
Пример #16
0
        public virtual FtpSite[] GetSites()
        {
            List <FtpSite> sites = new List <FtpSite>();

            // get all sites
            ManagementObjectCollection objSites = wmi.ExecuteQuery("SELECT * FROM IIsFtpServerSetting");

            foreach (ManagementObject objSite in objSites)
            {
                FtpSite site = new FtpSite();

                // fill site properties
                FillFtpSiteFromWmiObject(site, objSite);

                sites.Add(site);
            }
            return(sites.ToArray());
        }
Пример #17
0
        public virtual FtpSite[] GetSites()
        {
            List <FtpSite> sites = new List <FtpSite>();
            RegistryKey    key   = Registry.LocalMachine.OpenSubKey(SERVU_DOMAINS_REG);

            if (key == null)
            {
                return(sites.ToArray());
            }

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

                FtpSite site = new FtpSite();
                site.SiteId = domainId;
                site.Name   = parts[3];
                sites.Add(site);
            }
            return(sites.ToArray());
        }
Пример #18
0
        public override ServiceProviderItemBandwidth[] GetServiceItemsBandwidth(ServiceProviderItem[] items, DateTime since)
        {
            ServiceProviderItemBandwidth[] itemsBandwidth = new ServiceProviderItemBandwidth[items.Length];

            // calculate bandwidth for Default FTP Site
            FtpSite fptSite  = GetSite(SiteId);
            string  siteId   = SiteId.Replace("/", "");
            string  logsPath = Path.Combine(fptSite.LogFileDirectory, siteId);

            // create parser object
            // and update statistics
            LogParser parser = new LogParser("Ftp", siteId, logsPath, "s-sitename", "cs-username");

            parser.ParseLogs();

            // update items with diskspace
            for (int i = 0; i < items.Length; i++)
            {
                ServiceProviderItem item = items[i];

                // create new bandwidth object
                itemsBandwidth[i]        = new ServiceProviderItemBandwidth();
                itemsBandwidth[i].ItemId = item.Id;
                itemsBandwidth[i].Days   = new DailyStatistics[0];

                if (item is FtpAccount)
                {
                    try
                    {
                        // get daily statistics
                        itemsBandwidth[i].Days = parser.GetDailyStatistics(since, new string[] { siteId, item.Name });
                    }
                    catch (Exception ex)
                    {
                        Log.WriteError(ex);
                    }
                }
            }
            return(itemsBandwidth);
        }
Пример #19
0
        private void FillFtpSiteFromWmiObject(FtpSite site, ManagementBaseObject obj)
        {
            site.SiteId                = (string)obj.Properties["Name"].Value;
            site.Name                  = (string)obj.Properties["ServerComment"].Value;
            site.AllowReadAccess       = (bool)obj.Properties["AccessRead"].Value;
            site.AllowScriptAccess     = (bool)obj.Properties["AccessScript"].Value;
            site.AllowSourceAccess     = (bool)obj.Properties["AccessSource"].Value;
            site.AllowWriteAccess      = (bool)obj.Properties["AccessWrite"].Value;
            site.AllowExecuteAccess    = (bool)obj.Properties["AccessExecute"].Value;
            site.AnonymousUsername     = (string)obj.Properties["AnonymousUserName"].Value;
            site.AnonymousUserPassword = (string)obj.Properties["AnonymousUserPass"].Value;
            site.AllowAnonymous        = (bool)obj.Properties["AllowAnonymous"].Value;
            site.AnonymousOnly         = (bool)obj.Properties["AnonymousOnly"].Value;
            site.LogFileDirectory      = (string)obj.Properties["LogFileDirectory"].Value;

            // get server bindings
            ManagementBaseObject[] objBindings =
                ((ManagementBaseObject[])obj.Properties["ServerBindings"].Value);

            if (objBindings != null)
            {
                site.Bindings = new ServerBinding[objBindings.Length];
                for (int i = 0; i < objBindings.Length; i++)
                {
                    site.Bindings[i] = new ServerBinding(
                        (string)objBindings[i].Properties["IP"].Value,
                        (string)objBindings[i].Properties["Port"].Value,
                        (string)objBindings[i].Properties["Hostname"].Value);
                }
            }

            ManagementObject objVDir = wmi.GetObject(
                String.Format("IIsFtpVirtualDirSetting='{0}'", GetAccountPath(site.SiteId, "")));

            // determine root content folder
            site.ContentPath = (string)objVDir.Properties["Path"].Value;;
        }
Пример #20
0
        /// <summary>
        /// Fills ftp site with data from iis ftp site.
        /// </summary>
        /// <param name="ftpSite">Ftp site to fill.</param>
        private void FillFtpSiteFromIis(FtpSite ftpSite)
        {
            IisFtpSite iisFtpSite = this.ftpSitesService.GetIisFtpSite(ftpSite.SiteId);

            if (iisFtpSite != null)
            {
                // Security settings.
                ftpSite.AllowAnonymous        = iisFtpSite.Security.Authentication.AnonymousAuthentication.Enabled;
                ftpSite.AnonymousUsername     = iisFtpSite.Security.Authentication.AnonymousAuthentication.UserName;
                ftpSite.AnonymousUserPassword = iisFtpSite.Security.Authentication.AnonymousAuthentication.Password;
                ftpSite["UserIsolationMode"]  = iisFtpSite.UserIsolation.Mode.ToString();
                // Logging settings.
                ftpSite[FtpSite.MSFTP7_SITE_ID] = iisFtpSite.SiteServiceId;
                if (iisFtpSite.LogFile.Enabled)
                {
                    ftpSite.LogFileDirectory = iisFtpSite.LogFile.Directory;
                    ftpSite[FtpSite.MSFTP7_LOG_EXT_FILE_FIELDS] = iisFtpSite.LogFile.LogExtFileFlags.ToString();
                }
            }
            // Bindings
            ftpSite.Bindings = this.ftpSitesService.GetSiteBindings(ftpSite.SiteId);
            // Physical path
            ftpSite.ContentPath = this.ftpSitesService.GetSitePhysicalPath(ftpSite.SiteId, "/");
        }
Пример #21
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 = "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());
                    }
                }

                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());
        }
Пример #22
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());
        }
Пример #23
0
 /// <remarks/>
 public void UpdateSiteAsync(FtpSite site)
 {
     this.UpdateSiteAsync(site, null);
 }
Пример #24
0
 public virtual string CreateSite(FtpSite site)
 {
     // not implemented
     return(null);
 }
Пример #25
0
 public virtual void UpdateSite(FtpSite site)
 {
     // not implemented
 }
Пример #26
0
 public virtual string CreateSite(FtpSite site)
 {
     return(site.Name);
 }
Пример #27
0
        /// <summary>
        /// Creates ftp site.
        /// </summary>
        /// <param name="site">Ftp site to be created.</param>
        /// <returns>Created site id.</returns>
        /// <exception cref="ArgumentNullException">Is thrown in case supplied argument is null.</exception>
        /// <exception cref="ArgumentException">
        /// Is thrown in case site id or its name is null or empty or if site id is not equal to default ftp site name.
        /// </exception>
        public string CreateSite(FtpSite site)
        {
            if (site == null)
            {
                throw new ArgumentNullException("site");
            }

            if (String.IsNullOrEmpty(site.SiteId) || String.IsNullOrEmpty(site.Name))
            {
                throw new ArgumentException("Site id or name is null or empty.");
            }

            this.CheckFtpServerBindings(site);

            PropertyBag siteBag = this.ftpSitesService.GetSiteDefaults();

            // Set site name
            siteBag[FtpSiteGlobals.Site_Name] = site.Name;
            // Set site physical path
            siteBag[FtpSiteGlobals.AppVirtualDirectory_PhysicalPath] = site.ContentPath;
            PropertyBag ftpBinding = new PropertyBag();

            // Set site binding protocol
            ftpBinding[FtpSiteGlobals.BindingProtocol] = "ftp";
            // fill binding summary info
            ftpBinding[FtpSiteGlobals.BindingInformation] = site.Bindings[0].ToString();

            // Set site binding
            siteBag[FtpSiteGlobals.Site_SingleBinding] = ftpBinding;

            // Auto-start
            siteBag[FtpSiteGlobals.FtpSite_AutoStart] = true;

            // Set anonumous authentication
            siteBag[FtpSiteGlobals.Authentication_AnonymousEnabled] = true;
            siteBag[FtpSiteGlobals.Authentication_BasicEnabled]     = true;

            this.ftpSitesService.AddSite(siteBag);

            AuthorizationRuleCollection rules = this.ftpSitesService.GetAuthorizationRuleCollection(site.Name);

            rules.Add(AuthorizationRuleAccessType.Allow, "*", String.Empty, PermissionsFlags.Read);

            IisFtpSite iisFtpSite = this.ftpSitesService.GetIisFtpSite(site.Name);

            iisFtpSite.UserIsolation.Mode = Mode.StartInUsersDirectory;
            iisFtpSite.Security.Ssl.ControlChannelPolicy = ControlChannelPolicy.SslAllow;
            iisFtpSite.Security.Ssl.DataChannelPolicy    = DataChannelPolicy.SslAllow;

            this.FillIisFromFtpSite(site);

            this.ftpSitesService.CommitChanges();

            // Do not start the site because it is started during creation.
            try
            {
                this.ChangeSiteState(site.Name, ServerState.Started);
            }
            catch
            {
                // Ignore the error if happened.
            }
            return(site.Name);
        }
Пример #28
0
        private FtpSite LoadDomain(string domainName, out ServerState siteState)
        {
            siteState = ServerState.Started;

            NameValueCollection dict = ReadSettingsFile(GetDomainSettingsPath(domainName));

            if (dict == null)
            {
                return(null);
            }

            // process domain settings
            FtpSite site = new FtpSite();

            site.Name   = domainName;
            site.SiteId = domainName;

            ArrayList bindings = new ArrayList();

            foreach (string key in dict.Keys)
            {
                string val = dict[key];

                // check for binding
                if (key.ToUpper().StartsWith("IP"))
                {
                    bool numbers = true;
                    for (int i = 2; i < key.Length; i++)
                    {
                        if (!Char.IsNumber(key[i]))
                        {
                            numbers = false;
                            break;
                        }
                    }

                    if (numbers)
                    {
                        // process binding
                        string[] bindParts = val.Split(',');
                        bindings.Add(new ServerBinding(((bindParts[0] == "*") ? "" : bindParts[0]),
                                                       bindParts[1], ""));
                    }
                }
            }

            // set bindings
            site.Bindings = (ServerBinding[])bindings.ToArray(typeof(ServerBinding));

            // status
            string domainStatus = dict["Status"];

            switch (domainStatus)
            {
            case "0": siteState = ServerState.Started; break;

            case "1": siteState = ServerState.Paused; break;

            case "2": siteState = ServerState.Stopped; break;

            default: siteState = ServerState.Started; break;
            }

            return(site);
        }
Пример #29
0
        private void SaveDomain(FtpSite site, ServerState state)
        {
            StringBuilder sb = new StringBuilder();

            // append header
            sb.Append("[Domain]\n");

            // build IP bindings
            if (site.Bindings != null)
            {
                for (int i = 0; i < site.Bindings.Length; i++)
                {
                    ServerBinding binding = site.Bindings[i];
                    sb.Append("IP").Append(i).Append("=")
                    .Append((binding.IP == "" || binding.IP == "*") ? "*" : binding.IP).Append(",")
                    .Append(binding.Port).Append(",\n");
                }
            }

            // site state
            string domainStatus = "0"; // online "1" - closed, "2" - offline

            switch (state)
            {
            case ServerState.Continuing: domainStatus = "0"; break; // online

            case ServerState.Paused: domainStatus = "1"; break;     // closed

            case ServerState.Started: domainStatus = "0"; break;    // online

            case ServerState.Stopped: domainStatus = "2"; break;    // offline

            default: domainStatus = "0"; break;                     // online
            }

            sb.Append("Status=").Append(domainStatus).Append("\n");

            // footer (default settings)
            sb.Append(@"LogList0=Default,W3C,""-1,$DOM_NAME-$year-$mm-$dd.log,0""
LogList1=Transfers,W3C,""-1,$DOM_NAME-$year-$mm-$dd.log,0""
LogList2=Bandwidth,W3C,""-1,$DOM_NAME-$year-$mm-$dd.log,0""
MaxClients=0
MaxConnectionsPerIP=0
Running=1392
StatsCurrentlyLogged=0
CanDeleteReadOnly=-1
ChangeDataIPDependingOnClientIP=-1
DontLimitSpeedForLAN=-1
DontLimitTransferForLAN=-1
HammerResetOnLogin=-1
LogCacheEnabled=-1
LogEnabled=-1
NoCompressionForLAN=-1
ResolveIP=-1
TransferLimitType=never");

            // save domain file
            WriteTextFile(GetDomainSettingsPath(site.Name), sb.ToString());

            // flush cache
            FlushCache();
        }
Пример #30
0
 /// <remarks/>
 public System.IAsyncResult BeginUpdateSite(FtpSite site, System.AsyncCallback callback, object asyncState)
 {
     return(this.BeginInvoke("UpdateSite", new object[] {
         site
     }, callback, asyncState));
 }