Add clipboard monitoring functionality to the agent. Implement clipboard event logging, including text and image capture, with support for retention policies. Update API to allow file deletion and enhance web interface for file management. Add tests for clipboard operations.
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
package clipmon
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
const hourBucketLayout = "2006-01-02-15"
|
||||
|
||||
var logFilenamePattern = regexp.MustCompile(`^\d{4}-\d{2}-\d{2}-\d{2}\.log$`)
|
||||
|
||||
func HourBucket(t time.Time) string {
|
||||
return t.Local().Format(hourBucketLayout)
|
||||
}
|
||||
|
||||
func LogFilename(bucket string) string {
|
||||
return bucket + ".log"
|
||||
}
|
||||
|
||||
func ValidLogFilename(name string) bool {
|
||||
return logFilenamePattern.MatchString(filepath.Base(name))
|
||||
}
|
||||
|
||||
func formatLine(event Event) string {
|
||||
when := event.Time.UTC().Format("2006-01-02T15:04:05.000Z")
|
||||
switch event.Kind {
|
||||
case "image":
|
||||
return fmt.Sprintf("%s [image] %s\n", when, event.ImagePath)
|
||||
default:
|
||||
text := strings.ReplaceAll(event.Text, "\r\n", "\n")
|
||||
text = strings.ReplaceAll(text, "\r", "\n")
|
||||
return fmt.Sprintf("%s [text]\n%s\n", when, text)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user