def execute(macro, args):
    request = macro.request
    _ = request.getText

    if args:
        args = [x.strip() for x in args.split(',')]
    # Wrong number of arguments
    if not args or len(args) not in [1, 2]:
        return render_error( _("GetMetaData: Need to specify page, or page and key"))

    # Get all non-empty args
    args = [x for x in args if x]

    # If not page specified, defaulting to current page
    if len(args) == 1:
        page = request.page.page_name
        key = args[0]
    elif len(args) == 2:
        page = args[0]
        key = args[1]
    # Faulty args
    else:
        return render_error(_("GetMetaData: Need to specify page, or page and key"))

    vals = get_metas(request, page, [key], formatLinks=True)

    val = ', '.join(vals[key])

    return format_wikitext(request, val)
Beispiel #2
0
def execute(pagename, request):
    request.content_type = "application/json"

    form = values_to_form(request.values)

    args = form.get('args', [None])[0]

    try:
        metas = get_metas2(request, args)
    except ImportError:
        request.status_code = 501
        request.write(u"abusehelper package not available")
        return
    except ValueError:
        request.status_code = 400
        request.write(u"invalid query '" + args + u"'")
        return

    if form.get('formatted', [None])[0]:
        formatted = {}
        values = []
        for page, vals in metas.items():
            values.extend(vals.keys())
            for val in vals.values():
                values.extend(val)

        for value in values:
            f = format_wikitext(request, value)
            if f != value and value not in formatted:
                formatted[value] = f

        metas = {'metas': metas, 'formatted': formatted}

    json.dump(metas, request, indent=2)
Beispiel #3
0
def execute(macro, args):
    request = macro.request
    _ = request.getText

    if args:
        args = [x.strip() for x in args.split(',')]
    # Wrong number of arguments
    if not args or len(args) not in [1, 2]:
        return render_error(
            _("GetMetaData: Need to specify page, or page and key"))

    # Get all non-empty args
    args = [x for x in args if x]

    # If not page specified, defaulting to current page
    if len(args) == 1:
        page = request.page.page_name
        key = args[0]
    elif len(args) == 2:
        page = args[0]
        key = args[1]
    # Faulty args
    else:
        return render_error(
            _("GetMetaData: Need to specify page, or page and key"))

    vals = get_metas(request, page, [key], formatLinks=True)

    val = ', '.join(vals[key])

    return format_wikitext(request, val)
def execute(pagename, request):
    request.content_type = "application/json"

    form = values_to_form(request.values)

    args = form.get('args', [None])[0]

    try:
        metas = get_metas2(request, args)
    except ImportError:
        request.status_code = 501
        request.write(u"abusehelper package not available")
        return
    except ValueError:
        request.status_code = 400
        request.write(u"invalid query '" + args + u"'")
        return

    if form.get('formatted', [None])[0]:
        formatted = {}
        values = []
        for page, vals in metas.items():
            values.extend(vals.keys())
            for val in vals.values():
                values.extend(val)

        for value in values:
            f = format_wikitext(request, value)
            if f != value and value not in formatted:
                formatted[value] = f

        metas = {'metas': metas, 'formatted': formatted}

    json.dump(metas, request, indent=2)
Beispiel #5
0
    def form_radio(request, pagekey, curval, values, description=''):
        msg = ''

        for keyval, showval in values:
            msg += wr(
                '<input form="metaformedit" type="radio" name="%s" value="%s"%s>',
                pagekey, keyval, curval == keyval and ' checked' or '') + \
                '<label>' + format_wikitext(request, showval) +'</label>'

        return msg
Beispiel #6
0
def execute(macro, args):
    tset = set(['score', 'vector'])
    request = macro.request
    _ = request.getText

    if args:
        args = [x.strip() for x in args.split(',')]
    # Wrong number of arguments
    if len(args) not in [0, 1, 2]:
        return render_error(_("CVSS: Need to specify a page or page and " +
                              "type (score|vector)."))

    # Get all non-empty args
    args = [x for x in args if x]

    # If page is not specified, defaulting to current page
    if len(args) == 0:
        page = request.page.page_name
        type = "score"
    elif len(args) == 1:
        page = args[0]
        type = "score"
    else:
        page = args[0]
        type = args[1]
        if type not in tset:
            return render_error(_("CVSS: The type needs to be either score " +
                                  "or vector."))

    base_metas = get_metas(request, page, ["Access Vector", "Access Complexity", "Authentication", "Confidentiality", "Integrity", "Availability"])
    vector = buildVector(base_metas)
    if vector is not None:
        if type == "vector":
            return format_wikitext(request, vector)
        cvss = parse_cvss(vector)
        bscore = basescore(cvss)
        bstring = "%s" % bscore
        return format_wikitext(request, bstring)
    else:
        return render_error(_("CVSS: Invalid value(s) in Base Metrics."))
