Archive for the ‘Tutorial’ Category

Build your own URL shortener

Monday, August 30th, 2010
There are a lot of URL shorteners out there such as bit.ly, tinyurl.com, is.gd, tiny.cc. The list of services is large. For those of you that don’t know what a URL shortener is, it’s a piece of software that converts very long URLs such as:

http://www.blyon.com/blog/index.php/2010/08/28/build-your-own-url-shortener

Into: http://blyon.com/?efa

This make the URL easy to cut and paste and reduces the characters you use for things such as Twitter.

I’ve been using TinyURL.com for ages. This morning I wondered to myself, “why not just use blyon.com?” After all, the domain is shorter than TinyURL by 3 characters and if it’s just me using my service the hash only needs to be about 3 characters long because I am not storing millions of URLs. Other services use a long hash (7+ characters) because they need more unique ways to identify URLs.

It took all of 30 minutes to write the code, and maybe another 30 to debug it.

Here’s how it works and how to setup your own!

Go to http://www.blyon.com/t to input the URL and get the short URL which uses http://blyon.com/? as the base. There’s a simple PHP script inside /t/ which creates the hash and puts it into a two table MySQL database. I used /t/ just because I already had something at the root of blyon.com.

I added another snippet of code on blyon.com’s index.php page which figures out if someone is trying to lookup a hash or not. If it finds a hash that’s valid, it does a 302 redirect to the right location. The 302 redirect is an easy location director built right into HTTP, so basically you’re telling a browser that goes to the short URL to go somewhere else.

Now, why do this? For starters I was trying to wake up and wanted to have something to do while drinking coffee (the NPR stream was down). However, there may be a lot of SEO reasons to do this. For one, all my links I post are linked back to blyon.com, which means if something I tweet goes around the block a few times, it will all point back at blyon.com. Taking this one step further might mean that I should also allow for special keywords to be created, thus helping google learn indexicals that I want valued for my web site. The third great reason to do this (besides keeping oneself busy while drinking coffee) is to maintain your own links. If TinyURL goes down someday, everything you have ever linked to will stop working as well. However, who’s to say your (or my) admin skills are better than theirs.

Anyway, here’s the code!

The entire package as a tar: redir.tar.gz

To create the TinyURL you need this PHP code (my /t/ index page): index.php

The database include code: dbconfig.php

To figure out if a request is for your main index page or a shortened URL: mainindex.php

The MySQL database you’ll need: redir.mysql

PS: Thanks to Nathan Hickson for helping me debug this.

Get the iPhone4 on to T-Mobile

Wednesday, August 4th, 2010
Finally! The iPhone4 can be carrier unlocked, which means you can put the phone on any GSM network you would like! It feels great to enjoy freedom from the clutches of AT&T — their data services are over priced, their customer service is awful, their contracts and plans are nearly fraudulent, they opt-in to governmental monitoring, and to top it off their network barely works in most major markets. The alternative I prefer is T-Mobile. T-Mobile’s Edge service is not the fastest in the world but at least it works and is more reliable in the markets I use it in.

Here is a step-by-step instruction set to migrate your iPhone4 from AT&T to T-Mobile.

Step 1: The Micro SIM

Engadget published an article on how to create your own Micro SIM from your old SIM, however, it is missing a bunch of details:

First, there are several types of SIM cards that are out there in the wild. T-Mobile has two which are interchangeable. One of them will not work as a Micro SIM because it has connectors which are too wide. If you try to modify one of the older types you’ll end up destroying the SIM card and be left with nothing.

You can go to a T-Mobile store and buy a new SIM for $20. What you need is a 39.01a type SIM (shown in the picture) which is thinner and has smaller electrical contacts than the older types. [If anyone has more detail on the differences between the different SIM cards, please let me know and I will update the article to make this more clear.]

The SIM itself is the metal contact portion of the card, so what you’ll need to do is cut the plastic of the SIM to fit inside the iPhone SIM cradle.

Removing the actual sim is very easy, just get a staple and fold it out a bit and push it solidly into the center hole located on the side of the phone. The SIM cradle will pop free. Pull out the old ugly nasty AT&T SIM and use it as a template for the new T-Mobile SIM card.
Do your best to align the metal contact area on the T-Mobile SIM with the existing AT&T Micro SIM, pay close attention to orientation of the notch cut into the SIM cards, keep those in the same direction. If you have the right SIM style, it’s pretty easy, you really just need to align the SIM as closely as possible.

