feat: added shell option

This commit is contained in:
iam1337 2023-02-18 23:30:16 +03:00
parent fc62fb377c
commit f218df05e9
2 changed files with 15 additions and 1 deletions

View File

@ -197,6 +197,12 @@ func main() {
Usage: "debug mode",
EnvVars: []string{"PLUGIN_DEBUG", "DEBUG", "INPUT_DEBUG"},
},
&cli.StringFlag{
Name: "shell",
Usage: "shell on host",
EnvVars: []string{"PLUGIN_HOST_SHELL"},
Value: "bash",
},
}
// Override a template
@ -242,6 +248,7 @@ func run(c *cli.Context) error {
if s := c.String("script.string"); s != "" {
scripts = append(scripts, s)
}
plugin := Plugin{
Config: Config{
Key: c.String("ssh-key"),
@ -261,6 +268,7 @@ func run(c *cli.Context) error {
Sync: c.Bool("sync"),
Ciphers: c.StringSlice("ciphers"),
UseInsecureCipher: c.Bool("useInsecureCipher"),
Shell: c.String("shell"),
Proxy: easyssh.DefaultConfig{
Key: c.String("proxy.ssh-key"),
KeyPath: c.String("proxy.key-path"),

View File

@ -41,6 +41,7 @@ type (
Sync bool
Ciphers []string
UseInsecureCipher bool
Shell string
}
// Plugin structure
@ -99,11 +100,16 @@ func (p Plugin) exec(host string, wg *sync.WaitGroup, errChannel chan error) {
p.log(host, strings.Join(p.Config.Script, "\n"))
p.log(host, "======END======")
shell := p.Config.Shell
env := []string{}
for _, key := range p.Config.Envs {
key = strings.ToUpper(key)
if val, found := os.LookupEnv(key); found {
env = append(env, "export "+key+"="+escapeArg(val))
if shell == "bash" {
env = append(env, "export "+key+"="+escapeArg(val))
} else if shell == "powershell" {
env = append(env, "$env:"+key+" = "+escapeArg(val))
}
}
}