Skip to content

Commit

Permalink
Mostly work on banning
Browse files Browse the repository at this point in the history
If a user is banned, they are redirected to the ban page with all the information, but the appeal form doesn't work (yet)
In the next couple commits I'm going to work on actually submitting bans
  • Loading branch information
Joshua Merrell committed Oct 3, 2018
1 parent 0187793 commit ad9d098
Show file tree
Hide file tree
Showing 14 changed files with 210 additions and 314 deletions.
4 changes: 4 additions & 0 deletions html/css/pipes/front.css
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,7 @@ div#recent-posts-header {
box-shadow: 0px 2px 2px 3px #101010;
border-radius: 8px 8px 8px 8px;
margin-bottom: 8px; }

.postblock {
background-color: #202020;
font-weight: 700; }
93 changes: 3 additions & 90 deletions html/javascript/manage.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,89 +9,6 @@ function addStaffButtons() {
$jq("input[value=Delete]").after("<input type=\"submit\" name=\"Ban\" value=\"Ban\" onclick=\"alert('Bans not yet implemented'); return false;\" />")
}

function banPage() {
switch(getArg("type")) {
case "ip":
$jq("div#.ban-type-div#ip").css({"display":"inline"})
$jq("div#.ban-type-div#name").css({"display":"none"})
$jq("input[type=hidden][name=type]").attr("value", "ip")
break;
case "name-tripcode":
$jq("div#.ban-type-div#ip").css({"display":"none"})
$jq("div#.ban-type-div#name").css({"display":"inline"})
$jq("input[type=hidden][name=type]").attr("value", "name/tripcode")
break;
}

$jq("select#ban-type").bind("change", function (e){
var new_selection = this.value;
switch(new_selection) {
case "Single IP/IP range":
$jq("div#ip.ban-type-div").css({"display":"inline"})
$jq("div#name.ban-type-div").css({"display":"none"})
$jq("input[type=hidden][name=type]").attr("value", "ip")
break;
case "Name/tripcode":
$jq("div#ip.ban-type-div").css({"display":"none"})
$jq("div#name.ban-type-div").css({"display":"inline"});
$jq("input[type=hidden][name=type]").attr("value", "name-tripcode")
break;
}
});
$jq("input[type=checkbox]#allboards").bind("change", function() {
var allboards_check = this;
$jq("input[type=checkbox].board-check").each(function() {
this.checked = allboards_check.checked;
});
});
$jq("div.duration-select").html(
"<select class=\"duration-months\">" +
"<option>Months...</option>" +
"</select>" +
"<select class=\"duration-days\">" +
"<option>Days...</option>" +
"</select>" +
"<select class=\"duration-hours\">" +
"<option>Hours...</option>" +
"</select>" +
"<select class=\"duration-minutes\">" +
"<option>Minutes...</option>" +
"</select>"
);
var months_html = "";
var i;
for(i = 0; i < 49; i++) {
months_html += "<option>" + i + "</option>";
}

var days_html = "";
for(i = 0; i < 33; i++) {
days_html += "<option>" + i + "</option>";
}

var hours_html = "";
for(i = 0; i < 25; i++) {
hours_html += "<option>" + i + "</option>";
}

var minutes_html = "";
for(i = 0; i < 61; i++) {
minutes_html += "<option>" + i + "</option>";
}
$jq("select.duration-months").append(months_html);
$jq("select.duration-days").append(days_html);
$jq("select.duration-hours").append(hours_html);
$jq("select.duration-minutes").append(minutes_html);
/*if(watermark) {
$jq("input[type=text][name=ip]").watermark("IP address");
$jq("input[type=text][name=ip]").prev().remove();
$jq($jq("div#reason-staffnote input")[0]).prev().remove();
$jq($jq("div#reason-staffnote input")[0]).watermark("Reason");
$jq($jq("div#reason-staffnote input")[1]).watermark("Staff note");
$jq($jq("div#reason-staffnote input")[1]).prev().remove();
}*/
}

function getManagePage() {

}
Expand Down Expand Up @@ -224,10 +141,6 @@ function openStaffLightBox(action_url) {
});
}

$jq(document).ready(function() {
/*if(location.pathname.indexOf("/manage" == location.pathname.length -7)) {
if(getArg("action") == "banuser") {
banPage();
}
}*/
});
/* $jq(document).ready(function() {
}); */
26 changes: 26 additions & 0 deletions src/durationparse_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package main

import (
"fmt"
"testing"
)

