mirror of
https://github.com/dkmstr/openuds.git
synced 2024-12-25 23:21:41 +03:00
Added generic SMS using HTTP server
This commit is contained in:
parent
57b19757b9
commit
64fc61a2d6
@ -122,7 +122,7 @@ class gui:
|
|||||||
return [{'id': v, 'text': v} for v in vals]
|
return [{'id': v, 'text': v} for v in vals]
|
||||||
|
|
||||||
# Dictionary
|
# Dictionary
|
||||||
return [{'id': k, 'text': v} for k, v in vals.items()]
|
return [{'id': str(k), 'text': v} for k, v in vals.items()]
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def convertToList(vals: typing.Iterable[str]) -> typing.List[str]:
|
def convertToList(vals: typing.Iterable[str]) -> typing.List[str]:
|
||||||
|
@ -26,11 +26,9 @@ class SMSMFA(mfas.MFA):
|
|||||||
order=1,
|
order=1,
|
||||||
tooltip=_(
|
tooltip=_(
|
||||||
'URL pattern for SMS sending. It can contain the following '
|
'URL pattern for SMS sending. It can contain the following '
|
||||||
'variables:<br>'
|
'variables:\n'
|
||||||
'<ul>'
|
'* {code} - the code to send\n'
|
||||||
'<li>{code} - the code to send</li>'
|
'* {phone/+phone} - the phone number\n'
|
||||||
'<li>{phone} - the phone number</li>'
|
|
||||||
'</ul>'
|
|
||||||
),
|
),
|
||||||
required=True,
|
required=True,
|
||||||
tab=_('HTTP Server'),
|
tab=_('HTTP Server'),
|
||||||
@ -49,24 +47,39 @@ class SMSMFA(mfas.MFA):
|
|||||||
|
|
||||||
smsSendingMethod = gui.ChoiceField(
|
smsSendingMethod = gui.ChoiceField(
|
||||||
label=_('SMS sending method'),
|
label=_('SMS sending method'),
|
||||||
order=2,
|
order=3,
|
||||||
tooltip=_('Method for sending SMS'),
|
tooltip=_('Method for sending SMS'),
|
||||||
required=True,
|
required=True,
|
||||||
tab=_('HTTP Server'),
|
tab=_('HTTP Server'),
|
||||||
values=('GET', 'POST', 'PUT'),
|
values=('GET', 'POST', 'PUT'),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
smsHeadersParameters = gui.TextField(
|
||||||
|
length=4096,
|
||||||
|
multiline=4,
|
||||||
|
label=_('Headers for SMS requests'),
|
||||||
|
order=4,
|
||||||
|
tooltip=_(
|
||||||
|
'Headers for SMS requests. It can contain the following '
|
||||||
|
'variables:\n'
|
||||||
|
'* {code} - the code to send\n'
|
||||||
|
'* {phone/+phone} - the phone number\n'
|
||||||
|
'Headers are in the form of "Header: Value". (without the quotes)'
|
||||||
|
),
|
||||||
|
required=False,
|
||||||
|
tab=_('HTTP Server'),
|
||||||
|
)
|
||||||
|
|
||||||
smsSendingParameters = gui.TextField(
|
smsSendingParameters = gui.TextField(
|
||||||
length=128,
|
length=4096,
|
||||||
|
multiline=5,
|
||||||
label=_('Parameters for SMS POST/PUT sending'),
|
label=_('Parameters for SMS POST/PUT sending'),
|
||||||
order=3,
|
order=4,
|
||||||
tooltip=_(
|
tooltip=_(
|
||||||
'Parameters for SMS sending via POST/PUT. It can contain the following '
|
'Parameters for SMS sending via POST/PUT. It can contain the following '
|
||||||
'variables:<br>'
|
'variables:\n'
|
||||||
'<ul>'
|
'* {code} - the code to send\n'
|
||||||
'<li>{code} - the code to send</li>'
|
'* {phone/+phone} - the phone number\n'
|
||||||
'<li>{phone} - the phone number</li>'
|
|
||||||
'</ul>'
|
|
||||||
),
|
),
|
||||||
required=False,
|
required=False,
|
||||||
tab=_('HTTP Server'),
|
tab=_('HTTP Server'),
|
||||||
@ -74,31 +87,30 @@ class SMSMFA(mfas.MFA):
|
|||||||
|
|
||||||
smsAuthenticationMethod = gui.ChoiceField(
|
smsAuthenticationMethod = gui.ChoiceField(
|
||||||
label=_('SMS authentication method'),
|
label=_('SMS authentication method'),
|
||||||
order=3,
|
order=6,
|
||||||
tooltip=_('Method for sending SMS'),
|
tooltip=_('Method for sending SMS'),
|
||||||
required=True,
|
required=True,
|
||||||
tab=_('HTTP Server'),
|
tab=_('HTTP Server'),
|
||||||
values=[
|
values={
|
||||||
{'id': 0, 'text': _('None')},
|
'0': _('None'),
|
||||||
{'id': 1, 'text': _('HTTP Basic Auth')},
|
'1': _('HTTP Basic Auth'),
|
||||||
{'id': 2, 'text': _('HTTP Digest Auth')},
|
'2': _('HTTP Digest Auth'),
|
||||||
{'id': 3, 'text': _('HTTP Token Auth')},
|
},
|
||||||
],
|
|
||||||
)
|
)
|
||||||
|
|
||||||
smsAuthenticationUserOrToken = gui.TextField(
|
smsAuthenticationUserOrToken = gui.TextField(
|
||||||
length=128,
|
length=256,
|
||||||
label=_('SMS authentication user or token'),
|
label=_('SMS authentication user or token'),
|
||||||
order=4,
|
order=7,
|
||||||
tooltip=_('User or token for SMS authentication'),
|
tooltip=_('User or token for SMS authentication'),
|
||||||
required=False,
|
required=False,
|
||||||
tab=_('HTTP Server'),
|
tab=_('HTTP Server'),
|
||||||
)
|
)
|
||||||
|
|
||||||
smsAuthenticationPassword = gui.TextField(
|
smsAuthenticationPassword = gui.TextField(
|
||||||
length=128,
|
length=256,
|
||||||
label=_('SMS authentication password'),
|
label=_('SMS authentication password'),
|
||||||
order=5,
|
order=8,
|
||||||
tooltip=_('Password for SMS authentication'),
|
tooltip=_('Password for SMS authentication'),
|
||||||
required=False,
|
required=False,
|
||||||
tab=_('HTTP Server'),
|
tab=_('HTTP Server'),
|
||||||
@ -110,27 +122,31 @@ class SMSMFA(mfas.MFA):
|
|||||||
def composeSmsUrl(self, code: str, phone: str) -> str:
|
def composeSmsUrl(self, code: str, phone: str) -> str:
|
||||||
url = self.smsSendingUrl.value
|
url = self.smsSendingUrl.value
|
||||||
url = url.replace('{code}', code)
|
url = url.replace('{code}', code)
|
||||||
url = url.replace('{phone}', phone)
|
url = url.replace('{phone}', phone.replace('+', ''))
|
||||||
|
url = url.replace('{+phone}', phone)
|
||||||
return url
|
return url
|
||||||
|
|
||||||
def getSession(self) -> requests.Session:
|
def getSession(self) -> requests.Session:
|
||||||
session = requests.Session()
|
session = requests.Session()
|
||||||
# 0 means no authentication
|
# 0 means no authentication
|
||||||
if self.smsAuthenticationMethod.value == 1:
|
if self.smsAuthenticationMethod.value == '1':
|
||||||
session.auth = requests.auth.HTTPBasicAuth(
|
session.auth = requests.auth.HTTPBasicAuth(
|
||||||
username=self.smsAuthenticationUserOrToken.value,
|
username=self.smsAuthenticationUserOrToken.value,
|
||||||
password=self.smsAuthenticationPassword.value,
|
password=self.smsAuthenticationPassword.value,
|
||||||
)
|
)
|
||||||
elif self.smsAuthenticationMethod.value == 2:
|
elif self.smsAuthenticationMethod.value == '2':
|
||||||
session.auth = requests.auth.HTTPDigestAuth(
|
session.auth = requests.auth.HTTPDigestAuth(
|
||||||
self.smsAuthenticationUserOrToken.value,
|
self.smsAuthenticationUserOrToken.value,
|
||||||
self.smsAuthenticationPassword.value,
|
self.smsAuthenticationPassword.value,
|
||||||
)
|
)
|
||||||
elif self.smsAuthenticationMethod.value == 3:
|
|
||||||
session.headers['Authorization'] = (
|
|
||||||
'Token ' + self.smsAuthenticationUserOrToken.value
|
|
||||||
)
|
|
||||||
# Any other value means no authentication
|
# Any other value means no authentication
|
||||||
|
|
||||||
|
# Add headers. Headers are in the form of "Header: Value". (without the quotes)
|
||||||
|
if self.smsHeadersParameters.value.strip():
|
||||||
|
for header in self.smsHeadersParameters.value.split('\n'):
|
||||||
|
if header.strip():
|
||||||
|
headerName, headerValue = header.split(':', 1)
|
||||||
|
session.headers[headerName.strip()] = headerValue.strip()
|
||||||
return session
|
return session
|
||||||
|
|
||||||
def sendSMS_GET(self, url: str) -> None:
|
def sendSMS_GET(self, url: str) -> None:
|
||||||
@ -143,7 +159,7 @@ class SMSMFA(mfas.MFA):
|
|||||||
data = ''
|
data = ''
|
||||||
if self.smsSendingParameters.value:
|
if self.smsSendingParameters.value:
|
||||||
data = self.smsSendingParameters.value.replace('{code}', code).replace(
|
data = self.smsSendingParameters.value.replace('{code}', code).replace(
|
||||||
'{phone}', phone
|
'{phone}', phone.replace('+', '').replace('{+phone}', phone)
|
||||||
)
|
)
|
||||||
response = self.getSession().post(url, data=data.encode())
|
response = self.getSession().post(url, data=data.encode())
|
||||||
if response.status_code != 200:
|
if response.status_code != 200:
|
||||||
|
Loading…
Reference in New Issue
Block a user