kbr / fritzconnection

Python-Tool to communicate with the AVM Fritz!Box by the TR-064 protocol and the AHA-HTTP-Interface
MIT License
304 stars 59 forks source link

All phonebooks contain also all the internal numbers #53

Open bufemc opened 4 years ago

bufemc commented 4 years ago

TLDR: the xml phonebook provided via Fritz!Box Lua seems to contain all internal numbers, too.

I tried to get all the entries for my phonebook id 2, which is for cold calls only. To do so, I used:

        contacts = fp.get_all_names(2)
        for name, numbers in contacts.items():
            print(name, numbers)

However it seems every (!) phonebook will also include internal numbers as well, even in my list for cold calls, like: (I removed private numbers and names). [Possible solution below]

Alle (Rundruf) ['**9']
Anrufbeantworter ['**600', '**605']
Faxgerät ['**1']
FRITZ!App Fon (LGE LG-Hxxx, Name) ['**622']
Gewinnspiel ['0892213xxx']
I1 Nummer ['**610']
I2 Nummer ['**612']
I3 Nummer ['**613']
I4 Nummer ['**611']
ISDN/DECT Rundruf ['**50']
Lotto Berlin ['030422068xxx']
Lotto Neuss ['021317085xxx']
Names iPad ['**621']
Names iPhone ['**620']
Stromanbieter ['0493058877xxx']
Wecker 1 ['**41']
Wecker 2 ['**42']
Wecker 3 ['**43']

I checked the URL for the XML which is downloaded, unfortunately it also contains these internal numbers, it's a 7490 model here. So how could we filter them? I had a glimpse in the XML:

<number type="intern" vanity="" prio="1" >**9</number>

so type="intern" seems to represent an internal number, I've also seen "memo" or "". And:

<number type="home" vanity="" prio="1" >02212928xxx</number>

so only type="home" (wrong, see * below) seems to represent a real entry.

I could create an own branch and a pull request, if wished.

However, I've seen the processor for the xml.etree in the processor code is heavily examining node values, not attributes, before adding e.g the numbers via ValueSequencer just as a simple list. I guess, the author is more into this ;-) In case of a telephony record when the node is processed it would be available as: node.attrib with a dict of 3 entries, the keys are 'type', 'vanity', 'prio'. I guess it would be best to also extract at least the type. The other way would be to manipulate the xml.etree before processing it, e.g. by removing all (but full contact) entries where type != "home" (*)

(*) But, to make it even worse.. if comparing this with section "5.1 Phonebook Content" in https://avm.de/fileadmin/user_upload/Global/Service/Schnittstellen/x_contactSCPD.pdf it seems "home" is not the only value for "real" records, it could be also e.g. "work" etc. So we have to find out first the values for "real" records (whitelisting), or otherwise need a blacklist ("intern", "memo", "" spotted so far).

I just filled out anything in the Fritzbox for an invented whitelist number and set all the stuff, it seems "home", "mobile", "work" and "fax_work" would do the job for the whitelist.

<number type="home" vanity="" prio="1" >030xx</number>
<number type="mobile" vanity="" prio="" >030xx</number>
<number type="work" vanity="" prio="" >030xx</number>
<number type="fax_work" vanity="" prio="" >030xx</number>

Another very simple solution would be just to skip all numbers starting with "**", see above.

bufemc commented 4 years ago

Could be fixed by this PR for issue 55 + 53: https://github.com/kbr/fritzconnection/pull/56

bufemc commented 3 years ago

Heard a rumour that there are also other "internal" numbers, starting with #. So I tend to say we should keep only entries starting with a digit (\d) and remove ANYTHING ELSE..