Thursday, September 06, 2012

Using Blacklists, Google Contact Synchronization and Opencnam In Asterisk

I use Broadvoice who has had problems with passing callerid data to me since April 24, 2012 with no resolution as of the writing of this post on September 6, 2012.  I guess that only way that I can resolve issues with them is to dump them.  Yes, I'm calling you out Broadvoice.

I've been able to work around Broadvoice and their horrible technical support and engineering.

I've implemented a callerid solution in asterisk using the following:


  • Manual Database Entries for Blacklisting
  • Google Contact Synchronization
  • Opencnam Lookups



Blacklisting

I add political, charity, religious organizations and businesses that I've had dealings with that I never want to talk to again to a blacklist.  They don't follow do-not call rules here in the US.

Connect to the asterisk console using asterisk -r

Add the number the database.  I add the number with and without the country code because callerid comes in differently 

database put blacklist 6305392500 1
database put blacklist 16305392500 1

Google Contact Synchronization

I followed the instructions on the PBX in a Flash Forums below to setup the script.


I modified the python script to take out the plus symbol and also remove the the country code.  I planned on using the google contacts for caller id for Google Voice as well as from my voip provider.

# Insert the number into the cidname database, reinsert the country code if defined.
            #os.system("/usr/sbin/asterisk -rx \'database put cidname +%s%s \"%s\"\'" % (country_code,phone.text,entry.title.text))
            os.system("/usr/sbin/asterisk -rx \'database put cidname %s%s \"%s\"\'" % (country_code,phone.text,entry.title.text))
            os.system("/usr/sbin/asterisk -rx \'database put cidname %s \"%s\"\'" % (phone.text,entry.title.text))



Added A Crontab Entry That Runs Every 30 Minutes
0,30 * * * * /usr/local/bin/python /usr/local/bin/googlecontacts.py > /dev/null 2>&1




Opencnam Lookup

Here's the cnam.agi.  I made it an executable and added it to /usr/share/asterisk/agi-bin/.  Your install may be different.  You'll need the curl binary to make it work.  I also log the cnam transactions in a temporary log file.


cnam.agi 

#!/bin/bash

cidnum=$1
TODAY=$(date)
name=`curl -s -X GET https://api.opencnam.com/v1/phone/$cidnum?format=PBX`

echo $TODAY >> /tmp/cnam.log
echo $cidnum >> /tmp/cnam.log
echo $name >> /tmp/cnam.log
echo "" >> /tmp/cnam.log

if [ -n "$name"  ]; then

echo "SET VARIABLE lookupname \"${name}\""
read RESPONSE

exit 0

else

exit 1

fi




Here's everything in the extensions.conf



[from-broadvoice]
exten => _X!,1,GotoIf(${DB_EXISTS(blacklist/${CALLERID(num)})}?blacklisted,s,1)
exten => _X!,n,Set(CALLERID(name)=${DB(cidname/${CALLERID(num)})})
exten => _X!,n,GotoIf($["${CALLERID(name)}" = ""]?blank)
exten => _X!,n,Dial(SIP/holla,30,tr)
exten => _X!,n,Voicemail(holla)
exten => _X!,n,Playback(vm-goodbye)
exten => _X!,n,Hangup()
exten => _X!,n(blank),NoOp(cnam.agi)
exten => _X!,n,AGI(cnam.agi,${CALLERID(num)})
exten => _X!,n,Set(CALLERID(name)=${lookupname})
exten => _X!,n,Dial(SIP/holla)
exten => _X!,n,Voicemail(holla)
exten => _X!,n,Playback(vm-goodbye)
exten => _X!,n,Hangup()

[from-googlevoice]
exten => _X!,1,NoOp(Call from Google Voice)
exten => _X!,n,Set(CALLERID(num)=${CUT(EXTEN,/,2)})
exten => _X!,n,Set(CALLERID(name)=${DB(cidname/${CALLERID(num)})})
exten => _X!,n,GotoIf($["${CALLERID(name)}" = ""]?blank)
exten => _X!,n,Dial(SIP/holla,30,D(:1))
exten => _X!,n,Hangup()
exten => _X!,n(blank),NoOp(cnam.agi)
exten => _X!,n,AGI(cnam.agi,${CALLERID(num):1})
exten => _X!,n,Set(CALLERID(name)=${lookupname})
exten => _X!,n,Dial(SIP/holla,30,D(:1))
exten => _X!,n,Hangup()

[blacklisted]
exten => s,1,Wait(2)
exten => s,n,Playback(ss-noservice)
exten => s,n,Wait(1)
exten => s,n,Hangup()

Saturday, August 25, 2012

Integrating Mythtv and Plex/XBMC

