示例#1
0
文件: mysql.py 项目: Ropon/newpanel
 def post(self):
     rets = self.mysqlop.check()
     if rets:
         api_abort(httpcode=400, errcode=4025, key=rets)
     self.parser.parse_args()
     orgin_data = request.json
     mysql_user = orgin_data.get("mysql_user")
     if mysql_user == "":
         return api_abort(errcode=4012)
     orgin_data["mysql_name"] = orgin_data.get("mysql_name") or mysql_user
     orgin_data["mysql_passwd"] = orgin_data.get("mysql_passwd") or getRandomString()
     orgin_data["accept"] = orgin_data.get("accept") or "localhost"
     orgin_data["note"] = orgin_data.get("note") or mysql_user
     accept = orgin_data.get("accept")
     extra = {"mysql_user": mysql_user}
     check(Mysql, extra=extra, accept=accept)
     extra = {"mysql_name": orgin_data.get("mysql_name")}
     check(Mysql, extra=extra)
     create_dict = {
         "mysql_user": mysql_user,
         "mysql_passwd": orgin_data.get("mysql_passwd"),
         "mysql_name": orgin_data.get("mysql_name"),
         "accept": accept
     }
     # 创建mysql数据库
     result = self.mysqlop.create_mysql(**create_dict)
     mysqlobj = Mysql(**orgin_data)
     mysqlobj.add()
     res = BaseResponse()
     res.errmsg = result
     res.data = mysqlobj.to_json()
     return res.dict
示例#2
0
文件: mysql.py 项目: Ropon/newpanel
 def put(self):
     self.parser.parse_args()
     orgin_data = request.json
     nid = orgin_data.pop("nid")
     if nid == "":
         return api_abort(errcode=4012)
     mysql_obj = Mysql.get(nid)
     if mysql_obj:
         if orgin_data:
             accept = orgin_data.get("accept")
             check(Mysql, accept=accept)
             update_dict = {
                 "mysql_user": mysql_obj.mysql_user,
                 "old_passwd": mysql_obj.mysql_passwd,
                 "mysql_passwd": orgin_data.get("mysql_passwd"),
                 "mysql_name": mysql_obj.mysql_name,
                 "accept": accept,
                 "old_accept": mysql_obj.accept
             }
             # 更新数据库
             result = self.mysqlop.update_mysql(**update_dict)
             Mysql.update(nid, orgin_data)
             ftp_dict = mysql_obj.to_json()
             res = BaseResponse()
             res.data = ftp_dict
             res.errmsg = result
             return res.dict
         else:
             # 未传入修改的值
             return api_abort(errcode=4019)
     else:
         # 记录不存在
         return api_abort(errcode=4018)
示例#3
0
文件: soft.py 项目: Ropon/newpanel
 def put(self):
     self.parser.parse_args()
     orgin_data = request.json
     nid = orgin_data.pop("nid")
     installtype = orgin_data.get("installtype")
     soft_name = orgin_data.get("soft_name")
     soft_ver = orgin_data.get("soft_ver")
     if nid == "":
         return api_abort(errcode=4012)
     soft_obj = Soft.get(nid)
     if soft_obj:
         if orgin_data:
             softobj = Soft.query.filter_by(**{
                 'soft_name': soft_name,
                 'is_install': 1
             }).first()
             if softobj:
                 api_abort(httpcode=400,
                           errcode=4025,
                           key=f"已安装{softobj.soft_name},若要安装新版请先卸载")
             softobj2 = Soft.query.filter_by(**{'is_install': 2}).first()
             if softobj2:
                 api_abort(httpcode=400,
                           errcode=4025,
                           key=f"正在安装{softobj2.soft_name},请稍后重试")
             if installtype == "rpm":
                 api_abort(httpcode=400, errcode=4025, key=f"暂时不支持极速安装")
                 res = 0
                 # res = os.system(f"/bin/bash {self.shellpath}/{soft_name}_rpm.sh {soft_ver}")
             elif installtype == "bash":
                 Soft.update(nid, {"is_install": 2})
                 res = os.system(
                     f"/bin/bash {self.shellpath}/{soft_name}.sh {soft_ver}"
                 )
                 # res = execShell(f"bash {self.shellpath}/{soft_name}.sh {soft_ver}")
             if res == 1:
                 Soft.update(nid, {"is_install": 0})
                 api_abort(httpcode=400,
                           errcode=4025,
                           key=f"{soft_name}安装失败")
             Soft.update(nid, {"is_install": 1})
             soft_dict = soft_obj.to_json()
             res = BaseResponse()
             res.data = soft_dict
             res.errmsg = f"正在安装{soft_name}..."
             return res.dict
         else:
             # 未传入修改的值
             return api_abort(errcode=4019)
     else:
         # 记录不存在
         return api_abort(errcode=4018)
示例#4
0
 def post(self):
     username = request.headers.get("username")
     oldpasswd = request.json.get("oldpasswd")
     newpasswd = request.json.get("newpasswd")
     print(username, oldpasswd, newpasswd)
     if username == "" or oldpasswd == "" or newpasswd == "":
         api_abort(errcode=4012)
     user_obj = User.query.filter_by(username=username).first()
     if not user_obj.check_password(user_obj.password, oldpasswd):
         api_abort(httpcode=400, errcode=4025, key="原密码不正确")
     User.update(user_obj.nid, {'password': User.set_password(newpasswd)})
     res = BaseResponse()
     res.errmsg = "密码修改成功"
     return res.dict
示例#5
0
文件: mysql.py 项目: Ropon/newpanel
 def delete(self):
     self.parser.parse_args()
     nid = request.json.get("nid")
     if nid == "":
         return api_abort(errcode=4012)
     mysqlobj = Mysql.get(nid)
     if mysqlobj:
         delete_dict = {
             "mysql_user": mysqlobj.mysql_user,
             "mysql_name": mysqlobj.mysql_name,
             "accept": mysqlobj.accept
         }
         # 删除数据库
         result = self.mysqlop.delete_mysql(**delete_dict)
         Mysql.delete(nid)
         res = BaseResponse()
         res.errmsg = result
         res.dict.pop("data")
         return res.dict
     else:
         return api_abort(errcode=4018)