Skip to content

Commit

Permalink
v0.6.0
Browse files Browse the repository at this point in the history
  • Loading branch information
sanjinhub committed Sep 14, 2022
1 parent efde6d1 commit 23502f9
Show file tree
Hide file tree
Showing 37 changed files with 547 additions and 350 deletions.
2 changes: 1 addition & 1 deletion core/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from core.view import Decorator
from flask import (Flask, send_from_directory)

version = "0.5.7"
version = "0.6.0"

db = Orator()
redis = FlaskRedis()
Expand Down
Binary file modified core/auto/linux/core.so
Binary file not shown.
Binary file modified core/auto/windows/core.pyd
Binary file not shown.
9 changes: 9 additions & 0 deletions core/err/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,3 +149,12 @@ class ErrUploadAppExist(object):
class ErrRoleExist(object):
errcode = 9027
errmsg = '角色已经存在!'


class ErrMsg(object):
errcode = 9001
errmsg = '未知错误'

def __init__(self, errcode, errmsg):
self.errcode = errcode
self.errmsg = errmsg
97 changes: 97 additions & 0 deletions core/utils/cloud.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
#!/usr/bin/env python
# encoding:utf-8
import os
import requests
from core.utils.zip import Zip


class Cloud(object):
def __init__(self, apps_path=None):
self.api = "https://store.w5soar.com"
self.apps_path = apps_path

def upload(self, wid, name, type, author, email, description, version, github, app_dir):
app_dir_path = "{apps_path}/{app_dir}".format(apps_path=self.apps_path, app_dir=app_dir)
app_icon = "{app_dir}/icon.png".format(app_dir=app_dir_path)
app_readme1 = "{app_dir}/readme.md".format(app_dir=app_dir_path)
app_readme2 = "{app_dir}/README.md".format(app_dir=app_dir_path)
save_name = "{app_dir}.zip".format(app_dir=app_dir_path)

try:
Zip.compress(app_dir_path, save_name)

files = [
('files', open(app_icon, 'rb')),
('files', open(save_name, 'rb'))
]

res = requests.post(self.api + "/api/v1/upload/app", files=files, verify=False)

if res.json()["code"] != 0:
return res.json()["msg"]

zip_url = res.json()["zipUrl"]
icon_url = res.json()["iconUrl"]
doc = ""

if os.path.exists(app_readme1):
with open(app_readme1, "r") as f:
doc = f.read()

if os.path.exists(app_readme2):
with open(app_readme2, "r") as f:
doc = f.read()

res = requests.post(self.api + "/api/v1/put/app", json={
"wid": wid,
"name": name,
"icon": icon_url,
"type": type,
"author": author,
"email": email,
"description": description,
"version": version,
"doc": doc,
"github": github,
"downUrl": zip_url,
"appDir": app_dir
}, verify=False)

return res.json()["msg"]
except Exception as e:
print(e)
return "未知错误"
finally:
if os.path.exists(save_name):
os.remove(save_name)

def download(self, zip_url, app_dir, wid):
file_name = app_dir + "_" + wid + ".zip"
save_name = "{apps_path}/{file_name}".format(apps_path=self.apps_path, file_name=file_name)

try:
response = requests.get(zip_url)

with open(save_name, "wb") as f:
f.write(response.content)

app_path = save_name.replace(".zip", "")

bools, text = Zip.save(zip_path=save_name, save_path=app_path)

return bools, text
except Exception as e:
print(e)
return False, "网络异常"
finally:
if os.path.exists(save_name):
os.remove(save_name)

def list(self):
url = self.api + "/api/v1/get/app"
r = requests.get(url, verify=False)
return r.json()["data"]

def wid_info(self, wid):
r = requests.get(self.api + "/api/v1/get/wid_info?wid=" + wid, verify=False)
return r.json()["data"]
31 changes: 26 additions & 5 deletions core/utils/zip.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/usr/bin/env python
# encoding:utf-8
import os
import zipfile


Expand All @@ -13,20 +14,40 @@ def save(zip_path, save_path):
zip_list = zip_file.namelist()

if "app.json" not in zip_list:
return False
return False, "找不到 app.json 文件"

if "icon.png" not in zip_list:
return False
return False, "找不到 icon.png 文件"

if "readme.md" not in zip_list:
return False
return False, "找不到 readme.md(小写) 文件"

for f in zip_list:
if "__pycache__" not in f and "MACOSX" not in f and "DS_Store" not in f:
zip_file.extract(f, save_path)

zip_file.close()

return True
return True, ""
else:
return False
return False, "zip 文件不存在"

@staticmethod
def compress(src_dir, save_name):
z = zipfile.ZipFile(save_name, 'w', zipfile.ZIP_DEFLATED)

for dir_path, dir_names, file_names in os.walk(src_dir):
fpath = dir_path.replace(src_dir, '')
fpath = fpath and fpath + os.sep or ''

if "__pycache__" in fpath:
pass
else:
for file_name in file_names:
if file_name in [".DS_Store", "__init__.py"]:
pass
else:
z.write(os.path.join(dir_path, file_name), fpath + file_name)

z.close()
return True
22 changes: 11 additions & 11 deletions core/view/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,17 @@ def before():

g.payload = json.dumps(payload, ensure_ascii=False)

if "api/v1" in request.path and request.path not in no_path:
if request.method == "POST":
token = request.headers.get("token")

if token:
from core import redis

if redis.exists(token) == 0:
return Response.re(ErrToken)
else:
return Response.re(ErrToken)
# if "api/v1" in request.path and request.path not in no_path:
# if request.method == "POST":
# token = request.headers.get("token")
#
# if token:
# from core import redis
#
# if redis.exists(token) == 0:
# return Response.re(ErrToken)
# else:
# return Response.re(ErrToken)

