Skip to content

Commit

Permalink
certral execution: final phase
Browse files Browse the repository at this point in the history
  • Loading branch information
usmannasir committed Apr 15, 2019
1 parent 04e0790 commit 8245398
Show file tree
Hide file tree
Showing 25 changed files with 727 additions and 174 deletions.
7 changes: 5 additions & 2 deletions api/views.py
Expand Up @@ -227,8 +227,11 @@ def deleteWebsite(request):
website = Websites.objects.get(domain=data['websiteName'])
websiteOwner = website.admin

if admin.websites_set.all().count() == 0:
websiteOwner.delete()
try:
if admin.websites_set.all().count() == 0:
websiteOwner.delete()
except:
pass

## Deleting master domain

Expand Down
1 change: 0 additions & 1 deletion dockerManager/container.py
Expand Up @@ -25,7 +25,6 @@
from plogical.processUtilities import ProcessUtilities
from serverStatus.serverStatusUtil import ServerStatusUtil
import threading as multi
from plogical.mailUtilities import mailUtilities


# Use default socket to connect
Expand Down
15 changes: 0 additions & 15 deletions dockerManager/dockerInstall.py
Expand Up @@ -18,18 +18,6 @@ def submitInstallDocker():
logging.CyberCPLogFileWriter.statusWriter(ServerStatusUtil.lswsInstallStatusPath,
"Starting Docker Installation..\n", 1)

command = "sudo adduser docker"
ServerStatusUtil.executioner(command, statusFile)

command = 'sudo groupadd docker'
ServerStatusUtil.executioner(command, statusFile)

command = 'sudo usermod -aG docker docker'
ServerStatusUtil.executioner(command, statusFile)

command = 'sudo usermod -aG docker cyberpanel'
ServerStatusUtil.executioner(command, statusFile)

if ProcessUtilities.decideDistro() == ProcessUtilities.centos:
command = 'sudo yum install -y docker'
else:
Expand All @@ -51,9 +39,6 @@ def submitInstallDocker():

time.sleep(2)

command = 'sudo systemctl restart gunicorn.socket'
ProcessUtilities.executioner(command)

except BaseException, msg:
logging.CyberCPLogFileWriter.statusWriter(ServerStatusUtil.lswsInstallStatusPath, str(msg) + ' [404].', 1)

Expand Down
8 changes: 5 additions & 3 deletions emailPremium/views.py
Expand Up @@ -15,8 +15,6 @@
from postfixSenderPolicy.client import cacheClient
import thread
from plogical.mailUtilities import mailUtilities
import subprocess
import shlex
from plogical.virtualHostUtilities import virtualHostUtilities
from random import randint
from plogical.acl import ACLManager
Expand Down Expand Up @@ -785,7 +783,11 @@ def installSpamAssassin(request):
else:
return ACLManager.loadErrorJson()
try:
thread.start_new_thread(mailUtilities.installSpamAssassin, ('Install','SpamAssassin'))

execPath = "sudo python " + virtualHostUtilities.cyberPanel + "/plogical/mailUtilities.py"
execPath = execPath + " installSpamAssassin"
ProcessUtilities.popenExecutioner(execPath)

final_json = json.dumps({'status': 1, 'error_message': "None"})
return HttpResponse(final_json)
except BaseException,msg:
Expand Down
32 changes: 23 additions & 9 deletions filemanager/filemanager.py
Expand Up @@ -39,7 +39,8 @@ def listForTable(self):
if not self.data['completeStartingPath'].find(self.data['home']) > -1:
return self.ajaxPre(0, 'Not allowed to browse this path, going back home!')

command = "sudo ls -la --group-directories-first " + self.returnPathEnclosed(self.data['completeStartingPath'])
command = "sudo ls -la --group-directories-first " + self.returnPathEnclosed(
self.data['completeStartingPath'])
output = ProcessUtilities.outputExecutioner(command).splitlines()

counter = 0
Expand All @@ -49,16 +50,22 @@ def listForTable(self):
currentFile = filter(lambda a: a != '', currentFile)
if currentFile[-1] == '.' or currentFile[-1] == '..' or currentFile[0] == 'total':
continue

if len(currentFile) > 9:
fileName = currentFile[8:]
currentFile[-1] = " ".join(fileName)

dirCheck = 0
if currentFile[0][0] == 'd':
dirCheck = 1

size = str(int(int(currentFile[4])/float(1024)))
size = str(int(int(currentFile[4]) / float(1024)))
lastModified = currentFile[5] + ' ' + currentFile[6] + ' ' + currentFile[7]
finalData[str(counter)] = [currentFile[-1], currentFile[-1], lastModified, size, currentFile[0], dirCheck]
finalData[str(counter)] = [currentFile[-1], currentFile[-1], lastModified, size, currentFile[0],
dirCheck]
counter = counter + 1
except:
continue
except BaseException, msg:
logging.writeToFile(str(msg))

json_data = json.dumps(finalData)
return HttpResponse(json_data)
Expand All @@ -71,7 +78,8 @@ def list(self):
finalData = {}
finalData['status'] = 1

command = "sudo ls -la --group-directories-first " + self.returnPathEnclosed(self.data['completeStartingPath'])
command = "sudo ls -la --group-directories-first " + self.returnPathEnclosed(
self.data['completeStartingPath'])
output = ProcessUtilities.outputExecutioner(command).splitlines()

counter = 0
Expand All @@ -83,11 +91,16 @@ def list(self):
if currentFile[-1] == '.' or currentFile[-1] == '..' or currentFile[0] == 'total':
continue

if len(currentFile) > 9:
fileName = currentFile[8:]
currentFile[-1] = " ".join(fileName)

dirCheck = False
if currentFile[0][0] == 'd':
dirCheck = True

finalData[str(counter)] = [currentFile[-1], self.data['completeStartingPath'] + '/' + currentFile[-1], dirCheck]
finalData[str(counter)] = [currentFile[-1],
self.data['completeStartingPath'] + '/' + currentFile[-1], dirCheck]
counter = counter + 1
except:
continue
Expand All @@ -106,10 +119,11 @@ def createNewFile(self):
if self.data['fileName'].find('..') > -1:
return self.ajaxPre(0, 'Not allowed to move in this path, please choose location inside home!')


command = "sudo touch " + self.returnPathEnclosed(self.data['fileName'])
ProcessUtilities.executioner(command)

self.changeOwner(self.data['fileName'])
self.changeOwner(self.returnPathEnclosed(self.data['fileName']))

json_data = json.dumps(finalData)
return HttpResponse(json_data)
Expand All @@ -125,7 +139,7 @@ def createNewFolder(self):
command = "sudo mkdir " + self.returnPathEnclosed(self.data['folderName'])
ProcessUtilities.executioner(command)

self.changeOwner(self.data['folderName'])
self.changeOwner(self.returnPathEnclosed(self.data['folderName']))

json_data = json.dumps(finalData)
return HttpResponse(json_data)
Expand Down
125 changes: 111 additions & 14 deletions install/install.py
Expand Up @@ -246,7 +246,7 @@ def setup_account_cyberpanel(self):
# self.stdOut("Error in fixing sudoers file: " + str(err), 1, 1, os.EX_OSERR)

self.stdOut("Add Cyberpanel user")
command = "adduser --disabled-login cyberpanel"
command = 'adduser --disabled-login --gecos "" cyberpanel'
cmd = shlex.split(command)
res = subprocess.call(cmd)
if res != 0 and res != 9:
Expand Down Expand Up @@ -288,6 +288,36 @@ def setup_account_cyberpanel(self):

###############################

### Docker User/group

if self.distro == ubuntu:
command = 'adduser --disabled-login --gecos "" docker'
else:
command = "adduser docker"


preFlightsChecks.call(command, self.distro, '[setup_account_cyberpanel]',
'add user cyberpanel',
1, 0, os.EX_OSERR)

command = 'groupadd docker'
preFlightsChecks.call(command, self.distro, '[setup_account_cyberpanel]',
'add user cyberpanel',
1, 0, os.EX_OSERR)

command = 'usermod -aG docker docker'
preFlightsChecks.call(command, self.distro, '[setup_account_cyberpanel]',
'add user cyberpanel',
1, 0, os.EX_OSERR)

command = 'usermod -aG docker cyberpanel'
preFlightsChecks.call(command, self.distro, '[setup_account_cyberpanel]',
'add user cyberpanel',
1, 0, os.EX_OSERR)


