CELCOMBiller is an open source biller system to OpenBTS and Asterisk
- pyst Interface with Asterisk using either AGI or Manager interfaces
- sqlalchemy Database interface
$ virtualenv -p /usr/bin/python2.7 venv
$ source venv/bin/activate
$ pip install --allow-external --allow-unverified -r requirements.txt
Each SIP user must be inserted in the database of users with a balance. The python code snippet bellow is an example of a insertion of two users.
from flask import Flask
from flask.ext.sqlalchemy import SQLAlchemy
from config import db
from models import User, Ballance
admin = User(True,'administrator', 'nowhere', '000','admin', 'adm123', '999999999','999999999999999', '0' ,'0')
guest = User(True,'guest', 'nowhere', '1','guest', '123123', '999999998','999999999999998', '0' ,'0')
db.session.add(admin)
db.session.add(guest)
db.session.commit()
please check adduser.py
To test the api we will use curl
###USER
you must login before test the api:
curl -c cookiefile -d "username=admin&password=adm123" -X POST -s http://localhost:5000/login
now to add user:
curl -b cookiefile -H "Content-Type: application/json" -X POST -d '{"username":"yourusername","password":"yourpassword","clid":"999999999","imsi":"12345678900", "admin":'false', "name":"administrator","adress":"lasse","cpf":"000","voice_balance":"0","data_balance":"0"}' -s http://localhost:5000/api/users
the balance came by another table, so we want add balance to user we need run:
add/remove data balance:
curl -b cookiefile -H "Content-Type: application/json" -X POST -d '{"value": "1000", "user_id":3,"origin":"web"}' -s http://localhost:5000/api/data_balance
#note that userId need some user id, in that case we use 1
#to remove balance the value must be negative
add/remove voice balance:
curl -b cookiefile -H "Content-Type: application/json" -X POST -d '{"value": "1000", "userId":1}' -s http://localhost:5000/api/voice_balance
#note that userId need some user id, in that case we use 1
#to remove balance the value must be negative
update user
curl -X PATCH -H "Content-Type: application/json" -d '{"username":"yournewusername","password":"yournewpassowrd"}' -s http://localhost:5000/api/users/youroldusername -b cookiefile
remove user
curl -X DELETE -s http://localhost:5000/api/users/yourusername -b cookiefile
###Schedule
add group
curl -X POST -H "Content-Type: application/json" -d '{"name":"group_name","day":1, "month":1, "year":3000, "count":10}' -s http://localhost:5000/api/schedules
update group
curl -X PATCH -H "Content-Type: application/json" -d '{}' -s http://localost:5000/api/schedules/schedule
With a working OpenBTS Asterisk server you must modify the file /etc/asterisk/extensions-range.conf as follow:
Between the lines:
exten => h, 1,Log(NOTICE,A-Number=${CDR(A-Number)} A-Name=${CDR(A-Name)} A-IMSI=${CDR(A-IMSI)} B-Number=${CDR(B-Number)} B-Name=${CDR(B-Name)} B-IMSI=${CDR(B-IMSI)} hangupcause=${HANGUPCAUSE} dialstatus=${DIALSTATUS} hangupdirection=${CDR(hangupdirection)} duration=${CDR(duration)} billsec=${CDR(billsec)})
same => n,Hangup()
You have to write the command:
same => n,AGI(celcombiller_reducer) ;reduce the user balance
Change the line:
same => n,Dial(SIP/${ARG1}@${ARG2}:${ARG3},${IF(${VM_INFO(${CDR(B-Number)},exists)}?${DialIMSITimeoutVM}:${DialPSTNTimeout})},g)
To:
same => n,AGI(celcombiller_caller)
celcombiller is an AGI, implemented in the files celcombiller_reducer.py and celcombiller_caller.py,they must run in the virtual environment created in the first section. The follow files must be created in /usr/share/asterisk/agi-bin/
with execution permission.
celcombiller_caller
#!/bin/bash
/path_to_venv/venv/bin/python /path_to_celcombiller/celcombiller/celcombiller_caller.py
celcombiller_reducer
#!/bin/bash
/path_to_venv/venv/bin/python /path_to_celcombiller/celcombiller/celcombiller_reducer.py
To have Celcombiler running as a service you have to modify the file celcombiller.conf and put it in your /etc/init directory.