1
0
Fork 0
mirror of https://github.com/iiab/iiab.git synced 2025-02-12 19:22:24 +00:00

Merge pull request #1405 from m-anish/pbx

Asterisk (with chan_dongle) and FreePBX
This commit is contained in:
A Holt 2019-02-09 15:49:19 -05:00 committed by GitHub
commit 07081cd151
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
18 changed files with 580 additions and 1 deletions

View file

@ -57,6 +57,12 @@
# when: owncloud_install
# tags: owncloud
- name: PBX
include_role:
name: pbx
when: pbx_install
tags: pbx
- name: WORDPRESS
include_role:
name: wordpress

View file

@ -10,7 +10,7 @@
lineinfile:
path: /etc/hosts
regexp: '^172\.18\.96\.1'
line: '172.18.96.1 {{ iiab_hostname }}.{{ iiab_domain }} {{ iiab_hostname }} box box.lan'
line: '172.18.96.1 {{ iiab_hostname }}.{{ iiab_domain }} {{ iiab_hostname }} box box.lan pbx pbx.lan'
state: present
when: iiab_lan_iface != "none" and not installing

32
roles/pbx/README.rst Normal file
View file

@ -0,0 +1,32 @@
==========
PBX README
==========
This 'pbx' playbook adds `Asterisk <https://asterisk.org/>`_ and `FreePBX <https://freepbx.org/>`_ to Internet-in-a-Box (IIAB) for VoIP and SIP functionality.
Asterisk is a software implementation of a private branch exchange (PBX). In conjunction with suitable telephony hardware interfaces and network applications, Asterisk is used to establish and control telephone calls between telecommunication endpoints, such as customary telephone sets, destinations on the public switched telephone network (PSTN), and devices or services on Voice over Internet Protocol (VoIP) networks. Its name comes from the asterisk (*) symbol for a signal used in dual-tone multi-frequency (DTMF) dialing.
FreePBX is a web-based open source GUI (graphical user interface) that controls and manages Asterisk (PBX), an open source communication server.
Using It
--------
Prior to installing IIAB, make sure your `/etc/iiab/local_vars.yml <http://wiki.laptop.org/go/IIAB/FAQ#What_is_local_vars.yml_and_how_do_I_customize_it.3F>`_ contains::
pbx_install: True
pbx_enabled: True
Optionally, you may want to enable `chan_dongle <https://github.com/wdoekes/asterisk-chan-dongle>`_, which is a channel driver for Huawei UMTS cards allowing regular voice calls over GSM. You will need to configure a dongle post-install, for it to be recognized properly::
asterisk_chan_dongle: True
After installing PBX as part of IIAB, please visit http://pbx.lan/freepbx and proceed with initial configuration — which asks you to create a login/password.
You can monitor the PBX service with command::
systemctl status freepbx
Attribution
-----------
This 'pbx' playbook was heavily inspired by Yannik Sembritzki's `Asterisk <https://github.com/Yannik/ansible-role-asterisk>`_ and `FreePBX <https://github.com/Yannik/ansible-role-freepbx>`_ Ansible work.

View file

@ -0,0 +1,27 @@
# pbx_install: False
# pbx_enabled: False
# asterisk_chan_dongle: False
# All above are set in: github.com/iiab/iiab/blob/master/vars/default_vars.yml
# If nec, change them by editing /etc/iiab/local_vars.yml prior to installing!
pbx_installed: False
asterisk_url: http://downloads.asterisk.org/pub/telephony/asterisk/
asterisk_src_file: asterisk-16-current.tar.gz
asterisk_src_dir: /opt/iiab/asterisk
freepbx_url: http://mirror.freepbx.org/modules/packages/freepbx/
freepbx_src_file: freepbx-15.0-latest.tgz
freepbx_src_dir: /opt/iiab/freepbx
freepbx_install_dir: /var/www/html/freepbx
asterisk_db_host: localhost
asterisk_db_user: asterisk
asterisk_db_dbname: asterisk
asterisk_db_password: asterisk
asterisk_db_cdrdbname: asteriskcdrdb
chan_dongle_url: https://github.com/wdoekes/asterisk-chan-dongle/archive/
chan_dongle_src_file: master.zip
chan_dongle_src_dir: /opt/iiab/chan_dongle

