implement local ruleset
This commit is contained in:
@@ -29,6 +29,7 @@ Freedom of information is an essential pillar of democracy and informed decision
|
|||||||
- [x] Basic Auth
|
- [x] Basic Auth
|
||||||
- [x] Disable logs
|
- [x] Disable logs
|
||||||
- [x] No Tracking
|
- [x] No Tracking
|
||||||
|
- [ ] Limit the proxy to a list of domains
|
||||||
- [ ] Optional TOR proxy
|
- [ ] Optional TOR proxy
|
||||||
- [ ] A key to share only one URL
|
- [ ] A key to share only one URL
|
||||||
- [ ] Fetch from Google Cache if not available
|
- [ ] Fetch from Google Cache if not available
|
||||||
@@ -80,7 +81,7 @@ http://localhost:8080/raw/https://www.example.com
|
|||||||
|
|
||||||
### Environment Variables
|
### Environment Variables
|
||||||
|
|
||||||
| Variable | Description | Default |
|
| Variable | Description | Value |
|
||||||
| --- | --- | --- |
|
| --- | --- | --- |
|
||||||
| `PORT` | Port to listen on | `8080` |
|
| `PORT` | Port to listen on | `8080` |
|
||||||
| `PREFORK` | Spawn multiple server instances | `false` |
|
| `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` |
|
| `LOG_URLS` | Log fetched URL's | `true` |
|
||||||
| `DISABLE_FORM` | Disables URL Form Frontpage | `false` |
|
| `DISABLE_FORM` | Disables URL Form Frontpage | `false` |
|
||||||
| `FORM_PATH` | Path to custom Form HTML | `` |
|
| `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
|
### Ruleset
|
||||||
|
|
||||||
|
|||||||
@@ -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, "url(/", "url(/https://"+u.Host+"/")
|
||||||
body = strings.ReplaceAll(body, "href=\"https://"+u.Host, "href=\"/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)
|
body = applyRules(u.Host, u.Path, body)
|
||||||
}
|
}
|
||||||
return body
|
return body
|
||||||
@@ -113,13 +113,16 @@ func getenv(key, fallback string) string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func loadRules() RuleSet {
|
func loadRules() RuleSet {
|
||||||
rulesUrl := os.Getenv("RULES_URL")
|
rulesUrl := os.Getenv("RULESET")
|
||||||
if rulesUrl == "" {
|
if rulesUrl == "" {
|
||||||
RulesList := RuleSet{}
|
RulesList := RuleSet{}
|
||||||
return RulesList
|
return RulesList
|
||||||
}
|
}
|
||||||
log.Println("Loading rules")
|
log.Println("Loading rules")
|
||||||
|
|
||||||
|
var ruleSet RuleSet
|
||||||
|
if strings.HasPrefix(rulesUrl, "http") {
|
||||||
|
|
||||||
resp, err := http.Get(rulesUrl)
|
resp, err := http.Get(rulesUrl)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println("ERROR:", err)
|
log.Println("ERROR:", err)
|
||||||
@@ -134,12 +137,18 @@ func loadRules() RuleSet {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println("ERROR:", err)
|
log.Println("ERROR:", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
var ruleSet RuleSet
|
|
||||||
yaml.Unmarshal(body, &ruleSet)
|
yaml.Unmarshal(body, &ruleSet)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println("ERROR:", err)
|
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")
|
log.Println("Loaded rules for", len(ruleSet), "Domains")
|
||||||
return ruleSet
|
return ruleSet
|
||||||
|
|||||||
22
ruleset.yaml
22
ruleset.yaml
@@ -10,16 +10,14 @@
|
|||||||
console.log("test");
|
console.log("test");
|
||||||
alert("Hello!");
|
alert("Hello!");
|
||||||
</script>
|
</script>
|
||||||
- domain: www.anotherdomain.com # Domain where the rule applies
|
- domain: www.americanbanker.com
|
||||||
path: /article # Path where the rule applies
|
googleCache: false
|
||||||
googleCache: false # Search also in Google Cache
|
|
||||||
regexRules: # Regex rules to apply
|
|
||||||
- match: <script\s+([^>]*\s+)?src="(/)([^"]*)"
|
|
||||||
replace: <script $1 script="/https://www.example.com/$3"
|
|
||||||
injections:
|
injections:
|
||||||
- position: .left-content article .post-title # Position where to inject the code into DOM
|
- position: head
|
||||||
replace: |
|
append: |
|
||||||
<h1>My Custom Title</h1>
|
const inlineGate = document.querySelector('.inline-gate');
|
||||||
- position: .left-content article # Position where to inject the code into DOM
|
if (inlineGate) {
|
||||||
prepend: |
|
inlineGate.classList.remove('inline-gate');
|
||||||
<h2>Suptitle</h2>
|
const inlineGated = document.querySelectorAll('.inline-gated');
|
||||||
|
for (const elem of inlineGated) { elem.classList.remove('inline-gated'); }
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user