bug fix: backups to rustic

This commit is contained in:
usman@cyberpersons.com
2023-04-01 23:37:08 +05:00
parent 13ecd28c4a
commit 0ae3c01c5c
9 changed files with 198 additions and 171 deletions

View File

@@ -712,27 +712,25 @@ def add_website(request):
final_json = json.dumps({'status': 0, 'error_message': str(msg)}) final_json = json.dumps({'status': 0, 'error_message': str(msg)})
return HttpResponse(final_json) return HttpResponse(final_json)
#### Backups v2
def ConfigureV2Backup(request): def ConfigureV2Backup(request):
try: try:
user_id, current_acl = _get_user_acl(request) user_id, current_acl = _get_user_acl(request)
if ACLManager.currentContextPermission(current_acl, 'createBackup') == 0: if ACLManager.currentContextPermission(current_acl, 'createBackup') == 0:
return ACLManager.loadError() return ACLManager.loadError()
websites = ACLManager.findAllSites(current_acl, user_id) websites = ACLManager.findAllSites(current_acl, user_id)
# #
# destinations = _get_destinations(local=True) # destinations = _get_destinations(local=True)
proc = httpProc(request, 'IncBackups/ConfigureV2Backup.html', {'websiteList': websites}) proc = httpProc(request, 'IncBackups/ConfigureV2Backup.html', {'websiteList': websites})
return proc.render() return proc.render()
except BaseException as msg: except BaseException as msg:
logging.writeToFile(str(msg)) logging.writeToFile(str(msg))
return redirect(loadLoginPage) return redirect(loadLoginPage)
def CreateV2Backup(request): def CreateV2Backup(request):
try: try:
userID = request.session['userID'] userID = request.session['userID']
@@ -753,8 +751,18 @@ def createV2BackupSetup(request):
req_data['scopes'] = request.GET.get('s') req_data['scopes'] = request.GET.get('s')
req_data['accountname'] = request.GET.get('n') req_data['accountname'] = request.GET.get('n')
website = request.GET.get('d') website = request.GET.get('d')
# logging.writeToFile('domainname is ====%s'%(request.GET.get)) # logging.writeToFile('domainname is ====%s'%(request.GET.get))
currentACL = ACLManager.loadedACL(userID)
admin = Administrator.objects.get(pk=userID)
if ACLManager.checkOwnership(website, admin, currentACL) == 1:
pass
else:
return ACLManager.loadError()
cpbuv2 = CPBackupsV2( cpbuv2 = CPBackupsV2(
{'domain': website, 'BasePath': '/home/backup', 'BackupDatabase': 1, 'BackupData': 1, {'domain': website, 'BasePath': '/home/backup', 'BackupDatabase': 1, 'BackupData': 1,
'BackupEmails': 1, 'BackendName': 'testremote'}) 'BackupEmails': 1, 'BackendName': 'testremote'})
@@ -766,7 +774,6 @@ def createV2BackupSetup(request):
except KeyError: except KeyError:
return redirect(loadLoginPage) return redirect(loadLoginPage)
def CreateV2BackupButton(request): def CreateV2BackupButton(request):
import re import re
try: try:
@@ -775,8 +782,13 @@ def CreateV2BackupButton(request):
Selectedwebsite = data['Selectedwebsite'] Selectedwebsite = data['Selectedwebsite']
Selectedrepo = data['Selectedrepo'] Selectedrepo = data['Selectedrepo']
currentACL = ACLManager.loadedACL(userID)
admin = Administrator.objects.get(pk=userID)
if ACLManager.checkOwnership(Selectedwebsite, admin, currentACL) == 1:
pass
else:
return ACLManager.loadError()
background = CPBackupsV2({'domain': Selectedwebsite, 'BasePath': '/home/backup', 'BackupDatabase': 1, 'BackupData': 1, background = CPBackupsV2({'domain': Selectedwebsite, 'BasePath': '/home/backup', 'BackupDatabase': 1, 'BackupData': 1,
'BackupEmails': 1, 'BackendName': Selectedrepo, 'function': 'InitiateBackup', }) 'BackupEmails': 1, 'BackendName': Selectedrepo, 'function': 'InitiateBackup', })
@@ -793,7 +805,6 @@ def CreateV2BackupButton(request):
json_data = json.dumps(data_ret) json_data = json.dumps(data_ret)
return HttpResponse(json_data) return HttpResponse(json_data)
def CreateV2BackupStatus(request): def CreateV2BackupStatus(request):
try: try:
userID = request.session['userID'] userID = request.session['userID']
@@ -833,8 +844,15 @@ def selectwebsiteRetorev2(request):
userID = request.session['userID'] userID = request.session['userID']
data = json.loads(request.body) data = json.loads(request.body)
Selectedwebsite = data['Selectedwebsite'] Selectedwebsite = data['Selectedwebsite']
currentACL = ACLManager.loadedACL(userID)
admin = Administrator.objects.get(pk=userID) admin = Administrator.objects.get(pk=userID)
if ACLManager.checkOwnership(str(Selectedwebsite), admin, currentACL) == 1:
pass
else:
return ACLManager.loadError()
obj = Websites.objects.get(domain = str(Selectedwebsite), admin = admin) obj = Websites.objects.get(domain = str(Selectedwebsite), admin = admin)
#/home/cyberpanel.net/.config/rclone/rclone.conf #/home/cyberpanel.net/.config/rclone/rclone.conf
path = '/home/%s/.config/rclone/rclone.conf' %(obj.domain) path = '/home/%s/.config/rclone/rclone.conf' %(obj.domain)
@@ -859,8 +877,6 @@ def selectwebsiteRetorev2(request):
final_json = json.dumps(final_dic) final_json = json.dumps(final_dic)
return HttpResponse(final_json) return HttpResponse(final_json)
def ConfigureSftpV2Backup(request): def ConfigureSftpV2Backup(request):
try: try:
userID = request.session['userID'] userID = request.session['userID']
@@ -869,8 +885,14 @@ def ConfigureSftpV2Backup(request):
sfptpasswd = data['sfptpasswd'] sfptpasswd = data['sfptpasswd']
hostName = data['hostName'] hostName = data['hostName']
UserName = data['UserName'] UserName = data['UserName']
currentACL = ACLManager.loadedACL(userID)
admin = Administrator.objects.get(pk=userID) admin = Administrator.objects.get(pk=userID)
if ACLManager.checkOwnership(str(Selectedwebsite), admin, currentACL) == 1:
pass
else:
return ACLManager.loadError()
req_data = {} req_data = {}
req_data['name'] = 'SFTP' req_data['name'] = 'SFTP'
req_data['host'] = hostName req_data['host'] = hostName
@@ -895,15 +917,21 @@ def ConfigureSftpV2Backup(request):
final_json = json.dumps(final_dic) final_json = json.dumps(final_dic)
return HttpResponse(final_json) return HttpResponse(final_json)
def selectwebsiteCreatev2(request): def selectwebsiteCreatev2(request):
import re import re
try: try:
userID = request.session['userID'] userID = request.session['userID']
data = json.loads(request.body) data = json.loads(request.body)
Selectedwebsite = data['Selectedwebsite'] Selectedwebsite = data['Selectedwebsite']
currentACL = ACLManager.loadedACL(userID)
admin = Administrator.objects.get(pk=userID) admin = Administrator.objects.get(pk=userID)
if ACLManager.checkOwnership(str(Selectedwebsite), admin, currentACL) == 1:
pass
else:
return ACLManager.loadError()
obj = Websites.objects.get(domain = str(Selectedwebsite), admin = admin) obj = Websites.objects.get(domain = str(Selectedwebsite), admin = admin)
#/home/cyberpanel.net/.config/rclone/rclone.conf #/home/cyberpanel.net/.config/rclone/rclone.conf
path = '/home/%s/.config/rclone/rclone.conf' %(obj.domain) path = '/home/%s/.config/rclone/rclone.conf' %(obj.domain)
@@ -963,15 +991,21 @@ def selectwebsiteCreatev2(request):
final_json = json.dumps(final_dic) final_json = json.dumps(final_dic)
return HttpResponse(final_json) return HttpResponse(final_json)
def selectreporestorev2(request): def selectreporestorev2(request):
try: try:
userID = request.session['userID'] userID = request.session['userID']
data = json.loads(request.body) data = json.loads(request.body)
Selectedrepo = data['Selectedrepo'] Selectedrepo = data['Selectedrepo']
Selectedwebsite= data['Selectedwebsite'] Selectedwebsite= data['Selectedwebsite']
currentACL = ACLManager.loadedACL(userID)
admin = Administrator.objects.get(pk=userID) admin = Administrator.objects.get(pk=userID)
if ACLManager.checkOwnership(str(Selectedwebsite), admin, currentACL) == 1:
pass
else:
return ACLManager.loadError()
# f'rustic -r testremote snapshots --password "" --json 2>/dev/null' # f'rustic -r testremote snapshots --password "" --json 2>/dev/null'
# final_json = json.dumps({'status': 0, 'fetchStatus': 1, 'error_message': Selectedrepo }) # final_json = json.dumps({'status': 0, 'fetchStatus': 1, 'error_message': Selectedrepo })
# return HttpResponse(final_json) # return HttpResponse(final_json)

View File

@@ -3,78 +3,80 @@
{% block title %}{% trans "Manage SSL - CyberPanel" %}{% endblock %} {% block title %}{% trans "Manage SSL - CyberPanel" %}{% endblock %}
{% block content %} {% block content %}
{% load static %} {% load static %}
{% get_current_language as LANGUAGE_CODE %} {% get_current_language as LANGUAGE_CODE %}
<!-- Current language: {{ LANGUAGE_CODE }} --> <!-- Current language: {{ LANGUAGE_CODE }} -->
<div class="container">
<div id="page-title">
<h2>{% trans "Manage SSL" %} - <a target="_blank" href="http://go.cyberpanel.net/ssl-docs" style="height: 23px;line-height: 21px;" class="btn btn-border btn-alt border-red btn-link font-red" title=""><span>{% trans "SSL Docs" %}</span></a></h2>
<p>{% trans "This page can be used to issue Lets Encrypt SSL for existing websites on server." %}</p>
</div>
<div ng-controller="sslIssueCtrl" class="panel">
<div class="panel-body">
<h3 class="content-box-header">
{% trans "Manage SSL" %} <img ng-hide="manageSSLLoading" src="{% static 'images/loading.gif' %}">
</h3>
<div class="example-box-wrapper">
<form action="/" class="form-horizontal bordered-row panel-body">
<div class="form-group">
<label class="col-sm-3 control-label">{% trans "Select Website" %} </label>
<div class="col-sm-6">
<select ng-change="showbtn()" ng-model="virtualHost" class="form-control">
{% for items in websiteList %}
<option>{{ items }}</option>
{% endfor %}
</select>
</div>
</div>
<div ng-hide="issueSSLBtn" class="form-group">
<label class="col-sm-3 control-label"></label>
<div class="col-sm-4">
<button type="button" ng-click="issueSSL()" class="btn btn-primary btn-lg">{% trans "Issue SSL" %}</button>
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label"></label>
<div class="col-sm-6">
<div ng-hide="canNotIssue" class="alert alert-danger">
<p>{% trans "Cannot issue SSL. Error message:" %} {$ errorMessage $}</p>
</div>
<div ng-hide="sslIssued" class="alert alert-success">
<p>{% trans "SSL Issued for" %} <strong>{$ sslDomain $}</strong></p>
</div>
<div ng-hide="couldNotConnect" class="alert alert-danger">
<p>{% trans "Could not connect to server. Please refresh this page." %}</p>
</div>
</div>
</div>
</form>
<div class="container">
<div id="page-title">
<h2>{% trans "Manage SSL" %} - <a target="_blank" href="http://go.cyberpanel.net/ssl-docs"
style="height: 23px;line-height: 21px;"
class="btn btn-border btn-alt border-red btn-link font-red"
title=""><span>{% trans "SSL Docs" %}</span></a></h2>
<p>{% trans "This page can be used to issue Lets Encrypt SSL for existing websites on server." %}</p>
</div> </div>
<div ng-controller="sslIssueCtrl" class="panel">
<div class="panel-body">
<h3 class="content-box-header">
{% trans "Manage SSL" %} <img ng-hide="manageSSLLoading" src="{% static 'images/loading.gif' %}">
</h3>
<div class="example-box-wrapper">
<form action="/" class="form-horizontal bordered-row panel-body">
<div class="form-group">
<label class="col-sm-3 control-label">{% trans "Select Website" %} </label>
<div class="col-sm-6">
<select ng-change="showbtn()" ng-model="virtualHost" class="form-control">
{% for items in websiteList %}
<option>{{ items }}</option>
{% endfor %}
</select>
</div>
</div>
<div ng-hide="issueSSLBtn" class="form-group">
<label class="col-sm-3 control-label"></label>
<div class="col-sm-4">
<button type="button" ng-click="issueSSL()"
class="btn btn-primary btn-lg">{% trans "Issue SSL" %}</button>
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label"></label>
<div class="col-sm-6">
<div ng-hide="canNotIssue" class="alert alert-danger">
<p>{% trans "Cannot issue SSL. Error message:" %} {$ errorMessage $}</p>
</div>
<div ng-hide="sslIssued" class="alert alert-success">
<p>{% trans "SSL Issued for" %} <strong>{$ sslDomain $}</strong></p>
</div>
<div ng-hide="couldNotConnect" class="alert alert-danger">
<p>{% trans "Could not connect to server. Please refresh this page." %}</p>
</div>
</div>
</div>
</form>
</div>
</div>
</div>
</div> </div>
</div>
</div>
{% endblock %} {% endblock %}

