Commit faf42d58 authored by tywldx's avatar tywldx

fix

parent 6bc518f1
......@@ -30,6 +30,8 @@ var attrComsArr = [];
for(let i of attrComs){
attrComsArr.push(attrs[i]);
}
// 获取节点命令
admin.get('/get_node_command/:name', function (req, res) {
res.setHeader("Content-Type","application/json");
var str = execSync(`node ./get_project_config.js -name ${req.params.name} -attr config_file/command/gitPathHead`)
......@@ -40,6 +42,8 @@ admin.get('/get_node_command/:name', function (req, res) {
res.send({configPath:config_file,buildCmd:command,gitGroup:gitGroup});
});
// 获取项目配置
admin.get('/get_project_attr/:name', function (req, res) {
res.setHeader("Content-Type","application/json");
var comstr = attrComsArr.join("/");
......@@ -60,6 +64,8 @@ admin.get('/get_project_attr/:name', function (req, res) {
res.send(rs);
});
// 获取所有域名
admin.get('/get_hosts', function (req, res) {
res.setHeader("Content-Type","application/json");
var comstr = attrComsArr.join("/");
......@@ -68,75 +74,74 @@ admin.get('/get_hosts', function (req, res) {
res.send(items);
});
function parseStr2Json(str){
var a = {};
var strs = str.split(" ");
for(let i of strs){
if(i){
let os = i.split("|");
a[os[0]]={
name: os[0],
ip: os[1],
http: os[2],
https: os[3]
}
}
}
return a
}
function parseJson2Str(json){
var a = [];
let keys = Object.keys(json);
for(let k of keys){
a.push([
json[k].name,
json[k].ip,
json[k].http,
json[k].https
].join("|"))
}
return a.join(" ")
}
// 增加一个新的nginx映射
admin.post('/add_new_proxy', function (req, res) {
let request = req.body;
let new_namespace = request["namespace"],new_ip = request["ip"],new_ports=request["proxy_ports"];
var str = String(execSync(`cat ../ngrok/docker_env_name.sh`)).replace(/\n/,"");
console.log(str)
var index = str.indexOf(request["namespace"])
console.log(index)
let newstr = "",sourcestr;
if( index != -1 ){
//存在这个配置,判断是否是原有的IP
var reg = new RegExp(request["namespace"] + "\\|\\d*\\.\\d*\\.\\d*\\.\\d*\S*");
try{
sourcestr = str.match(reg);
sourcestr = sourcestr[0]
}catch(e){
res.send({msg:"错误,请检查 docket_env_name.sh 文件"})
return
}
// proxy_ports = {
// "http_port": http_port,
// "https_port": https_port
// }
console.log(request)
if(sourcestr != undefined){
var items = sourcestr.split("|");
if(items[1] == request["ip"]){
res.send({msg:"已经存在的配置"});
return
}else{
console.log("update new")
targetstr = request["namespace"] + "|" + request["ip"] + "|" + request["proxy_ports"]["http_port"]+ "|" + request["proxy_ports"]["https_port"] + " ";
newstr = str.replace(sourcestr,targetstr);
}
}else{
res.send({msg:"错误1"})
return
}
}else{
console.log("add new")
newstr = str + " " + request["namespace"] + "|" + request["ip"] + "|" + request["proxy_ports"]["http_port"]+ "|" + request["proxy_ports"]["https_port"] + " ";
//文件添加到这里面
let data = parseStr2Json(str);
data[new_namespace] = {
name: new_namespace,
ip: new_ip,
http: new_ports.http_port,
https: new_ports.https_port
}
newstr = newstr.replace(/\n/,"");
console.log(newstr)
execSync(`echo "${newstr}" > ../ngrok/docker_env_name.sh`)
let s = parseJson2Str(data)
s = s.replace("\n","")
execSync(`echo "${s}" > ../ngrok/docker_env_name.sh`)
cproc.exec("../ngrok/make_frp_ini_V2.sh");
res.send({msg:"执行完成"});
});
// 删除一个namespace映射
admin.post('/remove_proxy', function (req, res) {
let request = req.body;
let new_namespace = request["namespace"];
var str = String(execSync(`cat ../ngrok/docker_env_name.sh`)).replace(/\n/,"");
var sourcestr;
var reg = new RegExp(request["namespace"] + "\\|\\d*\\.\\d*\\.\\d*\\.\\d*\S*");
try{
sourcestr = str.replace(reg,"");
}catch(e){
res.send({msg:"错误,请检查 docket_env_name.sh 文件"})
return
}
execSync(`echo "${sourcestr}" > ../ngrok/docker_env_name.sh`);
cproc.exec(`../ngrok/remove.sh ${request["namespace"]}`);
res.setHeader("Content-Type","application/json");
var str = execSync(`cat ../ngrok/docker_env_name.sh`)
res.send({namespace:String(str)});
let data = parseStr2Json(str);
delete data[new_namespace]
let s = parseJson2Str(data)
s = s.replace("\n","")
execSync(`echo "${s}" > ../ngrok/docker_env_name.sh`)
cproc.exec("../ngrok/make_frp_ini_V2.sh");
res.send({msg:"执行完成"});
});
// 获取现有映射关系
admin.get('/get_proxy', function (req, res) {
res.setHeader("Content-Type","application/json");
var str = execSync(`cat ../ngrok/docker_env_name.sh`)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment