Exemplo n.º 1
0
    def stop(self, req, auth_ok=False):
        # check if this is allowed
        if not auth_ok:
            if not self.getAuthz(req).actionAllowed('stopBuild', req,
                                                    self.build_status):
                return Redirect(path_to_authfail(req))

        b = self.build_status
        log.msg("web stopBuild of build %s:%s" % \
                (b.getBuilder().getName(), b.getNumber()))
        name = req.args.get("username", ["<unknown>"])[0]
        comments = req.args.get("comments", ["<no reason specified>"])[0]
        # html-quote both the username and comments, just to be safe
        reason = ("The web-page 'stop build' button was pressed by "
                  "'%s': %s\n" % (html.escape(name), html.escape(comments)))

        c = interfaces.IControl(self.getBuildmaster(req))
        bldrc = c.getBuilder(self.build_status.getBuilder().getName())
        if bldrc:
            bldc = bldrc.getBuild(self.build_status.getNumber())
            if bldc:
                bldc.stopBuild(reason)

        # we're at http://localhost:8080/svn-hello/builds/5/stop?[args] and
        # we want to go to: http://localhost:8080/svn-hello
        r = Redirect(path_to_builder(req, self.build_status.getBuilder()))
        d = defer.Deferred()
        reactor.callLater(1, d.callback, r)
        return DeferredResource(d)
Exemplo n.º 2
0
    def force(self, req, auth_ok=False):
        name = self.getAuthz(req).getUsername(req)
        reason = req.args.get("comments", ["<no reason specified>"])[0]
        branch = req.args.get("branch", [""])[0]
        revision = req.args.get("revision", [""])[0]
        repository = req.args.get("repository", [""])[0]
        project = req.args.get("project", [""])[0]

        log.msg("web forcebuild of builder '%s', branch='%s', revision='%s',"
                " repository='%s', project='%s' by user '%s'" %
                (self.builder_status.getName(), branch, revision, repository,
                 project, name))

        if not auth_ok:
            req_args = dict(name=name,
                            reason=reason,
                            branch=branch,
                            revision=revision,
                            repository=repository,
                            project=project)
            return ForceBuildActionResource(self.builder_status, req_args)

        master = self.getBuildmaster(req)

        # keep weird stuff out of the branch revision, and property strings.
        branch_validate = master.config.validation['branch']
        revision_validate = master.config.validation['revision']
        if not branch_validate.match(branch):
            log.msg("bad branch '%s'" % branch)
            return Redirect(path_to_builder(req, self.builder_status))
        if not revision_validate.match(revision):
            log.msg("bad revision '%s'" % revision)
            return Redirect(path_to_builder(req, self.builder_status))
        properties = getAndCheckProperties(req)
        if properties is None:
            return Redirect(path_to_builder(req, self.builder_status))
        if not branch:
            branch = None
        if not revision:
            revision = None

        d = master.db.sourcestamps.addSourceStamp(branch=branch,
                                                  revision=revision,
                                                  project=project,
                                                  repository=repository)

        def make_buildset(ssid):
            r = (
                "The web-page 'force build' button was pressed by '%s': %s\n" %
                (html.escape(name), html.escape(reason)))
            return master.addBuildset(
                builderNames=[self.builder_status.getName()],
                ssid=ssid,
                reason=r,
                properties=properties.asDict())

        d.addCallback(make_buildset)
        d.addErrback(log.err, "(ignored) while trying to force build")
        # send the user back to the builder page
        return Redirect(path_to_builder(req, self.builder_status))
Exemplo n.º 3
0
def make_resource(
    stripe_publishable_api_key,
    stripe_plan_id,
    get_signup,
    stripe,
    mailer,
    cross_domain,
):
    resource = Resource()
    resource.putChild("", Redirect("https://leastauthority.com/"))
    resource.putChild("index.html", Redirect("https://leastauthority.com/"))
    resource.putChild('signup', Redirect("https://leastauthority.com/"))
    resource.putChild('static', File(_STATIC.path))
    resource.putChild(
        'configuration',
        configuration(stripe_publishable_api_key, cross_domain),
    )
    # add new path for AJAX POST
    resource.putChild(
        'create-subscription',
        CreateSubscription(
            get_signup,
            mailer,
            stripe,
            cross_domain,
            stripe_plan_id,
        ),
    )
    resource.putChild(
        "s4-subscription-form",
        JinjaHandler("s4-subscription-form.html"),
    )

    return resource
