Browse Source

Premier pigeon chopé

Jean-Francois Burdet 6 years ago
parent
commit
c6b8842f37
5 changed files with 55 additions and 14 deletions
  1. 11 9
      README.md
  2. BIN
      busted/call_from_003341265880109_2017-06-28_12h51mn58s.mp3
  3. 13 0
      busted/index.html
  4. 1 0
      config.yml
  5. 30 5
      lenny.py

+ 11 - 9
README.md

@@ -10,8 +10,10 @@ Le logiciel intercepte chaque appel, et consulte deux base de donnée sur Intern
 Si c'est le cas, il répond avant que le téléphone fixe ne sonne, et déclenche la séquence de réponse qui a pour but 
 de le tenir en ligne le plus longtemps possible.
 
-Voici quelques résultats de conversations : 
-* [A venir !]
+Pour écouter ceux que j'ai attrapé sur ma ligne personnelle, [] 
+
+[Sophia de la maison Linea à Carouge](../../raw/master/busted/index.html?render=1)
+
 
 # Installation
 
@@ -29,12 +31,12 @@ les logiciels suivants :
 L'installation décrite ci-dessous est basée sur Arch Linux, avec une installation serveur:
 
 ```
-sudo pacman -S python2 lame linphone
+sudo pacman -S python2 lame linphone libxslt
 sudo useradd -m  -s /bin/bash callblocker
 sudo su - callblocker
 git clone https://dev.burdet.ch/git/jfburdet/itslenny.git
 cd itslenny
-virtualenv2 venv2
+virtualenv -p python2 venv2
 ./venv2/bin/pip install -r requirements.txt -U
 exit
 ```
@@ -64,14 +66,14 @@ On configure maintenant itslenny, on lui spécifiant le compte SIP/VOIP auquel i
 
 ```
 sudo su - callblocker
-vi itslenny/config.ini
+vi itslenny/config.yml
 ```
 
 ```
-[connection_1]
-domain: 192.168.1.1
-username: 621
-password: toto
+- connection:
+  domain: "192.168.1.1"
+  username: "621"
+  password: "toto"
 ```
 
 On rend le service démarable automatiquement : 

BIN
busted/call_from_003341265880109_2017-06-28_12h51mn58s.mp3


+ 13 - 0
busted/index.html

@@ -0,0 +1,13 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+    <meta charset="UTF-8">
+    <title>Title</title>
+</head>
+<body>
+
+Le premier pigeon attrapé, est "Sophia de la maison Linia à Carouge" :
+<audio src="call_from_003341265880109_2017-06-28_12h51mn58s.mp3" controls> </audio>
+
+</body>
+</html>

+ 1 - 0
config.yml

@@ -2,6 +2,7 @@
   domain: "192.168.1.1"
   #domain_dyn_tag: "essai"
   #domain_dyn_log: "/home/jfburdet/tmp/blog.burdet.ch.log"
+  accept_first_call: true
   username: "621"
   password: "toto"
   mailer:

+ 30 - 5
lenny.py

@@ -19,6 +19,7 @@ import threading
 import urllib2
 import wave
 from datetime import datetime
+from email.mime.text import MIMEText
 
 import linphone
 import yaml
@@ -103,7 +104,13 @@ class SipConnection(object):
     def mail(self, mail_cfg, text):
         try:
             server = smtplib.SMTP(mail_cfg["smtp_host"])
-            server.sendmail(mail_cfg["from"], mail_cfg["to"], text)
+
+            msg = MIMEText(text)
+            msg['Subject'] = text
+            msg['From'] = mail_cfg["from"]
+            msg['To'] = mail_cfg["to"]
+
+            server.sendmail(mail_cfg["from"], [mail_cfg["to"]], msg.as_string())
             server.quit()
         except smtplib.SMTPException as e:
             self.log("Error sending email " + e.message)
@@ -133,6 +140,23 @@ class SipConnection(object):
             # On laisse l'autre l'occassion de reparler
             self._conversation.status = ConversationStatus.WAITFORANSWER
 
+    def storage_path(self):
+        path = current_dir + "/out/" + str(self) + "/"
+        if not os.path.isdir(path):
+            os.makedirs(path)
+        return path
+
+    def shoul_daccept_first_call(self, number):
+        first_call_file = self.storage_path() + "first_calls.txt"
+        if not os.path.isfile(first_call_file):
+            os.system("touch " + first_call_file)
+        if "accept_first_call" in self._config_info and self._config_info["accept_first_call"] and number not in open(
+                first_call_file).read():
+            os.system("echo " + number + " `date` >> " + first_call_file)
+            self.log("Accepting first call of " + number)
+            return True
+        return False
+
     def incoming_stream_worker(self, core, call):
         f = open(self._incoming_stream_file, "rb")
         f.seek(0, io.SEEK_END)
@@ -185,7 +209,7 @@ class SipConnection(object):
             # Let's convert wav to mp3
             if call.current_params.record_file is not None and os.path.isfile(call.current_params.record_file):
                 self.log("Saving to mp3 : " + call.current_params.record_file)
-                subprocess.call('lame --quiet --preset insane %s' % call.current_params.record_file, shell=True)
+                subprocess.call('lame --quiet --preset medium %s' % call.current_params.record_file, shell=True)
                 os.remove(call.current_params.record_file)
 
         if state == linphone.CallState.IncomingReceived:
@@ -195,7 +219,8 @@ class SipConnection(object):
 
             self._replies_pos = 0
 
-            if self.is_in_blacklists(call.remote_address.username):
+            if self.shoul_daccept_first_call(call.remote_address.username) or self.is_in_blacklists(
+                    call.remote_address.username):
                 self.log("telemarketer calling : " + call.remote_address.username)
                 self.mail_if_needed(call.remote_address.username, self.MailType.Notify_Incoming_Telemarketer_Call)
 
@@ -203,7 +228,7 @@ class SipConnection(object):
                 if not os.path.isdir(current_dir + "/out"):
                     os.makedirs(current_dir + "/out")
 
-                a_file = current_dir + "/out/call_from_" + slugify(call.remote_address.username) + \
+                a_file = self.storage_path() + "call_from_" + slugify(call.remote_address.username) + \
                          "_" + datetime.now().strftime(
                     '%Y-%m-%d_%Hh%Mmn%Ss') + ".wav"
 
@@ -300,7 +325,7 @@ class SipConnection(object):
                     self.mail(mail_cfg, "Appel entrant : " + number)
 
             if type == self.MailType.Notify_Incoming_Telemarketer_Call:
-                self.mail(mail_cfg, "Appel télémarketeur entrant : " + number)
+                self.mail(mail_cfg, "Appel telemarketeur entrant : " + number)
 
     def is_in_blacklists(self, a_number):
         return self.is_in_local_blacklist(a_number) or self.is_in_directory_ch_blacklist(