supporting device restrictions

This commit is contained in:
Roland Osborne 2024-01-12 13:21:51 -08:00
parent 560263606b
commit f18bd116fd
9 changed files with 33 additions and 29 deletions

View File

@ -37,7 +37,7 @@ func GetAccountStatus(w http.ResponseWriter, r *http.Request) {
status.Searchable = account.Searchable
status.Sealable = true
status.EnableIce = getBoolConfigValue(CNFEnableIce, false)
status.AllowUnsealed = getBoolConfigValue(CNFAllowUnsealed, true)
status.AllowUnsealed = getBoolConfigValue(CNFAllowUnsealed, false)
status.PushEnabled = session.PushEnabled
status.Seal = seal
WriteResponse(w, status)

View File

@ -17,11 +17,11 @@ func GetNodeConfig(w http.ResponseWriter, r *http.Request) {
var config NodeConfig
config.Domain = getStrConfigValue(CNFDomain, "")
config.AccountStorage = getNumConfigValue(CNFStorage, 0)
config.AllowUnsealed = getBoolConfigValue(CNFAllowUnsealed, true)
config.AllowUnsealed = getBoolConfigValue(CNFAllowUnsealed, false)
config.EnableImage = getBoolConfigValue(CNFEnableImage, true)
config.EnableAudio = getBoolConfigValue(CNFEnableAudio, true)
config.EnableVideo = getBoolConfigValue(CNFEnableVideo, true)
config.KeyType = getStrConfigValue(CNFKeyType, APPRSA4096)
config.KeyType = getStrConfigValue(CNFKeyType, APPRSA2048)
config.PushSupported = getBoolConfigValue(CNFPushSupported, true)
config.EnableIce = getBoolConfigValue(CNFEnableIce, false)
config.IceUrl = getStrConfigValue(CNFIceUrl, "")

View File

@ -73,7 +73,7 @@ func SetNodeConfig(w http.ResponseWriter, r *http.Request) {
if res := tx.Clauses(clause.OnConflict{
Columns: []clause.Column{{Name: "config_id"}},
DoUpdates: clause.AssignmentColumns([]string{"bool_value"}),
}).Create(&store.Config{ConfigID: CNFAllowUnsealed, BoolValue: config.AllowUnsealed}).Error; res != nil {
}).Create(&store.Config{ConfigID: CNFAllowUnsealed, BoolValue: false}).Error; res != nil {
return res
}

View File

@ -145,7 +145,7 @@ const APPQueuePhoto = "photo"
const APPQueueDefault = ""
//APPDefaultPath config for default path to store assets
const APPDefaultPath = "./asset"
const APPDefaultPath = "/tmp/databag/assets"
//AppCardStatus compares cards status with string
func AppCardStatus(status string) bool {

View File

@ -10,7 +10,7 @@ import (
//GenerateRsaKeyPair creates a public/private key for a new account
func GenerateRsaKeyPair() (*rsa.PrivateKey, *rsa.PublicKey, string, error) {
keyType := getStrConfigValue(CNFKeyType, "RSA4096");
keyType := getStrConfigValue(CNFKeyType, "RSA2048");
if keyType == "RSA2048" {
privkey, _ := rsa.GenerateKey(rand.Reader, 2048)
return privkey, &privkey.PublicKey, "RSA2048", nil

View File

@ -16,7 +16,7 @@ type route struct {
type routes []route
//NewRouter allocate router for databag API
func NewRouter() *mux.Router {
func NewRouter(path string) *mux.Router {
go SendNotifications()
@ -33,7 +33,7 @@ func NewRouter() *mux.Router {
Handler(handler)
}
fs := http.FileServer(http.Dir("/app/databag/net/web/build/"))
fs := http.FileServer(http.Dir(path));
router.PathPrefix("/").Handler(http.StripPrefix("/", fs))
return router

View File

@ -4,13 +4,14 @@ import (
"fmt"
"gorm.io/gorm"
"gorm.io/gorm/logger"
"gorm.io/gorm/clause"
"github.com/glebarez/sqlite"
)
var DB *gorm.DB;
func SetPath(path string) {
db, err := gorm.Open(sqlite.Open(path), &gorm.Config{
db, err := gorm.Open(sqlite.Open(path + "/databag.db"), &gorm.Config{
Logger: logger.Default.LogMode(logger.Silent),
})
if err != nil {
@ -18,6 +19,22 @@ func SetPath(path string) {
panic("failed to connect database")
}
AutoMigrate(db)
// upsert key type
err = db.Transaction(func(tx *gorm.DB) error {
if res := tx.Clauses(clause.OnConflict{
Columns: []clause.Column{{Name: "config_id"}},
DoUpdates: clause.AssignmentColumns([]string{"str_value"}),
}).Create(&Config{ConfigID: "asset_path", StrValue: path + "/assets"}).Error; res != nil {
return res
}
return nil
})
if err != nil {
fmt.Println(err);
panic("failed to set database path")
}
DB = db
}

View File

@ -10,26 +10,15 @@ import (
)
func main() {
store.SetPath("/var/lib/databag/databag.db")
router := app.NewRouter()
origins := handlers.AllowedOrigins([]string{"*"})
methods := handlers.AllowedMethods([]string{"GET", "HEAD", "POST", "PUT", "DELETE", "OPTIONS"})
args := os.Args
if len(args) == 3 {
port := ":" + args[2]
path := "/etc/letsencrypt/live/" + args[1]
log.Printf("starting server at: " + path + " " + port);
log.Fatal(http.ListenAndServeTLS(port, path + "/fullchain.pem", path + "/privkey.pem", handlers.CORS(origins, methods)(router)))
} else if len(args) == 2 {
path := "/etc/letsencrypt/live/" + args[1]
log.Printf("starting server at: " + path);
log.Fatal(http.ListenAndServeTLS(":443", path + "/fullchain.pem", path + "/privkey.pem", handlers.CORS(origins, methods)(router)))
port := ":" + args[1]
store.SetPath(args[2])
router := app.NewRouter("/opt/databag/web/build")
origins := handlers.AllowedOrigins([]string{"*"})
methods := handlers.AllowedMethods([]string{"GET", "HEAD", "POST", "PUT", "DELETE", "OPTIONS"})
log.Fatal(http.ListenAndServe(port, handlers.CORS(origins, methods)(router)))
} else {
log.Printf("starting server");
log.Fatal(http.ListenAndServe(":7000", handlers.CORS(origins, methods)(router)))
log.Printf("usage: databag <port> <store path>");
}
}

View File

@ -141,8 +141,6 @@ export function useCards() {
channel.state.channels.forEach((entry, id) => {
const cards = entry?.data?.channelDetail?.contacts?.cards || [];
const subject = entry?.data?.channelDetail?.data || '';
const type = entry?.data?.channelDetail?.dataType || '';
if (cards.length === 1 && cards[0] === cardId && subject === '{"subject":null}') {
channelId = entry.id;
}