From 89da4a1b05726ce1eca7d0bdd4a749e9d03ba8f9 Mon Sep 17 00:00:00 2001
From: Arya Kiran
Date: Tue, 9 May 2023 15:58:35 +0530
Subject: [PATCH 1/4] move esmailelbob instance to dev
---
README.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/README.md b/README.md
index 301a498..b2fbe73 100644
--- a/README.md
+++ b/README.md
@@ -34,6 +34,7 @@ The ``master`` branch runs on the master branch of GotHub. This means that the i
| Link | Cloudflare | Country | ISP | Branch |
| -------- | ---------- | ----------- | ----- | ----- |
| [gh.akisblack.dev](https://gh.akisblack.dev) | No | Germany | OVHcloud | master |
+| [gothub.esmailelbob.xyz](https://gothub.esmailelbob.xyz) | No | Canada | OVHcloud | master |
| [gh.odyssey346.dev](https://gh.odyssey346.dev) | No | France | OVHcloud (Trolling Solutions) | master |
| [gh.phreedom.club](https://gh.phreedom.club) | No | Iceland | Flokinet | master |
| [gothub.projectsegfau.lt](https://gothub.projectsegfau.lt) | No | GeoDNS (Luxembourg/USA/India) | BuyVM/Digital Ocean/Airtel | master |
@@ -43,7 +44,6 @@ The ``master`` branch runs on the master branch of GotHub. This means that the i
| [gothub.xbdm.fun](https://gothub.xbdm.fun) | Yes | Germany | Hetzner | master |
| [dev.gh.akisblack.dev](https://dev.gh.akisblack.dev) | No | Germany | OVHcloud | dev |
| [gh.creller.net](https://gh.creller.net) | No | Scotland | British Telecommunications PLC | dev |
-| [gothub.esmailelbob.xyz](https://gothub.esmailelbob.xyz) | No | Canada | OVHcloud | dev |
| [gothub.no-logs.com](https://gothub.no-logs.com/) | No | Sweden | Vultr | dev |
| [gh.dev.odyssey346.dev](https://gh.dev.odyssey346.dev) | No | France | OVHcloud (Trolling Solutions) | dev |
| [gothub.dev.projectsegfau.lt](https://gothub.dev.projectsegfau.lt) | No | Luxembourg | BuyVM | dev |
From b524fbe0ad6e559373d5757c8c1a596822281e2c Mon Sep 17 00:00:00 2001
From: Arya Kiran
Date: Wed, 10 May 2023 13:33:21 +0530
Subject: [PATCH 2/4] no-logs.com is master as well
---
README.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/README.md b/README.md
index b2fbe73..5aa428a 100644
--- a/README.md
+++ b/README.md
@@ -35,6 +35,7 @@ The ``master`` branch runs on the master branch of GotHub. This means that the i
| -------- | ---------- | ----------- | ----- | ----- |
| [gh.akisblack.dev](https://gh.akisblack.dev) | No | Germany | OVHcloud | master |
| [gothub.esmailelbob.xyz](https://gothub.esmailelbob.xyz) | No | Canada | OVHcloud | master |
+| [gothub.no-logs.com](https://gothub.no-logs.com/) | No | Sweden | Vultr | master |
| [gh.odyssey346.dev](https://gh.odyssey346.dev) | No | France | OVHcloud (Trolling Solutions) | master |
| [gh.phreedom.club](https://gh.phreedom.club) | No | Iceland | Flokinet | master |
| [gothub.projectsegfau.lt](https://gothub.projectsegfau.lt) | No | GeoDNS (Luxembourg/USA/India) | BuyVM/Digital Ocean/Airtel | master |
@@ -44,7 +45,6 @@ The ``master`` branch runs on the master branch of GotHub. This means that the i
| [gothub.xbdm.fun](https://gothub.xbdm.fun) | Yes | Germany | Hetzner | master |
| [dev.gh.akisblack.dev](https://dev.gh.akisblack.dev) | No | Germany | OVHcloud | dev |
| [gh.creller.net](https://gh.creller.net) | No | Scotland | British Telecommunications PLC | dev |
-| [gothub.no-logs.com](https://gothub.no-logs.com/) | No | Sweden | Vultr | dev |
| [gh.dev.odyssey346.dev](https://gh.dev.odyssey346.dev) | No | France | OVHcloud (Trolling Solutions) | dev |
| [gothub.dev.projectsegfau.lt](https://gothub.dev.projectsegfau.lt) | No | Luxembourg | BuyVM | dev |
From bf64cedb0819382de68a50007a6fc24058bfe8b2 Mon Sep 17 00:00:00 2001
From: Arya Kiran
Date: Wed, 10 May 2023 13:33:55 +0530
Subject: [PATCH 3/4] add master/dev clarification in compose file
---
compose.yml | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/compose.yml b/compose.yml
index a64c0db..e01b09b 100644
--- a/compose.yml
+++ b/compose.yml
@@ -1,7 +1,7 @@
version: "3"
services:
gothub:
- image: codeberg.org/gothub/gothub:latest
+ image: codeberg.org/gothub/gothub:latest # Master branch
# image: codeberg.org/gothub/gothub:dev # Dev branch
restart: unless-stopped
ports:
@@ -21,4 +21,4 @@ services:
test: wget -nv --tries=1 --spider http://127.0.0.1:3000/api/v1/version || exit 1
interval: 30s
timeout: 5s
- retries: 2
+ retries: 2
\ No newline at end of file
From aa94dcc60a565b7f974fa7daf80d8d70a5042105 Mon Sep 17 00:00:00 2001
From: Arya K
Date: Tue, 16 May 2023 12:42:17 +0000
Subject: [PATCH 4/4] add support for disabling proxying (#94)
fixes #45
Co-authored-by: Arya Kiran
Reviewed-on: https://codeberg.org/gothub/gothub/pulls/94
---
cmd/gothub/env.go | 2 ++
cmd/gothub/setup.go | 12 +++++++++
compose.yml | 1 +
pages/about.go | 2 ++
serve/serve.go | 62 ++++++++++++++++++++++++++++++++++-----------
views/about.html | 1 +
views/repo.html | 2 +-
7 files changed, 66 insertions(+), 16 deletions(-)
diff --git a/cmd/gothub/env.go b/cmd/gothub/env.go
index c286fb3..8c37e6b 100644
--- a/cmd/gothub/env.go
+++ b/cmd/gothub/env.go
@@ -29,6 +29,8 @@ func env() {
} else {
fmt.Println("Docker: false")
}
+ // Proxying
+ fmt.Println("Proxying: " + os.Getenv("GOTHUB_PROXYING_ENABLED"))
// IP logging
fmt.Println("IP logging: " + os.Getenv("GOTHUB_IP_LOGGED"))
// URL request logging
diff --git a/cmd/gothub/setup.go b/cmd/gothub/setup.go
index 08b35e5..b755de9 100644
--- a/cmd/gothub/setup.go
+++ b/cmd/gothub/setup.go
@@ -29,6 +29,7 @@ type Vars struct {
InstanceCountry string
InstanceProvider string
CloudflareStatus string
+ Proxying string
}
func setup() {
@@ -130,6 +131,16 @@ func setup() {
vars.CloudflareStatus = "false"
}
+ // ask user whether they want proxying enabled
+ fmt.Print("Do you want proxying enabled? (y/n) ")
+ var proxying string
+ fmt.Scanln(&proxying)
+ if proxying == "y" {
+ vars.Proxying = "true"
+ } else {
+ vars.Proxying = "false"
+ }
+
// save to .env file
fmt.Println("Saving environment variables to .env file...")
f, err := os.Create(".env")
@@ -151,6 +162,7 @@ func setup() {
f.WriteString("GOTHUB_INSTANCE_COUNTRY=" + vars.InstanceCountry + "\n")
f.WriteString("GOTHUB_INSTANCE_PROVIDER=" + vars.InstanceProvider + "\n")
f.WriteString("GOTHUB_INSTANCE_CLOUDFLARE=" + vars.CloudflareStatus)
+ f.WriteString("GOTHUB_PROXYING_ENABLED=" + vars.Proxying)
println("All done! You can now start your GotHub instance with 'gothub serve'.")
println("You can review the environment variables with 'gothub env'.")
diff --git a/compose.yml b/compose.yml
index e01b09b..ae3ec24 100644
--- a/compose.yml
+++ b/compose.yml
@@ -9,6 +9,7 @@ services:
environment:
- DOCKER=true
- GOTHUB_SETUP_COMPLETE=false
+ - GOTHUB_PROXYING_ENABLED=true/false
- GOTHUB_IP_LOGGED=true/false
- GOTHUB_REQUEST_URL_LOGGED=true/false
- GOTHUB_USER_AGENT_LOGGED=true/false
diff --git a/pages/about.go b/pages/about.go
index e7ce9bd..fde51c4 100644
--- a/pages/about.go
+++ b/pages/about.go
@@ -8,6 +8,7 @@ import (
)
type PrivacyInfo struct {
+ ProxyEnabled string
IPAddr string
ReqURL string
UserAgent string
@@ -24,6 +25,7 @@ type PrivacyInfo struct {
func HandleAbout(c *fiber.Ctx) error {
var privacyInfoArray []PrivacyInfo
privacyInfoArray = append(privacyInfoArray, PrivacyInfo{
+ ProxyEnabled: os.Getenv("GOTHUB_PROXYING_ENABLED"),
IPAddr: os.Getenv("GOTHUB_IP_LOGGED"),
ReqURL: os.Getenv("GOTHUB_REQUEST_URL_LOGGED"),
UserAgent: os.Getenv("GOTHUB_USER_AGENT_LOGGED"),
diff --git a/serve/serve.go b/serve/serve.go
index 3c0fcdc..58dd360 100644
--- a/serve/serve.go
+++ b/serve/serve.go
@@ -86,13 +86,21 @@ func Serve(port string) {
MaxAge: 31536000,
}
+ proxying, ok := os.LookupEnv("GOTHUB_PROXYING_ENABLED")
+ if !ok {
+ proxying = "true"
+ }
// add global headers
app.Use(func(c *fiber.Ctx) error {
c.Set("X-Frame-Options", "SAMEORIGIN")
c.Set("X-XSS-Protection", "1; mode=block")
c.Set("X-Content-Type-Options", "nosniff")
c.Set("Referrer-Policy", "no-referrer")
- c.Set("Content-Security-Policy", "default-src 'self'; style-src 'self' 'unsafe-inline'; img-src 'self' data; font-src 'self'; script-src 'self'; frame-ancestors 'self'; form-action 'self'; base-uri 'self'; connect-src 'self';")
+ if proxying == "true" {
+ c.Set("Content-Security-Policy", "default-src 'self'; style-src 'self' 'unsafe-inline'; img-src 'self' data; font-src 'self'; script-src 'self'; frame-ancestors 'self'; form-action 'self'; base-uri 'self'; connect-src 'self';")
+ } else {
+ c.Set("Content-Security-Policy", "default-src 'self' https://camo.githubusercontent.com https://avatars.githubusercontent.com https://github.com https://raw.githubusercontent.com https://gist.github.com; script-src 'self'; style-src 'self' 'unsafe-inline'; img-src 'self' data https://camo.githubusercontent.com https://avatars.githubusercontent.com https://gist.github.com; font-src 'self'; connect-src 'self' https://camo.githubusercontent.com https://avatars.githubusercontent.com https://github.com https://raw.githubusercontent.com https://gist.github.com; frame-ancestors 'self'; form-action 'self'; base-uri 'self'")
+ }
c.Set("Strict-Transport-Security", "max-age=31536000; includeSubDomains; preload")
return c.Next()
@@ -107,30 +115,54 @@ func Serve(port string) {
app.Get("/explore", ratelimiter, pages.HandleExplore)
app.Get("/:user", pages.HandleUser)
app.Get("/avatar/:id", func(c *fiber.Ctx) error {
- utils.ProxyRequest(c, "https://avatars.githubusercontent.com/u/"+c.Params("id")+"?v=4")
- return nil
+ if proxying == "true" {
+ utils.ProxyRequest(c, "https://avatars.githubusercontent.com/u/"+c.Params("id")+"?v=4")
+ return nil
+ } else {
+ c.Redirect("https://avatars.githubusercontent.com/u/" + c.Params("id") + "?v=4")
+ return nil
+ }
})
app.Get("/:user/:repo", pages.HandleRepo)
app.Get("/:user/:repo/blob/:branch/+", pages.FileView)
app.Get("/:user/:repo/tree/:branch/+", pages.DirView)
app.Get("/:user/:repo/tree/:branch", pages.HandleRepo)
- app.Get("/download/:user/:repo/:branch", func(c *fiber.Ctx) error {
- utils.ProxyRequest(c, "https://github.com/"+c.Params("user")+"/"+c.Params("repo")+"/archive/"+c.Params("branch")+".zip")
- return nil
+ app.Get("/:user/:repo/archive/:branch", func(c *fiber.Ctx) error {
+ if proxying == "true" {
+ utils.ProxyRequest(c, "https://github.com/"+c.Params("user")+"/"+c.Params("repo")+"/archive/"+c.Params("branch"))
+ return nil
+ } else {
+ c.Redirect("https://github.com/" + c.Params("user") + "/" + c.Params("repo") + "/archive/" + c.Params("branch"))
+ return nil
+ }
+ })
+ app.Get("/raw/:user/:repo/:branch/+", func(c *fiber.Ctx) error {
+ if proxying == "true" {
+ utils.ProxyRequest(c, "https://raw.githubusercontent.com/"+c.Params("user")+"/"+c.Params("repo")+"/"+c.Params("branch")+"/"+c.Params("+"))
+ return nil
+ } else {
+ c.Redirect("https://raw.githubusercontent.com/" + c.Params("user") + "/" + c.Params("repo") + "/" + c.Params("branch") + "/" + c.Params("+"))
+ return nil
+ }
})
app.Get("/camo/:p1/:p2", func(c *fiber.Ctx) error {
- utils.ProxyRequest(c, "https://camo.githubusercontent.com/"+c.Params("p1")+"/"+c.Params("p2"))
- return nil
+ if proxying == "true" {
+ utils.ProxyRequest(c, "https://camo.githubusercontent.com/"+c.Params("p1")+"/"+c.Params("p2"))
+ return nil
+ } else {
+ c.Redirect("https://camo.githubusercontent.com/"+c.Params("p1")+"/"+c.Params("p2"))
+ return nil
+ }
})
app.Get("/gist/:user/:gistID", pages.HandleGist)
app.Get("/download/gist/:user/:gistID/:revision", func(c *fiber.Ctx) error {
- utils.ProxyRequest(c, "https://gist.github.com/"+c.Params("user")+"/"+c.Params("gistID")+"/archive/"+c.Params("revision")+".zip")
- return nil
- })
-
- app.Get("/raw/:user/:repo/:branch/:file", func(c *fiber.Ctx) error {
- utils.ProxyRequest(c, "https://raw.githubusercontent.com/"+c.Params("user")+"/"+c.Params("repo")+"/"+c.Params("branch")+"/"+c.Params("file"))
- return nil
+ if proxying == "true" {
+ utils.ProxyRequest(c, "https://gist.github.com/"+c.Params("user")+"/"+c.Params("gistID")+"/archive/"+c.Params("revision")+".zip")
+ return nil
+ } else {
+ c.Redirect("https://gist.github.com/"+c.Params("user")+"/"+c.Params("gistID")+"/archive/"+c.Params("revision")+".zip")
+ return nil
+ }
})
api := app.Group("/api")
diff --git a/views/about.html b/views/about.html
index abf80a0..fe30323 100644
--- a/views/about.html
+++ b/views/about.html
@@ -10,6 +10,7 @@
If this page isn't filled, please contact your instance's maintainer.
+ - Proxying enabled: {{.ProxyEnabled}}
- IP Address logged: {{.IPAddr}}
- Request URL logged: {{.ReqURL}}
- User Agent logged: {{.UserAgent}}
diff --git a/views/repo.html b/views/repo.html
index 0fb36ae..e5816de 100644
--- a/views/repo.html
+++ b/views/repo.html
@@ -3,7 +3,7 @@
{{ if .repo }} {{ range $key, $value := .repo}}