示例#1
0
        private void dataGridView_RowPrePaint(object sender, DataGridViewRowPrePaintEventArgs e)
        {
            DataGridViewRow         row         = dataGridView.Rows[e.RowIndex];
            DataGridViewTextBoxCell nameCell    = (DataGridViewTextBoxCell)row.Cells[NameColumn.Name];
            WebsiteHost             websiteHost = (WebsiteHost)row.DataBoundItem;

            if (websiteHost.Protocol == WebsiteHostProtocol.Https)
            {
                nameCell.Style.BackColor = SystemColors.Control;
            }
            else
            {
                nameCell.Style.BackColor = SystemColors.Window;
            }

            //DataGridViewRow row = dataGridView.Rows[e.RowIndex];
            //WebsiteHost websiteHost = (WebsiteHost)row.DataBoundItem;
            //DataGridViewTextBoxCell nameCell = (DataGridViewTextBoxCell)row.Cells[NameColumn.Name];
            //DataGridViewCheckBoxCell primaryCell = (DataGridViewCheckBoxCell)row.Cells[PrimaryColumn.Name];

            //if (lastKnownMode == DataEditorMode.Update)
            //{
            //    primaryCell.Style.BackColor = SystemColors.Control;
            //    if (websiteHost.Primary)
            //    {
            //        nameCell.Style.BackColor = SystemColors.Control;
            //    }
            //}
        }
        private bool isValidPrimaryHost(WebsiteHost h)
        {
            bool b = (h.Port == WebsiteHost.DefaultHttpPort) &&
                     (h.Protocol == WebsiteHostProtocol.Http);

            return(b);
        }
示例#3
0
        public bool ExistsWithAnyHost(
            Website checkWebsite,
            out WebsiteHost[] conflictArray)
        {
            var q = from host in
                    // Check all sites except this one.
                    from website in GetAll()
                    where website.DataID != checkWebsite.DataID
                    select website.HostArray
                    where host.Any(h1 => checkWebsite.HostArray.Any(
                                       h2 => (!WebsiteHost.IsDeleteOrDiscard(h2) && hostsEqual(h1, h2))))
                    select host;

            if (q.Count() != 0)
            {
                // Select the first found host of the first range.
                conflictArray = q.First().ToArray();
                return(true);
            }
            else
            {
                conflictArray = new WebsiteHost[0];
                return(false);
            }
        }
示例#4
0
 private void deleteWebsiteHost(WebsiteHost websiteHost)
 {
     if (GetDataSchemaVersion <WebsiteHost>(websiteHost.DataID) >= 2)
     {
         HostingConfig.Delete <WebsiteHost>(websiteHost.DataID);
     }
 }
示例#5
0
        private bool hostsEqual(WebsiteHost h1, WebsiteHost h2)
        {
            string h1Name = string.IsNullOrEmpty(h1.Name) ? string.Empty : h1.Name;
            string h2Name = string.IsNullOrEmpty(h2.Name) ? string.Empty : h2.Name;

            return((h1Name == h2Name) &&
                   (h1.Port == h2.Port) &&
                   (h1.IpAddress == h2.IpAddress) &&
                   (h1.Protocol == h2.Protocol));
        }
示例#6
0
        private void addButton_Click(object sender, EventArgs e)
        {
            WebsiteHost host = new WebsiteHost(RhspDataID.Generate());

            host.PendingAction = ChildPendingAction.Create;
            host.Port          = WebsiteHost.DefaultHttpPort;
            host.IpAddress     = IpAddressArray.FirstOrDefault();

            hostList.Add(host);
            hostBindingList.Add(host);
            hostBindingList.ResetBindings();

            ChangeMade();

            selectGridViewRow(dataGridView.Rows.Cast <DataGridViewRow>().Last().Index);
            dataGridView.BeginEdit(false);
        }
示例#7
0
        private void processWebsiteHost(WebsiteHost h)
        {
            switch (h.PendingAction)
            {
            case ChildPendingAction.Create:
                HostingConfig.Create(h);
                break;

            case ChildPendingAction.Update:
                HostingConfig.Update(h);
                break;

            case ChildPendingAction.Delete:
                HostingConfig.Delete <WebsiteHost>(h.DataID);
                break;
            }
        }
示例#8
0
        private void dataGridView_CellValueChanged(object sender, DataGridViewCellEventArgs e)
        {
            ChangeMade();

            if (e.RowIndex != -1)
            {
                WebsiteHost host = (WebsiteHost)dataGridView.Rows[e.RowIndex].DataBoundItem;
                if (host.PendingAction != ChildPendingAction.Create)
                {
                    host.PendingAction = ChildPendingAction.Update;
                }

                if (e.ColumnIndex == dataGridView.Columns[ProtocolColumn.Name].Index)
                {
                    // If protocol changed from http to https.
                    if (host.Protocol == WebsiteHostProtocol.Https)
                    {
                        // Only change if non-custom port.
                        if (host.Port == WebsiteHost.DefaultHttpPort)
                        {
                            host.Port = WebsiteHost.DefaultHttpsPort;

                            // Secure sites are bound to IPs, not hostnames.
                            host.Name = string.Empty;
                        }
                    }
                    else
                    {
                        // Only change if non-custom port.
                        if (host.Port == WebsiteHost.DefaultHttpsPort)
                        {
                            host.Port = WebsiteHost.DefaultHttpPort;
                        }
                    }
                }
            }
        }
示例#9
0
 private void removeWebsiteHost(WebsiteHost host)
 {
     RhspData.SetDeleteOrDiscard(host);
     hostBindingList.Remove(host);
 }
示例#10
0
        void SettingsPage_AfterNextAsync(object sender, RunWorkerCompletedEventArgs e)
        {
            List <SecurityTemplate> stList      = new List <SecurityTemplate>();
            List <WebsiteHost>      hostList    = new List <WebsiteHost>();
            List <DnsZone>          dnsZoneList = new List <DnsZone>();
            string iisRedirectUrl = string.Empty;

            //Website.Name = hostNameTextBox.Text;

            if (iisEnableCheckBox.Checked)
            {
                if (iisStandardRadioButton.Checked)
                {
                    Website.IisSite.Mode = WebsiteIisMode.Standard;
                }

                if (iisRedirectRadioButton.Checked)
                {
                    Website.IisSite.Mode = WebsiteIisMode.Redirect;
                    iisRedirectUrl       = iisRedirectTextBox.Text;
                }

                // Only create security template when there will be a directory to use.
                SecurityTemplate securityTemplate = new SecurityTemplate(RhspDataID.Generate());
                securityTemplate.PendingAction  = ChildPendingAction.Create;
                securityTemplate.RelativePath   = "\\";
                securityTemplate.Read           = true;
                securityTemplate.Access         = SecurityTemplateAccess.Allow;
                securityTemplate.UseIisIdentity = true;
                stList.Add(securityTemplate);
            }
            else
            {
                Website.IisSite.Mode = WebsiteIisMode.Disabled;
            }

            WebsiteHost primaryHost = new WebsiteHost(RhspDataID.Generate());

            primaryHost.PendingAction = ChildPendingAction.Create;
            primaryHost.Port          = getIisPort();
            primaryHost.Name          = hostNameTextBox.Text;
            primaryHost.IpAddress     = (string)iisIpBindingSource.Current;
            //primaryHost.Primary = true;
            Website.PrimaryHostID = primaryHost.DataID;
            hostList.Add(primaryHost);

            if (wwwHostNameCheckBox.Checked)
            {
                WebsiteHost wwwHost = new WebsiteHost(RhspDataID.Generate());
                wwwHost.PendingAction = ChildPendingAction.Create;
                wwwHost.Port          = getIisPort();
                wwwHost.Name          = "www." + primaryHost.Name;
                wwwHost.IpAddress     = primaryHost.IpAddress;
                hostList.Add(wwwHost);
            }

            if (dnsCreateRadioButton.Checked)
            {
                List <DnsRecord> recordList = new List <DnsRecord>();

                DnsZone zone = new DnsZone(RhspDataID.Generate());
                zone.PendingAction = ChildPendingAction.Create;
                zone.Name          = hostNameTextBox.Text;
                zone.DefaultTtl    = "1h";
                dnsZoneList.Add(zone);

                foreach (string dnsServer in dnsServerArray)
                {
                    DnsRecord nsRecord = new DnsRecord(RhspDataID.Generate());
                    nsRecord.PendingAction = ChildPendingAction.Create;
                    nsRecord.Name          = "@";
                    nsRecord.RecordType    = DnsRecordType.NS;
                    nsRecord.Value         = dnsServer;
                    recordList.Add(nsRecord);
                }

                DnsRecord rootRecord = new DnsRecord(RhspDataID.Generate());
                rootRecord.PendingAction = ChildPendingAction.Create;
                rootRecord.Name          = "@";
                rootRecord.RecordType    = DnsRecordType.A;
                rootRecord.Value         = (string)dnsIpBindingSource.Current;
                recordList.Add(rootRecord);

                if (wwwHostNameCheckBox.Checked)
                {
                    DnsRecord wwwRecord = new DnsRecord(RhspDataID.Generate());
                    wwwRecord.PendingAction = ChildPendingAction.Create;
                    wwwRecord.Name          = "www";
                    wwwRecord.RecordType    = DnsRecordType.CNAME;
                    wwwRecord.Value         = "@";
                    recordList.Add(wwwRecord);
                }

                zone.RecordArray = recordList.ToArray();
            }

            Website.HostArray           = hostList.ToArray();
            Website.SecurityArray       = stList.ToArray();
            Website.DnsZoneArray        = dnsZoneList.ToArray();
            Website.IisSite.RedirectUrl = iisRedirectUrl;
        }
