mtes-scripts/scripts/module/change_domain.py

70 lines
1.7 KiB
Python
Raw Normal View History

2021-05-10 17:47:13 +02:00
#!/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")
2021-06-30 15:13:29 +02:00
print("{} [--r realm --d domain]".format(sys.argv[0]))
2021-05-10 17:47:13 +02:00
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()
2021-06-30 15:13:29 +02:00
cmd="""CreoleCat -t samba4-vars.conf"""
2021-05-10 17:47:13 +02:00
output = os.popen(cmd)
res = output.read().strip()
output.close()
2021-06-30 15:13:29 +02:00
cmd="""/usr/share/eole/postservice/25-manage-samba instance"""
2021-05-10 17:47:13 +02:00
output = os.popen(cmd)
res = output.read().strip()
output.close()
if __name__ == '__main__':
main()