-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add ability to disable auth and force specific creds for the web UI
- Loading branch information
Showing
3 changed files
with
35 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,44 @@ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"strings" | ||
|
||
"github.com/ddworken/hishtory/client/hctx" | ||
"github.com/ddworken/hishtory/client/lib" | ||
"github.com/ddworken/hishtory/client/webui" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
var disableAuth *bool | ||
var forceCreds *string | ||
|
||
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) { | ||
lib.CheckFatalError(webui.StartWebUiServer(hctx.MakeContext())) | ||
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")) | ||
} | ||
lib.CheckFatalError(webui.StartWebUiServer(hctx.MakeContext(), *disableAuth, overridenUsername, overridenPassword)) | ||
os.Exit(1) | ||
}, | ||
} | ||
|
||
func init() { | ||
rootCmd.AddCommand(webUiCmd) | ||
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`") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters