|
@@ -8,6 +8,7 @@ import (
|
|
|
"os"
|
|
|
"path"
|
|
|
"path/filepath"
|
|
|
+ "regexp"
|
|
|
"strings"
|
|
|
|
|
|
"github.com/G-Node/git-module"
|
|
@@ -174,6 +175,60 @@ func annexUpload(repoPath, remote string) error {
|
|
|
return nil
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+func isAddressAllowed(email string) bool {
|
|
|
+ fpath := path.Join(setting.CustomPath, "addressfilters")
|
|
|
+ if !com.IsExist(fpath) {
|
|
|
+
|
|
|
+ return true
|
|
|
+ }
|
|
|
+
|
|
|
+ f, err := os.Open(fpath)
|
|
|
+ if err != nil {
|
|
|
+ log.Error(2, "Failed to open file %q: %v", fpath, err)
|
|
|
+
|
|
|
+ return true
|
|
|
+ }
|
|
|
+ defer f.Close()
|
|
|
+
|
|
|
+ emailBytes := []byte(email)
|
|
|
+ scanner := bufio.NewScanner(f)
|
|
|
+ for scanner.Scan() {
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ var allow bool
|
|
|
+ line := scanner.Text()
|
|
|
+ if line[0] == '-' {
|
|
|
+ allow = false
|
|
|
+ } else if line[0] == '+' {
|
|
|
+ allow = true
|
|
|
+ } else {
|
|
|
+ log.Error(2, "Invalid line in addressfilters: %s", line)
|
|
|
+ log.Error(2, "Prefix invalid (must be '-' or '+')")
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ pattern := strings.TrimSpace(line[1:])
|
|
|
+ match, err := regexp.Match(pattern, emailBytes)
|
|
|
+ if err != nil {
|
|
|
+ log.Error(2, "Invalid line in addressfilters: %s", line)
|
|
|
+ log.Error(2, "Invalid pattern: %v", err)
|
|
|
+ }
|
|
|
+ if match {
|
|
|
+ return allow
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ return true
|
|
|
+}
|
|
|
+
|
|
|
func IsBlockedDomain(email string) bool {
|
|
|
fpath := path.Join(setting.CustomPath, "blocklist")
|
|
|
if !com.IsExist(fpath) {
|