66 lines
1.9 KiB
JavaScript
66 lines
1.9 KiB
JavaScript
'use strict';
|
|
const util = require('util');
|
|
const fs = require('fs');
|
|
exports.ReadAPIConfig = async function (req, res) {
|
|
var path = '/root/monitor/setup/apiConfig.txt';
|
|
if (fs.existsSync(path)) {
|
|
var text = fs.readFileSync(path,'utf8');
|
|
res.send({status:true,data:text});
|
|
} else {
|
|
res.send({status:false});
|
|
}
|
|
};
|
|
|
|
exports.SaveAPIConfig = async function (req, res) {
|
|
fs.writeFileSync('/root/monitor/setup/apiConfig.txt', JSON.stringify(req.body));
|
|
const { execSync } = require('child_process');
|
|
execSync('sudo systemctl enable S905X_BI');
|
|
execSync('sudo systemctl start S905X_BI');
|
|
res.send(req.body);
|
|
};
|
|
|
|
exports.ReadEngineConfig = async function (req, res) {
|
|
var path = '/root/monitor/setup/engine.json';
|
|
if (fs.existsSync(path)) {
|
|
var text = fs.readFileSync(path,'utf8');
|
|
res.send({status:true,data:text});
|
|
} else {
|
|
res.send({status:false});
|
|
}
|
|
};
|
|
|
|
exports.SaveEngineConfig = async function (req, res) {
|
|
fs.writeFileSync(req.body.path + "/data/config.json", req.body.configEngine);
|
|
fs.writeFileSync('/root/monitor/setup/engine.json', JSON.stringify(req.body.config));
|
|
const { execSync } = require('child_process');
|
|
execSync('sudo systemctl restart S905X_BI');
|
|
res.send(req.body);
|
|
};
|
|
|
|
exports.ReadConfig = async function (req, res) {
|
|
var path = req.body.path + "/data/config.json";
|
|
if (fs.existsSync(path)) {
|
|
var text = fs.readFileSync(path,'utf8');
|
|
res.send({status:true,data:text});
|
|
} else {
|
|
res.send({status:false});
|
|
}
|
|
};
|
|
|
|
|
|
exports.Reset = async function (req, res) {
|
|
console.log("Reset " + req.body.path);
|
|
const { execSync } = require('child_process');
|
|
execSync('sudo systemctl stop S905X_BI');
|
|
execSync('sudo systemctl disable S905X_BI');
|
|
execSync('rm /root/monitor/setup/engine.json');
|
|
|
|
if (req.body.path !== "") {
|
|
execSync('rm -rf ' + req.body.path);
|
|
}
|
|
|
|
res.send({status:true});
|
|
};
|
|
|
|
|