Posts tagged: php

Taming the Cloud: Introducing Gobble for Google docs

With the exception of SourceForge and Project Hosting on Google Code, there really is no free ride for Open Source, freeware, and shareware projects insofar as storage and bandwidth are concerned. As one of the earliest members of the Association of Shareware Professionals (circa 1985) and as a Hall of Fame inductee of the Shareware Industry Awards Foundation, we’ve always had a special relationship with shareware developers, most of whom are starving. So today we’re making a contribution to the community for the benefit of everyone involved in software development of any kind who needs an inexpensive storage and bandwidth solution for products they wish to distribute.

If you didn’t know, Google docs expanded its free offering this year in several ways. First, you now can upload any type of file up to a gigabyte in size. Second, for files that aren’t converted into recognized Google document formats, Google docs provides a free gigabyte of storage at no cost. And third, you now can buy additional storage in increments of 20 GB for only $5 a year.

You may also be unaware that the PBX in a Flash project provides an enormous source repository of just about everything connected with Internet telephony. Some of these products are open source while others are freeware or shareware, but they’re all available for your use from a single repository. We also provide one of the best forums in the business providing support from literally hundreds of telephony and Linux gurus around the world. While the gurus provide their time at no cost, the resources to support these projects are not free.

Google knols are one of the few cost-free platforms for preserving tutorials such as the main articles on Nerd Vittles. Our PBX in a Flash tutorial in knol format receives over 1,000 page views a week and is one of the highest rated, most frequently accessed knols on Google’s site. As time permits, we’re going to be migrating all of the more popular Nerd Vittles articles to Google knol-ville for posterity. Google knols house an incredible repository of medical reference materials. Hopefully others in the software development community will take advantage of this terrific resource in the future.

One of the drawbacks of Google docs has been Google’s insistence that you use a web browser and jump through several hoops even to download files which are tagged as publicly-accessible. Because many of our tutorials and scripts depend upon programmatically downloading files, we simply had to have a solution before Google docs storage would work for our project and many of our contributors.

Because many of you have contributed to Nerd Vittles in many ways over the years to keep the lights on, today we’re returning the favor. We’re releasing our new Gobble for Google docs app as GPL2 open source code. That means you can build your own public repositories on Google docs and download or let others download the files from the Linux command prompt whenever the need arises. Think of it as wget or curl for Google docs.

Before we get to the code and a brief tutorial on how to use it, we want to put in a good word for the folks that made this possible. If you haven’t heard of RentACoder.com, you’ve missed another great secret. The site actually has undergone a name change recently to better reflect their current offerings. vWorker.com (which stands for Virtual Worker) describes their new mission like this:

We changed our name to reflect the diversity of the many talented workers we have on the site. Back when I founded the company in 2001 we concentrated just on programming, and the name Rent a Coder fit us. But today in 2010, the site is not just coders, but also graphic artists, writers, translators, marketers, personal assistants and numerous other types of workers. Our new name reflects that and reminds employers that they can find all kinds of talent here.

As it happened, we needed a coder, someone who could translate HTML mumbo jumbo into a bash script to download files off of Google docs with no user intervention so we posted the following job announcement:

We distribute a CentOS-based, open-source Asterisk® PBX known as PBX in a Flash. The install requires booting of an ISO-based CD that sets up CentOS 5.5 and then downloads a payload file which is used to install the remaining components. We want to store these payload files in Google Docs for downloading and then use a bash install script (without user interaction or Google credentials) to retrieve the file anonymously for processing. We anticipate that the successful design will entail use of a combination of python or perl plus wget or curl. All of these tools are available in our base install of CentOS.

