mirror of
https://github.com/usmannasir/cyberpanel.git
synced 2025-11-07 13:56:01 +01:00
finish initial stage of remote mysql
This commit is contained in:
@@ -95,13 +95,18 @@ class preFlightsChecks:
|
||||
cyberPanelMirror = "mirror.cyberpanel.net/pip"
|
||||
cdn = 'cyberpanel.sh'
|
||||
|
||||
def __init__(self, rootPath, ip, path, cwd, cyberPanelPath, distro):
|
||||
def __init__(self, rootPath, ip, path, cwd, cyberPanelPath, distro, remotemysql = None , mysqlhost = None, mysqluser = None, mysqlpassword = None, mysqlport = None):
|
||||
self.ipAddr = ip
|
||||
self.path = path
|
||||
self.cwd = cwd
|
||||
self.server_root_path = rootPath
|
||||
self.cyberPanelPath = cyberPanelPath
|
||||
self.distro = distro
|
||||
self.remotemysql = remotemysql
|
||||
self.mysqlhost = mysqlhost
|
||||
self.mysqluser = mysqluser
|
||||
self.mysqlpassword = mysqlpassword
|
||||
self.mysqlport = mysqlport
|
||||
|
||||
@staticmethod
|
||||
def stdOut(message, log=0, do_exit=0, code=os.EX_OK):
|
||||
@@ -373,11 +378,15 @@ class preFlightsChecks:
|
||||
|
||||
### update password:
|
||||
|
||||
if self.remotemysql == 'OFF':
|
||||
|
||||
passFile = "/etc/cyberpanel/mysqlPassword"
|
||||
|
||||
f = open(passFile)
|
||||
data = f.read()
|
||||
password = data.split('\n', 1)[0]
|
||||
else:
|
||||
password = self.mysqlpassword
|
||||
|
||||
### Put correct mysql passwords in settings file!
|
||||
|
||||
@@ -396,6 +405,7 @@ class preFlightsChecks:
|
||||
SK = "SECRET_KEY = '%s'\n" % (generate_pass(50))
|
||||
writeDataToFile.writelines(SK)
|
||||
continue
|
||||
|
||||
if mysql == 'Two':
|
||||
if items.find("'PASSWORD':") > -1:
|
||||
if counter == 0:
|
||||
@@ -411,7 +421,6 @@ class preFlightsChecks:
|
||||
if counter == 0:
|
||||
writeDataToFile.writelines(" 'PASSWORD': '" + mysqlPassword + "'," + "\n")
|
||||
counter = counter + 1
|
||||
|
||||
else:
|
||||
writeDataToFile.writelines(" 'PASSWORD': '" + password + "'," + "\n")
|
||||
elif items.find('127.0.0.1') > -1:
|
||||
@@ -421,6 +430,17 @@ class preFlightsChecks:
|
||||
else:
|
||||
writeDataToFile.writelines(items)
|
||||
|
||||
|
||||
if self.remotemysql == 'ON':
|
||||
command = "sed -i 's|'HOST': 'localhost',|'HOST': '%s',|g' %s" % (self.mysqlhost, path)
|
||||
preFlightsChecks.call(command, self.distro, command, command, 1, 1, os.EX_OSERR)
|
||||
|
||||
command = "sed -i 's|'USER': 'root',|'USER': '%s',|g' %s" % (self.mysqluser, path)
|
||||
preFlightsChecks.call(command, self.distro, command, command, 1, 1, os.EX_OSERR)
|
||||
|
||||
command = "sed -i 's|'PORT':''|'PORT':'%s'|g' %s" % (self.mysqlport, path)
|
||||
preFlightsChecks.call(command, self.distro, command, command, 1, 1, os.EX_OSERR)
|
||||
|
||||
if self.distro == ubuntu:
|
||||
os.fchmod(writeDataToFile.fileno(), stat.S_IRUSR | stat.S_IWUSR)
|
||||
|
||||
@@ -2100,6 +2120,11 @@ def main():
|
||||
parser.add_argument('--serial', help='Install LS Ent or OpenLiteSpeed')
|
||||
parser.add_argument('--port', help='LSCPD Port')
|
||||
parser.add_argument('--redis', help='vHosts on Redis - Requires LiteSpeed Enterprise')
|
||||
parser.add_argument('--remotemysql', help='Opt to choose local or remote MySQL')
|
||||
parser.add_argument('--mysqlhost', help='MySQL host if remote is chosen.')
|
||||
parser.add_argument('--mysqluser', help='MySQL user if remote is chosen.')
|
||||
parser.add_argument('--mysqlpassword', help='MySQL password if remote is chosen.')
|
||||
parser.add_argument('--mysqlport', help='MySQL port if remote is chosen.')
|
||||
args = parser.parse_args()
|
||||
|
||||
logging.InstallLog.writeToFile("Starting CyberPanel installation..")
|
||||
@@ -2135,12 +2160,22 @@ def main():
|
||||
|
||||
cwd = os.getcwd()
|
||||
|
||||
distro = get_distro()
|
||||
checks = preFlightsChecks("/usr/local/lsws/", args.publicip, "/usr/local", cwd, "/usr/local/CyberCP", distro)
|
||||
checks.mountTemp()
|
||||
if args.remotemsql == 'ON':
|
||||
remotemysql = args.remotemysql
|
||||
mysqlhost = args.mysqlhost
|
||||
mysqluser = args.mysqluser
|
||||
mysqlpassword = args.mysqlpassword
|
||||
mysqlport = args.mysqlport
|
||||
else:
|
||||
remotemysql = args.remotemysql
|
||||
mysqlhost = ''
|
||||
mysqluser = ''
|
||||
mysqlpassword = ''
|
||||
mysqlport = ''
|
||||
|
||||
# if distro == ubuntu:
|
||||
# os.chdir("/etc/cyberpanel")
|
||||
distro = get_distro()
|
||||
checks = preFlightsChecks("/usr/local/lsws/", args.publicip, "/usr/local", cwd, "/usr/local/CyberCP", distro, remotemysql, mysqlhost, mysqluser, mysqlpassword, mysqlport)
|
||||
checks.mountTemp()
|
||||
|
||||
if args.port == None:
|
||||
port = "8090"
|
||||
@@ -2160,10 +2195,11 @@ def main():
|
||||
|
||||
import installCyberPanel
|
||||
|
||||
|
||||
if ent == 0:
|
||||
installCyberPanel.Main(cwd, mysql, distro, ent, None, port, args.ftp, args.powerdns, args.publicip)
|
||||
installCyberPanel.Main(cwd, mysql, distro, ent, None, port, args.ftp, args.powerdns, args.publicip, remotemysql, mysqlhost, mysqluser, mysqlpassword, mysqlport)
|
||||
else:
|
||||
installCyberPanel.Main(cwd, mysql, distro, ent, serial, port, args.ftp, args.powerdns, args.publicip)
|
||||
installCyberPanel.Main(cwd, mysql, distro, ent, serial, port, args.ftp, args.powerdns, args.publicip, remotemysql, mysqlhost, mysqluser, mysqlpassword, mysqlport)
|
||||
|
||||
checks.setupPHPAndComposer()
|
||||
checks.fix_selinux_issue()
|
||||
|
||||
@@ -38,7 +38,7 @@ class InstallCyberPanel:
|
||||
mysql_Root_password = ""
|
||||
mysqlPassword = ""
|
||||
|
||||
def __init__(self, rootPath, cwd, distro, ent, serial = None, port = None, ftp = None, dns = None, publicip = None):
|
||||
def __init__(self, rootPath, cwd, distro, ent, serial = None, port = None, ftp = None, dns = None, publicip = None, remotemysql = None , mysqlhost = None, mysqluser = None, mysqlpassword = None, mysqlport = None):
|
||||
self.server_root_path = rootPath
|
||||
self.cwd = cwd
|
||||
self.distro = distro
|
||||
@@ -48,6 +48,11 @@ class InstallCyberPanel:
|
||||
self.ftp = None
|
||||
self.dns = dns
|
||||
self.publicip = publicip
|
||||
self.remotemysql = remotemysql
|
||||
self.mysqlhost = mysqlhost
|
||||
self.mysqluser = mysqluser
|
||||
self.mysqlpassword = mysqlpassword
|
||||
self.mysqlport = mysqlport
|
||||
|
||||
@staticmethod
|
||||
def stdOut(message, log=0, exit=0, code=os.EX_OK):
|
||||
@@ -230,7 +235,7 @@ class InstallCyberPanel:
|
||||
subprocess.call(command, shell=True)
|
||||
|
||||
def installMySQL(self, mysql):
|
||||
|
||||
if self.remotemysql == 'OFF':
|
||||
############## Install mariadb ######################
|
||||
|
||||
if self.distro == ubuntu:
|
||||
@@ -289,6 +294,7 @@ class InstallCyberPanel:
|
||||
self.startMariaDB()
|
||||
|
||||
def changeMYSQLRootPassword(self):
|
||||
if self.remotemysql == 'OFF':
|
||||
if self.distro == ubuntu:
|
||||
passwordCMD = "use mysql;update user set password=PASSWORD('" + InstallCyberPanel.mysql_Root_password + "') where User='root';UPDATE user SET plugin='' WHERE User='root';flush privileges;"
|
||||
else:
|
||||
@@ -601,12 +607,14 @@ class InstallCyberPanel:
|
||||
install.preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR)
|
||||
|
||||
|
||||
def Main(cwd, mysql, distro, ent, serial = None, port = "8090", ftp = None, dns = None, publicip = None):
|
||||
def Main(cwd, mysql, distro, ent, serial = None, port = "8090", ftp = None, dns = None, publicip = None, remotemysql = None , mysqlhost = None, mysqluser = None, mysqlpassword = None, mysqlport = None):
|
||||
|
||||
InstallCyberPanel.mysqlPassword = randomPassword.generate_pass()
|
||||
InstallCyberPanel.mysql_Root_password = randomPassword.generate_pass()
|
||||
|
||||
file_name = '/etc/cyberpanel/mysqlPassword'
|
||||
|
||||
if remotemysql == 'OFF':
|
||||
if os.access(file_name, os.F_OK):
|
||||
password = open(file_name, 'r')
|
||||
InstallCyberPanel.mysql_Root_password = password.readline()
|
||||
@@ -614,9 +622,17 @@ def Main(cwd, mysql, distro, ent, serial = None, port = "8090", ftp = None, dns
|
||||
else:
|
||||
password = open(file_name, "w")
|
||||
password.writelines(InstallCyberPanel.mysql_Root_password)
|
||||
command = 'chmod 640 %s' % (file_name)
|
||||
password.close()
|
||||
else:
|
||||
mysqlData = {'remotemysql': remotemysql, 'mysqlhost': mysqlhost, 'mysqluser': mysqluser, 'mysqlpassword': mysqlpassword, 'mysqlport': mysqlport}
|
||||
from json import dumps
|
||||
writeToFile = open(file_name, 'w')
|
||||
writeToFile.write(dumps(mysqlData))
|
||||
writeToFile.close()
|
||||
|
||||
|
||||
try:
|
||||
command = 'chmod 640 %s' % (file_name)
|
||||
install.preFlightsChecks.call(command, distro, '[chmod]',
|
||||
'',
|
||||
1, 0, os.EX_OSERR)
|
||||
@@ -627,15 +643,12 @@ def Main(cwd, mysql, distro, ent, serial = None, port = "8090", ftp = None, dns
|
||||
except:
|
||||
pass
|
||||
|
||||
|
||||
|
||||
|
||||
if distro == centos:
|
||||
InstallCyberPanel.mysqlPassword = randomPassword.generate_pass()
|
||||
else:
|
||||
InstallCyberPanel.mysqlPassword = InstallCyberPanel.mysql_Root_password
|
||||
|
||||
installer = InstallCyberPanel("/usr/local/lsws/",cwd, distro, ent, serial, port, ftp, dns, publicip)
|
||||
installer = InstallCyberPanel("/usr/local/lsws/",cwd, distro, ent, serial, port, ftp, dns, publicip, remotemysql, mysqlhost, mysqluser, mysqlpassword, mysqlport)
|
||||
|
||||
installer.installLiteSpeed()
|
||||
if ent == 0:
|
||||
@@ -646,9 +659,10 @@ def Main(cwd, mysql, distro, ent, serial = None, port = "8090", ftp = None, dns
|
||||
|
||||
installer.installMySQL(mysql)
|
||||
installer.changeMYSQLRootPassword()
|
||||
#installer.changeMYSQLRootPasswordCyberPanel(mysql)
|
||||
|
||||
installer.startMariaDB()
|
||||
|
||||
if remotemysql == 'OFF':
|
||||
if distro == ubuntu:
|
||||
installer.fixMariaDB()
|
||||
|
||||
|
||||
@@ -7,6 +7,14 @@ class mysqlUtilities:
|
||||
|
||||
try:
|
||||
|
||||
try:
|
||||
from json import loads
|
||||
mysqlData = loads(open("/etc/cyberpanel/mysqlPassword", 'r').read())
|
||||
|
||||
createDB = "CREATE DATABASE " + dbname
|
||||
initCommand = 'mysql -h %s --port %s -u %s -p%s -e "' % (mysqlData['mysqlhost'], mysqlData['mysqlport'], mysqlData['mysqluser'], mysqlData['mysqlpassword'])
|
||||
|
||||
except:
|
||||
passFile = "/etc/cyberpanel/mysqlPassword"
|
||||
|
||||
f = open(passFile)
|
||||
@@ -14,8 +22,10 @@ class mysqlUtilities:
|
||||
password = data.split('\n', 1)[0]
|
||||
|
||||
createDB = "CREATE DATABASE " + dbname
|
||||
initCommand = 'mysql -u root -p' + password + ' -e "'
|
||||
|
||||
command = initCommand + createDB + '"'
|
||||
|
||||
command = 'mysql -u root -p' + password + ' -e "' + createDB + '"'
|
||||
cmd = shlex.split(command)
|
||||
res = subprocess.call(cmd)
|
||||
|
||||
@@ -24,7 +34,7 @@ class mysqlUtilities:
|
||||
|
||||
createUser = "CREATE USER '" + dbuser + "'@'localhost' IDENTIFIED BY '" + dbpassword + "'"
|
||||
|
||||
command = 'mysql -u root -p' + password + ' -e "' + createUser + '"'
|
||||
command = initCommand + createUser + '"'
|
||||
|
||||
cmd = shlex.split(command)
|
||||
res = subprocess.call(cmd)
|
||||
@@ -33,7 +43,7 @@ class mysqlUtilities:
|
||||
return 0
|
||||
else:
|
||||
dropDB = "GRANT ALL PRIVILEGES ON " + dbname + ".* TO '" + dbuser + "'@'localhost'"
|
||||
command = 'mysql -u root -p' + password + ' -e "' + dropDB + '"'
|
||||
command = initCommand + dropDB + '"'
|
||||
cmd = shlex.split(command)
|
||||
res = subprocess.call(cmd)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user