func TestDurationParse(t *testing.T) {
duration, err := parseDurationString("7y6mo5w4d3h2m1s")
if err != nil {
t.Fatal(err.Error())
}
fmt.Println(duration)

duration, err = parseDurationString("7year6month5weeks4days3hours2minutes1second")
if err != nil {
t.Fatal(err.Error())
}
fmt.Println(duration)

duration, err = parseDurationString("7 years 6 months 5 weeks 4 days 3 hours 2 minutes 1 seconds")
if err != nil {
t.Fatal(err.Error())
}
fmt.Println(duration)
}
11 changes: 3 additions & 8 deletions src/gochan.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,19 @@ func main() {
}
}()
initConfig()
config.Version = version
printf(0, "Starting gochan v%s.%s, using verbosity level %d\n", config.Version, buildtimeString, config.Verbosity)
println(0, "Config file loaded. Connecting to database...")
connectToSQLServer()

println(0, "Loading and parsing templates...")
if err := initTemplates(); err != nil {
handleError(0, customError(err))
os.Exit(2)
}

println(0, "Initializing server...")
if db != nil {
_, err := db.Exec("USE `" + config.DBname + "`")
if err != nil {
handleError(0, customError(err))
os.Exit(2)
}
if _, err := db.Exec("USE `" + config.DBname + "`"); err != nil {
handleError(0, customError(err))
os.Exit(2)
}
initServer()
}
121 changes: 13 additions & 108 deletions src/manage.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,7 @@ func callManageFunction(writer http.ResponseWriter, request *http.Request) {
}

