WIP: Add rules argument

This commit is contained in:
Gianni Carafa
2023-11-06 14:50:33 +01:00
parent e3eb866d48
commit 797a33068d
4 changed files with 21 additions and 6 deletions

0
.github/pull_request_template.md vendored Normal file
View File

View File

@@ -96,7 +96,7 @@ http://localhost:8080/ruleset
| `LOG_URLS` | Log fetched URL's | `true` |
| `DISABLE_FORM` | Disables URL Form Frontpage | `false` |
| `FORM_PATH` | Path to custom Form HTML | `` |
| `RULESET` | URL to a ruleset file | `https://raw.githubusercontent.com/kubero-dev/ladder/main/ruleset.yaml` or `/path/to/my/rules.yaml` |
| `RULESET` | URL to a ruleset file | `https://raw.githubusercontent.com/kubero-dev/ladder/main/ruleset.yaml` or `/path/to/my/rules.yaml` or `default` |
| `EXPOSE_RULESET` | Make your Ruleset available to other ladders | `true` |
| `ALLOWED_DOMAINS` | Comma separated list of allowed domains. Empty = no limitations | `` |
| `ALLOWED_DOMAINS_RULESET` | Allow Domains from Ruleset. false = no limitations | `false` |

View File

@@ -33,12 +33,19 @@ func main() {
Help: "Port the webserver will listen on"})
pf, _ := strconv.ParseBool(os.Getenv("PREFORK"))
prefork := parser.Flag("P", "prefork", &argparse.Options{
Required: false,
Default: pf,
Help: "This will spawn multiple processes listening"})
r := os.Getenv("RULESET")
ruleset := parser.String("r", "ruleset", &argparse.Options{
Required: false,
Default: r,
Help: "Path or URL to your ruleset"})
handlers.LoadRules(*ruleset)
err := parser.Parse(os.Args)
if err != nil {
fmt.Print(parser.Usage(err))

View File

@@ -17,8 +17,11 @@ import (
var UserAgent = getenv("USER_AGENT", "Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)")
var ForwardedFor = getenv("X_FORWARDED_FOR", "66.249.66.1")
var rulesSet = loadRules()
var rulesSet RuleSet
// var rulesSet = loadRules()
var allowedDomains = strings.Split(os.Getenv("ALLOWED_DOMAINS"), ",")
var Aaaa = "aaaa"
func ProxySite(c *fiber.Ctx) error {
// Get the url from the URL
@@ -117,13 +120,18 @@ func getenv(key, fallback string) string {
return value
}
func loadRules() RuleSet {
rulesUrl := os.Getenv("RULESET")
func LoadRules(rulesUrl string) RuleSet {
//rulesUrl := os.Getenv("RULESET")
if rulesUrl == "" {
RulesList := RuleSet{}
return RulesList
}
log.Println("Loading rules")
if rulesUrl == "default" {
rulesUrl = "https://raw.githubusercontent.com/kubero-dev/ladder/main/ruleset.yaml"
}
log.Println("Loading rules: " + rulesUrl)
var ruleSet RuleSet
if strings.HasPrefix(rulesUrl, "http") {