Browse Source

Adding readme + fine tuning.

Jean-Francois Burdet 6 years ago
parent
commit
230be1247e
2 changed files with 120 additions and 5 deletions
  1. 110 1
      README.md
  2. 10 4
      lenny.py

+ 110 - 1
README.md

@@ -1,2 +1,111 @@
-# itslenny
+# "Hello, it's Lenny" : un remake libre
+
+Ce projet à pour but de reproduire le comportement de https://www.reddit.com/r/itslenny/
+dans le cadre de mon réseau local de mon logement. Mon fournisseur est Sunrise en Suisse et ils ont eu
+la bonne idée de me fournir une Fritz!Box 7390, qui permet de créer un périphérique VoIP.
+
+# Installation
+
+Le logiciel a été testé sous Linux, mais devrait fonctionner sous mac et probablement Windows.
+
+Il a été conçu pour tourner comme un service/daemon.
+
+Il faut installer via le packager de votre système d'exploitation
+les logiciels suivants :
+
+* Python 2.7
+* Lame Mp3 encoder
+* Linphone
+
+L'installation décrite ci-dessous est basée sur Arch Linux, avec une installation serveur:
+
+```
+sudo pacman -S python2 lame linphone
+sudo useradd -m  -s /bin/bash callblocker
+sudo su - callblocker
+git clone https://dev.burdet.ch/git/jfburdet/itslenny.git
+cd itslenny
+virtualenv2 venv2
+./venv2/bin/pip install -r requirements.txt -U
+exit
+```
+
+Il faut créer le unit file en conséquence :
+
+vi /etc/systemd/system/callblocker.service
+ 
+```
+[Unit]
+Description=ItsLenny open sequel
+
+[Service]
+User=callblocker
+Group=callblocker
+Type=simple
+ExecStart= /home/callblocker/itslenny/venv2/bin/python2 /home/callblocker/itslenny/lenny.py
+Restart=always
+RestartSec=5
+TimeoutSec=10
+
+[Install]
+WantedBy=multi-user.target
+```
+
+On configure maintenant itslenny, on lui spécifiant le compte SIP/VOIP auquel il doit se connecter :
+
+```
+sudo su - callblocker
+vi itslenny/config.ini
+```
+
+```
+[connection_1]
+domain: 192.168.1.1
+username: 621
+password: toto
+```
+
+On rend le service démarable automatiquement : 
+```
+sudo systemctl enable callblocker
+sudo systemctl start callblocker
+sudo journalctl -f --since="5 minutes ago" -u callblocker
+```
+
+# Configuration de la Fritz!Box
+* Se logguer en admin
+* Aller dans Téléphonie -> Périphérique tél. -> Configurer un nouveaur périphérique
+* Choisir 'Téléphone avec ou sans répondeur' -> Suivant
+* Choisir ' ... (téléphone IP)' -> Suivant
+* Spécifier le mot de passe de votre choix (il faudra le reporter dans config.ini mentionné ci-dessus)
+* puis terminer l'assistant (->Suivant plusieurs fois)
+
+# Tester avec un appel concret
+
+* Démarrer le service : sudo systemctl start callblocker
+* Vérifier que le journal indique success : sudo journalctl --since="1 minute ago" -u callblocker
+
+Cela doit marquer un message du type : 
+```
+Jun 21 15:16:39 orion systemd[1]: Started ItsLenny open sequel.
+Jun 21 15:16:39 orion callblocker.py[12340]: starting 621@192.168.1.1
+Jun 21 15:16:39 orion callblocker.py[12340]: Registration status: Registration in progress
+Jun 21 15:16:39 orion callblocker.py[12340]: Registration status: Registration successful
+```
+
+On cas de problème de connection, la dernière ligne montrera "io error" ou "unautorized".
+
+Ajouter son propre numéro dans le fichier blacklist.txt puis appeler le numéro VoIP, le log doit ressembler ceci ci-dessous et Lenny doit se mettre à parler :
+
+```
+Jun 21 15:20:43 orion callblocker.py[12671]: starting 621@192.168.1.1      
+Jun 21 15:20:43 orion callblocker.py[12671]: Registration status: Registration in progress                                                            
+Jun 21 15:20:43 orion callblocker.py[12671]: Registration status: Registration successful                                                             
+Jun 21 15:20:53 orion callblocker.py[12671]: state changed : Incoming call
+Jun 21 15:20:53 orion callblocker.py[12671]: Incoming call : __votre numéro !__
+Jun 21 15:20:53 orion callblocker.py[12671]: telemarketer calling : __votre numéro !__
+
+```
+
+
 

+ 10 - 4
lenny.py

@@ -129,6 +129,8 @@ def sleep(duration):
     dummy_event.wait(timeout=duration)
 
 
+
+
 class SipConnection(object):
     def say(self, core):
         if self._conversation.status is not ConversationStatus.IMTALKING:
@@ -145,7 +147,7 @@ class SipConnection(object):
                 self._replies_pos = 1
 
             duration = get_wav_duration(voice_filename)
-            log("Saying : " + voice_filename + "(duration : " + str(duration) + ")")
+            log("Saying : " + voice_filename)
 
             core.play_file = voice_filename
 
@@ -156,8 +158,6 @@ class SipConnection(object):
             self._conversation.status = ConversationStatus.WAITFORANSWER
 
     def incoming_stream_worker(self, core, call):
-        log("Worker is starting")
-
         f = open(self._incoming_stream_file, "rb")
         f.seek(0, io.SEEK_END)
         p = f.tell()
@@ -195,6 +195,10 @@ class SipConnection(object):
 
         log("Worker is quitting")
 
+    @staticmethod
+    def registration_state_changed(core, call, state, message):
+        log("Registration status: " + message)
+
     def call_state_changed(self, core, call, state, message):
         log("state changed : " + message)
 
@@ -269,7 +273,8 @@ class SipConnection(object):
     def __init__(self, domain, username, password):
 
         callbacks = {
-            'call_state_changed': self.call_state_changed
+            'call_state_changed': self.call_state_changed,
+            'registration_state_changed': self.registration_state_changed,
         }
 
         self._core = linphone.Core.new(callbacks, None, None)
@@ -282,6 +287,7 @@ class SipConnection(object):
         self._replies_pos = 0
         self._volume_threshold = VOLUME_THRESHOLD
         self._incoming_stream_file = tempfile.NamedTemporaryFile(delete=False).name
+        self._core.iterate()
 
 
 if __name__ == "__main__":