fixes for webdav client
This commit is contained in:
parent
c6e7bc2f67
commit
4a1187c3a9
|
@ -23,10 +23,10 @@ services:
|
||||||
ERRORLOG: "/var/log/modsec_error.log"
|
ERRORLOG: "/var/log/modsec_error.log"
|
||||||
ACCESSLOG: "/var/log/apache2/access.log"
|
ACCESSLOG: "/var/log/apache2/access.log"
|
||||||
MODSEC_AUDIT_LOG_FORMAT: "JSON"
|
MODSEC_AUDIT_LOG_FORMAT: "JSON"
|
||||||
BLOCKING_PARANOIA: 1
|
BLOCKING_PARANOIA: 2
|
||||||
DETECTION_PARANOIA: 1
|
DETECTION_PARANOIA: 2
|
||||||
EXECUTING_PARANOIA: 1
|
EXECUTING_PARANOIA: 2
|
||||||
PARANOIA: 1
|
PARANOIA: 2
|
||||||
network_mode: "host"
|
network_mode: "host"
|
||||||
volumes:
|
volumes:
|
||||||
- "./logs/host-fs-auditlog.log:/var/log/modsec_audit.log"
|
- "./logs/host-fs-auditlog.log:/var/log/modsec_audit.log"
|
||||||
|
|
|
@ -10,13 +10,15 @@ import (
|
||||||
|
|
||||||
// TODO: use values from config file
|
// TODO: use values from config file
|
||||||
var localLogPaths = []string{
|
var localLogPaths = []string{
|
||||||
"/path/to/file1.log",
|
"/home/vomitblood/build/cspj-application/docker/chungus/logs/host-fs-accesslog.log",
|
||||||
"/path/to/file2.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{
|
var remoteFiles = []string{
|
||||||
"/my/remote/folder/file1.log",
|
"host-fs-accesslog.log",
|
||||||
"/my/remote/folder/file2.log",
|
"host-fs-auditlog.log",
|
||||||
|
"host-fs-errorlog.log",
|
||||||
}
|
}
|
||||||
|
|
||||||
func BackupLogs(client *gowebdav.Client) error {
|
func BackupLogs(client *gowebdav.Client) error {
|
||||||
|
@ -31,8 +33,6 @@ func BackupLogs(client *gowebdav.Client) error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("Error uploading file %s: %v", localLogPaths[i], err)
|
log.Printf("Error uploading file %s: %v", localLogPaths[i], err)
|
||||||
return fmt.Errorf("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 {
|
if err != nil {
|
||||||
log.Printf("Error downloading file %s: %v", remoteFiles[i], err)
|
log.Printf("Error downloading file %s: %v", remoteFiles[i], err)
|
||||||
return fmt.Errorf("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])
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -20,7 +20,7 @@ type LogEntry struct {
|
||||||
} `json:"audit_data"`
|
} `json:"audit_data"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func Init(client *gowebdav.Client) *tg.BotAPI {
|
func Init(webdavClient *gowebdav.Client) *tg.BotAPI {
|
||||||
bot, err := tg.NewBotAPI(telegramToken)
|
bot, err := tg.NewBotAPI(telegramToken)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal("Failed to create Telegram bot:", err)
|
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)
|
log.Fatal("Failed to send test message:", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
go handleUpdates(bot, client)
|
go handleUpdates(bot, webdavClient)
|
||||||
|
|
||||||
return bot
|
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" {
|
if command == "/restore_logs" {
|
||||||
err := log_backup.RestoreLogs(webdavClient)
|
err := log_backup.RestoreLogs(webdavClient)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -15,7 +15,7 @@ type WebDAVClient struct {
|
||||||
const (
|
const (
|
||||||
// TODO: use values from config file
|
// TODO: use values from config file
|
||||||
webdavURL = "https://webdav.vomitblood.com"
|
webdavURL = "https://webdav.vomitblood.com"
|
||||||
webdavUser = "Vomitblood"
|
webdavUser = "vomitblood"
|
||||||
webdavPassword = "alpine"
|
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)
|
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 {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to upload file %s: %v", localFilePath, err)
|
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)
|
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 {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to save downloaded file %s: %v", localFilePath, err)
|
return fmt.Errorf("failed to save downloaded file %s: %v", localFilePath, err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,11 +18,11 @@ func main() {
|
||||||
}
|
}
|
||||||
defer db.DbPool.Close()
|
defer db.DbPool.Close()
|
||||||
|
|
||||||
// init webdav client
|
// init webdav webdavClient
|
||||||
client := webdav.Init()
|
webdavClient := webdav.Init()
|
||||||
|
|
||||||
// init telegram bot
|
// init telegram bot
|
||||||
tgBot := telegram.Init(client)
|
tgBot := telegram.Init(webdavClient)
|
||||||
|
|
||||||
// start log watcher
|
// start log watcher
|
||||||
go log_watcher.WatchFile(tgBot)
|
go log_watcher.WatchFile(tgBot)
|
||||||
|
|
Loading…
Reference in a new issue