示例#1
0
 def authorize (self, channel, username, password):
     if username in ('ftp', 'anonymous'):
         channel.persona = -1, -1
         channel.read_only = 1
         return 1, 'Ok.', filesys.os_filesystem (self.root)
     else:
         return 0, 'Password invalid.', None
示例#2
0
 def authorize (self, channel, username, password):
     if username in ('ftp', 'anonymous'):
         channel.persona = -1, -1
         channel.read_only = 1
         return 1, 'Ok.', filesys.os_filesystem (self.root)
     else:
         return 0, 'Password invalid.', None
示例#3
0
    def handle_request (self, request):
        # get the user name
        user = user_dir.group(1)
        rest = user_dir.group(2)

        # special hack to catch those lazy URL typers
        if not rest:
            request['Location'] = 'http://%s/~%s/' % (
                    request.channel.server.server_name,
                    user
                    )
            request.error (301)
            return

        # have we already built a userdir fs for this user?
        if self.fs_cache.has_key (user):
            fs = self.fs_cache[user]
        else:
            # no, well then, let's build one.
            # first, find out where the user directory is
            try:
                info = pwd.getpwnam (user)
            except KeyError:
                request.error (404)
                return
            ud = info[5] + '/' + self.public_html
            if os.path.isdir (ud):
                fs = filesys.os_filesystem (ud)
                self.fs_cache[user] = fs
            else:
                request.error (404)
                return

        # fake out default_handler
        self.filesystem = fs
        # massage the request URI
        request.uri = '/' + rest
        return default_handler.default_handler.handle_request (self, request)
示例#4
0
def read(dir, filename, mode = 'rb'):
	import producers
	import filesys
	import asynchat
	reply = ''
	file = ''
	flag = 1

	try :
		fs = filesys.os_filesystem(dir)

		file = fs.open(filename, mode);

		p = producers.file_producer(file)

		while 1 :
			# p.more() 내에 file 자체 close 루틴 존재
			data = p.more()
			if data == '' :
				break;
			else :
				reply = reply + data
	except :
		t, v, tb = sys.exc_info()
		#print 'file_read exception(%s)' % v
		flag =0 

	try :
		file.close()
	except :
		t, v, tb = sys.exc_info()
		#print 'file_read close exception(%s)' % v
		flag =0 


	return (flag, reply)
示例#5
0
    def handle_request(self, request):
        # get the user name
        m = user_dir.match(request.uri)
        user = m.group(1)
        rest = m.group(2)

        # special hack to catch those lazy URL typers
        if not rest:
            request['Location'] = '/~%s/' % user
            request.error(301)
            return

        # have we already built a userdir fs for this user?
        if self.fs_cache.has_key(user):
            fs = self.fs_cache[user]
        else:
            # no, well then, let's build one.
            # first, find out where the user directory is
            try:
                info = pwd.getpwnam(user)
            except KeyError:
                request.error(404)
                return
            ud = info[5] + '/' + self.public_html
            if os.path.isdir(ud):
                fs = filesys.os_filesystem(ud)
                self.fs_cache[user] = fs
            else:
                request.error(404)
                return

        # fake out default_handler
        self.filesystem = fs
        # massage the request URI
        request.uri = '/' + rest
        return default_handler.default_handler.handle_request(self, request)
示例#6
0
 def authorize (self, channel, username, password):
     channel.persona = -1, -1
     channel.read_only = 1
     return 1, 'Ok.', filesys.os_filesystem (self.root)
示例#7
0
 def authorize (self, channel, username, password):
     channel.persona = -1, -1
     channel.read_only = 1
     return 1, 'Ok.', filesys.os_filesystem (self.root)
示例#8
0
import asyncore
import default_handler
import http_server
import put_handler
import auth_handler
import filesys

# For this demo, we'll just use a dictionary of usernames/passwords.
# You can of course use anything that supports the mapping interface,
# and it would be pretty easy to set this up to use the crypt module
# on unix.

users = { 'mozart' : 'jupiter', 'beethoven' : 'pastoral' }

# The filesystem we will be giving access to
fs = filesys.os_filesystem ('/home/medusa')

