Improve WordOps server ip check

This commit is contained in:
VirtuBox
2024-04-21 12:48:11 +02:00
parent 301b146ac1
commit e12cc063d6
2 changed files with 44 additions and 24 deletions

View File

@@ -22,6 +22,7 @@ from wo.core.template import WOTemplate
from wo.core.variables import WOVar from wo.core.variables import WOVar
from wo.core.stackconf import WOConf from wo.core.stackconf import WOConf
from wo.core.download import WODownload from wo.core.download import WODownload
from wo.core.checkfqdn import WOFqdn
def pre_pref(self, apt_packages): def pre_pref(self, apt_packages):
@@ -404,7 +405,9 @@ def post_pref(self, apt_packages, packages, upgrade=False):
"/var/www/22222/cert/22222.key;\n" "/var/www/22222/cert/22222.key;\n"
"ssl_stapling off;\n") "ssl_stapling off;\n")
server_ip = requests.get('http://v4.wordops.eu') server_ip = WOFqdn.get_server_ip(self)
if server_ip is None:
server_ip = "0.0.0.0"
if set(["nginx"]).issubset(set(apt_packages)): if set(["nginx"]).issubset(set(apt_packages)):
print("WordOps backend configuration was successful\n" print("WordOps backend configuration was successful\n"

View File

@@ -4,33 +4,50 @@ from wo.core.shellexec import WOShellExec
from wo.core.variables import WOVar from wo.core.variables import WOVar
def check_fqdn(self, wo_host): class WOFqdn:
"""FQDN check with WordOps, for mail server hostname must be FQDN""" """IP and FQDN tools for WordOps"""
# wo_host=os.popen("hostname -f | tr -d '\n'").read()
if '.' in wo_host: def check_fqdn(self, wo_host):
WOVar.wo_fqdn = wo_host """FQDN check with WordOps, for mail server hostname must be FQDN"""
with open('/etc/hostname', encoding='utf-8', mode='w') as hostfile: # wo_host=os.popen("hostname -f | tr -d '\n'").read()
hostfile.write(wo_host) if '.' in wo_host:
WOVar.wo_fqdn = wo_host
with open('/etc/hostname', encoding='utf-8', mode='w') as hostfile:
hostfile.write(wo_host)
WOShellExec.cmd_exec(self, "sed -i \"1i\\127.0.0.1 {0}\" /etc/hosts"
.format(wo_host))
if WOVar.wo_distro == 'debian':
WOShellExec.cmd_exec(self, "/etc/init.d/hostname.sh start")
else:
WOShellExec.cmd_exec(self, "service hostname restart")
WOShellExec.cmd_exec(self, "sed -i \"1i\\127.0.0.1 {0}\" /etc/hosts"
.format(wo_host))
if WOVar.wo_distro == 'debian':
WOShellExec.cmd_exec(self, "/etc/init.d/hostname.sh start")
else: else:
WOShellExec.cmd_exec(self, "service hostname restart") wo_host = input("Enter hostname [fqdn]:")
WOFqdn.check_fqdn(self, wo_host)
else: def check_fqdn_ip(self):
wo_host = input("Enter hostname [fqdn]:") """Check if server hostname resolved server IP"""
check_fqdn(self, wo_host) try:
x = requests.get('http://v4.wordops.eu')
ip = (x.text).strip()
wo_fqdn = WOVar.wo_fqdn
y = requests.get('http://v4.wordops.eu/dns/{0}/'.format(wo_fqdn))
ip_fqdn = (y.text).strip()
def check_fqdn_ip(self): return bool(ip == ip_fqdn)
"""Check if server hostname resolved server IP""" except requests.exceptions.RequestException as e:
x = requests.get('http://v4.wordops.eu') print("Error occurred during request:", e)
ip = (x.text).strip() return False
wo_fqdn = WOVar.wo_fqdn def get_server_ip(self):
y = requests.get('http://v4.wordops.eu/dns/{0}/'.format(wo_fqdn)) """Get the server externet IP"""
ip_fqdn = (y.text).strip() try:
x = requests.get('http://v4.wordops.eu')
ip = (x.text).strip()
return bool(ip == ip_fqdn) return ip
except requests.exceptions.RequestException as e:
print("Error occurred during request:", e)
return None