diff --git a/debian/docker-compose.yml b/debian/docker-compose.yml index 9a2a297..b7a289c 100644 --- a/debian/docker-compose.yml +++ b/debian/docker-compose.yml @@ -3,12 +3,10 @@ networks: working: driver: bridge services: - postgres: - # valor postgresql_version está definido na env + postgres: build: - context: postgres-${postgresql_version} - # nome do container com o versão postgresql_version é definido pela env - container_name: v1.7.12-postgres${postgresql_version} + context: postgres-11 + container_name: v1.8-postgres11 restart: always environment: - POSTGRES_USER=contacte @@ -23,36 +21,39 @@ services: - ${pasta_do_projeto}/projeto/base:/base # copiar a pasta /var/lib/pgsql/data - ${pasta_do_postgresql11}:/var/lib/postgresql/data - aplicativo: - build: - context: pabx - args: - # usar para compilar dockerfile - # DB_HOST DB_PORT DB_BASE - necessário para colocar no crontab - # environment compose é para depois do dockerfile - - DB_HOST=postgres - - DB_PORT=5432 - - DB_BASE=pbx - restart: always - container_name: v1.7.12-pabx-debian - working_dir: /var/www/html/ - ports: - - 8080:80 - - 5038:5038 - - "5060:5060/udp" - - "10000-10030:10000-10030/udp" - privileged: true - depends_on: - - postgres - networks: - - working - links: - - postgres - volumes: - - ${pasta_do_projeto}:/var/www/html/aplicativo - - ${pasta_do_projeto}/include:/var/www/html/include - - ${pasta_do_projeto}/asterisk/var_lib_asterisk/:/var/lib/asterisk/ - - ${pasta_do_projeto}/asterisk/hdaux_utilitarios_scripts/:/hdaux/utilitarios/scripts + aplicativo: + build: + context: pabx + args: + # usar para compilar dockerfile + # DB_HOST DB_PORT DB_BASE - necessário para colocar no crontab + # environment compose é para depois do dockerfile + - DB_HOST=postgres + - DB_PORT=5432 + - DB_BASE=pbx + - IP_HOST=${IP_HOST} + restart: always + environment: + - IP_HOST=${IP_HOST} + container_name: v1.8-pabx-debian + working_dir: /var/www/html/ + ports: + - 8080:80 + - 5038:5038 + - "5060:5060/udp" + - "10000-10030:10000-10030/udp" + privileged: true + depends_on: + - postgres + networks: + - working + links: + - postgres + volumes: + - ${pasta_do_projeto}:/var/www/html/aplicativo + - ${pasta_do_projeto}/include:/var/www/html/include + - ${pasta_do_projeto}/asterisk/var_lib_asterisk/:/var/lib/asterisk/ + - ${pasta_do_projeto}/asterisk/hdaux_utilitarios_scripts/:/hdaux/utilitarios/scripts volumes: storage: db: diff --git a/debian/pabx/Dockerfile b/debian/pabx/Dockerfile index c9df513..8320716 100755 --- a/debian/pabx/Dockerfile +++ b/debian/pabx/Dockerfile @@ -8,32 +8,44 @@ FROM debian:stable-slim ARG DB_HOST ARG DB_PORT ARG DB_BASE +ARG IP_HOST ENV ASTERISK_VERSION 13.18-cert3 ENV ASTERISK_ADDONS_VERSION 13.18-cert3 -ENV VERSION_SIMPLESIP v1.7.12 +ENV ASTERISK_USER pbx +ENV ASTERISK_GID pbx +ENV VERSION_SIMPLESIP v1.8 ENV APACHE_RUN_USER pbx ENV APACHE_RUN_GROUP pbx ENV DB_HOST $DB_HOST ENV DB_PORT $DB_PORT ENV DB_BASE $DB_BASE +ENV IP_HOST $IP_HOST # Instalação do asterisk e do PHP 8.2 COPY build-asterisk_php.sh / RUN chmod 755 /build-asterisk_php.sh RUN /build-asterisk_php.sh +COPY etc_asterisk/* /etc/asterisk + RUN printenv | sed 's/^\(.*\)$/export \1/g' > /env_to_crontab.sh COPY crontab.sh / RUN sh /crontab.sh +COPY /config_network / +RUN chmod 755 /config_network +RUN bash /config_network + EXPOSE 80/tcp 5038/tcp 5060/udp 5060/tcp 5160/udp 5160/tcp 10000-10030/udp -VOLUME /var/lib/asterisk/sounds /var/lib/asterisk/keys /var/lib/asterisk/phoneprov /var/spool/asterisk /var/log/asterisk COPY docker-entrypoint.sh / COPY supervisord.conf /etc/supervisor/supervisord.conf -COPY etc_asterisk/* /etc/asterisk + +RUN sed -i "s/rtpend=.*/rtpend=10030/g" /etc/asterisk/rtp.conf +RUN sed -i "s/hostname=.*/hostname=postgres/g" /etc/asterisk/cdr_pgsql.conf +RUN sed -i "s/;nocolor = .*/nocolor = yes/g" /etc/asterisk/asterisk.conf COPY cnvrtd /etc/init.d/ COPY rtabd /etc/init.d/ diff --git a/debian/pabx/build-asterisk_php.sh b/debian/pabx/build-asterisk_php.sh index c0d07bc..be4f145 100644 --- a/debian/pabx/build-asterisk_php.sh +++ b/debian/pabx/build-asterisk_php.sh @@ -9,17 +9,16 @@ fi set -ex useradd --system pbx -useradd --system asterisk apt-get -y update -apt install lsb-release apt-transport-https ca-certificates software-properties-common -y +apt-get install lsb-release apt-transport-https ca-certificates software-properties-common -y apt-get install wget wget -O /etc/apt/trusted.gpg.d/php.gpg https://packages.sury.org/php/apt.gpg sh -c 'echo "deb https://packages.sury.org/php/ $(lsb_release -sc) main" > /etc/apt/sources.list.d/php.list' -apt update +apt-get -y update apt-get install -y \ @@ -35,6 +34,7 @@ apt-get install -y \ git \ vim \ apache2 \ + libjansson-dev \ ffmpeg \ build-essential \ libedit-dev \ @@ -101,24 +101,6 @@ apt-get install -y \ php8.2-pgsql - -### INSTALL JANSSON ### -VERSION_JANSSON=jansson-2.11 -wget https://digip.org/jansson/releases/${VERSION_JANSSON}.tar.gz - -tar -zxf ${VERSION_JANSSON}.tar.gz -cd ${VERSION_JANSSON} - -./configure -make -make check -make install - -echo "/usr/local/lib" > /etc/ld.so.conf.d/local.conf -ldconfig - -cd .. - ### INSTALL CENTRAL SIMPLES IP ### sed -i 's/DocumentRoot \/var\/www\/html/DocumentRoot \/var\/www\/html\/aplicativo/g' /etc/apache2/sites-enabled/000-default.conf @@ -157,12 +139,8 @@ make install make samples make dist-clean -# set runuser and rungroup -sed -i -E 's/^;(run)(user|group)/\1\2/' /etc/asterisk/asterisk.conf -sed -i -e 's/# MAXFILES=/MAXFILES=/' /usr/sbin/safe_asterisk -chown -R asterisk:asterisk /etc/asterisk \ - /var/*/asterisk \ +chown -R pbx:pbx /var/*/asterisk \ /usr/*/asterisk \ /usr/lib64/asterisk chmod -R 750 /var/spool/asterisk @@ -171,8 +149,15 @@ cd / rm -rf /usr/src/asterisk \ /usr/src/codecs -apt-get clean -apt-get autoremove +sed -i 's/;nocolor = yes/nocolor = yes/g' /etc/asterisk/asterisk.conf + +echo "/usr/lib64/" > /etc/ld.so.conf.d/local.conf +ldconfig + +apt-get clean +apt-get autoremove -y +apt-get install -y iproute2 + ### CONFIGURANDO O PHP ### @@ -207,11 +192,5 @@ sed -i 's/^export APACHE_RUN_USER=.*/export APACHE_RUN_USER=pbx/g' /etc/apache2 sed -i 's/^export APACHE_RUN_GROUP=.*/export APACHE_RUN_GROUP=pbx/g' /etc/apache2/envvars cd /var/www/html/ -mkdir -p /hdaux/utilitarios/scripts - -### CONFIGURACOES ASTERISK ### -sed -i "s/rtpend=.*/rtpend=10030/g" /etc/asterisk/rtp.conf -sed -i "s/hostname=.*/hostname=postgres/g" /etc/asterisk/cdr_pgsql.conf - exec rm -f /build-asterisk.sh diff --git a/debian/pabx/config_network b/debian/pabx/config_network new file mode 100755 index 0000000..c51887f --- /dev/null +++ b/debian/pabx/config_network @@ -0,0 +1,26 @@ +#!/bin/bash + +echo "---- Configurar PABX SIMPLES IP ----" + +if [[ -z $IP_HOST ]];then + echo "Nao definido variavel de ambiente" + exit; +fi + +NET_CONTAINER=$(ip route|awk 'NR==2 {print $1}'|awk -F / '{print $1"\/"$2}') +if [[ -z $NET_CONTAINER ]];then + echo "Nao definido variavel de ambiente" + exit; +fi + +sed -i "s/;\?externaddr=.*/externaddr=${IP_HOST}/g" /etc/asterisk/sip_general.conf +sed -i "s/;\?localnet=.*/localnet=${NET_CONTAINER}/g" /etc/asterisk/sip_general.conf +sed -i "s/;\?media_address=.*/media_address=${IP_HOST}/g" /etc/asterisk/sip_general.conf + +pid_asterisk=$(ps -aux|grep -E "\/usr\/sbin\/asterisk"|awk '{print $2}') +if [[ -z $pid_asterisk ]];then + exit; +fi +kill -9 $pid_asterisk + + diff --git a/debian/pabx/etc_asterisk/sip_general.conf b/debian/pabx/etc_asterisk/sip_general.conf index 59d488c..b3f83cd 100644 --- a/debian/pabx/etc_asterisk/sip_general.conf +++ b/debian/pabx/etc_asterisk/sip_general.conf @@ -9,3 +9,10 @@ minexpiry=60 relaxdtmf=yes alwaysauthreject=yes sipdebug=no + +; Inserido para funcionar no docker +icesupport=no +localnet= +externaddr= +media_address= + diff --git a/debian/pabx/supervisord.conf b/debian/pabx/supervisord.conf index e040b69..6359084 100755 --- a/debian/pabx/supervisord.conf +++ b/debian/pabx/supervisord.conf @@ -8,7 +8,7 @@ command=chown pbx:pbx -R /etc/asterisk/ /var/lib/asterisk/ /var/www/html && /hda command=/usr/sbin/apachectl -D BACKGROUND [program:asterisk] -command=/usr/sbin/asterisk -vvvdddf -T -W -U asterisk -p +command=/usr/sbin/asterisk -vvvdddf -T -W -U pbx -p [program:cron] command=/usr/sbin/cron diff --git a/debian/postgres-13/Dockerfile b/debian/postgres-13/Dockerfile deleted file mode 100644 index 61dccf1..0000000 --- a/debian/postgres-13/Dockerfile +++ /dev/null @@ -1,23 +0,0 @@ -#postgres:11.5 -FROM postgres@sha256:7ffb249ddc0510a5248a019a71710ee222c6204c7c0ccf07f19f2d6cf638f18a - -ENV LC_ALL=en_US.ISO-8859-1 -ENV LC_MESSAGES=en_US.ISO-8859-1 -ENV LC_MONETARY=en_US.ISO-8859-1 -ENV LC_NUMERIC=en_US.ISO-8859-1 -ENV LC_TIME=en_US.ISO-8859-1 - -RUN echo "en_US ISO-8859-1" > /etc/locale.gen -RUN locale-gen "en_US ISO-8859-1" -RUN export LC_ALL="en_US ISO-8859-1" -RUN update-locale - -COPY include_sql.sh /docker-entrypoint-initdb.d/ -RUN chmod 755 /docker-entrypoint-initdb.d/include_sql.sh - -EXPOSE 5432 - -COPY permission_pg_hba.sh / -RUN chmod 755 /permission_pg_hba.sh -RUN /permission_pg_hba.sh - diff --git a/debian/postgres-13/include_sql.sh b/debian/postgres-13/include_sql.sh deleted file mode 100644 index 199c25a..0000000 --- a/debian/postgres-13/include_sql.sh +++ /dev/null @@ -1,14 +0,0 @@ - -psql -U contacte -d pbx -f /base/schema/createSchema_1.sql - -psql -U contacte -d pbx -f /base/schema/putData.sql - -psql -U contacte -d pbx -f /base/schema/whatsapp.sql - -psql -U contacte -d pbx -f /base/sql/versao-1.7.11.3.sql - -psql -U contacte -d pbx -f /base/sql/versao-1.7.11.4.sql - -psql -U contacte -d pbx -f /base/sql/versao-1.7.11.5.sql - -psql -U contacte -d pbx -f /base/sql/versao-1.7.12.sql \ No newline at end of file diff --git a/debian/postgres-13/permission_pg_hba.sh b/debian/postgres-13/permission_pg_hba.sh deleted file mode 100644 index e42031b..0000000 --- a/debian/postgres-13/permission_pg_hba.sh +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/sh - -echo "host all all 192.168.115.0/24 password" >> /var/lib/postgresql/data/pg_hba.conf -echo "host all all 10.252.252.0/24 password" >> /var/lib/postgresql/data/pg_hba.conf -echo "host all all 177.67.197.146/32 password" >> /var/lib/postgresql/data/pg_hba.conf