Esempio n. 1
0
        //创建站点
        protected void CSWSBtn_Click(object sender, EventArgs e)
        {
            IISWebSite webSite = new IISWebSite(CSWebName.Text.Trim(), CSPort.Text.Trim(), CSPhysicalPath.Text.Trim(), CSDomain.Text.Trim(), CSAppPool.Text.Trim());

            if (webSite.CheckIsValid())
            {
                if (!iisHelper.CreateSite(webSite))
                {
                    Page.ClientScript.RegisterStartupScript(this.GetType(), "", "alert('创建失败,站点名存在或信息填写错误.');", true);
                }
                if (string.IsNullOrEmpty(Request.Form["chk"]))//不立即启动站点
                {
                    iisHelper.StopSite(webSite.SiteName);
                }
                iisHelper.SyncDB();//创建站点时,同步下数据库
                Page.ClientScript.RegisterStartupScript(this.GetType(), "", "disParent('SiteCloudSetup.aspx?SiteName=" + webSite.SiteName + "');", true);
            }
            else
            {
                Page.ClientScript.RegisterStartupScript(this.GetType(), "", "alert('信息不完整,无法创建');", true);
            }
            if (!string.IsNullOrEmpty(Request.Form["sitePort"]) && !string.IsNullOrEmpty(Request.Form["Domain"]))//批量绑定信息
            {
                string[] sitePort = Request.Form["sitePort"].Split(',');
                string[] domain   = Request.Form["Domain"].Split(',');
                for (int i = 0; i < sitePort.Length && i < domain.Length; i++)
                {
                    Binding b = iis.Sites[webSite.SiteName].Bindings.CreateElement();
                    b.Protocol           = "Http";
                    b.BindingInformation = "*:" + sitePort[i] + ":" + domain[i];
                    iisHelper.AddSiteBindInfo(webSite.SiteName, b);
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        ///     Marca para fechar a vigencia das aplicações especificadas
        /// </summary>
        /// <param name="iisWebSite"></param>
        private void MarkToDeleteIISApplicationsFromWebSite([NotNull] IISWebSite iisWebSite)
        {
            IQueryable <IISApplication> applications =
                _uow.IISApplicationRepository.List().Where(e => e.Idiiswebsite == iisWebSite.IISWebSiteId);

            MarkToDeleteIISApplications(applications);
        }
Esempio n. 3
0
        /// <summary>
        ///     Gera os IIS Websites para inserção
        /// </summary>
        /// <param name="foundIISWebSites"></param>
        /// <returns></returns>
        private IEnumerable <IISWebSite> GenerateIISWebSite([NotNull] IEnumerable <FoundIISWebSite> foundIISWebSites)
        {
            var newIisWebSites = new List <IISWebSite>();
            IEnumerable <int>        idsOfFoundIISWebSites    = ListIdsOfGetIdsOfFoundIISWebSites(foundIISWebSites);
            IEnumerable <IISWebSite> webSitesThatAlreadyExist = ListIISWebSitesThatAlreadyExist(foundIISWebSites);
            IEnumerable <int>        newOnes =
                idsOfFoundIISWebSites.Except(webSitesThatAlreadyExist.Select(e => e.IISWebSiteId));

            foreach (var idfoundIisWebSite in newOnes)
            {
                var foundIisWebsite = foundIISWebSites.First(s => s.IISId == idfoundIisWebSite);
                var newIISWebSite   = new IISWebSite
                {
                    Namewebsite  = foundIisWebsite.Namewebsite,
                    Apppollname  = foundIisWebsite.Apppollname,
                    Creationdate = DateTime.Now,
                    IISWebSiteId = (int)foundIisWebsite.IISId,
                    Iislogpath   = foundIisWebsite.IISLogPath,
                    PhysicalPath = foundIisWebsite.PhysicalPath
                };
                newIisWebSites.Add(newIISWebSite);

                if (foundIisWebsite.IISApplications != null)
                {
                    InsertNewIISApplicationsFor(newIISWebSite, foundIisWebsite.IISApplications);
                }
            }

            return(newIisWebSites);
        }
Esempio n. 4
0
        private void UpdateApplicationsFromExistingIISWebsite([NotNull] IISWebSite iisWebSite,
                                                              [NotNull] IEnumerable <FoundIISApplication> iisApplications)
        {
            IQueryable <IISApplication> existingApplicationsFromIisWebsite =
                _uow.IISApplicationRepository.List().Where(a => a.Idiiswebsite == iisWebSite.Idiiswebsite);
            IQueryable <string> nameExistingApps           = existingApplicationsFromIisWebsite.Select(e => e.Logicalpath);
            IQueryable <string> nameOfFoundIisApplications =
                iisApplications.Select(e => e.ApplicationName).AsQueryable();
            IQueryable <string> toDelete = nameExistingApps.Except(nameOfFoundIisApplications);

            IQueryable <IISApplication> appsToDelete =
                existingApplicationsFromIisWebsite.Where(e => toDelete.Contains(e.Logicalpath));

            MarkToDeleteIISApplications(appsToDelete);
        }
Esempio n. 5
0
 //物理路径
 public bool UpdateConfig(IISWebSite site)
 {
     try
     {
         string      ppath  = site.PhysicalPath + @"Config\Site.config";
         XmlDocument xmlDoc = new XmlDocument();
         xmlDoc.Load(ppath);
         XmlNode tempDirNode = xmlDoc.SelectSingleNode("//SiteConfig/SiteOption/TemplateDir"); //  /Template/V3
         XmlNode cssDirNode  = xmlDoc.SelectSingleNode("//SiteConfig/SiteOption/CssDir");      //        /Template/V3/style
         tempDirNode.InnerText = "/Template/" + site.TempDir;
         cssDirNode.InnerText  = "/Template/" + site.TempDir + "/style";
         xmlDoc.Save(ppath);
         return(true);
     }
     catch { return(false); }
 }
Esempio n. 6
0
    /// <summary>
    /// 返回站点模型,包含站点所有信息
    /// </summary>
    public IISWebSite GetSiteModel(string siteName)
    {
        IISWebSite siteModel = new IISWebSite();

        siteModel.SiteName = siteName;
        siteModel.SiteID   = iis.Sites[siteName].Id.ToString();
        siteModel.State    = iis.Sites[siteName].State.ToString();
        siteModel.AppPool  = iis.Sites[siteName].Applications[0].ApplicationPoolName;
        foreach (Binding b in iis.Sites[siteName].Bindings)
        {
            siteModel.BindInfoList.Add(b.BindingInformation);
        }
        foreach (VirtualDirectory v in iis.Sites[siteName].Applications[0].VirtualDirectories)
        {
            siteModel.PhysicalPathList.Add(v.PhysicalPath);
        }
        return(siteModel);
    }
Esempio n. 7
0
        private void InsertNewIISApplicationsFor([NotNull] IISWebSite newIISWebSite,
                                                 [NotNull] IEnumerable <FoundIISApplication> applications)
        {
            IEnumerable <IISApplication> newApplications = applications.Select(e => new IISApplication
            {
                Iiswebsite   = newIISWebSite,
                Apppollname  = e.AppPoolName,
                Creationdate = DateTime.Now,
                Iislogpath   = newIISWebSite.Iislogpath,
                Physicalpath = e.PhysicalPath,
                Logicalpath  = e.IISLogicalPath
            });

            RaiseOnEntityParsed <IISApplication>();
            foreach (var newApplication in newApplications)
            {
                _uow.IISApplicationRepository.Add(newApplication);
            }
        }
        protected void Update(int rowNum, string id)//Update WebSite with index=0,Name,Port,PPath,Domain
        {
            IISWebSite  site = new IISWebSite();
            GridViewRow gr   = EGV.Rows[rowNum];

            site.SiteName = ((TextBox)gr.FindControl("EditSiteName")).Text.Trim();
            site.Port     = ((TextBox)gr.FindControl("EditPort")).Text.Trim();
            //site.PhysicalPath = ((TextBox)gr.FindControl("EditPhySicalPath")).Text.Trim();
            //site.DomainName = ((TextBox)gr.FindControl("EditDomain")).Text.Trim();
            IISHelper iisM = new IISHelper();
            DataTable dt   = iisM.GetWebSiteList();

            dt.DefaultView.RowFilter = "SiteID=" + id;
            DataRow dr = dt.DefaultView.ToTable().Rows[0];

            //-----有更改才更新,先更新域名
            if (!(dr["SiteName"] as string).Equals(site.SiteName))
            {
                iisHelper.ChangeSiteName(dr["SiteName"] as string, site.SiteName);
            }
            if (!(dr["SitePort"] as string).Equals(site.Port))
            {
                iisHelper.ChangeSitePort(site.SiteName, site.Port);
            }
            //if (!(dr["PhysicalPath"] as string).Equals(site.PhysicalPath))
            //    iisHelper.ChangeSitePath(site.SiteName, site.PhysicalPath);
            //if (!(dr["Domain"] as string).Equals(site.DomainName))
            //    iisHelper.ChangeSiteDomain(site.SiteName, site.DomainName);

            B_Site_SiteList siteBll   = new B_Site_SiteList();
            M_Site_SiteList siteModel = new M_Site_SiteList();

            siteModel         = siteBll.SelBySiteID(id);
            siteModel.EndDate = DataConvert.CDate(((TextBox)gr.FindControl("EditEndDate")).Text.Trim());
            siteBll.UpdateModel(siteModel);
            Page.ClientScript.RegisterStartupScript(this.GetType(), "", "alert('修改完成');location=location;", true);
        }
        //本地获取信息
        public void GetInfoLocal()
        {
            siteModel        = iisHelper.GetSiteModel(siteName);
            Name.Text        = siteModel.SiteName;
            siteAppPool.Text = siteModel.AppPool;

            lName.Text     = siteModel.SiteName;
            lSitePool.Text = siteModel.AppPool;
            string bind  = "";
            string lbind = "";

            for (int i = 0; i < siteModel.BindInfoList.Count; i++)
            {
                string[] temp = siteModel.BindInfoList[i].Split(':');
                if (i < 1)//第一行不显示移除,即最少要一行
                {
                    bind += "<tr><td>绑定信息:</td><td>";
                }
                else
                {
                    bind += "<tr><td>绑定信息:<a href='javascript:' onclick='remove(this)' title='移除'><i class='fa fa-remove'></i></a></td><td>";
                }

                bind += "<label style='float:left; display:block; width:50px;'>IP:</label><input type='text' name='siteIP'  class='form-control' style='width:150px;'   maxlength='15'  txt='IP不能为空' value='" + temp[0] + "' list='ipList'/>";
                bind += "<label style='float:left; display:block; width:50px;'>端口:</label>";
                bind += "<input type='text' name='sitePort' class='form-control'  maxlength='6'  txt='端口不能为空' style='width:150px;' value='" + temp[1] + "'/> ";
                bind += "<label style='float:left; display:block; width:50px;'>域名:</label><input type='text' name='Domain' style='width:150px;' class='form-control' txt='域名不能为空' value='" + temp[2] + "'/>";
                bind += "</td></tr>";

                //-----ReadOnly
                lbind     += "<tr'><td>绑定信息:</td><td><label>IP:" + temp[0] + "</label><br/>";
                lbind     += "<label >端口:" + temp[1] + "</label><br/>";
                lbind     += "<label >域名:" + temp[2] + "</label>";
                lbind     += "</td></tr>";
                sitePort   = temp[1];
                siteDomain = temp[2];
            }
            string path  = "";
            string lpath = "";

            foreach (string p in siteModel.PhysicalPathList)
            {
                path += "<tr><td>物理路径:</td><td>";
                path += "<input name='PPath' type='text' value='" + p + "' class='form-control text_md' maxlength='80' style='width:200px;' txt='物理路径为空'/>";
                path += "</td></tr>";

                lpath += "<tr><td>物理路径:</td><td>";
                lpath += "<label>" + p + "</label> ";
                lpath += "</td></tr>";
            }

            literalPath.Text = path;
            literalBind.Text = bind;
            labelPath.Text   = lpath;
            labelBind.Text   = lbind;

            siteM = siteBll.SelBySiteID(siteID); //如果无记录,则返回空
                                                 //------EditMode
            opSystem.Text            = enHelper.GetOSVersion();
            manageName.Text          = siteM == null ? "" : siteM.Remind;
            iisVersion.Text          = Request.ServerVariables["Server_SoftWare"].ToString();
            netVersion.SelectedValue = iis.ApplicationPools[appName].ManagedRuntimeVersion;
            runMode.SelectedValue    = iis.ApplicationPools[appName].ManagedPipelineMode.ToString();
            serverIP.Text            = enHelper.GetServerIP();
            //-----输出一个datalist服务于IP输入自动提示
            hideIPLiteral.Text = "<datalist id='ipList'><option>*</option>";
            foreach (string s in serverIP.Text.Split(','))
            {
                hideIPLiteral.Text += "<option>" + s + "</option>";
            }
            hideIPLiteral.Text += "</datalist>";
            //-----
            siteState.Text = iis.Sites[siteName].State == ObjectState.Started ? "运行中" : "已停止";
            ssBtn1.Text    = iis.Sites[siteName].State == ObjectState.Started ? "停止" : "启动";

            //------ReadOnly
            lOPSystem.Text = enHelper.GetOSVersion();
            lManager.Text  = (siteM == null || string.IsNullOrEmpty(siteM.SiteManager)) ? "尚未分配" : manageName.Text;
            //---颁发管理链接
            if (siteM != null)
            {
                string url      = Request.Url.AbsoluteUri;
                string userName = Server.UrlEncode(buser.GetUserByUserID(DataConverter.CLng(siteM.SiteManager)).UserName);
                Regex  re       = new Regex("(?<=(://))[.\\s\\S]*?(?=(/))", RegexOptions.IgnoreCase);
                url = re.Match(url).Value;

                manageID.Value     = "http://" + url + CustomerPageAction.customPath2 + "Site/Share.aspx?identity=" + userName;
                this.TextBox1.Text = manageID.Value;
                this.TextBox2.Text = manageID.Value;
            }

            lIISVersion.Text = Request.ServerVariables["Server_SoftWare"].ToString();
            lNetVersion.Text = iis.ApplicationPools[appName].ManagedRuntimeVersion;
            lRunMode.Text    = iis.ApplicationPools[appName].ManagedPipelineMode == ManagedPipelineMode.Classic ? "经典模式" : "集成模式";
            lServerIP.Text   = enHelper.GetServerIP();
            lSiteState.Text  = iis.Sites[siteName].State == ObjectState.Started ? "运行中" : "已停止";
            ssBtn2.Text      = iis.Sites[siteName].State == ObjectState.Started ? "停止" : "启动";

            try
            {
                //need Web.config
                errorPage1.Text = enHelper.GetCustomError(webPath, 403).Redirect;
                errorPage2.Text = enHelper.GetCustomError(webPath, 404).Redirect;
                errorPage3.Text = enHelper.GetCustomError(webPath, 500).Redirect;
                errorPage4.Text = enHelper.GetCustomError(webPath, 503).Redirect;

                lErrorPage1.Text = enHelper.GetCustomError(webPath, 403).Redirect;
                lErrorPage2.Text = enHelper.GetCustomError(webPath, 404).Redirect;
                lErrorPage3.Text = enHelper.GetCustomError(webPath, 500).Redirect;
                lErrorPage4.Text = enHelper.GetCustomError(webPath, 503).Redirect;
            }
            catch { }

            //------------------高级设置
            //---只读
            ApplicationPool appPool = iis.ApplicationPools[appName];

            lmaxCPULimit.Text      = appPool.Cpu.Limit.ToString();
            lconfigChange.Text     = appPool.Recycling.DisallowRotationOnConfigChange ? "是" : "否";
            lTimeSpanRecy.Text     = appPool.Recycling.PeriodicRestart.Time.TotalMinutes.ToString();
            lmaxMemory.Text        = (appPool.Recycling.PeriodicRestart.Memory / 1024).ToString();
            lmaxPrivateMemory.Text = (appPool.Recycling.PeriodicRestart.PrivateMemory / 1024).ToString();
            string[] defaultDoc = iisHelper.GetDefaultDocBySiteName(siteName);
            for (int i = 0; i < defaultDoc.Length; i++)
            {
                ldefaultDoc.Text += defaultDoc[i] + "<br />";
                edefaultDoc.Text += defaultDoc[i] + ",\r";//编辑状态
            }
            //---编辑
            emaxCPULimit.Text           = appPool.Cpu.Limit.ToString();
            econfigChange.SelectedValue = appPool.Recycling.DisallowRotationOnConfigChange.ToString();
            eTimeSpanRecy.Text          = appPool.Recycling.PeriodicRestart.Time.TotalMinutes.ToString();
            emaxMemory.Text             = (appPool.Recycling.PeriodicRestart.Memory / 1024).ToString();
            emaxPrivateMemory.Text      = (appPool.Recycling.PeriodicRestart.PrivateMemory / 1024).ToString();
        }
Esempio n. 10
0
        public void DownFileWork(int userID, HttpContext ct, string TempUrl, string TempZipFile, IISWebSite site)
        {
            string localTempDir = SiteConfig.SiteMapath() + "\\template\\";

            DownloadFile(TempUrl, TempZipFile, userID + "downTempP", ct); //下载模板
            UnzipFileWork(userID, ct, TempZipFile, localTempDir);         //解压
        }
Esempio n. 11
0
 //-----------站点创建与获取
 /// <summary>
 /// 创建一个新站点,注意如果端口相同,则新建的网站会停止
 /// </summary>
 public bool CreateSite(IISWebSite WebSite)
 {
     return(CreateSite(WebSite.SiteName, "http", "*:" + WebSite.Port + ":" + WebSite.DomainName, WebSite.PhysicalPath, WebSite.AppPool));//+WebSite.DomainName
 }
Esempio n. 12
0
        //application中标识,上下文,下载地址,本地物理路径
        public void DownFileWork(int userID, HttpContext ct, string sUrl, string tPath, IISWebSite site)
        {
            try
            {
                DownloadFile(sUrl, tPath, userID + "downCodeP", ct);                                  //下载源码
                UnzipFileWork(userID, ct, @site.PhysicalPath + "SourceCode.zip", @site.PhysicalPath); //解压

                string localTempZipFile = @site.PhysicalPath + "Template\\" + site.TempDir + ".zip";; //D:\Web\Site\Template\blue\
                string localTempDir     = @site.PhysicalPath + "Template\\";
                DownloadFile(site.TempUrl, localTempZipFile, userID + "downTempP", ct);               //下载模板
                UnzipFileWork(userID, ct, localTempZipFile, localTempDir);                            //解压

                UpdateConfig(site);                                                                   //更新配置
            }
            catch (Exception) { }
        }
Esempio n. 13
0
 //开始工作,下载,解压等
 public void BeginWork(IISWebSite site)
 {
     if (!string.IsNullOrEmpty(StationGroup.CodeSourceUrl) && GetFileSize(StationGroup.CodeSourceUrl) != -1)//未配置下载地址,则不允许操作
     {
         IdentityAnalogue ia = new IdentityAnalogue();
         if (!ia.CheckEnableSA(false))
         {
             dataInfo.InnerText = "错误800,请联系管理员!!!";
             CreateExLog("创建失败,未正确配置管理员信息,请联系管理员!!!");
             return;
         }
         if (!iisHelper.CreateSite(site))
         {
             dataInfo.InnerText = "错误801,请联系管理员!!!";
             CreateExLog("站点创建失败,站点同名或" + site.Port + "端口被占用,请联系管理员!!!");
             return;
         }
         dbMod.SiteName   = site.SiteName;
         dbMod.SiteID     = DataConverter.CLng(iisHelper.GetSiteModel(dbMod.SiteName).SiteID);
         dbMod.Status     = 1;
         dbMod.UserID     = buser.GetLogin().UserID;
         dbMod.UserName   = buser.GetLogin().UserName;
         dbMod.CreateTime = DateTime.Now;
         dbMod.Remind     = site.DomainName;
         #region 创建数据库
         if (StationGroup.AutoCreateDB)
         {
             if (!string.IsNullOrEmpty(StationGroup.DBManagerName) && !string.IsNullOrEmpty(StationGroup.DBManagerPasswd))//配置了数据库信息才会创建
             {
                 DBModHelper dbHelper   = new DBModHelper(StationGroup.DBManagerName, StationGroup.DBManagerPasswd);
                 M_UserInfo  userInfo   = buser.GetLogin();
                 string      dbName     = "Zdb_" + site.dbName;
                 string      dbUserName = dbName + "_" + userInfo.UserName;
                 string      dbPasswd   = function.GeneratePasswd();
                 //下载地址不可用,则终止,数据库创建失败,则仍继续,
                 try
                 {
                     if (dbHelper.DBIsExist(dbName) == 0)
                     {
                         dbHelper.CreateDatabase(dbName);
                         dbHelper.CreateDatabaseUser(dbUserName, dbPasswd);
                         dbHelper.CreateUserMap(dbName, dbUserName);
                         dataInfo.InnerText = "创建独立数据库成功:" + dbName + " 用户名:" + dbUserName + " 密码:" + dbPasswd;
                         dbMod.DBName       = dbName;
                         dbMod.DBUser       = dbUserName;
                         dbMod.DBInitPwd    = dbPasswd;
                     }
                     else
                     {
                         dataInfo.InnerText = "错误代码901:数据库未创建,请联系管理员!!!";//"创建独立数据库失败:" + dbName + "原因:数据库已存在,请联系管理员!!!"
                         CreateExLog("创建独立数据库失败:" + dbName + "原因:数据库已存在!!!");
                     }
                 }
                 catch (Exception ex)
                 {
                     dataInfo.InnerText = "错误代码902:数据库未创建,请联系管理员!!!";
                     CreateExLog("创建独立数据库失败:" + dbName + "原因:" + ex.Message);
                 }
             }
         }
         else
         {
             dataInfo.InnerText = "管理员未许可自动创建数据库,请联系管理员创建对应数据库!!!";
         }
         #endregion
         DownFile dw = DownFileWork;
         Application[buser.GetLogin().UserID + "downCodeT"] = GetFileSize(StationGroup.CodeSourceUrl);
         Application[buser.GetLogin().UserID + "downTempT"] = GetFileSize(site.TempUrl);
         dw.BeginInvoke(buser.GetLogin().UserID, HttpContext.Current, StationGroup.CodeSourceUrl, @site.PhysicalPath + "SourceCode.zip", site, null, null);
         dbBll.Insert(dbMod);
         Page.ClientScript.RegisterStartupScript(this.GetType(), "", "beginCheck('getCodeP');", true);
     }
     else
     {
         function.WriteErrMsg("下载地址:" + StationGroup.CodeSourceUrl + "无法访问,请联系管理员修复!!");
     }
 }
Esempio n. 14
0
 /// <summary>
 ///     Verifica se há campo para atualização
 /// </summary>
 /// <param name="foundIisWebsite"></param>
 /// <param name="iisWebSite"></param>
 /// <returns></returns>
 private static bool HasFieldToUpdate([NotNull] FoundIISWebSite foundIisWebsite, [NotNull] IISWebSite iisWebSite)
 {
     return(!string.Equals(foundIisWebsite.Namewebsite?.Trim(), iisWebSite.Namewebsite?.Trim(),
                           StringComparison.InvariantCultureIgnoreCase) ||
            !string.Equals(foundIisWebsite.PhysicalPath?.Trim(), iisWebSite.PhysicalPath?.Trim(),
                           StringComparison.InvariantCultureIgnoreCase) ||
            !string.Equals(foundIisWebsite.Apppollname?.Trim(), iisWebSite.Apppollname?.Trim(),
                           StringComparison.InvariantCultureIgnoreCase));
 }