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