license setting

This commit is contained in:
kuaifan 2023-03-16 12:47:58 +08:00
parent 809c6769f6
commit 4260549f72
9 changed files with 260 additions and 14 deletions

View File

@ -513,6 +513,41 @@ class SystemController extends AbstractController
return Base::retSuccess('success', $setting);
}
/**
* @api {post} api/system/license 08. License
*
* @apiDescription 获取License信息、保存License限管理员
* @apiVersion 1.0.0
* @apiGroup system
* @apiName license
*
* @apiParam {String} type
* - get: 获取
* - save: 保存
* @apiParam {String} license License 原文
*
* @apiSuccess {Number} ret 返回状态码1正确、0错误
* @apiSuccess {String} msg 返回信息(错误描述)
* @apiSuccess {Object} data 返回数据
*/
public function license()
{
User::auth('admin');
//
$type = trim(Request::input('type'));
if ($type == 'save') {
$license = Base::getPostValue('license');
Doo::licenseSave($license);
}
//
return Base::retSuccess('success', [
'license' => Doo::licenseContent(),
'info' => Doo::license(),
'macs' => Doo::macs(),
'user_count' => User::whereBot(0)->whereNull('disable_at')->count(),
]);
}
/**
* @api {get} api/system/get/info 10. 获取终端详细信息
*

View File

@ -24,6 +24,9 @@ class VerifyCsrfToken extends Middleware
// 保存创建项目列表模板
'api/system/column/template/',
// License 设置
'api/system/license/',
// 添加任务
'api/project/task/add/',

View File

@ -43,6 +43,7 @@ class Doo
char* tokenDecode(char* val);
char* translate(char* val, char* val);
char* md5s(char* text, char* password);
char* macs();
EOF, "/usr/lib/doo/doo.so");
$token = $token ?: Base::headerOrInput('token');
$language = $language ?: Base::headerOrInput('language');
@ -55,7 +56,8 @@ class Doo
* @param $language
* @return mixed
*/
public static function doo($token = null, $language = null) {
public static function doo($token = null, $language = null)
{
if (self::$doo == null) {
self::load($token, $language);
}
@ -86,6 +88,14 @@ class Doo
}
}
$macs = explode(",", $array['mac']);
$array['mac'] = [];
foreach ($macs as $mac) {
if (Base::isMac($mac)) {
$array['mac'][] = $mac;
}
}
$emails = explode(",", $array['email']);
$array['email'] = [];
foreach ($emails as $email) {
@ -97,6 +107,28 @@ class Doo
return $array;
}
/**
* 获取License原文
* @return string
*/
public static function licenseContent(): string
{
$paths = [
config_path("LICENSE"),
config_path("license"),
app_path("LICENSE"),
app_path("license"),
];
$content = "";
foreach ($paths as $path) {
if (file_exists($path)) {
$content = file_get_contents($path);
break;
}
}
return $content;
}
/**
* 解析License
* @param $license
@ -237,4 +269,20 @@ class Doo
{
return self::string(self::doo()->md5s($text, $password));
}
/**
* 获取php容器mac地址组
* @return array
*/
public static function macs(): array
{
$macs = explode(",", self::string(self::doo()->macs()));
$array = [];
foreach ($macs as $mac) {
if (Base::isMac($mac)) {
$array[] = $mac;
}
}
return $array;
}
}

View File

@ -3,7 +3,7 @@ version: '3'
services:
php:
container_name: "dootask-php-${APP_ID}"
image: "kuaifan/php:swoole-8.0.rc4"
image: "kuaifan/php:swoole-8.0.rc5"
shm_size: "1024m"
volumes:
- ./docker/crontab/crontab.conf:/etc/supervisor/conf.d/crontab.conf

View File

@ -539,7 +539,7 @@ export default {
array.push(...[
{path: 'personal', name: '个人设置', divided: true},
{path: 'system', name: '系统设置'},
{path: 'clearCache', name: '清除缓存'},
{path: 'license', name: 'License Key'},
{path: 'version', name: '更新版本', divided: true, visible: !!this.clientNewVersion},
@ -551,7 +551,6 @@ export default {
} else {
array.push(...[
{path: 'personal', name: '个人设置', divided: true},
{path: 'clearCache', name: '清除缓存'},
{path: 'version', name: '更新版本', divided: true, visible: !!this.clientNewVersion},
@ -562,11 +561,13 @@ export default {
if (needStartHome) {
array.push(...[
{path: 'goHome', name: '打开首页', divided: true},
{path: 'clearCache', name: '清除缓存'},
{path: 'logout', name: '退出登录', style: {color: '#f40'}}
])
} else {
array.push(...[
{path: 'logout', name: '退出登录', style: {color: '#f40'}, divided: true}
{path: 'clearCache', name: '清除缓存', divided: true},
{path: 'logout', name: '退出登录', style: {color: '#f40'}}
])
}
return array

View File

@ -4,12 +4,12 @@
<Row class="setting-color color-label-box">
<Col span="12">{{$L('名称')}}</Col>
<Col span="4">
<ETooltip :disabled="windowSmall || $isEEUiApp" :content="$L('数值越小级别越高')" max-width="auto" placement="top" transfer>
<ETooltip :content="$L('数值越小级别越高')" max-width="auto" placement="top" transfer>
<div><Icon class="information" type="ios-information-circle-outline" /> {{$L('级别')}}</div>
</ETooltip>
</Col>
<Col span="4">
<ETooltip :disabled="windowSmall || $isEEUiApp" :content="$L('任务完成时间')" max-width="auto" placement="top" transfer>
<ETooltip :content="$L('任务完成时间')" max-width="auto" placement="top" transfer>
<div><Icon class="information" type="ios-information-circle-outline" /> {{$L('天数')}}</div>
</ETooltip>
</Col>

View File

@ -99,15 +99,13 @@ export default {
if (this.userIsAdmin) {
menu.push(...[
{path: 'system', name: '系统设置', divided: true},
{path: 'clearCache', name: '清除缓存'},
{path: 'logout', name: '退出登录'},
])
} else {
menu.push(...[
{path: 'clearCache', name: '清除缓存', divided: true},
{path: 'logout', name: '退出登录'},
{path: 'license', name: 'License Key'},
])
}
menu.push(...[
{path: 'clearCache', name: '清除缓存', divided: true},
{path: 'logout', name: '退出登录'},
])
return menu;
},

View File

@ -0,0 +1,156 @@
<template>
<div class="setting-item submit">
<Form ref="formData" :model="formData" :labelPosition="formLabelPosition" :labelWidth="formLabelWidth" @submit.native.prevent>
<FormItem label="License" prop="license">
<Input v-model="formData.license" type="textarea" :autosize="{minRows: 3,maxRows: 14}" :placeholder="$L('请输入License...')" />
</FormItem>
<FormItem :label="$L('详细信息')">
<div class="license-box">
<ul>
<li>
<em>SN:</em>
<span>{{formData.info.sn}}</span>
</li>
<li>
<em>IP:</em>
<span>{{infoJoin(formData.info.ip)}}</span>
</li>
<li>
<em>{{$L('域名')}}:</em>
<span>{{infoJoin(formData.info.domain)}}</span>
</li>
<li>
<em>MAC:</em>
<span>{{infoJoin(formData.info.mac)}}</span>
<ETooltip max-width="auto" placement="right">
<div slot="content">{{$L('当前环境')}}: {{infoJoin(formData.macs, '-')}}</div>
<Icon class="information" type="ios-information-circle-outline" />
</ETooltip>
</li>
<li>
<em>{{$L('使用人数')}}:</em>
<span>{{formData.info.people || $L('无限制')}} ({{$L('已使用')}}: {{formData.user_count}})</span>
<ETooltip max-width="auto" placement="right">
<div slot="content">{{$L('限制注册人数')}}</div>
<Icon class="information" type="ios-information-circle-outline" />
</ETooltip>
</li>
<li>
<em>{{$L('创建时间')}}:</em>
<span>{{formData.info.created_at}}</span>
</li>
<li>
<em>{{$L('到期时间')}}:</em>
<span>{{formData.info.expired_at || $L('永久')}}</span>
<ETooltip v-if="formData.info.expired_at" max-width="auto" placement="right">
<div slot="content">{{$L('到期后限制注册帐号')}}</div>
<Icon class="information" type="ios-information-circle-outline" />
</ETooltip>
</li>
</ul>
</div>
</FormItem>
</Form>
<div class="setting-footer">
<Button :loading="loadIng > 0" type="primary" @click="submitForm">{{$L('提交')}}</Button>
<Button :loading="loadIng > 0" @click="resetForm" style="margin-left: 8px">{{$L('重置')}}</Button>
</div>
</div>
</template>
<style lang="scss" scoped>
.license-box {
padding-top: 6px;
> ul {
> li {
list-style: none;
font-size: 14px;
line-height: 22px;
padding-bottom: 6px;
display: flex;
> em {
flex-shrink: 0;
font-style: normal;
opacity: 0.8;
}
> span {
padding-left: 6px;
}
.information {
display: flex;
align-items: center;
justify-content: center;
margin-left: 6px;
}
}
}
}
</style>
<script>
import {mapState} from "vuex";
export default {
data() {
return {
loadIng: 0,
formData: {
license: '',
info: {},
macs: [],
user_count: 0
},
}
},
mounted() {
this.systemSetting();
},
computed: {
...mapState(['userInfo', 'formLabelPosition', 'formLabelWidth']),
},
methods: {
submitForm() {
this.$refs.formData.validate((valid) => {
if (valid) {
this.systemSetting(true);
}
})
},
resetForm() {
this.formData = $A.cloneJSON(this.formData_bak);
},
systemSetting(save) {
this.loadIng++;
this.$store.dispatch("call", {
url: 'system/license?type=' + (save ? 'save' : 'get'),
method: 'post',
data: this.formData,
}).then(({data}) => {
if (save) {
$A.messageSuccess('修改成功');
}
this.formData = data;
this.formData_bak = $A.cloneJSON(this.formData);
}).catch(({msg}) => {
if (save) {
$A.modalError(msg);
}
}).finally(_ => {
this.loadIng--;
});
},
infoJoin(val, def = null) {
if ($A.isArray(val)) {
val = val.join(",")
}
if (val) {
return val
}
return def === null ? this.$L("无限制") : def
}
}
}
</script>

View File

@ -59,6 +59,11 @@ export default [
path: 'keyboard',
component: () => import('./pages/manage/setting/keyboard.vue'),
},
{
name: 'manage-setting-license',
path: 'license',
component: () => import('./pages/manage/setting/license.vue'),
},
{
name: 'manage-setting-password',
path: 'password',