示例#11
0
 private static void upgradeVersion1Host(WebsiteHost h)
 {
     h.DataID        = RhspDataID.Generate();
     h.PendingAction = ChildPendingAction.Create;
 }
        public HostSiteCommand(Website website)
        {
            Tasks = new Queue<CassiniTask>();

            Tasks.Enqueue(
                new CassiniTask
                    {
                        Text = "Validating input..",
                        Argument = website,
                        Work = (arg) =>
                                   {
                                       if (!new WebsiteHost(website).IsPortUsable())
                                       {
                                           Cancel(new PortInUseException());
                                       }

                                       if(App.WebSiteHosts.ContainsKey(website.Url))
                                       {
                                           Cancel(new WebsiteExistsAtTheSameUrl());
                                       }

                                       return CassiniTaskResult.NoResult;
                                   }
                    });

            Tasks.Enqueue(
                new CassiniTask
                {
                    Text = "Creating website..",
                    Argument = website,
                    Work = (arg) =>
                    {
                        var host = new WebsiteHost(website);

                        if(website.IsRunning)
                            host.Start();

                        App.WebSiteHosts.Add(website.Url, host);

                        return CassiniTaskResult.NoResult;
                    }
                });

            Tasks.Enqueue(
                new CassiniTask
                {
                    Text = "Setting up website..",
                    Argument = website,
                    Work = (arg) =>
                    {
                        App.RaiseEvent(EventKeys.WEBSITE_CREATED, this, new EventBrokerEventArgs(website));

                        return CassiniTaskResult.NoResult;
                    }
                });

            Tasks.Enqueue(
                new CassiniTask
                {
                    Text = "Writing to configuration file..",
                    Argument = website,
                    Work = (arg) =>
                    {
                        if(!App.Config.Websites.ContainsKey(website.Url))
                        {
                            App.Config.Websites.Add(website.Url, website.ToConfiguration());
                        }
                        else
                        {
                            App.Config.Websites[website.Url] = website.ToConfiguration();
                        }

                        App.SaveConfig();

                        return CassiniTaskResult.NoResult;
                    }
                });
        }
        public HostSiteCommand(Website website)
        {
            Tasks = new Queue <CassiniTask>();

            Tasks.Enqueue(
                new CassiniTask
            {
                Text     = "Validating input..",
                Argument = website,
                Work     = (arg) =>
                {
                    if (!new WebsiteHost(website).IsPortUsable())
                    {
                        Cancel(new PortInUseException());
                    }

                    if (App.WebSiteHosts.ContainsKey(website.Url))
                    {
                        Cancel(new WebsiteExistsAtTheSameUrl());
                    }

                    return(CassiniTaskResult.NoResult);
                }
            });

            Tasks.Enqueue(
                new CassiniTask
            {
                Text     = "Creating website..",
                Argument = website,
                Work     = (arg) =>
                {
                    var host = new WebsiteHost(website);

                    if (website.IsRunning)
                    {
                        host.Start();
                    }

                    App.WebSiteHosts.Add(website.Url, host);

                    return(CassiniTaskResult.NoResult);
                }
            });

            Tasks.Enqueue(
                new CassiniTask
            {
                Text     = "Setting up website..",
                Argument = website,
                Work     = (arg) =>
                {
                    App.RaiseEvent(EventKeys.WEBSITE_CREATED, this, new EventBrokerEventArgs(website));

                    return(CassiniTaskResult.NoResult);
                }
            });

            Tasks.Enqueue(
                new CassiniTask
            {
                Text     = "Writing to configuration file..",
                Argument = website,
                Work     = (arg) =>
                {
                    if (!App.Config.Websites.ContainsKey(website.Url))
                    {
                        App.Config.Websites.Add(website.Url, website.ToConfiguration());
                    }
                    else
                    {
                        App.Config.Websites[website.Url] = website.ToConfiguration();
                    }

                    App.SaveConfig();

                    return(CassiniTaskResult.NoResult);
                }
            });
        }