Skip to content

Commit

Permalink
add get conffile webui
Browse files Browse the repository at this point in the history
  • Loading branch information
maguozhi committed Aug 10, 2022
1 parent d521241 commit e3bcb7e
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 29 deletions.
42 changes: 26 additions & 16 deletions webgui/conf.html
Original file line number Diff line number Diff line change
@@ -1,36 +1,26 @@
<!DOCTYPE html>
<html>
<head>
<title>Demo of ACE Editor</title>
<meta charset="UTF-8">
<title>ConfFile</title>
<!--导入js库-->
<script src="https://cdnjs.cloudflare.com/ajax/libs/ace/1.2.6/ace.js" type="text/javascript"
charset="utf-8"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/ace/1.2.6/ext-language_tools.js" type="text/javascript"
charset="utf-8"></script>
<script src="js/axios.min.js"></script>
<script src='js/jquery-3.3.1.min.js'></script>
<script src="js/common.js"></script>
<link rel="stylesheet" href="css/bootstrap.min.css"/>
<link rel="stylesheet" href="css/bootstrap-table.css"/>
<link rel="stylesheet" href="css/bootstrap-dialog.min.css"/>
</head>

<body>
<!--代码输入框(注意请务必设置高度,否则无法显示)-->
<pre id="code" class="ace_editor" style="min-height:400px">
<textarea id="text_conf" class="ace_text-input">
[inet_http_server]
port = :9001

[program:linx-test]
directory = /export/home/maguozhi/code/go/test_prometheus
command = ./test

[program:ddc]
directory = /export/home/maguozhi/unrealddc
command = ./unreal_httpddc_server
stdout_logfile = /export/home/maguozhi/unrealddc/logs/console.log
stderr_logfile = /export/home/maguozhi/unrealddc/logs/console.log
</textarea>
<pre id="code" class="ace_editor" style="min-height:600px">
<textarea id="text_conf" class="ace_text-input">
</textarea>
</pre>
<button class="btn btn-primary">
Save
Expand All @@ -54,6 +44,26 @@
//自动换行,设置为off关闭
editor.setOption("wrap", "free")

$(document).ready(function () {
console.log("hello world!")
let name = getUrlVars()["name"]
getConfFile(name)
});

function getConfFile(name) {
if (name === undefined || name.length === 0){
alert("need url variable name")
return
}
axios.get("/conf/" + name).then(function (response) {
console.log(response.data)
editor.setValue(response.data)
}).catch(function (err){
alert("ERROR:此程序未配置conf文件,如需配置参考conf_file")
})

}

</script>

</body>
Expand Down
12 changes: 12 additions & 0 deletions webgui/js/common.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
function getUrlVars()
{
var vars = [], hash;
var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
for(var i = 0; i < hashes.length; i++)
{
hash = hashes[i].split('=');
vars.push(hash[0]);
vars[hash[0]] = hash[1];
}
return vars;
}
16 changes: 3 additions & 13 deletions webgui/log.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<title>LOG</title>
</head>
<body>
<script src="js/axios.min.js"></script>
<script src='js/jquery-3.3.1.min.js'></script>
<script src="js/common.js"></script>
<link rel="stylesheet" href="css/bootstrap.min.css"/>
<link rel="stylesheet" href="css/bootstrap-table.css"/>
<link rel="stylesheet" href="css/bootstrap-dialog.min.css"/>
Expand Down Expand Up @@ -48,18 +49,7 @@

}

function getUrlVars()
{
var vars = [], hash;
var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
for(var i = 0; i < hashes.length; i++)
{
hash = hashes[i].split('=');
vars.push(hash[0]);
vars[hash[0]] = hash[1];
}
return vars;
}

</script>
</body>
</html>
10 changes: 10 additions & 0 deletions xmlrpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,16 @@ func (p *XMLRPC) startHTTPServer(user string, password string, protocol string,
// conf 文件
confHandler := NewConfApi(s).CreateHandler()
mux.Handle("/conf/", newHTTPBasicAuth(user, password, confHandler))
mux.HandleFunc("/confFile", func(writer http.ResponseWriter, request *http.Request) {
b, err := readFile("webgui/conf.html")
if err != nil {
writer.WriteHeader(http.StatusNotFound)
return
}

writer.WriteHeader(http.StatusOK)
writer.Write(b)
})

// 读log.html文件
mux.HandleFunc("/log", readLogHtml)
Expand Down

0 comments on commit e3bcb7e

Please sign in to comment.