|
|
|
@ -5,6 +5,7 @@ import io |
|
|
|
|
import os |
|
|
|
|
import time |
|
|
|
|
import re |
|
|
|
|
import json |
|
|
|
|
|
|
|
|
|
sys.path.append(os.getcwd() + "/class/core") |
|
|
|
|
import mw |
|
|
|
@ -44,6 +45,13 @@ def getArgs(): |
|
|
|
|
return tmp |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def checkArgs(data, ck=[]): |
|
|
|
|
for i in range(len(ck)): |
|
|
|
|
if not ck[i] in data: |
|
|
|
|
return (False, mw.returnJson(False, '参数:(' + ck[i] + ')没有!')) |
|
|
|
|
return (True, mw.returnJson(True, 'ok')) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def getConf(): |
|
|
|
|
return mw.getServerDir() + '/web_conf/nginx/vhost/phpmyadmin.conf' |
|
|
|
|
|
|
|
|
@ -107,9 +115,50 @@ def contentReplace(content): |
|
|
|
|
content = content.replace('{$PHP_CONF_PATH}', php_conf_dir) |
|
|
|
|
content = content.replace('{$PHP_VER}', php_ver) |
|
|
|
|
content = content.replace('{$BLOWFISH_SECRET}', blowfish_secret) |
|
|
|
|
|
|
|
|
|
cfg = getCfg() |
|
|
|
|
if (cfg['choose'] == ""): |
|
|
|
|
content = content.replace('{$CHOOSE_DB}', 'mysql') |
|
|
|
|
content = content.replace('{$CHOOSE_DB_DIR}', 'mysql') |
|
|
|
|
else: |
|
|
|
|
content = content.replace('{$CHOOSE_DB}', 'MariaDB') |
|
|
|
|
content = content.replace('{$CHOOSE_DB_DIR}', 'mariadb') |
|
|
|
|
|
|
|
|
|
return content |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def initCfg(): |
|
|
|
|
cfg = getServerDir() + "/cfg.json" |
|
|
|
|
if not os.path.exists(cfg): |
|
|
|
|
data = {} |
|
|
|
|
data['port'] = '888' |
|
|
|
|
data['choose'] = '' |
|
|
|
|
data['username'] = 'admin' |
|
|
|
|
data['password'] = 'admin' |
|
|
|
|
mw.writeFile(cfg, json.dumps(data)) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def setCfg(key, val): |
|
|
|
|
cfg = getServerDir() + "/cfg.json" |
|
|
|
|
data = mw.readFile(cfg) |
|
|
|
|
data = json.loads(data) |
|
|
|
|
data[key] = val |
|
|
|
|
mw.writeFile(cfg, json.dumps(data)) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def getCfg(): |
|
|
|
|
cfg = getServerDir() + "/cfg.json" |
|
|
|
|
data = mw.readFile(cfg) |
|
|
|
|
data = json.loads(data) |
|
|
|
|
return data |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def returnCfg(): |
|
|
|
|
cfg = getServerDir() + "/cfg.json" |
|
|
|
|
data = mw.readFile(cfg) |
|
|
|
|
return data |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def status(): |
|
|
|
|
conf = getConf() |
|
|
|
|
conf_inc = getServerDir() + '/phpmyadmin/config.inc.php' |
|
|
|
@ -120,6 +169,8 @@ def status(): |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def start(): |
|
|
|
|
initCfg() |
|
|
|
|
|
|
|
|
|
file_tpl = getPluginDir() + '/conf/phpmyadmin.conf' |
|
|
|
|
file_run = getConf() |
|
|
|
|
|
|
|
|
@ -128,6 +179,14 @@ def start(): |
|
|
|
|
centent = contentReplace(centent) |
|
|
|
|
mw.writeFile(file_run, centent) |
|
|
|
|
|
|
|
|
|
pma_path = getServerDir() + '/pma.pass' |
|
|
|
|
if not os.path.exists(pma_path): |
|
|
|
|
username = mw.getRandomString(10) |
|
|
|
|
pass_cmd = username + ':' + mw.hasPwd(username) |
|
|
|
|
setCfg('username', username) |
|
|
|
|
setCfg('password', username) |
|
|
|
|
mw.writeFile(pma_path, pass_cmd) |
|
|
|
|
|
|
|
|
|
tmp = getServerDir() + '/phpmyadmin/tmp' |
|
|
|
|
if not os.path.exists(tmp): |
|
|
|
|
os.mkdir(tmp) |
|
|
|
@ -179,12 +238,11 @@ def setPhpVer(): |
|
|
|
|
file_tpl = getPluginDir() + '/conf/phpmyadmin.conf' |
|
|
|
|
file_run = getConf() |
|
|
|
|
|
|
|
|
|
centent = mw.readFile(file_tpl) |
|
|
|
|
centent = contentReplace(centent) |
|
|
|
|
mw.writeFile(file_run, centent) |
|
|
|
|
content = mw.readFile(file_tpl) |
|
|
|
|
content = contentReplace(content) |
|
|
|
|
mw.writeFile(file_run, content) |
|
|
|
|
|
|
|
|
|
mw.restartWeb() |
|
|
|
|
|
|
|
|
|
return 'ok' |
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -195,6 +253,11 @@ def getSetPhpVer(): |
|
|
|
|
return '' |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def getPmaOption(): |
|
|
|
|
data = getCfg() |
|
|
|
|
return mw.returnJson(True, 'ok', data) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def getPmaPort(): |
|
|
|
|
try: |
|
|
|
|
port = getPort() |
|
|
|
@ -206,8 +269,9 @@ def getPmaPort(): |
|
|
|
|
|
|
|
|
|
def setPmaPort(): |
|
|
|
|
args = getArgs() |
|
|
|
|
if not 'port' in args: |
|
|
|
|
return mw.returnJson(False, 'port missing!') |
|
|
|
|
data = checkArgs(args, ['port']) |
|
|
|
|
if not data[0]: |
|
|
|
|
return data[1] |
|
|
|
|
|
|
|
|
|
port = args['port'] |
|
|
|
|
if port == '80': |
|
|
|
@ -224,6 +288,63 @@ def setPmaPort(): |
|
|
|
|
return mw.returnJson(True, '修改成功!') |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def setPmaChoose(): |
|
|
|
|
args = getArgs() |
|
|
|
|
data = checkArgs(args, ['choose']) |
|
|
|
|
if not data[0]: |
|
|
|
|
return data[1] |
|
|
|
|
|
|
|
|
|
choose = args['choose'] |
|
|
|
|
setCfg('choose', choose) |
|
|
|
|
|
|
|
|
|
conf_run = getServerDir() + '/phpmyadmin/config.inc.php' |
|
|
|
|
conf_tpl = getPluginDir() + '/conf/config.inc.php' |
|
|
|
|
centent = mw.readFile(conf_tpl) |
|
|
|
|
centent = contentReplace(centent) |
|
|
|
|
mw.writeFile(conf_run, centent) |
|
|
|
|
|
|
|
|
|
mw.restartWeb() |
|
|
|
|
return mw.returnJson(True, '修改成功!') |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def setPmaUsername(): |
|
|
|
|
args = getArgs() |
|
|
|
|
data = checkArgs(args, ['username']) |
|
|
|
|
if not data[0]: |
|
|
|
|
return data[1] |
|
|
|
|
|
|
|
|
|
username = args['username'] |
|
|
|
|
setCfg('username', username) |
|
|
|
|
|
|
|
|
|
cfg = getCfg() |
|
|
|
|
pma_path = getServerDir() + '/pma.pass' |
|
|
|
|
username = mw.getRandomString(10) |
|
|
|
|
pass_cmd = cfg['username'] + ':' + mw.hasPwd(cfg['password']) |
|
|
|
|
mw.writeFile(pma_path, pass_cmd) |
|
|
|
|
|
|
|
|
|
mw.restartWeb() |
|
|
|
|
return mw.returnJson(True, '修改成功!') |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def setPmaPassword(): |
|
|
|
|
args = getArgs() |
|
|
|
|
data = checkArgs(args, ['password']) |
|
|
|
|
if not data[0]: |
|
|
|
|
return data[1] |
|
|
|
|
|
|
|
|
|
password = args['password'] |
|
|
|
|
setCfg('password', password) |
|
|
|
|
|
|
|
|
|
cfg = getCfg() |
|
|
|
|
pma_path = getServerDir() + '/pma.pass' |
|
|
|
|
username = mw.getRandomString(10) |
|
|
|
|
pass_cmd = cfg['username'] + ':' + mw.hasPwd(cfg['password']) |
|
|
|
|
mw.writeFile(pma_path, pass_cmd) |
|
|
|
|
|
|
|
|
|
mw.restartWeb() |
|
|
|
|
return mw.returnJson(True, '修改成功!') |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def accessLog(): |
|
|
|
|
return getServerDir() + '/access.log' |
|
|
|
|
|
|
|
|
@ -252,6 +373,8 @@ if __name__ == "__main__": |
|
|
|
|
print(getConf()) |
|
|
|
|
elif func == 'version': |
|
|
|
|
print(Version()) |
|
|
|
|
elif func == 'get_cfg': |
|
|
|
|
print(returnCfg()) |
|
|
|
|
elif func == 'config_inc': |
|
|
|
|
print(getConfInc()) |
|
|
|
|
elif func == 'get_home_page': |
|
|
|
@ -264,6 +387,14 @@ if __name__ == "__main__": |
|
|
|
|
print(getPmaPort()) |
|
|
|
|
elif func == 'set_pma_port': |
|
|
|
|
print(setPmaPort()) |
|
|
|
|
elif func == 'get_pma_option': |
|
|
|
|
print(getPmaOption()) |
|
|
|
|
elif func == 'set_pma_choose': |
|
|
|
|
print(setPmaChoose()) |
|
|
|
|
elif func == 'set_pma_username': |
|
|
|
|
print(setPmaUsername()) |
|
|
|
|
elif func == 'set_pma_password': |
|
|
|
|
print(setPmaPassword()) |
|
|
|
|
elif func == 'access_log': |
|
|
|
|
print(accessLog()) |
|
|
|
|
elif func == 'error_log': |
|
|
|
|