Exemplo n.º 4
0
    def setUp(self):
        self.agent = None # for twisted.web.client.Agent test
        self.cleanupServerConnections = 0
        r = resource.Resource()
        r.putChild(b"file", Data(b"0123456789", "text/html"))
        r.putChild(b"redirect", Redirect(b"/file"))
        self.infiniteRedirectResource = CountingRedirect(b"/infiniteRedirect")
        r.putChild(b"infiniteRedirect", self.infiniteRedirectResource)
        r.putChild(b"wait", ForeverTakingResource())
        r.putChild(b"write-then-wait", ForeverTakingResource(write=True))
        r.putChild(b"never-read", ForeverTakingNoReadingResource())
        r.putChild(b"error", ErrorResource())
        r.putChild(b"nolength", NoLengthResource())
        r.putChild(b"host", HostHeaderResource())
        r.putChild(b"payload", PayloadResource())
        r.putChild(b"broken", BrokenDownloadResource())
        r.putChild(b"cookiemirror", CookieMirrorResource())
        r.putChild(b'delay1', DelayResource(1))
        r.putChild(b'delay2', DelayResource(2))

        self.afterFoundGetCounter = CountingResource()
        r.putChild(b"afterFoundGetCounter", self.afterFoundGetCounter)
        r.putChild(b"afterFoundGetRedirect", Redirect(b"/afterFoundGetCounter"))

        miscasedHead = Data(b"miscased-head GET response content", "major/minor")
        miscasedHead.render_Head = lambda request: b"miscased-head content"
        r.putChild(b"miscased-head", miscasedHead)

        self.extendedRedirect = ExtendedRedirect(b'/extendedRedirect')
        r.putChild(b"extendedRedirect", self.extendedRedirect)
        self.site = server.Site(r, timeout=None)
        self.wrapper = WrappingFactory(self.site)
        self.port = self._listen(self.wrapper)
        self.portno = self.port.getHost().port
Exemplo n.º 5
0
 def __init__(self, products):
     self.products = products
     self.children = {}
     self.putChild('', Redirect('/products'))
     for product in self.products:
         self.putChild(str(product['short_name']),
                       Redirect(str(product['signup_url'])))
Exemplo n.º 6
0
 def rebuild(self, req):
     if self.isUsingUserPasswd(req):
         if not self.authUser(req):
             return Redirect("../../../authfailed")
     b = self.build_status
     bc = self.builder_control
     builder_name = b.getBuilder().getName()
     log.msg("web rebuild of build %s:%s" % (builder_name, b.getNumber()))
     name = req.args.get("username", ["<unknown>"])[0]
     comments = req.args.get("comments", ["<no reason specified>"])[0]
     reason = ("The web-page 'rebuild' button was pressed by "
               "'%s': %s\n" % (html.escape(name), html.escape(comments)))
     extraProperties = getAndCheckProperties(req)
     if not bc or not b.isFinished() or extraProperties is None:
         log.msg("could not rebuild: bc=%s, isFinished=%s"
                 % (bc, b.isFinished()))
         # TODO: indicate an error
     else:
         bc.resubmitBuild(b, reason, extraProperties)
     # we're at
     # http://localhost:8080/builders/NAME/builds/5/rebuild?[args]
     # Where should we send them?
     #
     # Ideally it would be to the per-build page that they just started,
     # but we don't know the build number for it yet (besides, it might
     # have to wait for a current build to finish). The next-most
     # preferred place is somewhere that the user can see tangible
     # evidence of their build starting (or to see the reason that it
     # didn't start). This should be the Builder page.
     r = Redirect("../..") # the Builder's page
     d = defer.Deferred()
     reactor.callLater(1, d.callback, r)
     return DeferredResource(d)
Exemplo n.º 7
0
    def cancelbuild(self, req):
        try:
            request_id = req.args.get("id", [None])[0]
            if request_id == "all":
                cancel_all = True
            else:
                cancel_all = False
                request_id = int(request_id)
        except:
            request_id = None

        authz = self.getAuthz(req)
        if request_id:
            c = interfaces.IControl(self.getBuildmaster(req))
            bc = c.getBuilder(self.builder_status.getName())
            for build_req in bc.getPendingBuilds():
                if cancel_all or (build_req.brid == request_id):
                    log.msg("Cancelling %s" % build_req)
                    if authz.actionAllowed('cancelPendingBuild', req,
                                           build_req):
                        build_req.cancel()
                    else:
                        return Redirect(path_to_authfail(req))
                    if not cancel_all:
                        break
        return Redirect(path_to_builder(req, self.builder_status))
Exemplo n.º 8
0
    def stopchange(self, req, auth_ok=False):
        """Cancel all pending builds that include a given numbered change."""
        try:
            request_change = req.args.get("change", [None])[0]
            request_change = int(request_change)
        except:
            request_change = None

        authz = self.getAuthz(req)
        if request_change:
            # FIXME: Please, for the love of god one day make there only be
            # one getPendingBuilds() with combined status info/controls
            c = interfaces.IControl(self.getBuildmaster(req))
            builder_control = c.getBuilder(self.builder_status.getName())
            build_controls = dict(
                (x.brid, x) for x in builder_control.getPendingBuilds())
            for build_req in self.builder_status.getPendingBuilds():
                ss = build_req.getSourceStamp()
                if not ss.changes:
                    continue
                for change in ss.changes:
                    if change.number == request_change:
                        control = build_controls[build_req.brid]
                        log.msg("Cancelling %s" % control)
                        if auth_ok or authz.actionAllowed(
                                'stopChange', req, control):
                            control.cancel()
                        else:
                            return Redirect(path_to_authfail(req))
        return Redirect(path_to_builder(req, self.builder_status))
Exemplo n.º 9
0
def make_resource(
    stripe_publishable_api_key,
    get_signup,
    stripe,
    mailer,
):
    resource = Resource()
    resource.putChild("", Redirect("https://leastauthority.com/"))
    resource.putChild("index.html", Redirect("https://leastauthority.com/"))
    resource.putChild('signup', Redirect("https://leastauthority.com/"))
    resource.putChild('static', File(_STATIC.path))
    resource.putChild(
        'configuration',
        configuration(stripe_publishable_api_key),
    )
    resource.putChild("s4-signup-style", S4SignupStyle())
    resource.putChild(
        "s4-subscription-form",
        JinjaHandler("s4-subscription-form.html"),
    )
    resource.putChild(
        'submit-subscription',
        SubmitSubscriptionHandler(
            get_signup,
            mailer,
            stripe,
        ),
    )

    return resource
Exemplo n.º 10
0
    def installApplication(self, application):
        """Install the WSGI application into the Twisted site.

        It's installed as a child with path "MAAS". This matches the default
        front-end configuration (i.e. Apache) so that there's no need to force
        script names.
        """
        # Setup resources to process paths that twisted handles.
        metadata = Resource()
        metadata.putChild(b"status", StatusHandlerResource(self.status_worker))

        maas = Resource()
        maas.putChild(b"metadata", metadata)
        maas.putChild(
            b"ws", WebSocketsResource(lookupProtocolForFactory(self.websocket))
        )

        # /MAAS/r/{path} and /MAAS/l/{path} are all resolved by the new MAAS UI
        # react app, and legacy angularjs app respectively.
        # If any paths do not match then its routed to index.html in the new
        # UI code as it uses HTML 5 routing.
        maas.putChild(b"r", DefaultFallbackFile(settings.STATIC_ROOT))

        maas.putChild(b"l", DefaultFallbackFile(settings.STATIC_ROOT))

        # Redirect /MAAS to react app
        maas.putChild(b"", Redirect(b"/MAAS/r/"))

        # Setup static resources
        maas.putChild(
            b"assets",
            NoListingFile(os.path.join(settings.STATIC_ROOT, "assets")),
        )

        # Setup static docs
        maas.putChild(
            b"docs",
            DocsFallbackFile(os.path.join(settings.STATIC_ROOT, "docs")),
        )

        root = Resource()
        root.putChild(b"", Redirect(b"MAAS/"))
        root.putChild(b"MAAS", maas)

        # Setup the resources to process paths that django handles.
        underlay_maas = ResourceOverlay(
            WSGIResource(reactor, self.threadpool, application)
        )
        underlay_root = Resource()
        underlay_root.putChild(b"MAAS", underlay_maas)
        underlay_site = Site(
            underlay_root, logFormatter=reducedWebLogFormatter
        )
        underlay_site.requestFactory = CleanPathRequest

        # Setup the main resource as the twisted handler and the underlay
        # resource as the django handler.
        self.site.resource = root
        self.site.underlay = underlay_site
Exemplo n.º 11
0
    def force(self, req, auth_ok=False):
        name = req.args.get("username", ["<unknown>"])[0]
        reason = req.args.get("comments", ["<no reason specified>"])[0]
        branch = req.args.get("branch", [""])[0]
        revision = req.args.get("revision", [""])[0]
        repository = req.args.get("repository", [""])[0]
        project = req.args.get("project", [""])[0]

        r = "The web-page 'force build' button was pressed by '%s': %s\n" \
            % (html.escape(name), html.escape(reason))
        log.msg("web forcebuild of builder '%s', branch='%s', revision='%s',"
                " repository='%s', project='%s' by user '%s'" %
                (self.builder_status.getName(), branch, revision, repository,
                 project, name))

        # check if this is allowed
        if not auth_ok:
            if not self.getAuthz(req).actionAllowed('forceBuild', req,
                                                    self.builder_status):
                log.msg("..but not authorized")
                return Redirect(path_to_authfail(req))

        # keep weird stuff out of the branch revision, and property strings.
        # TODO: centralize this somewhere.
        if not re.match(r'^[\w.+/~-]*$', branch):
            log.msg("bad branch '%s'" % branch)
            return Redirect(path_to_builder(req, self.builder_status))
        if not re.match(r'^[ \w\.\-\/]*$', revision):
            log.msg("bad revision '%s'" % revision)
            return Redirect(path_to_builder(req, self.builder_status))
        properties = getAndCheckProperties(req)
        if properties is None:
            return Redirect(path_to_builder(req, self.builder_status))
        if not branch:
            branch = None
        if not revision:
            revision = None

        # TODO: if we can authenticate that a particular User pushed the
        # button, use their name instead of None, so they'll be informed of
        # the results.
        # TODO2: we can authenticate that a particular User pushed the button
        # now, so someone can write this support. but it requires a
        # buildbot.changes.changes.Change instance which is tedious at this
        # stage to compute
        s = SourceStamp(branch=branch,
                        revision=revision,
                        project=project,
                        repository=repository)
        try:
            c = interfaces.IControl(self.getBuildmaster(req))
            bc = c.getBuilder(self.builder_status.getName())
            bc.submitBuildRequest(s, r, properties)
        except interfaces.NoSlaveError:
            # TODO: tell the web user that their request could not be
            # honored
            pass
        # send the user back to the builder page
        return Redirect(path_to_builder(req, self.builder_status))
Exemplo n.º 12
0
 def getChild(self, path, req):
     s = self.getStatus(req)
     slave = s.getSlave(self.slavename)
     if path == "shutdown":
         if self.getAuthz(req).actionAllowed("gracefulShutdown", req, slave):
             slave.setGraceful(True)
         else:
             return Redirect(path_to_authfail(req))
     return Redirect(path_to_slave(req, slave))
