protected void btnCreateProfile_Click(object sender, EventArgs e)
        {
            string url = ConfigurationManager.AppSettings["API"] + "/CreateProfile.ashx" +
                "?WebUserID=" + this.CurrentUser.ID.ToString() +
                "&UserID=" + ConfigurationManager.AppSettings["UserID"] +
                "&ClientID=" + ConfigurationManager.AppSettings["ClientID"] +
                "&ProfileDomain=" + Session["CreateProfile?CurrentHost"] +
                "&ProfileSchedule=" + Session["CreateProfile?ProfileSchedule"] +
                "&ProfileDescription=" + Session["CreateProfile?ProfileDescription"] +
                "&ProfileName=" + Session["CreateProfile?ProfileName"];

            WebRequest request = WebRequest.Create(url);

            string xml = string.Empty;

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

            XmlDocument doc = new XmlDocument();
            doc.LoadXml(xml);

            PersistentProfile profile = new PersistentProfile(doc.FirstChild);

            this.CurrentProfile = profile;

            Response.Redirect("/ViewProfile.aspx?pid=" + profile.ID.ToString());
        }
        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 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["ProfileRange"];
                profile.RunEvery = new TimeSpan(24*(int.Parse(context.Request["ProfileSchedule"])), 0, 0);
                profile.RunAfter = DateTime.Now;
                profile.HasRun = false;

                profile.SetCreationInfo(userID);

                s.Save(profile);

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

                    throw ex;
                }

                string xml = profile.ToPersistentXml();

                context.Response.Write(xml);
            }
        }
        protected override void OnInit(EventArgs e)
        {
            base.OnInit (e);

            HttpWebRequest request = WebRequest
                .Create(ConfigurationManager.AppSettings["API"] + "/GetProfile.ashx" +
                    "?WebUserID=" + this.CurrentUser.UserID.ToString() +
                    "&UserID=" + ConfigurationManager.AppSettings["UserID"] +
                    "&IsActive=" + true +
                    "&ProfileID=" + Request["pid"] +
                    "&ClientID=" + ConfigurationManager.AppSettings["ClientID"]) as HttpWebRequest;

            WebResponse response = request.GetResponse();

            XmlDocument doc = new XmlDocument();
            string xml = string.Empty;
            byte[] buff = new byte[2048];
            int bytes = 0;
            using (Stream stream = response.GetResponseStream())
            {
                do
                {
                    bytes = stream.Read(buff, 0, buff.Length);

                    xml = xml + ASCIIEncoding.ASCII.GetString(buff);

                    buff = new byte[2048]; //clear cruft
                } while (bytes > 0);
            }

            xml = xml.Replace("&", "&amp;");

            doc.LoadXml(xml);

            PersistentProfile profile = new PersistentProfile(doc.DocumentElement);

            this.CurrentProfile = profile;

            string filename = Guid.NewGuid().ToString() + ".txt";
            string filedata = System.Convert.ToBase64String(Guid.NewGuid().ToByteArray());

            Session["VerifyProfile?FileName"] = filename;
            Session["VerifyProfile?FileData"] = filedata;
        }
Beispiel #4
0
        protected void btnCreateScanFromProfile_Click(object sender, EventArgs e)
        {
            Button l = sender as Button;

            HttpWebRequest request = WebRequest
                .Create(ConfigurationManager.AppSettings["API"] + "/GetProfile.ashx" +
                    "?WebUserID=" + this.CurrentUser.UserID.ToString() +
                    "&UserID=" + ConfigurationManager.AppSettings["UserID"] +
                    "&IsActive=" + true +
                    "&ProfileID=" + l.CommandArgument +
                    "&ClientID=" + ConfigurationManager.AppSettings["ClientID"]) as HttpWebRequest;

            WebResponse response = request.GetResponse();

            XmlDocument doc = new XmlDocument();
            string xml = string.Empty;
            byte[] buff = new byte[2048];
            int bytes = 0;
            using (Stream stream = response.GetResponseStream())
            {
                do
                {
                    bytes = stream.Read(buff, 0, buff.Length);

                    xml = xml + ASCIIEncoding.ASCII.GetString(buff);

                    buff = new byte[2048]; //clear cruft
                } while (bytes > 0);
            }

            doc.LoadXml(xml);

            PersistentProfile profile = new PersistentProfile(doc.DocumentElement);

            this.CurrentProfile = profile;

            Response.Redirect("/CreateScan.aspx");
        }
Beispiel #5
0
        private string MakeProfile()
        {
            string url = ConfigurationManager.AppSettings["API"] + "/CreateProfile.ashx" +
                "?WebUserID=" + ddlUser.SelectedValue +
                "&UserID=" + ConfigurationManager.AppSettings["UserID"] +
                "&ClientID=" + ConfigurationManager.AppSettings["ClientID"] +
                "&ProfileDomain=" + txtHosts.Text +
                "&ProfileSchedule=" + "30" + //30 days
                "&ProfileDescription=" + "Created through the admin interface" +
                "&ProfileName=" + txtProfileName.Text;

            WebRequest request = WebRequest.Create(url);

            string xml = string.Empty;

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

            XmlDocument doc = new XmlDocument();
            doc.LoadXml(xml);

            PersistentProfile profile = new PersistentProfile(doc.FirstChild);
            return profile.ID.ToString();
        }
        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);
            }
        }