mirror of
https://github.com/usmannasir/cyberpanel.git
synced 2025-11-07 05:45:59 +01:00
add online event
This commit is contained in:
@@ -2822,3 +2822,110 @@ class CloudManager:
|
|||||||
final_dic = {'status': 0, 'fetchStatus': 0, 'error_message': str(msg)}
|
final_dic = {'status': 0, 'fetchStatus': 0, 'error_message': str(msg)}
|
||||||
final_json = json.dumps(final_dic)
|
final_json = json.dumps(final_dic)
|
||||||
return HttpResponse(final_json)
|
return HttpResponse(final_json)
|
||||||
|
|
||||||
|
def SwitchDNS(self):
|
||||||
|
try:
|
||||||
|
|
||||||
|
command = 'chown -R cyberpanel:cyberpanel /usr/local/CyberCP/lib/python3.8/site-packages/tldextract/.suffix_cache/'
|
||||||
|
ProcessUtilities.executioner(command)
|
||||||
|
|
||||||
|
##
|
||||||
|
|
||||||
|
ipFile = "/etc/cyberpanel/machineIP"
|
||||||
|
f = open(ipFile)
|
||||||
|
ipData = f.read()
|
||||||
|
ipAddress = ipData.split('\n', 1)[0]
|
||||||
|
|
||||||
|
##
|
||||||
|
|
||||||
|
import CloudFlare
|
||||||
|
cf = CloudFlare.CloudFlare(email=self.data['cfemail'], token=self.data['apikey'])
|
||||||
|
|
||||||
|
zones = cf.zones.get(params = {'per_page':100})
|
||||||
|
|
||||||
|
for website in Websites.objects.all():
|
||||||
|
import tldextract
|
||||||
|
extractDomain = tldextract.extract(website.domain)
|
||||||
|
topLevelDomain = extractDomain.domain + '.' + extractDomain.suffix
|
||||||
|
|
||||||
|
for zone in zones:
|
||||||
|
if topLevelDomain == zone['name']:
|
||||||
|
try:
|
||||||
|
dns_records = cf.zones.dns_records.get(zone['id'], params={'name': website.domain})
|
||||||
|
|
||||||
|
for dns_record in dns_records:
|
||||||
|
|
||||||
|
r_zone_id = dns_record['zone_id']
|
||||||
|
r_id = dns_record['id']
|
||||||
|
r_name = dns_record['name']
|
||||||
|
r_type = dns_record['type']
|
||||||
|
r_ttl = dns_record['ttl']
|
||||||
|
r_proxied = dns_record['proxied']
|
||||||
|
|
||||||
|
|
||||||
|
dns_record_id = dns_record['id']
|
||||||
|
|
||||||
|
new_dns_record = {
|
||||||
|
'zone_id': r_zone_id,
|
||||||
|
'id': r_id,
|
||||||
|
'type': r_type,
|
||||||
|
'name': r_name,
|
||||||
|
'content': ipAddress,
|
||||||
|
'ttl': r_ttl,
|
||||||
|
'proxied': r_proxied
|
||||||
|
}
|
||||||
|
|
||||||
|
cf.zones.dns_records.put(zone['id'], dns_record_id, data=new_dns_record)
|
||||||
|
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
|
### For child domainsa
|
||||||
|
|
||||||
|
from websiteFunctions.models import ChildDomains
|
||||||
|
for website in ChildDomains.objects.all():
|
||||||
|
|
||||||
|
import tldextract
|
||||||
|
extractDomain = tldextract.extract(website.domain)
|
||||||
|
topLevelDomain = extractDomain.domain + '.' + extractDomain.suffix
|
||||||
|
|
||||||
|
for zone in zones:
|
||||||
|
if topLevelDomain == zone['name']:
|
||||||
|
try:
|
||||||
|
dns_records = cf.zones.dns_records.get(zone['id'], params={'name': website.domain})
|
||||||
|
|
||||||
|
for dns_record in dns_records:
|
||||||
|
|
||||||
|
r_zone_id = dns_record['zone_id']
|
||||||
|
r_id = dns_record['id']
|
||||||
|
r_name = dns_record['name']
|
||||||
|
r_type = dns_record['type']
|
||||||
|
r_ttl = dns_record['ttl']
|
||||||
|
r_proxied = dns_record['proxied']
|
||||||
|
|
||||||
|
|
||||||
|
dns_record_id = dns_record['id']
|
||||||
|
|
||||||
|
new_dns_record = {
|
||||||
|
'zone_id': r_zone_id,
|
||||||
|
'id': r_id,
|
||||||
|
'type': r_type,
|
||||||
|
'name': r_name,
|
||||||
|
'content': ipAddress,
|
||||||
|
'ttl': r_ttl,
|
||||||
|
'proxied': r_proxied
|
||||||
|
}
|
||||||
|
|
||||||
|
cf.zones.dns_records.put(zone['id'], dns_record_id, data=new_dns_record)
|
||||||
|
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
|
final_json = json.dumps({'status': 1})
|
||||||
|
return HttpResponse(final_json)
|
||||||
|
|
||||||
|
except BaseException as msg:
|
||||||
|
logging.writeToFile(str(msg))
|
||||||
|
final_dic = {'status': 0, 'fetchStatus': 0, 'error_message': str(msg)}
|
||||||
|
final_json = json.dumps(final_dic)
|
||||||
|
return HttpResponse(final_json)
|
||||||
|
|||||||
@@ -56,6 +56,8 @@ def router(request):
|
|||||||
return cm.CreatePendingVirtualHosts()
|
return cm.CreatePendingVirtualHosts()
|
||||||
elif controller == 'BootMaster':
|
elif controller == 'BootMaster':
|
||||||
return cm.BootMaster()
|
return cm.BootMaster()
|
||||||
|
elif controller == 'SwitchDNS':
|
||||||
|
return cm.SwitchDNS()
|
||||||
elif controller == 'BootChild':
|
elif controller == 'BootChild':
|
||||||
return cm.BootChild()
|
return cm.BootChild()
|
||||||
elif controller == 'SetupCluster':
|
elif controller == 'SetupCluster':
|
||||||
|
|||||||
@@ -193,7 +193,7 @@ Server_IP=$(curl --silent --max-time 30 -4 https://cyberpanel.sh/?ip)
|
|||||||
echo -e "Valid IP detected..."
|
echo -e "Valid IP detected..."
|
||||||
else
|
else
|
||||||
echo -e "Can not detect IP, exit..."
|
echo -e "Can not detect IP, exit..."
|
||||||
Debug_Log2 "Can not detect IP"
|
Debug_Log2 "Can not detect IP. [404]"
|
||||||
exit
|
exit
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|||||||
@@ -2,9 +2,13 @@ import json
|
|||||||
import os.path
|
import os.path
|
||||||
import sys
|
import sys
|
||||||
import argparse
|
import argparse
|
||||||
|
import django
|
||||||
import requests
|
import requests
|
||||||
sys.path.append('/usr/local/CyberCP')
|
sys.path.append('/usr/local/CyberCP')
|
||||||
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "CyberCP.settings")
|
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "CyberCP.settings")
|
||||||
|
django.setup()
|
||||||
|
from firewall.models import FirewallRules
|
||||||
|
from plogical.firewallUtilities import FirewallUtilities
|
||||||
from plogical.processUtilities import ProcessUtilities
|
from plogical.processUtilities import ProcessUtilities
|
||||||
from plogical.CyberCPLogFileWriter import CyberCPLogFileWriter as logging
|
from plogical.CyberCPLogFileWriter import CyberCPLogFileWriter as logging
|
||||||
|
|
||||||
@@ -64,9 +68,11 @@ class ClusterManager:
|
|||||||
config = json.loads(open(ClusterConfigPath, 'r').read())
|
config = json.loads(open(ClusterConfigPath, 'r').read())
|
||||||
|
|
||||||
if self.type == 'Child':
|
if self.type == 'Child':
|
||||||
|
|
||||||
writeToFile = open(ClusterPath, 'w')
|
writeToFile = open(ClusterPath, 'w')
|
||||||
writeToFile.write(config['ClusterConfigFailover'])
|
writeToFile.write(config['ClusterConfigFailover'])
|
||||||
writeToFile.close()
|
writeToFile.close()
|
||||||
|
|
||||||
else:
|
else:
|
||||||
writeToFile = open(ClusterPath, 'w')
|
writeToFile = open(ClusterPath, 'w')
|
||||||
writeToFile.write(config['ClusterConfigMaster'])
|
writeToFile.write(config['ClusterConfigMaster'])
|
||||||
@@ -81,11 +87,47 @@ class ClusterManager:
|
|||||||
|
|
||||||
writeToFile = open(cronPath, 'a')
|
writeToFile = open(cronPath, 'a')
|
||||||
writeToFile.write('*/%s * * * * /usr/local/CyberCP/bin/python /usr/local/CyberCP/plogical/ClusterManager.py --function SyncNow --type Master\n' % (str(self.config['syncTime'])))
|
writeToFile.write('*/%s * * * * /usr/local/CyberCP/bin/python /usr/local/CyberCP/plogical/ClusterManager.py --function SyncNow --type Master\n' % (str(self.config['syncTime'])))
|
||||||
|
writeToFile.write('*/3 * * * * /usr/local/CyberCP/bin/python /usr/local/CyberCP/plogical/ClusterManager.py --function PingNow --type Master\n')
|
||||||
writeToFile.close()
|
writeToFile.close()
|
||||||
|
|
||||||
command = 'systemctl restart cron'
|
command = 'systemctl restart cron'
|
||||||
ProcessUtilities.normalExecutioner(command)
|
ProcessUtilities.normalExecutioner(command)
|
||||||
|
|
||||||
|
try:
|
||||||
|
### MySQL Public
|
||||||
|
|
||||||
|
newFireWallRule = FirewallRules(name="mysqlpub", port='3306', proto="tcp")
|
||||||
|
newFireWallRule.save()
|
||||||
|
FirewallUtilities.addRule('tcp', '3306', "0.0.0.0/0")
|
||||||
|
|
||||||
|
### For Galera Cluster replication traffic.
|
||||||
|
|
||||||
|
newFireWallRule = FirewallRules(name="galery", port='4567', proto="tcp")
|
||||||
|
newFireWallRule.save()
|
||||||
|
FirewallUtilities.addRule('tcp', '4567', "0.0.0.0/0")
|
||||||
|
|
||||||
|
### For Galera Cluster IST
|
||||||
|
|
||||||
|
newFireWallRule = FirewallRules(name="galeryist", port='4568', proto="tcp")
|
||||||
|
newFireWallRule.save()
|
||||||
|
FirewallUtilities.addRule('tcp', '4568', "0.0.0.0/0")
|
||||||
|
|
||||||
|
### For Galera Cluster SST
|
||||||
|
|
||||||
|
newFireWallRule = FirewallRules(name="galerysst", port='4444', proto="tcp")
|
||||||
|
newFireWallRule.save()
|
||||||
|
FirewallUtilities.addRule('tcp', '4444', "0.0.0.0/0")
|
||||||
|
|
||||||
|
### For Galera Cluster replication traffic. (UDP)
|
||||||
|
|
||||||
|
newFireWallRule = FirewallRules(name="galeryudp", port='4567', proto="udp")
|
||||||
|
newFireWallRule.save()
|
||||||
|
FirewallUtilities.addRule('udp', '4567', "0.0.0.0/0")
|
||||||
|
|
||||||
|
except:
|
||||||
|
self.PostStatus('Failed to add Firewall rules, manually open the required ports..')
|
||||||
|
|
||||||
|
|
||||||
self.PostStatus('Successfully attached to cluster. [200]')
|
self.PostStatus('Successfully attached to cluster. [200]')
|
||||||
|
|
||||||
###
|
###
|
||||||
@@ -245,7 +287,7 @@ password=%s""" % (rootdbpassword, rootdbpassword)
|
|||||||
|
|
||||||
self.PostStatus('Syncing SSL certificates to fail over server..')
|
self.PostStatus('Syncing SSL certificates to fail over server..')
|
||||||
|
|
||||||
command = "rsync -avzp -e 'ssh -o StrictHostKeyChecking=no -p %s -i /root/.ssh/cyberpanel' /etc/letsencrypt/ root@%s:/etc" % (
|
command = "rsync -avzp -e 'ssh -o StrictHostKeyChecking=no -p %s -i /root/.ssh/cyberpanel' /etc/letsencrypt root@%s:/etc" % (
|
||||||
self.config['failoverServerSSHPort'], self.config['failoverServerIP'])
|
self.config['failoverServerSSHPort'], self.config['failoverServerIP'])
|
||||||
ProcessUtilities.normalExecutioner(command)
|
ProcessUtilities.normalExecutioner(command)
|
||||||
|
|
||||||
@@ -254,6 +296,12 @@ password=%s""" % (rootdbpassword, rootdbpassword)
|
|||||||
except BaseException as msg:
|
except BaseException as msg:
|
||||||
self.PostStatus('Failed to create pending vhosts, error %s [404].' % (str(msg)))
|
self.PostStatus('Failed to create pending vhosts, error %s [404].' % (str(msg)))
|
||||||
|
|
||||||
|
def PingNow(self):
|
||||||
|
try:
|
||||||
|
self.PostStatus('Master up. [200]')
|
||||||
|
except BaseException as msg:
|
||||||
|
self.PostStatus('Failed to ping cloud for online status, error %s [404].' % (str(msg)))
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
parser = argparse.ArgumentParser(description='CyberPanel Installer')
|
parser = argparse.ArgumentParser(description='CyberPanel Installer')
|
||||||
@@ -276,6 +324,8 @@ def main():
|
|||||||
uc.CreatePendingVirtualHosts()
|
uc.CreatePendingVirtualHosts()
|
||||||
elif args.function == 'SyncNow':
|
elif args.function == 'SyncNow':
|
||||||
uc.SyncNow()
|
uc.SyncNow()
|
||||||
|
elif args.function == 'PingNow':
|
||||||
|
uc.PingNow()
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|||||||
Reference in New Issue
Block a user