| 1 | package sessionscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/ |
| 2 | |
| 3 | import ( |
| 4 | "encoding/jsonscip-go gomod github.com/golang/go/src go1.16 `encoding/json`/" |
| 5 | "fmtscip-go gomod github.com/golang/go/src go1.16 fmt/" |
| 6 | "io/ioutilscip-go gomod github.com/golang/go/src go1.16 `io/ioutil`/" |
| 7 | "sortscip-go gomod github.com/golang/go/src go1.16 sort/" |
| 8 | "strconvscip-go gomod github.com/golang/go/src go1.16 strconv/" |
| 9 | "syncscip-go gomod github.com/golang/go/src go1.16 sync/" |
| 10 | |
| 11 | "github.com/evilsocket/islazy/fsscip-go gomod github.com/evilsocket/islazy v1.11.0 `github.com/evilsocket/islazy/fs`/" |
| 12 | ) |
| 13 | |
| 14 | type EnvironmentChangedCallbackscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/EnvironmentChangedCallback# func(newValue string) |
| 15 | |
| 16 | type Environmentscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/Environment# struct { |
| 17 | syncscip-go gomod github.com/golang/go/src go1.16 sync/.Mutexscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/Environment#Mutex. |
| 18 | Datascip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/Environment#Data. map[string]string `json:"data"` |
| 19 | cbsscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/Environment#cbs. map[string]EnvironmentChangedCallbackscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/EnvironmentChangedCallback# |
| 20 | } |
| 21 | |
| 22 | func NewEnvironmentscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/NewEnvironment().(envFile string) (*Environmentscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/Environment#, error) { |
| 23 | env := &Environmentscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/Environment#{ |
| 24 | Datascip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/Environment#Data.: make(map[string]string), |
| 25 | cbsscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/Environment#cbs.: make(map[string]EnvironmentChangedCallbackscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/EnvironmentChangedCallback#), |
| 26 | } |
| 27 | |
| 28 | if envFile != "" { |
| 29 | envFile, _ := fsscip-go gomod github.com/evilsocket/islazy v1.11.0 `github.com/evilsocket/islazy/fs`/.Expandscip-go gomod github.com/evilsocket/islazy v1.11.0 `github.com/evilsocket/islazy/fs`/Expand().(envFile) |
| 30 | if fsscip-go gomod github.com/evilsocket/islazy v1.11.0 `github.com/evilsocket/islazy/fs`/.Existsscip-go gomod github.com/evilsocket/islazy v1.11.0 `github.com/evilsocket/islazy/fs`/Exists().(envFile) { |
| 31 | if err := env.Loadscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/Environment#Load().(envFile); err != nil { |
| 32 | return nil, err |
| 33 | } |
| 34 | } |
| 35 | } |
| 36 | |
| 37 | return env, nil |
| 38 | } |
| 39 | |
| 40 | func (env *Environmentscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/Environment#) Loadscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/Environment#Load().(fileName string) error { |
| 41 | env.Lockscip-go gomod github.com/golang/go/src go1.16 sync/Mutex#Lock().() |
| 42 | defer env.Unlockscip-go gomod github.com/golang/go/src go1.16 sync/Mutex#Unlock().() |
| 43 | |
| 44 | raw, err := ioutilscip-go gomod github.com/golang/go/src go1.16 `io/ioutil`/.ReadFilescip-go gomod github.com/golang/go/src go1.16 `io/ioutil`/ReadFile().(fileName) |
| 45 | if err != nil { |
| 46 | return err |
| 47 | } |
| 48 | |
| 49 | if len(raw) > 0 { |
| 50 | return jsonscip-go gomod github.com/golang/go/src go1.16 `encoding/json`/.Unmarshalscip-go gomod github.com/golang/go/src go1.16 `encoding/json`/Unmarshal().(raw, &env.Datascip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/Environment#Data.) |
| 51 | } |
| 52 | return nil |
| 53 | } |
| 54 | |
| 55 | func (env *Environmentscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/Environment#) Savescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/Environment#Save().(fileName string) error { |
| 56 | env.Lockscip-go gomod github.com/golang/go/src go1.16 sync/Mutex#Lock().() |
| 57 | defer env.Unlockscip-go gomod github.com/golang/go/src go1.16 sync/Mutex#Unlock().() |
| 58 | |
| 59 | raw, err := jsonscip-go gomod github.com/golang/go/src go1.16 `encoding/json`/.Marshalscip-go gomod github.com/golang/go/src go1.16 `encoding/json`/Marshal().(env.Datascip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/Environment#Data.) |
| 60 | if err != nil { |
| 61 | return err |
| 62 | } |
| 63 | |
| 64 | return ioutilscip-go gomod github.com/golang/go/src go1.16 `io/ioutil`/.WriteFilescip-go gomod github.com/golang/go/src go1.16 `io/ioutil`/WriteFile().(fileName, raw, 0644) |
| 65 | } |
| 66 | |
| 67 | func (env *Environmentscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/Environment#) Hasscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/Environment#Has().(name string) bool { |
| 68 | env.Lockscip-go gomod github.com/golang/go/src go1.16 sync/Mutex#Lock().() |
| 69 | defer env.Unlockscip-go gomod github.com/golang/go/src go1.16 sync/Mutex#Unlock().() |
| 70 | |
| 71 | _, found := env.Datascip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/Environment#Data.[name] |
| 72 | |
| 73 | return found |
| 74 | } |
| 75 | |
| 76 | func (env *Environmentscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/Environment#) addCbscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/Environment#addCb().(name string, cb EnvironmentChangedCallbackscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/EnvironmentChangedCallback#) { |
| 77 | env.Lockscip-go gomod github.com/golang/go/src go1.16 sync/Mutex#Lock().() |
| 78 | defer env.Unlockscip-go gomod github.com/golang/go/src go1.16 sync/Mutex#Unlock().() |
| 79 | env.cbsscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/Environment#cbs.[name] = cb |
| 80 | } |
| 81 | |
| 82 | func (env *Environmentscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/Environment#) WithCallbackscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/Environment#WithCallback().(name, value string, cb EnvironmentChangedCallbackscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/EnvironmentChangedCallback#) string { |
| 83 | env.addCbscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/Environment#addCb().(name, cb) |
| 84 | ret := env.Setscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/Environment#Set().(name, value) |
| 85 | return ret |
| 86 | } |
| 87 | |
| 88 | func (env *Environmentscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/Environment#) Setscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/Environment#Set().(name, value string) string { |
| 89 | env.Lockscip-go gomod github.com/golang/go/src go1.16 sync/Mutex#Lock().() |
| 90 | |
| 91 | old := env.Datascip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/Environment#Data.[name] |
| 92 | env.Datascip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/Environment#Data.[name] = value |
| 93 | |
| 94 | env.Unlockscip-go gomod github.com/golang/go/src go1.16 sync/Mutex#Unlock().() |
| 95 | |
| 96 | if cb, hasCallback := env.cbsscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/Environment#cbs.[name]; hasCallback { |
| 97 | cb(value) |
| 98 | } |
| 99 | |
| 100 | return old |
| 101 | } |
| 102 | |
| 103 | func (env *Environmentscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/Environment#) GetUnlockedscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/Environment#GetUnlocked().(name string) (bool, string) { |
| 104 | if value, found := env.Datascip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/Environment#Data.[name]; found { |
| 105 | return true, value |
| 106 | } |
| 107 | return false, "" |
| 108 | } |
| 109 | |
| 110 | func (env *Environmentscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/Environment#) Getscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/Environment#Get().(name string) (bool, string) { |
| 111 | env.Lockscip-go gomod github.com/golang/go/src go1.16 sync/Mutex#Lock().() |
| 112 | defer env.Unlockscip-go gomod github.com/golang/go/src go1.16 sync/Mutex#Unlock().() |
| 113 | return env.GetUnlockedscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/Environment#GetUnlocked().(name) |
| 114 | } |
| 115 | |
| 116 | func (env *Environmentscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/Environment#) GetIntscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/Environment#GetInt().(name string) (error, int) { |
| 117 | if found, value := env.Getscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/Environment#Get().(name); found { |
| 118 | if i, err := strconvscip-go gomod github.com/golang/go/src go1.16 strconv/.Atoiscip-go gomod github.com/golang/go/src go1.16 strconv/Atoi().(value); err == nil { |
| 119 | return nil, i |
| 120 | } else { |
| 121 | return err, 0 |
| 122 | } |
| 123 | } |
| 124 | |
| 125 | return fmtscip-go gomod github.com/golang/go/src go1.16 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.16 fmt/Errorf().("Not found."), 0 |
| 126 | } |
| 127 | |
| 128 | func (env *Environmentscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/Environment#) Sortedscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/Environment#Sorted().() []string { |
| 129 | env.Lockscip-go gomod github.com/golang/go/src go1.16 sync/Mutex#Lock().() |
| 130 | defer env.Unlockscip-go gomod github.com/golang/go/src go1.16 sync/Mutex#Unlock().() |
| 131 | |
| 132 | var keys []string |
| 133 | for k := range env.Datascip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/Environment#Data. { |
| 134 | keys = append(keys, k) |
| 135 | } |
| 136 | sortscip-go gomod github.com/golang/go/src go1.16 sort/.Stringsscip-go gomod github.com/golang/go/src go1.16 sort/Strings().(keys) |
| 137 | return keys |
| 138 | } |