web.py templetor
I’ve used web.py some times (or even several, already?) and really enjoy it. The majority of the framework is really easy to use – and powerful, but the usage of $ on the templetor can be confusing, even after reading it’s well written documentation.
A question about it has raised on the webpy mailing list and Anand Chitipothu, as clear as always, explained, in the simplest form, how it must be used:
1. As a marker to indicate python expressions.
$x
$x.title
$x[0].foo
$f(x, y)
$(x + y)2. As as a marker to indicate python statements and var. ($
immediately followed by a keyword).
$for n in numbers:
$if x == 0:
$break3. As a marker to indicate python assignment. ($ followed by space)
$ x = 1
$ x = y + z*x
I think this covers all possible uses.
Confidence
I was trying to figure out where to host a svn server for a project and got impressed when I realized my client’s account on Locaweb already provides that. Also, it allows one to log into the server through ssh – no big deal, but cool.
Then, for the first time, I’ve logged into the server. As curious as I am, I was wondering what command line tools was available to my account and also in which (scripting) language they were written in, which led me to:
[mahuser@thahost ~]$ user
user-fix-owner users user-svn-deactivate user-svn-permissions user-wsgi-autostart user-wsgi-list
user_list user-svn-activate user-svn-list user-wsgi-activate user-wsgi-deactivate
[mahuser@thahost ~]$ which user-svn-activate
/usr/bin/user-svn-activate
[mahuser@thahost ~]$ file /usr/bin/user-svn-activate
/usr/bin/user-svn-activate: Bourne-Again shell script text executable
[mahuser@thahost ~]$ cat /usr/bin/user-svn-activate
#!/bin/bash
domain=$1
if [ -z "$domain" ] ; then
echo "Usage: ${0/*\//} "
exit 0
fi
/usr/local/locaweb/bin/locarun svn activate $domain
[mahuser@thahost ~]$ file /usr/local/locaweb/bin/locarun
/usr/local/locaweb/bin/locarun: setuid ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), for GNU/Linux 2.6.9, dynamically linked (uses shared libs), for GNU/Linux 2.6.9, not stripped
[mahuser@thahost ~]$ /usr/local/locaweb/bin/locarun
Segmentation fault
We all know that parsing is the biggest point of security flaws in software, BUT, when I saw that this locarun program expected an argument, I could bet it would crash if I didn’t pass one to it.
There’s also GCC and debugging tools on the server. What confidence does a service like that gives me? Well, do the math.
Web console for FreeSWITCH
After the addition of event_sink command to the event_socket interface (more on that later), I’ve rewrote the web console with more functionality: commands, event and logging. That means one can see the logs that appears on FreeSWITCH default console through a web browser.
The console is written using GWT.
Command completion screenshot:

Event details:

View logs:

