Wednesday, February 26, 2020

Install Kamailio 5.2 on DEBIAN 10

!! This is a work in progress as of Feb 25/2020 !! 

Create a standard Debian 10 installation.

I created this on Debian 10.3, NO Gui, only SSH server and standard server utils were selected.  GUI, printer server were not selected.

Log into the box as the user.  Run the commands in order in the grey boxes

su root


apt-get update && apt-get upgrade 

apt-get -y install git-core
apt-get -y install gcc g++
apt-get -y install flex
apt-get -y install bison
apt-get -y install make autoconf
apt-get -y install pkg-config
apt-get -y install default-libmysqlclient-dev 

mkdir -p /usr/local/src/kamailio-5.2

cd /usr/local/src/kamailio-5.2

We'll download the Kamailio branch
(this command is all one line)

git clone --depth 1 --no-single-branch kamailio

cd kamailio

git checkout -b 5.2 origin/5.2
make cfg


apt -y install mariadb-server mariadb-client

Check the status of MariaDB install

systemctl status mariadb

Setup the initial mariaDB implementation


"enter for none password" 
           Enter your root password you want
Remove anonymous users= Y
Disallow root login remotely = Y
Remove test database and access to it? = Y
Reload privilege tables now = Y
edit the following file entry of "include_modules= 

nano -w src/modules.lst

##modify to:##
include_modules= db_mysql

save your changes

make all

export PATH=$PATH:/usr/local/sbin

export PATH=$PATH:/usr/sbin

make install

nano -w /usr/local/etc/kamailio/kamctlrc

set this value by removing leading # symbol###

save your changes

nano /usr/local/etc/kamailio/kamailio.cfg

Paste these entries in near the top as pictured

#!define WITH_MYSQL
#!define WITH_AUTH

save your changes

cd /usr/local/src/kamailio-5.2/kamailio

make install-systemd-debian

kamdbctl create

(use latin1 for database)
(Y to all questions)

cd /home/
mkdir kamailio
chown kamailio:kamailio kamailio

cd /usr/local/src/kamailio-5.2/kamailio/src

make install-systemd-debian

systemctl enable kamailio
systemctl daemon-reload

systemctl start kamailio

KAMAILIO should be running!

This command should give you responses to show that the system is up and running


The output will look like this:

Sunday, February 23, 2020

enable disable asterisk extensions by time of day

Here's a way you could have extensions be activated/deactivated by a script.  Maybe you want to have an extension only work for a certain time frame. 

Create an bash script that changes modifies extension passwords stored in "SIP_ADDITIONAL.CONF" file in / etc / asterisk and use linux "crontab" to run it at the time you need. This just changes the extension credentials stored in active memory (not the ones stored in the mySQL database).
This script below maintains whatever the current extension password is, pre-pends it with characters of your choice,
sip_additional.conf looks SOMETHING like this (I have removed lines to make it easier to understand)
You will see extensions in your system and and their "secret" or passwords for each.
In my example you see extension 1000 and extension 1001

The SED command will alter the password and update the asterisk .conf file and reload it into memory.
sed -i '/1000]/!b;n;n;s/secret=/secret=DISABLED/' /etc/asterisk/sip_additional.conf
asterisk -rx 'reload'
NOW the config file looks like this.

Notice extension 1000 "SECRET" contains "DISABLED" as part of the password, this will de-register the softphone / SIPphone because the passwords now do not match.
I am adding the text "DISABLED", but you can use any characters you want. You could use 2388NNbbdh784.
You could also customize it for each extension to make it more complicated from being guessed by users.
This SED command would be used to restore the original password.
sed -i '/1000]/!b;n;n;s/secret=DISABLED/secret=/' /etc/asterisk/sip_additional.conf
asterisk -rx 'core reload'
Your conf file will be restored back and will look like this:

Notice that the secret for extension 1000 no longer has "DISABLED" in it.
So if you wanted to change a whole bunch of extensions, it would look something like this:
This bash script would change extensions 1001, 1015, 2153 and 7009
You'll notice that instead of "disabled" i'm using unique values ​​for some of them.
sed -i '/1001]/!b;n;n;s/secret=/secret=DISABLED/' /etc/asterisk/sip_additional.conf
sed -i '/1015]/!b;n;n;s/secret=/secret=DISABLED/' /etc/asterisk/sip_additional.conf
sed -i '/2153]/!b;n;n;s/secret=/secret=Sp3cilCharact3r$/' /etc/asterisk/sip_additional.conf
sed -i '/7009]/!b;n;n;s/secret=/secret=Sp3cilCharact3rS/' /etc/asterisk/sip_additional.conf
asterisk -rx 'core reload'
Your sip_additional.conf file would look like this:
And this command would revert them back. Just make sure that you match the secret values
sed -i '/1001]/!b;n;n;s/secret=DISABLED/secret=/' /etc/asterisk/sip_additional.conf
sed -i '/1015]/!b;n;n;s/secret=DISABLED/secret=/' /etc/asterisk/sip_additional.conf
sed -i '/2153]/!b;n;n;s/secret=Sp3cilCharact3rS/secret=/' /etc/asterisk/sip_additional.conf
sed -i '/7009]/!b;n;n;s/secret=Sp3cilCharact3rS/secret=/' /etc/asterisk/sip_additional.conf
asterisk -rx 'core reload'
Now your extensions are back to normal.
There is one thing to remember, if these extensions are disabled, and you make a GUI change, asterisk will rebuild the sip_additional.conf file and re-enable these and you would need to run the script again.
This is also a 'failsafe' for the above script. If you run it, but have problems, all you have to so is press "SUBMIT" and APPLY in the PBX GUI and everything is back to normal. You may have a fail2ban hit on these extensions, easy to clear that out at time of re-enable.
1> create a file "" in linux using NANO or Vi or similar
2> The first value at the top would be:
sed -i '/XXXXX]/!b;n;n;s/secret=/secret=DISABLE/' /etc/asterisk/sip_additional.conf
asterisk -rx 'core reload'
3> Save the file
4> Make the file executable
 chmod u+x
5> Now lets create the enable code.
6> create a file ""
7> Put this in the script
sed -i '/1000]/!b;n;n;s/secret=DISABLED/secret=/' /etc/asterisk/sip_additional.conf
asterisk -rx 'core reload'
8> Save the file
9> Make the file executable
 chmod u+x
10> You can test the file by typing in ./ or ./ to test the script
11> Once you confirm your scripts are working, you can activate it with CRONTAB.
There are many articles to better describe crontab, but here is how I tested
12> enter the crontab editer
crontab -e
13> You'll see something like:
25 * * * * /var/lib/asterisk/bin/issabelpbx-cron-scheduler.php
15> To make the script run at 8 am add this line:
8 00 * * * /home/
15> And to disable it at 10pm, use this line
22 00 * * * /home/
16> You'll see something like this when you are done:
You'll note the path. My scripts were created in / home so my path reflects that in the command.
25 * * * * /var/lib/asterisk/bin/issabelpbx-cron-scheduler.php
8 00 * * * /home/
22 00 * * * /home/
17> Save your changes and you are done!

Tuesday, February 18, 2020

Internet pages of things you didn't know you needed

7Zip: File archiving -
Arduino: Open-source electronics platform (software is free) -
Audacity: Audio editing software -
Audio Router: Sound routing -
Beyond Compare: Compare two files/directories: whole tree's and directories -
Blender: 3D modeling software -
Calibre: ebook manager -
Darktable: Photo workflow a la lightroom - and
DaVinci Resolve: Video color correcting/editing - Online Calculator -
Discord: Chat and Communication software -
Disk Fan: Visually see how much space is being used on a volume -
Draftsight: Free CAD -
Duolingo: Language learning -
F.lux: Day/Night cycle on monitor color/brightness -
Firefox: Web browser -
foobar2000: Freeware audio player -
FreeNAS: File server software -
Fusion 360: Free 3D CAD/CAM design software -
Math/engineering/chemistry solving - and and
Gimp: Digital design -
Git: Version control system -
Google Maps: Navigation app -
Google's Apps: Google’s document suite (Docs, Sheets, Gmail, etc) -
Greenshot: Print screen tool -
Handbrake: video converter - Contains music, movies, books, software, games, and webpages - Online diagram software -
Inkscape: Vector art software -
Irfanview: Image viewer, editor, organiser and converter -
KeePass: Password manager - https://.info/
Kodi: Entertainment center software -
Krita: Digital design -
LaTeX: Document software -
Libre Office: Document editing suite -
Linux/Apache/Postgres/Gcc: Various Linux based OS’s, webservers, compilers, etc. -
LMMS: Music studio -
Malwarebytes: Malware protection -
MPD/Mopidy: F/OSS music player daemon -  
MuseScore: Music notation software -
Notepad++: Text Editor -
OBS Studio: Streaming and Recording software -
OpenSCAD: 3D Model scripting software -
Oracle VirtualBox: Open-source hypervisor -
Paint.NET: Image design -
pfSense: Firewall software -
Plex: Media storage access -
PuTTy: An all in one protocol terminal -
Python: A programming language for quickly writing scripts -
R: Statistics software -
REAPER: Audio workstation -
Recuva: Restores deleted files -
Search Everything: Instant file search software -
Shazam: App that tells you what song is playing -
Space Engine: Space exploration simulator -
Steam: Platform for game distribution - Lego simulator -
TeamViewer: Remote desktop software -
The Windows Screen capture tool -
Ubuntu: A Linux OS -
Unity: Game design software -
Visual Studio Code: Code editor -
VLC: Video player -
VNCServer/Viewer: Remote desktop software -
Wikipedia: Online encyclopedia -
WinDirStat: Graphical disk usage analyzer -
Wireshark: Open source packet analyze -
Zotero: Reference manager -