3
roles/pbx/meta/main.yml Normal file
View file

@ -0,0 +1,3 @@
dependencies:
- { role: nodejs, tags: ['nodejs'], when: pbx_install and (nodejs_version == "10.x")}

View file

@ -0,0 +1,151 @@
- name: Asterisk - Install dependencies
include: asterisk_dependencies.yml
- name: Asterisk - Download software to /opt/iiab/downloads
get_url:
url: "{{ asterisk_url }}/{{ asterisk_src_file }}"
dest: "{{ downloads_dir }}/{{ asterisk_src_file }}"
timeout: "{{ download_timeout }}"
when: internet_available
- name: Asterisk - Check for /opt/iiab/downloads/{{ asterisk_src_file }}
stat:
path: "{{ downloads_dir }}/{{ asterisk_src_file }}"
register: asterisk_src
- name: Asterisk - FAIL (force Ansible to exit) IF /opt/iiab/downloads/{{ asterisk_src_file }} doesn't exist
fail:
msg: "{ downloads_dir }}/{{ asterisk_src_file }} is REQUIRED in order to install."
when: not asterisk_src.stat.exists
- name: Asterisk - Create install source directory
file:
path: "{{ asterisk_src_dir }}"
state: directory
- name: Asterisk - Extract source
unarchive:
src: "{{ downloads_dir }}/{{ asterisk_src_file }}"
dest: "{{ asterisk_src_dir }}"
owner: root
group: root
extra_opts: [--strip-components=1]
creates: "{{ asterisk_src_dir }}/Makefile"
- name: Asterisk - Download mp3 decoder library into source tree
command: "./contrib/scripts/get_mp3_source.sh"
args:
chdir: "{{ asterisk_src_dir }}"
creates: "addons/mp3/mpg123.h"
- name: Asterisk - Install aptitude (otherwise install_prereq fails?)
package:
name: aptitude
state: latest
- name: Asterisk - Ensure all dependencies are resolved - CAN TAKE 2 MIN OR LONGER!
shell: export DEBIAN_FRONTEND=noninteractive && ./contrib/scripts/install_prereq install
args:
chdir: "{{ asterisk_src_dir }}"
- name: Asterisk - Run the configure script
command: "./configure --with-jansson-bundled"
args:
chdir: "{{ asterisk_src_dir }}"
- name: Asterisk - Run make menuselect.makeopts
command: "make menuselect.makeopts"
args:
chdir: "{{ asterisk_src_dir }}"
creates: "menuselect.makeopts"
- name: Asterisk - Do a bit of menuselect configuration
command: >
menuselect/menuselect --enable app_macro --enable format_mp3
--enable CORE-SOUNDS-EN-WAV --enable CORE-SOUNDS-EN-G722
--enable EXTRA-SOUNDS-EN-WAV --enable EXTRA-SOUNDS-EN-G722 --enable EXTRA-SOUNDS-EN-GSM
--disable-category MENUSELECT_MOH
args:
chdir: "{{ asterisk_src_dir }}"
- name: Asterisk - Run 'make' - CAN TAKE 10 MIN OR LONGER!
command: make
args:
chdir: "{{ asterisk_src_dir }}"
creates: "defaults.h"
- name: Asterisk - Run 'make install' - CAN TAKE 3 MIN OR LONGER!
command: make install
args:
chdir: "{{ asterisk_src_dir }}"
creates: "/usr/sbin/asterisk"
- name: Asterisk - Run 'make config'
command: make config
args:
chdir: "{{ asterisk_src_dir }}"
- name: Asterisk - Run 'make samples'
command: make samples
args:
chdir: "{{ asterisk_src_dir }}"
- name: Asterisk - Run 'ldconfig'
shell: ldconfig
args:
chdir: "{{ asterisk_src_dir }}"
- name: Asterisk - Ensure group 'asterisk' exists
group:
name: asterisk
state: present
- name: Asterisk - Ensure user 'asterisk' exists, and belongs to the required groups
user:
name: asterisk
group: asterisk
groups: audio,dialout
home: "/var/lib/asterisk"
system: yes
append: yes
- name: 'Asterisk - Set ownership of 5 directories: /etc/asterisk, /var/lib/asterisk, /var/log/asterisk, /var/spool/asterisk, /usr/lib/asterisk'
file:
dest: "{{ item }}"
owner: asterisk
group: asterisk
recurse: yes
with_items:
- /etc/asterisk
- /var/lib/asterisk
- /var/log/asterisk
- /var/spool/asterisk
- /usr/lib/asterisk
- name: Asterisk - Set default user to 'asterisk' in /etc/default/asterisk
lineinfile:
path: /etc/default/asterisk
regexp: 'AST_USER='
line: 'AST_USER="asterisk"'
- name: Asterisk - Set default group to 'asterisk' in /etc/default/asterisk
lineinfile:
path: /etc/default/asterisk
regexp: 'AST_GROUP='
line: 'AST_GROUP="asterisk"'
- name: Asterisk - Set default user to 'asterisk' in /etc/asterisk/asterisk.conf
lineinfile:
path: /etc/asterisk/asterisk.conf
regexp: 'runuser ='
line: 'runuser = asterisk'
- name: Asterisk - Set default group to 'asterisk' in /etc/asterisk/asterisk.conf
lineinfile:
path: /etc/asterisk/asterisk.conf
regexp: 'rungroup ='
line: 'rungroup = asterisk'
- name: Asterisk - Install chan_dongle
include: chan_dongle.yml
when: asterisk_chan_dongle

View file

@ -0,0 +1,16 @@
- name: Asterisk - Install dependencies
package:
name:
- git
- curl
- wget
- libnewt-dev
- libssl-dev
- libncurses5-dev
- subversion
- libsqlite3-dev
- build-essential
- libjansson-dev
- libxml2-dev
- uuid-dev
state: latest

View file

@ -0,0 +1,68 @@
- name: chan_dongle - Download software to /opt/iiab/downloads
get_url:
url: "{{ chan_dongle_url }}/{{ chan_dongle_src_file }}"
dest: "{{ downloads_dir }}/{{ chan_dongle_src_file }}"
timeout: "{{ download_timeout }}"
when: internet_available
- name: chan_dongle - Check for /opt/iiab/downloads/{{ chan_dongle_src_file }}
stat:
path: "{{ downloads_dir }}/{{ chan_dongle_src_file }}"
register: chan_dongle_src
- name: chan_dongle - FAIL (force Ansible to exit) IF /opt/iiab/downloads/{{ chan_dongle_src_file }} doesn't exist
fail:
msg: "{ downloads_dir }}/{{ chan_dongle_src_file }} is REQUIRED in order to install."
when: not chan_dongle_src.stat.exists
- name: chan_dongle - Create install source directory
file:
path: "{{ chan_dongle_src_dir }}"
state: directory
- name: chan_dongle - Extract source
unarchive:
src: "{{ downloads_dir }}/{{ chan_dongle_src_file }}"
dest: "{{ downloads_dir }}"
owner: root
group: root
- name: chan_dongle - move to {{ chan_dongle_src_dir }}
command: rsync -av {{ downloads_dir }}/asterisk-chan-dongle-master/ {{ chan_dongle_src_dir }}
args:
chdir: "{{ downloads_dir }}"
- name: chan_dongle - Run the bootstrap script
command: "./bootstrap"
args:
chdir: "{{ chan_dongle_src_dir }}"
creates: "{{ chan_dongle_src_dir }}/configure"
- name: chan_dongle - Find out asterisk version
shell: asterisk -V |cut -d " " -f 2
register: asterisk_ver
- name: chan_dongle - Run the configure script
command: "./configure --with-astversion={{asterisk_ver.stdout}}"
args:
chdir: "{{ chan_dongle_src_dir }}"
creates: "{{ chan_dongle_src_dir }}/Makefile"
- name: chan_dongle - Run 'make'
command: make
args:
chdir: "{{ chan_dongle_src_dir }}"
creates: "{{ chan_dongle_src_dir }}/chan_dongle.o"
- name: chan_dongle - Run 'make install'
command: make install
args:
chdir: "{{ chan_dongle_src_dir }}"
creates: "/usr/lib/asterisk/modules/chan_dongle.so"
- name: chan_dongle - Copy dongle.conf over
command: cp {{ chan_dongle_src_dir }}/etc/dongle.conf /etc/asterisk/
args:
chdir: "{{ chan_dongle_src_dir }}"
creates: "/etc/asterisk/dongle.conf"

152
roles/pbx/tasks/freepbx.yml Normal file
View file

@ -0,0 +1,152 @@
- name: FreePBX - Install dependencies
include: freepbx_dependencies.yml
- name: FreePBX - Download software to /opt/iiab/downloads
get_url:
url: "{{ freepbx_url }}/{{ freepbx_src_file }}"
dest: "{{ downloads_dir }}/{{ freepbx_src_file }}"
timeout: "{{ download_timeout }}"
when: internet_available
- name: FreePBX - Check for {{ downloads_dir }}/{{ freepbx_src_file }}
stat:
path: "{{ downloads_dir }}/{{ freepbx_src_file }}"
register: freepbx_src
- name: FreePBX - FAIL (force Ansible to exit) IF {{ downloads_dir }}/{{ freepbx_src_file }} doesn't exist
fail:
msg: "{ downloads_dir }}/{{ freepbx_src_file }} is REQUIRED in order to install."
when: not freepbx_src.stat.exists
- name: FreePBX - Create install source directory
file:
path: "{{ freepbx_src_dir }}"
state: directory
- name: FreePBX - Extract source
unarchive:
src: "{{ downloads_dir }}/{{ freepbx_src_file }}"
dest: "{{ freepbx_src_dir }}"
owner: root
group: root
extra_opts: [--strip-components=1]
creates: "{{ freepbx_src_dir }}/install"
- name: FreePBX - Disable & Stop asterisk service
systemd:
daemon_reload: yes
name: asterisk
enabled: no
state: stopped
- name: FreePBX - Add mysql user
mysql_user:
name: "{{ asterisk_db_user }}"
password: "{{ asterisk_db_password }}"
priv: "{{ asterisk_db_dbname }}.*:ALL/{{ asterisk_db_cdrdbname }}.*:ALL"
login_host: "{{ asterisk_db_host }}"
login_user: "root"
login_password: "{{ mysql_root_password }}"
host: "{{ (asterisk_db_host == 'localhost') | ternary('localhost', ansible_default_ipv4.address) }}"
state: present
- name: FreePBX - Add mysql db
mysql_db:
name: "{{ asterisk_db_dbname }}"
encoding: utf8
collation: utf8_general_ci
login_host: "{{ asterisk_db_host }}"
login_user: "root"
login_password: "{{ mysql_root_password }}"
state: present
- name: FreePBX - Add cdr mysql db
mysql_db:
name: "{{ asterisk_db_cdrdbname }}"
encoding: utf8
collation: utf8_general_ci
login_host: "{{ asterisk_db_host }}"
state: present
- name: FreePBX - Don't let freepbx take over the php sessions dir
blockinfile:
content: |
[blacklist]
directory = /var/lib/php/sessions
marker: "; {mark} ANSIBLE MANAGED BLOCK"
dest: /etc/asterisk/freepbx_chown.conf
owner: asterisk
group: asterisk
create: yes
- name: FreePBX - Create php sessions directory
file:
path: "/var/lib/php/asterisk_sessions/"
state: directory
- name: FreePBX - Set ownership for php sessions directory
file:
dest: "/var/lib/php/asterisk_sessions/"
owner: asterisk
group: asterisk
recurse: yes
- name: FreePBX - Install (just run once) - CAN TAKE 2 MIN OR LONGER!
command: "{{ item }}"
args:
chdir: "{{ freepbx_src_dir }}"
creates: "{{ freepbx_install_dir }}"
with_items:
- ./start_asterisk start
- ./install -n --webroot {{ freepbx_install_dir }} --dbuser {{ asterisk_db_user }} --dbpass {{ asterisk_db_password }} --dbname {{ asterisk_db_dbname }} --cdrdbname {{ asterisk_db_cdrdbname }}
- name: FreePBX - Create /etc/odbc.ini
template:
src: odbc.ini.j2
dest: /etc/odbc.ini
owner: root
group: root
mode: 0644
- name: FreePBX - Copy freepbx.conf
template:
src: freepbx.conf.j2
dest: /etc/apache2/sites-available/freepbx.conf
owner: www-data
group: www-data
mode: 0644
- name: FreePBX - Link freepbx.conf apache file to sites-enabled
file:
src: /etc/apache2/sites-available/freepbx.conf
dest: /etc/apache2/sites-enabled/freepbx.conf
state: link
when: pbx_enabled
- name: FreePBX - Unlink freepbx.conf apachefile from sites-enabled
file:
path: /etc/apache2/sites-enabled/freepbx.conf
state: absent
when: (not pbx_enabled)
- name: FreePBX - Copy systemd unit file
template:
src: freepbx.service.j2
dest: /etc/systemd/system/freepbx.service
mode: 755
- name: FreePBX - Enable and Start freepbx service
systemd:
daemon_reload: yes
name: freepbx
enabled: yes
state: started
when: pbx_enabled
- name: FreePBX - Disable & Stop freepbx service
systemd:
daemon_reload: yes
name: freepbx
enabled: no
state: stopped
when: (not pbx_enabled)