View File

@@ -19,17 +19,25 @@
<div ng-controller="sslIssueCtrlV2" class="panel"> <div ng-controller="sslIssueCtrlV2" class="panel">
<div class="panel-body"> <div class="panel-body">
<h3 class="content-box-header"> <h3 class="content-box-header">
{% trans "Add Records" %} {% trans "SSL v2" %}
</h3> </h3>
<div class="example-box-wrapper"> <div class="example-box-wrapper">
{% if SaveSuccess %}
<div class="form-group">
<label class="col-sm-3 control-label"></label>
<div class="col-sm-6">
<div class="alert alert-success">
<p>{% trans "Changes saved succesfully." %}</p>
</div>
</div>
</div>
{% endif %}
<ul class="nav nav-tabs"> <ul class="nav nav-tabs">
<li class="col-md-4 nav-item tab-mod active"> <li class="col-md-4 nav-item tab-mod active">
<a href="#tab-example-1" data-toggle="tab" class="h4 nav-link"> <a href="#tab-example-1" data-toggle="tab" class="h4 nav-link">
<i class="fa fa-cog btn-icon"></i> <i class="fa fa-cog btn-icon"></i>
<span>{% trans "Manage DNS" %}</span> <span>{% trans "Issue SSL" %}</span>
</a> </a>
</li> </li>
@@ -86,7 +94,9 @@
<div class="tab-pane fade" id="tab-example-3"> <div class="tab-pane fade" id="tab-example-3">
<form action="/" class="form-horizontal bordered-row panel-body"> <form method="post" action="{% url 'v2ManageSSL' %}"
class="form-horizontal bordered-row panel-body">
{% csrf_token %}
<h2 style="margin-bottom: 2%">{% trans "Cloudflare Settings" %}</h2> <h2 style="margin-bottom: 2%">{% trans "Cloudflare Settings" %}</h2>
@@ -110,51 +120,7 @@
<div class="form-group"> <div class="form-group">
<label class="col-sm-3 control-label"></label> <label class="col-sm-3 control-label"></label>
<div class="col-sm-4"> <div class="col-sm-4">
<button type="button" ng-click="saveCFConfigs()" <button type="submit" class="btn btn-primary btn-lg">{% trans "Save" %}</button>
class="btn btn-primary btn-lg">{% trans "Save" %}</button>
</div>
</div>
<!----- Godaddy --->
<h2 style="margin-bottom: 2%">{% trans "Godaddy Settings" %}</h2>
<div class="form-group">
<label class="col-sm-3 control-label">{% trans "CloudFlare Email" %}</label>
<div class="col-sm-6">
<input ng-init="cfEmail='{{ cfEmail }}'" name="cfEmail" type="text"
class="form-control"
ng-model="cfEmail"
required>
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">{% trans "API Token" %}</label>
<div class="col-sm-6">
<input ng-init="cfToken='{{ cfToken }}'" name="cfToken" type="text"
class="form-control"
ng-model="cfToken"
required>
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">{% trans "Sync local Records to CloudFlare" %} </label>
<div class="col-sm-6">
<select ng-model="cfSync" class="form-control">
<option>Enable</option>
<option>Disable</option>
</select>
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label"></label>
<div class="col-sm-4">
<button type="button" ng-click="saveCFConfigs()"
class="btn btn-primary btn-lg">{% trans "Save" %}</button>
</div> </div>
</div> </div>

View File

@@ -32,12 +32,21 @@ def v2ManageSSL(request):
currentACL = ACLManager.loadedACL(userID) currentACL = ACLManager.loadedACL(userID)
websitesName = ACLManager.findAllSites(currentACL, userID) websitesName = ACLManager.findAllSites(currentACL, userID)
data = {}
if request.method == 'POST':
SAVED_CF_Key = request.POST.get('SAVED_CF_Key')
SAVED_CF_Email = request.POST.get('SAVED_CF_Email')
from plogical.dnsUtilities import DNS
DNS.ConfigureCloudflareInAcme(SAVED_CF_Key, SAVED_CF_Email)
data['SaveSuccess'] = 1
RetStatus, SAVED_CF_Key, SAVED_CF_Email = ACLManager.FetchCloudFlareAPIKeyFromAcme() RetStatus, SAVED_CF_Key, SAVED_CF_Email = ACLManager.FetchCloudFlareAPIKeyFromAcme()
from plogical.dnsUtilities import DNS from plogical.dnsUtilities import DNS
DNS.ConfigurePowerDNSInAcme() DNS.ConfigurePowerDNSInAcme()
data = {}
data['SAVED_CF_Key'] = SAVED_CF_Key data['SAVED_CF_Key'] = SAVED_CF_Key
data['SAVED_CF_Email'] = SAVED_CF_Email data['SAVED_CF_Email'] = SAVED_CF_Email
data['websiteList'] = websitesName data['websiteList'] = websitesName

View File

@@ -112,10 +112,9 @@ type = sftp
host = {config["host"]} host = {config["host"]}
user = {config["user"]} user = {config["user"]}
pass = {ObsecurePassword} pass = {ObsecurePassword}
''' '''
command = f"echo '{content}' > {self.ConfigFilePath}" command = f"echo '{content}' >> {self.ConfigFilePath}"
ProcessUtilities.executioner(command, self.website.externalApp, True) ProcessUtilities.executioner(command, self.website.externalApp, True)
command = f"chmod 600 {self.ConfigFilePath}" command = f"chmod 600 {self.ConfigFilePath}"
@@ -138,7 +137,7 @@ root_folder_id = ""
service_account_file = "" service_account_file = ""
token = {token} token = {token}
''' '''
command = f"echo '{content}' > {self.ConfigFilePath}" command = f"echo '{content}' >> {self.ConfigFilePath}"
ProcessUtilities.executioner(command, self.website.externalApp, True) ProcessUtilities.executioner(command, self.website.externalApp, True)
command = f"chmod 600 {self.ConfigFilePath}" command = f"chmod 600 {self.ConfigFilePath}"
@@ -429,11 +428,11 @@ token = {token}
return 0 return 0
self.UpdateStatus('Website data backup completed successfully..,70', CPBackupsV2.RUNNING) self.UpdateStatus('Website data backup completed successfully..,70', CPBackupsV2.RUNNING)
# if self.data['BackupEmails']: if self.data['BackupEmails']:
# self.UpdateStatus('Backing up emails..,75', CPBackupsV2.RUNNING) self.UpdateStatus('Backing up emails..,75', CPBackupsV2.RUNNING)
# if self.BackupEmailsRustic() == 0: if self.BackupEmailsRustic() == 0:
# return 0 return 0
# self.UpdateStatus('Emails backup completed successfully..,85', CPBackupsV2.RUNNING) self.UpdateStatus('Emails backup completed successfully..,85', CPBackupsV2.RUNNING)
### Finally change the backup rustic folder to the website user owner ### Finally change the backup rustic folder to the website user owner
@@ -603,7 +602,7 @@ token = {token}
exclude = f' --exclude-if-present rusticbackup --exclude-if-present logs ' exclude = f' --exclude-if-present rusticbackup --exclude-if-present logs '
command = f'rustic -P /home/{self.website.domain}/.config/rclone/rclone.conf -r {self.repo} backup {source} --password "" {exclude} --json 2>/dev/null' command = f'export RCLONE_CONFIG=/home/{self.website.domain}/.config/rclone/rclone.conf && rustic -r {self.repo} backup {source} --password "" {exclude} --json 2>/dev/null'
result = json.loads(ProcessUtilities.outputExecutioner(command, None, True).rstrip('\n')) result = json.loads(ProcessUtilities.outputExecutioner(command, None, True).rstrip('\n'))

View File

@@ -807,7 +807,6 @@ class DNS:
if CurrentContent.find('PDNS_Url') == -1: if CurrentContent.find('PDNS_Url') == -1:
PDNSContent = f""" PDNSContent = f"""
{CurrentContent}
PDNS_Url='http://localhost:8081' PDNS_Url='http://localhost:8081'
PDNS_ServerId='localhost' PDNS_ServerId='localhost'
PDNS_Token='{APIKey}' PDNS_Token='{APIKey}'
@@ -843,3 +842,29 @@ webserver-allow-from=0.0.0.0/0
except BaseException as msg: except BaseException as msg:
logging.CyberCPLogFileWriter.writeToFile(f'ConfigurePowerDNSInAcme, Error: {str(msg)}') logging.CyberCPLogFileWriter.writeToFile(f'ConfigurePowerDNSInAcme, Error: {str(msg)}')
return 0, str(msg) return 0, str(msg)
@staticmethod
def ConfigureCloudflareInAcme(SAVED_CF_Key, SAVED_CF_Email):
try:
## remove existing keys first
path = '/root/.acme.sh/account.conf'
command = f"sed -i '/SAVED_CF_Key/d;/SAVED_CF_Email/d' {path}"
ProcessUtilities.executioner(command)
CFContent = f"""
SAVED_CF_Key='{SAVED_CF_Key}'
SAVED_CF_Email='{SAVED_CF_Email}'
"""
command = f'echo "{CFContent}" >> {path}'
ProcessUtilities.executioner(command, None, True)
return 1, None
except BaseException as msg:
logging.CyberCPLogFileWriter.writeToFile(f'ConfigureCloudflareInAcme, Error: {str(msg)}')
return 0, str(msg)

View File

