def main(c_auth=None): try: REACTConfig = REACTutils.load_config("config.yml") confluence_space_name = REACTConfig.get('confluence_space_name') confluence_space_home_page_name = REACTConfig.get( 'confluence_space_home_page_name') confluence_rest_api_url = REACTConfig.get('confluence_rest_api_url') confluence_name_of_root_directory = REACTConfig.get( 'confluence_name_of_root_directory') except Exception as e: raise e pass if not c_auth: mail = input("Login: "******"" print("[*] Creating RE&CT root page...") data = { "title": confluence_name_of_root_directory, "spacekey": confluence_space_name, "parentid": str(REACTutils.confluence_get_page_id( url, auth, confluence_space_name, confluence_space_home_page_name)), "confluencecontent": content, } if not REACTutils.push_to_confluence(data, url, auth): raise Exception("[-] Could not create or update the page. " + "Is the parent name correct?") pages = ["Response Actions","Response Playbooks","Response Stages"] for page in pages: print("[*] Creating %s..." % page) data = { "title": page, "spacekey": confluence_space_name, "parentid": str(REACTutils.confluence_get_page_id( url, auth, confluence_space_name, confluence_name_of_root_directory)), "confluencecontent": content, } if not REACTutils.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
def response_action(self, ra_path): """Nothing here yet""" print("[*] Populating Response Actions...") if ra_path: ra_list = glob.glob(ra_path + '*.yml') else: ra_dir = REACTConfig.get('response_actions_dir') ra_list = glob.glob(ra_dir + '/*.yml') for ra_file in ra_list: try: ra = ResponseAction(ra_file, apipath=self.apipath, auth=self.auth, space=self.space) ra.render_template("confluence") confluence_data = { "title": ra.ra_parsed_file['title'], "spacekey": self.space, "parentid": str( REACTutils.confluence_get_page_id( self.apipath, self.auth, self.space, "Response Actions")), "confluencecontent": ra.content, } res = REACTutils.push_to_confluence(confluence_data, self.apipath, self.auth) if res == 'Page updated': print("==> updated page: RA '" + ra.ra_parsed_file['title'] + "'") # print("Done: ", ra.ra_parsed_file['title']) except Exception as err: print(ra_file + " failed") print("Err message: %s" % err) print('-' * 60) traceback.print_exc(file=sys.stdout) print('-' * 60) print("[+] Response Actions populated!")
def response_stage(self, rs_path): """Nothing here yet""" print("[*] Populating Response Stages...") if rs_path: rs_list = glob.glob(rs_path + '*.yml') else: rs_dir = REACTConfig.get('response_stages_dir') rs_list = glob.glob(rs_dir + '/*.yml') for rs_file in rs_list: try: rs = ResponseStage(rs_file, apipath=self.apipath, auth=self.auth, space=self.space) rs.render_template("confluence") base = os.path.basename(rs_file) confluence_data = { "title": rs.rs_parsed_file['title'], "spacekey": self.space, "parentid": str( REACTutils.confluence_get_page_id( self.apipath, self.auth, self.space, "Response Stages")), "confluencecontent": rs.content, } res = REACTutils.push_to_confluence(confluence_data, self.apipath, self.auth) if res == 'Page updated': print("==> updated page: RS '" + base + "'") except Exception as err: print(rs_file + " failed") print("Err message: %s" % err) print('-' * 60) traceback.print_exc(file=sys.stdout) print('-' * 60) # # Populate Response Stages root page # template = env.get_template( 'confluence_responsestage_main_template.html.j2') rss, rs_paths = REACTutils.load_yamls_with_paths( REACTConfig.get('response_stages_dir')) rss_dict = {} rss_list = [] for i in range(len(rss)): rs_id = rss[i].get('id') rs_title = rss[i].get('title') rs_confluence_page_name = rs_id + ": " + rs_title rs_confluence_page_id = str( REACTutils.confluence_get_page_id(self.apipath, self.auth, self.space, rs_confluence_page_name)) rs_description = rss[i].get('description') rss_list.append( (rs_id, rs_title, rs_description, rs_confluence_page_id)) rss_dict.update({'rss_list': sorted(rss_list)}) rss_dict.update({ 'confluence_viewpage_url': REACTConfig.get('confluence_viewpage_url') }) content = template.render(rss_dict) try: data = { "title": "Response Stages", "spacekey": self.space, "parentid": str( REACTutils.confluence_get_page_id(self.apipath, self.auth, self.space, self.root_name)), "confluencecontent": content, } res = REACTutils.push_to_confluence(data, self.apipath, self.auth) if res == 'Page updated': print("==> updated page: Response Stages root page") except Exception as err: print("Response Stages root page" + " failed") print("Err message: %s" % err) print('-' * 60) traceback.print_exc(file=sys.stdout) print('-' * 60) print("[+] Response Stages populated!")