105
+ − 1 #!/usr/bin/env python2
+ − 2
+ − 3 # This script set account domain in sat.conf if not already set
+ − 4 # if not set, domain is got from prosody container or DOMAIN environment variable
+ − 5
+ − 6 import os , os.path , xmlrpclib , ConfigParser , socket , subprocess
+ − 7 from sat.core.constants import Const as C
+ − 8 from sat.tools import config as sat_config
+ − 9
+ − 10 SECTION = "plugin account"
+ − 11 OPTION = "new_account_domain"
+ − 12 CONFIG_PATH = "/home/sat/.config/sat/sat.conf"
+ − 13
+ − 14 try :
+ − 15 os . makedirs ( os . path . dirname ( CONFIG_PATH ))
+ − 16 except OSError :
+ − 17 pass
+ − 18
+ − 19 config = ConfigParser . SafeConfigParser ()
+ − 20 config . read ( C . CONFIG_FILES )
+ − 21 domain = sat_config . getConfig ( config , SECTION , OPTION )
+ − 22
+ − 23 if domain is None :
+ − 24 os . getenv ( "DOMAIN" )
+ − 25 if domain is None :
+ − 26 proxy = xmlrpclib . ServerProxy ( "http://prosody:9999/" )
+ − 27 try :
+ − 28 if "prosody" not in open ( "/etc/hosts" ) . read ():
+ − 29 raise socket . gaierror # this avoid waiting for timeout if prosody is not linked
+ − 30 domain = proxy . getenv ( "DOMAIN" )
+ − 31 except socket . gaierror :
+ − 32 print "No prosody container connected or known domain, using \" localhost \" for new domains"
+ − 33 domain = "localhost"
+ − 34
+ − 35 config = ConfigParser . SafeConfigParser ()
+ − 36 config . readfp ( open ( CONFIG_PATH , "a+" ))
+ − 37
+ − 38 try :
+ − 39 config . add_section ( SECTION )
+ − 40 except ConfigParser . DuplicateSectionError :
+ − 41 pass
+ − 42
+ − 43 config . set ( SECTION , OPTION , domain )
+ − 44 config . write ( open ( CONFIG_PATH , "w" ))
+ − 45
+ − 46 subprocess . call ([ "add_host" , domain , "prosody" ])
+ − 47
+ − 48 for subdomain in ( "chat" , "proxy" , "upload" , "pubsub" , "salut" ):
+ − 49 subprocess . call ([ "add_host" , "{}.{}" . format ( subdomain , domain ), "prosody" ])