Friday, January 28, 2011

Redirect all incoming root domains to www

Put the following in your default virtual host if you want to redirect all of your root domains to your www subdomain.

Add any additional tlds to the list if you need them, uncomment the RewriteLog directives to see if it's working right.

I wrote this for Amazon EC2 to work with their load balancer, which requires you use a cname and using a cname for the root domain is invalid in DNS.

RewriteEngine on
#RewriteLog "/var/log/httpd/rewrite.log"
#RewriteLogLevel 3
RewriteCond %{HTTP_HOST} ^([^\.]+\.(com|net|org|biz|ca|info|co\.uk))$
RewriteRule (.*) http://www.%1$1 [R=301,L]

Michelle Trusty

Thursday, March 26, 2009

Firefox go to url with middle click

I use a lot of plain text urls and find it annoying to have to go to firefox, and move my mouse to the address bar to paste in a URL after selecting it, yes, I know, I'm lazy. One version of linux/firefox at some point had middle click go to url enabled way back and I became very used to it. You highlight any url, put your mouse over your firefox window and middle click and it loads the url. For some reason this is disabled by default in Ubuntu 6.x->8.10/Firefox and I find that I have to go searching for the setting each time I install a new version. Well here it is, thanks to google and a site that tells you how to disable it, my firefox is back the way I like it on my new 8.10 desktop install:

In firefox's address bar type:
about:config
Search for middlemouse.contentLoadURL (hint: type middle in the filter bar)
Change the setting to true and middle click away :)

Michelle Agnew

Wednesday, March 25, 2009

Mount ntfs partition on boot in Ubuntu

I'm just setting up my desktop with a dual-boot of Windows XP (which has been the main OS for too long) and Ubuntu Intrepid Ibex. During the install I shrunk the windows partition and gave linux 50GB's or so of space. I wanted to have access to the mass of files in my windows partition and to be able to share them on the network.

Ubuntu will mount the directory when you click on it in the Places menu, but I wanted it mounted all the time. I came across a program called ntfs-config that sets up your fstab for you.

sudo apt-get install ntfs-config

This will update your fstab and mount your windows partition on boot.

By default samba won't allow you to share the files on the network unless you own them, so you need to make a modification to the fstab entry that was just created by ntfs-config:

sudo vim /etc/fstab
*look for the line with ntfs-3g
*mine looks like this: /dev/sda1 /media/windows ntfs-3g defaults,locale=en_CA.UTF-8 0 0
*before the 0 0 with no space after the UTF-8 add: ,uid=yourusername,gid=yourusername
*It should look like this after:
/dev/sda1 /media/windows ntfs-3g defaults,locale=en_CA.UTF-8,uid=michelle,gid=michelle 0 0

Save the file and exit vi

sudo umount /media/windows
sudo mount /media/windows

Now you can go to the Places menu and click on your windows drive, you should now be able to share any folder you wish by right clicking on a folder and choosing "Sharing Options".

Michelle Agnew

Saturday, September 6, 2008

Shozu - A native blogging app for the iPhone

At first you could only use the blogger web interface to post, or use the email interface. Shozu was launched in the app store right away but you could only post images. They just emailed me about their latest update and it now allows text posts. I've now redownloaded the and and this is my first post with it. So far so good.

Michelle Trusty

Posted by ShoZu

Tuesday, February 5, 2008

Lightning - Can't create new calendar

I installed the Lightning calendar extension in my Thunderbird to manage the numerous meeting requests I've been receiving lately and it didn't work right out of the box. It wasn't detecting meeting requests and I couldn't even see the calendar. After a bit of googleing I found at the bottom of this thread that in Ubuntu 7.10 Gusty Gibbons you need to install the libstdc++5 package.

I ran the command: sudo apt-get install libstdc++5

Uninstalled and reinstalled the lightening package and it worked.

Michelle Trusty

Wednesday, October 10, 2007

After much searching I was unable to find a bash equivalent of inet_aton so I wrote one:

ip=10.3.2.25
ipint=0

for i in 1 2 3 4
do
octet=$(echo $ip |cut -d. -f$i)
let "ipint <<= 8"
let "ipint += $octet"
done

echo $ipint

It's probably not perfect, but it works.

Edit: Slightly improved version:

ip=10.3.2.25
ipint=0

for i in 1 2 3 4
do
octet=$(echo $ip |cut -d. -f$i)
let "ipint = (ipint << 8) + $octet"
done

echo $ipint

Michelle Trusty

Tuesday, August 7, 2007

Asterisk long distance alternative

I just found out a couple of weeks ago that Fido, my cell carrier, is charging us $0.30/min for long distance. My husband's long distance last month cost over $15 for less than an hour of calling. There are long distance companies that will give you an access number and let you call from a cell phone, giving you a dialtone to place your long distance call. One of these that we used to use is WinTel, who offers a $0.25/call for long distance no time limit. They work quite well, but the call quality can be a bit questionable at times. However I already have an Asterisk server, and I already have a voip account with Link2Voip for my incoming phone numbers who offer $0.011/min across Canada and $0.019/min in the US50 with incoming calls being the same as the Canadian rate. I should be able to call in on one of my DID's to my Asterisk server and somehow get it to give me a dialtone to call back out on allowing me to use my Link2Voip long distance rates rather than the atrocious Fido rates.