View file

@ -0,0 +1,30 @@
- name: FreePBX - Install dependencies
package:
name:
- wget
- git
- unixodbc # for Asterisk CDR (Call Detail Records)
- sudo # required by FreePBX install script
- net-tools # required by FWConsole (command-line utility, that controls FreePBX)
- cron # required by FreePBX UCP package (User Control Panel)
- sox # required for CDR web-playback
- php
- php-pear
- php-cgi
- php-common
- php-curl
- php-mbstring
- php-gd
- php-mysql
- php-gettext
- php-bcmath
- php-zip
- php-xml
- php-imap
- php-json
- php-snmp
- php-fpm
- libapache2-mod-php
- python-mysqldb # https://github.com/Yannik/ansible-role-freepbx/blob/master/tasks/freepbx.yml#L33
- libapache2-mpm-itk # To serve FreePBX through a VirtualHost as asterisk user
state: latest

27
roles/pbx/tasks/main.yml Normal file
View file

@ -0,0 +1,27 @@
- name: Fail if nodejs_version is incorrect
fail:
msg: >-
PBX: Refusing to install as nodejs_version is not 10.x. Please fix that
(looking into /etc/iiab/local_vars.yml and
/opt/iiab/iiab/vars/default_vars.yml) and then rerun.
when: pbx_install and (nodejs_version != "10.x")
#- name: TODO: Check if asterisk and freepbx are already installed
- debug: # Crazy spacing below is tuned for 80-column screens
msg: >-
####################################################################WARNING:
ONLY UBUNTU 18.04 AND DEBIAN 9 ARE SUPPORTED AS OF FEBRUARY 2019. Please
assist Internet-in-a-Box communities worldwide if you can make
Asterisk and FreePBX work on other OS's / distros, Thank
You! http://FAQ.IIAB.IO ###############################################################################
- name: Install Asterisk (debuntu)
include_tasks: asterisk.yml
when: internet_available and pbx_install and (not pbx_installed) and is_debuntu
#when: internet_available and pbx_install and (not pbx_installed) and ((is_debian and ansible_distribution_major_version == "9") or is_ubuntu_18)
- name: Install FreePBX (debuntu)
include_tasks: freepbx.yml
when: internet_available and pbx_install and (not pbx_installed) and is_debuntu
#when: internet_available and pbx_install and (not pbx_installed) and ((is_debian and ansible_distribution_major_version == "9") or is_ubuntu_18)

