123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384 |
- // sslvpn
- 'use strict';
- const Controller = require('egg').Controller;
- const filePath = require('../../config/filespath');
- class SslvpnController extends Controller {
- // sslvpn客户端
- async sslvpnclient() {
- const { ctx } = this;
- const form = ctx.request.body;
- // 引入数据文件
- const person = require(filePath.configJson);
- person.sslvpn = form;
- const jsonstr = JSON.stringify(person);
- try {
- // 写入数据文件
- await this.service.fileshandler.write({ filePath: filePath.configJson, str: jsonstr });
- form.capath = `${filePath.CAcert}${form.ca}.cer`;
- form.certpath = `${filePath.cert}${form.cert}.cer`;
- form.keys = `${filePath.keys}${form.cert}.key`;
- // 写入字符串模板
- const sslvpnStr = await ctx.renderView('sslvpn.nj', form);
- if (sslvpnStr) {
- // 写入sslvpn配置文件
- await this.service.fileshandler.write({ filePath: filePath.sslConf, str: sslvpnStr });
- }
- this.ctx.body = { errcode: 0, errmsg: '' };
- } catch (error) {
- const body = { errcode: -1002, errmsg: '设置失败', error };
- throw new Error(JSON.stringify(body));
- }
- }
- // ssl服务端
- async sslvpnservice() {
- const { ctx } = this;
- const form = ctx.request.body;
- const person = require(filePath.configJson);
- person.sslvpnservice = form;
- const jsonstr = JSON.stringify(person);
- try {
- // 写入数据文件
- await this.service.fileshandler.write({ filePath: filePath.configJson, str: jsonstr });
- form.capath = `${filePath.CAcert}${form.ca}.cer`;
- form.certpath = `${filePath.cert}${form.cert}.cer`;
- form.keys = `${filePath.key}${form.cert}.key`;
- // 写入字符串模板
- const sslvpnserviceStr = await ctx.renderView('sslvpnservice.nj', form);
- if (sslvpnserviceStr) {
- // 写入sslvpn配置文件
- await this.service.fileshandler.write({ filePath: filePath.sslConf, str: sslvpnserviceStr });
- }
- this.ctx.body = { errcode: 0, errmsg: '' };
- } catch (error) {
- const body = { errcode: -1002, errmsg: '设置失败', error };
- throw new Error(JSON.stringify(body));
- }
- }
- // 客户端查询
- async sslquery() {
- try {
- const { ctx } = this;
- const person = require(filePath.configJson);
- const data = person.sslvpn;
- ctx.body = { errcode: 0, errmsg: '', data };
- } catch (error) {
- const body = { errcode: -1001, errmsg: '查询失败', error };
- throw new Error(JSON.stringify(body));
- }
- }
- // 服务端查询
- async sslserivcequery() {
- try {
- const { ctx } = this;
- const person = require(filePath.configJson);
- const data = person.sslvpnservice;
- ctx.body = { errcode: 0, errmsg: '', data };
- } catch (error) {
- const body = { errcode: -1001, errmsg: '查询失败', error };
- throw new Error(JSON.stringify(body));
- }
- }
- }
- module.exports = SslvpnController;
|