|
Server : LiteSpeed System : Linux srv526460274 5.15.0-164-generic #174-Ubuntu SMP Fri Nov 14 20:25:16 UTC 2025 x86_64 User : kerao9884 ( 1082) PHP Version : 8.0.30 Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare, Directory : /usr/local/CyberCP/install/ |
Upload File : |
import subprocess, shlex
import install
import time
class mysqlUtilities:
@staticmethod
def createDatabase(dbname, dbuser, dbpassword, publicip):
try:
createDB = "CREATE DATABASE " + dbname
try:
from json import loads
mysqlData = loads(open("/etc/cyberpanel/mysqlPassword", 'r').read())
initCommand = 'mariadb -h %s --port %s -u %s -p%s -e "' % (mysqlData['mysqlhost'], mysqlData['mysqlport'], mysqlData['mysqluser'], mysqlData['mysqlpassword'])
remote = 1
except:
passFile = "/etc/cyberpanel/mysqlPassword"
f = open(passFile)
data = f.read()
password = data.split('\n', 1)[0]
initCommand = 'mariadb -u root -p' + password + ' -e "'
remote = 0
command = initCommand + createDB + '"'
if install.preFlightsChecks.debug:
print(command)
time.sleep(10)
cmd = shlex.split(command)
res = subprocess.call(cmd)
if res == 1:
return 0
if remote:
createUser = "CREATE USER '" + dbuser + "'@'%s' IDENTIFIED BY '" % (publicip) + dbpassword + "'"
else:
createUser = "CREATE USER '" + dbuser + "'@'localhost' IDENTIFIED BY '" + dbpassword + "'"
command = initCommand + createUser + '"'
if install.preFlightsChecks.debug:
print(command)
time.sleep(10)
cmd = shlex.split(command)
res = subprocess.call(cmd)
if res == 1:
return 0
else:
if remote:
### DO Check
if mysqlData['mysqlhost'].find('ondigitalocean') > -1:
alterUserPassword = "ALTER USER 'cyberpanel'@'%s' IDENTIFIED WITH mysql_native_password BY '%s'" % (
publicip, dbpassword)
command = initCommand + alterUserPassword + '"'
if install.preFlightsChecks.debug:
print(command)
time.sleep(10)
cmd = shlex.split(command)
subprocess.call(cmd)
## RDS Check
if mysqlData['mysqlhost'].find('rds.amazon') == -1:
dropDB = "GRANT ALL PRIVILEGES ON " + dbname + ".* TO '" + dbuser + "'@'%s'" % (publicip)
else:
dropDB = "GRANT INDEX, DROP, UPDATE, ALTER, CREATE, SELECT, INSERT, DELETE ON " + dbname + ".* TO '" + dbuser + "'@'%s'" % (publicip)
else:
dropDB = "GRANT ALL PRIVILEGES ON " + dbname + ".* TO '" + dbuser + "'@'localhost'"
command = initCommand + dropDB + '"'
if install.preFlightsChecks.debug:
print(command)
time.sleep(10)
cmd = shlex.split(command)
res = subprocess.call(cmd)
if res == 1:
return 0
return 1
except BaseException as msg:
return 0