diff --git a/README.md b/README.md index 37dcbc4..a7b4092 100644 --- a/README.md +++ b/README.md @@ -29,6 +29,7 @@ Freedom of information is an essential pillar of democracy and informed decision - [x] Basic Auth - [x] Disable logs - [x] No Tracking +- [ ] Limit the proxy to a list of domains - [ ] Optional TOR proxy - [ ] A key to share only one URL - [ ] Fetch from Google Cache if not available @@ -80,7 +81,7 @@ http://localhost:8080/raw/https://www.example.com ### Environment Variables -| Variable | Description | Default | +| Variable | Description | Value | | --- | --- | --- | | `PORT` | Port to listen on | `8080` | | `PREFORK` | Spawn multiple server instances | `false` | @@ -90,7 +91,7 @@ http://localhost:8080/raw/https://www.example.com | `LOG_URLS` | Log fetched URL's | `true` | | `DISABLE_FORM` | Disables URL Form Frontpage | `false` | | `FORM_PATH` | Path to custom Form HTML | `` | -| `RULES_URL` | URL to a ruleset file | `https://raw.githubusercontent.com/kubero-dev/ladder/main/ruleset.yaml` | +| `RULESET` | URL to a ruleset file | `https://raw.githubusercontent.com/kubero-dev/ladder/main/ruleset.yaml` or `/path/to/my/rules.yaml` | ### Ruleset diff --git a/handlers/proxy.go b/handlers/proxy.go index 7128c2b..16c29de 100644 --- a/handlers/proxy.go +++ b/handlers/proxy.go @@ -98,7 +98,7 @@ func rewriteHtml(bodyB []byte, u *url.URL) string { body = strings.ReplaceAll(body, "url(/", "url(/https://"+u.Host+"/") body = strings.ReplaceAll(body, "href=\"https://"+u.Host, "href=\"/https://"+u.Host+"/") - if os.Getenv("RULES_URL") != "" { + if os.Getenv("RULESET") != "" { body = applyRules(u.Host, u.Path, body) } return body @@ -113,32 +113,41 @@ func getenv(key, fallback string) string { } func loadRules() RuleSet { - rulesUrl := os.Getenv("RULES_URL") + rulesUrl := os.Getenv("RULESET") if rulesUrl == "" { RulesList := RuleSet{} return RulesList } log.Println("Loading rules") - resp, err := http.Get(rulesUrl) - if err != nil { - log.Println("ERROR:", err) - } - defer resp.Body.Close() - - if resp.StatusCode >= 400 { - log.Println("ERROR:", resp.StatusCode, rulesUrl) - } - - body, err := io.ReadAll(resp.Body) - if err != nil { - log.Println("ERROR:", err) - } - var ruleSet RuleSet - yaml.Unmarshal(body, &ruleSet) - if err != nil { - log.Println("ERROR:", err) + if strings.HasPrefix(rulesUrl, "http") { + + resp, err := http.Get(rulesUrl) + if err != nil { + log.Println("ERROR:", err) + } + defer resp.Body.Close() + + if resp.StatusCode >= 400 { + log.Println("ERROR:", resp.StatusCode, rulesUrl) + } + + body, err := io.ReadAll(resp.Body) + if err != nil { + log.Println("ERROR:", err) + } + yaml.Unmarshal(body, &ruleSet) + + if err != nil { + log.Println("ERROR:", err) + } + } else { + yamlFile, err := os.ReadFile(rulesUrl) + if err != nil { + log.Println("ERROR:", err) + } + yaml.Unmarshal(yamlFile, &ruleSet) } log.Println("Loaded rules for", len(ruleSet), "Domains") diff --git a/ruleset.yaml b/ruleset.yaml index 1fd2011..f0a4419 100644 --- a/ruleset.yaml +++ b/ruleset.yaml @@ -10,16 +10,14 @@ console.log("test"); alert("Hello!"); -- domain: www.anotherdomain.com # Domain where the rule applies - path: /article # Path where the rule applies - googleCache: false # Search also in Google Cache - regexRules: # Regex rules to apply - - match: ]*\s+)?src="(/)([^"]*)" - replace: