<commit_before>#!/usr/bin/env python 
# -*- coding: utf-8 -*-
############################################################################
# 
# Copyright (C) 2013 tele <<EMAIL>>
#
# SMS module
# This file is part of RCCN
#
# RCCN is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# RCCN is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Affero Public License for more details.
#
# You should have received a copy of the GNU Affero Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
############################################################################

import sys
sys.path.append("..")
from config import *

import urllib, obscvty, time
from subscriber import Subscriber, SubscriberException 
from numbering import Numbering, NumberingException
from threading import Thread


import binascii

class SMSException(Exception):
    pass

class SMS:

    def __init__(self):
        self.server = kannel_server
        self.port = kannel_port
        self.username = kannel_username
        self.password = <PASSWORD>
        self.charset = 'UTF-8'
        self.coding = 2
        self.context = 'SMS_LOCAL'
        self.source = ''
        self.destination = ''
        self.text = ''
        self.save_sms = 1

        self.numbering = Numbering()

    def filter(self):
        if self.destination in extensions_list:
            return False
        if len(self.destination) < 5:
            sms_log.info('Dropping SMS on floor because destinaton: %s' % self.destination)
            return True
        if self.charset=='8-BIT' and len(self.destination) < 7:
            sms_log.info('Dropping 8-BIT SMS with destinaton: %s' % self.destination)
            return True
        drop_regexp = ['simchautosynchro.+','DSAX[0-9]+ND','Activate:dt=','REG-REQ?v=3;','^GWDR']
        for regexp in drop_regexp:
            if re.search(regexp,self.text):
                sms_log.info('Dropping SMS on floor because text matched %s' % regexp)
                return True
        return False

    def receive(self, source, destination, text, charset, coding):
        self.charset = charset
        self.coding = coding
        self.source = source
        self.destination = destination
        self.text = text

        sms_log.info('Received SMS: %s %s %s %s %s' % (source, destination, text, charset, coding))	
        #sms_log.info(binascii.hexlify(text))
        # SMS_LOCAL | SMS_INTERNAL | SMS_INBOUND | SMS_OUTBOUND | SMS_ROAMING

        # some seemingly autogenerated SMS we just want to drop on the floor:
        try:
            if self.filter():
                return
        except Exception as e:
            api_log.info('Caught an Error in sms:filter %s' % e)
            pass

        if use_sip == 'yes':
            try:
                sip_endpoint=self.numbering.is_number_sip_connected_no_session(self.destination)
            except Exception as e:
                sms_log.info('SIP Exception: %s' % e)

            sms_log.info('SIP SMS? %s' % sip_endpoint)

            if sip_endpoint:
                simple_dest=self.destination+'@'+wan_ip_address
                try:
                    con = ESLconnection("127.0.0.1", "8021", "ClueCon")
                    event = ESLevent("CUSTOM", "SMS::SEND_MESSAGE")
                    event.addHeader("from", self.source)
                    event.addHeader("to", simple_dest)
                    event.addHeader("sip_profile", "external");
                    event.addHeader("dest_proto", "sip")
                    event.addHeader("type","text/plain")
                    sms_log.info('Text: %s' % self.text)
                    sms_log.info('Text: %s' % type(self.text))
                    sms_log.info('Coding: %s' % self.coding)
                    if self.coding == '0':
                        msg=self.text.encode('utf8','replace')
                    else:
                        msg=self.text.encode('utf-8')
                        #msg=urllib.urlencode({'text': msg })
                        #print binascii.hexlify(msg)
                    sms_log.info('Text: %s' % type(msg))
                    sms_log.info('Text: %s' % msg)
                    event.addBody(msg)
                    con.sendEvent(event)
                    return
                except Exception as e:
                    api_log.info('Caught an Error in sms sip routine: %s' % e)

        try:
            # auth checks<commit_msg>Make ESL sofia_contact lookups work in sms<commit_after>#!/usr/bin/env python 
