2024-02-19 18:34:33 +01:00
package cmd
import (
2024-02-19 20:14:32 +01:00
"fmt"
2024-02-19 18:34:33 +01:00
"os"
2024-02-19 20:14:32 +01:00
"strings"
2024-02-19 18:34:33 +01:00
"github.com/ddworken/hishtory/client/hctx"
"github.com/ddworken/hishtory/client/lib"
"github.com/ddworken/hishtory/client/webui"
"github.com/spf13/cobra"
)
2024-02-19 20:14:32 +01:00
var disableAuth * bool
var forceCreds * string
2024-04-15 03:18:11 +02:00
var port * int
2024-02-19 20:14:32 +01:00
2024-02-19 18:34:33 +01:00
var webUiCmd = & cobra . Command {
Use : "start-web-ui" ,
Short : "Serve a basic web UI for interacting with your shell history" ,
Run : func ( cmd * cobra . Command , args [ ] string ) {
2024-02-19 20:14:32 +01:00
overridenUsername := ""
overridenPassword := ""
if * forceCreds != "" {
if strings . Contains ( * forceCreds , ":" ) {
splitCreds := strings . SplitN ( * forceCreds , ":" , 2 )
overridenUsername = splitCreds [ 0 ]
overridenPassword = splitCreds [ 1 ]
} else {
lib . CheckFatalError ( fmt . Errorf ( "--force-creds=%#v doesn't contain a colon to delimit username and password" , * forceCreds ) )
}
}
if * disableAuth && * forceCreds != "" {
lib . CheckFatalError ( fmt . Errorf ( "cannot specify both --disable-auth and --force-creds" ) )
}
2024-04-15 03:18:11 +02:00
lib . CheckFatalError ( webui . StartWebUiServer ( hctx . MakeContext ( ) , * port , * disableAuth , overridenUsername , overridenPassword ) )
2024-02-19 18:34:33 +01:00
os . Exit ( 1 )
} ,
}
func init ( ) {
rootCmd . AddCommand ( webUiCmd )
2024-02-19 20:14:32 +01:00
disableAuth = webUiCmd . Flags ( ) . Bool ( "disable-auth" , false , "Disable authentication for the Web UI (Warning: This means your entire shell history will be accessible from the local web server)" )
forceCreds = webUiCmd . Flags ( ) . String ( "force-creds" , "" , "Specify the credentials to use for basic auth in the form `user:password`" )
2024-04-15 03:18:11 +02:00
port = webUiCmd . Flags ( ) . Int ( "port" , 8000 , "The port for the web server to listen on" )
2024-02-19 18:34:33 +01:00
}