@设置sa密码
(self, args)
| 1032 | return public.returnMsg(True, password) |
| 1033 | |
| 1034 | def set_root_pwd(self, args): |
| 1035 | """ |
| 1036 | @设置sa密码 |
| 1037 | """ |
| 1038 | password = public.trim(args['password']) |
| 1039 | if len(password) < 8: return public.returnMsg(False, '密码输入错误,不能少于8位数.') |
| 1040 | check_result = os.system('/www/server/pgsql/bin/psql --version') |
| 1041 | if check_result != 0: return public.returnMsg(False, '检测到PgSQL未安装或未启动,请先安装或启动') |
| 1042 | pgsql_obj = self.get_sql_obj_by_sid('0') |
| 1043 | status, err_msg = pgsql_obj.connect() |
| 1044 | if status is False: |
| 1045 | return public.returnMsg(False, "连接数据库失败!") |
| 1046 | |
| 1047 | data = pgsql_obj.query('SELECT datname FROM pg_database;') |
| 1048 | isError = self.IsSqlError(data) |
| 1049 | if isError != None: return isError |
| 1050 | |
| 1051 | path = '{}/data/pg_hba.conf'.format(self.__soft_path) |
| 1052 | p_path = '{}/data/postgresAS.json'.format(public.get_panel_path()) |
| 1053 | if not os.path.isfile(path): return public.returnMsg(False, '{}文件不存在,请检查安装是否完整!'.format(path)) |
| 1054 | src_conf = public.readFile(path) |
| 1055 | add_conf = src_conf.replace('md5', 'trust') |
| 1056 | # public.writeFile(path,public.readFile(path).replace('md5','trust')) |
| 1057 | public.writeFile(path, add_conf) |
| 1058 | |
| 1059 | pg_obj = panelPgsql() |
| 1060 | pg_obj.execute("""ALTER USER "postgres" WITH PASSWORD '{}';""".format(password)) |
| 1061 | data = {"username": "postgres", "password": ""} |
| 1062 | try: |
| 1063 | data = json.loads(public.readFile(p_path)) |
| 1064 | except: |
| 1065 | pass |
| 1066 | data['password'] = password |
| 1067 | public.writeFile(p_path, json.dumps(data)) |
| 1068 | public.writeFile(path, src_conf) |
| 1069 | return public.returnMsg(True, '管理员密码修改成功.') |
| 1070 | |
| 1071 | def get_info_by_db_id(self, db_id): |
| 1072 | """ |