# The 'default' handler - delivers files for the HTTP GET method.
dh = default_handler.default_handler (fs)

# Supports the HTTP PUT method...
ph = put_handler.put_handler (fs, '/.*')

# ... but be sure to wrap it with an auth handler:
ah = auth_handler.auth_handler (users, ph)

# Create a Web Server
hs = http_server.http_server (ip='', port=8080)

# install the handlers we created:
示例#9
0
	import sys
	if len(sys.argv) < 2:
		print 'usage: %s <root> <port>' % (sys.argv[0])
	else:
		import monitor
		import filesys
		import default_handler
		import status_handler
		import ftp_server
		import chat_server
		import resolver
		import logger
		rs = resolver.caching_resolver ('127.0.0.1')
		lg = logger.file_logger (sys.stdout)
		ms = monitor.secure_monitor_server ('fnord', '127.0.0.1', 9999)
		fs = filesys.os_filesystem (sys.argv[1])
		dh = default_handler.default_handler (fs)
		hs = http_server ('', string.atoi (sys.argv[2]), rs, lg)
		hs.install_handler (dh)
		ftp = ftp_server.ftp_server (
			ftp_server.dummy_authorizer(sys.argv[1]),
			port=8021,
			resolver=rs,
			logger_object=lg
			)
		cs = chat_server.chat_server ('', 7777)
		sh = status_handler.status_extension([hs,ms,ftp,cs,rs])
		hs.install_handler (sh)
		if ('-p' in sys.argv):
			def profile_loop ():
				try:
示例#10
0
 import sys
 if len(sys.argv) < 2:
     print 'usage: %s <root> <port>' % (sys.argv[0])
 else:
     import monitor
     import filesys
     import default_handler
     import status_handler
     import ftp_server
     import chat_server
     import resolver
     import logger
     rs = resolver.caching_resolver ('127.0.0.1')
     lg = logger.file_logger (sys.stdout)
     ms = monitor.secure_monitor_server ('fnord', '127.0.0.1', 9999)
     fs = filesys.os_filesystem (sys.argv[1])
     dh = default_handler.default_handler (fs)
     hs = http_server ('', string.atoi (sys.argv[2]), rs, lg)
     hs.install_handler (dh)
     ftp = ftp_server.ftp_server (
             ftp_server.dummy_authorizer(sys.argv[1]),
             port=8021,
             resolver=rs,
             logger_object=lg
             )
     cs = chat_server.chat_server ('', 7777)
     sh = status_handler.status_extension([hs,ms,ftp,cs,rs])
     hs.install_handler (sh)
     if ('-p' in sys.argv):
         def profile_loop ():
             try:
示例#11
0
文件: pycs.py 项目: myelin/pycs
		import os
		os.stat( rewriteFn )
	except:
		raise "Can't read URL rewriting config file " + rewriteFn
	execfile( rewriteFn )

	rw_h = pycs_rewrite_handler.pycs_rewrite_handler( set, rewriteMap )
	set.SetRewriteHandler(rw_h)

	set.reloadAliases( rw_h )
	
	# Make URL blocker
	bl_h = pycs_block_handler.pycs_block_handler( set )

	# Make GET handler	
	fs = filesys.os_filesystem( pycs_paths.WEBDIR )
	default_h = default_handler.default_handler( fs )

	if set.authorizer is not None:
		# Add auth wrapper
		default_h = pycs_auth_handler.pycs_auth_handler( set, default_h, set.authorizer )

	# Make XML-RPC handler
	rpc_h = pycs_xmlrpc_handler.pycs_xmlrpc_handler( set )
	
	for ns in ('xmlStorageSystem', 'radioCommunityServer', 'weblogUpdates', 'pycsAdmin'):
		h = getattr(__import__(ns), '%s_handler' % ns)(set)
		rpc_h.AddNamespace(ns, h)
	
	# Make accessRestrictions XML-RPC handler
	import accessRestrictions
