Commit faf42d58 authored by tywldx's avatar tywldx

fix

parent 6bc518f1
...@@ -30,6 +30,8 @@ var attrComsArr = []; ...@@ -30,6 +30,8 @@ var attrComsArr = [];
for(let i of attrComs){ for(let i of attrComs){
attrComsArr.push(attrs[i]); attrComsArr.push(attrs[i]);
} }
// 获取节点命令
admin.get('/get_node_command/:name', function (req, res) { admin.get('/get_node_command/:name', function (req, res) {
res.setHeader("Content-Type","application/json"); res.setHeader("Content-Type","application/json");
var str = execSync(`node ./get_project_config.js -name ${req.params.name} -attr config_file/command/gitPathHead`) 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) { ...@@ -40,6 +42,8 @@ admin.get('/get_node_command/:name', function (req, res) {
res.send({configPath:config_file,buildCmd:command,gitGroup:gitGroup}); res.send({configPath:config_file,buildCmd:command,gitGroup:gitGroup});
}); });
// 获取项目配置
admin.get('/get_project_attr/:name', function (req, res) { admin.get('/get_project_attr/:name', function (req, res) {
res.setHeader("Content-Type","application/json"); res.setHeader("Content-Type","application/json");
var comstr = attrComsArr.join("/"); var comstr = attrComsArr.join("/");
...@@ -60,6 +64,8 @@ admin.get('/get_project_attr/:name', function (req, res) { ...@@ -60,6 +64,8 @@ admin.get('/get_project_attr/:name', function (req, res) {
res.send(rs); res.send(rs);
}); });
// 获取所有域名
admin.get('/get_hosts', function (req, res) { admin.get('/get_hosts', function (req, res) {
res.setHeader("Content-Type","application/json"); res.setHeader("Content-Type","application/json");
var comstr = attrComsArr.join("/"); var comstr = attrComsArr.join("/");
...@@ -68,75 +74,74 @@ admin.get('/get_hosts', function (req, res) { ...@@ -68,75 +74,74 @@ admin.get('/get_hosts', function (req, res) {
res.send(items); 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) { admin.post('/add_new_proxy', function (req, res) {
let request = req.body; 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/,""); var str = String(execSync(`cat ../ngrok/docker_env_name.sh`)).replace(/\n/,"");
console.log(str) let data = parseStr2Json(str);
var index = str.indexOf(request["namespace"]) data[new_namespace] = {
console.log(index) name: new_namespace,
let newstr = "",sourcestr; ip: new_ip,
if( index != -1 ){ http: new_ports.http_port,
//存在这个配置,判断是否是原有的IP https: new_ports.https_port
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"] + " ";
//文件添加到这里面
} }
newstr = newstr.replace(/\n/,"");
console.log(newstr) let s = parseJson2Str(data)
execSync(`echo "${newstr}" > ../ngrok/docker_env_name.sh`) s = s.replace("\n","")
execSync(`echo "${s}" > ../ngrok/docker_env_name.sh`)
cproc.exec("../ngrok/make_frp_ini_V2.sh"); cproc.exec("../ngrok/make_frp_ini_V2.sh");
res.send({msg:"执行完成"}); res.send({msg:"执行完成"});
}); });
// 删除一个namespace映射
admin.post('/remove_proxy', function (req, res) { admin.post('/remove_proxy', function (req, res) {
let request = req.body; let request = req.body;
let new_namespace = request["namespace"];
var str = String(execSync(`cat ../ngrok/docker_env_name.sh`)).replace(/\n/,""); var str = String(execSync(`cat ../ngrok/docker_env_name.sh`)).replace(/\n/,"");
var sourcestr; let data = parseStr2Json(str);
var reg = new RegExp(request["namespace"] + "\\|\\d*\\.\\d*\\.\\d*\\.\\d*\S*"); delete data[new_namespace]
try{ let s = parseJson2Str(data)
sourcestr = str.replace(reg,""); s = s.replace("\n","")
}catch(e){ execSync(`echo "${s}" > ../ngrok/docker_env_name.sh`)
res.send({msg:"错误,请检查 docket_env_name.sh 文件"}) cproc.exec("../ngrok/make_frp_ini_V2.sh");
return res.send({msg:"执行完成"});
}
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)});
}); });
// 获取现有映射关系
admin.get('/get_proxy', function (req, res) { admin.get('/get_proxy', function (req, res) {
res.setHeader("Content-Type","application/json"); res.setHeader("Content-Type","application/json");
var str = execSync(`cat ../ngrok/docker_env_name.sh`) 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