We knew at the outset that this would be a thorny problem with Google’s penchant for using multiple cookies and multiple layers of obfuscation. We learned all of that from our Google Voice adventures this past year. So we limited our search to top-ranked experts on the web site and ultimately accepted a bid from CoderDan in Romania. He spoke fluent English and finished the job in a matter of days. We had a dialog which consisted of about a half dozen emails before the final code was delivered. Once you’re happy with the code, then you release the funds which you’ve placed in escrow via PayPal at the beginning of the job. Because we had never used the site or CoderDan, we opted to use a Pay-for-Deliverables contract with an Expert Guarantee. What that means is that the contractor also must pay 10% of the cost of the job into the escrow account to essentially guarantee that they will complete the job and will do so in a timely manner. Not only did CoderDan complete the job, but he finished it in record time with some terrific code as you will see when you download it. All rights to the code belong to us, and we now are releasing it as GPL2 open source for the benefit of all of you. So… thanks to all of you who have donated to Nerd Vittles over the years. Here’s just one of what we hope have been many rewards from Nerd Vittles for your contribution. For the rest of you, enjoy! And don’t be shy about clicking the Donate button at the top of the page. Even small contributions matter and are greatly appreciated!


Gobble for Google docs Prerequisites. We’ve tested this application with CentOS 5.2 through 5.5, but it should work fine with most other Linux distros that have bash and wget support. It also should work fine with Mac OS X once wget support is added.

Installing Gobble for Google docs. We’re assuming that /usr/bin is in your search path and is an appropriate place to house this application. If not, substitute an appropriate directory in the first line below and execute these commands to install the software:

cd /usr/bin
wget http://nerdvittles.com/wp-content/gobble.tgz
tar zxvf gobble.tgz
rm gobble.tgz

Using Gobble for Google docs. Complete documentation for using Gobble for Google docs is available by simply executing the script with no parameters: gobble. In a nutshell, you first must use a web browser to upload a file to Google docs making sure to change the Private setting for the file upload to Public on the Web. This is very important since Gobble can’t download files from Google docs that require authentication with user credentials. Once the file is uploaded to Google docs, click on the Folder where you stored the file and then click on the File name you wish to download. In the right column of Google docs, there will be an entry entitled Link to this page. Click on the link and copy it to your clipboard. Using SSH, log into the server with Gobble and type gobble followed by the link you copied to your clipboard. For example, to download the latest version of PBX in a Flash, the command would look like this:

gobble http://docs.google.com/leaf?id=0B5oMpKm8e6A9Y2JlZDcyOWQtN2RiMy00NDhiLWFjODctOWFhYjIxZDU3ODc2&sort=name&layout=list&num=50


When the download completes, you’ll have a file in your current directory matching the name displayed in Google docs, e.g. pbxinaflash17551-i386.iso in our example. You’re now a Gobble expert. For any gurus who embellish this script and we would encourage you to do so, please document and share your enhancements with all of us. Just leave a comment below, and we’ll take care of the rest. Enjoy!


News Flash: Many of you know Jared Smith, who has been a fixture at Digium® for many years and was one of the authors of the first two editions of Asterisk: The Future of Telephony. We’ve just learned that Jared has recently taken over as the Fedora Project Manager which is excellent news for the Fedora project. You can read all about it here. Best of luck and best wishes in your new role, Jared!




Need help with Asterisk? Visit the PBX in a Flash Forum.
Or Try the New, Free PBX in a Flash Conference Bridge.


whos.amung.us If you’re wondering what your fellow man is reading on Nerd Vittles these days, wonder no more. Visit our new whos.amung.us statistical web site and check out what’s happening. It’s a terrific resource both for us and for you.


 
New Vitelity Special. Vitelity has generously offered a new discount for PBX in a Flash users. You now can get an almost half-price DID and 60 free minutes from our special Vitelity sign-up link. If you’re seeking the best flexibility in choosing an area code and phone number plus the lowest entry level pricing plus high quality calls, then Vitelity is the hands-down winner. Vitelity provides Tier A DID inbound service in over 3,000 rate centers throughout the US and Canada. And, when you use our special link to sign up, the Nerd Vittles and PBX in a Flash projects get a few shekels down the road while you get an incredible signup deal as well. The going rate for Vitelity’s DID service is $7.95 a month which includes up to 4,000 incoming minutes on two simultaneous channels with terminations priced at 1.45¢ per minute. Not any more! For PBX in a Flash users, here’s a deal you can’t (and shouldn’t) refuse! Sign up now, and you can purchase a Tier A DID with unlimited incoming calls for just $3.99 a month and you get a free hour of outbound calling to test out their call quality. To check availability of local numbers and tiers of service from Vitelity, click here. Do not use this link to order your DIDs, or you won’t get the special pricing! After the free hour of outbound calling, Vitelity’s rate is just 1.44¢ per minute for outbound calls in the U.S. There is a $35 prepay when you sign up. This covers future usage and any balance is fully refundable if you decide to discontinue service with Vitelity.
 


Some Recent Nerd Vittles Articles of Interest…

It’s TweedleD: Twitter & SMS Alerts with Every Asterisk Call

Twitter Direct Messages and SMS Instant Messages are great ways to send yourself important notes that you want to keep track of... privately. Today, we'll show you how to harness the power of Twitter and SMS to announce every call on your Asterisk® server with the name and number of the caller as well as the DID of the incoming call. Reconfiguring your Asterisk server takes less than 10 minutes. We think you'll find this to be the perfect complement to our free Urang II desktop screenpop utility.

Prerequisites. You'll need one of the Asterisk aggregations to get all of this working quickly. At a minimum, you need Asterisk 1.4 or 1.6, FreePBX, Apache, PHP 5, PHP/AGI, and SendMail or an equivalent. You'll also need a service that provides CallerID name lookups such as CallerID Superfecta. We're assuming you already have all of these components working including outbound email which is necessary to deliver the SMS alerts.

Overview. The design strategy for TweedleD is pretty straight-forward. When a call comes into your server, FreePBX should catch the call in an inbound route that looks for incoming calls on a particular DID. A CallerID Lookup source will be used in the Inbound Route to look up the name of the caller based upon their CallerID number. Then we will use a Custom Destination to route the call to a special Asterisk context which will run the TweedleD AGI script. This script actually sends out the Twitter Direct Messages as well as the SMS messages to your cellphone. Once the script completes its work, the context will send the call along to its final destination, e.g. an extension, a ring group, a day/night control, or an IVR.

NOTE: There is a 100-150 API calls per hour per IP address limit with the Twitter API. If you also are using one or more Twitter clients at your site, this is something worth keeping in mind if you have a busy phone system.

1. FreePBX Custom Context. The trick with designing FreePBX dialplans is to build them in reverse. So we'll start with the custom context and work our way back to the inbound route. First, log into your server as root and edit extensions_custom.conf in /etc/asterisk. At the end of the file, we want to create a new context that looks like this. We've provided several sample destinations at s,5 to show you the syntax. The first routes a call to an extension or ring group number. The second routes the call to Day/Night Control #1. And the third routes the call to an IVR. To find the correct IVR number or day/night control for what you want to do, review the IVR and app-daynight contexts in extensions_additional.conf to find the one you need. Obviously, you only use one s,5 line. Comment out the remaining ones as shown below. For Asterisk 1.6, replace the vertical bars in line s,3 with commas.

[custom-twitter]
exten=>s,1,Answer
exten=>s,2,Wait(1)
exten=>s,3,AGI(nv-twitter.php|${CALLERID(name)}|${CALLERID(num)})
exten=>s,4,NoOp(${CUSTOMDATA})
exten=>s,5,Dial(local/701@from-internal)
;exten=>s,5,Goto(app-daynight,1,1)
;exten=>s,5,Goto(ivr-6,s,1)
exten=>s,6,Hangup

2. Installing PHP/AGI Scripts. Next we need to install the script that actually generates the messages for Twitter and SMS. In addition, we'll install Justin Poliey's terrific twitter.lib.php which is a PHP implementation of the Twitter API that lets you do just about anything with Twitter that you could do with the Twitter API itself. For a good writeup on the capabilities of twitter.lib.php, see Antonio Lupetti's article. To install the necessary code, issue the following commands while still logged in as root:

cd /
wget http://bestof.nerdvittles.com/applications/TweedleD.tgz
tar zxvf TweedleD.tgz
rm TweedleD.tgz
cd /var/lib/asterisk/agi-bin

3. Configuring TweedleD. Now we need to configure the PHP script with your Twitter and SMS credentials so that TweedleD knows where to send the messages. Edit nv-twitter.php in the /var/lib/asterisk/agi-bin directory on your server: nano -w nv-twitter.php. You'll see a section of code near the top of the application that looks like this:

//-------- DON'T CHANGE ANYTHING ABOVE THIS LINE ----------------

$tweet = 0;
$username = "your-twitter-name";
$password = "your-twitter-password";
$user4msg = "recipients-twitter-name";

$sms = 0;
// $smsaddress = "1234567890@txt.att.net" ; // AT&T
// $smsaddress = "1234567890@message.alltel.com" ; // AllTel
// $smsaddress = "1234567890@messaging.nextel.com" ; // Nextel
// $smsaddress = "1234567890@messaging.sprintpcs.com" ; // Sprint
// $smsaddress = "1234567890@tmomail.net" ; // T-Mobile
// $smsaddress = "1234567890@vtext.com" ; // Verizon

$debug = 0;
$newlogeachdebug = 1;

$emaildebuglog = 0;
$email = "yourname@yourdomain" ;

//-------- DON'T CHANGE ANYTHING BELOW THIS LINE ----------------

There are four things you can enable and, depending upon what choices you make, you need to add your credentials for the various options. Let's go through them in the order they appear.

