Browse Source

fcn-report: audit des utilisateurs dolibarr

root 6 years ago
parent
commit
64883cbbf6
3 changed files with 19 additions and 6 deletions
  1. 4 1
      fcn-dolibarr
  2. 15 4
      fcn-report
  3. 0 1
      fcntoolbox/dolibarr.py

+ 4 - 1
fcn-dolibarr

@@ -8,7 +8,7 @@ import fcntoolbox.dolibarr as dolibarr
 parser = argparse.ArgumentParser()
 
 parser.add_argument("selection", type=str,
-                    choices=["get-adherents", "get-subscribers", "get-bank-accounts"])
+                    choices=["get-adherents", "get-subscribers", "get-bank-accounts", "get-users"])
 parser.add_argument("-c", "--config", type=str,
                     default="/etc/fcntoolbox/config.ini",
                     help="specify a configuration file")
@@ -35,3 +35,6 @@ elif args.selection == "get-subscribers":
 elif args.selection == "get-bank-accounts":
   accounts = doli.get_bank_accounts(fields=['iban_prefix'])
   print("\n".join(map(lambda x: x[0], accounts)))
+elif args.selection == "get-users":
+  users = doli.get_users(fields = ['email'])
+  print("\n".join(map(lambda x: ','.join(x), users)))

+ 15 - 4
fcn-report

@@ -28,11 +28,26 @@ config.read(args.config)
 confac = config['ac']
 confdoli = config['dolibarr']
 confsympa = config['sympa']
+confsmtp = config['smtp']
 
 conn = psycopg2.connect(host=confdoli['host'], database=confdoli['database'], 
   user=confdoli['user'], password=confdoli['password'])
 
 doli = dolibarr.Instance(conn)
+s = smtplib.SMTP(confsmtp.get('host', 'localhost'))
+pp = pprint.PrettyPrinter()
+
+if confac.get('audit_dolibarr_users', False):
+  usrfields = ["firstname", "lastname", "email"]
+  cur = doli.get_users(fields=usrfields, active_user=True, active_member=False)
+  badusers = cur.fetchall()
+  if len(badusers) != 0:
+    body = "Salut, \n\nDes utilisateurs ne sont pas associés à un membre actif : \n\n" + pp.pformat(badusers)
+    msg = MIMEText(body)
+    msg['Subject'] = "Rapport utilisateurs Dolibarr"
+    msg['From'] = confsmtp.get('from', 'root')
+    msg['To'] = confac.get('audit_recipients', 'root')
+    s.send_message(msg)
 
 fields = ["rowid", "firstname", "lastname", "email"]
 fieldsextra = ['email_second']
@@ -100,10 +115,6 @@ for editor in editors:
 
 reportFormat = open('/etc/fcntoolbox/fcn-report.format', 'r').read()
 
-s = smtplib.SMTP('localhost')
-
-pp = pprint.PrettyPrinter()
-
 def sendReport(listname, tosubscribe, tounsubscribe, removeeditors):
   body = reportFormat.format(
     list = listname,

+ 0 - 1
fcntoolbox/dolibarr.py

@@ -89,6 +89,5 @@ class Instance:
     sqlfields = [sql.SQL('usr.') + sql.Identifier(a) for a in fields]
     sqlfields = sql.SQL(',').join(sqlfields)
     sqlquery = sql.SQL('SELECT DISTINCT ON (usr.rowid) ') + sqlfields + sql.SQL(' FROM llx_user AS usr, llx_adherent AS member') + sqlcond
-    print(sqlquery.as_string(self._cur))
     self._cur.execute(sqlquery.as_string(self._cur))
     return self._cur