@@ -329,6 +329,25 @@ class sslUtilities:
@staticmethod @staticmethod
def obtainSSLForADomain(virtualHostName, adminEmail, sslpath, aliasDomain=None): def obtainSSLForADomain(virtualHostName, adminEmail, sslpath, aliasDomain=None):
from plogical.acl import ACLManager
from plogical.sslv2 import sslUtilities as sslv2
import json
url = "https://platform.cyberpersons.com/CyberpanelAdOns/Adonpermission"
data = {
"name": "all",
"IP": ACLManager.GetServerIP()
}
import requests
response = requests.post(url, data=json.dumps(data))
Status = response.json()['status']
if (Status == 1) or ProcessUtilities.decideServer() == ProcessUtilities.ent:
retStatus, message = sslv2.obtainSSLForADomain(virtualHostName, adminEmail, sslpath, aliasDomain)
if retStatus == 1:
return retStatus
sender_email = 'root@%s' % (socket.gethostname()) sender_email = 'root@%s' % (socket.gethostname())
if not os.path.exists('/usr/local/lsws/Example/html/.well-known/acme-challenge'): if not os.path.exists('/usr/local/lsws/Example/html/.well-known/acme-challenge'):

View File

@@ -343,7 +343,7 @@ class sslUtilities:
extractDomain = tldextract.extract(virtualHostName) extractDomain = tldextract.extract(virtualHostName)
topLevelDomain = extractDomain.domain + '.' + extractDomain.suffix topLevelDomain = extractDomain.domain + '.' + extractDomain.suffix
logging.CyberCPLogFileWriter.writeToFile(f'domain: {topLevelDomain}') logging.CyberCPLogFileWriter.writeToFile(f'top level domain in cf: {topLevelDomain}')
import CloudFlare import CloudFlare
params = {'name': topLevelDomain, 'per_page': 50} params = {'name': topLevelDomain, 'per_page': 50}
@@ -356,7 +356,7 @@ class sslUtilities:
for zone in sorted(zones, key=lambda v: v['name']): for zone in sorted(zones, key=lambda v: v['name']):
logging.CyberCPLogFileWriter.writeToFile(f'zone: {zone["name"]}') logging.CyberCPLogFileWriter.writeToFile(f'zone: {zone["name"]}')
if zone['name'] == virtualHostName: if zone['name'] == topLevelDomain:
if zone['status'] == 'active': if zone['status'] == 'active':
return 1, None return 1, None
@@ -417,7 +417,6 @@ class sslUtilities:
else: else:
return 0, 'Domain is not active in any of the configured DNS provider.' return 0, 'Domain is not active in any of the configured DNS provider.'
try: try:
acmePath = '/root/.acme.sh/acme.sh' acmePath = '/root/.acme.sh/acme.sh'
@@ -437,7 +436,7 @@ class sslUtilities:
subprocess.check_output(shlex.split(command)) subprocess.check_output(shlex.split(command))
try: try:
command = acmePath + " --issue -d " + virtualHostName + " -d www." + virtualHostName \ command = acmePath + f" --issue -d *.{virtualHostName}" \
+ ' --cert-file ' + existingCertPath + '/cert.pem' + ' --key-file ' + existingCertPath + '/privkey.pem' \ + ' --cert-file ' + existingCertPath + '/cert.pem' + ' --key-file ' + existingCertPath + '/privkey.pem' \
+ ' --fullchain-file ' + existingCertPath + '/fullchain.pem' + f' --dns {DNS_TO_USE} -k ec-256 --force --server letsencrypt' + ' --fullchain-file ' + existingCertPath + '/fullchain.pem' + f' --dns {DNS_TO_USE} -k ec-256 --force --server letsencrypt'
#ResultText = open(logging.CyberCPLogFileWriter.fileName, 'r').read() #ResultText = open(logging.CyberCPLogFileWriter.fileName, 'r').read()

View File

@@ -1,26 +0,0 @@
import socket
def check_dns_record_socket(domain_name):
"""
Queries the A record for a given domain name using the socket module.
Args:
domain_name (str): The domain name to query.
Returns:
The IP address as a string, or None if the record is not found.
"""
try:
# Query the A record
result = socket.getaddrinfo(domain_name, None, socket.AF_INET)[0]
# Return the IP address as a string
return result[4][0]
except (socket.gaierror, IndexError):
# The domain does not exist or the record is not found
return None
# Check the A record for google.com
result = check_dns_record_socket("wpmautic.net")
print(result) # Output: 216.58.194.174