first commit
This commit is contained in:
31
asterisk/Dockerfile
Normal file
31
asterisk/Dockerfile
Normal file
@@ -0,0 +1,31 @@
|
||||
FROM andrius/asterisk:latest
|
||||
|
||||
RUN apt-get update && apt-get install -y \
|
||||
python3 \
|
||||
python3-pip \
|
||||
gettext-base \
|
||||
curl \
|
||||
file \
|
||||
sox \
|
||||
ffmpeg \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
|
||||
RUN pip3 install --break-system-packages \
|
||||
requests \
|
||||
pyst2
|
||||
|
||||
RUN mkdir -p \
|
||||
/tmp/voicebot \
|
||||
/var/lib/asterisk/sounds/custom \
|
||||
/etc/asterisk-templates
|
||||
|
||||
COPY templates/ /etc/asterisk-templates/
|
||||
COPY entrypoint.sh /entrypoint.sh
|
||||
|
||||
RUN chmod +x /entrypoint.sh
|
||||
|
||||
EXPOSE 5060/udp
|
||||
EXPOSE 5060/tcp
|
||||
EXPOSE 10000-20000/udp
|
||||
|
||||
ENTRYPOINT ["/entrypoint.sh"]
|
||||
0
asterisk/config/.gitkeep
Normal file
0
asterisk/config/.gitkeep
Normal file
3
asterisk/config/agi.conf
Normal file
3
asterisk/config/agi.conf
Normal file
@@ -0,0 +1,3 @@
|
||||
[general]
|
||||
enabled = yes
|
||||
agidir => /var/lib/asterisk/agi-bin
|
||||
41
asterisk/config/extensions.conf
Normal file
41
asterisk/config/extensions.conf
Normal file
@@ -0,0 +1,41 @@
|
||||
[general]
|
||||
static=yes
|
||||
writeprotect=no
|
||||
|
||||
|
||||
; ==========================================================
|
||||
; Incoming calls from SIP Trunk
|
||||
; ==========================================================
|
||||
|
||||
[from-trunk]
|
||||
|
||||
; Incoming call without DID
|
||||
exten => s,1,NoOp(Incoming call from trunk - CallerID: ${CALLERID(num)})
|
||||
same => n,Answer()
|
||||
same => n,Wait(1)
|
||||
same => n,AGI(voicebot.py)
|
||||
same => n,Hangup()
|
||||
|
||||
|
||||
; Incoming call with DID
|
||||
exten => _X.,1,NoOp(Incoming DID call: ${EXTEN} - CallerID: ${CALLERID(num)})
|
||||
same => n,Answer()
|
||||
same => n,Wait(1)
|
||||
same => n,AGI(voicebot.py)
|
||||
same => n,Hangup()
|
||||
|
||||
|
||||
|
||||
; ==========================================================
|
||||
; Internal test extension
|
||||
; Used with Zoiper / Linphone for testing
|
||||
; ==========================================================
|
||||
|
||||
[from-internal]
|
||||
|
||||
; Match any dialed extension
|
||||
exten => _X.,1,NoOp(Test call from internal extension ${EXTEN})
|
||||
same => n,Answer()
|
||||
same => n,Wait(1)
|
||||
same => n,AGI(voicebot.py)
|
||||
same => n,Hangup()
|
||||
5
asterisk/config/modules.conf
Normal file
5
asterisk/config/modules.conf
Normal file
@@ -0,0 +1,5 @@
|
||||
[modules]
|
||||
autoload=yes
|
||||
|
||||
; در صورتی که نمیخوای chan_sip قدیمی لود بشه (توصیه میشه فقط pjsip استفاده کنی)
|
||||
noload => chan_sip.so
|
||||
64
asterisk/config/pjsip.conf
Normal file
64
asterisk/config/pjsip.conf
Normal file
@@ -0,0 +1,64 @@
|
||||
[global]
|
||||
type=global
|
||||
user_agent=Pline-AI
|
||||
|
||||
[transport-udp]
|
||||
type=transport
|
||||
protocol=udp
|
||||
bind=0.0.0.0:5060
|
||||
|
||||
; ======================
|
||||
; Test Extension
|
||||
; ======================
|
||||
|
||||
[1000]
|
||||
type=endpoint
|
||||
context=from-internal
|
||||
disallow=all
|
||||
allow=ulaw,alaw
|
||||
auth=1000-auth
|
||||
aors=1000
|
||||
|
||||
[1000-auth]
|
||||
type=auth
|
||||
auth_type=userpass
|
||||
username=1000
|
||||
password=1000
|
||||
|
||||
[1000]
|
||||
type=aor
|
||||
max_contacts=5
|
||||
[121-reg]
|
||||
type=registration
|
||||
transport=transport-udp
|
||||
outbound_auth=121-auth
|
||||
server_uri=sip:192.168.102.253
|
||||
client_uri=sip:121@192.168.102.253
|
||||
retry_interval=60
|
||||
expiration=3600
|
||||
|
||||
[121-auth]
|
||||
type=auth
|
||||
auth_type=userpass
|
||||
username=121
|
||||
password=121
|
||||
|
||||
[121]
|
||||
type=aor
|
||||
contact=sip:192.168.102.253
|
||||
qualify_frequency=60
|
||||
|
||||
[121]
|
||||
type=endpoint
|
||||
context=from-trunk
|
||||
transport=transport-udp
|
||||
disallow=all
|
||||
allow=ulaw,alaw
|
||||
outbound_auth=121-auth
|
||||
aors=121
|
||||
|
||||
; --- اضافه کردن این بخش ---
|
||||
[121-identify]
|
||||
type=identify
|
||||
endpoint=121
|
||||
match=192.168.102.253
|
||||
41
asterisk/entrypoint.sh
Normal file
41
asterisk/entrypoint.sh
Normal file
@@ -0,0 +1,41 @@
|
||||
#!/bin/sh
|
||||
set -e
|
||||
|
||||
TEMPLATES_DIR="/etc/asterisk-templates"
|
||||
CONFIG_DIR="/etc/asterisk"
|
||||
|
||||
echo "[entrypoint] generating asterisk configuration..."
|
||||
|
||||
# کپی فایلهای ثابت
|
||||
cp "$TEMPLATES_DIR/agi.conf" "$CONFIG_DIR/agi.conf"
|
||||
cp "$TEMPLATES_DIR/modules.conf" "$CONFIG_DIR/modules.conf"
|
||||
|
||||
# تولید extensions.conf
|
||||
envsubst '${TEST_USER_EXTEN}' \
|
||||
< "$TEMPLATES_DIR/extensions.conf.template" \
|
||||
> "$CONFIG_DIR/extensions.conf"
|
||||
|
||||
# تولید pjsip.conf پایه (بدون ترانک)
|
||||
envsubst '${TEST_USER_EXTEN} ${TEST_USER_PASSWORD}' \
|
||||
< "$TEMPLATES_DIR/pjsip-base.conf.template" \
|
||||
> "$CONFIG_DIR/pjsip.conf"
|
||||
|
||||
# تابع افزودن ترانک
|
||||
add_trunk() {
|
||||
TRUNK_NAME=$1 TRUNK_HOST=$2 TRUNK_USERNAME=$3 TRUNK_PASSWORD=$4 \
|
||||
envsubst '${TRUNK_NAME} ${TRUNK_HOST} ${TRUNK_USERNAME} ${TRUNK_PASSWORD}' \
|
||||
< "$TEMPLATES_DIR/pjsip-trunk.conf.template" \
|
||||
>> "$CONFIG_DIR/pjsip.conf"
|
||||
}
|
||||
|
||||
# اضافه کردن ترانک ۱
|
||||
add_trunk "$TRUNK1_NAME" "$TRUNK1_HOST" "$TRUNK1_USERNAME" "$TRUNK1_PASSWORD"
|
||||
|
||||
# اضافه کردن ترانک ۲ (اگر وجود داشت)
|
||||
if [ -n "$TRUNK2_HOST" ]; then
|
||||
echo "[entrypoint] adding second trunk..."
|
||||
add_trunk "$TRUNK2_NAME" "$TRUNK2_HOST" "$TRUNK2_USERNAME" "$TRUNK2_PASSWORD"
|
||||
fi
|
||||
|
||||
echo "[entrypoint] configuration generated"
|
||||
exec asterisk -f -vvv
|
||||
3
asterisk/templates/agi.conf
Normal file
3
asterisk/templates/agi.conf
Normal file
@@ -0,0 +1,3 @@
|
||||
[general]
|
||||
enabled = yes
|
||||
agidir => /var/lib/asterisk/agi-bin
|
||||
41
asterisk/templates/extensions.conf.template
Normal file
41
asterisk/templates/extensions.conf.template
Normal file
@@ -0,0 +1,41 @@
|
||||
[general]
|
||||
static=yes
|
||||
writeprotect=no
|
||||
|
||||
|
||||
; ==========================================================
|
||||
; Incoming calls from SIP Trunk
|
||||
; ==========================================================
|
||||
|
||||
[from-trunk]
|
||||
|
||||
; Incoming call without DID
|
||||
exten => s,1,NoOp(Incoming call from trunk - CallerID: ${CALLERID(num)})
|
||||
same => n,Answer()
|
||||
same => n,Wait(1)
|
||||
same => n,AGI(voicebot.py)
|
||||
same => n,Hangup()
|
||||
|
||||
|
||||
; Incoming call with DID
|
||||
exten => _X.,1,NoOp(Incoming DID call: ${EXTEN} - CallerID: ${CALLERID(num)})
|
||||
same => n,Answer()
|
||||
same => n,Wait(1)
|
||||
same => n,AGI(voicebot.py)
|
||||
same => n,Hangup()
|
||||
|
||||
|
||||
|
||||
; ==========================================================
|
||||
; Internal test extension
|
||||
; Used with Zoiper / Linphone for testing
|
||||
; ==========================================================
|
||||
|
||||
[from-internal]
|
||||
|
||||
; Match any dialed extension
|
||||
exten => _X.,1,NoOp(Test call from internal extension ${EXTEN})
|
||||
same => n,Answer()
|
||||
same => n,Wait(1)
|
||||
same => n,AGI(voicebot.py)
|
||||
same => n,Hangup()
|
||||
5
asterisk/templates/modules.conf
Normal file
5
asterisk/templates/modules.conf
Normal file
@@ -0,0 +1,5 @@
|
||||
[modules]
|
||||
autoload=yes
|
||||
|
||||
; در صورتی که نمیخوای chan_sip قدیمی لود بشه (توصیه میشه فقط pjsip استفاده کنی)
|
||||
noload => chan_sip.so
|
||||
30
asterisk/templates/pjsip-base.conf.template
Normal file
30
asterisk/templates/pjsip-base.conf.template
Normal file
@@ -0,0 +1,30 @@
|
||||
[global]
|
||||
type=global
|
||||
user_agent=Pline-AI
|
||||
|
||||
[transport-udp]
|
||||
type=transport
|
||||
protocol=udp
|
||||
bind=0.0.0.0:5060
|
||||
|
||||
; ======================
|
||||
; Test Extension
|
||||
; ======================
|
||||
|
||||
[${TEST_USER_EXTEN}]
|
||||
type=endpoint
|
||||
context=from-internal
|
||||
disallow=all
|
||||
allow=ulaw,alaw
|
||||
auth=${TEST_USER_EXTEN}-auth
|
||||
aors=${TEST_USER_EXTEN}
|
||||
|
||||
[${TEST_USER_EXTEN}-auth]
|
||||
type=auth
|
||||
auth_type=userpass
|
||||
username=${TEST_USER_EXTEN}
|
||||
password=${TEST_USER_PASSWORD}
|
||||
|
||||
[${TEST_USER_EXTEN}]
|
||||
type=aor
|
||||
max_contacts=5
|
||||
34
asterisk/templates/pjsip-trunk.conf.template
Normal file
34
asterisk/templates/pjsip-trunk.conf.template
Normal file
@@ -0,0 +1,34 @@
|
||||
[${TRUNK_NAME}-reg]
|
||||
type=registration
|
||||
transport=transport-udp
|
||||
outbound_auth=${TRUNK_NAME}-auth
|
||||
server_uri=sip:${TRUNK_HOST}
|
||||
client_uri=sip:${TRUNK_USERNAME}@${TRUNK_HOST}
|
||||
retry_interval=60
|
||||
expiration=3600
|
||||
|
||||
[${TRUNK_NAME}-auth]
|
||||
type=auth
|
||||
auth_type=userpass
|
||||
username=${TRUNK_USERNAME}
|
||||
password=${TRUNK_PASSWORD}
|
||||
|
||||
[${TRUNK_NAME}]
|
||||
type=aor
|
||||
contact=sip:${TRUNK_HOST}
|
||||
qualify_frequency=60
|
||||
|
||||
[${TRUNK_NAME}]
|
||||
type=endpoint
|
||||
context=from-trunk
|
||||
transport=transport-udp
|
||||
disallow=all
|
||||
allow=ulaw,alaw
|
||||
outbound_auth=${TRUNK_NAME}-auth
|
||||
aors=${TRUNK_NAME}
|
||||
|
||||
; --- اضافه کردن این بخش ---
|
||||
[${TRUNK_NAME}-identify]
|
||||
type=identify
|
||||
endpoint=${TRUNK_NAME}
|
||||
match=${TRUNK_HOST}
|
||||
Reference in New Issue
Block a user