Commit 7e852f1e authored by Michael Murtaugh's avatar Michael Murtaugh
Browse files

really basic authentication

parent 21b81efe
from zope.interface import implements
from twisted.web.resource import IResource
from twisted.cred.portal import IRealm
class PublicHTMLRealm(object):
implements(IRealm)
def __init__(self, root):
self.root = root
def requestAvatar(self, avatarId, mind, *interfaces):
if IResource in interfaces:
return (IResource, self.root, lambda: None)
raise NotImplementedError()
......@@ -6,6 +6,20 @@ from time import sleep
from urlparse import urlparse, parse_qs
import urllib
##########################
# AUTHENTICATION
############################
# cache()
from zope.interface import implementer
from twisted.cred.portal import IRealm, Portal
from twisted.cred.checkers import FilePasswordDB
from twisted.web.static import File
from twisted.web.resource import IResource
from twisted.web.guard import HTTPAuthSessionWrapper, DigestCredentialFactory, BasicCredentialFactory
from makeserver.authentication import PublicHTMLRealm
from twisted.web.server import Site, NOT_DONE_YET
from twisted.web.static import File, DirectoryLister
from twisted.internet import reactor
......@@ -18,6 +32,9 @@ from makeserver.makefile import make_question_simple
from makeserver.makedirectorylisting import MakeDirectoryListingFactory
# todo: parameterize this.... or default for text files!!
# TEXT_SERVE_BY_DEFAULT = ("html", "svg", "js", "css")
# TEXT_SERVE_BY_DEFAULT = ()
......@@ -287,6 +304,7 @@ def main (args=None):
parser.add_argument('--index', default=None, help='default: index.cgi')
parser.add_argument('--makefile', default=None, help='location of the makefile to use, default ./makefile')
parser.add_argument('--alias', nargs="+", action="append", help='Add a folder to serve, syntax is [mountpoint path] ... ')
parser.add_argument('--authentication', default=None, help='')
args = parser.parse_args(args)
tryports = args.notryports
......@@ -352,7 +370,16 @@ def main (args=None):
if args.cgibin:
root_resource.putChild("cgi-bin", CGIDirectory(args.cgibin))
factory = Site(root_resource)
if args.authentication:
print ("USING AUTHENTICATION")
passwd_file = args.authentication
portal = Portal(PublicHTMLRealm(root_resource), [FilePasswordDB(passwd_file)])
# credentialFactory = DigestCredentialFactory("md5", "makeserver")
credentialFactory = BasicCredentialFactory("makeserver")
auth_root_resource = HTTPAuthSessionWrapper(portal, [credentialFactory])
factory = Site(auth_root_resource)
else:
factory = Site(root_resource)
while True:
try:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment