def execute(pagename, request): target = request.values.get('target') awd = AnyWikiDraw(request, pagename, target) do = request.values.get('do') if do == 'save': msg = awd.save() else: msg = awd.render() if msg: request.theme.add_msg(wikiutil.escape(msg), 'error') do_show(pagename, request)
def execute(pagename, request): target = request.values.get('target') twd = TwikiDraw(request, pagename, target) do = request.values.get('do') if do == 'save': msg = twd.save() else: msg = twd.render() if msg: request.theme.add_msg(msg, 'error') do_show(pagename, request)
def execute(pagename, request): _ = request.getText form = values_to_form(request.values) msgs = list() newpage = form['name'][0] if not newpage: request.theme.add_msg(_("IOCList page name not set!"), 'error') request.page.send_page() return template = form['template'][0] if not template: template = "IOCListTemplate" allow_overlap = form['allow_overlap'][0] if not allow_overlap: allow_overlap = "no" ips = IPV4_RE.findall(form['data'][0]) ips = filter(is_ipv4, ips) ips = set(ips) ipv6 = IPV6_RE.findall(form['data'][0]) ipv6 = filter(is_ipv6, ipv6) ips.update(set(ipv6)) ips = list(ips) domains = set(DOMAIN_RE.findall(form['data'][0])) urls = set(URL_RE.findall(form['data'][0])) emails = set(EMAIL_RE.findall(form['data'][0])) hashes = set(HASH_RE.findall(form['data'][0])) data = { 'ip': list(ips), 'domain name': list(domains), 'url': list(urls), 'email address': list(emails), 'artifact hash': list(hashes) } dataset = set() for key in data: dataset.update(data[key]) graphdata = request.graphdata vals_on_keys = graphdata.get_vals_on_keys() new_data = dict((key, list()) for (key, value) in data.iteritems()) for ip in ips: if ip not in vals_on_keys.get('ip', list()): new_data['ip'].append(ip) for domain in domains: if domain not in vals_on_keys.get('domain name', list()): new_data['domain name'].append(domain) for url in urls: if url not in vals_on_keys.get('url', list()): new_data['url'].append(url) for email in emails: if email not in vals_on_keys.get('email address', list()): new_data['email address'].append(email) for h in hashes: if h not in vals_on_keys.get('artifact hash', list()): new_data['artifact hash'].append(h) newdataset = list() for key in new_data: newdataset.extend(new_data[key]) old_data = dataset.difference(newdataset) if old_data: vals_on_pages = graphdata.get_vals_on_pages() if allow_overlap == 'no': for ioc in old_data: msgs.append( _("The following IOC already listed: %s (%s).") % (ioc, ', '.join(vals_on_pages[ioc]))) else: for ioc in old_data: if newpage in vals_on_pages[ioc]: for key in data.keys(): if ioc in data[key]: data[key].remove(ioc) else: msgs.append( _("The following IOC already listed: %s (%s).") % (ioc, ', '.join(vals_on_pages[ioc])) + " " + _("Adding anyway.")) if allow_overlap != 'no': new_data = data if not new_data: request.theme.add_msg(_("No new IOC!"), 'error') request.page.send_page() return if not Page(request, newpage).exists(): msgs.append( _("Creating page %s with template %s") % (newpage, template)) msgs.append(save_template(request, newpage, template)) ioccount = 0 for key in new_data: ioccount += len(new_data[key]) msgs.append(_("Added %s IOC to list %s") % (ioccount, newpage)) edit_meta(request, newpage, {}, new_data) msg = '' for line in msgs: msg += line + request.formatter.linebreak(0) request.theme.add_msg(msg) do_show(pagename, request)
def execute(pagename, request): _ = request.getText form = values_to_form(request.values) msgs = list() newpage = form['name'][0] if not newpage: request.theme.add_msg(_("IOCList page name not set!"), 'error') request.page.send_page() return template = form['template'][0] if not template: template = "IOCListTemplate" allow_overlap = form['allow_overlap'][0] if not allow_overlap: allow_overlap = "no" ips = IPV4_RE.findall(form['data'][0]) ips = filter(is_ipv4, ips) ips = set(ips) ipv6 = IPV6_RE.findall(form['data'][0]) ipv6 = filter(is_ipv6, ipv6) ips.update(set(ipv6)) ips = list(ips) domains = set(DOMAIN_RE.findall(form['data'][0])) urls = set(URL_RE.findall(form['data'][0])) emails = set(EMAIL_RE.findall(form['data'][0])) hashes = set(HASH_RE.findall(form['data'][0])) data = {'ip': list(ips), 'domain name': list(domains), 'url': list(urls), 'email address': list(emails), 'artifact hash': list(hashes)} dataset = set() for key in data: dataset.update(data[key]) graphdata = request.graphdata vals_on_keys = graphdata.get_vals_on_keys() new_data = dict((key, list()) for (key, value) in data.iteritems()) for ip in ips: if ip not in vals_on_keys.get('ip', list()): new_data['ip'].append(ip) for domain in domains: if domain not in vals_on_keys.get('domain name', list()): new_data['domain name'].append(domain) for url in urls: if url not in vals_on_keys.get('url', list()): new_data['url'].append(url) for email in emails: if email not in vals_on_keys.get('email address', list()): new_data['email address'].append(email) for h in hashes: if h not in vals_on_keys.get('artifact hash', list()): new_data['artifact hash'].append(h) newdataset = list() for key in new_data: newdataset.extend(new_data[key]) old_data = dataset.difference(newdataset) if old_data: vals_on_pages = graphdata.get_vals_on_pages() if allow_overlap == 'no': for ioc in old_data: msgs.append(_("The following IOC already listed: %s (%s).") % (ioc, ', '.join(vals_on_pages[ioc]))) else: for ioc in old_data: if newpage in vals_on_pages[ioc]: for key in data.keys(): if ioc in data[key]: data[key].remove(ioc) else: msgs.append( _("The following IOC already listed: %s (%s).") % (ioc, ', '.join(vals_on_pages[ioc])) + " " + _("Adding anyway.")) if allow_overlap != 'no': new_data = data if not new_data: request.theme.add_msg(_("No new IOC!"), 'error') request.page.send_page() return if not Page(request, newpage).exists(): msgs.append(_("Creating page %s with template %s") % (newpage, template)) msgs.append(save_template(request, newpage, template)) ioccount = 0 for key in new_data: ioccount += len(new_data[key]) msgs.append(_("Added %s IOC to list %s") % (ioccount, newpage)) edit_meta(request, newpage, {}, new_data) msg = '' for line in msgs: msg += line + request.formatter.linebreak(0) request.theme.add_msg(msg) do_show(pagename, request)