This commit is contained in:
Arya Kiran
2023-05-16 21:03:22 +08:00
8 changed files with 77 additions and 22 deletions
+2 -2
View File
@@ -34,6 +34,8 @@ 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 |
| [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 |
@@ -43,8 +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.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 |
+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'.")
+3 -2
View File
@@ -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:
@@ -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
@@ -21,4 +22,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
+2
View File
@@ -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"),
+54 -17
View File
@@ -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,8 +115,13 @@ 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)
@@ -116,27 +129,51 @@ func Serve(port string) {
app.Get("/:user/:repo/releases/:release", pages.ReleaseView)
app.Get("/:user/:repo/releases/tag/:release", pages.ReleaseView)
app.Get("/:user/:repo/releases/download/:release/:item", func(c *fiber.Ctx) error {
utils.ProxyRequest(c, "https://github.com/"+c.Params("user")+"/"+c.Params("repo")+"/releases/download"+c.Params("release")/c.Params("item"))
return nil
if proxying == "true" {
utils.ProxyRequest(c, "https://github.com/"+c.Params("user")+"/"+c.Params("repo")+"/releases/download"+c.Params("release")+"/"+c.Params("item"))
return nil
} else {
c.Redirect("https://github.com/" + c.Params("user") + "/" + c.Params("repo") + "/releases/download" + c.Params("release") + "/" + c.Params("item"))
return nil
}
})
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")
+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>
+1 -1
View File
@@ -3,7 +3,7 @@
<main>
{{ if .repo }} {{ range $key, $value := .repo}}
<div class="button-parent">
<a href="/download/{{.Fullname}}/{{.DefaultBranch}}" class="button"
<a href="/{{.Fullname}}/archive/{{.DefaultBranch}}.zip" class="button"
>Download (zip)</a
>
<a rel="noreferrer" href="https://github.com/{{.Fullname}}" class="button"