mirror of
https://github.com/bettercap/bettercap
synced 2025-08-19 21:13:18 -07:00
new: asking confirmation when the session is closed with CTRL+C / SIGINT
(closes #319)
This commit is contained in:
parent
6c43fb7673
commit
924387faf2
2 changed files with 15 additions and 4 deletions
12
main.go
12
main.go
|
@ -4,6 +4,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/bettercap/bettercap/core"
|
"github.com/bettercap/bettercap/core"
|
||||||
"github.com/bettercap/bettercap/log"
|
"github.com/bettercap/bettercap/log"
|
||||||
|
@ -90,9 +91,20 @@ func main() {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if err == io.EOF {
|
if err == io.EOF {
|
||||||
continue
|
continue
|
||||||
|
} else if err.Error() == "Interrupt" {
|
||||||
|
var ans string
|
||||||
|
fmt.Printf("Are you sure you want to quit this session? y/n ")
|
||||||
|
fmt.Scan(&ans)
|
||||||
|
|
||||||
|
if strings.ToLower(ans) == "y" {
|
||||||
|
sess.Run("exit")
|
||||||
|
os.Exit(0)
|
||||||
}
|
}
|
||||||
|
continue
|
||||||
|
} else {
|
||||||
log.Fatal("%s", err)
|
log.Fatal("%s", err)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for _, cmd := range session.ParseCommands(line) {
|
for _, cmd := range session.ParseCommands(line) {
|
||||||
if err = sess.Run(cmd); err != nil {
|
if err = sess.Run(cmd); err != nil {
|
||||||
|
|
|
@ -347,9 +347,8 @@ func (s *Session) startNetMon() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Session) setupSignals() {
|
func (s *Session) setupSignals() {
|
||||||
c := make(chan os.Signal, 1)
|
c := make(chan os.Signal)
|
||||||
signal.Notify(c, os.Interrupt)
|
signal.Notify(c, os.Interrupt, syscall.SIGTERM)
|
||||||
signal.Notify(c, syscall.SIGTERM)
|
|
||||||
go func() {
|
go func() {
|
||||||
<-c
|
<-c
|
||||||
fmt.Println()
|
fmt.Println()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue