예제 #1
0
    def cmd_pass(self, line):
        'specify password'
        if len(line) < 2:
            pw = ''
        else:
            pw = line[1]

        self.password = pw
        i = self.userid.find('@')
        if i == -1:
            if self.server.limiter.check_limit(self):
                self.respond('230 Login successful.')
                self.authorized = 1
                self.anonymous = 1
                self.log_info('Successful login.')
            else:
                self.respond('421 User limit reached. Closing connection.')
                self.close_when_done()
        else:
            path = self.userid[i + 1:]
            self.userid = self.userid[:i]
            self.anonymous = None
            response = make_response(self, self.pass_completion,
                                     self._join_paths('/', path))
            request = FTPRequest(path, 'PASS', self, response)
            handle(self.module, request, response)
예제 #2
0
    def run(self):
        # wait until the zhttp_server exist in socket_map
        # because TimerService has to be started after the Zope HTTPServer
        from asyncore import socket_map
        ip = port = ''
        while 1:
            time.sleep(5)
            for k, v in socket_map.items():
                if hasattr(v, 'addr'):
                    # see Zope/lib/python/App/ApplicationManager.py: def getServers(self)
                    type = str(getattr(v, '__class__', 'unknown'))
                    if type == 'ZServer.HTTPServer.zhttp_server':
                        ip, port = v.addr
                        break
            if port:
                break

        if ip == '0.0.0.0':
            ip = socket.gethostbyname(socket.gethostname())

        # To be very sure, try to connect to the HTTPServer
        # and only start after we are able to connect and got a response
        s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        s.settimeout(None)
        while 1:
            try:
                s.connect((ip, port))
            except socket.error:
                time.sleep(5)
                continue
            s.send('GET / HTTP/1.1\r\n\r\n')
            s.recv(4096)  # blocks until a response is received
            break
        s.close()

        module = self.module
        interval = self.interval

        # minutes = time.gmtime(time.time()[4], seconds = time.gmtime(time.time()[5]
        # max interval is therefore 59*60 + 59 = 208919 seconds

        wait = ((time.gmtime(time.time())[4] * 60) +
                time.gmtime(time.time())[5]) % interval
        sleep = interval - wait

        if sleep > 0:
            time.sleep(sleep)

        LOG('ZServer', INFO, 'Timerserver ready, starting timer services.')

        while 1:
            time.sleep(interval)
            # send message to zope
            try:
                out = StringIO()
                err = StringIO()
                response = TimerResponse(out, err)
                handle(module, TimerRequest(response, interval), response)
            except:
                pass
예제 #3
0
 def cmd_pass(self, line):
     'specify password'
     if len(line) < 2:
         pw = ''
     else:
         pw = line[1]
     self.password=pw
     i=self.userid.find('@')
     if i ==-1:
         if self.server.limiter.check_limit(self):
             self.respond ('230 Login successful.')
             self.authorized = 1
             self.anonymous = 1
             self.log_info ('Successful login.')
         else:
             self.respond('421 User limit reached. Closing connection.')
             self.close_when_done()
     else:
         path=self.userid[i+1:]
         self.userid=self.userid[:i]
         self.anonymous=None
         response=make_response(self, self.pass_completion,
                 self._join_paths('/',path))
         request=FTPRequest(path,'PASS',self,response)
         handle(self.module,request,response)
예제 #4
0
    def run(self):
        # wait until the zhttp_server exist in socket_map
        # because TimerService has to be started after the Zope HTTPServer
        from asyncore import socket_map
        ip = port = ''
        while 1:
            time.sleep(5)
            for k, v in socket_map.items():
                if hasattr(v, 'addr'):
                        # see Zope/lib/python/App/ApplicationManager.py: def getServers(self)
                        type = str(getattr(v, '__class__', 'unknown'))
                        if type == 'ZServer.HTTPServer.zhttp_server':
                            ip, port = v.addr
                            break
            if port:
                break

        if ip == '0.0.0.0':
          ip = socket.gethostbyname(socket.gethostname())

        # To be very sure, try to connect to the HTTPServer
        # and only start after we are able to connect and got a response
        s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        s.settimeout(None)
        while 1:
            try:
                s.connect((ip, port))
            except socket.error:
                time.sleep(5)
                continue
            s.send('GET / HTTP/1.1\r\n\r\n')
            s.recv(4096) # blocks until a response is received
            break
        s.close()

        module = self.module
        interval = self.interval

        # minutes = time.gmtime(time.time()[4], seconds = time.gmtime(time.time()[5]
        # max interval is therefore 59*60 + 59 = 208919 seconds

        wait = ((time.gmtime(time.time())[4] * 60) + time.gmtime(time.time())[5]) % interval
        sleep = interval - wait

        if sleep > 0:
            time.sleep(sleep)

        LOG('ZServer', INFO, 'Timerserver ready, starting timer services.')

        while 1:
            time.sleep(interval)
            # send message to zope
            try:
                out = StringIO()
                err = StringIO()
                response = TimerResponse(out, err)
                handle(module, TimerRequest(response, interval), response)
            except:
                pass
예제 #5
0
 def cmd_mdtm(self, line):
     'show last modification time of file'
     if len (line) != 2:
         self.command.not_understood (' '.join(line))
         return
     response=make_response(self, self.mdtm_completion)
     request=FTPRequest(line[1],'MDTM',self,response)
     handle(self.module,request,response)
예제 #6
0
 def cmd_mkd(self, line):
     if len(line) != 2:
         self.command.not_understood(' '.join(line))
         return
     path, id = os.path.split(line[1])
     response = make_response(self, self.mkd_completion)
     request = FTPRequest(path, ('MKD', id), self, response)
     handle(self.module, request, response)
예제 #7
0
 def cmd_size(self, line):
     'return size of file'
     if len (line) != 2:
         self.command.not_understood (' '.join(line))
         return
     response=make_response(self, self.size_completion)
     request=FTPRequest(line[1],'SIZE',self,response)
     handle(self.module,request,response)
예제 #8
0
 def cmd_size(self, line):
     'return size of file'
     if len(line) != 2:
         self.command.not_understood(' '.join(line))
         return
     response = make_response(self, self.size_completion)
     request = FTPRequest(line[1], 'SIZE', self, response)
     handle(self.module, request, response)
예제 #9
0
 def cmd_mdtm(self, line):
     'show last modification time of file'
     if len(line) != 2:
         self.command.not_understood(' '.join(line))
         return
     response = make_response(self, self.mdtm_completion)
     request = FTPRequest(line[1], 'MDTM', self, response)
     handle(self.module, request, response)
예제 #10
0
 def cmd_mkd(self, line):
     if len (line) != 2:
         self.command.not_understood (' '.join (line))
         return
     path,id=os.path.split(line[1])
     response=make_response(self, self.mkd_completion)
     request=FTPRequest(path,('MKD',id),self,response)
     handle(self.module,request,response)
예제 #11
0
 def send_response(self):
     # create an output pipe by passing request to ZPublisher,
     # and requesting a callback of self.log with the module
     # name and PATH_INFO as an argument.
     self.done = 1
     response = PCGIResponse(stdout=PCGIPipe(self), stderr=StringIO())
     request = HTTPRequest(self.data, self.env, response)
     handle(self.server.module, request, response)
예제 #12
0
파일: FTPServer.py 프로젝트: py361/ZServer
 def listdir(self, path, long=0):
     response = make_response(self, self.listdir_completion, long)
     request = FTPRequest(path,
                          'LST',
                          self,
                          response,
                          globbing=self.globbing,
                          recursive=self.recursive)
     handle(self.module, request, response)
예제 #13
0
    def next(self):
        if self._futures:
            IFutures(self._zrequest).update(self._futures)
            self._futures = {}  # mark consumed to raise StopIteration

            from ZServer.PubCore import handle
            handle('Zope2', self._zrequest, self._zrequest.response)
        else:
            raise StopIteration
예제 #14
0
 def cmd_rnto(self, line):
     if len(line) != 2:
         self.command_not_understood(' '.join(line))
         return
     pathf, idf = os.path.split(self.fromfile)
     patht, idt = os.path.split(line[1])
     response = make_response(self, self.rnto_completion)
     request = FTPRequest(pathf, ('RNTO', idf, idt), self, response)
     handle(self.module, request, response)
