[Freeswitch-svn] [commit] r12653 - freeswitch/trunk/scripts/contrib/swk/php/esl_cdr
FreeSWITCH SVN
silik0n at freeswitch.org
Tue Mar 17 14:09:12 PDT 2009
Author: silik0n
Date: Tue Mar 17 16:09:12 2009
New Revision: 12653
Log:
just a little something for an example of how to do CDRs from ESL with PHP
Added:
freeswitch/trunk/scripts/contrib/swk/php/esl_cdr/
freeswitch/trunk/scripts/contrib/swk/php/esl_cdr/esl_cdr.php
freeswitch/trunk/scripts/contrib/swk/php/esl_cdr/esl_cdr.postgres.sql
Added: freeswitch/trunk/scripts/contrib/swk/php/esl_cdr/esl_cdr.php
==============================================================================
--- (empty file)
+++ freeswitch/trunk/scripts/contrib/swk/php/esl_cdr/esl_cdr.php Tue Mar 17 16:09:12 2009
@@ -0,0 +1,92 @@
+<?
+require_once('ESL.php');
+require_once("MDB2.php");
+
+$esl_host = '127.0.0.1';
+$esl_port = '8021';
+$esl_password = 'ClueCon';
+
+
+$db_url ="pgsql://root@localhost/esl_cdr";
+
+$con = MDB2::factory($db_url);
+if(PEAR::isError($con)) {
+ die("Error while connecting : " . $con->getMessage());
+}
+
+/* set up the ESL Connection */
+$esl = new eslConnection('204.8.45.218', '8021', 'disasterisk-sucks');
+$e = $esl->sendRecv("api status");
+print $e->getBody();
+$esl->events("plain", "channel_hangup");
+for(;;) {
+ print "foo - 1\n";
+ $e = $esl->recvEvent();
+ if ($e) {
+ $lines = explode("\n", $e->serialize());
+ foreach ($lines as $line){
+ $temp_data = explode(": ", $line);
+
+ if ($temp_data[0]){
+ if ($temp_data[0] == 'variable_easy_acctcode'){
+ $data['acctcode'] = $temp_data[1];
+ } elseif ($temp_data[0] == 'variable_acctcode'){
+ $data['acctcode'] = $temp_data[1];
+ } elseif ($temp_data[0] == 'variable_accountcode'){
+ $data['acctcode'] = $temp_data[1];
+ } elseif ($temp_data[0] == 'variable_account_code'){
+ $data['acctcode'] = $temp_data[1];
+ } else {
+ $data[$temp_data[0]] = $temp_data[1];
+ }
+ }
+ }
+
+ $insert = sprintf("INSERT into cdr (uuid, acctcode, ani, e164_ani, dnis, translated_dnis, e164_dnis, src_host, read_codec, write_codec, clid_name, ".
+ "clid_number, src_sdp, dest_sdp, originate_disposition, bridge_to_uuid, endpoint_disposition, sip_hangup_disposition, term_cause, ".
+ "hangup_cause, start_stamp, answer_stamp, progress_media_stamp, end_stamp, duration, billsec, progress_mediasec, billmin, ".
+ "carrier_id, cust_cost, carrier_cost)".
+ "VALUES".
+ "('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', %s, '%s', '%s',".
+ "%s, %s, %s, %s, %s, %s, %s)",
+ $data['Unique-ID'],
+ $data['acctcode'],
+ $data['Caller-Caller-ID-Number'],
+ $data['Caller-Caller-ID-Number'],
+ urldecode($data['Caller-Destination-Number']),
+ urldecode($data['Caller-Destination-Number']),
+ urldecode($data['Caller-Destination-Number']),
+ $data['Caller-Network-Addr'],
+ $data['Channel-Read-Codec-Name']."-". $data['Channel-Read-Codec-Rate'],
+ $data['Channel-Write-Codec-Name']."-". $data['Channel-Write-Codec-Rate'],
+ urlencode($data['Caller-Caller-ID-Name']),
+ $data['Caller-Caller-ID-Number'],
+ $data['variable_switch_r_sdp'],
+ $data['variable_switch_m_sdp'],
+ $data['variable_originate_disposition'],
+ $data['variable_bridge_to'],
+ $data['variable_endpoint_disposition'],
+ $data['variable_sip_hangup_disposition'],
+ $data['variable_sip_term_cause'],
+ $data['variable_hangup_cause'],
+ urldecode($data['variable_start_stamp']) . '-05',
+ isset($data['variable_answer_stamp'])?'\''. urldecode($data['variable_answer_stamp']) . '-05\'':'null',
+ urldecode($data['variable_progress_media_stamp']) . '-05',
+ urldecode($data['variable_end_stamp']) . '-05',
+ $data['variable_duration'],
+ $data['variable_billsec'],
+ $data['variable_progress_mediasec'],
+ $data['variable_billsec'],
+ "0",
+ "0",
+ "0"
+ );
+
+ $result = $con->query($insert);
+ if(PEAR::isError($result)) {
+ echo "$insert\n";
+ die();
+ }
+ }
+}
+?>
Added: freeswitch/trunk/scripts/contrib/swk/php/esl_cdr/esl_cdr.postgres.sql
==============================================================================
--- (empty file)
+++ freeswitch/trunk/scripts/contrib/swk/php/esl_cdr/esl_cdr.postgres.sql Tue Mar 17 16:09:12 2009
@@ -0,0 +1,71 @@
+--
+-- PostgreSQL database dump
+--
+
+SET client_encoding = 'UTF8';
+SET standard_conforming_strings = off;
+SET check_function_bodies = false;
+SET client_min_messages = warning;
+SET escape_string_warning = off;
+
+SET search_path = public, pg_catalog;
+
+SET default_tablespace = '';
+
+SET default_with_oids = false;
+
+--
+-- Name: cdr; Type: TABLE; Schema: public; Owner: root; Tablespace:
+--
+
+CREATE TABLE cdr (
+ uuid character varying,
+ acctcode character varying,
+ ani character varying,
+ e164_ani character varying,
+ dnis character varying,
+ translated_dnis character varying,
+ e164_dnis character varying,
+ src_host character varying,
+ read_codec character varying,
+ write_codec character varying,
+ clid_name character varying,
+ clid_number character varying,
+ src_sdp character varying,
+ dest_sdp character varying,
+ originate_disposition character varying,
+ bridge_to_uuid character varying,
+ endpoint_disposition character varying,
+ sip_hangup_disposition character varying,
+ term_cause character varying,
+ hangup_cause character varying,
+ start_stamp timestamp with time zone,
+ answer_stamp timestamp with time zone,
+ progress_media_stamp timestamp with time zone,
+ end_stamp timestamp with time zone,
+ duration integer,
+ billsec integer,
+ progress_mediasec integer,
+ billmin numeric(8,2),
+ carrier_id integer,
+ cust_cost numeric(7,4),
+ carrier_cost numeric(7,4)
+);
+
+
+ALTER TABLE public.cdr OWNER TO root;
+
+--
+-- Name: public; Type: ACL; Schema: -; Owner: postgres
+--
+
+REVOKE ALL ON SCHEMA public FROM PUBLIC;
+REVOKE ALL ON SCHEMA public FROM postgres;
+GRANT ALL ON SCHEMA public TO postgres;
+GRANT ALL ON SCHEMA public TO PUBLIC;
+
+
+--
+-- PostgreSQL database dump complete
+--
+
More information about the Freeswitch-svn
mailing list