MCPcopy Create free account
hub / github.com/aaPanel/BaoTa / add_base_database

Method add_base_database

class/databaseModel/base.py:177–216  ·  view source on GitHub ↗

@添加数据库前置检测 @return username 用户名 data_name 数据库名 data_pwd:数据库密码

(self, get, dtype)

Source from the content-addressed store, hash-verified

175 return p.model(get)
176
177 def add_base_database(self, get, dtype):
178 """
179 @添加数据库前置检测
180 @return username 用户名
181 data_name 数据库名
182 data_pwd:数据库密码
183 """
184 data_name = get['name'].strip().lower()
185 if self.check_recyclebin(data_name):
186 return public.returnMsg(False, '数据库[' + data_name + ']已在回收站,请从回收站恢复!');
187
188 if len(data_name) > 16:
189 return public.returnMsg(False, 'DATABASE_NAME_LEN')
190
191 if not hasattr(get, 'db_user'): get.db_user = data_name;
192 username = get.db_user.strip();
193 checks = ['root', 'mysql', 'test', 'sys', 'panel_logs']
194 if username in checks or len(username) < 1:
195 return public.returnMsg(False, '数据库用户名不合法!');
196 if data_name in checks or len(data_name) < 1:
197 return public.returnMsg(False, '数据库名称不合法!');
198
199 reg = "^\w+$"
200 if not re.match(reg, data_name):
201 return public.returnMsg(False, 'DATABASE_NAME_ERR_T')
202
203 data_pwd = get['password']
204 if len(data_pwd) < 1:
205 data_pwd = public.md5(str(time.time()))[0:8]
206
207 if public.M('databases').where("name=? or username=? AND LOWER(type)=LOWER(?)", (data_name, username, dtype)).count():
208 return public.returnMsg(False, 'DATABASE_NAME_EXISTS')
209
210 res = {
211 'data_name': data_name,
212 'username': username,
213 'data_pwd': data_pwd,
214 'status': True
215 }
216 return res
217
218 def delete_base_backup(self, get):
219 """

Callers 3

AddDatabaseMethod · 0.80
AddDatabaseMethod · 0.80
AddDatabaseMethod · 0.80

Calls 8

check_recyclebinMethod · 0.95
returnMsgMethod · 0.80
timeMethod · 0.80
matchMethod · 0.45
md5Method · 0.45
countMethod · 0.45
whereMethod · 0.45
MMethod · 0.45

Tested by

no test coverage detected