Exemplo n.º 13
0
    def force(self, req, auth_ok=False):
        name = req.args.get("username", ["<unknown>"])[0]
        reason = req.args.get("comments", ["<no reason specified>"])[0]
        branch = req.args.get("branch", [""])[0]
        revision = req.args.get("revision", [""])[0]
        repository = req.args.get("repository", [""])[0]
        project = req.args.get("project", [""])[0]

        log.msg("web forcebuild of builder '%s', branch='%s', revision='%s',"
                " repository='%s', project='%s' by user '%s'" %
                (self.builder_status.getName(), branch, revision, repository,
                 project, name))

        # check if this is allowed
        if not auth_ok:
            if not self.getAuthz(req).actionAllowed('forceBuild', req,
                                                    self.builder_status):
                log.msg("..but not authorized")
                return Redirect(path_to_authfail(req))

        # keep weird stuff out of the branch revision, and property strings.
        # TODO: centralize this somewhere.
        if not re.match(r'^[\w.+/~-]*$', branch):
            log.msg("bad branch '%s'" % branch)
            return Redirect(path_to_builder(req, self.builder_status))
        if not re.match(r'^[ \w\.\-\/]*$', revision):
            log.msg("bad revision '%s'" % revision)
            return Redirect(path_to_builder(req, self.builder_status))
        properties = getAndCheckProperties(req)
        if properties is None:
            return Redirect(path_to_builder(req, self.builder_status))
        if not branch:
            branch = None
        if not revision:
            revision = None

        master = self.getBuildmaster(req)
        d = master.db.sourcestamps.createSourceStamp(branch=branch,
                                                     revision=revision,
                                                     project=project,
                                                     repository=repository)

        def make_buildset(ssid):
            r = (
                "The web-page 'force build' button was pressed by '%s': %s\n" %
                (html.escape(name), html.escape(reason)))
            return master.addBuildset(
                builderNames=[self.builder_status.getName()],
                ssid=ssid,
                reason=r,
                properties=None)

        d.addCallback(make_buildset)
        d.addErrback(log.err, "(ignored) while trying to force build")
        # send the user back to the builder page
        return Redirect(path_to_builder(req, self.builder_status))
Exemplo n.º 14
0
 def ping(self, req):
     log.msg("web ping of builder '%s'" % self.builder_status.getName())
     if not self.getAuthz(req).actionAllowed('pingBuilder', req, self.builder_status):
         log.msg("..but not authorized")
         return Redirect(path_to_authfail(req))
     c = interfaces.IControl(self.getBuildmaster(req))
     bc = c.getBuilder(self.builder_status.getName())
     bc.ping()
     # send the user back to the builder page
     return Redirect(path_to_builder(req, self.builder_status))
Exemplo n.º 15
0
 def getChild(self, path, request):
     if not request.prepath:
         return None
     cookie = request.getCookie(self.cookieKey)
     setupURL = urlToChild(request, INIT_SESSION,
                           *([path] + request.postpath))
     request.setupSessionURL = setupURL
     request.setupSession = lambda: Redirect(setupURL)
     if path.startswith(SESSION_KEY):
         key = path[len(SESSION_KEY):]
         if key not in self.sessions:
             return redirectToSession(request, '__start_session__')
         self.sessions[key].setLifetime(self.sessionLifetime)
         if cookie == key:
             # /sessionized-url/${SESSION_KEY}aef9c34aecc3d9148/foo
             #                  ^
             #                  we are this getChild
             # with a matching cookie
             return redirectToSession(request, '__session_just_started__')
         else:
             # We attempted to negotiate the session but failed (the user
             # probably has cookies disabled): now we're going to return the
             # resource we contain.  In general the getChild shouldn't stop
             # there.
             # /sessionized-url/${SESSION_KEY}aef9c34aecc3d9148/foo
             #                  ^ we are this getChild
             # without a cookie (or with a mismatched cookie)
             _setSession(self, request, key)
             return self.resource
     elif cookie in self.sessions:
         # /sessionized-url/foo
         #                 ^ we are this getChild
         # with a session
         _setSession(self, request, cookie)
         return getResource(self.resource, path, request)
     elif path == INIT_SESSION:
         # initialize the session
         # /sessionized-url/session-init
         #                  ^ this getChild
         # without a session
         newCookie = _sessionCookie()
         request.addCookie(self.cookieKey, newCookie, path="/")
         sz = self.sessions[newCookie] = GuardSession(self, newCookie)
         sz.checkExpired()
         rd = Redirect(
             urlToChild(request, SESSION_KEY + newCookie,
                        *request.postpath))
         rd.isLeaf = 1
         return rd
     else:
         # /sessionized-url/foo
         #                 ^ we are this getChild
         # without a session
         request.getSession = lambda interface=None: None
         return getResource(self.resource, path, request)
Exemplo n.º 16
0
    def forceselected(self, req):
        authz = self.getAuthz(req)
        if not authz.actionAllowed('forceAllBuilds', req):
            return Redirect(path_to_authfail(req))

        for bname in [b for b in req.args.get("selected", []) if b]:
            builder_status = self.status.getBuilder(bname)
            build = StatusResourceBuilder(builder_status)
            build.force(req, auth_ok=True) # auth_ok because we already checked
        # back to the welcome page
        return Redirect(path_to_root(req))
Exemplo n.º 17
0
    def stopchangeall(self, req):
        authz = self.getAuthz(req)
        if not authz.actionAllowed('stopChange', req):
            return Redirect(path_to_authfail(req))

        for bname in self.status.getBuilderNames():
            builder_status = self.status.getBuilder(bname)
            build = StatusResourceBuilder(builder_status)
            build.stopchange(req, auth_ok=True)

        return Redirect(path_to_root(req))
Exemplo n.º 18
0
    def force(self, req):
        """

        Custom properties can be passed from the web form.  To do
        this, subclass this class, overriding the force() method.  You
        can then determine the properties (usually from form values,
        by inspecting req.args), then pass them to this superclass
        force method.
        
        """
        name = req.args.get("username", ["<unknown>"])[0]
        reason = req.args.get("comments", ["<no reason specified>"])[0]
        branch = req.args.get("branch", [""])[0]
        revision = req.args.get("revision", [""])[0]

        r = "The web-page 'force build' button was pressed by '%s': %s\n" \
            % (name, reason)
        log.msg("web forcebuild of builder '%s', branch='%s', revision='%s'" %
                (self.builder_status.getName(), branch, revision))

        if not self.builder_control:
            # TODO: tell the web user that their request was denied
            log.msg("but builder control is disabled")
            return Redirect("..")

        # keep weird stuff out of the branch and revision strings. TODO:
        # centralize this somewhere.
        if not re.match(r'^[\w\.\-\/]*$', branch):
            log.msg("bad branch '%s'" % branch)
            return Redirect("..")
        if not re.match(r'^[\w\.\-\/]*$', revision):
            log.msg("bad revision '%s'" % revision)
            return Redirect("..")
        if not branch:
            branch = None
        if not revision:
            revision = None

        # TODO: if we can authenticate that a particular User pushed the
        # button, use their name instead of None, so they'll be informed of
        # the results.
        s = SourceStamp(branch=branch, revision=revision)
        req = BuildRequest(r, s, builderName=self.builder_status.getName())
        try:
            self.builder_control.requestBuildSoon(req)
        except interfaces.NoSlaveError:
            # TODO: tell the web user that their request could not be
            # honored
            pass
        # send the user back to the builder page
        return Redirect(".")
Exemplo n.º 19
0
    def installApplication(self, application):
        """Install the WSGI application into the Twisted site.

        It's installed as a child with path "MAAS". This matches the default
        front-end configuration (i.e. Apache) so that there's no need to force
        script names.
        """
        # Setup resources to process paths that twisted handles.
        metadata = Resource()
        metadata.putChild(b'status', StatusHandlerResource(self.status_worker))

        maas = Resource()
        maas.putChild(b'metadata', metadata)
        maas.putChild(b'static', File(settings.STATIC_ROOT))
        maas.putChild(
            b'ws',
            WebSocketsResource(lookupProtocolForFactory(self.websocket)))

        root = Resource()
        root.putChild(b'', Redirect(b"MAAS/"))
        root.putChild(b'MAAS', maas)

        # Setup the resources to process paths that django handles.
        underlay_maas = ResourceOverlay(
            WSGIResource(reactor, self.threadpool, application))
        underlay_root = Resource()
        underlay_root.putChild(b'MAAS', underlay_maas)
        underlay_site = Site(underlay_root,
                             logFormatter=reducedWebLogFormatter)
        underlay_site.requestFactory = CleanPathRequest

        # Setup the main resource as the twisted handler and the underlay
        # resource as the django handler.
        self.site.resource = root
        self.site.underlay = underlay_site
Exemplo n.º 20
0
 def rebuild(self, req):
     b = self.build_status
     bc = self.builder_control
     builder_name = b.getBuilder().getName()
     log.msg("web rebuild of build %s:%s" % (builder_name, b.getNumber()))
     name = req.args.get("username", ["<unknown>"])[0]
     comments = req.args.get("comments", ["<no reason specified>"])[0]
     reason = ("The web-page 'rebuild' button was pressed by "
               "'%s': %s\n" % (name, comments))
     if not bc or not b.isFinished():
         log.msg("could not rebuild: bc=%s, isFinished=%s" %
                 (bc, b.isFinished()))
         # TODO: indicate an error
     else:
         bc.resubmitBuild(b, reason)
     # we're at
     # http://localhost:8080/builders/NAME/builds/5/rebuild?[args]
     # Where should we send them?
     #
     # Ideally it would be to the per-build page that they just started,
     # but we don't know the build number for it yet (besides, it might
     # have to wait for a current build to finish). The next-most
     # preferred place is somewhere that the user can see tangible
     # evidence of their build starting (or to see the reason that it
     # didn't start). This could either be the Builder page, or the
     # waterfall.
     #r = Redirect("../../../..") # this takes us back to the welcome page
     #r = Redirect("../../../../waterfall") # or the Waterfall
     #r = Redirect("../../../../waterfall?show=%s" % builder_name)
     r = Redirect("../..")  # the Builder's page
     d = defer.Deferred()
     reactor.callLater(1, d.callback, r)
     return DeferredResource(d)
Exemplo n.º 21
0
 def getChild(self, path, req):
     if path == '':
         return Redirect('..')
     parent = req.site.buildbot_service
     if path in parent.slaves:
         return JhBuildbotResource(path, req)
     return HtmlResource.getChild(self, path, req)
Exemplo n.º 22
0
 def setupUsualPages(self, numbuilds, num_events, num_events_max):
     #self.putChild("", IndexOrWaterfallRedirection())
     self.putChild(
         "waterfall",
         WaterfallStatusResource(num_events=num_events,
                                 num_events_max=num_events_max))
     self.putChild("grid", GridStatusResource())
     self.putChild(
         "console",
         ConsoleStatusResource(orderByTime=self.orderConsoleByTime))
     self.putChild("tgrid", TransposedGridStatusResource())
     self.putChild(
         "builders",
         BuildersResource(numbuilds=numbuilds))  # has builds/steps/logs
     self.putChild("one_box_per_builder", Redirect("builders"))
     self.putChild("changes", ChangesResource())
     self.putChild("buildslaves", BuildSlavesResource())
     self.putChild("buildstatus", BuildStatusStatusResource())
     self.putChild("one_line_per_build",
                   OneLinePerBuild(numbuilds=numbuilds))
     self.putChild("about", AboutBuildbot())
     self.putChild("authfail", AuthFailResource())
     self.putChild("authzfail", AuthzFailResource())
     self.putChild("users", UsersResource())
     self.putChild("login", LoginResource())
     self.putChild("logout", LogoutResource())
Exemplo n.º 23
0
 def _delayedRender(self, request):
     if not is_authenticated(request):
         result = Redirect(b'/login').render(request)
     else:
         result = content.encode()
     request.write(result)
     request.finish()
Exemplo n.º 24
0
 def render_POST(self, request):
     if request.args[b'login'][0] == b'admin' and \
             request.args[b'password'][0] == b'secret':
         session_id = bytes(uuid.uuid4().hex, 'ascii')
         SESSIONS[session_id] = True
         request.setHeader(b'set-cookie', b'_uctest_auth=' + session_id)
     return Redirect(b'/').render(request)
Exemplo n.º 25
0
 def __init__(self, *args, **kwargs):
     Resource.__init__(self, *args, **kwargs)
     self.putChild('', Redirect('static/index.html'))
     self.putChild(
         'static',
         File(pkg_resources.resource_filename('babblelicious', 'static')))
     self.putChild('resource', SSEResource(subscribers))
Exemplo n.º 26
0
 def render_POST(self, request):
     if (request.args[b'login'][0] == b'admin' and
             request.args[b'password'][0] == b'secret'):
         request.setHeader(b'set-cookie', b'_auth=yes')
     elif request.received_cookies.get(b'_auth'):
         request.setHeader(b'set-cookie', b'_auth=')
     return Redirect(self.url.encode('utf-8')).render(request)
