mirror of
https://gitee.com/BDWare/agent-backend
synced 2025-01-10 09:54:11 +00:00
106 lines
3.1 KiB
Plaintext
106 lines
3.1 KiB
Plaintext
import "loadResource.yjs"
|
||
@Access("verified")
|
||
@Permission("SM2")
|
||
contract LicenceManager{
|
||
function onCreate(arg){
|
||
Global.owner=requester;
|
||
Global.applyList = [];
|
||
Global.accepted={
|
||
};
|
||
Global.keyPair = SM2Util.generateKeyPair();
|
||
}
|
||
export function getMainFrame(arg){
|
||
return "/html/main.html";
|
||
}
|
||
export function init(arg){
|
||
print("requester:"+requester +" owner:"+Global.owner);
|
||
if (requester==Global.owner){
|
||
Global.keyPair= JSON.parse(arg);
|
||
return "success";
|
||
}
|
||
else{
|
||
return "forbidden";
|
||
}
|
||
}
|
||
@LogType("Arg","Result")
|
||
export function isOwner(arg){
|
||
// print("Global.keyPair:"+JSON.stringify(Global.keyPair));
|
||
print("Owner:"+Global.owner+" requester:"+requester);
|
||
return requester==Global.owner;
|
||
}
|
||
@LogType("Arg","Result")
|
||
@Description("参数示例:{\"uuid\":\"IDRCMzBBMzQyLUUyOTAtNThFMC04NzY4LTVEOTRBQTkyRjM1OQ==\",\"remark\":\"备注 \"}")
|
||
export function apply(arg){
|
||
arg = JSON.parse(arg);
|
||
for (var i=0;i<Global.applyList.length;i++)
|
||
if (Global.applyList[i].uuid==arg.uuid){
|
||
Global.applyList[i].remark = arg.remark;
|
||
return "success";
|
||
}
|
||
Global.applyList.push(arg);
|
||
var acceptArg = {
|
||
};
|
||
acceptArg.uuid = arg.uuid;
|
||
acceptArg.date = new Date();
|
||
acceptArg.date = acceptArg.date.getTime();
|
||
acceptArg.date += 30*24*3600*1000;
|
||
// print("AcceptArg:"+JSON.stringify(acceptArg));
|
||
accept(JSON.stringify(acceptArg));
|
||
return "success";
|
||
}
|
||
@LogType("Arg","Result")
|
||
@Description("参数示例:IDRCMzBBMzQyLUUyOTAtNThFMC04NzY4LTVEOTRBQTkyRjM1OQ==")
|
||
export function request(arg){
|
||
return JSON.stringify(Global.accepted[arg]);
|
||
//arg为uuid,可获取其licence
|
||
}
|
||
//{"action":"accept","arg":""}
|
||
@Description("参数示例:{\"uuid\":\"IDRCMzBBMzQyLUUyOTAtNThFMC04NzY4LTVEOTRBQTkyRjM1OQ==\",\"expiredDate\":1614493178251,\"nodeCount\":10}")
|
||
@LogType("Arg","Result")
|
||
export function accept(arg){
|
||
if (requester!=Global.owner){
|
||
return "forbidden";
|
||
}
|
||
var oldArg = arg;
|
||
arg = JSON.parse(arg);
|
||
var i=0;
|
||
for (i=0;i<Global.applyList.length;i++){
|
||
if (Global.applyList[i].uuid == arg.uuid){
|
||
break;
|
||
}
|
||
}
|
||
var target = undefined;
|
||
if (i<Global.applyList.length){
|
||
target = Global.applyList[i];
|
||
Global.applyList[i] = Global.applyList[Global.applyList.length-1];
|
||
Global.applyList.pop();
|
||
}
|
||
if (target!=undefined){
|
||
var licence = SM2Util.sign(oldArg,Global.keyPair);
|
||
var result = {
|
||
};
|
||
result.uuid = target.uuid;
|
||
result.remark = target.remark;
|
||
result.expiredDate = arg.expiredDate;
|
||
result.nodeCount = arg.nodeCount;
|
||
result.sig = licence;
|
||
result.licence = oldArg+"|"+JSON.stringify(licence);
|
||
Global.accepted[target.uuid] = result;
|
||
return true;
|
||
}
|
||
return false;
|
||
}
|
||
export function queryAccept(arg){
|
||
if (requester!=Global.owner){
|
||
return "forbidden";
|
||
}
|
||
return JSON.stringify(Global.accepted);
|
||
}
|
||
export function queryApply(arg){
|
||
if (requester!=Global.owner){
|
||
return "forbidden";
|
||
}
|
||
return JSON.stringify(Global.applyList);
|
||
}
|
||
}
|