[crans_utils, lc_ldap] Pretty-printing de la date dans l'historique
This commit is contained in:
parent
ae7d33c267
commit
e239973d60
2 changed files with 21 additions and 10 deletions
|
@ -29,7 +29,7 @@
|
||||||
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||||
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
||||||
import netaddr, re, time, smtplib, sys
|
import calendar, netaddr, re, time, smtplib, sys
|
||||||
sys.path.append('/usr/scripts/gestion')
|
sys.path.append('/usr/scripts/gestion')
|
||||||
import config
|
import config
|
||||||
from unicodedata import normalize
|
from unicodedata import normalize
|
||||||
|
@ -68,6 +68,15 @@ def mailexist(mail):
|
||||||
|
|
||||||
return r
|
return r
|
||||||
|
|
||||||
|
def format_ldap_time(tm):
|
||||||
|
u"""Formatage des dates provenant de la base LDAP
|
||||||
|
Transforme la date YYYYMMDDHHMMSS.XXXXXXZ (UTC)
|
||||||
|
en date DD/MM/YY HH:MM (local)"""
|
||||||
|
tm_st = time.strptime(tm.split('.')[0], "%Y%m%d%H%M%S") # struct_time UTC
|
||||||
|
timestamp = calendar.timegm(tm_st)
|
||||||
|
tm_st = time.localtime(timestamp) # struct_time locale
|
||||||
|
return time.strftime("%d/%m/%Y %H:%M", tm_st)
|
||||||
|
|
||||||
def format_mac(mac):
|
def format_mac(mac):
|
||||||
u""" Formatage des adresses mac
|
u""" Formatage des adresses mac
|
||||||
Transforme une adresse pour obtenir la forme xx:xx:xx:xx:xx:xx
|
Transforme une adresse pour obtenir la forme xx:xx:xx:xx:xx:xx
|
||||||
|
|
20
lc_ldap.py
20
lc_ldap.py
|
@ -225,15 +225,6 @@ class lc_ldap(ldap.ldapobject.LDAPObject):
|
||||||
now = datetime.datetime.now().strftime('%Y-%m-%d %H:%M : ')
|
now = datetime.datetime.now().strftime('%Y-%m-%d %H:%M : ')
|
||||||
return unicode(now) + msg
|
return unicode(now) + msg
|
||||||
|
|
||||||
def search_historique(self, dn):
|
|
||||||
res = self.search_s(log_dn, 2, 'reqDN=%s' % dn)
|
|
||||||
res.sort((lambda a, b: cmp(a[1]['reqEnd'][0], b[1]['reqEnd'][0])))
|
|
||||||
for cn, attrs in res:
|
|
||||||
if attrs['reqType'][0] == 'delete':
|
|
||||||
print "%s deleted %s" % (attrs['reqAuthzID'][0], attrs['reqDN'][0])
|
|
||||||
elif attrs['reqType'][0] == 'modify':
|
|
||||||
print "%s modified %s (%s)" % (attrs['reqAuthzID'][0], attrs['reqDN'][0],
|
|
||||||
"/".join(attrs['reqMod']))
|
|
||||||
# ? def reconnect(self, conn=None):
|
# ? def reconnect(self, conn=None):
|
||||||
|
|
||||||
|
|
||||||
|
@ -426,6 +417,17 @@ class CransLdapObject(object):
|
||||||
|
|
||||||
return histo
|
return histo
|
||||||
|
|
||||||
|
def search_historique(self):
|
||||||
|
res = self.conn.search_s(log_dn, 2, 'reqDN=%s' % self.dn)
|
||||||
|
res.sort((lambda a, b: cmp(a[1]['reqEnd'][0], b[1]['reqEnd'][0])))
|
||||||
|
for cn, attrs in res:
|
||||||
|
date = crans_utils.format_ldap_time(attrs['reqEnd'][0])
|
||||||
|
if attrs['reqType'][0] == 'delete':
|
||||||
|
print "%s : %s deleted %s" % (date, attrs['reqAuthzID'][0], attrs['reqDN'][0])
|
||||||
|
elif attrs['reqType'][0] == 'modify':
|
||||||
|
print "%s : %s modified %s (%s)" % (date, attrs['reqAuthzID'][0], attrs['reqDN'][0],
|
||||||
|
"/".join(attrs['reqMod']))
|
||||||
|
|
||||||
def blacklist_actif(self):
|
def blacklist_actif(self):
|
||||||
u"""Vérifie si l'instance courante est blacklistée.
|
u"""Vérifie si l'instance courante est blacklistée.
|
||||||
Retourne les sanctions en cours (liste).
|
Retourne les sanctions en cours (liste).
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue