Basic auth

This commit is contained in:
Xavier Henner
2019-08-17 00:16:57 +02:00
parent 9eff9ce803
commit 2eb4f9e4ea
5 changed files with 78 additions and 5 deletions

View File

@@ -82,6 +82,12 @@ func (s *OpenVpnMgt) GetSession(pid int) (error, *OpenVpnSrv) {
if openvpn, ok := s.VpnServers[pid]; ok {
return nil, openvpn
}
// if there is only 1 session, ignore the pid parameter
if len(s.VpnServers) == 1 {
for _, openvpn := range s.VpnServers {
return nil, openvpn
}
}
return errors.New(fmt.Sprintf("unknown session %d", pid)), nil
}
@@ -96,6 +102,16 @@ func (s *OpenVpnMgt) Restart(pid int) error {
return nil
}
func (s *OpenVpnMgt) AuthUserPass(pid int, user, pass string) error {
// check if the session is valid
err, session := s.GetSession(pid)
if err != nil {
return err
}
session.AuthUserPass(user, pass)
return nil
}
func (s *OpenVpnMgt) Kill(pid int) error {
// check if the session is valid
err, session := s.GetSession(pid)
@@ -143,7 +159,6 @@ func (s *OpenVpnMgt) Remove(openvpn *OpenVpnSrv) {
delete(s.VpnServers, pid)
}
}
}
// send the version command on all vpn servers. Kind of useless
@@ -229,6 +244,8 @@ func (s *OpenVpnMgt) handleConn(conn net.Conn) {
remoteMatch := remoteRegexp.FindStringSubmatch(line)
switch {
// command successfull, we can ignore
case strings.HasPrefix(line, ">PASSWORD:"):
go openvpn.NeedPassword(line)
case strings.HasPrefix(line, ">HOLD"):
go openvpn.waitForRelase()
case len(remoteMatch) > 0: