2023-09-09 04:00:00 +02:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"flag"
|
|
|
|
"log"
|
|
|
|
"os"
|
|
|
|
"os/signal"
|
|
|
|
|
|
|
|
"forge.cadoles.com/wpetit/rebound"
|
2023-09-21 05:54:08 +02:00
|
|
|
"forge.cadoles.com/wpetit/rebound/http"
|
|
|
|
"forge.cadoles.com/wpetit/rebound/ssh"
|
2023-09-09 04:00:00 +02:00
|
|
|
"github.com/pkg/errors"
|
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
opts := rebound.DefaultOptions()
|
2023-09-21 05:54:08 +02:00
|
|
|
|
|
|
|
if err := opts.ParseEnv(); err != nil {
|
2023-09-09 04:00:00 +02:00
|
|
|
log.Fatalf("[ERROR] %+v", errors.WithStack(err))
|
|
|
|
}
|
|
|
|
|
2023-09-21 05:54:08 +02:00
|
|
|
// Global Options
|
2023-09-09 04:00:00 +02:00
|
|
|
address := flag.String("address", opts.Address, "server listening address")
|
2023-09-21 05:54:08 +02:00
|
|
|
|
|
|
|
// SSH Options
|
|
|
|
sockDir := flag.String("ssh-sock-dir", opts.SSH.SockDir, "ssh sock directory")
|
|
|
|
publicPort := flag.Uint("ssh-public-port", opts.SSH.PublicPort, "ssh public port")
|
|
|
|
publicHost := flag.String("ssh-public-host", opts.SSH.PublicHost, "ssh public host")
|
|
|
|
hostKey := flag.String("ssh-host-key", opts.SSH.HostKey, "ssh host key")
|
|
|
|
|
|
|
|
// HTTP Options
|
|
|
|
customDir := flag.String("http-custom-dir", opts.HTTP.CustomDir, "http custom templates/assets directory")
|
2023-09-09 04:00:00 +02:00
|
|
|
|
|
|
|
flag.Parse()
|
|
|
|
|
|
|
|
server := rebound.NewServer(
|
|
|
|
rebound.WithAddress(*address),
|
2023-09-21 05:54:08 +02:00
|
|
|
rebound.WithSSHOption(
|
|
|
|
ssh.WithSockDir(*sockDir),
|
|
|
|
ssh.WithPublicHost(*publicHost),
|
|
|
|
ssh.WithPublicPort(*publicPort),
|
|
|
|
ssh.WithHostKey(*hostKey),
|
|
|
|
),
|
|
|
|
rebound.WitHTTPOption(
|
|
|
|
http.WithCustomDir(*customDir),
|
|
|
|
),
|
2023-09-09 04:00:00 +02:00
|
|
|
)
|
|
|
|
|
2023-09-21 05:54:08 +02:00
|
|
|
if err := server.Start(); err != nil {
|
|
|
|
log.Fatalf("[FATAL] %+v", errors.WithStack(err))
|
|
|
|
}
|
2023-09-09 04:00:00 +02:00
|
|
|
|
|
|
|
c := make(chan os.Signal, 1)
|
|
|
|
signal.Notify(c, os.Interrupt)
|
|
|
|
|
|
|
|
<-c
|
|
|
|
|
|
|
|
if err := server.Stop(); err != nil {
|
|
|
|
log.Fatalf("[FATAL] %+v", errors.WithStack(err))
|
|
|
|
}
|
|
|
|
}
|