2024-04-11 03:42:38 +00:00
|
|
|
/*
|
|
|
|
Copyright © 2024 Steven Polley <himself@stevenpolley.net>
|
|
|
|
*/
|
|
|
|
package cmd
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2024-04-18 01:41:24 +00:00
|
|
|
"os/user"
|
2024-04-11 03:42:38 +00:00
|
|
|
|
2024-04-18 01:12:01 +00:00
|
|
|
"deadbeef.codes/steven/hyp/hypd/configuration"
|
2024-04-11 03:42:38 +00:00
|
|
|
"deadbeef.codes/steven/hyp/hypd/server"
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
)
|
|
|
|
|
|
|
|
// serverCmd represents the server command
|
|
|
|
var serverCmd = &cobra.Command{
|
2024-04-18 01:41:24 +00:00
|
|
|
Use: "server <configFilePath>",
|
2024-04-11 03:42:38 +00:00
|
|
|
Args: cobra.ExactArgs(1),
|
|
|
|
Short: "Runs hyp in server mode",
|
2024-04-18 01:41:24 +00:00
|
|
|
Long: `Runs the hyp server and begins watching for authentic knock sequences.
|
2024-04-11 03:42:38 +00:00
|
|
|
|
2024-04-18 01:41:24 +00:00
|
|
|
Before running this command, you must first have a configuration file. You can
|
|
|
|
generate a configuration file with: hypd generate defaultconfig > hypdconfig.json
|
|
|
|
|
|
|
|
You should then edit the config file to meet your needs.
|
2024-04-11 03:42:38 +00:00
|
|
|
|
2024-04-18 01:41:24 +00:00
|
|
|
In addition to a config file you will need to generate pre-shared keys:
|
|
|
|
mkdir -p ./secrets
|
|
|
|
hypd generate secret > secrets/mykey.secret
|
2024-04-11 03:42:38 +00:00
|
|
|
|
2024-04-18 01:41:24 +00:00
|
|
|
Example Usage:
|
2024-04-11 03:42:38 +00:00
|
|
|
|
2024-04-18 01:41:24 +00:00
|
|
|
# Use config file in local directory
|
|
|
|
hypd server hypdconfig.json
|
2024-04-11 03:42:38 +00:00
|
|
|
|
2024-04-18 01:41:24 +00:00
|
|
|
# Use config file in /etc/hyp/
|
|
|
|
hypd server /etc/hyp/hypdconfig.json
|
2024-04-11 03:42:38 +00:00
|
|
|
`,
|
|
|
|
Run: func(cmd *cobra.Command, args []string) {
|
2024-04-18 01:41:24 +00:00
|
|
|
currentUser, err := user.Current()
|
2024-04-18 01:12:01 +00:00
|
|
|
if err != nil {
|
2024-04-18 01:41:24 +00:00
|
|
|
panic(fmt.Errorf("could not determine current user: %w", err))
|
2024-04-18 01:12:01 +00:00
|
|
|
}
|
2024-04-18 01:41:24 +00:00
|
|
|
if currentUser.Username != "root" {
|
|
|
|
fmt.Println("WARNING: It's recommended you run this as root, but will proceed anyways...")
|
|
|
|
}
|
|
|
|
|
|
|
|
hypdConfiguration, err := configuration.LoadConfiguration(args[0])
|
2024-04-18 01:12:01 +00:00
|
|
|
if err != nil {
|
|
|
|
panic(fmt.Errorf("failed to start packet server: %w", err))
|
|
|
|
}
|
2024-04-18 01:41:24 +00:00
|
|
|
err = server.PacketServer(hypdConfiguration)
|
2024-04-11 03:42:38 +00:00
|
|
|
if err != nil {
|
|
|
|
panic(fmt.Errorf("failed to start packet server: %w", err))
|
|
|
|
}
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
rootCmd.AddCommand(serverCmd)
|
|
|
|
}
|