Added blacklist feature

This commit is contained in:
klonfish 2015-12-27 11:52:38 +01:00
parent 7730762f87
commit a6a82cfd87
4 changed files with 25 additions and 2 deletions

View file

@ -58,6 +58,13 @@ class ConfigurationReader(object):
print 'shortcuts:', shortcuts print 'shortcuts:', shortcuts
return 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): def read(self, f):
self.__cp.read(f) self.__cp.read(f)
@ -78,6 +85,7 @@ class ConfigurationReader(object):
self.__dialconfig = fetapdtest.DialConfiguration( self.__dialconfig = fetapdtest.DialConfiguration(
self.__get_global_val_int('dial_timeout'), self.__get_global_val_int('dial_timeout'),
self.__read_shortcuts(), self.__read_shortcuts(),
self.__read_blacklist(),
) )
proxyconfigs = [] proxyconfigs = []

View file

@ -18,7 +18,11 @@ incoming_timeout = 60
; gewaehlte nummer angerufen wird ; gewaehlte nummer angerufen wird
dial_timeout = 3 dial_timeout = 3
; CSV-Datei mit Kurzwahlen in der Form
; Header: shortcut,number
shortcuts_file = shortcuts.csv shortcuts_file = shortcuts.csv
; CSV-Datei mit Rufnummern die automatisch abgelehnt werden sollen
; Header: number
linphone_config = linphone.conf linphone_config = linphone.conf
; Einer der Namen der unten eingetragenen Proxys ; Einer der Namen der unten eingetragenen Proxys

View file

@ -7,9 +7,10 @@ import configreader
class DialConfiguration(object): class DialConfiguration(object):
def __init__(self, dial_timeout, shortcuts): def __init__(self, dial_timeout, shortcuts, blacklist):
self.dial_timeout = dial_timeout self.dial_timeout = dial_timeout
self.shortcuts = shortcuts self.shortcuts = shortcuts
self.blacklist = blacklist
class IllegalEventError(Exception): class IllegalEventError(Exception):
pass pass
@ -117,6 +118,13 @@ class RegisteringState(BaseState):
class IdleState(BaseState): class IdleState(BaseState):
def on_incoming_call(self): def on_incoming_call(self):
print('incomfing call') print('incomfing call')
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 return SchelltState
def on_gabelschalter_up(self): def on_gabelschalter_up(self):

View file

@ -199,6 +199,9 @@ class PhoneInterface(object):
self.__ttsproc.stdin.write(text + '\n') self.__ttsproc.stdin.write(text + '\n')
self.__ttsproc.stdin.flush() self.__ttsproc.stdin.flush()
def get_remote_number(self):
return self.__core.current_call_remote_address.username
if __name__ == '__main__': if __name__ == '__main__':
def event_cb(evt): def event_cb(evt):
print 'Got event:', PhoneEvent.string(evt) print 'Got event:', PhoneEvent.string(evt)