if action != "getstaffjquery" {
if err = global_header_tmpl.Execute(&managePageBuffer, config); err != nil {
handleError(0, customError(err))
fmt.Fprintf(writer, mangePageHTML+err.Error()+"\n</body>\n</html>")
return
}

managePageBuffer.WriteString("<!DOCTYPE html>\n<html>\n<head>\n")
if err = manage_header_tmpl.Execute(&managePageBuffer, config); err != nil {
handleError(0, customError(err))
fmt.Fprintf(writer, mangePageHTML+err.Error()+"\n</body>\n</html>")
Expand Down Expand Up @@ -574,118 +569,28 @@ var manage_functions = map[string]ManageFunction{
"bans": {
Permissions: 1,
Callback: func(writer http.ResponseWriter, request *http.Request) (html string) {
var ban_which string // user, image, or both

if request.PostFormValue("ban-user-button") == "Ban user" {
ban_which = "user"
} else if request.PostFormValue("ban-image-button") == "Ban image" {
ban_which = "image"
} else if request.PostFormValue("ban-both-button") == "Ban both" {
ban_which = "both"
}
// if none of these are true, we can assume that the page was loaded without sending anything
println(1, "ban_which"+ban_which)

if ban_which == "user" {
//var banned_tripcode string
banned_ip := request.PostFormValue("ip")
if banned_ip != "" {
println(0, banned_ip)
}
}

boards_list_html := " <span style=\"font-weight: bold;\">Boards: </span><br />\n" +
" <label>All boards <input type=\"checkbox\" id=\"allboards\" /></label> overrides individual board selection<br />\n"

rows, err := querySQL("SELECT `dir` FROM `" + config.DBprefix + "boards`")
rows, err := querySQL("SELECT `ip`,`name`,`tripcode`,`reason`,`boards`,`banned_by`,`timestamp`,`expires` FROM `" + config.DBprefix + "banlist`")
defer closeRows(rows)
if err != nil {
html += "<hr />" + handleError(1, err.Error())
return
}
var board_dir string

var banlist []BanlistTable
for rows.Next() {
if err = rows.Scan(&board_dir); err != nil {
html += "<hr />" + handleError(1, err.Error())
}
boards_list_html += " <label>/" + board_dir + "/ <input type=\"checkbox\" id=\"" + board_dir + "\" class=\"board-check\"/></label>&nbsp;&nbsp;\n"
var ban BanlistTable
rows.Scan(&ban.IP, &ban.Name, &ban.Tripcode, &ban.Reason, &ban.Boards, &ban.BannedBy, &ban.Timestamp, &ban.Expires)
banlist = append(banlist, ban)
}
manageBansBuffer := bytes.NewBufferString("")

html = "<h1>Ban user(s)</h1>\n" +
"<form method=\"POST\" action=\"/manage\">\n" +
"<input type=\"hidden\" name=\"action\" value=\"bans\" />\n" +
"<fieldset><legend>User(s)</legend>" +
" <div id=\"ip\" class=\"ban-type-div\" style=\"width:100%%; display: inline;\">\n" +
" <span style=\"font-weight: bold;\">IP address:</span> <input type=\"text\" name=\"ip\" /><br />\n" +
" \"192.168.1.36\" will ban posts from that IP address<br />\n" +
" \"192.168\" will block all IPs starting with 192.168<br /><hr />\n" +
" </div>\n" +
" <div id=\"name\" class=\"ban-type-div\" style=\"width:100%%;\">\n" +
" <span style=\"font-weight: bold;\">Name/tripcode:</span> <input type=\"text\" name=\"ip\" /><br />\n" +
" (format: \"Poster!tripcode\", \"!tripcode\", or \"Poster\")<br />\n" +
" <hr />\n" +
" </div>\n" +
" <span style=\"font-weight: bold;\">Duration: </span><br />\n" +
" <label>Permanent ban (overrides duration dropdowns if checked)<input type=\"checkbox\" name=\"forever\" value=\"forever\" /></label><br />\n" +
" <div class=\"duration-select\"></div>\n<hr />\n" +
boards_list_html + "<hr />\n" +
" <div id=\"reason-staffnote\" style=\"text-align: right; float:left;\">\n" +
" <span style=\"font-weight: bold;\">Reason: </span><input type=\"text\" name=\"reason\" /><br />\n" +
" <span style=\"font-weight: bold;\">Staff note: </span><input type=\"text\" name=\"staff-note\" /><br />\n" +
" </div>\n<br /><br /><br /><input type=\"submit\" name=\"ban-user-button\" value=\"Ban user\"/>" +
"</fieldset>\n<br />\n<hr />\n" +
"<fieldset><legend>Image</legend>\n" +
" This will disallow an image with this hash from being posted, and will ban users who try to post it for the specified amount of time.<br /><br />\n" +
" <label style=\"font-weight: bold;\">Ban image hash: <input type=\"checkbox\" /></label><br />\n" +
" <span style=\"font-weight: bold;\">Duration: </span><br />\n" +
" <label>Permanent ban (overrides duration dropdowns if checked)<input type=\"checkbox\" name=\"forever\" value=\"forever\" /></label><br />\n" +
" <div class=\"duration-select\"></div>\n" +
" <hr />\n" +
boards_list_html + "<hr />\n" +
" <div id=\"reason-staffnote\" style=\"text-align: right; float:left;\">\n" +
" <span style=\"font-weight: bold;\">Reason: </span><input type=\"text\" name=\"reason\" /><br />\n" +
" <span style=\"font-weight: bold;\">Staff note: </span><input type=\"text\" name=\"staff-note\" /><br />\n" +
" </div>\n<br /><br /><br /><input type=\"submit\" name=\"ban-image-button\" value=\"Ban image\"/>" +
"</fieldset><br />\n" +
"<input type=\"submit\" name=\"ban-both-button\" value=\"Ban both\" /></form>\n</br />" +
"<h2>Banned IPs</h2>\n"

rows, err = querySQL("SELECT * FROM `" + config.DBprefix + "banlist`")
if err != nil {
html += "</table><br />" + handleError(1, err.Error())
if err := manage_bans_tmpl.Execute(manageBansBuffer,
map[string]interface{}{"config": config, "banlist": banlist, "boards": allBoards},
); err != nil {
html += handleError(1, err.Error())
return
}
var ban BanlistTable

num_rows := 0
for rows.Next() {
if num_rows == 0 {
html += "<table width=\"100%%\" border=\"1\">\n" +
"<tr><th>IP</th><th>Name/Tripcode</th><th>Message</th><th>Date added</th><th>Added by</th><th>Reason</th><th>Expires/expired</th><th></th></tr>"
}
err = rows.Scan(&ban.ID, &ban.AllowRead, &ban.IP, &ban.Name, &ban.Tripcode, &ban.Message, &ban.SilentBan, &ban.Boards, &ban.BannedBy, &ban.Timestamp, &ban.Expires, &ban.Reason, &ban.StaffNote, &ban.AppealMessage, &ban.AppealAt)
if err != nil {
html += "</table><br />" + handleError(1, err.Error())
return
}
ban_name := ""
if ban.Name+ban.Tripcode != "" {
ban_name = ban.Name + "!" + ban.Tripcode
}

html += "<tr><td>" + ban.IP + "</td><td>" + ban_name + "</td><td>" + ban.Message + "</td><td>" + humanReadableTime(ban.Timestamp) + "</td><td>" + ban.BannedBy + "</td><td>" + ban.Reason + "</td><td>" + humanReadableTime(ban.Expires) + "</td><td>Delete</td></tr>"
num_rows++
}
if num_rows == 0 {
html += "No banned IPs"
} else {
html += "</table>\n"
}

// html += "<tr><td>127.0.0.1</td><td>Banned message</td><td>12/25/1991</td><td>Luna</td><td>Spam</td><td>never</td><td>Delete</td></tr>" +

html += "<br /><br /><br />" +
"<script type=\"text/javascript\">banPage();</script>\n "
html += manageBansBuffer.String()
return
}},
"getstaffjquery": {
Expand Down
Loading

0 comments on commit ad9d098

Please sign in to comment.