mirror of
https://github.com/balzack/databag.git
synced 2025-02-12 03:29: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.Searchable = account.Searchable
|
||||||
status.Sealable = true
|
status.Sealable = true
|
||||||
status.EnableIce = getBoolConfigValue(CNFEnableIce, false)
|
status.EnableIce = getBoolConfigValue(CNFEnableIce, false)
|
||||||
status.AllowUnsealed = getBoolConfigValue(CNFAllowUnsealed, true)
|
status.AllowUnsealed = getBoolConfigValue(CNFAllowUnsealed, false)
|
||||||
status.PushEnabled = session.PushEnabled
|
status.PushEnabled = session.PushEnabled
|
||||||
status.Seal = seal
|
status.Seal = seal
|
||||||
WriteResponse(w, status)
|
WriteResponse(w, status)
|
||||||
|
@ -17,11 +17,11 @@ func GetNodeConfig(w http.ResponseWriter, r *http.Request) {
|
|||||||
var config NodeConfig
|
var config NodeConfig
|
||||||
config.Domain = getStrConfigValue(CNFDomain, "")
|
config.Domain = getStrConfigValue(CNFDomain, "")
|
||||||
config.AccountStorage = getNumConfigValue(CNFStorage, 0)
|
config.AccountStorage = getNumConfigValue(CNFStorage, 0)
|
||||||
config.AllowUnsealed = getBoolConfigValue(CNFAllowUnsealed, true)
|
config.AllowUnsealed = getBoolConfigValue(CNFAllowUnsealed, false)
|
||||||
config.EnableImage = getBoolConfigValue(CNFEnableImage, true)
|
config.EnableImage = getBoolConfigValue(CNFEnableImage, true)
|
||||||
config.EnableAudio = getBoolConfigValue(CNFEnableAudio, true)
|
config.EnableAudio = getBoolConfigValue(CNFEnableAudio, true)
|
||||||
config.EnableVideo = getBoolConfigValue(CNFEnableVideo, true)
|
config.EnableVideo = getBoolConfigValue(CNFEnableVideo, true)
|
||||||
config.KeyType = getStrConfigValue(CNFKeyType, APPRSA4096)
|
config.KeyType = getStrConfigValue(CNFKeyType, APPRSA2048)
|
||||||
config.PushSupported = getBoolConfigValue(CNFPushSupported, true)
|
config.PushSupported = getBoolConfigValue(CNFPushSupported, true)
|
||||||
config.EnableIce = getBoolConfigValue(CNFEnableIce, false)
|
config.EnableIce = getBoolConfigValue(CNFEnableIce, false)
|
||||||
config.IceUrl = getStrConfigValue(CNFIceUrl, "")
|
config.IceUrl = getStrConfigValue(CNFIceUrl, "")
|
||||||
|
@ -73,7 +73,7 @@ func SetNodeConfig(w http.ResponseWriter, r *http.Request) {
|
|||||||
if res := tx.Clauses(clause.OnConflict{
|
if res := tx.Clauses(clause.OnConflict{
|
||||||
Columns: []clause.Column{{Name: "config_id"}},
|
Columns: []clause.Column{{Name: "config_id"}},
|
||||||
DoUpdates: clause.AssignmentColumns([]string{"bool_value"}),
|
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
|
return res
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -145,7 +145,7 @@ const APPQueuePhoto = "photo"
|
|||||||
const APPQueueDefault = ""
|
const APPQueueDefault = ""
|
||||||
|
|
||||||
//APPDefaultPath config for default path to store assets
|
//APPDefaultPath config for default path to store assets
|
||||||
const APPDefaultPath = "./asset"
|
const APPDefaultPath = "/tmp/databag/assets"
|
||||||
|
|
||||||
//AppCardStatus compares cards status with string
|
//AppCardStatus compares cards status with string
|
||||||
func AppCardStatus(status string) bool {
|
func AppCardStatus(status string) bool {
|
||||||
|
@ -10,7 +10,7 @@ import (
|
|||||||
|
|
||||||
//GenerateRsaKeyPair creates a public/private key for a new account
|
//GenerateRsaKeyPair creates a public/private key for a new account
|
||||||
func GenerateRsaKeyPair() (*rsa.PrivateKey, *rsa.PublicKey, string, error) {
|
func GenerateRsaKeyPair() (*rsa.PrivateKey, *rsa.PublicKey, string, error) {
|
||||||
keyType := getStrConfigValue(CNFKeyType, "RSA4096");
|
keyType := getStrConfigValue(CNFKeyType, "RSA2048");
|
||||||
if keyType == "RSA2048" {
|
if keyType == "RSA2048" {
|
||||||
privkey, _ := rsa.GenerateKey(rand.Reader, 2048)
|
privkey, _ := rsa.GenerateKey(rand.Reader, 2048)
|
||||||
return privkey, &privkey.PublicKey, "RSA2048", nil
|
return privkey, &privkey.PublicKey, "RSA2048", nil
|
||||||
|
@ -16,7 +16,7 @@ type route struct {
|
|||||||
type routes []route
|
type routes []route
|
||||||
|
|
||||||
//NewRouter allocate router for databag API
|
//NewRouter allocate router for databag API
|
||||||
func NewRouter() *mux.Router {
|
func NewRouter(path string) *mux.Router {
|
||||||
|
|
||||||
go SendNotifications()
|
go SendNotifications()
|
||||||
|
|
||||||
@ -33,7 +33,7 @@ func NewRouter() *mux.Router {
|
|||||||
Handler(handler)
|
Handler(handler)
|
||||||
}
|
}
|
||||||
|
|
||||||
fs := http.FileServer(http.Dir("/app/databag/net/web/build/"))
|
fs := http.FileServer(http.Dir(path));
|
||||||
router.PathPrefix("/").Handler(http.StripPrefix("/", fs))
|
router.PathPrefix("/").Handler(http.StripPrefix("/", fs))
|
||||||
|
|
||||||
return router
|
return router
|
||||||
|
@ -4,13 +4,14 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"gorm.io/gorm"
|
"gorm.io/gorm"
|
||||||
"gorm.io/gorm/logger"
|
"gorm.io/gorm/logger"
|
||||||
|
"gorm.io/gorm/clause"
|
||||||
"github.com/glebarez/sqlite"
|
"github.com/glebarez/sqlite"
|
||||||
)
|
)
|
||||||
|
|
||||||
var DB *gorm.DB;
|
var DB *gorm.DB;
|
||||||
|
|
||||||
func SetPath(path string) {
|
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),
|
Logger: logger.Default.LogMode(logger.Silent),
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -18,6 +19,22 @@ func SetPath(path string) {
|
|||||||
panic("failed to connect database")
|
panic("failed to connect database")
|
||||||
}
|
}
|
||||||
AutoMigrate(db)
|
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
|
DB = db
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -10,26 +10,15 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
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
|
args := os.Args
|
||||||
if len(args) == 3 {
|
if len(args) == 3 {
|
||||||
port := ":" + args[2]
|
port := ":" + args[1]
|
||||||
path := "/etc/letsencrypt/live/" + args[1]
|
store.SetPath(args[2])
|
||||||
log.Printf("starting server at: " + path + " " + port);
|
router := app.NewRouter("/opt/databag/web/build")
|
||||||
log.Fatal(http.ListenAndServeTLS(port, path + "/fullchain.pem", path + "/privkey.pem", handlers.CORS(origins, methods)(router)))
|
origins := handlers.AllowedOrigins([]string{"*"})
|
||||||
} else if len(args) == 2 {
|
methods := handlers.AllowedMethods([]string{"GET", "HEAD", "POST", "PUT", "DELETE", "OPTIONS"})
|
||||||
path := "/etc/letsencrypt/live/" + args[1]
|
log.Fatal(http.ListenAndServe(port, handlers.CORS(origins, methods)(router)))
|
||||||
log.Printf("starting server at: " + path);
|
|
||||||
log.Fatal(http.ListenAndServeTLS(":443", path + "/fullchain.pem", path + "/privkey.pem", handlers.CORS(origins, methods)(router)))
|
|
||||||
} else {
|
} else {
|
||||||
log.Printf("starting server");
|
log.Printf("usage: databag <port> <store path>");
|
||||||
log.Fatal(http.ListenAndServe(":7000", handlers.CORS(origins, methods)(router)))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -141,8 +141,6 @@ export function useCards() {
|
|||||||
channel.state.channels.forEach((entry, id) => {
|
channel.state.channels.forEach((entry, id) => {
|
||||||
const cards = entry?.data?.channelDetail?.contacts?.cards || [];
|
const cards = entry?.data?.channelDetail?.contacts?.cards || [];
|
||||||
const subject = entry?.data?.channelDetail?.data || '';
|
const subject = entry?.data?.channelDetail?.data || '';
|
||||||
const type = entry?.data?.channelDetail?.dataType || '';
|
|
||||||
|
|
||||||
if (cards.length === 1 && cards[0] === cardId && subject === '{"subject":null}') {
|
if (cards.length === 1 && cards[0] === cardId && subject === '{"subject":null}') {
|
||||||
channelId = entry.id;
|
channelId = entry.id;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user