add support for disabling proxying

This commit is contained in:
Arya Kiran
2023-04-08 13:04:11 +05:30
parent f6ecbe4f99
commit ced35c4190
6 changed files with 48 additions and 8 deletions
+2
View File
@@ -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
+12
View File
@@ -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'.")
+1
View File
@@ -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
+1
View File
@@ -24,6 +24,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"),
+31 -8
View File
@@ -84,13 +84,19 @@ 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';")
}
c.Set("Strict-Transport-Security", "max-age=31536000; includeSubDomains; preload")
return c.Next()
@@ -105,20 +111,37 @@ 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
log.Println(proxying)
if proxying == "true" {
utils.ProxyRequest(c, "https://github.com/"+c.Params("user")+"/"+c.Params("repo")+"/archive/"+c.Params("branch")+".zip")
return nil
} else {
c.Redirect("https://github.com/" + c.Params("user") + "/" + c.Params("repo") + "/archive/" + c.Params("branch") + ".zip")
log.Println("no proxi")
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
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
}
})
api := app.Group("/api")
+1
View File
@@ -10,6 +10,7 @@
</p>
<p>If this page isn't filled, please contact your instance's maintainer.</p>
<ul>
<li><b>Proxying enabled:</b> {{.ProxyEnabled}}</li>
<li><b>IP Address logged:</b> {{.IPAddr}}</li>
<li><b>Request URL logged:</b> {{.ReqURL}}</li>
<li><b>User Agent logged:</b> {{.UserAgent}}</li>