审批
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
允许通过激活码延长数据库过期时间
|
||||
|
||||
增加database.partner,数据库合作伙伴系统参数以区分客户
|
||||
|
||||
此模块为客户使用模块,还有一个激活码签发模块。
|
||||
@@ -0,0 +1,3 @@
|
||||
# Copyright 2014-2016 Therp BV <http://therp.nl>
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
||||
from . import models
|
||||
@@ -0,0 +1,23 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
{
|
||||
"name": "数据库过期时间激活码",
|
||||
"description": """
|
||||
允许通过激活码延长数据库过期时间
|
||||
""",
|
||||
"author": "songbo",
|
||||
"website": "https://www.pengyuthon.com/",
|
||||
"category": "Customizations/Studio",
|
||||
"version": "17.0.0.1",
|
||||
"depends": ["web_enterprise", "mail"],
|
||||
"external_dependencies": {
|
||||
"python": ["rsa"],
|
||||
},
|
||||
"data": ["data/account_report_actions.xml"],
|
||||
"assets": {
|
||||
"web.assets_backend": [
|
||||
"database_activation_code/static/src/webclient/**/*.xml",
|
||||
],
|
||||
},
|
||||
"installable": True,
|
||||
"auto_install": False,
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<odoo>
|
||||
<record model="ir.config_parameter" id="database_activation_code_partner" forcecreate="False">
|
||||
<field name="key">database.partner</field>
|
||||
<field name="value">base</field>
|
||||
</record>
|
||||
</odoo>
|
||||
@@ -0,0 +1,2 @@
|
||||
from . import update
|
||||
from . import ir_http
|
||||
@@ -0,0 +1,30 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
import json
|
||||
|
||||
from odoo import models
|
||||
from odoo.http import request
|
||||
|
||||
|
||||
class Http(models.AbstractModel):
|
||||
_inherit = "ir.http"
|
||||
|
||||
def session_info(self):
|
||||
ICP = self.env["ir.config_parameter"].sudo()
|
||||
User = self.env["res.users"]
|
||||
|
||||
if User.has_group("base.group_system"):
|
||||
warn_enterprise = "admin"
|
||||
elif User.has_group("base.group_user"):
|
||||
warn_enterprise = "user"
|
||||
else:
|
||||
warn_enterprise = False
|
||||
|
||||
result = super(Http, self).session_info()
|
||||
result["support_url"] = "https://www.pengyuthon.com//help"
|
||||
if warn_enterprise:
|
||||
result["warning"] = warn_enterprise
|
||||
result["expiration_date"] = ICP.get_param("database.expiration_date")
|
||||
result["expiration_reason"] = ICP.get_param("database.expiration_reason")
|
||||
return result
|
||||
@@ -0,0 +1,74 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
import datetime
|
||||
import logging
|
||||
import rsa
|
||||
import base64
|
||||
from os.path import join as opj
|
||||
from odoo.modules import get_module_path
|
||||
|
||||
from odoo import api, release, SUPERUSER_ID
|
||||
from odoo.exceptions import UserError
|
||||
from odoo.models import AbstractModel
|
||||
|
||||
_logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class PublisherWarrantyContract(AbstractModel):
|
||||
_inherit = "publisher_warranty.contract"
|
||||
|
||||
# rsa解密
|
||||
def rsaDecrypt(self, str1):
|
||||
modpath = get_module_path("database_activation_code")
|
||||
file_path = opj(modpath, "static", "privkey.pem")
|
||||
with open(file_path) as privatefile:
|
||||
p = privatefile.read()
|
||||
# 验证密钥
|
||||
try:
|
||||
privkey = rsa.PrivateKey.load_pkcs1(p)
|
||||
except:
|
||||
raise UserError("请联系管理员!")
|
||||
|
||||
try:
|
||||
str1 = base64.b16decode(str1)
|
||||
# 私钥解密
|
||||
content = rsa.decrypt(str1, privkey)
|
||||
con = content.decode("utf-8").split("#")
|
||||
if len(con) != 2:
|
||||
raise
|
||||
database_partner = con[0]
|
||||
old_database_partner = (
|
||||
self.sudo().env["ir.config_parameter"].get_param("database.partner")
|
||||
)
|
||||
if database_partner != old_database_partner:
|
||||
raise
|
||||
|
||||
expiration_date = con[1]
|
||||
old_enterprise_code = (
|
||||
self.sudo()
|
||||
.env["ir.config_parameter"]
|
||||
.get_param("database.expiration_date")
|
||||
)
|
||||
except:
|
||||
raise UserError("激活码错误")
|
||||
|
||||
if expiration_date <= old_enterprise_code:
|
||||
raise UserError("激活码已过期")
|
||||
# 设置过期时间
|
||||
set_param = self.env["ir.config_parameter"].sudo().set_param
|
||||
set_param("database.expiration_date", expiration_date)
|
||||
|
||||
def update_notification(self, cron_mode=True):
|
||||
# 获取激活码
|
||||
enterprise_code = (
|
||||
self.sudo().env["ir.config_parameter"].get_param("database.enterprise_code")
|
||||
)
|
||||
if enterprise_code:
|
||||
try:
|
||||
enterprise_code = str.encode(enterprise_code)
|
||||
except:
|
||||
raise UserError("激活码错误")
|
||||
# 验证激活码
|
||||
self.rsaDecrypt(enterprise_code)
|
||||
return True
|
||||
@@ -0,0 +1,9 @@
|
||||
-----BEGIN RSA PRIVATE KEY-----
|
||||
MIIBPAIBAAJBAIfrf/oF/janGFgNeu0Y3YWoVg9SB3msMhfKq6q4G1t9gqdodLYs
|
||||
oc2vNgUd7689231R+vvLGdKzBizDJZVh3tMCAwEAAQJAZTKvX1108AYrNuwaeUuJ
|
||||
K8mxAckmba4KwfIRLJPUxvUvrKDkRwmQCNQ6/FF8UFiYexwu19wOPSYsdiq4b6eT
|
||||
qQIjAJCfBBtskYgfT0qdcPu9NlE++vyTG/QZVlXOCEIr4WcB7BUCHwDwmPrY/nOU
|
||||
nek6/QawqfkUZh7SO7rc/5KMp6V8EUcCImWpMmTow8CxabakyAheMLGaGSq1aqAD
|
||||
s5nrlAiX+gHD6yUCHwDPZjAmygF8RTt9/Au+UmdCbF15QL/uLel4kjOW5ZUCImOr
|
||||
yrfsjcjVr3+nXOqYdR+/Q+6q6sMBRC1Nn2+pbgI5dRY=
|
||||
-----END RSA PRIVATE KEY-----
|
||||
@@ -0,0 +1,10 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<templates xml:space="preserve">
|
||||
|
||||
<t t-name="database_activation_code.DatabaseExpirationPanel" t-inherit="web_enterprise.DatabaseExpirationPanel" t-inherit-mode="extension">
|
||||
<xpath expr="//a[hasclass('oe_instance_buy')]" position="replace">
|
||||
<a class="oe_instance_buy alert-link text-decoration-underline" href="https://www.pengyuthon.com/">联系我们</a>.
|
||||
</xpath>
|
||||
</t>
|
||||
|
||||
</templates>
|
||||
Reference in New Issue
Block a user