Пример #1
0
        public MX_RR(byte[] data, int offset, int len)
        {
            Preference = data[offset++] * 256 + data[offset++];
            int labelLen;

            Mail = MyDns.GetLabelName(data, offset, out labelLen);
        }
Пример #2
0
        int RunServer()
        {
            if (host == null)
            {
                host = MyDns.GetHostName();
            }
            CmdServer server = new CmdServer(host, port);

            Console.WriteLine("server {0} started, press enter to exit", port);
            Console.ReadLine();
            server.Stop();
            return(0);
        }
 private void bw_DoWork(object sender, DoWorkEventArgs e)
 {
     if (bw.CancellationPending)
     {
         return;
     }
     else
     {
         dt.Rows.Add("DNS记录", "记录类型", "解析结果", "TTL");
         MyDns mydns = new MyDns();
         if (!mydns.Search(_host, QueryType.A, _dnsname, null))
         {
             UMessageBox.Show("提示", mydns.header.RCODE.ToString());
             return;
         }
         foreach (MyDnsRecord item in mydns.record.Records)
         {
             dt.Rows.Add(item.Name, item.QType.ToString(), item.RDDate.ToString().Replace(" ", ""), item.TTL.ToString());
         }
         if (!mydns.Search(_host, QueryType.MX, _dnsname, null))
         {
             UMessageBox.Show("提示", mydns.header.RCODE.ToString());
             return;
         }
         foreach (MyDnsRecord item in mydns.record.Records)
         {
             dt.Rows.Add(item.Name, item.QType.ToString(), item.RDDate.ToString().Replace(" ", "").Replace('|', '\r'), item.TTL.ToString());
         }
         if (!mydns.Search(_host, QueryType.CNAME, _dnsname, null))
         {
             UMessageBox.Show("提示", mydns.header.RCODE.ToString());
             return;
         }
         foreach (MyDnsRecord item in mydns.record.Records)
         {
             dt.Rows.Add(item.Name, item.QType.ToString(), item.RDDate.ToString().Replace(" ", "").Replace('|', '\r'), item.TTL.ToString());
         }
         if (!mydns.Search(_host, QueryType.TXT, _dnsname, null))
         {
             UMessageBox.Show("提示", mydns.header.RCODE.ToString());
             return;
         }
         foreach (MyDnsRecord item in mydns.record.Records)
         {
             dt.Rows.Add(item.Name, item.QType.ToString(), item.RDDate.ToString().Replace(' ', '\r'), item.TTL.ToString());
         }
         bw.ReportProgress(100);
     }
 }
Пример #4
0
        int Invite(string user, Uri docRoot, string invitationFile)
        {
            if (host == null)
            {
                host = MyDns.GetHostName();
            }
            FileInviter fi = new FileInviter();

            if (!fi.Invite(user, docRoot, host, port, invitationFile))
            {
                Console.WriteLine("could not make invitation");
                return(20);
            }
            return(0);
        }
Пример #5
0
        public SOA_RR(byte[] data, int offset, int len)
        {
            int endOffset = offset + len;
            int labelLen;

            NameServer = MyDns.GetLabelName(data, offset, out labelLen);
            offset    += labelLen;
            Mail       = MyDns.GetLabelName(data, ++offset, out labelLen);
            offset    += labelLen;
            offset++;
            Serial  = data[offset++] * 256 * 256 * 256 + data[offset++] * 256 * 256 + data[offset++] * 256 + data[offset++];
            Refresh = data[offset++] * 256 * 256 * 256 + data[offset++] * 256 * 256 + data[offset++] * 256 + data[offset++];
            Retry   = data[offset++] * 256 * 256 * 256 + data[offset++] * 256 * 256 + data[offset++] * 256 + data[offset++];
            Expire  = data[offset++] * 256 * 256 * 256 + data[offset++] * 256 * 256 + data[offset++] * 256 + data[offset++];
            TTL     = data[offset++] * 256 * 256 * 256 + data[offset++] * 256 * 256 + data[offset++] * 256 + data[offset++];
        }
Пример #6
0
        /// <summary>
        /// Initializes a module and prepares it to handle requests.
        /// </summary>
        /// <param name="app">An HttpApplication that provides access to the methods,
        /// properties, and events common to all application objects within an ASP.NET
        /// application </param>
        public void Init(HttpApplication app)
        {
            // Register for the interesting events in the HTTP life-cycle.
            app.BeginRequest        += new EventHandler(OnBeginRequest);
            app.AuthenticateRequest += new EventHandler(OnAuthenticateRequest);
            app.AcquireRequestState += new EventHandler(OnAcquireRequestState);

            // Get the application settings from the Simias.config.
            string setting = Store.Config.Get("Authentication", "SimiasRequireSSL");

            if (setting != null)
            {
                if (String.Compare(setting, "no", true) == 0)
                {
                    sslRequired = false;
                }
            }

            // Get the ssl port setting.
            setting = Store.Config.Get("Authentication", "SimiasSSLPort");
            if (setting != null)
            {
                sslPort = Convert.ToInt32(setting);
            }

            // Get the services that do not need authentication.
            setting = Store.Config.Get("Authentication", "SimiasAuthNotRequired");
            if (setting != null)
            {
                ParseAuthNotRequiredServices(setting);
            }

            // Get all the addresses that this host is known by.
            string[] addresses = MyDns.GetHostAddresses();
            foreach (string s in addresses)
            {
                localAddresses[s.ToLower()] = null;
            }
        }
Пример #7
0
        private void btnSearch_Click(object sender, EventArgs e)
        {
            Type      myenum = typeof(QueryType);
            Array     ar     = Enum.GetValues(myenum);
            QueryType qtype  = (QueryType )ar.GetValue(cbType.SelectedIndex);
            MyDns     mydns  = new MyDns();

            if (!mydns.Search(txtDomain.Text.Trim(), qtype, txtDns.Text.Trim(), null))
            {
                MessageBox.Show(mydns.header.RCODE.ToString());
                return;
            }
            txtInfo.Clear();
            txtInfo.AppendText(string.Format("回复记录数:{0}\n", mydns.header.ANCOUNT));
            txtInfo.AppendText(string.Format("回复额外记录数:{0}\n", mydns.header.ARCOUNT));
            txtInfo.AppendText(string.Format("回复权威记录数:{0}", mydns.header.NSCOUNT));

            txtContent.Clear();
            foreach (MyDnsRecord item in mydns.record.Records)
            {
                txtContent.AppendText(item.QType.ToString() + "   " + item.RDDate.ToString() + "\n");
            }
        }
Пример #8
0
        /// <summary>
        /// Construct a Host domain.
        /// </summary>
        /// <param name="domain">The enterprise domain.</param>
        public HostProvider(Domain domain)
        {
            hostDomain = domain;

            // Check if this is the master server.
            bool master = (hostDomain.Role == SyncRoles.Master) ? true : false;

            // Get the HostDomain
            // If the HostNode does not exist create it.
            lock (typeof(HostProvider))
            {
                // Check if the host node exists.
                string hName = Store.Config.Get(ServerSection, ServerNameKey);

                // Make sure a master host can run without any pre-configured settings
                // so if the public address wasn't configured get a non-loopback local
                // address and configure the public address with it.
                string publicAddress = Store.Config.Get(ServerSection, PublicAddressKey);
                if (publicAddress == null || publicAddress == String.Empty)
                {
                    // Get the first non-localhost address
                    string[] addresses = MyDns.GetHostAddresses();
                    foreach (string addr in addresses)
                    {
                        if (IPAddress.IsLoopback(IPAddress.Parse(addr)) == false)
                        {
                            publicAddress = addr;
                            break;
                        }
                    }
                }

                string privateAddress = Store.Config.Get(ServerSection, PrivateAddressKey);
                if (privateAddress == null || privateAddress == String.Empty)
                {
                    if (publicAddress != null)
                    {
                        privateAddress = publicAddress;
                    }
                }

                string masterAddress = Store.Config.Get(ServerSection, MasterAddressKey);
                Member mNode         = hostDomain.GetMemberByName(hName);
                host = (mNode == null) ? null : new HostNode(mNode);
                if (host == null)
                {
                    Console.Error.WriteLine("Checking if the host node exists.");
                    HostNode hn = HostNode.GetLocalHost();
                    if (hn == null)
                    {
                        Console.Error.WriteLine("Host node is null.");
                    }
                    else
                    {
                        Console.Error.WriteLine("Host node ID is: {0} and public url is: {1}", hn.ID, hn.PublicUrl);
                    }
                    host = hn;
                }

                if (host == null)
                {
                    Console.Error.WriteLine("Host node is null. Creating the host node.");
                    RSACryptoServiceProvider rsa = new RSACryptoServiceProvider();
                    if (master == true)
                    {
                        host              = new HostNode(hName, System.Guid.NewGuid().ToString(), publicAddress, privateAddress, rsa);
                        host.Rights       = Simias.Storage.Access.Rights.Admin;
                        host.IsMasterHost = true;
                    }
                    else
                    {
                        host       = SlaveSetup.GetHost(Store.StorePath);
                        host.Proxy = true;
                        rsa        = SlaveSetup.GetKeys(Store.StorePath);
                        // TODO remove
                        Property p = new Property(PropertyTags.HostAddress, new Uri(masterAddress));
                        p.LocalProperty = true;
                        hostDomain.Properties.AddNodeProperty(p);
                        // END TODO
                    }

                    host.IsLocalHost = true;
                    hostDomain.Commit(new Node[] { hostDomain, host });

                    // Now Associate this host with the local identity.
                    store.AddDomainIdentity(hostDomain.ID, host.UserID, rsa.ToXmlString(true), Simias.Storage.CredentialType.PPK);
                    SlaveSetup.DeleteTempSetupFiles(Store.StorePath);
                }
                else
                {
                    Console.Error.WriteLine("Host is not null. Updating the host node.");
                    if (host.IsMasterHost == true)
                    {
                        // Make sure the address has not changed.
                        bool hostChanged = false;
                        if (host.PublicUrl != publicAddress)
                        {
                            host.PublicUrl = publicAddress;
                            hostChanged    = true;
                        }
                        if (host.PrivateUrl != privateAddress)
                        {
                            host.PrivateUrl = privateAddress;
                            hostChanged     = true;
                        }

                        if (hostChanged == true)
                        {
                            hostDomain.Commit(host);
                        }
                    }
                }
            }

            if (master == true)
            {
                // Register the ProvisionUser Provider.
                ProvisionService.RegisterProvider(new LoadBalanceProvisionUserProvider());
                //ProvisionService.RegisterProvider( new MasterHostProvisionProvider() );
            }
            else
            {
                // Now start the sync process for the domain.
                Thread syncThread = new Thread(new ThreadStart(SyncDomain));
                syncThread.IsBackground = true;
                syncThread.Name         = "Domain Sync Thread";
                syncThread.Start();
            }
        }
Пример #9
0
        public NS_RR(byte[] data, int offset, int len)
        {
            int labelLen;

            NameServer += MyDns.GetLabelName(data, offset, out labelLen);
        }
Пример #10
0
        public CNAME_RR(byte[] data, int offset, int len)
        {
            int labelLen;

            name += MyDns.GetLabelName(data, offset, out labelLen);
        }