Beispiel #1
0
 def new_sms(cls, request, gateway):
     """
     Handle callback from gateway, creating a generic object representing
     an incoming SMS
     """
     logger.debug("Entering: %s()" % who_am_i())
     request.encoding = 'iso-8859-1' #TODO: some GWs allow this to be set I think
     try:
         # if we find an mms already, do nuthin...
         sms, created = cls.objects.get(msg_id=request.GET.get(gateway.msg_id)), False
         logger.debug("SMS with id %s already exists!" % msg_id)
     except:
         try:
             raw = {}
             # loop over all field names and do lookup of the callback api name of
             # the field to get the incoming value
             for f in cls._meta.fields:
                 value = request.GET.get(getattr(gateway, f.name, ''), False)
                 if value:
                     raw[f.name] = value
             raw['saved_at'] = datetime.now()
             sms, created = cls.objects.create(**raw), True
         except Exception, e:
             logger.exception("Exception trying to create a MoSms instance. Error: %s Locals:\n %s\n\n" % (e.message, locals()))
             return None, False
Beispiel #2
0
def receive_sms(request, gw_name):
    '''
    Handle a callback from a mobile message gateway
    '''
    # see if message already has been received for some reason, if so ignore
    logger.debug("Entering: %s()" % who_am_i())
    try:
        gateway = Gateway.objects.get(name__iexact=gw_name)
        logger.debug("Found a gateway: %s" % gw_name)
    except Exception, e:
        # general bork...bail out
        logger.exception("Exception trying to create a gateway instance. Error: %s Locals:\n %s\n\n" % (e.message, locals()))
        return HttpResponse("OK") #return OK under all conditions
Beispiel #3
0
 def send_sms(self, mt_number, message):
     logger.debug("Entering: %s()" % who_am_i())
     try:
         send_fields = GW_SENDING_FIELDS_42IT #TODO: generalize to handle any defined gateway
         data = GW_SENDING_DATA_42IT #TODO: generalize to handle any defined gateway
         gw_number = self.number
         for field_name in ['gw_number', 'mt_number', 'message',]:
             data[send_fields[field_name]] = locals()[field_name]
         url_values = urllib.urlencode(dict([k, v.encode('utf-8')] for k, v in data.items()))
         gw = self.gateway
         full_url = 'http://%s%s?%s' % (gw.host_name, gw.send_path, url_values)
         if getattr(settings, 'SMS_DEBUG', False):
             print "send_sms URL call: %s" % full_url    
         else:
             data = urllib2.urlopen(full_url)
     except Exception, e:
         logger.exception('%s Locals:\n %s\n\n' % (e.message, locals(), ))            
Beispiel #4
0
# -*- coding: utf-8 -*-

# Akvo RSR is covered by the GNU Affero General Public License.
# See more details in the license.txt file located at the root folder of the Akvo RSR module. 
# For additional details on the GNU license please see < http://www.gnu.org/licenses/agpl.html >.

from django.http import HttpResponse#, HttpResponseRedirect, HttpResponsePermanentRedirect

from models import Gateway, MoSms
from utils import who_am_i

import logging
logger = logging.getLogger('django.request')

def receive_sms(request, gw_name):
    '''
    Handle a callback from a mobile message gateway
    '''
    # see if message already has been received for some reason, if so ignore
    logger.debug("Entering: %s()" % who_am_i())
    try:
        gateway = Gateway.objects.get(name__iexact=gw_name)
        logger.debug("Found a gateway: %s" % gw_name)
    except Exception, e:
        # general bork...bail out
        logger.exception("Exception trying to create a gateway instance. Error: %s Locals:\n %s\n\n" % (e.message, locals()))
        return HttpResponse("OK") #return OK under all conditions
    sms, created = MoSms.new_sms(request, gateway)
    logger.debug("Exiting: %s()" % who_am_i())
    return HttpResponse("OK") #return OK under all conditions TODO: this should probably be configurable on the gateway