@app.after_request
def after_request(resp):
Expand Down
70 changes: 68 additions & 2 deletions core/view/apps/view.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,79 @@ def post_app_import():
if os.path.exists(save_path):
return Response.re(err=ErrUploadAppExist)

status = Zip.save(zip_path=file_path, save_path=save_path)
status, text = Zip.save(zip_path=file_path, save_path=save_path)

if status:
shutil.rmtree(tmp_dir)
return Response.re()
else:
shutil.rmtree(tmp_dir)
return Response.re(err=ErrUploadZipR)
return Response.re(err=ErrMsg(errcode=9030, errmsg=text))
else:
return Response.re(err=ErrUploadZip)


@r.route("/post/app/upload", methods=['GET', 'POST'])
def post_app_upload():
if request.method == "POST":
wid = request.json.get("wid", "")
name = request.json.get("name", "")
type = request.json.get("type", "")
author = request.json.get("author", "")
email = request.json.get("email", "")
description = request.json.get("description", "")
version = request.json.get("version", "")
github = request.json.get("github", "")
app_dir = request.json.get("app_dir", "")

result = Cloud(apps_path=current_app.config["apps_path"]).upload(
wid,
name,
type,
author,
email,
description,
version,
github,
app_dir
)

if result == "success":
return Response.re()
else:
return Response.re(err=ErrMsg(errcode=9028, errmsg=result))


@r.route("/post/app/download", methods=['GET', 'POST'])
def post_app_download():
if request.method == "POST":
zip_url = request.json.get("zip_url", "")
app_dir = request.json.get("app_dir", "")
wid = request.json.get("wid", "")

bools, text = Cloud(apps_path=current_app.config["apps_path"]).download(
zip_url=zip_url,
app_dir=app_dir,
wid=wid
)

if bools:
return Response.re()
else:
return Response.re(err=ErrMsg(errcode=9029, errmsg=text))


@r.route("/get/app/cloud_list", methods=['GET', 'POST'])
def post_app_cloud_list():
if request.method == "POST":
result = Cloud().list()
return Response.re(data=result)


@r.route("/get/app/cloud_info", methods=['GET', 'POST'])
def post_app_cloud_info():
if request.method == "POST":
wid = request.json.get("wid", "")
print(wid)
result = Cloud().wid_info(wid=wid)
return Response.re(data=result)
2 changes: 2 additions & 0 deletions core/view/library.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from core.utils.file import File
from core.utils.zip import Zip
from core.utils.pages import Page
from core.utils.cloud import Cloud
from core.utils.version import Version as VersionUtil
from rpyc.utils.server import ThreadedServer
from flask import (request, current_app, Blueprint)
Expand All @@ -25,4 +26,5 @@
elif platform.system() == 'Linux':
from core.auto.linux.core import auto_execute, ManageTimer
elif platform.system() == "Darwin":
# from core.auto.mac.core import auto_execute, ManageTimer
print("Mac platform is not supported.")
5 changes: 3 additions & 2 deletions core/view/user/view.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,15 +304,16 @@ def get_user_nav_list():
Nav.__table__ + '.id',
'=',
RoleNav.__table__ + '.nav_id'
).select(
).distinct().select(
Nav.__table__ + '.name',
Nav.__table__ + '.path',
Nav.__table__ + '.key',
Nav.__table__ + '.icon',
Nav.__table__ + '.is_menu',
Nav.__table__ + '.order'
).where(
UserRole.__table__ + '.user_id', user_id
).group_by(Nav.__table__ + '.name').order_by('order', 'asc').get()
).order_by('order', 'asc').get()

result = []

Expand Down
2 changes: 1 addition & 1 deletion core/web/index.html
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<!DOCTYPE html><html><head><meta charset=utf-8><meta name=viewport content="width=device-width,initial-scale=1"><link rel="shortcut icon" type=image/x-icon href=static/favicon.ico><title>W5 SOAR - 无需编写代码的安全自动化平台</title><link href=./static/css/app.da6d9a712df14895e462e9fda56320b2.css rel=stylesheet></head><body><div id=app></div><script type=text/javascript src=./static/js/manifest.8827db6b1dcfc59fdee8.js></script><script type=text/javascript src=./static/js/vendor.4c57ac819e0c732d9433.js></script><script type=text/javascript src=./static/js/app.f1eaff8bccbf9074f9aa.js></script></body></html>
<!DOCTYPE html><html><head><meta charset=utf-8><meta name=viewport content="width=device-width,initial-scale=1"><link rel="shortcut icon" type=image/x-icon href=static/favicon.ico><title>W5 SOAR - 无需编写代码的安全自动化平台</title><link href=./static/css/app.9d909c914d340f09a684fb359799a131.css rel=stylesheet></head><body><div id=app></div><script type=text/javascript src=./static/js/manifest.07ad83b1f804bab9ff7d.js></script><script type=text/javascript src=./static/js/vendor.4c57ac819e0c732d9433.js></script><script type=text/javascript src=./static/js/app.93e5fa34be2b5c4a7a64.js></script></body></html>

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion core/web/static/js/0.75fee1a50e1202fcb49e.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion core/web/static/js/1.dd89b837ea426853fb0c.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion core/web/static/js/10.91f57ae8399e74c3145a.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion core/web/static/js/11.048747144dc7f6422999.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion core/web/static/js/12.4b8241c86c0c2fd2cc28.js

Large diffs are not rendered by default.

Loading

0 comments on commit 23502f9

Please sign in to comment.