mirror of
https://github.com/schollz/hostyoself.git
synced 2026-01-23 02:15:14 +00:00
improvements for analytics (customize Google Site Verification ID and add support for Umami (github.com/umami-software/umami))
Signed-off-by: Seth Grover <seth.d.grover@gmail.com>
This commit is contained in:
parent
04ad1997a6
commit
22b2abb4b8
3 changed files with 39 additions and 14 deletions
10
main.go
10
main.go
|
|
@ -43,6 +43,9 @@ func main() {
|
|||
Flags: []cli.Flag{
|
||||
cli.StringFlag{Name: "url, u", Value: "localhost", Usage: "public URL to use"},
|
||||
cli.StringFlag{Name: "port", Value: "8010", Usage: "ports of the local relay"},
|
||||
cli.StringFlag{Name: "google-site-verification-id, g", Value: "", Usage: "Google site verification ID"},
|
||||
cli.StringFlag{Name: "umami-url", Value: "", Usage: "Umami analytics URL"},
|
||||
cli.StringFlag{Name: "umami-id", Value: "", Usage: "Umami analytics ID"},
|
||||
},
|
||||
HelpName: "hostyoself relay",
|
||||
Action: func(c *cli.Context) error {
|
||||
|
|
@ -118,6 +121,11 @@ func relay(c *cli.Context) (err error) {
|
|||
flagPublicURL = "http://" + flagPublicURL
|
||||
}
|
||||
|
||||
s := server.New(flagPublicURL, c.String("port"))
|
||||
s := server.New(
|
||||
flagPublicURL,
|
||||
c.String("port"),
|
||||
c.String("google-site-verification-id"),
|
||||
c.String("umami-url"),
|
||||
c.String("umami-id"))
|
||||
return s.Run()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,8 +21,11 @@ import (
|
|||
)
|
||||
|
||||
type server struct {
|
||||
publicURL string
|
||||
port string
|
||||
publicURL string
|
||||
port string
|
||||
googleSiteVerification string
|
||||
umamiURL string
|
||||
umamiID string
|
||||
|
||||
// connections stored as map of domain -> connections
|
||||
conn map[string][]*connection
|
||||
|
|
@ -39,11 +42,14 @@ type connection struct {
|
|||
ws *wsconn.WebsocketConn
|
||||
}
|
||||
|
||||
func New(publicURL, port string) *server {
|
||||
func New(publicURL, port, googleSiteVerification, umamiURL, umamiID string) *server {
|
||||
return &server{
|
||||
publicURL: publicURL,
|
||||
port: port,
|
||||
conn: make(map[string][]*connection),
|
||||
publicURL: publicURL,
|
||||
port: port,
|
||||
googleSiteVerification: googleSiteVerification,
|
||||
umamiURL: umamiURL,
|
||||
umamiID: umamiID,
|
||||
conn: make(map[string][]*connection),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -106,14 +112,20 @@ Disallow:`))
|
|||
return err
|
||||
}
|
||||
type view struct {
|
||||
PublicURL template.JS
|
||||
GeneratedDomain string
|
||||
GeneratedKey string
|
||||
PublicURL template.JS
|
||||
GoogleSiteVerification string
|
||||
UmamiURL template.JS
|
||||
UmamiID string
|
||||
GeneratedDomain string
|
||||
GeneratedKey string
|
||||
}
|
||||
return t.Execute(w, view{
|
||||
PublicURL: template.JS(s.publicURL),
|
||||
GeneratedDomain: namesgenerator.GetRandomName(),
|
||||
GeneratedKey: utils.RandStringBytesMaskImpr(6),
|
||||
PublicURL: template.JS(s.publicURL),
|
||||
GoogleSiteVerification: s.googleSiteVerification,
|
||||
UmamiURL: template.JS(s.umamiURL),
|
||||
UmamiID: s.umamiID,
|
||||
GeneratedDomain: namesgenerator.GetRandomName(),
|
||||
GeneratedKey: utils.RandStringBytesMaskImpr(6),
|
||||
})
|
||||
} else {
|
||||
// get IP address
|
||||
|
|
|
|||
7
templates/view.html
vendored
7
templates/view.html
vendored
|
|
@ -4,7 +4,12 @@
|
|||
<head>
|
||||
<meta charset='utf-8'>
|
||||
<title>host yo self</title>
|
||||
<meta name="google-site-verification" content="shffrGJ5t6F5m-ILyEVvbmxk8Fh1x_dSl6SF-WNKIWU" />
|
||||
{{ if .GoogleSiteVerification }}
|
||||
<meta name="google-site-verification" content="{{ .GoogleSiteVerification }}" />
|
||||
{{ end }}
|
||||
{{ if and .UmamiURL .UmamiID }}
|
||||
<script defer src="{{ .UmamiURL }}" data-website-id="{{ .UmamiID }}"></script>
|
||||
{{ end }}
|
||||
<meta http-equiv='X-UA-Compatible' content='IE=edge'>
|
||||
<meta name='description' content='Need a web host? Host your self! Use this page to host a website or a file directly from your computer / phone / smartwatch / toaster!'>
|
||||
<meta name='viewport' content='width=device-width, initial-scale=1'>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue