]> git.r.bdr.sh - rbdr/dead-drop/commitdiff
Check the Account SID (#3)
authorRubén Beltrán del Río <redacted>
Sun, 19 Feb 2017 07:59:26 +0000 (01:59 -0600)
committerGitHub <redacted>
Sun, 19 Feb 2017 07:59:26 +0000 (01:59 -0600)
* Add twilio config to readme

* Modify wording of main menu.

* Modify wording of recording message

* Add account sid setting to readme

* Add the twilio account sid to config

* Add check for accountSid

* Update paw to send AccountSid

README.md
config/config.js
config/env.dist
etc/dead_drop.paw
lib/controllers/main_menu.js
lib/controllers/recordings.js
lib/dead_drop.js

index 7690f61490a23b9b3125290282e452d46c655033..39d2086d10dbf2fbc5b0fe1232a7b530d1f1398d 100644 (file)
--- a/README.md
+++ b/README.md
@@ -9,7 +9,9 @@ the file in `config/env.dist` to `.env` in the project root and override
 the values.
 
 When running with `make run`, it'll pick up these values automatically.
-If you're doing it the hard way, you'll have to source them.
+If you're doing it the hard way, you'll have to source them. You must
+set the `DEAD_DROP_ACCOUNT_SID` to match your account sid. This is so
+dead drop can filter out calls from other accounts.
 
 ## Running Locally
 
@@ -41,7 +43,14 @@ You can also do some other operations
 
 ## Setting up Twilio
 
-TBD
+Get a twilio number, and on the configuration set the voice settings to
+"Webhooks/TwiML" and point the `A call comes in` hook to:
+the `/menus/main/` path of your dead drop installation. For example: 
+`https://dead-drop.unlimited.piza/menus/main`. It must be accessible
+from the internet.
+
+You will also need your account sid. This is obtained from the "[Account
+Settings][account-settings]" area in the twilio dashboard.
 
 ## Checking the code
 
@@ -51,3 +60,4 @@ javascript style, and includes eslint configuration to check them. Run
 
 [docker]: https://www.docker.com/
 [hapi-style-guide]: https://hapijs.com/styleguide
+[account-settings]: https://www.twilio.com/console/account/settings
index 16e9a9f017dad1f581b82aa03aa0150c40542b5c..b1a1fac1fd7f5da09c06a3fb92d2456b5225ef11 100644 (file)
@@ -12,11 +12,13 @@ const internals = {};
  * @memberof DeadDrop
  * @typedef {object} tConfiguration
  * @property {number} [port=1988] the port where the app will listen on
+ * @property {string} twilioAccountSid the twilio account sid used to authorize calls
  * @property {DeadDrop.tRedisConfiguration} redis the configuration to
  * connect to the redis server
  */
 module.exports = internals.Config = {
   port: Getenv.int('DEAD_DROP_PORT', 1988),
+  twilioAccountSid: Getenv('DEAD_DROP_TWILIO_ACCOUNT_SID'),
 
   /**
    * Information required to connect to the redis server
index 11f79f10feb4e6d9ffc2a5a53d96307b75081184..5686169dfb1a36af3c02bec8960f03bd9ecec915 100644 (file)
@@ -1 +1,2 @@
 DEAD_DROP_REDIS_HOST=location_of_redis_server
+DEAD_DROP_TWILIO_ACCOUNT_SID=your_twilio_account_sid
index 4627b2d912558807bdae42d07341926173ba1d80..3aeaca6a2aa020b1de462170c3cac9b65d311bbf 100644 (file)
Binary files a/etc/dead_drop.paw and b/etc/dead_drop.paw differ
index 461cff819e8a31ef11fb3ee817968e0c6981d809..06e172bf6d251918d53c5adb860fb996ce40f7bc 100644 (file)
@@ -13,9 +13,9 @@ internals.kMainMenuRoute = '/menus/main';
 internals.kRecordingMenuRoute = '/menus/recording';
 internals.kRandomMessageRoute = '/recordings/0';
 internals.kLeaveMessageRoute = '/recordings';
-internals.kMenuMessage = 'Para dejar un mensaje, presiona 1. ' +
-                         'Para escuchar un mensaje al azar, presiona 2. ' +
-                         'Para escuchar un mensaje específico, presioan 3.'; // the message that will be shown
+internals.kMenuMessage = 'Marca 1 para grabar mensaje. ' +
+                         'Marca 2 para escuchar mensaje al azar. ' +
+                         'Marca 3 si conoces el número de mensaje'; // the message that will be shown
 internals.kMenuInvalidResponseMessage = 'No entendí... Volviendo al menu principal.'; // invalid selection message
 internals.kMenuOptions = {
   leaveMessage: 1,
index 591dbd5d05d024aa860bc052cfd5c750e9ea803f..c7a75843779efabbc307ed25721e8b8b9c91c399 100644 (file)
@@ -10,10 +10,9 @@ const internals = {};
 internals.kContentType = 'application/xml'; // The content type used to respond
 internals.kLanguage = 'es-mx'; // the language to use
 internals.kMaxMessageLength = 30; // max message length in seconds
-internals.kIdDateFormat = 'YYMMDDHHmmssSSS'; // derive ids from current date. 15 digits.
 internals.kRecordingsSet = 'recordings';
-internals.kRecordMessage = 'Graba tu mensaje despues del bip. ' +
-                           'Presiona cualquier tecla para finalizar tu mensaje. '; // the recording message
+internals.kRecordMessage = 'Graba tu mensaje despues del bip y ' +
+                           'presiona cualquier tecla para finalizar. '; // the recording message
 internals.kConfirmationMessage = 'Gracias. Tu mensaje es el número: ';
 internals.kNotFoundMessage = 'Mensaje no encontrado. Adiós!';
 
index 6f976459e18231d8ed5fbd0cb950b33b0024ca7d..3336444e7e1246489a504738ac8c665ba9ae6b3e 100644 (file)
@@ -45,10 +45,24 @@ module.exports = internals.DeadDrop = class DeadDrop {
 
   _initializeServer() {
 
+    const self = this;
+
     this._app = Koa();
 
     this._app.use(KoaBodyParser());
 
+    this._app.use(function * (next) {
+
+      const accountSid = this.request.body.AccountSid || this.request.query.AccountSid;
+
+      if (accountSid === self.twilioAccountSid) {
+        yield next;
+      }
+      else {
+        this.throw('Unauthorized', 401);
+      }
+    });
+
     this._initializeMainMenuRoutes();
     this._initializeRecordingMenuRoutes();
     this._initializeRecordingsRoutes();