#!/bin/bash
# state.sh - configuration fingerprint of a FreePBX server (no secrets): compare before backup and after restore
echo "== versions"; fwconsole -V 2>/dev/null | tail -1; asterisk -rx "core show version" | cut -d" " -f1-2
echo "== modules enabled: $(fwconsole ma list 2>/dev/null | grep -c Enabled)"
echo "== extensions"; mysql -N asterisk -e "select extension, name from users order by extension"
echo "== devices tech"; mysql -N asterisk -e "select id, tech from devices order by id"
echo "== trunks"; mysql -N asterisk -e "select trunkid, name, tech, channelid from trunks order by trunkid"
echo "== outbound routes"; mysql -N asterisk -e "select r.name, group_concat(p.match_pattern_pass order by p.match_pattern_pass) from outbound_routes r left join outbound_route_patterns p using(route_id) group by r.route_id order by r.name"
echo "== inbound routes"; mysql -N asterisk -e "select extension, cidnum, description, destination from incoming order by extension"
echo "== ext 1002 settings"; mysql -N asterisk -e "select keyword, data from sip where id=\"1002\" and keyword in (\"context\",\"dtmfmode\",\"max_contacts\",\"direct_media\",\"rtp_symmetric\",\"outbound_concurrency_limit\",\"callerid\") order by keyword"
echo "== voicemail boxes: $(grep -cE "^[0-9]+ =>" /etc/asterisk/voicemail.conf 2>/dev/null)"
echo "== custom files"; for f in pjsip_custom.conf pjsip.transports_custom.conf extensions_custom.conf logger_logfiles_custom.conf; do printf "%s %s\n" "$f" "$(sed "s/password=.*/password=x/" /etc/asterisk/$f 2>/dev/null | md5sum | cut -c1-12)"; done
echo "== cdr rows: $(mysql -N asteriskcdrdb -e "select count(*) from cdr")"
echo "== recordings: $(find /var/spool/asterisk/monitor -type f 2>/dev/null | wc -l)"
echo "== pjsip endpoints"; asterisk -rx "pjsip show endpoints" | awk "\$1==\"Endpoint:\" && \$2 !~ /^</ {print \$2}"
echo "== pjsip registrations"; asterisk -rx "pjsip show registrations" | awk "\$1 ~ /\// {print \$1, \$NF}" | head