I brainstormed this a bit with my colleague at work and he suggested yes that it could be done. I borrowed his O'Reilly Asterisk book for the weekend and take Monday to play around with it. After reading the chapter on dialplans I understand them for the first time, previous to this I just sortof hacked around them with examples from the default Asterisk configs and what Link2Voip supplied me.

Monday afternoon I started playing with it. I set up an extension in my outgoing context that allowed me to test functions and used the POTS phone that I have hooked up to my PAP2-NA SIP adapter. To start with my extensions.conf looked something like this:

[outgoing]
exten => 222,1,Answer()
exten => 222,2,Playback(hello-world)
exten => 222,3,Hangup

That was my basic dialplan that I had set up for extension 222, when I dialed that in my phone Asterisk would play back the sound file "hello-world.gsm" and hang up. Not all that useful, but at least I knew I had an area I could test things. I then decided to figure out the best way to authenticate a person with passcode of some sort. I found the Authenticate() app and implemented that into the dialplan:

[outgoing]
exten => 222,1,Answer()
exten => 222,2,Authenticate(54321)
exten => 222,3,Playback(hello-world)
exten => 222,4,Hangup

Now when I call 222 I get a voice response of: "Please enter your password followed by the # key" You can now enter 54321 and press # and it will play the "hello-world.gsm" audio file. If you enter the wrong password it will let you try 2 more times, then fail and hang up. If the authorization is successful, I wanted it to play back a message saying so, so I dug around in /var/lib/asterisk/sounds and found the "pin-number-accepted.gsm" file and added that to the dialplan:

[outgoing]
exten => 222,1,Answer()
exten => 222,n,Authenticate(54321)
exten => 222,n,Playback(pin-number-accepted)
exten => 222,n,Hangup

I got sick of reordering the priorities in the dialplan so I switched to their auto-order format by setting the first one to "1", then the rest to "n" for "next".

Now that I have authentication working I need to figure out how to read in a number from a user to forward the call to. I found the Read() app and after some playing with it I figured out how to use it to capture a phone number 10 digits in length to a variable, to verify that it was working and reading the digit's correctly, I used the SayDigits() app to have it read them back to me:

[outgoing]
exten => 222,1,Answer()
exten => 222,n,Authenticate(54321)
exten => 222,n,Playback(pin-number-accepted)
exten => 222,n,Read(NUM_TO_DIAL,vm-enter-num-to-call,10,,3,15)
exten => 222,n,SayDigits(NUM_TO_DIAL)
exten => 222,n,Hangup

Once I was able to confirm that that was working, I needed to figure out how to forward it to another extention, for this I used the Goto() to send it to the pattern matching extension that would normally handle these types of calls:

[outgoing]
exten => 222,1,Answer()
exten => 222,n,Authenticate(54321)
exten => 222,n,Playback(pin-number-accepted)
exten => 222,n,Read(NUM_TO_DIAL,vm-enter-num-to-call,10,,3,15)
exten => 222,n,SayDigits(NUM_TO_DIAL)
exten => 222,n,Goto(outgoing,${NUM_TO_DIAL},1)
exten => 222,n,Hangup

This pretty much completes the steps needed to authenticate the user, read in the number to dial and then to dial it. My next problem was that I wanted to be able to access this when calling in on any of my DID's. I set up a 2 second delay where when a user calls in on any of my DID's, if they press a key they will be asked for a password. If no key is pressed, the DID will follow it's normal behavior and forward the call to it's appropriate destination.

I first set a 1 second Wait() then play a beep, just as an identifier to know that I've been connected to the Asterisk server and then wait 2 seconds to see if a key had been pressed. I use Read() to listen for the keypress and GotoIf to go to the appropriate extenstion based on the results:

[incoming]
exten => 16045551212,1,Answer() ; Answer the call
exten => 16045551212,n,Wait(1) ; Wait 1 second to make sure we're connected
exten => 16045551212,n,Read(KEYPRESS|beep|1||1|2) ; listen for any key, for up to 2 seconds
;If the results of the read above has at least one digit in it
; forward to the outgoing context, authout extension, priority 1
; otherwise send the call to the current context, incomingdid extension and priority 1.
exten => 16045551212,n,GotoIf(${LEN(${KEYPRESS})} > "0"?outgoing,authout,1:incomingdid,1)

exten => incomingdid,1,Dial(SIP/home,60) ; incomingdid extension, priority 1

[outgoing]
exten => authout,1,Answer()
exten => authout,n,Authenticate(54321)
exten => authout,n,Playback(pin-number-accepted)
exten => authout,n,Read(NUM_TO_DIAL,vm-enter-num-to-call,10,,3,15)
exten => authout,n,SayDigits(NUM_TO_DIAL)
exten => authout,n,Goto(outgoing,${NUM_TO_DIAL},1)
exten => authout,n,Hangup

; The macro's Link2Voip gives to the user to dial out their trunk
exten => _1NXXNXXXXXX,1,Macro(diallink2voip,${EXTEN})
exten => _NXXNXXXXXX,1,Macro(diallink2voip,1${EXTEN})

I'm happy to say that this all works. I can dial in on any DID, preempt the standard dialplan and allow myself to authenticate and choose a new number to dial. Calling from my cell phone this makes my long distance charges $0.022/min to Canada and $0.03/min to the US about 1/10th of what Fido is charging me. If I use one of my Toll-Free DID's that I purchased from Link2Voip it puts the cost below $0.06/min, still 1/5th of what Fido is charging.

Michelle Trusty