Login now working

parent 1190f6d8
#username:salt:sha256 salted password
admin:admin:d82494f05d6917ba02f7aaa29689ccb444bb73f20380876cb05d1f37537b7892
...@@ -135,5 +135,3 @@ class penguidomService(service.Service): ...@@ -135,5 +135,3 @@ class penguidomService(service.Service):
cfg.readConfig() cfg.readConfig()
return cfg return cfg
...@@ -29,20 +29,13 @@ import twisted.cred.checkers ...@@ -29,20 +29,13 @@ import twisted.cred.checkers
import twisted.cred.error import twisted.cred.error
import logging import logging
from twisted.internet import defer from twisted.internet import defer
try:
import hashlib
md5 = hashlib
md5.new = hashlib.md5
sha1 = hashlib.sha1
except:
import md5
import sha1
from nexlibs.utils import genutils from nexlibs.utils import genutils
import os, sys
log = logging.getLogger("Webgui") log = logging.getLogger("Webgui")
USERFILE = os.path.join(os.path.abspath(os.path.dirname(sys.argv[0])), 'conf', 'users.conf')
class mindFactory(object): class mindFactory(object):
loginsaved = False loginsaved = False
...@@ -62,39 +55,34 @@ class clientAuth(object): ...@@ -62,39 +55,34 @@ class clientAuth(object):
cred.credentials.IUsernamePassword, cred.credentials.IUsernamePassword,
) )
users = {}
def __init__(self): def __init__(self):
pass with open(USERFILE) as fp:
for cnt, line in enumerate(fp):
if not line.startswith('#') and len(line) > 0:
try:
l = line.split(':')
self.users[l[0]] = {'salt': l[1], 'hash': l[2].rstrip("\r\n")}
except:
pass
def checkAuth(self, usr, pwd): def checkAuth(self, usr, pwd):
log.debug("CheckAuth for "+str(usr)+" "+str(pwd)) log.debug("CheckAuth for "+str(usr))
return self.core.getAuth(usr, genutils.hashPwd(pwd)) if usr in self.users.keys():
return defer.succeed((genutils.hashPwd256("".join([self.users[usr]['salt'], pwd])) == self.users[usr]['hash']))
return defer.succeed(False)
def getAuth(self, usr, pwd): def getAuth(self, usr, pwd):
log.debug("getAuth for "+str(usr)+" "+str(pwd)) log.debug("getAuth for "+str(usr))
return self.checkAuth(usr, pwd).addCallback(self.getPerms, pwd) return self.checkAuth(usr, pwd)
def getPerms(self, res, pwd):
log.info("getPerms "+str(res))
"""
if len(res) > 0:
if res[0].admin == True:
perms['admin'] = True
return perms
"""
if len(res) > 0:
perms = res[0]
perms.loginpwd = pwd
return perms
return False
def requestAvatarId(self, c): def requestAvatarId(self, c):
log.debug('AUTH: '+str(c)+" "+str(c.username)) log.debug('requestAvatarId: '+str(c.username))
return self.checkAuth(c.username, c.password).addCallback( return self.checkAuth(c.username, c.password).addCallback(
self.getPerms, c.password).addCallback(
self.AvatarResults, c) self.AvatarResults, c)
def AvatarResults(self, res, c): def AvatarResults(self, res, c):
log.debug("AvatarResults "+str(res)+" "+str(c)) log.debug("AvatarResults "+str(res)+" "+str(c.username))
if res: if res:
return defer.succeed([c, res]) return defer.succeed([c, res])
raise cred.error.UnauthorizedLogin() raise cred.error.UnauthorizedLogin()
...@@ -202,8 +202,6 @@ class RootPage(rend.Page): ...@@ -202,8 +202,6 @@ class RootPage(rend.Page):
def child_(self, ctx): def child_(self, ctx):
if str(self.core.configGet('web', 'enableusergui')).lower() not in ['yes', '1', 'y','true']:
return "Permission Denied"
html = """ html = """
Redirecting... Redirecting...
""" """
...@@ -278,7 +276,7 @@ class SessionWrapper(guard.SessionWrapper): ...@@ -278,7 +276,7 @@ class SessionWrapper(guard.SessionWrapper):
def renderHTTP( self, ctx): def renderHTTP( self, ctx):
request = inevow.IRequest(ctx) request = inevow.IRequest(ctx)
host=request.getHeader('host') host=request.getHeader('host')
log.info("USERNAME: "+str(request.getUser())+" "+str(request.getPassword())) log.info("USERNAME: "+str(request.getUser()))
log.debug("SessionWrapper HOST CALLED: "+str(host)) log.debug("SessionWrapper HOST CALLED: "+str(host))
return guard.SessionWrapper.renderHTTP(self, ctx) return guard.SessionWrapper.renderHTTP(self, ctx)
...@@ -302,7 +300,6 @@ class SessionWrapper(guard.SessionWrapper): ...@@ -302,7 +300,6 @@ class SessionWrapper(guard.SessionWrapper):
request.args["username"] = [request.getUser()] request.args["username"] = [request.getUser()]
request.args["password"] = [request.getPassword()] request.args["password"] = [request.getPassword()]
log.info("Calling Guard..."+str(request.args))
return guard.SessionWrapper.locateChild(self, ctx, segments) return guard.SessionWrapper.locateChild(self, ctx, segments)
...@@ -529,13 +526,13 @@ class PenguidomAuthRealm(object): ...@@ -529,13 +526,13 @@ class PenguidomAuthRealm(object):
resc.core = self.core resc.core = self.core
return (inevow.IResource, resc, noLogout) return (inevow.IResource, resc, noLogout)
else: else:
# Qui dovrebbe arrivare in caso di autenticazione # Here it is, we are authenticated.
# avatarId dovrebbe contenere il ritorno al checkauth # avatarId should contain the results of the authentication
# process
resc = RootAuthPage(avatarId, self.port, mind) resc = RootAuthPage(avatarId, self.port, mind)
resc.realm = self resc.realm = self
resc.core = self.core resc.core = self.core
if str(self.core.configGet('web', 'enableajaxgui')).lower() in ['yes', '1', 'y','true']: resc.putChild('sockjs', ajax.getSocketJSResource(self.core))
resc.putChild('sockjs', ajax.getSocketJSResource(self.core))
return (inevow.IResource, resc, resc.logout) return (inevow.IResource, resc, resc.logout)
raise NotImplementedError("Can't support that interface.") raise NotImplementedError("Can't support that interface.")
......
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