Example #1
0
 def render_show_readonly(self, ctx, data):
     if self.node.is_unknown() or self.node.is_readonly():
         return ""
     rocap = self.node.get_readonly_uri()
     root = get_root(ctx)
     uri_link = "%s/uri/%s/" % (root, urllib.quote(rocap))
     return ctx.tag[T.a(href=uri_link)["Read-Only Version"]]
Example #2
0
 def render_show_readonly(self, ctx, data):
     if self.node.is_unknown() or self.node.is_readonly():
         return ""
     rocap = self.node.get_readonly_uri()
     root = get_root(ctx)
     uri_link = "%s/uri/%s/" % (root, urllib.quote(rocap))
     return ctx.tag[T.a(href=uri_link)["Read-Only Version"]]
Example #3
0
 def redirect_to(self, ctx):
     ophandle = get_arg(ctx, "ophandle")
     assert ophandle
     target = get_root(ctx) + "/operations/" + ophandle
     output = get_arg(ctx, "output")
     if output:
         target = target + "?output=%s" % output
     return url.URL.fromString(target)
Example #4
0
 def redirect_to(self, ctx):
     ophandle = get_arg(ctx, "ophandle")
     assert ophandle
     target = get_root(ctx) + "/operations/" + ophandle
     output = get_arg(ctx, "output")
     if output:
         target = target + "?output=%s" % output
     return url.URL.fromString(target)
Example #5
0
 def _render_si_link(self, req, storage_index):
     si_s = base32.b2a(storage_index)
     ophandle = req.prepath[-1]
     target = "%s/operations/%s/%s" % (get_root(req), ophandle, si_s)
     output = get_arg(req, "output")
     if output:
         target = target + "?output=%s" % output
     return tags.a(si_s, href=target)
Example #6
0
 def _render_si_link(self, req, storage_index):
     si_s = str(base32.b2a(storage_index), "utf-8")
     ophandle = str(req.prepath[-1], "utf-8")
     target = "%s/operations/%s/%s" % (get_root(req), ophandle, si_s)
     output = get_arg(req, "output")
     if output:
         target = target + "?output=" + str(output, "utf-8")
     return tags.a(si_s, href=target)
 def _render_si_link(self, ctx, storage_index):
     si_s = base32.b2a(storage_index)
     req = inevow.IRequest(ctx)
     ophandle = req.prepath[-1]
     target = "%s/operations/%s/%s" % (get_root(ctx), ophandle, si_s)
     output = get_arg(ctx, "output")
     if output:
         target = target + "?output=%s" % output
     return T.a(href=target)[si_s]
Example #8
0
 def _render_si_link(self, ctx, storage_index):
     si_s = base32.b2a(storage_index)
     req = inevow.IRequest(ctx)
     ophandle = req.prepath[-1]
     target = "%s/operations/%s/%s" % (get_root(ctx), ophandle, si_s)
     output = get_arg(ctx, "output")
     if output:
         target = target + "?output=%s" % output
     return T.a(href=target)[si_s]
Example #9
0
    def redirect_to(self, req):
        """
        :param allmydata.webish.MyRequest req:
        """
        ophandle = get_arg(req, "ophandle")
        assert ophandle
        target = get_root(req) + "/operations/" + ophandle
        output = get_arg(req, "output")
        if output:
            target = target + "?output=%s" % output

        # XXX: We have to use nevow.url here because nevow.appserver
        # is unhappy with anything else; so this gets its own ticket.
        # https://tahoe-lafs.org/trac/tahoe-lafs/ticket/3314
        return url.URL.fromString(target)
Example #10
0
 def render_row(self, ctx, path_cap):
     path, cap = path_cap
     ctx.fillSlots("path", self.slashify_path(path))
     root = get_root(ctx)
     # TODO: we need a clean consistent way to get the type of a cap string
     if cap:
         if cap.startswith("URI:CHK") or cap.startswith("URI:SSK"):
             nameurl = urllib.quote(path[-1].encode("utf-8"))
             uri_link = "%s/file/%s/@@named=/%s" % (root, urllib.quote(cap),
                                                    nameurl)
         else:
             uri_link = "%s/uri/%s" % (root, urllib.quote(cap, safe=""))
         ctx.fillSlots("cap", T.a(href=uri_link)[cap])
     else:
         ctx.fillSlots("cap", "")
     return ctx.tag
Example #11
0
 def render_row(self, ctx, path_cap):
     path, cap = path_cap
     ctx.fillSlots("path", self.slashify_path(path))
     root = get_root(ctx)
     # TODO: we need a clean consistent way to get the type of a cap string
     if cap:
         if cap.startswith("URI:CHK") or cap.startswith("URI:SSK"):
             nameurl = urllib.quote(path[-1].encode("utf-8"))
             uri_link = "%s/file/%s/@@named=/%s" % (root, urllib.quote(cap),
                                                    nameurl)
         else:
             uri_link = "%s/uri/%s" % (root, urllib.quote(cap, safe=""))
         ctx.fillSlots("cap", T.a(href=uri_link)[cap])
     else:
         ctx.fillSlots("cap", "")
     return ctx.tag
Example #12
0
class ManifestResults(rend.Page, ReloadMixin):
    docFactory = getxmlfile("manifest.xhtml")

    def __init__(self, client, monitor):
        self.client = client
        self.monitor = monitor

    def renderHTTP(self, ctx):
        req = inevow.IRequest(ctx)
        output = get_arg(req, "output", "html").lower()
        if output == "text":
            return self.text(req)
        if output == "json":
            return self.json(req)
        return rend.Page.renderHTTP(self, ctx)

    def slashify_path(self, path):
        if not path:
            return ""
        return "/".join([p.encode("utf-8") for p in path])

    def text(self, req):
        req.setHeader("content-type", "text/plain")
        lines = []
        is_finished = self.monitor.is_finished()
        lines.append("finished: " + {True: "yes", False: "no"}[is_finished])
        for (path, cap) in self.monitor.get_status()["manifest"]:
            lines.append(self.slashify_path(path) + " " + cap)
        return "\n".join(lines) + "\n"

    def json(self, req):
        req.setHeader("content-type", "text/plain")
        m = self.monitor
        s = m.get_status()

        if m.origin_si:
            origin_base32 = base32.b2a(m.origin_si)
        else:
            origin_base32 = ""
        status = { "stats": s["stats"],
                   "finished": m.is_finished(),
                   "origin": origin_base32,
                   }
        if m.is_finished():
            # don't return manifest/verifycaps/SIs unless the operation is
            # done, to save on CPU/memory (both here and in the HTTP client
            # who has to unpack the JSON). Tests show that the ManifestWalker
            # needs about 1092 bytes per item, the JSON we generate here
            # requires about 503 bytes per item, and some internal overhead
            # (perhaps transport-layer buffers in twisted.web?) requires an
            # additional 1047 bytes per item.
            status.update({ "manifest": s["manifest"],
                            "verifycaps": [i for i in s["verifycaps"]],
                            "storage-index": [i for i in s["storage-index"]],
                            })
            # simplejson doesn't know how to serialize a set. We use a
            # generator that walks the set rather than list(setofthing) to
            # save a small amount of memory (4B*len) and a moderate amount of
            # CPU.
        return simplejson.dumps(status, indent=1)

    def _si_abbrev(self):
        si = self.monitor.origin_si
        if not si:
            return "<LIT>"
        return base32.b2a(si)[:6]

    def render_title(self, ctx):
        return T.title["Manifest of SI=%s" % self._si_abbrev()]

    def render_header(self, ctx):
        return T.p["Manifest of SI=%s" % self._si_abbrev()]

    def data_items(self, ctx, data):
        return self.monitor.get_status()["manifest"]

    def render_row(self, ctx, (path, cap)):
        ctx.fillSlots("path", self.slashify_path(path))
        root = get_root(ctx)
        # TODO: we need a clean consistent way to get the type of a cap string
        if cap:
            if cap.startswith("URI:CHK") or cap.startswith("URI:SSK"):
                nameurl = urllib.quote(path[-1].encode("utf-8"))
                uri_link = "%s/file/%s/@@named=/%s" % (root, urllib.quote(cap),
                                                       nameurl)
            else:
                uri_link = "%s/uri/%s" % (root, urllib.quote(cap, safe=""))
            ctx.fillSlots("cap", T.a(href=uri_link)[cap])
        else:
            ctx.fillSlots("cap", "")
        return ctx.tag
