aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cacheDatabase.go6
-rw-r--r--client.go6
-rw-r--r--database.go51
-rw-r--r--databaseschema.psql4
-rw-r--r--main.go80
-rw-r--r--static/admin.html77
-rw-r--r--static/faq.html2
-rw-r--r--static/nadmin.html53
8 files changed, 176 insertions, 103 deletions
diff --git a/cacheDatabase.go b/cacheDatabase.go
index 7ab3b9e..deaed2e 100644
--- a/cacheDatabase.go
+++ b/cacheDatabase.go
@@ -5,6 +5,12 @@ import "database/sql"
import _ "github.com/lib/pq"
func WriteObjectToCache(db *sql.DB, obj ObjectBase) ObjectBase {
+
+ if(IsPostBlacklist(db, obj.Content)){
+ fmt.Println("\n\nBlacklist post blocked\n\n")
+ return obj
+ }
+
if len(obj.Attachment) > 0 {
if obj.Preview.Href != "" {
WritePreviewToCache(db, *obj.Preview)
diff --git a/client.go b/client.go
index de0168f..a46f2a1 100644
--- a/client.go
+++ b/client.go
@@ -63,6 +63,7 @@ type AdminPage struct {
Reported []Report
Domain string
IsLocal bool
+ PostBlacklist []PostBlacklist
}
type Report struct {
@@ -84,6 +85,11 @@ type NewsItem struct {
Time int
}
+type PostBlacklist struct {
+ Id int
+ Regex string
+}
+
func IndexGet(w http.ResponseWriter, r *http.Request, db *sql.DB) {
t := template.Must(template.New("").Funcs(template.FuncMap{
"mod": func(i, j int) bool { return i%j == 0 },
diff --git a/database.go b/database.go
index 5668a4d..0e53142 100644
--- a/database.go
+++ b/database.go
@@ -1598,3 +1598,54 @@ func WriteNewsToDB(db *sql.DB, news NewsItem) {
CheckError(err, "error writing news item")
}
+
+func WriteRegexBlacklistDB(db *sql.DB, regex string) {
+ query := `select from postblacklist where regex=$1`
+
+ rows, err := db.Query(query, regex)
+
+ CheckError(err, "error select from postblacklist db")
+
+ var re string
+ defer rows.Close()
+ rows.Next()
+ rows.Scan(&re)
+
+ if re != "" {
+ return
+ }
+
+ query = `insert into postblacklist (regex) values ($1)`
+
+ _, err = db.Exec(query, regex)
+
+ CheckError(err, "error inserting postblacklist into db")
+}
+
+func GetRegexBlacklistDB(db *sql.DB) []PostBlacklist {
+ query := `select id, regex from postblacklist`
+
+ rows, err := db.Query(query)
+
+ CheckError(err, "error with select all from postblacklist db")
+
+ var List []PostBlacklist
+
+ defer rows.Close()
+ for rows.Next() {
+ var temp PostBlacklist
+ rows.Scan(&temp.Id, &temp.Regex)
+
+ List = append(List, temp)
+ }
+
+ return List
+}
+
+func DeleteRegexBlacklistDB(db *sql.DB, id int) {
+ query := `delete from postblacklist where id=$1`
+
+ _, err := db.Exec(query, id)
+
+ CheckError(err, "error with delete from postblacklist")
+}
diff --git a/databaseschema.psql b/databaseschema.psql
index 02c229b..8c0c0d4 100644
--- a/databaseschema.psql
+++ b/databaseschema.psql
@@ -227,3 +227,7 @@ ALTER TABLE actor ADD COLUMN IF NOT EXISTS publicKeyPem varchar(100) default '';
ALTER TABLE activitystream ADD COLUMN IF NOT EXISTS sensitive boolean default false;
ALTER TABLE cacheactivitystream ADD COLUMN IF NOT EXISTS sensitive boolean default false;
+CREATE TABLE IF NOT EXISTS postblacklist(
+id serial primary key,
+regex varchar(200)
+); \ No newline at end of file
diff --git a/main.go b/main.go
index b520aa7..d606674 100644
--- a/main.go
+++ b/main.go
@@ -322,6 +322,12 @@ func main() {
file, header, _ := r.FormFile("file")
+ if(IsPostBlacklist(db, r.FormValue("comment"))){
+ fmt.Println("\n\nBlacklist post blocked\n\n")
+ http.Redirect(w, r, Domain + "/", http.StatusMovedPermanently)
+ return
+ }
+
if(file != nil && header.Size > (7 << 20)){
w.Write([]byte("7MB max file size"))
return
@@ -559,7 +565,9 @@ func main() {
adminData.Board.TP = TP
adminData.Board.Post.Actor = actor.Id
-
+
+
+
t.ExecuteTemplate(w, "layout", adminData)
} else if admin || actor.Id == Domain {
@@ -591,7 +599,9 @@ func main() {
adminData.Boards = Boards
- adminData.Board.Post.Actor = actor.Id
+ adminData.Board.Post.Actor = actor.Id
+
+ adminData.PostBlacklist = GetRegexBlacklistDB(db)
t.ExecuteTemplate(w, "layout", adminData)
}
@@ -1203,14 +1213,56 @@ func main() {
if Domain != "https://fchan.xyz" {
return
}
-
-
go AddInstanceToIndexDB(db, actor)
})
+ http.HandleFunc("/blacklist", func(w http.ResponseWriter, r *http.Request) {
+
+ id, _ := GetPasswordFromSession(r)
+
+ actor := GetActorFromDB(db, Domain)
+
+ if id == "" || (id != actor.Id && id != Domain) {
+ http.Redirect(w, r, "/", http.StatusSeeOther)
+ return
+ }
+
+ if r.Method == "GET" {
+ id := r.URL.Query().Get("remove")
+
+ if id != "" {
+ i, _ := strconv.Atoi(id)
+ DeleteRegexBlacklistDB(db, i)
+ }
+
+ } else {
+ regex := r.FormValue("regex")
+ testCase := r.FormValue("testCase")
+
+ if regex == "" {
+ http.Redirect(w, r, "/", http.StatusSeeOther)
+ return
+ }
+
+ r.ParseForm()
+
+ re := regexp.MustCompile(regex)
+
+ if testCase == "" {
+ WriteRegexBlacklistDB(db, regex)
+ } else if re.MatchString(testCase) {
+ WriteRegexBlacklistDB(db, regex)
+ }
+ }
+
+ http.Redirect(w, r, "/" + *Key + "#regex", http.StatusSeeOther)
+ })
+
http.HandleFunc("/api/media", func(w http.ResponseWriter, r *http.Request) {
- RouteImages(w, r.URL.Query().Get("hash"))
+ if r.URL.Query().Get("hash") != "" {
+ RouteImages(w, r.URL.Query().Get("hash"))
+ }
})
fmt.Println("Server for " + Domain + " running on port " + Port)
@@ -2590,8 +2642,8 @@ func RouteImages(w http.ResponseWriter, media string) {
resp, err := http.DefaultClient.Do(req)
- CheckError(err, "error with Route Images resp")
-
+ CheckError(err, "error with Route Images resp")
+
defer resp.Body.Close()
body, _ := ioutil.ReadAll(resp.Body)
@@ -2603,3 +2655,17 @@ func RouteImages(w http.ResponseWriter, media string) {
w.Write(body)
}
+
+func IsPostBlacklist(db *sql.DB, comment string) bool {
+ postblacklist := GetRegexBlacklistDB(db)
+
+ for _, e := range postblacklist {
+ re := regexp.MustCompile(e.Regex)
+
+ if re.MatchString(comment) {
+ return true
+ }
+ }
+
+ return false
+}
diff --git a/static/admin.html b/static/admin.html
deleted file mode 100644
index f238ec0..0000000
--- a/static/admin.html
+++ /dev/null
@@ -1,77 +0,0 @@
-<!DOCTYPE html>
-<html>
- <head>
- <title></title>
- </head>
- <body>
- <div style="margin: 0 auto; width: 400px;">
- <h3>Add Board</h3>
- <form id="new-board" action="/{{ .Key }}/addboard" method="post" enctype="application/x-www-form-urlencoded">
- <label>Name:</label><br>
- <input type="text" name="name" placeholder="g" required><br>
- <label>Prefered Name:</label><br>
- <input type="text" name="prefname" placeholder="Technology" required><input type="submit" value="Add"><br>
- <label>Summary:</label><br>
- <textarea name="summary" rows="8" cols="50"></textarea><br>
- <label>Restricted:</label><br>
- <select name="restricted">
- <option value="True">True</option>
- <option value="False">False</option>
- </select>
- </form>
-
- <ul style="display: inline-block; padding: 0;">
- <li style="display: inline-block;"><a href="javascript:show('following')">Subscribed</a></li>
- <!-- <li style="display: inline-block;"><a href="javascript:show('followers')">Followers</a></li> -->
- <li style="display: inline-block;"><a href="javascript:show('reported')">Reported</a></li>
- </ul>
-
- </div>
-
- <div id="following">
- <h4>Following</h4>
- <form id="follow-form" action="/{{ .Key }}/follow" method="post" enctype="application/x-www-form-urlencoded">
- <label>Subscribe:</label><br>
- <input id="follow" name="follow" style="margin-bottom: 12px;" placeholder="http://localhost:3000/g"></input><input type="submit" value="Subscribe"><br>
- <input type="hidden" name="actor" value="{{ .Actor.Id }}">
- </form>
- <ul style="display: inline-block; padding: 0; margin: 0;">
- {{ $actor := .Actor.Id }}
- {{ $key := .Key }}
- {{ range .Following }}
- <li><a href="/{{ $key }}/follow?follow={{ . }}&actor={{ $actor }}">[Unfollow]</a><a href="{{ . }}">{{ . }}</a></li>
- {{ end }}
- </ul>
- </div>
-
- <div id="followers" style="display: none;">
- <h4>Followers</h4>
- <ul style="display: inline-block; padding: 0; margin: 0;">
- {{ range .Followers }}
- <li><a href="http://localhost:3000/g">{{ . }}</a></li>
- {{ end }}
- </ul>
- </div>
-
- <div id="reported" style="display: none;">
- <h4>Reported</h4>
- <ul style="display: inline-block; padding: 0; margin: 0;">
- </ul>
- </div>
- </body>
-</html>
-
-<script>
- function show(element)
- {
- var following = document.getElementById("following");
- // var followers = document.getElementById("followers");
- var reported = document.getElementById("reported");
-
- following.style.display = "none";
- // followers.style.display = "none";
- reported.style.display = "none";
-
- document.getElementById(element).style.display = "block";
- }
-</script>
diff --git a/static/faq.html b/static/faq.html
index 7405982..5d70e8e 100644
--- a/static/faq.html
+++ b/static/faq.html
@@ -56,7 +56,7 @@
<p>Soon&trade;.</p>
<h4 id="version">What version is this FChannel instance?</h4>
- <p>v0.0.8-dev</p>
+ <p>v0.0.9-dev</p>
</div>
<div style="width: 500px; margin:0 auto; margin-top: 50px; text-align: center;">
<a href="/">[Home]</a><a href="/static/rules.html">[Rules]</a><a href="/static/faq.html">[FAQ]</a>
diff --git a/static/nadmin.html b/static/nadmin.html
index 88b92c9..5e38151 100644
--- a/static/nadmin.html
+++ b/static/nadmin.html
@@ -11,30 +11,20 @@
<input type="text" name="prefname" placeholder="Technology" required><input type="submit" value="Add"><br>
<label>Summary:</label><br>
<textarea name="summary" rows="8" cols="50"></textarea><br>
- <label>Restricted:</label><br>
+ <label>Restricted (i.e SFW):</label><br>
<select name="restricted">
<option value="True">True</option>
<option value="False">False</option>
</select>
</form>
<ul style="display: inline-block; padding: 0;">
- <li style="display: inline-block;"><a href="#following">Subscribed</a></li>
+ <li style="display: inline-block;"><a href="#news">[Create News]</a></li>
+ <li style="display: inline-block;"><a href="#regex">[Post Blacklist]</a></li>
<!-- <li style="display: inline-block;"><a href="javascript:show('followers')">Followers</a></li> -->
- <li style="display: inline-block;"><a href="#reported">Reported</a></li>
+ <!-- <li style="display: inline-block;"><a href="#reported">Reported</a></li> -->
</ul>
</div>
-<div class="popup-box" style="margin-bottom: 25px; padding: 12px;">
- <h3>Post News</h3>
- <form id="news" action="/{{ .Key }}/postnews" method="post" enctype="application/x-www-form-urlencoded">
- <label>Title:</label><br>
- <input type="text" name="title" placeholder="New Board" required><input type="submit" value="Post"><br>
- <label>Content:</label><br>
- <textarea name="summary" rows="8" cols="50"></textarea><br>
- </form>
-</div>
-
-
<div id="following" class="popup-box" style="margin-bottom: 25px; padding: 12px;">
<h4 style="margin: 0; margin-bottom: 5px;">Subscribed</h4>
@@ -60,11 +50,38 @@
</ul>
</div>
-<div id="reported" class="popup-box" style="margin-bottom: 25px; padding: 12px;">
- <h4 style="margin: 0; margin-bottom: 5px;">Reported</h4>
- <ul style="display: inline-block; padding: 0; margin: 0; list-style-type: none;">
- </ul>
+<div class="popup-box" style="margin-bottom: 25px; padding: 12px;">
+ <h3>Create News</h3>
+ <form id="news" action="/{{ .Key }}/postnews" method="post" enctype="application/x-www-form-urlencoded">
+ <label>Title:</label><br>
+ <input type="text" name="title" placeholder="New Board" required><input type="submit" value="Post"><br>
+ <label>Content:</label><br>
+ <textarea name="summary" rows="8" cols="50"></textarea><br>
+ </form>
</div>
+
+<div id="regex" class="popup-box" style="margin-bottom: 25px; padding: 12px;">
+ <h3>Regex Post Blacklist</h3>
+ <form id="blacklist" action="/blacklist" method="post" enctype="application/x-www-form-urlencoded">
+ <label>Regex:</label><br>
+ <input type="text" name="regex" placeholder="(?i)(?s)(.+)?stuff?(.+)to(.+)?block(.+)?https?://(.+)?" size="38" required><input style="margin-left: 5px;" type="submit" value="Post"><br>
+ <label>Test Case:</label><br>
+ <textarea name="testCase" rows="8" cols="50" placeholder="enter a test case to block, if it passes the regex will be added to the blacklist.&#10;&#10;(?i) for case insesitive &#10;(?s) to span multiple lines"></textarea><br>
+ </form>
+ {{ if .PostBlacklist }}
+ <ul style="display: inline-block; padding: 0; margin: 0; margin-top: 25px; list-style-type: none;">
+ {{ range .PostBlacklist }}
+ <li>{{ .Regex }} <a href="/blacklist?remove={{ .Id }}">[remove]</a></li>
+ {{ end }}
+ </ul>
+ {{ end }}
+</div>
+
+<!-- <div id="reported" class="popup-box" style="margin-bottom: 25px; padding: 12px;"> -->
+<!-- <h4 style="margin: 0; margin-bottom: 5px;">Reported</h4> -->
+<!-- <ul style="display: inline-block; padding: 0; margin: 0; list-style-type: none;"> -->
+<!-- </ul> -->
+<!-- </div> -->
{{ end }}
{{ define "bottom" }}{{ end }}