|
|
@ -9,7 +9,7 @@ from jinja2 import Environment, FileSystemLoader
|
|
|
|
import requests
|
|
|
|
import requests
|
|
|
|
import base64
|
|
|
|
import base64
|
|
|
|
import json
|
|
|
|
import json
|
|
|
|
from subprocess import call
|
|
|
|
from subprocess import call, DEVNULL
|
|
|
|
import os
|
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
import sys
|
|
|
|
|
|
|
|
|
|
|
@ -30,13 +30,15 @@ def generate(api_client):
|
|
|
|
all_users = api_client.list("localemail/users")
|
|
|
|
all_users = api_client.list("localemail/users")
|
|
|
|
# Création de l'environnement Jinja
|
|
|
|
# Création de l'environnement Jinja
|
|
|
|
env = Environment(loader=FileSystemLoader(path))
|
|
|
|
env = Environment(loader=FileSystemLoader(path))
|
|
|
|
template = env.get_template('templates/list')
|
|
|
|
|
|
|
|
|
|
|
|
# On commence par les alias
|
|
|
|
|
|
|
|
template = env.get_template('templates/list_alias')
|
|
|
|
aliases_rendered = template.render(data=all_users)
|
|
|
|
aliases_rendered = template.render(data=all_users)
|
|
|
|
|
|
|
|
|
|
|
|
fichier = open(path+'/generated/aliases','w')
|
|
|
|
fichier = open(path+'/generated/aliases','w', encoding='utf-8')
|
|
|
|
|
|
|
|
|
|
|
|
if os.path.isfile(path+'/aliases_local'): # if a local aliases file exist, add it's content at the beginning
|
|
|
|
if os.path.isfile(path+'/aliases_local'): # if a local aliases file exist, add it's content at the beginning
|
|
|
|
local = open(path+'/aliases_local','r')
|
|
|
|
local = open(path+'/aliases_local','r', encoding='utf-8')
|
|
|
|
for line in local.readlines():
|
|
|
|
for line in local.readlines():
|
|
|
|
fichier.write(line)
|
|
|
|
fichier.write(line)
|
|
|
|
local.close()
|
|
|
|
local.close()
|
|
|
@ -44,7 +46,23 @@ def generate(api_client):
|
|
|
|
fichier.write(aliases_rendered)
|
|
|
|
fichier.write(aliases_rendered)
|
|
|
|
fichier.close()
|
|
|
|
fichier.close()
|
|
|
|
|
|
|
|
|
|
|
|
call(["/usr/bin/newaliases"], stdout=open(os.devnull, 'wb')) # Update the aliases config file
|
|
|
|
# On enchaine avec les redirections
|
|
|
|
|
|
|
|
template = env.get_template('templates/list_virtual')
|
|
|
|
|
|
|
|
virtuals_rendered = template.render(data=all_users)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fichier = open(path+'/generated/virtual','w', encoding='utf-8')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if os.path.isfile(path+'/virtuals_local'): # if a local aliases file exist, add it's content at the beginning
|
|
|
|
|
|
|
|
local = open(path+'/virtuals_local','r', encoding='utf-8')
|
|
|
|
|
|
|
|
for line in local.readlines():
|
|
|
|
|
|
|
|
fichier.write(line)
|
|
|
|
|
|
|
|
local.close()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fichier.write(virtuals_rendered)
|
|
|
|
|
|
|
|
fichier.close()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
call(["/usr/bin/newaliases"], stdout=DEVNULL) # Update the aliases config file
|
|
|
|
|
|
|
|
call(["/usr/sbin/postmap", path+"/generated/virtual"], stdout=DEVNULL) # Update the aliases config file
|
|
|
|
call(["/usr/sbin/postfix", "reload"]) # force the reloading now
|
|
|
|
call(["/usr/sbin/postfix", "reload"]) # force the reloading now
|
|
|
|
|
|
|
|
|
|
|
|
for arg in sys.argv:
|
|
|
|
for arg in sys.argv:
|
|
|
|