# -*- coding: utf-8 -*-
############################################################################
# 
# Copyright (C) 2013 tele <<EMAIL>>
#
# SMS module
# This file is part of RCCN
#
# RCCN is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# RCCN is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Affero Public License for more details.
#
# You should have received a copy of the GNU Affero Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
############################################################################

import sys
sys.path.append("..")
from config import *

import urllib, obscvty, time
from subscriber import Subscriber, SubscriberException 
from numbering import Numbering, NumberingException
from threading import Thread
import ESL
import binascii

class SMSException(Exception):
    pass

class SMS:

    def __init__(self):
        self.server = kannel_server
        self.port = kannel_port
        self.username = kannel_username
        self.password = kannel_password
        self.charset = 'UTF-8'
        self.coding = 2
        self.context = 'SMS_LOCAL'
        self.source = ''
        self.destination = ''
        self.text = ''
        self.save_sms = 1

        self.numbering = Numbering()

    def filter(self):
        if self.destination in extensions_list:
            return False
        if len(self.destination) < 5:
            sms_log.info('Dropping SMS on floor because destinaton: %s' % self.destination)
            return True
        if self.charset=='8-BIT' and len(self.destination) < 7:
            sms_log.info('Dropping 8-BIT SMS with destinaton: %s' % self.destination)
            return True
        drop_regexp = ['simchautosynchro.+','DSAX[0-9]+ND','Activate:dt=','REG-REQ?v=3;','^GWDR']
        for regexp in drop_regexp:
            if re.search(regexp,self.text):
                sms_log.info('Dropping SMS on floor because text matched %s' % regexp)
                return True
        return False

    def receive(self, source, destination, text, charset, coding):
        self.charset = charset
        self.coding = coding
        self.source = source
        self.destination = destination
        self.text = text

        sms_log.info('Received SMS: %s %s %s %s %s' % (source, destination, text, charset, coding))	
        #sms_log.info(binascii.hexlify(text))
        # SMS_LOCAL | SMS_INTERNAL | SMS_INBOUND | SMS_OUTBOUND | SMS_ROAMING

        # some seemingly autogenerated SMS we just want to drop on the floor:
        try:
            if self.filter():
                return
        except Exception as e:
            api_log.info('Caught an Error in sms:filter %s' % e)
            pass

        if use_sip == 'yes':
            try:
                sip_endpoint=self.numbering.is_number_sip_connected_no_session(self.destination)
            except Exception as e:
                sms_log.info('SIP Exception: %s' % e)

            sms_log.info('SIP SMS? %s' % sip_endpoint)

            if sip_endpoint:
                m=re.compile('sofia/([a-z]*)/sip').search(sip_endpoint)
                if m:
                    sip_profile=m.group(1)
                if sip_profile == 'internalvpn':
                    simple_dest=self.destination+'@'+vpn_ip_address
                else:
                    simple_dest=self.destination+'@'+wan_ip_address
                try:
                    con = ESL.ESLconnection("127.0.0.1", "8021", "ClueCon")
                    event = ESL.ESLevent("CUSTOM", "SMS::SEND_MESSAGE")
                    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")
                    sms_log.info('Text: %s' % self.text)
                    sms_log.info('Text: %s' % type(self.text))
                    sms_log.info('Coding: %s' % self.coding)
                    if self.coding == '0':
                        msg=self.text.encode('utf8','replace')
                    else:
                        msg=self.text.encode('utf-8')
                        #msg=urllib.urlencode({'text': msg })
                        #print binascii.hexlify(msg)
                    sms_log.info('Text: %s' % type(msg))
                    sms_log.info('Text: %s' % msg)
                    event.addBody(msg)
                    con.sendEvent(event)
                    return
                except Exception as e:
                    api_log.info('Caught an Error in sms sip routine: %s' % e)

        try:
            # auth checks
{'fraction_non_alphanumeric': 0.13104920699471329, 'fraction_numerical': 0.0059983733224888165, 'mean_word_length': 1.9936092513694461, 'pattern_counts': {'":': 0, '<': 14, '<?xml version=': 0, '>': 10, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1261895', 'n_tokens_mistral': 2913, 'n_tokens_neox': 2720, 'n_words': 752}