|
@@ -10,7 +10,7 @@ class SystemctlController extends Controller {
|
|
|
try {
|
|
|
await this.service.shell.shell(shells.reboot);
|
|
|
} catch (error) {
|
|
|
- const body = { errcode: -1002, errmsg: '重启机器失败', error };
|
|
|
+ const body = { errcode: -1021, errmsg: '重启机器失败', error };
|
|
|
throw new Error(JSON.stringify(body));
|
|
|
}
|
|
|
}
|
|
@@ -19,12 +19,12 @@ class SystemctlController extends Controller {
|
|
|
try {
|
|
|
const res = await this.service.shell.shell(shells.wanDown);
|
|
|
if (res.errcode === 0) {
|
|
|
- this.ctx.body = { errcode: 0, errmsg: '' };
|
|
|
+ this.ctx.body = { errcode: 0, errmsg: 'ok' };
|
|
|
} else {
|
|
|
this.ctx.body = { errcode: -1, errmsg: '禁用wan网卡失败' };
|
|
|
}
|
|
|
} catch (error) {
|
|
|
- const body = { errcode: -1002, errmsg: '禁用wan网卡失败', error };
|
|
|
+ const body = { errcode: -1022, errmsg: '禁用wan网卡失败', error };
|
|
|
throw new Error(JSON.stringify(body));
|
|
|
}
|
|
|
}
|
|
@@ -33,12 +33,12 @@ class SystemctlController extends Controller {
|
|
|
try {
|
|
|
const res = await this.service.shell.shell(shells.wanUp);
|
|
|
if (res.errcode === 0) {
|
|
|
- this.ctx.body = { errcode: 0, errmsg: '' };
|
|
|
+ this.ctx.body = { errcode: 0, errmsg: 'ok' };
|
|
|
} else {
|
|
|
this.ctx.body = { errcode: -1, errmsg: '启用wan网卡失败' };
|
|
|
}
|
|
|
} catch (error) {
|
|
|
- const body = { errcode: -1002, errmsg: '启用wan网卡失败', error };
|
|
|
+ const body = { errcode: -1023, errmsg: '启用wan网卡失败', error };
|
|
|
throw new Error(JSON.stringify(body));
|
|
|
}
|
|
|
}
|
|
@@ -47,12 +47,12 @@ class SystemctlController extends Controller {
|
|
|
try {
|
|
|
const res = await this.service.shell.shell(shells.lanUp);
|
|
|
if (res.errcode === 0) {
|
|
|
- this.ctx.body = { errcode: 0, errmsg: '' };
|
|
|
+ this.ctx.body = { errcode: 0, errmsg: 'ok' };
|
|
|
} else {
|
|
|
this.ctx.body = { errcode: -1, errmsg: '启用lan网卡失败' };
|
|
|
}
|
|
|
} catch (error) {
|
|
|
- const body = { errcode: -1002, errmsg: '启用lan网卡失败', error };
|
|
|
+ const body = { errcode: -1024, errmsg: '启用lan网卡失败', error };
|
|
|
throw new Error(JSON.stringify(body));
|
|
|
}
|
|
|
}
|
|
@@ -61,12 +61,12 @@ class SystemctlController extends Controller {
|
|
|
try {
|
|
|
const res = await this.service.shell.shell(shells.lanDown);
|
|
|
if (res.errcode === 0) {
|
|
|
- this.ctx.body = { errcode: 0, errmsg: '' };
|
|
|
+ this.ctx.body = { errcode: 0, errmsg: 'ok' };
|
|
|
} else {
|
|
|
this.ctx.body = { errcode: -1, errmsg: '禁用lan网卡失败' };
|
|
|
}
|
|
|
} catch (error) {
|
|
|
- const body = { errcode: -1002, errmsg: '禁用lan网卡失败', error };
|
|
|
+ const body = { errcode: -1025, errmsg: '禁用lan网卡失败', error };
|
|
|
throw new Error(JSON.stringify(body));
|
|
|
}
|
|
|
}
|
|
@@ -77,12 +77,12 @@ class SystemctlController extends Controller {
|
|
|
const res = await this.service.shell.shell(`ping ${address} -c 3`);
|
|
|
console.log(res, 'res');
|
|
|
if (res.errcode === 0 && res.data !== '') {
|
|
|
- this.ctx.body = { errcode: 0, errmsg: '' };
|
|
|
+ this.ctx.body = { errcode: 0, errmsg: 'ok' };
|
|
|
} else {
|
|
|
this.ctx.body = { errcode: -1, errmsg: '地址连接失败' };
|
|
|
}
|
|
|
} catch (error) {
|
|
|
- const body = { errcode: -1002, errmsg: '地址连接异常', error };
|
|
|
+ const body = { errcode: -1026, errmsg: '地址连接异常', error };
|
|
|
throw new Error(JSON.stringify(body));
|
|
|
}
|
|
|
}
|
|
@@ -91,12 +91,12 @@ class SystemctlController extends Controller {
|
|
|
try {
|
|
|
const res = await this.service.shell.shell('date "+%Y-%m-%d %H:%M:%S"');
|
|
|
if (res.errcode === 0) {
|
|
|
- this.ctx.body = { errcode: 0, errmsg: '' };
|
|
|
+ this.ctx.body = { errcode: 0, errmsg: 'ok' };
|
|
|
} else {
|
|
|
this.ctx.body = { errcode: -1, errmsg: '获取时间失败' };
|
|
|
}
|
|
|
} catch (error) {
|
|
|
- const body = { errcode: -1002, errmsg: '获取时间失败', error };
|
|
|
+ const body = { errcode: -1027, errmsg: '获取时间失败', error };
|
|
|
throw new Error(JSON.stringify(body));
|
|
|
}
|
|
|
}
|
|
@@ -107,12 +107,12 @@ class SystemctlController extends Controller {
|
|
|
const res = await this.service.shell.shell(`date -s "${date}"`);
|
|
|
console.log(res);
|
|
|
if (res.errcode === 0) {
|
|
|
- this.ctx.body = { errcode: 0, errmsg: '' };
|
|
|
+ this.ctx.body = { errcode: 0, errmsg: 'ok' };
|
|
|
} else {
|
|
|
this.ctx.body = { errcode: -0, errmsg: '设置系统时间失败' };
|
|
|
}
|
|
|
} catch (error) {
|
|
|
- const body = { errcode: -1002, errmsg: '设置系统时间失败', error };
|
|
|
+ const body = { errcode: -1028, errmsg: '设置系统时间失败', error };
|
|
|
throw new Error(JSON.stringify(body));
|
|
|
}
|
|
|
}
|
|
@@ -121,12 +121,12 @@ class SystemctlController extends Controller {
|
|
|
try {
|
|
|
const res = await this.service.shell.shell('swanctl -l | grep established');
|
|
|
if (res.errcode === 0 && res.data.length > 0) {
|
|
|
- this.ctx.body = { errcode: 0, errmsg: '', data: '已连接' };
|
|
|
+ this.ctx.body = { errcode: 0, errmsg: 'ok', data: '已连接' };
|
|
|
} else {
|
|
|
- this.ctx.body = { errcode: 0, errmsg: '', data: '未连接' };
|
|
|
+ this.ctx.body = { errcode: 0, errmsg: 'ok', data: '未连接' };
|
|
|
}
|
|
|
} catch (error) {
|
|
|
- const body = { errcode: -1002, errmsg: '获取VPN连接状态失败', error };
|
|
|
+ const body = { errcode: -1029, errmsg: '获取VPN连接状态失败', error };
|
|
|
throw new Error(JSON.stringify(body));
|
|
|
}
|
|
|
}
|
|
@@ -135,12 +135,12 @@ class SystemctlController extends Controller {
|
|
|
try {
|
|
|
const res = await this.service.shell.shell('vmstat | tail -n 1 | awk \'{print $13}\'');
|
|
|
if (res.errcode === 0 && res.data) {
|
|
|
- this.ctx.body = { errcode: 0, errmsg: '', data: { cpu: res.data } };
|
|
|
+ this.ctx.body = { errcode: 0, errmsg: 'ok', data: { cpu: res.data } };
|
|
|
} else {
|
|
|
this.ctx.body = { errcode: -1, errmsg: '获取CPU使用率失败' };
|
|
|
}
|
|
|
} catch (error) {
|
|
|
- const body = { errcode: -1002, errmsg: '获取CPU使用率失败', error };
|
|
|
+ const body = { errcode: -1030, errmsg: '获取CPU使用率失败', error };
|
|
|
throw new Error(JSON.stringify(body));
|
|
|
}
|
|
|
}
|
|
@@ -154,7 +154,7 @@ class SystemctlController extends Controller {
|
|
|
this.ctx.body = { errcode: -1, errmsg: '获取内存使用率失败' };
|
|
|
}
|
|
|
} catch (error) {
|
|
|
- const body = { errcode: -1002, errmsg: '获取内存使用率失败', error };
|
|
|
+ const body = { errcode: -1031, errmsg: '获取内存使用率失败', error };
|
|
|
throw new Error(JSON.stringify(body));
|
|
|
}
|
|
|
}
|
|
@@ -166,7 +166,7 @@ class SystemctlController extends Controller {
|
|
|
const version = configJson.version;
|
|
|
this.ctx.body = { errcode: 0, errmsg: '', data: { model, version } };
|
|
|
} catch (error) {
|
|
|
- const body = { errcode: -1002, errmsg: '获取设备信息失败', error };
|
|
|
+ const body = { errcode: -1032, errmsg: '获取设备信息失败', error };
|
|
|
throw new Error(JSON.stringify(body));
|
|
|
}
|
|
|
}
|
|
@@ -186,12 +186,12 @@ class SystemctlController extends Controller {
|
|
|
try {
|
|
|
const res = await this.service.shell.shell(data);
|
|
|
if (res.errcode === 0) {
|
|
|
- this.ctx.body = { errcode: 0, errmsg: '' };
|
|
|
+ this.ctx.body = { errcode: 0, errmsg: 'ok' };
|
|
|
} else {
|
|
|
this.ctx.body = { errcode: -1, errmsg: '操作失败' };
|
|
|
}
|
|
|
} catch (error) {
|
|
|
- const body = { errcode: -1002, errmsg: '操作失败', error };
|
|
|
+ const body = { errcode: -1033, errmsg: '操作失败', error };
|
|
|
throw new Error(JSON.stringify(body));
|
|
|
}
|
|
|
}
|
|
@@ -211,12 +211,23 @@ class SystemctlController extends Controller {
|
|
|
try {
|
|
|
const res = await this.service.shell.shell(data);
|
|
|
if (res.errcode === 0) {
|
|
|
- this.ctx.body = { errcode: 0, errmsg: '' };
|
|
|
+ this.ctx.body = { errcode: 0, errmsg: 'ok' };
|
|
|
} else {
|
|
|
this.ctx.body = { errcode: -1, errmsg: '操作失败' };
|
|
|
}
|
|
|
} catch (error) {
|
|
|
- const body = { errcode: -1002, errmsg: '操作失败', error };
|
|
|
+ const body = { errcode: -1034, errmsg: '操作失败', error };
|
|
|
+ throw new Error(JSON.stringify(body));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 恢复默认配置
|
|
|
+ async configDefault() {
|
|
|
+ try {
|
|
|
+ await this.service.shell.shell(shells.configDefault);
|
|
|
+ this.ctx.body = { errcode: 0, errmsg: 'ok' };
|
|
|
+ } catch (error) {
|
|
|
+ const body = { errcode: -1035, errmsg: '恢复默认设置失败', error };
|
|
|
throw new Error(JSON.stringify(body));
|
|
|
}
|
|
|
}
|