ipa eta gailua

This commit is contained in:
Aitzol 2023-04-05 13:23:26 +02:00
parent 6968957159
commit 6094fc1156
11 changed files with 24 additions and 7 deletions

BIN
.app.py.swo Normal file

Binary file not shown.

BIN
.app.py.swp Normal file

Binary file not shown.

BIN
.edit_email.tpl.swp Normal file

Binary file not shown.

BIN
.index.tpl.swp Normal file

Binary file not shown.

BIN
.user.tpl.swp Normal file

Binary file not shown.

31
app.py
View File

@ -390,10 +390,16 @@ def login_user_ldap(conf, username, password):
#with connect_ldap(conf) as c: #with connect_ldap(conf) as c:
with connect_ldap(conf, user=superUser.readonly_dn, password=superUser.readonly_pwd) as c: with connect_ldap(conf, user=superUser.readonly_dn, password=superUser.readonly_pwd) as c:
user_dn = find_user_dn(conf, c, username) user_dn = find_user_dn(conf, c, username)
cur_dev = get_dev()
known_device = find_device(conf, c, cur_dev)
print('KNOWN DEVICE:',known_device)
print(request.environ.get('HTTP_X_REAL_IP', request.remote_addr))
# Note: raises LDAPUserNameIsMandatoryError when user_dn is None. # Note: raises LDAPUserNameIsMandatoryError when user_dn is None.
with connect_ldap(conf, authentication=SIMPLE, user=user_dn, password=password) as c: with connect_ldap(conf, authentication=SIMPLE, user=user_dn, password=password) as c:
c.bind() c.bind()
#IP helbidea sartu db-an
ip = {'ip':request.environ.get('HTTP_X_REAL_IP', request.remote_addr)}
c.add(attributes=ip)
newSession().set(get_user_data(user_dn, c)) newSession().set(get_user_data(user_dn, c))
LOG.debug("%s logged in to %s" % (username, conf['base'])) LOG.debug("%s logged in to %s" % (username, conf['base']))
@ -510,7 +516,8 @@ def register(conf, username, firstname, surname, password, email, isFake, device
directory = 'home/user/'+to_ascii(username) directory = 'home/user/'+to_ascii(username)
OBJECT_CLASS = ['top', 'inetOrgPerson', 'posixAccount', 'accountsManagement'] OBJECT_CLASS = ['top', 'inetOrgPerson', 'posixAccount', 'accountsManagement']
attributes = {'gidNumber': '501', 'uidNumber': uidNumber, 'homeDirectory': directory, 'givenName': attributes = {'gidNumber': '501', 'uidNumber': uidNumber, 'homeDirectory': directory, 'givenName':
firstname, 'sn': surname, 'uid' : username, 'mail': email, 'active': False, 'fakeCn': isFake, 'device':device} firstname, 'sn': surname, 'uid' : username, 'mail': email, 'active': False, 'fakeCn': isFake,
'devices':device}
new_user_dn = "cn="+firstname+" "+surname+" - "+username+",cn=users,"+conf['base'] new_user_dn = "cn="+firstname+" "+surname+" - "+username+",cn=users,"+conf['base']
c.add(dn=new_user_dn,object_class=OBJECT_CLASS, attributes=attributes) c.add(dn=new_user_dn,object_class=OBJECT_CLASS, attributes=attributes)
#create/change user password #create/change user password
@ -760,6 +767,17 @@ def find_email(conf, conn, email):
return False return False
#find devices
def find_device(conf, conn, device):
search_filter = '(uid=*)'
if conn.search(conf['base'], search_filter, attributes=['devices']):
for i in conn.response:
for j in i['attributes']['devices']:
if(j == device):
return True
return False
#find highest uidNumber #find highest uidNumber
def find_uid_number(conf, conn): def find_uid_number(conf, conn):
search_filter = '(uid=*)' search_filter = '(uid=*)'
@ -786,7 +804,7 @@ def get_user_email_array(user_dn, conn, old_email, new_email):
def get_user_data(user_dn, conn): def get_user_data(user_dn, conn):
search_filter = '(objectClass=*)' search_filter = '(objectClass=*)'
conn.search(user_dn, search_filter, attributes=['active','fakeCn','givenName','sn','uid','mail','device']) conn.search(user_dn, search_filter, attributes=['active','fakeCn','givenName','sn','uid','mail','devices'])
data = [] data = []
data.append(conn.entries[0].active.values[0]) data.append(conn.entries[0].active.values[0])
data.append(conn.entries[0].fakeCn.values[0]) data.append(conn.entries[0].fakeCn.values[0])
@ -794,7 +812,7 @@ def get_user_data(user_dn, conn):
data.append(conn.entries[0].sn.values[0]) data.append(conn.entries[0].sn.values[0])
data.append(conn.entries[0].uid.values[0]) data.append(conn.entries[0].uid.values[0])
data.append(conn.entries[0].mail.values[0]) data.append(conn.entries[0].mail.values[0])
data.append(conn.entries[0].device.values) data.append(conn.entries[0].devices.values)
return(data) return(data)
def read_config(): def read_config():
@ -825,7 +843,6 @@ def get_dev():
user_agent = parse(ua_string) user_agent = parse(ua_string)
return str(user_agent) return str(user_agent)
class Error(Exception): class Error(Exception):
pass pass
@ -863,7 +880,7 @@ def newSession():
self.surname = data[3] self.surname = data[3]
self.username = data[4] self.username = data[4]
self.mail = data[5] self.mail = data[5]
self.device = data[6] self.devices = data[6]
self.data['active'] = self.active self.data['active'] = self.active
self.data['fakeCn'] = self.fakeCn self.data['fakeCn'] = self.fakeCn
@ -871,7 +888,7 @@ def newSession():
self.data['surname'] = self.surname self.data['surname'] = self.surname
self.data['username'] = self.username self.data['username'] = self.username
self.data['mail'] = self.mail self.data['mail'] = self.mail
self.data['device'] = self.device self.data['devices'] = self.devices
def close(self): def close(self):
self.data.pop('username') self.data.pop('username')

Binary file not shown.