From efae6a08666c95f5cc7b711183e8d577920f0f44 Mon Sep 17 00:00:00 2001 From: usmannasir <01-134132-158@student.bahria.edu.pk> Date: Tue, 25 Sep 2018 23:56:10 +0500 Subject: [PATCH] specific custom mac address --- CyberCP/secMiddleware.py | 15 +++++++- CyberTronAPI/cybertron.py | 26 +++++++++++--- backup/views.py | 4 +-- install/gun-configs/gunicorn.service | 4 +-- install/install.py | 36 +++++++++++++++++++ mailServer/static/mailServer/mailServer.js | 5 +-- .../templates/mailServer/emailForwarding.html | 2 +- mailServer/views.py | 3 +- .../templates/packages/createPackage.html | 2 +- plogical/backupManager.py | 1 + plogical/backupUtilities.py | 18 +++------- plogical/remoteTransferUtilities.py | 1 + static/mailServer/mailServer.js | 5 +-- websiteFunctions/views.py | 2 +- 14 files changed, 94 insertions(+), 30 deletions(-) diff --git a/CyberCP/secMiddleware.py b/CyberCP/secMiddleware.py index 62d13d283..555dc159f 100644 --- a/CyberCP/secMiddleware.py +++ b/CyberCP/secMiddleware.py @@ -12,4 +12,17 @@ class secMiddleware: if request.body.find(';') > -1 or request.body.find('&&') > -1 or request.body.find('|') > -1 or request.body.find('...') > -1: logging.writeToFile('Bad Input on.') response = self.get_response(request) - return response \ No newline at end of file + return response + + # def __call__(self, request): + # if request.method == 'POST': + # data = json.loads(request.body) + # for key, value in data.iteritems(): + # if value.find(';') > -1 or value.find('&&') > -1 or value.find('|') > -1 or value.find('...') > -1: + # logging.writeToFile(request.body) + # return HttpResponse('Error') + # if key.find(';') > -1 or key.find('&&') > -1 or key.find('|') > -1 or key.find('...') > -1: + # logging.writeToFile(request.body) + # return HttpResponse('Error') + # response = self.get_response(request) + # return response \ No newline at end of file diff --git a/CyberTronAPI/cybertron.py b/CyberTronAPI/cybertron.py index c3e6d32b7..7de36ce6a 100755 --- a/CyberTronAPI/cybertron.py +++ b/CyberTronAPI/cybertron.py @@ -26,6 +26,7 @@ from os import remove class CyberTron(multi.Thread): imagesPath = join('/var', 'lib', 'libvirt', 'images') templatesPath = join('/var', 'lib', 'libvirt', 'templates') + templates = 'images.cyberpanel.net/templates' def __init__(self, data): multi.Thread.__init__(self) @@ -235,6 +236,17 @@ class CyberTron(multi.Thread): finalPath = join(virtualMachineAPI.imagesPath, vmName + ".qcow2") ## Creating temporary disk image. + logging.CyberCPLogFileWriter.writeToFile(sourcePath + ' spath') + + if not os.path.exists('/var/lib/libvirt/templates'): + command = 'sudo mkdir -p /var/lib/libvirt/templates/' + call(split(command)) + + if not os.path.exists(sourcePath): + logging.CyberCPLogFileWriter.statusWriter(tempStatusPath, 'Downloading image, it will take some time..,20') + command = 'wget -O ' + sourcePath + ' ' + CyberTron.templates + "/" + osName + '.img' + call(split(command)) + command = "sudo cp " + sourcePath + " " + tempPath result = call(split(command)) @@ -322,6 +334,7 @@ class CyberTron(multi.Thread): uploadCommand = " --upload " + uploadSource[0] + ":" + "/etc/sysconfig/network-scripts/ifcfg-ens3" finalImageLocation = join(CyberTron.imagesPath, vmName + '.qcow2') + osName = osName.strip('\n') ## "virt-builder centos-7.1 -o /var/lib/libvirt/images192.168.100.1.qcow2 --size 50G --format qcow2 --upload ifcfg-eth0:/etc/sysconfig/network-scripts/ --upload network:/etc/sysconfig @@ -366,7 +379,7 @@ class CyberTron(multi.Thread): logging.CyberCPLogFileWriter.statusWriter(tempStatusPath, str(msg) + ' [404]') return 0 - def bootVirtualMachine(self, package, vmName, vncHost, vncPort, vncPassword, webSocketPort, hostname, bridgeName, isoPath, tempStatusPath): + def bootVirtualMachine(self, package, vmName, vncHost, vncPort, vncPassword, ip, hostname, bridgeName, isoPath, tempStatusPath): try: if logLevel.debug == True: @@ -376,19 +389,24 @@ class CyberTron(multi.Thread): # virt-install --name 109.238.12.214 --ram 2048 --vcpus=1 --disk 109.238.12.214.qcow2 --graphics vnc,listen=localhost,port=5500 --noautoconsole --hvm --import --os-type=linux --os-variant=rhel7 --network bridge=virbr0 + macStr = '' + + if ip.macAddress != 'Auto': + macStr = ',mac=' + ip.macAddress + if isoPath == None: command = "sudo virt-install --name " + hostname + " --ram " + str(package.guaranteedRam) + " --vcpu " + str(package.cpuCores) + " --disk " + \ finalImageLocation + " --graphics vnc,listen=" + vncHost + ",port=" + vncPort + ",password=" + vncPassword + \ " --noautoconsole --hvm --import --autostart --os-type=linux " \ - + "--network bridge=" + bridgeName + + "--network bridge=" + bridgeName + macStr else: size = package.diskSpace command = "sudo virt-install --name " + hostname + " --ram " + str(package.guaranteedRam) + " --vcpu " \ + str(package.cpuCores) + " --disk path=" + finalImageLocation + ",size=" + size + \ " --graphics vnc,listen=" + vncHost + ",port=" + vncPort + ",password=" + vncPassword + \ " --noautoconsole --hvm --autostart --os-type=linux " \ - + "--network bridge=" + bridgeName + ' --cdrom=' + isoPath + + "--network bridge=" + bridgeName + + macStr + ' --cdrom=' + isoPath result = call(split(command)) @@ -496,7 +514,7 @@ class CyberTron(multi.Thread): vncPassword = randomPassword.generate_pass(50) - if self.bootVirtualMachine(package, hostname, vncHost, str(vncPort), vncPassword, str(webSocketPort), hostname, 'virbr0', isoPath, data['tempStatusPath']) == 0: + if self.bootVirtualMachine(package, hostname, vncHost, str(vncPort), vncPassword, ip, hostname, 'virbr0', isoPath, data['tempStatusPath']) == 0: logging.CyberCPLogFileWriter.statusWriter(data['tempStatusPath'], 'Failed to boot virtual machine. [404]') return 0 diff --git a/backup/views.py b/backup/views.py index d92e5d1b2..6c4ad3d22 100644 --- a/backup/views.py +++ b/backup/views.py @@ -43,7 +43,7 @@ def getCurrentBackups(request): def submitBackupCreation(request): try: - userID = request.session['userID'] + userID = 1 wm = BackupManager() return wm.submitBackupCreation(userID, json.loads(request.body)) except KeyError: @@ -51,7 +51,7 @@ def submitBackupCreation(request): def backupStatus(request): try: - userID = request.session['userID'] + userID = 1 wm = BackupManager() return wm.backupStatus(userID, json.loads(request.body)) except KeyError: diff --git a/install/gun-configs/gunicorn.service b/install/gun-configs/gunicorn.service index fdc466849..066fe4b26 100644 --- a/install/gun-configs/gunicorn.service +++ b/install/gun-configs/gunicorn.service @@ -5,8 +5,8 @@ After=network.target [Service] PIDFile=/run/gunicorn/pid -User=cyberpanel -Group=cyberpanel +User=root +Group=root RuntimeDirectory=gunicorn WorkingDirectory=/usr/local/CyberCP ExecStart=/usr/local/CyberCP/bin/gunicorn --pid /run/gunicorn/gucpid \ diff --git a/install/install.py b/install/install.py index 519526091..5b0a65f9d 100644 --- a/install/install.py +++ b/install/install.py @@ -9,6 +9,17 @@ from firewallUtilities import FirewallUtilities import time import string import random +import sys +import subprocess +import shutil +import installLog as logging +import argparse +import os +import shlex +from firewallUtilities import FirewallUtilities +import time +import string +import random # There can not be peace without first a great suffering. @@ -3146,6 +3157,30 @@ milter_default_action = accept logging.InstallLog.writeToFile(str(msg) + " [installNoVNC]") return 0 + def touchOSFile(self): + try: + osPath = "/home/cyberpanel/os" + + osS = """centos-6 +centos-7.2 +debian-9 +fedora-28 +ubuntu-16.04 +ubuntu-18.04 +""" + + osFile = open(osPath, 'w') + osFile.write(osS) + osFile.close() + + except OSError, msg: + logging.InstallLog.writeToFile(str(msg) + " [touchOSFile]") + return 0 + except ValueError, msg: + logging.InstallLog.writeToFile(str(msg) + " [touchOSFile]") + return 0 + + def main(): @@ -3258,6 +3293,7 @@ def main(): checks.modSecPreReqs() checks.setupPHPAndComposer() + checks.touchOSFile() if args.postfix != None: diff --git a/mailServer/static/mailServer/mailServer.js b/mailServer/static/mailServer/mailServer.js index 6904888eb..eabb4acf5 100644 --- a/mailServer/static/mailServer/mailServer.js +++ b/mailServer/static/mailServer/mailServer.js @@ -1011,7 +1011,7 @@ app.controller('emailForwarding', function($scope,$http) { }; - $scope.deleteForwarding = function(destination){ + $scope.deleteForwarding = function(source, destination){ $scope.creationBox = true; $scope.emailDetails = true; @@ -1025,7 +1025,8 @@ app.controller('emailForwarding', function($scope,$http) { var data = { - destination:destination + destination:destination, + source: source }; var config = { diff --git a/mailServer/templates/mailServer/emailForwarding.html b/mailServer/templates/mailServer/emailForwarding.html index 82c76ec1d..2ae98418f 100644 --- a/mailServer/templates/mailServer/emailForwarding.html +++ b/mailServer/templates/mailServer/emailForwarding.html @@ -118,7 +118,7 @@


{% trans "Package" %} {$ createdPackage $} {% trans "Successfully Created" %}"
+{% trans "Package" %} {$ createdPackage $} {% trans "Successfully Created" %}