Created
February 9, 2011 16:12
-
-
Save XULRunner42/818727 to your computer and use it in GitHub Desktop.
go/mustache+dbi and web.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ybookmarks.sqlite |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Build script generated by gb: http://go-gb.googlecode.com | |
# gb provides configuration-free building and distributing | |
echo "Build script generated by gb: http://go-gb.googlecode.com" | |
if [ "$1" = "goinstall" ]; then | |
echo Running goinstall \ | |
&& echo "goinstall github.com/hoisie/web.go" \ | |
&& goinstall github.com/hoisie/web.go \ | |
&& echo "goinstall github.com/hoisie/mustache.go" \ | |
&& goinstall github.com/hoisie/mustache.go \ | |
&& echo "goinstall github.com/thomaslee/go-dbi" \ | |
&& goinstall github.com/thomaslee/go-dbi \ | |
&& echo "goinstall github.com/thomaslee/go-dbd-sqlite" \ | |
&& goinstall github.com/thomaslee/go-dbd-sqlite \ | |
else | |
echo Building \ | |
&& echo "(in ybookmarks)" && cd ybookmarks && make $1 && cd - > /dev/null \ | |
&& echo "(in websrv)" && cd websrv && make $1 && cd - > /dev/null \ | |
fi | |
# The makefiles above are invoked in topological dependence order |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package ybookmarks | |
import ( | |
"github.com/hoisie/web.go" | |
"github.com/hoisie/mustache.go" | |
s "strconv" | |
"log" | |
) | |
func params(ctx *web.Context) (setcount int, page int) { | |
var params = ctx.Request.Params | |
setcount, err := s.Atoi(params["setcount"]) | |
if err != nil { | |
setcount = 100 | |
} | |
page, err = s.Atoi(params["page"]) | |
if err != nil { | |
page = 1 | |
} | |
return | |
} | |
func ShowTop(ctx *web.Context) { | |
toppost := getFirstPost() | |
posts := Posts{"posts": {toppost}} | |
out := mustache.Render("{{> calicious}}", posts) | |
ctx.WriteString(out) | |
} | |
func NumPosts() (max int) { | |
query := "SELECT count(bookmarks.rowid) FROM bookmarks" | |
maxstr := getFirst(query) | |
max, err := s.Atoi(maxstr) | |
if err != nil { | |
return 0 | |
} | |
return max | |
} | |
func GetTagId(tag string) (tag_id string) { | |
// BAD : this should be done with parameterized queries | |
query := "SELECT tags.rowid FROM tags WHERE name LIKE '" + tag + "'" | |
tag_id = getFirst(query) | |
log.Printf("tag/tag_id: %s/%s\n", tag, tag_id) | |
return tag_id | |
} | |
func ShowTagBookmarks(ctx *web.Context, val string) { | |
bookmark_ids := getTagBookmarkIds(val) | |
where := "WHERE bookmarks.rowid IN (" | |
for _, id := range bookmark_ids { | |
where += id + ", " | |
} | |
where += "0)" | |
setcount, page := params(ctx) | |
query := buildQueryWhere(setcount, page, where) | |
conn, rs := queryDB(query) | |
defer conn.Close() | |
defer rs.Close() | |
posts := consumeRs(rs) | |
out := mustache.Render("{{> calicious}}", posts) | |
ctx.WriteString(out) | |
} | |
/** calicious planner | |
* | |
*/ | |
func Calicious(ctx *web.Context, val string) { | |
setcount, page := params(ctx) | |
var posts = GetPosts(setcount, page) | |
log.Printf("Posts: %d\n", NumPosts()) | |
// I believe that the path is in val, and the headers and params are | |
// in ctx.Request.Headers and ctx.Request.Params! | |
out := mustache.Render("{{> calicious}}", posts) | |
ctx.WriteString(out) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
dbi "github.com/thomaslee/go-dbi" | |
// | |
// important: import all drivers that need to be supported by your | |
// application! | |
// | |
_ "github.com/thomaslee/go-dbd-sqlite" | |
) | |
func main() { | |
conn, err := dbi.Connect("sqlite:///tmp/test.sq3") | |
if err != nil { | |
fmt.Printf("error: unable to connect to the database: %s\n", err.String()) | |
return | |
} | |
defer conn.Close() | |
err = conn.Execute("CREATE TABLE IF NOT EXISTS data" + | |
"(name STRING, value STRING)") | |
err = conn.Execute("CREATE TABLE IF NOT EXISTS users" + | |
"(username STRING, uid INTEGER PRIMARY KEY ASC)") | |
err = conn.Execute("INSERT INTO users (username) VALUES ('tom')") | |
if err != nil { | |
fmt.Printf("error: unable to insert user: %s\n", err.String()) | |
return | |
} | |
rs, err := conn.Query("SELECT username FROM users WHERE username='tom'") | |
if err != nil { | |
fmt.Printf("error: unable to fetch users: %s\n", err.String()) | |
return | |
} | |
defer rs.Close() | |
for rs.Next() { | |
// You can scan the current row of values like so ... | |
var username string | |
err = rs.Scan(&username) | |
if err != nil { | |
fmt.Printf("error: %s\n", err.String()) | |
} else { | |
fmt.Printf("rs.Scan(&username): %s\n", username) | |
} | |
// ... or scan by column name. | |
err = rs.NamedScan("username", &username) | |
if err != nil { | |
fmt.Printf("error: %s\n", err.String()) | |
} else { | |
fmt.Printf("rs.Scan(\"username\", &username): %s\n", username) | |
} | |
} | |
} | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Makefile generated by gb: http://go-gb.googlecode.com | |
# gb provides configuration-free building and distributing | |
include $(GOROOT)/src/Make.inc | |
TARG=websrv | |
GOFILES=\ | |
webfr.go\ | |
webfr_fun.go\ | |
# gb: this is the local install | |
GBROOT=.. | |
# gb: compile/link against local install | |
GC+= -I $(GBROOT)/_obj | |
LD+= -L $(GBROOT)/_obj | |
# gb: default target is in GBROOT this way | |
command: | |
include $(GOROOT)/src/Make.cmd | |
# gb: copy to local install | |
$(GBROOT)/bin/$(TARG): $(TARG) | |
mkdir -p $(dir $@); cp -f $< $@ | |
command: $(GBROOT)/bin/$(TARG) | |
# gb: local dependencies | |
$(TARG): $(GBROOT)/_obj/ybookmarks.a |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Makefile generated by gb: http://go-gb.googlecode.com | |
# gb provides configuration-free building and distributing | |
include $(GOROOT)/src/Make.inc | |
TARG=ybookmarks | |
GOFILES=\ | |
calicious.go\ | |
multiuser.go\ | |
sqlite.go\ | |
# gb: this is the local install | |
GBROOT=.. | |
# gb: compile/link against local install | |
GC+= -I $(GBROOT)/_obj | |
LD+= -L $(GBROOT)/_obj | |
# gb: copy to local install | |
$(GBROOT)/_obj/$(TARG).a: _obj/$(TARG).a | |
mkdir -p $(dir $@); cp -f $< $@ | |
package: $(GBROOT)/_obj/$(TARG).a | |
include $(GOROOT)/src/Make.pkg |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package ybookmarks | |
import ( | |
// dbi "github.com/thomaslee/go-dbi" | |
// _ "github.com/thomaslee/go-dbd-sqlite" | |
) | |
func GetPage(setcount int, page int) Posts { | |
return Posts{} | |
} | |
// Connect to all /ybookmarks\.sqlite\.(.*)/ and get a set | |
// of all posts from all users... order is chronological, | |
// the Post schema is amended to include the username of | |
// the tagger, which is represented as $1 with above regex | |
// Default behavior is to get all pages, and store in cache | |
// for quick retrieval at once. Stale cache is invalidated | |
// by a changed sqlite file hash and regenerated at once. | |
/* | |
func GetAllPosts() Posts { | |
var kingdon, xulrunner, yebyen dbi.Connection | |
kingdon= | |
} | |
*/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"log" | |
) | |
type Passthrough func(string)string | |
type Functor func()Passthrough | |
func render(text string) string { | |
return text | |
} | |
func blender(text string)string { return "<b>" + render(text) + "</b>" } | |
func main() { | |
var x = func() Passthrough { return blender } | |
//var x = Functor { return blender } | |
var container = map[string]interface{} { | |
"name": "Willy", | |
"wrapped": x, | |
} | |
y := x() | |
z := y("Willy") | |
log.Printf("text\n") | |
log.Printf("%s", container["name"]) | |
log.Printf("%s", y("Willy")) | |
log.Printf("%s", x()("Willy")) | |
log.Printf("%s", z) | |
w := container["wrapped"] | |
v := w.(func ()Passthrough) | |
u := v() | |
log.Printf("%s", u(container["name"].(string))) | |
log.Printf("%s", container["wrapped"].(func ()Passthrough)()(container["name"].(string))) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package ybookmarks | |
import ( | |
dbi "github.com/thomaslee/go-dbi" | |
_ "github.com/thomaslee/go-dbd-sqlite" | |
s "strconv" | |
//"log" | |
"time" | |
"strings" | |
) | |
type Post map[string]string | |
type Posts map[string][]map[string]string | |
type PostData struct { | |
name, url, description, datestamp string | |
hash string | |
} | |
func dmyTime(unixtime int64) string { | |
return time.SecondsToLocalTime(unixtime).Format("02 Jan 06") | |
} | |
func scanPost(rs dbi.ResultSet) *PostData { | |
var pd PostData = PostData{} | |
err := rs.Scan(&pd.name, &pd.url, &pd.description, &pd.hash, | |
&pd.datestamp) | |
if err != nil { | |
return nil | |
} | |
return &pd | |
} | |
func readPost(rs dbi.ResultSet, lastDate string) (p *Post, date string) { | |
var post = Post{} | |
if rs.Next() { | |
pd := scanPost(rs) | |
if pd != nil { | |
post["name"] = pd.name | |
post["url"] = pd.url | |
post["description"] = pd.description | |
post["hash"] = pd.hash | |
unixtime, _ := s.Atoi64(pd.datestamp) | |
date = dmyTime(unixtime) | |
} | |
if lastDate == date { | |
//dmy := "" | |
} else { | |
post["datestamp"] = strings.ToUpper(date) | |
} | |
} else { | |
return nil, date | |
} | |
return &post, date | |
} | |
func getFirst(query string) (first string) { | |
conn, rs := queryDB(query) | |
defer conn.Close() | |
defer rs.Close() | |
if rs.Next() { | |
err := rs.Scan(&first) | |
if err != nil { | |
return "" | |
} | |
} | |
return first | |
} | |
func getFirstPost() (first Post) { | |
query := `SELECT name, url, description, hash, added_date / 1000000 as | |
datestamp FROM bookmarks ORDER BY added_date ASC LIMIT 1` | |
conn, rs := queryDB(query) | |
defer conn.Close() | |
defer rs.Close() | |
if rs.Next() { | |
pd := scanPost(rs) | |
first = Post{ | |
"name": pd.name, | |
"url": pd.url, | |
"description": pd.description, | |
"hash": pd.hash, | |
} | |
unixtime, _ := s.Atoi64(pd.datestamp) | |
dmy := dmyTime(unixtime) | |
first["datestamp"] = strings.ToUpper(dmy) | |
} | |
return first | |
} | |
func getTagBookmarkIds(tag string) []string { | |
tag_id := GetTagId(tag) | |
query := `SELECT bookmarks.rowid FROM bookmarks CROSS | |
JOIN bookmarks_tags ON bookmarks_tags.tag_id=` + tag_id + ` AND | |
bookmarks.rowid = bookmarks_tags.bookmark_id` | |
conn, rs := queryDB(query) | |
defer conn.Close() | |
defer rs.Close() | |
var bookmark_ids []string | |
var bookmark_id = "0" | |
for { | |
if rs.Next() { | |
err := rs.Scan(&bookmark_id) | |
if err != nil { | |
return nil | |
} | |
bookmark_ids = append(bookmark_ids, bookmark_id) | |
} else { | |
break | |
} | |
} | |
return bookmark_ids | |
} | |
func buildQueryWhere(setcount int, page int, wh string) string { | |
first := (page - 1) * setcount | |
query := `SELECT name, url, description, hash, added_date / 1000000 as | |
datestamp FROM bookmarks ` + wh + ` ORDER BY added_date ASC LIMIT ` + | |
s.Itoa(first) + "," + s.Itoa(setcount) | |
return query | |
} | |
func buildQuery(setcount int, page int) string { | |
first := (page - 1) * setcount | |
query := `SELECT name, url, description, hash, added_date / 1000000 as | |
datestamp FROM bookmarks ORDER BY added_date ASC LIMIT ` + | |
s.Itoa(first) + "," + s.Itoa(setcount) | |
return query | |
} | |
func consumeRs(rs dbi.ResultSet) Posts { | |
var date string | |
var posts = Posts{"posts": []map[string]string{}} | |
for b, date := readPost(rs, date); b != nil; b, date = readPost(rs, date) { | |
a := *b | |
if b != nil { | |
posts["posts"] = append(posts["posts"], a) | |
} | |
} | |
return posts | |
} | |
func queryDB(query string) (conn dbi.Connection, rs dbi.ResultSet) { | |
conn, err := dbi.Connect("sqlite://./ybookmarks.sqlite") | |
if err != nil { | |
return nil, nil | |
} | |
rs, err = conn.Query(query) | |
if err != nil { | |
//log.Printf("error: unable to fetch bookmarks: %s\n", err.String()) | |
return conn, nil | |
} | |
return conn, rs | |
} | |
func GetPosts(setcount int, page int) Posts { | |
conn, rs := queryDB(buildQuery(setcount, page)) | |
defer conn.Close() | |
defer rs.Close() | |
//log.Printf(" Page %d ##########\n", page) | |
posts := consumeRs(rs) | |
return posts | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
From xulr.unfuddle.com:xulr/webfr-go | |
84f9a2f..44a298b master -> origin/master | |
84f9a2f..44a298b webframework -> origin/webframework | |
Updating 84f9a2f..44a298b | |
Fast-forward | |
818727 | 2 +- | |
toys/ybookmarks/calicious.go | 2 +- | |
2 files changed, 2 insertions(+), 2 deletions(-) | |
~/webfr-go/toys ~/webfr-go | |
[goinstall github.com/thomaslee/go-dbi] | |
[goinstall github.com/hoisie/web.go] | |
[goinstall github.com/thomaslee/go-dbd-sqlite] | |
[goinstall github.com/hoisie/mustache.go] | |
(in ybookmarks) building pkg "ybookmarks" | |
(in websrv) building cmd "websrv" | |
Installing pkg "ybookmarks" | |
Installing cmd "websrv" | |
Built 2 targets | |
Installed 2 targets | |
Removing _obj | |
Removing bin | |
Cleaning ybookmarks | |
Cleaning websrv | |
~/webfr-go | |
Working directory: /home/yebyen/webfr-go | |
Restarting OpenBSD Secure Shell server: sshd. | |
2011/03/04 11:39:10 web.go serving 0.0.0.0:9999 | |
2011/03/04 11:49:44 GET /jcurry | |
2011/03/04 11:50:15 GET /jcurry | |
2011/03/04 11:50:18 GET /jcurry | |
2011/03/04 11:50:21 GET /headers | |
2011/03/04 11:50:39 GET /00_intro.html | |
2011/03/04 12:01:28 GET /jcurry | |
2011/03/04 13:13:19 GET / | |
2011/03/04 13:13:22 GET /toc.xml | |
2011/03/04 13:13:52 GET /jcurry | |
2011/03/04 13:14:59 GET /01_hello.pdf | |
2011/03/04 13:15:06 GET /jcurry | |
2011/03/04 13:15:31 GET /about | |
2011/03/04 13:15:38 GET /index_src | |
2011/03/04 13:16:24 GET /headers | |
2011/03/04 13:16:34 GET /calicious-tags/linux?page=2&setcount=70 | |
2011/03/04 13:16:34 tag/tag_id: linux/55 | |
2011/03/04 13:16:41 GET /calicious-tags/linux?page=2&setcount=70 | |
2011/03/04 13:16:41 tag/tag_id: linux/55 | |
2011/03/04 13:17:04 GET /calicious-tags/csharp | |
2011/03/04 13:17:04 tag/tag_id: csharp/291 | |
2011/03/04 20:56:16 GET /calicious-tags/linux?page=2&setcount=78 | |
2011/03/04 20:56:16 tag/tag_id: linux/55 | |
2011/03/05 11:43:08 GET /calicious-tags/linux?page=2&setcount=78 | |
2011/03/05 11:43:08 tag/tag_id: linux/55 | |
2011/03/05 12:05:38 GET /favicon.ico | |
2011/03/05 15:14:13 GET / | |
2011/03/05 15:19:26 GET /calicious-tags/csharp | |
2011/03/05 15:19:26 tag/tag_id: csharp/291 | |
2011/03/05 15:19:27 GET /css/del-frontend-tidy.css | |
2011/03/05 15:19:28 GET /javascript/main.js | |
2011/03/06 08:24:31 GET /calicious-tags/linux?page=2&setcount=78 | |
2011/03/06 08:24:31 tag/tag_id: linux/55 | |
2011/03/07 13:00:48 GET / | |
2011/03/07 13:00:50 GET /xml/templates.xsl | |
2011/03/07 13:00:50 GET /xml/class.dtd | |
2011/03/07 13:00:51 GET /title.xml | |
2011/03/07 13:00:51 GET /xml/class.css | |
2011/03/07 13:00:51 GET /content.xml | |
2011/03/07 13:00:51 GET /toc.xml | |
2011/03/07 13:00:51 GET /main.xml | |
2011/03/07 13:00:51 GET /xml/cslogo.jpg | |
2011/03/07 13:00:51 GET /xml/toc2html.xsl | |
2011/03/07 13:00:52 GET /xml/mail.png | |
2011/03/07 13:00:53 GET /xml/html.gif | |
2011/03/07 13:00:53 GET /xml/cal.png | |
2011/03/07 13:00:53 GET /xml/rss.png | |
2011/03/07 13:00:53 GET /xml/pdf.gif | |
2011/03/07 13:00:53 GET /xml/dir.png | |
2011/03/07 13:00:53 GET /xml/zip.png | |
2011/03/07 13:00:56 GET /favicon.ico | |
2011/03/07 13:01:00 GET /jcurry | |
2011/03/07 13:01:01 GET /css/main.css | |
2011/03/07 13:01:01 GET /javascript/main.js | |
2011/03/07 13:01:03 GET /favicon.ico | |
2011/03/07 13:02:21 GET /calicious | |
2011/03/07 13:02:21 Posts: 7036 | |
2011/03/07 13:02:22 GET /css/del-frontend-tidy.css | |
2011/03/07 13:02:23 GET /favicon.ico | |
2011/03/07 13:02:56 GET /favicon.ico | |
2011/03/07 13:03:01 GET /favicon.ico | |
2011/03/07 13:03:07 GET /calicious-tags/business | |
2011/03/07 13:03:07 tag/tag_id: business/471 | |
2011/03/07 13:03:09 GET /favicon.ico | |
2011/03/07 13:03:46 GET /calicious-tags/language | |
2011/03/07 13:03:46 tag/tag_id: language/443 | |
2011/03/07 13:03:48 GET /favicon.ico | |
2011/03/07 13:03:55 GET /jcurry | |
2011/03/07 13:03:57 GET /favicon.ico | |
2011/03/07 13:22:53 GET /calicious-tags/linux?page=2&setcount=78 | |
2011/03/07 13:22:53 tag/tag_id: linux/55 | |
2011/03/08 11:05:59 GET / | |
2011/03/08 11:05:59 OPTIONS / | |
2011/03/08 11:06:34 GET / | |
2011/03/08 11:07:03 GET /spiffymcgee.cfm | |
2011/03/08 11:07:03 GET /spiffymcgee.jsp | |
2011/03/08 11:07:03 SEARCH / | |
2011/03/08 11:07:03 PROPFIND / | |
2011/03/08 11:07:03 GET / | |
2011/03/08 11:07:03 GET /jbossws/ | |
2011/03/08 11:07:03 GET /invoker/ | |
2011/03/08 11:07:03 GET /jbossmq-httpil/ | |
2011/03/08 11:07:03 GET /status/ | |
2011/03/08 11:07:03 GET /servlet/ | |
2011/03/08 11:07:13 GET / | |
2011/03/08 11:07:14 CONNECT / | |
2011/03/08 11:07:14 CONNECT / | |
2011/03/08 11:07:16 GET / | |
2011/03/08 11:07:18 GET / | |
2011/03/08 11:07:19 GET / | |
2011/03/08 11:07:20 GET / | |
2011/03/08 11:07:21 GET / | |
2011/03/08 11:07:24 GET /cgi-bin/spiffyfoo.pl | |
2011/03/08 11:07:26 GET / | |
2011/03/08 11:07:27 HEAD / | |
2011/03/08 11:07:30 POST / | |
2011/03/08 11:07:30 PROPFIND / | |
2011/03/08 11:07:31 PROPFIND / | |
2011/03/08 11:07:32 TRACE / | |
2011/03/08 11:07:33 GET /spiffymcgee.nsf | |
2011/03/08 11:07:33 GET / | |
2011/03/08 11:07:33 GET / | |
2011/03/08 11:07:33 GET /spiffymcgee.cfm | |
2011/03/08 11:07:33 GET /spiffymcgee.jsp | |
2011/03/08 11:07:33 SEARCH / | |
2011/03/08 11:07:33 PROPFIND / | |
2011/03/08 11:07:33 GET / | |
2011/03/08 11:07:33 GET /jbossws/ | |
2011/03/08 11:07:33 GET /invoker/ | |
2011/03/08 11:07:33 GET /jbossmq-httpil/ | |
2011/03/08 11:07:33 GET /status/ | |
2011/03/08 11:07:33 GET /servlet/ | |
2011/03/08 11:07:43 GET / | |
2011/03/08 11:07:44 CONNECT / | |
2011/03/08 11:07:45 CONNECT / | |
2011/03/08 11:07:46 GET / | |
2011/03/08 11:07:48 GET / | |
2011/03/08 11:07:49 GET / | |
2011/03/08 11:07:50 GET / | |
2011/03/08 11:07:51 GET / | |
2011/03/08 11:07:54 GET /cgi-bin/spiffyfoo.pl | |
2011/03/08 11:07:57 GET / | |
2011/03/08 11:07:57 HEAD / | |
2011/03/08 11:08:00 POST / | |
2011/03/08 11:08:01 PROPFIND / | |
2011/03/08 11:08:01 PROPFIND / | |
2011/03/08 11:08:02 TRACE / | |
2011/03/08 11:08:03 SEARCH / | |
2011/03/08 11:08:03 GET / | |
2011/03/08 11:08:03 GET / | |
2011/03/08 11:08:03 GET /spiffymcgee.nsf | |
2011/03/08 11:08:03 GET /phpmyadmin/ | |
2011/03/08 11:08:03 GET /console/faces/com_sun_web_ui/jsp/version/version_30.jsp | |
2011/03/08 11:08:03 GET /console/faces/com_sun_web_ui/jsp/version/version_30.jsp | |
2011/03/08 11:08:03 GET /phpmyadmin/ | |
2011/03/08 11:08:27 GET /error/..\conf\httpd.conf | |
2011/03/08 11:08:27 GET /doc/ | |
2011/03/08 11:08:27 GET / | |
2011/03/08 11:08:27 GET /docs/htdocs | |
2011/03/08 11:08:27 GET /welcome.html | |
2011/03/08 11:08:27 GET /index.html | |
2011/03/08 11:08:27 HEAD / | |
2011/03/08 11:08:27 HEAD /login.htm | |
2011/03/08 11:08:27 HEAD /login.html | |
2011/03/08 11:08:27 HEAD /login.shtml | |
2011/03/08 11:08:27 HEAD /default.htm | |
2011/03/08 11:08:27 HEAD /default.html | |
2011/03/08 11:08:27 HEAD /default.shtml | |
2011/03/08 11:08:27 HEAD /index.htm | |
2011/03/08 11:08:27 HEAD /index.html | |
2011/03/08 11:08:27 HEAD /index.shtml | |
2011/03/08 11:08:27 GET / | |
2011/03/08 11:08:27 GET /spiffymcgee.rpd7 | |
2011/03/08 11:08:27 GET /spiffymcgee.rpd7 | |
2011/03/08 11:08:27 GET /doc/packages/ | |
2011/03/08 11:08:27 GET /server-info?mod_info.c | |
2011/03/08 11:08:27 GET /server-status?auto | |
2011/03/08 11:08:27 GET /server-status?refresh=1;http://example.com | |
2011/03/08 11:08:27 GET /server-status?refresh=1;http://example.com | |
2011/03/08 11:08:27 GET /server-status?refresh=1;http://example.com | |
2011/03/08 11:08:27 GET /server-status?auto | |
2011/03/08 11:08:27 GET /server-status?auto | |
2011/03/08 11:08:27 GET /server-status?auto | |
2011/03/08 11:08:27 GET /cgi-bin/printenv | |
2011/03/08 11:08:27 GET /cgi-bin/printenv.pl | |
2011/03/08 11:08:27 GET /cgi-bin/rpm_query | |
2011/03/08 11:08:27 GET /cgi-bin/test-cgi | |
2011/03/08 11:08:27 PROPFIND / | |
2011/03/08 11:08:27 GET /cgi-bin/phf?Qalias=%0A/bin/cat%20/etc/passwd | |
2011/03/08 11:08:27 GET /r7.txt | |
2011/03/08 11:08:27 PUT /r7.txt | |
2011/03/08 11:08:27 GET /r7.txt | |
2011/03/08 11:08:27 GET / | |
2011/03/08 11:08:27 GET /portal/diag/index.jsp | |
2011/03/08 11:08:27 GET / | |
2011/03/08 11:08:27 POST /cgi-bin/webcgi/login | |
2011/03/08 11:08:27 GET /conf/ssl/apache/integrity.key | |
2011/03/08 11:08:27 GET /conf/ssl/apache/integrity-smartcenter.key | |
2011/03/08 11:08:27 POST /index.htm | |
2011/03/08 11:08:27 GET /*<img src="" onerror="alert(42)"> | |
2011/03/08 11:08:27 GET /*<img src="" onerror="alert(42)"> | |
2011/03/08 11:08:27 GET /;utf7xss | |
2011/03/08 11:08:27 GET /;utf7xss | |
2011/03/08 11:08:27 GET /cgi-bin/awstats.pl?debug=1 | |
2011/03/08 11:08:27 GET /cgi-bin/awstats/awstats.pl?debug=1 | |
2011/03/08 11:08:27 GET /cgi-bin/awstats.pl?PluginMode=:print+%22x%22%2e(1042+%2b+1099)%2e%22x%22; | |
2011/03/08 11:08:27 GET /cgi-bin/awstats/awstats.pl?PluginMode=:print+%22x%22%2e(1042+%2b+1099)%2e%22x%22; | |
2011/03/08 11:08:27 GET /bb/ | |
2011/03/08 11:08:27 GET /cgi-bin/faxsurvey?/bin/cat%20/etc/passwd | |
2011/03/08 11:08:27 GET /cgi-bin/faxquery?/bin/cat%20/etc/passwd | |
2011/03/08 11:08:27 GET /cgi-bin/htsearch?Exclude=%60/etc/passwd%60 | |
2011/03/08 11:08:27 GET /cgi-bin/htgrep/file=index.html&hdr=/etc/passwd | |
2011/03/08 11:08:27 GET /cgi-bin/htmlscript?../../../../../../../etc/passwd | |
2011/03/08 11:08:27 POST /cgi-bin/test-cgi | |
2011/03/08 11:08:27 Failed to parse form data "unknown Content-Type \"/*\"" | |
2011/03/08 11:08:27 GET /cgi-bin/view-source?../../../../../../../etc/passwd | |
2011/03/08 11:08:27 GET /_vti_bin/_vti_aut/author.dll | |
2011/03/08 11:08:27 GET /scripts/tools/newdsn.exe?driver=Microsoft%2BAccess%2BDriver%2B%28*.mdb%29&dsn=Web%20SQL&dbq=c:%5ctemp%5cxyz.mdb&newdb=CREATE_DB&attr= | |
2011/03/08 11:08:27 GET /scripts/samples/ctguestb.idc | |
2011/03/08 11:08:27 GET /scripts/samples/details.idc?Fname=|shell(%22c:cmd.exe%22)| | |
2011/03/08 11:08:27 GET /AdvWorks/equipment/catalog_type.asp?ProductType=|shell(%22c:cmd.exe%22)| | |
2011/03/08 11:08:27 GET /AdvWorks/equipment/catalog_type.asp?ProductType=|shell(%22_:cmd.exe%22)| | |
2011/03/08 11:08:27 GET /ASPSamp/AdvWorks/equipment/catalog_type.asp?ProductType=|shell(%22c:cmd.exe%22)| | |
2011/03/08 11:08:27 GET /ASPSamp/AdvWorks/equipment/catalog_type.asp?ProductType=|shell(%22_:cmd.exe%22)| | |
2011/03/08 11:08:27 GET /~bin/true | |
2011/03/08 11:08:27 POST /cgi-bin/home.tcl | |
2011/03/08 11:08:27 HEAD / | |
2011/03/08 11:08:27 GET /cgi-bin/php.ini | |
2011/03/08 11:08:27 POST /xmlrpc.php | |
2011/03/08 11:08:27 Failed to parse form data "unknown Content-Type \"text/xml\"" | |
2011/03/08 11:08:27 POST /serendipity/serendipity_xmlrpc.php | |
2011/03/08 11:08:27 Failed to parse form data "unknown Content-Type \"text/xml\"" | |
2011/03/08 11:08:27 POST /serendipity/xmlrpc.php | |
2011/03/08 11:08:27 Failed to parse form data "unknown Content-Type \"text/xml\"" | |
2011/03/08 11:08:27 POST /drupal/xmlrpc.php | |
2011/03/08 11:08:27 Failed to parse form data "unknown Content-Type \"text/xml\"" | |
2011/03/08 11:08:27 POST /bblog/xmlrpc.php | |
2011/03/08 11:08:27 Failed to parse form data "unknown Content-Type \"text/xml\"" | |
2011/03/08 11:08:27 POST /blogs/xmlsrv/xmlrpc.php | |
2011/03/08 11:08:27 Failed to parse form data "unknown Content-Type \"text/xml\"" | |
2011/03/08 11:08:27 POST /xmlsrv/xmlrpc.php | |
2011/03/08 11:08:27 Failed to parse form data "unknown Content-Type \"text/xml\"" | |
2011/03/08 11:08:27 POST /xmlrpc/xmlrpc.php | |
2011/03/08 11:08:27 Failed to parse form data "unknown Content-Type \"text/xml\"" | |
2011/03/08 11:08:27 POST /script/xmlrpc.php | |
2011/03/08 11:08:27 Failed to parse form data "unknown Content-Type \"text/xml\"" | |
2011/03/08 11:08:27 GET /phpmyadmin/ | |
2011/03/08 11:08:27 GET /README.txt | |
2011/03/08 11:08:27 GET /jkstatus/ | |
2011/03/08 11:08:27 TRACE / | |
2011/03/08 11:08:27 TRACK / | |
2011/03/08 11:08:27 GET /crossdomain.xml | |
2011/03/08 11:08:27 GET / | |
2011/03/08 22:48:57 GET / | |
2011/03/09 05:54:42 GET /calicious-tags/linux?page=2&setcount=78 | |
2011/03/09 05:54:42 tag/tag_id: linux/55 | |
2011/03/11 14:57:56 GET /calicious-tags/linux?page=2&setcount=78 | |
2011/03/11 14:57:56 tag/tag_id: linux/55 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
##To make your system stay accessible: (if your ssh craps out like mine) | |
##1) Add the following line to /etc/sudoers with the command visudo: | |
# | |
# %sudo ALL=NOPASSWD: /etc/init.d/ssh restart | |
# | |
# | |
##2) Add your web server user to the group sudo by running vigr and | |
## vigr -s to modify /etc/group and /etc/gshadow | |
## something like this line (if you are yebyen like me): | |
# | |
# sudo:x:27:yebyen | |
# | |
# | |
##3) Add the incantation to crontab for your user with crontab -e to | |
##launch this script periodically: | |
# | |
# 0 5 * * * $HOME/webfr-go/webfr-go.sh | |
# | |
# | |
## This will restart your sshd and run the commands which update your | |
## deployment of webfr-go webframework. Do whatever you want with the | |
## script's output. With this configuration, all updates and restarts | |
## happen every day at 5:00am. So, if you lose connectivity, you will | |
## have to wait til 5:00am to see it come back. | |
## | |
## Most cron daemons will mail you the logs every day. So, be sure to | |
## login via ssh to your account and check your mail for anomalies! | |
export PS1="$" # Fool crontab into thinking we are running interactively | |
# Important: PATH is set to include webframework toys in "$GOROOT/bin" -- | |
# The sources are cloned and binaries recompiled when this script runs. | |
. /home/yebyen/.bashrc | |
# Set the working directory path and | |
# Pull the latest sources from unfuddle | |
cd /home/yebyen/818727 | |
#git pull | |
GOARCH=386 | |
GOOS=freebsd | |
GOROOT="${HOME}/go" | |
GOPATH="${GOROOT}" | |
GOBIN="${HOME}/bin" | |
#PATH="$GOBIN" | |
export GOARCH GOOS GOROOT GOBIN GOPATH | |
export PATH="${HOME}/bin:${GOBIN}:${PATH}" | |
export HOME | |
# Visit toys directory: | |
# Recompile and install webframework toys | |
pushd ~/818727/toys | |
gb -ig; gb -c | |
popd | |
pushd ~/818727/webroot | |
echo -n "Working directory: " | |
pwd | |
# Restart sshd on 0.0.0.0:22 | |
sudo /etc/init.d/ssh restart | |
# Restart websrv on 0.0.0.0:9999 | |
killall websrv | |
exec websrv | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"github.com/hoisie/web.go" | |
"github.com/hoisie/mustache.go" | |
"ybookmarks" | |
) | |
func main() { | |
web.Get("/about", about) | |
web.Get("/index_src", index_src) | |
web.Get("/jcurry", webfr_jcurry) | |
web.Get("/headers(.*)", webfr_headers) | |
web.Get("/webfr-restart", webfr_restart) | |
web.Get("/top", ybookmarks.ShowTop) | |
web.Get("/calicious-sqlite", calicious_sqlite) | |
web.Get("/calicious-objects", calicious_objects) | |
web.Get("/calicious-tags/(.*)", ybookmarks.ShowTagBookmarks) | |
web.Get("/calicious(.*)", ybookmarks.Calicious) | |
web.Get("/(.*)", index) | |
web.Run("0.0.0.0:9999") | |
} | |
func about(ctx *web.Context) { | |
out := mustache.Render("{{> about}}", map[string]string{}) | |
ctx.WriteString(out) | |
} | |
func js_test(ctx *web.Context, val string) { | |
} | |
/** calicious sqlite reader | |
* | |
*/ | |
func calicious_sqlite(ctx *web.Context) { | |
out := mustache.Render("about sqlite", map[string]string{}) | |
ctx.WriteString(out) | |
} | |
/** calicious objects database | |
* | |
*/ | |
func calicious_objects(ctx *web.Context) { | |
out := mustache.Render("about objects", map[string]string{}) | |
ctx.WriteString(out) | |
} | |
func error(ctx *web.Context, val string) { | |
} | |
/** directory_index emulation | |
* - if index.go resolves but no index.mustache exists, display content | |
* of index.go with a wrapper to format go into colored html output. | |
* - if an unresolved path is specified, forward to the error handler | |
*/ | |
func index(ctx *web.Context, val string) { | |
ctx.ContentType("xml") | |
out := mustache.Render("{{> index}}", | |
map[string][]map[string]string{}) | |
ctx.WriteString(out) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"github.com/hoisie/web.go" | |
"github.com/hoisie/mustache.go" | |
"exec" | |
) | |
type container map[string][]map[string]string | |
type dataslice []map[string]string | |
type dict map[string]string | |
func index_src(ctx *web.Context) { | |
out := mustache.Render("{{> index_src}}", dict{}) | |
ctx.WriteString(out) | |
} | |
func webfr_jcurry(ctx *web.Context) { | |
out := mustache.Render("{{> jcurry}}", dict{}) | |
ctx.WriteString(out) | |
} | |
func webfr_headers(ctx *web.Context, val string) { | |
headers_obj := ctx.Request.Headers | |
headers := dataslice{} | |
params := dataslice{} | |
for index, value := range headers_obj { | |
for _, v := range value { | |
m := dict{"index": index, "value": v} | |
headers = append(headers, m) | |
} | |
} | |
for index, value := range ctx.Request.Params { | |
m := dict{"index": index, "value": value} | |
params = append(params, m) | |
} | |
header := container{"headers": headers, | |
"params": params} | |
out := mustache.Render("{{> header}}", header) | |
ctx.WriteString(out) | |
} | |
func webfr_restart(ctx *web.Context) { | |
err := exec.Command("/home/yebyen/webfr-go.sh").Run() | |
if err != nil { | |
ctx.WriteString("Error restarting webframework!") | |
return | |
} | |
ctx.WriteString("Restarting webframework!") | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
gist-963235 |
View raw
(Sorry about that, but we can’t show files that are this big right now.)
View raw
(Sorry about that, but we can’t show files that are this big right now.)
This file has been truncated, but you can view the full file.
View raw
(Sorry about that, but we can’t show files that are this big right now.)
View raw
(Sorry about that, but we can’t show files that are this big right now.)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment