Difference between pages "Asterisk" and "Linux basics"

From Wikislax
(Difference between pages)
Jump to: navigation, search
(Documentation)
 
(Useful linux commands)
 
Line 1: Line 1:
{{RightTOC}}
+
== Using VI ==
  
== What is Asterisk ? ==
+
'''vi''' (pronounced vee-eye) is the Unix standard text editor so affords editing the configuration files by hand. If you don’t know it yet, it can be a bit surprising. Actually, '''vi''' was created at a time when the keyboards did not have any arrow or insert keys. So there are two modes: the «open» mode and the «insert» mode.
  
[http://www.asterisk.org/ Asterisk] is an Open Source telephony server. Asterisk can handle traditional telephony hardware and be connected to your telephony provider, but Asterisk can also be used to connect VoIP phones locally and on the Internet. In case a SIP subscription is included with your Internet access, you will be able to use it to access the telephony network. And if you need simultaneous calls, then you will be able to use a multi-channel "SIP trunk", that you can get from one of the many SIP providers on the market. Among various applications, Asterisk affords leaving recorded messages and sending them by mail, or doing some conferencing.
+
The open mode affords moving the cursor. '''j''', '''k''', '''l''', '''m''' move the cursor by one character. '''ctrl-f''' moves one page forward and '''ctrl-b''' moves one page backwards. '''w''' moves one word forward and '''b''' moves one word backwards. It is also possible to use the arrow keys.
  
From a practical viewpoint, Asterisk is easy to install but requires quite some efforts to understand and properly configure, as it is massive and the available documentation is not easy to understand, or some key points are sometimes missing. Also the configuration files are sensitive to syntax errors and the software will stop working, with no clue on what's wrong. However these syntax difficulties are during configuration only. When fixed, the software seems to be quite stable.
+
'''i''' goes into insert mode before the cursor, '''a''' goes into insert mode after the cursor, and '''A''' goes into insert mode at the end of the line. '''o''' adds a line after the current line, and '''O''' adds a live before the current line. '''R''' goes into rewrite mode.
  
== Installing Dahdi ==
+
'''esc''' affords getting out of the insert mode.
  
Dahdi-linux is a set of Asterisk linux modules required only when using telephony hardware. It was once also required to provide timing functions to the rest of the sofware but this is no longer the case so you probably don't need to install it. If you do, [http://www.asterisk.org/downloads download] then untar and install.
+
'''c$''' affords replacing the end of the line and '''d$''' affords deleting the end of the line. '''cw''' affords replacing one word and '''dw''' affords deleting one word. '''dd''' affords deleting the current line.
  
# tar -C /usr/local -xvf dahdi-linux-x.y.z.tar.gz
+
''':q''' affords quitting without saving. If the file has been modified, quitting must be forced by typing ''':q!'''. ''':x''' affords saving and quitting. If the file does not have the write rigths, saving must be forced by typing ''':x!'''. ''':w''' affords writing the text in a new file. If the new file already exists, writing must be forced by typing ''':w!'''.
# cd /usr/local/include
 
# ln -s ../dahdi-linux-x.y.z/linux/include/dahdi .
 
# cd /usr/local/dahdi-linux-x.y.z
 
# make
 
# make install
 
# make clean
 
  
That's it. <u>Note</u> : the other package Dahdi-tools is not required. <u>Other note</u> : Dahdi requires a kernel compiled with CONFIG_CRC_CCITT=y.
+
''':num''' affords moving to the line number num. ''':$''' affords moving to the end of the file.
 +
''':num1copynum2''' affords copying the line number num1 after the line number num2. ''':num1mnum2''' affords moving the line number num1 after the line number num2.
  
== Installing Jansson ==
+
For detailed information, check the [http://vimdoc.sourceforge.net/htmldoc/help.html VIM Documentation]. To enter special characters check the page on [http://vimdoc.sourceforge.net/htmldoc/digraph.html digraphs]. To get rid of the message "skipping N old session files", delete files elvis*.ses in /var/tmp.
  
Jansson is a required Json development library. [http://www.digip.org/jansson/releases/ Download] then untar and install.
+
== Using SSH ==
  
# tar -C /usr/local -xvf jansson-x.y.z.tar.gz
+
SSH is a suite of tools affording connecting remotely over encrypted communications. On the client side, '''ssh''' offers a command line terminal, '''scp''' affords copying a file, and '''sftp''' behaves like ftp. The server side consists of sshd, sftp-server, and ssh-agent. ssh-add, ssh-keysign, ssh-keyscan, and ssh-keygen afford key management. The SSH present on Slackware and the BSDs is [https://www.openssh.com/ OpenSSH], developped by members of the [https://www.openbsd.org/ OpenBSD] project.
# cd /usr/local/jansson-linux-x.y.z
 
# ./configure --prefix=/usr/local --libdir=/usr/local/lib64
 
# make
 
# make install
 
# make clean
 
  
== Installing c-client ==
+
'''ssh''' obviously requires your connection password every time it is executed. This can be avoided by creating on the client a pair of rsa keys and copying the public key to the server. Not specifying a passphrase is not very secure but will afford avoiding having to enter it every time :
  
The asterisk imap option requires presence of library c-lient.a, which is part of Imap-uw, by the University of Washington. The University of Washington seems to be no longer distributing the software so we keep a copy for your convenience. [{{SERVER}}/wikislax/download/c-client.tar.Z Download] then untar and install :
+
# '''ssh-keygen -t rsa'''
 +
Generating public/private rsa key pair.
 +
Enter file in which to save the key (/root/.ssh/id_rsa): '''<cr>'''
 +
Enter passphrase (empty for no passphrase): '''<cr>'''
 +
Enter same passphrase again: '''cr>'''
 +
Your identification has been saved in /root/.ssh/id_rsa.
 +
Your public key has been saved in /root/.ssh/id_rsa.pub.
 +
The key fingerprint is:
 +
SHA256:ATSDdER5/l8OJvr+jpINIReJtd81zntVbTjuJW5aobE root@client
 +
The key's randomart image is:
 +
+---[RSA 2048]----+
 +
|  ..=O+..      |
 +
|    ..o++.    ..|
 +
|      oo.    = +|
 +
|      . +o . = +.|
 +
|      oSo. o * o|
 +
|        . o o*.=.|
 +
|        = +E+* .|
 +
|        + ...+.. |
 +
|        ++o+    |
 +
+----[SHA256]-----+
 +
# '''scp root@client:.ssh/id_rsa.pub root@server:.ssh/id_rsa.pub'''
 +
password: '''secret<cr>'''
 +
id_rsa.pub                                          100% 394      1.8MB/s  00:00
 +
# '''ssh server'''
 +
password: '''secret<cr>'''
 +
# '''cd .ssh'''
 +
# '''cat >> authorized_keys < id_rsa.pub'''
 +
# '''chmod 600 authorized_keys'''
 +
# '''rm id_rsa.pub'''
  
# gunzip c-client.tar.Z
+
== Useful linux commands ==
# tar -C /usr/local -xvf c-client.tar
 
# cd /usr/local
 
# chown -R root:root imap-2007f
 
# chmod -R o-w imap-2007f
 
# cd imap2007f
 
# make slx EXTRACFLAGS="-I/usr/include/openssl -g -O2 -fPIC" SSLCERTS=/etc/ssl/certs SSLKEYS=/etc/ssl/private
 
 
 
== Installing Speex ==
 
 
 
Speex is a required free codec. [https://www.speex.org/downloads/ Download] speex source code then untar and install.
 
 
 
# tar -C /usr/local -xvf speex-x.y.z.tar.gz
 
# cd /usr/local/speex-x.y.z
 
# ./configure --prefix=/usr/local --libdir=/usr/local/lib64
 
# make
 
# make install
 
# make clean
 
 
 
== Installing Asterisk ==
 
 
 
[http://www.asterisk.org/downloads Download Asterisk] then untar and install. Make menuselect affords choosing which components to use. If using mysql, be sure to read the next paragraph before invoking make. Otherwise proceed. make samples affords creating the configuration files in /usr/local/etc/asterisk.
 
 
 
# groupadd asterisk
 
# useradd -g asterisk asterisk
 
# tar -C /usr/local --no-same-permissions --no-same-owner -xvf asterisk-x.y.z.t.tar.gz
 
# cd /usr/local/asterisk-x.y.z.t
 
# ./configure --prefix=/usr/local --libdir=/usr/local/lib64 --mandir=/usr/local/man \
 
--with-asound --with-crypto --with-iconv --with-imap=/usr/local/imap-2007f \
 
--with-jansson --with-ldap --with-speex --with-ssl
 
# make menuselect
 
# make
 
# make install
 
# make install-logrotate
 
# make samples
 
# make clean
 
# chown -R asterisk:asterisk /usr/local/lib64/asterisk
 
# chown -R asterisk:asterisk /usr/local/var/lib/asterisk
 
# chown -R asterisk:asterisk /usr/local/var/log/asterisk
 
# chown -R asterisk:asterisk /usr/local/var/run/asterisk
 
# chown -R asterisk:asterisk /usr/local/var/spool/asterisk
 
# chmod o+x /usr/local/etc/asterisk
 
# chmod o-x /usr/local/lib64/asterisk
 
# chmod o-x /usr/local/var/lib/asterisk
 
# chmod o-x /usr/local/var/log/asterisk
 
# chmod o-x /usr/local/var/run/asterisk
 
# chmod o-x /usr/local/var/spool/asterisk
 
 
 
If using mysql modules, there might be a glitch with the mysql include path. Replace in the files below the lines with "#include <mysql/mysql.h>" by lines with "#include <mysql.h>" (removing the directory) :
 
 
 
addons/app_mysql.c
 
addons/cdr_mysql.c
 
addons/res_config_mysql.c
 
 
 
It is then possible to launch asterisk in the foreground with various levels of verbosity (depending on the number of v's). However the default configuration files include a number of options that we don't want, so we'll rename them first and start with empty files. Asterisk includes a console and then proposes a shell  :
 
 
 
# cd /usr/local/etc/asterisk
 
# mv extensions.conf extensions.conf.sample
 
# mv extensions.ael extensions.ael.sample
 
# mv sip.conf sip.conf.sample
 
# sudo -u asterisk asterisk -vvvc
 
. . .
 
*CLI>
 
 
 
Type '''help''' to view the available commands, however before doing anything useful we'll need to modify the configuration files so let's just '''core stop gracefully''' here.
 
 
 
== Running asterisk ==
 
 
 
Asterisk runs as a daemon so must be launched at startup and stopped at shutdown. Update /etc/rc.d/rc.local and /etc/rc.d/rc.local_shutdown accordingly :
 
 
 
# vi /etc/rc.d/rc.local
 
. . .
 
# start asterisk
 
if [ -x /usr/local/sbin/safe_asterisk ]; then
 
        echo "Starting asterisk: /usr/local/sbin/safe_asterisk -G asterisk -U asterisk -p"
 
        /usr/local/sbin/safe_asterisk -G asterisk -U asterisk -p
 
fi
 
<esc>
 
:x
 
# vi /etc/rc.d/rc.local_shutdown
 
. . .
 
# stop asterisk
 
if [ -r /usr/local/var/run/asterisk/asterisk.pid ]; then
 
        echo "Stopping asterisk: kill -INT `cat /usr/local/var/run/asterisk/asterisk.pid`"
 
        kill -INT `cat /usr/local/var/run/asterisk/asterisk.pid`
 
fi
 
<esc>
 
:x
 
 
 
== Configuring Asterisk ==
 
 
 
Asterisk running in the backgroung, it's possible to attach to the process using '''asterisk -r''' and to exit the asterisk shell by typing '''exit'''. Most of the configuration files can be modified externally then reloaded using commands such as '''dialplan reload''', '''sip reload''', or '''voicemail reload'''. A few files however cannot (example confbridge.conf), and require restarting using '''core restart now'''. Type '''help''' to get a complete list of commands.
 
 
 
The configuration files are created under EPREFIX/etc and there are many of them (112 in version 1.15.0.0 !). The bad news is that they must be all reviewed and modified to remove unneeded configuration options. When done though, modifying only a few will afford getting a working system with a reasonnable set of features. We decided to use LDAP to configure our users so this is what is detailed below.
 
 
 
<u>Note</u> : the asterisk configuration files are organized in contexts whose names are enclosed in square brackets on a line of its own. Definitions in these contexts - otherwise mentionned - are valid inside these contexts only.
 
  
 
{| {{thead}}
 
{| {{thead}}
 
|-
 
|-
! {{chead}} width="150" | Configuration file
+
! {{chead}} width="220" | Command
! {{chead}} | Usage
+
! {{chead}} | Effect
 
|-
 
|-
| [[Sip.conf|sip.conf]]
+
|<tt>'''cd'''</tt>||change directory.
| to configure sip accounts
 
 
|-
 
|-
| [[Res_ldap.conf|res_ldap.conf]]
+
|<tt>'''chmod -R ppp ddd'''</tt>||recursively change permissions on file or directory.
| to configure LDAP users
 
 
|-
 
|-
| [[Confbridge.conf|confbridge.conf]]
+
|<tt>'''chown -R uuu:ggg ddd'''</tt>||recursively change user:group ownership on file or directory.
| to configure conferences
 
 
|-
 
|-
| [[Voicemail.conf|voicemail.conf]]
+
|<tt>'''chgrp -R ggg ddd'''</tt>||recursively change group ownership on file or directory.
| to configure voicemail boxes
 
 
|-
 
|-
| [[Extensions.conf|extensions.conf]]
+
|<tt>'''command xxx <nowiki>|</nowiki> grep yyy'''</tt>||search for string yyy in output of command xxx.
| to configure the dialplan
+
|-
 +
|<tt>'''ethtool -s eth0 wol g'''</tt>||puts interface eth0 in wake-on-lan status.
 +
|-
 +
|<tt>'''find xxx -name yyy -print'''</tt>||find file yyy in in subdirectories of xxx.
 +
|-
 +
|<tt>'''ifconfig -a'''</tt>||kill print the network interfaces configuration.
 +
|-
 +
|<tt>'''iptables -L'''</tt>||print the firewall rules.
 +
|-
 +
|<tt>'''killall xxx'''</tt>||kill program named xxx.
 +
|-
 +
|<tt>'''ldconfig'''</tt>||reload libraries taking into account new libraries just built.
 +
|-
 +
|<tt>'''ln -s existing new'''</tt>||create a symbolic link new to an existing directory or file.
 +
|-
 +
|<tt>'''ls -al'''</tt>||list the working directory, including files beginning with a dot.
 +
|-
 +
|<tt>'''man xxx'''</tt>||display the xxx command manual page.
 +
|-
 +
|<tt>'''more xxx'''</tt>||display file xxx with the possibility of moving up and down. '''less''' and '''most''' are similar commands.
 +
|-
 +
|<tt>'''mount -t ttt /dev/xxx /mnt/ddd'''</tt>||mount device xxx as type ttt under directory ddd.
 +
|-
 +
|<tt>'''(u)mount /mnt/ddd'''</tt>||(u)mount device ddd as specified in /etc/fstab.
 +
|-
 +
|<tt>'''nmap <i>host</i>'''</tt>||check filtering status of ports on <i>host</i>. '''-sU''' for UDP.
 +
|-
 +
|<tt>'''ps -ef'''</tt>||list the running processes.
 +
|-
 +
|<tt>'''pwd'''</tt>||print working directory.
 +
|-
 +
|<tt>'''rm -r'''</tt>||remove file or directory recursively.
 +
|-
 +
|<tt>'''route'''</tt>||display the network routing table.
 +
|-
 +
|<tt>'''screen <i>-S<name></i>'''</tt>||screen offers a frame to run a shell, detach from it (<ctrl>-a d) and later reattach to it.
 +
|-
 +
|<tt>'''ssh <i>host</i>'''</tt>||connect remotely to site <i>host</i>.
 +
|-
 +
|<tt>'''su -l uuuu'''</tt>||execute shell as another user. if -l is used an environment similar to what the other user would have had with a direct login is provided.
 +
|-
 +
|<tt>'''telinit n'''</tt>||go to the runlevel n (1=single-user, 3=multi-user, 4=graphical, 6=reboot).
 +
|-
 +
|<tt>'''umask'''</tt>||edit /etc/profile to change the default umask value of 022 and '''set it to 027''' (files not readable by other users), a good setting except when installing as root server software to be ran as a standard user account (permission issues).
 +
|-
 +
|<tt>'''vi'''</tt>||run the vi text editor. To get rid of the message "skipping N old session files", delete files elvis*.ses in /var/tmp.
 
|}
 
|}
  
 
<br clear=all>
 
<br clear=all>
  
== Documentation ==
+
{{pFoot|[[Maintaining Slackware]]|[[Main Page]]|[[Configuration files]]}}
 
 
[https://wiki.asterisk.org/wiki/display/AST/Asterisk+15+Documentation Asterisk Wiki]
 
 
 
[{{SERVER}}/wikislax/download/Asterisk.pdf Asterisk Book]
 
 
 
<br/>
 
 
 
{{pFoot|[[Sucknews]]|[[Main Page]]|[[Sip.conf]]}}
 

Revision as of 11:48, 15 December 2022

Using VI

vi (pronounced vee-eye) is the Unix standard text editor so affords editing the configuration files by hand. If you don’t know it yet, it can be a bit surprising. Actually, vi was created at a time when the keyboards did not have any arrow or insert keys. So there are two modes: the «open» mode and the «insert» mode.

The open mode affords moving the cursor. j, k, l, m move the cursor by one character. ctrl-f moves one page forward and ctrl-b moves one page backwards. w moves one word forward and b moves one word backwards. It is also possible to use the arrow keys.

i goes into insert mode before the cursor, a goes into insert mode after the cursor, and A goes into insert mode at the end of the line. o adds a line after the current line, and O adds a live before the current line. R goes into rewrite mode.

esc affords getting out of the insert mode.

c$ affords replacing the end of the line and d$ affords deleting the end of the line. cw affords replacing one word and dw affords deleting one word. dd affords deleting the current line.

:q affords quitting without saving. If the file has been modified, quitting must be forced by typing :q!. :x affords saving and quitting. If the file does not have the write rigths, saving must be forced by typing :x!. :w affords writing the text in a new file. If the new file already exists, writing must be forced by typing :w!.

:num affords moving to the line number num. :$ affords moving to the end of the file. :num1copynum2 affords copying the line number num1 after the line number num2. :num1mnum2 affords moving the line number num1 after the line number num2.

For detailed information, check the VIM Documentation. To enter special characters check the page on digraphs. To get rid of the message "skipping N old session files", delete files elvis*.ses in /var/tmp.

Using SSH

SSH is a suite of tools affording connecting remotely over encrypted communications. On the client side, ssh offers a command line terminal, scp affords copying a file, and sftp behaves like ftp. The server side consists of sshd, sftp-server, and ssh-agent. ssh-add, ssh-keysign, ssh-keyscan, and ssh-keygen afford key management. The SSH present on Slackware and the BSDs is OpenSSH, developped by members of the OpenBSD project.

ssh obviously requires your connection password every time it is executed. This can be avoided by creating on the client a pair of rsa keys and copying the public key to the server. Not specifying a passphrase is not very secure but will afford avoiding having to enter it every time :

# ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa): <cr>
Enter passphrase (empty for no passphrase): <cr>
Enter same passphrase again: cr>
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:ATSDdER5/l8OJvr+jpINIReJtd81zntVbTjuJW5aobE root@client
The key's randomart image is:
+---[RSA 2048]----+
|   ..=O+..       |
|    ..o++.     ..|
|       oo.    = +|
|      . +o . = +.|
|       oSo. o * o|
|        . o o*.=.|
|         = +E+* .|
|        + ...+.. |
|         ++o+    |
+----[SHA256]-----+
# scp root@client:.ssh/id_rsa.pub root@server:.ssh/id_rsa.pub
password: secret<cr>
id_rsa.pub                                          100% 394      1.8MB/s   00:00
# ssh server
password: secret<cr>
# cd .ssh
# cat >> authorized_keys < id_rsa.pub
# chmod 600 authorized_keys
# rm id_rsa.pub

Useful linux commands

Command Effect
cd change directory.
chmod -R ppp ddd recursively change permissions on file or directory.
chown -R uuu:ggg ddd recursively change user:group ownership on file or directory.
chgrp -R ggg ddd recursively change group ownership on file or directory.
command xxx | grep yyy search for string yyy in output of command xxx.
ethtool -s eth0 wol g puts interface eth0 in wake-on-lan status.
find xxx -name yyy -print find file yyy in in subdirectories of xxx.
ifconfig -a kill print the network interfaces configuration.
iptables -L print the firewall rules.
killall xxx kill program named xxx.
ldconfig reload libraries taking into account new libraries just built.
ln -s existing new create a symbolic link new to an existing directory or file.
ls -al list the working directory, including files beginning with a dot.
man xxx display the xxx command manual page.
more xxx display file xxx with the possibility of moving up and down. less and most are similar commands.
mount -t ttt /dev/xxx /mnt/ddd mount device xxx as type ttt under directory ddd.
(u)mount /mnt/ddd (u)mount device ddd as specified in /etc/fstab.
nmap host check filtering status of ports on host. -sU for UDP.
ps -ef list the running processes.
pwd print working directory.
rm -r remove file or directory recursively.
route display the network routing table.
screen -S<name> screen offers a frame to run a shell, detach from it (<ctrl>-a d) and later reattach to it.
ssh host connect remotely to site host.
su -l uuuu execute shell as another user. if -l is used an environment similar to what the other user would have had with a direct login is provided.
telinit n go to the runlevel n (1=single-user, 3=multi-user, 4=graphical, 6=reboot).
umask edit /etc/profile to change the default umask value of 022 and set it to 027 (files not readable by other users), a good setting except when installing as root server software to be ran as a standard user account (permission issues).
vi run the vi text editor. To get rid of the message "skipping N old session files", delete files elvis*.ses in /var/tmp.


Maintaining Slackware Main Page Configuration files