Compare commits

15 Commits
main ... master

5 changed files with 512 additions and 28 deletions

241
installed_packages.txt Normal file
View File

@@ -0,0 +1,241 @@
adduser
apt
apt-listchanges
apt-utils
base-files
base-passwd
bash
bash-completion
bind9-dnsutils
bind9-host
bsdutils
build-essential
busybox
bzip2
ca-certificates
console-setup
coreutils
cpio
cron
cron-daemon-common
dash
dbus
debconf
debconf-i18n
debian-archive-keyring
debian-faq
debianutils
diffutils
discover
dmidecode
dmsetup
doc-debian
dpkg
e2fsprogs
eject
fdisk
file
findutils
gcc-12-base
gettext-base
git
gnome
gnome-core
gpgv
grep
groff-base
grub-common
grub-pc
gzip
hostname
htop
hunspell-en-us
hyphen-en-us
ifupdown
inetutils-syslogd
inetutils-telnet
init
init-system-helpers
initramfs-tools
installation-report
intel-microcode
iproute2
iputils-ping
isc-dhcp-client
isc-dhcp-common
kamailio
kamailio-mysql-modules
kamcli
keyboard-configuration
kmod
krb5-locales
laptop-detect
less
libacl1
libapparmor1
libapt-pkg6.0
libargon2-1
libattr1
libaudit-common
libaudit1
libblkid1
libbpf1
libbsd0
libbz2-1.0
libc-bin
libc6
libcap-ng0
libcap2
libcap2-bin
libcom-err2
libcrypt1
libcryptsetup12
libdb5.3
libdebconfclient0
libdevmapper1.02.1
libedit-dev
libedit2
libelf1
libext2fs2
libfdisk1
libffi8
libgcc-s1
libgcrypt20
libgmp10
libgnutls30
libgpg-error0
libgssapi-krb5-2
libhogweed6
libidn2-0
libip4tc2
libjansson-dev
libjansson4
libjson-c5
libk5crypto3
libkeyutils1
libkmod2
libkrb5-3
libkrb5support0
liblocale-gettext-perl
liblockfile-bin
liblz4-1
liblzma5
libmd0
libmnl0
libmount1
libncursesw6
libnettle8
libnewt0.52
libnftables1
libnftnl11
libnss-systemd
libp11-kit0
libpam-modules
libpam-modules-bin
libpam-runtime
libpam-systemd
libpam0g
libpcre2-8-0
libpopt0
libproc2-0
libreadline8
libreoffice-calc
libreoffice-gnome
libreoffice-help-en-us
libreoffice-impress
libreoffice-writer
libseccomp2
libselinux1
libsemanage-common
libsemanage2
libsepol2
libslang2
libsmartcols1
libsqlite3-dev
libss2
libssl-dev
libssl3
libstdc++6
libsystemd-shared
libsystemd0
libtasn1-6
libtext-charwidth-perl
libtext-iconv-perl
libtext-wrapi18n-perl
libtinfo6
libtirpc-common
libtirpc3
libudev1
libunistring2
libuuid1
libxml2-dev
libxtables12
libxxhash0
libzstd1
linux-headers-6.1.0-22-amd64
linux-image-amd64
locales
login
logrotate
logsave
lsof
man-db
manpages
mariadb-server
mawk
media-types
mime-support
mlocate
mount
mythes-en-us
nano
ncurses-base
ncurses-bin
ncurses-term
netbase
netcat-traditional
network-manager-gnome
nftables
openssh-client
openssh-server
os-prober
passwd
pciutils
perl
perl-base
procps
python3-reportbug
readline-common
reportbug
rtpengine
sed
sensible-utils
sngrep
synaptic
systemd
systemd-sysv
systemd-timesyncd
sysvinit-utils
tar
task-english
task-laptop
tasksel
tasksel-data
tcpdump
traceroute
tzdata
ucf
udev
usbutils
usr-is-merged
util-linux
util-linux-extra
uuid-dev
vim-common
vim-tiny
wamerican
wget
whiptail
xz-utils
zlib1g
zstd

68
instructions.txt Normal file
View File

@@ -0,0 +1,68 @@
1. Install all the software
apt-get install $(cat installed_packages.txt)
2. Configure database
2.1 mysql server config:
create database kamailio;
create USER 'kamy'@'%' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON kamailio.* TO 'kamy'@'%';
flush privileges;
exit;
2.2 Configure and import database:
update sql database file with text editor: kamailio.sql
lines @481
lines @1831
mysql -ppassword kamailio < kamailio.sql
3. Copy and configure kamailio.cfg
3.1 Module parameters
Lines 32 and 39
db_url for dispatcher
ds_ping_from for dispatcher
Lines 44 and 45
reg_contact_addr for uac
reg_db_url for uac
Line 61
db_url for acc module
3.2 Variables in request route section
Lines 84-86
$avp(customerpbxip)="10.0.5.4";
$avp(sip1)="10.0.5.7";
$avp(sip2)="10.0.5.5";
3.3 TRUNKAUTH variables
Lines 176 and 177
$avp(auser) = "kam";
$avp(apass) = "kam";
4. Configure kamtcl -> edit kamctlrc file
uncomment lines 18,21,24,27,33,36
configure lines 33 and 36
5. Configure rtpengine
- copy config file from this repository
6. Configure syslog to log call CDRS into separate file
- /etc/syslog.conf /add these lines at the end
local2.* -/var/log/cdr.log
local0.* -/var/log/kamailio.log
7. Reboot server all should be working
open sngrep in one window and in another:
systemctl stop kamailio
systemctl start kamailio
Register messages should be visible.
Example data:
10.0.5.4 ip of your main SIP server
10.0.5.6 ip of kamailio voip proxy
10.0.5.5 ip of secondary SIP server from your provider
10.0.5.7 ip of primary SIP server form your provider
registration user/pass is kam/kam
Check dispatcher status for routing:
kamcmd dispatcher.list

View File