View file

@ -0,0 +1,23 @@
<VirtualHost *:80>
ServerName pbx.lan
ServerAdmin admin@box.lan
DocumentRoot /var/www/html/
<Directory {{ freepbx_install_dir }}>
AllowOverride All
Options Indexes FollowSymLinks
Require all granted
</Directory>
<IfModule mpm_itk_module>
AssignUserId asterisk asterisk
</IfModule>
php_value session.save_path /var/lib/php/asterisk_sessions/
ErrorLog ${APACHE_LOG_DIR}/pbx-error.log
CustomLog ${APACHE_LOG_DIR}/pbx-access.log combined
</VirtualHost>

View file

@ -0,0 +1,12 @@
[Unit]
Description=FreePBX VoIP Server
After=mysql.service
[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/usr/sbin/fwconsole start
ExecStop=/usr/sbin/fwconsole stop
[Install]
WantedBy=multi-user.target

View file

@ -0,0 +1,8 @@
[MySQL-asteriskcdrdb]
Description=MySQL connection to 'asteriskcdrdb' database
driver=MySQL
server=localhost
database=asteriskcdrdb
Port=3306
Socket=/var/run/mysqld/mysqld.sock
option=3

View file

@ -296,6 +296,12 @@ nodered_port: 1880
nextcloud_install: False
nextcloud_enabled: False
# A full-featured PBX (for rural telephony, etc) based on Asterisk and FreePBX.
# So far, supported on Ubuntu 18.x and Debian 9 ONLY. Uses Node.js 10.x
pbx_install: False
pbx_enabled: False
asterisk_chan_dongle: False
# If using WordPress intensively, set apache_high_php_limits in 3-BASE-SERVER
wordpress_install: False
wordpress_enabled: False

View file

@ -195,6 +195,12 @@ nodered_enabled: True
nextcloud_install: True
nextcloud_enabled: True
# A full-featured PBX (for rural telephony, etc) based on Asterisk and FreePBX.
# So far, supported on Ubuntu 18.x and Debian 9 ONLY. Uses Node.js 10.x
pbx_install: False
pbx_enabled: False
asterisk_chan_dongle: False
# If using WordPress intensively, set apache_high_php_limits in 3-BASE-SERVER
wordpress_install: True
wordpress_enabled: True

View file

@ -195,6 +195,12 @@ nodered_enabled: False
nextcloud_install: True
nextcloud_enabled: True
# A full-featured PBX (for rural telephony, etc) based on Asterisk and FreePBX.
# So far, supported on Ubuntu 18.x and Debian 9 ONLY. Uses Node.js 10.x
pbx_install: False
pbx_enabled: False
asterisk_chan_dongle: False
# If using WordPress intensively, set apache_high_php_limits in 3-BASE-SERVER
wordpress_install: True
wordpress_enabled: True

View file

@ -195,6 +195,12 @@ nodered_enabled: False
nextcloud_install: False
nextcloud_enabled: False
# A full-featured PBX (for rural telephony, etc) based on Asterisk and FreePBX.
# So far, supported on Ubuntu 18.x and Debian 9 ONLY. Uses Node.js 10.x
pbx_install: False
pbx_enabled: False
asterisk_chan_dongle: False
# If using WordPress intensively, set apache_high_php_limits in 3-BASE-SERVER
wordpress_install: False
wordpress_enabled: False