示例#12
0
Rand.load_file('../randpool.dat', -1) 
ssl_ctx=SSL.Context('sslv23')
ssl_ctx.load_cert('server.pem')
#ssl_ctx.load_verify_location('ca.pem')
#ssl_ctx.load_client_CA('ca.pem')
#ssl_ctx.set_verify(SSL.verify_peer, 10)
#ssl_ctx.set_verify(SSL.verify_peer|SSL.verify_fail_if_no_peer_cert, 10)
#ssl_ctx.set_verify(SSL.verify_peer|SSL.verify_client_once, 10)
ssl_ctx.set_verify(SSL.verify_none, 10)
ssl_ctx.set_session_id_ctx('127.0.0.1:9443')
ssl_ctx.set_tmp_dh('dh1024.pem')
#ssl_ctx.set_info_callback()

hss=https_server.https_server('', HTTPS_PORT, ssl_ctx)

fs=filesys.os_filesystem(os.path.abspath(os.curdir))
#fs=filesys.os_filesystem('/usr/local/pkg/apache/htdocs')
#fs=filesys.os_filesystem('c:/pkg/jdk118/docs')
dh=default_handler.default_handler(fs)
hs.install_handler(dh)
hss.install_handler(dh)

# Cribbed from xmlrpc_handler.py.
# This is where you implement your RPC functionality.
class rpc_demo (xmlrpc_handler.xmlrpc_handler):
    def call (self, method, params):
        print 'method="%s" params=%s' % (method, params)
        return "Sure, that works"

rpch = rpc_demo()
hs.install_handler(rpch)
示例#13
0
# -*- Mode: Python; tab-width: 4 -*-

import asyncore
import http_server
import script_handler
import filesys

h = http_server.http_server ('', 8081)
fs = filesys.os_filesystem ('.')
sh = script_handler.script_handler (fs)

import persistent
ph = script_handler.persistent_script_handler()
ph.add_module ('per', persistent)

# install the two handlers
# Hit me as: http://www.your_server.com:8081/per
h.install_handler (ph)
# Hit me as: http://www.your_server.com:8081/form.mpy
h.install_handler (sh)

asyncore.loop()
示例#14
0
#     to view these log entries.
#
#  If you decide to comment this out, be sure to remove the
#  logger object from the list of status objects below.
#

lg = status_handler.logger_for_status (lg)

# ===========================================================================
# Filesystem Object.
# ===========================================================================
# An abstraction for the file system.  Filesystem objects can be
# combined and implemented in interesting ways.  The default type
# simply remaps a directory to root.

dfs = filesys.os_filesystem (WEB_ROOT)
fs =cdms_filesystem.cdms_filesystem(CDMS_SERVER, CDMS_ROOT)

# ===========================================================================
# Default HTTP handler
# ===========================================================================

# The 'default' handler for the HTTP server is one that delivers
# files normally - this is the expected behavior of a web server.
# Note that you needn't use it:  Your web server might not want to
# deliver files!

# This default handler uses the filesystem object we just constructed.

dh = default_handler.default_handler (dfs)
cdh = cdms_handler.cdms_handler(fs)
示例#15
0
文件: START.py 项目: mdlx/M2Crypto
ssl_ctx=SSL.Context('sslv23')
ssl_ctx.load_cert('server.pem')
ssl_ctx.load_verify_locations('ca.pem')
ssl_ctx.load_client_CA('ca.pem')
#ssl_ctx.set_verify(SSL.verify_peer, 10)
#ssl_ctx.set_verify(SSL.verify_peer|SSL.verify_fail_if_no_peer_cert, 10)
#ssl_ctx.set_verify(SSL.verify_peer|SSL.verify_client_once, 10)
ssl_ctx.set_verify(SSL.verify_none, 10)
ssl_ctx.set_session_id_ctx('127.0.0.1:9443')
ssl_ctx.set_tmp_dh('dh1024.pem')
ssl_ctx.set_info_callback()

hss=https_server.https_server('', HTTPS_PORT, ssl_ctx)

#fs=filesys.os_filesystem(os.path.abspath(os.curdir))
fs=filesys.os_filesystem('/usr/local/pkg/apache/htdocs')
#fs=filesys.os_filesystem('c:/pkg/jdk130/docs')
dh=default_handler.default_handler(fs)
hs.install_handler(dh)
hss.install_handler(dh)

#class rpc_demo (xmlrpc_handler.xmlrpc_handler):
#    def call (self, method, params):
#        print 'method="%s" params=%s' % (method, params)
#        return "Sure, that works"
#rpch = rpc_demo()
#hs.install_handler(rpch)
#hss.install_handler(rpch)

ph=poison_handler.poison_handler(10)
hs.install_handler(ph)
示例#16
0
文件: httpd.py 项目: randix/aprsna
sys.path.append(os.path.normpath(base + '/http'))
sys.path.append(os.path.normpath(base + '/../cfg'))
sys.path.append(os.path.normpath(base + '/../share'))
sys.path.append(os.path.normpath(base + '/../bin'))

import asyncore, default_handler, filesys, ftp_server
import http_server, script_handler
import basecfg

#--------------------------------------

path = basecfg.basepath+'/browser/http'
#path = '/home/rand/apr/browser/http'

os.chdir(path)
fs = filesys.os_filesystem(path)

dh = default_handler.default_handler(fs)
sh = script_handler.script_handler(fs)

if os.uname()[0] == 'AIX' or len(sys.argv) > 1:
  h = http_server.http_server('', 8080)
else:
  h = http_server.http_server('', 8180)

h.install_handler (dh)
h.install_handler (sh)

authorizer = ftp_server.anon_authorizer (basecfg.baselog)
if os.uname()[0] == 'AIX' or len(sys.argv) > 1:
  fs = ftp_server.ftp_server (authorizer, port=8021)
示例#17
0
Rand.load_file('../randpool.dat', -1)
ssl_ctx = SSL.Context('sslv23')
ssl_ctx.load_cert('server.pem')
ssl_ctx.load_verify_locations('ca.pem', '')
ssl_ctx.load_client_CA('ca.pem')
#ssl_ctx.set_verify(SSL.verify_peer, 10)
#ssl_ctx.set_verify(SSL.verify_peer|SSL.verify_fail_if_no_peer_cert, 10)
#ssl_ctx.set_verify(SSL.verify_peer|SSL.verify_client_once, 10)
ssl_ctx.set_verify(SSL.verify_none, 10)
ssl_ctx.set_session_id_ctx('127.0.0.1:39443')
ssl_ctx.set_tmp_dh('dh1024.pem')
ssl_ctx.set_info_callback()

hss = https_server.https_server('', HTTPS_PORT, ssl_ctx)

fs = filesys.os_filesystem(os.path.abspath(os.curdir))
#fs=filesys.os_filesystem('/usr/local/pkg/apache/htdocs')
#fs=filesys.os_filesystem('c:/pkg/jdk130/docs')
dh = default_handler.default_handler(fs)
hs.install_handler(dh)
hss.install_handler(dh)

#class rpc_demo (xmlrpc_handler.xmlrpc_handler):
#    def call (self, method, params):
#        print 'method="%s" params=%s' % (method, params)
#        return "Sure, that works"
#rpch = rpc_demo()
#hs.install_handler(rpch)
#hss.install_handler(rpch)

ph = poison_handler.poison_handler(10)
示例#18
0
#     to view these log entries.
#
#  If you decide to comment this out, be sure to remove the
#  logger object from the list of status objects below.
#

lg = status_handler.logger_for_status(lg)

# ===========================================================================
# Filesystem Object.
# ===========================================================================
# An abstraction for the file system.  Filesystem objects can be
# combined and implemented in interesting ways.  The default type
# simply remaps a directory to root.

dfs = filesys.os_filesystem(WEB_ROOT)
fs = cdms_filesystem.cdms_filesystem(CDMS_SERVER, CDMS_ROOT)

# ===========================================================================
# Default HTTP handler
# ===========================================================================

# The 'default' handler for the HTTP server is one that delivers
# files normally - this is the expected behavior of a web server.
# Note that you needn't use it:  Your web server might not want to
# deliver files!

# This default handler uses the filesystem object we just constructed.

dh = default_handler.default_handler(dfs)
cdh = cdms_handler.cdms_handler(fs)