Saturday, March 12, 2011

FreePBX Device User Mode – Enforce login



I had responded to a thread on the FreePBX forum about how to restrict calling without a user first logging in on a device/user mode in FreePBX.
Here’s a simple dialplan which you can then use for your implementation. For FreePBX users, put these lines of codes in /etc/asterisk/extension_custom.conf
[devcheck]
exten => *11,1,Goto(from-internal,${EXTEN},1)
exten => *12,1,Goto(from-internal,${EXTEN},1)
exten => _.,1,Set(USEREXIST=$[${DB(DEVICE/${CALLERID(num)}/user)}])
exten => _.,n,GotoIf($[${USEREXIST}=none]?endit)
exten => _.,n,Goto(from-internal,${EXTEN},1)
exten => _.,n(endit),Playback(pbx-invalid)
exten => h,1,Hangup

Reload the dialplan asterisk –rx “dialplan reload”
Put this in each extension under context settings like below for each device in FreePBX UI.
image
Submit and apply.
At the end that context/dialplan, play anything you like in the Playback() macro. Here, you can record stuff like “You must first log in before making any calls”. I use the above one as a simple sample.
You can put in more exceptions like emergency numbers; besides the login and logoff feature codes in FreePBX at the top.
exten => 999,1,Goto(from-internal,${EXTEN},1)
Where 999 is our Malaysian emergency number.

Saturday, February 12, 2011

Google Voice extends free calls to US and Canada for whole of 2011


Google’s awesome quality Voice service which lets you make free calls to US and Canada is now extended to 2011. There was news that it will only be for 2010 ,but now, in their blog statement they offer this all the way through 2011. Use but don’t abuse.
http://googlevoiceblog.blogspot.com/2010/12/free-calling-in-gmail-extended-through.html

Tuesday, January 25, 2011

[UPDATED] Asterisk & FreePBX Faxing Solution with IAXModem + Hylafax + AvantFax

Updated: 04-11-2013

This guide attempts to walk you through installing a faxing solution on top of Asterisk that has FreePBX as it’s frontend GUI/dialplan generator.

So for it to work, you need to be
1) Using Debian (this is a Debian guide btw). Tested working on Debian 5,6
2) Have a working Asterisk (tested on 1.6,1.8,10,11) either locally or remote. If locally, the IAXModem as shown below, points to itself i.e. 127.0.0.1, if its somewhere, just change the IP
3) Running FreePBX 2.7 or higher (don’t need that if you do manual dialplans tho)

The process is as follow:
1) Create an IAX extension on FreePBX
2) Install IAXModem – Configure at least one virtual serial port
3) Install Hylafax – “Bind” the modem you just created above into Hylafax
4) Install Avantfax, create users and bind users to each virtual modem
5) Use Avantfax to login and retrieve/send faxes

FreePBX IAX extensions (the FAX number)
1) Create an IAX extension in FreePBX, insert the DID and CID so that calls can come into that extension
2) Click on the newly created IAX extension and modify the port (do not use port 4569, use anything else that does not conflict with your system’s UDP listening ports), example below is 4800 and the next IAX extension for fax can then use 4801, so on... This corresponds to the ttyIAX0 file setup below. 
image
3) Apply configuration
4) Go back to that IAX extension again you just created, and set requirecalltoken to no or auto (FreePBX 2.11).

Update apt and fix any broken apt installs
1) # apt-get update
2) # apt-get -f install

Install and configure IAXModem
Install and configure first IAXModem which will then map to the newly created extension above. If you use device/user mode you need to fix the user to an extension and use the user as the username and password in the IAXModem setup below.
1) # apt-get install gcc libtiff-tools libtiff4-dev
2) # apt-get install iaxmodem
3) # cd /etc/iaxmodem/
4) # Create our first modem config as below
5) # nano ttyIAX0 (see something like this below). Note, if you are running Asterisk on this same box, then use 127.0.0.1 as your server IP
device          /dev/ttyIAX0
owner           uucp:uucp
mode            660
port            4800
refresh         3600
server          127.0.0.1
peername        5500
secret          myCOMPLEX123pass
codec           ulaw