When cutting out the SIM, do not initially use scissors — doing so will put a lot of stress on the SIM itself and if you hear a “crunch” noise you’re destroying the SIM. I used a knife to cut out the SIM and a very sharp set of scissors to trim it in order to get it to fit into the iPhone4 SIM cradle.

Make sure that there’s no protruding shards of plastic, if there are, you may have a very hard time removing your SIM card.

Step 2: Jailbreak

This step is pretty simple. Using your iPhone4 (connected to wifi or some network) browse to www.jailbreakme.com and follow their really simple instructions to jailbreak the phone. Once the phone is jailbroken, you can move on to further steps.

If you find you can’t “slide to jailbreak” you may need to factory reset your phone using iTunes. I had to factory reset because apparently the www.jailbreakme.com site needs a fresh install.

If you run into problems or want to know more about this process, follow the direction on http://blog.iphone-dev.org/

Step 3: Carrier Unlock

There will be a new application on your iPhone desktop called Cydia, just open Cydia, allow it to upgrade itself (upgrading the packages ensure you get the most current packages). Search for the application ultrasn0w and install ultrasn0w. Once it is installed, you will be prompted to reboot the phone.

Before you do this, please take the time to visit the Dev-Team Blog to read more about their work and possibly give them a donation to help them with further efforts.

They also have much better and in-depth tutorials on Unlocking and Jailbreaking phones.

Step 4: Swap the SIM

After the phone has rebooted, make sure the phone activates and is functioning before you swap the old AT&T sim out with the new T-Mobile SIM.

Step 5: MMS and Internet setup

Make sure you have a data plan with T-Mobile, they have an unlimited service available which can be ordered by asking for the Blackberry data service. That will come with SMS and MMS services as well.

First you need to re-enable your data plan and MMS, you can do that by going to Settings -> General -> Network -> Cellular Data Network and enter the following:

Cellular Data:

APN: wap.voicestream.com
Username: [do not put anything]
Password: [do not put anything]
MMS

APN: wap.voicestream.com
Username: [do not put anything]
Password: [do not put anything]
MMSC: 216.155.174.84/servlets/mms
MMS Proxy 216.155.165.50:8080
MMS Max Size: [do not put anything]
MMS UA URL: [do not put anything]
Internet Tethering

APN wap.voicestream.net
Username: [do not put anything]
Password: [do not put anything]

Step 6: Canceling your AT&T contract

Dial customer support at 1-800-331-0500, enter your old phone number that was on the old AT&T SIM. Wait to get a customer service person on the phone and tell them you are moving to Spain or somewhere like Brazil and ask to cancel the service. By telling them you’re leaving the country they’ll give you 60 days to re-activate service.

If you have the time, throw a fit and tell them you never signed a physical contract. Just sit back and demand they find your signature and the AT&T cancellation person will actually call the Apple store where you bought the phone. It will at least cost AT&T some money for the hour they will spend digging around for your information.

**Tip For Jailbreakers: Buy the phone under contract and sign “Apple Store Sales Person” when you agree to the contract. Then sing your real name on the bill itself. That will result in no termination fees because you can contest you never signed the contract! (I know it’s evil but so is AT&T)

Problems: Facetime

T-Mobile apparently does not have support for Facetime. I’ve tried a few different methods to get it to register while on T-Mobile but no luck yet. This is all so fresh that I am sure there will be a patch to re-enable it soon. I will update this post when there is a method to update the phone to enable Facetime.

Using Squid Proxy to Fight DDoS

Friday, July 24th, 2009



Complicated web applications are often difficult to scale, as a result they become easy DDoS targets. However, making them scale is easy with front-end proxy servers. The added scale gives an application more resiliency to DDoS attacks.


When setup correctly, the proxy “network” becomes the target of any malicious activity and can be placed globally while still keeping the original web application in same location for content.


This is by no means new, it’s been done all over the Internet and in some cases is the base of a bunch of different companies. This is just a simple tutorial that is meant to help people understand how this works.


Proxy servers can also be used with a dynamic caching function which can provide caching which will help increase the speed and functionality of the web site.

