Shell Scrips
Here is a collection of shell scripts that provide various useful functions. These scripts interact with the PBX database or utilize the comprehensive Vodia REST API interface.
MAC Overview
The first shell script shows how to list the MAC addresses that have been assigned to extensions.
#!/bin/bash
function get_xml()
{
gawk -v tag=$1 'BEGIN{regex="<" tag ">([^<]*)</" tag ">";}{ match($0, regex, m); for(i = 1;; i++) { if(!(i in m)) break; printf("%s\n",m[i]);}}' $2
}
for mac in macs/*.xml
do
name=${user:5}
# only the name
user=$(get_xml user $mac)
adr=$(get_xml adr $mac)
alias=$(get_xml alias users/$user.xml)
domain=$(get_xml domain users/$user.xml)
echo $adr $(get_xml name user_alias/$alias.xml)@$(get_xml name domains/$domain.xml)
done
Count Extensions
This script count how many extensions are in each domain.
#!/bin/bash
# Show the passwords of all users:
function get_xml()
{
gawk -v tag=$1 'BEGIN{regex="<" tag ">([^<]*)</" tag ">";}{ match($0, regex, m); for(i = 1;; i++) { if(!(i in m)) break; printf("%s\n",m[i]);}}' $2
}
for dom in domains/*.xml; do
name=${dom:8}
# only the name
idx=${name%.xml}
# only the number
dn=$(get_xml name $dom)
if [ ! -z "$dn" ]; then
count=0
for ext in users/*.xml; do
domain=$(get_xml domain $ext)
if [ "$domain" == "$idx" ]; then
type=$(get_xml type $ext)
if [ $type == "extensions" ]; then
count=$[$count+1]
fi
fi
done
echo $dn $count
fi
done
Show Email Addresses
This script shows the various email addresses .
#!/bin/bash
# Show the emails of the users
function get_xml()
{
gawk -v tag=$1 'BEGIN{regex="<" tag ">([^<]*)</" tag ">";}{ match($0, regex, m); for(i = 1;; i++) { if(!(i in m)) break; printf("%s\n",m[i]);}}' $2
}
for xml in users/*.xml; do
n=$(get_xml alias $xml)
name=$(get_xml name user_alias/$n.xml)
d=$(get_xml domain $xml)
domain=$(get_xml name domains/$d.xml)
email=$(get_xml email_cdr $xml)
[ -n "$email" ] && echo $name@$domain: $email
type=$(get_xml type $xml)
if [ $type = extensions ]; then
id=$(get_xml id $xml)
for t in email_address email_recadr wakeup_fail_email; do
email=$(get_xml $t extensions/$id.xml)
[ -n "$email" ] && echo $name@$domain: $email
done
fi
done
for xml in domains/*.xml; do
domain=$(get_xml name $xml)
for t in email_cdr e911_emails billing_email; do
email=$(get_xml $t $xml)
[ -n "$email" ] && echo $domain: $email
done
done
Managing PBX Administrators: Add, Delete or Modify Across Multiple PBXs
Download the script from here (supports version 69 onwards) - pbx-admin.sh
This script provides options for managing PBX administrators, including adding, modifying or deleting administrators across multiple PBXs. Below are detailed instructions and usage examples for each option.
Configuration
The script requires a configuration file located at:
/your-home-directory/.pbx-admin.conf
This file must include the following settings:
-
username
The administrator username. -
password
The administrator password. -
server
The server address.
Ensure that this file is properly configured before using the script to manage PBX administrators.
Example Configuration File:
username=admin
password=securepassword123
server=https://pbx1.example.com https://pbx2.example.com https://pbx3.example.com
Options
--add
Add a new PBX administrator. This option requires the following parameters:
Required:
-
--username <admin_username>
Specify the username of the new administrator. -
--password <admin_password>
Set the password for the new administrator.
Optional:
-
--display <admin_display_name>
Provide a display name for the administrator. Defaults to the username if not specified. -
--email <admin_email>
Provide an email address for the administrator. Defaults to none. -
--ip <ip_restrictions>
Define IP restrictions for the administrator. Accepts individual IP addresses or CIDR ranges. -
--api <true|false>
Enable or disable API access for the administrator. Defaults tofalse
. -
--phone <admin_phone>
Provide a phone number for the administrator. Defaults to none.
Usage Examples:
./pbx-admin.sh --add --username jerry --password "password"
./pbx-admin.sh --add --username jerry --password "password" --display "Jerry Admin" --email jerry@vodia.com --api true --ip "192.168.92.1 192.168.71.0/24" --phone 1801801801
--delete
Delete an existing PBX administrator. Provide the username of the administrator to be removed.
Required:
<admin_username>
Specify the username of the administrator to delete.
Usage Example:
./pbx-admin.sh --delete jerry
--modify
Modify the details of an existing PBX administrator. This option requires the following parameters:
Required:
--username <admin_username>
Specify the username of the administrator to modify.
At Least One of:
-
--password <new_password>
Update the administrator's password. -
--display <new_display_name>
Update the administrator's display name. -
--email <new_email>
Update the administrator's email address. -
--ip <new_ip_restrictions>
Update IP restrictions for the administrator. -
--api <true|false>
Enable or disable API access for the administrator. -
--phone <new_phone>
Update the administrator's phone number.
Usage Examples:
./pbx-admin.sh --modify --username jerry --display "Jerry Admin"
./pbx-admin.sh --modify --username jerry --password "newpassword"