package main import ( "crypto/tls" "log" "net/http" "os" "nutfactory.org/Matrix/config" "nutfactory.org/Matrix/entities/device" "nutfactory.org/Matrix/entities/event" "nutfactory.org/Matrix/entities/general" "nutfactory.org/Matrix/entities/room" "nutfactory.org/Matrix/entities/user" "nutfactory.org/Matrix/utils/database" "nutfactory.org/Matrix/utils/router" ) var keyPath = "./ssl.key" var certPath = "./ssl.crt" var routes = router.Routes{ // General router.Route{"ResolveServerName", "GET", "/.well-known/matrix/server", general.ResolveServerName}, router.Route{"GetServerImplementation", "GET", "/_matrix/federation/v1/version", general.GetServerImplementation}, router.Route{"Reset", "GET", "/reset", general.Reset}, // Keys router.Route{"GetSigningKey", "GET", "/_matrix/key/v2/server/{keyId}", device.GetServerSigningKeyHandler}, router.Route{"GetSigningKey", "GET", "/_matrix/key/v2/server", device.GetServerSigningKeyHandler}, // Users router.Route{"CheckUsernameAvailability", "GET", "/_matrix/client/r0/register/available", user.CheckUsernameAvailabilityHandler}, router.Route{"Register", "POST", "/_matrix/client/r0/register", user.RegisterHandler}, router.Route{"Login", "POST", "/_matrix/client/r0/login", user.LoginHandler}, router.Route{"Logout", "POST", "/_matrix/client/r0/logout", user.LogoutHandler}, router.Route{"Sync", "GET", "/_matrix/client/r0/sync", user.SyncHandler}, // Rooms router.Route{"CreateRoom", "POST", "/_matrix/client/r0/createRoom", room.CreateRoomHandler}, router.Route{"GetRoomMembers", "GET", "/_matrix/client/r0/rooms/{roomId}/members", room.GetRoomMemberHandler}, router.Route{"JoinRoomUser", "POST", "/_matrix/client/r0/rooms/{roomId}/join", room.JoinRoomUserHandler}, router.Route{"GetPrepInfoToJoin", "GET", "/_matrix/federation/v1/make_join/{roomId}/{userId}", room.GetPrepInfoToJoinHandler}, router.Route{"JoinRoomServer", "PUT", "/_matrix/federation/v2/send_join/{roomId}/{eventId}", room.JoinRoomServerHandler}, // Events router.Route{"CreateEvent", "PUT", "/_matrix/client/r0/rooms/{roomId}/send/{eventType}/{txnId}", event.SendMessageHandler}, router.Route{"CreateStateEvent", "PUT", "/_matrix/client/r0/rooms/{roomId}/state/{eventType}/{stateKey}", event.CreateStateEventHandler}, router.Route{"GetEventUser", "GET", "/_matrix/client/r0/rooms/{roomId}/event/{eventId}", event.GetEventUserHandler}, router.Route{"GetStateEvent", "GET", "/_matrix/client/r0/rooms/{roomId}/state/{eventType}/{stateKey}", event.GetStateEventHandler}, router.Route{"SyncEventsServer", "PUT", "/_matrix/federation/v1/send/{txnId}", event.SyncEventsServerHandler}, router.Route{"Backfill", "GET", "/_matrix/federation/v1/backfill/{roomId}", event.BackfillHandler}, } func main() { // TODO: Change to something variable --> cli // TODO: Implement Message Counter http.DefaultTransport.(*http.Transport).TLSClientConfig = &tls.Config{InsecureSkipVerify: true} config.Homeserver = "localhost" config.Port = "80" if err := device.InitServerSigningKey(); err != nil { log.Fatal(err) } config.VerifyKeys = make(map[string]map[string][]byte) os.Remove("sqlite.db") if err := database.InitDB("sqlite.db"); err != nil { log.Fatal(err) } defer database.DB.Close() // TODO: Set Default Config Params here config.HttpString = "https" router := router.NewRouter(routes) // TODO: Serve on Port 443 and 80 without Redirect httpErr := http.ListenAndServeTLS(":443", certPath, keyPath, router) if httpErr != nil { log.Fatal(httpErr) } go http.ListenAndServe(":80", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { http.Redirect(w, r, "https://"+r.Host+r.URL.String(), http.StatusMovedPermanently) })) }