6) Edit your inittab to add two lines for each ttyIAX modem you just created, example below
7) # nano /etc/inittab (NOTE: The last zeros are running numbers on IA00, m0, ttyIAX0)

# Load iaxmodem
IA00:23:respawn:/usr/bin/iaxmodem ttyIAX0

# Load hylafax modem listener agent
m0:2345:respawn:/usr/sbin/faxgetty ttyIAX0


7b) #telinit q
The above will initialize /dev/ttyIAX0 or others if you’ve configured them

8) Load your modems
9) #/etc/init.d/iaxmodem stop, then start
10) #ps -ef |grep iaxmodem (you should see your first modem there)
11) On your asterisk server (run on the same server if it runs asterisk as well)
12) # asterisk –rx “iax2 show peers” (you should see that your extension above is now registered, in this case 5500) should show you OK, it may take a while before registration spawns into action.

IAXModem is now done and is registered to Asterisk (ready to receive calls, you can try and you will hear the ringing but no picks up yet, this is hylafax’s job done below..)

Install and configure Hylafax
1) # apt-get install openssh-server hylafax-server
2) Time to configure hylafax
3) #faxsetup
When the faxsetup calls the faxaddmodem script, when it asks "Serial port that modem....enter the modem name above which like ttyIAX0), it will then ask you to enter you country code, area code and phone number, enter anything you wish there. For the rest of the questions, enter default values [press enter all the way till the end unless you know this stuff, i don't, but you may want to set the "Local Identification String" to say your company name on headers..].  Finally it will probe our modem and if that worked it will say OK and tell you what class modem you’re running. If it prompts you to create another modem just terminate by pressing <CTRL+C>
3b) If you are merely adding new users/faxmodems just run # faxaddmodem instead of # faxsetup (which is done only once)
4) #telinit q (run #ps –ef |grep fax and you should see faxgetty there now)
5) For each modem you created in #faxaddmodem a file will be created in /etc/hylafax
6)  #nano /etc/hylafax/config.ttyIAX0, at the end of this file add the following

## Add for AvantFAX use each time you add new modems
#
FaxRcvdCmd:     bin/faxrcvd.php
DynamicConfig:  bin/dynconf.php
UseJobTSI:      true


8) #/etc/init.d/hylafax restart
Hylafax setup done, the modem should pickup and you hear the modem sound

Install and configure AvantFax
1) # apt-get install -y apache2-mpm-prefork apache2-utils apache2.2-common libapache2-mod-php5 libapr1 libaprutil1 libpq5 libsqlite3-0 php5-cli php5-common mysql-server imagemagick libtiff4-dev netpbm libnetpbm10-dev libungif-bin libungif4-dev sudo php-mail php-mail-mime php-file php-db php5-mysql sudo php-mail php-mail-mime php-file php-db php5-mysql

(NOTE: if you get a disclaimer file from mysql5.1 and you see the word "END" after scrolling down, do a ":q!" to quit that screen and continue)

Note: During the Avantfax install script for debian below, it may disable or remove other SMTP engine. This script WILL ATTEMPT TO REMOVE OTHER SMTP and INSTALL POSTFIX, continue first, we will show you how to fix that below...
2) #cd /usr/src
3) #wget http://downloads.sourceforge.net/project/avantfax/avantfax-3.3.3.tgz
4) #tar -zxvf avantfax-3.3.3.tgz
5) #cd avantfax-3.3.3
6) #mv /usr/src/avantfax-3.3.3/avantfax /var/www/
7) #chmod -R 777 /var/www/avantfax/tmp /var/www/avantfax/faxes
8) #cd /var/spool/hylafax/bin
9) #mv faxrcvd faxrcvd.old
10) #mv notify notify.old
11) #ln -s /var/www/avantfax/includes/faxrcvd.php /var/spool/hylafax/bin/faxrcvd
12) #ln -s /var/www/avantfax/includes/notify.php /var/spool/hylafax/bin/notify
13) #mv /usr/bin/faxcover /usr/bin/faxcover.old
14) #ln -s /var/www/avantfax/includes/faxcover.php /usr/bin/faxcover
15) #cd /usr/src/avantfax-3.3.3
16) #nano create_tables.sql
17) When editing this file, right on top of this file insert “USE avantfax;” without quotes
18) # nano debian-prefs.txt (IMPORTANT!: Ensure the settings here are correct, e.g. ROOTMYSQLPWD is the root MySQL user, supply its password, pay attention to the httpuser and httpgroup (you can do a ps –ef |grep apache and see what user apache2 is running)
19) Fix some apache logging requirements for Avantfax
20) #mkdir /etc/apache2/logs
21) #touch /etc/apache2/logs/avantfax-error_log
22) #/etc/init.d/apache2 restart

Start install script. This will be the install script for debian then...below.

IMPORTANT: if you do not want to use postfix because you already have an email server, like exim, edit the debian-install.sh script and remove the existence of the word postfix normally found at the line that says apt-get install, then, start. Install will start downloading packages, configuring postfix (if enabled), getting some pear perl stuff. (YOU SHOULD NOT SEE ANY ERRORS!) .

23) #./debian-install.sh
24) When install completes, it may point you to /admin URL, ignore that, we go into /avantfax/admin instead. Do note, that htaccess may interfere with Avantfax, if you face issues being unable to login, remote .htaccess where the avantfax directory also got affected. Once done, you can now login to the WebUI at http(s)://<IPADDRESS>/avantfax/admin. You will be asked to change the password, please do that!

Creating new users/faxes/devices etc...
Firstly, create a category, e.g. Engineering Team, using the pulldown menu.
For each modem you create (iaxmodem), create it also in AvantFax. Modems can be mapped to users, which is what we will do now. Under the pull-down menu, select modems. Create the modem when you configured iaxmodem above.
image
Now, you need to create a new user:
Under the pull-down menu, select new user: create a user and make sure you map him/her to a modem like below;
 image
IMPORTANT! – When you create a new user, there’s a “bug” in hylafax that you also need to manually do it over the cli. So in this case, I've created user sanjay and must delete this user and recreate via cli like below; YOU MUST FOLLOW THE ORDER IN WHICH IS SHOWN AFTER CREATING A USER IN AVANTFAX UI ABOVE.
# faxdeluser sanjay
# faxadduser sanjay
image
It should not have any other objects/characters after the @ for the newly created regular users! as seen corrected above by the faxadduser command.. Make sure the name you created in Avantfax is similar and unique and match that name with the faxadduser command. Be sure to restart hylafax after doing that.

#/etc/init.d/hylafax restart

Now, you should be able to send the fax in to this user/extension and log on to the WebUI or you can receive an fax-to-email email. Regular users can login to: http(s)://<IPADDRESS>/avantfax/ and start receiving and sending faxes. Here’s a test fax i just received without any modification to the graphics and what not:

image

To create more users/devices/faxes:
1) Create a FreePBX extension like shown above (make sure you use unique port numbers, like 4801….4802….4803…etc)
2) Create an IAX modem (you can copy the ttyIAX0 config file to another file, say #cp ttyIAX0 ttyIAX1, modify that 1 file to match the FreePBX extension info you just created on FreePBX), follow the rest of the steps there to restart and create the inittab entry, like below (for ttyIAX1) : NOTICE the underlined values go up as we add new modems.

# Load modem
IA00:23:respawn:/usr/bin/iaxmodem ttyIAX0
IA01:23:respawn:/usr/bin/iaxmodem ttyIAX1

# Faxgetty
m0:2345:respawn:/usr/sbin/faxgetty ttyIAX0
m1:2345:respawn:/usr/sbin/faxgetty ttyIAX1


3) # /etc/init.d/iaxmodem restart && tellinit q
4) Add hylafax, faxmodem, #faxaddmodem, choose ttyIAX1 now and so on..
5) # /etc/init.d/hylafax restart
6) Create modem in AvantFax called ttyIAX1, create user, say john and map to ttyIAX1
7) # faxdeluser john
8) # faxadduser john
9) # /etc/init.d/hylafax restart
10) That user can log in to http(s)://<IPADDRESS>/avantfax/

