Sms sender for FreeMobile API
@constructor

@param {Object} opts
501458
function Sms(opts) {

  if (!(this instanceof Sms)) {
    return new Sms(opts);
  }

  // Ensure opts is an object
  opts = opts || {};
  
  // API user 
  this.user = opts.user || null;
  
  // API password
  this.pass = opts.pass || null;
  
  // Message
  this.message = opts.message || null;    
}
602081
function(content, opts, onOk, oncancel) {
        Dialog.setup('prompt', content, opts, onOk, oncancel);
      }
846379
function AjaxGateway(opts) {

    // in HTTP mode they is not initial connection concept adapter as to handle data.
    function HttpRequest (request, response) {
        this.gateway.Debug(7, "Data=[%s]", request.url);

        var question=url.parse(request.url, true, true);
        var query=question.query;

        var batchRequest = new BatchRequest(this.gateway, query, response);
        var command = path.basename(question.pathname);
        var tracker = true;

        if (query.phonenum == undefined) {
            this.gateway.Debug (0,"Hoops phonenum undefined");
            response.writeHeader(400, {"Content-Type": "text/plain"});
            response.write('ERR: AjaxSMS check-phonenum missing phonenum=xxxxx');
            response.end();
            return;
        }

        switch (command)  {

            case "check-dev-mobile":
                tracker=false;
            case "check-dev-tracker": // http://geotobe.localnet/smsgateway/check-dev-tracker?phonenum=+33782849007&passwd=123456&apn=free&host=46.105.45.122&port=4010
                batchRequest.CheckTrackerBySms(tracker, query);
                break;

            case "send-sms-text":
                batchRequest.SendSmsText(tracker, query);
                break;

            case 'check-accesscode':
                this.backend.getByEmei(batchRequest.CheckAccessCode, query.imeinum);
                break;

            default:
                response.writeHeader(400, {"Content-Type": "text/plain"});
                response.write('ERR: AjaxSMS command: ['+ command + '] in Http Request');
                response.end();
        }

    }

    function TcpSvrListenOk () {
        this.gateway.Debug (1,"AjaxGateway [%s] listening", this.uid);
    }

    // Server fail to listen on port [probably busy]
    function TcpSvrListenFx (err) {
        this.gateway.Debug (0,"Hoop fail to listen err=%s", err);
        console.log ("### AjaxGateway process abort ###");
        process.exit (-1);
    }

    this.uid   = "AjaxGateway:" + opts.name;
    this.debug =  opts.debug;   

    // Compute some opts and provide some defaults
    this.opts            =
    { name:       opts.name || "smsg"
    , debug:      opts.debug || 1     // default 1
    , inactivity: opts.timeout || 60  // default 1mn
    };

    this.smsc = new SmsControl (opts.smsc);

    this.backend = new AjaxBackend (this, opts.userdb);

    this.Debug (1,"AjaxGateway Start: %s", opts.name );
    this.AjaxGateway           = http.createServer(HttpRequest);
    this.AjaxGateway.gateway   = this;
    this.AjaxGateway.backend   = this.backend;
    this.AjaxGateway.uid       = "AjaxGateway:" + opts.listenPort;
    this.AjaxGateway.listen(opts.listenPort, TcpSvrListenOk);
    this.AjaxGateway.on('error', TcpSvrListenFx);
}
444521
function(opts){
  //setup options
  this.opts = new ObjectManage({
    username: '',
    password: '',
    domain: 'cdn.oose.io',
    prism: {
      host: null,
      port: 5971
    }
  })
  this.opts.$load(opts)
  //set properties
  this.api = {}
  this.authenticated = false
  this.connected = false
  this.session = {}
}
53869
def send_sms(self, message, to, sender='elkme', options=[]):
        """"""
        sms = self.format_sms_payload(message=message,
            to=to,
            sender=sender,
            options=options)
        return self.query_api(sms)
184947
function onMessage( msg ) {
	// TODO: log
	if ( msg !== null ) {
		if ( msg.opts ) {
			topical.publish( 'opts', msg.opts );
		}
		if ( msg.body ) {
			topical.publish( 'body', msg.body );
		}
	}
	run();
}
1010381
function json (opts) {
  return {
    ...opts,
    headers: {
      ...opts.headers,
      'content-type': 'application/json'
    },
    body: JSON.stringify(opts.body)
  }
}
1274812
function XHR(opts){
  Polling.call(this, opts);

  if (global.location) {
    var isSSL = 'https:' == location.protocol;
    var port = location.port;

    // some user agents have empty `location.port`
    if (Number(port) !== port) {
      port = isSSL ? 443 : 80;
    }

    this.xd = opts.hostname != global.location.hostname ||
      port != opts.port;
  }
}
80922
function(url, opts) {
    var that = this;
    var buf_pos = 0;
    var orsc = function (xhr, e, abort_reason) {
        if (xhr.readyState === 3 || xhr.readyState === 4) {
            // IE doesn't like peeking into responseText or status on
            // XHR and readystate=3
            try {
                var responseText = xhr.responseText;
                var status = xhr.status;
            } catch (x) {}
            if (responseText && status === 200) {
                var msgs = [];
                while (1) {
                    var buf = responseText.slice(buf_pos);
                    var p = buf.indexOf('\n');
                    if (p === -1) break;
                    buf_pos += p+1;
                    var msg = buf.slice(0, p);
                    that.dispatchEvent(
                        new SimpleEvent('message', {
                                            data: msg,
                                            readystate: xhr.readyState,
                                            responsetext: responseText
                                        }));
                }
            }
        }
        if (xhr.readyState === 4 || abort_reason) {
            var reason = abort_reason ? 'user' :
                (xhr.status === 200 ? 'network' : 'permanent');
            that.xhr_close = null;
            that.dispatchEvent(new SimpleEvent('close', {reason: reason}));
        }
    };
    var createXhr = (opts.cors && _window.XDomainRequest) ?
                                    utils.createXDR : utils.createXHR;
    that.xhr_close = createXhr('POST', url, null, orsc);
}
708067
function(opts) {
      opts = opts || {};
      var path = opts.path || this.path,
          callback = opts.callback,
          method = opts.method || this.method,
          ws = getWebsocketPlugin(),
          transports = app.config.transports,
          self = this,
          i = 0,
          error,
          response;

      if (ws) {
        if (transports && transports.length > 0) {
          async.whilst(
            function () {
              return (i < transports.length);
            },
            function (done) {
              self.doConnect(transports[i], method, path, function (err, res) {
                error = err;
                response = res;
                if (!err && res) {
                  i = transports.length;
                } else {
                  i++;
                  if (i < transports.length) {
                    delete self.request;
                  }
                }
                done();
              });
            },
            function (err) {
              callback(err || error, response);
            }
          );
        } else {
          error = 'no transport available';
          log.error('%s %s', app.name, error);
          callback(error);
        }
      } else {
        this.doConnect('http', method, path, callback);
      }
      return this;
    }
