Support for username and password changes
This commit is contained in:
@@ -1,20 +1,28 @@
|
||||
package openvpn
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"github.com/qdm12/golibs/files"
|
||||
"github.com/qdm12/private-internet-access-docker/internal/constants"
|
||||
)
|
||||
|
||||
// WriteAuthFile writes the OpenVPN auth file to disk with the right permissions
|
||||
func (c *configurator) WriteAuthFile(user, password string, uid, gid int) error {
|
||||
authExists, err := c.fileManager.FileExists(string(constants.OpenVPNAuthConf))
|
||||
exists, err := c.fileManager.FileExists(string(constants.OpenVPNAuthConf))
|
||||
if err != nil {
|
||||
return err
|
||||
} else if authExists { // in case of container stop/start
|
||||
c.logger.Info("%s already exists", constants.OpenVPNAuthConf)
|
||||
return nil
|
||||
} else if exists {
|
||||
data, err := c.fileManager.ReadFile(string(constants.OpenVPNAuthConf))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
lines := strings.Split(string(data), "\n")
|
||||
if len(lines) > 1 && lines[0] == user && lines[1] == password {
|
||||
return nil
|
||||
}
|
||||
c.logger.Info("username and password changed", constants.OpenVPNAuthConf)
|
||||
}
|
||||
c.logger.Info("writing auth file %s", constants.OpenVPNAuthConf)
|
||||
return c.fileManager.WriteLinesToFile(
|
||||
string(constants.OpenVPNAuthConf),
|
||||
[]string{user, password},
|
||||
|
||||
Reference in New Issue
Block a user