Пример #1
0
class Version(BasePage):

    contentTemplateFile = "pasting.html"

    child_ = rend.FourOhFour()

    def __init__(self, pastebin, pasting, version):
        BasePage.__init__(self)
        self.pastebin = pastebin
        self.pasting = pasting
        self.version = version

    def data_history(self, context, data):
        return self.pasting.getHistory()

    def render_aPasting(self, context, data):
        return render_pasting(self.pasting.getVersion(self.version))

    def render_version(self, context, data):
        version, author, theTime = data
        context.fillSlots(
            'link',
            tags.a(href=[url.here.sibling(str(version))])[render_time(theTime),
                                                          ' (', author, ')'])
        return context.tag
Пример #2
0
 def renderHTTP(self, ctx):
     """
     Render the resource I was provided at construction time.
     """
     if self.currentResource is None:
         return rend.FourOhFour()
     return self.currentResource  # nevow will automatically adapt to
Пример #3
0
    def childFactory(self, ctx, seg):
        db = list(self.db) + [self.Hooky]
        keyOk = False

        if not os.path.exists('/usr/local/tcs/tums/.kvd'):
            # Uptime more than 7 days (prevent bootstrapping issues)
            up = open('/proc/uptime').read().strip('\n').strip().split()
            n = float(up[0])
            days = n / (60 * 60 * 24)

            if days > 7:
                if os.path.exists('/usr/local/tcs/tums/.tliac'):
                    mk = self.gK()
                    if mk == open('/usr/local/tcs/tums/.tliac').read():
                        keyOk = True

                if not keyOk and os.path.exists('/usr/local/tcs/tums/.kxd'):
                    kt = os.stat('/usr/local/tcs/tums/.kxd').st_mtime
                    nw = time.time()
                    #seconds = (60*60*24*16) - (nw-kt)
                    seconds = (60 * 60 * 24 * 16) - (nw - kt)

                    if seconds < 60:
                        return self.childPages['Status'].Page(
                            self.avatarId, db)

        if seg in self.childPages.keys():
            thisPage = self.childPages[seg].Page(self.avatarId, db)
        elif self.Hooky.hookExists(seg):
            thisPage = self.Hooky.getHook(seg)(self.avatarId, tuple(db))
        else:
            thisPage = rend.FourOhFour()

        # Ensure that the db list is immutable

        if seg == "Settings":
            return thisPage

        if self.lockStatus and self.lockUser != self.avatarId.username:
            return PageHelpers.AdminLocked(self.avatarId, db)

        if self.avatarId.reports:
            if seg in [
                    "Overview", "NetworkStats", "Mail", "Reports", "Stats",
                    "ProxyUse", "InterfaceStats"
            ]:
                return thisPage

        if not self.avatarId.isAdmin and not self.avatarId.isUser:
            if seg in ["Users", "Reports", "Tools", "Stats"]:
                return thisPage
            else:
                return PermissionDenied.Page(self.avatarId, db)

        if self.avatarId.isUser:
            return PermissionDenied.Page(self.avatarId, db)

        return thisPage
Пример #4
0
    def renderHTTP(self, ctx):
        """You know what you doing. Not particularly..."""

        self.fp.restat()

        if self.type is None:
            self.type, self.encoding = static.getTypeAndEncoding(
                self.fp.basename(), self.contentTypes, self.contentEncodings,
                self.defaultType)

        if not self.avatarId.username in self.fp.path:
            return rend.FourOhFour()

        if not self.fp.exists():
            return rend.FourOhFour()

        request = inevow.IRequest(ctx)

        if self.fp.isdir():
            return self.redirect(request)

        # fsize is the full file size
        # size is the length of the part actually transmitted
        fsize = size = self.getFileSize()

        request.setHeader('accept-ranges', 'bytes')

        if self.type:
            request.setHeader('content-type', self.type)
        if self.encoding:
            request.setHeader('content-encoding', self.encoding)

        try:
            f = self.openForReading()
        except IOError, e:
            import errno
            if e[0] == errno.EACCES:
                return error.ForbiddenResource().render(request)
            else:
                raise
Пример #5
0
    def renderHTTP(self, ctx):
        """You know what you doing."""
        self.fp.restat()

        if self.type is None:
            self.type, self.encoding = getTypeAndEncoding(
                self.fp.basename(), self.contentTypes, self.contentEncodings,
                self.defaultType)

        if not self.fp.exists():
            return rend.FourOhFour()

        request = inevow.IRequest(ctx)

        if self.fp.isdir():
            return self.redirect(request)

        # fsize is the full file size
        # size is the length of the part actually transmitted
        fsize = size = self.getFileSize()

        request.setHeader('accept-ranges', 'bytes')

        if self.type:
            request.setHeader('content-type', self.type)
        if self.encoding:
            request.setHeader('content-encoding', self.encoding)

        try:
            f = self.openForReading()
        except IOError as e:
            import errno
            if e[0] == errno.EACCES:
                return ForbiddenResource().render(request)
            else:
                raise

        if request.setLastModified(
                self.fp.getModificationTime()) is http.CACHED:
            return ''

        try:
            range = request.getHeader('range')

            if range is not None:
                # This is a request for partial data...
                bytesrange = string.split(range, '=')
                assert bytesrange[0] == 'bytes',\
                       "Syntactically invalid http range header!"
                start, end = string.split(bytesrange[1], '-')
                if start:
                    f.seek(int(start))
                if end:
                    end = int(end)
                else:
                    end = fsize - 1
                request.setResponseCode(http.PARTIAL_CONTENT)
                request.setHeader(
                    'content-range',
                    "bytes %s-%s/%s" % (str(start), str(end), str(fsize)))
                #content-length should be the actual size of the stuff we're
                #sending, not the full size of the on-server entity.
                size = 1 + end - int(start)

            request.setHeader('content-length', str(size))
        except:
            traceback.print_exc(file=log.logfile)

        if request.method == 'HEAD':
            return ''

        # return data
        FileTransfer(f, size, request)
        # and make sure the connection doesn't get closed
        return request.deferred
Пример #6
0
 def renderHTTP(self, ctx):
     return rend.FourOhFour()