(self, get)
| 2270 | |
| 2271 | # 设置数据库权限 |
| 2272 | def SetDatabaseAccess(self, get): |
| 2273 | names = get['name'].split(',') |
| 2274 | set_phpv_successfully = [] |
| 2275 | set_phpv_failed = {} |
| 2276 | for name in names: |
| 2277 | try: |
| 2278 | db_find = public.M('databases').where("username=? AND LOWER(type)=LOWER('mysql')", (name,)).find() |
| 2279 | db_name = db_find['name'] |
| 2280 | sid = db_find['sid'] |
| 2281 | mysql_obj = public.get_mysql_obj(db_name) |
| 2282 | access = get['access'].strip() |
| 2283 | if access in ['']: return public.returnMsg(False, 'IP地址不能为空!') |
| 2284 | password = public.M('databases').where("username=? AND LOWER(type)=LOWER('mysql')", (name,)).getField( |
| 2285 | 'password') |
| 2286 | result = mysql_obj.query("show databases") |
| 2287 | isError = self.IsSqlError(result) |
| 2288 | if isError != None: return isError |
| 2289 | users = mysql_obj.query("select Host from mysql.user where User='" + name + "' AND Host!='localhost'") |
| 2290 | |
| 2291 | for us in users: |
| 2292 | mysql_obj.execute("drop user `{name}`@`{host}`".format(name=name, host=us[0])) |
| 2293 | self.__CreateUsers(sid, db_name, name, password, access) |
| 2294 | set_phpv_successfully.append(db_name) |
| 2295 | except Exception as e: |
| 2296 | set_phpv_failed[name] = "操作失败" |
| 2297 | pass |
| 2298 | |
| 2299 | if len(names) > 1: |
| 2300 | return {'status': True, 'msg': '设置[ {} ]数据库权限成功'.format(','.join(set_phpv_successfully)), |
| 2301 | 'error': set_phpv_failed, |
| 2302 | 'success': set_phpv_successfully} |
| 2303 | |
| 2304 | return public.returnMsg(True, 'SET_SUCCESS') |
| 2305 | |
| 2306 | # 获取数据库配置信息 |
| 2307 | def GetMySQLInfo(self, get): |
no test coverage detected