Example #1
0
 /* Add/Remove VirtualHosts/Aliases/Directories */
 public int AddUpdateVirtualHost(VirtualHost VH)
 {
     if (VH.VHostID > 0)
     {
         try
         {
             return(Globals.dbConn.ExecuteNonQuery("UPDATE VirtualHosts SET " +
                                                   "DocumentRoot = '" + VH.DocumentRoot + "', " +
                                                   "ServerName = '" + VH.ServerName + "', " +
                                                   "ServerAlias = '" + VH.ServerAlias + "', " +
                                                   "IP = '" + VH.IP + "', " +
                                                   "Port = " + VH.Port + ", " +
                                                   "Others = '" + VH.Others + "' " +
                                                   "WHERE VHostID = " + VH.VHostID));
         }
         catch (Exception /*ex*/)
         {
             //Globals.Error.Show(ex.Message);
             return(-1);
         }
     }
     else
     {
         Globals.dbConn.ExecuteNonQuery("INSERT INTO VirtualHosts ('ServerName', 'IP', 'Port', 'DocumentRoot') VALUES ('" + VH.ServerName + "', '" + VH.IP + "', " + VH.Port + ", '" + VH.DocumentRoot + "')");
         return(Convert.ToInt32(Globals.dbConn.ExecuteScalar("SELECT MAX(VHostID) from VirtualHosts")));
     }
 }
        private void AddServer_Click(object sender, EventArgs e)
        {
            VirtualHost newVHost = new VirtualHost();

            newVHost.ServerName   = "New virtual server";
            newVHost.IP           = "*";
            newVHost.Port         = "80";
            newVHost.DocumentRoot = Globals.AppFolder;

            newVHost.VHostID = this.Database.AddUpdateVirtualHost(newVHost);

            Globals.VHosts.Add(newVHost);

            this.ServerList.Items.Add(newVHost.ServerName);
            this.ServerList.SelectedIndex = this.ServerList.Items.Count - 1;
        }
Example #3
0
        public void LoadVirtualHosts()
        {
            Globals.VHosts.Clear();

            // Load Virtual Hosts info from database.
            DataTable DBVHosts = Globals.dbConn.GetDataTable("SELECT * FROM VirtualHosts");

            foreach (DataRow rowVH in DBVHosts.Rows)
            {
                VirtualHost VH = new VirtualHost();

                foreach (DataColumn colVH in DBVHosts.Columns)
                {
                    try
                    {
                        PropertyInfo pi = VH.GetType().GetProperty(colVH.ToString());
                        pi.SetValue(VH, Convert.ChangeType(rowVH[colVH], pi.PropertyType), null);
                        //Object collection = pi.GetValue(VH, null);
                    }
                    catch (Exception /*ex*/)
                    {
                        //Globals.Error.Show("Column: " + colVH.ToString() + "\r\nContent: " + rowVH[colVH].ToString() + "\r\n" + ex.Message);
                    }
                }

                // Load Aliases info for each Virtual Host from database.
                DataTable DBAliases = Globals.dbConn.GetDataTable("SELECT * FROM Aliases WHERE VHostID = " + rowVH["VHostID"].ToString());

                foreach (DataRow rowAl in DBAliases.Rows)
                {
                    Aliases Alias = new Aliases();
                    foreach (DataColumn colAl in DBAliases.Columns)
                    {
                        try
                        {
                            PropertyInfo pi = Alias.GetType().GetProperty(colAl.ToString());
                            pi.SetValue(Alias, Convert.ChangeType(rowAl[colAl], pi.PropertyType), null);
                        }
                        catch (Exception)
                        {
                        }
                    }

                    VH.Alias.Add(Alias);
                }

                // Load Directories info for each Virtual Host from database.
                DataTable DBDirectories = Globals.dbConn.GetDataTable("SELECT * FROM Directories WHERE VHostID = " + rowVH["VHostID"].ToString());

                foreach (DataRow rowDir in DBDirectories.Rows)
                {
                    Directories Directory = new Directories();
                    foreach (DataColumn colDir in DBDirectories.Columns)
                    {
                        try
                        {
                            PropertyInfo pi = Directory.GetType().GetProperty(colDir.ToString());
                            pi.SetValue(Directory, Convert.ChangeType(rowDir[colDir], pi.PropertyType), null);
                        }
                        catch (Exception)
                        {
                        }
                    }

                    VH.Directory.Add(Directory);
                }

                Globals.VHosts.Add(VH);
            }
        }