copied from internal repo
This commit is contained in:
0
file_generator/__init__.py
Normal file
0
file_generator/__init__.py
Normal file
124
file_generator/generate_bind9.py
Normal file
124
file_generator/generate_bind9.py
Normal file
@@ -0,0 +1,124 @@
|
||||
import os
|
||||
import shutil
|
||||
from datetime import datetime
|
||||
|
||||
from conpeek_setup import util
|
||||
from jinja2 import Template
|
||||
|
||||
|
||||
def get_serial():
|
||||
current_date = datetime.now()
|
||||
bind_serial_number = int(current_date.timestamp())
|
||||
return bind_serial_number
|
||||
|
||||
|
||||
def prepare_access_zone_config(external_ip, app_installation_domain, output_directory, template_file_dir, script_dir, internal_ip, developer_mode, kamailio_nat):
|
||||
util.print_black_light(f"Preparing access zone (External IP:{external_ip}) (Core IP: {internal_ip})")
|
||||
template_file_path = os.path.join(script_dir, template_file_dir)
|
||||
|
||||
file = open(template_file_path, 'r')
|
||||
template_content = file.read()
|
||||
template = Template(template_content)
|
||||
|
||||
data = {
|
||||
"app_installation_domain": app_installation_domain,
|
||||
"access_ip": external_ip,
|
||||
"serial_number": get_serial(),
|
||||
"core_ip": internal_ip,
|
||||
"developer_mode": developer_mode,
|
||||
"kamailio_nat": kamailio_nat == '1'
|
||||
}
|
||||
|
||||
output_text = template.render(data)
|
||||
output_file = output_directory + "/db." + app_installation_domain
|
||||
output_file_path = os.path.join(script_dir, output_file)
|
||||
|
||||
with open(output_file_path, "w") as file:
|
||||
file.write(output_text + "\n")
|
||||
|
||||
|
||||
def prepare_system_zone_config(core_ip, output_directory, template_file_dir, script_dir, system_app_installation_domain):
|
||||
util.print_black_light(f"Preparing system zone (Core IP:{core_ip})")
|
||||
template_file_path = os.path.join(script_dir, template_file_dir)
|
||||
|
||||
file = open(template_file_path, 'r')
|
||||
template_content = file.read()
|
||||
template = Template(template_content)
|
||||
|
||||
data = {
|
||||
"system_app_installation_domain": system_app_installation_domain,
|
||||
"core_ip": core_ip,
|
||||
"serial_number": get_serial()
|
||||
}
|
||||
|
||||
output_text = template.render(data)
|
||||
output_file = output_directory + "/db." + system_app_installation_domain
|
||||
output_file_path = os.path.join(script_dir, output_file)
|
||||
|
||||
with open(output_file_path, "w") as file:
|
||||
file.write(output_text + "\n")
|
||||
|
||||
|
||||
def create_config(data, template_path, output_path, script_dir):
|
||||
template_file_path = os.path.join(script_dir, template_path)
|
||||
|
||||
file = open(template_file_path, 'r')
|
||||
template_content = file.read()
|
||||
template = Template(template_content)
|
||||
|
||||
output_text = template.render(data)
|
||||
|
||||
output_file_path = os.path.join(script_dir, output_path)
|
||||
|
||||
with open(output_file_path, "w") as file:
|
||||
file.write(output_text + "\n")
|
||||
|
||||
|
||||
def run(config, developer_mode=False):
|
||||
util.print_black_light("Preparing bind configs")
|
||||
|
||||
internal_ip = config["new_machine_network"]["internal_ip"]
|
||||
external_ip = config["new_machine_network"]["external_ip"]
|
||||
app_installation_domain = config["new_machine_network"]["app_installation_domain"]
|
||||
system_app_installation_domain = config["new_machine_network"]["system_app_installation_domain"]
|
||||
|
||||
var_bind_directory = os.path.join(util.get_output_path(), "var", "cache", "bind")
|
||||
shutil.rmtree(var_bind_directory, ignore_errors=True)
|
||||
os.makedirs(var_bind_directory, exist_ok=True)
|
||||
|
||||
etc_bind_directory = os.path.join(util.get_output_path(), "etc", "bind")
|
||||
shutil.rmtree(etc_bind_directory, ignore_errors=True)
|
||||
os.makedirs(etc_bind_directory, exist_ok=True)
|
||||
|
||||
template_directory = os.path.join(util.get_templates_path(), "bind9")
|
||||
|
||||
kamailio_nat = '1'
|
||||
if config.has_option('kamailio', 'nat'):
|
||||
kamailio_nat = config["kamailio"]["nat"]
|
||||
|
||||
# /var/cache configs
|
||||
prepare_access_zone_config(external_ip, app_installation_domain, var_bind_directory, "access_zone.tmpl", template_directory, internal_ip, developer_mode, kamailio_nat)
|
||||
prepare_system_zone_config(internal_ip, var_bind_directory, "system_zone.tmpl", template_directory, system_app_installation_domain)
|
||||
|
||||
forwarders = config["bind9"]["forwarders"]
|
||||
if not forwarders:
|
||||
forwarders = "1.1.1.1;"
|
||||
|
||||
if ";" not in forwarders:
|
||||
util.print_yellow("; not in bind9 forwarders... dynamically add to end")
|
||||
forwarders += ";"
|
||||
|
||||
# /etc/configs
|
||||
data = {"forward_dns": forwarders}
|
||||
create_config(data, "named.conf.options.tmpl", os.path.join(etc_bind_directory, "named.conf.options"), template_directory)
|
||||
data = {"NETWORK_DOMAIN": app_installation_domain}
|
||||
create_config(data, "named.conf.access_network.tmpl", os.path.join(etc_bind_directory, "named.conf.access_network"), template_directory)
|
||||
data = {"NETWORK_DOMAIN": system_app_installation_domain}
|
||||
create_config(data, "named.conf.system_network.tmpl", os.path.join(etc_bind_directory, "named.conf.system_network"), template_directory)
|
||||
|
||||
files_to_copy = [
|
||||
"named.conf"
|
||||
]
|
||||
|
||||
for file in files_to_copy:
|
||||
util.copy_file(os.path.join(template_directory, file), etc_bind_directory)
|
||||
13
file_generator/generate_cert.py
Normal file
13
file_generator/generate_cert.py
Normal file
@@ -0,0 +1,13 @@
|
||||
import os
|
||||
|
||||
from conpeek_setup import util
|
||||
|
||||
|
||||
def run(config):
|
||||
util.print_black_light("Preparing certificates directories")
|
||||
|
||||
certs_directory = os.path.join(util.get_output_path(), "etc/ssl/certs")
|
||||
private_directory = os.path.join(util.get_output_path(), "etc/ssl/private")
|
||||
|
||||
os.makedirs(certs_directory, exist_ok=True)
|
||||
os.makedirs(private_directory, exist_ok=True)
|
||||
64
file_generator/generate_env.py
Normal file
64
file_generator/generate_env.py
Normal file
@@ -0,0 +1,64 @@
|
||||
import os
|
||||
import shutil
|
||||
|
||||
from jinja2 import Template
|
||||
|
||||
from conpeek_setup import util
|
||||
|
||||
|
||||
def run(config):
|
||||
util.print_black_light("Preparing env file")
|
||||
|
||||
output_directory = os.path.join(util.get_output_path(), "env")
|
||||
template_env_directory = os.path.join(util.get_templates_path(), "env")
|
||||
|
||||
compose_prod = os.path.join(util.get_output_path(), "compose_prod")
|
||||
template_compose_prod = os.path.join(util.get_templates_path(), "compose_prod")
|
||||
|
||||
shutil.rmtree(output_directory, ignore_errors=True)
|
||||
os.makedirs(output_directory, exist_ok=True)
|
||||
os.makedirs(os.path.join(util.get_output_path(), "etc"), exist_ok=True)
|
||||
|
||||
shutil.rmtree(compose_prod, ignore_errors=True)
|
||||
shutil.copytree(template_compose_prod, compose_prod)
|
||||
|
||||
file = open(os.path.join(template_env_directory, "config.env"), 'r')
|
||||
template_content = file.read()
|
||||
template = Template(template_content)
|
||||
tenant_data = util.get_minimal_configuration()
|
||||
|
||||
util.copy_file(os.path.join(template_env_directory, "basic_conpeek.ini"), util.get_output_path())
|
||||
|
||||
kamailio_private_ip = config["new_machine_network"]["internal_ip"]
|
||||
if config.has_option('kamailio', 'private_ip'):
|
||||
kamailio_private_ip = config["kamailio"]["private_ip"]
|
||||
|
||||
kamailio_public_ip = config["new_machine_network"]["external_ip"]
|
||||
if config.has_option('kamailio', 'public_ip'):
|
||||
kamailio_public_ip = config["kamailio"]["public_ip"]
|
||||
|
||||
kamailio_nat = '1'
|
||||
if config.has_option('kamailio', 'nat'):
|
||||
kamailio_nat = config["kamailio"]["nat"]
|
||||
|
||||
data = {
|
||||
"MASTER_PASSWORD": config["machine_secrets"]["master_password"],
|
||||
"DEPLOYMENT_TAG": config["deployment_purpose"]["deployment_tag"],
|
||||
"APP_INSTALLATION_DOMAIN": config["new_machine_network"]["app_installation_domain"],
|
||||
"SYSTEM_APP_INSTALLATION_DOMAIN": config["new_machine_network"]["system_app_installation_domain"],
|
||||
"INTERNAL_IP": config["new_machine_network"]["internal_ip"],
|
||||
"EXTERNAL_IP": config["new_machine_network"]["external_ip"],
|
||||
"REPLICASET": config["new_machine_network"]["cluster_name"],
|
||||
"SYSTEM_TOKEN_SECRETKEY": util.get_token("system_token_secretkey"),
|
||||
"KAMAILIO_PRIVATE_IP": kamailio_private_ip,
|
||||
"KAMAILIO_PUBLIC_IP": kamailio_public_ip,
|
||||
"KAMAILIO_NAT": kamailio_nat
|
||||
}
|
||||
|
||||
data.update(tenant_data)
|
||||
|
||||
output_text = template.render(data)
|
||||
output_file = os.path.join(output_directory, "config.env")
|
||||
|
||||
with open(output_file, "w") as file:
|
||||
file.write(output_text)
|
||||
83
file_generator/generate_freeswitch.py
Normal file
83
file_generator/generate_freeswitch.py
Normal file
@@ -0,0 +1,83 @@
|
||||
import os
|
||||
import shutil
|
||||
|
||||
from conpeek_setup import util
|
||||
|
||||
|
||||
def subnet_mask_to_cidr(mask):
|
||||
# Split the subnet mask into its octets
|
||||
octets = mask.split('.')
|
||||
# Convert each octet from string to integer, then to binary, count the '1' bits
|
||||
try:
|
||||
cidr = str(sum(bin(int(octet)).count('1') for octet in octets))
|
||||
except Exception:
|
||||
util.print_red(f"Mask {mask} is invalid")
|
||||
raise Exception("Mask {mask} is invalid")
|
||||
|
||||
return cidr
|
||||
|
||||
|
||||
def run(config):
|
||||
util.print_black_light("Preparing freeswitch file")
|
||||
|
||||
output_directory = os.path.join(util.get_output_path(), "freeswitch")
|
||||
template_freeswitch_directory = os.path.join(util.get_templates_path(), "freeswitch/conf")
|
||||
|
||||
shutil.rmtree(output_directory, ignore_errors=True)
|
||||
os.makedirs(output_directory, exist_ok=True)
|
||||
|
||||
util.copy_directory(template_freeswitch_directory, os.path.join(output_directory, "conf"))
|
||||
|
||||
mod_verto_replacements = {
|
||||
'VERTO_IP': config["new_machine_network"]["internal_ip"],
|
||||
'EXTERNAL_IP': config["new_machine_network"]["external_ip"],
|
||||
'EXTERNAL_NET_ADDRESS': config["new_machine_network"]["external_net_address"],
|
||||
'EXTERNAL_NET_MASK': subnet_mask_to_cidr(config["new_machine_network"]['external_mask']),
|
||||
'INTERNAL_IP': config["new_machine_network"]["internal_ip"],
|
||||
'INTERNAL_NET_ADDRESS': config["new_machine_network"]["internal_net_address"],
|
||||
'INTERNAL_NET_MASK': subnet_mask_to_cidr(config["new_machine_network"]['internal_mask']),
|
||||
}
|
||||
|
||||
for name in mod_verto_replacements.keys():
|
||||
util.basic_on_location_sed(os.path.join(output_directory, "conf/autoload_configs/verto.conf.xml"), name, mod_verto_replacements[name])
|
||||
|
||||
tenant_data = util.get_minimal_configuration()
|
||||
|
||||
# mod_event_socket
|
||||
util.basic_on_location_sed(os.path.join(output_directory, "conf/autoload_configs/event_socket.conf.xml"), "ES_PORT", "9900")
|
||||
util.basic_on_location_sed(os.path.join(output_directory, "conf/autoload_configs/event_socket.conf.xml"), "ES_IP", config["new_machine_network"]["internal_ip"])
|
||||
|
||||
# switch
|
||||
util.basic_on_location_sed(os.path.join(output_directory, "conf/autoload_configs/switch.conf.xml"), "FS_DOMAIN", f"{tenant_data['freeswitch_name']}.{config['new_machine_network']['system_app_installation_domain']}")
|
||||
|
||||
if config.has_option("freeswitch", "rtp_start_port") and config.has_option("freeswitch", "rtp_end_port"):
|
||||
util.basic_on_location_sed(os.path.join(output_directory, "conf/autoload_configs/switch.conf.xml"), "RTP_START_PORT", config["freeswitch"]["rtp_start_port"])
|
||||
util.basic_on_location_sed(os.path.join(output_directory, "conf/autoload_configs/switch.conf.xml"), "RTP_END_PORT", config["freeswitch"]["rtp_end_port"])
|
||||
else:
|
||||
util.basic_on_location_sed(os.path.join(output_directory, "conf/autoload_configs/switch.conf.xml"), "RTP_START_PORT", "16384")
|
||||
util.basic_on_location_sed(os.path.join(output_directory, "conf/autoload_configs/switch.conf.xml"), "RTP_END_PORT", "32767")
|
||||
|
||||
# vars.xml
|
||||
util.basic_on_location_sed(os.path.join(output_directory, "conf/vars.xml"), "XML_RPC_PASSWORD", "works")
|
||||
util.basic_on_location_sed(os.path.join(output_directory, "conf/vars.xml"), "DEFAULT_PASSWORD", "Q3G2omiUNgD67fgwP6Xa")
|
||||
|
||||
# dialplan
|
||||
util.basic_on_location_sed(os.path.join(output_directory, "conf/dialplan/virtual_contact.xml"), "GATEWAY_NAME", tenant_data["gateway_server_name"])
|
||||
util.basic_on_location_sed(os.path.join(output_directory, "conf/dialplan/virtual_contact.xml"), "INTERNAL_IP", config["new_machine_network"]['internal_ip'])
|
||||
|
||||
# sip profiles
|
||||
util.basic_on_location_sed(os.path.join(output_directory, "conf/sip_profiles/gateway0.xml"), "INTERNAL_IP", config["new_machine_network"]['internal_ip'])
|
||||
util.basic_on_location_sed(os.path.join(output_directory, "conf/sip_profiles/line0_an1.xml"), "INTERNAL_IP", config["new_machine_network"]['internal_ip'])
|
||||
|
||||
is_nat = True
|
||||
if config.has_option('kamailio', 'nat'):
|
||||
is_nat = config["kamailio"]['nat'] == '1'
|
||||
|
||||
if is_nat == '1':
|
||||
util.basic_on_location_sed(os.path.join(output_directory, "conf/sip_profiles/line0_an1.xml"), "LOCAL_NETWORK_ACL", 'nat.auto')
|
||||
util.basic_on_location_sed(os.path.join(output_directory, "conf/sip_profiles/line0_an1.xml"), "EXT_RTP_IP", config["new_machine_network"]['external_ip'])
|
||||
else:
|
||||
util.basic_on_location_sed(os.path.join(output_directory, "conf/sip_profiles/line0_an1.xml"), "LOCAL_NETWORK_ACL", 'localnet.auto')
|
||||
util.basic_on_location_sed(os.path.join(output_directory, "conf/sip_profiles/line0_an1.xml"), "EXT_RTP_IP", config["new_machine_network"]['internal_ip'])
|
||||
|
||||
util.basic_on_location_sed(os.path.join(output_directory, "conf/sip_profiles/gw1_internal0.xml"), "INTERNAL_IP", config["new_machine_network"]['internal_ip'])
|
||||
39
file_generator/generate_kamailio.py
Normal file
39
file_generator/generate_kamailio.py
Normal file
@@ -0,0 +1,39 @@
|
||||
import os
|
||||
import shutil
|
||||
|
||||
from conpeek_setup import util
|
||||
|
||||
|
||||
def run(config):
|
||||
util.print_black_light("Preparing kamailio file")
|
||||
|
||||
output_directory = os.path.join(util.get_output_path(), "kamailio")
|
||||
template_kamailio_directory = os.path.join(util.get_templates_path(), "kamailio")
|
||||
|
||||
shutil.rmtree(output_directory, ignore_errors=True)
|
||||
os.makedirs(output_directory, exist_ok=True)
|
||||
|
||||
tenant_data = util.get_minimal_configuration()
|
||||
|
||||
files_to_copy = [
|
||||
"kamailio.cfg",
|
||||
"kamailio-python.cfg"
|
||||
]
|
||||
|
||||
for file in files_to_copy:
|
||||
util.copy_file(os.path.join(template_kamailio_directory, file), output_directory)
|
||||
|
||||
kamailio_replacements = {
|
||||
'MASTER_PASSWORD': config["machine_secrets"]["master_password"],
|
||||
'KAMAILIO_NAME': tenant_data["kamailio_name"],
|
||||
'DB_HOST': config["new_machine_network"]["internal_ip"]
|
||||
}
|
||||
|
||||
for name in kamailio_replacements.keys():
|
||||
util.basic_on_location_sed(os.path.join(output_directory, "kamailio-python.cfg"), name, kamailio_replacements[name])
|
||||
|
||||
public_ip = config["new_machine_network"]["external_ip"]
|
||||
if config.has_option('kamailio', 'public_ip'):
|
||||
public_ip = config["kamailio"]["public_ip"]
|
||||
|
||||
util.basic_on_location_sed(os.path.join(output_directory, "kamailio.cfg"), 'KAMAILIO_PUBLIC_IP', public_ip)
|
||||
32
file_generator/generate_mail_relay.py
Normal file
32
file_generator/generate_mail_relay.py
Normal file
@@ -0,0 +1,32 @@
|
||||
import os
|
||||
import shutil
|
||||
|
||||
from conpeek_setup import util
|
||||
|
||||
|
||||
def run(config):
|
||||
util.print_black_light("Preparing mail relay file")
|
||||
output_directory = os.path.join(util.get_output_path(), "mail_relay")
|
||||
template_mail_relay_directory = os.path.join(util.get_templates_path(), "mail_relay")
|
||||
|
||||
shutil.rmtree(output_directory, ignore_errors=True)
|
||||
os.makedirs(output_directory, exist_ok=True)
|
||||
|
||||
files_to_copy = [
|
||||
"000-default.conf",
|
||||
"ports.conf",
|
||||
"main.cf"
|
||||
]
|
||||
|
||||
for file in files_to_copy:
|
||||
util.copy_file(os.path.join(template_mail_relay_directory, file), output_directory)
|
||||
|
||||
replacements = {
|
||||
'ACCESS_DOMAIN_NAME': config["new_machine_network"]["app_installation_domain"],
|
||||
}
|
||||
|
||||
if "mail_relay" in config:
|
||||
replacements["POSTFIX_MYNETWORKS"] = config["mail_relay"]["mynetworks"]
|
||||
|
||||
for name in replacements.keys():
|
||||
util.basic_on_location_sed(os.path.join(output_directory, "main.cf"), name, replacements[name])
|
||||
55
file_generator/generate_mariadb.py
Normal file
55
file_generator/generate_mariadb.py
Normal file
@@ -0,0 +1,55 @@
|
||||
import os
|
||||
import shutil
|
||||
|
||||
from conpeek_setup import util
|
||||
|
||||
|
||||
def run(config):
|
||||
util.print_black_light("Preparing mariadb file")
|
||||
|
||||
output_directory = os.path.join(util.get_output_path(), "mariadb")
|
||||
template_mariadb_directory = os.path.join(util.get_templates_path(), "mariadb")
|
||||
|
||||
shutil.rmtree(output_directory, ignore_errors=True)
|
||||
os.makedirs(output_directory, exist_ok=True)
|
||||
|
||||
shutil.copytree(template_mariadb_directory, output_directory, dirs_exist_ok=True)
|
||||
topology_data_file_path = os.path.join(output_directory, "07_topology_data_for_1_tenant.sql")
|
||||
|
||||
tenant_data = util.get_minimal_configuration()
|
||||
|
||||
topology_replacements = {
|
||||
# machine secrets
|
||||
'MASTER_PASSWORD': config["machine_secrets"]["master_password"],
|
||||
# new machine network
|
||||
'KAMAILIO_NAME': tenant_data["kamailio_name"],
|
||||
'INSTANCE_NAME': config["new_machine_network"]["app_installation_domain"],
|
||||
'ACCESS_DOMAIN_NAME': config["new_machine_network"]["app_installation_domain"],
|
||||
'SYSTEM_DOMAIN_NAME': config["new_machine_network"]["system_app_installation_domain"],
|
||||
'CORE_IP': config["new_machine_network"]["internal_ip"],
|
||||
'CORE_MASK': config["new_machine_network"]["internal_mask"],
|
||||
'CORE_NET_ADDRESS': config["new_machine_network"]["internal_net_address"],
|
||||
'ACCESS_IP': config["new_machine_network"]["external_ip"],
|
||||
'ACCESS_MASK': config["new_machine_network"]["external_mask"],
|
||||
'ACCESS_NET_ADDRESS': config["new_machine_network"]["external_net_address"],
|
||||
'TELCO_IP': config["new_machine_network"]["telco_ip"],
|
||||
'TELCO_GATEWAY': config["new_machine_network"]["telco_gateway"],
|
||||
'TELCO_MASK': config["new_machine_network"]["telco_mask"],
|
||||
'TELCO_NET_ADDRESS': config["new_machine_network"]["telco_net_address"],
|
||||
'MONGO_REPLICASET_NAME': config["new_machine_network"]["cluster_name"],
|
||||
'SYSTEM_TOKEN_SECRETKEY': util.get_token("system_token_secretkey"),
|
||||
}
|
||||
|
||||
for name in topology_replacements.keys():
|
||||
util.basic_on_location_sed(topology_data_file_path, name, topology_replacements[name])
|
||||
|
||||
manager_data_file_path = os.path.join(output_directory, "06_manager_data_for_1_tenant.sql")
|
||||
|
||||
manager_replacements = {
|
||||
'OPERATOR_DOMAIN': config["operator"]["domain"],
|
||||
'OPERATOR_USERNAME': config["operator"]["username"],
|
||||
'OPERATOR_PASSWORD': config["operator"]["password"]
|
||||
}
|
||||
|
||||
for name in manager_replacements.keys():
|
||||
util.basic_on_location_sed(manager_data_file_path, name, manager_replacements[name])
|
||||
20
file_generator/generate_metrics.py
Normal file
20
file_generator/generate_metrics.py
Normal file
@@ -0,0 +1,20 @@
|
||||
import os
|
||||
import shutil
|
||||
|
||||
import bcrypt
|
||||
|
||||
from conpeek_setup import util
|
||||
|
||||
|
||||
def run(config):
|
||||
util.print_black_light("Preparing metrics file")
|
||||
output_directory = os.path.join(util.get_output_path(), "metrics")
|
||||
template_env_directory = os.path.join(util.get_templates_path(), "metrics")
|
||||
|
||||
shutil.rmtree(output_directory, ignore_errors=True)
|
||||
os.makedirs(output_directory, exist_ok=True)
|
||||
|
||||
util.copy_file(os.path.join(template_env_directory, "node_exporter.yml"), output_directory)
|
||||
hashed_password = bcrypt.hashpw(config["machine_secrets"]["prometheus_password"].encode("utf-8"), bcrypt.gensalt()).decode()
|
||||
|
||||
util.basic_on_location_sed(os.path.join(output_directory, "node_exporter.yml"), 'PROMETHEUS_PASSWORD', hashed_password)
|
||||
24
file_generator/generate_mongodb.py
Normal file
24
file_generator/generate_mongodb.py
Normal file
@@ -0,0 +1,24 @@
|
||||
import os
|
||||
import shutil
|
||||
|
||||
from conpeek_setup import util
|
||||
|
||||
|
||||
def run(config):
|
||||
util.print_black_light("Preparing mongodb file")
|
||||
|
||||
output_directory = os.path.join(util.get_output_path(), "mongodb")
|
||||
template_mongodb_directory = os.path.join(util.get_templates_path(), "mongodb")
|
||||
|
||||
shutil.rmtree(output_directory, ignore_errors=True)
|
||||
os.makedirs(output_directory, exist_ok=True)
|
||||
|
||||
files_to_copy = [
|
||||
"mongo_init.sh",
|
||||
"text_to_speech.js"
|
||||
]
|
||||
|
||||
for file in files_to_copy:
|
||||
util.copy_file(os.path.join(template_mongodb_directory, file), output_directory)
|
||||
|
||||
util.basic_on_location_sed(os.path.join(output_directory, "mongo_init.sh"), 'MASTER_PASSWORD', config["machine_secrets"]["master_password"])
|
||||
280
file_generator/generate_nginx.py
Normal file
280
file_generator/generate_nginx.py
Normal file
@@ -0,0 +1,280 @@
|
||||
import hashlib
|
||||
import os
|
||||
import random
|
||||
import shutil
|
||||
|
||||
from jinja2 import Template
|
||||
|
||||
from conpeek_setup import util
|
||||
|
||||
|
||||
def generate_upstream_name():
|
||||
# Define a helper function to generate a 7-character MD5 hash from a random number
|
||||
def generate_part():
|
||||
random_number = str(random.randint(0, 32767)) # Equivalent to $RANDOM in bash
|
||||
md5_hash = hashlib.md5(random_number.encode()).hexdigest()
|
||||
return md5_hash[:7]
|
||||
|
||||
# Generate the upstream name by concatenating four parts with hyphens
|
||||
upstream_name = f"{generate_part()}-{generate_part()}-{generate_part()}-{generate_part()}"
|
||||
return upstream_name
|
||||
|
||||
def generate_custom_settings(template_file_path, config_location, app_installation_domain):
|
||||
util.print_black_light(f"Preparing custom settings")
|
||||
|
||||
file = open(template_file_path, 'r')
|
||||
template_content = file.read()
|
||||
template = Template(template_content)
|
||||
|
||||
data = {
|
||||
"app_installation_domain": app_installation_domain[1:].replace(".", "\.")
|
||||
}
|
||||
|
||||
output_text = template.render(data)
|
||||
output_file = os.path.join(config_location, "custom_settings.conf")
|
||||
|
||||
with open(output_file, "w") as file:
|
||||
file.write(output_text)
|
||||
|
||||
|
||||
def generate_default_config(template_file_path, config_location, access_ip, cert_name):
|
||||
util.print_black_light(f"Preparing default.conf")
|
||||
|
||||
file = open(template_file_path, 'r')
|
||||
template_content = file.read()
|
||||
template = Template(template_content)
|
||||
|
||||
data = {
|
||||
"nginx_ip": access_ip,
|
||||
"network_domain": cert_name,
|
||||
}
|
||||
|
||||
output_text = template.render(data)
|
||||
|
||||
output_file = os.path.join(config_location, "default.conf")
|
||||
|
||||
with open(output_file, "w") as file:
|
||||
file.write(output_text)
|
||||
|
||||
|
||||
def generate_config(template_file_path, config_location, listening_port, internal_ip, access_ip, external_ip, server_name, cert_name, app_installation_domain):
|
||||
util.print_black_light(f"Preparing {server_name}{app_installation_domain}")
|
||||
|
||||
file = open(template_file_path, 'r')
|
||||
template_content = file.read()
|
||||
template = Template(template_content)
|
||||
|
||||
data = {
|
||||
"upstream_name": generate_upstream_name(),
|
||||
"service_port": listening_port, # Example list of ports
|
||||
"ip_v4": internal_ip,
|
||||
"nginx_ip": access_ip,
|
||||
"server_name": server_name + app_installation_domain,
|
||||
"network_domain": cert_name,
|
||||
"app_installation_domain": app_installation_domain[1:]
|
||||
}
|
||||
|
||||
output_text = template.render(data)
|
||||
|
||||
output_file = os.path.join(config_location, server_name + app_installation_domain + ".conf")
|
||||
|
||||
with open(output_file, "w") as file:
|
||||
file.write(output_text)
|
||||
|
||||
|
||||
def generate_frontend_config(template_file_path, ready_config_location, internal_ip, server_name, app_name, app_installation_domain, service_port='brak_portu'):
|
||||
util.print_black_light(f"Preparing {server_name}{app_installation_domain}")
|
||||
file = open(template_file_path, 'r')
|
||||
template_content = file.read()
|
||||
template = Template(template_content)
|
||||
|
||||
data = {
|
||||
"internal_ip": internal_ip,
|
||||
"server_name": server_name + app_installation_domain,
|
||||
"app_name": app_name,
|
||||
"service_port": service_port,
|
||||
"app_installation_domain": app_installation_domain[1:]
|
||||
}
|
||||
|
||||
output_text = template.render(data)
|
||||
output_file = os.path.join(ready_config_location, server_name + app_installation_domain + ".conf")
|
||||
|
||||
with open(output_file, "w") as file:
|
||||
file.write(output_text)
|
||||
|
||||
|
||||
def run(config, developer_mode=False):
|
||||
util.print_black_light("Preparing nginx file")
|
||||
|
||||
output_directory = os.path.join(util.get_output_path(), "etc/nginx")
|
||||
template_nginx_directory = os.path.join(util.get_templates_path(), "nginx")
|
||||
|
||||
shutil.rmtree(output_directory, ignore_errors=True)
|
||||
os.makedirs(output_directory, exist_ok=True)
|
||||
|
||||
internal_ip = config["new_machine_network"]["internal_ip"]
|
||||
external_ip = config["new_machine_network"]["internal_ip"] # listen IP same as redirectIP, due to NAT in universal inteface in ŁDZ cloud
|
||||
|
||||
access_ip = config["new_machine_network"]["internal_ip"]
|
||||
if config.has_option('new_machine_network', 'access_ip'):
|
||||
access_ip = config["new_machine_network"]["access_ip"]
|
||||
|
||||
app_installation_domain = "." + config["new_machine_network"]["app_installation_domain"] # code fault, it must be this dot here, for fix in the future
|
||||
cert_name = "conpeek_ssl"
|
||||
|
||||
tenant_data = util.get_minimal_configuration()
|
||||
|
||||
reverse_proxy_directory = os.path.join(util.get_output_path(), "etc/nginx/reverse_proxy")
|
||||
shutil.rmtree(reverse_proxy_directory, ignore_errors=True)
|
||||
os.makedirs(reverse_proxy_directory, exist_ok=True)
|
||||
|
||||
frontend_directory = os.path.join(util.get_output_path(), "etc/nginx/frontend")
|
||||
shutil.rmtree(frontend_directory, ignore_errors=True)
|
||||
os.makedirs(frontend_directory, exist_ok=True)
|
||||
|
||||
reverse_proxy_replacements = {
|
||||
# api tenant login
|
||||
f"{tenant_data['tenant_login_api_server_name']}": tenant_data['tenant_login_api_server_port'],
|
||||
# api tenant
|
||||
f"api-{tenant_data['api_tenant_name']}": tenant_data['api_tenant_port'],
|
||||
# api operator
|
||||
f"api-{tenant_data['operator_api_server_response_name']}": tenant_data['operator_api_server_response_port'],
|
||||
# session_server
|
||||
f"{tenant_data['session_server_name']}": tenant_data['private_api_port'],
|
||||
f"public-api-{tenant_data['session_server_name']}": tenant_data['public_api_port'],
|
||||
f"api-monitoring-{tenant_data['session_server_name']}": tenant_data['monitoring_initial_api_port'],
|
||||
# cdr_server
|
||||
f"api-{tenant_data['cdr_server_name']}": tenant_data['cdr_server_api_port'],
|
||||
# report server
|
||||
f"api-{tenant_data['report_server_name']}": tenant_data['report_server_api_port'],
|
||||
# local contact db server
|
||||
f"api-{tenant_data['local_contact_db_name']}": tenant_data['local_contact_db_api_port'],
|
||||
f"public-api-{tenant_data['local_contact_db_name']}": tenant_data['local_contact_db_public_api_port'],
|
||||
# hubspot server
|
||||
f"api-{tenant_data['hubspot_server_name']}": tenant_data['hubspot_server_api_port'],
|
||||
f"public-api-{tenant_data['hubspot_server_name']}": tenant_data['hubspot_server_public_api_port'],
|
||||
# ticketing server
|
||||
f"api-{tenant_data['ticketing_server_name']}": tenant_data['ticketing_server_api_port'],
|
||||
# gus server
|
||||
f"api-{tenant_data['gus_server_name']}": tenant_data['gus_server_public_api_port'],
|
||||
# meets
|
||||
f"{tenant_data['meets_server_name']}": tenant_data['meets_server_port'],
|
||||
# bss api server
|
||||
f"api-{tenant_data['tenant_bss_api_server_name']}": tenant_data['tenant_bss_api_server_initial_application_port'],
|
||||
# sms server
|
||||
f"api-{tenant_data['sms_server_name']}": tenant_data['sms_server_api_port'],
|
||||
f"public-api-{tenant_data['sms_server_name']}": tenant_data['sms_server_public_api_port'],
|
||||
# mailbox server
|
||||
f"api-{tenant_data['mailbox_server_name']}": tenant_data['mailbox_server_api_port'],
|
||||
f"public-api-{tenant_data['mailbox_server_name']}": tenant_data['mailbox_server_public_api_port'],
|
||||
# facebook server
|
||||
f"api-{tenant_data['facebook_server_name']}": tenant_data['facebook_server_api_port'],
|
||||
f"public-api-{tenant_data['facebook_server_name']}": tenant_data['facebook_server_public_api_port'],
|
||||
# messagebird server
|
||||
f"api-{tenant_data['messagebird_server_name']}": tenant_data['messagebird_server_api_port'],
|
||||
# tenant_web_polling_server
|
||||
f"{tenant_data['api_tenant_web_polling_name']}": tenant_data['api_tenant_web_polling_port'],
|
||||
# bot server
|
||||
f"api-{tenant_data['bot_server_name']}": tenant_data['bot_server_api_port'],
|
||||
|
||||
# verto
|
||||
f"api-{tenant_data['freeswitch_name']}": 6900,
|
||||
f"verto-routing-{tenant_data['freeswitch_name']}": 9800,
|
||||
f"verto-stun-{tenant_data['freeswitch_name']}": 9801,
|
||||
f"verto-no-stun-{tenant_data['freeswitch_name']}": 9802,
|
||||
f"verto-ext-stun-{tenant_data['freeswitch_name']}": 9803,
|
||||
f"verto-ext-no-stun-{tenant_data['freeswitch_name']}": 9804,
|
||||
|
||||
# metrics
|
||||
"invitation": 3900,
|
||||
"conpeek-exporter": 9850,
|
||||
"statsd-exporter": 9851,
|
||||
"statsd-api-exporter": 9852,
|
||||
"ping-exporter": 9853,
|
||||
"node-exporter": 9854,
|
||||
"freeswitch-exporter": 9855,
|
||||
"process-exporter": 9856,
|
||||
"docker-exporter": 9857,
|
||||
|
||||
# frontend
|
||||
"app": 81,
|
||||
"wallboard": 81,
|
||||
"device": 81,
|
||||
"operator": 81,
|
||||
"docs": 81,
|
||||
"desk": 81
|
||||
}
|
||||
|
||||
if developer_mode:
|
||||
reverse_proxy_replacements["app-prod"] = 81
|
||||
|
||||
for name in reverse_proxy_replacements.keys():
|
||||
generate_config(os.path.join(template_nginx_directory, "nginx-proxy.tmpl"), reverse_proxy_directory, reverse_proxy_replacements[name], internal_ip, access_ip, external_ip, name, cert_name, app_installation_domain)
|
||||
|
||||
generate_custom_settings(os.path.join(template_nginx_directory, "custom_settings.tmpl"), reverse_proxy_directory, app_installation_domain)
|
||||
generate_custom_settings(os.path.join(template_nginx_directory, "custom_settings.tmpl"), frontend_directory, app_installation_domain)
|
||||
generate_default_config(os.path.join(template_nginx_directory, "default.tmpl"), reverse_proxy_directory, access_ip, cert_name)
|
||||
|
||||
reverse_proxy_wss_replacements = {
|
||||
f"wss-{tenant_data['session_server_name']}": tenant_data['wss_port'],
|
||||
f"wss-monitoring-{tenant_data['session_server_name']}": tenant_data['monitoring_initial_wss_port'],
|
||||
f"wss-monitoring-{tenant_data['messaging_server_name']}": tenant_data['messaging_server_wss_port'],
|
||||
f"wss-{tenant_data['user_notification_server_name']}": tenant_data['user_notification_server_wss_port'],
|
||||
f"wss-{tenant_data['messaging_server_name']}": tenant_data['messaging_server_wss_port'],
|
||||
}
|
||||
|
||||
for name in reverse_proxy_wss_replacements.keys():
|
||||
generate_config(os.path.join(template_nginx_directory, "nginx-web-socket.tmpl"), reverse_proxy_directory, reverse_proxy_wss_replacements[name], internal_ip, access_ip, external_ip, name, cert_name, app_installation_domain)
|
||||
|
||||
frontend_replacements = {
|
||||
"app": "app_tenant",
|
||||
"wallboard": "app_wallboard",
|
||||
"device": "app_device",
|
||||
"operator": "app_operator"
|
||||
}
|
||||
|
||||
if developer_mode:
|
||||
generate_frontend_config(os.path.join(template_nginx_directory, "docker_frontend_production_template.tmpl"), frontend_directory, internal_ip, "app-prod", "app_tenant", app_installation_domain)
|
||||
|
||||
for name in frontend_replacements.keys():
|
||||
generate_frontend_config(os.path.join(template_nginx_directory, "docker_frontend_template.tmpl"), frontend_directory, internal_ip, name, frontend_replacements[name], app_installation_domain)
|
||||
|
||||
# server specific
|
||||
|
||||
# docs
|
||||
generate_frontend_config(os.path.join(template_nginx_directory, "docker_docs_template.tmpl"), frontend_directory, internal_ip, "docs", "docs", app_installation_domain)
|
||||
# desk
|
||||
generate_frontend_config(os.path.join(template_nginx_directory, "docker_desk_template.tmpl"), frontend_directory, internal_ip, "desk", "app_desk", app_installation_domain)
|
||||
# api tenant plugin frontend
|
||||
generate_frontend_config(os.path.join(template_nginx_directory, "tenant_plugin_frontend_template.tmpl"), frontend_directory, internal_ip, tenant_data['tenant_plugin_api_server_name'], None, app_installation_domain, tenant_data['tenant_plugin_api_server_initial_application_port'])
|
||||
# api tenant plugin reverse proxy
|
||||
generate_config(os.path.join(template_nginx_directory, "tenant_plugin_reverse_proxy_template.tmpl"), reverse_proxy_directory, tenant_data['tenant_plugin_api_server_initial_application_port'], internal_ip, access_ip, external_ip, tenant_data['tenant_plugin_api_server_name'], cert_name, app_installation_domain)
|
||||
# file server
|
||||
generate_config(os.path.join(template_nginx_directory, "nginx-file-server.tmpl"), reverse_proxy_directory, tenant_data['file_server_api_port'], internal_ip, access_ip, external_ip, f"api-{tenant_data['file_server_name']}", cert_name, app_installation_domain)
|
||||
# messaging server
|
||||
generate_config(os.path.join(template_nginx_directory, "nginx-messaging-server.tmpl"), reverse_proxy_directory, tenant_data['messaging_server_public_api_port'], internal_ip, access_ip, external_ip, f"api-{tenant_data['messaging_server_name']}", cert_name, app_installation_domain)
|
||||
# api tenant plugin frontend
|
||||
generate_frontend_config(os.path.join(template_nginx_directory, "tenant_web_polling_frontend_template.tmpl"), frontend_directory, internal_ip, tenant_data['api_tenant_web_polling_name'], None, app_installation_domain, tenant_data['api_tenant_web_polling_port'])
|
||||
# api tenant plugin reverse proxy
|
||||
generate_config(os.path.join(template_nginx_directory, "tenant_web_polling_reverse_proxy_template.tmpl"), reverse_proxy_directory, tenant_data['api_tenant_web_polling_port'], internal_ip, access_ip, external_ip, tenant_data['api_tenant_web_polling_name'], cert_name, app_installation_domain)
|
||||
|
||||
files_to_copy = [
|
||||
"nginx.conf",
|
||||
"nginx.conf_frontend"
|
||||
]
|
||||
|
||||
for file in files_to_copy:
|
||||
util.copy_file(os.path.join(template_nginx_directory, file), output_directory)
|
||||
|
||||
# custom docker entrypoint scripts
|
||||
|
||||
frontend_custom_template_directory = os.path.join(util.get_templates_path(), "nginx")
|
||||
frontend_custom_directory = os.path.join(util.get_output_path(), "custom/frontend")
|
||||
os.makedirs(frontend_custom_directory, exist_ok=True)
|
||||
util.copy_file(os.path.join(frontend_custom_template_directory, "custom.sh"), frontend_custom_directory)
|
||||
|
||||
if config.has_option("custom", "operator_name"):
|
||||
util.basic_on_location_sed(os.path.join(frontend_custom_directory, "custom.sh"), 'OPERATOR_NAME', config["custom"]["operator_name"])
|
||||
else:
|
||||
util.basic_on_location_sed(os.path.join(frontend_custom_directory, "custom.sh"), 'OPERATOR_NAME', 'Conpeek')
|
||||
|
||||
27
file_generator/generate_rabbitmq.py
Normal file
27
file_generator/generate_rabbitmq.py
Normal file
@@ -0,0 +1,27 @@
|
||||
import os
|
||||
import shutil
|
||||
|
||||
from conpeek_setup import util
|
||||
|
||||
|
||||
def run(config):
|
||||
util.print_black_light("Preparing rabbitmq file")
|
||||
|
||||
output_directory = os.path.join(util.get_output_path(), "rabbitmq")
|
||||
template_rabbitmq_directory = os.path.join(util.get_templates_path(), "rabbitmq")
|
||||
|
||||
shutil.rmtree(output_directory, ignore_errors=True)
|
||||
os.makedirs(output_directory, exist_ok=True)
|
||||
|
||||
rabbitmq_directory = os.path.join(util.get_output_path(), "etc/rabbitmq")
|
||||
os.makedirs(rabbitmq_directory, exist_ok=True)
|
||||
|
||||
files_to_copy = [
|
||||
"rabbit_init.sh"
|
||||
]
|
||||
|
||||
for file in files_to_copy:
|
||||
util.copy_file(os.path.join(template_rabbitmq_directory, file), output_directory)
|
||||
|
||||
util.basic_on_location_sed(os.path.join(template_rabbitmq_directory, "rabbit_init.sh"), 'MASTER_PASSWORD', config["machine_secrets"]["master_password"])
|
||||
util.copy_file(os.path.join(template_rabbitmq_directory, "rabbitmq.config"), rabbitmq_directory)
|
||||
40
file_generator/generate_tokens.py
Normal file
40
file_generator/generate_tokens.py
Normal file
@@ -0,0 +1,40 @@
|
||||
import os
|
||||
import random
|
||||
import string
|
||||
|
||||
from conpeek_setup import util
|
||||
|
||||
|
||||
def generate_password(length=64, lowercase=True, uppercase=True, digits=True):
|
||||
|
||||
basic_characters = ""
|
||||
if lowercase:
|
||||
basic_characters += string.ascii_lowercase
|
||||
|
||||
if uppercase:
|
||||
basic_characters += string.ascii_uppercase
|
||||
|
||||
if digits:
|
||||
basic_characters += string.digits
|
||||
|
||||
if not lowercase and not uppercase and not digits:
|
||||
util.print_red("Password must contain at least lowercase, uppercase or digits.")
|
||||
|
||||
password = ''.join(random.choices(basic_characters, k=length))
|
||||
return password
|
||||
|
||||
|
||||
def run(config):
|
||||
output_directory = os.path.join(util.get_output_path(), "tokens")
|
||||
os.makedirs(output_directory, exist_ok=True)
|
||||
|
||||
passwords = {
|
||||
"system_token_secretkey": 64,
|
||||
".erlang.cookie": 56,
|
||||
}
|
||||
|
||||
for key in passwords.keys():
|
||||
token_path = os.path.join(output_directory, key)
|
||||
if not os.path.exists(token_path):
|
||||
with open(token_path, "w") as file:
|
||||
file.write(generate_password(length=passwords[key]))
|
||||
Reference in New Issue
Block a user