@@ -1,3 +1,4 @@
# Working version 1.0 by Matija Turk
# Load required modules # Load required modules
loadmodule "tm.so" loadmodule "tm.so"
loadmodule "sl.so" loadmodule "sl.so"
@@ -15,42 +16,70 @@ loadmodule "xlog.so"
loadmodule "tmx" loadmodule "tmx"
loadmodule "siputils" loadmodule "siputils"
loadmodule "sanity" loadmodule "sanity"
loadmodule "acc" loadmodule "acc.so"
loadmodule "dialog.so"
loadmodule "db_flatstore.so"
# Global parameters # Global parameters
cfgengine "native" cfgengine "native"
fork=yes fork=yes
children=4 children=4
log_facility=LOG_LOCAL0 log_facility=LOG_LOCAL0
log_prefix="{$mt $hdr(CSeq) $ci} "
# RTPProxy settings # RTPProxy settings
modparam("rtpengine", "rtpengine_sock", "udp:127.0.0.1:2223") modparam("rtpengine", "rtpengine_sock", "udp:127.0.0.1:2223")
# Dispatcher settings # Dispatcher settings
modparam("dispatcher", "db_url", "mysql://kamailio:kamailiow@localhost/kamailio") modparam("dispatcher", "db_url", "mysql://kamy:kamy@localhost/kamailio")
#modparam("dispatcher", "ds_ping_interval", 10) modparam("dispatcher", "ds_ping_interval", 3)
#modparam("dispatcher", "ds_ping_method", "REGISTER") modparam("dispatcher", "ds_ping_method", "OPTIONS")
#modparam("dispatcher", "ds_probing_threshold", 10) modparam("dispatcher", "ds_probing_threshold", 2)
#modparam("dispatcher", "ds_inactive_threshold", 10) modparam("dispatcher", "ds_inactive_threshold", 3)
#modparam("dispatcher", "ds_ping_latency_stats", 1) modparam("dispatcher", "ds_ping_latency_stats", 1)
#modparam("dispatcher", "ds_ping_from", "sip:kam@10.0.5.6") modparam("dispatcher", "ds_ping_reply_codes", "class=2;code=404;code=401")
#modparam("dispatcher", "ds_probing_mode", 1) #Keeps pinging gateways when state is known (to detect change in state) modparam("dispatcher", "ds_ping_from", "sip:kam@10.0.5.6")
modparam("dispatcher", "ds_probing_mode", 1) #Keeps pinging gateways when state is known (to detect change in state)
# KAMCTL config # KAMCTL config
modparam("ctl", "binrpc", "/var/run/kamailio/kamailio_ctl") modparam("ctl", "binrpc", "/var/run/kamailio/kamailio_ctl")
# UAC settings # UAC settings
modparam("uac","reg_contact_addr", "10.0.5.6:5060") modparam("uac","reg_contact_addr", "10.0.5.6:5060")
modparam("uac","reg_db_url", "mysql://kamailio:kamailiow@localhost/kamailio") modparam("uac","reg_db_url", "mysql://kamy:kamy@localhost/kamailio")
modparam("uac","auth_username_avp","$avp(auser)") modparam("uac","auth_username_avp","$avp(auser)")
modparam("uac","auth_password_avp","$avp(apass)") modparam("uac","auth_password_avp","$avp(apass)")
modparam("uac","auth_realm_avp","$avp(arealm)") modparam("uac","auth_realm_avp","$avp(arealm)")
# TM settings # TM settings
modparam("tm", "auto_inv_100_reason", "Trying") modparam("tm", "auto_inv_100_reason", "Trying")
# CDR STUFF
#!define DLG_FLAG 4
#!define FLT_ACC 5
#!define FLT_ACCMISSED 6
#!define FLT_ACCFAILED 7
modparam("dialog", "dlg_flag", DLG_FLAG)
# ACC
# -- cdr accounting to database
modparam("acc", "db_url", "mysql://kamy:kamy@localhost/kamailio")
modparam("acc", "cdrs_table", "acc_cdrs")
modparam("acc", "cdr_enable", 1)
modparam("acc", "cdr_skip", "nocdr")
modparam("acc", "cdr_extra_nullable", 1)
modparam("acc", "cdr_log_enable", 1)
modparam("acc", "cdr_on_failed", 1)
modparam("acc", "cdr_expired_dlg_enable", 1)
modparam("acc", "cdr_start_on_confirmed", 1)
modparam("acc", "cdr_facility", "LOG_LOCAL2")
modparam("acc", "cdr_extra","src_user=$fU;src_domain=$fd;src_ip=$si;dst_user=$rU;dst_ouser=$tU;dst_domain=$rd;callid=$dlg(callid);dst_ip=$Ri;direction=$avp(direction)")
# DIALOG
modparam("dialog", "dlg_flag", DLG_FLAG)
modparam("dialog", "dlg_match_mode", 1)
modparam("dialog", "enable_stats", 1)
/* Main SIP request routing logic /* Main SIP request routing logic
* - processing of any incoming SIP request starts with this route * - processing of any incoming SIP request starts with this route
* - note: this is the same as route { ... } */ * - note: this is the same as route { ... } */
request_route { request_route {
dlg_manage();
# Variables # Variables
$avp(customerpbxip)="10.0.5.4"; $avp(customerpbxip)="10.0.5.4";
$avp(sip1)="10.0.5.7"; $avp(sip1)="10.0.5.7";
@@ -109,26 +138,28 @@ route[RELAY] {
} }
if (is_method("INVITE")) { if (is_method("INVITE")) {
if(!t_is_set("failure_route")) t_on_failure("MANAGE_FAILURE"); if(!t_is_set("failure_route")) t_on_failure("MANAGE_FAILURE");
setflag(DLG_FLAG);
setflag(FLT_ACC); # do accounting
setflag(FLT_ACCFAILED); # even if the transaction fails
} }
# Force RTPENGINE # Force RTPENGINE
if (is_method("INVITE")) { if (is_method("INVITE")) {
rtpengine_manage("replace-origin replace-session-connection force-relay"); rtpengine_manage("replace-origin replace-session-connection force-relay");
} }
# update $du to set the destination address for proxying based on caller IP # update $du to set the destination address for proxying based on caller IP
if ($siz==$avp(sip1) || $siz==$avp(sip2)) { if ($siz==$avp(sip1) || $siz==$avp(sip2)) {
xlog("Incomming call from SIP provider");
# $du = "sip:" + "10.0.5.4";
$du = "sip:" + $avp(customerpbxip); $du = "sip:" + $avp(customerpbxip);
$avp(direction)="inbound";
} else { } else {
xlog("Incomming call from Customer PBX"); $avp(direction)="outbound";
# $du = "sip:" + "10.0.5.7"; # Change To header
ds_select_dst("1","9"); ds_select_dst("1","9");
if (is_method("INVITE")) {
uac_replace_to("sip:" + $rU + "@" + $nh(d) + ":" + $nh(p));
}
} }
# if ($siz=="10.0.5.5") {
# xlog("Incomming call from SIP provider2");
# $du = "sip:" + "10.0.5.4";
# }
# If auth is required perform it # If auth is required perform it
t_on_failure("TRUNKAUTH"); t_on_failure("TRUNKAUTH");
# Relay # Relay
@@ -138,17 +169,13 @@ route[RELAY] {
# TRUNK AUTH ROUTE # TRUNK AUTH ROUTE
failure_route[TRUNKAUTH] { failure_route[TRUNKAUTH] {
xlog("trunk auth");
if (t_is_canceled()) { if (t_is_canceled()) {
exit; exit;
} }
xlog("Checking status code");
if(t_check_status("401|407")) { if(t_check_status("401|407")) {
xlog("status code is valid auth challenge");
$avp(auser) = "kam"; $avp(auser) = "kam";
$avp(apass) = "kam"; $avp(apass) = "kam";
uac_auth(); uac_auth();
xlog("after uac_auth");
t_relay(); t_relay();
exit; exit;
} }

View File

@@ -56,7 +56,15 @@ CREATE TABLE `acc_cdrs` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT, `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`start_time` datetime NOT NULL DEFAULT '2000-01-01 00:00:00', `start_time` datetime NOT NULL DEFAULT '2000-01-01 00:00:00',
`end_time` datetime NOT NULL DEFAULT '2000-01-01 00:00:00', `end_time` datetime NOT NULL DEFAULT '2000-01-01 00:00:00',
`duration` float(10,3) NOT NULL DEFAULT 0.000, `duration` float(10,3) DEFAULT NULL,
`src_user` varchar(32) DEFAULT NULL,
`src_domain` varchar(64) DEFAULT NULL,
`src_ip` varchar(39) DEFAULT NULL,
`dst_user` varchar(64) DEFAULT NULL,
`dst_ouser` varchar(64) DEFAULT NULL,
`dst_domain` varchar(64) DEFAULT NULL,
`callid` varchar(128) DEFAULT NULL,
`dst_ip` varchar(39) DEFAULT NULL,
PRIMARY KEY (`id`), PRIMARY KEY (`id`),
KEY `start_time_idx` (`start_time`) KEY `start_time_idx` (`start_time`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci; ) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci;
@@ -460,7 +468,7 @@ CREATE TABLE `dispatcher` (
`attrs` varchar(128) NOT NULL DEFAULT '', `attrs` varchar(128) NOT NULL DEFAULT '',
`description` varchar(64) NOT NULL DEFAULT '', `description` varchar(64) NOT NULL DEFAULT '',
PRIMARY KEY (`id`) PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci; ) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci;
/*!40101 SET character_set_client = @saved_cs_client */; /*!40101 SET character_set_client = @saved_cs_client */;
-- --
@@ -469,6 +477,9 @@ CREATE TABLE `dispatcher` (
LOCK TABLES `dispatcher` WRITE; LOCK TABLES `dispatcher` WRITE;
/*!40000 ALTER TABLE `dispatcher` DISABLE KEYS */; /*!40000 ALTER TABLE `dispatcher` DISABLE KEYS */;
INSERT INTO `dispatcher` VALUES
(1,1,'sip:10.0.5.7:5060',0,1,'','SIP Provider'),
(2,1,'sip:10.0.5.5:5060',0,0,'','SIP Provider2');
/*!40000 ALTER TABLE `dispatcher` ENABLE KEYS */; /*!40000 ALTER TABLE `dispatcher` ENABLE KEYS */;
UNLOCK TABLES; UNLOCK TABLES;
@@ -1806,7 +1817,7 @@ CREATE TABLE `uacreg` (
`socket` varchar(128) NOT NULL DEFAULT '', `socket` varchar(128) NOT NULL DEFAULT '',
PRIMARY KEY (`id`), PRIMARY KEY (`id`),
UNIQUE KEY `l_uuid_idx` (`l_uuid`) UNIQUE KEY `l_uuid_idx` (`l_uuid`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci; ) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci;
/*!40101 SET character_set_client = @saved_cs_client */; /*!40101 SET character_set_client = @saved_cs_client */;
-- --
@@ -1816,7 +1827,8 @@ CREATE TABLE `uacreg` (
LOCK TABLES `uacreg` WRITE; LOCK TABLES `uacreg` WRITE;
/*!40000 ALTER TABLE `uacreg` DISABLE KEYS */; /*!40000 ALTER TABLE `uacreg` DISABLE KEYS */;
INSERT INTO `uacreg` VALUES INSERT INTO `uacreg` VALUES
(1,'kamailio','kamailio','10.0.5.7','kamailio','10.0.5.7','asterisk','kam','kam','','sip:10.0.5.7:5060',1800,0,0,'10.0.5.6:5060',''); (1,'kamailio','kamailio','10.0.5.7','kamailio','10.0.5.7','asterisk','kam','kam','','sip:10.0.5.7:5060',1800,0,0,'10.0.5.6:5060',''),
(2,'kamailio2','kamailio','10.0.5.5','kamailio','10.0.5.5','asterisk','kam','kam','','sip:10.0.5.5:5060',1800,0,0,'10.0.5.6:5060','');
/*!40000 ALTER TABLE `uacreg` ENABLE KEYS */; /*!40000 ALTER TABLE `uacreg` ENABLE KEYS */;
UNLOCK TABLES; UNLOCK TABLES;
@@ -2279,4 +2291,4 @@ UNLOCK TABLES;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; /*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
-- Dump completed on 2024-09-06 10:12:59 -- Dump completed on 2024-09-15 18:19:52

136
rtpengine.conf Normal file
View File

@@ -0,0 +1,136 @@
[rtpengine]
table = 0
# no-fallback = false
### for userspace forwarding only:
# table = -1
### a single interface:
# interface = 123.234.345.456
### separate multiple interfaces with semicolons:
# interface = internal/12.23.34.45;external/23.34.45.54
### for different advertised address:
# interface = 12.23.34.45!23.34.45.56
interface = any
listen-ng = localhost:2223
# listen-tcp = 25060
# listen-udp = 12222
### interface for HTTP, WS and Prometheus
# listen-http = 9101
listen-http = localhost:2225
# listen-https = localhost:2226
# https-cert =
# https-key =
listen-cli = localhost:2224
timeout = 60
silent-timeout = 3600
tos = 184
# control-tos = 184
# delete-delay = 30
# final-timeout = 10800
# endpoint-learning = heuristic
# reject-invalid-sdp = false
# foreground = false
# pidfile = /run/ngcp-rtpengine-daemon.pid
# num-threads = 16
# num-media-threads = 8
# http-threads = 4
port-min = 30000
port-max = 40000
# max-sessions = 5000
# software-id = rtpengine
# max-load = 5
# max-cpu = 90
# max-bandwidth = 10000000
# scheduling = default
# priority = -3
# idle-scheduling = idle
# idle-priority = 10
recording-dir = /var/spool/rtpengine
recording-method = proc
# recording-format = raw
# redis = 127.0.0.1:6379/5
# redis-write = password@12.23.34.45:6379/42
# redis-num-threads = 8
# no-redis-required = false
# redis-expires = 86400
# redis-allowed-errors = -1
# redis-disable-time = 10
# redis-cmd-timeout = 0
# redis-connect-timeout = 1000
# b2b-url = http://127.0.0.1:8090/
# xmlrpc-format = 0
# janus-secret = ABC123
log-level = 6
log-stderr = false
log-facility = daemon
log-facility-cdr = local0
log-facility-rtcp = local1
# debug-srtp = false
# log-srtp-keys = false
# dtls-cert-cipher = prime256v1
# dtls-rsa-key-size = 2048
# dtls-mtu = 1200
# dtls-signature = sha-256
# dtls-ciphers = DEFAULT:!NULL:!aNULL:!SHA256:!SHA384:!aECDH:!AESGCM+AES256:!aPSK
# graphite = 127.0.0.1:9006
# graphite-interval = 60
# graphite-prefix = foobar.
# homer = 123.234.345.456:65432
# homer-protocol = udp
# homer-id = 2001
# mysql-host = localhost
# mysql-port = 3306
# mysql-user = mysql
# myser-pass = mysql
# mysql-query = select data from voip.files where id = %llu
# dtx-delay = 50
# max-dtx = 600
# dtx-buffer = 5
# dtx-lag = 100
# dtx-shift = 0
# amr-dtx = native
# dtx-cn-params = 60
# silence-detect = 0.05
# cn-payload = 60
# sip-source = false
# dtls-passive = false
# mqtt-host = localhost
# mqtt-port = 1883
# mqtt-id =
# mqtt-user = foo
# mqtt-pass = bar
# mqtt-capath =
# mqtt-cafile =
# mqtt-certfile =
# mqtt-keyfile =
# mqtt-publish-qos = 0
# mqtt-publish-topic = rtpengine
# mqtt-publish-interval = 5000
# mqtt-publish-scope = media
# mos = CQ
# poller-per-thread = false
# socket-cpu-affinity = -1