752618
function(app, opts) {
  opts = opts || {};
  this.app = app;
  this.channels = {};
  this.prefix = opts.prefix;
  this.store = opts.store;
  this.broadcastFilter = opts.broadcastFilter;
  this.channelRemote = new ChannelRemote(app);
}
516732
function Deferred(opts){
 	/**
	 * @define {object} Collection of public methods.
	 */
	var self = {};

	/**
	 * @define {object} options for the constructor 
	 */
	var opts = opts || {};

	/**
	 * @define {object} A promise object that will be returned
	 */
	var promise = {};

	/**
	 * @define {object} Event system for controlling events
	 */
	var event = Event();
	
	/**
	 * Promise then method
	 * This is for chaining promis callbacks
	 * @example promiseFunction().then(
	 * function(){ // success }, 
	 * function(){ // rejected }, 
	 * function(){ // notify } 
	 * ).then( ... );
	 * @param {function} sucess Success callback
	 * @param {function} reject Reject callback
	 * @param {function} notify notify callback
	 * @return {object} Returns the promise object
	 */
	function promiseThen(success, reject, notify){
		/**
		 * @define {object} Return a new promise
		 */
		var def = Deferred();

		/**
		 * Resolved promise
		 * @example example
		 * @param {string} A string key for the event system
		 * @param {function} A callback when event is triggered
		 * @return {object} Returns promise object
		 */
		event.on('resolve', function(){ 
			/**
			 * If the success callback returns a promise
			 * then resolve/reject/notify that returned promise
			 */
			var promise = success();
			if(!promise) return;
			promise.success(function(){
				/** handle the returned deferred object */
				def.resolve();
			});
			promise.error(function(){
				def.reject();
			});
			promise.notify(function(){
				def.notify();
			});
		});

		/**
		 * If promise is rejected/notify trigger the callback
		 */
		event.on('reject', function(){ 
			if(reject) reject();
		});

		event.on('notify', function(){ 
			if(notify) notify();
		});

		/**
		 * @return {object} Returns a promise object
		 */
		return def.promise; 
	}

	/**
	 * Promise methods
	 * @example promise.then( //new promise ).then(...)
	 * @example promise.success(...).error(...).notify(...)
	 * @param {function} callback A callback for the promise
	 * @return {object} Return the promise
	 */
	function promiseSuccess(callback){
		event.on('resolve', callback);
		return promise;
	}

	function promiseError(callback){
		event.on('reject', callback);
		return promise;
	}

	function promiseNotified(callback){
		event.on('notify', callback);
		return promise;
	}

	/**
	 * Deferred methods to trigger the promise
	 * @example def.resolve(args)
	 * @example def.reject(args)
	 * @example def.notify(args)
	 */
	function resolve(){
		var args = Array.prototype.slice.call(arguments);
		event.trigger('resolve', args);
	}

	function reject(){
		var args = Array.prototype.slice.call(arguments);
		event.trigger('reject', args);	
	}

	function notify(){
		var args = Array.prototype.slice.call(arguments);
		event.trigger('notify', args);		
	}

	/**
	 * Add the promise methods to the promise object
	 */
	promise.then = promiseThen;
	promise.success = promiseSuccess;
	promise.error = promiseError;
	promise.notify = promiseNotified;

	/**
	 * The promise object
	 * @public {object}
	 */
	self.promise = promise;

	/**
	 * Deferred public methods	
	 * @public {function}
	 */
	self.resolve = resolve;
	self.reject = reject;
	self.notify = notify;

	/**
	 * @return {object} return public methos
	 */
	return self;
}
756915
function GodSocket(opts) {
	var self = this
	events.EventEmitter.call(this)
	this.send = send
	var socketManager = socketio.listen(opts.app)
	var log = opts.log || console.log

	socketManager.set('log level', 0)
	socketManager.sockets.on('connection', newConnection)
	opts = null

	function newConnection(socket) {
		var actionsAreAllowed = getWriteAllowed(socket)

		socket.on('togod', receiveAction)
			//.on('disconnect', 'reason')
			.on('error', socketErrorListener)

		function receiveAction(data) {
			if (actionsAreAllowed) self.emit('data', data, socketSend)
			else {
				log('Denined request:', data)
				socketSend({error: 'denied'})
			}
		}
		function socketErrorListener(etext) {
			log('socket error:', etext)
		}
		function socketSend(data) {
			socket.emit('fromgod', data)
		}
	}

	function send(update) {
		socketManager.sockets.emit('fromgod', update) // emit has no callback
	}

	function getWriteAllowed(socket) {
		// determine if writing is allowed for this socket
		// ie. from localhost
		var ip
		var sockid = socket.id
		if (sockid) {
			var hand = socket.manager && socket.manager.handshaken &&
				socket.manager.handshaken
			if (hand && hand[sockid] && hand[sockid].address) ip = hand[sockid].address.address
			log('Connecting ip:', ip)
		}
		return ip === '127.0.0.1'
	}
}
613731
function sendText(payload: {
  to: string,
  from: string,
  message: string,
  statusCallback: string,
}): Promise<null | TwilioResponse> {
  if (!(process.env.TWILIO_ACCOUNT_SID && process.env.TWILIO_AUTH_TOKEN)) {
    logErr(
      new Error(
        "Could not send text message, missing required Twilio env vars"
      ),
      { payload }
    );
    return Promise.resolve(null);
  } else if (!Twilio) {
    Twilio = require("twilio");
  }

  return new Twilio(
    process.env.TWILIO_ACCOUNT_SID,
    process.env.TWILIO_AUTH_TOKEN
  ).messages.create({
    to: `+1${payload.to}`,
    from: `+1${payload.from}`,
    body: payload.message,
    statusCallback: payload.statusCallback,
  });
}
862066
function Plugin(opts) {
  this.namespace = opts.namespace;
  this._fns = {};
  this.util = _.clone(util);
}
1094992
function (opt) {
    if (typeof opt !== "object" || opt === null) {
        opt = {};
    }
    if (typeof opt.tag !== "string") {
        opt.tag = null;
    }
    if (typeof opt.encoding !== "string") {
        opt.encoding = "utf8";
    }

    //Extends the readable stream
    stream.Readable.call(this, {encoding: opt.encoding});

    this._tag = (typeof opt.tag === "string") ? opt.tag.trim() : null;
    this._level = labels.length;
    this._disabled = false;

    //Default message format
    this._format = function (tag, label, text) {
        let list = [];
        if (tag) {
            //Add the tag if it is provided
            list.push("[" + tag + "]");
        }
        list.push("[" + timestamp("YYYY-MM-DD hh:mm:ss") + "]");
        list.push("[" + label.toUpperCase() + "]");
        list.push(text.trim());
        return list.join(" ");
    };

    return this;
}
395373
function(params) {
                if (userInfo && params.ownerId !== userInfo.id) {
                    return sendMessage({
                        chatMessageVOType: chatMessageVOTypes.DELIVERY,
                        typeCode: params.typeCode,
                        content: params.messageId,
                        pushMsgType: 3
                    });
                }
            }