diff --git a/configreader.py b/configreader.py index f0780fc..7852f41 100644 --- a/configreader.py +++ b/configreader.py @@ -58,6 +58,13 @@ class ConfigurationReader(object): print 'shortcuts:', shortcuts return shortcuts + def __read_blacklist(self): + fname = self.__get_global_val('blacklist_file') + blacklist = [] + with open(fname, 'r') as csvfile: + for row in csv.DictReader(csvfile): + blacklist.append(row['number']) + return blacklist def read(self, f): self.__cp.read(f) @@ -78,6 +85,7 @@ class ConfigurationReader(object): self.__dialconfig = fetapdtest.DialConfiguration( self.__get_global_val_int('dial_timeout'), self.__read_shortcuts(), + self.__read_blacklist(), ) proxyconfigs = [] diff --git a/fetap.ini.example b/fetap.ini.example index 17a9dd7..4a9cfab 100644 --- a/fetap.ini.example +++ b/fetap.ini.example @@ -18,7 +18,11 @@ incoming_timeout = 60 ; gewaehlte nummer angerufen wird dial_timeout = 3 +; CSV-Datei mit Kurzwahlen in der Form +; Header: shortcut,number shortcuts_file = shortcuts.csv +; CSV-Datei mit Rufnummern die automatisch abgelehnt werden sollen +; Header: number linphone_config = linphone.conf ; Einer der Namen der unten eingetragenen Proxys diff --git a/fetapdtest.py b/fetapdtest.py index 924fe37..5df43a3 100644 --- a/fetapdtest.py +++ b/fetapdtest.py @@ -7,9 +7,10 @@ import configreader class DialConfiguration(object): - def __init__(self, dial_timeout, shortcuts): + def __init__(self, dial_timeout, shortcuts, blacklist): self.dial_timeout = dial_timeout self.shortcuts = shortcuts + self.blacklist = blacklist class IllegalEventError(Exception): pass @@ -117,7 +118,14 @@ class RegisteringState(BaseState): class IdleState(BaseState): def on_incoming_call(self): print('incomfing call') - return SchelltState + caller = self._controller.phone.get_remote_number() + print('From: %s' % caller) + if caller in self._controller.dialconfig.blacklist: + print('Caller on blacklist - declining') + self._controller.phone.decline_call() + return CallTerminatingState + else: + return SchelltState def on_gabelschalter_up(self): print('gabel up') diff --git a/phoneinterface.py b/phoneinterface.py index 9582b2a..c4473c0 100644 --- a/phoneinterface.py +++ b/phoneinterface.py @@ -199,6 +199,9 @@ class PhoneInterface(object): self.__ttsproc.stdin.write(text + '\n') self.__ttsproc.stdin.flush() + def get_remote_number(self): + return self.__core.current_call_remote_address.username + if __name__ == '__main__': def event_cb(evt): print 'Got event:', PhoneEvent.string(evt)