Escape user/network/entity characters in log file path

ZNC replaces slashes and backslashes with a dashes.
This commit is contained in:
Simon Ser 2020-08-19 12:22:32 +02:00
parent ee32329a14
commit 9f26422592
No known key found for this signature in database
GPG Key ID: 0FDE7BE0E88F5E48

View File

@ -28,14 +28,15 @@ func newMessageLogger(network *network, entity string) *messageLogger {
} }
} }
var escapeFilename = strings.NewReplacer("/", "-", "\\", "-")
func logPath(network *network, entity string, t time.Time) string { func logPath(network *network, entity string, t time.Time) string {
user := network.user user := network.user
srv := user.srv srv := user.srv
// TODO: handle/forbid network/entity names with illegal path characters
year, month, day := t.Date() year, month, day := t.Date()
filename := fmt.Sprintf("%04d-%02d-%02d.log", year, month, day) filename := fmt.Sprintf("%04d-%02d-%02d.log", year, month, day)
return filepath.Join(srv.LogPath, user.Username, network.GetName(), entity, filename) return filepath.Join(srv.LogPath, escapeFilename.Replace(user.Username), escapeFilename.Replace(network.GetName()), escapeFilename.Replace(entity), filename)
} }
func (ml *messageLogger) Append(msg *irc.Message) error { func (ml *messageLogger) Append(msg *irc.Message) error {