2018-03-09 16:09:33 +01:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
def toCidr(ip,mask=False):
|
|
|
|
""" Convert to CIDR notation
|
|
|
|
ip can be like this : 192.168.5.100/255.255.255.0
|
|
|
|
or you can provide the ip and the mask
|
|
|
|
"""
|
|
|
|
from IPy import IP
|
|
|
|
try:
|
|
|
|
if mask:
|
|
|
|
data="{0}/{1}".format(ip,mask)
|
|
|
|
else:
|
|
|
|
data=ip
|
|
|
|
return str(IP(data))
|
|
|
|
except:
|
|
|
|
return data
|
2018-03-19 14:35:00 +01:00
|
|
|
|
|
|
|
def readPass(encoder,reader):
|
|
|
|
try:
|
|
|
|
mypwdreader=open(reader, "r").readline().rstrip()
|
|
|
|
if encoder == "":
|
|
|
|
return mypwdreader
|
|
|
|
elif encoder == "base64":
|
|
|
|
import base64
|
|
|
|
return base64.b64encode(mypwdreader)
|
|
|
|
|
|
|
|
except:
|
|
|
|
return "mot de passe inconnu"
|
2018-03-21 12:17:20 +01:00
|
|
|
|
|
|
|
def getSSOFilters():
|
|
|
|
""" Convert former eole-sso filters to LemonLDAP filters
|
|
|
|
"""
|
|
|
|
import glob
|
2020-12-21 16:10:54 +01:00
|
|
|
from ConfigParser import ConfigParser
|
2018-04-09 14:31:35 +02:00
|
|
|
|
2018-03-21 12:17:20 +01:00
|
|
|
try:
|
2018-03-21 15:03:50 +01:00
|
|
|
filters = { 'uid': "uid", "mail": "mail" }
|
2018-03-21 12:17:20 +01:00
|
|
|
filterDirectory = "/usr/share/sso/app_filters/"
|
|
|
|
filterExtention = ".ini"
|
|
|
|
filterSection = "utilisateur"
|
|
|
|
filterFiles = glob.glob("{0}/*{1}".format(filterDirectory, filterExtention))
|
2018-03-21 15:03:50 +01:00
|
|
|
toClean = [ "__name__" ]
|
|
|
|
if len(filterFiles) != 0:
|
|
|
|
for fi in filterFiles:
|
|
|
|
# Don't parse "applications.ini"
|
|
|
|
config = ConfigParser()
|
|
|
|
config.read(fi)
|
|
|
|
if filterSection in config._sections:
|
|
|
|
filters.update(config._sections[filterSection].items())
|
|
|
|
for key in toClean:
|
|
|
|
if key in filters.keys():
|
|
|
|
del(filters[key])
|
2018-04-09 14:31:35 +02:00
|
|
|
res = {}
|
2018-03-21 12:17:20 +01:00
|
|
|
index=0
|
|
|
|
size=len(filters)
|
2018-04-09 14:31:35 +02:00
|
|
|
return(filters.items())
|
|
|
|
"""
|
2018-03-21 12:17:20 +01:00
|
|
|
for k,v in filters.items():
|
2018-04-09 14:31:35 +02:00
|
|
|
res[k] " \"{0}\": \"{1}\"".format(k,v)
|
2018-03-21 12:17:20 +01:00
|
|
|
index += 1
|
|
|
|
if index != size:
|
2018-03-21 15:03:50 +01:00
|
|
|
res += ",\n"
|
2018-03-21 12:17:20 +01:00
|
|
|
return(res)
|
2018-04-09 14:31:35 +02:00
|
|
|
"""
|
2018-03-21 12:17:20 +01:00
|
|
|
except:
|
|
|
|
return "Error Generating Filters"
|
2018-04-09 14:31:35 +02:00
|
|
|
|