Skip to content

Commit

Permalink
feat: add option commandline flag
Browse files Browse the repository at this point in the history
  • Loading branch information
hugefiver committed Jul 24, 2024
1 parent a6f735d commit 25bfc25
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 3 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ Usage of FakeSSH:
see maxconn
-msc maxsuccconn
see maxsuccconn
-o option
see option
-option module.key=value
options for modules, "module.key=value"
-passwd
log password to file
-r float
Expand Down
15 changes: 15 additions & 0 deletions conf/conf.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"strconv"
"strings"

"github.com/hugefiver/fakessh/modules"
"github.com/hugefiver/fakessh/modules/fakeshell"
"github.com/hugefiver/fakessh/modules/gitserver"
"github.com/hugefiver/fakessh/utils"
Expand Down Expand Up @@ -253,6 +254,20 @@ func MergeConfig(c *AppConfig, f *FlagArgsStruct, set StringSet) error {
c.Server.MaxSuccConn = mc
}

for _, o := range f.Options {
o, err := modules.ParseOpt(o)
if err != nil {
return err
}

switch o.Module {
case "fakeshell":
if fakeshell.Embedded {
c.Modules.FakeShell.MergeOptions(o)
}
}
}

return nil
}

Expand Down
23 changes: 21 additions & 2 deletions conf/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -84,5 +84,24 @@ loss_ratio = 1.0
# if true, authorized_keys will be auto updated
#watch_keys = false

max_git_shell_processes = 0
refuse_when_busy = false
# max_git_shell_processes = 0
# refuse_when_busy = false

[modules.fakeshell]
enable = false

#rootfs = "/path/to/rootfs.tar"
# or
#rootfs = "/path/to/rootfs.zip"
# or
#rootfs = "/path/to/somewhere"

#[modules.fakeshell.env]
#user = "root"
#home = "/root"
#os = "FairyOS"
#kernel = "ctOS 3.1"
#hostname = "fakeshell"

#genenv = true
#envs = {"ENV1" = "VALUE1", "ENV2" = "VALUE2"}
6 changes: 6 additions & 0 deletions conf/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ type FlagArgsStruct struct {

// Max success connections
MaxSuccConns string

// Module Options
Options []string
}

// GetArg : get args
Expand Down Expand Up @@ -115,6 +118,9 @@ func GetArg() (args *FlagArgsStruct, set StringSet, helper func()) {
f.StringVar(&args.MaxSuccConns, "maxsucc", "", "see `maxsuccconn`")
f.StringVar(&args.MaxSuccConns, "msc", "", "see `maxsuccconn`")

StringArrayVar(f, &args.Options, "option", "options for modules, \"`module.key=value`\"")
StringArrayVar(f, &args.Options, "o", "see `option`")

f.Parse(os.Args[1:])
//_args = &args

Expand Down
6 changes: 6 additions & 0 deletions modules/fakeshell/module_ignore.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,16 @@

package fakeshell

import "github.com/hugefiver/fakessh/modules"

const Embedded = false

type Config struct {
Enable bool
}

func (c *Config) FillDefault() {}

func (c *Config) MergeOptions(opt *modules.Opt) bool {
return false
}
3 changes: 2 additions & 1 deletion modules/opt.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package modules

import (
"errors"
"fmt"
"strings"
)

Expand All @@ -17,7 +18,7 @@ func ParseOpt(opt string) (*Opt, error) {
xs := strings.SplitN(opt, "=", 2)

if len(xs) != 2 {
return nil, ErrFailParseOpt
return nil, fmt.Errorf("%w: option must be 'module.key=value'", ErrFailParseOpt)
}

key, value := xs[0], xs[1]
Expand Down

0 comments on commit 25bfc25

Please sign in to comment.