| 1 |
package updatescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/update`/ |
| 2 |
|
| 3 |
import ( |
| 4 |
"mathscip-go gomod github.com/golang/go/src go1.16 math/" |
| 5 |
"strconvscip-go gomod github.com/golang/go/src go1.16 strconv/" |
| 6 |
"stringsscip-go gomod github.com/golang/go/src go1.16 strings/" |
| 7 |
|
| 8 |
"github.com/bettercap/bettercap/sessionscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/" |
| 9 |
|
| 10 |
"github.com/google/go-github/githubscip-go gomod github.com/google/go-github v17.0.0 `github.com/google/go-github/github`/" |
| 11 |
|
| 12 |
) |
| 13 |
|
| 14 |
type UpdateModulescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/update`/UpdateModule# struct { |
| 15 |
sessionscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/.SessionModulescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/update`/UpdateModule#SessionModule. |
| 16 |
clientscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/update`/UpdateModule#client. *githubscip-go gomod github.com/google/go-github v17.0.0 `github.com/google/go-github/github`/.Clientscip-go gomod github.com/google/go-github v17.0.0 `github.com/google/go-github/github`/Client# |
| 17 |
} |
| 18 |
|
| 19 |
func NewUpdateModulescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/update`/NewUpdateModule().(s *sessionscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/.Sessionscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/Session#) *UpdateModulescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/update`/UpdateModule# { |
| 20 |
mod := &UpdateModulescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/update`/UpdateModule#{ |
| 21 |
SessionModulescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/update`/UpdateModule#SessionModule.: sessionscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/.NewSessionModulescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/NewSessionModule().("update", s), |
| 22 |
clientscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/update`/UpdateModule#client.: githubscip-go gomod github.com/google/go-github v17.0.0 `github.com/google/go-github/github`/.NewClientscip-go gomod github.com/google/go-github v17.0.0 `github.com/google/go-github/github`/NewClient().(nil), |
| 23 |
} |
| 24 |
|
| 25 |
mod.AddHandlerscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/SessionModule#AddHandler().(sessionscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/.NewModuleHandlerscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/NewModuleHandler().("update.check on", "", |
| 26 |
"Check latest available stable version and compare it with the one being used.", |
| 27 |
func(args []string) error { |
| 28 |
return mod.Startscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/update`/UpdateModule#Start().() |
| 29 |
})) |
| 30 |
|
| 31 |
return mod |
| 32 |
} |
| 33 |
|
| 34 |
func (mod *UpdateModulescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/update`/UpdateModule#) Namescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/update`/UpdateModule#Name().() string { |
| 35 |
return "update" |
| 36 |
} |
| 37 |
|
| 38 |
func (mod *UpdateModulescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/update`/UpdateModule#) Descriptionscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/update`/UpdateModule#Description().() string { |
| 39 |
return "A module to check for bettercap's updates." |
| 40 |
} |
| 41 |
|
| 42 |
func (mod *UpdateModulescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/update`/UpdateModule#) Authorscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/update`/UpdateModule#Author().() string { |
| 43 |
return "Simone Margaritelli <[email protected]>" |
| 44 |
} |
| 45 |
|
| 46 |
func (mod *UpdateModulescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/update`/UpdateModule#) Configurescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/update`/UpdateModule#Configure().() error { |
| 47 |
return nil |
| 48 |
} |
| 49 |
|
| 50 |
func (mod *UpdateModulescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/update`/UpdateModule#) Stopscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/update`/UpdateModule#Stop().() error { |
| 51 |
return nil |
| 52 |
} |
| 53 |
|
| 54 |
func (mod *UpdateModulescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/update`/UpdateModule#) versionToNumscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/update`/UpdateModule#versionToNum().(ver string) float64 { |
| 55 |
if ver[0] == 'v' { |
| 56 |
ver = ver[1:] |
| 57 |
} |
| 58 |
|
| 59 |
n := 0.0 |
| 60 |
parts := stringsscip-go gomod github.com/golang/go/src go1.16 strings/.Splitscip-go gomod github.com/golang/go/src go1.16 strings/Split().(ver, ".") |
| 61 |
nparts := len(parts) |
| 62 |
|
| 63 |
// reverse |
| 64 |
for i := nparts/2 - 1; i >= 0; i-- { |
| 65 |
opp := nparts - 1 - i |
| 66 |
parts[i], parts[opp] = parts[opp], parts[i] |
| 67 |
} |
| 68 |
|
| 69 |
for i, e := range parts { |
| 70 |
ev, _ := strconvscip-go gomod github.com/golang/go/src go1.16 strconv/.Atoiscip-go gomod github.com/golang/go/src go1.16 strconv/Atoi().(e) |
| 71 |
n += float64(ev) * mathscip-go gomod github.com/golang/go/src go1.16 math/.Pow10scip-go gomod github.com/golang/go/src go1.16 math/Pow10().(i) |
| 72 |
} |
| 73 |
|
| 74 |
return n |
| 75 |
} |
| 76 |
|
| 77 |
func (mod *UpdateModulescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/update`/UpdateModule#) Startscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/update`/UpdateModule#Start().() error { |
| 78 |
return mod.SetRunningscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/SessionModule#SetRunning().(true, func() { |
| 79 |
defer mod.SetRunningscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/SessionModule#SetRunning().(false, nil) |
| 80 |
|
| •81 |
mod.Infoscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/SessionModule#Info().("this command is inactive in Debian.") |
| 82 |
}) |
| 83 |
} |