|
|
@ -2,18 +2,19 @@
|
|
|
|
import ast
|
|
|
|
import ast
|
|
|
|
import functools
|
|
|
|
import functools
|
|
|
|
import hashlib
|
|
|
|
import hashlib
|
|
|
|
|
|
|
|
import json
|
|
|
|
import logging
|
|
|
|
import logging
|
|
|
|
import re
|
|
|
|
import re
|
|
|
|
import time
|
|
|
|
import time
|
|
|
|
import traceback
|
|
|
|
import traceback
|
|
|
|
import urllib
|
|
|
|
import urllib
|
|
|
|
import json
|
|
|
|
from typing import Any
|
|
|
|
# import urlparse
|
|
|
|
# import urlparse
|
|
|
|
from urllib.parse import parse_qs, unquote
|
|
|
|
from urllib.parse import parse_qs, unquote
|
|
|
|
from typing import Any
|
|
|
|
|
|
|
|
# from urllib import unquote
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# from urllib import unquote
|
|
|
|
import tornado
|
|
|
|
import tornado
|
|
|
|
|
|
|
|
from sqlalchemy import text
|
|
|
|
from tornado import escape
|
|
|
|
from tornado import escape
|
|
|
|
from tornado.httpclient import AsyncHTTPClient, HTTPRequest
|
|
|
|
from tornado.httpclient import AsyncHTTPClient, HTTPRequest
|
|
|
|
from tornado.options import options
|
|
|
|
from tornado.options import options
|
|
|
@ -102,6 +103,7 @@ class BaseHandler(BaseRequestHandler):
|
|
|
|
@property
|
|
|
|
@property
|
|
|
|
def kafka_producer(self):
|
|
|
|
def kafka_producer(self):
|
|
|
|
return self.application.kafka_producer
|
|
|
|
return self.application.kafka_producer
|
|
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
#
|
|
|
|
@property
|
|
|
|
@property
|
|
|
|
def es(self):
|
|
|
|
def es(self):
|
|
|
@ -206,8 +208,8 @@ class BaseHandler(BaseRequestHandler):
|
|
|
|
|
|
|
|
|
|
|
|
def set_default_jsonbody(self):
|
|
|
|
def set_default_jsonbody(self):
|
|
|
|
if self.request.headers.get('Content-Type') == 'application/json' and self.request.body:
|
|
|
|
if self.request.headers.get('Content-Type') == 'application/json' and self.request.body:
|
|
|
|
# logging.info(self.request.headers.get('Content-Type'))
|
|
|
|
# logging.info(self.request.headers.get('Content-Type'))
|
|
|
|
# if self.request.headers.get('Content-Type') == 'application/json; charset=UTF-8':
|
|
|
|
# if self.request.headers.get('Content-Type') == 'application/json; charset=UTF-8':
|
|
|
|
json_body = tornado.escape.json_decode(self.request.body)
|
|
|
|
json_body = tornado.escape.json_decode(self.request.body)
|
|
|
|
for key, value in json_body.items():
|
|
|
|
for key, value in json_body.items():
|
|
|
|
if value is not None:
|
|
|
|
if value is not None:
|
|
|
@ -326,6 +328,7 @@ class BaseHandler(BaseRequestHandler):
|
|
|
|
current_pos += len(substring)
|
|
|
|
current_pos += len(substring)
|
|
|
|
current_pos = target.find(substring, current_pos)
|
|
|
|
current_pos = target.find(substring, current_pos)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class WebHandler(BaseHandler):
|
|
|
|
class WebHandler(BaseHandler):
|
|
|
|
def finish(self, chunk=None, message=None):
|
|
|
|
def finish(self, chunk=None, message=None):
|
|
|
|
callback = escape.utf8(self.get_argument("callback", None))
|
|
|
|
callback = escape.utf8(self.get_argument("callback", None))
|
|
|
@ -467,6 +470,7 @@ def authenticated(method):
|
|
|
|
# raise HTTPError(401)
|
|
|
|
# raise HTTPError(401)
|
|
|
|
raise errors.HTTPAPIError(errors.ERROR_UNAUTHORIZED, "登录失效")
|
|
|
|
raise errors.HTTPAPIError(errors.ERROR_UNAUTHORIZED, "登录失效")
|
|
|
|
return method(self, *args, **kwargs)
|
|
|
|
return method(self, *args, **kwargs)
|
|
|
|
|
|
|
|
|
|
|
|
return wrapper
|
|
|
|
return wrapper
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -481,28 +485,41 @@ def authenticated_admin(method):
|
|
|
|
return wrapper
|
|
|
|
return wrapper
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def operation_log(primary_module, secondary_module, operation_type, content, desc):
|
|
|
|
def operation_log(primary_menu, sub_menu, ope_type, content, comment):
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
Add logging to a function. level is the logging
|
|
|
|
Add logging to a function. level is the logging
|
|
|
|
level, name is the logger name, and message is the
|
|
|
|
level, name is the logger name, and message is the
|
|
|
|
log message. If name and message aren't specified,
|
|
|
|
log message. If name and message aren't specified,
|
|
|
|
they default to the function's module and name.
|
|
|
|
they default to the function's module and name.
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
def decorate(func):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def decorate(func):
|
|
|
|
@functools.wraps(func)
|
|
|
|
@functools.wraps(func)
|
|
|
|
def wrapper(self, *args, **kwargs):
|
|
|
|
def wrapper(self, *args, **kwargs):
|
|
|
|
self.db_app.insert(
|
|
|
|
with self.app_mysql.connect() as conn:
|
|
|
|
"insert into system_log(user, ip, first_module, second_module, op_type, op_content, description) "
|
|
|
|
conn.execute(text(
|
|
|
|
"values(%s, %s, %s, %s, %s, %s, %s)",
|
|
|
|
"insert into sys_log(user, ip, primary_menu, sub_menu, op_type, content, comment) "
|
|
|
|
self.current_user.name, self.request.headers["X-Forwarded-For"], primary_module, secondary_module, operation_type,
|
|
|
|
"values(:user, :ip, :primary_menu, :sub_menu, :op_type, :content, :comment)"
|
|
|
|
content, desc
|
|
|
|
),
|
|
|
|
)
|
|
|
|
{"user": self.current_user.name,
|
|
|
|
|
|
|
|
"ip": self.request.headers[
|
|
|
|
|
|
|
|
"X-Forwarded-For"] if "X-Forwarded-For" in self.request.headers else self.request.remote_ip,
|
|
|
|
|
|
|
|
"primary_menu": primary_menu,
|
|
|
|
|
|
|
|
"sub_menu": sub_menu,
|
|
|
|
|
|
|
|
"op_type": ope_type,
|
|
|
|
|
|
|
|
"content": content,
|
|
|
|
|
|
|
|
"comment": comment
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
conn.commit()
|
|
|
|
|
|
|
|
|
|
|
|
return func(self, *args, **kwargs)
|
|
|
|
return func(self, *args, **kwargs)
|
|
|
|
|
|
|
|
|
|
|
|
return wrapper
|
|
|
|
return wrapper
|
|
|
|
|
|
|
|
|
|
|
|
return decorate
|
|
|
|
return decorate
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def permission(codes):
|
|
|
|
def permission(codes):
|
|
|
|
def decorate(func):
|
|
|
|
def decorate(func):
|
|
|
|
@functools.wraps(func)
|
|
|
|
@functools.wraps(func)
|
|
|
@ -517,9 +534,12 @@ def permission(codes):
|
|
|
|
raise errors.HTTPAPIError(errors.ERROR_FORBIDDEN, "permission denied")
|
|
|
|
raise errors.HTTPAPIError(errors.ERROR_FORBIDDEN, "permission denied")
|
|
|
|
|
|
|
|
|
|
|
|
return func(self, *args, **kwargs)
|
|
|
|
return func(self, *args, **kwargs)
|
|
|
|
|
|
|
|
|
|
|
|
return wrapper
|
|
|
|
return wrapper
|
|
|
|
|
|
|
|
|
|
|
|
return decorate
|
|
|
|
return decorate
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def license_validate(codes):
|
|
|
|
def license_validate(codes):
|
|
|
|
def decorate(func):
|
|
|
|
def decorate(func):
|
|
|
|
@functools.wraps(func)
|
|
|
|
@functools.wraps(func)
|
|
|
@ -531,7 +551,8 @@ def license_validate(codes):
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
row = self.db_app.get("select syscode, expireat from license limit 1")
|
|
|
|
row = self.db_app.get("select syscode, expireat from license limit 1")
|
|
|
|
if row:
|
|
|
|
if row:
|
|
|
|
self.r_app.set("system:license", json.dumps({"syscode":row["syscode"], "expireat":row["expireat"]}))
|
|
|
|
self.r_app.set("system:license",
|
|
|
|
|
|
|
|
json.dumps({"syscode": row["syscode"], "expireat": row["expireat"]}))
|
|
|
|
license_info = row
|
|
|
|
license_info = row
|
|
|
|
|
|
|
|
|
|
|
|
license_status = get_license_status(license_info)
|
|
|
|
license_status = get_license_status(license_info)
|
|
|
@ -546,9 +567,12 @@ def license_validate(codes):
|
|
|
|
# raise errors.HTTPAPIError(errors.ERROR_LICENSE_NOT_ACTIVE, "License授权过期")
|
|
|
|
# raise errors.HTTPAPIError(errors.ERROR_LICENSE_NOT_ACTIVE, "License授权过期")
|
|
|
|
|
|
|
|
|
|
|
|
return func(self, *args, **kwargs)
|
|
|
|
return func(self, *args, **kwargs)
|
|
|
|
|
|
|
|
|
|
|
|
return wrapper
|
|
|
|
return wrapper
|
|
|
|
|
|
|
|
|
|
|
|
return decorate
|
|
|
|
return decorate
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def userlog(method):
|
|
|
|
def userlog(method):
|
|
|
|
@functools.wraps(method)
|
|
|
|
@functools.wraps(method)
|
|
|
|
def wrapper(self, *args, **kwargs):
|
|
|
|
def wrapper(self, *args, **kwargs):
|
|
|
|