Skip to content

Commit

Permalink
v1.3.1 fix the way NM VP config is being updated
Browse files Browse the repository at this point in the history
  • Loading branch information
nixargh committed Jan 24, 2024
1 parent 9bfa45d commit f8b5cb4
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 5 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## [1.3.1] - 2024-01-24
### Fixed
- `nmcli.go` fix the way NM VPN config is being updated.
- `main.go` use full timestamp even when TTY is attached.

## [1.3.0] - 2024-01-21
### Added
- `nmcli.go` new function **nmcliConnectionUpdatePassword** that updates NM VPN config with a generated password for only current user.
Expand Down
13 changes: 12 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
// "github.com/pkg/profile"
)

var version string = "1.3.0"
var version string = "1.3.1"

var clog *log.Entry

Expand All @@ -43,6 +43,9 @@ func main() {
flag.Parse()

// Setup logging
log.SetFormatter(&log.TextFormatter{
FullTimestamp: true,
})
log.SetOutput(os.Stdout)

if showVersion {
Expand Down Expand Up @@ -85,8 +88,16 @@ func main() {
passcode := GeneratePassCode(otpSecret)
clog.WithFields(log.Fields{"passcode": passcode}).Info("Got a new pass code.")

// Update VPN config to store password only for current user
nmcliConnectionUpdatePasswordFlags(config, 1)

nmcliConnectionUpdatePassword(password, passcode, config)

nmcliConnectionUp(config)

/* Update VPN config to ask password every time.
That should prevent NM reconections with an old password. */
nmcliConnectionUpdatePasswordFlags(config, 2)
} else {
clog.Info("No active connection found thus posponding VPN connection.")
}
Expand Down
18 changes: 14 additions & 4 deletions nmcli.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,15 +88,25 @@ func nmcliConnectionUp(config string) {
clog.WithFields(log.Fields{"config": config}).Info("VPN is connected.")
}

func nmcliConnectionUpdatePassword(password string, passcode string, config string) {
func nmcliConnectionUpdatePasswordFlags(config string, value int) {
var cmd string

clog.WithFields(log.Fields{"config": config}).Info("Updating VPN connection with a new password.")
clog.WithFields(log.Fields{
"config": config,
"password-flags": value,
}).Debug("Updating VPN connection with a new password-flags.")

// Update VPN config to store password only for current user
cmd = fmt.Sprintf("nmcli connection mod %v vpn.secrets 'password-flags=1'", config)
cmd = fmt.Sprintf("nmcli connection mod %v +vpn.data 'password-flags=%d'", config, value)
basher(cmd, "")

clog.WithFields(log.Fields{"config": config}).Debug("VPN password-flags is updated.")
}

func nmcliConnectionUpdatePassword(password string, passcode string, config string) {
var cmd string

clog.WithFields(log.Fields{"config": config}).Info("Updating VPN connection with a new password.")

// Update VPN config with a newly generated password
fullpass := fmt.Sprintf("%v%v", password, passcode)
cmd = fmt.Sprintf("nmcli connection mod %v vpn.secrets 'password=%v'", config, fullpass)
Expand Down

0 comments on commit f8b5cb4

Please sign in to comment.