92 lines
2.5 KiB
Python
92 lines
2.5 KiB
Python
#!/usr/bin/env python
|
|
# -*- coding: utf-8 -*-
|
|
|
|
import sys, getpass, socket, cjson, os
|
|
from pyeole.ihm import print_line
|
|
from pyeole.ansiprint import print_orange, print_red
|
|
from creole.client import CreoleClient
|
|
from collections import OrderedDict
|
|
|
|
|
|
def display_help():
|
|
print("Modification de la valeur d'une variable d'un serveur")
|
|
print("{} [--d domain --integration --save --no-save]".format(sys.argv[0]))
|
|
|
|
|
|
def argparser():
|
|
# récupère l'ID du groupe
|
|
arglen = len(sys.argv)
|
|
save = None
|
|
integration = None
|
|
if "--save" in sys.argv:
|
|
save = True
|
|
if "--no-save" in sys.argv:
|
|
save = False
|
|
if "--integration" in sys.argv:
|
|
integration = True
|
|
if arglen == 1:
|
|
return None, save
|
|
if sys.argv[1] in ['-h', '--help']:
|
|
display_help()
|
|
sys.exit(0)
|
|
|
|
if sys.argv[1] in ['-d', '--domain']:
|
|
domain = sys.argv[2]
|
|
return domain, save, integration
|
|
|
|
return None, save, integration
|
|
|
|
|
|
def main():
|
|
# import des fonctions communes de Zéphir client
|
|
domain, save, integration = argparser()
|
|
|
|
if domain is None :
|
|
domain = raw_input("Domaine AD : ")
|
|
|
|
fh = open("/etc/eole/config.eol", 'r')
|
|
store = cjson.decode(fh.read(), all_unicode=True)
|
|
fh.close
|
|
if "nom_domaine_local" in store:
|
|
store["nom_domaine_local"]['val'] = domain
|
|
|
|
fh = open("/etc/eole/config.eol", 'w')
|
|
fh.write(cjson.encode(store))
|
|
fh.close()
|
|
|
|
cmd="""CreoleCat -t samba4-vars.conf"""
|
|
output = os.popen(cmd)
|
|
res = output.read().strip()
|
|
output.close()
|
|
|
|
if not integration :
|
|
to_integrate = raw_input("Souhaitez vous intégrer le serveur au domaine ad ? (O/N) ")
|
|
if to_integrate == "O":
|
|
integration = True
|
|
|
|
if integration:
|
|
cmd="""rm -f /var/lib/samba/.instance_ok; rm -f *.tdb"""
|
|
output = os.popen(cmd)
|
|
res = output.read().strip()
|
|
output.close()
|
|
cmd="""/usr/share/eole/postservice/25-manage-samba instance"""
|
|
output = os.popen(cmd)
|
|
res = output.read().strip()
|
|
output.close()
|
|
|
|
to_save = ""
|
|
if save if None:
|
|
to_save = raw_input("Souhaitez vous sauvegarder la configuration sur Zephir ? (O/N) ")
|
|
if to_save == "O":
|
|
save = True
|
|
print("Sauvegarde de la configuration sur zephir")
|
|
else:
|
|
print("La configuration ne sera pas sauvegardé sur le zephir")
|
|
if save:
|
|
cmd="""/usr/share/zephir/scripts/zephir_client save_files"""
|
|
output = os.popen(cmd)
|
|
output.close()
|
|
|
|
if __name__ == '__main__':
|
|
main()
|