mirror of
https://github.com/fankes/beszel.git
synced 2025-10-19 01:39:34 +08:00
update default data directory
This commit is contained in:
3
.gitignore
vendored
3
.gitignore
vendored
@@ -3,4 +3,5 @@ pb_data
|
|||||||
data
|
data
|
||||||
temp
|
temp
|
||||||
.vscode
|
.vscode
|
||||||
beszel
|
beszel
|
||||||
|
beszel_data
|
21
main.go
21
main.go
@@ -34,7 +34,9 @@ var app *pocketbase.PocketBase
|
|||||||
var serverConnections = make(map[string]Server)
|
var serverConnections = make(map[string]Server)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
app = pocketbase.New()
|
app = pocketbase.NewWithConfig(pocketbase.Config{
|
||||||
|
DefaultDataDir: "beszel_data",
|
||||||
|
})
|
||||||
app.RootCmd.Version = Version
|
app.RootCmd.Version = Version
|
||||||
app.RootCmd.Use = "beszel"
|
app.RootCmd.Use = "beszel"
|
||||||
app.RootCmd.Short = ""
|
app.RootCmd.Short = ""
|
||||||
@@ -117,7 +119,7 @@ func main() {
|
|||||||
if requestData.AuthRecord == nil {
|
if requestData.AuthRecord == nil {
|
||||||
return apis.NewForbiddenError("Forbidden", nil)
|
return apis.NewForbiddenError("Forbidden", nil)
|
||||||
}
|
}
|
||||||
key, err := os.ReadFile("./pb_data/id_ed25519.pub")
|
key, err := os.ReadFile(app.DataDir() + "/id_ed25519.pub")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -400,7 +402,7 @@ func handleStatusAlerts(newStatus string, oldRecord *models.Record) error {
|
|||||||
alerts, err := app.Dao().FindRecordsByFilter("alerts", "name = 'status' && system = {:system}", "-created", -1, 0, dbx.Params{
|
alerts, err := app.Dao().FindRecordsByFilter("alerts", "name = 'status' && system = {:system}", "-created", -1, 0, dbx.Params{
|
||||||
"system": oldRecord.Get("id")})
|
"system": oldRecord.Get("id")})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println("failed to get users", "err", err.Error())
|
log.Println("failed to get users", "err", err.Error())
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
if len(alerts) == 0 {
|
if len(alerts) == 0 {
|
||||||
@@ -431,8 +433,9 @@ func handleStatusAlerts(newStatus string, oldRecord *models.Record) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func getSSHKey() ([]byte, error) {
|
func getSSHKey() ([]byte, error) {
|
||||||
|
dataDir := app.DataDir()
|
||||||
// check if the key pair already exists
|
// check if the key pair already exists
|
||||||
existingKey, err := os.ReadFile("./pb_data/id_ed25519")
|
existingKey, err := os.ReadFile(dataDir + "/id_ed25519")
|
||||||
if err == nil {
|
if err == nil {
|
||||||
return existingKey, nil
|
return existingKey, nil
|
||||||
}
|
}
|
||||||
@@ -452,7 +455,7 @@ func getSSHKey() ([]byte, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Save the private key to a file
|
// Save the private key to a file
|
||||||
privateFile, err := os.Create("./pb_data/id_ed25519")
|
privateFile, err := os.Create(dataDir + "/id_ed25519")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// app.Logger().Error("Error creating private key file:", "err", err.Error())
|
// app.Logger().Error("Error creating private key file:", "err", err.Error())
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -473,7 +476,7 @@ func getSSHKey() ([]byte, error) {
|
|||||||
pubKeyBytes := ssh.MarshalAuthorizedKey(publicKey)
|
pubKeyBytes := ssh.MarshalAuthorizedKey(publicKey)
|
||||||
|
|
||||||
// Save the public key to a file
|
// Save the public key to a file
|
||||||
publicFile, err := os.Create("./pb_data/id_ed25519.pub")
|
publicFile, err := os.Create(dataDir + "/id_ed25519.pub")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -484,10 +487,10 @@ func getSSHKey() ([]byte, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
app.Logger().Info("ed25519 SSH key pair generated successfully.")
|
app.Logger().Info("ed25519 SSH key pair generated successfully.")
|
||||||
app.Logger().Info("Private key saved to: pb_data/id_ed25519")
|
app.Logger().Info("Private key saved to: " + dataDir + "/id_ed25519")
|
||||||
app.Logger().Info("Public key saved to: pb_data/id_ed25519.pub")
|
app.Logger().Info("Public key saved to: " + dataDir + "/id_ed25519.pub")
|
||||||
|
|
||||||
existingKey, err = os.ReadFile("./pb_data/id_ed25519")
|
existingKey, err = os.ReadFile(dataDir + "/id_ed25519")
|
||||||
if err == nil {
|
if err == nil {
|
||||||
return existingKey, nil
|
return existingKey, nil
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user