From 32aa08d39cd796a3a2af320603a7f89f57377a10 Mon Sep 17 00:00:00 2001 From: Jakob Lechner Date: Mon, 6 Nov 2023 22:09:35 +0000 Subject: [PATCH] Add asterisk test service --- hosts/aluminium/services/asterisk/default.nix | 7 +- hosts/cadmium/configuration.nix | 1 + hosts/cadmium/services/asterisk.nix | 119 ++++++++++++++++++ hosts/cadmium/services/default.nix | 5 + 4 files changed, 129 insertions(+), 3 deletions(-) create mode 100644 hosts/cadmium/services/asterisk.nix create mode 100644 hosts/cadmium/services/default.nix diff --git a/hosts/aluminium/services/asterisk/default.nix b/hosts/aluminium/services/asterisk/default.nix index bc672dc..d6aaa9e 100644 --- a/hosts/aluminium/services/asterisk/default.nix +++ b/hosts/aluminium/services/asterisk/default.nix @@ -67,9 +67,10 @@ in { same = n,Hangup() exten = _499846977891,1,Noop(Processing an incoming call) - same = n,Dial(PJSIP/13&PJSIP/16,30,tT) - same = n,VoiceMail(977891@jakob,u) - same = n,Hangup() + same = n,VoiceMail(876@lechner,uS) + ;same = n,Dial(PJSIP/13&PJSIP/16,30,tT) + ;same = n,VoiceMail(977891@jakob,u) + ;same = n,Hangup() [dect] exten = 100,1,Answer() diff --git a/hosts/cadmium/configuration.nix b/hosts/cadmium/configuration.nix index 0024313..4926148 100644 --- a/hosts/cadmium/configuration.nix +++ b/hosts/cadmium/configuration.nix @@ -4,6 +4,7 @@ imports = [ ./hardware-configuration.nix ../../home-manager/users/jalr.nix + ./services ]; networking = { diff --git a/hosts/cadmium/services/asterisk.nix b/hosts/cadmium/services/asterisk.nix new file mode 100644 index 0000000..13c6807 --- /dev/null +++ b/hosts/cadmium/services/asterisk.nix @@ -0,0 +1,119 @@ +{ config, lib, pkgs, ... }: +let + rtp = { + start = 10000; + end = 10200; + }; +in +{ + services.asterisk = { + enable = true; + confFiles = { + "features.conf" = '' + [applicationmap] + doorOpen => #9,peer,Gosub,"door-open,s,1" + ''; + "extensions.conf" = '' + [door-open] + exten => s,1,Verbose("Here we are in a subroutine!") + same = n,System("/tmp/door-open.sh") + same = n,Hangup() + + [doorbell] + exten = s,1,Set(CHANNEL(hangup_handler_push)=hdlr1,s,1(args)); + same = n,Set(__DYNAMIC_FEATURES=doorOpen) + same = n,Dial(PJSIP/1000,60) + same = n,Hangup() + + [hdlr1] + exten = s,1,Verbose(0, Executed First) + same = n,Playback(hello-world) + same => n,Set(HANGUPCAUSE_STRING=''${HANGUPCAUSE_KEYS()}) + same = n,Verbose(0, Channels with hangup cause information: ''${HANGUPCAUSE_STRING}) + same = n,Set(ARRAY(item)=''${HANGUPCAUSE_STRING}) + same = n,Set(HANGUPCAUSE_STRING=''${HANGUPCAUSE_STRING:''${LEN(''${item})}}) + same = n,Verbose(0, Got Channel ID ''${item} with Technology Cause Code ''${HANGUPCAUSE(''${item},tech)}, Asterisk Cause Code ''${HANGUPCAUSE(''${item},ast)}) + same = n,Return() + + [test] + exten = 10,1,Answer() + same = n,Wait(1) + same = n,Playback(hello-world) + same = n,Hangup() + + exten = 11,1,Answer() + same = n,AudioSocket(c81c42bb-d640-49b1-936b-989607d1985f,127.0.0.1:9092) + same = n,Hangup() + + exten = 12,1,Answer() + ;same = n,Festival(‘Please record your message’) + same = n,Record(mymessage:gsm) + ;same = n,Festival(‘You said’) + same = n,Playback(mymessage) + ;same = n,Festival(‘Press 1 to continue or 2 to change your message’) + same = n,Read(KEEPORTOSS||1) + + ''; + "http.conf" = '' + [general] + enabled=yes + bindaddr=127.0.0.1 + + ; Port to bind to for HTTP sessions (default is 8088) + ;bindport=8088 + + tlsdisablev1=yes + tlsdisablev11=yes + tlsdisablev12=yes + + tlsservercipherorder=yes + ''; + "rtp.conf" = '' + [general] + rtpstart=${toString rtp.start} + rtpend=${toString rtp.end} + ''; + "dnsmgr.conf" = '' + [general] + enable=yes + refreshinterval=300 + ''; + "pjsip.conf" = '' + [simpletrans] + type=transport + protocol=udp + bind=127.0.0.1:5070 + + [1000] + type=endpoint + context=test + disallow=all + allow=alaw + auth=1000 + aors=1000 + direct_media=no + language=de + + [1000] + type=auth + auth_type=userpass + password=1000 + username=1000 + + [1000] + type=aor + max_contacts=1 + ''; + }; + useTheseDefaultConfFiles = [ ]; + }; + + networking.firewall = { + allowedUDPPortRanges = [ + { + from = rtp.start; + to = rtp.end; + } + ]; + }; +} diff --git a/hosts/cadmium/services/default.nix b/hosts/cadmium/services/default.nix new file mode 100644 index 0000000..03d0006 --- /dev/null +++ b/hosts/cadmium/services/default.nix @@ -0,0 +1,5 @@ +{ + imports = [ + ./asterisk.nix + ]; +}