To use it, download the compiled code from here, unzip it into FreeSWITCH’s htdocs folder and point your browser to http://freeswitch-ip-address:8080/org.freeswitch.FSConsole/FSConsole.html
Full size screenshots:
http://lustyscripps.files.wordpress.com/2009/01/picture-3.png
http://lustyscripps.files.wordpress.com/2009/01/picture-4.png
http://lustyscripps.files.wordpress.com/2009/01/picture-5.png
Rough FreeSWITCH console with GWT
When writing an web ui for a automated dialer, I thought it’d be nice to have a client for FreeSWITCH written in GWT, the Google Web Toolkit. Actually, it would be even more nice to have a full featured ui written in GWT.
Anyway, I wrote a test and it works. It’s far from being nice to use, but it shows how easy it is to write web 2.0 apps that communicate with FreeSWITCH. The compiled source code is here, to use it, just unzip it on FreeSWITCH’s htdocs directory, usually: /usr/local/freeswitch/htdocs and point your browser to http://ipaddr:8080/com.ap.FSConsole/FSConsole.html
There’s almost no functionality in this program, it just works as a wrapper between your browser and FreeSWITCH’s xmlrpc interface. It also has completion for a minor number of commands (screen shot here). You should have mod_xml_rpc enabled to use it.
I tried to paste the source code here, but it stays VERY ugly with this template.
Update: As suggested by MikeJ, the autocomplete commands’ list is now fetched from FreeSWITCH.
Enormous source code here.
Zip with the whole directory tree, as well as Eclipse’s project file, here. The two scripts inside the zip file, FSConsole-{shell,compile} should be updated with the proper gwt’s compiler path for the whole thing to work. They both are generated by gwt and have the jar’s path absolute; I’m not sure how to change that, but if anyone is willing to touch the code, please let me know.
In the meantime, I’ll keep shaping FSConsole.java in my spare time.
Just to double check if you understood what’s this about: GWT is a set of axioms and a compiler. It allows the user to write code in Java and generates an output in HTML+Javascript. So you just have to touch the Java code if you plan to change/extend the UI’s behaviour, otherwise just use the zip file.
libopenr2 and FreeSWITCH
I haven’t taken the time to do some things with FreeSWITCH or anything alike. Actually, I dropped the development of the MFC/R2 endpoint for Digivoice cards and have written nothing since that, so it’s time to come back. As I get no money out if it (either from VoixTel nor anybody), I work on it when I can, so don’t create any expectations about it. I don’t create any about you, the visitor, neither.
One thing I should mention here, is the willingness of Devel IT, a brazilian company, to borrow me some Digivoice cards, free of charge, so that I could write and endpoint for FreeSWITCH to support it. Digivoice itself has borrow me a card, but for a limited time and, when the period has expired, they had asked me to buy the card or to return it.
For some months I’ve used FreeSWITCH in production systems, in the middle of Asterisk and SipXecs to take care of things Asterisk just don’t understand – and to more reliably take care of the things, none wants a PBX software process to hang on gethostbyname() calls when a DNS server is not available. It has shown to be a very stable and rock solid piece of software, easily extensible and many-other-good-things-anyone-can-write-here. Now, Moy, a Mexican software engineer, has come up with another good piece of software: libopenr2.
There are also some brazilians working on the develpment of the library, most notably the ones cited on the CREDITS file, as: Alexandre Cavalcante Alencar, Cleiber Marques da Silva and Humberto Figuera. (NOTE: Humberto Figuera is actually venezuelan, really sorry Humberto.) Melcon Moraes is also notable for taking the time and risk of installing the library on some of our company’s production servers. I know those guys will keep the good work and fix/report any issues they might find.
What I plan to do now, is to make sure the build process works on mac OS X. After that, write an FreeSWITCH endpoint. Besides it’s 4:27am, and I haven’t slept more than 10 hours in the last ~5 days, I’m pretty much excited about all this and I’m anxious to port the library and write the endpoint for FreeSWITCH. The company I co-own uses fonast as it’s gateway platform, which means an Asterisk 1.2 which _a lot_ of fixes from Fonality, but that’s just not acceptable anymore.
The last thing I needed to write for it, was a work-around to get a partial QSIG-CF (ECMA-174) to work with Ericsson MD110 devices. I promised to myself not to touch any Asterisk’s, or libpri’s as that’s the case, anymore, as they’re VERY badly written. As a note, again: I really enjoy what Asterisk has exported, but it doesn’t fit my present needs and I don’t plan to use it on new projects. Anyway, after a hack in libpri, the partial QSIG-CF was working properly with MD110 and our client was happy.
Now to the real solution: let’s see how many days I take to port OpenZAP to OS X and, after that, make libopenr2 build on OS X. That’s the first step to have a FreeSWITCH endpoint which already implements forced disconnection on MFC/R2 Brazilian links, collect calls blocking and some other goodies. Of course I have just my spare time to work on that, but I don’t think It’ll take very long time – and I’m sure it’ll worth it, FreeSWITCH just runs out of the box and fixes the issues we have, instead of adding more. So, I really think the path to the MFC/R2’s FreeSWITCH endpoint is with libopenr2.
The conclusion is a little confusing here, but, for the people who work with those things, the idea is clear. Maybe I’ll try to sleep a little now.
MFC/R2 for FreeSWITCH
I can’t wait to have a dozen of FreeSWITCH deploys, so we can sleep at night without worries. For that I have to satisfy a need in Brazilian telephony systems: E1 MFC/R2 support. That procotol was developed in 1954 and is still broadly used in Brazil, Mexico and Asian countries.
We can add support to it in Asterisk, since Steve Underwood wrote chan_unicall and, most importantly, spandsp, libunicall and libmfcr2. That was a huge contribution to us, merely mortals from the third world. Asterisk could then be used as the gateway between calls from the TDM to the IP world and vice-versa; within a single box, we could have a Sangoma card (no, not Digium) and some application the callers/callee would end up being served with.
That was nice, but that was before the problems started to appear. Asterisk showed itself poorly designed, the deadlocks were frequent and there really wasn’t anything being done to address this issue. We weren’t even using (ISDN) PRIs, “there’s probably something wrong with the unicall implementation”, we naively thought, but years after hunting bugs that lied in bottom layers, we found out that Asterisk itself implemented the errors. Or, probably more appropriately, that it has never written to deal with those situations, which fired a paradox in my head, I thought it was.
Today, Digivoice, a Brazilian cards manufacturer, produces cheap E1 cards which takes care of the signalling on the hardware side. I’m writing a driver so that FreeSWITCH can support MFC/R2 through the usage of those cards, which will be extremely useful to us. Besides that, Steve Underwood is also making his protocol’s implementation set work on FreeSWITCH, which will probably become officially supported by the project.
At the same time version 1.0 will be released, I’ll have the MFC/R2 driver for Digivoice cards. I’ll soon be able to use just FreeSWITCH where I need MFC/R2.
FreeSWITCH 1.0 coming
The FreeSWITCH project will get to an important milestone may 26th, next monday, when the version 1.0 will be released.
For the people involved with the project, which includes the developers, testers, users and everybody else, this is a great achievement. The project was a promise since it’s early days of development and, since it reached some level of stability, several months ago, it already showed it’s architecture was rock-solid.
My company has used FreeSWITCH in a multihomed environment for several months, serving a passive call center, which used to make television ads to receive calls, hence creating a peak of calls on small periods of time. Asterisk was the gateway between a TDM E1 MFC/R2 link and a SIP VoIP account, for that it worked kind of fine; the errors were manageable. When two internet links were connected to it, with the purpose of load balance the outbound calls, we got stucket. Asterisk just sends RTP packets to the server’s default route, hence making it useless on multihomed environments.
I advised my fellow Melcon Moraes to use FreeSWITCH to solve the problem. He was already aware of the project and probably had played with it at home, but he surely had never used it on production systems, neither I did, the first version wasn’t even released – we were issuing svn checkouts commands to install it on our client box. Our plan was to put it in front of the Asterisk process, which should act as the gateway between SIP and MFC/R2, also making the transcoding of the RTP media from/to g729 and g711 – a candy to who figure out what codec was used at each side.
The downside here is that we had to keep Asterisk on the path, because FreeSWITCH doesn’t support MFC/R2, nor does it transcode g729. That’s a bad thing, because assuming FreeSWITCH works the way we expect it to, we don’t want to have Asterisk anywhere near that system, but it turns out everything worked well together. FreeSWITCH solved our issues with load balancing, sending or receiving the calls the way we wanted it to do and Asterisk was kept as the gateway.
It was incredible to checkout the project’s trunk and have it working for months without a single human interaction. After the first configuration, everything was fine and the outbound calls were sent to the VoIP provider using a simple round-robin strategy, which was more than enough to solve the client’s issues.
Version 1.0 will be out on monday.
Friendfeed’s rooms
Friendfeed has rooms now. If you’re not familiar with friendfeed, mixing feeds with rooms may sound very strange to you, but for the site’s users this probably makes sense. If you’re not getting anything and doesn’t know friendfeed, it’s a news streamer, created by Google’s ex-employees. Check it out here, it’s worth it.
I’ve used friendfeed for some months now and found it to be very handy for sharing stuff and discussing ideas, but I felt there could be some boundaries on the context you discuss things, or the context the things are shared, or something like that. What I mean is: I can choose the people I subscribe to, but I can’t filter my friends’ feed, in a way I could get a feed about a specific subject.
Friendfeed’s rooms brings that functionality to the users. It actually goes beyond that, since it makes possible to the users to control who can join a specific group, which is useful to discuss private things (I wonder what “the terms of use” says about the content).
Anyway, Google Blogoscoped has a more clarifying post about ff’s rooms here.
