Exemplo n.º 1
0
        private void ReSetRights(object state)
        {
            string[]       parms      = (string[])state;
            string         siteNum    = parms[0];
            string         WebPath    = parms[1];
            Operator       iisAdmin   = new Operator();
            DirectoryEntry chdenEntry = iisAdmin.GetDirectoryBySite(siteNum, true);
            string         UserName   = chdenEntry.Properties["AnonymousUserName"][0].ToString();

            FileSystemRights rights = FileSystemRights.Read
                                      | FileSystemRights.Write
                                      | FileSystemRights.ReadAndExecute
                                      | FileSystemRights.ListDirectory
                                      | FileSystemRights.Modify;



            bool   addRights = NTFSControl.AddDirectorySecurity(WebPath, UserName, rights);
            string msg       = "权限重设成功。";

            if (!addRights)
            {
                msg = "权限重设失败。";
            }
            Invoke(new ShowAppState(SetAppState), true);
            Invoke(new AlertDelegate(CallMessageBox), new object[] { new string[] { msg, "重设权限" } });
        }
Exemplo n.º 2
0
        /// <summary>
        ///  删除一个网站。
        /// </summary>
        /// <param name="siteNum">网站ID</param>
        public bool DeleteWebSiteByName(string siteNum)
        {
            try
            {
                DirectoryEntry siteEntry = this.GetDirectoryBySite(siteNum);
                string         appName   = siteEntry.Properties["ServerComment"].Value.ToString() + "_AppPool";
                this.DeleteAppPool(appName);

                DirectoryEntry childEntry = this.GetDirectoryBySite(siteNum, true);
                string         userName   = childEntry.Properties["AnonymousUserName"][0].ToString();
                this.DelSysUser(userName);
                var dir = new DirectoryInfo(childEntry.Properties["Path"].Value.ToString());

                FileSystemRights rights = FileSystemRights.Read
                                          | FileSystemRights.Write
                                          | FileSystemRights.ReadAndExecute
                                          | FileSystemRights.ListDirectory
                                          | FileSystemRights.Modify;

                NTFSControl.RemoveDirectoryAccountSecurity(dir.Parent.FullName, userName, rights);
                childEntry.Close();

                string         rootPath  = String.Format("IIS://{0}/w3svc", this.HOSTNAME);
                DirectoryEntry rootEntry = GetDirectoryEntry(rootPath);
                rootEntry.Children.Remove(siteEntry);
                rootEntry.CommitChanges();
                rootEntry.Close();
                return(true);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "删除失败", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(false);
            }
        }
Exemplo n.º 3
0
        private void AddWebSite(object state)
        {
            SiteParms parms    = (SiteParms)state;
            string    ip       = parms.siteIP;
            string    doms     = parms.siteUrls;
            string    strName  = parms.siteName;
            string    sitepath = parms.webFilePath;

            if (sitepath == "" || doms == "" || sitepath == "")
            {
                string[] s = new string[] { "必要项没填写完整!\r\n1、网站名称。\r\n2、网站域名。\r\n3、本地路径。", "建立网站" };
                Invoke(new AlertDelegate(CallMessageBox), new object[] { s });
                return;
            }
            Invoke(new ShowAppState(SetAppState), false);
            Operator      iisAdmin = new Operator();
            List <string> dom      = new List <string>();

            string[] arr = doms.Split(new char[] { '\r' });
            foreach (string val in arr)
            {
                if (val != "")
                {
                    dom.Add(val.Replace("\n", ""));
                }
            }
            iisAdmin.WebName = strName;
            iisAdmin.WebPath = sitepath;
            iisAdmin.LogFile = parms.logFilePath;
            iisAdmin.Domain  = dom;
            iisAdmin.HostIP  = (ip.CompareTo("(全部未分配IP)") == 0) ? "" : ip;
            bool addWeb = iisAdmin.CreateNewWebSite();

            if (!addWeb)
            {
                string[] s = new string[] { "添加虚拟目录时发生错误,网站没有建立成功。", "建立网站" };
                Invoke(new AlertDelegate(CallMessageBox), new object[] { s });
                return;
            }
            string pwd     = iisAdmin.WebPassword;
            string uid     = iisAdmin.WebUserName;
            bool   addUser = iisAdmin.NewSysUser(uid, pwd);

            if (!addUser)
            {
                //MessageBox.Show(this, "添加IIS用户时发生错误,没有顺利完成。", "添加用户", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                //return;
            }

            FileSystemRights rights = FileSystemRights.Read
                                      | FileSystemRights.Write
                                      | FileSystemRights.ReadAndExecute
                                      | FileSystemRights.ListDirectory
                                      | FileSystemRights.Modify;

            bool addRights = NTFSControl.AddDirectorySecurity(sitepath, uid, rights);

            if (!addRights)
            {
                //MessageBox.Show(this, "添加文件夹权限时发生错误,没有顺利完成。", "附加权限", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                //return;
            }

            //LogFilePath.Text = sitePath.Text = webName.Text = Address.Text = "";
            iisAdmin = null;
            this.RefreshGridView();
        }