Compare commits

..

No commits in common. "master" and "public" have entirely different histories.

10 changed files with 43 additions and 110 deletions

View File

@ -20,53 +20,55 @@ sudo apt-get install postgres postgresql-contrib
Setup postgres to handle a local connection for transmet in pg_hba.conf
either:
host transmet transmet 127.0.0.1/32 md5
'''host transmet transmet 127.0.0.1/32 md5'''
or a more liberal:
host all all 127.0.0.1/32 md5
'''host all all 127.0.0.1/32 md5 '''
and do the same for
host all all ::1/128 md5
'''host all all ::1/128 md5'''
ipv6
create ssl certs and put them somewhere
enable SSL in postgresql.conf
ssl = true
ssl_cert_file = 'WHER_YOU_PUT/server.crt'
ssl_key_file = 'WHERE_YOU_PUT/server.key'
'''
ssl = true
ssl_cert_file = 'WHER_YOU_PUT/server.crt'
ssl_key_file = 'WHERE_YOU_PUT/server.key'
'''
Create postgress DB and user
sh
sudo -u postgres --or-- sudo su - postgres
createuser -S -P -E transmet
createdb --owner transmet --encoding utf8 transmet
psql
\c transmet
CREATE EXTENSION pgcrypto;
'''sh
sudo -u postgres --or-- sudo su - postgres
createuser -S -P -E transmet
createdb --owner transmet --encoding utf8 transmet
psql
\c transmet
CREATE EXTENSION pgcrypto;
'''
put DB details in
db/dbconf.yml (copied from db/dbconf.EXAMPLE)
config/prod.json (copied from config/local.json)
put DB details in:
* db/dbconf.yml (copied from db/dbconf.EXAMPLE)
* config/prod.json (copied from config/local.json)
go get bitbucket.org/liamstask/goose/cmd/goose
go get bitbucket.org/liamstask/goose/cmd/goose
goose up
goose up
## Run
Assumed `GOPATH=/opt/go`
Assumed GOPATH=/opt/go
edit transmet.conf to point to correct location
sudo cp transmet.conf /etc/init
./gen-csrf.sh
sudo service transmet start
sudo cp transmet.conf /etc/init
./gen-csrf.sh
sudo service transmet start
## Setup environment
### Adding a user
INSERT INTO users (username, password) VALUES('USERNAME', crypt('PASSWORD', gen_salt('bf')));
INSERT INTO users (username, password) VALUES('USERNAME', crypt('PASSWORD', gen_salt('bf')));

View File

@ -38,27 +38,10 @@ body {
font-size: 12px;
}
.post-content {
.post-preview {
font-size: 12px;
max-height: 5em;
overflow: hidden;
padding-bottom: 10px;
}
.post-content blockquote {
font-size: 12px;
font-family: serif;
}
.content-slider {
text-align: center;
font-weight: bold;
font-size: 16px;
border-radius: 3px;
padding: 0px;
}
.post-delete, .post-edit {
font-size: 12px;
}

View File

@ -42,16 +42,4 @@ $(document).ready( function () {
form.submit();
}
});
$(".content-slider").click(function (e) {
var contentDiv = $(this).parents('.news-row').find('.post-content');
if (contentDiv.hasClass("state-up")) {
contentDiv.removeClass('state-up').addClass('state-down').animate({'max-height': '100%', 'height': '100%'});
$(this).html('^');
} else {
contentDiv.removeClass('state-down').addClass('state-up').animate({height: '5em'});
$(this).html('v');
}
});
});

11
main.go
View File

@ -104,18 +104,15 @@ func main() {
dbConnect()
initTemplates()
muxRouter := init_route_handlers()
//errHandler := csrf.ErrorHandler( CSRFErrorHandler{} )
errHandler := csrf.ErrorHandler( CSRFErrorHandler{} )
// Terrible. TODO: Get SSL for prod, and then wrap in if(dev) { {
//csrfSecurityOption := csrf.Secure(false)
//csrfMaxTimeOption := csrf.MaxAge(3600 * 24 * 3) // 3 Days - a little more wiggle room
csrfSecurityOption := csrf.Secure(false)
csrfMaxTimeOption := csrf.MaxAge(3600 * 24 * 3) // 3 Days - a little more wiggle room
fmt.Println("Listening on", config.Port, "...")
// Disabled CSRF until SSL (and sorting why the popup is throwing CSRF errs
// for tor and FF with ublock + https everywhere)
//err := http.ListenAndServe(":"+config.Port, csrf.Protect([]byte(csrfSecret()), errHandler, csrfSecurityOption, csrfMaxTimeOption)(muxRouter))
err := http.ListenAndServe(":"+config.Port, muxRouter)
err := http.ListenAndServe(":"+config.Port, csrf.Protect([]byte(csrfSecret()), errHandler, csrfSecurityOption, csrfMaxTimeOption)(muxRouter))
if err != nil {
fmt.Println("Fatal Error: ", err)
}

View File

@ -8,8 +8,6 @@ import (
_ "github.com/lib/pq"
"strconv"
"time"
"html/template"
"strings"
)
type News struct {
@ -19,7 +17,6 @@ type News struct {
Category_id int
Date time.Time
Notes string
htmlNotes template.HTML
}
const (
@ -97,7 +94,7 @@ func Get(db *sql.DB, id int) (*News, error) {
func LoadPage(db *sql.DB, offset, amount int) ([]*News, int, error) {
categories.LoadCategories(db) // required by addContainer
rows, err := db.Query("SELECT " + SQL_NEWS_FIELDS + " FROM news ORDER BY timestamp DESC LIMIT $1 OFFSET $2", amount, offset)
rows, err := db.Query("SELECT " + SQL_NEWS_FIELDS + " FROM news order by timestamp DESC")
if err != nil {
fmt.Println("DB errpr reading LoadPage news: ", err)
return nil, 0, err
@ -141,10 +138,6 @@ func (news *News) Id() int {
return news.id
}
func (news *News) HTMLNotes() template.HTML {
return news.htmlNotes
}
func nullStringToString(str *sql.NullString) string {
if str.Valid {
return str.String
@ -189,9 +182,6 @@ func scanNews(rows *sql.Rows) (*News, error) {
news.Url = nullStringToString(&url)
news.Title = nullStringToString(&title)
news.Notes = nullStringToString(&notes)
// support wordpress style <quote> tags
news.Notes = strings.Replace(news.Notes, "quote>", "blockquote>", -1)
news.htmlNotes = template.HTML(news.Notes)
if category_id.Valid {
news.Category_id = int(category_id.Int64)

View File

@ -418,7 +418,7 @@ func newsFormHandler(w http.ResponseWriter, r *http.Request, user *user.User, se
session.AddFlash("Error loading news", flash_err)
}
ShowTemplate("news", w, r, map[string]interface{}{"user": user, "flashes": flashes, "news": news, "count": count, "offset": argOffset, "amount": amount, "categories": categories.CategoriesFlat, "url": config.Url})
ShowTemplate("news", w, r, map[string]interface{}{"user": user, "flashes": flashes, "news": news, "count": count, "categories": categories.CategoriesFlat, "url": config.Url})
}
func ServeFileHandler(res http.ResponseWriter, req *http.Request) {

View File

@ -5,6 +5,7 @@ import (
"fmt"
"github.com/dballard/transmet/categories"
"github.com/gorilla/csrf"
"html/template"
"net/http"
"path/filepath"

View File

@ -40,8 +40,8 @@
</ul>
<ul class="nav navbar-nav navbar-right">
{{if .user}}
<li><a href="">{{.user.Username}}</a></li>
<li><form method="POST" action="/logout">{{ .csrfField }}<input type="submit" value="Logout" class="btn-sm btn-primary btn-block" /></form></li>
<li>{{.user.Username}}</li>
<li><form method="POST" action="/logout">{{ .csrfField }}<input type="submit" value="Logout" class="btn btn-sm btn-primary btn-block" /></form></li>
{{else}}
<li><a href="/login">Log in</a></li>
{{end}}

View File

@ -35,7 +35,7 @@ new category select
</div>
<div class="col-xs-1">
<form method="POST" action="/categories/{{.category.Id}}/delete" class="cat-delete">{{ $.csrfField }}
<input type="submit" class="btn btn-default btn-sm btn-block" value="Delete" />
<input type="submit" class="btn btn-sm btn-block" value="Delete" />
</form>
</div>
<div class="col-xs-3">

View File

@ -9,22 +9,14 @@
<div class="col-xs-6">
Drag this bookmarklet to bookmark bar and click anywhere to add a link
</div>
<div class="col-xs-4"></div>
{{template "pager" .}}
<div class="col-xs-4"></div>
<div class="col-xs-12">&nbsp;</div>
</div>
<div class="news-posts">
{{range $news_post := .news}}
{{template "row-news" dict "post" $news_post "categories" $.categories "csrfField" $.csrfField}}
{{end}}
</div>
<div class="row">
{{template "pager" .}}
</div>
{{end}}
@ -47,39 +39,19 @@
<div class="col-xs-8 post-url">
<a href="{{.post.Url}}">{{truncate .post.Url 100}}</a>
</div>
<div class="col-xs-2 post-edit"><a href="/news/{{.post.Id}}/edit" class="btn btn-default btn-sm btn-block">Edit</a></div>
<div class="col-xs-2 post-edit"><a href="/news/{{.post.Id}}/edit" class="btn btn-sm btn-block">Edit</a></div>
</div>
<div class="row">
<div class="col-xs-2">&nbsp;</div>
<div class="col-xs-8 post-content state-up"> {{ .post.HTMLNotes }}</div>
<div class="col-xs-8 post-preview">{{truncate .post.Notes 500}}</div>
<div class="col-xs-2 post-delete">
<form method="POST" action="/news/{{.post.Id}}/delete" class="confirm-news-delete">{{ .csrfField }}
<input type="submit" class="btn btn-default btn-sm btn-block" value="Delete" />
<input type="submit" class="btn btn-sm btn-block" value="Delete" />
</form>
</div>
</div>
<div class="row">
<div class="col-xs-2">&nbsp;</div>
<div class="col-xs-8 btn-default btn content-slider state-up">v</div>
</div>
</div>
{{end}}
{{define "pager"}}
<div class="col-xs-12">&nbsp;</div>
<div class="col-xs-2">
{{if ge .count .amount }}
<a href="?offset={{ add .offset 1}}">&lt; Prev</a>
{{end}}
</div>
<div class="col-xs-8">&nbsp;</div>
<div class="col-xs-2">
{{ if ne .offset 0 }}
<a href="?offset={{ minus .offset 1 }}">Next &gt</a>
{{end}}
</div>
{{end}}
<!-- JS for the launcher of the add bookmarklet -->
{{define "launch-add"}}javascript:(function() { var d=document,w=window,e=w.getSelection,k=d.getSelection,x=d.selection,s=(e?e():(k)?k():(x?x.createRange().text:0)),f='{{.url}}/news/add',l=d.location,e=encodeURIComponent,u=f+'?popup=1&url='+e(l.href)+'&title='+e(d.title)+'&selection='+e(s);a=function(){if(!w.open(u,'t','toolbar=0,resizable=1,scrollbars=1,status=1,width=720,height=480'))l.href=u;};if (/Firefox/.test(navigator.userAgent)) setTimeout(a, 0); else a();void(0) })();{{end}}