func main() {
	thisFile := os.Args[0] + ".go"
	contents, err := ioutil.ReadFile(thisFile)
	if err != nil {
		fmt.Printf("Run this command several times: \n\n    %s\n\n",
			INCREMENT_COMMAND)
		return
	}

	// Find the line where `incrementMe` is defined
	getNum := regexp.MustCompile(LINE_PREFIX + `\d+`)
	oldLine := getNum.FindAllString(string(contents), -1)[0]

	// Parse out the int to be incremented (the current value of `incrementMe`)
	intStr := oldLine[len(LINE_PREFIX):]

	// Convert to int and increment
	theInt, err := strconv.Atoi(intStr)
	fun.MaybeFatalAt("Atoi", err)
	theInt++
	fmt.Printf("%v\n", theInt)

	// Replace old value of `incrementMe` with new value
	newContents := bytes.Replace(contents, []byte(oldLine),
		[]byte(LINE_PREFIX+strconv.Itoa(theInt)), 1)

	// Open thisFile and set its contents to newContents
	file, err := os.OpenFile(thisFile, os.O_WRONLY, 0666)
	fun.MaybeFatalAt("OpenFile", err)

	_, err = file.Write(newContents)
	fun.MaybeFatalAt("file.Write", err)
}
Exemplo n.º 2
0
func main() {
	// Before running this, be sure to install Polipo: 'sudo apt-get
	// install polipo'. Get the config file at
	// https://gitweb.torproject.org/torbrowser.git/blob_plain/1ffcd9dafb9dd76c3a29dd686e05a71a95599fb5:/build-scripts/config/polipo.conf
	// then save it to /etc/polipo/config and restart Polipo with
	// 'sudo service polipo restart', _then_ run this program.

	go noProxy()

	proxyURL, err := url.Parse(PROXY_URL)
	fun.MaybeFatalAt("url.Parse", err)

	transport := &http.Transport{Proxy: http.ProxyURL(proxyURL)}
	// fmt.Printf("transport == %+v\n", transport)
	client := &http.Client{Transport: transport}

	request, err := http.NewRequest("GET", REMOTE_HTTP_ADDR, nil)
	fun.MaybeFatalAt("NewRequest", err)

	resp, err := client.Do(request)
	fun.MaybeFatalAt("client.Do", err)

	// resp, err := http.Get(REMOTE_HTTP_ADDR)
	// fun.MaybeFatalAt("Get", err)
	body, err := ioutil.ReadAll(resp.Body)
	fun.MaybeFatalAt("ReadAll", err)
	defer resp.Body.Close()

	fmt.Printf("Torified: %s", body)
}
Exemplo n.º 3
0
func main() {
	if USERNAME == "" || CURRENT_AUTH_DETAILS == "" {
		log.Fatalf("Set USERNAME and CURRENT_AUTH_DETAILS in this file")
	}

	// Construct a client
	client, err := tent.NewClientWithAuthStr(TENT_SERVER, CURRENT_AUTH_DETAILS)
	fun.MaybeFatalAt("tent.NewClientWithAuthStr", err)

	//
	// Get your most recent statuses
	//
	posts, err := client.GetStatuses()
	fun.MaybeFatalAt("client.GetStatuses", err)
	if len(posts) != 0 {
		post := posts[0]
		fmt.Printf("The latest post in %s's feed, from %s:\n%v",
			TENT_SERVER, post.Entity, post.Content.Text)
	}

	//
	// Get entities that the user follows
	//
	followings, err := client.GetFollowings()
	fun.MaybeFatalAt("client.GetFollowings", err)
	fmt.Printf("\n\n%s's %d most-recently-followed users:\n\n",
		TENT_SERVER, len(followings))

	// Loop over tent.Following vars
	for ndx, f := range followings {
		if ndx != 0 {
			fmt.Printf(", ")
		}
		fmt.Printf("%s", f.Entity)
	}
	fmt.Printf("\n\n")

	//
	// Post new private status that only you and ^https://tent.tent.is can see
	//
	msg := "Dear ^https://tent.tent.is -- don't tell anyone this, but..."
	statusPost, err := client.PostPrivateStatus(msg, "https://tent.tent.is",
		"https://"+TENT_SERVER)
	fun.MaybeFatalAt("client.PostPrivateStatus", err)
	fmt.Printf("See a status post that only you and ^https://tent.tent.is ")
	fmt.Printf("can see at https://%s/posts/%s\n\n", TENT_SERVER, statusPost.Id)

	//
	// Post new status update to TENT_SERVER
	//
	msg = "This message posted with go.tent's sample client "
	msg += "https://github.com/elimisteve/go.tent"
	publicPost, err := client.PostStatus(msg)
	fun.MaybeFatalAt("client.PostStatus", err)
	fmt.Printf("You just posted to Tent.is! See it at https://%s/posts/%s\n",
		TENT_SERVER, publicPost.Id)
}
Exemplo n.º 4
0
func noProxy() {
	resp, err := http.Get(REMOTE_HTTP_ADDR)
	fun.MaybeFatalAt("Get", err)

	body, err := ioutil.ReadAll(resp.Body)
	fun.MaybeFatalAt("ReadAll", err)
	defer resp.Body.Close()

	fmt.Printf("Direct:   %s", body)
}
func main() {
	p := &Person{FirstName: "Abraham"}
	fmt.Printf("p == %+v\n", p)
	err := json.Unmarshal([]byte("{}"), p)
	fun.MaybeFatalAt("json.Unmarshal", err)

	fmt.Printf("p after unmarshal'ing '{}' == %+v\n", p)

	hasLast := []byte(`{"last_name": "Lincoln"}`)
	err = json.Unmarshal(hasLast, p)
	fun.MaybeFatalAt("json.Unmarshal", err)
	fmt.Printf("p after unmarshal'ing 'first + last' == %+v\n", p)
}
func main() {
	jsonStr := `{"entities":{"https://thecloakproject.tent.is":true,"https://jcook.cc":true}}`
	m := map[string]map[string]bool{}
	err := json.Unmarshal([]byte(jsonStr), &m)
	fun.MaybeFatalAt("json.Unmarshal", err)
	fmt.Printf("m == %v\n", m)
}
func main() {
	// Be sure to run 'nc -l -p 9999' or else this won't work. Install
	// netcat with 'sudo apt-get install netcat-traditional'

	req, err := http.NewRequest("GET", "http://localhost:9999", nil)
	fun.MaybeFatalAt("NewRequest", err)

	// Change User Agent String (default: 'Go http package')
	req.Header["User-Agent"] = []string{USER_AGENT}

	client := http.Client{}
	resp, err := client.Do(req)
	fun.MaybeFatalAt("client.Do", err)

	body, err := ioutil.ReadAll(resp.Body)
	fun.MaybeFatalAt("ReadAll", err)
	defer resp.Body.Close()

	fmt.Printf("%s", body)
}
Exemplo n.º 8
0
func signRequest(method string, info *RequestInfo) (authHeader string) {
	mac := info.Mac
	now := strconv.Itoa(int(time.Now().Unix()))
	nonce := fun.RandStrOfLen(NONCE_LENGTH, HEX_CHARSET)
	reqStr := buildRequestString(info, method, now, nonce)
	signed, err := macSigner(mac.Algorithm, mac.Key, reqStr)
	fun.MaybeFatalAt("macSigner", err)
	// TODO: Make sure there should only be 1 replacement
	signature := strings.Replace(base64Encode(signed), "\n", "", 1)
	authHeader = buildAuthHeader(mac, now, nonce, signature)
	return
}
Exemplo n.º 9
0
func main() {
	if USERNAME == "" || CURRENT_AUTH_DETAILS == "" {
		log.Fatalf("Set USERNAME and CURRENT_AUTH_DETAILS in this file")
	}

	// Construct a client
	client, err := tent.NewClientWithAuthStr(TENT_SERVER, CURRENT_AUTH_DETAILS)

	//
	// Post new status update to TENT_SERVER
	//
	fun.MaybeFatalAt("tent.PostStatus", err)
	status := "This message posted with go.tent's sample client "
	status += "https://github.com/elimisteve/go.tent"
	responsePost, err := client.PostStatus(status)
	fun.MaybeFatalAt("tent.PostStatus", err)
	fmt.Printf("Post from %s: \n%+v\n\n", TENT_SERVER, responsePost)

	//
	// Get entities that the user follows
	//
	followings, err := client.GetFollowings()
	fun.MaybeFatalAt("client.GetFollowings", err)
	fmt.Printf("\n\n%d users %s is following:\n\n", len(followings), TENT_SERVER)
	// Loop over tent.Following vars
	for _, f := range followings[:] {
		fmt.Printf("%#v\n\n", f)
	}

	//
	// TODO
	//

	// // Tent profile discovery
	// err := client.Discover("http://tent-user.example.org")
	// fun.MaybeFatalAt("client.Discover", err)

	// err = client.Following().Create("http://another-tent.example.com")
	// fun.MaybeFatalAt("client.Following().Create", err)
}
func main() {
	msg := []byte("This is 18+ chars!")
	fmt.Printf("msg ==    %s\n", msg)

	// Encrypt
	encBlock, err := aes.NewCipher(PASSPHRASE)
	fun.MaybeFatalAt("aes.NewCipher", err)

	// See https://github.com/thecloakproject/utils/blob/master/crypt/aes.go
	cipher, err := crypt.AESEncryptBytes(encBlock, msg)
	fun.MaybeFatalAt("AESEncryptBytes", err)

	fmt.Printf("cipher == %v\n", cipher)

	// Decrypt
	decBlock, err := aes.NewCipher(PASSPHRASE)
	fun.MaybeFatalAt("aes.NewCipher", err)

	// See https://github.com/thecloakproject/utils/blob/master/crypt/aes.go
	plain, err := crypt.AESDecryptBytes(decBlock, cipher)
	fun.MaybeFatalAt("AESDecryptBytes", err)

	fmt.Printf("plain ==  %s\n", plain)
	msgPadded := utils.PadBytes(msg, decBlock.BlockSize())

	// Check for equality
	fmt.Printf("\nThey match? %v!\n", bytes.Equal(msgPadded, plain))

	// Check for equality in other ways
	msgUnpadded := strings.TrimSpace(string(msgPadded))
	match := (msgUnpadded == string(plain))
	fmt.Printf("\nDo their trimmed versions match? %v!\n", match)
	if match {
		fmt.Printf("They both equal '%s'\n", msgUnpadded)
	}

	// Here's how to remove those ugly trailing nulls
	fmt.Printf("Cleanest-looking version: '%s'\n",
		strings.TrimRight(string(plain), "\x00"))
}