Howto:Is there any example code or simple scripts/programs in order to put call-information into an MySQL (or similiar) database in order to build CRM-alike solutions towards the MySQL DB?
FAQ
Is there any example code or simple scripts/programs in order to put call-information into an MySQL (or similiar) database in order to build CRM-alike solutions towards the MySQL DB?
Answer
Documentation regarding PBX CDR and Gateway CDR format is in the wiki.
Sample PHP Script
The script cdr.php takes CDRs via HTTP GET requests and stores them in following files in the subfolder data
:
- data/cdr_pbx.txt - PBX CDRs in text file
- data/cdr_gw.txt - Gateway CDRs in text file
- data/db_pbx.sq3 - PBX CDRs in SQLite DB
- data/db_gw.sq3 - Gateway CDRs in SQLite DB
Make sure subfolder data
exists and web server can write into this folder.
The script will create a local SQLite DB using PDO abstraction layer.
Make sure folowing extensions are enabled in php.ini:
extension=php_pdo.dll extension=php_pdo_sqlite.dll
You can easily switch to another DB like Postgres using other PDO extension.
To check the contents of the DB browse files show_pbx_cdrs.php
and show_gw_cdrs.php
.
The PHP version used in this example is 5.2.17.
Sample Active Server Page
This is somewhat outdated pre-.Net ASP sample code. It may help to get the idea though
This example outlines the storage of CDRs using an ASP-enabled Web Service (tested with MS’s IIS5).
The application lives in the URL /cdr
. It will by default create logfiles named cdrlog_date_srcip.txt
in a subdirectory CDR
underneath /cdr
. Thus, a logfile may be found e.g. on \\webserver\webroot\cdr\CDR\cdrlog_20010208_195.226.104.135.txt
.
The application is made up of 3 files, all located in asp/cdr
.
global.asa
, initialises system parameter.Cdrwrite.asp
, actually writes the CDR entries to the log fileCdrform.htm
, sample HTML form to debug the installation
To install
- copy all files into your web servers
/cdr
position - create a subdirectory called
CDR
- make sure your web server processes ASP applications in the
/cdr
directory - Point your browser to the server and open
/cdr/cdrform.htm
. You should see a form that allows to submit Time and Event - Fill in the fields and submit the form. You should see something like
Event: A:Disc CDR LOG Entry saved to d:\inetpub\wwwroot\cdr\CDR\cdrlog_20010208_127.0.0.1.txt Tag: time = 100 Tag: event = A:Disc CDR ENTRY(082829 time='100' event='A:Disc' ) Done.
- open your Gateways configuration UI
- set CDR-Logging parameters to log to your web server, using method HTTP, URL
/cdr/cdrwrite.asp
Known Problems
It has been reported that later .ASP platforms will not accept the HTTP GET requests used to send the CDR data from the PBX to the .ASP Web server. To work around this issue, it has been reported that the following must be done:
- set the web services config as follows
<system.web><httpRuntime requestValidationMode="2.0"/></system.web>
- on the page that receives the CDR data, disable request verification
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="log.aspx.cs" Inherits="innoLog.Log" ValidateRequest="false" %>
Download
- Download the complete file package of scripts and files described in this article.