aboutsummaryrefslogtreecommitdiff
path: root/main.go
diff options
context:
space:
mode:
authorFChannel <>2021-05-11 20:10:57 -0700
committerFChannel <>2021-05-11 20:10:57 -0700
commite3eba9b6c64b1e8d884a51638deca0078f2f4760 (patch)
tree78e38bfaf8260cbf115d4cfd32b7253178c0bcb1 /main.go
parent43e30cd3bc559eb9c51a2df0f45f3e29090cd0aa (diff)
added proxy for tor
Diffstat (limited to 'main.go')
-rw-r--r--main.go50
1 files changed, 41 insertions, 9 deletions
diff --git a/main.go b/main.go
index 43ea539..cedc09c 100644
--- a/main.go
+++ b/main.go
@@ -4,6 +4,7 @@ import "fmt"
import "strings"
import "strconv"
import "net/http"
+import "net/url"
import "database/sql"
import _ "github.com/lib/pq"
import "math/rand"
@@ -33,6 +34,8 @@ var SiteEmailPassword = GetConfigValue("emailpass")
var SiteEmailServer = GetConfigValue("emailserver") //mail.fchan.xyz
var SiteEmailPort = GetConfigValue("emailport") //587
+var TorProxy = "127.0.0.1:9050"
+
var ldjson = "application/ld+json"
var activitystreams = "application/ld+json; profile=\"https://www.w3.org/ns/activitystreams\""
@@ -55,7 +58,7 @@ func main() {
FollowingBoards = GetActorFollowingDB(db, Domain)
Boards = GetBoardCollection(db)
-
+
// root actor is used to follow remote feeds that are not local
//name, prefname, summary, auth requirements, restricted
if GetConfigValue("instancename") != "" {
@@ -1982,19 +1985,48 @@ func localShort(url string) string {
}
func remoteShort(url string) string {
- re := regexp.MustCompile(`\w+$`)
+ re := regexp.MustCompile(`\w+$`)
+
+ id := re.FindString(StripTransferProtocol(url));
- id := re.FindString(StripTransferProtocol(url));
+ re = regexp.MustCompile(`.+/.+/`)
- re = regexp.MustCompile(`.+/.+/`)
+ actorurl := re.FindString(StripTransferProtocol(url))
- actorurl := re.FindString(StripTransferProtocol(url))
+ re = regexp.MustCompile(`/.+/`)
+
+ actorname := re.FindString(actorurl)
+
+ actorname = strings.Replace(actorname, "/", "", -1)
+
+ return "f" + actorname + "-" + id
+}
- re = regexp.MustCompile(`/.+/`)
+func RouteProxy(req *http.Request) (*http.Response, error) {
- actorname := re.FindString(actorurl)
+ var proxyType = GetPathProxyType(req.URL.Host)
- actorname = strings.Replace(actorname, "/", "", -1)
+ if proxyType == "tor" {
+ proxyUrl, err := url.Parse("socks5://" + TorProxy)
+
+ CheckError(err, "error parsing tor proxy url")
+
+ proxyTransport := &http.Transport{Proxy: http.ProxyURL(proxyUrl)}
+ client := &http.Client{ Transport: proxyTransport, Timeout: time.Second * 10 }
+ return client.Do(req)
+ }
+
+ return http.DefaultClient.Do(req)
+}
+
+func GetPathProxyType(path string) string {
+ if TorProxy != "" {
+ re := regexp.MustCompile(`(http://|http://)?(www.)?\w+\.onion`)
+ onion := re.MatchString(path)
+ if onion {
+ return "tor"
+ }
+ }
- return "f" + actorname + "-" + id
+ return "clearnet"
}