public override void ProcessRequest(HttpContext context)
        {
            using (NexposeSession session = new NexposeSession("192.168.56.105"))
            {
                session.Authenticate("nexpose", "nexpose");

                using (NexposeManager11 manager = new NexposeManager11(session))
                {
                    string template = "audit-report";
                    string format = "text";
                    string siteID = context.Request["SiteID"];
                    string xml = string.Empty;

                    xml = xml + "<AdhocReportConfig template-id=\"" + template + "\" format=\"" + format + "\">";
                    xml = xml + "<Filters><filter type=\"site\" id=\"" + siteID + "\"></filter></Filters>";
                    xml = xml + "</AdhocReportConfig>";

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

                    byte[] report = manager.GenerateAdHocReport(request);

                    context.Response.Write(Encoding.ASCII.GetString(report));

                }
            }
        }
Пример #2
0
        public static void Main(string[] args)
        {
            using (NexposeSession session = new NexposeSession("127.0.0.1"))
            {
                session.Authenticate("nexpose"/*user*/, "nexpose"/*password*/);

                using (NexposeManager11 manager = new NexposeManager11(session))
                {
                    XmlDocument sites = manager.GetSiteListing();

                    Console.WriteLine("Which site do you want a scan report for?");

                    foreach (XmlNode site in sites.FirstChild.ChildNodes)
                        Console.WriteLine(String.Format("{0}. {1}", site.Attributes["id"].Value, site.Attributes["name"].Value));

                    string id = Console.ReadLine();

                    XmlDocument templates = manager.GetReportTemplateListing();

                    string templateID = string.Empty;

                    Console.WriteLine("Which template do you want to use?");
                    foreach (XmlNode template in templates.FirstChild.ChildNodes)
                        Console.WriteLine(template.Attributes["template-id"].Value);

                    templateID = Console.ReadLine();

                    Dictionary<NexposeReportFilterType, string> filters = new Dictionary<NexposeReportFilterType, string>();

                    //add a filter for a specific "site" with and id of "id"
                    filters.Add(NexposeReportFilterType.Site, id);

                    byte[] report = manager.GenerateAdHocReport(NexposeUtil.GenerateAdHocReportConfig(templateID, NexposeReportFormat.RawXML, filters));
                    Console.WriteLine(report);
                }
            }
        }
Пример #3
0
        private XmlNode GetNexposeReport(string id)
        {
            byte[] report;
            using (NexposeSession session = new NexposeSession(this.Configuration["nexposeHost"])) {
                session.Authenticate (this.Configuration ["nexposeUser"], this.Configuration ["nexposePass"]);

                using (NexposeManager11 manager = new NexposeManager11(session)) {
                    Dictionary<NexposeReportFilterType, string> filters = new Dictionary<NexposeReportFilterType, string> ();
                    filters.Add (NexposeReportFilterType.Site, id);

                    report = manager.GenerateAdHocReport (NexposeUtil.GenerateAdHocReportConfig ("audit-report", NexposeReportFormat.RawXML, filters));

                    //stupid hack
                    while (report.Length < 91) {
                        Thread.Sleep (500);
                        report = manager.GenerateAdHocReport (NexposeUtil.GenerateAdHocReportConfig ("audit-report", NexposeReportFormat.RawXML, filters));
                    }
                }
            }

            XmlDocument doc = new XmlDocument();
            doc.LoadXml(Encoding.UTF8.GetString(report));

            return doc.LastChild;
        }