Ejemplo n.º 1
0
        public override void ProcessRequest(HttpContext context)
        {
            ISession s = this.CurrentSession;

            using (ITransaction t = s.BeginTransaction()) {
                Guid userID   = new Guid(context.Request ["UserID"]);
                Guid clientID = new Guid(context.Request ["ClientID"]);

                PersistentUser   user   = s.Get <PersistentUser> (userID);
                PersistentClient client = s.Get <PersistentClient> (clientID);

                if (user == null || !user.HasAPIAccess)
                {
                    throw new Exception("no api access");
                }

                if (client == null || !client.HasAPIAccess)
                {
                    throw new Exception("no api access");
                }

                PersistentProfile     p    = s.Get <PersistentProfile>(new Guid(context.Request["ProfileID"]));
                DateTime              now  = DateTime.Now;
                PersistentProfileHost host = new PersistentProfileHost(new Guid(context.Request ["WebUserID"]));
                host.ParentProfile       = p;
                host.Name                = context.Request["HostSubDomain"];
                host.IPv4Address         = Dns.GetHostEntry(context.Request["HostSubDomain"]).AddressList [0].ToString();
                host.VerifiedByFile      = true;
                host.VerifiedByWhois     = true;
                host.VerifiedOn          = DateTime.Now;
                host.WasManuallyVerified = false;
                host.IsVerified          = true;
                host.CreatedBy           = Guid.Empty;
                host.CreatedOn           = now;
                host.LastModifiedBy      = Guid.Empty;
                host.LastModifiedOn      = now;
                host.IsActive            = true;

                p.Range += " " + host.IPv4Address;
                p.SetUpdateInfo(Guid.Empty, true);

                s.Save(p);
                s.Save(host);

                try {
                    t.Commit();
                } catch (Exception ex) {
                    t.Rollback();

                    throw ex;
                }

                string xml = host.ToPersistentXML(false /*include nmap hosts? no, because none exist right now*/);

                context.Response.Write(xml);
            }
        }
Ejemplo n.º 2
0
        protected void btnAddHost_Click(object sender, EventArgs e)
        {
            Session["CreateProfile?CurrentHost"] = txtHostURL.Text;
            string url = ConfigurationManager.AppSettings["API"] + "/CreateWhoisReport.ashx?Host=" + Session["CreateProfile?CurrentHost"] +
                         "&WebUserID=" + this.CurrentUser.ID.ToString() +
                         "&UserID=" + ConfigurationManager.AppSettings["UserID"] +
                         "&ClientID=" + ConfigurationManager.AppSettings["ClientID"];

            WebRequest request  = WebRequest.Create(url);
            string     response = string.Empty;

            using (StreamReader reader = new StreamReader(request.GetResponse().GetResponseStream()))
                response = reader.ReadToEnd();

            Session["CreateProfile?CurrentProfileHost"]  = new PersistentProfileHost(this.CurrentUser.UserID);
            Session["CreateProfile?CurrentVerification"] = new PersistentProfileHostVerification(new ProfileHostVerification(), this.CurrentUser.UserID);

            (Session["CreateProfile?CurrentVerification"] as PersistentProfileHostVerification).ProfileHost = Session["CreateProfile?CurrentProfileHost"] as PersistentProfileHost;

            List <string> emails = FindEmailAddresses(response).ToList();

            if (emails.Count == 0)
            {
                throw new Exception("Cannot verify whois with an email address.");
            }

            ddlWhoisEmail.DataSource = emails;
            ddlWhoisEmail.DataBind();

            lblFileContents.Text    = (Session["CreateProfile?CurrentVerification"] as PersistentProfileHostVerification).VerificationData;
            lblFilename.Text        = (Session["CreateProfile?CurrentVerification"] as PersistentProfileHostVerification).VerificationFileName;
            lblVerificationURL.Text = "http://" + Session["CreateProfile?CurrentHost"] + ":80/" + (Session["CreateProfile?CurrentVerification"] as PersistentProfileHostVerification).VerificationFileName;

            divAddHostContainer.Attributes["class"] = "addHostContainerInactive";
            txtHostURL.Enabled = false;
            btnAddHost.Enabled = false;

            divMultiEmailContainer.Attributes["class"] = "multiEmailContainerActive";
            ddlWhoisEmail.Enabled       = true;
            btnSendVerification.Enabled = true;
        }
Ejemplo n.º 3
0
        public override void ProcessRequest(HttpContext context)
        {
            ISession s = this.CurrentSession;

            using (ITransaction t = s.BeginTransaction())
            {
                Console.WriteLine("fdsa");
                Guid userID   = new Guid(context.Request["UserID"]);
                Guid clientID = new Guid(context.Request["ClientID"]);

                PersistentUser   user   = s.Get <PersistentUser>(userID);
                PersistentClient client = s.Get <PersistentClient>(clientID);

                if (user == null || !user.HasAPIAccess)
                {
                    throw new Exception("no api access");
                }

                if (client == null || !client.HasAPIAccess)
                {
                    throw new Exception("no api access");
                }

                PersistentProfile profile = new PersistentProfile();

                string webUserID = context.Request["WebUserID"];

                profile.WebUserID   = new Guid(context.Request["WebUserID"]);
                profile.Description = context.Request["ProfileDescription"];
                profile.Name        = context.Request["ProfileName"];
                profile.Range       = context.Request["ProfileDomain"];
                profile.Domain      = context.Request["ProfileDomain"];
                profile.RunEvery    = new TimeSpan(24 * (int.Parse(context.Request["ProfileSchedule"])), 0, 0);            //30 days
                profile.RunAfter    = DateTime.Now;
                profile.HasRun      = false;

                profile.SetCreationInfo(userID);

                s.Save(profile);

                foreach (string h in profile.Range.Split(','))
                {
                    PersistentProfileHost host = new PersistentProfileHost(new Guid(context.Request["WebUserID"]));
                    host.ParentProfile       = profile;
                    host.IPv4Address         = Dns.GetHostEntry(h).AddressList[0].ToString();
                    host.VerifiedByFile      = true;
                    host.VerifiedByWhois     = true;
                    host.VerifiedOn          = DateTime.Now;
                    host.WasManuallyVerified = false;
                    host.IsVerified          = true;

                    s.Save(host);
                }

                try
                {
                    t.Commit();
                }
                catch (Exception ex)
                {
                    t.Rollback();

                    throw ex;
                }

                string xml = profile.ToPersistentXml();

                context.Response.Write(xml);
            }
        }