Example #1
0
func main() {
	println("# Hosts file line for debugging...")
	print("127.0.0.1\t", config.Domain, " tag.", config.Domain)
	for _, v := range cookie.ExportSubdomains(config.Domain) {
		print(" ", v)
	}
	println()
	r := mux.NewRouter()
	r.HandleFunc("/dispatch.css", webui.TagDispatchHandler).Host("tag." + config.Domain)
	r.HandleFunc("/setup.css", webui.TagSetupHandler).Host("tag." + config.Domain)
	r.HandleFunc("/reset.css", webui.TagResetHandler).Host("tag." + config.Domain)
	r.HandleFunc("/get/{token:[0-9]+}.css", webui.GetBitHandler).Host("{subdomain:[0-9a-z]}." + config.Domain)
	r.HandleFunc("/set/{switch:(on|off)}.css", webui.SetBitHandler).Host("{subdomain:[0-9a-z]}." + config.Domain)

	r.HandleFunc("/", indexHandler)
	http.Handle("/", r)

	aborted := make(chan int)
	go func() {
		http.ListenAndServe(":8080", nil)
		aborted <- 0
	}()
	go func() {
		http.ListenAndServeTLS(":4343", "secret/hsts.crt", "secret/hsts.key", nil)
		aborted <- 0
	}()
	println("Up and running")
	<-aborted
	println("Aborted")
}
Example #2
0
func TagDispatchHandler(response http.ResponseWriter, request *http.Request) {
	if request.TLS == nil {
		http.Redirect(response, request, fmt.Sprintf("https://tag.%s/setup.css", config.Domain), 302)
	} else {
		op := StartResolvingOp{token: make(chan cookie.Token)}
		start <- &op
		token := <-op.token

		response.Header().Add("Content-Type", "text/css")
		for _, subdomain := range cookie.ExportSubdomains(config.Domain) {
			fmt.Fprintf(response, "@import url(\"http://%s/get/%d.css\") all;\n", subdomain, token)
		}
	}
}