Finishing Prototype
This commit is contained in:
parent
da9196f389
commit
473dc4a495
25 changed files with 1150 additions and 825 deletions
|
@ -6,6 +6,7 @@ import (
|
|||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"git.nutfactory.org/hoernschen/Matrix/config"
|
||||
"git.nutfactory.org/hoernschen/Matrix/entities/device"
|
||||
|
@ -26,12 +27,13 @@ type serverImplementation struct {
|
|||
Version string `json:"version,omitempty"`
|
||||
}
|
||||
|
||||
type ResetBody struct {
|
||||
Packetloss float32 `json:"packetloss,omitempty"`
|
||||
UnavailableTill int `json:"unavailableTill,omitempty"`
|
||||
AuthentificationCheck bool `json:"authentificationCheck,omitempty"`
|
||||
Signing bool `json:"signing,omitempty"`
|
||||
Encryption bool `json:"encryption,omitempty"`
|
||||
type SetParamBody struct {
|
||||
Packetloss int `json:"packetloss,omitempty"`
|
||||
UnavailableTill int64 `json:"unavailableTill,omitempty"`
|
||||
Consensus bool `json:"consensus,omitempty"`
|
||||
AuthentificationCheck bool `json:"authentificationCheck,omitempty"`
|
||||
Signing bool `json:"signing,omitempty"`
|
||||
Encryption bool `json:"encryption,omitempty"`
|
||||
}
|
||||
|
||||
func ResolveServerName(w http.ResponseWriter, r *http.Request) {
|
||||
|
@ -52,10 +54,9 @@ func GetServerImplementation(w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
}
|
||||
|
||||
// TODO: Add a function to set the Config-Params
|
||||
func Reset(w http.ResponseWriter, r *http.Request) {
|
||||
func SetParams(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Content-Type", "application/json; charset=UTF-8")
|
||||
request := ResetBody{}
|
||||
request := SetParamBody{}
|
||||
errResponse := utils.CheckRequest(r)
|
||||
if errResponse != nil {
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
|
@ -74,22 +75,45 @@ func Reset(w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
config.Packetloss = request.Packetloss
|
||||
config.UnavailableTill = request.UnavailableTill
|
||||
config.Consensus = request.Consensus
|
||||
config.AuthentificationCheck = request.AuthentificationCheck
|
||||
config.Signing = request.Signing
|
||||
config.Encryption = request.Signing
|
||||
config.HttpString = "https"
|
||||
if !config.Encryption {
|
||||
config.HttpString = "http"
|
||||
}
|
||||
|
||||
w.WriteHeader(http.StatusOK)
|
||||
}
|
||||
|
||||
func Reset(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Content-Type", "application/json; charset=UTF-8")
|
||||
errResponse := utils.CheckRequest(r)
|
||||
if errResponse != nil {
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
if err := json.NewEncoder(w).Encode(errResponse); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
if err := device.InitServerSigningKey(); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
config.VerifyKeys = make(map[string]map[string][]byte)
|
||||
|
||||
os.Remove("sqlite.db")
|
||||
if err := os.Remove("sqlite.db"); err != nil {
|
||||
log.Println(err)
|
||||
}
|
||||
|
||||
if err := database.InitDB("sqlite.db"); err != nil {
|
||||
if err := database.InitDB(fmt.Sprintf("sqlite%s.db", time.Now().Unix())); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
config.Packetloss = request.Packetloss
|
||||
config.UnavailableTill = request.UnavailableTill
|
||||
config.AuthentificationCheck = request.AuthentificationCheck
|
||||
config.Signing = request.Signing
|
||||
config.Encryption = request.Signing
|
||||
config.SetDefaultParams()
|
||||
|
||||
w.WriteHeader(http.StatusOK)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue