aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--main.go50
1 files changed, 42 insertions, 8 deletions
diff --git a/main.go b/main.go
index fb6efc7..4333d36 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"
@@ -34,6 +35,10 @@ 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\""
func main() {
@@ -2230,21 +2235,50 @@ func localShort(url string) string {
}
func remoteShort(url string) string {
- re := regexp.MustCompile(`\w+$`)
+ re := regexp.MustCompile(`\w+$`)
+
+ id := re.FindString(StripTransferProtocol(url));
+
+ re = regexp.MustCompile(`.+/.+/`)
+
+ actorurl := re.FindString(StripTransferProtocol(url))
+
+ re = regexp.MustCompile(`/.+/`)
+
+ actorname := re.FindString(actorurl)
- id := re.FindString(StripTransferProtocol(url));
+ actorname = strings.Replace(actorname, "/", "", -1)
- re = regexp.MustCompile(`.+/.+/`)
+ return "f" + actorname + "-" + id
+}
+
+func RouteProxy(req *http.Request) (*http.Response, error) {
+
+ var proxyType = GetPathProxyType(req.URL.Host)
+
+ if proxyType == "tor" {
+ proxyUrl, err := url.Parse("socks5://" + TorProxy)
- actorurl := re.FindString(StripTransferProtocol(url))
+ CheckError(err, "error parsing tor proxy url")
- re = regexp.MustCompile(`/.+/`)
+ proxyTransport := &http.Transport{Proxy: http.ProxyURL(proxyUrl)}
+ client := &http.Client{ Transport: proxyTransport, Timeout: time.Second * 10 }
+ return client.Do(req)
+ }
- actorname := re.FindString(actorurl)
+ return http.DefaultClient.Do(req)
+}
- actorname = strings.Replace(actorname, "/", "", -1)
+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"
}
func RunDatabaseSchema(db *sql.DB) {