Esempio n. 1
0
    def enrichment(self, en_path):
        """Nothing here yet"""

        print("[*] Populating Enrichments...")
        if en_path:
            en_list = glob.glob(en_path + '*.yml')
        else:
            en_dir = ATCconfig.get('enrichments_dir')
            en_list = glob.glob(en_dir + '/*.yml')

        for en_file in en_list:
            try:
                en = Enrichment(en_file,
                                apipath=self.apipath,
                                auth=self.auth,
                                space=self.space)
                en.render_template("confluence")

                confluence_data = {
                    "title":
                    en.en_parsed_file['title'],
                    "spacekey":
                    self.space,
                    "parentid":
                    str(
                        DATAutils.confluence_get_page_id(
                            self.apipath, self.auth, self.space,
                            "Enrichments")),
                    "confluencecontent":
                    en.content,
                }

                res = DATAutils.push_to_confluence(confluence_data,
                                                   self.apipath, self.auth)
                if res == 'Page updated':
                    print("==> updated page: EN '" +
                          en.en_parsed_file['title'] + "'")
                # print("Done: ", en.en_parsed_file['title'])
            except Exception as err:
                print(en_file + " failed")
                print("Err message: %s" % err)
                print('-' * 60)
                traceback.print_exc(file=sys.stdout)
                print('-' * 60)
        print("[+] Enrichments populated!")
Esempio n. 2
0
    def data_needed(self, dn_path):
        """Desc"""

        print("[*] Populating Data Needed...")
        if dn_path:
            dn_list = glob.glob(dn_path + '*.yml')
        else:
            dn_dir = ATCconfig.get('data_needed_dir')
            dn_list = glob.glob(dn_dir + '/*.yml')

        for dn_file in dn_list:
            try:
                dn = DataNeeded(dn_file,
                                apipath=self.apipath,
                                auth=self.auth,
                                space=self.space)
                dn.render_template("confluence")
                confluence_data = {
                    "title":
                    dn.dn_fields["title"],
                    "spacekey":
                    self.space,
                    "parentid":
                    str(
                        DATAutils.confluence_get_page_id(
                            self.apipath, self.auth, self.space,
                            "Data Needed")),
                    "confluencecontent":
                    dn.content,
                }

                res = DATAutils.push_to_confluence(confluence_data,
                                                   self.apipath, self.auth)
                if res == 'Page updated':
                    print("==> updated page: DN '" + dn.dn_fields['title'] +
                          "'")
                # print("Done: ", dn.dn_fields['title'])
            except Exception as err:
                print(dn_file + " failed")
                print("Err message: %s" % err)
                print('-' * 60)
                traceback.print_exc(file=sys.stdout)
                print('-' * 60)
        print("[+] Data Needed populated!")
Esempio n. 3
0
    def logging_policy(self, lp_path):
        """Desc"""

        print("[*] Populating Logging Policies...")
        if lp_path:
            lp_list = glob.glob(lp_path + '*.yml')
        else:
            lp_dir = ATCconfig.get('logging_policies_dir')
            lp_list = glob.glob(lp_dir + '/*.yml')

        for lp_file in lp_list:
            try:
                lp = LoggingPolicy(lp_file)
                lp.render_template("confluence")
                confluence_data = {
                    "title":
                    lp.fields["title"],
                    "spacekey":
                    self.space,
                    "parentid":
                    str(
                        DATAutils.confluence_get_page_id(
                            self.apipath, self.auth, self.space,
                            "Logging Policies")),
                    "confluencecontent":
                    lp.content,
                }

                res = DATAutils.push_to_confluence(confluence_data,
                                                   self.apipath, self.auth)
                if res == 'Page updated':
                    print("==> updated page: LP '" + lp.fields['title'] + "'")
                # print("Done: ", lp.fields['title'])
            except Exception as err:
                print(lp_file + " failed")
                print("Err message: %s" % err)
                print('-' * 60)
                traceback.print_exc(file=sys.stdout)
                print('-' * 60)
        print("[+] Logging Policies populated!")
