1
0
Fork 0
mirror of https://github.com/Eggbertx/gochan.git synced 2025-08-18 07:36:24 -07:00

show ban page when a banned user tries to post

This commit is contained in:
Joshua Merrell 2014-04-04 12:48:32 -07:00
parent 4c0aaa8ab7
commit f99b61fd37
4 changed files with 143 additions and 363 deletions

View file

@ -1,335 +0,0 @@
#verytopbar {
-moz-box-shadow: 3px 3px 5px 6px #101010;
-webkit-box-shadow: 3px 3px 5px 6px #101010;
background-color: #202020;
box-shadow: 0 3px 5px 6px #101010;
height: 30px;
width: 100%;
}
.admin {
border-bottom: dotted 2px;
border-top: dotted 2px;
color: #d700f7;
font-weight: 400;
}
.adminbar {
background: inherit;
clear: both;
float: right;
text-align: right;
}
.adminbar,.navbar {
margin-top: 4px;
}
.commentpostername {
background: inherit;
color: #117743;
font-family: serif;
font-size: 12px;
font-weight: 800;
}
.delbuttons {
background: inherit;
padding-bottom: 4px;
text-align: center;
}
.dellist {
background: inherit;
text-align: center;
}
.doubledash {
clear: both;
float: left;
vertical-align: top;
}
.expandthread {
background: transparent url(/css/images/pipes/s_icons.gif) 0 -16px no-repeat;
}
.filesize {
font-family: sans-serif;
font-size: 12px;
padding-left: 0;
text-decoration: none;
}
.filesize a,.filesize a:visited {
text-decoration: none;
}
.filetitle {
background: inherit;
color: #d48e2a;
font-family: serif;
font-size: 18px;
font-weight: 800;
}
.footer {
font-family: sans-serif;
font-size: 10px;
text-align: center;
}
.hidethread {
background: transparent url(/css/images/pipes/s_icons.gif) -32px -16px no-repeat;
}
.hidewatchedthreads {
background: transparent url(/css/images/pipes/s_icons.gif) -48px -16px no-repeat;
}
.highlight {
background: #25272d;
background-attachment: fixed;
background-image: url(/css/images/pipes/pipes_bg3.png);
border: dotted 1px #ffd43f;
}
.logo {
background: inherit;
clear: both;
color: #e1b400;
font-family: sans-serif;
font-size: 34pt;
text-align: center;
width: 100%;
}
.managehead {
background: #0F8FE1;
color: #000;
font-family: sans-serif;
font-size: 14px;
padding: 0;
}
.mod {
border-bottom: dotted 2px;
border-top: dotted 2px;
color: #ced540;
font-weight: 400;
}
.oldpost {
background: inherit;
color: #ca2600;
font-family: serif;
font-size: 18px;
font-weight: 800;
}
.omittedposts {
background: inherit;
color: #fff;
font-family: serif;
font-size: 14px;
}
.passvalid {
background: #98E;
color: #fff;
text-align: center;
width: 100%;
}
.postarea {
background: inherit;
}
.postarea input[type=submit],.postarea button,input {
background-color: #30333b;
border: 1px solid #777e91;
color: #d8d0b9;
}
.postarea input[type=submit]:focus,.postarea button:focus,input:focus {
border: 1px solid #ffd43f;
}
.postarea input[type=text],.postarea input[type=password],.postarea textarea {
background: #30333b;
border: 1px solid #777e91;
color: #d8d0b9;
margin: 0;
}
.postarea input[type=text]:focus,.postarea input[type=password]:focus,.postarea textarea:focus {
border-color: #ffd43f;
border-width: 1px;
margin: 0;
}
.postblock {
background: #1a1c20;
border: solid 1px #585d6b;
color: #a6a08e;
font-weight: 800;
}
.postername {
background: inherit;
color: #fc0;
font-family: serif;
font-size: 15px;
font-weight: 800;
}
.postername a {
border-bottom: 1px dashed #fc0;
color: #fc0;
font-family: serif;
}
.postertrip {
color: #ebbc00;
}
.postlists {
background: #FFF;
color: #000;
padding: 0;
width: 100%;
}
.quickreply {
background: transparent url(/css/images/pipes/s_icons.gif) 0 0 no-repeat;
}
.reflink a:hover {
color: #ffd43f;
}
.reflinkpreview {
background: #25272d;
background-attachment: fixed;
background-image: url(/css/images/pipes/pipes_bg3.png);
border: solid 1px #585d6b;
}
.refreshwatchedthreads {
background: transparent url(/css/images/pipes/s_icons.gif) -16px -16px no-repeat;
}
.reply {
background: #25272d;
background-attachment: fixed;
background-image: url(/css/images/pipes/pipes_bg3.png);
border: solid 1px #8c94ab;
font-family: serif;
}
.reply .filesize {
margin-left: 0;
padding-left: 0;
}
.replyhl {
background: #D6BAD0;
color: #000;
}
.replymode,.catalogmode {
background: #4a4f5a;
color: #FFF;
text-align: center;
width: 100%;
}
.replytitle {
background: inherit;
color: #0F0C5D;
font-family: serif;
font-size: 18px;
font-weight: 800;
}
.restorewatchedthreads {
background: transparent url(/css/images/pipes/s_icons.gif) -16px 0 no-repeat;
}
.row1 {
background: #9AD2F6;
color: #000;
font-family: sans-serif;
font-size: 12px;
}
.row2 {
background: #FFF;
color: #000;
font-family: sans-serif;
font-size: 12px;
}
.rules {
font-family: sans-serif;
font-size: 10px;
width: 468px;
}
.rules li {
margin-left: 1em;
}
.thumbnailmsg {
background: inherit;
color: #000;
font-family: sans-serif;
font-size: 9px;
}
.unhidethread {
background: transparent url(/css/images/pipes/s_icons.gif) -48px 0 no-repeat;
}
.unkfunc {
color: #b6a046;
}
.userdelete {
background-image: url(/css/images/pipes/pipes_bg2.png);
border: solid 1px #585d6b;
text-align: center;
white-space: nowrap;
}
.watchedthreads {
background-color: #D6DAF0!important;
background-image: url(/css/images/pipes/pipes_bg2.png);
border: 1px solid #D6DAF0!important;
border-top: 0 none!important;
}
.watchthread {
background: transparent url(/css/images/pipes/s_icons.gif) -32px 0 no-repeat;
}
a {
background: inherit;
color: #f90;
font-family: sans-serif;
text-decoration: none;
}
a:hover {
background: inherit;
color: #ffd43f;
font-family: sans-serif;
}
html,body {
background: #32353d;
background-attachment: fixed;
background-image: url(/css/images/pipes/pipes_bg.png);
color: #d8d0b9;
font-size: 12pt;
}

