diff --git a/README b/README new file mode 100644 index 0000000..7d1d1ac --- /dev/null +++ b/README @@ -0,0 +1,4 @@ +Repository discontinued +----------------------- + +The repository is for historical purposes only and not in use anymore. diff --git a/acc-cdi.conf b/acc-cdi.conf deleted file mode 100644 index ee7d4bf..0000000 --- a/acc-cdi.conf +++ /dev/null @@ -1,5 +0,0 @@ -NGCP_KAMCTL = /usr/sbin/ngcp-kamctl -NGCP_CHK_ACT = /usr/sbin/ngcp-check-active -p -LOG_FILE = /var/log/ngcp/acc-cdi.log -LOGGING = 1 -DEBUG = 0 diff --git a/acc-cdi.pl b/acc-cdi.pl deleted file mode 100755 index 05ba148..0000000 --- a/acc-cdi.pl +++ /dev/null @@ -1,377 +0,0 @@ -#!/usr/bin/perl -w -# vim set sw=4 ts=4 et noai -#---------------------------------------------------------------------- -# Sipwise Development Team -#---------------------------------------------------------------------- -## no critic -use strict; -our $VERSION = 1.0; -use DBI; -use Time::HiRes qw(gettimeofday); -use Date::Format qw(time2str); -use Data::Dumper; -#---------------------------------------------------------------------- -BEGIN { - $SIG{TERM} = \&release_term; - $SIG{INT} = \&release_int; - $SIG{__DIE__} = \&ERROR; -} -my %CONFIG = (); -my $pid_file = '/var/run/ngcp-acc-cdi.pid'; -my $config_file = '/etc/ngcp-acc-cdi/acc-cdi.conf'; -my $dbcredentials = '/etc/mysql/sipwise_extra.cnf'; -my $dbh; -my $ch = {}; -my $dsn = "DBI:mysql:database=accounting;host=localhost;mysql_read_default_file=${dbcredentials}"; -my %cnt = qw(updated 0 cleaned 0 finished 0 skipped 0); - -# Read config -#---------------------------------------------------------------------- -sub read_config { - open (my $config_fh, $config_file) - || die "Can't open config file: $!"; - while (<$config_fh>) { - chomp $_; - $_ =~ /^\s*(\S*)\s*=\s*(.+)$/; - next unless $1 && $2; - $CONFIG{$1} = $2; - } - close $config_fh; - - # redirect out/err to the log file - if ($CONFIG{LOGGING}) { - open (STDOUT, ">>" . $CONFIG{LOG_FILE}) - || die "Can't open logfile: $!"; - open (STDERR, ">>" . $CONFIG{LOG_FILE}) - || die "Can't open logfile: $!"; - } -} - -# Logging -#---------------------------------------------------------------------- -sub INFO { - my $msg = shift; - return unless $msg; - chomp $msg; - my $time_s = '[' . time2str('%Y-%m-%d %T', time).']'; - print $time_s .' '.$msg."\n"; -} - -sub DEBUG { - return unless $CONFIG{DEBUG}; - INFO shift; -} - -sub ERROR { - INFO shift; - $dbh->rollback if $dbh; - $dbh->disconnect if $dbh; - exit 1; -} - -# Init/release -#---------------------------------------------------------------------- -sub init { - read_config(); - # check/create lock - if (-f $pid_file) { - open(my $pf_fh, $pid_file) || die "Can't open file: $!"; - my $old_pid = <$pf_fh> || 0; - chomp $old_pid; - if ($old_pid && kill 0, $old_pid) { - INFO "Already running."; - exit 0; - } else { - DEBUG "Releasing stale lock $old_pid"; - unlink $pid_file || DEBUG "Can't release old lock: $!"; - } - } - open(my $pf_fh, '>'.$pid_file) || die "Can't create lock: $!"; - print $pf_fh $$."\n"; - INFO "Started."; -} - -sub release_int { - DEBUG "-- Interrupted --"; - release(); - exit 1; -} - -sub release_term { - DEBUG "-- Terminated --"; - release(); - exit 1; -} - -sub release { - $dbh->disconnect if $dbh; - INFO sprintf(<; - chomp($rc); - - return $rc eq '!' ? 1 : 0; -} - -# Get active calls from kamailio -#---------------------------------------------------------------------- -sub get_active_calls { - open(my $calls, $CONFIG{NGCP_KAMCTL}." proxy fifo dlg.list |") - || die "Can't open kamctl: $!"; - - my @active_calls;; - while (<$calls>) { - chomp $_; - if ($_ =~ /call-id:\s+(\S+)$/) { - push @active_calls, $1; - } - } - close $calls; - return \@active_calls; -} - -# Get start acc records (single INVITES with sip_reason = OK) -#---------------------------------------------------------------------- -sub get_start_acc { - - my $ch = $dbh->prepare(<execute() || die "Can't execute query: ".$DBI::errstr; - - INFO sprintf("Fetched %d start acc records.", $rc); - - my %start_acc = (); - while (my $row = $ch->fetchrow_hashref) { - $start_acc{$row->{callid}} = $row; - } - - $ch->finish(); - - $dbh->commit; - die "Can't commit transaction: ".$DBI::errstr if $DBI::err; - - return \%start_acc; -} - -# Prepare sql statements that will be called repeatedly -#---------------------------------------------------------------------- -sub prepare_statements { - - $ch->{insert_mark} = $dbh->prepare(<{update_mark} = $dbh->prepare(<{delete_mark} = $dbh->prepare(<{finish_acc} = $dbh->prepare(<{time_hires}; - # already have the mark, update it - if ($acc->{mark}) { - DEBUG sprintf("Updating mark for callid: %s with duration: %d", - $acc->{callid}, $duration); - $ch->{update_mark}->execute($acc->{callid}, $time_hires) - || die "Can't execute query: ".$DBI::errstr; - # insert a new intermediate mark record - } else { - DEBUG sprintf("Inserting mark for callid: %s with duration: %d", - $acc->{callid}, $duration); - $ch->{insert_mark}->execute($acc->{callid}, $time_hires) - || die "Can't execute query: ".$DBI::errstr; - } - }; - if ($@) { - ERROR $@; - } - - $dbh->commit; - die "Can't commit transaction: ".$DBI::errstr if $DBI::err; - $cnt{updated}++; -} - -# Finish acc records (create BYE for INVITES with marks but not active) -#---------------------------------------------------------------------- -sub finish_acc { - my $acc = shift; - die "No acc passed into fisnih_acc" unless ref $acc; - - my $duration = $acc->{mark} - $acc->{time_hires}; - - DEBUG sprintf("Finishing callid: %s with duration: %d", - $acc->{callid}, $duration); - - eval { - $acc->{method} = 'BYE'; - $acc->{sip_reason} = 'Interrupted'; - $acc->{src_domain} = '127.0.0.1'; - - # create the BYE (mediator will do the rest) - $ch->{finish_acc}->execute(@{$acc}{qw(method from_tag to_tag - callid - sip_code sip_reason - mark - dst_ouser dst_domain - src_domain) - }) - || die "Can't execute query: ".$DBI::errstr; - - # cleanup the related mark - $ch->{delete_mark}->execute($acc->{callid}) - || die "Can't execute query: ".$DBI::errstr; - }; - if ($@) { - ERROR $@; - } - - $dbh->commit; - die "Can't commit transaction: ".$DBI::errstr if $DBI::err; - $cnt{finished}++; -} - -# Clean up marks for already normally completed calls -#---------------------------------------------------------------------- -sub cleanup_marks { - - eval { - - $cnt{cleaned} = int $dbh->do(<commit; - die "Can't commit transaction: ".$DBI::errstr if $DBI::err; - -} -# Main (start) entry -#---------------------------------------------------------------------- -sub main { - - # only run on the active node - unless (check_active()) { - DEBUG "The node is not active... stopping."; - exit 0; - } - - # db connect, with tx support for inserts/updates - $dbh = DBI->connect($dsn, "", "", { AutoCommit => 0 }); - die "Can't connect to mysql: ".$DBI::errstr if $DBI::err; - - # fetch start acc records, active calls for processing - my $start_acc = get_start_acc(); - my $active_calls = get_active_calls(); - - prepare_statements(); - - #print Data::Dumper->Dumpxs([$start_acc]),"\n"; - - foreach my $callid (keys %$start_acc) { - # active call - if (grep /^$callid$/, @$active_calls) { - update_mark($start_acc->{$callid}); - # inactive call but with a mark record - } elsif ($start_acc->{$callid}{mark}) { - finish_acc($start_acc->{$callid}); - # inactive call w/o mark record = stale - } else { - $cnt{skipped}++; - } - } - - # records in acc_cdi w/o any related acc records in kamailio.acc - # =normally finished calls by kamailio/mediator - cleanup_marks(); -} -#---------------------------------------------------------------------- - -init(); -main(); -release(); - -exit 0; - -# vim set sw=4 ts=4 et noai -__END__ - -NOTE: accounting.acc_cdi table is required for the script to operate properly. - normally covered by ngcp db schema. - -CREATE TABLE `acc_cdi` ( - `id` int(11) NOT NULL AUTO_INCREMENT, - `callid` varchar(255) NOT NULL, - `mark` decimal(13,3) NOT NULL, - PRIMARY KEY (`id`), - UNIQUE KEY `callid` (`callid`), - KEY `callid_idx` (`callid`) -) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8 - diff --git a/debian/.gitignore b/debian/.gitignore deleted file mode 100644 index 1a3fd2c..0000000 --- a/debian/.gitignore +++ /dev/null @@ -1,7 +0,0 @@ -*.debhelper -*.log -*.substvars -/.debhelper/ -/debhelper-build-stamp -/files -/ngcp-acc-cdi/ diff --git a/debian/changelog b/debian/changelog deleted file mode 100644 index 6c3d7c5..0000000 --- a/debian/changelog +++ /dev/null @@ -1,241 +0,0 @@ -ngcp-acc-cdi (8.1.0.0+0~mr8.1.0.0) unstable; urgency=medium - - * New release. - - -- Sipwise Jenkins Builder Tue, 08 Oct 2019 09:04:44 +0200 - -ngcp-acc-cdi (8.0.0.0+0~mr8.0.0.0) unstable; urgency=medium - - [ Guillem Jover ] - * [cdaadf5] TT#61954 Update copyright years - * [75ace01] TT#61954 Namespace debhelper fragment files - * [89c9854] TT#61954 Set debhelper compat level in Build-Depends instead of debian/compat - - [ Sipwise Jenkins Builder ] - - -- Sipwise Jenkins Builder Mon, 05 Aug 2019 20:51:26 +0200 - -ngcp-acc-cdi (7.5.0.0+0~mr7.5.0.0) unstable; urgency=medium - - * New release. - - -- Sipwise Jenkins Builder Mon, 17 Jun 2019 14:33:32 +0200 - -ngcp-acc-cdi (7.4.0.0+0~mr7.4.0.0) unstable; urgency=medium - - * New release. - - -- Sipwise Jenkins Builder Thu, 25 Apr 2019 14:25:18 +0200 - -ngcp-acc-cdi (7.3.0.0+0~mr7.3.0.0) unstable; urgency=medium - - * New release. - - -- Sipwise Jenkins Builder Mon, 25 Feb 2019 22:50:06 +0100 - -ngcp-acc-cdi (7.2.0.0+0~mr7.2.0.0) unstable; urgency=medium - - * New release. - - -- Sipwise Jenkins Builder Wed, 09 Jan 2019 21:53:56 +0100 - -ngcp-acc-cdi (7.1.0.0+0~mr7.1.0.0) unstable; urgency=medium - - * New release. - - -- Sipwise Jenkins Builder Mon, 12 Nov 2018 22:31:59 +0100 - -ngcp-acc-cdi (7.0.0.0+0~mr7.0.0.0) unstable; urgency=medium - - * New release. - - -- Sipwise Jenkins Builder Mon, 24 Sep 2018 18:50:53 +0200 - -ngcp-acc-cdi (6.5.0.0+0~mr6.5.0.0) unstable; urgency=medium - - * New release. - - -- Sipwise Jenkins Builder Tue, 24 Jul 2018 13:31:45 +0200 - -ngcp-acc-cdi (6.4.0.0+0~mr6.4.0.0) unstable; urgency=medium - - [ Guillem Jover ] - * [5910752] TT#36351 Use modern ngcp-check-active - - [ Sipwise Jenkins Builder ] - - -- Sipwise Jenkins Builder Tue, 29 May 2018 10:01:14 +0200 - -ngcp-acc-cdi (6.3.0.0+0~mr6.3.0.0) unstable; urgency=medium - - [ Marco Capetta ] - * [df6156d] TT#33867 Update ngcp-kamctl format to the one used in kamailio 5.1.2 - - [ Alexander Lutay ] - * [ff8c5ce] TT#33867 Perform 'wrap-and-sort -sat' - - [ Sipwise Jenkins Builder ] - - -- Sipwise Jenkins Builder Tue, 03 Apr 2018 22:25:16 +0200 - -ngcp-acc-cdi (6.2.0.0+0~mr6.2.0.0) unstable; urgency=medium - - * New release. - - -- Sipwise Jenkins Builder Mon, 29 Jan 2018 21:51:04 +0100 - -ngcp-acc-cdi (6.1.0.0+0~mr6.1.0.0) unstable; urgency=medium - - [ Guillem Jover ] - * [be87bb0] TT#22072 Update packaging - * [34b58ef] TT#22072 Update packaging - - [ Sipwise Jenkins Builder ] - - -- Sipwise Jenkins Builder Tue, 05 Dec 2017 23:58:46 +0100 - -ngcp-acc-cdi (6.0.0.0+0~mr6.0.0.0) unstable; urgency=medium - - * New release. - - -- Sipwise Jenkins Builder Mon, 02 Oct 2017 23:35:47 +0200 - -ngcp-acc-cdi (5.5.0.0+0~mr5.5.0.0) unstable; urgency=medium - - * New release. - - -- Sipwise Jenkins Builder Mon, 17 Jul 2017 22:40:58 +0200 - -ngcp-acc-cdi (5.4.0.0+0~mr5.4.0.0) unstable; urgency=medium - - [ Guillem Jover ] - * [8a3f5f2] TT#5420 Update packaging - - [ Sipwise Jenkins Builder ] - - -- Sipwise Jenkins Builder Tue, 16 May 2017 21:29:22 +0200 - -ngcp-acc-cdi (5.3.0.0+0~mr5.3.0.0) unstable; urgency=medium - - * New release. - - -- Sipwise Jenkins Builder Wed, 22 Mar 2017 10:45:20 +0100 - -ngcp-acc-cdi (5.2.0.0+0~mr5.2.0.0) unstable; urgency=medium - - * New release. - - -- Sipwise Jenkins Builder Fri, 03 Feb 2017 00:26:25 +0100 - -ngcp-acc-cdi (5.1.0.0+0~mr5.1.0.0) unstable; urgency=medium - - * New release. - - -- Sipwise Jenkins Builder Thu, 17 Nov 2016 23:07:24 +0100 - -ngcp-acc-cdi (5.0.0.0+0~mr5.0.0.0) unstable; urgency=medium - - [ Guillem Jover ] - * [9aec03b] MT#20479 Fix dependencies - - -- Alexander Lutay Fri, 21 Oct 2016 14:13:55 +0200 - -ngcp-acc-cdi (1.12.0.0+0~mr4.5.0.0) unstable; urgency=medium - - * New release. - - -- Sipwise Jenkins Builder Mon, 23 May 2016 18:35:13 +0200 - -ngcp-acc-cdi (1.11.0.0+0~mr4.4.0.0) unstable; urgency=medium - - [ Guillem Jover ] - * [3925b71] MT#16473 Convert debian/copyright to machine-readable format - - [ Michael Prokop ] - * [a6a1be0] MT#17699 Bump Standards-Version to 3.9.7 - - [ Sipwise Jenkins Builder ] - - -- Sipwise Jenkins Builder Mon, 21 Mar 2016 22:04:48 +0100 - -ngcp-acc-cdi (1.10.0.0+0~mr4.3.0.0) unstable; urgency=medium - - * New release. - - -- Sipwise Jenkins Builder Wed, 16 Dec 2015 08:59:51 +0100 - -ngcp-acc-cdi (1.9.0.0+0~mr4.2.0.0) unstable; urgency=medium - - * New release. - - -- Sipwise Jenkins Builder Mon, 12 Oct 2015 15:13:46 +0200 - -ngcp-acc-cdi (1.8.0.0+0~mr4.1.0.0) unstable; urgency=low - - [ Kirill Solomko ] - * [9be16fc] perl no critic - - [ Michael Prokop ] - * [fe2a9c1] MT#7505 Add .gitreview file for acc-cdi - - [ Sipwise Jenkins Builder ] - - -- Sipwise Jenkins Builder Mon, 13 Jul 2015 15:00:08 +0200 - -ngcp-acc-cdi (1.7.0.0+0~mr4.0.0.0) unstable; urgency=low - - [ Michael Prokop ] - * [4d1a621] MT#9127 Bump Standards-Version to 3.9.6 - - [ Sipwise Jenkins Builder ] - - -- Sipwise Jenkins Builder Wed, 18 Mar 2015 13:40:42 +0100 - -ngcp-acc-cdi (1.6.0.0+0~mr3.8.0.0) unstable; urgency=low - - * New release. - - -- Sipwise Jenkins Builder Wed, 07 Jan 2015 21:14:14 +0100 - -ngcp-acc-cdi (1.5.0.0+0~mr3.7.0.0) unstable; urgency=low - - * New release. - - -- Sipwise Jenkins Builder Thu, 30 Oct 2014 17:10:06 +0100 - -ngcp-acc-cdi (1.4.0.0+0~mr3.6.0.0) unstable; urgency=low - - * New release. - - -- Sipwise Jenkins Builder Thu, 09 Oct 2014 16:15:58 +0200 - -ngcp-acc-cdi (1.3.0.0+0~mr3.5.0.0) unstable; urgency=low - - * New release. - - -- Sipwise Jenkins Builder Thu, 10 Jul 2014 15:15:46 +0200 - -ngcp-acc-cdi (1.2.0.0+0~mr3.4.0.0) unstable; urgency=low - - [ Alexander Lutay ] - * [6258386] MT#6191 Fixed building warning extended-description-is-empty - - [ Michael Prokop ] - * [8f164da] MT#6511 Bump Standards-Version to 3.9.5 - - [ Sipwise Jenkins Builder ] - - -- Sipwise Jenkins Builder Mon, 26 May 2014 15:32:42 +0200 - -ngcp-acc-cdi (1.1.0.0+0~mr3.3.0.0) unstable; urgency=low - - * New release. - - -- Sipwise Jenkins Builder Fri, 21 Mar 2014 13:07:05 +0100 - -ngcp-acc-cdi (1.0.0) unstable; urgency=low - - * Initial release. - - -- Kirill Solomko Fri, 07 Mar 2014 13:31:01 +0100 - diff --git a/debian/control b/debian/control deleted file mode 100644 index a7ecba8..0000000 --- a/debian/control +++ /dev/null @@ -1,20 +0,0 @@ -Source: ngcp-acc-cdi -Section: utils -Priority: optional -Maintainer: Sipwise Development Team -Build-Depends: - debhelper-compat (= 12), -Standards-Version: 3.9.8 -Homepage: https://www.sipwise.com/ - -Package: ngcp-acc-cdi -Architecture: all -Depends: - libclass-dbi-mysql-perl, - ${misc:Depends}, - ${perl:Depends}, -Description: NGCP component to reduce amount of "lost" calls - A component for NGCP that provides a failsafe mechanism to reduce amount - of "lost" calls in case of unexpected system crashes. Creates intermediate - records for ongoing calls based on acc start (INVITE) records and fixes - "lost" calls based on last intermediate time. diff --git a/debian/copyright b/debian/copyright deleted file mode 100644 index 6501e21..0000000 --- a/debian/copyright +++ /dev/null @@ -1,23 +0,0 @@ -Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/ -Source: https://www.sipwise.com/ -Upstream-Contact: Sipwise Development Team - -Files: * -Copyright: - Copyright © 2007-2019 Sipwise GmbH, Austria -License: GPL-3+ - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - . - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - . - You should have received a copy of the GNU General Public License - along with this program. If not, see . -Comment: - On Debian systems, the full text of the GNU General Public License - version 3 can be found in the file '/usr/share/common-licenses/GPL-3'. diff --git a/debian/ngcp-acc-cdi.cron.d b/debian/ngcp-acc-cdi.cron.d deleted file mode 100644 index b5228ca..0000000 --- a/debian/ngcp-acc-cdi.cron.d +++ /dev/null @@ -1 +0,0 @@ -* * * * * root /usr/sbin/ngcp-acc-cdi >/dev/null diff --git a/debian/ngcp-acc-cdi.dirs b/debian/ngcp-acc-cdi.dirs deleted file mode 100644 index 236670a..0000000 --- a/debian/ngcp-acc-cdi.dirs +++ /dev/null @@ -1 +0,0 @@ -usr/sbin diff --git a/debian/ngcp-acc-cdi.install b/debian/ngcp-acc-cdi.install deleted file mode 100644 index 3f86d36..0000000 --- a/debian/ngcp-acc-cdi.install +++ /dev/null @@ -1 +0,0 @@ -acc-cdi.conf etc/ngcp-acc-cdi/ diff --git a/debian/rules b/debian/rules deleted file mode 100755 index 69aef39..0000000 --- a/debian/rules +++ /dev/null @@ -1,15 +0,0 @@ -#!/usr/bin/make -f - -# Uncomment this to turn on verbose mode. -#export DH_VERBOSE=1 - -D = debian/ngcp-acc-cdi - -%: - dh $@ - -override_dh_install: - install -m 755 acc-cdi.pl $(D)/usr/sbin/ngcp-acc-cdi - dh_install - -.PHONY: override_dh_install diff --git a/debian/source/format b/debian/source/format deleted file mode 100644 index 89ae9db..0000000 --- a/debian/source/format +++ /dev/null @@ -1 +0,0 @@ -3.0 (native)