Finished Prototype
This commit is contained in:
parent
ea54a27796
commit
6de476260d
30 changed files with 2189 additions and 0 deletions
36
config/config.go
Normal file
36
config/config.go
Normal file
|
@ -0,0 +1,36 @@
|
|||
package config
|
||||
|
||||
import (
|
||||
"time"
|
||||
)
|
||||
|
||||
var ServerName string = "Hoernschen's ActivityPub Server"
|
||||
var Version string = "0.1"
|
||||
|
||||
var Homeserver string
|
||||
var Port string
|
||||
|
||||
var PrivateKey []byte
|
||||
var PublicKey []byte
|
||||
var KeyId string
|
||||
var VerifyKeys map[string]map[string][]byte
|
||||
|
||||
var Packetloss int
|
||||
var UnavailableTill int64
|
||||
var Consensus bool
|
||||
var AuthentificationCheck bool
|
||||
var Signing bool
|
||||
var Encryption bool
|
||||
var HttpString string
|
||||
|
||||
//var BackoffPolicy *backoff.Exponential
|
||||
|
||||
func SetDefaultParams() {
|
||||
Packetloss = 0.0
|
||||
UnavailableTill = time.Now().Unix()
|
||||
Consensus = true
|
||||
AuthentificationCheck = true
|
||||
Signing = true
|
||||
Encryption = true
|
||||
HttpString = "https"
|
||||
}
|
69
config/configController.go
Normal file
69
config/configController.go
Normal file
|
@ -0,0 +1,69 @@
|
|||
package config
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
|
||||
"git.nutfactory.org/hoernschen/ActivityPub/utils/database"
|
||||
)
|
||||
|
||||
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 SetParams(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Content-Type", "application/json; charset=UTF-8")
|
||||
request := SetParamBody{}
|
||||
decoder := json.NewDecoder(r.Body)
|
||||
err := decoder.Decode(&request)
|
||||
if err != nil {
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
if err := json.NewEncoder(w).Encode(fmt.Sprintf("Could not parse JSON: %s", err)); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
Packetloss = request.Packetloss
|
||||
UnavailableTill = request.UnavailableTill
|
||||
Consensus = request.Consensus
|
||||
AuthentificationCheck = request.AuthentificationCheck
|
||||
Signing = request.Signing
|
||||
Encryption = request.Signing
|
||||
HttpString = "https"
|
||||
if !Encryption {
|
||||
HttpString = "http"
|
||||
}
|
||||
|
||||
w.WriteHeader(http.StatusOK)
|
||||
}
|
||||
|
||||
func Reset(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Content-Type", "application/json; charset=UTF-8")
|
||||
|
||||
/*
|
||||
if err := device.InitServerSigningKey(); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
config.VerifyKeys = make(map[string]map[string][]byte)
|
||||
*/
|
||||
|
||||
database.DB.Close()
|
||||
os.Remove("sqlite.db")
|
||||
|
||||
if err := database.InitDB("sqlite.db"); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
SetDefaultParams()
|
||||
|
||||
w.WriteHeader(http.StatusOK)
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue