Exemplo n.º 1
0
        void SetDefaultDataDirValue()
        {
            for (int i = 0; ; i++)
            {
                string strDateDir = "c:\\opac_data";
                if (i > 0)
                {
                    strDateDir = "c:\\opac_data_" + (i + 1).ToString();
                }

                // 已经存在的物理目录不能使用
                if (Directory.Exists(strDateDir) == true)
                {
                    continue;
                }

                // 注意检查,不能是别的instance的数据目录
                if (this.VerifyDataDir != null)
                {
                    VerifyEventArgs e1 = new VerifyEventArgs();
                    e1.Value = strDateDir;
                    this.VerifyDataDir(this, e1);
                    if (String.IsNullOrEmpty(e1.ErrorInfo) == false)
                    {
                        continue;
                    }
                }

                this.textBox_dataDir.Text = strDateDir;
                return;
            }
        }
Exemplo n.º 2
0
        private void verifyLevel2Authentication(SecureSocket socket,
                                                Certificate cert,
                                                CertificateChain chain,
                                                VerifyEventArgs e
                                                )
        {
            // Verify level 1 first
            verifyLevel1Authentication(socket, cert, chain, e);
            if (!e.Valid)
            {
                return;
            }

            CertificateStatus certStatus =
                chain.VerifyChain(null, AuthType.Client, VerificationFlags.IgnoreInvalidName);

            if (certStatus != CertificateStatus.ValidCertificate)
            {
                if ((Adk.Debug & AdkDebugFlags.Messaging_Detailed) != 0)
                {
                    log.Warn
                        ("Client Certificate is not trusted and fails SIF Level 2 Authentication: " +
                        certStatus.ToString());
                }
                e.Valid = false;
            }
            else
            {
                e.Valid = true;
            }
        }
Exemplo n.º 3
0
 private void verifyLevel1Authentication(SecureSocket socket,
                                         Certificate cert,
                                         CertificateChain chain,
                                         VerifyEventArgs e
                                         )
 {
     if (cert == null)
     {
         if ((Adk.Debug & AdkDebugFlags.Messaging_Detailed) != 0)
         {
             log.Warn("Client Certificate is missing and fails SIF Level 1 Authentication");
         }
         e.Valid = false;
     }
     else if (!cert.IsCurrent)
     {
         if ((Adk.Debug & AdkDebugFlags.Messaging_Detailed) != 0)
         {
             log.Warn("Client Certificate is invalid and fails SIF Level 1 Authentication");
         }
         e.Valid = false;
     }
     else
     {
         e.Valid = true;
     }
 }
Exemplo n.º 4
0
        void modify_instance_dlg_VerifyDataDir(object sender, VerifyEventArgs e)
        {
            bool bRet = IsDataDirDup(e.Value,
                                     this.m_currentEditItem);

            if (bRet == true)
            {
                e.ErrorInfo = "数据目录 '" + e.Value + "' 和已存在的其他实例发生了重复";
            }
        }
Exemplo n.º 5
0
        void modify_instance_dlg_VerifyInstanceName(object sender, VerifyEventArgs e)
        {
            bool bRet = IsInstanceNameDup(e.Value,
                                          this.m_currentEditItem);

            if (bRet == true)
            {
                e.ErrorInfo = "实例名 '" + e.Value + "' 和已存在的其他实例发生了重复";
            }
        }
Exemplo n.º 6
0
        void new_instance_dlg_VerifyDataDir(object sender, VerifyEventArgs e)
        {
            bool bRet = IsDataDirDup(e.Value,
                                     (ListViewItem)null);

            if (bRet == true)
            {
                e.ErrorInfo = "数据目录 '" + e.Value + "' 和已存在的其他实例发生了重复";
            }
        }
Exemplo n.º 7
0
        void new_instance_dlg_VerifyInstanceName(object sender, VerifyEventArgs e)
        {
            bool bRet = IsInstanceNameDup(e.Value,
                                          (ListViewItem)null);

            if (bRet == true)
            {
                e.ErrorInfo = "实例名 '" + e.Value + "' 和已存在的其他实例发生了重复";
            }
        }
Exemplo n.º 8
0
 private void CheckClientCertAtServer(SecureSocket socket, Certificate clientCertificate, CertificateChain allClientCertificates,
                                      VerifyEventArgs args)
 {
     Debug.WriteLine("check the client certificate event");
     if (allClientCertificates != null)
     {
         args.Valid = m_serverAuth.IsValidClientCertificate(clientCertificate,
                                                            allClientCertificates, ((IPEndPoint)socket.RemoteEndPoint).Address);
     }
     else
     {
         args.Valid = !((m_requiredOptions & SecurityAssociationOptions.EstablishTrustInClient) > 0);
     }
 }
Exemplo n.º 9
0
        protected void VerifyChain(CertificateChain chain, bool client)
        {
            VerifyEventArgs e = new VerifyEventArgs();

            switch (m_Options.VerificationType)
            {
            case CredentialVerification.Manual:
                try {
                    m_Options.Verifier(Parent, m_RemoteCertificate, chain, e);
                } catch (Exception de) {
                    throw new SslException(de, AlertDescription.InternalError, "The code inside the CertVerifyEventHandler delegate threw an exception.");
                }
                break;

            case CredentialVerification.Auto:
                if (chain != null)
                {
                    e.Valid = (chain.VerifyChain(m_Options.CommonName, client ? AuthType.Client : AuthType.Server) == CertificateStatus.ValidCertificate);
                }
                else
                {
                    e.Valid = false;
                }
                break;

            case CredentialVerification.AutoWithoutCName:
                if (chain != null)
                {
                    e.Valid = (chain.VerifyChain(m_Options.CommonName, client ? AuthType.Client : AuthType.Server, VerificationFlags.IgnoreInvalidName) == CertificateStatus.ValidCertificate);
                }
                else
                {
                    e.Valid = false;
                }
                break;

            case CredentialVerification.None:
            default:
                e.Valid = true;
                break;
            }
            if (!e.Valid)
            {
                throw new SslException(AlertDescription.CertificateUnknown, "The certificate could not be verified.");
            }
        }
Exemplo n.º 10
0
        // ------------------------ OnVerify -------------------------------------
        protected void OnVerify(
            SecureSocket socket,
            Certificate remote,
            CertificateChain InChain,
            VerifyEventArgs e)
        {
            Certificate[] certs = InChain.GetCertificates( );
            for (int Ix = 0; Ix < certs.Length; Ix++)
            {
                AddMessage(NetworkRole.Client, certs[Ix].ToString(true));
            }

            // print out the result of the chain verification
            AddMessage(
                NetworkRole.Client,
                "Verify certificate: " +
                InChain.VerifyChain(socket.CommonName, AuthType.Server).ToString( ));
        }
Exemplo n.º 11
0
        void IndicateVerificationStarted(WebDomainVerifier source, VerifyEventArgs args)
        {
            // Indicate verification started
            eventsText.AppendLine(VerificationStartMessage);

            // Append status info
            eventsText.Append(StatusMessage);
            eventsText.Append(source.CurrentState);
            eventsText.AppendLine();

            // Append time info
            eventsText.Append("Start time: ");
            eventsText.Append(args.StartTime);
            eventsText.Append(" seconds since app has started");

            // Apply text to label
            eventsStatusLabel.text = eventsText.ToString();
        }
Exemplo n.º 12
0
        void IndicateVerificationEnded(WebDomainVerifier source, VerifyEventArgs args)
        {
            // Indicate verification finished
            eventsText.AppendLine();
            eventsText.AppendLine(VerificationEndMessage);

            // Append status info
            eventsText.Append(StatusMessage);
            eventsText.Append(domainVerifier.CurrentState);
            eventsText.AppendLine();

            // Append duration info
            eventsText.Append("Processing duration: ");
            eventsText.Append(args.VerificationDurationSeconds);
            eventsText.Append(" seconds");

            // Update the label
            eventsStatusLabel.text = eventsText.ToString();
        }
Exemplo n.º 13
0
        // 检测目录是否已经存在
        private void textBox_dataDir_Leave(object sender, EventArgs e)
        {
            // 已经准备Cancel,就不检查了
            if (IsMouseOnCancelButton() == true)
            {
                return;
            }

            // 新建时
            if (IsNew == true &&
                String.IsNullOrEmpty(this.textBox_dataDir.Text) == false &&
                this.LoadedDataDir != this.textBox_dataDir.Text)
            {
                // 注意检查,不能是别的instance的数据目录
                if (this.VerifyDataDir != null)
                {
                    VerifyEventArgs e1 = new VerifyEventArgs();
                    e1.Value = this.textBox_dataDir.Text;
                    this.VerifyDataDir(this, e1);
                    if (String.IsNullOrEmpty(e1.ErrorInfo) == false)
                    {
                        MessageBox.Show(this, e1.ErrorInfo);
                        return;
                    }
                }

                string strXmlFilename = PathUtil.MergePath(this.textBox_dataDir.Text, "library.xml");
                if (File.Exists(strXmlFilename) == true)
                {
                    DialogResult result = MessageBox.Show(ForegroundWindow.Instance,
                                                          "您指定的数据目录 '" + this.textBox_dataDir.Text + "' 中已经存在 library.xml 文件。\r\n\r\n是否要直接利用其中的配置信息?",
                                                          "安装 dp2Library",
                                                          MessageBoxButtons.YesNo,
                                                          MessageBoxIcon.Question,
                                                          MessageBoxDefaultButton.Button1);
                    if (result == System.Windows.Forms.DialogResult.No)
                    {
                        this.LoadedDataDir = this.textBox_dataDir.Text; // 防止重复询问
                        return;
                    }

                    if (this.LoadXmlFileInfo != null)
                    {
                        LoadXmlFileInfoEventArgs e1 = new LoadXmlFileInfoEventArgs();
                        e1.DataDir = this.textBox_dataDir.Text;
                        this.LoadXmlFileInfo(this, e1);
                        if (string.IsNullOrEmpty(e1.ErrorInfo) == false)
                        {
                            MessageBox.Show(this, e1.ErrorInfo);
                            return;
                        }

                        // refresh
                        this.LineInfo = (LineInfo)e1.LineInfo;
                        Refreshdp2KernelDef();
                        RefreshSupervisorUserInfo();
                        RefreshLibraryName();
                        RefreshUpdateCfgsDir();
                        this.LoadedDataDir   = this.textBox_dataDir.Text; // 防止重复装载
                        this.m_bDataDirExist = true;                      // 防止OK时不合适的检查警告
                    }
                }

                return;
            }

            // 修改时
            if (IsNew == false &&
                String.IsNullOrEmpty(this.textBox_dataDir.Text) == false &&
                this.LoadedDataDir != this.textBox_dataDir.Text)
            {
                // 注意检查,不能是别的instance的数据目录
                if (this.VerifyDataDir != null)
                {
                    VerifyEventArgs e1 = new VerifyEventArgs();
                    e1.Value = this.textBox_dataDir.Text;
                    this.VerifyDataDir(this, e1);
                    if (String.IsNullOrEmpty(e1.ErrorInfo) == false)
                    {
                        MessageBox.Show(this, e1.ErrorInfo);
                        return;
                    }
                }

                string strXmlFilename = PathUtil.MergePath(this.textBox_dataDir.Text, "library.xml");
                if (File.Exists(strXmlFilename) == true)
                {
                    DialogResult result = MessageBox.Show(ForegroundWindow.Instance,
                                                          "您指定的数据目录 '" + this.textBox_dataDir.Text + "' 中已经存在 library.xml 文件。\r\n\r\n是否要直接利用其中的配置信息?\r\n\r\n是:直接利用其中的信息,也即将其中的配置信息装入当前对话框\r\n否:利用这个数据目录,但其中xml文件的相关信息即将被当前对话框中的值覆盖\r\n\r\n(提示:无论您选“是”“否”,原有目录 '" + this.LoadedDataDir + "' 都会被闲置)",
                                                          "安装 dp2Library",
                                                          MessageBoxButtons.YesNo,
                                                          MessageBoxIcon.Question,
                                                          MessageBoxDefaultButton.Button1);
                    if (result == System.Windows.Forms.DialogResult.No)
                    {
                        this.LoadedDataDir = this.textBox_dataDir.Text; // 防止重复询问
                        return;
                    }

                    if (this.LoadXmlFileInfo != null)
                    {
                        LoadXmlFileInfoEventArgs e1 = new LoadXmlFileInfoEventArgs();
                        e1.DataDir = this.textBox_dataDir.Text;
                        this.LoadXmlFileInfo(this, e1);
                        if (string.IsNullOrEmpty(e1.ErrorInfo) == false)
                        {
                            MessageBox.Show(this, e1.ErrorInfo);
                            return;
                        }

                        // refresh
                        this.LineInfo = (LineInfo)e1.LineInfo;
                        Refreshdp2KernelDef();
                        RefreshSupervisorUserInfo();
                        RefreshLibraryName();
                        RefreshUpdateCfgsDir();
                        this.LoadedDataDir   = this.textBox_dataDir.Text; // 防止重复装载
                        this.m_bDataDirExist = true;                      // 防止OK时不合适的检查警告
                    }
                }
                else if (String.IsNullOrEmpty(this.LoadedDataDir) == false)
                {
                    // 修改目录名

                    DialogResult result = MessageBox.Show(ForegroundWindow.Instance,
                                                          "要将已经存在的数据目录 '" + this.LoadedDataDir + "' 更名为 '" + this.textBox_dataDir.Text + "' 么?\r\n\r\n(如果选择“否”,则安装程序在稍后将新创建一个数据目录,并复制进初始内容)",
                                                          "安装 dp2Library",
                                                          MessageBoxButtons.YesNo,
                                                          MessageBoxIcon.Question,
                                                          MessageBoxDefaultButton.Button1);
                    if (result == System.Windows.Forms.DialogResult.No)
                    {
                        this.m_bDataDirExist = false;
                        return;
                    }

                    try
                    {
                        // TODO: 需要测试当数据目录中内容尺寸太大,而目标盘无妨容纳时的报错情况
                        Directory.Move(this.LoadedDataDir, this.textBox_dataDir.Text);

                        this.LoadedDataDir = this.textBox_dataDir.Text; // 防止重复装载
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(this, "将已经存在的数据目录 '" + this.LoadedDataDir + "' 更名为 '" + this.textBox_dataDir.Text + "' 时发生错误: " + ex.Message);
                    }
                }

                return;
            }
        }
Exemplo n.º 14
0
        private void button_OK_Click(object sender, EventArgs e)
        {
            string strError = "";

            // 检查

            // 数据目录
            if (String.IsNullOrEmpty(this.textBox_dataDir.Text) == true)
            {
                strError = "尚未指定数据目录";
                goto ERROR1;
            }

            if (String.IsNullOrEmpty(this.comboBox_sqlServerType.Text) == true)
            {
                strError = "尚未指定 SQL 服务器类型";
                goto ERROR1;
            }

            // sql服务器信息
            if (String.IsNullOrEmpty(this.textBox_sqlDef.Text) == true)
            {
                strError = "尚未指定 SQL 服务器信息";
                goto ERROR1;
            }

            // 协议绑定
            if (String.IsNullOrEmpty(this.textBox_bindings.Text) == true)
            {
                strError = "尚未指定协议绑定信息";
                goto ERROR1;
            }


            if (this.IsNew == true
                && this.m_bDataDirExist == false)
            {
                // root用户信息
                if (this.LineInfo.RootUserName == null
        || this.LineInfo.RootPassword == null
        || this.LineInfo.RootUserRights == null)
                {
                    strError = "尚未设定root账户的用户名、密码、权限";
                    goto ERROR1;
                }
            }

            // 如果修改时,需要创建新的数据目录
            if (this.IsNew == false)
            {
                // 探测数据目录,是否已经存在数据,是不是属于升级情形
                // return:
                //      -1  error
                //      0   数据目录不存在
                //      1   数据目录存在,但是xml文件不存在
                //      2   xml文件已经存在
                int nRet = InstanceDialog.DetectDataDir(this.textBox_dataDir.Text,
            out strError);
                if (nRet == -1)
                {
                    strError = "探测数据目录 '" + this.textBox_dataDir.Text + "' 是否存在时,出现错误: " + strError;
                    goto ERROR1;
                }

                if (nRet == 0 || nRet == 1)
                {

                    // root用户信息
                    if (this.LineInfo.RootUserName == null
            || this.LineInfo.RootPassword == null
            || this.LineInfo.RootUserRights == null)
                    {
                        strError = "尚未设定root账户的用户名、密码、权限";
                        goto ERROR1;
                    }
                }
            }

            // TODO: 如果在编辑状态,需要排除和listview中自己重的情况

            if (this.VerifyInstanceName != null)
            {
                VerifyEventArgs e1 = new VerifyEventArgs();
                e1.Value = this.textBox_instanceName.Text;
                this.VerifyInstanceName(this, e1);
                if (String.IsNullOrEmpty(e1.ErrorInfo) == false)
                {
                    strError = e1.ErrorInfo;
                    goto ERROR1;
                }
            }

            if (this.VerifyDataDir != null)
            {
                VerifyEventArgs e1 = new VerifyEventArgs();
                e1.Value = this.textBox_dataDir.Text;
                this.VerifyDataDir(this, e1);
                if (String.IsNullOrEmpty(e1.ErrorInfo) == false)
                {
                    strError = e1.ErrorInfo;
                    goto ERROR1;
                }
            }

            if (this.VerifyBindings != null)
            {
                VerifyEventArgs e1 = new VerifyEventArgs();
                e1.Value = this.textBox_bindings.Text;
                this.VerifyBindings(this, e1);
                if (String.IsNullOrEmpty(e1.ErrorInfo) == false)
                {
                    strError = e1.ErrorInfo;
                    goto ERROR1;
                }
            }

            this.DialogResult = System.Windows.Forms.DialogResult.OK;
            this.Close();
            return;
        ERROR1:
            MessageBox.Show(this, strError);
        }
Exemplo n.º 15
0
        private void button_OK_Click(object sender, EventArgs e)
        {
            string strError = "";

            // 检查

            // 数据目录
            if (String.IsNullOrEmpty(this.textBox_dataDir.Text) == true)
            {
                strError = "尚未指定数据目录";
                goto ERROR1;
            }

            // dp2Kernel服务器信息
            if (String.IsNullOrEmpty(this.textBox_dp2KernelDef.Text) == true)
            {
                strError = "尚未指定dp2Kernel服务器信息";
                goto ERROR1;
            }

            // 协议绑定
            if (String.IsNullOrEmpty(this.textBox_bindings.Text) == true)
            {
                strError = "尚未指定协议绑定信息";
                goto ERROR1;
            }

            // 图书馆名
            if (String.IsNullOrEmpty(this.textBox_libraryName.Text) == true)
            {
                strError = "尚未指定图书馆名";
                goto ERROR1;
            }
            if (this.LineInfo == null)
                this.LineInfo = new LineInfo();
            this.LineInfo.LibraryName = this.textBox_libraryName.Text;

            this.LineInfo.UpdateCfgsDir = this.checkBox_updateCfgsDir.Checked;

            // 检查是否为旧式url地址
            string strKernelUrl = this.LineInfo.KernelUrl;
            if (strKernelUrl.IndexOf(".asmx") != -1)
            {
                strError = "安装程序发现当前使用了旧版本数据库内核的地址 '" + strKernelUrl + "',需要您将它修改为新版dp2Kernel(内核)的URL地址。";
                goto ERROR1;
            }

            if (this.IsNew == true
                && this.m_bDataDirExist == false)
            {
                // supervisor用户信息
                if (this.LineInfo.SupervisorUserName == null
        || this.LineInfo.SupervisorPassword == null
        || this.LineInfo.SupervisorRights == null)
                {
                    strError = "尚未设定supervisor账户的用户名、密码、权限";
                    goto ERROR1;
                }
            }

            // 如果修改时,需要创建新的数据目录
            if (this.IsNew == false)
            {
                // 探测数据目录,是否已经存在数据,是不是属于升级情形
                // return:
                //      -1  error
                //      0   数据目录不存在
                //      1   数据目录存在,但是xml文件不存在
                //      2   xml文件已经存在
                int nRet = InstanceDialog.DetectDataDir(this.textBox_dataDir.Text,
            out strError);
                if (nRet == -1)
                {
                    strError = "探测数据目录 '" + this.textBox_dataDir.Text + "' 是否存在时,出现错误: " + strError;
                    goto ERROR1;
                }

                if (nRet == 0 || nRet == 1)
                {
                    // supervisor用户信息
                    if (this.LineInfo.SupervisorUserName == null
            || this.LineInfo.SupervisorPassword == null
            || this.LineInfo.SupervisorRights == null)
                    {
                        strError = "尚未设定supervisor账户的用户名、密码、权限";
                        goto ERROR1;
                    }
                }
            }

            // TODO: 如果在编辑状态,需要排除和listview中自己重的情况

            if (this.VerifyInstanceName != null)
            {
                VerifyEventArgs e1 = new VerifyEventArgs();
                e1.Value = this.textBox_instanceName.Text;
                this.VerifyInstanceName(this, e1);
                if (String.IsNullOrEmpty(e1.ErrorInfo) == false)
                {
                    strError = e1.ErrorInfo;
                    goto ERROR1;
                }
            }

            if (this.VerifyDataDir != null)
            {
                VerifyEventArgs e1 = new VerifyEventArgs();
                e1.Value = this.textBox_dataDir.Text;
                this.VerifyDataDir(this, e1);
                if (String.IsNullOrEmpty(e1.ErrorInfo) == false)
                {
                    strError = e1.ErrorInfo;
                    goto ERROR1;
                }
            }

            if (this.VerifyBindings != null)
            {
                VerifyEventArgs e1 = new VerifyEventArgs();
                e1.Value = this.textBox_bindings.Text;
                this.VerifyBindings(this, e1);
                if (String.IsNullOrEmpty(e1.ErrorInfo) == false)
                {
                    strError = e1.ErrorInfo;
                    goto ERROR1;
                }
            }

            this.DialogResult = System.Windows.Forms.DialogResult.OK;
            this.Close();
            return;
        ERROR1:
            MessageBox.Show(this, strError);
        }
Exemplo n.º 16
0
        // 准备可选的缺省绑定内容
        int PrepareDefaultBindings(string strTail,
                                   out string[] default_urls,
                                   out string strError)
        {
            default_urls = null;
            strError     = "";

            // 无法检查
            if (this.VerifyBindings == null)
            {
                default_urls = new string[] {
                    "net.tcp://localhost:8002/dp2library/" + strTail,
                    "net.pipe://localhost/dp2library/" + strTail,
                    "http://localhost:8001/dp2library/" + strTail,
                    "rest.http://localhost:8001/dp2library/" + strTail,
                    "basic.http://localhost:8001/dp2library/" + strTail
                };
                return(0);
            }

            string strTcpUrl = "";

            for (int nPort = 8002; ; nPort++)
            {
                strTcpUrl = "net.tcp://localhost:" + nPort.ToString() + "/dp2library/" + strTail;
                VerifyEventArgs e1 = new VerifyEventArgs();
                e1.Value = strTcpUrl;
                this.VerifyBindings(this, e1);
                if (String.IsNullOrEmpty(e1.ErrorInfo) == true)
                {
                    break;
                }
            }

            string strPipeUrl = "";

            for (int nNumber = 0; ; nNumber++)
            {
                strPipeUrl = "net.pipe://localhost/dp2library/" + strTail;
                if (nNumber > 0)
                {
                    strPipeUrl += nNumber.ToString() + "/";
                }

                VerifyEventArgs e1 = new VerifyEventArgs();
                e1.Value = strPipeUrl;
                this.VerifyBindings(this, e1);
                if (String.IsNullOrEmpty(e1.ErrorInfo) == true)
                {
                    break;
                }
            }

            string strHttpUrl = "";

            for (int nPort = 8001; ; nPort++)
            {
                strHttpUrl = "http://localhost:" + nPort.ToString() + "/dp2library/" + strTail;
                VerifyEventArgs e1 = new VerifyEventArgs();
                e1.Value = strHttpUrl;
                this.VerifyBindings(this, e1);
                if (String.IsNullOrEmpty(e1.ErrorInfo) == true)
                {
                    break;
                }
            }

            string strRestUrl = "";

            for (int nPort = 8001; ; nPort++)
            {
                strRestUrl = "rest.http://localhost:" + nPort.ToString() + "/dp2library/rest/" + strTail;
                VerifyEventArgs e1 = new VerifyEventArgs();
                e1.Value = strRestUrl;
                this.VerifyBindings(this, e1);
                if (String.IsNullOrEmpty(e1.ErrorInfo) == true)
                {
                    break;
                }
            }

            string strBasicUrl = "";

            for (int nPort = 8001; ; nPort++)
            {
                strBasicUrl = "basic.http://localhost:" + nPort.ToString() + "/dp2library/basic/" + strTail;
                VerifyEventArgs e1 = new VerifyEventArgs();
                e1.Value = strBasicUrl;
                this.VerifyBindings(this, e1);
                if (String.IsNullOrEmpty(e1.ErrorInfo) == true)
                {
                    break;
                }
            }

            default_urls = new string[] {
                strTcpUrl,
                strPipeUrl,
                strHttpUrl,
                strRestUrl,
                strBasicUrl,
            };
            return(0);
        }
Exemplo n.º 17
0
 void new_instance_dlg_VerifyInstanceName(object sender, VerifyEventArgs e)
 {
     bool bRet = IsInstanceNameDup(e.Value,
         (ListViewItem)null);
     if (bRet == true)
         e.ErrorInfo = "实例名 '" + e.Value + "' 和已存在的其他实例发生了重复";
 }
Exemplo n.º 18
0
 void modify_instance_dlg_VerifyDataDir(object sender, VerifyEventArgs e)
 {
     bool bRet = IsDataDirDup(e.Value,
         this.m_currentEditItem);
     if (bRet == true)
         e.ErrorInfo = "数据目录 '" + e.Value + "' 和已存在的其他实例发生了重复";
 }
Exemplo n.º 19
0
        private void button_OK_Click(object sender, EventArgs e)
        {
            string strError = "";
            int    nRet     = 0;

            // 检查

            if (String.IsNullOrEmpty(this.comboBox_site.Text) == true)
            {
                strError = "尚未指定站点名";
                goto ERROR1;
            }

            if (String.IsNullOrEmpty(this.textBox_instanceName.Text) == true)
            {
                strError = "尚未指定虚拟目录名";
                goto ERROR1;
            }

            if (this.textBox_instanceName.Text[0] != '/')
            {
                strError = "虚拟目录名第一字符必须为 '/'";
                goto ERROR1;
            }

            string strVirtualDirRight = this.textBox_instanceName.Text.Substring(1);

            if (strVirtualDirRight.IndexOfAny(new char[] { '/', ' ' }) != -1)
            {
                strError = "虚拟目录名第一字符以外的字符中,不允许包含 '/' 或空格字符";
                goto ERROR1;
            }

            // 数据目录
            if (String.IsNullOrEmpty(this.textBox_dataDir.Text) == true)
            {
                strError = "尚未指定数据目录";
                goto ERROR1;
            }

            // dp2Library 服务器信息
            if (String.IsNullOrEmpty(this.textBox_dp2LibraryDef.Text) == true)
            {
                strError = "尚未指定 dp2Library 服务器信息";
                goto ERROR1;
            }

            if (this.LineInfo == null)
            {
                this.LineInfo = new DigitalPlatform.OPAC.LineInfo();
            }

            // 检查是否为旧式url地址
            string strUrl = this.LineInfo.LibraryUrl;

            if (strUrl.IndexOf(".asmx") != -1)
            {
                strError = "安装程序发现当前使用了旧版本 dp2LibraryWs 的地址 '" + strUrl + "',需要您将它修改为新版 dp2Library (图书馆应用服务器) 的 URL 地址。";
                goto ERROR1;
            }

            if (this.CreateMode == true &&
                this.m_bDataDirExist == false)
            {
                // opac 用户信息
                if (this.LineInfo.LibraryUserName == null ||
                    this.LineInfo.LibraryPassword == null)
                {
                    strError = "尚未设定 opac 账户的用户名、密码";
                    goto ERROR1;
                }
            }

            // 如果修改时,需要创建新的数据目录
            if (this.CreateMode == false)
            {
                // 探测数据目录,是否已经存在数据,是不是属于升级情形
                // return:
                //      -1  error
                //      0   数据目录不存在
                //      1   数据目录存在,但是xml文件不存在
                //      2   xml文件已经存在
                nRet = InstanceDialog.DetectDataDir(this.textBox_dataDir.Text,
                                                    out strError);
                if (nRet == -1)
                {
                    strError = "探测数据目录 '" + this.textBox_dataDir.Text + "' 是否存在时,出现错误: " + strError;
                    goto ERROR1;
                }

                if (nRet == 0 || nRet == 1)
                {
                    // opac 用户信息
                    if (this.LineInfo.LibraryUserName == null ||
                        this.LineInfo.LibraryPassword == null)
                    {
                        strError = "尚未设定 opac 账户的用户名、密码";
                        goto ERROR1;
                    }
                }
            }

            // 处理数据目录更名情况
            nRet = RenameDataDir(out strError);
            if (nRet == -1)
            {
                goto ERROR1;
            }

            // TODO: 如果在编辑状态,需要排除和 listview 中自己重的情况

            if (this.VerifyInstanceName != null)
            {
                VerifyEventArgs e1 = new VerifyEventArgs();
                e1.Value = this.comboBox_site.Text + this.textBox_instanceName.Text;
                this.VerifyInstanceName(this, e1);
                if (String.IsNullOrEmpty(e1.ErrorInfo) == false)
                {
                    strError = e1.ErrorInfo;
                    goto ERROR1;
                }
            }

            if (this.VerifyDataDir != null)
            {
                VerifyEventArgs e1 = new VerifyEventArgs();
                e1.Value = this.textBox_dataDir.Text;
                this.VerifyDataDir(this, e1);
                if (String.IsNullOrEmpty(e1.ErrorInfo) == false)
                {
                    strError = e1.ErrorInfo;
                    goto ERROR1;
                }
            }

            this.DialogResult = System.Windows.Forms.DialogResult.OK;
            this.Close();
            return;

ERROR1:
            MessageBox.Show(this, strError);
        }
Exemplo n.º 20
0
        void new_instance_dlg_VerifyBindings(object sender, VerifyEventArgs e)
        {
            string strError = "";
            // return:
            //      -1  出错
            //      0   不重
            //      1    重复
            int nRet = IsBindingDup(e.Value,
                (ListViewItem)null,
                out strError);
            if (nRet != 0)
            {
                e.ErrorInfo = strError;
                return;
            }

            nRet = InstallHelper.IsGlobalBindingDup(e.Value,
    "dp2Kernel",
    out strError);
            if (nRet != 0)
            {
                e.ErrorInfo = strError;
                return;
            }
        }
Exemplo n.º 21
0
 public void OnVerify(SecureSocket socket, Certificate remote, CertificateChain chain, VerifyEventArgs e)
 {
     Console.WriteLine("\r\nThe certificate of the FTP server:");
     Console.WriteLine(remote.ToString(true) + "\r\n");
     // certificate chain verification can be placed here
 }
Exemplo n.º 22
0
 private void CheckServerCertAtClient(SecureSocket socket, Certificate cert, CertificateChain chain, VerifyEventArgs args)
 {
     Debug.WriteLine("check the server certificate event");
     args.Valid = m_clientAuth.IsValidServerCertificate(cert, chain, ((IPEndPoint)socket.RemoteEndPoint).Address);
 }