There is not native Mythtv support in Plex as of the writing of this blog post.  However, Plex contains xbmc code that can play Mythtv's transcoded .nuv NuppelVideo files. I transcode mpeg2 files to nuv to save on disk space.  XBMC has mythtv integration but scanning of tv shows doesn't always work and it's sometimes days or weeks behind in updating the tv shows and episodes.

Mythtv also does not name the files in a format that plex and xbmc scrapers can use to help identify the episode.  Hell On Wheels.s02e02.mpg looks something like 5066_20120825091500.nuv on the mythtv side.


The recipe for integration calls for:

MythicalLibrarian - http://code.google.com/p/mythicallibrarian/
SMB/CIFS share of your mythtv recordings or where you link your mythtv recordings via MythicalLibrarian.



Follow the instructions for downloading and installing MythicalLibrarian on the following site: http://wiki.xbmc.org/?title=MythicalLibrarian


Easy installation:

sudo apt-get install curl && mkdir ~/.mythicalLibrarian && mkdir ~/.mythicalLibrarian/mythicalSetup && cd ~/.mythicalLibrarian/mythicalSetup
curl http://mythicallibrarian.googlecode.com/svn/trunk/mythicalSetup.sh>./mythicalSetup.sh
sudo su
chmod +x ./mythicalSetup.sh && ./mythicalSetup.sh


I made 3 modifications to the default settings in the file.

I set the MoveDir= to a directory where I would make a samba share just for mythtv linked recordings.

I set  the SYMLINK=LINK  to symbolically link the nuv to the mpeg file created by the mythicalLibrarian script.

I also added the ip addresses of my xbmc frontends in the XBMCIPs=( '192.168.x.x:8080') section.


When the script finished it will add a user job to mythtv to automatically run for new recording schedules. A few modifications will be needed to modify existing recording schedules.  I'll show you how to do that shortly.

I had years of recordings that I needed to scan and identify so I let the script run over 3 days to identify all my shows in a format the plex and xbmc could understand.

mythicalLibrarian --scan nuv /home/mythtv/Videos


Once that was complete I added the following share to my samba configuration file.  (/etc/samba/smb.conf for me in linux) and restarted samba for it to take effect.

[Tv]
        comment = Tv
        path = /home/mythtv/Videos
        writeable = yes
        browseable = yes
        create mask = 0775
        force create mode = 0664
        directory mask = 0775
        force directory mode = 0775


sudo service smb restart


I added the directory /home/mythtv/Videos as a tv source in both Plex and XBMC.  They will both need some time to scan and also identify the files in their own way.

The recording now looks like this:

Hell on Wheels S02E02 (Durant, Nebraska).nuv -> /mnt/tv/5066_20120825091500.nuv



How do update your mythtv recording schedules to use the mythicalLibrarian scripts

You'll need to use mysql to update the database.  You setup may be different.


mysql -umythtv -pmythtv mythconverg
update record set autouserjob1=1 where autouserjob1=0;


That should update your recording schedule to use mythicalLibrarian to run after the recording has ended.

This will work where mythicalLibrarian is setup as userjob 1.   Modify the job number to meet your setup.


Saturday, August 11, 2012

How I Manage My Music Collection

I've been using iTunes to manage my music since 2005 after an unfortunate iTunes folder organization mishap.  Prior to then I'd been using a combination of Windows Media Player and Musicmatch Jukebox for management for music I had on Samba Shares.  I used the convention Artist - Album (Year) and iTunes used Artist/Album  so my I had a ton of orphaned folders and I still do :-)

I gave up and eventually allowed iTunes to just handle the folder structure since I had a dedicated Mac Mini at that point. I would rip CDs and let iTunes convert them to 192kbps mp3s and then manually copy to the Samba share.  I had a local copy and a copy on my NAS.  This was tedious but I never wanted my entire library to become mangled again.

