Exemplo n.º 1
0
func checkHttpsCertificates() {
	// Check https certificates. If they are not available generate temporary ones for testing.
	err := httpscerts.Check(filenames.HttpsCertFilename, filenames.HttpsKeyFilename)
	if err != nil {
		log.Println("Warning: couldn't load https certs. Generating new ones. Replace " + filenames.HttpsCertFilename + " and " + filenames.HttpsKeyFilename + " with your own certificates as soon as possible!")
		err := httpscerts.Generate(filenames.HttpsCertFilename, filenames.HttpsKeyFilename, configuration.Config.HttpsUrl)
		if err != nil {
			log.Fatal("Error: Couldn't create https certificates.")
			return
		}
	}
}
Exemplo n.º 2
0
//MAIN FUNC
func main() {
	cfg, _ := config.DefaultConfig()
	defaultinvite := ""

	//read params from terminal
	cfgfile := "./config.json"
	if len(os.Args) > 1 {
		cfgfile = os.Args[1]
		if cfgfile == "--help" {
			fmt.Println("usage: assemble <path/config.json> <invitekey>")
			return
		}

		if len(os.Args) > 2 {
			defaultinvite = os.Args[2]
		}
	}

	// Read the custom config
	clientconfig, err := ioutil.ReadFile(cfgfile)
	if err != nil {
		log.Println("Error reading config.json:", err)
	} else {
		cfg, err = config.LoadConfig(cfg, string(clientconfig))
		if err != nil {
			log.Fatal("Error parsing config.json:", err)
		}
	}

	//grab/create enc key
	userkey := []byte{}
	fc, _ := ioutil.ReadFile("./userkey.txt")
	if fc != nil {
		userkey = fc[:]
	} else {
		tmp := uuid.NewV4().String()
		tmp = tmp[4:]
		ioutil.WriteFile("./userkey.txt", []byte(tmp), 0666)
		userkey = []byte(tmp)
	}

	service = assemble.NewService(cfg, userkey)

	if defaultinvite != "" {
		service.Invites[defaultinvite] = "admin@localhost"
	}

	// Check if the cert files are available and make new ones if needed
	err = httpscerts.Check("cert.pem", "key.pem")
	if err != nil {
		err = httpscerts.Generate("cert.pem", "key.pem", cfg.Host)
		if err != nil {
			log.Fatal("Error: Couldn't find or create https certs.")
		}
	}

	service.SocketServer.On("connection", socketHandlers)
	service.SocketServer.On("error", func(so socketio.Socket, err error) {
		log.Println("socket error:", err)
	})

	http.Handle("/socket.io/", service.SocketServer)
	http.HandleFunc("/signup/", signupHandler)
	http.HandleFunc("/login/", loginHandler)
	http.HandleFunc("/iconlib.js", iconlibHandler)
	http.Handle("/", http.FileServer(http.Dir("./static")))

	service.Start()
}