Beispiel #7
0
def execute(pagename, request):
    request.content_type = "application/json"

    form = values_to_form(request.values)

    args = form.get('args', [None])[0]
    if not args:
        args = pagename

    handle = form.get('handle', [None])[0]
    if handle:
        handle = str(handle)

    getvalues = form.get('getvalues', [None])[0]
    if getvalues:
        args = "%s=/.+/" % getvalues

    inc_get_metas = wikiutil.importPlugin(request.cfg, "xmlrpc", "IncGetMeta",
                                          "inc_get_metas")
    out = inc_get_metas(request, args, handle)

    if getvalues:
        changed = out[2][1]
        filtered = dict()
        for page, metas in changed.items():
            for key, vals in metas.items():
                if key == getvalues:
                    filtered[page] = {key: vals}

        out[2] = (out[2][0], filtered)
    
    if form.get('formatted', [None])[0]:
        formatted = dict()

        for page, metas in out[2][1].items():
            vals = list()
            for key, values in metas.items():
                vals.append(key)
                vals.extend(values[1])
           
            request.page = Page(request, page)

            for val in vals:
                f = format_wikitext(request, val)
                if val != f:
                    formatted[val] = f

        out.append(formatted)


    json.dump(out, request, indent=2)
Beispiel #8
0
def t_cell(macro, vals, head=0, style=dict(), rev=''):
    out = str()

    if not 'class' in style:
        if head:
            style['class'] = 'meta_page'
        else:
            style['class'] = 'meta_cell'

    out += macro.formatter.table_cell(1, attrs=style)
    cellstyle = style.get('gwikistyle', '').strip('"')

    if cellstyle == 'list':
        out += macro.formatter.bullet_list(1)

    first_val = True

    for data in sorted(vals):

        # cosmetic for having a "a, b, c" kind of lists
        if cellstyle not in ['list'] and not first_val:
            out += macro.formatter.text(',') + macro.formatter.linebreak()

        if head:
            kw = dict()
            if rev:
                kw['querystr'] = '?action=recall&amp;rev=' + rev
            out += macro.formatter.pagelink(1, data, **kw)
            out += macro.formatter.text(data)
            out += macro.formatter.pagelink(0)
        elif data.strip():
            if cellstyle == 'list':
                out += macro.formatter.listitem(1)

            out += format_wikitext(macro.request, data)

            if cellstyle == 'list':
                out += macro.formatter.listitem(0)

        first_val = False

    if cellstyle == 'list':
        out += macro.formatter.bullet_list(1)

    return out
def formatMetaSelection(request, pages, keys, styles, addpagename=False):

    f = request.formatter
    divfmt = {'class': 'metaselection_area'}
    listfmt = {'class': 'metaselection_list'}
    entryfmt = {'class': 'metaselection_entry'}

    result = ''
    result = f.div(1, **divfmt)
    result += f.bullet_list(1, **listfmt)

    tmp_page = request.page

    for page in pages:

        pageobj = Page(request, page)
        request.page = pageobj
        request.formatter.page = pageobj

        metas = get_metas(request, page, keys,
                          checkAccess=True, formatLinks=True)

        result += f.listitem(1, **entryfmt)

        args = {'class': 'metaselection_link'}

        for key in keys:
            for val in metas[key]:
                text = format_wikitext(request, val)
                result += pageobj.link_to_raw(request, text=text, **args)

        if addpagename:
            result += pageobj.link_to_raw(request,
                                          text=pageobj.page_name, **args)

        result += f.listitem(0)

    request.page = tmp_page
    request.formatter.page = tmp_page

    result += f.bullet_list(0)
    result += f.div(0)
    return result
