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


UPDATE BOX


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 https://github.com/kamailio/kamailio kamailio



cd kamailio

git checkout -b 5.2 origin/5.2
make cfg


INSTALL MARIADB (aka MySQL)

apt -y install mariadb-server mariadb-client



Check the status of MariaDB install

systemctl status mariadb



Setup the initial mariaDB implementation

mysql_secure_installation


"enter for none password" 
           Enter your root password you want
SET ROOT PASSWORD = Y
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###
DBENGINE=MYSQL


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
#!define WITH_USRLOCDB

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





kamctl

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,
HOW IT WORKS:
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
[1000]
deny=0.0.0.0/0.0.0.0
secret=34e9d4179cff8a74259ebb52994bc844
dtmfmode=rfc2833
canreinvite=no
permit=0.0.0.0/0.0.0.0
faxdetect=no

[1001]
deny=0.0.0.0/0.0.0.0
secret=61476817178bc4051dc30de0c429ba29
dtmfmode=rfc2833
canreinvite=no
permit=0.0.0.0/0.0.0.0
faxdetect=no
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.
[1000]
deny=0.0.0.0/0.0.0.0
secret=DISABLED34e9d4179cff8a74259ebb52994bc844
dtmfmode=rfc2833
canreinvite=no
permit=0.0.0.0/0.0.0.0
faxdetect=no

[1001]
deny=0.0.0.0/0.0.0.0
secret=61476817178bc4051dc30de0c429ba29
dtmfmode=rfc2833
canreinvite=no
permit=0.0.0.0/0.0.0.0
faxdetect=no
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:
[1000]
deny=0.0.0.0/0.0.0.0
secret=34e9d4179cff8a74259ebb52994bc844
dtmfmode=rfc2833
canreinvite=no
permit=0.0.0.0/0.0.0.0
faxdetect=no