To enable Twitter Direct Messages, change $tweet=0 to $tweet=1. $username and $password are used to set your Twitter login credentials for your Twitter account. You must have one! $user4msg is the Twitter account name where the DMs should be delivered. They do not necessarily have to be delivered to your Twitter account although they can be. Be sure to preserve the quotes! And, remember, you can only send direct messages to people on Twitter that you are following, and they must be following you as well. If in doubt, attempt to send a direct message in Twitter to the desired recipient. Then you'll know for sure. TweedleD provides no error messages if things don't work. :-(

To enable delivery of SMS messages to your cellphone, set $sms=1. TweedleD actually delivers SMS messages using email. Virtually all of the carriers provide an SMS-Email Gateway for this purpose. The trick is knowing the email domain for your desired carrier. The full list is available here. And here is an even newer Email to SMS Gateway list. In the script, we've provided samples for the major U.S. carriers so, if yours is in the list, just uncomment the appropriate line by removing the leading // on the line and replace 1234567890 with your 10-digit cellphone number.

If you want a debug log generated for each call, set $debug=1. The default is to overwrite the previous log (/var/log/asterisk/nv-twitter.txt) with each new call. If you'd prefer an ever-growing log, set $newlogeachdebug=0.

The debug log also can be emailed to you. Set $emaildebuglog=1 and enter your email address in $email.

When you've completed the configuration, save the file (Ctrl-X, Y, Enter) and reload the Asterisk dialplan: asterisk -rx "dialplan reload".

4. FreePBX Setup. Finally, we need to configure FreePBX to support TweedleD. We'll add a Custom Destination and then adjust our inbound route(s) to support the custom context we added in Step 1. Open FreePBX with a web browser and choose Admin, Tools, Custom Destinations, Add Custom Destination. For the Description, call it TweedleD. For the Custom Destination, enter the following: custom-twitter,s,1. Then click Submit. Now edit your Inbound Routes for the DIDs for which you wish to activate TweedleD. For each inbound route, make sure you have activated a CallerID lookup source and then set the destination to: Custom Destination: TweedleD. Save your changes and reload the dialplan.

Trying Out TweedleD. Now you're ready to place a test call. Just call into your system on one of the DIDs that has been configured for TweedleD. On the Asterisk CLI, you should see an entry that identifies the CallerID name and number of the caller. And, if you've activated delivery of notifications to Twitter and/or SMS, the messages will magically appear within seconds. Enjoy!


Tips of the Week. If you hurry, you can get 25GB of free, password-protected online storage with the new Microsoft SkyDrive offering. Or, for a free incoming call number for your Skype account, check this service out. A new precompiled version of Asterisk 1.6 for Mac OS X Leopard has been released. You can download it here. Finally, Sprint is offering a Netbook for 99¢ with any 2-year EVDO contract at Best Buy stores this week. Regular price for the Compaq Mini is $389.99. Add your cell phone or Asterisk DID to the DO NOT CALL Registry. Just call 888-382-1222 using the CallerID of the number to wish to block.


Sign of the Times. Before you get too comfortable with all your free Google apps, you might want to read this article. Despite assurances to the contrary from Google's President of Enterprise, it seems that the free version of Google Apps has quietly disappeared.

Update: Google Apps team invokes Brain Fart defense saying they momentarily forgot about "free" but it won't happen again. Heh, heh. Official Blog Posting.


VoIP Users Conference. Come join the fun. The VoIP Users Conference is held every Friday at noon, Eastern time. ISN: 8647*1061 (Hint: 8647 spells VOIP on your phone).


The World According to Twitter. Be on the lookout for David Pogue's new book, The World According to Twitter. It goes to press today! Incidentally, Pogue's books are just about the only reasonably priced tech books available for the Kindle, and they're all excellent.

Tomorrow's the Big Day. The last time this happened, it was a pretty quiet year. Just after noon tomorrow comes your once-in-a-lifetime moment when the time will officially be 12:34:56 7/8/9. The last time we had this much fun in our lifetime was... uh, about a year ago: 01:23:45 6/7/8. Can't wait for next year's thriller: 23:45:67 8/9/10. Ooops! That won't work on most clocks. Will it? Amazing what you can learn on Twitter. Isn't it? Thanks, @ejovi and @ev.




Need help with Asterisk? Visit the PBX in a Flash Forum.
Or Try the New, Free PBX in a Flash Conference Bridge.


whos.amung.us If you're wondering what your fellow man is reading on Nerd Vittles these days, wonder no more. Visit our new whos.amung.us statistical web site and check out what's happening. It's a terrific resource both for us and for you.


 
New Vitelity Special. Vitelity has generously offered a new discount for PBX in a Flash users. You now can get an almost half-price DID and 60 free minutes from our special Vitelity sign-up link. If you're seeking the best flexibility in choosing an area code and phone number plus the lowest entry level pricing plus high quality calls, then Vitelity is the hands-down winner. Vitelity provides Tier A DID inbound service in over 3,000 rate centers throughout the US and Canada. And, when you use our special link to sign up, the Nerd Vittles and PBX in a Flash projects get a few shekels down the road while you get an incredible signup deal as well. The going rate for Vitelity's DID service is $7.95 a month which includes up to 4,000 incoming minutes on two simultaneous channels with terminations priced at 1.45¢ per minute. Not any more! For PBX in a Flash users, here's a deal you can't (and shouldn't) refuse! Sign up now, and you can purchase a Tier A DID with unlimited incoming calls for just $3.99 a month and you get a free hour of outbound calling to test out their call quality. To check availability of local numbers and tiers of service from Vitelity, click here. Do not use this link to order your DIDs, or you won't get the special pricing! After the free hour of outbound calling, Vitelity's rate is just 1.44¢ per minute for outbound calls in the U.S. There is a $35 prepay when you sign up. This covers future usage and any balance is fully refundable if you decide to discontinue service with Vitelity.
 


Some Recent Nerd Vittles Articles of Interest...

Ringbinder theme by Themocracy