예제 #1
0
파일: ftp.py 프로젝트: Ropon/newpanel
 def post(self):
     rets = self.ftpop.check()
     if rets:
         api_abort(httpcode=400, errcode=4025, key=rets)
     self.parser.parse_args()
     orgin_data = request.json
     ftp_user = orgin_data.get("ftp_user")
     if ftp_user == "":
         return api_abort(errcode=4012)
     orgin_data["ftp_passwd"] = orgin_data.get(
         "ftp_passwd") or getRandomString()
     orgin_data["ftp_path"] = orgin_data.get(
         "ftp_path") or f'{www_path}/{ftp_user}'
     orgin_data["note"] = orgin_data.get("note") or ftp_user
     parms = {"ftp_user": ftp_user}
     check(Ftp, extra=parms, obj_path=orgin_data["ftp_path"])
     create_dict = {
         "ftp_user": ftp_user,
         "ftp_passwd": orgin_data.get("ftp_passwd"),
         "ftp_path": orgin_data.get("ftp_path")
     }
     # 创建FTP站点
     self.ftpop.create_ftp(**create_dict)
     ftpobj = Ftp(**orgin_data)
     ftpobj.add()
     res = BaseResponse()
     res.data = ftpobj.to_json()
     return res.dict
예제 #2
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
예제 #3
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)
예제 #4
0
    def post(self):
        rets = self.siteop.check()
        if rets:
            api_abort(httpcode=400, errcode=4025, key=rets)
        self.parser.parse_args()
        orgin_data = request.json
        site_name = orgin_data.get("site_name", "")
        bind_domain = orgin_data.get("bind_domain", "")
        if site_name == "" or bind_domain == "":
            api_abort(errcode=4012)
        orgin_data["root_path"] = orgin_data.get(
            "root_path") or f'{www_path}/{site_name}'
        orgin_data["note"] = orgin_data.get("note") or site_name
        # 检查域名、路径合法性及站点、域名重复性
        parms = {"site_name": site_name}
        check(Site, bind_domain, parms, orgin_data.get("root_path"))
        orgin_data.pop("ftpinfo")
        orgin_data.pop("mysqlinfo")
        # orgin_data.pop("sslinfo")
        siteinfo_orgin_data = orgin_data.pop("site_info", {})
        if siteinfo_orgin_data.get('is_log'):
            siteinfo_orgin_data["log_path"] = f'{logs_path}/{site_name}'
        else:
            siteinfo_orgin_data["log_path"] = ""
        # 规范 port is_ssl 值
        if siteinfo_orgin_data.get("port") == 80:
            siteinfo_orgin_data["is_ssl"] = False
        elif siteinfo_orgin_data.get("port") == 443:
            siteinfo_orgin_data["is_ssl"] = True
        if siteinfo_orgin_data.get("is_ssl") == False:
            siteinfo_orgin_data["port"] = 80
        elif siteinfo_orgin_data.get("is_ssl") == True:
            siteinfo_orgin_data["port"] = 443

        extra_kwargs = siteinfo_orgin_data.pop("extra_kwargs",
                                               {}) or extra_kwargs_dict
        domain_301 = siteinfo_orgin_data.get("domain_301")
        if extra_kwargs.get('set_301') and domain_301 == "":
            api_abort(httpcode=400, errcode=4025, key="开启301,跳转域名不能为空")
        check(obj_domain=domain_301)
        siteinfo_orgin_data["extra_kwargs"] = json.dumps(extra_kwargs)
        phpver = siteinfo_orgin_data.get("php_ver") or php_ver
        create_dict = {
            "site_name": site_name,
            "bind_domain": bind_domain.replace(",", " "),
            "root_path": orgin_data.get("root_path"),
            "is_ssl": siteinfo_orgin_data.get("is_ssl") or False,
            "is_log": siteinfo_orgin_data.get('is_log') or False,
            "log_path": siteinfo_orgin_data.get("log_path"),
            "domain_301": siteinfo_orgin_data.get("domain_301") or "",
            "default_index": siteinfo_orgin_data.get("default_index")
            or default_index,
            "php_ver": phpver.replace(".", ""),
            "extra_kwargs": extra_kwargs
        }
        # 创建站点
        res = self.siteop.create_site(**create_dict)
        if res:
            api_abort(httpcode=400, errcode=4025, key=res)
        siteobj = Site(**orgin_data)
        siteobj.add()
        site_dict = siteobj.to_json()
        siteinfo_orgin_data["site_id"] = siteobj.nid
        siteinfoobj = SiteInfo(**siteinfo_orgin_data)
        siteinfoobj.add()
        site_info = SiteInfo.sget(siteobj.nid)
        if site_info:
            site_dict["site_info"] = site_info.to_json()
        res = BaseResponse()
        res.data = site_dict
        return res.dict
예제 #5
0
 def put(self):
     self.parser.parse_args()
     fields = {
         "nid", "site_name", "bind_domain", "root_path", "site_info", "note"
     }
     orgin_data = {}
     if fields.issubset(set(request.json.keys())):
         for key in fields:
             orgin_data[key] = request.json.get(key)
     orgin_data = request.json
     nid = orgin_data.pop("nid")
     if nid == "":
         return api_abort(errcode=4012)
     bind_domain = orgin_data.get("bind_domain")
     # 站点名、路径不支持修改
     orgin_data.pop("site_name", "")
     orgin_data.pop("root_path", "")
     site_obj = Site.get(nid)
     if site_obj:
         check(Site, obj_domain=bind_domain, site_name=site_obj.site_name)
         bind_domain = bind_domain or site_obj.bind_domain
         siteinfo_orgin_data = orgin_data.pop("site_info", {})
         if siteinfo_orgin_data.get('is_log'):
             siteinfo_orgin_data[
                 "log_path"] = f'{logs_path}/{site_obj.site_name}'
         else:
             siteinfo_orgin_data["log_path"] = ""
         if siteinfo_orgin_data:
             extra_kwargs = siteinfo_orgin_data.pop("extra_kwargs", {})
             if extra_kwargs:
                 siteinfo_orgin_data["extra_kwargs"] = json.dumps(
                     extra_kwargs)
         if orgin_data:
             site_info = SiteInfo.sget(nid)
             php_ver = siteinfo_orgin_data.get(
                 'php_ver') or site_info.php_ver
             domain_301 = siteinfo_orgin_data.get("domain_301")
             if extra_kwargs.get('set_301') and domain_301 == "":
                 api_abort(httpcode=400, errcode=4025, key="开启301,跳转域名不能为空")
             check(obj_domain=domain_301)
             create_dict = {
                 "site_name": site_obj.site_name,
                 "bind_domain": bind_domain.replace(",", " "),
                 "root_path": site_obj.root_path,
                 "is_ssl": siteinfo_orgin_data.get('is_ssl'),
                 "is_log": siteinfo_orgin_data.get('is_log'),
                 "log_path": siteinfo_orgin_data.get('log_path'),
                 "domain_301": domain_301,
                 "default_index": site_info.default_index,
                 "php_ver": php_ver.replace(".", ""),
                 "extra_kwargs": extra_kwargs
             }
             # 更新站点调用 创建站点
             res = self.siteop.create_site(**create_dict)
             if res:
                 api_abort(httpcode=400, errcode=4025, key=res)
             SiteInfo.supdate(nid, siteinfo_orgin_data)
             Site.update(nid, orgin_data)
             site_dict = site_obj.to_json()
             if site_info:
                 site_dict["site_info"] = site_info.to_json()
             res = BaseResponse()
             res.data = site_dict
             return res.dict
         else:
             # 未传入修改的值
             return api_abort(errcode=4019)
     else:
         # 记录不存在
         return api_abort(errcode=4018)