mirror of
https://github.com/usmannasir/cyberpanel.git
synced 2025-11-03 03:45:52 +01:00
Changes to backup engine and security improvments.
This commit is contained in:
@@ -527,6 +527,7 @@ app.controller('backupDestinations', function($scope,$http,$timeout) {
|
||||
var data = {
|
||||
IPAddress : $scope.IPAddress,
|
||||
password : $scope.password,
|
||||
backupSSHPort:$scope.backupSSHPort,
|
||||
};
|
||||
|
||||
var config = {
|
||||
|
||||
@@ -37,7 +37,14 @@
|
||||
<div class="form-group">
|
||||
<label class="col-sm-3 control-label">{% trans "Password" %}</label>
|
||||
<div class="col-sm-6">
|
||||
<input placeholder="{% trans "Remote server password for CyberPanel" %}" type="password" class="form-control" ng-model="password" required>
|
||||
<input placeholder="" type="password" class="form-control" ng-model="password" required>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label class="col-sm-3 control-label">{% trans "Port" %}</label>
|
||||
<div class="col-sm-6">
|
||||
<input placeholder="{% trans "Backup server SSH Port, leave empty for 22." %}" type="text" class="form-control" ng-model="backupSSHPort" required>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
@@ -513,6 +513,13 @@ def submitDestinationCreation(request):
|
||||
ipAddress = data['IPAddress']
|
||||
password = data['password']
|
||||
|
||||
port = "22"
|
||||
|
||||
try:
|
||||
port = data['backupSSHPort']
|
||||
except:
|
||||
pass
|
||||
|
||||
if dest.objects.all().count() == 2:
|
||||
final_dic = {'destStatus': 0, 'error_message': "Currently only one remote destination is allowed."}
|
||||
final_json = json.dumps(final_dic)
|
||||
@@ -527,44 +534,36 @@ def submitDestinationCreation(request):
|
||||
|
||||
except:
|
||||
|
||||
keyPath = "/home/cyberpanel/.ssh"
|
||||
|
||||
if not os.path.exists(keyPath):
|
||||
os.makedirs(keyPath)
|
||||
command = "ssh-keygen -f "+keyPath+"/cyberpanel -t rsa -N ''"
|
||||
cmd = shlex.split(command)
|
||||
res = subprocess.call(cmd)
|
||||
setupKeys = backupUtil.backupUtilities.setupSSHKeys(ipAddress,password,port)
|
||||
|
||||
pubKey = keyPath+"/cyberpanel.pub"
|
||||
|
||||
f = open(pubKey)
|
||||
data = f.read()
|
||||
|
||||
finalData = json.dumps({'username': "admin", "password": password,"putSSHKey":data})
|
||||
|
||||
url = "https://" + ipAddress + ":8090/api/putSSHkey"
|
||||
|
||||
r = requests.post(url, data=finalData, verify=False)
|
||||
|
||||
data = json.loads(r.text)
|
||||
|
||||
if data['putSSHKey'] == 1:
|
||||
|
||||
newDest = dest(destLoc=ipAddress)
|
||||
newDest.save()
|
||||
|
||||
writeToFile = open(destinations, "w")
|
||||
writeToFile.writelines(ipAddress + "\n")
|
||||
writeToFile.close()
|
||||
if setupKeys[0] == 1:
|
||||
|
||||
|
||||
backupUtil.backupUtilities.initiateBackupDirCreation(ipAddress)
|
||||
|
||||
backupUtil.backupUtilities.initiateBackupDirCreation(ipAddress,port)
|
||||
|
||||
try:
|
||||
writeToFile = open(destinations, "w")
|
||||
writeToFile.writelines(ipAddress + "\n")
|
||||
writeToFile.writelines(data['backupSSHPort'] + "\n")
|
||||
writeToFile.close()
|
||||
newDest = dest(destLoc=ipAddress)
|
||||
newDest.save()
|
||||
except:
|
||||
writeToFile = open(destinations, "w")
|
||||
writeToFile.writelines(ipAddress + "\n")
|
||||
writeToFile.writelines("22"+"\n")
|
||||
writeToFile.close()
|
||||
newDest = dest(destLoc=ipAddress)
|
||||
newDest.save()
|
||||
|
||||
|
||||
final_dic = {'destStatus': 1, 'error_message': "None"}
|
||||
final_json = json.dumps(final_dic)
|
||||
return HttpResponse(final_json)
|
||||
else:
|
||||
final_dic = {'destStatus': 0, 'error_message': data['error_message']}
|
||||
final_dic = {'destStatus': 0, 'error_message': setupKeys[1]}
|
||||
final_json = json.dumps(final_dic)
|
||||
return HttpResponse(final_json)
|
||||
|
||||
|
||||
@@ -99,6 +99,9 @@ app.controller('adminController', function($scope,$http,$timeout) {
|
||||
$scope.currentAdmin = response.data.user_name;
|
||||
$scope.admin_type = response.data.admin_type;
|
||||
|
||||
|
||||
$("#serverIPAddress").text(response.data.serverIPAddress);
|
||||
|
||||
if (response.data.admin_type != "Administrator")
|
||||
{
|
||||
|
||||
|
||||
@@ -410,11 +410,15 @@
|
||||
<ul id="sidebar-menu">
|
||||
<li class="header"><span>{% trans "Overview" %}</span></li>
|
||||
<li>
|
||||
<a href="#" title="{% trans 'Server IP Address' %}">
|
||||
<i class="glyph-icon tooltip-button icon-laptop" title="{% trans 'Server IP Address' %}" data-original-title=".icon-laptop"></i>
|
||||
<span style="color: #db6868;font-weight: bold;" id="serverIPAddress"></span>
|
||||
</a>
|
||||
<a href="{% url 'index' %}" title="{% trans 'Dashboard' %}">
|
||||
<i class="glyph-icon icon-linecons-tv"></i>
|
||||
<span>{% trans "Dashboard" %}</span>
|
||||
</a>
|
||||
<a href="{% url 'versionManagment' %}" title="{% trans 'Dashboard' %}">
|
||||
<a href="{% url 'versionManagment' %}" title="{% trans 'Version Management' %}">
|
||||
<i class="glyph-icon tooltip-button icon-cloud-upload" title="{% trans 'Version Management' %}" data-original-title=".icon-cloud-upload" aria-describedby="tooltip896208"></i>
|
||||
<span>{% trans "Version Management" %}</span>
|
||||
</a>
|
||||
|
||||
@@ -46,9 +46,16 @@ def getAdminStatus(request):
|
||||
else:
|
||||
admin_type = "Normal User"
|
||||
|
||||
serverIPAddress = "192.168.100.1"
|
||||
|
||||
try:
|
||||
serverIPAddress = requests.get('https://api.ipify.org').text
|
||||
except:
|
||||
pass
|
||||
|
||||
adminName = administrator.firstName + " " + administrator.lastName
|
||||
|
||||
adminData = {"admin_type":admin_type,"user_name":adminName}
|
||||
adminData = {"admin_type":admin_type,"user_name":adminName,"serverIPAddress":serverIPAddress}
|
||||
|
||||
json_data = json.dumps(adminData)
|
||||
|
||||
|
||||
@@ -10,6 +10,7 @@ from plogical.firewallUtilities import FirewallUtilities
|
||||
from .models import FirewallRules
|
||||
import os
|
||||
from loginSystem.models import Administrator
|
||||
import plogical.CyberCPLogFileWriter as logging
|
||||
# Create your views here.
|
||||
|
||||
|
||||
@@ -395,7 +396,7 @@ def getSSHConfigs(request):
|
||||
final_json = json.dumps(final_dic)
|
||||
return HttpResponse(final_json)
|
||||
except KeyError,msg:
|
||||
final_dic = {'v': 0, 'error_message': "Not Logged In, please refresh the page or login again."}
|
||||
final_dic = {'status': 0, 'error_message': "Not Logged In, please refresh the page or login again."}
|
||||
final_json = json.dumps(final_dic)
|
||||
return HttpResponse(final_json)
|
||||
|
||||
@@ -421,7 +422,7 @@ def saveSSHConfigs(request):
|
||||
res = subprocess.call(cmd)
|
||||
|
||||
|
||||
FirewallUtilities.addRule('tcp',sshPort)
|
||||
FirewallUtilities.addRule('tcp',sshPort,"0.0.0.0/0")
|
||||
|
||||
try:
|
||||
updateFW = FirewallRules.objects.get(name="SSHCustom")
|
||||
@@ -429,8 +430,11 @@ def saveSSHConfigs(request):
|
||||
updateFW.port = sshPort
|
||||
updateFW.save()
|
||||
except:
|
||||
newFireWallRule = FirewallRules(name="SSHCustom",port=sshPort,proto="tcp")
|
||||
newFireWallRule.save()
|
||||
try:
|
||||
newFireWallRule = FirewallRules(name="SSHCustom",port=sshPort,proto="tcp")
|
||||
newFireWallRule.save()
|
||||
except BaseException,msg:
|
||||
logging.CyberCPLogFileWriter.writeToFile(str(msg))
|
||||
|
||||
|
||||
## temporarily changing permission for sshd files
|
||||
@@ -492,11 +496,11 @@ def saveSSHConfigs(request):
|
||||
return HttpResponse(final_json)
|
||||
|
||||
except BaseException,msg:
|
||||
final_dic = {'saveStatus': 0}
|
||||
final_dic = {'saveStatus': 0,'error_message':str(msg)}
|
||||
final_json = json.dumps(final_dic)
|
||||
return HttpResponse(final_json)
|
||||
except KeyError,msg:
|
||||
final_dic = {'saveStatus': 0}
|
||||
final_dic = {'saveStatus': 0,'error_message':str(msg)}
|
||||
final_json = json.dumps(final_dic)
|
||||
return HttpResponse(final_json)
|
||||
|
||||
|
||||
@@ -1714,6 +1714,45 @@ class preFlightsChecks:
|
||||
|
||||
try:
|
||||
|
||||
## first install crontab
|
||||
|
||||
file = open("installLogs.txt", 'a')
|
||||
|
||||
command = 'yum install cronie -y'
|
||||
|
||||
cmd = shlex.split(command)
|
||||
|
||||
res = subprocess.call(cmd,stdout=file)
|
||||
|
||||
if res == 1:
|
||||
logging.InstallLog.writeToFile("1725 [Cron is not installed]")
|
||||
else:
|
||||
pass
|
||||
|
||||
command = 'systemctl enable crond'
|
||||
|
||||
cmd = shlex.split(command)
|
||||
|
||||
res = subprocess.call(cmd,stdout=file)
|
||||
|
||||
if res == 1:
|
||||
logging.InstallLog.writeToFile("1737 [Cron is not enabled]")
|
||||
else:
|
||||
pass
|
||||
|
||||
command = 'systemctl start crond'
|
||||
|
||||
cmd = shlex.split(command)
|
||||
|
||||
res = subprocess.call(cmd,stdout=file)
|
||||
|
||||
if res == 1:
|
||||
logging.InstallLog.writeToFile("1748 [Cron is not started]")
|
||||
else:
|
||||
pass
|
||||
|
||||
##
|
||||
|
||||
cronFile = open("/etc/crontab","a")
|
||||
cronFile.writelines("0 * * * * root python /usr/local/CyberCP/plogical/findBWUsage.py"+"\n")
|
||||
cronFile.close()
|
||||
@@ -1723,9 +1762,8 @@ class preFlightsChecks:
|
||||
|
||||
cmd = shlex.split(command)
|
||||
|
||||
file = open("installLogs.txt", 'a')
|
||||
res = subprocess.call(cmd,stdout=file)
|
||||
file.close()
|
||||
|
||||
|
||||
if res == 1:
|
||||
logging.InstallLog.writeToFile("1428 [setup_cron]")
|
||||
@@ -1737,17 +1775,15 @@ class preFlightsChecks:
|
||||
|
||||
cmd = shlex.split(command)
|
||||
|
||||
res = subprocess.call(cmd)
|
||||
res = subprocess.call(cmd,stdout=file)
|
||||
|
||||
if res == 1:
|
||||
logging.InstallLog.writeToFile("1440 [setup_cron]")
|
||||
else:
|
||||
pass
|
||||
|
||||
file.close()
|
||||
|
||||
print("###############################################")
|
||||
print(" Cron Enabled ")
|
||||
print("###############################################")
|
||||
|
||||
|
||||
except OSError, msg:
|
||||
|
||||
@@ -14,7 +14,7 @@ class backupSchedule:
|
||||
|
||||
|
||||
@staticmethod
|
||||
def createBackup(virtualHost, ipAddress,writeToFile):
|
||||
def createBackup(virtualHost, ipAddress,writeToFile,port):
|
||||
try:
|
||||
|
||||
writeToFile.writelines("["+time.strftime("%I-%M-%S-%a-%b-%Y")+"]"+" Preparing to create backup for: "+virtualHost+"\n")
|
||||
@@ -42,7 +42,7 @@ class backupSchedule:
|
||||
"%I-%M-%S-%a-%b-%Y") + "]" + " Preparing to send backup for: " + virtualHost +" to "+ipAddress+ "\n")
|
||||
writeToFile.flush()
|
||||
|
||||
backupSchedule.sendBackup(backupPath+".tar.gz", ipAddress,writeToFile)
|
||||
backupSchedule.sendBackup(backupPath+".tar.gz", ipAddress,writeToFile,port)
|
||||
|
||||
writeToFile.writelines("[" + time.strftime(
|
||||
"%I-%M-%S-%a-%b-%Y") + "]" + " Backup for: " + virtualHost + " is sent to " + ipAddress + "\n")
|
||||
@@ -56,17 +56,16 @@ class backupSchedule:
|
||||
writeToFile.writelines("\n")
|
||||
|
||||
except BaseException,msg:
|
||||
logging.CyberCPLogFileWriter.writeToFile(str(msg) + " [startBackup]")
|
||||
|
||||
logging.CyberCPLogFileWriter.writeToFile(str(msg) + " [createBackup]")
|
||||
|
||||
@staticmethod
|
||||
def sendBackup(backupPath,IPAddress,writeToFile):
|
||||
def sendBackup(backupPath, IPAddress, writeToFile,port):
|
||||
try:
|
||||
command ='rsync -avz -e "ssh -i /home/cyberpanel/.ssh/cyberpanel -o StrictHostKeyChecking=no" '+ backupPath+ ' cyberpanel@'+IPAddress+':/home/backup/'+time.strftime("%a-%b")+"/"
|
||||
command = 'rsync -avz -e "ssh -i /root/.ssh/cyberpanel -o StrictHostKeyChecking=no -p '+port+'" ' + backupPath + ' root@' + IPAddress + ':/home/backup/' + time.strftime(
|
||||
"%a-%b") + "/"
|
||||
subprocess.call(shlex.split(command), stdout=writeToFile)
|
||||
|
||||
subprocess.call(shlex.split(command),stdout=writeToFile)
|
||||
|
||||
except BaseException,msg:
|
||||
except BaseException, msg:
|
||||
logging.CyberCPLogFileWriter.writeToFile(str(msg) + " [startBackup]")
|
||||
|
||||
@staticmethod
|
||||
@@ -88,12 +87,15 @@ class backupSchedule:
|
||||
writeToFile.writelines("\n")
|
||||
writeToFile.writelines("\n")
|
||||
|
||||
ipAddress = open(destinations,'r').readlines()[0].strip("\n")
|
||||
data = open(destinations,'r').readlines()
|
||||
ipAddress = data[0].strip("\n")
|
||||
port = data[1].strip("\n")
|
||||
|
||||
|
||||
|
||||
if backupUtilities.checkIfHostIsUp(ipAddress) == 1:
|
||||
if backupUtilities.checkConnection(ipAddress) != 1:
|
||||
checkConn = backupUtilities.checkConnection(ipAddress)
|
||||
if checkConn[0] == 0:
|
||||
writeToFile.writelines("[" + time.strftime(
|
||||
"%I-%M-%S-%a-%b-%Y") + "]" + " Connection to:" + ipAddress+" Failed, please resetup this destination from CyberPanel, aborting." + "\n")
|
||||
return 0
|
||||
@@ -101,14 +103,16 @@ class backupSchedule:
|
||||
pass
|
||||
else:
|
||||
writeToFile.writelines("[" + time.strftime(
|
||||
"%I-%M-%S-%a-%b-%Y") + "]" + " Host:" + ipAddress + " is down, aborting." + "\n")
|
||||
"%I-%M-%S-%a-%b-%Y") + "]" + " Host: " + ipAddress + " is down, aborting." + "\n")
|
||||
return 0
|
||||
|
||||
for virtualHost in os.listdir("/home"):
|
||||
backupSchedule.createBackup(virtualHost,ipAddress,writeToFile)
|
||||
if virtualHost == "vmail" or virtualHost == "cyberpanel" or virtualHost =="backup":
|
||||
continue
|
||||
backupSchedule.createBackup(virtualHost,ipAddress,writeToFile,port)
|
||||
|
||||
except BaseException,msg:
|
||||
logging.CyberCPLogFileWriter.writeToFile(str(msg) + " [startBackup]")
|
||||
logging.CyberCPLogFileWriter.writeToFile(str(msg) + " [prepare]")
|
||||
|
||||
|
||||
backupSchedule.prepare()
|
||||
@@ -272,14 +272,12 @@ class backupUtilities:
|
||||
logging.CyberCPLogFileWriter.writeToFile(str(msg) + " [initiateRestore]")
|
||||
|
||||
@staticmethod
|
||||
def sendKey(IPAddress,password):
|
||||
def sendKey(IPAddress, password,port):
|
||||
try:
|
||||
if not os.path.exists(backupUtilities.completeKeyPath+"/cyberpanel"):
|
||||
command = "ssh-keygen -f "+backupUtilities.completeKeyPath+"/cyberpanel -t rsa -N ''"
|
||||
cmd = shlex.split(command)
|
||||
res = subprocess.call(cmd)
|
||||
|
||||
sendKeyProc = pexpect.spawn("scp "+backupUtilities.completeKeyPath+"/cyberpanel.pub root@"+IPAddress+":"+backupUtilities.completeKeyPath+"/authorized_keys")
|
||||
command = "sudo scp -o StrictHostKeyChecking=no -P "+ port +" /root/.ssh/cyberpanel.pub root@" + IPAddress + ":/root/.ssh/authorized_keys"
|
||||
|
||||
sendKeyProc = pexpect.spawn(command,timeout=3)
|
||||
sendKeyProc.expect("password:")
|
||||
|
||||
sendKeyProc.sendline(password)
|
||||
@@ -287,20 +285,20 @@ class backupUtilities:
|
||||
|
||||
sendKeyProc.wait()
|
||||
|
||||
return 1
|
||||
return [1, "None"]
|
||||
|
||||
except pexpect.TIMEOUT,msg:
|
||||
except pexpect.TIMEOUT, msg:
|
||||
logging.CyberCPLogFileWriter.writeToFile(str(msg) + " [sendKey]")
|
||||
return 0
|
||||
except pexpect.EOF,msg:
|
||||
return [0, "TIMEOUT [sendKey]"]
|
||||
except pexpect.EOF, msg:
|
||||
logging.CyberCPLogFileWriter.writeToFile(str(msg) + " [sendKey]")
|
||||
return 0
|
||||
return [0, "EOF [sendKey]"]
|
||||
except BaseException, msg:
|
||||
logging.CyberCPLogFileWriter.writeToFile(str(msg) + " [sendKey]")
|
||||
return 0
|
||||
return [0, str(msg) + " [sendKey]"]
|
||||
|
||||
@staticmethod
|
||||
def setupSSHKeys(IPAddress, password):
|
||||
def setupSSHKeys(IPAddress, password,port):
|
||||
try:
|
||||
## Checking for host verification
|
||||
|
||||
@@ -309,101 +307,48 @@ class backupUtilities:
|
||||
if backupUtilities.checkIfHostIsUp(IPAddress) == 1:
|
||||
pass
|
||||
else:
|
||||
return "Host is Down."
|
||||
return [0,"Host is Down."]
|
||||
|
||||
expectation = "password:"
|
||||
|
||||
|
||||
command = "ssh -o StrictHostKeyChecking=no -p "+ port +" root@"+IPAddress+" mkdir /root/.ssh"
|
||||
|
||||
setupKeys = pexpect.spawn(command,timeout=3)
|
||||
|
||||
setupKeys.expect(expectation)
|
||||
|
||||
## on first login attempt send password
|
||||
|
||||
setupKeys.sendline(password)
|
||||
|
||||
## if it again give you password, than provided password is wrong
|
||||
|
||||
expectation = []
|
||||
expectation.append("please try again.")
|
||||
expectation.append(pexpect.EOF)
|
||||
|
||||
expectation.append("continue connecting (yes/no)?")
|
||||
expectation.append("password:")
|
||||
|
||||
setupSSHKeys = pexpect.spawn("ssh cyberpanel@"+IPAddress+" mkdir "+backupUtilities.keyPath)
|
||||
|
||||
index = setupSSHKeys.expect(expectation)
|
||||
index = setupKeys.expect(expectation)
|
||||
|
||||
if index == 0:
|
||||
setupSSHKeys.sendline("yes")
|
||||
setupSSHKeys.expect("password:")
|
||||
setupSSHKeys.sendline(password)
|
||||
|
||||
expectation = []
|
||||
|
||||
expectation.append("File exists")
|
||||
expectation.append(pexpect.EOF)
|
||||
expectation.append("please try again.")
|
||||
|
||||
innerIndex = setupSSHKeys.expect(expectation)
|
||||
|
||||
if innerIndex == 0:
|
||||
print "Exists"
|
||||
setupSSHKeys.wait()
|
||||
|
||||
## setting up keys.
|
||||
|
||||
if backupUtilities.sendKey(IPAddress,password) == 0:
|
||||
return "Can't setup connection, check CyberPanel Main log file."
|
||||
else:
|
||||
return 1
|
||||
|
||||
elif innerIndex == 1:
|
||||
|
||||
print "Created"
|
||||
setupSSHKeys.wait()
|
||||
|
||||
## setting up keys.
|
||||
|
||||
if backupUtilities.sendKey(IPAddress,password) == 0:
|
||||
return "Can't setup connection, check CyberPanel Main log file."
|
||||
else:
|
||||
return 1
|
||||
|
||||
else:
|
||||
return "Wrong Password"
|
||||
|
||||
return [0,"Wrong Password"]
|
||||
elif index == 1:
|
||||
setupSSHKeys.sendline(password)
|
||||
setupKeys.wait()
|
||||
|
||||
expectation = []
|
||||
|
||||
expectation.append("File exists")
|
||||
expectation.append(pexpect.EOF)
|
||||
expectation.append("please try again.")
|
||||
|
||||
innerIndex = setupSSHKeys.expect(expectation)
|
||||
|
||||
if innerIndex == 0:
|
||||
print "Exists"
|
||||
setupSSHKeys.wait()
|
||||
|
||||
## setting up keys.
|
||||
|
||||
if backupUtilities.sendKey(IPAddress,password) == 0:
|
||||
return "Can't setup connection, check CyberPanel Main log file."
|
||||
else:
|
||||
return 1
|
||||
|
||||
elif innerIndex == 1:
|
||||
setupSSHKeys.wait()
|
||||
|
||||
## setting up keys.
|
||||
|
||||
## setting up keys.
|
||||
|
||||
if backupUtilities.sendKey(IPAddress,password) == 0:
|
||||
return "Can't setup connection, check CyberPanel Main log file."
|
||||
else:
|
||||
return 1
|
||||
sendKey = backupUtilities.sendKey(IPAddress,password,port)
|
||||
|
||||
if sendKey[0] == 1:
|
||||
return [1, "None"]
|
||||
else:
|
||||
return "Wrong Password"
|
||||
return [0,sendKey[1]]
|
||||
|
||||
|
||||
except pexpect.TIMEOUT, msg:
|
||||
logging.CyberCPLogFileWriter.writeToFile(str(msg) + " [setupSSHKeys]")
|
||||
return 0
|
||||
except pexpect.EOF, msg:
|
||||
logging.CyberCPLogFileWriter.writeToFile(str(msg) + " [setupSSHKeys]")
|
||||
return 0
|
||||
logging.CyberCPLogFileWriter.writeToFile(setupKeys.before + " " + str(msg) + " [setupSSHKeys]")
|
||||
return [0, str(msg) + " [TIMEOUT setupSSHKeys]"]
|
||||
except BaseException, msg:
|
||||
logging.CyberCPLogFileWriter.writeToFile(str(msg) + " [setupSSHKeys]")
|
||||
return 0
|
||||
return [0, str(msg) + " [setupSSHKeys]"]
|
||||
|
||||
@staticmethod
|
||||
def checkIfHostIsUp(IPAddress):
|
||||
@@ -418,12 +363,19 @@ class backupUtilities:
|
||||
@staticmethod
|
||||
def checkConnection(IPAddress):
|
||||
try:
|
||||
|
||||
path = "/usr/local/CyberCP/backup/"
|
||||
destinations = path + "destinations"
|
||||
|
||||
data = open(destinations, 'r').readlines()
|
||||
port = data[1].strip("\n")
|
||||
|
||||
expectation = []
|
||||
expectation.append("password:")
|
||||
expectation.append("Last login")
|
||||
expectation.append(pexpect.EOF)
|
||||
|
||||
checkConn = pexpect.spawn("ssh -i /home/cyberpanel/.ssh/cyberpanel -o StrictHostKeyChecking=no cyberpanel@"+IPAddress, timeout=3)
|
||||
checkConn = pexpect.spawn("sudo ssh -i /root/.ssh/cyberpanel -o StrictHostKeyChecking=no -p "+ port+" root@"+IPAddress, timeout=3)
|
||||
index = checkConn.expect(expectation)
|
||||
|
||||
if index == 0:
|
||||
@@ -518,10 +470,10 @@ class backupUtilities:
|
||||
|
||||
|
||||
@staticmethod
|
||||
def createBackupDir(IPAddress,IPAddressA):
|
||||
def createBackupDir(IPAddress,port):
|
||||
|
||||
try:
|
||||
command = "ssh -i /home/cyberpanel/.ssh/cyberpanel cyberpanel@"+IPAddress+" mkdir /home/backup"
|
||||
command = "ssh -o StrictHostKeyChecking=no -p "+ port +" -i /home/cyberpanel/.ssh/cyberpanel cyberpanel@"+IPAddress+" mkdir /home/backup"
|
||||
|
||||
shlex.split(command)
|
||||
|
||||
@@ -532,10 +484,9 @@ class backupUtilities:
|
||||
return 0
|
||||
|
||||
@staticmethod
|
||||
def initiateBackupDirCreation(IPAddress):
|
||||
def initiateBackupDirCreation(IPAddress,port):
|
||||
try:
|
||||
backupUtilities.verifyHostKey(IPAddress)
|
||||
thread.start_new_thread(backupUtilities.createBackupDir, (IPAddress,IPAddress))
|
||||
thread.start_new_thread(backupUtilities.createBackupDir, (IPAddress,port))
|
||||
except BaseException,msg:
|
||||
logging.CyberCPLogFileWriter.writeToFile(str(msg) + " [initiateBackupDirCreation]")
|
||||
|
||||
|
||||
@@ -49,46 +49,49 @@ class mysqlUtilities:
|
||||
data = f.read()
|
||||
password = data.split('\n', 1)[0]
|
||||
|
||||
expectation = "Enter password:"
|
||||
securemysql = pexpect.spawn("mysql -u root -p")
|
||||
securemysql.expect(expectation)
|
||||
securemysql.sendline(password)
|
||||
createDB = "CREATE DATABASE "+dbname
|
||||
|
||||
expectation = ["Access denied for user", "Welcome to the MariaDB monitor"]
|
||||
command = 'sudo mysql -u root -p' + password + ' -e "' + createDB + '"'
|
||||
cmd = shlex.split(command)
|
||||
res = subprocess.call(cmd)
|
||||
|
||||
index = securemysql.expect(expectation)
|
||||
if res == 1:
|
||||
logging.CyberCPLogFileWriter.writeToFile("Can not create Database: " +dbname)
|
||||
return 0
|
||||
|
||||
if index == 0:
|
||||
return "Wrong root Password"
|
||||
createUser = "CREATE USER '" +dbuser+ "'@'localhost' IDENTIFIED BY '"+dbpassword+"'"
|
||||
|
||||
command = 'sudo mysql -u root -p' + password + ' -e "' + createUser + '"'
|
||||
|
||||
cmd = shlex.split(command)
|
||||
res = subprocess.call(cmd)
|
||||
|
||||
if res == 1:
|
||||
logging.CyberCPLogFileWriter.writeToFile("Can not create Database User: " + dbuser)
|
||||
|
||||
## reverting the db creation which was created earlier
|
||||
|
||||
mysqlUtilities.deleteDatabase(dbname,dbuser)
|
||||
|
||||
return 0
|
||||
else:
|
||||
securemysql.sendline("CREATE DATABASE "+dbname+";")
|
||||
|
||||
dropDB = "GRANT ALL PRIVILEGES ON " +dbname+ ".* TO '" +dbuser+ "'@'localhost'"
|
||||
command = 'sudo mysql -u root -p' + password + ' -e "' + dropDB + '"'
|
||||
cmd = shlex.split(command)
|
||||
res = subprocess.call(cmd)
|
||||
|
||||
expectation = ["database exists","Query OK"]
|
||||
index = securemysql.expect(expectation)
|
||||
if res == 1:
|
||||
mysqlUtilities.deleteDatabase(dbname, dbuser)
|
||||
logging.CyberCPLogFileWriter.writeToFile("Can not grant privileges to user: " + dbuser)
|
||||
return 0
|
||||
|
||||
|
||||
if index == 0:
|
||||
return "This database already exists, please choose another name."
|
||||
elif index == 1:
|
||||
securemysql.sendline("CREATE USER '" +dbuser+ "'@'localhost' IDENTIFIED BY '"+dbpassword+"';")
|
||||
expectation = ["CREATE USER failed","Query OK"]
|
||||
|
||||
index = securemysql.expect(expectation)
|
||||
|
||||
if index == 0:
|
||||
securemysql.sendline("DROP DATABASE IF EXISTS "+dbname+";")
|
||||
return "This user already exists, please choose another user."
|
||||
else:
|
||||
securemysql.sendline("GRANT ALL PRIVILEGES ON " +dbname+ ".* TO '" +dbuser+ "'@'localhost';")
|
||||
expectation = "Query OK"
|
||||
securemysql.expect(expectation)
|
||||
securemysql.sendline("exit")
|
||||
securemysql.wait()
|
||||
return 1
|
||||
except pexpect.EOF, msg:
|
||||
logging.CyberCPLogFileWriter.writeToFile(str(msg) + " Exception EOF [createDatabase]")
|
||||
|
||||
except BaseException, msg:
|
||||
logging.CyberCPLogFileWriter.writeToFile(str(msg) + "[createDatabase]")
|
||||
return 0
|
||||
|
||||
@staticmethod
|
||||
def deleteDatabase(dbname, dbuser):
|
||||
@@ -101,40 +104,29 @@ class mysqlUtilities:
|
||||
data = f.read()
|
||||
password = data.split('\n', 1)[0]
|
||||
|
||||
dropDB = "DROP DATABASE " + dbname
|
||||
command = 'sudo mysql -u root -p' + password + ' -e "' + dropDB + '"'
|
||||
cmd = shlex.split(command)
|
||||
res = subprocess.call(cmd)
|
||||
|
||||
expectation = "Enter password:"
|
||||
securemysql = pexpect.spawn("mysql -u root -p")
|
||||
securemysql.expect(expectation)
|
||||
securemysql.sendline(password)
|
||||
|
||||
expectation = ["Access denied for user", "Welcome to the MariaDB monitor"]
|
||||
|
||||
index = securemysql.expect(expectation)
|
||||
|
||||
if index == 0:
|
||||
return "Wrong root Password"
|
||||
if res == 1:
|
||||
logging.CyberCPLogFileWriter.writeToFile("Can not delete Database: " + dbname)
|
||||
return 0
|
||||
else:
|
||||
securemysql.sendline("DROP DATABASE IF EXISTS " + dbname + ";")
|
||||
dropUser = "DROP USER '"+dbuser+"'@'localhost'"
|
||||
command = 'sudo mysql -u root -p' + password + ' -e "' + dropUser + '"'
|
||||
cmd = shlex.split(command)
|
||||
res = subprocess.call(cmd)
|
||||
|
||||
expectation = ["Query OK",pexpect.EOF]
|
||||
index = securemysql.expect(expectation)
|
||||
if res == 1:
|
||||
logging.CyberCPLogFileWriter.writeToFile("Can not delete Database User: " + dbuser)
|
||||
return 0
|
||||
|
||||
if index == 0:
|
||||
return 1
|
||||
|
||||
securemysql.sendline("DROP USER '"+dbuser+"'@'localhost';")
|
||||
|
||||
securemysql.close()
|
||||
return 1
|
||||
else:
|
||||
securemysql.sendline("DROP USER '" + dbuser + "'@'localhost';")
|
||||
securemysql.close()
|
||||
return 1
|
||||
|
||||
except pexpect.EOF, msg:
|
||||
logging.CyberCPLogFileWriter.writeToFile(str(msg) + " Exception EOF [deleteDatabase]")
|
||||
return str(msg)
|
||||
except BaseException, msg:
|
||||
logging.CyberCPLogFileWriter.writeToFile(str(msg) + "[createDatabase]")
|
||||
logging.CyberCPLogFileWriter.writeToFile(str(msg) + "[deleteDatabase]")
|
||||
return str(msg)
|
||||
|
||||
@staticmethod
|
||||
|
||||
@@ -527,6 +527,7 @@ app.controller('backupDestinations', function($scope,$http,$timeout) {
|
||||
var data = {
|
||||
IPAddress : $scope.IPAddress,
|
||||
password : $scope.password,
|
||||
backupSSHPort:$scope.backupSSHPort,
|
||||
};
|
||||
|
||||
var config = {
|
||||
|
||||
@@ -1,7 +1,84 @@
|
||||
/* Default color schemes */
|
||||
|
||||
@import url(https://fonts.googleapis.com/css?family=Raleway:300);
|
||||
@import url(https://fonts.googleapis.com/css?family=Open+Sans);
|
||||
/* Google imports */
|
||||
|
||||
/* latin-ext */
|
||||
@font-face {
|
||||
font-family: 'Raleway';
|
||||
font-style: normal;
|
||||
font-weight: 300;
|
||||
src: local('Raleway Light'), local('Raleway-Light'), url(https://fonts.gstatic.com/s/raleway/v12/ZKwULyCG95tk6mOqHQfRBCEAvth_LlrfE80CYdSH47w.woff2) format('woff2');
|
||||
unicode-range: U+0100-024F, U+1E00-1EFF, U+20A0-20AB, U+20AD-20CF, U+2C60-2C7F, U+A720-A7FF;
|
||||
}
|
||||
/* latin */
|
||||
@font-face {
|
||||
font-family: 'Raleway';
|
||||
font-style: normal;
|
||||
font-weight: 300;
|
||||
src: local('Raleway Light'), local('Raleway-Light'), url(https://fonts.gstatic.com/s/raleway/v12/-_Ctzj9b56b8RgXW8FArifk_vArhqVIZ0nv9q090hN8.woff2) format('woff2');
|
||||
unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2212, U+2215;
|
||||
}
|
||||
|
||||
|
||||
/* cyrillic-ext */
|
||||
@font-face {
|
||||
font-family: 'Open Sans';
|
||||
font-style: normal;
|
||||
font-weight: 400;
|
||||
src: local('Open Sans Regular'), local('OpenSans-Regular'), url(https://fonts.gstatic.com/s/opensans/v15/K88pR3goAWT7BTt32Z01mxJtnKITppOI_IvcXXDNrsc.woff2) format('woff2');
|
||||
unicode-range: U+0460-052F, U+20B4, U+2DE0-2DFF, U+A640-A69F;
|
||||
}
|
||||
/* cyrillic */
|
||||
@font-face {
|
||||
font-family: 'Open Sans';
|
||||
font-style: normal;
|
||||
font-weight: 400;
|
||||
src: local('Open Sans Regular'), local('OpenSans-Regular'), url(https://fonts.gstatic.com/s/opensans/v15/RjgO7rYTmqiVp7vzi-Q5URJtnKITppOI_IvcXXDNrsc.woff2) format('woff2');
|
||||
unicode-range: U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116;
|
||||
}
|
||||
/* greek-ext */
|
||||
@font-face {
|
||||
font-family: 'Open Sans';
|
||||
font-style: normal;
|
||||
font-weight: 400;
|
||||
src: local('Open Sans Regular'), local('OpenSans-Regular'), url(https://fonts.gstatic.com/s/opensans/v15/LWCjsQkB6EMdfHrEVqA1KRJtnKITppOI_IvcXXDNrsc.woff2) format('woff2');
|
||||
unicode-range: U+1F00-1FFF;
|
||||
}
|
||||
/* greek */
|
||||
@font-face {
|
||||
font-family: 'Open Sans';
|
||||
font-style: normal;
|
||||
font-weight: 400;
|
||||
src: local('Open Sans Regular'), local('OpenSans-Regular'), url(https://fonts.gstatic.com/s/opensans/v15/xozscpT2726on7jbcb_pAhJtnKITppOI_IvcXXDNrsc.woff2) format('woff2');
|
||||
unicode-range: U+0370-03FF;
|
||||
}
|
||||
/* vietnamese */
|
||||
@font-face {
|
||||
font-family: 'Open Sans';
|
||||
font-style: normal;
|
||||
font-weight: 400;
|
||||
src: local('Open Sans Regular'), local('OpenSans-Regular'), url(https://fonts.gstatic.com/s/opensans/v15/59ZRklaO5bWGqF5A9baEERJtnKITppOI_IvcXXDNrsc.woff2) format('woff2');
|
||||
unicode-range: U+0102-0103, U+1EA0-1EF9, U+20AB;
|
||||
}
|
||||
/* latin-ext */
|
||||
@font-face {
|
||||
font-family: 'Open Sans';
|
||||
font-style: normal;
|
||||
font-weight: 400;
|
||||
src: local('Open Sans Regular'), local('OpenSans-Regular'), url(https://fonts.gstatic.com/s/opensans/v15/u-WUoqrET9fUeobQW7jkRRJtnKITppOI_IvcXXDNrsc.woff2) format('woff2');
|
||||
unicode-range: U+0100-024F, U+1E00-1EFF, U+20A0-20AB, U+20AD-20CF, U+2C60-2C7F, U+A720-A7FF;
|
||||
}
|
||||
/* latin */
|
||||
@font-face {
|
||||
font-family: 'Open Sans';
|
||||
font-style: normal;
|
||||
font-weight: 400;
|
||||
src: local('Open Sans Regular'), local('OpenSans-Regular'), url(https://fonts.gstatic.com/s/opensans/v15/cJZKeOuBrn4kERxqtaUH3VtXRa8TVwTICgirnJhmVJw.woff2) format('woff2');
|
||||
unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2212, U+2215;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/* General */
|
||||
|
||||
|
||||
@@ -99,6 +99,9 @@ app.controller('adminController', function($scope,$http,$timeout) {
|
||||
$scope.currentAdmin = response.data.user_name;
|
||||
$scope.admin_type = response.data.admin_type;
|
||||
|
||||
|
||||
$("#serverIPAddress").text(response.data.serverIPAddress);
|
||||
|
||||
if (response.data.admin_type != "Administrator")
|
||||
{
|
||||
|
||||
|
||||
Reference in New Issue
Block a user