1
0
Fork 0
mirror of synced 2024-11-22 09:05:34 -05:00

Add check commnad; Fixes

This commit is contained in:
Ilya Sosnovsky 2021-02-05 21:19:54 +03:00
parent 2659cce1f7
commit 43c0962f25
2 changed files with 15 additions and 5 deletions

View file

@ -1,7 +1,10 @@
# openvpn-user # openvpn-user
### disclaimer ## Disclaimer
Not tested in production environments! ```diff
- Not tested in production environments!
```
Use it on your own risk =) Use it on your own risk =)
@ -9,14 +12,16 @@ Use it on your own risk =)
A simple tool to use with openvpn when you need to use `auth-user-pass-verify` or wherever you want A simple tool to use with openvpn when you need to use `auth-user-pass-verify` or wherever you want
### Example ### Example
make sure `openvpn-user` binary available through `PATH` variable and you have `auth.sh` script with `+x` rights available to openvpn server
i.e. put binary to `/usr/local/sbin/` and auth script to `/etc/openvpn/scripts/` dir
part of openvpn server config part of openvpn server config
```bash ```bash
script-security 2
auth-user-pass-verify /etc/openvpn/scripts/auth.sh via-file auth-user-pass-verify /etc/openvpn/scripts/auth.sh via-file
``` ```
make sure `openvpn-user` binary available through `PATH` variable
i.e. put it in `/usr/local/sbin/openvpn-user`
### Usage ### Usage
``` ```

View file

@ -32,6 +32,9 @@ var (
listCommand = kingpin.Command("list", "List active users.") listCommand = kingpin.Command("list", "List active users.")
listAll = listCommand.Flag("all", "Show all users include revoked and deleted.").Default("false").Bool() listAll = listCommand.Flag("all", "Show all users include revoked and deleted.").Default("false").Bool()
checkCommand = kingpin.Command("check", "check user existent.")
checkCommandUserFlag = checkCommand.Flag("user", "Username.").Required().String()
authCommand = kingpin.Command("auth", "Auth user.") authCommand = kingpin.Command("auth", "Auth user.")
authCommandUserFlag = authCommand.Flag("user", "Username.").Required().String() authCommandUserFlag = authCommand.Flag("user", "Username.").Required().String()
authCommandPasswordFlag = authCommand.Flag("password", "Password.").Required().String() authCommandPasswordFlag = authCommand.Flag("password", "Password.").Required().String()
@ -66,6 +69,8 @@ func main() {
restoreUser(*restoreCommandUserFlag) restoreUser(*restoreCommandUserFlag)
case listCommand.FullCommand(): case listCommand.FullCommand():
printUsers() printUsers()
case checkCommand.FullCommand():
_ = checkUserExistent(*checkCommandUserFlag)
case authCommand.FullCommand(): case authCommand.FullCommand():
authUser(*authCommandUserFlag, *authCommandPasswordFlag) authUser(*authCommandUserFlag, *authCommandPasswordFlag)
case changePasswordCommand.FullCommand(): case changePasswordCommand.FullCommand():
@ -128,7 +133,7 @@ func restoreUser(username string) {
func checkUserExistent(username string) bool { func checkUserExistent(username string) bool {
// we need to check if there is already such a user // we need to check if there is already such a user
// return true if user exist
var c int var c int
_ = getDb().QueryRow("SELECT count(*) FROM users WHERE username = $1", username).Scan(&c) _ = getDb().QueryRow("SELECT count(*) FROM users WHERE username = $1", username).Scan(&c)
if c == 1 { if c == 1 {