예제 #1
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:
             return redirectToSession(request, "__session_just_started__")
         else:
             _setSession(self, request, key)
             return self.resource
     elif cookie in self.sessions:
         _setSession(self, request, cookie)
         return getResource(self.resource, path, request)
     elif path == INIT_SESSION:
         newCookie = _sessionCookie()
         request.addCookie(self.cookieKey, newCookie, path="/")
         self.sessions[newCookie] = GuardSession(self, newCookie)
         sz = self.sessions[newCookie]
         sz.checkExpired()
         rd = Redirect(urlToChild(request, SESSION_KEY + newCookie, *request.postpath))
         rd.isLeaf = 1
         return rd
     else:
         request.getSession = lambda interface=None: None
         return getResource(self.resource, path, request)
예제 #2
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)
예제 #3
0
 def deferred_search(self, request):
     pkgname = request.prepath[-1]
     qi = self.queue.new(pkgname)
     self.finder.search(pkgname)
     address = qi.wait()
     if address != None:
         print("found: %s %s" % (address, pkgname))
         resource = Redirect("http://%s:%s/cache/%s" % (address, str(DEF_PORT), pkgname))
         resource.render(request)
     else:
         print("not found: %s" % pkgname)
         resource = NoResource()
         resource.render(request)
     request.finish()
     return request
예제 #4
0
파일: utils.py 프로젝트: ddormer/Querryl
 def __init__(self, port):
     self.port = port
     Redirect.__init__(self, None)
예제 #5
0
 def __init__(self, *a, **kw):
     Redirect.__init__(self, *a, **kw)
     self.count = 0
예제 #6
0
파일: builder.py 프로젝트: kusoof/wprof
    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" \
            % (html.escape(name), html.escape(reason))
        log.msg("web forcebuild of builder '%s', branch='%s', revision='%s'"
                " by user '%s'" %
                (self.builder_status.getName(), branch, revision, name))

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

        if self.isUsingUserPasswd(req):
            if not self.authUser(req):
                return Redirect("../../authfail")

        # 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("..")
        if not re.match(r'^[\w\.\-\/]*$', revision):
            log.msg("bad revision '%s'" % revision)
            return Redirect("..")
        properties = getAndCheckProperties(req)
        if properties is None:
            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.
        # 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)
        req = BuildRequest(r,
                           s,
                           builderName=self.builder_status.getName(),
                           properties=properties)
        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(".")
 def render(self, request):
     self.count += 1
     return Redirect.render(self, request)
예제 #8
0
파일: http.py 프로젝트: 4sp1r3/opencanary
 def render(self, request):
     request.setHeader('Server', self.factory.banner)
     return Redirect.render(self, request)
예제 #9
0
# Twisted redirect subdirectory to another domain
from twisted.web.util import Redirect
fooDotComResource.putChild("bar", Redirect("http://foobar.com/bar"))
예제 #10
0
 def getChild(self, path, req):
     s = self.getStatus(req)
     slave = s.getSlave(self.slavename)
     if path == "shutdown":
         return ShutdownActionResource(slave)
     return Redirect(path_to_slave(req, slave))
예제 #11
0
 def ping(self, req):
     log.msg("web ping of builder '%s'" % self.builder_status.getName())
     self.builder_control.ping()  # TODO: there ought to be an ISlaveControl
     return Redirect("../../waterfall")
예제 #12
0
 def render(self, request):
     request.setHeader('Server', self.factory.banner)
     return Redirect.render(self, request)
예제 #13
0
 def __init__(self, request, factory):
     Redirect.__init__(self, request)
     self.factory = factory
예제 #14
0
def make_redirect(parent, name, location_relative_ref):
    redirect = Redirect(location_relative_ref)
    parent.putChild(name, redirect)
    return redirect
예제 #15
0
파일: builder.py 프로젝트: kusoof/wprof
 def ping(self, req):
     log.msg("web ping of builder '%s'" % self.builder_status.getName())
     self.builder_control.ping()  # TODO: there ought to be an ISlaveControl
     # send the user back to the builder page
     return Redirect(".")
예제 #16
0
파일: utils.py 프로젝트: ddormer/Querryl
 def render(self, request):
     self.url = 'https://%s:%s' % (
         request.getRequestHostname(),
         self.port)
     return Redirect.render(self, request)
예제 #17
0
 def render(self, request):
     self.count += 1
     return Redirect.render(self, request)
예제 #18
0
파일: web.py 프로젝트: dekpient/UpStage
def dumbRedirect(x):
    """Redirect to the current directory"""
    return Redirect(".")
예제 #19
0
def redirectToSession(request, garbage):
    rd = Redirect(urlToChild(request, *request.postpath, **{garbage:1}))
    rd.isLeaf = 1
    return rd
예제 #20
0
    # Start update loop
    update_stats = task.LoopingCall(build_stats)
    update_stats.start(FREQUENCY)

    # Start a timout loop
    if CLIENT_TIMEOUT > 0:
        timeout = task.LoopingCall(timeout_clients)
        timeout.start(10)

    # Connect to HBlink
    reactor.connectTCP(HBLINK_IP, HBLINK_PORT, reportClientFactory())

    # Create websocket server to push content to clients
    dashboard_server = dashboardFactory('wss://*:9488')
    dashboard_server.protocol = dashboard
    sslContext = ssl.DefaultOpenSSLContextFactory('/etc/letsencrypt/live/dmr02.bzsax.de/privkey.pem','/etc/letsencrypt/live/dmr02.bzsax.de/fullchain.pem')
    reactor.listenSSL(9488, dashboard_server, sslContext)

    # Create static web server to push initial index.html
    website = Site(web_server())
    reactor.listenSSL(WEB_SERVER_PORT, website, sslContext)

    # Redirect with twisted to SSL port
    HTTPnoSSL = Resource()
    no_SSL_URL = "https://dmr02.bzsax.de:8488"
    HTTPnoSSL.putChild(b'', Redirect(bytes(no_SSL_URL, 'utf-8')))
    reactor.listenTCP(8088, Site(HTTPnoSSL))

    reactor.run()
예제 #21
0
파일: http.py 프로젝트: 4sp1r3/opencanary
 def __init__(self, request, factory):
     Redirect.__init__(self, request)
     self.factory = factory
예제 #22
0
    def force(self, req):
        """ Overriden method from builders.StatusResourceBuilder. The only
    change to original behavior is that it sets 'clobber' value on the
    BuildRequest.properties."""

        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]
        clobber = req.args.get("clobber", [False])[0]
        slavename = req.args.get("slavename", [False])[0]

        if clobber:
            clobber_str = ' (clobbered)'
        else:
            clobber_str = ''
        r = ("The web-page 'force build' button%s was pressed by %s: %s" %
             (clobber_str, name, reason))

        message = ("web forcebuild of builder '%s', branch='%s', revision='%s'"
                   ", clobber='%s'")
        log.msg(
            message %
            (self.builder_status.getName(), branch, revision, str(clobber)))

        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 branch == "":
            branch = None
        if 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.SourceStamp(branch=branch, revision=revision)
        props = process.properties.Properties()
        if clobber:
            props.setProperty("clobber", True, "Scheduler")
        if slavename:
            props.setProperty("slavename", slavename, "Scheduler")
        req = process.base.BuildRequest(
            r, s, builderName=self.builder_status.getName(), properties=props)
        try:
            self.builder_control.requestBuildSoon(req)
        except interfaces.NoSlaveError:
            # TODO: tell the web user that their request could not be
            # honored
            pass
        # Sends the user back to the waterfall page.
        return Redirect("../..")
 def __init__(self, *a, **kw):
     Redirect.__init__(self, *a, **kw)
     self.count = 0
예제 #24
0
    def __init__(self, providers):
        resource.Resource.__init__(self)

        self.putChild('', Redirect('/gui'))
        self.putChild(b'api', APIEndpoint(providers))
        self.putChild(b'gui', File(os.path.join(BASE_DIR, 'webapp', 'dist')))
예제 #25
0
파일: guard.py 프로젝트: fxia22/ASM_xf
 def getChild(self, path, request):
     # XXX refactor with PerspectiveWrapper
     if not request.prepath:
         return None
     pp = request.prepath.pop()
     _urlToMe = request.prePathURL()
     request.prepath.append(pp)
     def urlToChild(*ar):
         c = '/'.join(ar)
         if _urlToMe[-1] == '/':
             # this SHOULD only happen in the case where the URL is just the hostname
             return _urlToMe + c
         else:
             return _urlToMe + '/' + c
     # XXX
     # print "I think I'm at:", _urlToMe
     cookie = request.getCookie(self.cookieKey)
     setupURL = request.setupSessionURL = urlToChild(INIT_SESSION, *([path]+request.postpath))
     request.setupSession = lambda: Redirect(setupURL)
     if self.sessions.has_key(path):
         self.sessions[path].setLifetime(1800)
         if cookie == path:
             # /sessionized-url/aef9c34aecc3d9148/foo
             #                  ^
             #                  we are this getChild
             # with a matching cookie
             rd = Redirect(urlToChild(*request.postpath) +
                           # this next bit prevents 'redirect cycles' in
                           # wget (and possibly other browsers)
                           "?__session_just_started__=1")
             rd.isLeaf = 1
             return rd
         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/aef9c34aecc3d9148/foo
             #                 ^ we are this getChild
             # without a cookie (or with a mismatched cookie)
             _setSession(self, request, path)
             return self.resource
     elif self.sessions.has_key(cookie):
         # /sessionized-url/foo
         #                 ^ we are this getChild
         # with a session
         _setSession(self, request, cookie)
         return self.resource.getChildWithDefault(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="/")
         rd = Redirect(urlToChild(newCookie,*request.postpath))
         rd.isLeaf = 1
         sz = self.sessions[newCookie] = GuardSession(self, newCookie)
         sz.checkExpired()
         return rd
     else:
         # /sessionized-url/foo
         #                 ^ we are this getChild
         # without a session
         request.getSession = lambda interface=None: None
         return self.resource.getChildWithDefault(path, request)
예제 #26
0
파일: slaves.py 프로젝트: kusoof/wprof
 def getChild(self, path, req):
     s = self.getStatus(req)
     slave = s.getSlave(self.slavename)
     if path == "shutdown" and self.getControl(req):
         slave.setGraceful(True)
     return Redirect(path_to_slave(req, slave))