Exemplo n.º 23
0
    /// <summary>
    /// Verifies a certificate received from the remote host.
    /// </summary>
    /// <param name="socket">The SecureSocket that received the certificate.</param>
    /// <param name="remote">The received certificate.</param>
    /// <param name="e">The event parameters.</param>
    protected void OnVerify(SecureSocket socket, Certificate remote, CertificateChain chain, VerifyEventArgs e)
    {
        CertificateChain cc = new CertificateChain(remote);

        Console.WriteLine("\r\nServer Certificate:\r\n-------------------");
        Console.WriteLine(remote.ToString(true));
        Console.Write("\r\nServer Certificate Verification:\r\n--------------------------------\r\n    -> ");
        Console.WriteLine(cc.VerifyChain(socket.CommonName, AuthType.Server).ToString() + "\r\n");
    }
Exemplo n.º 24
0
 /// <summary>
 /// This method is called when the SecureSocket received the remote
 /// certificate and when the certificate validation type is set to Manual.
 /// </summary>
 /// <param name="socket">The <see cref="SecureSocket"/> that received the certificate to verify.</param>
 /// <param name="remote">The <see cref="Certificate"/> of the remote party to verify.</param>
 /// <param name="chain">The <see cref="CertificateChain"/> associated with the remote certificate.</param>
 /// <param name="e">A <see cref="VerifyEventArgs"/> instance used to (in)validate the certificate.</param>
 /// <remarks>If an error is thrown by the code in the delegate, the SecureSocket will close the connection.</remarks>
 protected void OnVerify(SecureSocket socket, Certificate remote, CertificateChain chain, VerifyEventArgs e)
 {
     // get all the certificates from the certificate chain ..
     Certificate[] certs = chain.GetCertificates();
     // .. and print them out in the console
     for (int i = 0; i < certs.Length; i++)
     {
         Console.WriteLine(certs[i].ToString(true));
     }
     // print out the result of the chain verification
     Console.WriteLine(chain.VerifyChain(socket.CommonName, AuthType.Server));
 }
Exemplo n.º 25
0
        // 准备可选的缺省绑定内容
        int PrepareDefaultBindings(string strTail,
            out string [] default_urls,
            out string strError)
        {
            default_urls = null;
            strError = "";

            // 无法检查
            if (this.VerifyBindings == null)
            {
                default_urls = new string[] {
                    "net.tcp://localhost:8002/dp2library/" + strTail,
                    "net.pipe://localhost/dp2library/" + strTail,
                    "http://localhost:8001/dp2library/" + strTail,
                    "rest.http://localhost:8001/dp2library/" + strTail,
                    "basic.http://localhost:8001/dp2library/" + strTail
                };
                return 0;
            }

            string strTcpUrl = "";
            for (int nPort = 8002; ; nPort++)
            {
                strTcpUrl = "net.tcp://localhost:" + nPort.ToString() + "/dp2library/" + strTail;
                VerifyEventArgs e1 = new VerifyEventArgs();
                e1.Value = strTcpUrl;
                this.VerifyBindings(this, e1);
                if (String.IsNullOrEmpty(e1.ErrorInfo) == true)
                {
                    break;
                }
            }

            string strPipeUrl = "";
            for (int nNumber = 0; ; nNumber++)
            {
                strPipeUrl = "net.pipe://localhost/dp2library/" + strTail;
                if (nNumber > 0)
                    strPipeUrl += nNumber.ToString() + "/";

                VerifyEventArgs e1 = new VerifyEventArgs();
                e1.Value = strPipeUrl;
                this.VerifyBindings(this, e1);
                if (String.IsNullOrEmpty(e1.ErrorInfo) == true)
                {
                    break;
                }
            }

            string strHttpUrl = "";
            for (int nPort = 8001; ; nPort++)
            {
                strHttpUrl = "http://localhost:" + nPort.ToString() + "/dp2library/" + strTail;
                VerifyEventArgs e1 = new VerifyEventArgs();
                e1.Value = strHttpUrl;
                this.VerifyBindings(this, e1);
                if (String.IsNullOrEmpty(e1.ErrorInfo) == true)
                {
                    break;
                }
            }

            string strRestUrl = "";
            for (int nPort = 8001; ; nPort++)
            {
                strRestUrl = "rest.http://localhost:" + nPort.ToString() + "/dp2library/rest/" + strTail;
                VerifyEventArgs e1 = new VerifyEventArgs();
                e1.Value = strRestUrl;
                this.VerifyBindings(this, e1);
                if (String.IsNullOrEmpty(e1.ErrorInfo) == true)
                {
                    break;
                }
            }

            string strBasicUrl = "";
            for (int nPort = 8001; ; nPort++)
            {
                strBasicUrl = "basic.http://localhost:" + nPort.ToString() + "/dp2library/basic/" + strTail;
                VerifyEventArgs e1 = new VerifyEventArgs();
                e1.Value = strBasicUrl;
                this.VerifyBindings(this, e1);
                if (String.IsNullOrEmpty(e1.ErrorInfo) == true)
                {
                    break;
                }
            }

            default_urls = new string[] {
                    strTcpUrl,
                    strPipeUrl,
                    strHttpUrl,
                    strRestUrl,
                    strBasicUrl,
                };
            return 0;
        }
Exemplo n.º 26
0
        // 准备可选的缺省绑定内容
        // 2015/6/19 为了安全考虑,缺省情况下只绑定 net.pipe 协议。其他协议需要安装者主动选择才行
        int PrepareDefaultBindings(string strTail,
            out string [] default_urls,
            out string strError)
        {
            default_urls = null;
            strError = "";

            // 无法检查
            if (this.VerifyBindings == null)
            {
                default_urls = new string[] {
                    // "net.tcp://localhost:8002/dp2kernel/" + strTail,
                    "net.pipe://localhost/dp2kernel/" + strTail,
                    // "http://localhost:8001/dp2kernel/" + strTail
                };
                return 0;
            }

#if NO
            string strTcpUrl = "";
            for (int nPort = 8002; ; nPort++)
            {
                strTcpUrl = "net.tcp://localhost:" + nPort.ToString() + "/dp2kernel/" + strTail;
                VerifyEventArgs e1 = new VerifyEventArgs();
                e1.Value = strTcpUrl;
                this.VerifyBindings(this, e1);
                if (String.IsNullOrEmpty(e1.ErrorInfo) == true)
                {
                    break;
                }
            }
#endif

            string strPipeUrl = "";
            for (int nNumber = 0; ; nNumber++)
            {
                strPipeUrl = "net.pipe://localhost/dp2kernel/" + strTail;
                if (nNumber > 0)
                    strPipeUrl += nNumber.ToString() + "/";

                VerifyEventArgs e1 = new VerifyEventArgs();
                e1.Value = strPipeUrl;
                this.VerifyBindings(this, e1);
                if (String.IsNullOrEmpty(e1.ErrorInfo) == true)
                {
                    break;
                }
            }

#if NO
            string strHttpUrl = "";
            for (int nPort = 8001; ; nPort++)
            {
                strHttpUrl = "http://localhost:" + nPort.ToString() + "/dp2kernel/" + strTail;
                VerifyEventArgs e1 = new VerifyEventArgs();
                e1.Value = strHttpUrl;
                this.VerifyBindings(this, e1);
                if (String.IsNullOrEmpty(e1.ErrorInfo) == true)
                {
                    break;
                }
            }
#endif

            default_urls = new string[] {
                    // strTcpUrl,
                    strPipeUrl,
                    // strHttpUrl
                };
            return 0;
        }
Exemplo n.º 27
0
        void SetDefaultVirtualDirValue()
        {
            string             strError = "";
            List <OpacAppInfo> infos    = null;
            // 用 appcmd 方式获得 所有虚拟目录的信息 (不仅仅是 dp2OPAC 虚拟目录)
            int nRet = OpacAppInfo.GetAllVirtualInfoByAppCmd(out infos,
                                                             out strError);

            if (nRet == -1)
            {
                goto ERROR1;
            }

            for (int i = 0; ; i++)
            {
                string strVirtualDir = "/dp2OPAC";
                if (i > 0)
                {
                    strVirtualDir = "/dp2OPAC" + (i + 1).ToString();
                }

                // 已经存在的虚拟目录不能使用

                // 查找一个虚拟目录是否存在
                // return:
                //      -1  不存在
                //      其他  数组元素的下标
                nRet = OpacAppInfo.Find(infos,
                                        this.comboBox_site.Text,
                                        strVirtualDir);
                if (nRet != -1)
                {
                    continue;
                }

                // 注意检查,不能是别的instance的数据目录
                if (this.VerifyDataDir != null)
                {
                    VerifyEventArgs e1 = new VerifyEventArgs();
                    e1.Value = strVirtualDir;
                    this.VerifyDataDir(this, e1);
                    if (String.IsNullOrEmpty(e1.ErrorInfo) == false)
                    {
                        continue;
                    }
                }

                if (this.VerifyInstanceName != null)
                {
                    VerifyEventArgs e1 = new VerifyEventArgs();
                    e1.Value = this.comboBox_site.Text + strVirtualDir;
                    this.VerifyInstanceName(this, e1);
                    if (String.IsNullOrEmpty(e1.ErrorInfo) == false)
                    {
                        continue;
                    }
                }

                this.textBox_instanceName.Text = strVirtualDir;
                return;
            }
            return;

ERROR1:
            MessageBox.Show(this, strError);
        }
Exemplo n.º 28
0
        // 检测目录是否已经存在
        private void textBox_dataDir_Leave(object sender, EventArgs e)
        {
            // 已经准备Cancel,就不检查了
            if (IsMouseOnCancelButton() == true)
                return;

            // 新建时
            if (IsNew == true 
                && String.IsNullOrEmpty(this.textBox_dataDir.Text) == false
                && this.LoadedDataDir != this.textBox_dataDir.Text)
            {
                // 注意检查,不能是别的instance的数据目录
                if (this.VerifyDataDir != null)
                {
                    VerifyEventArgs e1 = new VerifyEventArgs();
                    e1.Value = this.textBox_dataDir.Text;
                    this.VerifyDataDir(this, e1);
                    if (String.IsNullOrEmpty(e1.ErrorInfo) == false)
                    {
                        MessageBox.Show(this, e1.ErrorInfo);
                        return;
                    }
                }

                string strXmlFilename = PathUtil.MergePath(this.textBox_dataDir.Text, "databases.xml");
                if (File.Exists(strXmlFilename) == true)
                {
                    DialogResult result = MessageBox.Show(ForegroundWindow.Instance,
"您指定的数据目录 '" + this.textBox_dataDir.Text + "' 中已经存在 database.xml 文件。\r\n\r\n是否要直接利用此其中(指xml文件和目录中有关帐户文件)的配置信息?",
"安装 dp2Kernel",
MessageBoxButtons.YesNo,
MessageBoxIcon.Question,
MessageBoxDefaultButton.Button1);
                    if (result == System.Windows.Forms.DialogResult.No)
                    {
                        this.LoadedDataDir = this.textBox_dataDir.Text; // 防止重复询问
                        return;
                    }

                    if (this.LoadXmlFileInfo != null)
                    {
                        LoadXmlFileInfoEventArgs e1 = new LoadXmlFileInfoEventArgs();
                        e1.DataDir = this.textBox_dataDir.Text;
                        this.LoadXmlFileInfo(this, e1);
                        if (string.IsNullOrEmpty(e1.ErrorInfo) == false)
                        {
                            MessageBox.Show(this, e1.ErrorInfo);
                            return;
                        }

                        // refresh
                        this.LineInfo = e1.LineInfo;
                        RefreshSqlDef();
                        RefreshRootUserInfo();
                        this.LoadedDataDir = this.textBox_dataDir.Text; // 防止重复装载
                        this.m_bDataDirExist = true;    // 防止OK时不合适的检查警告
                    }
                }

                return;
            }

            // 修改时
            if (IsNew == false
    && String.IsNullOrEmpty(this.textBox_dataDir.Text) == false
    && this.LoadedDataDir != this.textBox_dataDir.Text)
            {
                // 注意检查,不能是别的instance的数据目录
                if (this.VerifyDataDir != null)
                {
                    VerifyEventArgs e1 = new VerifyEventArgs();
                    e1.Value = this.textBox_dataDir.Text;
                    this.VerifyDataDir(this, e1);
                    if (String.IsNullOrEmpty(e1.ErrorInfo) == false)
                    {
                        MessageBox.Show(this, e1.ErrorInfo);
                        return;
                    }
                }

                string strXmlFilename = PathUtil.MergePath(this.textBox_dataDir.Text, "databases.xml");
                if (File.Exists(strXmlFilename) == true)
                {
                    DialogResult result = MessageBox.Show(ForegroundWindow.Instance,
"您指定的数据目录 '" + this.textBox_dataDir.Text + "' 中已经存在 database.xml 文件。\r\n\r\n是否要直接利用其中(指xml文件和目录中有关帐户文件)的配置信息?\r\n\r\n是:直接利用其中的信息,也即将其中的配置信息装入当前对话框\r\n否:利用这个数据目录,但其中xml文件和帐户文件的相关信息即将被当前对话框中的值覆盖\r\n\r\n(提示:无论您选“是”“否”,原有目录 '" + this.LoadedDataDir + "' 都会被闲置)",
"安装 dp2Kernel",
MessageBoxButtons.YesNo,
MessageBoxIcon.Question,
MessageBoxDefaultButton.Button1);
                    if (result == System.Windows.Forms.DialogResult.No)
                    {
                        this.LoadedDataDir = this.textBox_dataDir.Text; // 防止重复询问
                        return;
                    }

                    if (this.LoadXmlFileInfo != null)
                    {
                        LoadXmlFileInfoEventArgs e1 = new LoadXmlFileInfoEventArgs();
                        e1.DataDir = this.textBox_dataDir.Text;
                        this.LoadXmlFileInfo(this, e1);
                        if (string.IsNullOrEmpty(e1.ErrorInfo) == false)
                        {
                            MessageBox.Show(this, e1.ErrorInfo);
                            return;
                        }

                        // refresh
                        this.LineInfo = e1.LineInfo;
                        RefreshSqlDef();
                        RefreshRootUserInfo();
                        this.LoadedDataDir = this.textBox_dataDir.Text; // 防止重复装载
                        this.m_bDataDirExist = true;    // 防止OK时不合适的检查警告
                    }
                }
                else if (String.IsNullOrEmpty(this.LoadedDataDir) == false)
                {
                    // 修改目录名

                    DialogResult result = MessageBox.Show(ForegroundWindow.Instance,
"要将已经存在的数据目录 '" + this.LoadedDataDir + "' 更名为 '"+this.textBox_dataDir.Text+"' 么?\r\n\r\n(如果选择“否”,则安装程序在稍后将新创建一个数据目录,并复制进初始内容)",
"安装 dp2Kernel",
MessageBoxButtons.YesNo,
MessageBoxIcon.Question,
MessageBoxDefaultButton.Button1);
                    if (result == System.Windows.Forms.DialogResult.No)
                    {
                        this.m_bDataDirExist = false;
                        return;
                    }

                    try
                    {
                        // TODO: 需要测试当数据目录中内容尺寸太大,而目标盘无妨容纳时的报错情况
                        Directory.Move(this.LoadedDataDir, this.textBox_dataDir.Text);

                        this.LoadedDataDir = this.textBox_dataDir.Text; // 防止重复装载
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(this, "将已经存在的数据目录 '" + this.LoadedDataDir + "' 更名为 '"+this.textBox_dataDir.Text+"' 时发生错误: " + ex.Message);
                    }

                }

                return;
            }

        }
