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
|
||||||
javascript:window.location.href="http://localhost:8080/"+location.href
|
javascript:window.location.href="http://localhost:8080/"+location.href
|
||||||
```
|
```
|
||||||
|
### Outline
|
||||||
|
```bash
|
||||||
|
curl -X GET "http://localhost:8080/outline/https://www.example.com"
|
||||||
|
```
|
||||||
|
|
||||||
### API
|
### API
|
||||||
```bash
|
```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
|
### RAW
|
||||||
http://localhost:8080/raw/https://www.example.com
|
http://localhost:8080/api/raw/https://www.example.com
|
||||||
|
|
||||||
|
|
||||||
### Running Ruleset
|
### Running Ruleset
|
||||||
http://localhost:8080/ruleset
|
http://localhost:8080/api/ruleset
|
||||||
|
|
||||||
|
### Running Rule
|
||||||
|
http://localhost:8080/api/ruleset/https://example.com
|
||||||
|
|
||||||
## Configuration
|
## Configuration
|
||||||
|
|
||||||
|
|||||||
@@ -167,10 +167,10 @@ func main() {
|
|||||||
|
|
||||||
app.Get("styles.css", handlers.Styles)
|
app.Get("styles.css", handlers.Styles)
|
||||||
app.Get("script.js", handlers.Script)
|
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("api/content/*", handlers.NewAPIContentHandler("api/outline/*", proxyOpts))
|
||||||
|
|
||||||
app.Get("outline/*", handlers.NewOutlineHandler("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
|
// a specific rule was requested by path /ruleset/https://example.com
|
||||||
// return only that particular rule
|
// return only that particular rule
|
||||||
reqURL, err := extractURLFromContext(c, "ruleset/")
|
reqURL, err := extractURLFromContext(c, "api/ruleset/")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
package ruleset_v2
|
package ruleset_v2
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
//"bytes"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"gopkg.in/yaml.v3"
|
//"gopkg.in/yaml.v3"
|
||||||
"ladder/proxychain"
|
"ladder/proxychain"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -129,15 +129,9 @@ func (rule *Rule) MarshalYAML() (interface{}, error) {
|
|||||||
ResponseModifications []_rsm `yaml:"responsemodifications"`
|
ResponseModifications []_rsm `yaml:"responsemodifications"`
|
||||||
}
|
}
|
||||||
|
|
||||||
aux := &Aux{
|
return &Aux{
|
||||||
Domains: rule.Domains,
|
Domains: rule.Domains,
|
||||||
RequestModifications: rule._rqms,
|
RequestModifications: rule._rqms,
|
||||||
ResponseModifications: rule._rsms,
|
ResponseModifications: rule._rsms,
|
||||||
}
|
}, nil
|
||||||
|
|
||||||
var b bytes.Buffer
|
|
||||||
y := yaml.NewEncoder(&b)
|
|
||||||
y.SetIndent(2)
|
|
||||||
err := y.Encode(aux)
|
|
||||||
return b.String(), err
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
package ruleset_v2
|
package ruleset_v2
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
//"bytes"
|
||||||
"compress/gzip"
|
"compress/gzip"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
@@ -81,13 +81,16 @@ func (rs *Ruleset) MarshalYAML() (interface{}, error) {
|
|||||||
}
|
}
|
||||||
aux.Rules = append(aux.Rules, auxRule)
|
aux.Rules = append(aux.Rules, auxRule)
|
||||||
}
|
}
|
||||||
|
return aux, nil
|
||||||
|
|
||||||
|
/*
|
||||||
var b bytes.Buffer
|
var b bytes.Buffer
|
||||||
y := yaml.NewEncoder(&b)
|
y := yaml.NewEncoder(&b)
|
||||||
y.SetIndent(2)
|
y.SetIndent(2)
|
||||||
err := y.Encode(&aux)
|
err := y.Encode(&aux)
|
||||||
|
|
||||||
return b.String(), err
|
return b.String(), err
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
// ==========================================================
|
// ==========================================================
|
||||||
@@ -320,27 +323,20 @@ func (rs *Ruleset) loadRulesFromRemoteFile(rulesURL string) error {
|
|||||||
|
|
||||||
// YAML returns the ruleset as a Yaml string
|
// YAML returns the ruleset as a Yaml string
|
||||||
func (rs Ruleset) YAML() (string, error) {
|
func (rs Ruleset) YAML() (string, error) {
|
||||||
y, err := yaml.Marshal(rs)
|
yml, err := yaml.Marshal(&rs)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
return string(yml), nil
|
||||||
// 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
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// JSON returns the ruleset as a JSON string
|
// JSON returns the ruleset as a JSON string
|
||||||
func (rs Ruleset) JSON() (string, error) {
|
func (rs Ruleset) JSON() (string, error) {
|
||||||
j, err := json.Marshal(rs)
|
jsn, err := json.Marshal(&rs)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
return string(j), nil
|
return string(jsn), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Domains extracts and returns a slice of all domains present in the RuleSet.
|
// Domains extracts and returns a slice of all domains present in the RuleSet.
|
||||||
|
|||||||
Reference in New Issue
Block a user