diff --git a/WebTerminal/CPWebSocket.py b/WebTerminal/CPWebSocket.py index 9c83e8a38..1b2ee7ee1 100644 --- a/WebTerminal/CPWebSocket.py +++ b/WebTerminal/CPWebSocket.py @@ -13,7 +13,7 @@ import json import threading as multi import time import asyncio - +from plogical.processUtilities import ProcessUtilities class SSHServer(multi.Thread): OKGREEN = '\033[92m' @@ -24,7 +24,8 @@ class SSHServer(multi.Thread): @staticmethod def findSSHPort(): try: - sshData = open('/etc/ssh/sshd_config', 'r').readlines() + + sshData = ProcessUtilities.outputExecutioner('cat /etc/ssh/sshd_config').readlines() for items in sshData: if items.find('Port') > -1: diff --git a/cloudAPI/cloudManager.py b/cloudAPI/cloudManager.py index b2850f8cd..1b0a8e586 100755 --- a/cloudAPI/cloudManager.py +++ b/cloudAPI/cloudManager.py @@ -2484,11 +2484,14 @@ class CloudManager: fm = FirewallManager() fm.addSSHKey(self.admin.pk, self.data) - ## Create backup path so that file can be sent here later. + ## Create backup path so that file can be sent here later. If just submitting the key, no need to create backup folder domain. - BackupPath = '/home/cyberpanel/backups/%s' % (self.data['domain']) - command = 'mkdir -p %s' % (BackupPath) - ProcessUtilities.executioner(command, 'cyberpanel') + try: + BackupPath = '/home/cyberpanel/backups/%s' % (self.data['domain']) + command = 'mkdir -p %s' % (BackupPath) + ProcessUtilities.executioner(command, 'cyberpanel') + except: + pass ### @@ -2689,3 +2692,23 @@ class CloudManager: final_dic = {'status': 0, 'fetchStatus': 0, 'error_message': str(msg)} final_json = json.dumps(final_dic) return HttpResponse(final_json) + + def SetupCluster(self): + try: + + ClusterConfigPath = '/home/cyberpanel/cluster' + writeToFile = open(ClusterConfigPath, 'w') + writeToFile.write(json.dumps(self.data)) + writeToFile.close() + + execPath = "/usr/local/CyberCP/bin/python /usr/local/CyberCP/plogical/ClusterManager.py --function %s --type %s" % ( + 'SetupCluster', type) + ProcessUtilities.popenExecutioner(execPath) + + final_json = json.dumps({'status': 1}) + return HttpResponse(final_json) + + except BaseException as msg: + final_dic = {'status': 0, 'fetchStatus': 0, 'error_message': str(msg)} + final_json = json.dumps(final_dic) + return HttpResponse(final_json) diff --git a/cloudAPI/views.py b/cloudAPI/views.py index 5a66dc7cd..c7c47fb7c 100755 --- a/cloudAPI/views.py +++ b/cloudAPI/views.py @@ -39,6 +39,8 @@ def router(request): return cm.RunServerLevelEmailChecks() elif controller == 'DetachCluster': return cm.DetachCluster() + elif controller == 'SetupCluster': + return cm.SetupCluster() elif controller == 'ReadReport': return cm.ReadReport() elif controller == 'ResetEmailConfigurations': diff --git a/plogical/ClusterManager.py b/plogical/ClusterManager.py index 719a1ecd7..44da71a0f 100644 --- a/plogical/ClusterManager.py +++ b/plogical/ClusterManager.py @@ -60,6 +60,45 @@ class ClusterManager: self.config['masterServerMessage'] = 'Failed to detach, error %s [404].' % (str(msg)) self.PostStatus() + def SetupCluster(self, type): + try: + + ClusterPath = self.FetchMySQLConfigFile() + ClusterConfigPath = '/home/cyberpanel/cluster' + config = json.loads(open(ClusterConfigPath, 'r').read()) + + command = 'systemctl stop mysql' + ProcessUtilities.normalExecutioner(command) + + if type == 'Child': + + writeToFile = open(ClusterPath, 'w') + writeToFile.write(config['ClusterConfigFailover']) + + command = 'systemctl start mysql' + ProcessUtilities.normalExecutioner(command) + + self.config['failoverServerMessage'] = 'Successfully attached to cluster. [200]' + self.PostStatus() + else: + + writeToFile = open(ClusterPath, 'w') + writeToFile.write(config['ClusterConfigMaster']) + + command = 'galera_new_cluster' + ProcessUtilities.normalExecutioner(command) + + self.config['masterServerMessage'] = 'Successfully attached to cluster. [200]' + self.PostStatus() + + except BaseException as msg: + if type == 'Child': + self.config['failoverServerMessage'] = 'Failed to attach, error %s [404].' % (str(msg)) + self.PostStatus() + else: + self.config['masterServerMessage'] = 'Failed to attach, error %s [404].' % (str(msg)) + self.PostStatus() + def main(): parser = argparse.ArgumentParser(description='CyberPanel Installer') @@ -71,7 +110,9 @@ def main(): uc = ClusterManager() if args.function == 'DetachCluster': - uc.DetechFromCluster() + uc.DetechFromCluster(args.type) + elif args.function == 'SetupCluster': + uc.SetupCluster(args.type) if __name__ == "__main__":