Exemplo n.º 29
0
        // 数据目录需要更名的情况,是否延迟到 OK 时候执行?如果立即执行,则需要禁止 Cancel 按钮,表示必须 OK 结束对话框
        // 检测目录是否已经存在
        // return:
        //      -1  出错
        //      0   没有处理
        //      1   已经处理
        int RenameDataDir(out string strError)
        {
            strError = "";

#if NO
            // 已经准备Cancel,就不检查了
            if (IsMouseOnCancelButton() == true)
            {
                return;
            }
#endif

            // 新建时
            if (CreateMode == true &&
                String.IsNullOrEmpty(this.textBox_dataDir.Text) == false &&
                this.LoadedDataDir != this.textBox_dataDir.Text)
            {
                // 注意检查,不能是别的instance的数据目录
                if (this.VerifyDataDir != null)
                {
                    VerifyEventArgs e1 = new VerifyEventArgs();
                    e1.Value = this.textBox_dataDir.Text;
                    this.VerifyDataDir(this, e1);
                    if (String.IsNullOrEmpty(e1.ErrorInfo) == false)
                    {
                        strError = e1.ErrorInfo;
                        return(-1);
                    }
                }

                string strXmlFilename = PathUtil.MergePath(this.textBox_dataDir.Text, "opac.xml");
                if (File.Exists(strXmlFilename) == true)
                {
                    DialogResult result = MessageBox.Show(this,
                                                          "您指定的数据目录 '" + this.textBox_dataDir.Text + "' 中已经存在 opac.xml 文件。\r\n\r\n是否要直接利用其中的配置信息?",
                                                          "安装 dp2OPAC",
                                                          MessageBoxButtons.YesNo,
                                                          MessageBoxIcon.Question,
                                                          MessageBoxDefaultButton.Button1);
                    if (result == System.Windows.Forms.DialogResult.No)
                    {
                        this.LoadedDataDir = this.textBox_dataDir.Text; // 防止重复询问
                        return(0);
                    }

                    if (this.LoadXmlFileInfo != null)
                    {
                        LoadXmlFileInfoEventArgs e1 = new LoadXmlFileInfoEventArgs();
                        e1.DataDir = this.textBox_dataDir.Text;
                        this.LoadXmlFileInfo(this, e1);
                        if (string.IsNullOrEmpty(e1.ErrorInfo) == false)
                        {
                            strError = e1.ErrorInfo;
                            return(-1);
                        }

                        // refresh
                        this.LineInfo = (LineInfo)e1.LineInfo;
                        //Refreshdp2KernelDef();
                        //RefreshSupervisorUserInfo();
                        //RefreshLibraryName();
                        //RefreshUpdateCfgsDir();
                        RefreshDp2LibraryInfo();

                        this.LoadedDataDir   = this.textBox_dataDir.Text; // 防止重复装载
                        this.m_bDataDirExist = true;                      // 防止OK时不合适的检查警告
                    }
                }

                return(0);
            }

            // 修改时
            if (CreateMode == false &&
                String.IsNullOrEmpty(this.textBox_dataDir.Text) == false &&
                this.LoadedDataDir != this.textBox_dataDir.Text)
            {
                // 注意检查,不能是别的instance的数据目录
                if (this.VerifyDataDir != null)
                {
                    VerifyEventArgs e1 = new VerifyEventArgs();
                    e1.Value = this.textBox_dataDir.Text;
                    this.VerifyDataDir(this, e1);
                    if (String.IsNullOrEmpty(e1.ErrorInfo) == false)
                    {
                        strError = e1.ErrorInfo;
                        return(-1);
                    }
                }

                string strXmlFilename = PathUtil.MergePath(this.textBox_dataDir.Text, "opac.xml");
                if (File.Exists(strXmlFilename) == true)
                {
                    DialogResult result = MessageBox.Show(this,
                                                          "您指定的数据目录 '" + this.textBox_dataDir.Text + "' 中已经存在 opac.xml 文件。\r\n\r\n是否要直接利用其中的配置信息?\r\n\r\n是:直接利用其中的信息,也即将其中的配置信息装入当前对话框\r\n否:利用这个数据目录,但其中xml文件的相关信息即将被当前对话框中的值覆盖\r\n\r\n(提示:无论您选“是”“否”,原有目录 '" + this.LoadedDataDir + "' 都会被闲置)",
                                                          "安装 dp2OPAC",
                                                          MessageBoxButtons.YesNo,
                                                          MessageBoxIcon.Question,
                                                          MessageBoxDefaultButton.Button1);
                    if (result == System.Windows.Forms.DialogResult.No)
                    {
                        this.LoadedDataDir = this.textBox_dataDir.Text; // 防止重复询问
                        return(0);
                    }

                    if (this.LoadXmlFileInfo != null)
                    {
                        LoadXmlFileInfoEventArgs e1 = new LoadXmlFileInfoEventArgs();
                        e1.DataDir = this.textBox_dataDir.Text;
                        this.LoadXmlFileInfo(this, e1);
                        if (string.IsNullOrEmpty(e1.ErrorInfo) == false)
                        {
                            strError = e1.ErrorInfo;
                            return(-1);
                        }

                        // refresh
                        this.LineInfo = (LineInfo)e1.LineInfo;
                        //Refreshdp2KernelDef();
                        //RefreshSupervisorUserInfo();
                        //RefreshLibraryName();
                        //RefreshUpdateCfgsDir();
                        RefreshDp2LibraryInfo();

                        this.LoadedDataDir   = this.textBox_dataDir.Text; // 防止重复装载
                        this.m_bDataDirExist = true;                      // 防止OK时不合适的检查警告
                    }
                }
                else if (String.IsNullOrEmpty(this.LoadedDataDir) == false)
                {
                    // 修改目录名

                    DialogResult result = MessageBox.Show(this,
                                                          "要将已经存在的数据目录 '" + this.LoadedDataDir + "' 更名为 '" + this.textBox_dataDir.Text + "' 么?\r\n\r\n(如果选择“否”,则安装程序在稍后将新创建一个数据目录,并复制进初始内容)",
                                                          "安装 dp2OPAC",
                                                          MessageBoxButtons.YesNo,
                                                          MessageBoxIcon.Question,
                                                          MessageBoxDefaultButton.Button1);
                    if (result == System.Windows.Forms.DialogResult.No)
                    {
                        this.m_bDataDirExist = false;
                        return(0);
                    }

REDO_MOVE:
                    strError = "";
                    try
                    {
                        // TODO: 需要测试当数据目录中内容尺寸太大,而目标盘无妨容纳时的报错情况
                        Directory.Move(this.LoadedDataDir, this.textBox_dataDir.Text);

                        this.LoadedDataDir = this.textBox_dataDir.Text; // 防止重复装载
                    }
                    catch (Exception ex)
                    {
                        // MessageBox.Show(this, "将已经存在的数据目录 '" + this.LoadedDataDir + "' 更名为 '" + this.textBox_dataDir.Text + "' 时发生错误: " + ex.Message);
                        strError = "将已经存在的数据目录 '" + this.LoadedDataDir + "' 更名为 '" + this.textBox_dataDir.Text + "' 时发生错误: " + ex.Message;
                    }

                    if (string.IsNullOrEmpty(strError) == false)
                    {
                        DialogResult temp_result = MessageBox.Show(this,
                                                                   strError + "\r\n\r\n建议先停止 IIS,然后重试操作。\r\n\r\n是否重试?",
                                                                   "安装 dp2OPAC",
                                                                   MessageBoxButtons.RetryCancel,
                                                                   MessageBoxIcon.Question,
                                                                   MessageBoxDefaultButton.Button1);
                        if (temp_result == DialogResult.Retry)
                        {
                            goto REDO_MOVE;
                        }
                        return(-1);
                    }
                }

                return(0);
            }

            return(0);
        }
Exemplo n.º 30
0
 void new_instance_dlg_VerifyDataDir(object sender, VerifyEventArgs e)
 {
     bool bRet = IsDataDirDup(e.Value,
         (ListViewItem)null);
     if (bRet == true)
         e.ErrorInfo = "数据目录 '" + e.Value + "' 和已存在的其他实例发生了重复";
 }
