Skip to content

Commit

Permalink
version G for git and rename postkey to URLKey
Browse files Browse the repository at this point in the history
  • Loading branch information
aerth committed Jun 16, 2016
1 parent 8596769 commit 6ab9dd4
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 18 deletions.
25 changes: 19 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,21 @@
# https://github.com/aerth
NAME=cosgo
VERSION=0.9
RELEASE:=${VERSION}.X${COMMIT}
COMMIT=$(shell git rev-parse --verify --short HEAD)
RELEASE:=${VERSION}.X${COMMIT}


# Build a static linked binary
export CGO_ENABLED=0

# Embed commit version into binary
GO_LDFLAGS=-ldflags "-X main.version=$(RELEASE)"
PREFIX=/usr/local
PREFIX?=$(shell pwd)

# Install to /usr/local/
#PREFIX=/usr/local
PREFIX?=/usr/local

# Set temp gopath if none exists
ifeq (,${GOPATH})
export GOPATH=/tmp/gopath
endif
Expand Down Expand Up @@ -43,8 +53,11 @@ cross:
GOOS=netbsd GOARCH=amd64 go build -v ${GO_LDFLAGS} -o bin/${NAME}-v${RELEASE}-netbsd-amd64
GOOS=netbsd GOARCH=386 go build -v ${GO_LDFLAGS} -o bin/${NAME}-v${RELEASE}-netbsd-x86
echo ${RELEASE} > bin/VERSION
for i in $(ls ./bin/); do sha384sum $i >> bin/HASH; done

package: cross
for i in $(ls ./bin/ | grep "-v"); do zip $i.zip $i README.md LICENSE.md HASH; done

# package target is not working out, moved to a shell script named "package.bash"
package:
mkdir -p pkg
for i in $(shell ls bin); do sha384sum bin/$i >> HASH; done
for i in $(shell ls bin); do zip $i.zip bin/$i README.md LICENSE.md HASH; done

26 changes: 14 additions & 12 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ import (
)

var (
version = "0.9-go-get"
version = "0.9.G"
destinationEmail = "cosgo@localhost"
antiCSRFkey = []byte("LI80PNK1xcT01jmQBsEyxyrNCrbyyFPjPU8CKnxwmCruxNijgnyb3hXXD3p1RBc0+LIRQUUbTtis6hc6LD4I/A==")
cosgoRefresh = 42 * time.Minute
Expand All @@ -83,9 +83,10 @@ var (
mboxfile = flag.String("mbox", "cosgo.mbox", "Custom mbox file name\n\tExample: -mbox custom.mbox")
)

// Cosgo struct holds the Boottime and
type Cosgo struct {
PostKey string
Boottime time.Time
URLKey string
Visitors int
}

func main() {
Expand All @@ -108,13 +109,15 @@ func main() {
go func() {
for {
if *debug && !*quiet {
log.Println("Info: Generating Random POST Key...")
log.Println("Info: Generating Random 40 URL Key...")
}
cosgo.PostKey = generateAPIKey(40)
// set a random URL key (40 char length)
cosgo.URLKey = generateURLKey(40)
if *debug && !*quiet {
log.Printf("Info: POST Key is " + cosgo.PostKey + "\n")
log.Printf("Info: URL Key is " + cosgo.URLKey + "\n")
}
time.Sleep(cosgoRefresh) // Internal cron!!!
// every X minutes
time.Sleep(cosgoRefresh)
}
}()

Expand Down Expand Up @@ -311,7 +314,7 @@ func staticFinder(cwd string) string {
}

func getKey() string {
return cosgo.PostKey
return cosgo.URLKey
}
func getDestination() string {
return destinationEmail
Expand Down Expand Up @@ -368,10 +371,9 @@ func getSubdomain(r *http.Request) string {
return ""
}

var runes = []rune("____ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890123456789012345678901234567890")

//generateAPIKey does API Key Generation with the given runes.
func generateAPIKey(n int) string {
//generateURLKey creates a new key, with the given runes, n length.
func generateURLKey(n int) string {
runes := []rune("____ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890123456789012345678901234567890")
b := make([]rune, n)
for i := range b {
b[i] = runes[rand.Intn(len(runes))]
Expand Down

0 comments on commit 6ab9dd4

Please sign in to comment.