-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
21 changed files
with
241 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export API_KEY="your africas api key" | ||
export USERNAME="your africastalking username" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,3 @@ | ||
release: python manage.py makemigrations | ||
release: python manage.py migrate | ||
release: python manage.py ensuretriggers | ||
release: python manage.py sendalerts | ||
web: gunicorn hc.wsgi --log-file - |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import base64 | ||
import hashlib | ||
|
||
from Crypto import Random | ||
from Crypto.Cipher import AES | ||
|
||
class AESCipher(object): | ||
""" | ||
A classical AES Cipher. Can use any size of data and any size of password thanks to padding. | ||
Also ensure the coherence and the type of the data with a unicode to byte converter. | ||
""" | ||
def __init__(self, key): | ||
self.bs = 32 | ||
self.key = hashlib.sha256(AESCipher.str_to_bytes(key)).digest() | ||
|
||
@staticmethod | ||
def str_to_bytes(data): | ||
u_type = type(b''.decode('utf8')) | ||
if isinstance(data, u_type): | ||
return data.encode('utf8') | ||
return data | ||
|
||
def _pad(self, s): | ||
return s + (self.bs - len(s) % self.bs) * AESCipher.str_to_bytes(chr(self.bs - len(s) % self.bs)) | ||
|
||
@staticmethod | ||
def _unpad(s): | ||
return s[:-ord(s[len(s)-1:])] | ||
|
||
def encrypt(self, raw): | ||
raw = self._pad(AESCipher.str_to_bytes(raw)) | ||
iv = Random.new().read(AES.block_size) | ||
cipher = AES.new(self.key, AES.MODE_CBC, iv) | ||
return base64.b64encode(iv + cipher.encrypt(raw)).decode('utf-8') | ||
|
||
def decrypt(self, enc): | ||
enc = base64.b64decode(enc) | ||
iv = enc[:AES.block_size] | ||
cipher = AES.new(self.key, AES.MODE_CBC, iv) | ||
return self._unpad(cipher.decrypt(enc[AES.block_size:])).decode('utf-8') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import json | ||
from hc.api.models import Channel | ||
from hc.test import BaseTestCase | ||
|
||
|
||
class AddSMSTestCase(BaseTestCase): | ||
|
||
def test_sms_works(self): | ||
self.client.login(username="alice@example.org", password="password") | ||
r = self.client.get("/integrations/add_sms/") | ||
self.assertContains(r, "Integration Settings", status_code=200) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
from django.conf import settings | ||
from djmail.template_mail import InlineCSSTemplateMail | ||
|
||
def send(name, to, ctx): | ||
o = InlineCSSTemplateMail(name) | ||
ctx["SITE_ROOT"] = settings.SITE_ROOT | ||
o.send(to, ctx) | ||
|
||
def alert(to, ctx): | ||
send("alert", to, ctx) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import os | ||
import dj_database_url | ||
|
||
DATABASES = { | ||
'default': { | ||
'ENGINE': 'django.db.backends.postgresql', | ||
'NAME': 'hc', | ||
'USER': 'postgres', | ||
'TEST': {'CHARSET': 'UTF8'} | ||
} | ||
} | ||
|
||
if os.getenv('DATABASE_URL'): | ||
db_from_env = dj_database_url.config() | ||
STATICFILES_STORAGE = 'whitenoise.django.GzipManifestStaticFilesStorage' | ||
DATABASES['default'].update(db_from_env) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.