Exemplo n.º 31
0
        private void verifyLevel3Authentication(SecureSocket socket,
                                                Certificate cert,
                                                CertificateChain chain,
                                                VerifyEventArgs e
                                                )
        {
            try
            {
                // Verify level 2 first
                verifyLevel2Authentication(socket, cert, chain, e);
                if (!e.Valid)
                {
                    return;
                }

                // Verify that the host name or IP matches the subject on the certificate
                // ( Level3 authentication )
                // First, get the "CN=" name from the certificate
                string            commonName      = null;
                DistinguishedName certificateName = cert.GetDistinguishedName();
                for (int a = 0; a < certificateName.Count; a++)
                {
                    NameAttribute part = certificateName[a];
                    if (part.ObjectID == OID_CN)
                    {
                        commonName = part.Value;
                        break;
                    }
                }
                if (commonName == null)
                {
                    if ((Adk.Debug & AdkDebugFlags.Messaging_Detailed) != 0)
                    {
                        log.Warn
                            ("Client Certificate fails SIF Level 3 Authentication: common name attribute not found.");
                    }
                    e.Valid = false;
                    return;
                }

                if (String.Compare(commonName, "localhost", true) == 0)
                {
                    commonName = "127.0.0.1";
                }

                // Does it match the IP Address?
                IPEndPoint remoteEndPoint = (IPEndPoint)socket.RemoteEndPoint;
                if (remoteEndPoint.Address.ToString() == commonName)
                {
                    e.Valid = true;
                    return;
                }

                // Does it match the common name of the client machine?
                IPHostEntry entry = GetHostByAddress(remoteEndPoint.Address);
                if (entry == null)
                {
                    if ((Adk.Debug & AdkDebugFlags.Messaging_Detailed) != 0)
                    {
                        log.Warn
                            ("Client Certificate fails SIF Level 3 Authentication: Host Name not found for Address " +
                            remoteEndPoint.Address.ToString());
                    }
                    e.Valid = false;
                    return;
                }

                if (string.Compare(commonName, entry.HostName, true) == 0)
                {
                    e.Valid = true;
                    return;
                }

                // No match was found
                e.Valid = false;
                if ((Adk.Debug & AdkDebugFlags.Messaging_Detailed) != 0)
                {
                    log.Warn
                        ("Client Certificate fails SIF Level 3 Authentication: Certificate Common Name=" +
                        commonName + ". Does not match client IP / Host: " +
                        remoteEndPoint.Address.ToString() + " / " + socket.CommonName);
                }
            }
            catch (Exception ex)
            {
                if ((Adk.Debug & AdkDebugFlags.Messaging_Detailed) != 0)
                {
                    log.Warn
                        ("Client Certificate fails SIF Level 3 Authentication: " + ex.Message, ex);
                }
                e.Valid = false;
            }
        }
Exemplo n.º 32
0
        void modify_instance_dlg_VerifyBindings(object sender, VerifyEventArgs e)
        {
            string strError = "";
            // return:
            //      -1  出错
            //      0   不重
            //      1    重复
            int nRet = IsBindingDup(e.Value,
            this.m_currentEditItem,
            out strError);
            if (nRet != 0)
            {
                e.ErrorInfo = strError;
                return;
            }

            nRet = InstallHelper.IsGlobalBindingDup(e.Value,
"dp2Kernel",
out strError);
            if (nRet != 0)
            {
                e.ErrorInfo = strError;
                return;
            }
        }
Exemplo n.º 33
0
        private void button_OK_Click(object sender, EventArgs e)
        {
            string strError = "";

            // 检查

            // 数据目录
            if (String.IsNullOrEmpty(this.textBox_dataDir.Text) == true)
            {
                strError = "尚未指定数据目录";
                goto ERROR1;
            }

            // dp2Kernel服务器信息
            if (String.IsNullOrEmpty(this.textBox_dp2KernelDef.Text) == true)
            {
                strError = "尚未指定dp2Kernel服务器信息";
                goto ERROR1;
            }

            // 协议绑定
            if (String.IsNullOrEmpty(this.textBox_bindings.Text) == true)
            {
                strError = "尚未指定协议绑定信息";
                goto ERROR1;
            }

            // 图书馆名
            if (String.IsNullOrEmpty(this.textBox_libraryName.Text) == true)
            {
                strError = "尚未指定图书馆名";
                goto ERROR1;
            }
            if (this.LineInfo == null)
            {
                this.LineInfo = new DigitalPlatform.LibraryServer.LineInfo();
            }
            this.LineInfo.LibraryName = this.textBox_libraryName.Text;

            this.LineInfo.UpdateCfgsDir = this.checkBox_updateCfgsDir.Checked;

            // 检查是否为旧式url地址
            string strKernelUrl = this.LineInfo.KernelUrl;

            if (strKernelUrl.IndexOf(".asmx") != -1)
            {
                strError = "安装程序发现当前使用了旧版本数据库内核的地址 '" + strKernelUrl + "',需要您将它修改为新版dp2Kernel(内核)的URL地址。";
                goto ERROR1;
            }

            if (this.IsNew == true &&
                this.m_bDataDirExist == false)
            {
                // supervisor用户信息
                if (this.LineInfo.SupervisorUserName == null ||
                    this.LineInfo.SupervisorPassword == null ||
                    this.LineInfo.SupervisorRights == null)
                {
                    strError = "尚未设定supervisor账户的用户名、密码、权限";
                    goto ERROR1;
                }
            }

            // 如果修改时,需要创建新的数据目录
            if (this.IsNew == false)
            {
                // 探测数据目录,是否已经存在数据,是不是属于升级情形
                // return:
                //      -1  error
                //      0   数据目录不存在
                //      1   数据目录存在,但是xml文件不存在
                //      2   xml文件已经存在
                int nRet = LibraryInstallHelper.DetectDataDir(this.textBox_dataDir.Text,
                                                              out strError);
                if (nRet == -1)
                {
                    strError = "探测数据目录 '" + this.textBox_dataDir.Text + "' 是否存在时,出现错误: " + strError;
                    goto ERROR1;
                }

                if (nRet == 0 || nRet == 1)
                {
                    // supervisor用户信息
                    if (this.LineInfo.SupervisorUserName == null ||
                        this.LineInfo.SupervisorPassword == null ||
                        this.LineInfo.SupervisorRights == null)
                    {
                        strError = "尚未设定supervisor账户的用户名、密码、权限";
                        goto ERROR1;
                    }
                }
            }

            // TODO: 如果在编辑状态,需要排除和listview中自己重的情况

            if (this.VerifyInstanceName != null)
            {
                VerifyEventArgs e1 = new VerifyEventArgs();
                e1.Value = this.textBox_instanceName.Text;
                this.VerifyInstanceName(this, e1);
                if (String.IsNullOrEmpty(e1.ErrorInfo) == false)
                {
                    strError = e1.ErrorInfo;
                    goto ERROR1;
                }
            }

            if (this.VerifyDataDir != null)
            {
                VerifyEventArgs e1 = new VerifyEventArgs();
                e1.Value = this.textBox_dataDir.Text;
                this.VerifyDataDir(this, e1);
                if (String.IsNullOrEmpty(e1.ErrorInfo) == false)
                {
                    strError = e1.ErrorInfo;
                    goto ERROR1;
                }
            }

            if (this.VerifyBindings != null)
            {
                VerifyEventArgs e1 = new VerifyEventArgs();
                e1.Value = this.textBox_bindings.Text;
                this.VerifyBindings(this, e1);
                if (String.IsNullOrEmpty(e1.ErrorInfo) == false)
                {
                    strError = e1.ErrorInfo;
                    goto ERROR1;
                }
            }

            this.DialogResult = System.Windows.Forms.DialogResult.OK;
            this.Close();
            return;

ERROR1:
            MessageBox.Show(this, strError);
        }
Exemplo n.º 34
0
 void modify_instance_dlg_VerifyInstanceName(object sender, VerifyEventArgs e)
 {
     bool bRet = IsInstanceNameDup(e.Value,
         this.m_currentEditItem);
     if (bRet == true)
         e.ErrorInfo = "实例名 '"+e.Value+"' 和已存在的其他实例发生了重复";
 }
Exemplo n.º 35
0
 private void OnCertificateVerify(SecureSocket socket, Certificate remote, CertificateChain chain, VerifyEventArgs e)
 {
     Certificate[] certs = chain.GetCertificates();
     chain.VerifyChain(socket.CommonName, AuthType.Server);
 }