mirror of
https://github.com/bettercap/bettercap
synced 2025-08-22 06:23:18 -07:00
Fix the hard coded ui path
Add new command "caplets.fixpaths": will fix the windows path problem Add new http Response attributes (ok, status, statusText)
This commit is contained in:
parent
9dd6145a39
commit
5a26110c69
4 changed files with 47 additions and 3 deletions
|
@ -28,6 +28,7 @@ func getUserHomeDir() string {
|
|||
}
|
||||
|
||||
var (
|
||||
UserHomePath = getUserHomeDir()
|
||||
InstallBase = getInstallBase()
|
||||
InstallPathArchive = filepath.Join(InstallBase, "caplets-master")
|
||||
InstallPath = filepath.Join(InstallBase, "caplets")
|
||||
|
@ -37,7 +38,7 @@ var (
|
|||
"./",
|
||||
"./caplets/",
|
||||
InstallPath,
|
||||
filepath.Join(getUserHomeDir(), "caplets"),
|
||||
filepath.Join(UserHomePath, "caplets"),
|
||||
}
|
||||
)
|
||||
|
||||
|
|
|
@ -3,12 +3,15 @@ package caplets
|
|||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"strings"
|
||||
|
||||
"github.com/bettercap/bettercap/caplets"
|
||||
"github.com/bettercap/bettercap/session"
|
||||
|
||||
"github.com/dustin/go-humanize"
|
||||
|
||||
"github.com/evilsocket/islazy/fs"
|
||||
|
@ -43,6 +46,42 @@ func NewCapletsModule(s *session.Session) *CapletsModule {
|
|||
return mod.Update()
|
||||
}))
|
||||
|
||||
mod.AddHandler(session.NewModuleHandler("caplets.fixpaths", "",
|
||||
"Fix the absolute caplets path.",
|
||||
func(args []string) error {
|
||||
re := regexp.MustCompile(`(~/|/usr/local/share/bettercap/)`)
|
||||
return filepath.Walk(caplets.InstallPath,
|
||||
func(path string, info os.FileInfo, err error) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if info.IsDir() || (filepath.Ext(path) != ".js" && filepath.Ext(path) != ".cap") {
|
||||
return nil
|
||||
}
|
||||
|
||||
raw, err := ioutil.ReadFile(path)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
res := re.ReplaceAllStringFunc(string(raw), func(value string) string {
|
||||
switch value {
|
||||
case "~/":
|
||||
return strings.Replace(caplets.UserHomePath, `\`, `/`, -1) + "/"
|
||||
case "/usr/local/share/bettercap/":
|
||||
return strings.Replace(caplets.InstallBase, `\`, `/`, -1) + "/"
|
||||
default:
|
||||
return value
|
||||
}
|
||||
})
|
||||
err = ioutil.WriteFile(path, []byte(res), info.Mode())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
})
|
||||
}))
|
||||
|
||||
return mod
|
||||
}
|
||||
|
||||
|
|
|
@ -10,6 +10,7 @@ import (
|
|||
"path/filepath"
|
||||
"regexp"
|
||||
|
||||
"github.com/bettercap/bettercap/caplets"
|
||||
"github.com/bettercap/bettercap/session"
|
||||
|
||||
"github.com/google/go-github/github"
|
||||
|
@ -36,7 +37,7 @@ func NewUIModule(s *session.Session) *UIModule {
|
|||
}
|
||||
|
||||
mod.AddParam(session.NewStringParameter("ui.basepath",
|
||||
"/usr/local/share/bettercap/",
|
||||
caplets.InstallBase,
|
||||
"",
|
||||
"UI base installation path."))
|
||||
|
||||
|
|
|
@ -297,6 +297,9 @@ func init() {
|
|||
return errOtto("Could not create response object: %s", err)
|
||||
}
|
||||
|
||||
err = object.Set("status", resp.StatusCode)
|
||||
err = object.Set("statusText", resp.Status)
|
||||
err = object.Set("ok", resp.StatusCode >= 200 && resp.StatusCode <= 299)
|
||||
err = object.Set("body", string(body))
|
||||
if err != nil {
|
||||
return errOtto("Could not populate response object: %s", err)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue