Skip to content

Commit

Permalink
Merge pull request #162 from Elektordi/charge-info
Browse files Browse the repository at this point in the history
 Storing P-Charge-Info SIP header into CDR
  • Loading branch information
mwolff44 authored Nov 8, 2018
2 parents 1ae19d3 + 31ba062 commit 0ca39a3
Show file tree
Hide file tree
Showing 9 changed files with 44 additions and 9 deletions.
3 changes: 3 additions & 0 deletions config/settings/local.py.dist
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ from .base import *

# ######### DEBUG CONFIGURATION
DEBUG = True
# Note: Set following parameters to False if you want to use django runserver for testing.
SECURE_SSL_REDIRECT = True
SESSION_COOKIE_SECURE = True
# ######### END DEBUG CONFIGURATION

# ######### HOST CONFIGURATION
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@
<param name="master-file-only" value="true"/>
</settings>
<templates>
<template name="pyfreebilling">"${customer}","${customer_ip}","${originating_leg_uuid}","${caller_id_number}","${destination_number}","${channel_name}","${start_stamp}","${answer_stamp}","${end_stamp}","${duration}","${read_codec}","${write_codec}","${hangup_cause}","${hangup_cause_q850}","${gateway}","${cost_rate}","${prefix}","","${sell_rate}","${init_block}","${sell_increment}","${lcr_carrier_id}","${ratecard_id}","${lcr_group_id}","${user_agent}","${sip_rtp_rxstat}","${sip_rtp_txstat}","${uuid}","${FreeSWITCH-Switchname}","${FreeSWITCH-IPv4}","${sip_hangup_disposition}","${billmsec}","${proto_specific_hangup_cause}","${sell_destination}","${cost_destination}","${sip_account_id}"</template>
<template name="pyfreebilling">"${customer}","${customer_ip}","${originating_leg_uuid}","${caller_id_number}","${destination_number}","${channel_name}","${start_stamp}","${answer_stamp}","${end_stamp}","${duration}","${read_codec}","${write_codec}","${hangup_cause}","${hangup_cause_q850}","${gateway}","${cost_rate}","${prefix}","","${sell_rate}","${init_block}","${sell_increment}","${lcr_carrier_id}","${ratecard_id}","${lcr_group_id}","${user_agent}","${sip_rtp_rxstat}","${sip_rtp_txstat}","${uuid}","${FreeSWITCH-Switchname}","${FreeSWITCH-IPv4}","${sip_hangup_disposition}","${billmsec}","${proto_specific_hangup_cause}","${sell_destination}","${cost_destination}","${sip_account_id}","${sip_h_p-charge-info}"</template>
</templates>
</configuration>
4 changes: 2 additions & 2 deletions install/resources/fs/config/scripts/import-csv.pl
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
my $dsn="DBI:Pg:dbname=$pg_db;host=$pg_host;port=$pg_port";
my $dbh=DBI->connect($dsn,$pg_user,$pg_pwd)or die "$0: Couldn't connect to database: " . DBI->errstr;

my $insert_str = "insert into $pg_table (customer_id, customer_ip, uuid, caller_id_number, destination_number, chan_name, start_stamp, answered_stamp, end_stamp, duration, read_codec, write_codec, hangup_cause, hangup_cause_q850, gateway_id, cost_rate, prefix, country, rate, init_block, block_min_duration, lcr_carrier_id_id, ratecard_id_id, lcr_group_id_id, sip_user_agent, sip_rtp_rxstat, sip_rtp_txstat, bleg_uuid, switchname, switch_ipv4, hangup_disposition, effectiv_duration, sip_hangup_cause, effective_duration, billsec, total_sell, total_cost, sell_destination, cost_destination, customerdirectory_id) values ( ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);";
my $insert_str = "insert into $pg_table (customer_id, customer_ip, uuid, caller_id_number, destination_number, chan_name, start_stamp, answered_stamp, end_stamp, duration, read_codec, write_codec, hangup_cause, hangup_cause_q850, gateway_id, cost_rate, prefix, country, rate, init_block, block_min_duration, lcr_carrier_id_id, ratecard_id_id, lcr_group_id_id, sip_user_agent, sip_rtp_rxstat, sip_rtp_txstat, bleg_uuid, switchname, switch_ipv4, hangup_disposition, effectiv_duration, sip_hangup_cause, effective_duration, billsec, total_sell, total_cost, sell_destination, cost_destination, customerdirectory_id, sip_charge_info) values ( ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);";
my $sth = $dbh->prepare($insert_str) or die "$0: Couldn't prepare statement\n$insert_str\n" . $dbh->errstr;

my @files = glob($cdr_files);
Expand Down Expand Up @@ -111,7 +111,7 @@
}
# print " total_cost : $totalcost \n\n";

