mirror of
https://github.com/usmannasir/cyberpanel.git
synced 2025-11-07 13:56:01 +01:00
update mysql password in config files
This commit is contained in:
@@ -172,8 +172,6 @@ class ClusterManager:
|
||||
|
||||
writeToFile.close()
|
||||
|
||||
|
||||
|
||||
## new settings file restored
|
||||
|
||||
command = 'systemctl stop mysql'
|
||||
@@ -187,6 +185,26 @@ class ClusterManager:
|
||||
command = 'systemctl restart lscpd'
|
||||
ProcessUtilities.normalExecutioner(command)
|
||||
|
||||
## Update root password in cyberpanel file
|
||||
|
||||
writeToFile = open('/etc/cyberpanel/mysqlPassword', 'w')
|
||||
writeToFile.write(rootdbpassword)
|
||||
writeToFile.close()
|
||||
|
||||
## Update root password in .my.cnf
|
||||
|
||||
writeToFile = open('/home/cyberpanel/.my.cnf', 'w')
|
||||
content = """[mysqldump]
|
||||
user=root
|
||||
password=%s
|
||||
max_allowed_packet=1024M
|
||||
[mysql]
|
||||
user=root
|
||||
password=%s""" % (rootdbpassword, rootdbpassword)
|
||||
|
||||
writeToFile.write(content)
|
||||
writeToFile.close()
|
||||
|
||||
self.PostStatus('Fail over server successfully booted. [200]')
|
||||
|
||||
###
|
||||
|
||||
@@ -43,6 +43,22 @@ class ACLManager:
|
||||
'"dkimManager": 1, "createFTPAccount": 1, "deleteFTPAccount": 1, "listFTPAccounts": 1, "createBackup": 1,' \
|
||||
' "restoreBackup": 0, "addDeleteDestinations": 0, "scheDuleBackups": 0, "remoteBackups": 0, "googleDriveBackups": 1, "manageSSL": 1, ' \
|
||||
'"hostnameSSL": 0, "mailServerSSL": 0 }'
|
||||
@staticmethod
|
||||
def FindIfChild():
|
||||
try:
|
||||
ipFile = "/etc/cyberpanel/machineIP"
|
||||
f = open(ipFile)
|
||||
ipData = f.read()
|
||||
ipAddress = ipData.split('\n', 1)[0]
|
||||
|
||||
config = json.loads(open('/home/cyberpanel/cluster', 'r').read())
|
||||
if config['failoverServerIP'] == ipAddress:
|
||||
return 1
|
||||
else:
|
||||
return 0
|
||||
except:
|
||||
return 0
|
||||
|
||||
|
||||
@staticmethod
|
||||
def fetchIP():
|
||||
|
||||
@@ -220,6 +220,7 @@ class mailUtilities:
|
||||
virtualHostName = extractDomain.domain + '.' + extractDomain.suffix
|
||||
|
||||
if not os.path.exists("/etc/opendkim/keys/" + virtualHostName + "/default.txt"):
|
||||
|
||||
path = '/etc/opendkim/keys/%s' % (virtualHostName)
|
||||
command = 'mkdir %s' % (path)
|
||||
ProcessUtilities.normalExecutioner(command)
|
||||
@@ -231,7 +232,10 @@ class mailUtilities:
|
||||
else:
|
||||
command = "opendkim-genkey -D /etc/opendkim/keys/%s -d %s -s default" % (
|
||||
virtualHostName, virtualHostName)
|
||||
|
||||
ProcessUtilities.normalExecutioner(command)
|
||||
|
||||
|
||||
## Fix permissions
|
||||
|
||||
command = "chown -R root:opendkim /etc/opendkim/keys/" + virtualHostName
|
||||
@@ -245,7 +249,6 @@ class mailUtilities:
|
||||
|
||||
## Edit key file
|
||||
|
||||
|
||||
keyTable = "/etc/opendkim/KeyTable"
|
||||
configToWrite = "default._domainkey." + actualDomain + " " + actualDomain + ":default:/etc/opendkim/keys/" + virtualHostName + "/default.private\n"
|
||||
|
||||
@@ -271,7 +274,7 @@ class mailUtilities:
|
||||
writeToFile.write(configToWrite)
|
||||
writeToFile.close()
|
||||
|
||||
## Restart postfix and OpenDKIM
|
||||
## Restart Postfix and OpenDKIM
|
||||
|
||||
command = "systemctl restart opendkim"
|
||||
subprocess.call(shlex.split(command))
|
||||
|
||||
@@ -86,7 +86,7 @@ class vhost:
|
||||
except OSError as msg:
|
||||
logging.CyberCPLogFileWriter.writeToFile(
|
||||
str(msg) + " [27 Not able create to directories for virtual host [createDirectories]]")
|
||||
return [0, "[27 Not able to directories for virtual host [createDirectories]]"]
|
||||
#return [0, "[27 Not able to directories for virtual host [createDirectories]]"]
|
||||
|
||||
try:
|
||||
os.makedirs(pathHTML)
|
||||
@@ -107,7 +107,7 @@ class vhost:
|
||||
except OSError as msg:
|
||||
logging.CyberCPLogFileWriter.writeToFile(
|
||||
str(msg) + " [33 Not able to directories for virtual host [createDirectories]]")
|
||||
return [0, "[33 Not able to directories for virtual host [createDirectories]]"]
|
||||
#return [0, "[33 Not able to directories for virtual host [createDirectories]]"]
|
||||
|
||||
try:
|
||||
os.makedirs(pathLogs)
|
||||
@@ -133,7 +133,7 @@ class vhost:
|
||||
except OSError as msg:
|
||||
logging.CyberCPLogFileWriter.writeToFile(
|
||||
str(msg) + " [39 Not able to directories for virtual host [createDirectories]]")
|
||||
return [0, "[39 Not able to directories for virtual host [createDirectories]]"]
|
||||
#return [0, "[39 Not able to directories for virtual host [createDirectories]]"]
|
||||
|
||||
try:
|
||||
## For configuration files permissions will be changed later globally.
|
||||
@@ -142,7 +142,7 @@ class vhost:
|
||||
except OSError as msg:
|
||||
logging.CyberCPLogFileWriter.writeToFile(
|
||||
str(msg) + " [45 Not able to directories for virtual host [createDirectories]]")
|
||||
return [0, "[45 Not able to directories for virtual host [createDirectories]]"]
|
||||
#return [0, "[45 Not able to directories for virtual host [createDirectories]]"]
|
||||
|
||||
try:
|
||||
## For configuration files permissions will be changed later globally.
|
||||
@@ -158,13 +158,13 @@ class vhost:
|
||||
|
||||
except IOError as msg:
|
||||
logging.CyberCPLogFileWriter.writeToFile(str(msg) + " [createDirectories]]")
|
||||
return [0, "[45 Not able to directories for virtual host [createDirectories]]"]
|
||||
#return [0, "[45 Not able to directories for virtual host [createDirectories]]"]
|
||||
|
||||
return [1, 'None']
|
||||
|
||||
except BaseException as msg:
|
||||
logging.CyberCPLogFileWriter.writeToFile(str(msg) + " [createDirectories]")
|
||||
return [0, str(msg)]
|
||||
return [1, str(msg)]
|
||||
|
||||
@staticmethod
|
||||
def finalizeVhostCreation(virtualHostName, virtualHostUser):
|
||||
@@ -242,11 +242,12 @@ class vhost:
|
||||
confFile.write(currentConf)
|
||||
confFile.close()
|
||||
|
||||
return 1
|
||||
|
||||
except BaseException as msg:
|
||||
logging.CyberCPLogFileWriter.writeToFile(
|
||||
str(msg) + " [IO Error with per host config file [perHostVirtualConf]]")
|
||||
return 0
|
||||
return 1
|
||||
else:
|
||||
try:
|
||||
|
||||
@@ -296,12 +297,13 @@ class vhost:
|
||||
command = 'redis-cli set %s' % (currentConf)
|
||||
ProcessUtilities.executioner(command)
|
||||
|
||||
return 1
|
||||
|
||||
except BaseException as msg:
|
||||
logging.CyberCPLogFileWriter.writeToFile(
|
||||
str(msg) + " [IO Error with per host config file [perHostVirtualConf]]")
|
||||
return 0
|
||||
return 1
|
||||
|
||||
|
||||
@staticmethod
|
||||
def createNONSSLMapEntry(virtualHostName):
|
||||
@@ -889,20 +891,23 @@ class vhost:
|
||||
except OSError as msg:
|
||||
logging.CyberCPLogFileWriter.writeToFile(
|
||||
str(msg) + "335 [Not able to create directories for virtual host [createDirectoryForDomain]]")
|
||||
return [0, "[344 Not able to directories for virtual host [createDirectoryForDomain]]"]
|
||||
#return [0, "[344 Not able to directories for virtual host [createDirectoryForDomain]]"]
|
||||
|
||||
try:
|
||||
## For configuration files permissions will be changed later globally.
|
||||
file = open(completePathToConfigFile, "w+")
|
||||
except IOError as msg:
|
||||
logging.CyberCPLogFileWriter.writeToFile(str(msg) + " [createDirectoryForDomain]]")
|
||||
return [0, "[351 Not able to directories for virtual host [createDirectoryForDomain]]"]
|
||||
#return [0, "[351 Not able to directories for virtual host [createDirectoryForDomain]]"]
|
||||
|
||||
if vhost.perHostDomainConf(path, masterDomain, domain, completePathToConfigFile,
|
||||
administratorEmail, phpVersion, virtualHostUser, openBasedir) == 1:
|
||||
return [1, "None"]
|
||||
else:
|
||||
return [0, "[359 Not able to create per host virtual configurations [createDirectoryForDomain]"]
|
||||
pass
|
||||
#return [0, "[359 Not able to create per host virtual configurations [createDirectoryForDomain]"]
|
||||
|
||||
return [1, "None"]
|
||||
|
||||
@staticmethod
|
||||
def perHostDomainConf(path, masterDomain, domain, vhFile, administratorEmail, phpVersion, virtualHostUser, openBasedir):
|
||||
|
||||
@@ -138,6 +138,7 @@ class virtualHostUtilities:
|
||||
if LimitsCheck:
|
||||
|
||||
if ACLManager.websitesLimitCheck(admin, 1) == 0:
|
||||
|
||||
logging.CyberCPLogFileWriter.statusWriter(tempStatusPath,
|
||||
'You\'ve reached maximum websites limit as a reseller. [404]')
|
||||
return 0, 'You\'ve reached maximum websites limit as a reseller.'
|
||||
@@ -148,7 +149,6 @@ class virtualHostUtilities:
|
||||
logging.CyberCPLogFileWriter.statusWriter(tempStatusPath, 'This website already exists. [404]')
|
||||
return 0, "This website already exists."
|
||||
|
||||
|
||||
if Websites.objects.filter(domain=virtualHostName.lstrip('www.')).count() > 0:
|
||||
logging.CyberCPLogFileWriter.statusWriter(tempStatusPath, 'This website already exists. [404]')
|
||||
return 0, "This website already exists."
|
||||
@@ -184,6 +184,9 @@ class virtualHostUtilities:
|
||||
logging.CyberCPLogFileWriter.statusWriter(tempStatusPath, 'This domain exists as Alias. [404]')
|
||||
return 0, "This domain exists as Alias."
|
||||
|
||||
postfixPath = '/home/cyberpanel/postfix'
|
||||
|
||||
if os.path.exists(postfixPath):
|
||||
retValues = mailUtilities.setupDKIM(virtualHostName)
|
||||
if retValues[0] == 0:
|
||||
raise BaseException(retValues[1])
|
||||
@@ -279,6 +282,7 @@ class virtualHostUtilities:
|
||||
return 1, 'None'
|
||||
|
||||
except BaseException as msg:
|
||||
if ACLManager.FindIfChild() == 0:
|
||||
vhost.deleteVirtualHostConfigurations(virtualHostName)
|
||||
logging.CyberCPLogFileWriter.writeToFile(str(msg) + " [createVirtualHost]")
|
||||
logging.CyberCPLogFileWriter.statusWriter(tempStatusPath, str(msg) + " [404]")
|
||||
@@ -437,155 +441,6 @@ class virtualHostUtilities:
|
||||
str(msg) + " [saveRewriteRules]")
|
||||
print("0," + str(msg))
|
||||
|
||||
@staticmethod
|
||||
def installWordPress(domainName, finalPath, virtualHostUser, dbName, dbUser, dbPassword):
|
||||
try:
|
||||
|
||||
FNULL = open(os.devnull, 'w')
|
||||
|
||||
if not os.path.exists(finalPath):
|
||||
os.makedirs(finalPath)
|
||||
|
||||
## checking for directories/files
|
||||
|
||||
dirFiles = os.listdir(finalPath)
|
||||
|
||||
if len(dirFiles) == 1:
|
||||
if dirFiles[0] == ".well-known":
|
||||
pass
|
||||
else:
|
||||
print("0,Target directory should be empty before installation, otherwise data loss could occur.")
|
||||
return
|
||||
elif len(dirFiles) == 0:
|
||||
pass
|
||||
else:
|
||||
print("0,Target directory should be empty before installation, otherwise data loss could occur.")
|
||||
return
|
||||
|
||||
## Get wordpress
|
||||
|
||||
if not os.path.exists("latest.tar.gz"):
|
||||
command = 'wget --no-check-certificate http://wordpress.org/latest.tar.gz -O latest.tar.gz'
|
||||
cmd = shlex.split(command)
|
||||
res = subprocess.call(cmd, stdout=FNULL, stderr=subprocess.STDOUT)
|
||||
|
||||
command = 'tar -xzvf latest.tar.gz -C ' + finalPath
|
||||
|
||||
cmd = shlex.split(command)
|
||||
|
||||
res = subprocess.call(cmd, stdout=FNULL, stderr=subprocess.STDOUT)
|
||||
|
||||
## Get plugin
|
||||
|
||||
if not os.path.exists("litespeed-cache.1.1.5.1.zip"):
|
||||
command = 'wget --no-check-certificate https://downloads.wordpress.org/plugin/litespeed-cache.1.1.5.1.zip'
|
||||
|
||||
cmd = shlex.split(command)
|
||||
|
||||
res = subprocess.call(cmd, stdout=FNULL, stderr=subprocess.STDOUT)
|
||||
|
||||
command = 'unzip litespeed-cache.1.1.5.1.zip -d ' + finalPath
|
||||
|
||||
cmd = shlex.split(command)
|
||||
|
||||
res = subprocess.call(cmd, stdout=FNULL, stderr=subprocess.STDOUT)
|
||||
|
||||
root = finalPath
|
||||
|
||||
for filename in listdir(join(root, 'wordpress')):
|
||||
move(join(root, 'wordpress', filename), join(root, filename))
|
||||
|
||||
rmdir(root + "wordpress")
|
||||
|
||||
shutil.copytree(finalPath + "litespeed-cache", finalPath + "wp-content/plugins/litespeed-cache")
|
||||
shutil.rmtree(finalPath + "litespeed-cache")
|
||||
|
||||
## edit config file
|
||||
|
||||
wpconfigfile = finalPath + "wp-config-sample.php"
|
||||
|
||||
data = open(wpconfigfile, "r").readlines()
|
||||
|
||||
writeDataToFile = open(wpconfigfile, "w")
|
||||
|
||||
defDBName = "define('DB_NAME', '" + dbName + "');" + "\n"
|
||||
defDBUser = "define('DB_USER', '" + dbUser + "');" + "\n"
|
||||
defDBPassword = "define('DB_PASSWORD', '" + dbPassword + "');" + "\n"
|
||||
|
||||
for items in data:
|
||||
if items.find("DB_NAME") > -1:
|
||||
if items.find("database_name_here") > -1:
|
||||
writeDataToFile.writelines(defDBName)
|
||||
elif items.find("DB_USER") > -1:
|
||||
if items.find("username_here") > -1:
|
||||
writeDataToFile.writelines(defDBUser)
|
||||
elif items.find("DB_PASSWORD") > -1:
|
||||
writeDataToFile.writelines(defDBPassword)
|
||||
else:
|
||||
writeDataToFile.writelines(items)
|
||||
|
||||
writeDataToFile.close()
|
||||
|
||||
os.rename(wpconfigfile, finalPath + 'wp-config.php')
|
||||
|
||||
command = "chown -R " + virtualHostUser + ":" + virtualHostUser + " " + "/home/" + domainName + "/public_html/"
|
||||
|
||||
cmd = shlex.split(command)
|
||||
|
||||
res = subprocess.call(cmd, stdout=FNULL, stderr=subprocess.STDOUT)
|
||||
|
||||
vhost.addRewriteRules(domainName)
|
||||
|
||||
installUtilities.installUtilities.reStartLiteSpeed()
|
||||
|
||||
print("1,None")
|
||||
|
||||
|
||||
except BaseException as msg:
|
||||
# remove the downloaded files
|
||||
try:
|
||||
|
||||
shutil.rmtree(finalPath)
|
||||
except:
|
||||
logging.CyberCPLogFileWriter.writeToFile("shutil.rmtree(finalPath)")
|
||||
|
||||
homeDir = "/home/" + domainName + "/public_html"
|
||||
|
||||
if not os.path.exists(homeDir):
|
||||
FNULL = open(os.devnull, 'w')
|
||||
os.mkdir(homeDir)
|
||||
command = "chown -R " + virtualHostUser + ":" + virtualHostUser + " " + homeDir
|
||||
cmd = shlex.split(command)
|
||||
res = subprocess.call(cmd, stdout=FNULL, stderr=subprocess.STDOUT)
|
||||
|
||||
print("0," + str(msg))
|
||||
return
|
||||
|
||||
@staticmethod
|
||||
def installJoomla(domainName, finalPath, virtualHostUser, dbName, dbUser, dbPassword, username, password, prefix,
|
||||
sitename, tempStatusPath):
|
||||
try:
|
||||
|
||||
extraArgs = {}
|
||||
extraArgs['domainName'] = domainName
|
||||
extraArgs['finalPath'] = finalPath
|
||||
extraArgs['virtualHostUser'] = virtualHostUser
|
||||
extraArgs['dbName'] = dbName
|
||||
extraArgs['dbUser'] = dbUser
|
||||
extraArgs['dbPassword'] = dbPassword
|
||||
extraArgs['username'] = username
|
||||
extraArgs['password'] = password
|
||||
extraArgs['prefix'] = prefix
|
||||
extraArgs['sitename'] = sitename
|
||||
extraArgs['tempStatusPath'] = tempStatusPath
|
||||
|
||||
background = ApplicationInstaller('joomla', extraArgs)
|
||||
background.start()
|
||||
|
||||
|
||||
except BaseException as msg:
|
||||
logging.CyberCPLogFileWriter.writeToFile(str(msg) + ' [installJoomla]')
|
||||
|
||||
@staticmethod
|
||||
def issueSSLForHostName(virtualHost, path):
|
||||
try:
|
||||
@@ -1145,6 +1000,9 @@ class virtualHostUtilities:
|
||||
|
||||
logging.CyberCPLogFileWriter.statusWriter(tempStatusPath, 'DKIM Setup..,30')
|
||||
|
||||
postFixPath = '/home/cyberpanel/postfix'
|
||||
|
||||
if os.path.exists(postFixPath):
|
||||
retValues = mailUtilities.setupDKIM(virtualHostName)
|
||||
if retValues[0] == 0:
|
||||
raise BaseException(retValues[1])
|
||||
@@ -1157,6 +1015,7 @@ class virtualHostUtilities:
|
||||
master.adminEmail, master.externalApp, openBasedir)
|
||||
if retValues[0] == 0:
|
||||
raise BaseException(retValues[1])
|
||||
|
||||
if not os.path.exists(virtualHostUtilities.redisConf):
|
||||
retValues = vhost.createConfigInMainDomainHostFile(virtualHostName, masterDomain)
|
||||
|
||||
@@ -1221,8 +1080,10 @@ class virtualHostUtilities:
|
||||
return 1, "None"
|
||||
|
||||
except BaseException as msg:
|
||||
if ACLManager.FindIfChild() == 0:
|
||||
numberOfWebsites = Websites.objects.count() + ChildDomains.objects.count()
|
||||
vhost.deleteCoreConf(virtualHostName, numberOfWebsites)
|
||||
|
||||
logging.CyberCPLogFileWriter.statusWriter(tempStatusPath, str(msg) + ". [404]")
|
||||
logging.CyberCPLogFileWriter.writeToFile(
|
||||
str(msg) + " [createDomain]")
|
||||
|
||||
Reference in New Issue
Block a user