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

View File

@ -41,6 +41,7 @@ type (
Sync bool Sync bool
Ciphers []string Ciphers []string
UseInsecureCipher bool UseInsecureCipher bool
Shell string
} }
// Plugin structure // 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, strings.Join(p.Config.Script, "\n"))
p.log(host, "======END======") p.log(host, "======END======")
shell := p.Config.Shell
env := []string{} env := []string{}
for _, key := range p.Config.Envs { for _, key := range p.Config.Envs {
key = strings.ToUpper(key) key = strings.ToUpper(key)
if val, found := os.LookupEnv(key); found { if val, found := os.LookupEnv(key); found {
if shell == "bash" {
env = append(env, "export "+key+"="+escapeArg(val)) env = append(env, "export "+key+"="+escapeArg(val))
} else if shell == "powershell" {
env = append(env, "$env:"+key+" = "+escapeArg(val))
}
} }
} }