-
Notifications
You must be signed in to change notification settings - Fork 4
/
main.go
54 lines (46 loc) · 1.21 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package main
import (
"github.com/rakuten-tech/jndi-ldap-test-server/args"
"github.com/rakuten-tech/jndi-ldap-test-server/routes"
"github.com/rakuten-tech/jndi-ldap-test-server/util/logging"
"github.com/urfave/cli/v2"
"os"
"os/signal"
"syscall"
"github.com/rs/zerolog/log"
ldap "github.com/vjeantet/ldapserver"
)
func main() {
logging.InitializeLogger()
err := args.RunWithArgs(os.Args, runApp)
if err != nil {
log.Fatal().Err(err).Msg("Failed to launch server")
}
}
func runApp(c *cli.Context) error {
// Setup according to CLI flags
setupLogger(c)
c.StringSlice("dynamic-payloads")
routes.SetExploit(routes.ParseExploitSettings(
c.String("payload"),
args.GetEnumValueSet(c, "dynamic-payloads"),
))
server := startServer(c.String("listen-address"), c.Int("port"))
// Quit gracefully on SIGINT (CTRL-C) and SIGTERM
ch := make(chan os.Signal)
signal.Notify(ch, syscall.SIGINT, syscall.SIGTERM)
<-ch
close(ch)
server.Stop()
return nil
}
func setupLogger(c *cli.Context) {
logging.UpdateLoggerWithFlags(
&logging.Flags{
Color: c.String("color"),
Level: c.String("log-level"),
},
)
ldapLogger := log.With().Str("component", "server").Logger()
ldap.Logger = logging.NewStdAdapter(&ldapLogger)
}