mirror of
https://github.com/usmannasir/cyberpanel.git
synced 2025-11-08 06:16:08 +01:00
add dns_cyberpanel custom api for acme ssl
This commit is contained in:
@@ -313,7 +313,13 @@ class cyberPanel:
|
|||||||
|
|
||||||
def createDNSRecord(self, virtualHostName, name, recordType, value, priority, ttl):
|
def createDNSRecord(self, virtualHostName, name, recordType, value, priority, ttl):
|
||||||
try:
|
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))
|
DNS.createDNSRecord(zone, name, recordType, value, int(priority), int(ttl))
|
||||||
self.printStatus(1, 'None')
|
self.printStatus(1, 'None')
|
||||||
except BaseException as msg:
|
except BaseException as msg:
|
||||||
|
|||||||
@@ -710,7 +710,7 @@ class DNSManager:
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
zones = cf.zones.get(params=params)
|
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": '[]'})
|
final_json = json.dumps({'status': 0, 'fetchStatus': 0, 'error_message': str(e), "data": '[]'})
|
||||||
return HttpResponse(final_json)
|
return HttpResponse(final_json)
|
||||||
|
|
||||||
@@ -749,7 +749,7 @@ class DNSManager:
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
dns_records = cf.zones.dns_records.get(zone_id, params={'per_page':50, 'type':fetchType})
|
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": '[]'})
|
final_json = json.dumps({'status': 0, 'fetchStatus': 0, 'error_message': str(e), "data": '[]'})
|
||||||
return HttpResponse(final_json)
|
return HttpResponse(final_json)
|
||||||
|
|
||||||
@@ -816,7 +816,7 @@ class DNSManager:
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
zones = cf.zones.get(params=params)
|
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": '[]'})
|
final_json = json.dumps({'status': 0, 'delete_status': 0, 'error_message': str(e), "data": '[]'})
|
||||||
return HttpResponse(final_json)
|
return HttpResponse(final_json)
|
||||||
|
|
||||||
@@ -868,7 +868,7 @@ class DNSManager:
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
zones = cf.zones.get(params=params)
|
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": '[]'})
|
final_json = json.dumps({'status': 0, 'delete_status': 0, 'error_message': str(e), "data": '[]'})
|
||||||
return HttpResponse(final_json)
|
return HttpResponse(final_json)
|
||||||
|
|
||||||
|
|||||||
50
install/dns_cyberpanel.sh
Normal file
50
install/dns_cyberpanel.sh
Normal 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
|
||||||
@@ -2583,6 +2583,16 @@ vmail
|
|||||||
writeToFile.close()
|
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():
|
def main():
|
||||||
parser = argparse.ArgumentParser(description='CyberPanel Installer')
|
parser = argparse.ArgumentParser(description='CyberPanel Installer')
|
||||||
parser.add_argument('publicip', help='Please enter public IP for your VPS or dedicated server.')
|
parser.add_argument('publicip', help='Please enter public IP for your VPS or dedicated server.')
|
||||||
@@ -2734,6 +2744,7 @@ def main():
|
|||||||
checks.setupPort()
|
checks.setupPort()
|
||||||
checks.setupPythonWSGI()
|
checks.setupPythonWSGI()
|
||||||
checks.setupLSCPDDaemon()
|
checks.setupLSCPDDaemon()
|
||||||
|
checks.installDNS_CyberPanelACMEFile()
|
||||||
|
|
||||||
if args.redis is not None:
|
if args.redis is not None:
|
||||||
checks.installRedis()
|
checks.installRedis()
|
||||||
|
|||||||
@@ -220,7 +220,6 @@ context /.well-known/acme-challenge {
|
|||||||
except BaseException as msg:
|
except BaseException as msg:
|
||||||
return 0, str(msg)
|
return 0, str(msg)
|
||||||
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def installSSLForDomain(virtualHostName, adminEmail='example@example.org'):
|
def installSSLForDomain(virtualHostName, adminEmail='example@example.org'):
|
||||||
|
|
||||||
|
|||||||
@@ -361,6 +361,8 @@ class sslUtilities:
|
|||||||
if zone['name'] == topLevelDomain:
|
if zone['name'] == topLevelDomain:
|
||||||
if zone['status'] == 'active':
|
if zone['status'] == 'active':
|
||||||
return 1, None
|
return 1, None
|
||||||
|
else:
|
||||||
|
logging.CyberCPLogFileWriter.writeToFile(f'zone is not active in cf: {zone["name"]}')
|
||||||
|
|
||||||
return 0, 'Zone not found in Cloudflare'
|
return 0, 'Zone not found in Cloudflare'
|
||||||
|
|
||||||
@@ -387,6 +389,8 @@ class sslUtilities:
|
|||||||
|
|
||||||
result = socket.getaddrinfo(f'cptest.{topLevelDomain}', None, socket.AF_INET)[0]
|
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
|
# Return the IP address as a string
|
||||||
if result[4][0] == ACLManager.GetServerIP():
|
if result[4][0] == ACLManager.GetServerIP():
|
||||||
return 1, None
|
return 1, None
|
||||||
@@ -426,7 +430,7 @@ class sslUtilities:
|
|||||||
CyberPanel_Check, message = sslUtilities.FindIfDomainInPowerDNS(virtualHostName)
|
CyberPanel_Check, message = sslUtilities.FindIfDomainInPowerDNS(virtualHostName)
|
||||||
|
|
||||||
if CyberPanel_Check:
|
if CyberPanel_Check:
|
||||||
DNS_TO_USE = 'dns_pdns'
|
DNS_TO_USE = 'dns_cyberpanel'
|
||||||
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.'
|
||||||
|
|
||||||
|
|||||||
@@ -3594,6 +3594,8 @@ pm.max_spare_servers = 3
|
|||||||
command = 'chmod +x /usr/local/CyberCP/public/imunifyav/bin/execute.py'
|
command = 'chmod +x /usr/local/CyberCP/public/imunifyav/bin/execute.py'
|
||||||
Upgrade.executioner(command, command, 1)
|
Upgrade.executioner(command, command, 1)
|
||||||
|
|
||||||
|
Upgrade.installDNS_CyberPanelACMEFile()
|
||||||
|
|
||||||
Upgrade.stdOut("Upgrade Completed.")
|
Upgrade.stdOut("Upgrade Completed.")
|
||||||
|
|
||||||
### remove log file path incase its there
|
### remove log file path incase its there
|
||||||
@@ -3842,6 +3844,17 @@ pm.max_spare_servers = 3
|
|||||||
else:
|
else:
|
||||||
print("Quotas can not be enabled continue to use chhtr.")
|
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():
|
def main():
|
||||||
parser = argparse.ArgumentParser(description='CyberPanel Installer')
|
parser = argparse.ArgumentParser(description='CyberPanel Installer')
|
||||||
|
|||||||
Reference in New Issue
Block a user