Skip to content

Commit

Permalink
Enable -timeout option when detecting OS
Browse files Browse the repository at this point in the history
  • Loading branch information
knqyf263 committed Apr 9, 2017
1 parent eb2598f commit e15bd53
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 35 deletions.
6 changes: 3 additions & 3 deletions README.ja.md
Original file line number Diff line number Diff line change
Expand Up @@ -774,10 +774,10 @@ scan:
[-skip-broken]
[-http-proxy=http://192.168.0.1:8080]
[-ask-key-password]
[-timeout=300]
[-timeout-scan=7200]
[-debug]
[-pipe]
[-timeout]
[-timeout-scan]

[SERVER]...
-ask-key-password
Expand All @@ -803,7 +803,7 @@ scan:
-ssh-native-insecure
Use Native Go implementation of SSH. Default: Use the external command
-timeout int
Number of seconds for detecting platform for all servers (default 60)
Number of seconds for processing other than scan (default 300)
-timeout-scan int
Number of second for scaning vulnerabilities for all servers (default 7200)
```
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -783,10 +783,10 @@ scan:
[-skip-broken]
[-http-proxy=http://192.168.0.1:8080]
[-ask-key-password]
[-timeout=300]
[-timeout-scan=7200]
[-debug]
[-pipe]
[-timeout]
[-timeout-scan]

[SERVER]...
-ask-key-password
Expand All @@ -812,7 +812,7 @@ scan:
-ssh-native-insecure
Use Native Go implementation of SSH. Default: Use the external command
-timeout int
Number of seconds for detecting platform for all servers (default 60)
Number of seconds for processing other than scan (default 300)
-timeout-scan int
Number of second for scaning vulnerabilities for all servers (default 7200)
```
Expand Down
2 changes: 1 addition & 1 deletion commands/configtest.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ func (p *ConfigtestCmd) Execute(_ context.Context, f *flag.FlagSet, _ ...interfa
}

util.Log.Info("Detecting Server/Container OS... ")
if err := scan.InitServers(); err != nil {
if err := scan.InitServers(p.timeoutSec); err != nil {
util.Log.Errorf("Failed to init servers: %s", err)
return subcommands.ExitFailure
}
Expand Down
42 changes: 21 additions & 21 deletions commands/scan.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,19 @@ import (

// ScanCmd is Subcommand of host discovery mode
type ScanCmd struct {
debug bool
configPath string
resultsDir string
logDir string
cacheDBPath string
httpProxy string
askKeyPassword bool
containersOnly bool
skipBroken bool
sshNative bool
pipe bool
scanTimeoutSec int
detectTimeoutSec int
debug bool
configPath string
resultsDir string
logDir string
cacheDBPath string
httpProxy string
askKeyPassword bool
containersOnly bool
skipBroken bool
sshNative bool
pipe bool
timeoutSec int
scanTimeoutSec int
}

// Name return subcommand name
Expand All @@ -69,10 +69,10 @@ func (*ScanCmd) Usage() string {
[-skip-broken]
[-http-proxy=http://192.168.0.1:8080]
[-ask-key-password]
[-timeout=300]
[-timeout-scan=7200]
[-debug]
[-pipe]
[-timeout]
[-timeout-detect-platform]
[SERVER]...
`
Expand Down Expand Up @@ -139,17 +139,17 @@ func (p *ScanCmd) SetFlags(f *flag.FlagSet) {
"Use stdin via PIPE")

f.IntVar(
&p.detectTimeoutSec,
&p.timeoutSec,
"timeout",
1*60,
"Number of seconds for detecting platform for all servers",
5*60,
"Number of seconds for processing other than scan",
)

f.IntVar(
&p.scanTimeoutSec,
"timeout-scan",
120*60,
"Number of second for scaning vulnerabilities for all servers",
"Number of seconds for scaning vulnerabilities for all servers",
)
}

Expand Down Expand Up @@ -231,13 +231,13 @@ func (p *ScanCmd) Execute(_ context.Context, f *flag.FlagSet, _ ...interface{})
}

util.Log.Info("Detecting Server/Container OS... ")
if err := scan.InitServers(); err != nil {
if err := scan.InitServers(p.timeoutSec); err != nil {
util.Log.Errorf("Failed to init servers: %s", err)
return subcommands.ExitFailure
}

util.Log.Info("Detecting Platforms... ")
scan.DetectPlatforms(p.detectTimeoutSec)
scan.DetectPlatforms(p.timeoutSec)

util.Log.Info("Scanning vulnerabilities... ")
if err := scan.Scan(p.scanTimeoutSec); err != nil {
Expand Down
14 changes: 7 additions & 7 deletions scan/serverapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,13 +121,13 @@ func PrintSSHableServerNames() {
}

// InitServers detect the kind of OS distribution of target servers
func InitServers() error {
servers, errServers = detectServerOSes()
func InitServers(timeoutSec int) error {
servers, errServers = detectServerOSes(timeoutSec)
if len(servers) == 0 {
return fmt.Errorf("No scannable servers")
}

actives, inactives := detectContainerOSes()
actives, inactives := detectContainerOSes(timeoutSec)
if config.Conf.ContainersOnly {
servers = actives
errServers = inactives
Expand All @@ -138,7 +138,7 @@ func InitServers() error {
return nil
}

func detectServerOSes() (servers, errServers []osTypeInterface) {
func detectServerOSes(timeoutSec int) (servers, errServers []osTypeInterface) {
util.Log.Info("Detecting OS of servers... ")
osTypeChan := make(chan osTypeInterface, len(config.Conf.Servers))
defer close(osTypeChan)
Expand All @@ -153,7 +153,7 @@ func detectServerOSes() (servers, errServers []osTypeInterface) {
}(s)
}

timeout := time.After(30 * time.Second)
timeout := time.After(time.Duration(timeoutSec) * time.Second)
for i := 0; i < len(config.Conf.Servers); i++ {
select {
case res := <-osTypeChan:
Expand Down Expand Up @@ -199,7 +199,7 @@ func detectServerOSes() (servers, errServers []osTypeInterface) {
return
}

func detectContainerOSes() (actives, inactives []osTypeInterface) {
func detectContainerOSes(timeoutSec int) (actives, inactives []osTypeInterface) {
util.Log.Info("Detecting OS of containers... ")
osTypesChan := make(chan []osTypeInterface, len(servers))
defer close(osTypesChan)
Expand All @@ -215,7 +215,7 @@ func detectContainerOSes() (actives, inactives []osTypeInterface) {
}(s)
}

timeout := time.After(30 * time.Second)
timeout := time.After(time.Duration(timeoutSec) * time.Second)
for i := 0; i < len(servers); i++ {
select {
case res := <-osTypesChan:
Expand Down

0 comments on commit e15bd53

Please sign in to comment.