Implement client connect form defaults
This commit is contained in:
parent
a9031eb532
commit
2ccca3a778
9 changed files with 127 additions and 57 deletions
41
server/index_template.go
Normal file
41
server/index_template.go
Normal file
|
@ -0,0 +1,41 @@
|
|||
package server
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"io"
|
||||
|
||||
"github.com/khlieng/dispatch/Godeps/_workspace/src/github.com/spf13/viper"
|
||||
)
|
||||
|
||||
var (
|
||||
index_start = []byte(`<!DOCTYPE html><html lang=en><head><meta charset=UTF-8><meta name=viewport content="width=device-width,initial-scale=1"><title>Dispatch</title><link href="https://fonts.googleapis.com/css?family=Montserrat:400,700|Roboto+Mono:400,700" rel=stylesheet><link href=/bundle.css rel=stylesheet></head><body><div id=root></div><script>window.__ENV__=`)
|
||||
index_end = []byte(`;</script><script src=/bundle.js></script></body></html>`)
|
||||
)
|
||||
|
||||
type connectDefaults struct {
|
||||
Name string `json:"name"`
|
||||
Address string `json:"address"`
|
||||
Channels []string `json:"channels"`
|
||||
Password string `json:"password"`
|
||||
SSL bool `json:"ssl"`
|
||||
}
|
||||
|
||||
type indexData struct {
|
||||
Defaults connectDefaults `json:"defaults"`
|
||||
}
|
||||
|
||||
func renderIndex(w io.Writer, session *Session) {
|
||||
w.Write(index_start)
|
||||
|
||||
json.NewEncoder(w).Encode(indexData{
|
||||
Defaults: connectDefaults{
|
||||
Name: viper.GetString("defaults.name"),
|
||||
Address: viper.GetString("defaults.address"),
|
||||
Channels: viper.GetStringSlice("defaults.channels"),
|
||||
Password: viper.GetString("defaults.password"),
|
||||
SSL: viper.GetBool("defaults.ssl"),
|
||||
},
|
||||
})
|
||||
|
||||
w.Write(index_end)
|
||||
}
|
|
@ -4,6 +4,8 @@ import (
|
|||
"crypto/tls"
|
||||
"net"
|
||||
|
||||
"github.com/khlieng/dispatch/Godeps/_workspace/src/github.com/spf13/viper"
|
||||
|
||||
"github.com/khlieng/dispatch/irc"
|
||||
"github.com/khlieng/dispatch/storage"
|
||||
)
|
||||
|
@ -24,7 +26,8 @@ func reconnectIRC() {
|
|||
|
||||
if cert := user.GetCertificate(); cert != nil {
|
||||
i.TLSConfig = &tls.Config{
|
||||
Certificates: []tls.Certificate{*cert},
|
||||
Certificates: []tls.Certificate{*cert},
|
||||
InsecureSkipVerify: !viper.GetBool("verify_client_certificates"),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -4,6 +4,7 @@ import (
|
|||
"bytes"
|
||||
"compress/gzip"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
@ -29,8 +30,7 @@ type File struct {
|
|||
|
||||
func serveFiles(w http.ResponseWriter, r *http.Request) {
|
||||
if r.URL.Path == "/" {
|
||||
handleAuth(w, r)
|
||||
serveFile(w, r, "index.html.gz", "text/html")
|
||||
serveIndex(w, r)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -46,8 +46,27 @@ func serveFiles(w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
}
|
||||
|
||||
handleAuth(w, r)
|
||||
serveFile(w, r, "index.html.gz", "text/html")
|
||||
serveIndex(w, r)
|
||||
}
|
||||
|
||||
func serveIndex(w http.ResponseWriter, r *http.Request) {
|
||||
session := handleAuth(w, r)
|
||||
if session == nil {
|
||||
log.Println("[Auth] No session")
|
||||
w.WriteHeader(500)
|
||||
return
|
||||
}
|
||||
|
||||
w.Header().Set("Content-Type", "text/html")
|
||||
|
||||
if strings.Contains(r.Header.Get("Accept-Encoding"), "gzip") {
|
||||
w.Header().Set("Content-Encoding", "gzip")
|
||||
gzw := gzip.NewWriter(w)
|
||||
renderIndex(gzw, session)
|
||||
gzw.Close()
|
||||
} else {
|
||||
renderIndex(w, session)
|
||||
}
|
||||
}
|
||||
|
||||
func serveFile(w http.ResponseWriter, r *http.Request, path, contentType string) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue