Skip to content

Commit

Permalink
Add MediaDownloadBlacklist option. Closes #442
Browse files Browse the repository at this point in the history
  • Loading branch information
42wim committed Jun 9, 2018
1 parent 51327a4 commit bd9ea7a
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
3 changes: 2 additions & 1 deletion bridge/config/config.go
Expand Up @@ -74,10 +74,11 @@ type Protocol struct {
Jid string // xmpp
Label string // all protocols
Login string // mattermost, matrix
MediaDownloadBlackList []string
MediaDownloadPath string // Basically MediaServerUpload, but instead of uploading it, just write it to a file on the same server.
MediaDownloadSize int // all protocols
MediaServerDownload string
MediaServerUpload string
MediaDownloadPath string // Basically MediaServerUpload, but instead of uploading it, just write it to a file on the same server.
MessageDelay int // IRC, time in millisecond to wait between messages
MessageFormat string // telegram
MessageLength int // IRC, max length of a message allowed
Expand Down
14 changes: 14 additions & 0 deletions bridge/helper/helper.go
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"io"
"net/http"
"regexp"
"strings"
"time"

Expand Down Expand Up @@ -73,6 +74,19 @@ func GetAvatar(av map[string]string, userid string, general *config.Protocol) st
}

func HandleDownloadSize(flog *log.Entry, msg *config.Message, name string, size int64, general *config.Protocol) error {
// check blacklist here
for _, entry := range general.MediaDownloadBlackList {
if entry != "" {
re, err := regexp.Compile(entry)
if err != nil {
flog.Errorf("incorrect regexp %s for %s", entry, msg.Account)
continue
}
if re.MatchString(name) {
return fmt.Errorf("Matching blacklist %s. Not downloading %s", entry, name)
}
}
}
flog.Debugf("Trying to download %#v with size %#v", name, size)
if int(size) > general.MediaDownloadSize {
msg.Event = config.EVENT_FILE_FAILURE_SIZE
Expand Down
8 changes: 7 additions & 1 deletion matterbridge.toml.sample
Expand Up @@ -1331,9 +1331,15 @@ MediaServerDownload="https://youserver.com/download"
#It will only download from bridges that don't have public links available, which are for the moment
#slack, telegram, matrix and mattermost
#
#Optional (default 1000000 (1 megabyte))
#OPTIONAL (default 1000000 (1 megabyte))
MediaDownloadSize=1000000

#MediaDownloadBlacklist allows you to blacklist specific files from being downloaded.
#Filenames matching these regexp will not be download/uploaded to the mediaserver
#You can use regex for this, see https://regex-golang.appspot.com/assets/html/index.html for more regex info
#OPTIONAL (default empty)
MediaDownloadBlacklist=[".html$",".htm$"]

###################################################################
#Gateway configuration
###################################################################
Expand Down

0 comments on commit bd9ea7a

Please sign in to comment.