annotate docker_legacy/base/scripts/set_account_domain @ 172:a91a55a87830

0.8 screenshots
author Goffi <goffi@goffi.org>
date Tue, 30 Nov 2021 21:42:40 +0100
parents 29873a41aae1
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
164
29873a41aae1 docker: new docker files are now in sat main repos, this one is legacy
Goffi <goffi@goffi.org>
parents:
diff changeset
1 #!/usr/bin/env python2
29873a41aae1 docker: new docker files are now in sat main repos, this one is legacy
Goffi <goffi@goffi.org>
parents:
diff changeset
2
29873a41aae1 docker: new docker files are now in sat main repos, this one is legacy
Goffi <goffi@goffi.org>
parents:
diff changeset
3 # This script set account domain in sat.conf if not already set
29873a41aae1 docker: new docker files are now in sat main repos, this one is legacy
Goffi <goffi@goffi.org>
parents:
diff changeset
4 # if not set, domain is got from prosody container or DOMAIN environment variable
29873a41aae1 docker: new docker files are now in sat main repos, this one is legacy
Goffi <goffi@goffi.org>
parents:
diff changeset
5
29873a41aae1 docker: new docker files are now in sat main repos, this one is legacy
Goffi <goffi@goffi.org>
parents:
diff changeset
6 import os, os.path, xmlrpclib, ConfigParser, socket, subprocess
29873a41aae1 docker: new docker files are now in sat main repos, this one is legacy
Goffi <goffi@goffi.org>
parents:
diff changeset
7 from sat.core.constants import Const as C
29873a41aae1 docker: new docker files are now in sat main repos, this one is legacy
Goffi <goffi@goffi.org>
parents:
diff changeset
8 from sat.tools import config as sat_config
29873a41aae1 docker: new docker files are now in sat main repos, this one is legacy
Goffi <goffi@goffi.org>
parents:
diff changeset
9
29873a41aae1 docker: new docker files are now in sat main repos, this one is legacy
Goffi <goffi@goffi.org>
parents:
diff changeset
10 SECTION = "plugin account"
29873a41aae1 docker: new docker files are now in sat main repos, this one is legacy
Goffi <goffi@goffi.org>
parents:
diff changeset
11 OPTION = "new_account_domain"
29873a41aae1 docker: new docker files are now in sat main repos, this one is legacy
Goffi <goffi@goffi.org>
parents:
diff changeset
12 CONFIG_PATH = "/home/sat/.config/sat/sat.conf"
29873a41aae1 docker: new docker files are now in sat main repos, this one is legacy
Goffi <goffi@goffi.org>
parents:
diff changeset
13
29873a41aae1 docker: new docker files are now in sat main repos, this one is legacy
Goffi <goffi@goffi.org>
parents:
diff changeset
14 try:
29873a41aae1 docker: new docker files are now in sat main repos, this one is legacy
Goffi <goffi@goffi.org>
parents:
diff changeset
15 os.makedirs(os.path.dirname(CONFIG_PATH))
29873a41aae1 docker: new docker files are now in sat main repos, this one is legacy
Goffi <goffi@goffi.org>
parents:
diff changeset
16 except OSError:
29873a41aae1 docker: new docker files are now in sat main repos, this one is legacy
Goffi <goffi@goffi.org>
parents:
diff changeset
17 pass
29873a41aae1 docker: new docker files are now in sat main repos, this one is legacy
Goffi <goffi@goffi.org>
parents:
diff changeset
18
29873a41aae1 docker: new docker files are now in sat main repos, this one is legacy
Goffi <goffi@goffi.org>
parents:
diff changeset
19 config = ConfigParser.SafeConfigParser()
29873a41aae1 docker: new docker files are now in sat main repos, this one is legacy
Goffi <goffi@goffi.org>
parents:
diff changeset
20 config.read(C.CONFIG_FILES)
29873a41aae1 docker: new docker files are now in sat main repos, this one is legacy
Goffi <goffi@goffi.org>
parents:
diff changeset
21 domain = sat_config.getConfig(config, SECTION, OPTION)
29873a41aae1 docker: new docker files are now in sat main repos, this one is legacy
Goffi <goffi@goffi.org>
parents:
diff changeset
22
29873a41aae1 docker: new docker files are now in sat main repos, this one is legacy
Goffi <goffi@goffi.org>
parents:
diff changeset
23 if domain is None:
29873a41aae1 docker: new docker files are now in sat main repos, this one is legacy
Goffi <goffi@goffi.org>
parents:
diff changeset
24 os.getenv("DOMAIN")
29873a41aae1 docker: new docker files are now in sat main repos, this one is legacy
Goffi <goffi@goffi.org>
parents:
diff changeset
25 if domain is None:
29873a41aae1 docker: new docker files are now in sat main repos, this one is legacy
Goffi <goffi@goffi.org>
parents:
diff changeset
26 proxy = xmlrpclib.ServerProxy("http://prosody:9999/")
29873a41aae1 docker: new docker files are now in sat main repos, this one is legacy
Goffi <goffi@goffi.org>
parents:
diff changeset
27 try:
29873a41aae1 docker: new docker files are now in sat main repos, this one is legacy
Goffi <goffi@goffi.org>
parents:
diff changeset
28 if "prosody" not in open("/etc/hosts").read():
29873a41aae1 docker: new docker files are now in sat main repos, this one is legacy
Goffi <goffi@goffi.org>
parents:
diff changeset
29 raise socket.gaierror # this avoid waiting for timeout if prosody is not linked
29873a41aae1 docker: new docker files are now in sat main repos, this one is legacy
Goffi <goffi@goffi.org>
parents:
diff changeset
30 domain = proxy.getenv("DOMAIN")
29873a41aae1 docker: new docker files are now in sat main repos, this one is legacy
Goffi <goffi@goffi.org>
parents:
diff changeset
31 except socket.gaierror:
29873a41aae1 docker: new docker files are now in sat main repos, this one is legacy
Goffi <goffi@goffi.org>
parents:
diff changeset
32 print "No prosody container connected or known domain, using \"localhost\" for new domains"
29873a41aae1 docker: new docker files are now in sat main repos, this one is legacy
Goffi <goffi@goffi.org>
parents:
diff changeset
33 domain = "localhost"
29873a41aae1 docker: new docker files are now in sat main repos, this one is legacy
Goffi <goffi@goffi.org>
parents:
diff changeset
34
29873a41aae1 docker: new docker files are now in sat main repos, this one is legacy
Goffi <goffi@goffi.org>
parents:
diff changeset
35 config = ConfigParser.SafeConfigParser()
29873a41aae1 docker: new docker files are now in sat main repos, this one is legacy
Goffi <goffi@goffi.org>
parents:
diff changeset
36 config.readfp(open(CONFIG_PATH, "a+"))
29873a41aae1 docker: new docker files are now in sat main repos, this one is legacy
Goffi <goffi@goffi.org>
parents:
diff changeset
37
29873a41aae1 docker: new docker files are now in sat main repos, this one is legacy
Goffi <goffi@goffi.org>
parents:
diff changeset
38 try:
29873a41aae1 docker: new docker files are now in sat main repos, this one is legacy
Goffi <goffi@goffi.org>
parents:
diff changeset
39 config.add_section(SECTION)
29873a41aae1 docker: new docker files are now in sat main repos, this one is legacy
Goffi <goffi@goffi.org>
parents:
diff changeset
40 except ConfigParser.DuplicateSectionError:
29873a41aae1 docker: new docker files are now in sat main repos, this one is legacy
Goffi <goffi@goffi.org>
parents:
diff changeset
41 pass
29873a41aae1 docker: new docker files are now in sat main repos, this one is legacy
Goffi <goffi@goffi.org>
parents:
diff changeset
42
29873a41aae1 docker: new docker files are now in sat main repos, this one is legacy
Goffi <goffi@goffi.org>
parents:
diff changeset
43 config.set(SECTION, OPTION, domain)
29873a41aae1 docker: new docker files are now in sat main repos, this one is legacy
Goffi <goffi@goffi.org>
parents:
diff changeset
44 config.write(open(CONFIG_PATH, "w"))
29873a41aae1 docker: new docker files are now in sat main repos, this one is legacy
Goffi <goffi@goffi.org>
parents:
diff changeset
45
29873a41aae1 docker: new docker files are now in sat main repos, this one is legacy
Goffi <goffi@goffi.org>
parents:
diff changeset
46 subprocess.call(["add_host", domain, "prosody"])
29873a41aae1 docker: new docker files are now in sat main repos, this one is legacy
Goffi <goffi@goffi.org>
parents:
diff changeset
47
29873a41aae1 docker: new docker files are now in sat main repos, this one is legacy
Goffi <goffi@goffi.org>
parents:
diff changeset
48 for subdomain in ("chat", "proxy", "upload", "pubsub", "salut"):
29873a41aae1 docker: new docker files are now in sat main repos, this one is legacy
Goffi <goffi@goffi.org>
parents:
diff changeset
49 subprocess.call(["add_host", "{}.{}".format(subdomain, domain), "prosody"])