diff --git a/roles/pbx/defaults/main.yml b/roles/pbx/defaults/main.yml index 9d2c46051..5aab6f0f6 100644 --- a/roles/pbx/defaults/main.yml +++ b/roles/pbx/defaults/main.yml @@ -14,7 +14,7 @@ # 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 +#pbx_installed: False asterisk_url: http://downloads.asterisk.org/pub/telephony/asterisk/ asterisk_src_file: asterisk-16-current.tar.gz diff --git a/roles/pbx/tasks/freepbx.yml b/roles/pbx/tasks/freepbx.yml index 4ba0c6b9e..bab813434 100644 --- a/roles/pbx/tasks/freepbx.yml +++ b/roles/pbx/tasks/freepbx.yml @@ -37,6 +37,11 @@ src: "roles/pbx/templates/71-freepbx-framework.patch" dest: "{{ freepbx_src_dir }}/amp_conf/htdocs/admin/libraries/BMO/Framework.class.php" +- name: FreePBX - Patch FreePBX source - wants [] not {} + patch: + src: "roles/pbx/templates/pbx.patch" + dest: "{{ freepbx_src_dir }}/amp_conf/htdocs/admin/libraries/Composer/vendor/neitanod/forceutf8/src/ForceUTF8/Encoding.php" + - name: FreePBX - Disable & Stop asterisk service systemd: daemon_reload: yes @@ -97,13 +102,21 @@ recurse: yes - name: FreePBX - Install (just run once) - CAN TAKE 12 MIN OR LONGER! - command: "{{ item }}" + command: ./start_asterisk start 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 - Install (just run once) - CAN TAKE 12 MIN OR LONGER! + command: ./install -n --webroot {{ freepbx_install_dir }} --dbuser {{ asterisk_db_user }} --dbpass {{ asterisk_db_password }} --dbname {{ asterisk_db_dbname }} --cdrdbname {{ asterisk_db_cdrdbname }} + args: + chdir: "{{ freepbx_src_dir }}" + creates: "{{ freepbx_install_dir }}" + +- name: FreePBX - Patch FreePBX source - disable get_magic_quotes_gpc() + patch: + src: "roles/pbx/templates/pbx2.patch" + dest: "{{ freepbx_install_dir }}/freepbx/admin/libraries/view.functions.php" - name: FreePBX - Create /etc/odbc.ini template: @@ -117,29 +130,16 @@ template: src: freepbx.conf.j2 dest: /etc/apache2/sites-available/freepbx.conf - owner: {{ apache_user }} - group: {{ apache_user }} + owner: "{{ apache_user }}" + group: "{{ apache_user }}" mode: '0644' -- name: FreePBX - Enable http://box:{{ pbx_http_port }} via Apache, if pbx_enabled # http://box:83 - command: a2ensite freepbx.conf - when: apache_installed and pbx_enabled - -- name: FreePBX - Disable http://box:{{ pbx_http_port }} via Apache, if not pbx_enabled # http://box:83 - command: a2dissite freepbx.conf - when: apache_installed and not pbx_enabled - - name: FreePBX - Add {{ pbx_http_port }} as a Listen directive to apache ports.conf lineinfile: path: /etc/apache2/ports.conf line: "Listen {{ pbx_http_port }}" insertafter: Listen 80 -- name: FreePBX - Restart Apache service ({{ apache_service }}) - systemd: - name: "{{ apache_service }}" # httpd or apache2 - state: restarted - - name: FreePBX - Install /etc/systemd/system/freepbx.service systemd unit file from template template: src: freepbx.service.j2 diff --git a/roles/pbx/tasks/freepbx_dependencies.yml b/roles/pbx/tasks/freepbx_dependencies.yml index 37c235fbb..52c7783ed 100644 --- a/roles/pbx/tasks/freepbx_dependencies.yml +++ b/roles/pbx/tasks/freepbx_dependencies.yml @@ -16,7 +16,7 @@ - php-mbstring - php-gd - php-mysql - - php-gettext +# - php-gettext - php-bcmath - php-zip - php-xml diff --git a/roles/pbx/tasks/freepbx_enable.yml b/roles/pbx/tasks/freepbx_enable.yml index 18dc7a713..0473353c9 100644 --- a/roles/pbx/tasks/freepbx_enable.yml +++ b/roles/pbx/tasks/freepbx_enable.yml @@ -13,3 +13,16 @@ enabled: no state: stopped when: not pbx_enabled + +- name: FreePBX - Enable http://box:{{ pbx_http_port }} via Apache, if pbx_enabled # http://box:83 + command: a2ensite freepbx.conf + when: pbx_enabled | bool + +- name: FreePBX - Disable http://box:{{ pbx_http_port }} via Apache, if not pbx_enabled # http://box:83 + command: a2dissite freepbx.conf + when: not pbx_enabled + +- name: FreePBX - Restart Apache service ({{ apache_service }}) + systemd: + name: "{{ apache_service }}" # httpd or apache2 + state: restarted diff --git a/roles/pbx/tasks/install.yml b/roles/pbx/tasks/install.yml index 6eec69a3a..c64068bdd 100644 --- a/roles/pbx/tasks/install.yml +++ b/roles/pbx/tasks/install.yml @@ -15,8 +15,16 @@ - name: FAIL (STOP THE INSTALL) IF 'nodejs_version != "10.x"' fail: msg: "PBX install cannot proceed, as it currently requires Node.js 10.x, whereas nodejs_version is set to {{ nodejs_version }}. Please check the value of nodejs_version in /opt/iiab/iiab/vars/default_vars.yml, /etc/iiab/local_vars.yml, /opt/iiab/iiab/roles/nodejs, etc." - when: nodejs_version != "10.x" + when: nodejs_version != "12.x" +- name: "Set 'apache_install: True' and 'apache_enabled: True'" + set_fact: + apache_install: True + apache_enabled: True + +- name: APACHE - run 'httpd' role + include_role: + name: httpd #- name: TODO: Check if asterisk and freepbx are already installed @@ -40,24 +48,14 @@ - name: Install Asterisk (debuntu) include_tasks: asterisk.yml - when: internet_available and pbx_install and (not pbx_installed) and is_debuntu and (not freepbx_installed.stat.exists) - + when: internet_available and pbx_install and (pbx_installed is undefined) and is_debuntu and (not freepbx_installed.stat.exists) #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 and (not freepbx_installed.stat.exists) + when: internet_available and pbx_install and (pbx_installed is undefined) and is_debuntu and (not freepbx_installed.stat.exists) #when: internet_available and pbx_install and (not pbx_installed) and ((is_debian and ansible_distribution_major_version == "9") or is_ubuntu_18) -- name: Enable FreePBX (debuntu) - include_tasks: freepbx_enable.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: Asterisk - Install chan_dongle - include: chan_dongle.yml - when: asterisk_chan_dongle | bool - # RECORD PBX AS INSTALLED diff --git a/roles/pbx/tasks/main.yml b/roles/pbx/tasks/main.yml index 44bbe2332..edec5ab14 100644 --- a/roles/pbx/tasks/main.yml +++ b/roles/pbx/tasks/main.yml @@ -23,6 +23,13 @@ include_tasks: install.yml when: pbx_installed is undefined +- name: Enable FreePBX (debuntu) + include_tasks: freepbx_enable.yml + when: pbx_installed is defined + +- name: Asterisk - Install chan_dongle + include: chan_dongle.yml + when: asterisk_chan_dongle | bool - name: Add 'pbx' variable values to {{ iiab_ini_file }} ini_file: diff --git a/roles/pbx/templates/pbx.patch b/roles/pbx/templates/pbx.patch new file mode 100644 index 000000000..9ab748378 --- /dev/null +++ b/roles/pbx/templates/pbx.patch @@ -0,0 +1,18 @@ +--- /opt/iiab/freepbx/amp_conf/htdocs/admin/libraries/Composer/vendor/neitanod/forceutf8/src/ForceUTF8/Encoding.php.orig 2020-08-24 08:52:41.291376894 +0000 ++++ /opt/iiab/freepbx/amp_conf/htdocs/admin/libraries/Composer/vendor/neitanod/forceutf8/src/ForceUTF8/Encoding.php 2020-08-24 08:55:36.429818838 +0000 +@@ -193,11 +193,11 @@ + + $buf = ""; + for($i = 0; $i < $max; $i++){ +- $c1 = $text{$i}; ++ $c1 = $text[$i]; + if($c1>="\xc0"){ //Should be converted to UTF8, if it's not UTF8 already +- $c2 = $i+1 >= $max? "\x00" : $text{$i+1}; +- $c3 = $i+2 >= $max? "\x00" : $text{$i+2}; +- $c4 = $i+3 >= $max? "\x00" : $text{$i+3}; ++ $c2 = $i+1 >= $max? "\x00" : $text[$i+1]; ++ $c3 = $i+2 >= $max? "\x00" : $text[$i+2]; ++ $c4 = $i+3 >= $max? "\x00" : $text[$i+3]; + if($c1 >= "\xc0" & $c1 <= "\xdf"){ //looks like 2 bytes UTF8 + if($c2 >= "\x80" && $c2 <= "\xbf"){ //yeah, almost sure it's UTF8 already + $buf .= $c1 . $c2; diff --git a/roles/pbx/templates/pbx2.patch b/roles/pbx/templates/pbx2.patch new file mode 100644 index 000000000..665089970 --- /dev/null +++ b/roles/pbx/templates/pbx2.patch @@ -0,0 +1,19 @@ +--- /var/www/html/freepbx/admin/libraries/view.functions.php.orig 2020-08-24 11:14:51.551433838 +0000 ++++ /var/www/html/freepbx/admin/libraries/view.functions.php 2020-08-24 11:14:30.207107776 +0000 +@@ -12,11 +12,11 @@ + + // send error if magic_quotes_gpc is enabled on this system as much of the code base assumes not + // +- if(get_magic_quotes_gpc()) { +- $nt->add_error('core', 'MQGPC', _("Magic Quotes GPC"), _("You have magic_quotes_gpc enabled in your php.ini, http or .htaccess file which will cause errors in some modules. FreePBX expects this to be off and runs under that assumption")); +- } else { +- $nt->delete('core', 'MQGPC'); +- } ++ //if(get_magic_quotes_gpc()) { ++ // $nt->add_error('core', 'MQGPC', _("Magic Quotes GPC"), _("You have magic_quotes_gpc enabled in your php.ini, http or .htaccess file which will cause errors in some modules. FreePBX expects this to be off and runs under that assumption")); ++ //} else { ++ // $nt->delete('core', 'MQGPC'); ++ //} + } + + // setup locale