def webphone_sms(self, source, destination, text, coding): if not ('webphone_prefix' in globals() and isinstance(webphone_prefix, list) and isinstance(sip_central_ip_address, list)): sms_log.warning('SMS for Webphone but required config missing.') return False if not self.destination[:5] in webphone_prefix: sms_log.warning('WEBPHONE SMS for non webphone extension?') return False sms_log.debug('WEBPHONE SMS from %s for %s [%s] [%s]', (source, destination, text, coding)) self.source = source + '@sip.rhizomatica.org' self.destination = destination self.text = text simple_dest = self.destination + '@' + sip_central_ip_address[0] sip_profile = 'outgoing' try: event = ESL.ESLevent("CUSTOM", "SMS::SEND_MESSAGE") sms_log.debug('SMS to SIP: Source is %s' % self.source) sms_log.debug('SMS to SIP: Dest: %s' % simple_dest) sms_log.debug('Text: %s' % self.text.decode(self.charset, 'replace')) event.addHeader("from", self.source) event.addHeader("to", simple_dest) event.addHeader("sip_profile", sip_profile) event.addHeader("dest_proto", "sip") event.addHeader("type", "text/plain") # Todo, see how we can actually get the result of this back here? #event.addHeader("blocking", "true") event.addBody(text.encode(self.charset, 'replace')) con = ESL.ESLconnection("127.0.0.1", "8021", "ClueCon") ret = con.sendEvent(event) con.disconnect() sms_log.info('WEBPHONE SMS SENT Status:[%s]', ret) return True except Exception as excep: sms_log.info('Exception with Webphone SMS or FS Event: %s' % excep) return False
def sip_sms(self): if use_sip != 'yes': return False if self.destination == '': return False try: sip_endpoints = self.numbering.is_number_sip_connected_no_session( self.destination) sip_endpoint = sip_endpoints.split(',')[0] except Exception as e: sms_log.info('Exception: %s' % e) return False sms_log.info('SIP SMS? %s' % sip_endpoint) if not sip_endpoint: return False m = re.compile('sofia/([a-z]*)/sip:(.*)').search(sip_endpoint) if m: sip_profile = m.group(1) sip_contact = (m.group(2)) params = sip_contact.split(';') # Get fs_path param. res = re.compile('^fs_path=') search = filter(res.match, params) if len(search) > 0: # Have fs_path bracket = re.compile('fs_path=%3C(.*)%3E').search(search[0]) if bracket: params = urllib.unquote(bracket.group(1)).split(';') path = params[0].replace('sip:', '') r = re.compile('received=*') rec = filter(r.match, params) received = rec[0].replace('received=sip:', '') else: import code code.interact(local=locals()) path = search[0] received = urllib.unquote(path).split('=')[1].split('@')[1] else: received = 'None' if sip_profile == 'internalvpn': simple_dest = self.destination + '@' + vpn_ip_address if path == sip_central_ip_address: self.source = self.source + '@sip.rhizomatica.org' simple_dest = self.destination + '@' + sip_central_ip_address + ';received=' + received else: simple_dest = sip_profile + '/' + sip_contact try: con = ESL.ESLconnection("127.0.0.1", "8021", "ClueCon") event = ESL.ESLevent("CUSTOM", "SMS::SEND_MESSAGE") sms_log.info('SMS to SIP: Source is %s' % self.source) sms_log.info('SMS to SIP: Dest: %s' % simple_dest) sms_log.info('SMS to SIP: Received: %s' % received) sms_log.info('Text: %s' % self.text.decode(self.charset, 'replace')) sms_log.info('Text: %s' % type(self.text)) sms_log.info('Coding: %s' % self.coding) event.addHeader("from", self.source) event.addHeader("to", simple_dest) event.addHeader("sip_profile", sip_profile) event.addHeader("dest_proto", "sip") event.addHeader("type", "text/plain") if self.coding == '0': msg = self.text.decode('utf8', 'replace') else: msg = self.text.decode(self.charset, 'replace') sms_log.info('Type: %s' % type(msg)) sms_log.info('Text: %s' % msg) event.addBody(msg.encode(self.charset, 'replace')) con.sendEvent(event) return True except Exception as e: api_log.info('Caught Error in sms sip routine: %s' % e)