| Server IP : 85.214.239.14 / Your IP : 216.73.216.27 Web Server : Apache/2.4.65 (Debian) System : Linux h2886529.stratoserver.net 4.9.0 #1 SMP Mon Sep 30 15:36:27 MSK 2024 x86_64 User : www-data ( 33) PHP Version : 8.2.29 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : OFF Directory : /proc/3/task/3/root/srv/modoboa/env/lib/python3.5/site-packages/modoboa/core/sms_backends/ |
Upload File : |
"""OVH SMS backend."""
import ovh
from django import forms
from django.utils.functional import cached_property
from django.utils.translation import ugettext_lazy as _
from . import SMSBackend
class OVHBackend(SMSBackend):
"""OVH SMS backend class."""
settings = {
"sms_ovh_endpoint": {
"type": forms.ChoiceField,
"attrs": {
"label": _("API endpoint"),
"initial": "ovh-eu",
"choices": (
("ovh-eu", _("OVH Europe")),
("ovh-us", _("OVH US")),
("ovh-ca", _("OVH North-America")),
("soyoustart-eu", _("So you Start Europe")),
("soyoustart-ca", _("So you Start North America")),
("kimsufi-eu", _("Kimsufi Europe")),
("kimsufi-ca", _("Kimsufi North America")),
)
}
},
"sms_ovh_application_key": {
"type": forms.CharField,
"attrs": {
"label": _("Application key"),
"required": False
}
},
"sms_ovh_application_secret": {
"type": forms.CharField,
"attrs": {
"label": _("Application secret"),
"widget": forms.widgets.PasswordInput(render_value=True),
"required": False
}
},
"sms_ovh_consumer_key": {
"type": forms.CharField,
"attrs": {
"label": _("Consumer key"),
"widget": forms.widgets.PasswordInput(render_value=True),
"required": False
}
}
}
visibility_rules = {
"sms_ovh_endpoint": "sms_provider=ovh",
"sms_ovh_application_key": "sms_provider=ovh",
"sms_ovh_application_secret": "sms_provider=ovh",
"sms_ovh_consumer_key": "sms_provider=ovh"
}
@cached_property
def client(self):
return ovh.Client(
endpoint=self._params.get_value("sms_ovh_endpoint"),
application_key=self._params.get_value("sms_ovh_application_key"),
application_secret=self._params.get_value("sms_ovh_application_secret"),
consumer_key=self._params.get_value("sms_ovh_consumer_key")
)
def send(self, text, recipients):
"""Send a new SMS to given recipients."""
services = self.client.get("/sms")
result = self.client.post(
"/sms/{}/jobs".format(services[0]),
message=text,
receivers=recipients,
priority="high",
noStopClause=True,
senderForResponse=True
)
if result["totalCreditsRemoved"] != len(recipients):
return False
return True