move ruleset and raw endpoints to /api/*, update docs, fix ruleset yaml marshal panic issue
This commit is contained in:
13
README.md
13
README.md
@@ -91,18 +91,25 @@ Or create a bookmark with the following URL:
|
||||
```javascript
|
||||
javascript:window.location.href="http://localhost:8080/"+location.href
|
||||
```
|
||||
### Outline
|
||||
```bash
|
||||
curl -X GET "http://localhost:8080/outline/https://www.example.com"
|
||||
```
|
||||
|
||||
### API
|
||||
```bash
|
||||
curl -X GET "http://localhost:8080/api/https://www.example.com"
|
||||
curl -X GET "http://localhost:8080/api/content/https://www.example.com"
|
||||
```
|
||||
|
||||
### RAW
|
||||
http://localhost:8080/raw/https://www.example.com
|
||||
http://localhost:8080/api/raw/https://www.example.com
|
||||
|
||||
|
||||
### Running Ruleset
|
||||
http://localhost:8080/ruleset
|
||||
http://localhost:8080/api/ruleset
|
||||
|
||||
### Running Rule
|
||||
http://localhost:8080/api/ruleset/https://example.com
|
||||
|
||||
## Configuration
|
||||
|
||||
|
||||
@@ -167,10 +167,10 @@ func main() {
|
||||
|
||||
app.Get("styles.css", handlers.Styles)
|
||||
app.Get("script.js", handlers.Script)
|
||||
app.Get("ruleset/*", handlers.NewRulesetSiteHandler(proxyOpts))
|
||||
|
||||
app.All("raw/*", handlers.NewRawProxySiteHandler(proxyOpts))
|
||||
app.All("api/raw/*", handlers.NewRawProxySiteHandler(proxyOpts))
|
||||
|
||||
app.Get("api/ruleset/*", handlers.NewRulesetSiteHandler(proxyOpts))
|
||||
app.Get("api/content/*", handlers.NewAPIContentHandler("api/outline/*", proxyOpts))
|
||||
|
||||
app.Get("outline/*", handlers.NewOutlineHandler("outline/*", proxyOpts))
|
||||
|
||||
@@ -41,7 +41,7 @@ func NewRulesetSiteHandler(opts *ProxyOptions) fiber.Handler {
|
||||
|
||||
// a specific rule was requested by path /ruleset/https://example.com
|
||||
// return only that particular rule
|
||||
reqURL, err := extractURLFromContext(c, "ruleset/")
|
||||
reqURL, err := extractURLFromContext(c, "api/ruleset/")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
package ruleset_v2
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
//"bytes"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
|
||||
"gopkg.in/yaml.v3"
|
||||
//"gopkg.in/yaml.v3"
|
||||
"ladder/proxychain"
|
||||
)
|
||||
|
||||
@@ -129,15 +129,9 @@ func (rule *Rule) MarshalYAML() (interface{}, error) {
|
||||
ResponseModifications []_rsm `yaml:"responsemodifications"`
|
||||
}
|
||||
|
||||
aux := &Aux{
|
||||
return &Aux{
|
||||
Domains: rule.Domains,
|
||||
RequestModifications: rule._rqms,
|
||||
ResponseModifications: rule._rsms,
|
||||
}
|
||||
|
||||
var b bytes.Buffer
|
||||
y := yaml.NewEncoder(&b)
|
||||
y.SetIndent(2)
|
||||
err := y.Encode(aux)
|
||||
return b.String(), err
|
||||
}, nil
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package ruleset_v2
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
//"bytes"
|
||||
"compress/gzip"
|
||||
"errors"
|
||||
"fmt"
|
||||
@@ -81,13 +81,16 @@ func (rs *Ruleset) MarshalYAML() (interface{}, error) {
|
||||
}
|
||||
aux.Rules = append(aux.Rules, auxRule)
|
||||
}
|
||||
return aux, nil
|
||||
|
||||
/*
|
||||
var b bytes.Buffer
|
||||
y := yaml.NewEncoder(&b)
|
||||
y.SetIndent(2)
|
||||
err := y.Encode(&aux)
|
||||
|
||||
return b.String(), err
|
||||
*/
|
||||
}
|
||||
|
||||
// ==========================================================
|
||||
@@ -320,27 +323,20 @@ func (rs *Ruleset) loadRulesFromRemoteFile(rulesURL string) error {
|
||||
|
||||
// YAML returns the ruleset as a Yaml string
|
||||
func (rs Ruleset) YAML() (string, error) {
|
||||
y, err := yaml.Marshal(rs)
|
||||
yml, err := yaml.Marshal(&rs)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
// for some reason, MarshalYAML seems to turn everything into a string block
|
||||
// this is a workaround. Don't call yaml.Marshal directly, instead call this helper method.
|
||||
x := strings.ReplaceAll(string(y), "\n ", "\n")
|
||||
x = strings.Replace(x, "|\n", "", 1)
|
||||
fmt.Println(x)
|
||||
|
||||
return x, nil
|
||||
return string(yml), nil
|
||||
}
|
||||
|
||||
// JSON returns the ruleset as a JSON string
|
||||
func (rs Ruleset) JSON() (string, error) {
|
||||
j, err := json.Marshal(rs)
|
||||
jsn, err := json.Marshal(&rs)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return string(j), nil
|
||||
return string(jsn), nil
|
||||
}
|
||||
|
||||
// Domains extracts and returns a slice of all domains present in the RuleSet.
|
||||
|
||||
Reference in New Issue
Block a user