$sth->execute($fields[0], $fields[1], $fields[2], $fields[3], $fields[4], $fields[5], $fields[6], $fields[7], $fields[8], $fields[9], $fields[10], $fields[11], $fields[12], $fields[13], $fields[14], $fields[15], $fields[16], $fields[17], $fields[18], $fields[19], $fields[20], $fields[21], $fields[22], $fields[23], $fields[24], $fields[25], $fields[26], $fields[27], $host, $addr, $fields[30], $fields[31], $fields[32], $effectiveduration, $billsec, $totalsell, $totalcost, $fields[33], $fields[34], $fields[35]) or print "$0: Couldn't execute statement: " . $dbh->errstr;
$sth->execute($fields[0], $fields[1], $fields[2], $fields[3], $fields[4], $fields[5], $fields[6], $fields[7], $fields[8], $fields[9], $fields[10], $fields[11], $fields[12], $fields[13], $fields[14], $fields[15], $fields[16], $fields[17], $fields[18], $fields[19], $fields[20], $fields[21], $fields[22], $fields[23], $fields[24], $fields[25], $fields[26], $fields[27], $host, $addr, $fields[30], $fields[31], $fields[32], $effectiveduration, $billsec, $totalsell, $totalcost, $fields[33], $fields[34], $fields[35], $fields[36]) or print "$0: Couldn't execute statement: " . $dbh->errstr;
} else {
my $err = $csv->error_input;
print "Failed to parse line: $err";
Expand Down
2 changes: 2 additions & 0 deletions pyfreebilling/cdr/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ class CDRAdmin(ExportMixin, admin.ModelAdmin):
'hangup_disposition',
'sip_hangup_cause'),
('read_codec', 'write_codec'),
'sip_charge_info',
'sip_user_agent',
'customer_ip',
('uuid', 'bleg_uuid', 'chan_name', 'country'))
Expand Down Expand Up @@ -231,6 +232,7 @@ def get_readonly_fields(self, request, obj=None):
'chan_name',
'read_codec',
'write_codec',
'sip_charge_info',
'sip_user_agent',
'hangup_disposition',
'effectiv_duration',
Expand Down
8 changes: 5 additions & 3 deletions pyfreebilling/cdr/management/commands/send_cdr_by_email.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def handle(self, *args, **options):
list = CDR.objects.all().filter(end_stamp__gte=p_start, end_stamp__lt=p_end, customer_id=cust.id, billsec__gt=0)
csvfile = StringIO()
csvwriter = csv.writer(csvfile)
csvwriter.writerow(['direction', 'start', 'end', 'billed_sec', 'from', 'to', 'ip', 'destination', 'price', 'uuid'])
csvwriter.writerow(['direction', 'start', 'end', 'billed_sec', 'from', 'to', 'ip', 'destination', 'price', 'uuid', 'charge_info'])
for l in list:
if l.ratecard_id_id in rc_emerg:
continue
Expand All @@ -78,7 +78,8 @@ def handle(self, *args, **options):
None,
l.sell_destination.encode('ascii',errors='ignore'),
l.total_sell,
l.bleg_uuid
l.bleg_uuid,
None
])
else:
csvwriter.writerow(['OUT',
Expand All @@ -90,7 +91,8 @@ def handle(self, *args, **options):
l.customer_ip,
l.sell_destination.encode('ascii',errors='ignore'),
l.total_sell,
l.uuid
l.uuid,
l.sip_charge_info
])

message = EmailMessage("%s - CDR for customer %s"%(settings.EMAIL_SIGNATURE, cust.name),
Expand Down
20 changes: 20 additions & 0 deletions pyfreebilling/cdr/migrations/0007_cdr_sip_charge_info.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.12 on 2018-10-18 19:42
from __future__ import unicode_literals

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('cdr', '0006_auto_20171222_1716'),
]

operations = [
migrations.AddField(
model_name='cdr',
name='sip_charge_info',
field=models.CharField(help_text='Contents of the P-Charge-Info header for billing purpose.', max_length=100, null=True, verbose_name='charge info'),
),
]
5 changes: 5 additions & 0 deletions pyfreebilling/cdr/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,11 @@ class CDR(models.Model):
LCRGroup,
null=True,
verbose_name=_(u"lcr group"))
sip_charge_info = models.CharField(
_(u'charge info'),
null=True,
max_length=100,
help_text=_(u"Contents of the P-Charge-Info header for billing purpose."))
sip_user_agent = models.CharField(
_(u'sip user agent'),
null=True,
Expand Down
3 changes: 2 additions & 1 deletion pyfreebilling/customerportal/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,8 @@ def csv_view(request, *args, **kwargs):
'block_min_duration',
'total_sell',
'customer_ip',
'sip_user_agent'
'sip_user_agent',
'sip_charge_info'
)

try:
Expand Down
6 changes: 4 additions & 2 deletions pyfreebilling/templates/customer/cdr_view.html
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,7 @@ <h3 class="form-signin-heading">{% trans "CDR search" %} : </h3>
<thead>
<tr>
<th>{% trans "Date" %}</th>
<th>{% trans "Caller number" %}</th>
<th>{% trans "Destination number" %}</th>
<th>{% trans "Duration" %}</th>
<th>{% trans "Prefix" %}</th>
Expand All @@ -274,15 +275,16 @@ <h3 class="form-signin-heading">{% trans "CDR search" %} : </h3>
<tbody>
{% for cdr in Cdr %}
<tr>
<td>{{ cdr.start_stamp }}</td>
<td>{{ cdr.start_stamp|date:"d M Y h:m:s" }}</td>
<td{% if cdr.sip_charge_info %} title="{% trans "Charge info" %}: {{ cdr.sip_charge_info }}"{% endif %}>{{ cdr.caller_id_number }}</td>
<td>{{ cdr.destination_number }}</td>
<td>{{ cdr.min_effective_duration }}</td>
<td>{{ cdr.prefix }}</td>
<td>{{ cdr.sell_destination }}</td>
<td>{{ cdr.rate }}</td>
<td>{{ cdr.total_sell_py }}</td>
<td>{{ cdr.read_codec }}/{{ cdr.write_codec }}</td>
<td>{{ cdr.customer_ip }}</td>
<td title="{% trans "User-Agent" %}: {{ cdr.sip_user_agent }}">{{ cdr.customer_ip }}</td>
</tr>
{% endfor %}
</tbody>
Expand Down

0 comments on commit 0ca39a3

Please sign in to comment.