Esempio n. 4
0
    def render_template(self, template_type):
        """Description
        template_type:
            - "markdown"
            - "confluence"
        """

        if template_type not in ["markdown", "confluence"]:
            raise Exception("Bad template_type. Available values:" +
                            " [\"markdown\", \"confluence\"]")

        # Get proper template
        if template_type == "markdown":
            template = env\
                .get_template('markdown_dataneeded_template.md.j2')

            logging_policies = self.dn_fields.get("loggingpolicy")

            if isinstance(logging_policies, str):
                logging_policies = [logging_policies]

            self.dn_fields.update({'loggingpolicy': logging_policies})

            mitigation_policy = self.dn_fields.get("mitigation_policy")

            if isinstance(mitigation_policy, str):
                mitigation_policy = [mitigation_policy]

            self.dn_fields.update({'mitigation_policy': mitigation_policy})

            self.dn_fields.update(
                {'description': self.dn_fields.get('description').strip()})

            refs = self.dn_fields.get("references")

            if isinstance(refs, str):
                self.dn_fields.update({'references': [refs]})

        elif template_type == "confluence":
            template = env\
                .get_template('confluence_dataneeded_template.html.j2')

            self.dn_fields.update({
                'confluence_viewpage_url':
                ATCconfig.get('confluence_viewpage_url')
            })

            self.dn_fields.update(
                {'description': self.dn_fields.get('description').strip()})

            logging_policies = self.dn_fields.get("loggingpolicy")

            if not logging_policies:
                logging_policies = [
                    "None",
                ]

            logging_policies_with_id = []

            for lp in logging_policies:
                if lp != "None" and self.apipath and self.auth and self.space:
                    logging_policies_id = str(
                        DATAutils.confluence_get_page_id(
                            self.apipath, self.auth, self.space, lp))
                else:
                    logging_policies_id = ""
                lp = (lp, logging_policies_id)
                logging_policies_with_id.append(lp)

            self.dn_fields.update({'loggingpolicy': logging_policies_with_id})

            mitigation_policies = self.dn_fields.get("mitigation_policy")

            if not mitigation_policies:
                mitigation_policies = [
                    "None",
                ]

            mitigation_policies_with_id = []

            for mp in mitigation_policies:
                if mp != "None" and self.apipath and self.auth and self.space:
                    mitigation_policies_id = str(
                        DATAutils.confluence_get_page_id(
                            self.apipath, self.auth, self.space, mp))
                else:
                    mitigation_policies_id = ""
                mp = (mp, mitigation_policies_id)
                mitigation_policies_with_id.append(mp)

            self.dn_fields.update(
                {'mitigation_policy': mitigation_policies_with_id})

            refs = self.dn_fields.get("references")

            if isinstance(refs, str):
                self.dn_fields.update({'references': [refs]})

        self.content = template.render(self.dn_fields)

        return True
Esempio n. 5
0
def main(c_auth=None):

    try:
        ATCconfig = DATAutils.load_config("config.yml")
        confluence_space_name = ATCconfig.get('confluence_space_name')
        confluence_space_home_page_name = ATCconfig.get(
            'confluence_space_home_page_name')
        confluence_rest_api_url = ATCconfig.get('confluence_rest_api_url')
        confluence_name_of_root_directory = ATCconfig.get(
            'confluence_name_of_root_directory')

    except Exception as e:
        raise e
        pass

    if not c_auth:
        mail = input("Login: "******""

    print("[*] Creating ATC root page...")

    data = {
        "title":
        confluence_name_of_root_directory,
        "spacekey":
        confluence_space_name,
        "parentid":
        str(
            DATAutils.confluence_get_page_id(url, auth, confluence_space_name,
                                             confluence_space_home_page_name)),
        "confluencecontent":
        content,
    }

    if not DATAutils.push_to_confluence(data, url, auth):
        raise Exception("[-] Could not create or update the page. " +
                        "Is the parent name correct?")

    pages = ["Logging Policies", "Data Needed", "Enrichments"]

    for page in pages:
        print("Creating %s..." % page)
        data = {
            "title":
            page,
            "spacekey":
            confluence_space_name,
            "parentid":
            str(
                DATAutils.confluence_get_page_id(
                    url, auth, confluence_space_name,
                    confluence_name_of_root_directory)),
            "confluencecontent":
            content,
        }

        if not DATAutils.push_to_confluence(data, url, auth):
            raise Exception("[-] Could not create or update the page. " +
                            "Is the parent name correct?")
    print("[+] Initial Confluence page structure created!")
    return True
Esempio n. 6
0
    def render_template(self, template_type):
        """Description
        template_type:
            - "markdown"
            - "confluence"
        """

        if template_type not in ["markdown", "confluence"]:
            raise Exception("Bad template_type. Available values:" +
                            " [\"markdown\", \"confluence\"]")

        # Get proper template
        if template_type == "markdown":
            template = env.get_template('markdown_enrichments_template.md.j2')

            self.en_parsed_file.update({
                'description':
                self.en_parsed_file.get('description').strip()
            })
        elif template_type == "confluence":
            template = env.get_template(
                'confluence_enrichments_template.html.j2')

            self.en_parsed_file.update({
                'confluence_viewpage_url':
                ATCconfig.get('confluence_viewpage_url')
            })

            data_needed = self.en_parsed_file.get('data_needed')
            if data_needed:
                data_needed_with_id = []
                for dn in data_needed:
                    data_needed_id = str(
                        DATAutils.confluence_get_page_id(
                            self.apipath, self.auth, self.space, dn))
                    dn = (dn, data_needed_id)
                    data_needed_with_id.append(dn)

                self.en_parsed_file.update(
                    {'data_needed': data_needed_with_id})

            data_to_enrich = self.en_parsed_file.get('data_to_enrich')
            if data_to_enrich:
                data_to_enrich_with_id = []
                for de in data_to_enrich:
                    data_to_enrich_id = str(
                        DATAutils.confluence_get_page_id(
                            self.apipath, self.auth, self.space, de))
                    de = (de, data_to_enrich_id)
                    data_to_enrich_with_id.append(de)

                self.en_parsed_file.update(
                    {'data_to_enrich': data_to_enrich_with_id})

            requirements = self.en_parsed_file.get('requirements')
            if requirements:
                requirements_with_id = []
                for req in requirements:
                    requirements_id = str(
                        DATAutils.confluence_get_page_id(
                            self.apipath, self.auth, self.space, req))
                    req = (req, requirements_id)
                    requirements_with_id.append(req)

                self.en_parsed_file.update(
                    {'requirements': requirements_with_id})

            self.en_parsed_file.update({
                'description':
                self.en_parsed_file.get('description').strip()
            })
        # Render
        self.content = template.render(self.en_parsed_file)