|
|
@ -1,21 +1,19 @@
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
"""系统信息"""
|
|
|
|
"""系统信息"""
|
|
|
|
|
|
|
|
import datetime
|
|
|
|
|
|
|
|
import json
|
|
|
|
import logging
|
|
|
|
import logging
|
|
|
|
import uuid
|
|
|
|
|
|
|
|
import time
|
|
|
|
|
|
|
|
import re
|
|
|
|
import re
|
|
|
|
import os
|
|
|
|
import time
|
|
|
|
import json
|
|
|
|
|
|
|
|
import hashlib
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import datetime
|
|
|
|
from sqlalchemy import text
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
from website import consts
|
|
|
|
from website import errors
|
|
|
|
from website import errors
|
|
|
|
from website import settings
|
|
|
|
from website import settings
|
|
|
|
from website.handler import APIHandler, WebHandler, authenticated, operation_log, permission
|
|
|
|
|
|
|
|
from website.db_mysql import to_json_list
|
|
|
|
from website.db_mysql import to_json_list
|
|
|
|
from website.util import sysinfo, rsa
|
|
|
|
from website.handler import APIHandler, authenticated
|
|
|
|
from sqlalchemy import text
|
|
|
|
from website.util import sysinfo, rsa_oaep
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class VersionHandler(APIHandler):
|
|
|
|
class VersionHandler(APIHandler):
|
|
|
@ -24,8 +22,12 @@ class VersionHandler(APIHandler):
|
|
|
|
def post(self):
|
|
|
|
def post(self):
|
|
|
|
self.finish()
|
|
|
|
self.finish()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class IdentifycodeHandler(APIHandler):
|
|
|
|
class IdentifycodeHandler(APIHandler):
|
|
|
|
@authenticated
|
|
|
|
"""系统识别码"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# @authenticated
|
|
|
|
|
|
|
|
|
|
|
|
# @permission([100014, 100015])
|
|
|
|
# @permission([100014, 100015])
|
|
|
|
# @operation_log("资产管理中心", "系统激活", "查询", "查询本地识别码", "查询本地识别码")
|
|
|
|
# @operation_log("资产管理中心", "系统激活", "查询", "查询本地识别码", "查询本地识别码")
|
|
|
|
def post(self):
|
|
|
|
def post(self):
|
|
|
@ -33,6 +35,7 @@ class IdentifycodeHandler(APIHandler):
|
|
|
|
|
|
|
|
|
|
|
|
self.finish({"result": code})
|
|
|
|
self.finish({"result": code})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class LicenseUploadHandler(APIHandler):
|
|
|
|
class LicenseUploadHandler(APIHandler):
|
|
|
|
@authenticated
|
|
|
|
@authenticated
|
|
|
|
# @permission([100014, 100015])
|
|
|
|
# @permission([100014, 100015])
|
|
|
@ -55,45 +58,44 @@ class LicenseUploadHandler(APIHandler):
|
|
|
|
if file_size > 10 * 1024 * 1024:
|
|
|
|
if file_size > 10 * 1024 * 1024:
|
|
|
|
raise errors.HTTPAPIError(errors.ERROR_METHOD_NOT_ALLOWED, 'Exceed 10M size limit')
|
|
|
|
raise errors.HTTPAPIError(errors.ERROR_METHOD_NOT_ALLOWED, 'Exceed 10M size limit')
|
|
|
|
|
|
|
|
|
|
|
|
md5_str = hashlib.md5(file.body).hexdigest()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
filepath = settings.rsa_license_file
|
|
|
|
filepath = settings.rsa_license_file
|
|
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
body = file['body']
|
|
|
|
body = file['body']
|
|
|
|
public_key = rsa.load_pub_key_string(open(settings.rsa_public_file).read().strip('\n').encode('utf-8'))
|
|
|
|
plaintext = rsa_oaep.decrypt_message_pri(
|
|
|
|
plaintext = rsa.decrypt(public_key, body)
|
|
|
|
open(settings.rsa_private_file).read().strip('\n').encode('utf-8'), body)
|
|
|
|
plaintext_json = json.loads(self.tostr(plaintext))
|
|
|
|
plaintext_json = json.loads(self.tostr(plaintext))
|
|
|
|
|
|
|
|
|
|
|
|
syscode = plaintext_json["syscode"]
|
|
|
|
syscode = plaintext_json["sys_code"]
|
|
|
|
expireat = plaintext_json["expireat"]
|
|
|
|
expireat = plaintext_json["expire_at"]
|
|
|
|
|
|
|
|
|
|
|
|
current_syscode = sysinfo.get_identify_code()
|
|
|
|
current_syscode = sysinfo.get_idntify_code_v2()
|
|
|
|
if syscode != current_syscode:
|
|
|
|
if syscode != current_syscode:
|
|
|
|
raise errors.HTTPAPIError(errors.ERROR_BAD_REQUEST, "license激活失败,请重新激活")
|
|
|
|
raise errors.HTTPAPIError(errors.ERROR_BAD_REQUEST, "license激活失败,请重新激活")
|
|
|
|
|
|
|
|
|
|
|
|
row = self.db_app.get("select id from license where syscode=%s", syscode)
|
|
|
|
with self.app_mysql.connect() as conn:
|
|
|
|
if row:
|
|
|
|
conn.execute(text(
|
|
|
|
self.db_app.update(
|
|
|
|
"update sys_license set syscode=:syscode, expireat=:expireat, status=:status",
|
|
|
|
"update license set expireat=%s where syscode=%s", str(expireat), syscode
|
|
|
|
{
|
|
|
|
)
|
|
|
|
"syscode": syscode,
|
|
|
|
else:
|
|
|
|
"expireat": expireat,
|
|
|
|
self.db_app.insert(
|
|
|
|
"status": consts.system_status_activated
|
|
|
|
"insert into license(syscode, expireat) values(%s, %s)",
|
|
|
|
}
|
|
|
|
syscode, expireat
|
|
|
|
))
|
|
|
|
)
|
|
|
|
conn.commit()
|
|
|
|
|
|
|
|
|
|
|
|
self.r_app.set("system:license", json.dumps({"syscode": syscode, "expireat": expireat}))
|
|
|
|
self.r_app.set("system:license", json.dumps({"syscode": syscode, "expireat": expireat}))
|
|
|
|
|
|
|
|
|
|
|
|
with open(filepath, 'wb') as f:
|
|
|
|
with open(filepath, 'wb') as f:
|
|
|
|
f.write(file['body'])
|
|
|
|
f.write(file['body'])
|
|
|
|
|
|
|
|
|
|
|
|
logging.info(plaintext_json)
|
|
|
|
|
|
|
|
except Exception as e:
|
|
|
|
except Exception as e:
|
|
|
|
logging.info(e)
|
|
|
|
logging.info(e)
|
|
|
|
raise errors.HTTPAPIError(errors.ERROR_BAD_REQUEST, "license激活失败,请重新激活")
|
|
|
|
raise errors.HTTPAPIError(errors.ERROR_BAD_REQUEST, "license激活失败,请重新激活")
|
|
|
|
|
|
|
|
|
|
|
|
self.finish()
|
|
|
|
self.finish()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class ActivateInfoHandler(APIHandler):
|
|
|
|
class ActivateInfoHandler(APIHandler):
|
|
|
|
@authenticated
|
|
|
|
@authenticated
|
|
|
|
# @permission([100014, 100015])
|
|
|
|
# @permission([100014, 100015])
|
|
|
@ -128,7 +130,6 @@ class ActivateInfoHandler(APIHandler):
|
|
|
|
|
|
|
|
|
|
|
|
class InfoHandler(APIHandler):
|
|
|
|
class InfoHandler(APIHandler):
|
|
|
|
def post(self):
|
|
|
|
def post(self):
|
|
|
|
|
|
|
|
|
|
|
|
self.finish()
|
|
|
|
self.finish()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|