fixes for webdav client

This commit is contained in:
Vomitblood 2025-02-09 20:07:57 +08:00
parent c6e7bc2f67
commit 4a1187c3a9
5 changed files with 19 additions and 21 deletions

View file

@ -23,10 +23,10 @@ services:
ERRORLOG: "/var/log/modsec_error.log"
ACCESSLOG: "/var/log/apache2/access.log"
MODSEC_AUDIT_LOG_FORMAT: "JSON"
BLOCKING_PARANOIA: 1
DETECTION_PARANOIA: 1
EXECUTING_PARANOIA: 1
PARANOIA: 1
BLOCKING_PARANOIA: 2
DETECTION_PARANOIA: 2
EXECUTING_PARANOIA: 2
PARANOIA: 2
network_mode: "host"
volumes:
- "./logs/host-fs-auditlog.log:/var/log/modsec_audit.log"

View file

@ -10,13 +10,15 @@ import (
// TODO: use values from config file
var localLogPaths = []string{
"/path/to/file1.log",
"/path/to/file2.log",
"/home/vomitblood/build/cspj-application/docker/chungus/logs/host-fs-accesslog.log",
"/home/vomitblood/build/cspj-application/docker/chungus/logs/host-fs-auditlog.log",
"/home/vomitblood/build/cspj-application/docker/chungus/logs/host-fs-errorlog.log",
}
var remoteFiles = []string{
"/my/remote/folder/file1.log",
"/my/remote/folder/file2.log",
"host-fs-accesslog.log",
"host-fs-auditlog.log",
"host-fs-errorlog.log",
}
func BackupLogs(client *gowebdav.Client) error {
@ -31,8 +33,6 @@ func BackupLogs(client *gowebdav.Client) error {
if err != nil {
log.Printf("Error uploading file %s: %v", localLogPaths[i], err)
return fmt.Errorf("error uploading file %s: %v", localLogPaths[i], err)
} else {
log.Printf("Successfully uploaded file: %s", localLogPaths[i])
}
}
@ -51,8 +51,6 @@ func RestoreLogs(client *gowebdav.Client) error {
if err != nil {
log.Printf("Error downloading file %s: %v", remoteFiles[i], err)
return fmt.Errorf("error downloading file %s: %v", remoteFiles[i], err)
} else {
log.Printf("Successfully downloaded file: %s", remoteFiles[i])
}
}

View file

@ -20,7 +20,7 @@ type LogEntry struct {
} `json:"audit_data"`
}
func Init(client *gowebdav.Client) *tg.BotAPI {
func Init(webdavClient *gowebdav.Client) *tg.BotAPI {
bot, err := tg.NewBotAPI(telegramToken)
if err != nil {
log.Fatal("Failed to create Telegram bot:", err)
@ -35,7 +35,7 @@ func Init(client *gowebdav.Client) *tg.BotAPI {
log.Fatal("Failed to send test message:", err)
}
go handleUpdates(bot, client)
go handleUpdates(bot, webdavClient)
return bot
}
@ -60,7 +60,7 @@ func handleUpdates(bot *tg.BotAPI, webdavClient *gowebdav.Client) {
}
}
// Check for /download_logs command to download files from WebDAV
// /restore_logs
if command == "/restore_logs" {
err := log_backup.RestoreLogs(webdavClient)
if err != nil {

View file

@ -15,7 +15,7 @@ type WebDAVClient struct {
const (
// TODO: use values from config file
webdavURL = "https://webdav.vomitblood.com"
webdavUser = "Vomitblood"
webdavUser = "vomitblood"
webdavPassword = "alpine"
)
@ -48,7 +48,7 @@ func UploadFile(client *gowebdav.Client, localFilePath string, remoteFilePath st
return fmt.Errorf("failed to read file %s: %v", localFilePath, err)
}
err = client.Write(remoteFilePath, bytes, 0644)
err = client.Write(remoteFilePath, bytes, 0777)
if err != nil {
return fmt.Errorf("failed to upload file %s: %v", localFilePath, err)
}
@ -63,7 +63,7 @@ func DownloadFile(client *gowebdav.Client, remoteFilePath string, localFilePath
return fmt.Errorf("failed to download file %s: %v", remoteFilePath, err)
}
err = os.WriteFile(localFilePath, bytes, 0644)
err = os.WriteFile(localFilePath, bytes, 0777)
if err != nil {
return fmt.Errorf("failed to save downloaded file %s: %v", localFilePath, err)
}

View file

@ -18,11 +18,11 @@ func main() {
}
defer db.DbPool.Close()
// init webdav client
client := webdav.Init()
// init webdav webdavClient
webdavClient := webdav.Init()
// init telegram bot
tgBot := telegram.Init(client)
tgBot := telegram.Init(webdavClient)
// start log watcher
go log_watcher.WatchFile(tgBot)