Beispiel #10
0
def execute(pagename, request):
    request.content_type = "application/json"

    form = values_to_form(request.values)

    args = form.get('args', [None])[0]
    key = form.get('getvalues', [None])[0]
    formatted = form.get('formatted', [None])[0]

    do_action = wikiutil.importPlugin(request.cfg, "xmlrpc", "GetMetaStruct",
                                      "do_action")

    if not args:
        if key:
            results = do_action(request, "%s=/.+/" % key)
            metas = dict()
            for page in results:
                values = results[page].get(key, [])
                if values:
                    metas.setdefault(page, list())
                    metas[page].extend(values)
        else:
            metas = do_action(request, pagename)
    else:
        metas = do_action(request, args)

    if formatted:
        formatted = {}
        values = []
        for page, vals in metas.items():
            values.extend(vals.keys())
            for val in vals.values():
                values.extend(val)

        for value in values:
            f = format_wikitext(request, value)
            if f != value and value not in formatted:
                formatted[value] = f

        metas = {'metas': metas, 'formatted': formatted}

    json.dump(metas, request, indent=2)
Beispiel #11
0
def wrap_span(request, pageobj, key, data, id):
    pagename = pageobj.page_name
    fdata = format_wikitext(request, data)

    if not key:
        return fdata

    header = False

    if key == data:
        header = True

    if '->' in key:
        # Get indirection data, the same function get_metas uses
        linkdata = add_matching_redirs(request, request.page, {}, {}, {}, key,
                                       pagename, key)

        # Broken link, do not give anything editable as this will not
        # work in any case.
        if not linkdata:
            return fdata

        if key in linkdata:
            for pname in linkdata[key]:
                if not data:
                    pagename = pname
                    key = key.split('->')[-1]
                    break
                if data in linkdata[key][pname] or header:
                    pagename = pname
                    key = key.split('->')[-1]
                    break

    if data == fdata or header:
        return form_writer(
            u'<span data-page="%s" data-key="%s" data-index="%s">', pagename,
            key, str(id)) + fdata + '</span>'

    return form_writer(
        u'<span data-page="%s" data-key="%s" data-value="%s" data-index="%s">',
        pagename, key, data, str(id)) + fdata + '</span>'
def execute(pagename, request):
    request.content_type = "application/json"

    form = values_to_form(request.values)

    args = form.get("args", [None])[0]
    key = form.get("getvalues", [None])[0]
    formatted = form.get("formatted", [None])[0]

    do_action = wikiutil.importPlugin(request.cfg, "xmlrpc", "GetMetaStruct", "do_action")

    if not args:
        if key:
            results = do_action(request, "%s=/.+/" % key)
            metas = dict()
            for page in results:
                values = results[page].get(key, [])
                if values:
                    metas.setdefault(page, list())
                    metas[page].extend(values)
        else:
            metas = do_action(request, pagename)
    else:
        metas = do_action(request, args)

    if formatted:
        formatted = {}
        values = []
        for page, vals in metas.items():
            values.extend(vals.keys())
            for val in vals.values():
                values.extend(val)

        for value in values:
            f = format_wikitext(request, value)
            if f != value and value not in formatted:
                formatted[value] = f

        metas = {"metas": metas, "formatted": formatted}

    json.dump(metas, request, indent=2)
Beispiel #13
0
def wrap_span(request, pageobj, key, data, id, parser=None):
    fdata = format_wikitext(request, data, parser)

    if not key:
        return fdata

    header = False

    if key == data:
        header = True

    if '->' in key:
        # Get indirection data, the same function get_metas uses
        linkdata = add_matching_redirs(request, request.page, {}, {}, {},
                                       key, pageobj.page_name, key)

        # Broken link, do not give anything editable as this will not
        # work in any case.
        if not linkdata:
            return fdata

        if key in linkdata:
            for pname in linkdata[key]:
                if not data:
                    pagename = pname
                    key = key.split('->')[-1]
                    break
                if data in linkdata[key][pname] or header:
                    pagename = pname
                    key = key.split('->')[-1]
                    break

    if data == fdata or header:
        return form_writer(
            u'<span data-page="%s" data-key="%s" data-index="%s">',
            pageobj.page_name, key, str(id)) + fdata + '</span>'

    return form_writer(
        u'<span data-page="%s" data-key="%s" data-value="%s" data-index="%s">',
        pageobj.page_name, key, data, str(id)) + fdata + '</span>'
Beispiel #14
0
def execute(pagename, request):
    form = values_to_form(request.values)

    util = form.get('util', [None])[0]

    if util == "format":
        txt = form.get('text', [None])[0]
        request.write(format_wikitext(request, txt))

    elif util == "getTemplate":
        template = form.get('name', [None])[0]
        template_page = wikiutil.unquoteWikiname(template)
        if request.user.may.read(template_page):
            Page(request, template_page).send_raw()

    elif util == "newPage":
        page = form.get('page', [None])[0]
        content = form.get('content', [""])[0]
        request.content_type = "application/json"

        if request.environ['REQUEST_METHOD'] != 'POST':
            return

        if not page:
            msg = "Page name not defined!"
            json.dump(dict(status="error", msg=msg), request)
            return

        if not request.user.may.write(page):
            msg = "You are not allowed to edit this page"
            json.dump(dict(status="error", msg=msg), request)
            return

        p = Page(request, page)
        if p.exists():
            msg = "Page already exists"
            json.dump(dict(status="error", msg=msg), request)
            return

        editor = PageEditor(request, page)
        msg = editor.saveText(content, p.get_real_rev())
        json.dump(dict(status="ok", msg=msg), request)


    elif util == "getProperties":
        request.content_type = "application/json"
        key = form.get('key', [''])[0]
        json.dump(get_properties(request, key), request)
        return

    elif util == "uploadFile":
        request.content_type = "application/json"

        if not request.user.may.write(pagename):
            msg = u"You are not allowed to edit this page!"
            json.dump(dict(status="error", msg=msg), request)
            request.status_code = 403
            return

        from MoinMoin.action.AttachFile import add_attachment, AttachmentAlreadyExists

        try:
            overwrite = int(form.get('overwrite', ['0'])[0])
        except:
            overwrite = 0

        response = dict(success=list(), failed=list())
        for name in request.files:
            _file = request.files.get(name)
            filename = _file.filename
            try:
                t,s = add_attachment(request, pagename, filename, _file.stream, overwrite=overwrite)
                response['success'].append(filename)
            except AttachmentAlreadyExists:
                response['failed'].append(filename)

        json.dump(response, request)
        return

    elif util == "getAttachments":
        request.content_type = "application/json"
        from MoinMoin.action.AttachFile import _get_files, getAttachUrl

        files = _get_files(request, pagename)
        response = []
        for name in files:
            response.append(dict(url=getAttachUrl(pagename, name, request),name=name))

        json.dump(response, request)

    return
Beispiel #15
0
def execute(pagename, request):
    form = values_to_form(request.values)

    util = form.get('util', [None])[0]

    if util == "format":
        txt = form.get('text', [None])[0]
        request.write(format_wikitext(request, txt))

    elif util == "getTemplate":
        template = form.get('name', [None])[0]
        template_page = wikiutil.unquoteWikiname(template)
        if request.user.may.read(template_page):
            Page(request, template_page).send_raw()

    elif util == "newPage":
        page = form.get('page', [None])[0]
        content = form.get('content', [""])[0]
        request.content_type = "application/json"

        if request.environ['REQUEST_METHOD'] != 'POST':
            return

        if not page:
            msg = "Page name not defined!"
            json.dump(dict(status="error", msg=msg), request)
            return

        if not request.user.may.write(page):
            msg = "You are not allowed to edit this page"
            json.dump(dict(status="error", msg=msg), request)
            return

        p = Page(request, page)
        if p.exists():
            msg = "Page already exists"
            json.dump(dict(status="error", msg=msg), request)
            return

        editor = PageEditor(request, page)
        msg = editor.saveText(content, p.get_real_rev())
        json.dump(dict(status="ok", msg=msg), request)

    elif util == "getProperties":
        request.content_type = "application/json"
        key = form.get('key', [''])[0]
        json.dump(get_properties(request, key), request)
        return

    elif util == "uploadFile":
        request.content_type = "application/json"

        if not request.user.may.write(pagename):
            msg = u"You are not allowed to edit this page!"
            json.dump(dict(status="error", msg=msg), request)
            request.status_code = 403
            return

        from MoinMoin.action.AttachFile import add_attachment, AttachmentAlreadyExists

        try:
            overwrite = int(form.get('overwrite', ['0'])[0])
        except:
            overwrite = 0

        response = dict(success=list(), failed=list())
        for name in request.files:
            _file = request.files.get(name)
            filename = _file.filename
            try:
                t, s = add_attachment(request,
                                      pagename,
                                      filename,
                                      _file.stream,
                                      overwrite=overwrite)
                response['success'].append(filename)
            except AttachmentAlreadyExists:
                response['failed'].append(filename)

        json.dump(response, request)
        return

    elif util == "getAttachments":
        request.content_type = "application/json"
        from MoinMoin.action.AttachFile import _get_files, getAttachUrl

        files = _get_files(request, pagename)
        response = []
        for name in files:
            response.append(
                dict(url=getAttachUrl(pagename, name, request), name=name))

        json.dump(response, request)

    return