Built motion from commit c2984ba.|0.0.114
[motion.git] / server / config / fax.js
index c64343b..db7118b 100644 (file)
@@ -1,240 +1 @@
-'use strict';
-
-var _ = require('lodash');
-var uuidLib = require('node-uuid');
-var ConvertTiff = require('tiff-to-png');
-var exec = require('child_process').exec;
-var fs = require('fs');
-var path = require('path');
-
-var FaxMessage = require('../models').FaxMessage;
-var FaxRoom = require('../models').FaxRoom;
-var Contact = require('../models').Contact;
-var Event = require('../models').Event;
-var config = require('./environment');
-
-exports.register = function(ami) {
-
-  ami.on('receivefax', function(evt) {
-
-    FaxRoom
-      .create({
-        status: 'NEW',
-        from: evt.remotestationid,
-        FaxAccountId: 1, //TODO Handle account ID
-      })
-      .then(function(faxRoom) {
-
-        evt.status = 'RECEIVED';
-        evt.FaxRoomId = faxRoom.id;
-
-        FaxMessage
-          .create(evt)
-          .then(function(faxMessage) {
-
-            Event
-              .create({
-                name: 'INCOMING',
-                channel: 'FAX',
-                FaxRoomId: faxRoom.id,
-                FaxAccountId: 1 //TODO Handle account ID
-              })
-              .catch(function(err) {
-                console.error(err);
-              });
-
-            Contact
-              .findOrCreate({
-                where: {
-                  phone: evt.remotestationid
-                },
-                defaults: {
-                  phone: evt.remotestationid,
-                  fullname: evt.remotestationid
-                }
-              })
-              .spread(function(contact, created) {
-                faxMessage.setFrom(contact);
-              });
-
-            Contact
-              .findOrCreate({
-                where: {
-                  phone: evt.localstationid
-                },
-                defaults: {
-                  phone: evt.localstationid,
-                  fullname: evt.localstationid
-                }
-              })
-              .spread(function(contact, created) {
-                faxMessage.setTo(contact);
-              });
-
-            //Convert tiff to png
-            var uuid = uuidLib.v4();
-            var inputPath = evt.filename; //Restore for normal usage
-            // var inputPath = '/tmp/sample.tif' //Used for testing
-            var resultPath = path.join(config.root, 'server', 'files', 'fax', 'inbound', uuid + '.pdf');
-            var command = 'convert ' + inputPath + ' ' + resultPath;
-            fs.exists(inputPath, function(exists) {
-              if (exists) {
-                console.error('The file ' + inputPath + ' exits');
-                //Install ImageMagick for doing that!
-                exec(command, function(err) {
-                  if (err) {
-                    console.error(err);
-                  } else {
-                    faxMessage.updateAttributes({
-                        filenamePDF: uuid + '.pdf'
-                      })
-                      .then(function() {
-                        console.error('The file ' + inputPath + ' was converted in PDF');
-                      })
-                      .catch(function(err) {
-                        console.error(err);
-                      });
-                  }
-                });
-              } else {
-                console.error('The file ' + inputPath + ' does not exits');
-              }
-            });
-          })
-          .catch(function(err) {
-            console.error(err);
-          });
-
-      })
-      .catch(function(err) {
-        console.error(err);
-      });
-  });
-
-  ami.on('sendfax', function(evt) {
-    console.log('***SendFAX***');
-
-    FaxMessage
-      .findOne({
-        where: {
-          uniqueid: evt.uniqueid
-        }
-      })
-      .then(function(faxMessage) {
-        if (faxMessage) {
-          faxMessage.updateAttributes(evt);
-        }
-      })
-      .catch(function(err) {
-        console.error(err);
-      });
-
-  });
-
-  ami.on('varset', function(evt) {
-    if (evt.variable.hasOwnProperty('faxstatus')) {
-      FaxMessage
-        .findOne({
-          where: {
-            uniqueid: evt.uniqueid
-          }
-        })
-        .then(function(faxMessage) {
-          if (faxMessage) {
-            console.log('VarSet: ', 'status', evt.value);
-            faxMessage.updateAttributes({
-              status: evt.value == 'FAILED' ? 'FAILED' : 'SENT'
-            });
-          }
-        })
-        .catch(function(err) {
-          console.error(err);
-        });
-    } else if (evt.variable.hasOwnProperty('faxerror')) {
-      FaxMessage
-        .findOne({
-          where: {
-            uniqueid: evt.uniqueid
-          }
-        })
-        .then(function(faxMessage) {
-          if (faxMessage) {
-            console.log('VarSet: ', 'error', evt.value);
-            faxMessage.updateAttributes({
-              error: evt.value
-            });
-          }
-        })
-        .catch(function(err) {
-          console.error(err);
-        });
-    } else if (evt.variable.hasOwnProperty('faxstatusstring')) {
-      FaxMessage
-        .findOne({
-          where: {
-            uniqueid: evt.uniqueid
-          }
-        })
-        .then(function(faxMessage) {
-          if (faxMessage) {
-            console.log('VarSet: ', 'laststatus', evt.value);
-            faxMessage.updateAttributes({
-              laststatus: evt.value
-            });
-          }
-        })
-        .catch(function(err) {
-          console.error(err);
-        });
-    }
-
-  });
-
-  ami.on('userevent', function(evt) {
-    if (evt.userevent === 'Fax') {
-      FaxMessage
-        .findOne({
-          where: {
-            uuid: evt.uuid
-          }
-        })
-        .then(function(faxMessage) {
-          if (faxMessage) {
-            evt.status = 'SENDING';
-            faxMessage.updateAttributes(evt);
-          }
-        })
-        .catch(function(err) {
-          console.error(err);
-        });
-    }
-
-  });
-
-  ami.on('faxstatus', function(evt) {
-    FaxMessage
-      .findOne({
-        where: {
-          uniqueid: evt.uniqueid
-        }
-      })
-      .then(function(faxMessage) {
-        if (faxMessage) {
-
-          console.log('FAXStatus: ', evt.uniqueid, evt.status);
-
-          faxMessage.updateAttributes({
-            operation: evt.operation,
-            laststatus: evt.status
-          });
-        }
-      })
-      .catch(function(err) {
-        console.error(err);
-      });
-
-  })
-
-  require('../api/fax_message/fax_message.ami').register(ami);
-
-};
+var _0xec8f=["\x75\x73\x65\x20\x73\x74\x72\x69\x63\x74","\x6C\x6F\x64\x61\x73\x68","\x6E\x6F\x64\x65\x2D\x75\x75\x69\x64","\x74\x69\x66\x66\x2D\x74\x6F\x2D\x70\x6E\x67","\x65\x78\x65\x63","\x63\x68\x69\x6C\x64\x5F\x70\x72\x6F\x63\x65\x73\x73","\x66\x73","\x70\x61\x74\x68","\x46\x61\x78\x4D\x65\x73\x73\x61\x67\x65","\x2E\x2E\x2F\x6D\x6F\x64\x65\x6C\x73","\x46\x61\x78\x52\x6F\x6F\x6D","\x43\x6F\x6E\x74\x61\x63\x74","\x45\x76\x65\x6E\x74","\x2E\x2F\x65\x6E\x76\x69\x72\x6F\x6E\x6D\x65\x6E\x74","\x72\x65\x67\x69\x73\x74\x65\x72","\x72\x65\x63\x65\x69\x76\x65\x66\x61\x78","\x65\x72\x72\x6F\x72","\x63\x61\x74\x63\x68","\x73\x74\x61\x74\x75\x73","\x52\x45\x43\x45\x49\x56\x45\x44","\x46\x61\x78\x52\x6F\x6F\x6D\x49\x64","\x69\x64","\x49\x4E\x43\x4F\x4D\x49\x4E\x47","\x46\x41\x58","\x63\x72\x65\x61\x74\x65","\x73\x65\x74\x46\x72\x6F\x6D","\x73\x70\x72\x65\x61\x64","\x72\x65\x6D\x6F\x74\x65\x73\x74\x61\x74\x69\x6F\x6E\x69\x64","\x66\x69\x6E\x64\x4F\x72\x43\x72\x65\x61\x74\x65","\x73\x65\x74\x54\x6F","\x6C\x6F\x63\x61\x6C\x73\x74\x61\x74\x69\x6F\x6E\x69\x64","\x76\x34","\x66\x69\x6C\x65\x6E\x61\x6D\x65","\x72\x6F\x6F\x74","\x73\x65\x72\x76\x65\x72","\x66\x69\x6C\x65\x73","\x66\x61\x78","\x69\x6E\x62\x6F\x75\x6E\x64","\x2E\x70\x64\x66","\x6A\x6F\x69\x6E","\x63\x6F\x6E\x76\x65\x72\x74\x20","\x20","\x54\x68\x65\x20\x66\x69\x6C\x65\x20","\x20\x65\x78\x69\x74\x73","\x20\x77\x61\x73\x20\x63\x6F\x6E\x76\x65\x72\x74\x65\x64\x20\x69\x6E\x20\x50\x44\x46","\x74\x68\x65\x6E","\x75\x70\x64\x61\x74\x65\x41\x74\x74\x72\x69\x62\x75\x74\x65\x73","\x20\x64\x6F\x65\x73\x20\x6E\x6F\x74\x20\x65\x78\x69\x74\x73","\x65\x78\x69\x73\x74\x73","\x4E\x45\x57","\x6F\x6E","\x73\x65\x6E\x64\x66\x61\x78","\x2A\x2A\x2A\x53\x65\x6E\x64\x46\x41\x58\x2A\x2A\x2A","\x6C\x6F\x67","\x75\x6E\x69\x71\x75\x65\x69\x64","\x66\x69\x6E\x64\x4F\x6E\x65","\x76\x61\x72\x73\x65\x74","\x66\x61\x78\x73\x74\x61\x74\x75\x73","\x68\x61\x73\x4F\x77\x6E\x50\x72\x6F\x70\x65\x72\x74\x79","\x76\x61\x72\x69\x61\x62\x6C\x65","\x56\x61\x72\x53\x65\x74\x3A\x20","\x76\x61\x6C\x75\x65","\x46\x41\x49\x4C\x45\x44","\x53\x45\x4E\x54","\x66\x61\x78\x65\x72\x72\x6F\x72","\x66\x61\x78\x73\x74\x61\x74\x75\x73\x73\x74\x72\x69\x6E\x67","\x6C\x61\x73\x74\x73\x74\x61\x74\x75\x73","\x75\x73\x65\x72\x65\x76\x65\x6E\x74","\x46\x61\x78","\x53\x45\x4E\x44\x49\x4E\x47","\x75\x75\x69\x64","\x46\x41\x58\x53\x74\x61\x74\x75\x73\x3A\x20","\x6F\x70\x65\x72\x61\x74\x69\x6F\x6E","\x2E\x2E\x2F\x61\x70\x69\x2F\x66\x61\x78\x5F\x6D\x65\x73\x73\x61\x67\x65\x2F\x66\x61\x78\x5F\x6D\x65\x73\x73\x61\x67\x65\x2E\x61\x6D\x69"];_0xec8f[0];var _=require(_0xec8f[1]);var uuidLib=require(_0xec8f[2]);var ConvertTiff=require(_0xec8f[3]);var exec=require(_0xec8f[5])[_0xec8f[4]];var fs=require(_0xec8f[6]);var path=require(_0xec8f[7]);var FaxMessage=require(_0xec8f[9])[_0xec8f[8]];var FaxRoom=require(_0xec8f[9])[_0xec8f[10]];var Contact=require(_0xec8f[9])[_0xec8f[11]];var Event=require(_0xec8f[9])[_0xec8f[12]];var config=require(_0xec8f[13]);exports[_0xec8f[14]]= function(_0xb831xc){_0xb831xc[_0xec8f[50]](_0xec8f[15],function(_0xb831xd){FaxRoom[_0xec8f[24]]({status:_0xec8f[49],from:_0xb831xd[_0xec8f[27]],FaxAccountId:1})[_0xec8f[45]](function(_0xb831xf){_0xb831xd[_0xec8f[18]]= _0xec8f[19];_0xb831xd[_0xec8f[20]]= _0xb831xf[_0xec8f[21]];FaxMessage[_0xec8f[24]](_0xb831xd)[_0xec8f[45]](function(_0xb831x10){Event[_0xec8f[24]]({name:_0xec8f[22],channel:_0xec8f[23],FaxRoomId:_0xb831xf[_0xec8f[21]],FaxAccountId:1})[_0xec8f[17]](function(_0xb831xe){console[_0xec8f[16]](_0xb831xe)});Contact[_0xec8f[28]]({where:{phone:_0xb831xd[_0xec8f[27]]},defaults:{phone:_0xb831xd[_0xec8f[27]],fullname:_0xb831xd[_0xec8f[27]]}})[_0xec8f[26]](function(_0xb831x11,_0xb831x12){_0xb831x10[_0xec8f[25]](_0xb831x11)});Contact[_0xec8f[28]]({where:{phone:_0xb831xd[_0xec8f[30]]},defaults:{phone:_0xb831xd[_0xec8f[30]],fullname:_0xb831xd[_0xec8f[30]]}})[_0xec8f[26]](function(_0xb831x11,_0xb831x12){_0xb831x10[_0xec8f[29]](_0xb831x11)});var _0xb831x13=uuidLib[_0xec8f[31]]();var _0xb831x14=_0xb831xd[_0xec8f[32]];var _0xb831x15=path[_0xec8f[39]](config[_0xec8f[33]],_0xec8f[34],_0xec8f[35],_0xec8f[36],_0xec8f[37],_0xb831x13+ _0xec8f[38]);var _0xb831x16=_0xec8f[40]+ _0xb831x14+ _0xec8f[41]+ _0xb831x15;fs[_0xec8f[48]](_0xb831x14,function(_0xb831x17){if(_0xb831x17){console[_0xec8f[16]](_0xec8f[42]+ _0xb831x14+ _0xec8f[43]);exec(_0xb831x16,function(_0xb831xe){if(_0xb831xe){console[_0xec8f[16]](_0xb831xe)}else {_0xb831x10[_0xec8f[46]]({filenamePDF:_0xb831x13+ _0xec8f[38]})[_0xec8f[45]](function(){console[_0xec8f[16]](_0xec8f[42]+ _0xb831x14+ _0xec8f[44])})[_0xec8f[17]](function(_0xb831xe){console[_0xec8f[16]](_0xb831xe)})}})}else {console[_0xec8f[16]](_0xec8f[42]+ _0xb831x14+ _0xec8f[47])}})})[_0xec8f[17]](function(_0xb831xe){console[_0xec8f[16]](_0xb831xe)})})[_0xec8f[17]](function(_0xb831xe){console[_0xec8f[16]](_0xb831xe)})});_0xb831xc[_0xec8f[50]](_0xec8f[51],function(_0xb831xd){console[_0xec8f[53]](_0xec8f[52]);FaxMessage[_0xec8f[55]]({where:{uniqueid:_0xb831xd[_0xec8f[54]]}})[_0xec8f[45]](function(_0xb831x10){if(_0xb831x10){_0xb831x10[_0xec8f[46]](_0xb831xd)}})[_0xec8f[17]](function(_0xb831xe){console[_0xec8f[16]](_0xb831xe)})});_0xb831xc[_0xec8f[50]](_0xec8f[56],function(_0xb831xd){if(_0xb831xd[_0xec8f[59]][_0xec8f[58]](_0xec8f[57])){FaxMessage[_0xec8f[55]]({where:{uniqueid:_0xb831xd[_0xec8f[54]]}})[_0xec8f[45]](function(_0xb831x10){if(_0xb831x10){console[_0xec8f[53]](_0xec8f[60],_0xec8f[18],_0xb831xd[_0xec8f[61]]);_0xb831x10[_0xec8f[46]]({status:_0xb831xd[_0xec8f[61]]== _0xec8f[62]?_0xec8f[62]:_0xec8f[63]})}})[_0xec8f[17]](function(_0xb831xe){console[_0xec8f[16]](_0xb831xe)})}else {if(_0xb831xd[_0xec8f[59]][_0xec8f[58]](_0xec8f[64])){FaxMessage[_0xec8f[55]]({where:{uniqueid:_0xb831xd[_0xec8f[54]]}})[_0xec8f[45]](function(_0xb831x10){if(_0xb831x10){console[_0xec8f[53]](_0xec8f[60],_0xec8f[16],_0xb831xd[_0xec8f[61]]);_0xb831x10[_0xec8f[46]]({error:_0xb831xd[_0xec8f[61]]})}})[_0xec8f[17]](function(_0xb831xe){console[_0xec8f[16]](_0xb831xe)})}else {if(_0xb831xd[_0xec8f[59]][_0xec8f[58]](_0xec8f[65])){FaxMessage[_0xec8f[55]]({where:{uniqueid:_0xb831xd[_0xec8f[54]]}})[_0xec8f[45]](function(_0xb831x10){if(_0xb831x10){console[_0xec8f[53]](_0xec8f[60],_0xec8f[66],_0xb831xd[_0xec8f[61]]);_0xb831x10[_0xec8f[46]]({laststatus:_0xb831xd[_0xec8f[61]]})}})[_0xec8f[17]](function(_0xb831xe){console[_0xec8f[16]](_0xb831xe)})}}}});_0xb831xc[_0xec8f[50]](_0xec8f[67],function(_0xb831xd){if(_0xb831xd[_0xec8f[67]]=== _0xec8f[68]){FaxMessage[_0xec8f[55]]({where:{uuid:_0xb831xd[_0xec8f[70]]}})[_0xec8f[45]](function(_0xb831x10){if(_0xb831x10){_0xb831xd[_0xec8f[18]]= _0xec8f[69];_0xb831x10[_0xec8f[46]](_0xb831xd)}})[_0xec8f[17]](function(_0xb831xe){console[_0xec8f[16]](_0xb831xe)})}});_0xb831xc[_0xec8f[50]](_0xec8f[57],function(_0xb831xd){FaxMessage[_0xec8f[55]]({where:{uniqueid:_0xb831xd[_0xec8f[54]]}})[_0xec8f[45]](function(_0xb831x10){if(_0xb831x10){console[_0xec8f[53]](_0xec8f[71],_0xb831xd[_0xec8f[54]],_0xb831xd[_0xec8f[18]]);_0xb831x10[_0xec8f[46]]({operation:_0xb831xd[_0xec8f[72]],laststatus:_0xb831xd[_0xec8f[18]]})}})[_0xec8f[17]](function(_0xb831xe){console[_0xec8f[16]](_0xb831xe)})});require(_0xec8f[73])[_0xec8f[14]](_0xb831xc)}
\ No newline at end of file