def __init__(self, directory, uri, server_conf, dav_conf, verbose=False): """Simply call parent constructor""" FilesystemHandler.__init__(self, directory, uri, verbose) self.root = directory self.daemon_conf = server_conf.daemon_conf self.chroot_exceptions = self.daemon_conf['chroot_exceptions'] self.chmod_exceptions = self.daemon_conf['chmod_exceptions']
def webdav_server(): class DummyConfigDAV: def getboolean(self, name): return False class DummyConfig: DAV = DummyConfigDAV() host = 'localhost' port = 4242 handler = DAVAuthHandler handler._config = DummyConfig() handler.DO_AUTH = False handler.IFACE_CLASS = FilesystemHandler('/tmp', 'http://%s:%d/' % (host, port)) handler.IFACE_CLASS.baseurl = '' httpd = HTTPServer((host, port), handler) httpd.serve_forever()
def runserver( port = 8008, host='localhost', directory='/tmp', verbose = False, noauth = False, user = '', password = '', handler = DAVAuthHandler, server = ThreadedHTTPServer): directory = directory.strip() directory = directory.rstrip('/') host = host.strip() if not os.path.isdir(directory): os.makedirs(directory) # log.error('%s is not a valid directory!' % directory) # return sys.exit(233) # basic checks against wrong hosts if host.find('/') != -1 or host.find(':') != -1: log.error('Malformed host %s' % host) return sys.exit(233) # no root directory if directory == '/': log.error('Root directory not allowed!') sys.exit(233) # dispatch directory and host to the filesystem handler # This handler is responsible from where to take the data handler.IFACE_CLASS = FilesystemHandler(directory, 'http://%s:%s/' % (host, port), verbose ) # put some extra vars handler.verbose = verbose if noauth: log.warning('Authentication disabled!') handler.DO_AUTH = False log.info('Serving data from %s' % directory) if handler._config.DAV.getboolean('lockemulation') is False: log.info('Deactivated LOCK, UNLOCK (WebDAV level 2) support') handler.IFACE_CLASS.mimecheck = True if handler._config.DAV.getboolean('mimecheck') is False: handler.IFACE_CLASS.mimecheck = False log.info('Disabled mimetype sniffing (All files will have type application/octet-stream)') if handler._config.DAV.baseurl: log.info('Using %s as base url for PROPFIND requests' % handler._config.DAV.baseurl) handler.IFACE_CLASS.baseurl = handler._config.DAV.baseurl # initialize server on specified port runner = server( (host, port), handler ) print(('Listening on %s (%i)' % (host, port))) try: runner.serve_forever() except KeyboardInterrupt: log.info('Killed by user')
def get_data(self, uri, range=None): """return the content of an object""" reply = FilesystemHandler.get_data(self, uri, range) logger.info("returning get_data reply: %s" % reply) return reply