Compare commits

..

5 Commits
v0.3.1 ... main

Author SHA1 Message Date
26c50085d6 new/pipeline (#6)
All checks were successful
code scans / scans (push) Successful in 1m27s
Reviewed-on: #6
Co-authored-by: jake <jake.young.dev@gmail.com>
Co-committed-by: jake <jake.young.dev@gmail.com>
2025-04-24 18:22:16 +00:00
13d3b2cef3 feature/view-all (#5)
Reviewed-on: #5
Co-authored-by: jake <jake.young.dev@gmail.com>
Co-committed-by: jake <jake.young.dev@gmail.com>
2025-04-20 05:28:56 +00:00
4100762986 Update README.md 2025-04-19 05:18:26 +00:00
a3527d3388 dev/standards (#4)
Reviewed-on: #4
Co-authored-by: jake <jake.young.dev@gmail.com>
Co-committed-by: jake <jake.young.dev@gmail.com>
2025-04-19 05:13:53 +00:00
35fb9fc270 version bump 2025-04-17 17:34:32 -04:00
11 changed files with 83 additions and 36 deletions

View File

@ -0,0 +1,25 @@
name: "code scans"
on: [push, pull_request] #runs on pushes to any branch
jobs:
scans:
runs-on: smoke-test
steps:
- name: "clone code"
uses: actions/checkout@v4
- name: "install go"
uses: https://code.jakeyoungdev.com/actions/install-go@v0.1.3
with:
commands: |
golang.org/x/vuln/cmd/govulncheck@latest
- name: "dependency and stdlib scan"
uses: https://code.jakeyoungdev.com/actions/report-vulns@master
with:
manager: go
- name: "static code analysis"
uses: securego/gosec@master
with:
args: ./...

View File

@ -1,5 +1,5 @@
# mctl
mctl is a terminal-friendly remote connection client
mctl is a terminal-friendly remote console client
## Installation
Install mctl using golang
@ -10,7 +10,7 @@ go install code.jakeyoungdev.com/jake/mctl@main #it is recommended to use a tagg
## Setup
### Configuring mctl
mctl requires a one-time setup via the 'config' command before interacting with any servers, password is entered securely from the terminal
mctl requires a one-time setup via the 'config' command before interacting with any servers, password is entered securely from the terminal and encrypted
```bash
mctl config -s <serveraddress> -p <rconport>
```
@ -23,7 +23,7 @@ mctl login #makes auth request to server with saved password
```
### Sending commands
If login is successful the app will enter the command loop, which allows commands to be sent directly to the server until 'mctl' is sent. Commands are sent as-is to the server, there is no validation of command syntax within mctl
If login is successful the app will enter the command loop, which allows commands to be sent directly to the server. Commands are sent as-is to the server, there is no validation of command syntax within mctl
```
Logging into X.X.X.X on port 61695
Connected! Type 'mctl' to close
@ -33,7 +33,7 @@ There are 0 of a max of 20 players online:
```
### Saving commands
Commands can be saved under an alias for quick execution later, saved commands can contain placeholders '%s' that can be populated at runtime to allow for commands with unique runtime args to still be saved:
Commands can be saved under an alias for quick execution later, saved commands can contain placeholders '%s' that can be populated at runtime to allow for commands with unique runtime args to still be saved, see [example](#saving-and-running-example) for more:
```bash
mctl save <name>
```
@ -43,6 +43,10 @@ Saved commands can be viewed with:
```bash
mctl view <name>
```
All saved commands can be viewed with:
```bash
mctl view all
```
### Running saved commands
Commands that have been saved can be run with:
@ -90,10 +94,12 @@ mctl delete <name>
|server|s|yes|RCon address|
### Configuration file
All configuration data will be kept in /home/.mctl.yaml or C:\\Users\\username\\.mctl.yaml, passwords are encrypted for an added layer of security
All configuration data will be kept in the home directory and any sensitive data is encrypted for added security
## Security
RCon is an inherently insecure protocol, passwords are sent in plaintext and, if possible, the port should not be exposed to the internet. It is best to keep these connections local or over a VPN
RCon is an inherently insecure protocol, passwords are sent in plaintext and, if possible, the port should not be exposed to the internet. It is best to keep these connections local or over a VPN.
mctl utilizes [govulncheck](https://pkg.go.dev/golang.org/x/vuln/cmd/govulncheck) and [gosec](https://github.com/securego/gosec) in workflows to ensure quality, secure code is being pushed. These workflow steps must pass before a PR will be accepted
## Development
this repo is currently in heavy development and may encounter breaking changes, use a tag to prevent any surprises

View File

@ -48,7 +48,8 @@ var configCmd = &cobra.Command{
viper.Set("server", cfgserver)
viper.Set("password", string(ciphert))
viper.Set("port", cfgport)
viper.WriteConfig()
err = viper.WriteConfig()
cobra.CheckErr(err)
fmt.Println()
fmt.Println("Config file updated!")
},
@ -57,9 +58,11 @@ var configCmd = &cobra.Command{
func init() {
initConfig()
configCmd.Flags().StringVarP(&cfgserver, "server", "s", "", "server address")
configCmd.MarkFlagRequired("server")
err := configCmd.MarkFlagRequired("server")
cobra.CheckErr(err)
configCmd.Flags().IntVarP(&cfgport, "port", "p", 0, "server rcon port")
configCmd.MarkFlagRequired("port")
err = configCmd.MarkFlagRequired("port")
cobra.CheckErr(err)
rootCmd.AddCommand(configCmd)
}
@ -72,7 +75,8 @@ func initConfig() {
viper.SetConfigType("yaml")
viper.SetConfigName(".mctl")
viper.AutomaticEnv()
viper.ReadInConfig()
err = viper.ReadInConfig()
cobra.CheckErr(err)
if err := viper.ReadInConfig(); err != nil {
//file does not exist, create it
@ -92,6 +96,7 @@ func initConfig() {
//write config
viper.Set("customcmd", cmdMap)
viper.Set("device", string(uu))
viper.SafeWriteConfig()
err = viper.SafeWriteConfig()
cobra.CheckErr(err)
}
}

View File

@ -17,16 +17,13 @@ var deleteCmd = &cobra.Command{
Short: "Delete a saved command",
Long: `Deletes a command stored using the save command`,
Run: func(cmd *cobra.Command, args []string) {
var cm map[string]any
cmdMap := viper.Get("customcmd")
if cmdMap == nil {
cm = make(map[string]any, 0)
} else {
cm = cmdMap.(map[string]any)
if viper.IsSet("customcmd") {
cmdMap := viper.Get("customcmd").(map[string]any)
delete(cmdMap, args[0])
viper.Set("customcmd", cmdMap)
err := viper.WriteConfig()
cobra.CheckErr(err)
}
delete(cm, args[0])
viper.Set("customcmd", cmdMap)
viper.WriteConfig()
},
PreRunE: func(cmd *cobra.Command, args []string) error {
if len(args) == 0 {

View File

@ -58,9 +58,10 @@ var loginCmd = &cobra.Command{
},
PreRunE: func(cmd *cobra.Command, args []string) error {
//ensure config command has been run
if viper.Get("server") == "" || viper.Get("password") == "" || viper.Get("port") == 0 {
if !viper.IsSet("server") || !viper.IsSet("password") || !viper.IsSet("port") {
return errors.New("the 'config' command must be run before you can interact with servers")
}
return nil
},
}

View File

@ -14,7 +14,7 @@ var rootCmd = &cobra.Command{
Use: "mctl",
Short: "A remote console client",
Long: `mctl is a terminal-friendly remote console client made to manage game servers.`,
Version: "v0.2.0",
Version: "v0.3.4",
// Run: func(cmd *cobra.Command, args []string) { },
}

View File

@ -22,14 +22,7 @@ var runCmd = &cobra.Command{
Long: `Loads a saved command, injects the supplied arguments into the command, and sends the command to the remove server
printing the response`,
Run: func(cmd *cobra.Command, args []string) {
//check for command map
var cm map[string]any
cmdMap := viper.Get("customcmd")
if cmdMap == nil {
cm = make(map[string]any, 0)
} else {
cm = cmdMap.(map[string]any)
}
cm := viper.Get("customcmd").(map[string]any)
//is this an existing command
cmdRun, ok := cm[args[0]]
if !ok {
@ -58,11 +51,15 @@ var runCmd = &cobra.Command{
fmt.Println(res)
},
PreRunE: func(cmd *cobra.Command, args []string) error {
//ensure configuration has been setup
if viper.Get("server") == "" || viper.Get("password") == "" || viper.Get("port") == 0 {
//ensure config command has been run
if !viper.IsSet("server") || !viper.IsSet("password") || !viper.IsSet("port") {
return errors.New("the 'config' command must be run before you can interact with servers")
}
if !viper.IsSet("customcmd") {
return errors.New("no saved commands to run")
}
//ensure we have a command name
al := len(args)
if al == 0 {

View File

@ -36,7 +36,8 @@ var saveCmd = &cobra.Command{
}
cmdMap[args[0]] = txt
viper.Set("customcmd", cmdMap)
viper.WriteConfig()
err := viper.WriteConfig()
cobra.CheckErr(err)
fmt.Println("\nSaved!")
}
}

View File

@ -6,6 +6,7 @@ package cmd
import (
"errors"
"fmt"
"strings"
"github.com/spf13/cobra"
"github.com/spf13/viper"
@ -16,7 +17,7 @@ var viewCmd = &cobra.Command{
Use: "view <name>",
Example: "mctl view test",
Short: "View saved commands",
Long: `Load command using the supplied name and displays it in the terminal`,
Long: `Load command using the supplied name and displays it in the terminal, 'all' will list every saved command`,
Run: func(cmd *cobra.Command, args []string) {
var cm map[string]any
cmdMap := viper.Get("customcmd")
@ -26,6 +27,17 @@ var viewCmd = &cobra.Command{
}
cm = cmdMap.(map[string]any)
if strings.EqualFold(args[0], "all") {
//show all commands
fmt.Println("\nCommands: ")
for k, v := range cm {
fmt.Printf("%s - %s\n", k, v)
}
fmt.Println()
return
}
custom, ok := cm[args[0]]
if !ok {
fmt.Println("command not found")

View File

@ -21,7 +21,10 @@ func EncryptPassword(b []byte) ([]byte, error) {
return nil, err
}
ct := aesg.Seal(nil, []byte(nonce), []byte(b), nil)
//adding #nosec trigger here since gosec interprets this as a hardcoded nonce value. The nonce is calculated using crypto/rand when the
//config command is ran and is pulled from memory when used any times after, for now we must prevent the scan from catching here until gosec
//is updated to account for this properly
ct := aesg.Seal(nil, []byte(nonce), []byte(b), nil) // #nosec
return ct, nil
}

2
go.mod
View File

@ -1,6 +1,6 @@
module code.jakeyoungdev.com/jake/mctl
go 1.24.0
go 1.24.2
require (
github.com/jake-young-dev/mcr v1.3.1