If you wish to get help with all of these and more customization, contact us at info[@@@]astiostech.com – use one @ of course

As usual, your feedback is much appreciated.

Friday, January 21, 2011

Cancelling an iPhone AppStore Application Install


Thought i’d write this if someone needs some assistance.
Iphone installations using the Appstore while it’s a magical experience, it freaked me out when i had tried to download a game that was over 240MB but i wanted to cancel it and can’t do it on the phone itself (at least for when i tried it). Even though it was on a WiFi i am not fitting my lil pocket rocket with that kinda sized app!
Anyway, to do this is simple. If you wish to cancel or delete a download happening in your Phone right now, simply go to your PC’s/Mac’s iTunes, plug in the iPhone and stop the download there, under the Downloads below STORE (see pic below). Click or Right click (on PCs) and say delete or something…and you’re done! And it will sync the action back to the phone and no more downloading baby!+


Tuesday, December 21, 2010

Asterisk 1.8.1.1 Fixes Google Voice Out

This release fixes the Google Voice out bug. So this would then supersede any patching needed to get Google Voice working on Asterisk 1.8

Get it from asterisk.org

Cheers!

Sunday, December 19, 2010

Nagios Bulk Host Creator (and other bulk operations, if you wish) straight into nagios format


I was at the office today and had to create more than 150 hosts and to create it one by one even with a text editor or WUIs, it can be very taxing. So being the lazy guy that i am, i created this script to generate as many hosts and as an addon, create hostgroup list so that you just need to copy and paste into the hostgroup definition.
This is to create the first of steps when defining Nagios hosts. It of course can be used to generate similar items if they are repeated.
Pre-requisite:
1) You need csvtool (apt-get install csvtool or yum)
So, in essence here are the steps
1) Create a CSV file (in excel or in text editor) with at least 3 fields, hostname, description and IP address. This is probably what your customer had given or your existing inventory.
Example:
MIS-M-3-ASW,MIS Admin Switch 3,192.168.199.103
Where, MIS-M-3-ASW is the hostname, MIS Admin Switch 3 is the description and of course 192.168.199.103 is that hosts IP address

2) Create a script as seen below #nano ngenerator.sh and make it executable #chmod +x ngenerator.sh

###START ###
#!/bin/bash
# sanjay@astiostech.com
#
hosttemplate=switches-host # nagios template to use
inputfile=master.csv # inputfile in csv format only
outputhost=hosts.txt # the output for hosts definition which you can copy paste into nagios
outputservices=services.txt # the output for services (all these hosts) definition which you can copy paste into nagios
columns="1-3" #define like 3-4 to read column 3-4 etc


#start check tool
testcsvtool=`which csvtool`
if [[ $? == "1" ]]; then
    clear
    echo "ERROR"
    echo "No csvtool software found, do a 'apt-get install csvtool' or 'yum install csvtool'"
    exit 1
fi   

#start script
listdata=`csvtool -t ',' col $columns $inputfile`
IFS=`echo -en "\n\b"`
echo "" > $outputhost

# to add all this in hosts.cfg
# modify accordingly
for i in $listdata; do
    #set these
    field1=`echo $i | cut -d "," -f 1`
    field2=`echo $i | cut -d "," -f 2`
    field3=`echo $i | cut -d "," -f 3`

    echo "" >> $outputhost
    echo "# $field1" >> $outputhost
    echo "#----------------------------------------------------------------------" >> $outputhost
    echo "" >> $outputhost
    echo "define host{" >> $outputhost
    echo "        use                        $hosttemplate" >> $outputhost
    echo "        host_name                $field1" >> $outputhost
    echo "        alias                   $field2" >> $outputhost
    echo "        display_name            $field2" >> $outputhost
    echo "        address                    $field3" >> $outputhost
    echo "}" >> $outputhost
    echo "#----------------------------------------------------------------------" >> $outputhost
    echo "" >> $outputhost

done
# to add all this in services.cfg
echo "" > $outputservices
for i in $listdata; do
field1=`echo $i | cut -d "," -f 1`
    echo -n "$field1," >> $outputservices
done
exit 0

###END###
3) Define settings like the hosttemplate name you already created, inputfile file name (the csv file), the outputhost file name (will be the file you use to copy and paste into Nagios, outputservices file where you can use this that lists all the hosts that were imported from your CSV file (you can use e.g. to add to hostgroup or a minimum ping for instance) and the columns in the csv. If you have more than 3 values in your CSV you need to adjust this value and also the amount of fields you wish to import (field1, field2, field3 is currently defined).
4) Run the script and it will take the input csv file and generate your output files hosts.txt and services.txt
5) Paste into your actual nagios host configuration directly, restart nagios daemon.
You can of course define a lot of other stuff if you wish. Just get a little creative. But this script should already help you a lot a little with the initial script creation.

Monday, December 13, 2010

Unified Communications?– Use Google and Asterisk!



Over the past two weekends, I've dwelled in some not-so-light weighted testing of the spanking new Asterisk 1. 8 PBX. While honestly, there’s not a world of improvements from its already awesome predecessors but heck, its technically only a minor version update from the powerhouses 1.4 and 1.6. While there are many tiny yet significant changes, the ones that I've had a chance to work on (as also seen in this blog) are;
1) Google Talk/Voice (and oh, jabber)
2) Calendaring
3) Festival Text To Speech Engine
See, in contrast these three alone, comprise of probably 90% of what those big boys like Microsoft, Cisco and Ayava would claim Unified Communications on their offerings and thus swoop your left leg out of your budget should you then want/need it. Fret not homies, read on..there’s hope with quality and just about nothing spent on software!
Google boasts it’s business apps which is free for 200 users, mostly useless, but some really cool and completely integrated! Like GMail, Google Calendaring, Google Chat, Google Talk and Google Voice!
The missing link here, is, corporatization of these services and not pocketed or isolations.
Office PBXes are probably the first “corporatization” of a communication medium, next to email (but even that’s sometimes are disparate). People don’t really care if you are from @somedomain vs @someotherdomain, as long as you have a domain, you are regarded a more “serious” fish in the sea.
Now, lets jive!. Imagine, if you have a corporate PBX that can integrate with Google Business Apps! Imagine these;
1) Being able to make calls to the rest of the millions of Google (Talk) users worldwide for completely free
2) Send and receive messages via Google, route them through your cellphone and let your phone read that message to you and vis-a-viz reply a person from your cellphone back!
3) Let your PBX read out your calendar events and write impromptu events when on the GO
4) Put yourself as “busy” on your Google status and all calls now go to your voicemail
5) When a call comes to you, let the PBX decide, how to reach you? Your desk phone, cellphone, skype, google-talk, send you an SMS or an instant message that you got a call, do what ever. You can be reached and the lowest cost is decided by the system!
6) Send Fax? Sure, but its only the most ancient way of communicating, hah! But yea go crazy, how do you wish it delivered? Read it to you over the phone? Sure. Print out straight to your printer/fax, easy!. Send it as an email, anytime!
7) With a Text-To-Speech engine and the capability to do just about any dial-plan, use your PBX to read not only calendars, but things like your email, your tasks, your RSS feeds…google docs? yea, that also…
8) With Google, you have a single UI when you sign in, to call/chat/email friends straight from your browser and integrates with your PBX or the other way around
I am tickled silly with these capabilities. It really lies in the mind what you wish to build. The rest, coding etc, get a guy Smile
I hope organizations will soon come to realize the power of Asterisk 1.8 with its partner in crime Google Apps! Happy building.
From the Astiostechtech Geek (engineering) Office,
Sanjay

Sunday, December 12, 2010

Asterisk 1.8 Calendaring with text to speech reading out your calendar info


The Asterisk Calendaring API aims to be a generic interface for integrating Asterisk with various calendaring technologies. The goal is to be able to support reading and writing of calendar events as well as allowing notification of pending events through the Asterisk dialplan.
There are three calendaring modules that ship with Asterisk that provide support for iCalendar, CalDAV, and Microsoft Exchange Server calendars. All three modules support event notification. Both CalDAV and Exchange support reading and writing calendars, while iCalendar is a read-only format.
NOTE: This is for Debians alike. Please modify accordingly for your own distros.
What we are attempting here to do is to read the calendar event on an and in this example/setup a Google Calendar using its iCal link and read the event to the user of his latest schedule.
The Google iCal is currently set to a public accessible link showing Malaysian holidays: (IN HTML FORMAT)
https://www.google.com/calendar/b/0/embed?src=en.malaysia%23holiday@group.v.calendar.google.com&ctz=Asia/Kuala_Lumpur&gsessionid=3UZQTRxAyF3erYCVGGIcMw
Part 1 – Getting calendar for ical to work on Asterisk
You need to get Asterisk 1.8.
Go to your preferred source directory, extract Asterisk source
1) wget http://sourceforge.net/projects/freeassociation/files/libical/libical-0.44/libical-0.44.tar.gz/download
2)  tar -zxvf libical-0.44.tar.gz
3 cd libical-0.44
4) ./configure
5) make && make install
6) apt-get install libneon27 # or use yum
7) apt-get install libneon27-dev # or use yum
8)  (Re)compile and install asterisk (not going to show how here), do a “make menuselect” to ensure that Calendar and Internet Calendar Icalendar is enabled/selected
9) nano /etc/asterisk/calendar.conf # add a sample, like below from google’s malaysia holidays ical file
[myholidays]
type = ical
url =
http://www.google.com/calendar/ical/en.malaysia%23holiday%40group.v.calendar.google.com/public/basic.ics
refresh = 15
timeframe = 1576800


Part 2 – Getting festival (the free text to speech engine), parts taken off a guide from here
1) apt-get install festival # install it with apt or yum
2) nano /etc/festival.scm # modify some configs on how to parse the audio files
3) Add the following inside this file (below), check to ensure the texts are properly copied, i had issues with that causing festival not to start and listen on TCP port 1314.
;; Enable access to localhost (needed by debian users)
(set! server_access_list '("localhost\\.localdomain" "localhost"))

;; set italian voice (comment the following 2 lines to use british_american)
;;; Command for Asterisk begin

(define (tts_textasterisk string mode)
"(tts_textasterisk STRING MODE)
Apply tts to STRING. This function is specifically designed for
use in server mode so a single function call may synthesize the string.
This function name may be added to the server safe functions."
(let ((wholeutt (utt.synth (eval (list 'Utterance 'Text string)))))
(utt.wave.resample wholeutt 8000)
(utt.wave.rescale wholeutt 5)
(utt.send.wave.client wholeutt)))

;;; Command for Asterisk end
4) Copy the init script (so it will auto run next time you reboot)
5) cp /usr/share/doc/festival/examples/festival.init /etc/init.d/festival
6) chmod +x /etc/init.d/festival
7)  update-rc.d festival defaults
8) nano /etc/default/festival # add the line below inside
9) RUN_FESTIVAL=yes
10) nano /etc/asterisk/festival.conf # configure asterisk to use festival, make sure that cache directory exists and permission are okay
[general]
host=localhost
port=1314
usecache=yes
cachedir=/var/cache/asterisk/festival/
festivalcommand=(tts_textasterisk "%s" 'file)(quit)\n

11)  /etc/init.d/festival start # start festival
12)  netstat -an |grep 1314 # it must exist with TCP listening on 0.0.0.0, otherwise, can try starting it manually to see any error # /usr/bin/festival --server --script /etc/festival.scm   this is also good for debugging if the text file is sent to the festival server from asterisk
12) Now, create some dialplans in /etc/asterisk/extensions.conf or anywhere related (like in freepbx would be /etc/asterisk/extension_custom.conf)
exten => gc*cal,1,Answer
exten => gc*cal,n,Set(i=${MATH(${EPOCH}+1576800,int)}) ; 1576800 is about half a year EPOCH
exten => gc*cal,n,NoOp(Math func addon is ${i})
exten => gc*cal,n,Set(id=${CALENDAR_QUERY(myholidays,${EPOCH},${i})})
exten => gc*cal,n,NoOp(Event NoOp ${CALENDAR_QUERY_RESULT(${id},summary)})
exten => gc*cal,n,Set(es=$[${CALENDAR_QUERY_RESULT(${id},summary)}])
exten => gc*cal,n,Set(es=$[${CALENDAR_QUERY_RESULT(${id},summary)}])
;
exten => gc*cal,n,Festival(Event type is)
exten => gc*cal,n,Festival(${es})
;
exten => gc*cal,n,Set(epochstart=${CALENDAR_QUERY_RESULT(${id},start)})
exten => gc*cal,n,set(startdate=${STRFTIME(${epochstart},,%A%t %e%t %B%t %G%t)})
exten => gc*cal,n,set(starttime=${STRFTIME(${epochstart},,%H%t %M%t)}) 
exten => gc*cal,n,Festival(start date)
exten => gc*cal,n,Festival(${startdate})
exten => gc*cal,n,Festival(start time)
exten => gc*cal,n,Festival(${starttime} hours)
;
exten => gc*cal,n,Set(epochend=${CALENDAR_QUERY_RESULT(${id},end)})
exten => gc*cal,n,set(enddate=${STRFTIME(${epochend},,%A%t %e%t %B%t %G%t)})
exten => gc*cal,n,set(endtime=${STRFTIME(${epochend},,%H%t %M%t)}) 
exten => gc*cal,n,Festival(end date)
exten => gc*cal,n,Festival(${enddate})
exten => gc*cal,n,Festival(end time)
exten => gc*cal,n,Festival(${endtime} hours)
;
exten => gc*cal,n,Hangup

13) Remember to restart asterisk at least once for all these to work, as we are loading the calendar module and dialplans in it.
14) You would need a phone that’s capable to dial letters (or change that dialplan to dial a number instead like exten => 1000
15) Dial from your phone gc*cal

Saturday, December 11, 2010

Google Voice on Asterisk 1.8 bug is now fixed!



When Asterisk 1.8 was released, it had a perfect integration with Google Voice @voice.google.com service. Sometime in the 4th week of November, this broke and Gtalk worked (calling other google accounts) but calling Google Voice (e.g calling to US numbers for Free), didn’t.
I just saw this fixed in Digium’s bug tracker here
Here’s how i got my current working Asterisk to apply the patch. I am sure there are more “polished” ways but this just worked for me
1) Go to your Asterisk source directory, mine is #cd /usr/src/asterisk-1.8.0
2) Go to the channels directory #cd channels
3) Backup the original chan_gtalk.c to somewhere # mv chan_gtalk.c /usr/src/somebackup
4) Get the patch # wget http://svnview.digium.com/svn/asterisk/trunk/channels/chan_gtalk.c?revision=297958&pathrev=297958
5) Rename it #mv chan_gtalk.c\?revision\=297958 chan_gtalk.c
6) Go back to asterisk source main directory #cd ..
7) # ./configure
8) make && make install
9) Stop and restart asterisk # asterisk –rx “core stop now”
And voila! Google Voice worked again, just dialed a friend in US for free <joy>, my dialplan had exten => _1. I dial straight from my Deskphone!
Perfect! now lets enjoy our weekend,
PS> If you want some (flexible) dialplans, here an article that can help you. Go to http://highsecurity.blogspot.com/2010/11/googlevoice-asterisk-18-with-freepbx.html

