Skip to content

itelo/celcombiller

 
 

Repository files navigation

Used third-party libraries

  • pyst Interface with Asterisk using either AGI or Manager interfaces
  • sqlalchemy Database interface

Setup developemnt enrironment

$ virtualenv -p /usr/bin/python2.7 venv
$ source venv/bin/activate
$ pip install --allow-external pyst --allow-unverified pyst -r requirements.txt

Database setup

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

admin = User('admin', 'adm123', '999999999', '9999', True)
guest = User('guest', '123123', '999999999', '0000', False)

db.session.add(admin)
db.session.add(guest)
db.session.commit()

please check adduser.py

To test api

To test the api we will use curl

###USER

login is required to test:

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'}' -s http://localhost:5000/api/users

the balance came by another table, so we want add balance to user we need run:

add balance:

curl -b cookiefile -H "Content-Type: application/json" -X POST -d '{"signal":"+", "type_":"increase", "value": "1000", "userId":1}' -s http://localhost:5000/api/balance

#note that userId need some user id, in that case we use 1

remove balance:

curl -b cookiefile -H "Content-Type: application/json" -X POST -d '{"signal":"+", "type_":"increase", "value": "1000", "userId":1}' -s http://localhost:5000/api/balance

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

###GROUPS

add group

curl -X POST -H "Content-Type: application/json" -d '{"name":"group_name","day":1, "month":1, "year":3000, "count":10, "users":[id_]}' -s http://localhost:5000/api/groups

update group

curl -X PATCH -H "Content-Type: application/json" -d '{}' -s http://localost:5000/api/groups/group_name

Deployment With Docker

docker build -t celcom:1 .
docker run -p 5000:5000 -d --name celcom celcom:1 -v /home/celcom/db:/tmp/alph.db

Asterisk setup

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

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 88.4%
  • HTML 11.6%