This adds a BLACKLIST_TERMS configuration value that contains a comma-separated list of terms that indicate spam posts and will prevent a link from being showcased on the Browse page, tweeted out, etc.pull/4/head
@@ -55,6 +55,7 @@ DB_USER=dbuser DB_PASSWORD=pass DB_DB=htmlhouse PRIVATE_KEY=keys/dev PUBLIC_KEY= | |||||
| `PREVIEWS_HOST` | Fully-qualified URL (without trailing slash) of screenshot server | None. | | | `PREVIEWS_HOST` | Fully-qualified URL (without trailing slash) of screenshot server | None. | | ||||
| `ADMIN_PASS` | Password to perform admin functions via API | `uhoh` | | | `ADMIN_PASS` | Password to perform admin functions via API | `uhoh` | | ||||
| `BROWSE_ITEMS` | Number of items to show on Browse page | 10 | | | `BROWSE_ITEMS` | Number of items to show on Browse page | 10 | | ||||
| `BLACKLIST_TERMS` | Comma-separated list of terms to prevent a post from being made public | None. | | |||||
| `TWITTER_KEY` | Twitter consumer key | `notreal` | | | `TWITTER_KEY` | Twitter consumer key | `notreal` | | ||||
| `TWITTER_SECRET` | Twitter consumer secret | `notreal` | | | `TWITTER_SECRET` | Twitter consumer secret | `notreal` | | ||||
| `TWITTER_TOKEN` | Twitter access token of the posting Twitter account | `notreal` | | | `TWITTER_TOKEN` | Twitter access token of the posting Twitter account | `notreal` | | ||||
@@ -2,6 +2,8 @@ package htmlhouse | |||||
import ( | import ( | ||||
"github.com/danryan/env" | "github.com/danryan/env" | ||||
"regexp" | |||||
"strings" | |||||
) | ) | ||||
type config struct { | type config struct { | ||||
@@ -23,6 +25,9 @@ type config struct { | |||||
AdminPass string `env:"key=ADMIN_PASS default=uhoh"` | AdminPass string `env:"key=ADMIN_PASS default=uhoh"` | ||||
BrowseItems int `env:"key=BROWSE_ITEMS default=10"` | BrowseItems int `env:"key=BROWSE_ITEMS default=10"` | ||||
BlacklistTerms string `env:"key=BLACKLIST_TERMS"` | |||||
BlacklistReg *regexp.Regexp | |||||
// Twitter configuration | // Twitter configuration | ||||
TwitterConsumerKey string `env:"key=TWITTER_KEY default=notreal"` | TwitterConsumerKey string `env:"key=TWITTER_KEY default=notreal"` | ||||
TwitterConsumerSecret string `env:"key=TWITTER_SECRET default=notreal"` | TwitterConsumerSecret string `env:"key=TWITTER_SECRET default=notreal"` | ||||
@@ -36,5 +41,11 @@ func newConfig() (*config, error) { | |||||
return cfg, err | return cfg, err | ||||
} | } | ||||
// Process anything | |||||
termsReg := `(?i)\b` + cfg.BlacklistTerms + `\b` | |||||
termsReg = strings.Replace(termsReg, ",", `\b|\b`, -1) | |||||
cfg.BlacklistReg = regexp.MustCompile(termsReg) | |||||
// Return result | |||||
return cfg, nil | return cfg, nil | ||||
} | } |
@@ -39,7 +39,7 @@ func createHouse(app *app, w http.ResponseWriter, r *http.Request) error { | |||||
resUser := newSessionInfo(houseID) | resUser := newSessionInfo(houseID) | ||||
if public { | |||||
if public && passesPublicFilter(app, html) { | |||||
go addPublicAccess(app, houseID, html) | go addPublicAccess(app, houseID, html) | ||||
} | } | ||||
@@ -0,0 +1,6 @@ | |||||
package htmlhouse | |||||
func passesPublicFilter(app *app, html string) bool { | |||||
spam := app.cfg.BlacklistReg.MatchString(html) | |||||
return !spam | |||||
} |