Example #13
0
    def render_row(self, ctx, data):
        name, (target, metadata) = data
        name = name.encode("utf-8")
        assert not isinstance(name, unicode)
        nameurl = urllib.quote(name, safe="") # encode any slashes too

        root = get_root(ctx)
        here = "%s/uri/%s/" % (root, urllib.quote(self.node.get_uri()))
        if self.node.is_unknown() or self.node.is_readonly():
            unlink = "-"
            rename = "-"
        else:
            # this creates a button which will cause our _POST_unlink method
            # to be invoked, which unlinks the file and then redirects the
            # browser back to this directory
            unlink = T.form(action=here, method="post")[
                T.input(type='hidden', name='t', value='unlink'),
                T.input(type='hidden', name='name', value=name),
                T.input(type='hidden', name='when_done', value="."),
                T.input(type='submit', value='unlink', name="unlink"),
                ]

            rename = T.form(action=here, method="get")[
                T.input(type='hidden', name='t', value='rename-form'),
                T.input(type='hidden', name='name', value=name),
                T.input(type='hidden', name='when_done', value="."),
                T.input(type='submit', value='rename/relink', name="rename"),
                ]

        ctx.fillSlots("unlink", unlink)
        ctx.fillSlots("rename", rename)

        times = []
        linkcrtime = metadata.get('tahoe', {}).get("linkcrtime")
        if linkcrtime is not None:
            times.append("lcr: " + time_format.iso_local(linkcrtime))
        else:
            # For backwards-compatibility with links last modified by Tahoe < 1.4.0:
            if "ctime" in metadata:
                ctime = time_format.iso_local(metadata["ctime"])
                times.append("c: " + ctime)
        linkmotime = metadata.get('tahoe', {}).get("linkmotime")
        if linkmotime is not None:
            if times:
                times.append(T.br())
            times.append("lmo: " + time_format.iso_local(linkmotime))
        else:
            # For backwards-compatibility with links last modified by Tahoe < 1.4.0:
            if "mtime" in metadata:
                mtime = time_format.iso_local(metadata["mtime"])
                if times:
                    times.append(T.br())
                times.append("m: " + mtime)
        ctx.fillSlots("times", times)

        assert IFilesystemNode.providedBy(target), target
        target_uri = target.get_uri() or ""
        quoted_uri = urllib.quote(target_uri, safe="") # escape slashes too

        if IMutableFileNode.providedBy(target):
            # to prevent javascript in displayed .html files from stealing a
            # secret directory URI from the URL, send the browser to a URI-based
            # page that doesn't know about the directory at all
            dlurl = "%s/file/%s/@@named=/%s" % (root, quoted_uri, nameurl)

            ctx.fillSlots("filename", T.a(href=dlurl)[name])
            ctx.fillSlots("type", "SSK")

            ctx.fillSlots("size", "?")

            info_link = "%s/uri/%s?t=info" % (root, quoted_uri)

        elif IImmutableFileNode.providedBy(target):
            dlurl = "%s/file/%s/@@named=/%s" % (root, quoted_uri, nameurl)

            ctx.fillSlots("filename", T.a(href=dlurl)[name])
            ctx.fillSlots("type", "FILE")

            ctx.fillSlots("size", target.get_size())

            info_link = "%s/uri/%s?t=info" % (root, quoted_uri)

        elif IDirectoryNode.providedBy(target):
            # directory
            uri_link = "%s/uri/%s/" % (root, urllib.quote(target_uri))
            ctx.fillSlots("filename", T.a(href=uri_link)[name])
            if not target.is_mutable():
                dirtype = "DIR-IMM"
            elif target.is_readonly():
                dirtype = "DIR-RO"
            else:
                dirtype = "DIR"
            ctx.fillSlots("type", dirtype)
            ctx.fillSlots("size", "-")
            info_link = "%s/uri/%s/?t=info" % (root, quoted_uri)

        elif isinstance(target, ProhibitedNode):
            ctx.fillSlots("filename", T.strike[name])
            if IDirectoryNode.providedBy(target.wrapped_node):
                blacklisted_type = "DIR-BLACKLISTED"
            else:
                blacklisted_type = "BLACKLISTED"
            ctx.fillSlots("type", blacklisted_type)
            ctx.fillSlots("size", "-")
            info_link = None
            ctx.fillSlots("info", ["Access Prohibited:", T.br, target.reason])

        else:
            # unknown
            ctx.fillSlots("filename", name)
            if target.get_write_uri() is not None:
                unknowntype = "?"
            elif not self.node.is_mutable() or target.is_alleged_immutable():
                unknowntype = "?-IMM"
            else:
                unknowntype = "?-RO"
            ctx.fillSlots("type", unknowntype)
            ctx.fillSlots("size", "-")
            # use a directory-relative info link, so we can extract both the
            # writecap and the readcap
            info_link = "%s?t=info" % urllib.quote(name)

        if info_link:
            ctx.fillSlots("info", T.a(href=info_link)["More Info"])

        return ctx.tag
Example #14
0
 def render_welcome(self, ctx, data):
     link = get_root(ctx)
     return ctx.tag[T.a(href=link)["Return to Welcome page"]]
Example #15
0
    def render_row(self, ctx, data):
        name, (target, metadata) = data
        name = name.encode("utf-8")
        assert not isinstance(name, unicode)
        nameurl = urllib.quote(name, safe="") # encode any slashes too

        root = get_root(ctx)
        here = "%s/uri/%s/" % (root, urllib.quote(self.node.get_uri()))
        if self.node.is_unknown() or self.node.is_readonly():
            unlink = "-"
            rename = "-"
        else:
            # this creates a button which will cause our _POST_unlink method
            # to be invoked, which unlinks the file and then redirects the
            # browser back to this directory
            unlink = T.form(action=here, method="post")[
                T.input(type='hidden', name='t', value='unlink'),
                T.input(type='hidden', name='name', value=name),
                T.input(type='hidden', name='when_done', value="."),
                T.input(type='submit', _class='btn', value='unlink', name="unlink"),
                ]

            rename = T.form(action=here, method="get")[
                T.input(type='hidden', name='t', value='rename-form'),
                T.input(type='hidden', name='name', value=name),
                T.input(type='hidden', name='when_done', value="."),
                T.input(type='submit', _class='btn', value='rename/relink', name="rename"),
                ]

        ctx.fillSlots("unlink", unlink)
        ctx.fillSlots("rename", rename)

        times = []
        linkcrtime = metadata.get('tahoe', {}).get("linkcrtime")
        if linkcrtime is not None:
            times.append("lcr: " + render_time(linkcrtime))
        else:
            # For backwards-compatibility with links last modified by Tahoe < 1.4.0:
            if "ctime" in metadata:
                ctime = render_time(metadata["ctime"])
                times.append("c: " + ctime)
        linkmotime = metadata.get('tahoe', {}).get("linkmotime")
        if linkmotime is not None:
            if times:
                times.append(T.br())
            times.append("lmo: " + render_time(linkmotime))
        else:
            # For backwards-compatibility with links last modified by Tahoe < 1.4.0:
            if "mtime" in metadata:
                mtime = render_time(metadata["mtime"])
                if times:
                    times.append(T.br())
                times.append("m: " + mtime)
        ctx.fillSlots("times", times)

        assert IFilesystemNode.providedBy(target), target
        target_uri = target.get_uri() or ""
        quoted_uri = urllib.quote(target_uri, safe="") # escape slashes too

        if IMutableFileNode.providedBy(target):
            # to prevent javascript in displayed .html files from stealing a
            # secret directory URI from the URL, send the browser to a URI-based
            # page that doesn't know about the directory at all
            dlurl = "%s/file/%s/@@named=/%s" % (root, quoted_uri, nameurl)

            ctx.fillSlots("filename", T.a(href=dlurl, rel="noreferrer")[name])
            ctx.fillSlots("type", "SSK")

            ctx.fillSlots("size", "?")

            info_link = "%s/uri/%s?t=info" % (root, quoted_uri)

        elif IImmutableFileNode.providedBy(target):
            dlurl = "%s/file/%s/@@named=/%s" % (root, quoted_uri, nameurl)

            ctx.fillSlots("filename", T.a(href=dlurl, rel="noreferrer")[name])
            ctx.fillSlots("type", "FILE")

            ctx.fillSlots("size", target.get_size())

            info_link = "%s/uri/%s?t=info" % (root, quoted_uri)

        elif IDirectoryNode.providedBy(target):
            # directory
            uri_link = "%s/uri/%s/" % (root, urllib.quote(target_uri))
            ctx.fillSlots("filename", T.a(href=uri_link)[name])
            if not target.is_mutable():
                dirtype = "DIR-IMM"
            elif target.is_readonly():
                dirtype = "DIR-RO"
            else:
                dirtype = "DIR"
            ctx.fillSlots("type", dirtype)
            ctx.fillSlots("size", "-")
            info_link = "%s/uri/%s/?t=info" % (root, quoted_uri)

        elif isinstance(target, ProhibitedNode):
            ctx.fillSlots("filename", T.strike[name])
            if IDirectoryNode.providedBy(target.wrapped_node):
                blacklisted_type = "DIR-BLACKLISTED"
            else:
                blacklisted_type = "BLACKLISTED"
            ctx.fillSlots("type", blacklisted_type)
            ctx.fillSlots("size", "-")
            info_link = None
            ctx.fillSlots("info", ["Access Prohibited:", T.br, target.reason])

        else:
            # unknown
            ctx.fillSlots("filename", name)
            if target.get_write_uri() is not None:
                unknowntype = "?"
            elif not self.node.is_mutable() or target.is_alleged_immutable():
                unknowntype = "?-IMM"
            else:
                unknowntype = "?-RO"
            ctx.fillSlots("type", unknowntype)
            ctx.fillSlots("size", "-")
            # use a directory-relative info link, so we can extract both the
            # writecap and the readcap
            info_link = "%s?t=info" % urllib.quote(name)

        if info_link:
            ctx.fillSlots("info", T.a(href=info_link)["More Info"])

        return ctx.tag
Example #16
0
 def render_welcome(self, ctx, data):
     link = get_root(ctx)
     return ctx.tag[T.a(href=link)["Return to Welcome page"]]