Multiple HTTPS certificate support

This commit is contained in:
刘河
2019-03-30 12:03:17 +08:00
parent 5fd335f330
commit 2b841adb1b
16 changed files with 560 additions and 111 deletions

View File

@@ -43,6 +43,7 @@ func (s *BaseController) Prepare() {
} else {
s.Data["isAdmin"] = true
}
s.Data["https_just_proxy"], _ = beego.AppConfig.Bool("https_just_proxy")
}
//加载模板

View File

@@ -251,10 +251,12 @@ func (s *IndexController) AddHost() {
Location: s.GetString("location"),
Flow: &file.Flow{},
Scheme: s.GetString("scheme"),
KeyFilePath: s.GetString("key_file_path"),
CertFilePath: s.GetString("cert_file_path"),
}
var err error
if h.Client, err = file.GetDb().GetClient(s.GetIntNoErr("client_id")); err != nil {
s.AjaxErr("add error")
s.AjaxErr("add error the client can not be found")
}
if err := file.GetDb().NewHost(h); err != nil {
s.AjaxErr("add fail" + err.Error())
@@ -300,6 +302,8 @@ func (s *IndexController) EditHost() {
h.Remark = s.GetString("remark")
h.Location = s.GetString("location")
h.Scheme = s.GetString("scheme")
h.KeyFilePath = s.GetString("key_file_path")
h.CertFilePath = s.GetString("cert_file_path")
file.GetDb().JsonDb.StoreHostToJsonFile()
}
s.AjaxOk("modified success")

View File

@@ -19,13 +19,29 @@
<div class="form-group" id="scheme">
<label class="control-label col-sm-2" langtag="info-scheme">协议类型</label>
<div class="col-sm-10">
<select class="form-control" name="scheme">
<select id="scheme_select" class="form-control" name="scheme">
<option value="all">all</option>
<option value="http">http</option>
<option value="https">https</option>
</select>
</div>
</div>
{{if eq false .https_just_proxy}}
<div class="form-group" id="cert_file">
<label class="col-sm-2 control-label" langtag="info-https-cert">https cert file路径</label>
<div class="col-sm-10">
<input class="form-control" type="text" name="cert_file_path"
placeholder="empty means to be unrestricted">
</div>
</div>
<div class="form-group" id="key_file">
<label class="col-sm-2 control-label" langtag="info-https-key">https key file路径</label>
<div class="col-sm-10">
<input class="form-control" type="text" name="key_file_path"
placeholder="empty means to be unrestricted">
</div>
</div>
{{end}}
<div class="form-group">
<label class="col-sm-2 control-label" langtag="info-url-router">url路由</label>
<div class="col-sm-10">
@@ -60,7 +76,7 @@
</div>
</div>
<div class="form-group" id="hostchange" >
<div class="form-group" id="hostchange">
<label class="col-sm-2 control-label" langtag="info-host-change">request host修改</label>
<div class="col-sm-10">
<input class="form-control" value="" type="text" name="hostchange"
@@ -95,5 +111,14 @@
}
})
})
$("#scheme_select").on("change", function () {
if ($("#scheme_select").val() == "all" || $("#scheme_select").val() == "https") {
$("#cert_file").css("display", "block")
$("#key_file").css("display", "block")
} else {
$("#cert_file").css("display", "none")
$("#key_file").css("display", "none")
}
})
})
</script>

View File

@@ -22,13 +22,29 @@
<div class="form-group" id="scheme">
<label class="control-label col-sm-2" langtag="info-scheme">协议类型</label>
<div class="col-sm-10">
<select class="form-control" name="scheme">
<select id="scheme_select" class="form-control" name="scheme">
<option {{if eq "all" .h.Scheme}}selected{{end}} value="all">all</option>
<option {{if eq "http" .h.Scheme}}selected{{end}} value="http">http</option>
<option {{if eq "https" .h.Scheme}}selected{{end}} value="https">https</option>
</select>
</div>
</div>
{{if eq false .https_just_proxy}}
<div class="form-group" id="cert_file">
<label class="col-sm-2 control-label" langtag="info-https-cert">https cert file路径</label>
<div class="col-sm-10">
<input value="{{.h.CertFilePath}}" class="form-control" type="text" name="cert_file_path"
placeholder="empty means to be unrestricted">
</div>
</div>
<div class="form-group" id="key_file">
<label class="col-sm-2 control-label" langtag="info-https-key">https key file路径</label>
<div class="col-sm-10">
<input value="{{.h.KeyFilePath}}" class="form-control" type="text" name="key_file_path"
placeholder="empty means to be unrestricted">
</div>
</div>
{{end}}
<div class="form-group">
<label class="col-sm-2 control-label" langtag="info-url-router">url路由</label>
<div class="col-sm-10">
@@ -99,5 +115,15 @@
}
})
})
$("#scheme_select").on("change", function () {
if ($("#scheme_select").val() == "all" || $("#scheme_select").val() == "https") {
$("#cert_file").css("display", "block")
$("#key_file").css("display", "block")
} else {
$("#cert_file").css("display", "none")
$("#key_file").css("display", "none")
}
})
})
</script>

View File

@@ -68,6 +68,8 @@
+ '<b langtag="info-compress">压缩</b>' + row.Client.Cnf.Compress + `&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp` + "<br/><br>"
+ '<b langtag="info-web-auth-username">basic权限认证用户名</b>' + row.Client.Cnf.U + `&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp`
+ '<b langtag="info-web-auth-password">basic权限认证密码</b>' + row.Client.Cnf.P + `&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp` + "<br/><br>"
+ '<b langtag="info-https-cert">cert file路径</b>' + row.CertFilePath + `&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp`
+ '<b langtag="info-https-key">key file路径</b>' + row.KeyFilePath + `&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp` + "<br/><br>"
+ '<b langtag="info-header-change">request header修改</b>' + row.HeaderChange + `&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp` + "<br/><br>"
+ '<b langtag="info-host-change">request host 修改</b>' + row.HostChange + `&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp`
},
@@ -77,13 +79,13 @@
field: 'Id',//域值
title: 'id',//标题
visible: true,//false表示不显示
},
{
field: 'Id',//域值
title: 'client id',//标题
visible: true,//false表示不显示
formatter: function (value, row, index) {
return row.Client.Id
}
@@ -92,25 +94,25 @@
field: 'Remark',//域值
title: 'remark',//标题
visible: true,//false表示不显示
},
{
field: 'Host',//域值
title: 'host',//标题
visible: true,//false表示不显示
},
{
field: 'Scheme',//域值
title: 'scheme',//标题
visible: true,//false表示不显示
},
{
field: 'Target',//域值
title: 'target',//标题
visible: true,//false表示不显示
formatter: function (value, row, index) {
return row.Target.TargetStr
}
@@ -119,13 +121,13 @@
field: 'Location',//域值
title: 'location',//标题
visible: true,//false表示不显示
},
{
field: '',//域值
title: 'client status',//内容
visible: true,//false表示不显示
formatter: function (value, row, index) {
if (row.Client.IsConnect) {
return '<span class="badge badge-primary">online</span>'
@@ -138,7 +140,7 @@
field: 'option',//域值
title: 'option',//内容
visible: true,//false表示不显示
formatter: function (value, row, index) {
btn_group = '<div class="btn-group">'
btn = `<button onclick="del(` + row.Id + `)" class="btn-danger"><i class="fa fa-trash"></i></button><button onclick="edit(` + row.Id + `)" class="btn-primary"><i class="fa fa-edit"></i></button></div>`