Posts Tagged ‘ Asterisk

Dump Asterisk Realtime Voicemail users into Voicemail.conf

While I’ve been lazy about updating my site, I have not been lazy with writing new scripts and coming up with ideas to write about.

The first in the set that I’m going to make public is a script to dump your Asterisk Realtime Voicemail database users into a flat voicemail.conf file. I used this technique while troubleshooting to revert back to the standard setup while I was working on the realtime config.

#!/bin/bash
function get_mailbox {
 
   mailbox=$( mysql -u dbuser --password=dbpass asterisk -e "select mailbox from voicemail_users where uniqueid = '$i'")
   mailbox=`echo $mailbox | awk '{print $2}'`
 
}
 
function get_password {
 
    password=$(mysql -u dbuser --password=dbpass asterisk -e "select password from voicemail_users where uniqueid = '$i'")
    password=`echo $password | awk '{print $2}'`
 
}
 
function get_fullname {
 
    name=$(mysql -u dbuser --password=dbpass asterisk -e "select fullname from voicemail_users where uniqueid = '$i'")
    name=`echo $name | awk '{print $2}'`
 
}
 
function get_email {
 
    email=$(mysql -u dbuser --password=dbpass asterisk -e "select email from voicemail_users where uniqueid = '$i'")
    email=`echo $email | awk '{print $2}'`
 
}
 
function write_file {
 
    echo "$mailbox => $password,$name,$email,,attach=yes|saycid=no|envelope=no|delete=no" >> /root/test_dump.txt
 
}
 
for (( i=1; i<=151; i++))
do
get_mailbox
get_password
get_fullname
get_email
write_file
done

Asterisk Voicemail Check Disk Usage Script

This latest script was written to prevent 3:00am phone calls. I was recently called because our voicemail server was beginning to run out of disk space. The following script simply scans the voicemail directory, if a user is over 100MB it looks up their extension in the asterisk database and then sends them an email notification to clean it out. Below is the script:

#!/bin/bash
 
#set the maximum disk usage for a user to approx 100MB
size_limit=100000
 
function send_email () {
 
    subject="Voicemail Over Limit"
    message="/tmp/emailmessage.txt.$f"
 
    echo "Hello $name, " > $message
    echo " " >> $message
    echo "This is a notification that your voicemail is currently over the allowed limit.  You are currently using $humansize.  Please either manually delete the voicemails, or you can send an email to patb@codero.com for help with wiping all of the new and saved voicemails in your mailbox." >> $message
    echo " " >> $message
    echo "Thank you," >> $message
    echo "Admin" >> $message
 
    /bin/mail -s "$subject" "$email" < $message
}
 
for f in $(ls /var/spool/asterisk/voicemail/default/)
do
  size=$(du -s /var/spool/asterisk/voicemail/default/$f | awk '{print $1}')
  if [ "$size" -gt "$size_limit" ]
    then
 
        humansize=$(du -sh /var/spool/asterisk/voicemail/default/$f | awk '{print $1}')
        #Query the database for the users email address
        email=$(mysql -u asterisk --password=dbpassword asterisk -e "select email from voicemail_users where mailbox = '$f'")
        #Parse just the email address out of the above query
        email=$(echo $email | awk '{print $2}' )
 
        name=$(mysql -u asterisk --password=dbpassword asterisk -e "select fullname from voicemail_users where mailbox = '$f'")
        name=$(echo $name | awk '{print $2,$3}' )
        #echo "$name    $f  $email  $humansize"
        send_email $email $name $humansize
  fi
    # take action on each file. $f store current file name
done

Rick Roll Script is Back!!! Well sorta…

Notice I used 3 exclamations in the title to convey how excited I am. I’ve been working on developing a new platform that I can better monitor for the Rick Roll Script. I’ve setup a new domain called prankforce.com which now hosts the previous script. I’ve spent a lot of time cleaning this bad boy up for production use and I’ve learned quite a bit in the process. After proving to be one of the most popular features on the site, I think that these changes will be welcomed. If you have any suggestions or questions regarding this project, please let me know.

Right now the site has the following features:

  • custom invite script
  • call logging
  • 1 hour wait between prank calls
  • blacklist of phone numbers that can’t be dialed

Coming features:

  • Message Board
  • ability to suggest new audio and vote for other suggestions (reddit style)
  • a decent UI (Sorry I’m not a designer)

Right now the site is by invite only. If want an invite, just send an email to admin@prankforce.com

Asterisk Rick Roll Script

You know Rick Astley will never give you up, let your friends know. This was my first Asterisk Scripting project, decided to post the end results under the Asterisk header at the top of the page. Check it out, and let your friends and loved ones know that you’ll never give them up. Click here to check it out