예제 #15
0
    def next(self):
        if self._futures:
            IFutures(self._zrequest).update(self._futures)
            self._futures = {}  # mark consumed to raise StopIteration

            from ZServer.PubCore import handle
            handle('Zope2', self._zrequest, self._zrequest.response)
        else:
            raise StopIteration
예제 #16
0
 def cmd_rnto (self, line):
     if len (line) != 2:
         self.command_not_understood (' '.join(line))
         return
     pathf,idf=os.path.split(self.fromfile)
     patht,idt=os.path.split(line[1])
     response=make_response(self, self.rnto_completion)
     request=FTPRequest(pathf,('RNTO',idf,idt),self,response)
     handle(self.module,request,response)
예제 #17
0
 def cmd_rmd(self, line):
     # XXX should object be checked to see if it's folderish
     #     before we allow it to be RMD'd?
     if len(line) != 2:
         self.command.not_understood(' '.join(line))
         return
     path, id = os.path.split(line[1])
     response = make_response(self, self.rmd_completion)
     request = FTPRequest(path, ('RMD', id), self, response)
     handle(self.module, request, response)
예제 #18
0
 def cmd_rnfr (self, line):
     'rename from'
     if len (line) != 2:
         self.command_not_understood (' '.join(line))
     else:
         self.fromfile = line[1]
         pathf,idf=os.path.split(self.fromfile)
         response=make_response(self, self.rnfr_completion)
         request=FTPRequest(pathf,('RNFR',idf),self,response)
         handle(self.module,request,response)
예제 #19
0
 def cmd_rnfr(self, line):
     'rename from'
     if len(line) != 2:
         self.command_not_understood(' '.join(line))
     else:
         self.fromfile = line[1]
         pathf, idf = os.path.split(self.fromfile)
         response = make_response(self, self.rnfr_completion)
         request = FTPRequest(pathf, ('RNFR', idf), self, response)
         handle(self.module, request, response)
예제 #20
0
파일: FTPServer.py 프로젝트: py361/ZServer
 def stor_callback(self, path, data, size):
     'callback to do the STOR, after we have the input'
     response = make_response(self, self.stor_completion)
     request = FTPRequest(path,
                          'STOR',
                          self,
                          response,
                          stdin=data,
                          size=size)
     handle(self.module, request, response)
예제 #21
0
 def work(self):
     "try to handle a request"
     if not self.working:
         if self.queue and not self.no_more_requests:
             self.working = 1
             try:
                 module_name, request, response = self.queue.pop(0)
             except Exception:
                 return
             handle(module_name, request, response)
예제 #22
0
 def send_response(self):
     """
     Create output pipes, request, and response objects.  Give them
     to ZPublisher for processing.
     """
     response = FCGIResponse(stdout=FCGIPipe(self, FCGI_STDOUT),
                             stderr=StringIO())
     response.setChannel(self)
     request = HTTPRequest(self.stdin, self.env, response)
     handle(self.server.module, request, response)
예제 #23
0
 def send_response(self):
     """
     Create output pipes, request, and response objects.  Give them
     to ZPublisher for processing.
     """
     response = FCGIResponse(stdout=FCGIPipe(self, FCGI_STDOUT),
                             stderr=StringIO())
     response.setChannel(self)
     request = HTTPRequest(self.stdin, self.env, response)
     handle(self.server.module, request, response)
예제 #24
0
파일: HTTPServer.py 프로젝트: py361/ZServer
 def work(self):
     "try to handle a request"
     if not self.working:
         if self.queue and not self.no_more_requests:
             self.working = 1
             try:
                 module_name, request, response = self.queue.pop(0)
             except Exception:
                 return
             handle(module_name, request, response)
예제 #25
0
 def cmd_rmd(self, line):
     # XXX should object be checked to see if it's folderish
     #     before we allow it to be RMD'd?
     if len (line) != 2:
         self.command.not_understood (' '.join (line))
         return
     path,id=os.path.split(line[1])
     response=make_response(self, self.rmd_completion)
     request=FTPRequest(path,('RMD',id),self,response)
     handle(self.module,request,response)
