mtes-scripts/scripts/module/change_domain.py

70 lines
1.7 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("{} [--var nom_variable --value valeur]".format(sys.argv[0]))
def argparser():
# récupère l'ID du groupe
arglen = len(sys.argv)
if arglen == 1:
return None, None
if sys.argv[1] in ['-h', '--help']:
display_help()
sys.exit(0)
if sys.argv[1] in ['-r', '--realm']:
realm = sys.argv[2]
return realm, None
if sys.argv[3] in ['-d', '--domain']:
domain = sys.argv[4]
return realm, domain
return None, None
def main():
# import des fonctions communes de Zéphir client
realm, domain = argparser()
if realm is None :
realm = raw_input("Realm AD : ")
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 "ad_realm" in store:
store["ad_realm"]['val'] = realm
if "ad_domain" in store:
store["ad_domain"]['val'] = domain
fh = open("/etc/eole/config.eol", 'w')
fh.write(cjson.encode(store))
fh.close()
cmd="""CreoleCat samba4-vars.conf"""
output = os.popen(cmd)
res = output.read().strip()
output.close()
cmd="""/usr/share/eole/posttemplate/25-manage-samba instance"""
output = os.popen(cmd)
res = output.read().strip()
output.close()
if __name__ == '__main__':
main()