-
Notifications
You must be signed in to change notification settings - Fork 50
/
web_vhost.go
38 lines (34 loc) · 1013 Bytes
/
web_vhost.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package proxy
import (
"regexp"
"strings"
)
func (wr *webReq) vhostInfo() {
if wr.req.Method == "GET" {
wr.values["vhost"] = wr.web.apiServer.ServerVhostConf
wr.values["userCanEdit"] = wr.user != nil && (wr.web.apiServer.hasUser(wr.user.ID))
wr.render("vhost.html", true)
} else if wr.req.Method == "POST" {
// id:=wr.req.FormValue("id")
// port:=wr.req.FormValue("port")
vhost := wr.web.apiServer.ServerVhostConf
vhost.Name = wr.req.FormValue("name")
vhost.Note = wr.req.FormValue("note")
domain_arr := strings.Split(wr.req.FormValue("domain"), "\n")
domain_reg := regexp.MustCompile(`^(?=^.{3,255}$)[a-zA-Z0-9][-a-zA-Z0-9]{0,62}(\.[a-zA-Z0-9][-a-zA-Z0-9]{0,62})+$`)
var domains []string
for _, line := range domain_arr {
line = strings.TrimSpace(line)
if line == "" {
continue
}
if !domain_reg.MatchString(line) {
wr.alert("域名错误:" + line)
return
}
domains = append(domains, line)
}
vhost.Domains = domains
vhost.Enable = true
}
}