From 88e1b863ed3da0aa5614dde985384ccbd3ece7ec Mon Sep 17 00:00:00 2001 From: Miguel Gonzalez Date: Tue, 17 Jan 2023 16:55:23 +0100 Subject: [PATCH 1/8] Fixed and tested on Zammad 5.3.1. Dockerized --- Dockerfile | 31 +++++++++++++++++++++++++++++++ asterisk-zammad-cti-bridge | 2 +- docker-compose.yml | 5 +++++ 3 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 Dockerfile create mode 100644 docker-compose.yml diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..1dc448a --- /dev/null +++ b/Dockerfile @@ -0,0 +1,31 @@ +FROM debian:11-slim + +MAINTAINER magonzalez112 + +ARG USERNAME=bridge-user +ARG USER_UID=1000 +ARG USER_GID=$USER_UID + +WORKDIR /opt +COPY asterisk-zammad-cti-bridge /opt +COPY config.cfg /opt + +# Create the user and install dependencies +RUN groupadd --gid $USER_GID $USERNAME \ + && useradd --uid $USER_UID --gid $USER_GID -m $USERNAME \ + && apt-get update \ + && apt-get install --no-install-recommends -y perl libanyevent-http-perl libconfig-simple-perl libdata-printer-perl \ + liblog-any-perl liblog-any-adapter-dispatch-perl libwww-form-urlencoded-perl libnet-ssleay-perl libcrypt-ssleay-perl make cpanminus \ + && cpanm Asterisk::AMI + #&& apt-get install -y sudo \ + #&& echo $USERNAME ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/$USERNAME \ + #&& chmod 0440 /etc/sudoers.d/$USERNAME + +RUN chown $USER_UID:$USER_GID config.cfg +RUN chown $USER_UID:$USER_GID asterisk-zammad-cti-bridge +RUN chmod u+x asterisk-zammad-cti-bridge +RUN chmod 600 config.cfg + +USER $USERNAME + +ENTRYPOINT ["/opt/asterisk-zammad-cti-bridge"] diff --git a/asterisk-zammad-cti-bridge b/asterisk-zammad-cti-bridge index 89b1483..85b27fc 100755 --- a/asterisk-zammad-cti-bridge +++ b/asterisk-zammad-cti-bridge @@ -188,6 +188,7 @@ sub cb_default to => $event->{Queue}, direction => "in", callId => $event->{Queue}.$event->{Uniqueid}, + "user[]" => $event->{CallerIDName}, }; } elsif ($event->{Event} eq "AgentConnect") @@ -393,4 +394,3 @@ my $connection_watcher = AnyEvent->timer( ); AnyEvent->condvar->recv; - diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..9c68672 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,5 @@ +version: "3.3" +services: + asterisk-zammad-cti-bridge: + build: . + container_name: asterisk-zammad-cti-bridge From 4da2d0e6d70911baf71566227a8ecf5e52bb9b4e Mon Sep 17 00:00:00 2001 From: Miguel Gonzalez Date: Tue, 17 Jan 2023 16:58:04 +0100 Subject: [PATCH 2/8] Remove unnecessary files --- asterisk-zammad-cti-bridge.service.example | 16 ---------------- config.cfg.sample | 8 -------- 2 files changed, 24 deletions(-) delete mode 100644 asterisk-zammad-cti-bridge.service.example delete mode 100644 config.cfg.sample diff --git a/asterisk-zammad-cti-bridge.service.example b/asterisk-zammad-cti-bridge.service.example deleted file mode 100644 index c3573e0..0000000 --- a/asterisk-zammad-cti-bridge.service.example +++ /dev/null @@ -1,16 +0,0 @@ -[Unit] -Description=asterisk-zammad-cti-bridge -After=network.target - -[Service] -; FIXME requires systemd >= 240 -;Type=exec -Type=simple -;ExecStart=/opt/asterisk-zammad-cti-bridge/asterisk-zammad-cti-bridge --asterisk asterisk-test --zammad zammad-test -ExecStart=/opt/asterisk-zammad-cti-bridge/asterisk-zammad-cti-bridge -User=asterisk-zammad-cti-bridge -Restart=on-failure -RestartSec=5 - -[Install] -WantedBy=multi-user.target diff --git a/config.cfg.sample b/config.cfg.sample deleted file mode 100644 index c2ad15f..0000000 --- a/config.cfg.sample +++ /dev/null @@ -1,8 +0,0 @@ -[zammad] -url=https://zammad.example.com/api/v1/cti/mytoken - -[asterisk] -host=127.0.0.1 -port=5038 -user=zammad -secret=foobar From 13e377e2d42d4813903cb0abc2126bc82ff091d8 Mon Sep 17 00:00:00 2001 From: magonzalez112 Date: Tue, 17 Jan 2023 17:13:21 +0100 Subject: [PATCH 3/8] Update README.me --- README.md | 82 ++++++------------------------------------------------- 1 file changed, 8 insertions(+), 74 deletions(-) diff --git a/README.md b/README.md index e056ac1..e2ff257 100644 --- a/README.md +++ b/README.md @@ -21,86 +21,20 @@ This Perl script serves as a bridge between an Asterisk server and the Zammad CT 3. Run `manager reload` in `asterisk -r`. -4. Install the Perl dependencies listed in the script. +4. Enable Zammad's CTI (Generic) interface. - E.g. on Debian stretch: +5. Edit `config.cfg` and fill in your Zammad CTI URL and your AMI secret. - ``` - apt install libanyevent-http-perl libconfig-simple-perl libdata-printer-perl liblog-any-perl liblog-any-adapter-dispatch-perl libwww-form-urlencoded-perl - cpan Asterisk::AMI - ``` - -5. Enable Zammad's CTI (Generic) interface. - -6. Copy `config.cfg.sample` to `config.cfg`: - - ``` - cp config.cfg.sample config.cfg - chmod 600 config.cfg - ``` - -7. Edit `config.cfg` and fill in your Zammad CTI URL and your AMI secret. - -8. Start the script: - - ``` - ./asterisk-zammad-cti-bridge - ``` - -# systemd - -An example systemd service file `asterisk-zammad-cti-bridge.service.example` is provided. To install it: - -1. Copy the file to `/etc/systemd/system` and remove the `.example`: - - ``` - cp -a asterisk-zammad-cti-bridge.service.example /etc/systemd/system/asterisk-zammad-cti-bridge.service - ``` - -2. Create the required user: - - ``` - useradd asterisk-zammad-cti-bridge - ``` - -3. Set the `config.cfg` permissions: - - ``` - chown asterisk-zammad-cti-bridge config.cfg - chmod 0600 config.cfg - ``` - - `asterisk-zammad-cti-bridge` will read `config.cfg` from the current working directory or from the application directory, so you can place it either in `/home/asterisk-zammad-cti-bridge` or in `/opt/asterisk-zammad-cti-bridge`. - -4. Adapt the service file to your requirements: - - - Change `ExecStart` to the correct path where you've placed `asterisk-zammad-cti-bridge.service`. The service defaults to `/opt/asterisk-zammad-cti-bridge`. - - - If you want to use different Asterisk/Zammad instances from the config (see "Multiple instances" below), edit the service file as necessary. Create one systemd service file for each `asterisk-zammad-cti-bridge.service` instance. - -5. Enable the service: +6. Build and start the container: ``` - systemctl enable asterisk-zammad-cti-bridge.service + docker-compose up --build -d ``` -6. Start the service: +7. Check the logs and troubleshoot: ``` - systemctl start asterisk-zammad-cti-bridge.service + docker-compose logs -f ``` - -# Multiple instances - -If you want to bridge multiple Asterisk/Zammad instances, e.g. one Asterisk to two Zammad instances (prod and test), you need to run multiple `asterisk-zammad-cti-bridge` instances. Add a new section to `config.cfg` for each additional instance, e.g.: - -``` -[zammad-test] -url=https://zammad-test.example.com/api/v1/cti/mytoken -``` - -Then start a new `asterisk-zammad-cti-bridge` instance and tell it to read the `[zammad-test]` section instead of the `[zammad]` section: - -``` -./asterisk-zammad-cti-bridge --zammad zammad-test -``` +# Multiple Instances +Add config.cfg sections and edit the entrypoint of the Dockerfile accordingly to load them. From ef9e36be1e92e0b749a34911812366b92689bfe0 Mon Sep 17 00:00:00 2001 From: magonzalez112 Date: Tue, 17 Jan 2023 17:16:14 +0100 Subject: [PATCH 4/8] Update README.me --- config.cfg.sample | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 config.cfg.sample diff --git a/config.cfg.sample b/config.cfg.sample new file mode 100644 index 0000000..c2ad15f --- /dev/null +++ b/config.cfg.sample @@ -0,0 +1,8 @@ +[zammad] +url=https://zammad.example.com/api/v1/cti/mytoken + +[asterisk] +host=127.0.0.1 +port=5038 +user=zammad +secret=foobar From 15024d5ee4e8682feb9c09776010f0c16a026450 Mon Sep 17 00:00:00 2001 From: Miguel Angel Gonzalez Date: Tue, 17 Jan 2023 17:18:06 +0100 Subject: [PATCH 5/8] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index e2ff257..19adc11 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,7 @@ This Perl script serves as a bridge between an Asterisk server and the Zammad CT 4. Enable Zammad's CTI (Generic) interface. -5. Edit `config.cfg` and fill in your Zammad CTI URL and your AMI secret. +5. Rename `config.cfg.sample` to `config.cfg`. Edit and fill in your Zammad CTI URL and your AMI secret. 6. Build and start the container: From 35a03ffb85632d1c4d6cbe87961abf756b325f03 Mon Sep 17 00:00:00 2001 From: Miguel Angel Gonzalez Date: Wed, 18 Jan 2023 08:06:06 +0100 Subject: [PATCH 6/8] Update README.md --- README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/README.md b/README.md index 19adc11..c17f913 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,6 @@ This Perl script serves as a bridge between an Asterisk server and the Zammad CT # Limitations -- No AMI SSL support yet, so use it only on the Asterisk host. - Can only monitor queue events and nothing else. # Setup From b8a8280b3ccc1df37133bd7a31b947e1f7e47d97 Mon Sep 17 00:00:00 2001 From: Miguel Angel Gonzalez Date: Wed, 18 Jan 2023 08:15:12 +0100 Subject: [PATCH 7/8] Update README.md --- README.md | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index c17f913..411318f 100644 --- a/README.md +++ b/README.md @@ -35,5 +35,32 @@ This Perl script serves as a bridge between an Asterisk server and the Zammad CT ``` docker-compose logs -f ``` + +# Rebuild when changes are made + +1. Take down and remove container: + + ``` + docker-compose down + ``` + +2. Force re-building: + + ``` + docker-compose up --force-recreate --build -d + ``` + +3. Remove orphan images: + + ``` + docker image prune -f + ``` + +BONUS. One-liner + + ``` + docker-compose up --force-recreate --build -d && docker image prune -f && docker-compose logs -f + ``` + # Multiple Instances -Add config.cfg sections and edit the entrypoint of the Dockerfile accordingly to load them. +Add config.cfg sections and edit the entrypoint of the Dockerfile accordingly to load them by using an script. Or just simply spin up a second container From 210d5edd97c53c95476932ac0962a48277440a40 Mon Sep 17 00:00:00 2001 From: Miguel Angel Gonzalez Date: Wed, 18 Jan 2023 08:17:23 +0100 Subject: [PATCH 8/8] Update README.md --- README.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 411318f..856eaf1 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,7 @@ This Perl script serves as a bridge between an Asterisk server and the Zammad CTI interface. It connects via AMI to Asterisk and monitors it for queue events; the relevant ones will be pushed to Zammad's CTI interface. +This version supports TLS, so you can run it in a different host from asterisk. + # Limitations - Can only monitor queue events and nothing else. @@ -63,4 +65,5 @@ BONUS. One-liner ``` # Multiple Instances -Add config.cfg sections and edit the entrypoint of the Dockerfile accordingly to load them by using an script. Or just simply spin up a second container +Add config.cfg sections and edit the entrypoint of the Dockerfile accordingly to load them by using an script. +Or just simply spin up a second container with a completely new config.cfg