Positives:

  • Scales web server farms
  • Increases reach
  • Can accelerate a web site
  • Can provide additional security layers

    Negatives:

  • Adds an additional layer of debugging
  • Slows down long dynamic pages if they are not cacheable
  • Expensive to operate


    To start, I recommend using Squid Proxy version 2.7, it is available at http://www.squid-cache.org/


    After downloading the package, the vanilla build will suffice for most needs. You can use FreeBSD as the operating system and simply make install on the /usr/ports/www/squid package or build the package with a ./configure –prefix=/usr/local ; make install


    Often the prefix is /usr/local but determine what is appropriate for your OS.


    After the build has finished you will need to configure Squid, attached below is a sample configuration file:

    acl all src 0.0.0.0/0.0.0.0
    acl DO_NOT_CACHE urlpath_regex -i cgi-bin \? asp php css js
    acl manager proto cache_object
    acl purge method PURGE
    #
    refresh_pattern .               0       20%     1440
    #
    http_access allow all
    icp_access allow all
    #
    request_header_max_size 10 KB
    #
    cache_dir ufs /vol1/cachedir 512 16 256
    #
    visible_hostname supersite.com
    pid_filename /var/run/squid.pid
    #
    cache_access_log /var/log/httpd/proxy-a_access.log
    #
    cache_mem 64 MB
    maximum_object_size_in_memory 64 MB
    #
    httpd_accel_host virtual
    httpd_accel_uses_host_header on
    #
    #
    connect_timeout 30 seconds
    #
    emulate_httpd_log on
    hierarchy_stoplist cgi-bin ? asp css js php
    http_port XX.YY.ZZ.AA:80
    http_port XX.YY.ZZ.BB:80
    negative_ttl 60 seconds
    no_cache deny NOCACHE
    

    The configuration options are all explained in the default configuration file, the only major items to change are the http_port list, which should be the IP address it should respond on and the cache configuration. Some sites may have special items that should not cache. Often css and js should cache, but for this example they are dynamic.


    The logs will be written to /var/log/httpd/proxy-a_access.log in a combined Apache style format.


    When starting the squid, you will need to create a /cache directory on the server, simply run:


    mkdir /vol1/cachedir
    chown squid /vol1/cachedir

    You will also need to Create swap directories so Squid can run:


    /usr/local/bin/squid –z


    You will also need to teach squid how to communicate back to your “real” or “backend” web farm, often the DNS for www points to the IP address squid is answering requests for, this can be done using the /etc/hosts file:


    XX.YY.AA.BB www.mysitedns.com


    Replace the example above with the real IP address of the web farm and the host entry you want to be used to reach the IP address.


    Once squid is running and answering requests (/usr/local/bin/squid -k reconfigure /usr/local/etc/squid.conf) and the cache is working, it tends to stay stable until the hardware fails or you become under DDoS attack, which may require some additional ACLs within the squid.conf or SYN cookies configurations on the OS itself.


    Scaling squid is also not very difficult, it’s possible to load balance a farm of Squid servers with any standard load balancer, and have the requests still return to the same web farm, which may or may not work with any given user authentication / sessions setup.


    Blocking a given attack in Squid is trivial, however, if there are hundreds of Squid servers to configure at the same time, this may require some special configuration management that could require some development effort.


    Often most attacks have an empty or mal-formed User-Agent, this simple ACL will block 99% of invalid User-Agent attacks:

    acl OK_BROWSER browser a b c d e f g h i j k l m n o p a r s t u v w x y z 1 2 3 4 5 6 7 8 9 0 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
    acl DO_NOT_CACHE urlpath_regex -i cgi-bin \? asp php css js
    http_access allow OK_BROWSER
    http_access deny all
    http_access deny manager
    http_access deny purge
    icp_access allow all
    


    You can also create a deny filter by creating an ACL that will deny rather than allow, the above ACL requires the user to have an VARCHAR in their User-Agent, which is pretty wide, so denying a specific item can be done like this:


    acl BAD_BROWSER browser Attack-Bot


    Add the deny line as the first line in the http_access ACL:


    http_access deny BAD_BROWSER


    Blocking a specific URL can look like this configuration line (which is designed to block most malicious requests):


    acl BLOCK_URI urlpath_regex -i \.exe \.\./\.\. \.\.\. \.ida \.idq \.IDA \.cnf \.asp \.dll 333-3333 test999 passwd /etc \` boot \.exe cmd \./\./ filenumber \% \* \; SELECT \\\.\.\\ \/\.\.\/


    Configuration of connection rate limiting looks like:


    acl 8conn maxconn 8


    And blocking a specific source address prefix:


    acl ip_addr1 src 192.168.1.0/24


    Just ensure that the ACL that is created is also configured in the http_access deny/allow list properly. Squid also needs to be told to re-read the configuration file, this is done by sending squid a –k reconfigure flag which will simply reload the rules without impacting traffic.


    To enable reverse proxy of SSL with the Squid cache owning the SSL certificate, you can use a pem cert and the following configuration line:


    https_port IP:443 cert=/usr/local/etc/squid/certs/COMPANY/COMPANY.pem key=/usr/local/etc/squid/certs/COMPANY/COMPANY.key


    Good luck and happy calamari

  • Watch and Stream Cable TV with your Mac via FireWire!

    Wednesday, July 1st, 2009

    No home office is complete without some distracting TV to watch. Originally I was going to install a TV in my office, but I thought “I have this nice display, why do I need a TV?”. Well, after a little digging I did manage to get the FireWire feed off my Comcast box working well. This works for any cable box that has an enabled FireWire port, so this is not limited to Comcast.

    This works thanks to a 2004 FCC mandate which requires cable companies to provide a functional 1394 (FireWire) port on request. The main issue is that there’s no real easy instructions on how to attach to the FireWire port and control it with a Mac (until now).

    Once I found the right software, getting it all working was actually very easy. In fact, for technical people, it is less work than using a Slingbox.

    The instructions here are for the Mac, but there are some links at the end of this article to help the PC folks out there too. On Linux, I am sure this is a cakewalk because Video4Linux is very feature rich and attaching to the FireWire device is easy.

    Step 1 – Connect the Firewire

    Comcast STB Firewire ports This step is rather self-explanatory, but hey… every time I fly somewhere, someone tells me how to buckle my seatbelt. So, connect your Comcast box to your Mac via Firewire. You should find a Firewire port on the back of your Comcast box. On my Motorola DCT-6412 the Firewire is on the back.

    Step 2 – Install VLC

    Install the current version of VLC. You can find the most current DMG here. The install is very clean because the folks at the VideoLAN Project have really done a fantastic job creating a tier 1 product.

    Just install VLC and we’ll come back to it later.

    Step 3 – Install Apple’s FireWire SDK

    Download and install the FireWire SDK, it’s a bunch of developer tools, example projects, documentation, and other components that will really help you get this thing working. The actual “example” tool kit we need is called the AV/C Device-Control Panel.

    First download the SDK by following this link: Apple Development Kits. This requires an Apple developer account. The kit you want to download is 39.6 MB large and is called, “FireWire SDK 26 for Mac OS X (DMG)”.

    Download and install the SDK. It will create a new directory called “Developer” which you should be able to locate via Finder. Inside Developer is another directory called, “Applications”, and inside there is “FireWireSDK Applications”.

    The full path is: /Developer/Applications/FireWireSDK Applications

    You should see an application called AVCBrowser, just double click that.

    Once the AVCBrowser is open, you should see your STB appear on the list. In my case it looks like this:



    Simply click on “Open Device-Control Panel”.

    This should bring up another window that looks like this:



    Click on the “Panel” tab and click “Open Device”, followed by “Start Viewer”:



    Once you click “Start Viewer” it should create a socket for VLC to attach to the FireWire device and launch VLC. Within seconds you should see whatever channel your STB is tuned to.



    Using the panel you can change channels, adjust volume, etc!

    Step 4 – Experiment and Enjoy!

    VLC is a feature rich application which works very well for this type of use. There are a few things you might want to play with before settling down with “it works”.

    Streaming

    VLC has a fantastic Streaming/Transcoding Wizard which will allow you to re-broadcast (stream) your feed.

    When streaming your TV, it makes a Slingbox obsolete. Just export the stream to your lan or to the Internet using Multicast or a variety of other interesting streaming methods.

    There is a fantastic tutorial on how to stream using VLC here.

    I highly suggest you play with this. If you have a dedicated Mac powering your stream, you can export the stream and watch TV around the house/office over wifi.

    Interlaced video

    Comcast also tends to broadcast their channels interlaced, thus enabling the de-interlace option in VLC is a good idea, I usually use “BOB” as the de-interlacing method.

    DVR/save shows

    There’s a very easy tab within VLC which will allow you to both save and stream a feed. Likewise you can also just save what you’re watching. Just look for the “Streaming/Saving” option in “open network”. The Streaming/Transcoding wizard will also let you “Save to file”.

    Good luck!

    If you have improvements, suggestions, or additional how-to data, I will be happy to post them here with credit to you.

    Also please comment or email me your results, I would love to know if this helped people.

    Other useful links:

  • Replay Guide Windows Directions
  • MythTV Cable Boxes which support FireWire
  • Comcast Channel Listings
  • Video4Linux Wiki

    Barrett Lyon creates fun companies that do all sorts of innovative exciting things with video and security.

    CDN cdn
    BitGravityBitGravity Barrett Lyon
    BitGravityBitGravity
    Barrett Lyon
    LimeLight Networks LimeLight Networks
    EdgeCast EdgeCast
    CDNetworks CDNetworks
    Consulting Consulting
    Speaker Speaking Opportunity
    Speaker Speaking Opportunity
    Content Delivery Network Content Delivery Network
    Content Delivery Content Delivery
    Flash Streaming Flash Streaming
    Interactive Video Interactive Video
    Live Streaming Live Streaming
    Live Video Live Video
    Streaming Audio Streaming Audio
    Streaming Media Streaming Media
    Video Delivery Video Delivery
    Video Hosting Service Video Hosting
    Video Podcasting Video Podcasting
    Video Podcasts Video Podcasts
    Video Services Video Services
    Video Streaming Video Streaming
    Barrett Lyon Barrett Lyon
    Barrett Lyon Barrett Lyon
    Barrett Lyon Barrett Lyon
    Barrett Lyon Barrett Lyon
    Barrett Lyon Barrett Lyon
    Barrett Lyon Barrett Lyon
    Barrett Lyon Barrett Lyon

  • Export your Tweets with PHP

    Tuesday, June 30th, 2009

    Exporting your Tweets via PHP should be simple. There are several tools that exist but they are annoying and overly complicated.  If you want to print your last 20 Tweets on your web page (like I did with the front page of blyon.com), you can now use my simple script.

    The first hack at it failed quickly because Twitter actually rate limits how many times a single host can pull the XML data per-hour.  To fix the rate limit issue I added a very basic cache function to the script which limits the requests to 60 an hour.

    Setup and usage is simple, you include the PHP as you always would:

    include("./twitter-1.0.php");

    Configure the script by editing these items:

    /* define where to store the cached result */
    $CACHEDIR="/tmp/";
    
    /* define your username */
    $USERNAME="BarrettLyon";
    
    /* define the max number of tweets to output */
    $MAXTWEETS=20;
    
    /* error message when twitter fails */
    $ERRORMSG="Awh... Twitter is broken/down/not working/unhappy...";
    


    Then call twitterPrint() or just hack the script up to do what you want.

    If you make changes or have improvement ideas, just comment on this posting and I will update the code.

    Get the code here: twitter-1.1.php.

    UPDATE: I fixed a bunch of bugs, as a result I released v1.1.

    Barrett Lyon creates fun companies that do all sorts of innovative exciting things with video and security.

    CDN cdn
    BitGravityBitGravity Barrett Lyon
    BitGravityBitGravity
    Barrett Lyon
    LimeLight Networks LimeLight Networks
    EdgeCast EdgeCast
    CDNetworks CDNetworks
    Consulting Consulting
    Speaker Speaking Opportunity
    Speaker Speaking Opportunity
    Content Delivery Network Content Delivery Network
    Content Delivery Content Delivery
    Flash Streaming Flash Streaming
    Interactive Video Interactive Video
    Live Streaming Live Streaming
    Live Video Live Video
    Streaming Audio Streaming Audio
    Streaming Media Streaming Media
    Video Delivery Video Delivery
    Video Hosting Service Video Hosting
    Video Podcasting Video Podcasting
    Video Podcasts Video Podcasts
    Video Services Video Services
    Video Streaming Video Streaming
    Barrett Lyon Barrett Lyon
    Barrett Lyon Barrett Lyon
    Barrett Lyon Barrett Lyon
    Barrett Lyon Barrett Lyon
    Barrett Lyon Barrett Lyon
    Barrett Lyon Barrett Lyon
    Barrett Lyon Barrett Lyon

    P2P SIP URI Dialing!

    Monday, June 22nd, 2009

     

    There are thousands of people that operate their own Asterisk based PBX systems, yet they do not enable any method to allow for p2p sip URI dialing. These sip “targets” are very easy to enable and allow you to dial anyone that has also enabled the function. Dialing with SIP URI completely avoids toll calling and forces your Asterisk server to create P2P sip connections when you dial someone’s SIP URI. It makes a less complex phone call without a system administrator configuring a peer and best of all: It gets rid of phone numbers and your telco!

    How does it work?

    By creating a SRV record in DNS for your domain you can help remote PBX systems establish P2P calls for a specific extensions. For example, when someone calls me, my URI is resolved to my PBX (sip.blyon.com). When the call comes into my Asterisk box, blyon is setup as a extension, and that extension is connected to a phone or a context. As a result, if someone uses something like Xten to call blyon@blyon.com, I get a normal ring and phone call. When I use my Cisco 7960 phone and dial someone’s SIP URI it completes like a normal phone call.

    Why is this cool?

    This is great because it takes away any central control for locating people. The ENUM standard is nice, but gives someone else control over the mapping database and it keeps an ugly old phone numbers in place. I really don’t want to dial phone numbers 10 years from now, I much rather just give someone my email address and have that map to my phone. If I need to call a business, I much rather just call pbx@somecompany.com then find some obscure phone number.

    If more people adopt this as a standard, it will be the method of choice for calling people and it puts power into the end user’s hands!

    Configuring the DNS SRV Record

    Much like an MX record that defines mail servers for a domain, you can use an SRV record to define your PBX server for a domain. My domain blyon.com has a PBX and I simply created the SRV record for it:

    In bind it would look something like this:

    _iax._udp               SRV     10 10 4569 iax2.blyon.com.
    _sip._udp               SRV     10 10 5060 sip.blyon.com.

    SIP and IAX2 are also host names that point to my PBX. When someone dials my URI extension@blyon.com, their client or PBX will do a DNS lookup and see that sip is available on port 5060 at sip.blyon.com.

    IAX records are not needed to make SIP URI dialing work. It is listed here to show that you can use other protocols like IAX.

    Create a whitepage TXT record

    To make it easy on others to locate your public extensions you should also create a protocol whitepage listing. I suggesst you map your user’s email addresses to extensions. If you do enable extensions to email addresses, you will want to include “email_addr” in your TXT record. A sample in bind looks like this:

    sip.whitepage		TXT	"email_addr, home, echo, pbx"

    “sip.whitepage” is the SIP protocol whitepages txt record, the first “email_addr” tells people that email addresses are mapped to extensions, and other non-email address extensions are listed. You should list each extension seperated by a comma.

    This TXT record is not a standard RFC, it’s something I thought would be helpful for people to establish SIP communications. This is not needed to make the system work.

    Configuring Asterisk to accept inbound URI calls:

    Under [general] in sip.conf make sure the following is allowed:

    [general]
    context=in                      ; Context for incoming calls
    allowguest=yes                  ; Allow or reject guest calls (default is yes, this can also be set to 'osp'
    bindport=5060                   ; UDP Port to bind to (SIP standard port is 5060)
    srvlookup=yes                   ; Enable DNS SRV lookups on outbound calls

    My specific context is “in” that’s where these calls go in the extensions.conf, this is the same place that I send inbound calls from a telco or another sip peer. Under your version of the “in” context just define your username mapping:

    exten => blyon,1,Macro(doDialExten,${BARRETT-VM},${BARRETT-HOME})

    I have BARRETT-VM and BARRETT-HOME setup so that it rings my home office and then sends the caller to voicemail if I don’t answer. So rather than putting my extension there, I just define my username that will be picked apart by Asterisk and matched.

    Configuring Asterisk to accept outbound URI calls:

    When you define a sip proxy for things like a Cisco 7960 or Xten, they forward all URI calls to the proxy. Asterisk does not have any idea what to do with them so they usually 404 error and as a result you can’t make your free calls to your buddy that also set this up and operates Asterisk. There is a simple fix however, in your dial plan after you have defined your local extensions and usernames, and after your _1XXX… toll definitions simply add this uri context or the exten directly into your dialplan:

    [uri]
    exten => _[a-z].,1,Macro(uridial,${EXTEN}@${SIPDOMAIN})
    exten => _[A-Z].,1,Macro(uridial,${EXTEN}@${SIPDOMAIN})
    exten => _X.,1,Macro(uridial,${EXTEN}@${SIPDOMAIN})

    Next make sure you add the macro into the extensions.conf in the area where you have your other macros defined:

    [macro-uridial]
    exten => s,1,NoOp(Calling remote SIP peer ${ARG1})
    exten => s,n,Dial(SIP/${ARG1},120,tr)
    exten => s,n,Congestion()

    After local extensions are not matched and toll extensions are not matched it will then take the call and make a SIP connection and away you go! Asterisk splits everything past the “@” in the call and makes an ${EXTEN} variable and a ${SIPDOMAIN} variable. If we match an lowercase alpha character in the ${EXTEN} then we simply just dial the EXTEN@SIPDOMAIN and away you go!

    Dialing with a free “Soft Phone”

    Any “soft phone” that can dial sip numbers including Micscrewsoft NetMeeting can now be used to make free inbound calls to your Asterisk box. If you setup an extension called pbx that goes to your main phone tree, and someone calls pbx@yourdomain.com, they would get your main tree just as if they called via a toll system. You can also do SIP calls without any fancy DNS by specifying the full hostname to the Asterisk/PBX:

    sip:exten@hostname.of.asterisk.server.com

    This requires you to know the exact IP or hostname of the Asterisk PBX, rather it would be more simple to have the one time DNS record and then you can give your extension@hostname.com.

    Dialing the URI with DNS is simply:

    pbx@blyon.com, blyon@blyon.com, or foo@bar given there are functioning SRV records.

    Use Xten without any provider or special settings to call a SIP URI

    If you would like to directly dial to another URI without setting up a SIP proxy, X-Lite allows for this option. To configure the direct dialing just go to System Settings -> SIP Proxy menu:

    Enabled: Choose "Yes"
    Display Name: Your calling name, maybe Joe Daly's PC
    Domain/Realm: Just put your ISP or local domain
    Direct Dial IP: choose "Yes"

    To make a call, simply specify the URI and away you go!

    This works great for dialing out, I have not spent any time to figure out how to accept P2P URI calls just via a raw softphone client, but I am sure they support it. If you know how to do this email me and I will add it to this doc.

    SIP URI and Vonage

    When I was a vonage user people could dial me by calling: sip:{Vonage_Phone Number 10 digits}@sip.vonage.net. This is a SIP URI but it would be much more clean if they had created SRV records for vonage.com.

    Dialing URI with an ATA

    This is doable but a little more complex, but for a free call, who cares? The ‘@’ is dialed as “**”, and ‘.’ and ‘:’ are dialed as a ‘*’. If you were to dial 10000000000@sip.vonage.net, it would be dialed like this: 10000000000**12*144*47*38

    To keep it easy we have replaced the hostname of sip.vonage.com with the IP address 12.144.47.38 (12*144*74*38). This really sucks having to dial using an IP address, so you may want to setup an exten for old phones that don’t support URI. Someone may also be kind and give us some clue on how to dial alpha with a standard phone, I am sure you can do it somehow.

    To setup an exten for the URI to make it simple (if you are using Asterisk):

    ; Bob
    exten => 1100,1,DIAL(SIP/bob@foo.com,120,tr);

    Test it!!!

    I have setup an echo test so you can just call into the system and see how it goes, just dial: echo@blyon.com

    You can also test your SRV and TXT records by running the dig command:

    # dig _sip._udp.blyon.com SRV
    
    ;; ANSWER SECTION:
    _sip._udp.blyon.com.    1200    IN      SRV     10 10 5060 sip.blyon.com.
    
    # dig sip.whitepage.blyon.com TXT
    
    ;; ANSWER SECTION:
    sip.whitepage.blyon.com. 408 IN    TXT     "email_addr, home, echo, pbx"

    You can also use my test form to see if your domain or others are configured for SIP URI.

    I also want to thank Victor Oppleman over at Vostrom for his help and research on this fun quick project, he’s a really smart guy!