mirror of
https://github.com/balzack/databag.git
synced 2025-02-11 19:19:16 +00:00
supporting device restrictions
This commit is contained in:
parent
560263606b
commit
f18bd116fd
@ -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)
|
||||
|
@ -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, "")
|
||||
|
@ -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
|
||||
}
|
||||
|
||||
|
@ -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 {
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
}
|
||||
|
||||
|
@ -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>");
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user