Exemplo n.º 27
0
    def getChildWithDefault(self, name: bytes,
                            request: TwistedRequest) -> IResource:
        try:
            nameStr = name.decode()
        except UnicodeDecodeError:
            return ClientErrorResource('Path is not valid UTF-8')

        # Take one step along the prescribed path.
        rightPath = self.rightPath
        if rightPath:
            if rightPath[0] != nameStr:
                return AccessDeniedResource('You have strayed from the path')
            rightPath = rightPath[1:]

        dirPath = self.dirPath
        subDirPath = dirPath.child(nameStr)
        if subDirPath.isdir():
            return SandboxedResource(subDirPath, rightPath)
        for ext, contentClass in (('.gz', GzippedArtifact), ('.zip',
                                                             ZippedArtifact)):
            filePath = dirPath.child(nameStr + ext)
            if filePath.isfile():
                return contentClass(filePath)

        # Redirect to non-sandboxed URL.
        # It is possible the user edited the URL to request a different
        # artifact or different presentation of the artifact that doesn't
        # exist in the sandbox.
        return Redirect(b'/'.join([b'..'] * (len(request.prepath) - 1) +
                                  request.prepath[2:]))
Exemplo n.º 28
0
    def stop(self, req, auth_ok=False):
        # check if this is allowed
        if not auth_ok:
            return StopBuildActionResource(self.build_status)

        b = self.build_status
        log.msg("web stopBuild of build %s:%s" %
                (b.getBuilder().getName(), b.getNumber()))

        name = self.getAuthz(req).getUsernameFull(req)
        comments = _get_comments_from_request(req)
        # html-quote both the username and comments, just to be safe
        reason = ("The web-page 'stop build' button was pressed by "
                  "'%s': %s\n" % (html.escape(name), html.escape(comments)))

        c = interfaces.IControl(self.getBuildmaster(req))
        bldrc = c.getBuilder(self.build_status.getBuilder().getName())
        if bldrc:
            bldc = bldrc.getBuild(self.build_status.getNumber())
            if bldc:
                bldc.stopBuild(reason)

        # we're at http://localhost:8080/svn-hello/builds/5/stop?[args] and
        # we want to go to: http://localhost:8080/svn-hello
        r = Redirect(path_to_builder(req, self.build_status.getBuilder()))
        d = defer.Deferred()
        reactor.callLater(1, d.callback, r)
        return DeferredResource(d)
Exemplo n.º 29
0
    def getChild(self, path, request):
        s = request.getSession()
        if s is None:
            return request.setupSession()

        if path == INIT_PERSPECTIVE:

            def loginMethod(identity, password, perspective=None):
                idfr = self.service.authorizer.getIdentityRequest(identity)
                idfr.addCallback(lambda ident: ident.verifyPlainPassword(
                    password
                ).addCallback(lambda ign: ident.requestPerspectiveForService(
                    self.service.serviceName
                )).addCallback(lambda psp: s.setClientForService(
                    ident, psp, self.authResourceFactory(psp), self.service)))

                def loginFailure(f):
                    if f.trap(Unauthorized):
                        raise fm.FormException(str(f.value))
                    raise f

                idfr.addErrback(loginFailure)
                return idfr

            return form.FormProcessor(loginSignature.method(loginMethod),
                                      callback=self.callback)
        elif path == DESTROY_PERSPECTIVE:
            s.setClientForService(None, None, None, self.service)
            return Redirect(".")
        else:
            sc = s.clientForService(self.service)
            if sc:
                return getResource(sc, path, request)
            return getResource(self.noAuthResource, path, request)
Exemplo n.º 30
0
    def getChild(self, path, request):
        s = request.getSession()
        if s is None:
            return request.setupSession()
        if path == INIT_PERSPECTIVE:

            def loginSuccess(result):
                interface, avatarAspect, logout = result
                s.setResourceForPortal(avatarAspect, self.portal, logout)

            def triggerLogin(username, password, submit=None):
                return self.portal.login(
                    UsernamePassword(username, password), None,
                    IResource).addCallback(loginSuccess).addErrback(
                        self._ebFilter)

            return form.FormProcessor(newLoginSignature.method(triggerLogin),
                                      callback=self.callback,
                                      errback=self.errback)
        elif path == DESTROY_PERSPECTIVE:
            s.portalLogout(self.portal)
            return Redirect(".")
        else:
            r = s.resourceForPortal(self.portal)
            if r:
                ## Delegate our getChild to the resource our portal says is the right one.
                return getResource(r[0], path, request)
            else:
                return DeferredResource(
                    self.portal.login(Anonymous(), None, IResource).
                    addCallback(
                        lambda (interface, avatarAspect, logout): getResource(
                            s.setResourceForPortal(avatarAspect, self.portal,
                                                   logout), path, request)))