예제 #1
0
func Start() {
	timeStart = time.Now()
	templates = template.Must(template.ParseFiles("www/index.html"))

	cfgCtrl := srv.Cfg().Get("server")
	sessionkey := cfgCtrl.Get("sessionkey").String()

	http.Handle("/rpc/", seshcookie.NewSessionHandler(&RpcHandler{}, sessionkey, nil))
	http.Handle("/upload", seshcookie.NewSessionHandler(&UploadHandler{}, sessionkey, nil))
	//http.HandleFunc("/vfile/", vfileHandler)
	http.Handle("/", seshcookie.NewSessionHandler(&WebHandler{}, sessionkey, nil))
	StartAuth()

	port := cfgCtrl.Get("port").String()
	if len(port) > 0 {
		srv.HttpListenAndServeAsync(":"+port, nil, "", "", "")
	}
	tlsport := cfgCtrl.Get("tlsport").String()
	if len(tlsport) > 0 && tlsport != "null" {
		srv.HttpListenAndServeAsync(":"+tlsport, nil, "tls_cert.pem", "tls_key.pem", "")
	}

	//srv.VersionDataDir = cfgCtrl.Get("data").String()
	//srv.DoRefreshVersions()
}
예제 #2
0
func StartAuth() {
	gob.Register(make(map[string]string))
	authCache = cache.NewLRUCache(&cache.LRUOptions{Capacity: 128, MaxAge: time.Hour * 1})

	cfgCtrl := srv.Cfg().Get("server")
	sessionkey := cfgCtrl.Get("sessionkey").String()

	http.HandleFunc("/authorize", handleAuthorize)
	http.Handle("/oauth2callback", seshcookie.NewSessionHandler(
		&AuthHandler{},
		sessionkey, nil))

	cfgAU, _ := srv.Cfg().Get("authusers").Array()
	for i := 0; i < len(cfgAU); i++ {
		au := cfgAU[i].(map[string]interface{})
		id := au["id"].(string)
		name := au["name"].(string)
		log.Println("Authorized:", id, name)
		authUsers = append(authUsers, id)
	}

	port := cfgCtrl.Get("port").String()
	addr := cfgCtrl.Get("addr").String()
	if len(redirectAddr) > 0 {
		addr = redirectAddr
	}

	oauthCfg.RedirectURL = "http://" + addr + ":" + port + "/oauth2callback"

	table, _ = db.Main.InitTable(OAuth{})
}