Sunday, February 16, 2020

How balanced XLR audio works

XLR refers to the type of connector used, but the concept of "XLR audio" is generally referring to the balanced audio mechanism its most popularly know for.

Balanced audio uses a 3 wire model: GROUND/SHIELD, POSITIVE/HOT/In-Phase and NEGATIVE/COLD/Out-Of-Phase

The ground provides an electrical ground to the device connected to it.  The Positive in-phase and Negative out-of-phase signal contain a copies of the analog signal with one signal electronically flipped to be a mirrored version of its original.  These two signals pass, down the wire, any encountered external interference being applied to both signals.  The receiving device (mixer usually) flips the mirrored signal back and recombines the signals together, restoring the original signal and cancelling out interference.

This diagram shows the audio signal entering the microphone, transformed into a balanced "positive" and "negative" signal and sent on an audio wire to a mixer on the right.
How balanced XLR audio works (click on it to zoom)
The red and blue squares represent interference encountered as the signal travels along the wire between the microphone and mixer.

When the signal arrives at the mixer, the negative signal is flipped back, restoring the full original audio, and the interference cancels itself out.

The audio signal enters the microphone, where the signal is copied, with one copy going out the positive connection and an inverted 180° out of phase copy of the signal simultaneously goes out the negative connection.  The signals are identical, but a mirror "opposite" of its counter part.  As the wave form goes up on the positive, the negative form of the wave does the same thing, but in an opposite form.

As the audio signal flows along the wire, external interference that is encountered will affects both the negative and positive signal equally and simultaneously.  The interference represented by the squares applies itself simultaneously to both copies of the signal on the wire.  The interference is pushing the red signal 'upwards', and that same interference on the negative (blue) signal is also pushing the signal 'upwards.

Upon reaching the mixer, the inverted negative signal flipped (in blue) back to 'normal' to match the copy of the signal on the positive (red) connection using a differential amplifier.

When the negative signal is inverted, both the positive and negative sound wave match perfectly, but what doesn't match now is the signal for the interference that is encountered, it is now 180° out of phase with each other.  

When the two signals are recombined, two things happen.  The overall level of the original sound file increases (superposition) and the squares that represent the interference in the line, cancels itself out (know as "destructive interference").  It should also be noted that when the signals are combined, the final signal level is larger too.  My diagram does it being same heights, which is a little bit misleading.

The original clean signal is now at the destination!

This is the how you get clean audio signals over long distance cables!!

Heres a bit of a real world visual.

In this picture, I've taken two leads from an oscilloscope and connected them to the positive and negative pins of an XLR microphone.

On this dual channel scope, you can see positive (top) and negative (bottom).  

You can see the signals are opposite to each other.

Saturday, February 15, 2020

SED and AWK examples

Keeping some weird SED examples that might help people.

This example.  I needed to search for an entry, go down a couple of lines and then do a find replace in that line.

So in the below example, i wanted to find the entry starting with 1001, move down 2 lines, and insert change that line using a substitute.  This was in a file called sip_additional.conf

deny= secret=34e9d4179cff8a74259ebb52994bc844 dtmfmode=rfc2833 canreinvite=no permit= faxdetect=no [1001] deny= secret=61476817178bc4051dc30de0c429ba29 dtmfmode=rfc2833 canreinvite=no permit= faxdetect=no

So I used this command 

sed -i '/1001]/!b;n;n;s/secret=/secret=DISABLED/' sip_additional.conf

This looks for the entry 1000]
Then the ;n;n entries mean move down 2 lines
then we perform a (s)ubstitute secret= to secret=DISALBED

The end result looks like this:

deny= secret=34e9d4179cff8a74259ebb52994bc844 dtmfmode=rfc2833 canreinvite=no permit= faxdetect=no [1001] deny= secret=DISABLED61476817178bc4051dc30de0c429ba29 dtmfmode=rfc2833 canreinvite=no permit= faxdetect=no


This is a typical find/replace in a file
sed -i -r 's/display_errors = Off/display_errors = On/' /etc/php.ini