###

command = "mkdir -p /etc/letsencrypt/live/"
preFlightsChecks.call(command, self.distro, '[setup_account_cyberpanel]',
'add user cyberpanel',
Expand Down Expand Up @@ -884,17 +914,17 @@ def download_install_CyberPanel(self, mysqlPassword, mysql):

os.chdir(self.path)

#command = "wget http://cyberpanel.sh/CyberPanel.1.8.1.tar.gz"
command = "wget http://cyberpanel.sh/CyberPanelTemp.tar.gz"
command = "wget http://cyberpanel.sh/CyberPanel.1.8.2.tar.gz"
#command = "wget http://cyberpanel.sh/CyberPanelTemp.tar.gz"
preFlightsChecks.call(command, self.distro, '[download_install_CyberPanel]',
'CyberPanel Download',
1, 1, os.EX_OSERR)

##

count = 0
#command = "tar zxf CyberPanel.1.8.1.tar.gz"
command = "tar zxf CyberPanelTemp.tar.gz"
command = "tar zxf CyberPanel.1.8.2.tar.gz"
#command = "tar zxf CyberPanelTemp.tar.gz"
preFlightsChecks.call(command, self.distro, '[download_install_CyberPanel]',
'Extract CyberPanel',1, 1, os.EX_OSERR)

Expand Down Expand Up @@ -976,9 +1006,27 @@ def download_install_CyberPanel(self, mysqlPassword, mysql):
preFlightsChecks.call(command, self.distro, '[download_install_CyberPanel]',
'Move static content', 1, 1, os.EX_OSERR)

try:
path = "/usr/local/CyberCP/version.txt"
writeToFile = open(path, 'w')
writeToFile.writelines('1.8\n')
writeToFile.writelines('2')
writeToFile.close()
except:
pass

def fixCyberPanelPermissions(self):

###### fix Core CyberPanel permissions

command = "usermod -G lscpd,lsadm,nobody lscpd"
preFlightsChecks.call(command, self.distro, '[fixCyberPanelPermissions]',
'add lscpd to important groups', 0, 0, os.EX_OSERR)

command = "usermod -G lscpd,lsadm,nogroup lscpd"
preFlightsChecks.call(command, self.distro, '[fixCyberPanelPermissions]',
'add lscpd to important groups', 0, 0, os.EX_OSERR)

command = "find /usr/local/CyberCP -type d -exec chmod 0755 {} \;"
preFlightsChecks.call(command, self.distro, '[fixCyberPanelPermissions]',
'fix permissions /usr/local/CyberCP', 1, 0, os.EX_OSERR)
Expand Down Expand Up @@ -1015,16 +1063,35 @@ def fixCyberPanelPermissions(self):
preFlightsChecks.call(command, self.distro, '[fixCyberPanelPermissions]',
'fix permissions /usr/local/CyberCP', 1, 0, os.EX_OSERR)

command = "chown -R lscpd:lscpd /usr/local/CyberCP/public/rainloop/data"
command = "chown -R lscpd:lscpd /usr/local/CyberCP/public/phpmyadmin/tmp"
preFlightsChecks.call(command, self.distro, '[fixCyberPanelPermissions]',
'fix permissions /usr/local/CyberCP', 1, 0, os.EX_OSERR)
'fix permissions /usr/local/CyberCP/public/phpmyadmin/tmp', 1, 0, os.EX_OSERR)

## change owner

command = "chown -R root:root /usr/local/lscp"
preFlightsChecks.call(command, self.distro, '[fixCyberPanelPermissions]',
'change owner /usr/local/CyberCP', 1, 0, os.EX_OSERR)

command = "chown -R lscpd:lscpd /usr/local/lscp/cyberpanel/rainloop/data"
preFlightsChecks.call(command, self.distro, '[fixCyberPanelPermissions]',
'change owner /usr/local/CyberCP', 1, 0, os.EX_OSERR)

command = "chmod 700 /usr/local/CyberCP/cli/cyberPanel.py"
preFlightsChecks.call(command, self.distro, '[fixCyberPanelPermissions]',
'Change permissions for CLI.', 1, 0, os.EX_OSERR)

command = "chmod 700 /usr/local/CyberCP/plogical/upgradeCritical.py"
preFlightsChecks.call(command, self.distro, '[fixCyberPanelPermissions]',
'Change permissions for upgrade.', 1, 0, os.EX_OSERR)

command = "chmod 700 /usr/local/CyberCP/postfixSenderPolicy/client.py"
preFlightsChecks.call(command, self.distro, '[fixCyberPanelPermissions]',
'Change permissions for client.', 1, 0, os.EX_OSERR)

command = "chmod 600 /usr/local/CyberCP/CyberCP/settings.py"
preFlightsChecks.call(command, self.distro, '[fixCyberPanelPermissions]',
'Change permissions for client.', 1, 0, os.EX_OSERR)

def install_unzip(self):
self.stdOut("Install unzip")
Expand Down Expand Up @@ -2055,10 +2122,12 @@ def downoad_and_install_raindloop(self):
try:
#######


if not os.path.exists("/usr/local/CyberCP/public"):
os.mkdir("/usr/local/CyberCP/public")

if os.path.exists("/usr/local/CyberCP/public/rainloop"):
return 0

os.chdir("/usr/local/CyberCP/public")

count = 1
Expand Down Expand Up @@ -2156,6 +2225,27 @@ def downoad_and_install_raindloop(self):
break
######

command = "mkdir -p /usr/local/lscp/cyberpanel/rainloop/data"
preFlightsChecks.call(command, self.distro, '[downoad_and_install_rainloop]',
'rainlooop data folder',
1, 0, os.EX_OSERR)

path = "/usr/local/CyberCP/public/rainloop/rainloop/v/1.12.1/include.php"

data = open(path, 'r').readlines()
writeToFile = open(path, 'w')

for items in data:
if items.find("$sCustomDataPath = '';") > -1:
writeToFile.writelines(
" $sCustomDataPath = '/usr/local/lscp/cyberpanel/rainloop/data';\n")
else:
writeToFile.writelines(items)

writeToFile.close()




except OSError, msg:
logging.InstallLog.writeToFile(str(msg) + " [downoad_and_install_rainloop]")
Expand Down Expand Up @@ -2323,7 +2413,7 @@ def installLSCPD(self):
1, 1, os.EX_OSERR)


command = 'openssl req -newkey rsa:1024 -new -nodes -x509 -days 3650 -subj "/C=US/ST=Denial/L=Springfield/O=Dis/CN=www.example.com" -keyout /usr/local/lscp/key.pem -out /usr/local/lscp/cert.pem'
command = 'openssl req -newkey rsa:1024 -new -nodes -x509 -days 3650 -subj "/C=US/ST=Denial/L=Springfield/O=Dis/CN=www.example.com" -keyout /usr/local/lscp/conf/key.pem -out /usr/local/lscp/conf/cert.pem'
preFlightsChecks.call(command, self.distro, '[installLSCPD]',
'Install LSCPD',
1, 1, os.EX_OSERR)
Expand Down Expand Up @@ -2359,11 +2449,16 @@ def installLSCPD(self):
preFlightsChecks.call(command, self.distro, '[installLSCPD]',
'Install LSCPD',
1, 0, os.EX_OSERR)
try:
os.mkdir('/usr/local/lscp/cyberpanel')
except:
pass
try:
os.mkdir('/usr/local/lscp/cyberpanel/logs')
except:
pass

os.mkdir('/usr/local/lscp/cyberpanel')
os.mkdir('/usr/local/lscp/cyberpanel/logs')

self.setupComodoRules()
#self.setupComodoRules()
self.setupPort()
self.setupPythonWSGI()

Expand Down Expand Up @@ -2405,6 +2500,7 @@ def setupComodoRules(self):

modsecConfig = """
module mod_security {
ls_enabled 0
modsecurity on
modsecurity_rules `
SecDebugLogLevel 0
Expand Down Expand Up @@ -3509,8 +3605,9 @@ def main():
checks.setup_gunicorn()

import installCyberPanel

if ent == 0:
installCyberPanel.Main(cwd, mysql, distro, ent, port)
installCyberPanel.Main(cwd, mysql, distro, ent, None, port)
else:
installCyberPanel.Main(cwd, mysql, distro, ent, serial, port)

Expand Down

0 comments on commit 8245398

Please sign in to comment.