secubox-openwrt/package/secubox/luci-app-voip/root/usr/libexec/rpcd/luci.voip
CyberMind-FR e416fa14a6 feat(jabber): Add VoIP integration to LuCI dashboard
Add Jingle VoIP, SMS Relay, and Voicemail Notifications sections to
the Jabber overview.js. Expose 9 new RPC methods in api.js for VoIP
control. Also includes remaining VoIP package updates (dialer view,
asterisk-config.sh) from previous session.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-19 14:37:17 +01:00

255 lines
9.1 KiB
Bash
Executable File

#!/bin/sh
# RPCD backend for VoIP PBX
. /usr/share/libubox/jshn.sh
VOIPCTL="/usr/sbin/voipctl"
case "$1" in
list)
cat <<JSON
{
"status": {},
"extensions": {},
"calls": {},
"voicemails": {},
"trunk_status": {},
"install": {},
"start": {},
"stop": {},
"restart": {},
"reload": {},
"ext_add": {"number": "str", "name": "str", "password": "str"},
"ext_del": {"number": "str"},
"ext_passwd": {"number": "str", "password": "str"},
"call_originate": {"from_ext": "str", "to_number": "str"},
"call_hangup": {"channel": "str"},
"trunk_add": {"provider": "str"},
"trunk_test": {},
"vm_delete": {"extension": "str", "msg_id": "str"}
}
JSON
;;
call)
case "$2" in
status)
$VOIPCTL status
;;
extensions)
json_init
json_add_array "extensions"
uci show voip 2>/dev/null | grep "=extension" | while read -r line; do
section=$(echo "$line" | cut -d'.' -f2 | cut -d'=' -f1)
ext=$(echo "$section" | sed 's/ext_//')
name=$(uci -q get "voip.$section.name")
context=$(uci -q get "voip.$section.context" || echo "internal")
vm=$(uci -q get "voip.$section.voicemail" || echo "0")
json_add_object
json_add_string "number" "$ext"
json_add_string "name" "$name"
json_add_string "context" "$context"
json_add_boolean "voicemail" "$vm"
json_close_object
done
json_close_array
json_dump
;;
calls)
if lxc-info -n voip -s 2>/dev/null | grep -q "RUNNING"; then
local output=$(lxc-attach -n voip -- asterisk -rx "core show channels concise" 2>/dev/null)
json_init
json_add_array "calls"
echo "$output" | while IFS='!' read -r channel context ext prio state app data caller connected duration; do
[ -z "$channel" ] && continue
json_add_object
json_add_string "channel" "$channel"
json_add_string "state" "$state"
json_add_string "caller" "$caller"
json_add_string "connected" "$connected"
json_add_string "duration" "$duration"
json_close_object
done
json_close_array
json_dump
else
echo '{"calls":[]}'
fi
;;
voicemails)
json_init
json_add_array "voicemails"
find /srv/voip/voicemail/default -name "msg*.txt" 2>/dev/null | while read -r txtfile; do
local ext=$(echo "$txtfile" | sed -n 's|.*/\([0-9]*\)/msg.*|\1|p')
local id=$(basename "$txtfile" .txt)
local caller=$(grep "^callerid=" "$txtfile" 2>/dev/null | cut -d'=' -f2)
local date=$(grep "^origdate=" "$txtfile" 2>/dev/null | cut -d'=' -f2)
local duration=$(grep "^duration=" "$txtfile" 2>/dev/null | cut -d'=' -f2)
json_add_object
json_add_string "extension" "$ext"
json_add_string "id" "$id"
json_add_string "caller" "$caller"
json_add_string "date" "$date"
json_add_int "duration" "${duration:-0}"
json_close_object
done
json_close_array
json_dump
;;
trunk_status)
if lxc-info -n voip -s 2>/dev/null | grep -q "RUNNING"; then
local output=$(lxc-attach -n voip -- asterisk -rx "pjsip show registrations" 2>/dev/null)
local registered=0
echo "$output" | grep -q "Registered" && registered=1
json_init
json_add_boolean "registered" "$registered"
json_add_string "details" "$output"
json_dump
else
echo '{"registered":false,"details":"Container not running"}'
fi
;;
install)
local output=$($VOIPCTL install 2>&1)
local rc=$?
json_init
json_add_boolean "success" "$((rc == 0))"
json_add_string "output" "$output"
json_dump
;;
start)
local output=$($VOIPCTL start 2>&1)
local rc=$?
json_init
json_add_boolean "success" "$((rc == 0))"
json_add_string "output" "$output"
json_dump
;;
stop)
local output=$($VOIPCTL stop 2>&1)
local rc=$?
json_init
json_add_boolean "success" "$((rc == 0))"
json_add_string "output" "$output"
json_dump
;;
restart)
local output=$($VOIPCTL restart 2>&1)
local rc=$?
json_init
json_add_boolean "success" "$((rc == 0))"
json_add_string "output" "$output"
json_dump
;;
reload)
local output=$($VOIPCTL reload 2>&1)
local rc=$?
json_init
json_add_boolean "success" "$((rc == 0))"
json_add_string "output" "$output"
json_dump
;;
ext_add)
read -r input
json_load "$input"
json_get_var number number
json_get_var name name
json_get_var password password
local output=$($VOIPCTL ext add "$number" "$name" "$password" 2>&1)
local rc=$?
json_init
json_add_boolean "success" "$((rc == 0))"
json_add_string "output" "$output"
json_dump
;;
ext_del)
read -r input
json_load "$input"
json_get_var number number
local output=$($VOIPCTL ext del "$number" 2>&1)
local rc=$?
json_init
json_add_boolean "success" "$((rc == 0))"
json_add_string "output" "$output"
json_dump
;;
ext_passwd)
read -r input
json_load "$input"
json_get_var number number
json_get_var password password
local output=$($VOIPCTL ext passwd "$number" "$password" 2>&1)
local rc=$?
json_init
json_add_boolean "success" "$((rc == 0))"
json_add_string "output" "$output"
json_dump
;;
call_originate)
read -r input
json_load "$input"
json_get_var from_ext from_ext
json_get_var to_number to_number
local output=$($VOIPCTL call "$from_ext" "$to_number" 2>&1)
local rc=$?
json_init
json_add_boolean "success" "$((rc == 0))"
json_add_string "output" "$output"
json_dump
;;
call_hangup)
read -r input
json_load "$input"
json_get_var channel channel
local output=$($VOIPCTL hangup "$channel" 2>&1)
local rc=$?
json_init
json_add_boolean "success" "$((rc == 0))"
json_add_string "output" "$output"
json_dump
;;
trunk_test)
local output=$($VOIPCTL trunk test 2>&1)
local rc=$?
json_init
json_add_boolean "success" "$((rc == 0))"
json_add_string "output" "$output"
json_dump
;;
vm_delete)
read -r input
json_load "$input"
json_get_var extension extension
json_get_var msg_id msg_id
local output=$($VOIPCTL vm delete "$extension" "$msg_id" 2>&1)
local rc=$?
json_init
json_add_boolean "success" "$((rc == 0))"
json_add_string "output" "$output"
json_dump
;;
esac
;;
esac