add dns_cyberpanel custom api for acme ssl

This commit is contained in:
usmannasir
2024-10-05 21:47:16 +05:00
parent d6e883ece8
commit afea741bfa
7 changed files with 90 additions and 7 deletions

View File

@@ -313,7 +313,13 @@ class cyberPanel:
def createDNSRecord(self, virtualHostName, name, recordType, value, priority, ttl):
try:
zone = DNS.getZoneObject(virtualHostName)
import tldextract
no_cache_extract = tldextract.TLDExtract(cache_dir=None)
extractDomain = no_cache_extract(virtualHostName)
topLevelDomain = extractDomain.domain + '.' + extractDomain.suffix
zone = DNS.getZoneObject(topLevelDomain)
DNS.createDNSRecord(zone, name, recordType, value, int(priority), int(ttl))
self.printStatus(1, 'None')
except BaseException as msg:

View File

@@ -710,7 +710,7 @@ class DNSManager:
try:
zones = cf.zones.get(params=params)
except CloudFlare.CloudFlareAPIError as e:
except BaseException as e:
final_json = json.dumps({'status': 0, 'fetchStatus': 0, 'error_message': str(e), "data": '[]'})
return HttpResponse(final_json)
@@ -749,7 +749,7 @@ class DNSManager:
try:
dns_records = cf.zones.dns_records.get(zone_id, params={'per_page':50, 'type':fetchType})
except CloudFlare.exceptions.CloudFlareAPIError as e:
except BaseException as e:
final_json = json.dumps({'status': 0, 'fetchStatus': 0, 'error_message': str(e), "data": '[]'})
return HttpResponse(final_json)
@@ -816,7 +816,7 @@ class DNSManager:
try:
zones = cf.zones.get(params=params)
except CloudFlare.CloudFlareAPIError as e:
except BaseException as e:
final_json = json.dumps({'status': 0, 'delete_status': 0, 'error_message': str(e), "data": '[]'})
return HttpResponse(final_json)
@@ -868,7 +868,7 @@ class DNSManager:
try:
zones = cf.zones.get(params=params)
except CloudFlare.CloudFlareAPIError as e:
except BaseException as e:
final_json = json.dumps({'status': 0, 'delete_status': 0, 'error_message': str(e), "data": '[]'})
return HttpResponse(final_json)

50
install/dns_cyberpanel.sh Normal file
View File

@@ -0,0 +1,50 @@
#!/usr/bin/env sh
# shellcheck disable=SC2034
dns_myapi_info='CyberPanel script for ACME to add records to PDNS
A sample custom DNS API script.
Domains: example.com
Site: github.com/acmesh-official/acme.sh/wiki/DNS-API-Dev-Guide
Docs: github.com/acmesh-official/acme.sh/wiki/dnsapi#dns_duckdns
Options:
MYAPI_Token API Token. Get API Token from https://example.com/api/. Optional.
Issues: github.com/usmannasir/cyberpanel
Author: Neil Pang <usman@cyberpersons.com>
'
# This file name is "dns_myapi.sh"
# So, here must be a method dns_myapi_add()
# Which will be called by acme.sh to add the txt record to your API system.
# Returns 0 means success, otherwise error.
######## Public functions #####################
# Please Read this guide first: https://github.com/acmesh-official/acme.sh/wiki/DNS-API-Dev-Guide
# Usage: dns_myapi_add _acme-challenge.www.domain.com "XKrxpRBosdIKFzxW_CT3KLZNf6q0HG9i01zxXp5CPBs"
dns_cyberpanel_add() {
fulldomain=$1
txtvalue=$2
_info "Using myapi"
_debug fulldomain "$fulldomain"
_debug txtvalue "$txtvalue"
_info "cyberpanel createDNSRecord --domainName $fulldomain --name $fulldomain --recordType TXT --value $txtvalue --priority 0 --ttl 3600"
cyberpanel createDNSRecord --domainName $fulldomain --name $fulldomain --recordType TXT --value $txtvalue --priority 0 --ttl 3600
return 0
}
# Usage: fulldomain txtvalue
# Remove the txt record after validation.
dns_cyberpanel_rm() {
fulldomain=$1
txtvalue=$2
_info "Using myapi"
_debug fulldomain "$fulldomain"
_debug txtvalue "$txtvalue"
return 0
}
#################### Private functions below ##################################
# You can add private helper functions here if needed

View File

@@ -2583,6 +2583,16 @@ vmail
writeToFile.close()
def installDNS_CyberPanelACMEFile(self):
os.chdir(self.cwd)
filePath = '/root/.acme.sh/dns_cyberpanel.sh'
shutil.copy('dns_cyberpanel.sh', filePath)
command = f'chmod +x {filePath}'
preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR)
def main():
parser = argparse.ArgumentParser(description='CyberPanel Installer')
parser.add_argument('publicip', help='Please enter public IP for your VPS or dedicated server.')
@@ -2734,6 +2744,7 @@ def main():
checks.setupPort()
checks.setupPythonWSGI()
checks.setupLSCPDDaemon()
checks.installDNS_CyberPanelACMEFile()
if args.redis is not None:
checks.installRedis()

View File

@@ -220,7 +220,6 @@ context /.well-known/acme-challenge {
except BaseException as msg:
return 0, str(msg)
@staticmethod
def installSSLForDomain(virtualHostName, adminEmail='example@example.org'):

View File

@@ -361,6 +361,8 @@ class sslUtilities:
if zone['name'] == topLevelDomain:
if zone['status'] == 'active':
return 1, None
else:
logging.CyberCPLogFileWriter.writeToFile(f'zone is not active in cf: {zone["name"]}')
return 0, 'Zone not found in Cloudflare'
@@ -387,6 +389,8 @@ class sslUtilities:
result = socket.getaddrinfo(f'cptest.{topLevelDomain}', None, socket.AF_INET)[0]
logging.CyberCPLogFileWriter.writeToFile(f'PDNS Result: {str(result)}.')
# Return the IP address as a string
if result[4][0] == ACLManager.GetServerIP():
return 1, None
@@ -426,7 +430,7 @@ class sslUtilities:
CyberPanel_Check, message = sslUtilities.FindIfDomainInPowerDNS(virtualHostName)
if CyberPanel_Check:
DNS_TO_USE = 'dns_pdns'
DNS_TO_USE = 'dns_cyberpanel'
else:
return 0, 'Domain is not active in any of the configured DNS provider.'

View File

@@ -3594,6 +3594,8 @@ pm.max_spare_servers = 3
command = 'chmod +x /usr/local/CyberCP/public/imunifyav/bin/execute.py'
Upgrade.executioner(command, command, 1)
Upgrade.installDNS_CyberPanelACMEFile()
Upgrade.stdOut("Upgrade Completed.")
### remove log file path incase its there
@@ -3842,6 +3844,17 @@ pm.max_spare_servers = 3
else:
print("Quotas can not be enabled continue to use chhtr.")
@staticmethod
def installDNS_CyberPanelACMEFile():
filePath = '/root/.acme.sh/dns_cyberpanel.sh'
if os.path.exists(filePath):
os.remove(filePath)
shutil.copy('/usr/local/CyberCP/install/dns_cyberpanel.sh', filePath)
command = f'chmod +x {filePath}'
Upgrade.executioner(command, command, 0, True)
def main():
parser = argparse.ArgumentParser(description='CyberPanel Installer')