Tuesday, December 7, 2010

Asterisk Script for Recordings to Move or Copy -n- number of days old (an archiving tool if you may)


Here’s' a script that moves or copies certain files (in my case Asterisk recordings) of anything above a certain date (as defined in the CLI) to a destination you pick.
You must first define the sourcepath, sourcefilename, destination and an option to flag move or just copy.
Place it anywhere and execute ./archivefiles 10
-> which means move/copy files that are over 10 days old from date to a desired location.
You could of course run it in cron if you like on a regular basis. Say you run ./
Here’s the script. Copy from the start till the end.
1) nano /usr/bin/archivefiles # create it
2) paste start –> end of script below # copy the script
3) chmod +x /usr/bin/archivefiles # make it executable
NOTE: Make sure your date/time in server is consistent/correct.
###start###
#!/bin/bash
# sanjay@astiostech.com
# usage #archivefiles 10 (meaning archivefiles will find files older than 10 days to do a move or copy)
#
# DEFINE THESE
SOURCEPATH=/var/spool/asterisk/monitor/                                 # With trailing / (slash )
SOURCEFILENAME=*.wav                                                 # filetype
DEST=/usr/src/mytestdst/                                                 # With trailing / (slash )
MOVE=0                                                                # NOTE:0 - copy, 1 - move
#
#
#
# START THE SCRIPT
# CHECK IF OLDER THAN VARIABLE DEFINED
#
OLDERTHAN=$1
if [[ $OLDERTHAN = "" ]]; then
        echo "Define a period. Like 10 for 10 days"
    exit 1
else
        echo ""
fi
# CHECK IF VALUE ENTERED IS AN INTEGER
#
if [ $OLDERTHAN ]; then
    if [ ! $(echo "$OLDERTHAN" | grep -E "^[0-9]+$") ]; then
        echo $OLDERTHAN is not a valid integer.
        exit 1
    else
    if ! [ $OLDERTHAN -ge 0 ] || ! [ $OLDERTHAN -le 10000 ]; then
        echo $OLDERTHAN is an invalid value. Range is [1-10000]
        exit 1
    fi
    fi
fi
# CHECK IF SOURCE DIRECTORY EXIST
#
if [[ -d $SOURCEPATH ]]; then
        echo "OK - Source directory exits"
        cd $SOURCEPATH
else
        echo "Source Directory not found, check your settings... quitting"
        exit 1
fi
grabfiles=`ls -l  $SOURCEPATH$SOURCEFILENAME | head -n 1 | grep -c "\-r"`
if [[ $grabfiles != "0" ]]; then
        echo "OK - Source files exist"
else
        echo "Oops, no source files, check your settings...quitting"
        exit 1
fi
       
# CHECK IF DESTINATION EXISTS
#
if [ -d $DEST ]; then
    echo "OK - Destination directory exits"
else
    echo "Destination directory not found, check your settings... quitting"
    exit 1
fi
# START OUR JOB, DEFINE ACTIONS
#
if [[ $MOVE = "1"  ]];then
   
    find  $SOURCEPATH$SOURCEFILENAME -mtime +$OLDERTHAN -exec mv -f {} $DEST \;
else
    find  $SOURCEPATH$SOURCEFILENAME -mtime +$OLDERTHAN -exec cp -fpr {} $DEST \;
fi   
###end###