예제 #26
0
 def cmd_retr(self, line):
     if len(line) < 2:
         self.command_not_understood(' '.join(line))
         return
     response = make_response(self, self.retr_completion, line[1])
     self._response_producers = response.stdout._producers
     request = FTPRequest(line[1], 'RETR', self, response)
     # Support download restarts if possible.
     if self.restart_position > 0:
         request.environ['HTTP_RANGE'] = 'bytes=%d-' % self.restart_position
     handle(self.module, request, response)
예제 #27
0
 def cmd_retr(self,line):
     if len(line) < 2:
         self.command_not_understood (' '.join(line))
         return
     response=make_response(self, self.retr_completion, line[1])
     self._response_producers = response.stdout._producers
     request=FTPRequest(line[1],'RETR',self,response)
     # Support download restarts if possible.
     if self.restart_position > 0:
         request.environ['HTTP_RANGE'] = 'bytes=%d-' % self.restart_position
     handle(self.module,request,response)
예제 #28
0
 def cmd_cwd (self, line):
     'change working directory'
     response=make_response(self, self.cwd_completion,
                            self._join_paths(self.path,line[1]))
     request=FTPRequest(line[1],'CWD',self,response)
     handle(self.module,request,response)
예제 #29
0
 def cmd_cwd(self, line):
     'change working directory'
     response = make_response(self, self.cwd_completion,
                              self._join_paths(self.path, line[1]))
     request = FTPRequest(line[1], 'CWD', self, response)
     handle(self.module, request, response)
예제 #30
0
    def run(self):
        try:
            zopewsgi = sys.modules['Products.ERP5.bin.zopewsgi']
        except KeyError:
            # wait until the zhttp_server exist in socket_map
            # because TimerService has to be started after the Zope HTTPServer
            from asyncore import socket_map
            ip = port = ''
            while 1:
                time.sleep(5)
                for k, v in socket_map.items():
                    if hasattr(v, 'addr'):
                        # see Zope/lib/python/App/ApplicationManager.py: def getServers(self)
                        type = str(getattr(v, '__class__', 'unknown'))
                        if type == 'ZServer.HTTPServer.zhttp_server':
                            ip, port = v.addr
                            break
                if port:
                    break
            from ZServer.PubCore import handle
        else:
            while 1:
                time.sleep(5)
                try:
                    server = zopewsgi.server
                    break
                except AttributeError:
                    pass

            ip, port = server.addr
            start_response = lambda *_: None

            class handle(object):
                def __init__(self, module_name, request, response):
                    self.service = partial(zopewsgi.publish_module,
                                           request.environ,
                                           start_response,
                                           _module_name=module_name,
                                           _request=request,
                                           _response=response)
                    server.add_task(self)

                def cancel(self):
                    pass

        if ip == '0.0.0.0':
            ip = socket.gethostbyname(socket.gethostname())

        # To be very sure, try to connect to the HTTPServer
        # and only start after we are able to connect and got a response
        s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        s.settimeout(None)
        while 1:
            try:
                s.connect((ip, port))
            except socket.error:
                time.sleep(5)
                continue
            s.send(b'GET / HTTP/1.1\r\n\r\n')
            s.recv(4096)  # blocks until a response is received
            break
        s.close()

        module = self.module
        interval = self.interval

        logger.info('Service ready.')

        while 1:
            time.sleep(interval)
            # send message to zope
            try:
                out = StringIO()
                err = StringIO()
                response = TimerResponse(out, err)
                handle(module, TimerRequest(response, interval), response)
            except Exception:
                logger.warn("Ignoring exception in run loop", exc_info=True)
예제 #31
0
 def stor_callback(self, path, data, size):
     'callback to do the STOR, after we have the input'
     response = make_response(self, self.stor_completion)
     request = FTPRequest(path, 'STOR', self, response,
                          stdin=data, size=size)
     handle(self.module, request, response)
예제 #32
0
 def listdir(self, path, long=0):
     response = make_response(self, self.listdir_completion, long)
     request = FTPRequest(path, 'LST', self, response,
                          globbing=self.globbing,
                          recursive=self.recursive)
     handle(self.module, request, response)