[1001]
deny=0.0.0.0/0.0.0.0
secret=61476817178bc4051dc30de0c429ba29
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:
[1001]
secret=DISABLED34e9d4179cff8a74259ebb52994bc844
[1015]
secret=DISABLEDa74259e179cff8a74252994bc8449ebb
[2153]
secret=Sp3cilCharact3rSff8a7425933479cebb2994bc221
[7009]
secret=Sp3cilCharact3rSb52994bc84434e9d4179cff85ff
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.
INSTALLATION INSTRUCTIONS!
1> create a file "disable.sh" in linux using NANO or Vi or similar
2> The first value at the top would be:
#!/bin/bash
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 disable.sh
5> Now lets create the enable code.
6> create a file "enable.sh"
7> Put this in the script
#!/bin/bash
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 enable.sh
10> You can test the file by typing in ./enable.sh or ./disable.sh 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/enable.sh
15> And to disable it at 10pm, use this line
22 00 * * * /home/disable.sh
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/enable.sh
22 00 * * * /home/disable.sh
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 - http://www.7-zip.org/
Arduino: Open-source electronics platform (software is free) - https://www.arduino.cc/
Audacity: Audio editing software - https://www.audacityteam.org/
Audio Router: Sound routing - https://github.com/audiorouterdev/audio-router
Beyond Compare: Compare two files/directories: whole tree's and directories - https://www.scootersoftware.com/
Blender: 3D modeling software - https://www.blender.org/
Calibre: ebook manager - https://calibre-ebook.com/download
Darktable: Photo workflow a la lightroom - https://www.musicpd.org/ and https://www.darktable.org/
DaVinci Resolve: Video color correcting/editing - https://www.blackmagicdesign.com/products/davinciresolve/
Desmos.com: Online Calculator - https://www.desmos.com/
Discord: Chat and Communication software - https://discordapp.com/
Disk Fan: Visually see how much space is being used on a volume - http://www.diskspacefan.com/
Draftsight: Free CAD - https://www.3ds.com/products-services/draftsight-cad-software/free-download/
Duolingo: Language learning - https://www.duolingo.com/
F.lux: Day/Night cycle on monitor color/brightness - https://justgetflux.com/
Firefox: Web browser - https://www.mozilla.org/en-US/firefox/new/
foobar2000: Freeware audio player - https://www.foobar2000.org
FreeNAS: File server software - http://www.freenas.org/
Fusion 360: Free 3D CAD/CAM design software - https://www.autodesk.com/products/fusion-360/students-teachers-educators
Math/engineering/chemistry solving - https://www.fxsolver.com/ and https://www.cymath.com/ and https://www.mathway.com/Algebra
Gimp: Digital design - https://www.gimp.org/
Git: Version control system - https://git-scm.com/
Google Maps: Navigation app - https://www.google.com/maps
Google's Apps: Google’s document suite (Docs, Sheets, Gmail, etc) - https://www.google.com/
Greenshot: Print screen tool - http://getgreenshot.org/
Handbrake: video converter - https://handbrake.fr/
http://archive.org/: Contains music, movies, books, software, games, and webpages - http://archive.org/
https://www.draw.io/: Online diagram software - https://www.draw.io/
Inkscape: Vector art software - https://inkscape.org/en/
Irfanview: Image viewer, editor, organiser and converter - http://www.irfanview.com/
KeePass: Password manager - https://.info/
Kodi: Entertainment center software - https://kodi.tv/
Krita: Digital design - https://krita.org/en/
LaTeX: Document software - https://www.latex-project.org/
Libre Office: Document editing suite - https://www.libreoffice.org/
Linux/Apache/Postgres/Gcc: Various Linux based OS’s, webservers, compilers, etc. - https://www.linux.org/
LMMS: Music studio - https://lmms.io/
Malwarebytes: Malware protection - https://www.malwarebytes.com/
MPD/Mopidy: F/OSS music player daemon - https://www.mopidy.com/  
MuseScore: Music notation software - https://musescore.org/en
Notepad++: Text Editor - https://notepad-plus-plus.org/
OBS Studio: Streaming and Recording software - https://obsproject.com/
OpenSCAD: 3D Model scripting software - http://www.openscad.org/
Oracle VirtualBox: Open-source hypervisor - https://www.virtualbox.org/
Paint.NET: Image design - https://www.getpaint.net/
pfSense: Firewall software - https://www.pfsense.org/
Plex: Media storage access - https://www.plex.tv/
PuTTy: An all in one protocol terminal - https://www.chiark.greenend.org.uk/~sgtatham/putty/latest.html
Python: A programming language for quickly writing scripts - https://www.python.org/
R: Statistics software - https://www.r-project.org/
REAPER: Audio workstation - https://www.reaper.fm/
Recuva: Restores deleted files - https://www.ccleaner.com/recuva
Search Everything: Instant file search software - https://www.voidtools.com/
Shazam: App that tells you what song is playing - https://www.shazam.com/
Space Engine: Space exploration simulator - http://spaceengine.org/
Steam: Platform for game distribution - http://store.steampowered.com/
stud.io: Lego simulator - https://studio.bricklink.com/v2/build/studio.page
TeamViewer: Remote desktop software - https://www.teamviewer.us/
The Windows Screen capture tool - https://support.microsoft.com/en-us/help/4027213/windows-open-snipping-tool-and-take-a-screenshot
Ubuntu: A Linux OS - https://www.ubuntu.com/
Unity: Game design software - https://unity3d.com/
Visual Studio Code: Code editor - https://code.visualstudio.com/
VLC: Video player - https://www.videolan.org/index.html
VNCServer/Viewer: Remote desktop software - https://www.realvnc.com/en/connect/download/vnc/
Wikipedia: Online encyclopedia - https://www.wikipedia.org/
WinDirStat: Graphical disk usage analyzer - https://windirstat.net/
Wireshark: Open source packet analyze - https://www.wireshark.org/
Zotero: Reference manager - https://www.zotero.org/

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.

IN DETAIL
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.

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")

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

[1000]
deny=0.0.0.0/0.0.0.0 secret=34e9d4179cff8a74259ebb52994bc844 dtmfmode=rfc2833 canreinvite=no permit=0.0.0.0/0.0.0.0 faxdetect=no [1001] deny=0.0.0.0/0.0.0.0 secret=61476817178bc4051dc30de0c429ba29 dtmfmode=rfc2833 canreinvite=no permit=0.0.0.0/0.0.0.0 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:

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


##################################################################

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

##################################################################