boilerplate

This commit is contained in:
idk
2019-11-14 15:59:35 -05:00
parent e455685500
commit 1214d6c85a
10 changed files with 847 additions and 2 deletions

1
.gitignore vendored
View File

@ -10,3 +10,4 @@
# Output of the go coverage tool, specifically when used with LiteIDE
*.out
reposam/reposam

15
Makefile Normal file
View File

@ -0,0 +1,15 @@
GO111MODULE=on
build:
cd reposam && go build -tags netgo \
-ldflags '-w -extldflags "-static"'
install:
install -m755 reposam/reposam /usr/local/bin
fixup:
sed -i 's|CowYoSam|RepoSam|g' *.go
sed -i 's|cowyosam|reposam|g' *.go
sed -i 's|CowYoSam|RepoSam|g' reposam/*.go
sed -i 's|cowyosam|reposam|g' reposam/*.go

View File

@ -1,2 +1,24 @@
# reposam
Manage a Debian repository and make it available to I2P over SAM.
CowYoSam
========
A zero-configuration wiki for I2P based on
[cowyo](https://github.com/schollz/cowyo) and sam-forwarder. Works as an
alternative launcher for a cowyo wiki that automatically forwards it to I2P.
Or something I should probably have not done between the hours of noon and 1PM
on Wednesday, November 6th.
Compile/Installation
====================
[cowyo](https://github.com/schollz/cowyo) is sort of like what you'd get if you crossed a wiki and a pastebin.
Anyone can edit, anonymously, in the default configuration. For now, I have
disabled file uploads and some some other features are non-configurable. I will
add them back in soon.
With your GOPATH set:
git clone https://github.com/eydeekay/cowyosam $GOPATH/src/github.com/eyedeekay/cowyosam
cd $GOPATH/src/github.com/eyedeekay/cowyosam
make
sudo make install

8
go.mod Normal file
View File

@ -0,0 +1,8 @@
module github.com/eyedeekay/reposam
go 1.13
require (
github.com/eyedeekay/sam-forwarder v0.32.1-0.20190928041036-d2f767dbe008
golang.org/x/crypto v0.0.0-20191112222119-e1110fd1c708
)

71
go.sum Normal file
View File

@ -0,0 +1,71 @@
crawshaw.io/littleboss v0.0.0-20190317185602-8957d0aedcce/go.mod h1:TIbCAHgttUfOKudw59Il7Z0XIlitzo228/mtwMe4vPM=
github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5/go.mod h1:wHh0iHkYZB8zMSxRWpUBQtwG5a7fFgvEO+odwuTv2gs=
github.com/boltdb/bolt v1.3.1/go.mod h1:clJnj/oiGkjum5o1McbSZDSLxVThjynRyGBgiAx27Ps=
github.com/boreq/friendlyhash v0.0.0-20190522010448-1ca64b3ca69e h1:2q8XPjAYhXX8H71AoAPdgBrCUA3HPhC4ax8XHrTsY6I=
github.com/boreq/friendlyhash v0.0.0-20190522010448-1ca64b3ca69e/go.mod h1:y80zLCg0QS5u3fJKeF2rwpezcyZuCpZpbFcWv6Pn98w=
github.com/creack/pty v1.1.7/go.mod h1:lj5s0c3V2DBrqTV7llrYr5NG6My20zk30Fl46Y7DoTY=
github.com/cryptix/go v1.3.1/go.mod h1:mFQotm9rTzptzvNjJM+1vSIDa/rVOVqMu0889GIXg70=
github.com/cryptix/goSam v0.1.0/go.mod h1:7ewkjhXT8V5RG07pvWUOHHtMahvGbeKlEv8ukUyRiTA=
github.com/d5/tengo v1.24.3/go.mod h1:VhLq8Q2QFhCIJO3NhvM934qOThykMqJi9y9Siqd1ocQ=
github.com/eyedeekay/eephttpd v0.0.0-20190903000420-52f5a8485a4e/go.mod h1:wFPQsNBnY95LkuujFEZARo7slafRwoF0D97FFHBoZro=
github.com/eyedeekay/goSam v0.1.1-0.20190814204230-d4c9b8c57dd6/go.mod h1:kGTfZrncJ4CwMX3d1qA6bcMJTOcuTbOqgWg7WrFNAQ0=
github.com/eyedeekay/httptunnel v0.0.0-20190814204746-0081636585cd/go.mod h1:fD9CRejMpwLs7GC4mu5re58JInU/8Foi3b4hn0NT0a4=
github.com/eyedeekay/httptunnel v0.0.0-20190831065052-9eab288b8a82/go.mod h1:VeXBZz04xj4eUGAcD8ygn2WFxY/dAvRbSNYMWoDzMxc=
github.com/eyedeekay/httptunnel v0.0.0-20190831071439-0ff3d5f798fb/go.mod h1:SnCAM9CskhwSFkzDfh+H5yNTbvhcTeKekkuX0ejCcSk=
github.com/eyedeekay/i2pdig v0.0.0-20180718204453-a67cb46e2e5f/go.mod h1:Zp2JSsndmRykjDGbNS5QHnCYCLnOeYFvwuZFwsATz8k=
github.com/eyedeekay/outproxy v0.0.0-20190908174238-22bd71d43733/go.mod h1:jUBr6XRbiuUBe/sSbVdO5upU4mp8842bdpXDsQY54Rc=
github.com/eyedeekay/portcheck v0.0.0-20190218044454-bb8718669680/go.mod h1:8VVIH19/CU2VFJB8P6e58Mo9nvDqqKgllS0oQY3F83U=
github.com/eyedeekay/ramp v0.0.0-20190429201811-305b382042ab h1:EfTRHxGSbiaEyxNzvKRBWVIDw3mD8xXGxj4gvwFzY7Q=
github.com/eyedeekay/ramp v0.0.0-20190429201811-305b382042ab/go.mod h1:h7mvUAMgZ/rtRDUOkvKTK+8LnDMeUhJSoa5EPdB51fc=
github.com/eyedeekay/sam-forwarder v0.0.0-20190814201550-7c0d7cb0d56c/go.mod h1:Ptrm1d4a3KC5/cN264Gn6OntYOmcuJ8Pkyd7+hA01gw=
github.com/eyedeekay/sam-forwarder v0.0.0-20190831071254-d67c0c0e311f/go.mod h1:u4K8aGwSIuMSQ/OzsH7zkshnEvCQgUupfexLXZIjsDI=
github.com/eyedeekay/sam-forwarder v0.0.0-20190905212604-029317222e15/go.mod h1:kFP6jkqHUTGGW/nMUZLnRonkPWE9fyEc8/eSU1CqTFg=
github.com/eyedeekay/sam-forwarder v0.32.0 h1:PxdqMC37rLU76F/NVUwN1706Qsb/9za2viCkaoiZy8M=
github.com/eyedeekay/sam-forwarder v0.32.0/go.mod h1:mU4OYDLUGupVLIH+P+RYc1QnwI/PVyB4VPtpckppxsw=
github.com/eyedeekay/sam-forwarder v0.32.1-0.20190928041036-d2f767dbe008 h1:v7kHjRGYyK+X13HSDGqLOkY/tFCoMRihJzq78XDAJSY=
github.com/eyedeekay/sam-forwarder v0.32.1-0.20190928041036-d2f767dbe008/go.mod h1:G4w9flJ+VSyuRDfwk8OyPlIayIyGX85km3c993isqgQ=
github.com/eyedeekay/sam3 v0.0.0-20190613034117-99ad6522ebe3/go.mod h1:Vrxh+71E3HVYqyRlT5Jg+E26sSuu8UNTLB4p8qyT408=
github.com/eyedeekay/sam3 v0.0.0-20190730185140-f8d54526ea25 h1:tlVdqLWbZmlZHAUBHB/8jyQPu8VKD0bDXTtGYTESOEg=
github.com/eyedeekay/sam3 v0.0.0-20190730185140-f8d54526ea25/go.mod h1:Y3igFVzN4ybqkkpfUWULGhw7WRp8lieq0ORXbLBbcZM=
github.com/go-kit/kit v0.6.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as=
github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE=
github.com/go-stack/stack v1.7.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY=
github.com/gtank/cryptopasta v0.0.0-20170601214702-1f550f6f2f69 h1:7xsUJsB2NrdcttQPa7JLEaGzvdbk7KvfrjgHZXOQRo0=
github.com/gtank/cryptopasta v0.0.0-20170601214702-1f550f6f2f69/go.mod h1:YLEMZOtU+AZ7dhN9T/IpGhXVGly2bvkJQ+zxj3WeVQo=
github.com/justinas/nosurf v0.0.0-20190416172904-05988550ea18/go.mod h1:Aucr5I5chr4OCuuVB4LTuHVrKHBuyRSo7vM2hqrcb7E=
github.com/kr/pty v1.1.8/go.mod h1:O1sed60cT9XZ5uDucP5qwvh+TE3NnUj51EiZO/lmSfw=
github.com/miolini/datacounter v0.0.0-20171104152933-fd4e42a1d5e0/go.mod h1:P6fDJzlxN+cWYR09KbE9/ta+Y6JofX9tAUhJpWkWPaM=
github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
github.com/zieckey/goini v0.0.0-20180118150432-0da17d361d26 h1:E0lEWrifmR0ACbGf5PLji1XbW6rtIXLHCXO/YOqi0AE=
github.com/zieckey/goini v0.0.0-20180118150432-0da17d361d26/go.mod h1:TQpdgg7I9+PFIkatlx/dnZyZb4iZyCUx1HJj4rXi3+E=
github.com/zserge/lorca v0.1.8/go.mod h1:gTrVdXKyWxNhc8aUb1Uu3s0mY343arR1T6jUtxmBxR8=
github.com/zserge/webview v0.0.0-20180509070823-016c6ffd99f3/go.mod h1:a1CV8KR4Dd1eP2g+mEijGOp+HKczwdKHWyx0aPHKvo4=
github.com/zserge/webview v0.0.0-20190123072648-16c93bcaeaeb/go.mod h1:a1CV8KR4Dd1eP2g+mEijGOp+HKczwdKHWyx0aPHKvo4=
gitlab.com/golang-commonmark/html v0.0.0-20180917080848-cfaf75183c4a/go.mod h1:JT4uoTz0tfPoyVH88GZoWDNm5NHJI2VbUW+eyPClueI=
gitlab.com/golang-commonmark/linkify v0.0.0-20180917065525-c22b7bdb1179/go.mod h1:Gn+LZmCrhPECMD3SOKlE+BOHwhOYD9j7WT9NUtkCrC8=
gitlab.com/golang-commonmark/markdown v0.0.0-20181102083822-772775880e1f/go.mod h1:SIHlEr9462fpIfTrVWf3GqQDxnA65Vm3BMMsUtuA6W0=
gitlab.com/golang-commonmark/mdurl v0.0.0-20180912090424-e5bce34c34f2/go.mod h1:wQk4rLkWrdOPjUAtqJRJ10hIlseLSVYWP95PLrjDF9s=
gitlab.com/golang-commonmark/puny v0.0.0-20180912090636-2cd490539afe/go.mod h1:P9LSM1KVzrIstFgUaveuwiAm8PK5VTB3yJEU8kqlbrU=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20190701094942-4def268fd1a4/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20190829043050-9756ffdc2472/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20191112222119-e1110fd1c708 h1:pXVtWnwHkrWD9ru3sDxY/qFK/bfc0egRovX91EjWjf4=
golang.org/x/crypto v0.0.0-20191112222119-e1110fd1c708/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/net v0.0.0-20181102091132-c10e9556a7bc/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20190813141303-74dc4d7220e7/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20190827160401-ba9fcec4b297/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190813064441-fde4db37ae7a/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190830142957-1e83adbbebd0/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20190814214036-f60b6e7d83f4/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.0.0-20190830223141-573d9926052a/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=

447
reposam-options.go Normal file
View File

@ -0,0 +1,447 @@
package reposam
import (
"fmt"
"path/filepath"
"strconv"
)
//Option is a RepoSam Option
type Option func(*RepoSam) error
//SetFilePath sets the path to save the config file at.
func SetFilePath(s string) func(*RepoSam) error {
return func(c *RepoSam) error {
c.SAMForwarder.Config().FilePath = s
return nil
}
}
//SetType sets the type of the forwarder server
func SetType(s string) func(*RepoSam) error {
return func(c *RepoSam) error {
if s == "http" {
c.SAMForwarder.Config().Type = s
return nil
} else {
c.SAMForwarder.Config().Type = "server"
return nil
}
}
}
//SetSigType sets the type of the forwarder server
func SetSigType(s string) func(*RepoSam) error {
return func(c *RepoSam) error {
if s == "" {
c.SAMForwarder.Config().SigType = ""
} else if s == "DSA_SHA1" {
c.SAMForwarder.Config().SigType = "DSA_SHA1"
} else if s == "ECDSA_SHA256_P256" {
c.SAMForwarder.Config().SigType = "ECDSA_SHA256_P256"
} else if s == "ECDSA_SHA384_P384" {
c.SAMForwarder.Config().SigType = "ECDSA_SHA384_P384"
} else if s == "ECDSA_SHA512_P521" {
c.SAMForwarder.Config().SigType = "ECDSA_SHA512_P521"
} else if s == "EdDSA_SHA512_Ed25519" {
c.SAMForwarder.Config().SigType = "EdDSA_SHA512_Ed25519"
} else {
c.SAMForwarder.Config().SigType = "EdDSA_SHA512_Ed25519"
}
return nil
}
}
//SetSaveFile tells the router to save the tunnel's keys long-term
func SetSaveFile(b bool) func(*RepoSam) error {
return func(c *RepoSam) error {
c.SAMForwarder.Config().SaveFile = b
return nil
}
}
//SetHost sets the host of the service to forward
func SetHost(s string) func(*RepoSam) error {
return func(c *RepoSam) error {
c.SAMForwarder.Config().TargetHost = s
return nil
}
}
//SetPort sets the port of the service to forward
func SetPort(s string) func(*RepoSam) error {
return func(c *RepoSam) error {
port, err := strconv.Atoi(s)
if err != nil {
return fmt.Errorf("Invalid TCP Server Target Port %s; non-number ", s)
}
if port < 65536 && port > -1 {
c.SAMForwarder.Config().TargetPort = s
return nil
}
return fmt.Errorf("Invalid port")
}
}
//SetSAMHost sets the host of the RepoSam's SAM bridge
func SetSAMHost(s string) func(*RepoSam) error {
return func(c *RepoSam) error {
c.SAMForwarder.Config().SamHost = s
return nil
}
}
//SetSAMPort sets the port of the RepoSam's SAM bridge using a string
func SetSAMPort(s string) func(*RepoSam) error {
return func(c *RepoSam) error {
port, err := strconv.Atoi(s)
if err != nil {
return fmt.Errorf("Invalid SAM Port %s; non-number", s)
}
if port < 65536 && port > -1 {
c.SAMForwarder.Config().SamPort = s
return nil
}
return fmt.Errorf("Invalid port")
}
}
//SetName sets the host of the RepoSam's SAM bridge
func SetName(s string) func(*RepoSam) error {
return func(c *RepoSam) error {
c.SAMForwarder.Config().TunName = s
return nil
}
}
//SetInLength sets the number of hops inbound
func SetInLength(u int) func(*RepoSam) error {
return func(c *RepoSam) error {
if u < 7 && u >= 0 {
c.SAMForwarder.Config().InLength = u
return nil
}
return fmt.Errorf("Invalid inbound tunnel length")
}
}
//SetOutLength sets the number of hops outbound
func SetOutLength(u int) func(*RepoSam) error {
return func(c *RepoSam) error {
if u < 7 && u >= 0 {
c.SAMForwarder.Config().OutLength = u
return nil
}
return fmt.Errorf("Invalid outbound tunnel length")
}
}
//SetInVariance sets the variance of a number of hops inbound
func SetInVariance(i int) func(*RepoSam) error {
return func(c *RepoSam) error {
if i < 7 && i > -7 {
c.SAMForwarder.Config().InVariance = i
return nil
}
return fmt.Errorf("Invalid inbound tunnel length")
}
}
//SetOutVariance sets the variance of a number of hops outbound
func SetOutVariance(i int) func(*RepoSam) error {
return func(c *RepoSam) error {
if i < 7 && i > -7 {
c.SAMForwarder.Config().OutVariance = i
return nil
}
return fmt.Errorf("Invalid outbound tunnel variance")
}
}
//SetInQuantity sets the inbound tunnel quantity
func SetInQuantity(u int) func(*RepoSam) error {
return func(c *RepoSam) error {
if u <= 16 && u > 0 {
c.SAMForwarder.Config().InQuantity = u
return nil
}
return fmt.Errorf("Invalid inbound tunnel quantity")
}
}
//SetOutQuantity sets the outbound tunnel quantity
func SetOutQuantity(u int) func(*RepoSam) error {
return func(c *RepoSam) error {
if u <= 16 && u > 0 {
c.SAMForwarder.Config().OutQuantity = u
return nil
}
return fmt.Errorf("Invalid outbound tunnel quantity")
}
}
//SetInBackups sets the inbound tunnel backups
func SetInBackups(u int) func(*RepoSam) error {
return func(c *RepoSam) error {
if u < 6 && u >= 0 {
c.SAMForwarder.Config().InBackupQuantity = u
return nil
}
return fmt.Errorf("Invalid inbound tunnel backup quantity")
}
}
//SetOutBackups sets the inbound tunnel backups
func SetOutBackups(u int) func(*RepoSam) error {
return func(c *RepoSam) error {
if u < 6 && u >= 0 {
c.SAMForwarder.Config().OutBackupQuantity = u
return nil
}
return fmt.Errorf("Invalid outbound tunnel backup quantity")
}
}
//SetEncrypt tells the router to use an encrypted leaseset
func SetEncrypt(b bool) func(*RepoSam) error {
return func(c *RepoSam) error {
if b {
c.SAMForwarder.Config().EncryptLeaseSet = true
return nil
}
c.SAMForwarder.Config().EncryptLeaseSet = false
return nil
}
}
//SetServeDir sets the path to the directory you want to serve
func SetServeDir(s string) func(*RepoSam) error {
return func(c *RepoSam) error {
var err error
c.ServeDir, err = filepath.Abs(s)
if err != nil {
return err
}
return nil
}
}
//SetLeaseSetKey sets the host of the RepoSam's SAM bridge
func SetLeaseSetKey(s string) func(*RepoSam) error {
return func(c *RepoSam) error {
c.SAMForwarder.Config().LeaseSetKey = s
return nil
}
}
//SetLeaseSetPrivateKey sets the host of the RepoSam's SAM bridge
func SetLeaseSetPrivateKey(s string) func(*RepoSam) error {
return func(c *RepoSam) error {
c.SAMForwarder.Config().LeaseSetPrivateKey = s
return nil
}
}
//SetLeaseSetPrivateSigningKey sets the host of the RepoSam's SAM bridge
func SetLeaseSetPrivateSigningKey(s string) func(*RepoSam) error {
return func(c *RepoSam) error {
c.SAMForwarder.Config().LeaseSetPrivateSigningKey = s
return nil
}
}
//SetMessageReliability sets the host of the RepoSam's SAM bridge
func SetMessageReliability(s string) func(*RepoSam) error {
return func(c *RepoSam) error {
c.SAMForwarder.Config().MessageReliability = s
return nil
}
}
//SetAllowZeroIn tells the tunnel to accept zero-hop peers
func SetAllowZeroIn(b bool) func(*RepoSam) error {
return func(c *RepoSam) error {
if b {
c.SAMForwarder.Config().InAllowZeroHop = true
return nil
}
c.SAMForwarder.Config().InAllowZeroHop = false
return nil
}
}
//SetAllowZeroOut tells the tunnel to accept zero-hop peers
func SetAllowZeroOut(b bool) func(*RepoSam) error {
return func(c *RepoSam) error {
if b {
c.SAMForwarder.Config().OutAllowZeroHop = true
return nil
}
c.SAMForwarder.Config().OutAllowZeroHop = false
return nil
}
}
//SetCompress tells clients to use compression
func SetCompress(b bool) func(*RepoSam) error {
return func(c *RepoSam) error {
if b {
c.SAMForwarder.Config().UseCompression = true
return nil
}
c.SAMForwarder.Config().UseCompression = false
return nil
}
}
//SetFastRecieve tells clients to use compression
func SetFastRecieve(b bool) func(*RepoSam) error {
return func(c *RepoSam) error {
if b {
c.SAMForwarder.Config().FastRecieve = true
return nil
}
c.SAMForwarder.Config().FastRecieve = false
return nil
}
}
//SetReduceIdle tells the connection to reduce it's tunnels during extended idle time.
func SetReduceIdle(b bool) func(*RepoSam) error {
return func(c *RepoSam) error {
if b {
c.SAMForwarder.Config().ReduceIdle = true
return nil
}
c.SAMForwarder.Config().ReduceIdle = false
return nil
}
}
//SetReduceIdleTime sets the time to wait before reducing tunnels to idle levels
func SetReduceIdleTime(u int) func(*RepoSam) error {
return func(c *RepoSam) error {
c.SAMForwarder.Config().ReduceIdleTime = 300000
if u >= 6 {
c.SAMForwarder.Config().ReduceIdleTime = (u * 60) * 1000
return nil
}
return fmt.Errorf("Invalid reduce idle timeout(Measured in minutes) %v", u)
}
}
//SetReduceIdleTimeMs sets the time to wait before reducing tunnels to idle levels in milliseconds
func SetReduceIdleTimeMs(u int) func(*RepoSam) error {
return func(c *RepoSam) error {
c.SAMForwarder.Config().ReduceIdleTime = 300000
if u >= 300000 {
c.SAMForwarder.Config().ReduceIdleTime = u
return nil
}
return fmt.Errorf("Invalid reduce idle timeout(Measured in milliseconds) %v", u)
}
}
//SetReduceIdleQuantity sets minimum number of tunnels to reduce to during idle time
func SetReduceIdleQuantity(u int) func(*RepoSam) error {
return func(c *RepoSam) error {
if u < 5 {
c.SAMForwarder.Config().ReduceIdleQuantity = u
return nil
}
return fmt.Errorf("Invalid reduce tunnel quantity")
}
}
//SetCloseIdle tells the connection to close it's tunnels during extended idle time.
func SetCloseIdle(b bool) func(*RepoSam) error {
return func(c *RepoSam) error {
if b {
c.SAMForwarder.Config().CloseIdle = true
return nil
}
c.SAMForwarder.Config().CloseIdle = false
return nil
}
}
//SetCloseIdleTime sets the time to wait before closing tunnels to idle levels
func SetCloseIdleTime(u int) func(*RepoSam) error {
return func(c *RepoSam) error {
c.SAMForwarder.Config().CloseIdleTime = 300000
if u >= 6 {
c.SAMForwarder.Config().CloseIdleTime = (u * 60) * 1000
return nil
}
return fmt.Errorf("Invalid close idle timeout(Measured in minutes) %v", u)
}
}
//SetCloseIdleTimeMs sets the time to wait before closing tunnels to idle levels in milliseconds
func SetCloseIdleTimeMs(u int) func(*RepoSam) error {
return func(c *RepoSam) error {
c.SAMForwarder.Config().CloseIdleTime = 300000
if u >= 300000 {
c.SAMForwarder.Config().CloseIdleTime = u
return nil
}
return fmt.Errorf("Invalid close idle timeout(Measured in milliseconds) %v", u)
}
}
//SetAccessListType tells the system to treat the accessList as a whitelist
func SetAccessListType(s string) func(*RepoSam) error {
return func(c *RepoSam) error {
if s == "whitelist" {
c.SAMForwarder.Config().AccessListType = "whitelist"
return nil
} else if s == "blacklist" {
c.SAMForwarder.Config().AccessListType = "blacklist"
return nil
} else if s == "none" {
c.SAMForwarder.Config().AccessListType = ""
return nil
} else if s == "" {
c.SAMForwarder.Config().AccessListType = ""
return nil
}
return fmt.Errorf("Invalid Access list type(whitelist, blacklist, none)")
}
}
//SetAccessList tells the system to treat the accessList as a whitelist
func SetAccessList(s []string) func(*RepoSam) error {
return func(c *RepoSam) error {
if len(s) > 0 {
for _, a := range s {
c.SAMForwarder.Config().AccessList = append(c.SAMForwarder.Config().AccessList, a)
}
return nil
}
return nil
}
}
//SetTargetForPort sets the port of the RepoSam's SAM bridge using a string
/*func SetTargetForPort443(s string) func(*RepoSam) error {
return func(c *RepoSam) error {
port, err := strconv.Atoi(s)
if err != nil {
return fmt.Errorf("Invalid Target Port %s; non-number ", s)
}
if port < 65536 && port > -1 {
c.SAMForwarder.Config().TargetForPort443 = s
return nil
}
return fmt.Errorf("Invalid port")
}
}
*/
//SetKeyFile sets
func SetKeyFile(s string) func(*RepoSam) error {
return func(c *RepoSam) error {
c.SAMForwarder.Config().KeyFilePath = s
return nil
}
}

151
reposam.go Normal file
View File

@ -0,0 +1,151 @@
package reposam
import (
"crypto/rand"
"golang.org/x/crypto/bcrypt"
"log"
//"strings"
"github.com/eyedeekay/sam-forwarder/interface"
"github.com/eyedeekay/sam-forwarder/tcp"
//"github.com/jcelliott/lumber"
//"github.com/schollz/cowyo/server"
)
func GenerateRandomBytes(n int) ([]byte, error) {
b := make([]byte, n)
_, err := rand.Read(b)
// Note that err == nil only if we read len(b) bytes.
if err != nil {
return nil, err
}
b, err = bcrypt.GenerateFromPassword(b, 14)
if err != nil {
return nil, err
}
return b, nil
}
//RepoSam is a structure which automatically configured the forwarding of
//a local service to i2p over the SAM API.
type RepoSam struct {
*samforwarder.SAMForwarder
password string
ServeDir string
up bool
}
var err error
func (f *RepoSam) GetType() string {
return "reposam"
}
func (f *RepoSam) ServeParent() {
log.Println("Starting eepsite server", f.Base32())
if err = f.SAMForwarder.Serve(); err != nil {
f.Cleanup()
}
}
//Serve starts the SAM connection and and forwards the local host:port to i2p
func (f *RepoSam) Serve() error {
go f.ServeParent()
if f.Up() {
/*sec, err := GenerateRandomBytes(256)
if err != nil {
return err
}
hostport := strings.SplitN(f.Target(), ":", 2)
log.Println("Starting web server", f.Target())*/
/*server.Serve(
f.ServeDir,
hostport[0],
hostport[1],
//c.GlobalString("cert"),
//c.GlobalString("key"),
//TLS,
"",
"",
false,
//c.GlobalString("css"),
//c.GlobalString("default-page"),
"",
"",
//c.GlobalString("lock"),
"",
//c.GlobalInt("debounce"),
5000,
//c.GlobalBool("diary"),
true,
string(sec),
//c.GlobalString("access-code"),
f.password,
//c.GlobalBool("allow-insecure-markup"),
false,
//c.GlobalBool("allow-file-uploads"),
//c.GlobalUint("max-upload-mb"),
false,
0,
//c.GlobalUint("max-document-length"),
100000000,
logger(false),
)*/
}
return nil
}
/*func logger(debug bool) *lumber.ConsoleLogger {
if !debug {
return lumber.NewConsoleLogger(lumber.WARN)
}
return lumber.NewConsoleLogger(lumber.TRACE)
}*/
func (f *RepoSam) Up() bool {
return f.up
}
//Close shuts the whole thing down.
func (f *RepoSam) Close() error {
return f.SAMForwarder.Close()
}
func (s *RepoSam) Load() (samtunnel.SAMTunnel, error) {
if !s.up {
log.Println("Started putting tunnel up")
}
f, e := s.SAMForwarder.Load()
if e != nil {
return nil, e
}
s.SAMForwarder = f.(*samforwarder.SAMForwarder)
s.up = true
log.Println("Finished putting tunnel up")
return s, nil
}
//NewRepoSam makes a new SAM forwarder with default options, accepts host:port arguments
func NewRepoSam(host, port string) (*RepoSam, error) {
return NewRepoSamFromOptions(SetHost(host), SetPort(port))
}
//NewRepoSamFromOptions makes a new SAM forwarder with default options, accepts host:port arguments
func NewRepoSamFromOptions(opts ...func(*RepoSam) error) (*RepoSam, error) {
var s RepoSam
s.SAMForwarder = &samforwarder.SAMForwarder{}
log.Println("Initializing eephttpd")
for _, o := range opts {
if err := o(&s); err != nil {
return nil, err
}
}
s.SAMForwarder.Config().SaveFile = true
l, e := s.Load()
//log.Println("Options loaded", s.Print())
if e != nil {
return nil, e
}
return l.(*RepoSam), nil
}

BIN
reposam/cowyosam Executable file

Binary file not shown.

129
reposam/main.go Normal file
View File

@ -0,0 +1,129 @@
package main
import (
"crypto/tls"
"flag"
"log"
)
import (
"github.com/eyedeekay/reposam"
"github.com/eyedeekay/sam-forwarder/config"
)
var cfg = &tls.Config{
MinVersion: tls.VersionTLS12,
CurvePreferences: []tls.CurveID{tls.CurveP521, tls.CurveP384, tls.CurveP256},
PreferServerCipherSuites: true,
CipherSuites: []uint16{
tls.TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,
tls.TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA,
tls.TLS_RSA_WITH_AES_256_GCM_SHA384,
tls.TLS_RSA_WITH_AES_256_CBC_SHA,
},
}
var (
host = flag.String("a", "127.0.0.1", "hostname to serve on")
port = flag.String("p", "7880", "port to serve locally on")
samhost = flag.String("sh", "127.0.0.1", "sam host to connect to")
samport = flag.String("sp", "7656", "sam port to connect to")
directory = flag.String("d", "./www", "the directory of static files to host(default ./www)")
usei2p = flag.Bool("i", true, "save i2p keys(and thus destinations) across reboots")
servicename = flag.String("n", "reposam", "name to give the tunnel(default reposam)")
useCompression = flag.Bool("g", true, "Uze gzip(true or false)")
accessListType = flag.String("l", "none", "Type of access list to use, can be \"whitelist\" \"blacklist\" or \"none\".")
encryptLeaseSet = flag.Bool("c", false, "Use an encrypted leaseset(true or false)")
allowZeroHop = flag.Bool("z", false, "Allow zero-hop, non-anonymous tunnels(true or false)")
reduceIdle = flag.Bool("r", false, "Reduce tunnel quantity when idle(true or false)")
reduceIdleTime = flag.Int("rt", 600000, "Reduce tunnel quantity after X (milliseconds)")
reduceIdleQuantity = flag.Int("rc", 3, "Reduce idle tunnel quantity to X (0 to 5)")
inLength = flag.Int("il", 3, "Set inbound tunnel length(0 to 7)")
outLength = flag.Int("ol", 3, "Set outbound tunnel length(0 to 7)")
inQuantity = flag.Int("iq", 2, "Set inbound tunnel quantity(0 to 15)")
outQuantity = flag.Int("oq", 2, "Set outbound tunnel quantity(0 to 15)")
inVariance = flag.Int("iv", 0, "Set inbound tunnel length variance(-7 to 7)")
outVariance = flag.Int("ov", 0, "Set outbound tunnel length variance(-7 to 7)")
inBackupQuantity = flag.Int("ib", 1, "Set inbound tunnel backup quantity(0 to 5)")
outBackupQuantity = flag.Int("ob", 1, "Set outbound tunnel backup quantity(0 to 5)")
iniFile = flag.String("f", "none", "Use an ini file for configuration")
useTLS = flag.Bool("t", false, "Generate or use an existing TLS certificate")
certFile = flag.String("m", "cert", "Certificate name to use")
)
func main() {
flag.Parse()
var eepsite *reposam.RepoSam
var err error
config := i2ptunconf.NewI2PBlankTunConf()
if *iniFile != "none" {
var err error
config, err = i2ptunconf.NewI2PTunConf(*iniFile)
if err != nil {
log.Fatal(err)
}
}
config.TargetHost = config.GetHost(*host, "127.0.0.1")
config.TargetPort = config.GetPort(*port, "7880")
config.SaveFile = config.GetSaveFile(*usei2p, true)
config.SamHost = config.GetSAMHost(*samhost, "127.0.0.1")
config.SamPort = config.GetSAMPort(*samport, "7656")
config.TunName = config.GetKeys(*servicename, "reposam")
config.InLength = config.GetInLength(*inLength, 3)
config.OutLength = config.GetOutLength(*outLength, 3)
config.InVariance = config.GetInVariance(*inVariance, 0)
config.OutVariance = config.GetOutVariance(*outVariance, 0)
config.InQuantity = config.GetInQuantity(*inQuantity, 2)
config.OutQuantity = config.GetOutQuantity(*outQuantity, 2)
config.InBackupQuantity = config.GetInBackups(*inBackupQuantity, 1)
config.OutBackupQuantity = config.GetOutBackups(*outBackupQuantity, 1)
config.EncryptLeaseSet = config.GetEncryptLeaseset(*encryptLeaseSet, false)
config.InAllowZeroHop = config.GetInAllowZeroHop(*allowZeroHop, false)
config.OutAllowZeroHop = config.GetOutAllowZeroHop(*allowZeroHop, false)
config.UseCompression = config.GetUseCompression(*useCompression, true)
config.ReduceIdle = config.GetReduceOnIdle(*reduceIdle, true)
config.ReduceIdleTime = config.GetReduceIdleTime(*reduceIdleTime, 600000)
config.ReduceIdleQuantity = config.GetReduceIdleQuantity(*reduceIdleQuantity, 2)
config.AccessListType = config.GetAccessListType(*accessListType, "none")
config.Type = config.GetTypes(false, false, false, "server")
eepsite, err = reposam.NewRepoSamFromOptions(
reposam.SetType(config.Type),
reposam.SetSAMHost(config.SamHost),
reposam.SetSAMPort(config.SamPort),
reposam.SetHost(config.TargetHost),
reposam.SetPort(config.TargetPort),
reposam.SetSaveFile(config.SaveFile),
reposam.SetName(config.TunName),
reposam.SetInLength(config.InLength),
reposam.SetOutLength(config.OutLength),
reposam.SetInVariance(config.InVariance),
reposam.SetOutVariance(config.OutVariance),
reposam.SetInQuantity(config.InQuantity),
reposam.SetOutQuantity(config.OutQuantity),
reposam.SetInBackups(config.InBackupQuantity),
reposam.SetOutBackups(config.OutBackupQuantity),
reposam.SetEncrypt(config.EncryptLeaseSet),
reposam.SetAllowZeroIn(config.InAllowZeroHop),
reposam.SetAllowZeroOut(config.OutAllowZeroHop),
reposam.SetCompress(config.UseCompression),
reposam.SetReduceIdle(config.ReduceIdle),
reposam.SetReduceIdleTimeMs(config.ReduceIdleTime),
reposam.SetReduceIdleQuantity(config.ReduceIdleQuantity),
reposam.SetAccessListType(config.AccessListType),
reposam.SetAccessList(config.AccessList),
reposam.SetServeDir(*directory),
)
if err != nil {
log.Fatal(err)
}
if eepsite != nil {
log.Println("Starting server")
if err = eepsite.Serve(); err != nil {
log.Fatal(err)
}
} else {
log.Println("Unable to start, eepsite was", eepsite)
}
}

1
reposam_test.go Normal file
View File

@ -0,0 +1 @@
package reposam