View file

@ -3,6 +3,7 @@
package main
import (
"bytes"
"database/sql"
"fmt"
"github.com/disintegration/imaging"
@ -228,28 +229,53 @@ func buildThread(op_id int, board_id int) (err error) {
}
// checks to see if the poster's tripcode/name is banned, if the IP is banned, or if the file checksum is banned
func checkBannedStatus(post *PostTable) (bool, error) {
/*var ip string
var name string
var tripcode string
var boards string
var expires string
var count int
var search
// returns true if the user is banned
func checkBannedStatus(post *PostTable, writer *http.ResponseWriter) ([]interface{}, error) {
fmt.Println(post.IP)
var is_expired bool
var ban_entry BanlistTable
// var count int
// var search string
err := db.QueryRow("SELECT `ip`, `name`, `tripcode`, `message`, `boards`, `timestamp`, `expires`, `appeal_at` FROM `" + config.DBprefix + "banlist` WHERE `ip` = '" + post.IP + "'").Scan(&ban_entry.IP,&ban_entry.Name,&ban_entry.Tripcode, &ban_entry.Message, &ban_entry.Boards, &ban_entry.Timestamp, &ban_entry.Expires, &ban_entry.AppealAt)
var interfaces []interface{}
err := db.QueryRow("SELECT `ip`, `name`, `tripcode`, `boards`, `expires` FROM `" + config.DBprefix + "banlist`").Scan(&ip,&name,&tripcode, &boards, &expires)
if err != nil {
if err == sql.ErrNoRows {
count = 0
} else {
error_log.Print(err.Error())
exitWithErrorPage(w, err.Error())
return
}
}*/
return false, nil
fmt.Println("not in the list")
// the user isn't banned
// We don't need to return err because it isn't necessary
return interfaces, nil
} else {
// something went wrong
fmt.Println("something's wrong")
return interfaces,err
}
} else {
is_expired = ban_entry.Expires.After(time.Now()) == false
if is_expired {
// if it is expired, send a message saying that it's expired, but still post
fmt.Println("expired")
return interfaces,nil
}
// the user's IP is in the banlist. Check if the ban has expired
if getSpecificSQLDateTime(ban_entry.Expires) == "0001-01-01 00:00:00" || ban_entry.Expires.After(time.Now()) {
// for some funky reason, Go's MySQL driver seems to not like getting a supposedly nil timestamp as an ACTUAL nil timestamp
// so we're just going to wing it and cheat. Of course if they change that, we're kind of hosed.
var interfaces []interface{}
interfaces = append(interfaces, config)
interfaces = append(interfaces, ban_entry)
return interfaces,nil
}
return interfaces,nil
}
return interfaces, nil
}
func createThumbnail(image_obj image.Image, size string) image.Image {
@ -462,7 +488,7 @@ func makePost(w http.ResponseWriter, r *http.Request) {
http.SetCookie(writer, &http.Cookie{Name: "password", Value: request.FormValue("postpassword"), Path: "/", Domain: config.SiteDomain, RawExpires: getSpecificSQLDateTime(time.Now().Add(time.Duration(31536000))),MaxAge: 31536000})
//http.SetCookie(writer, &http.Cookie{Name: "password", Value: request.FormValue("postpassword"), Path: "/", Domain: config.Domain, RawExpires: getSpecificSQLDateTime(time.Now().Add(time.Duration(31536000))),MaxAge: 31536000})
post.IP = request.RemoteAddr
post.IP = request.RemoteAddr[:strings.Index(request.RemoteAddr,":")]
post.Timestamp = time.Now()
post.PosterAuthority = getStaffRank()
post.Bumped = time.Now()
@ -584,15 +610,30 @@ func makePost(w http.ResponseWriter, r *http.Request) {
return
}
isbanned, err := checkBannedStatus(&post)
isbanned, err := checkBannedStatus(&post, &w)
if err != nil {
exitWithErrorPage(w, err.Error())
return
}
if isbanned {
if len(isbanned) > 0 {
post.IP = request.RemoteAddr
exitWithErrorPage(w, "ur banned")
wrapped := &Wrapper{IName: "bans",Data: isbanned}
var banpage_buffer bytes.Buffer
var banpage_html string
banpage_buffer.Write([]byte(""))
err = banpage_tmpl.Execute(&banpage_buffer,wrapped)
if err != nil {
fmt.Println(banpage_html)
fmt.Fprintf(writer,banpage_html + err.Error() + "\n</body>\n</html>")
return
}
fmt.Fprintf(w,banpage_buffer.String())
return
}

View file

@ -62,6 +62,12 @@ var funcMap = template.FuncMap{
return style != config.DefaultStyle_img
},
"getInterface":func(in []interface{}, index int) interface{} {
var nope interface{}
if len(in) == 0 {
return nope
} else if len(in) < index + 1 {
return nope
}
return in[index]
},
"formatTimestamp": func(timestamp time.Time) string {
@ -109,6 +115,10 @@ var funcMap = template.FuncMap{
var (
footer_data = FooterData{version, float32(0)}
banpage_tmpl_str string
banpage_tmpl *template.Template
global_footer_tmpl_str string
global_footer_tmpl *template.Template
@ -132,6 +142,18 @@ var (
)
func initTemplates() {
banpage_tmpl_bytes,tmpl_err := ioutil.ReadFile(config.TemplateDir+"/banpage.html")
if tmpl_err != nil {
fmt.Println("Failed loading template \""+config.TemplateDir+"/banpage.html\": " + tmpl_err.Error())
os.Exit(2)
}
banpage_tmpl_str = "{{$config := getInterface .Data 0}}{{$ban := getInterface .Data 1}}" + string(banpage_tmpl_bytes)
banpage_tmpl,tmpl_err = template.New("banpage_tmpl").Funcs(funcMap).Parse(string(banpage_tmpl_str))
if tmpl_err != nil {
fmt.Println("Failed loading template \""+config.TemplateDir+"/banpage.html\": " + tmpl_err.Error())
os.Exit(2)
}
global_footer_tmpl_bytes,tmpl_err := ioutil.ReadFile(config.TemplateDir+"/global_footer.html")
if tmpl_err != nil {
fmt.Println("Failed loading template \""+config.TemplateDir+"/global_footer.html\": " + tmpl_err.Error())
@ -229,9 +251,3 @@ func getStyleLinks(w http.ResponseWriter, stylesheet string) {
func buildFrontPage() error {
return nil
}
func buildBoard(boardid int, page int, boards []BoardsTable, secions []interface{}) (string, error) {
//build board pages
//build board thread pages
return "", nil
}

58
templates/banpage.html Normal file
View file

@ -0,0 +1,58 @@
<!DOCTYPE html>
<html>
<head>
<title>Banned</title>
<link rel="stylesheet" href="/css/global/front.css" />
{{range $i, $style := $config.Styles_img}}
<link rel="{{if isStyleNotDefault_img $style}}alternate {{end}}stylesheet" href="/css/{{$style}}/front.css" />{{end}}
<script type="text/javascript">
var styles = [{{range $i, $style := $config.Styles_img}}{{if gt $i 0}}, {{end}}"{{$style}}"{{end}}];
var webroot = "{{$config.SiteWebfolder}}"
</script>
<script type="text/javascript" src="/javascript/jquery/jquery-1.10.2.min.js"></script>
<script type="text/javascript" src="/javascript/gochan.js"></script>
<script type="text/javascript" src="/javascript/manage.js"></script>
</head>
<body>
<div id="top-pane">
<span id="site-title">{{$config.SiteName}}</span><br />
<span id="site-slogan">{{$config.SiteSlogan}}</span>
</div>
<br />
<br />
<div class="section-block" style="margin: 0px 26px 0px 24px">
<div class="section-title-block">
<span class="section-title"><b>YOU ARE BANNED :(</b></span>
</div>
<div class="section-body" style="padding-top:8px">
<div id="ban-info" style="float:left">
{{if stringEq $ban.Boards "*"}}
You are banned from posting on <b>all boards</b> for the following reason:
{{else}}
You are banned from posting on <b>{{$ban.Boards}}</b> for the following reason:
{{end}}
<br /><br />
<b>{{$ban.Message}}</b>
<br /><br />
{{$expires_timestamp := formatTimestamp $ban.Expires}}
{{$appeal_timestamp := formatTimestamp $ban.AppealAt}}
{{if stringEq $expires_timestamp "Mon, January 01, 0001 00:00 AM"}}
Your ban was placed on {{formatTimestamp $ban.Timestamp}} and will not expire.<br />
{{else}}
Your ban was placed on {{formatTimestamp $ban.Timestamp}} and will expire on {{formatTimestamp $ban.Expires}}<br />
{{end}}
<br />
{{if stringEq $appeal_timestamp "Mon, January 01, 0001 00:00 AM"}}
You may not appeal this ban.
{{else}}
You may appeal this ban {{formatTimestamp $ban.AppealAt}}
{{end}}
<br /><br />
Your IP address is {{$ban.IP}}.
</div>
<img id="banpage-image" src="/banned.jpg" style="float:right; margin: 4px 8px 8px 4px"/>
</div>
</div>
</body>
</html>