diff --git a/CHANGELOG.md b/CHANGELOG.md index 413a53a..9b15722 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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. diff --git a/main.go b/main.go index a2cfb28..ebc9293 100644 --- a/main.go +++ b/main.go @@ -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 @@ -43,6 +43,9 @@ func main() { flag.Parse() // Setup logging + log.SetFormatter(&log.TextFormatter{ + FullTimestamp: true, + }) log.SetOutput(os.Stdout) if showVersion { @@ -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.") } diff --git a/nmcli.go b/nmcli.go index 735a99f..dffb96a 100644 --- a/nmcli.go +++ b/nmcli.go @@ -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)