allow domain list in rules
This commit is contained in:
@@ -121,12 +121,15 @@ See in [ruleset.yaml](ruleset.yaml) for an example.
|
|||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
- domain: www.example.com
|
- domain: www.example.com
|
||||||
|
domains: # Additional domains to apply the rule
|
||||||
|
- www.example.com
|
||||||
|
- www.beispiel.de
|
||||||
regexRules:
|
regexRules:
|
||||||
- match: <script\s+([^>]*\s+)?src="(/)([^"]*)"
|
- match: <script\s+([^>]*\s+)?src="(/)([^"]*)"
|
||||||
replace: <script $1 script="/https://www.example.com/$3"
|
replace: <script $1 script="/https://www.example.com/$3"
|
||||||
injections:
|
injections:
|
||||||
- position: head # Position where to inject the code
|
- position: head # Position where to inject the code
|
||||||
append: |
|
append: | # possible keys: append, prepend, replace
|
||||||
<script>
|
<script>
|
||||||
window.localStorage.clear();
|
window.localStorage.clear();
|
||||||
console.log("test");
|
console.log("test");
|
||||||
|
|||||||
@@ -155,14 +155,17 @@ func loadRules() RuleSet {
|
|||||||
yaml.Unmarshal(yamlFile, &ruleSet)
|
yaml.Unmarshal(yamlFile, &ruleSet)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
domains := []string{}
|
||||||
for _, rule := range ruleSet {
|
for _, rule := range ruleSet {
|
||||||
//log.Println("Loaded rules for", rule.Domain)
|
|
||||||
|
domains = append(domains, rule.Domain)
|
||||||
|
domains = append(domains, rule.Domains...)
|
||||||
if os.Getenv("ALLOWED_DOMAINS_RULESET") == "true" {
|
if os.Getenv("ALLOWED_DOMAINS_RULESET") == "true" {
|
||||||
allowedDomains = append(allowedDomains, rule.Domain)
|
allowedDomains = append(allowedDomains, domains...)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Println("Loaded rules for", len(ruleSet), "Domains")
|
log.Println("Loaded ", len(ruleSet), " rules for", len(domains), "Domains")
|
||||||
return ruleSet
|
return ruleSet
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -172,8 +175,8 @@ func applyRules(domain string, path string, body string) string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, rule := range rulesSet {
|
for _, rule := range rulesSet {
|
||||||
// rule.Domain can be multiple domains delimited by "|"
|
domains := rule.Domains
|
||||||
domains := strings.Split(rule.Domain, "|")
|
domains = append(domains, rule.Domain)
|
||||||
for _, ruleDomain := range domains {
|
for _, ruleDomain := range domains {
|
||||||
if ruleDomain != domain {
|
if ruleDomain != domain {
|
||||||
continue
|
continue
|
||||||
@@ -217,6 +220,7 @@ type Rule struct {
|
|||||||
|
|
||||||
type RuleSet []struct {
|
type RuleSet []struct {
|
||||||
Domain string `yaml:"domain"`
|
Domain string `yaml:"domain"`
|
||||||
|
Domains []string `yaml:"domains,omitempty"`
|
||||||
Paths []string `yaml:"paths,omitempty"`
|
Paths []string `yaml:"paths,omitempty"`
|
||||||
GoogleCache bool `yaml:"googleCache,omitempty"`
|
GoogleCache bool `yaml:"googleCache,omitempty"`
|
||||||
RegexRules []Rule `yaml:"regexRules"`
|
RegexRules []Rule `yaml:"regexRules"`
|
||||||
|
|||||||
26
ruleset.yaml
26
ruleset.yaml
@@ -1,4 +1,6 @@
|
|||||||
- domain: www.example.com
|
- domain: www.example.com
|
||||||
|
domains:
|
||||||
|
- www.beispiel.com
|
||||||
regexRules:
|
regexRules:
|
||||||
- match: <script\s+([^>]*\s+)?src="(/)([^"]*)"
|
- match: <script\s+([^>]*\s+)?src="(/)([^"]*)"
|
||||||
replace: <script $1 script="/https://www.example.com/$3"
|
replace: <script $1 script="/https://www.example.com/$3"
|
||||||
@@ -53,7 +55,16 @@
|
|||||||
removeDOMElement(paywall)
|
removeDOMElement(paywall)
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
- domain: www.architecturaldigest.com|www.bonappetit.com|www.cntraveler.com|www.epicurious.com|www.gq.com|www.newyorker.com|www.vanityfair.com|www.vogue.com|www.wired.com
|
- domains:
|
||||||
|
- www.architecturaldigest.com
|
||||||
|
- www.bonappetit.com
|
||||||
|
- www.cntraveler.com
|
||||||
|
- www.epicurious.com
|
||||||
|
- www.gq.com
|
||||||
|
- www.newyorker.com
|
||||||
|
- www.vanityfair.com
|
||||||
|
- www.vogue.com
|
||||||
|
- www.wired.com
|
||||||
injections:
|
injections:
|
||||||
- position: head
|
- position: head
|
||||||
append: |
|
append: |
|
||||||
@@ -63,7 +74,9 @@
|
|||||||
banners.forEach(el => { el.remove(); });
|
banners.forEach(el => { el.remove(); });
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
- domain: www.nytimes.com|www.time.com
|
- domains:
|
||||||
|
- www.nytimes.com
|
||||||
|
- www.time.com
|
||||||
injections:
|
injections:
|
||||||
- position: head
|
- position: head
|
||||||
append: |
|
append: |
|
||||||
@@ -74,7 +87,14 @@
|
|||||||
banners.forEach(el => { el.remove(); });
|
banners.forEach(el => { el.remove(); });
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
- domain: www.thestar.com|www.niagarafallsreview.ca|www.stcatharinesstandard.ca|www.thepeterboroughexaminer.com|www.therecord.com|www.thespec.com|www.wellandtribune.ca
|
- domains:
|
||||||
|
- www.thestar.com
|
||||||
|
- www.niagarafallsreview.ca
|
||||||
|
- www.stcatharinesstandard.ca
|
||||||
|
- www.thepeterboroughexaminer.com
|
||||||
|
- www.therecord.com
|
||||||
|
- www.thespec.com
|
||||||
|
- www.wellandtribune.ca
|
||||||
injections:
|
injections:
|
||||||
- position: head
|
- position: head
|
||||||
append: |
|
append: |
|
||||||
|
|||||||
Reference in New Issue
Block a user