I moved up to dedicated NAS instead of Samba Shares on a windows media center.  The problem with NASes is that if a proprietary has has a logic board failure or raid controller failure you must purchase from the same manufacturer if you want your data.  I had a logic board failure and was down for 6 weeks during the holiday season from November  2009 - January 2010. Upon placing the drives back in the NAS in the correct order a reboot of the NAS reinitialized the raid array and wiped all of my music, movies, documents, backups and website starting from 1992. :-((((((

I cried and have spent the better part of  2 years recovering the data from old hard drives and online backup.

I now only buy mp3 from iTunes, Amazon, Google play or directly from the artist or distributor.   Most of these non iTunes MP3 markets have an iTunes and Windows Mediaplayer app that adds the music that you've purchased and downloaded into your itunes music collection.  All my iTunes purchases are automatically downloaded to the library and copied over to the NAS.  Google Play and Amazon purchases require and extra step to make this happen.  It's usually just a few clicks to identify the music on their websites and initiate a download to their own app that adds the content to my iTunes library.  Google Music Manager and Amazon Music Importer also copies that music to the cloud so I can listen pretty much from any mobile device or computer.


All my music is in the cloud, locally on a Mac and on a Nas so I never have to worry about losing it anymore.

Here's the simple bash script that runs at the top of the hour to copy my music over to a mount on my NAS

Crontab Entry
5 * * * * /Users/xxx/itunesbackup.sh


Script
##########################


#!/bin/bash

cd /Users/xxx/Music/iTunes/iTunes\ Media/Music/

rsync -av . /Volumes/Music/

exit

Sunday, August 05, 2012

Wii U Experience - Atlanta Ga

I was invited to the Nintendo Experience for hands on game play to the successor of the Nintendo Wii. I brought my 10 year old cousin as a guest because he will have a great what did you do over the summer story to tell.

I was pretty impressed by the playback and in improved control.  Games are finally in HD. 

I played New Super Mario Bros U, Luigi's Mansion, Rayman Legends and Just Dance 4.

I smoked a family of 3 playing Just Dance 4 dancing to Rock Lobster. With the Wii Motion plus controller tracking your hands and body's position and movement in space and in relation to 3 other players is a modern programming miracle.  Ubisoft has a hit on their hand. Its no Xbox Kinect but has

There was a little bit of stutter in New Super Mario Bros U with 4 players connected.  I'm hoping this was just a bug in the demo unit. Hopefully Nintendo can work out the I/O or processing hiccup. Overall I'm really excited because up until now I thought the Wii U would be underwhelming after I saw the E3 Keynote. I sent Nintendo a social message blast to go back to the drawing board.

Nintendo if you're listening, please include the following for a hit:

Ethernet! Cmon
DLNA playback
Bluray Support
Skype and/or Google Talk chat with the GamePad or release a Bluetooth or USB HD Webcam
Use USB 3.0 for future proofing








Wednesday, July 11, 2012

Protect Yourself on the Net

Here are some free suggestions to protect yourself from Virus, Trojans and Email Hacks in this order.

1) Download and Install Spybot Search and Destroy.  This will scan and eliminate spyware, adware, key loggers, browser hijackers and trojans. http://www.safer-networking.org/en/mirrors/index.html

2) Download and install Microsoft Security Essentials or  AVG Anti-Virus Free 2012 (The free edition only.  The Internet Security Edition is not needed) http://windows.microsoft.com/en-US/windows/products/security-essentials/download or http://free.avg.com/us-en/homepage

3) Change your email password to a strong password using numbers, mixed case or special characters once your computer is clean.  (This will make it harder for brute force password guessing programs to guess your password) Randpass.com can help you with choosing a stronger password. http://www.randpass.com/


Optional

1) Switch to Gmail and use Google Authenticator that requires your email password and an additional password sent to your mobile phone or designated voice telephone to access your email.
http://support.google.com/accounts/bin/answer.py?hl=en&answer=1066447

2) Use LastPass to help keep track of all your web passwords and generate secure password https://lastpass.com

Tuesday, June 12, 2012

Dear Nintendo, I've loved you since I was old enough to hold a controller. Please shelve the Wii-U and go back to the drawing board. -Noah

Wednesday, June 06, 2012

6.5 Million #LinkedIn Passwords leaked. I recommend using @lastpass to manage and change your passwords! http://ping.fm/uWaZX #in

Saturday, May 26, 2012

Adding Music on Hold Via The Logitech Media Server



Adding Music on Hold Via The Logitech Media Server (aka Squeezebox Server)

I had an AHA moment this morning when I thought about my abismal music on hold situation on my asterisk server.   I checked my logs for the first time in awhile and found out that people waiting on hold hadn't been receiving music while on hold for quite some time because I migrated to a different mount point for a new raid array.


I did a little research and found out this article (Using Slimserver for Music on Hold )that I could already use the  Logitech Media Server's mp3 stream to loop thru a playlist of selected songs.



Here's how it works.


mkdir /var/lib/asterisk/mohmp3-dummy
touch /var/lib/asterisk/mohmp3-dummy/dummy.mp3

Install mpg123 if you don't have it already
Edit your musiconhold.conf. and note the location of mpg123.

[default]
mode=custom
dir=/var/lib/asterisk/mohmp3-dummy {COMMENT}daab{/COMMENT}
application=/usr/bin/mpg123 -q -r 8000 -f 8192 -s --mono http://localhost:9000/stream.mp3



Reload asterisk
asterisk -rx 'reload'


Go to your Logitech Media Server/Squeezebox server's website.   Usually http://ip:9000.  Click on the player pulldown and you should see an entry for mpg123 from ipaddress.


From there  start creating a playlist and don't forget to save it and set it on repeat.