2019-06-24 10:46:06 +00:00
|
|
|
import binascii
|
|
|
|
import requests
|
|
|
|
|
|
|
|
from decouple import config
|
|
|
|
from pyotp import TOTP
|
|
|
|
|
2019-06-24 12:43:48 +00:00
|
|
|
|
2019-07-03 12:47:24 +00:00
|
|
|
def check_otp(name, realm, token):
|
2019-06-24 10:46:06 +00:00
|
|
|
try:
|
|
|
|
data = {
|
2019-07-18 12:10:17 +00:00
|
|
|
"auth_name": config("AUTH_NAME", ""),
|
|
|
|
"auth_token": TOTP(config("AUTH_SEED", "")).now(),
|
|
|
|
"auth_realm": config("AUTH_REALM", ""),
|
2019-06-24 10:46:06 +00:00
|
|
|
"name": name,
|
|
|
|
"realm": realm,
|
2019-07-18 12:10:17 +00:00
|
|
|
"token": token,
|
2019-06-24 10:46:06 +00:00
|
|
|
}
|
|
|
|
except binascii.Error:
|
|
|
|
return 400
|
|
|
|
|
|
|
|
response = requests.post(
|
|
|
|
"{OTP_SERVER}{OTP_VERIFY_ENDPOINT}".format(
|
2019-07-18 12:10:17 +00:00
|
|
|
OTP_SERVER=config("OTP_SERVER", ""),
|
|
|
|
OTP_VERIFY_ENDPOINT=config("OTP_VERIFY_ENDPOINT", "verify/"),
|
2019-06-24 10:46:06 +00:00
|
|
|
),
|
2019-07-18 12:10:17 +00:00
|
|
|
data=data,
|
2019-06-24 10:46:06 +00:00
|
|
|
)
|
|
|
|
return response.status_code
|
2019-07-03 12:47:24 +00:00
|
|
|
|
|
|
|
|
|
|
|
def add_otp_args(parser):
|
|
|
|
parser.add_argument("name", required=True)
|
|
|
|
parser.add_argument("realm", required=True)
|
|
|
|
parser.add_argument("token", required=True)
|
|
|
|
return parser
|
|
|
|
|
|
|
|
|
|
|
|
def add_vmid_args(parser):
|
|
|
|
parser.add_argument("vmid", required=True)
|
|
|
|
return parser
|