mirror of
https://github.com/midoks/mdserver-web
synced 2026-11-04 19:16:00 +08:00
@@ -1543,20 +1543,33 @@ def getDbUserAccessDiff(db_access, input_access):
|
||||
add = []
|
||||
delete = []
|
||||
|
||||
host_var = 'localhost'
|
||||
local_ipvar = '127.0.0.1'
|
||||
|
||||
for ac in input_access:
|
||||
if ac == "localhost":
|
||||
if ac == host_var:
|
||||
continue
|
||||
if ac == local_ipvar:
|
||||
continue
|
||||
if mw.inArray(db_access,ac):
|
||||
continue
|
||||
add.append(ac)
|
||||
|
||||
if not mw.inArray(db_access, local_ipvar) and not mw.inArray(add, local_ipvar):
|
||||
add.append(local_ipvar)
|
||||
|
||||
for ac in db_access:
|
||||
if ac == "localhost":
|
||||
if ac == host_var:
|
||||
continue
|
||||
if ac == local_ipvar:
|
||||
continue
|
||||
if mw.inArray(input_access,ac):
|
||||
continue
|
||||
delete.append(ac)
|
||||
|
||||
if mw.inArray(delete, local_ipvar):
|
||||
delete.remove(local_ipvar)
|
||||
|
||||
return {"add":add,"delete":delete}
|
||||
|
||||
def getDbAccess():
|
||||
@@ -1569,8 +1582,10 @@ def getDbAccess():
|
||||
users = getDbUserAccess(username)
|
||||
if len(users) == 1:
|
||||
return mw.returnJson(True, "localhost")
|
||||
|
||||
userStr = ','.join(users)
|
||||
if userStr == '127.0.0.1,localhost':
|
||||
return mw.returnJson(True, 'localhost')
|
||||
|
||||
return mw.returnJson(True, userStr)
|
||||
|
||||
def setDbAccess():
|
||||
@@ -1967,23 +1982,18 @@ def setDbMasterAccess():
|
||||
pdb = pMysqlDb()
|
||||
psdb = pSqliteDb('master_replication_user')
|
||||
password = psdb.where("username=?", (username,)).getField('password')
|
||||
try:
|
||||
users = pdb.query("select Host from user where User='" +
|
||||
username + "' AND Host!='localhost'")
|
||||
except Exception:
|
||||
users = []
|
||||
for us in users:
|
||||
|
||||
db_users_access = getDbUserAccess(username)
|
||||
for user_access in db_users_access:
|
||||
try:
|
||||
pdb.execute("drop user '" + username + "'@'" + us["Host"] + "'")
|
||||
pdb.execute("drop user '" + username + "'@'%s'" % (user_access,))
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
dbname = '*'
|
||||
for a in access.split(','):
|
||||
pdb.execute(
|
||||
"CREATE USER `%s`@`%s` IDENTIFIED BY '%s'" % (username, a, password))
|
||||
pdb.execute(
|
||||
"grant all privileges on %s.* to `%s`@`%s`" % (dbname, username, a))
|
||||
pdb.execute("CREATE USER `%s`@`%s` IDENTIFIED BY '%s'" % (username, a, password))
|
||||
pdb.execute("grant all privileges on %s.* to `%s`@`%s`" % (dbname, username, a))
|
||||
|
||||
pdb.execute("flush privileges")
|
||||
psdb.where('username=?', (username,)).save('accept', (access,))
|
||||
|
||||
@@ -1710,20 +1710,33 @@ def getDbUserAccessDiff(db_access, input_access):
|
||||
add = []
|
||||
delete = []
|
||||
|
||||
host_var = 'localhost'
|
||||
local_ipvar = '127.0.0.1'
|
||||
|
||||
for ac in input_access:
|
||||
if ac == "localhost":
|
||||
if ac == host_var:
|
||||
continue
|
||||
if ac == local_ipvar:
|
||||
continue
|
||||
if mw.inArray(db_access,ac):
|
||||
continue
|
||||
add.append(ac)
|
||||
|
||||
if not mw.inArray(db_access, local_ipvar) and not mw.inArray(add, local_ipvar):
|
||||
add.append(local_ipvar)
|
||||
|
||||
for ac in db_access:
|
||||
if ac == "localhost":
|
||||
if ac == host_var:
|
||||
continue
|
||||
if ac == local_ipvar:
|
||||
continue
|
||||
if mw.inArray(input_access,ac):
|
||||
continue
|
||||
delete.append(ac)
|
||||
|
||||
if mw.inArray(delete, local_ipvar):
|
||||
delete.remove(local_ipvar)
|
||||
|
||||
return {"add":add,"delete":delete}
|
||||
|
||||
def getDbAccess():
|
||||
@@ -1736,8 +1749,10 @@ def getDbAccess():
|
||||
users = getDbUserAccess(username)
|
||||
if len(users) == 1:
|
||||
return mw.returnJson(True, "localhost")
|
||||
|
||||
userStr = ','.join(users)
|
||||
if userStr == '127.0.0.1,localhost':
|
||||
return mw.returnJson(True, 'localhost')
|
||||
|
||||
return mw.returnJson(True, userStr)
|
||||
|
||||
def setDbAccess():
|
||||
@@ -2235,23 +2250,18 @@ def setDbMasterAccess():
|
||||
pdb = pMysqlDb()
|
||||
psdb = pSqliteDb('master_replication_user')
|
||||
password = psdb.where("username=?", (username,)).getField('password')
|
||||
try:
|
||||
users = pdb.query("select Host from mysql.user where User='" +
|
||||
username + "' AND Host!='localhost'")
|
||||
except Exception:
|
||||
users = []
|
||||
for us in users:
|
||||
|
||||
db_users_access = getDbUserAccess(username)
|
||||
for user_access in db_users_access:
|
||||
try:
|
||||
pdb.execute("drop user '" + username + "'@'" + us["Host"] + "'")
|
||||
pdb.execute("drop user '" + username + "'@'%s'" % (user_access,))
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
dbname = '*'
|
||||
for a in access.split(','):
|
||||
pdb.execute(
|
||||
"CREATE USER `%s`@`%s` IDENTIFIED BY '%s'" % (username, a, password))
|
||||
pdb.execute(
|
||||
"grant all privileges on %s.* to `%s`@`%s`" % (dbname, username, a))
|
||||
pdb.execute("CREATE USER `%s`@`%s` IDENTIFIED BY '%s'" % (username, a, password))
|
||||
pdb.execute("grant all privileges on %s.* to `%s`@`%s`" % (dbname, username, a))
|
||||
|
||||
pdb.execute("flush privileges")
|
||||
psdb.where('username=?', (username,)).save('accept', (access,))
|
||||
|
||||
@@ -1917,20 +1917,33 @@ def getDbUserAccessDiff(db_access, input_access):
|
||||
add = []
|
||||
delete = []
|
||||
|
||||
host_var = 'localhost'
|
||||
local_ipvar = '127.0.0.1'
|
||||
|
||||
for ac in input_access:
|
||||
if ac == "localhost":
|
||||
if ac == host_var:
|
||||
continue
|
||||
if ac == local_ipvar:
|
||||
continue
|
||||
if mw.inArray(db_access,ac):
|
||||
continue
|
||||
add.append(ac)
|
||||
|
||||
if not mw.inArray(db_access, local_ipvar) and not mw.inArray(add, local_ipvar):
|
||||
add.append(local_ipvar)
|
||||
|
||||
for ac in db_access:
|
||||
if ac == "localhost":
|
||||
if ac == host_var:
|
||||
continue
|
||||
if ac == local_ipvar:
|
||||
continue
|
||||
if mw.inArray(input_access,ac):
|
||||
continue
|
||||
delete.append(ac)
|
||||
|
||||
if mw.inArray(delete, local_ipvar):
|
||||
delete.remove(local_ipvar)
|
||||
|
||||
return {"add":add,"delete":delete}
|
||||
|
||||
def getDbAccess():
|
||||
@@ -1943,8 +1956,10 @@ def getDbAccess():
|
||||
users = getDbUserAccess(username)
|
||||
if len(users) == 1:
|
||||
return mw.returnJson(True, "localhost")
|
||||
|
||||
userStr = ','.join(users)
|
||||
if userStr == '127.0.0.1,localhost':
|
||||
return mw.returnJson(True, 'localhost')
|
||||
|
||||
return mw.returnJson(True, userStr)
|
||||
|
||||
def setDbAccess():
|
||||
@@ -2390,23 +2405,19 @@ def setDbMasterAccess():
|
||||
pdb = pMysqlDb()
|
||||
psdb = pSqliteDb('master_replication_user')
|
||||
password = psdb.where("username=?", (username,)).getField('password')
|
||||
try:
|
||||
users = pdb.query("select Host from mysql.user where User='" +
|
||||
username + "' AND Host!='localhost'")
|
||||
except Exception:
|
||||
users = []
|
||||
for us in users:
|
||||
|
||||
|
||||
db_users_access = getDbUserAccess(username)
|
||||
for user_access in db_users_access:
|
||||
try:
|
||||
pdb.execute("drop user '" + username + "'@'" + us["Host"] + "'")
|
||||
pdb.execute("drop user '" + username + "'@'%s'" % (user_access,))
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
dbname = '*'
|
||||
for a in access.split(','):
|
||||
pdb.execute(
|
||||
"CREATE USER `%s`@`%s` IDENTIFIED BY '%s'" % (username, a, password))
|
||||
pdb.execute(
|
||||
"grant all privileges on %s.* to `%s`@`%s`" % (dbname, username, a))
|
||||
pdb.execute("CREATE USER `%s`@`%s` IDENTIFIED BY '%s'" % (username, a, password))
|
||||
pdb.execute("grant all privileges on %s.* to `%s`@'%s'" % (dbname, username, a))
|
||||
|
||||
pdb.execute("flush privileges")
|
||||
psdb.where('username=?', (username,)).save('accept', (access,))
|
||||
@@ -2702,8 +2713,7 @@ def addMasterRepSlaveUser(version=''):
|
||||
if isError != None:
|
||||
return isError
|
||||
else:
|
||||
sql = "grant replication SLAVE ON *.* TO '" + username + \
|
||||
"'@'%' identified by '" + password + "';"
|
||||
sql = "grant replication SLAVE ON *.* TO '" + username + "'@'%' identified by '" + password + "';"
|
||||
result = pdb.execute(sql)
|
||||
isError = isSqlError(result)
|
||||
if isError != None:
|
||||
|
||||
@@ -559,6 +559,7 @@ def upgradeCheck(version):
|
||||
return mw.returnJson(0,"pass")
|
||||
|
||||
def uninstallPreInspection(version):
|
||||
version = version.strip()
|
||||
from utils.plugin import plugin as MwPlugin
|
||||
MwPlugin.instance().removeIndex(getPluginName(), version)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user