Commit b34e5242 authored by Valentin Samir's avatar Valentin Samir

[sip] Début d'un AGI pour faire de la facturation

Il reste à écrire la fonction de débit sur le solde crans
parent fb8dff75
#!/bin/bash /usr/scripts/python.sh
# -*- coding: utf-8 -*-
import os
import sys
import time
import socket
import syslog
import thread
from threading import Thread
import gestion.secrets_new as secrets
from sip.asterisk import AGI, Manager, NullRecv
se = os.open("/tmp/breakage.log", os.O_WRONLY|os.O_APPEND|os.O_CREAT)
os.dup2(se, sys.stderr.fileno())
os.close(se)
def hangup_callback(manager, params):
agi=manager.agi()
if params['Channel'] == agi['channel']:
os._exit(0)
def unreachble_callback(manager, params):
agi=manager.agi()
if params['Peer'] == "SIP/%s" % agi['callerid'] and params['PeerStatus'] in ['Unregistered','Unreachable']:
agi.hangup(agi['channel'])
os._exit(0)
def start_billing(agi, src, dest):
syslog.syslog("Start billing from %s to %s" % (src, dest))
while True:
time.sleep(60)
syslog.syslog("Billing from %s to %s, one more minutes" % (src, dest))
def Newstate_callback(manager, params):
agi=manager.agi()
syslog.syslog(params['ChannelStateDesc'])
if params['ChannelStateDesc'] in ['Up'] and params['Channel'] == agi['channel']:
t=Thread(target=start_billing, args=(agi, agi['callerid'], agi['extension']))
t.start()
def dial(agi, to):
agi.dial(to)
os._exit(0)
if __name__ == '__main__' :
manager=Manager("billing", secrets.get('asterisk_billig_passwd') , server="127.0.0.1", event=True, auto_connect=False, timeout=10)
syslog.openlog('billing')
agi=manager.agi()
manager.register_events_callback('Newstate', Newstate_callback)
manager.register_events_callback('PeerStatus', unreachble_callback)
manager.register_events_callback('Hangup', hangup_callback)
SIPDOMAIN=agi['SIPDOMAIN']
if not SIPDOMAIN or SIPDOMAIN in ['crans.org']:
SIPDOMAIN='forfait-ovh'
t=Thread(target=dial, args=(agi, "SIP/%s@%s" % (agi['extension'], SIPDOMAIN)))
t.start()
while True:
manager.connect()
try:
while True:
manager.process_events()
if not t.isAlive():
os._exit(0)
except (socket.error, NullRecv):
pass
os._exit(0)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment