You are on page 1of 108

THE COMPLETE MAGAZINE ON OPEN SOURCE

Volume: 03 | Issue: 01 | Pages: 108 | October 2014


Liferay India Pvt Ltd
Alfa Center, Ground Floor,
Double Road Indiranagar
2nd stage, Bangalore -560038
Tel : +91 080 45445445 / 41532222
Email : sales-in@liferay.com
Contents
Developers
35 Building Web Applications
Using the Python Flask Mi-
croframework

39 IBM Worklight A Mobile App


Development Platform

44 What’s the Android Open Ac-


cessory Protocol All About?

49 An Introduction to Haskell
classes and User Defined
Data Types

53 How to Contribute to GNOME


57 Grails: An Agile and Friendly
27 Open Source Tools That Simplify Tasks
for C Programmers
Framework

62 Getting Started with Clojure

65 Mobile Applcation Testing


Tools: You Should Know About

Admin
70 Send Bulk Mail Without Be-
ing Treated Like a Spammer

75 Is Your Network Getting


Slower?

79 Use LimeSurvey for an


Extraordinary Surveying
Experience 32 Tornado: A Python Web Framework
That’s Simple and Quick
81 Make Your Own PBX with
Asterisk: A Collage of Multi-
ple Hardware Equipment REGULAR FEATURES
FOR YOU & ME 08 You Said It... 26 Editorial Calendar

48 Case Study: Unotech helps 09 Offers of the Month 100 Tips & Tricks
Mahindra & Mahindra
Financial Services Limited
10 New Products
105 FOSS Jobs
to optimize 87 per cent of its 13 FOSSBytes
proprietary field force solu-
tions costs.

4  |  October 2014  |  OPEN SOURCE For You  |  www.OpenSourceForU.com


Zimbra Releases 8.5 Version
Collaboration
Anytime, Anywhere, Any Device

New Feature Highlights


Touch client for tablets Zimbra Collaboration 8.5 includes Outlook (ZCO) provides real-time,
and smartphones: integrated support for Zimbra Social. two-way syncing of mail, contacts,
The secure, HTML5 mobile web Customers running both Zimbra tasks and calendars between Outlook
application provides a device-specific products benefit from a shared and Zimbra. The latest release adds
user experience for Android and iOS user experience and single sign-on. support for traditional Chinese
devices. The Zimbra touch client can Keeping employees connected to all and improvements for system
be tailored through open APIs and of the collaboration touch points. administrators including: syncing,
fully white labeled. It delivers anytime, connection security and share
anywhere mailbox access, through a Document preview: message support. Administrators
unique Zimbra experience, that keeps High fidelity document preview is now can better support and troubleshoot
people connected to their data. available, allowing users to preview issues with logging improvements.
documents in their Web browser. Users can now accept shared mail
Offline Web client: folders and calendars from Outlook
without opening the Zimbra Web client
Offline Web client support for Chrome Infrastructure and will notice improved performance
and Firefox keeps Zimbra users
connected, even when not taking
Enhancements when syncing a large number of
messages.
advantage of native HTML5 data
storage support. Users get the Active-active:
ability to work offline with access to ActiveSync Performance and
Active-active is part of a multi- Scalability Enhancements
one month’s worth of data. And, IT
administrators benefit from an offline release effort to increase Zimbra
Service providers running large-scale
client that doesn’t increase the cost Collaboration’s scale and performance
ActiveSync deployments will benefit
or management associated with a full capabilities in complex Zimbra
from decreased computing resource
desktop client. deployments. This encompasses
costs and increased user density per
a number of enhancements to
server. Administrators can now add
Exchange Web Services: the web application and server
BlackBerry 10 devices to the list of
architecture, and introduces support
The latest release adds new Exchange ActiveSync-enabled devices that are
for MariaDB. Zimbra Collaboration 9.x
Web Services (EWS) support, supported for BYOD environments.
will continue this investment, helping
enabling all mail, contacts, tasks and I’m very excited about what we are
eliminate downtime due to upgrades,
calendar functionality in Outlook for building at Zimbra and, with the
maintenance or unplanned outages.
Mac. Administrators can add Outlook addition of the Mezeo platform to
for Mac to the list of supported clients the product portfolio, there will be
for BYOD environments, and users
Feature Enhancements some great product updates and
get to choose whatever Mac desktop advancements integrating sync and
client they prefer. Zimbra Connector for share into your daily work life, down
Microsoft Outlook (ZCO) the road.
Zimbra Social integration: The Zimbra Connector for Microsoft

Contact sales at +91 20 6730 4731 Free trial, visit


or email india.marketing@zimbra.com for further information www.zimbra.com
YOU SAID IT
Contributing content I've my own reasons to believe that ExFAT is a newer
I started using CentOS 7 as my primary OS, thanks to version file system. On my sister’s laptop, the hard disk's
the previous issue of OSFY in which you shipped the CentOS 7 second partition of 480GB was formatted in ExFAT too! After
DVD. I was able to tweak it to my liking, the details of which I putting the photos into her hard drive, I formatted my 64GB
have included in my blog: priteshugrankar.wordpress.com. Also, pen drive in her laptop —in the ExFAT file system. I was
I have always wanted to try out GIT and was not able to set it up able to access the pen drive on her laptop (running on MS
the first time I tried. This time though, it worked fine and I was Windows 7), but the pen drive was not accessible on both my
wondering if you would be interested in publishing an article on desktop (running on MS Windows XP) and my laptop running
installing and setting up GIT on CentOS 7, which I plan to write. on Ubuntu 13.10. The pen drive was actually detected only
Kindly let me know. Is there a way that my blog articles could be on the XP system, but was not accessible. A message came
published in the magazine (online or offline versions)? up saying that I must format it before I can use it. Please look
—Pritesh Ugrankar; into this new format too.
pritesh.ugrankar@gmail.com —Mathew John Kurian;
nkmathewjohn@gmail.com
ED: Thank you for writing in to us. We are glad that our DVD
could help you use CentOS 7. Thank you for including it in your ED: Thank you for your query. We have forwarded your email
blog too. We always welcome open source enthusiasts who want to the author of that article and we are forwarding this request
to contribute content to our magazine. In order to submit an to the other authors who write for us in order to come out with a
article to us, you will have to first send us a detailed Table of write-up featuring more information on the different file systems.
Contents (ToC) and once it is reviewed by our team, you can go
ahead with the write-up. You can find our editorial guidelines at Setting up a proxy server
http://www.opensourceforu.com/write-for-linux-for-you/ for your I am trying to open a small office and plan to use five
reference. Please feel free to get back to us in case of any other computer systems. I would like to set up a proxy server to
queries; we're always happy to help! share the broadband connection in the office and also to restrict
access to certain social media websites. How am I supposed
Query regarding Linux kernel support for to go about this? Kindly note that my financial resources are
file systems limited. An early reply would be very helpful.
I read the August 2014 issue of OSFY. On Page 26 (‘An
Introduction to The Linux Kernel’), the last line reads, “The —Tamit Das Sharma;
Linux kernel supports all major file systems including MS official.tamitdassharma@gmail.com
Windows' NTFS." Yes, it's true! But does the Linux kernel
support the new ExFAT file systems? In my personal experience, ED: You can set up a Squid caching proxy server which will
it does not. I've a 64GB USB 2.0 pen drive (Transcend), and help you in achieving what you want. To configure it, you can
when I used it in Windows XP, I was unable to format it in FAT32 refer to the link below:
but could do so in NTFS, and NTFS alone. But, when I used the http://www.squid-cache.org/
same pen drive in my sister's laptop which runs on Windows 7, I You can also install and use firewalls like IPCop and
was able to format it in two versions - NTFS and ExFAT. pfSence to share and restrict access to the Internet.

Please send your comments


Share Your or suggestions to:
The Editor,
Open Source For You,
D-87/1, Okhla Industrial Area, Phase I,
New Delhi 110020, Phone: 011-26810601/02/03,
Fax: 011-26817563, Email: osfyedit@efy.in

8  |  october 2014  | OPEN SOURCE For You  |  www.OpenSourceForU.com


offe
rS THE
monTH
One 2000
Rupees
month Coupon
free Free Dedicated Server Hosting
(Free Trial Coupon)

No condition attached for trial of our


for one month cloud platform
Subscribe for our Annual Package of Dedicated
Server Hosting & enjoy one month free service Enjoy & Please share Feedback at
sales@cloudoye.com
Hurry!till 31st Hurry!till 31st
alid For more information, call us r valid 014!
Offer vber 2014! Offe
er 2
Octo
on 1800-209-3006/ +91-253-6636500 Octob For more information, call us on
1800-212-2022 / +91-120-666-7718

www.esds.co.in www.cloudoye.com

Get 10%
discount
35%
off & more
“Do not wait! Be a part of
Reseller package special offer ! the winning team”
Free Dedicated hosting/VPS for one Get 35% off on course fees and if you appear
month. Subscribe for annual package for two Red Hat exams, the second shot is free
of Dedicated hosting/VPS and get
Hurry!till 31st one month FREE Hurry!till 31st
alid alid Contact us @ 98409 82184/85 or
Offer vber 2014! Contact us at 09841073179 Offer vber 2014! Write to enquiry@vectratech.in
Octo or Write to sales@space2host.com Octo

www.space2host.com www.vectratech.in

Get Get 25% PACKWEB PACK WEB


12 Months HOSTING

Free Off ProX

Time to go PRO now

Pay Annually & get 12 Month Free Considering VPS or a Dedicated


Services on Dedicated Server Hosting Server? Save Big !!! And go
Subscribe for the Annual Packages of with our ProX Plans
Dedicated Server Hosting & Enjoy Next 25% Off on ProX Plans - Ideal for running
Hurry!till 31st
12 Months Free Services Hurry!till 31st High Traffic or E-Commerce Website
alid alid Coupon Code : OSFY2014
Offer vber 2014! Offer vber 2014!
Octo For more information, call us on Octo Contact us at 98769-44977 or
1800-212-2022 / +91-120-666-7777 Write to support@packwebhosting.com

www.goforhosting.com www.prox.packwebhosting.com

Fees Register in
Rs. 15000/- Advance to EMBEDDED SOFTWARE DEVELOPMENT
(SC/ST/PH-50% receive a COURSES AND WORKSHOPS
Concession) BIG DATA ANALYTICS special School of Embedded
using hadoop eco-system discount Software Development
Venue: Malleshwaram, Bangalore Faculty - Babu Krishnamuthy
Date: 27th, 28th Sept. & 4th, 5th, 11th, 12th Visiting Faculty/ CDAC/ACTS Porting
18th & 19th October2014 Embedded RTOS to an ARM platform
Time: 10.00 am to 02.00pm (4 hrs.) per day
Qualification: Degree / Diploma Dates : October 11 and 12 ( 2 days program )
Trainging Contents: Introduction, HDFS Nominal
Certificates Maoreduce, Administration, Hbase, Hive, Pig fees: CDAC Alumni will get a special rate if
Will Be Sqoop, Flume, Oozie, Hadoop2.0 42/-
Rs.67siv registered in advance -please write to
e of
(inclu tax) babu_krishnamurthy@yahoo.com
Awarded For more information, call us on service
mentioning the CDAC/ACTS center
Balajee. K.M, Asst, Director, per delegate
Mob.: 9900226980, 080 41100557 and batch details

www.msmedibangalore.gov.in
FOSSBYTES Powered by www.efytimes.com

IBM brings Linux to its Power LibreOffice 4.3.1 released


System servers with 100 bugs fixed
The free, power-packed, open source,
IBM has installed Linux on its Power System servers in the company’s 54 centres personal productivity suite called
across the globe. Earlier LibreOffice has been updated to a
this year, the company new version and it’s ready for use on
announced plans of Windows, Mac OS and Linux. The
investing billions of dollars release of LibreOffice 4.3.1 has been
on the Linux platform. IBM announced by The Document Foundation
will be training developers (TDF). With this new update, 100 bugs
to build applications on have been fixed successfully. These fixes
Linux systems. Developers include RTF improvement, enhancement
can use Ubuntu, Red Hat to OOXML file handling, and
Linux and SUSE Enterprise improvement in both RTF and OOXML
Server to access parallel processing and virtualisation features. files import. The background colour of
IBM also announced a few new services recently at LinuxCon, which the Writer word processing app has been
are expected to be run on the Power Server environment. The OpenPower slightly lightened and also improved for
Foundation has made Power System architecture open source. Developers can overall stability and performance. Two
access the source code for the software and designs for hardware solutions. essential security patches have been
These services are better than generic servers in data centres. IBM claims that included and they have been back-
they are the best tools for data analytics and cloud computing. These services ported to the older 4.2.x series. This
will help IBM to expand Power System expertise in various sectors. IBM can updated version includes six feature-rich
finally focus on the untapped market segment of high performance, efficient and applications: Writer, Calc, Impress, Draw,
effective big data analytics. This move will also reduce the use of software and Math and Base.
hardware resources at data centres.
Easily add videos to
Ubuntu Installer bug formats the entire hard drive! WordPress with the new
Installing a new OS on VideoNab plugin
your PC is never a risk- PaperTelevision—one of the many start-
free task. There is always ups emerging from Cincinnati, Ohio in
a huge threat to your data. the US—has proudly announced a new
Hence, it’s recommended WordPress plugin titled VideoNab. Yes,
that you back up your hard they seem to be fond of mashing two
drive before installing words together and randomly capitalising
any OS. Many users have letters in order to form a new word.
filed reports regarding the VideoNab is a powerful WordPress plugin
‘Reinstall Ubuntu’ option in that scours YouTube for videos on any
the Ubuntu Installer over the topic. Though the results are spectacular,
past one year. According to the concept itself is simple: set the topic,
these reports, the ‘Reinstall choose a schedule for how often new
Ubuntu’ option secretly wipes the data in other partitions of the hard drive. It videos are ‘nabbed’, and VideoNab’s
also wipes out recovery images and other operating systems. This option is filtering and aggregation software handles
supposed to overwrite the existing Ubuntu installation only. Ubuntu Installer the rest. Set it, forget it, and the site
warns users that it will delete all Ubuntu programs, documents, photos, music is suddenly an automated machine of
and any other files, which creates confusion since users think that it will delete constant, fresh video content. Users can
the data residing only on Ubuntu. Hence, there is the need for a clear warning refine the settings to include comments for
from Ubuntu Installer to avoid losing data. each video, design customisations, share
them across all social media, and even use
The MIPS Creator CI20 board, a Raspberry Pi-like an integrated voting system — a nice touch
dev board for hackers for hosting contests, or simply allowing
There is a new entry among open source developers’ boards—the MIPS visitors to rate their favourite videos.

www.OpenSourceForU.com  |  OPEN SOURCE For You  |  october 2014  |  13


FOSSBYTES

Akamai warns of IptabLes and


IptabLex infection Calendar of forthcoming events
on Linux, and DDoS attacks Name, Date and Venue Description Contact Details and Website
Akamai Technologies
is a leading provider Gartner Symposium IT Xpo,
CIOs and senior IT executives from across the
world will gather at this event, which offers Website:
of cloud services for October 14-17, 2014; Grand
talks and workshops on new ideas and strate- http://www.gartner.com
Hyatt, Goa
gies in the IT industry.
delivering, optimising
and securing online content and business
Open Source India, Asia’s premier open source conference that Omar Farooq; Email: omar.farooq@
applications. Through the company’s November 7-8, 2014; aims to nurture and promote the open source efy.in; Ph: 09958881862
Prolexic Security Engineering & Research NIMHANS Center, Bengaluru ecosystem across the sub-continent. http://www.osidays.com
Team (PLXsert), it has released a new
CeBit This is one of the world’s leading business IT Website:
cyber security threat advisory that alerts November 12-14, 2014; events, and offers a combination of services http://www.cebit-india.com/
enterprises to a high-risk threat of IptabLes BIEC, Bengaluru and benefits that will strengthen the Indian IT
and ITES markets.
and IptabLex infections on Linux systems.
People with malicious intentions could use 5th Annual Datacenter The event aims to assist the community in Praveen Nair; Email: Praveen.nair@
infected Linux systems to launch distributed Dynamics Converged; the datacentre domain by exchanging ideas, datacenterdynamics.com; Ph: +91
December 9, 2014; Riyadh accessing market knowledge and launching 9820003158; Website:
denial of service (DDoS) attacks against the new initiatives. http://www.datacenterdynamics.com/
entertainment industry and other verticals.
Hostingconindia This event will be attended by Web hosting Website:
DDoS botnet threat to Linux systems: December 12-13, 2014; companies, Web design companies, domain http://www.hostingcon.com/
The mass infestation of IptabLes and NCPA, Jamshedji Bhabha and hosting resellers, ISPs and SMBs from contact-us/
Theatre, Mumbai across the world.
IptabLex seems to have been driven by a
large number of Linux-based Web servers
being compromised, mainly by exploiting Creator CI20. Imagination
Apache Struts, Tomcat and Elasticsearch Technologies has launched
vulnerabilities. Attackers have used the an ISA developer board
Linux vulnerabilities on unmaintained similar to the Raspberry Pi
servers to gain access, escalate privileges to and BeagleBone Black SBCs.
allow remote control of the machine, and Creator is Imagination’s new
then drop malicious code into the system and program, which will help it to
run it. As a result, a system can be controlled provide low cost development
remotely as part of a DDoS botnet. A post- systems for use to the open
infection indication of an attack is a payload source community—to enthusiasts, hobbyists, cross-platform developers (i.e.,
named .IptabLes or. IptabLex located in the Arduino), and partners looking to create applications using IP technologies.
/boot directory. These script files run the Creator CI20 SBC is powered by the 1.2GHz Ingenic JZ4780 system chip along
.IptabLes binary on reboot. The malware also with a PowerVR SGX540 GPU and 1GB of DDR3 RAM. It comes with 8GB of
contains a self-updating feature that causes NAND flash storage as an option and an SD card slot for expandable memory
the infected system to contact a remote host support. The board comes with a 10/100 Ethernet port, Wi-Fi and Bluetooth
to download a file. In the lab environment, an connectivity, USB OTG support, a HDMI port and CMOS camera input. The
infected system attempted to contact two IP board’s dimensions are just 90.2mm x 95.3mm.
addresses located in Asia.
Asia apparently a significant source Mozilla Firefox 32 arrives with better SSL security features
of DDoS attacks: Command and control Mozilla has announced the release of Firefox
centres (C2, CC) for IptabLes and 32, which means users of the open source
IptabLex are currently located in Asia. Web browser can now access new security
Infected systems were initially known to fixes and features. Firefox 32 supports public-
be in Asia; however, more recently, many key pinning. This feature provides better
infections have been observed on servers security for Secure Sockets Layer (SSL)
hosted in the US and in other regions. certificate authentication. The latest feature
In the past, most DDoS bot infections in the new version of Firefox combines
originated from Russia, but now Asia with other mechanisms, which are used by
appears to be a significant source of such Web browsers to enhance the integrity and
infections. authenticity of SSL certificates.

14  |  october 2014  |  OPEN SOURCE For You  |  www.OpenSourceForU.com


OSFYClassifieds
Classifieds for Linux & Open Source IT Training Institutes

IPSR Solutions Ltd.


WESTERN REGION SOUTHERN REGION
Courses Offered: RHCE, RHCVA,
Linux Lab (empowering linux mastery) *astTECS Academy RHCSS, RHCDS, RHCA,
Courses Offered: Enterprise Linux Courses Offered: Basic Asterisk Course, Produced Highest number of
& VMware Advanced Asterisk Course, Free PBX Red Hat professionals
Course, Vici Dial Administration Course in the world
Address (HQ): 1104, D’ Gold House, Address (HQ): Merchant's
Nr. Bharat Petrol Pump, Ghyaneshwer Address (HQ): 1176, 12th B Main, Association Building, M.L. Road,
Paduka Chowk, FC Road, Shivajinagar HAL 2nd Stage, Indiranagar, Kottayam - 686001,
Pune-411 005 Bangalore - 560008, India Kerala, India
Contact Person: Mr.Bhavesh M. Nayani Contact Person: Lt. Col. Shaju N. T. Contact Person: Benila Mendus
Contact No.: +020 60602277, Contact No.: +91-9611192237 Contact No.: +91-9447294635
Email: training@ipsrsolutions.com
+91 8793342945 Email: info@asterisk-training.com
Branch(es): Kochi, Kozhikode,
Email: info@linuxlab.org.in Website: www.asttecs.com, Thrissur, Trivandrum
Branch(es): coming soon www.asterisk-training.com Website: www.ipsr.org
Website: www.linuxlab.org.in
Advantage Pro Linux Learning Centre
Linux Training & Certification Courses Offered: RHCSS, RHCVA, Courses Offered: Linux OS Admin
Courses Offered: RHCSA, RHCE, PHP, Perl, Python, Ruby, Ajax, & Security Courses for Migration,
RHCE, RHCVA, RHCSS, A prominent player in Open Source Courses for Developers, RHCE,
NCLA, NCLP, Linux Basics, Technology RHCVA, RHCSS, NCLP
Shell Scripting,
(Coming soon) MySQL Address (HQ): 1 & 2 , 4th Floor, Address (HQ): 635, 6th Main Road,
Jhaver Plaza, 1A Nungambakkam Hanumanthnagar,
Address (HQ): 104B Instant Plaza, High Road, Chennai - 600 034, India Bangalore - 560 019, India
Behind Nagrik Stores, Contact Person: Ms. Rema Contact Person: Mr. Ramesh Kumar
Near Ashok Cinema, Contact No.: +91-9840982185 Contact No.: +91-80-22428538,
Thane Station West - 400601, Email: enquiry@vectratech.in 26780762, 65680048 /
Maharashtra, India Website(s): www.vectratech.in +91-9845057731, 9449857731
Contact Person: Ms. Swati Farde Email: info@linuxlearningcentre.com
Contact No.: +91-22-25379116/ Branch(es): Bangalore
+91-9869502832 Website: www.linuxlearningcentre.com
Duestor Technologies
Email: mail@ltcert.com
Website: www.ltcert.com Courses Offered: Solaris, AIX, Eastern Region
RHEL, HP UX, SAN Administration
(Netapp, EMC, HDS, HP), Academy of Engineering and
NORTHERN REGION Virtualisation(VMWare, Citrix, OVM), Management (AEM)
Cloud Computing, Enterprise Courses Offered: RHCE, RHCVA,
GRRASLinuxTrainingandDevelopmentCenter RHCSS,Clustering & Storage,
Middleware.
Courses Offered: RHCE,RHCSS,RHCVA, Advanced Linux, Shell
CCNA,PHP,ShellScripting(onlinetraining Address (H.Q.): 2-88, 1st floor, Scripting, CCNA, MCITP, A+, N+
isalsoavailable) Sai Nagar Colony, Chaitanyapuri,
Hyderabad - 060 Address (HQ): North Kolkata, 2/80
Address (HQ): GRRASLinuxTrainingand Dumdum Road, Near Dumdum
Contact Person: Mr. Amit
DevelopmentCenter,219,HimmatNagar, Metro Station, 1st & 2nd Floor,
Contact Number(s): +91-9030450039,
BehindKiranSweets,GopalpuraTurn, Kolkata - 700074
+91-9030450397.
TonkRoad,Jaipur,Rajasthan,India Contact Person: Mr. Tuhin Sinha
E-mail id(s): info@duestor.com
Contact Person: Mr.AkhileshJain Contact No.: +91-9830075018,
Websit(es): www.duestor.com
Contact No.: +91-141-3136868/ 9830051236
+91-9983340133,9785598711,9887789124 Email: sinhatuhin1@gmail.com
Email: info@grras.com Branch(es): North & South Kolkata
Branch(es): Nagpur,Pune Website: www.aemk.org
Website(s): www.grras.org,www.grras.com
FOSSBYTES

Mozilla has provided long-term support to Online Certificate Status


India-based start-up Protocol (OCSP), which is used to check with a CA on the status of a
launches maiden Linux given certificate. OCSP Stapling, an extension of OCSP, accelerates the
container-sharing website SSL certificate status-checking process. Moreover, to improve security,
Firefox 32 doesn’t contain a number of 1,024-bit trust certificates from
the browser. Additionally, Mozilla has also issued six security advisories
for vulnerabilities. Three of them are quite critical. Details of the
memory-corruption vulnerabilities have been provided by the Mozilla
Foundation Security Advisory (MFSA) 2014-67. A researcher who has
been working with Hewlett-Packard’s Tipping Point Zero Day Initiative
(ZDI) has been credited with reporting a use-after-free memory issue
(identified as MFSA 2014-72). This, in particular, was caused by setting
the direction of text on a page.

Chrome 38 brings a new responsive image


Flockport, a start-up based in Mumbai, element called ‘Picture’
announced the launch of Flockport. The pictures and photographs on websites, known as simple images, are
com, which is the first Linux container all static images. But Google’s Chrome 38 is
(LXC) sharing website that will offer set to change this old concept with a new
users popular Web applications in responsive element called ‘Picture’. This
portable containers. Users will get would introduce a new responsive
cloud-like flexibility of application design to the website, which renders
instances, which can be deployed and scales the elements on the Web
on demand. Users and developers page in the appropriate format for
accessing this website will be able to the screen size. HTML 5.1 has
download and share LXC containers; a replaced image tag with the superset
Flockport Utility will also be provided element for image containers. Google’s
to set up LXC for users, who will ‘Picture’ element is based on this
be allowed to view and download technology in W3C HTML 5.1. Some
Flockport containers directly to Linux distributions like Ubuntu, Fedora,
their systems. A fast improving openSUSE, Debian and Red Hat already have
technology, Linux containers provides 64-bit beta channel support but for the Mac, this will be the first browser
all the benefits of virtualisation to provide a 64-bit build. Currently, Mac users can run the Canary branch
without any performance penalty. of Chrome to get a 64-bit version of Chrome. This new 64-bit build of
Containers are portable and they can Chrome for the Mac should bring the most stable and usable Web browser
be cloned, backed up, launched and to the Mac platform. The Chrome 37 64-bit build for Windows is supposed
also deployed across environments. to release in the same week.
This opens up a world of flexibility
for application developers and CoreOS announces free availability of its
users. Unlike preceding container Docker-focused Linux distribution
technology, Linux containers pave the Last year, Docker emerged as one of the most discussed virtualisation
way for widespread adoption. There technologies. But running
is a significant information gap on Docker requires much effort.
LXC in the marketplace, which has CoreOS has announced that
to be addressed by Flockport. This is its Docker-focused Linux
a free service and users will also be distribution is now available
allowed to deploy containers directly for free as an image that can
to the cloud. This will help public be deployed on the popular
cloud providers broaden their market DigitalOcean cloud service.
base by allowing customers to deploy It also lowers the barrier to
complex applications in seconds. entry, and the cost for setting
up the Docker and running it.

16  |  october 2014  |  OPEN SOURCE For You  |  www.OpenSourceForU.com


FOSSBYTES

DigitalOcean is one of the fastest growing cloud vendors and offers services Avnet releases Linux-ready
for just US$ 5 a month. It runs on fast solid state drives (SSDs). ‘PicoZed’ COMs
In March this year, DigitalOcean had announced a round of funding that An array of four Linux-ready ‘PicoZed’
brought in US$ 37.5 million from investors. Droplets are deployed by users COMs has been released by Avnet.
as virtual instances of operating systems. The new partnership has brought out
the CoreOS as an image, which DigitalOcean customers can easily deploy as
a Droplet. This partnership between CoreOS and DigitalOcean does not have
a specific revenue target.

Blivet-gui–the new partition manager for Fedora


The next-gen partition
manager for Fedora
has been announced These are based on Xilinx’s Zynq-
by developer Vratislav 7000 SoCs and integrate dual ARM
Podzimek and it’s called Cortex-A9 cores with FPGAs. Avnet
Blivet-gui. This version has delivered a true COM without the
is going to replace real-world Ethernet and USB ports. The
Gparted, which is the basic design supports Linux on a variety
most popular GUI- of Xilinx Zynq-7000 system-on-chips.
based partition manager Avnet has spun off different versions
found in all major of the MicroZed for several Zynq-7000
distros. The new Blivet- models. But this PicoZed is a single
gui is based on the board which offers pin compatibility
Blivet Python library, with a greater range of Zynq SoC
which was originally Anaconda’s storage management and configuration variants. PicoZed is offered in versions
tool. This new partition manager was required as none of the existing GUI that are based on Zynq-7010, -7015,
partitioning tools support all the modern storage technologies. Fedora’s -7020, and -7030 SoCs.
Anaconda base has support for all and has been chosen as the back-end for PicoZed is aimed at industrial
the new tool. The application has been out for just a few months now and it controls, embedded vision, test and
looks to be quite interesting and useful. More developments are awaited on measurement, motor controls, and
features like RAID and BTRFS support. software-defined radio applications.
The other developer working on this project is Vojtech Trefny. Gparted’s It offers functions like memory,
look and feel is closely followed in this new version so that users get a familiar configuration, Ethernet, USB, clocks
interface. Tasks are also handled almost in the same way as tasks are added, one and power. Most of PicoZed’s
by one, and then the ‘Apply’ button is pressed. The features that have already programmable logic I/O is expressed
been implemented are: visualisation of storage devices; and creating, editing via a Low-Pin Count (LPC) FMC
and deleting disk partitions. connector. Zynq models also differ in
the tightly linked FPGA subsystem
The city of Turin to dump Windows XP and switch to Ubuntu and it offers 53,200 look-up tables
The city of Turin’s municipality is hoping to save 6 million Euros in five (LUTs). All four versions provide
years, as it has decided to switch to Ubuntu Linux from Windows XP, across access to over 100 user I/O pins
all its offices. This means that the open source operating system will be through three I/O connectors on the
installed on 8,300 PCs. This move will generate an immediate savings of rear of the module for connecting
approximately € 300 per machine. This amount will grow over the years Ethernet, USB, JTAG, power and other
as there will no longer be any need for the renewal of proprietary software control signals. According to Avnet, the
licences. The employees will also get used to the new machines, with time. four serial transceivers on the Zynq-
There is another reason behind this switchover. The computers currently 7015 and -7030 based PicoZeds are
in use in Turin’s municipal offices are quite old and might not be able to allocated to a PCI-Express x1 (Gen2)
efficiently support Windows 8 on them. Linux offers more flexibility with card edge interface, as well as the
older machines. Windows XP support officially ends this year. In early FMC connector, an SFP+ cage, and a
August, the switch to Ubuntu was officially approved and it will take one- general-purpose SMA interface.
and-a-half years to complete the changeover.

www.OpenSourceForU.com  |  OPEN SOURCE For You  |  october 2014  |  17


Buyers’ Guide

A Guide to Buying
the ‘Perfect’ Projector
Looking for a projector for the classroom, home theatre, meeting room, auditorium or
even for gaming? Here’s a guide that helps you decide between the huge variety of
models, as well as a wide range of technologies, shapes and sizes.

P
rojectors are no longer used only in those stylish meeting affordable price point, in order to get more people to indulge in their
rooms. People are now also replacing their huge LCD and craving for bold, big-screen entertainment at home. Packed with an
plasma screens with these reflectors. And gone are the days assortment of advanced features and Hitachi’s unparalleled technology
when they were categorised based on their weight. Technology and reliability, our designers have ensured that this projector truly
has changed all that! Saji Kumar, director, product management, enhances the entertainment experience — presenting movies, sports
Acer India, explains, “Earlier, we used to bundle projectors with and video games in a way that one has never seen before.”
other key products as there was not much demand for them. Now Acer believes in giving the best support to its customers. Kumar
we see so many requirements for projectors coming from various explains, “We first try and understand the requirements of our customer,
segments that we have dedicated manpower for this product. as we just don’t want to sell a product. Rather, we want to help a
It has become a key product like desktops and laptops.” Apart customer buy a product. We ask a few questions before selling our
from Acer, there are other brands like Hitachi that offer a variety product—whether the customer is looking for a home theatre, what the
of technologically advanced projectors. Tarun Jain, country room’s dimensions are, the resolution or brightness required, etc.”
head, Hitachi Home Electronics India, says, “Hitachi offers a To help you decide on what you need, here are a few factors to
comprehensive range of projectors, designed to suit varied space keep in mind.
and projection needs. Whether it is maximising screen size in a Specifications: If you’re a technical person, you will know
small room, limiting shadowing and glare, or maximising image the kind of specifications required for your projector. But if you
quality in a large space, we have a projector for every purpose.” are not, you will have to research a bit on that too. Specifications
would include a few factors that are listed below.
Comparing DLP-based projectors with Dimensions: The dimension of the room in which you plan to
LCD versions place your projector. Projectors have different configurations to
Projectors can be best described as inverted cameras which, suit the dimensions of a place.
instead of receiving light, emit it out of the lens. They fall into two Size: Projectors now have a wide range in shapes and sizes as well.
broad categories, LCD- and DLP-based. LCDs represent an old Wireless or wired: Both wireless and wired projectors are now
technology and the first projector ever launched was a LCD version. available. If you are planning to buy one for your home, you may
With time, the use of DLP projectors has become more widespread. be comfortable with the wired version but if you’re looking for a
There are many leading players in the market including Acer, projector in your meeting room then a wireless projector might be
Hitachi and BenQ, and most of them offer DLP projectors. Saji more appropriate.
Kumar states, “We focus on DLP projectors as it accounts for 60-65 Resolution: This is the number of pixels used to display an
per cent of the market.” DLP or digital light processing projectors image. If the projector has a higher resolution, it uses more pixels
use a type of MEMS (microelectromechanical systems) technology to create the image, which results in a cleaner, sharper and crisper
with a digital micro-mirror device. These projectors are used in image. A high resolution will be necessary if the projector is
a variety of display applications, ranging from traditional static intended for classrooms or meeting rooms as it will help to project
displays to interactive displays. They are also used in non-traditional charts, texts and graphs more clearly.
applications like the security, medical and industrial domains. Colour brightness or lumens: Select the level of brightness
based on the room’s dimensions. The brightness of a projector
Factors you should consider when is measured in lumens. For homes, you would need nearly
buying a projector 1500 lumens, and for classrooms and conference rooms, you
Buying a projector is a major decision and there are many factors to would need a minimum of 2500 lumens. For larger spaces like
keep in mind when doing so. Potential buyers should be very clear auditoriums, you would need even higher lumens.
about what their requirements are and then thoroughly research Distance and positioning: This refers to the distance between
what the market offers, as a projector is an expensive product to the projector and the screen. The position of the projector and
acquire. This is where companies shoulder a big portion of the the dimensions of the room or hall will determine the size of the
responsibility of ensuring buyers pick up the right product. Says image projected. You would need to look for the features that
Jain, “We have deliberately introduced this product at an extremely offer flexibility in placement.

18  |  October 2014  |  OPEN SOURCE For You  |  www.OpenSourceForU.com


Buyers’ Guide

Some of the best projectors


available in the Indian market
Acer: X1273N
ƒƒ Brightness: 3000 ANSI
ƒƒ Native resolution: XGA
ƒƒ Key features: 3D ready, 17,000:1 CR, 10,000
hours lamp life (ExtremeEco), 2 watt speaker,
VGA x 2, VGA out x1

Hitachi: CP-DH300
ƒƒ Native resolution: 1080p (1920 x 1080)
ƒƒ Brightness: 3000 ANSI lumens
ƒƒ Key features: 3D ready, weighs 2.2 kg, power supply:
AC100-120V (50/60Hz), wireless display (optional)

BenQ: MW665
ƒƒ Native resolution: WXGA (1280×800)
ƒƒ Brightness: 3200AL
ƒƒ Key features: 3D ready, weighs 2.65kg, USB
display, wireless display (optional), power
supply: AC100 to 240V, 50 to 60Hz

Epson: EB-
1420WI/1430WI
ƒƒ Native resolution: WXGA (1280×800)
ƒƒ Brightness: 3,300lm / 1,900lm
ƒƒ Key features: Weighs 5.6kg, 365W/274W
lamp, lamp type: 245W UHE

By: Manvi Saxena


The author is a part of the editorial team at EFY.

www.OpenSourceForU.com  |  OPEN SOURCE For You  |  October 2014  |  19


CODE
SPORT Sandya Mannarswamy

In this month’s column, we shift our focus to mobile application development and
discuss the issue of energy consumption of mobile apps. We also briefly cover
how a layman can quickly learn to develop Android apps.

F
or the past few months, we have been discussing characteristics being validated and documented. This
information retrieval and natural language can lead to poorly written apps causing an abnormal
processing as well as the algorithms associated drain on the device’s battery.
with them. In this month’s column, we take a break Given a smartphone with a fully charged battery,
from our discussion of NLP and, instead, focus on the user expects that the device should be usable for
mobile application development. We discuss some a certain number of hours without requiring a battery
of the recent research work on the energy consumed recharge. The user is aware that prolonged use of
by mobile apps. Then we move on to mobile app certain hardware such as the camera, GPS, etc, can
development, which has been growing at a furious shorten the period before the next recharge. However,
pace over the past few years and has attracted many in the course of using normal apps, such ‘Abnormal
non-software developers to its fold, including school Battery Drain’ (ABD) issues are not expected to
students. Learning to develop mobile apps using occur. When an ABD issue occurs, it is difficult
open source software is quite easy. In this month’s for normal users to figure out what it is caused by.
column, we have one of our student readers, Ankith Some of the potential causes could be configuration
Subramanya, who is a Class XI student from The changes; a hardware or software malfunction which
International School, Bengaluru, share his experience keeps a power-hungry hardware component such
of learning to develop an Android app. as the camera always on, even when not in use;
an app upgrade, etc. Hence, intelligent tools are
Energy consumption in mobile apps needed to diagnose ABD issues. One such tool is a
Smartphones run complete operating systems tailored research project called eDoctor, which is described
for the mobile device, and support a wide variety of in the following research paper http://cseweb.ucsd.
additional hardware devices such as cameras, GPS, a edu/~voelker/pubs/edoctor-nsdi13.pdf. eDoctor
light sensor, accelerometer, gyroscope, compass, etc. records various events such as configuration changes,
Along with such a rich plethora of ‘exotic’ hardware, app installations and app upgrades; and it monitors
smartphones also need to be extremely lightweight app phases. Using this information, it tries to pinpoint
and portable. This requires that smartphone batteries what is responsible for the ABD.
must be small and lightweight. This, in turn, implies Given the importance of conserving battery life,
that energy consumption in smartphones needs to be as smartphone OSs are designed to turn off hardware
low as possible to conserve battery life. Hence, energy components the moment they detect that they are not
consumption by mobile apps needs to be tracked and in use. Smartphones employ aggressive CPU/screen
managed to extend the battery life of smartphones. sleeping policies. Such measures can result in issues
Smartphones have become open platforms for for apps which are in the middle of communicating
hosting a variety of applications. Given the rapid pace with an external server and are waiting for data to be
of mobile app development, more and more apps are returned from the server. In such cases, the device
being developed, downloaded and installed on to the should not be put to sleep. Hence, smartphone OSs
device, without their performance, security and energy export explicit ‘wakelock’ APIs, which can be used

20  |  october 2014  | OPEN SOURCE For You  |  www.OpenSourceForU.com


by the apps to indicate that the device should not be put to is installed, periodically sends information on battery usage,
sleep. However, bugs in mobile apps can cause ‘wakelocks’ configuration settings, the set of applications installed and set
to be misused, resulting in the device continuing to drain of apps running currently to a centralised server. Data from
energy even when not in use. For instance, if an application a wide number of devices is collected, stored and analysed
has acquired a ‘wakelock’ at some point in time, it should in the centralised database, to infer statistically, a normal
release the ‘wakelock’ to allow the device to go back to sleep. energy consumption pattern for a device. If the measurements
Failure to release the ‘wakelock’ can cause continuous drain reported from the device deviate considerably from the
of the battery. There has been considerable research work on expected consumption, an energy consumption anomaly is
detecting ‘wakelock’ bugs, also known as ‘no-sleep’ bugs. A flagged by the app.
detailed discussion of ‘wakelock’ bugs can be found in the While the tools we have discussed so far help to detect
paper http://web1.cs.columbia.edu/~junfeng/reliable-software/ abnormal energy consumption by applications in smartphones,
papers/no-sleep.pdf. as an app developer, you would be interested in making
While the previous research papers we have discussed sure that your app is ‘well-behaved’ with respect to energy
focus on detecting energy bugs in smartphones by analysing consumption. The open source tool JouleUnit is an energy
the individual device’s behaviour, detecting energy profiling and testing framework, and is available at https://
consumption anomalies by analysing the behaviour in code.google.com/p/jouleunit/. The JouleUnit workbench is
individual phones is difficult since the energy consumption integrated into the Eclipse IDE, and allows you to construct
can vary widely due to different device configurations, and trigger energy tests for your app from the Eclipse IDE.
different apps co-running simultaneously, and usage under
different environmental conditions. A novel direction in Learning to develop Android apps
pinpointing energy bugs and high energy consumptions One of our student readers, Ankith Subramanya, had written to
has been proposed in the free mobile app, ‘Carat’, which is me, sharing his experience on how he rapidly learnt Android
available from http://carat.cs.berkeley.edu/. app development. Given the enormous interest in mobile app
Carat uses a collaborative approach to detect anomalies by development even from non-core programmers, I felt that it
collecting energy information from a wide variety of devices would be useful to share his experience in this column, for the
and uses that information to detect anomalous behaviour on benefit of those who are interested in learning Android app
an individual smartphone. Each smartphone on which Carat development. Here are Ankith’s comments:

Customer Feedback Form


Open Source For You

None

OSFY?

You can mail us at osfyedit@efy.in You can send this form to


‘The Editor’, OSFY, D-87/1, Okhla Industrial Area, Phase-1, New Delhi-20. Phone No. 011-26810601/02/03, Fax: 011-26817563

www.OpenSourceForU.com  | OPEN SOURCE For You  |  october 2014  |  21


CodeSport Guest Column

“I’m writing this for those novices out there who are itching is entirely your choice. As Android Studio is still in the
to develop Android apps, but don’t yet know how to. Until a early stages of development, and as only the beta version
few weeks ago, I too had no idea about creating Android apps, is available for use, I would recommend using Eclipse
but I really wanted to develop my own mobile apps. I did some (www.eclipse.org). Android apps can be made on Eclipse
reading on the Internet, and found out that Android apps are by downloading the necessary plugins. The complete
developed using Java. I was a little disheartened at first because package that you need to install, including Eclipse with
I had never learnt Java or, for that matter, any Object Oriented the necessary plugins, as well as the SDK manager (an app
Programming language. Nonetheless, I found the time in my that manages the downloading and installation of build
summer vacation to attend a few classes on Java at a local tools and libraries) is available on developer.android.com,
teaching centre. A few weeks into it, I discovered that Java is and is called the ADT (Android Developer Tools) bundle
extremely intuitive and easy to grasp. (JDK must be pre-installed). The IDE contains Java classes
“Earlier experience in Java would definitely be a plus and XML files, that are made to interact with the help of
point, but don’t be disheartened if you don’t know any Java Android manifest, which is an XML file.
at all. There are plenty of resources online to help you learn, “Essentially, each screen of an Android project is called
and using a book wouldn’t be a bad idea as well. I must stress an activity, and every activity has a backing XML file and
that getting your syntax bang on is not as important as getting Java class. Android apps follow the MVC (model view
the hang of the basics and the fundamental concepts. You controller) design pattern. The XML file, which is for UI,
should have a solid understanding of OO concepts such as acts as the view, whereas the backing Java classes are for the
object creation, inheritance, overriding, interfaces, collections, model and controller. If you do not wish to do the XML part,
packages, etc. These might sound like Greek and Latin, but the UI can be designed by the intuitive dragging and dropping
once you get started on Java, this will be your bread and of UI elements (called views), and the IDE will automatically
butter. make changes in the XML file.
“A lot of people think that knowing XML is crucial in “Debugging is made simple with the help of LogCat,
building Android apps, but the truth is that you can build a debugging tool that shows what exactly is going on at
whatever you want with no previous knowledge of XML. every step in the runtime of the application. The app that
This is basically because the XML elements are integrated you create can be run either using an emulator or on your
as a drag and drop feature in the Android environment. Also, Android device. I would recommend the latter, as the
XML is very simple and you will definitely pick it up while emulator is incredibly slow in loading. If you want to run on
building an app. Learning Android is merely about getting your Android device, make sure that you install the device
to know a few additional concepts. First, visit developer. driver. Also, if your Android version is 4.2 or higher, you will
android.com. You will find instructions there to install and need to turn on developer options. You can do this by going
set up your SDK (what you’ll need to develop the apps). to ‘About phone’ in ‘Settings’ and then clicking on ‘Build
This contains half-built Android programs, in the sense that version’. However, if you do not have an Android device,
it contains incomplete classes that you have merely to extend you will have to create an emulator on AVD (Android Virtual
(again, don’t worry about these terms, you’ll understand them Device) manager. Simple apps such as a calculator and apps
soon enough) to build your apps. This way, it becomes very to print out your name are surprisingly easy to build. Now go,
simple as you don’t have to start from scratch. get started on your Android adventure!”
“There are plenty of resources online to help you learn Thank you, Ankith, for sharing your experience on
Android. Udacity (www.udacity.org) and Coursera (www. learning Android app development!
coursera.org) offer courses on mobile app development. If you have any favourite programming questions/software
The course in Udacity, named ‘Developing Android apps’, topics that you would like to discuss on this forum, please
is interactive and is centred on the purpose of making you send them to me, along with your solutions and feedback, at
build your own weather app. The entire course involves sandyasm_AT_yahoo_DOT_com. Till we meet again next
the steps to build that app, and you are expected to do so month, happy programming!
on your own. The idea is that, from this, you will develop
your skillsets to develop your own Android apps. This By: Sandya Mannarswamy
is a very nice concept, and provides a hands-on learning The author is an expert in systems software and is currently working
experience. There is also another course available from with Hewlett Packard India Ltd. Her interests include compilers,
Coursera titled, ‘Creative, Serious and Playful Science of multi-core and storage systems. If you are preparing for systems
Android Apps’. This requires no previous knowledge of software interviews, you may find it useful to visit Sandya’s LinkedIn
Java. You may find this useful as well. group: Computer Science Interview Training India at http://www.
linkedin.com/groups?home=HYPERLINK “http://www.linkedin.com/
“The two IDEs that you can use for Android groups?home=&gid=2339182”&HYPERLINK “http://www.linkedin.
development are Android Studio and Eclipse. While both com/groups?home=&gid=2339182”gid=2339182
are very similar in many ways, I use Eclipse, though this

22  |  october 2014  | OPEN SOURCE For You  |  www.OpenSourceForU.com


Exploring Software Guest Column

Anil Seth Exploring Big Data on a Desktop


Putting Data into HDFS
Hadoop is a large scale open source storage and processing
framework for data sets. This article builds upon the previous
article in this series, ‘Exploring Big Data on a Desktop: Getting
Started with Hadoop’ that appeared in last month’s issue of OSFY.
The focus, now, is on putting data into the system.

O
nce you have the basics of Hadoop functioning, the $ sudo systemctl start hadoop-datanode
obvious question is: how does one put the data into $ hdfs dfs -copyFromLocal large_file.txt second_large_file.txt
the system? And the corollary to that is: how does $ hadoop fs -ls -h
one distribute the data between the various data nodes? Since -rw-r--r-- 1 fedora supergroup 3.3 G 2014-08-15 12:25
the system can grow to thousands of data nodes, it is pretty large_file.txt
obvious that you should not have to tell HDFS anything more -rw-r--r-- 1 fedora supergroup 3.3 G 2014-08-15 12:33
than the bare minimum. second_large_file.txt
$ sudo du -sh /var/cache/hadoop-hdfs/
A simple test [fedora@h-mstr ~]$ sudo du -sh /var/cache/hadoop-hdfs/
Your first test can be to take a large text file and load it into 3.4G /var/cache/hadoop-hdfs/
HDFS. Start the Hadoop cluster as described in the previous $ ssh -t fedora@h-slv1 du -sh /var/cache/hadoop-hdfs/
article, with three nodes. On the first test, stop the datanode 1.7G /var/cache/hadoop-hdfs/
service on h-mstr and copy a large file on two slave nodes. Connection to h-slv1 closed.
(To create a text file for testing, take a hexdump of a 1GB tar [fedora@h-mstr ~]$ ssh -t fedora@h-slv2 sudo du -sh /var/cache/
—you should get a text file of around 3GB.) hadoop-hdfs/
1.7G /var/cache/hadoop-hdfs/
$ ssh fedora@h-mstr Connection to h-slv2 closed.
$ sudo systemctl stop hadoop-datanode
$ hdfs dfs -copyFromLocal large_file.txt The new data seems to be stored on the h-mstr only. If you
run the command from h-slv2, the data is likely to be stored on
You can verify that the data has been copied and how the h-slv2 datanode only. That is, HDFS will try to optimise
much resides on each node, as follows: and store the data close to the origin. You can find out about
the status of HDFS, including the location of data blocks, by
$ hadoop fs -ls -h large_file.txt browsing http://h-mstr:50070/.
Found 1 items The file you want to put in HDFS may be on the desktop. You
-rw-r--r-- 1 fedora supergroup 3.3 G 2014-08-15 12:25 can, of course, access that file using nfs. However, if you have
large_file.txt installed the HDFS binaries on your desktop, you can copy the file
$ sudo du -sh /var/cache/hadoop-hdfs/ by running the following command on the desktop:
13M /var/cache/hadoop-hdfs/
$ ssh -t fedora@h-slv1 du -sh /var/cache/hadoop-hdfs/ $ HADOOP_USER_NAME=fedora hdfs dfs -fs hdfs://h-mstr/ -put
1.7G /var/cache/hadoop-hdfs/ desktop_file.txt
Connection to h-slv1 closed.
$ ssh -t fedora@h-slv2 du -sh /var/cache/hadoop-hdfs/ The commands -put and -copyFromLocal are synonyms.
[fedora@h-mstr ~]$ ssh -t fedora@h-slv2 sudo du -sh /var/
cache/hadoop-hdfs/ Replication
1.7G /var/cache/hadoop-hdfs/ You should stop the Hadoop services on all the nodes. In /etc/
Connection to h-slv2 closed. hadoop/hdfs-site.xml, on each of the nodes, change the value of
dfs.replication from 1 to 2 and the data blocks will be replicated
The data file is distributed on h-slv1 and h-slv2. Now, start on one additional datanode.
the datanode on h-mstr as well. Run the above commands
again, as follows: <property>

24  |  October 2014  |  OPEN SOURCE For You  |  www.OpenSourceForU.com


Guest Column Exploring Software

<name>dfs.replication</name> '--outdir','/tmp','/'.join([inpath,infile])])
<value>2</value> return '/tmp/' + infile.rsplit('.',1)[0] + '.txt'
</property> # Convert & print file as a single line replacing '\n' by '\t'
adding file name at the start
Restart the Hadoop services. Increase the replication for def process_file(p,f):
existing files and explore http://h-mstr:50070/. print("%s"%f, end=DELIM)
textfile = convert_to_text(p,f)
$ hadoop fs -setrep -R 2 /user/fedora/ for line in open(textfile):
print("%s"%line.strip(),end=DELIM)
These experiments illustrate the resilience and flexibility print()
of the Hadoop distributed file system, and the implicit # Generator for files of type odt, doc, etc.
optimisation to minimise the transfer of data across the def get_documents(path):
network. You don't need to worry about distribution of data. for curr_path,dirs,files in os.walk(path):
During your experiments, in case you come across the for f in files:
error stating that the namenode is in safe mode, run the try:
following command: if f.rsplit('.',1)[1].lower() in FILETYPES:
yield curr_path,f
$ sudo runuser hdfs -s /bin/bash /bin/bash -c "hdfs dfsadmin except:
-safemode leave" pass
# pass the root directory as a parameter
Loading data programmatically for path,f in get_documents(sys.argv[1]):
It is likely that you will need to get the data from some existing process_file(path,f)
sources like files and databases and put what you need into HDFS.
As the next experiment, you can take up the document files you You may run the above program as follows, from the desktop:
may have collected over the years. Convert each into text and load
them. Hadoop works best with large files and not with a collection $ ./load_doc_files.py ~/Documents | HADOOP_USER_NAME=fedora \
of small files. So, all files will go into a single HDFS file, where hdfs dfs -fs hdfs://h-mstr/ -put – doc_files.txt
each file will be a single record with the name of the file as the
prefix. You don't need to create a local file. The output of the The above program can be easily extended to convert and
program can be piped to the hdfs dfs -put command. load PDF files as well. Or another program can be used to
The following Python program load_doc_files.py append to the existing HDFS file.
illustrates the idea. The obvious next step is that once the data is in Hadoop, you
ƒƒ It selects document files. need to figure out how to use it and what you can do with it.
ƒƒ Each document file is converted to a text file.
ƒƒ The name of the file is output with a delimiter (a tab, in An example of modified word count
this case). Hadoop Map-Reduce offers a very convenient streaming
ƒƒ Each line from the file is read and output with the new framework. It takes input lines from an HDFS file and passes
line character replaced by a delimiter. them on standard input to one or more mapper programs.
ƒƒ On reaching the end of the file, a new line character is The standard output of the mapper programs is routed to
written to the standard output. the standard input of the reducer programs. The mapper and
reducer programs could be in any language.
#!/usr/bin/python Each line of a mapper output is expected to be a keyword,
from __future__ import print_function value pair separated by a tab. All lines with the same keyword
import sys are routed to the same reducer.
import os A common first example is a word count in a text file.
import subprocess Each line of a text file is split into words by a mapper. It
writes the word as the key with the value 1. The reducer
DELIM='\t' counts the number of times a particular word is received.
FILETYPES=['odt','doc','sxw','abw'] Since the word is the key, all occurrences of the same word
# use soffice to convert a document to text file will be routed to the same reducer.
def convert_to_text(inpath,infile): In doc_files.txt, each line is actually a file. It is very likely
subprocess.call(['soffice','--headless','--convert- that words will be repeated in a line. So, it is better if the
to','txt:Text', mapper counts the words in a line before writing to stdout, as

www.OpenSourceForU.com  |  OPEN SOURCE For You  |  October 2014  |  25


Exploring Software Guest Column

shown in the following mapper.py: def read_mapper_output(file, sep):


for line in file:
#!/usr/bin/python yield line.strip().split(sep)
import sys # add the count for each occurrence of the word
import re def main(sep='\t'):
# Generator for words in a line wc = {}
def read_input(file): for word, count in read_mapper_output(sys.stdin, sep):
for line in file: wc[word] = wc.get(word,0) + int(count)
yield re.compile('\W*').split(line) # print the sorted list
for word in sorted(wc):
def main(sep='\t'): print("%s%s%d"%(word,sep,wc[word]))
for words in read_input(sys.stdin): if __name__ == "__main__":
wd_dict={} main()
# count the number of occurences of a case-insensitive word
for word in words: So, having signed into fedora@h-mstr, you may run these
if word != '': commands to count the words and examine the result:
wd = word.lower()
wd_dict[wd] = wd_dict.get(wd,0) + 1 $ hadoop jar /usr/share/java/hadoop/hadoop-streaming.jar \
# print each word and its count -files mapper.py,reducer.py -mapper mapper.py -reducer
for word in wd_dict: reducer.py\
print('%s%s%d'%(word,sep,wd_dict[word])) -input document_files.txt -output wordcount.out
if __name__ == "__main__" : $ hadoop fs -cat wordcount.out/part-00000 | less
main()
There is no need to change the reducer function as long As seen in the earlier experiments, you can store the data
as it had not assumed that the count of each word was 1. The in a HDFS file using any programming language. Then, you
corresponding reducer.py: can write fairly simple ‘map and reduce’ programs in any
programming language, without worrying about any issues
#!/usr/bin/python related to distributed processing. Hadoop will make the effort
import sys to optimise the distribution of the data across the nodes as well
# convert each line into a word and its count as feed the data to the appropriate mapper programs.

OSFY Magazine Attractions During 2014-15


By: Dr Anil Seth
Month Theme Featured List buyers’ guide
The author has earned the right to do what interests him.
March 2014 Network monitoring Security You can find him online at http://sethanil.com,
------------------- http://sethanil.
blogspot.com, and reach him via email at anil@sethanil.com
April 2014 Android Special Anti Virus Wifi Hotspot Devices

May 2014 Backup and Data Storage Certification External Storage

June 2014 Open Source on Windows Mobile Apps UTMs fo SMEs

July 2014 Firewall and Network security Web Hosting Solutions Providers MFD Printers for SMEs

August 2014 Kernel Development Big Data Solutions Providers SSDs for Servers

September 2014 Open Source for Start-ups Cloud Android Devices

October 2014 Mobile App Development Training on Programming Languages Projectors

November 2014 Cloud Special Virtualisation Solutions Providers Network Switches and Routers

December 2014 Web Development Leading Ecommerce Sites AV Conferencing

January 2015 Programming Languages IT Consultancy Service Providers Laser Printers for SMEs

February 2015 Top 10 of Everything on Open Source Storage Solutions Providers Wireless Routers

26  |  October 2014  |  OPEN SOURCE For You  |  www.OpenSourceForU.com


Insight Developers

Open Source Tools That Simplify


Tasks for C Programmers
This article will interest programmers and engineering students. It describes various open
source tools that C programmers ought to add to their toolkit.

E
ven though C was developed around 1973, it still elicits many people still cling to this tool, citing ease of use. I have had
a fair share of interest from professional programmers. a difficult time convincing others how easy it is to use the Linux
But beyond this, C is also the preferred language of environment to program in C, and this article has its roots in my
academia. There is possibly not a single university in the frustration over this argument. In this article, I have presented a
world which does not have a C programming paper in its few open source tools that will make the life of a C programmer
undergraduate curriculum. The destinies of C and UNIX comfortable in the Linux environment.
have been intertwined ever since they were created. C is There are lots of open source tools that can be used to
most powerful when it is used with UNIX. In fact, the system automate and simplify many of the steps involved in program
calls and commands of UNIX/Linux invigorate C programs. development, using C. This list is in no way comprehensive,
Unfortunately, in India, this language is most often taught using but the tools have been selected based on my experience
proprietary tools. To add insult to injury, the most widely used and personal preferences. So the relevance of a particular
IDE is Turbo C++ for Microsoft Windows, a product of Borland tool might be debatable, occasionally, but the general idea is
Software Corporation, an erstwhile software company. The last to introduce some useful tools to the interested user. Open
stable version of this IDE was released in 1996, which makes it source tools from the following categories will be discussed:
as old as many of the first-year undergraduate students who use • Integrated Development Environments
it. In 2006, the Turbo C++ IDE was released as freeware, which • Build automation tools
effectively tells us that the software has become obsolete. But • Revision control systems

www.OpenSourceForU.com  |  OPEN SOURCE For You  |  OCTOBER 2014  |  27


Developers Insight
• Debuggers Revision control systems
• Code coverage tools Another important tool that should be in the arsenal of a C
• Static code checking tools programmer is a revision control system, a.k.a. a version
• Dynamic code checking tools control system. A revision control system is used when the
• Profiling tools changes made to the software being developed are very
• Code formatters high, which makes it difficult to version properly. Here too,
• Documentation generators we have to choose from a wide list of tools, which include
• Open source libraries Mercurial, RCS, CVS, etc. Among all the different tools
available, Mercurial is very simple and efficient.
Integrated Development Environments The command hg init is used to initialise the repository by
An Integrated Development Environment (IDE) is an application creating a directory called .hg. The hg status command tells
that provides comprehensive facilities for software development. us the status of the files being tracked by the repository. hg
There are a large number of IDEs available for C programmers. add file_name is used to add files for tracking. You can use
Some of the popular open source IDEs include Code::Blocks, the command hg commit to save different versions of your
CodeLite, Geany, etc. In this race, Code::Blocks is the clear program files. hg log gives the details of different versions
winner because of its ability to perform debugging, profiling, being tracked by the repository. And to revert to older
code completion, code coverage testing and static code analysis. versions, use hg revert –ar version_number.
Moreover, if you are an expert user of Code::Blocks, there won’t One common error message that haunts first time users of
be many practical situations for which you will need another Mercurial is ‘abort: no username supplied (see «hg help config»)’.
tool for program analysis. Code::Blocks is a cross-platform If you get this error, you should edit the file .hgrc located inside
application that will work on Windows, Linux and Mac OS X. your home directory and add the following lines of text:
The different compilers supported include GCC, MinGW, Digital
Mars, Microsoft Visual C++, Borland C++, LLVM Clang, etc. [ui]
The latest stable version is Code::Blocks 13.12, which was username = Your Name <your@email.com>
released on December 27, 2013.
Debuggers
Build automation tools For novices, writing a program devoid of syntax errors is
Build automation is the process of automating tasks like a difficult task. But the real difficulty occurs while dealing
compiling source code to binary code, running tests and with run time errors. As the size of the program increases,
deploying the final application. Here too, we have a wide variety identifying bugs that cause run time errors becomes more and
of tools to select from. Some of the popular tools include Make, more difficult. In order to debug large programs, we ought
Waf, and Automake. Waf is a Python-based tool which is gaining to get help from debuggers like GDB, DBX, DDD, etc. The
popularity. But Make is still the preferred tool for C developers. debugger GDB (GNU Debugger) has become so popular and
C program compilation can be automated with the Make utility influential that the selection of a debugger is made very easy
by executing the command make. This will execute the Makefile, for most of the programmers. In fact, most other debuggers are
which should contain all the rules to automatically compile and influenced by GDB, with DBX being the only real competitor
build an executable from the source code. The rules mention that is not based on the philosophy of GDB. The success of
prerequisite files and actions to be carried out in order to obtain a GDB even led to the development of a GUI-based debugger
target file. You can download the source code of the C program called DDD (Data Display Debugger) based on GDB.
and a Makefile from http://opensourceforu.com/article_source_ GDB allows you to inspect various program parameters
code/sept14/make.zip. The zip file contains two C program files during and after program execution. Errors like segmentation
main.c and fun.c, a Makefile to build the source files and an faults are identified with relative ease using GDB. The C
image showing the output of Make. program fragment given below contains a run time error and
There is some criticism about the Make utility regarding GDB is used to uncover it.
the rigid structure and syntax of the Makefile. Some criticism is
based on the fact that Make offers too little in comparison with int a=111,b=0,div;
other tools like Waf. But, personally, I believe the best feature div=a/b;
of Make is its simplicity and the criticism arises from the fact printf(“After division result is %d\n”,div);
that it has been in use for the past 30 years. As often quoted,
familiarity breeds contempt and with that, I rest my case. The program compiles without any syntax errors but
Another tool which is often mentioned in conjunction contains a logical error. The program should be compiled as
with build automation is Automake, which is part of the GNU follows to enable debugging with GDB: gcc -g program_
toolchain. Automake is an autotool used to automatically name.c. The option -g enables built-in debugging support
generate Makefiles for the Make utility. required by GDB. You can start the GDB debugger by using

28  |  OCTOBER 2014  |  OPEN SOURCE For You  |  www.OpenSourceForU.com


Insight Developers
option -Wall shows all the warnings, the option -fprofile-arcs is
to deal with the execution of branch statements and the option
-ftest-coverage adds the number of times each line is executed.
After compilation, the program should be executed once before
calling the Gcov utility. The following command calls the Gcov
utility: gcov program_name.c. This will create a file called
program_name.c.gcov which contains the output of Gcov. This
file contains the program annotated with the line number and
the number of times each line is being executed. Dead code that
never gets executed is marked with the symbol ‘#####’. Figure 1
shows the output of Gcov for a program called gcov_example.c.

Static code checking tools


Static code checkers uncover security vulnerabilities and coding
mistakes. Static code checking is carried out by analysing
the source code or the object code. In static code checking
the executable code is never analysed. The standard static
code checking utility of Linux was Lint. But nowadays, the
most popular static code checker for the Linux environment
is Splint (Secure Programming Lint). Splint can uncover
unused declarations, the use of variables before definition, type
inconsistencies, unreachable code, ignored return values, infinite
loops, etc. Consider the program buggy_program1.c for a
demonstration of Splint’s ability to uncover potential errors.
Figure 1: Output of Gcov
#include<studio.h>
the gdb command. The transcript below shows the GDB int main()
session, which debugs the program gdb_example.c. {
int i;
(gdb) file ./a.out printf(“\n%d\n”,i);
Reading symbols from /root/Desktop/gdb/a.out...done. i=’A’;
(gdb) run printf(“%d”,i);
Starting program: /root/Desktop/gdb/a.out i=++i+i++;
Program received signal SIGFPE, Arithmetic exception. printf(“\n%d\n”,i);
0x08048422 in main () at gdb_example.c:8 }
8 div=a/b;
The program can be processed with Splint by using the
The message clearly tells us that the run time error is due to following command, splint program_name.c. This will list many
division by zero. The command file is used to open an executable unwanted warnings about potential threats which do not hinder
file for processing by GDB. The run command runs the program program processing. These warnings can be suppressed by turning
completely if there are no errors and stops processing with a on the flag weak, as follows, splint -weak program_name.c.
diagnostic message at the first instance of a run time error. A very The three potential logical errors in the program buggy_
rich command set is available for fine tuned debugging of buggy program1.c are uncovered by Splint after analysing the source
programs and this makes GDB a tool of great importance. code. The three potential problems are the use of variable ‘i’
before initialisation, the assignment of a character value to the
Code coverage tools integer variable ‘i’ and the use of the undefined expression
Source code coverage analysis tools tell the programmer the ++i+i++. This shows us that Splint can uncover many
number of times each instruction in a program is executed. This potential threats unidentified by the compiler.
information can be further used by the programmer to remove
dead code and optimise the frequently executed instructions Dynamic code checking tools
in a program. GCC offers a very simple and elegant tool for Dynamic code checking involves the analysis of the executable
code coverage analysis called Gcov. The program should be file and system execution of a program to identify potential threats.
compiled as follows to enable the proper working of Gcov: Let’s discuss a dynamic testing tool called Valgrind, which is used
gcc -Wall -fprofile-arcs -ftest-coverage program_name.c. The for memory debugging and memory leak detection. Sometimes

www.OpenSourceForU.com  |  OPEN SOURCE For You  |  OCTOBER 2014  |  29


Developers Insight
even the most advanced programmers commit memory related
errors. This makes Valgrind a tool that’s sought after even by the
most seasoned programmer. The working of Valgrind is explained
with the help of the program buggy_program2.c given below.

/* Program name : buggy_program2.c */


#include<stdio.h>
#include<stdlib.h>
int main( )
{
char *ptr=calloc(5,sizeof(char));
ptr[5]=’A’;
}

This program is compiled to get the executable by typing the


command gcc program_name.c. The executable created is used by
the Valgrind utility to identify memory related vulnerabilities. There
are multiple tools in Valgrind. The default and most frequently used
one is Memcheck. The command for invoking Valgrind is valgrind
executable_name. Valgrind will identify both the memory related Figure 2: Beautifying programs with Astyle
errors in the program, the invalid write at location ptr[5] and the
memory leakage of 5 bytes caused by not calling free( ). return 0;
}
Profiling tools
Profiling tools are used to analyse the performance of a program. The Gprof utility should be enabled while compiling the
They are used to analyse both the space and time complexity of program as follows: gcc -p program_name.c. Before calling
a program. They also carry out a form of dynamic code analysis. Gprof, the program should be executed once. This will create
The most widely used performance analysis tool for C is Grprof, a file called gmon.out. This, along with the executable file,
an extended version of an older tool called prof. Profiling should is used by the Gprof utility to analyse the performance of
be enabled while compiling the programs as follows. A program the program. The command to call Gprof is: gprof a.out
called gprof_example.c is used to analyse how Gprof works. gmon.out. The time taken by various functions can be easily
understood from the output of Gprof. If the program gprof_
/* Program name : gprof_example.c */ example.c is processed with Gprof, then you will observe that
#include<stdio.h> the execution time for function delay2( ) is roughly 10 times
void delay1( ) that of function delay1( ). This sort of information can be
{ further used to identify functions that require optimisation.
int j;
for(j=0;j<10000000;j++); Code formatters
printf(“\nIn function delay1\n”); There are programming languages like Python and Occam in
} which the formatting style of the program is as important as
the syntax to get the correct output. Such languages force the
void delay2( ) programmer to write well intended programs. But C is a free-
{ form language, which does require proper formatting to obtain
int k; the correct output. The result of such freedom, if misused, often
for(k=0;k<100000000;k++); gives nightmares and sleepless nights to many a programmer.
printf(“\nIn function delay2\n”); It is very difficult to debug programs if the code is not properly
} intended. Many different styles have been proposed for formatting
int main( ) C programs. Some of the very popular ones are K&R style,
{ GNU style, Kernel style, etc. Problems arise when programmers
int i; with different formatting styles work together on a project. This
for(i=0;i<1000000;i++); problem can easily be solved by using a code formatter, which can
printf(“\nIn function main\n”); translate code from one style to another. The most widely used
delay1( ); code formatter in the Linux environment is Astyle. It supports
delay2( ); multiple styles like Allmann, KR, GNU, etc, which are suitable

30  |  OCTOBER 2014  |  OPEN SOURCE For You  |  www.OpenSourceForU.com


Insight Developers
for formatting C programs. Astyle also has other options to set etc. OpenGL is a cross language application programming
parameters like the bracket style, tab size, indentation style, empty interface to handle 2D and 3D vector graphics. It is used in
line padding, etc. Figure 2 shows a program called astyle_example.c CAD, flight simulation, scientific visualisation, etc. OpenCV
formatted in a style that ought to be called ‘chaos’. If the program is a library of functions that can be used for applications
was a bit lengthier, it would have been impossible to fathom and related to computer vision. Even though the latest interface
any decent programmer would curse me for my insolence. But the is based on C++, OpenCV still maintains an older C-based
figure also displays the magic of Astyle by changing the format interface. OpenSSL is an implementation of SSL and TLS. It
of the program to GNU style. Yes, the ugly duckling has finally contains a lot of cryptographic functions to be used in security
become a swan. The original unformatted program is stored in a file related applications. And remember, this is just the tip of the
called astyle_example.c.orig. iceberg; there are hundreds of useful open source libraries.
A thorough discussion of all the tools and packages
Document generators described in this article will take up scores of text books. I
While writing efficient programs involves logical reasoning hope this introduction will help you start a lifelong journey on
and is hence a task for the left hemisphere of the human brain, interacting with the elegant language called C. The best thing
preparing documentation involves creativity and is handled by about the tools discussed here is that they are all open source
the right hemisphere of the brain. No computer in the world can technologies. Hence, there are countless manuals freely
perform creative writing, but automatic document preparation available on the Internet. Go through the manuals and learn
from specially commented programs has become a reality. these tools; you can use them with many other languages and
Document generators are able to produce API documentation for platforms because most of them are not limited to C.
programmers and user manuals for end users. Doxygen is one of
the most widely used document generators and one that is highly By: Deepu Benson
suitable for the C language. It can cross-reference documentation The author has nearly 15 years of programming experience and
and code, and the documentation part is written within the code. is working as an assistant professor in Amal Jyothi College of
The program fragment shown below contains Doxygen based Engineering, Kanjirappally, Kerala. He maintains a technical blog
at www.computingforbeginners.blogspot.in and can be reached
comments. The comments are ignored by the C compiler but they at deepumb@hotmail.com.
are recognised and processed by Doxygen.

/**
EMBEDDED SOFTWARE
DEVELOPMENT
* @file doxygen_example.c
* @author deepu
* @date 15 Jul 2014 COURSES AND WORKSHOPS
* @brief Example for using doxygen with C.
*/

Porting an Embedded RTOS -


Doxygen can be called as follows to process the C file: Driver Development and Board Support
doxygen program_name.c. It can prepare documents in the form FACULTY : Babu Krishnamurthy
of HTML, XML, RTF, etc. Doxygen can also produce a Latex (Visiting Faculty, CDAC/ACTS - with 18 years of Industry
file as output, which can be further processed to obtain output and Faculty Experience)
in the PDF or DVI format. The example program given above AUDIENCE : BE/BTECH Students, PG Diploma Students,
uses only the basic tags. There is a large set of tags available to ME/MTECH Students and Embedded / sw Engineers
prepare all kinds of documentation. NOMINAL FEES : Rs. 6742.00 (inclusive of taxes) per delegate
DATES : October 11 and 12 ( 2 days program )
Open source libraries VENUE: School of Embedded Software Development,
One severe criticism that C has faced over the years is with M.V. Creators' Wing,
respect to the scarcity of useful library functions. To some 3rd Floor, #218, Sunshine Complex, Kammanahalli,
extent, this is true, because when compared with languages 4th Main, 2nd Block, HRBR Layout, Kalyan Nagar,
Bangalore - 560043.
like Java or Python, the number of library functions is (Opposite to HDFC Bank, Next to FoodWorld
comparatively less. But to overcome this drawback and to aid and near JalaVayu Vihar )
us in development, there are countless open source libraries that Email : babu_krishnamurthy@yahoo.com
can be used along with the C standard library. The open source Phone : 080-41207855
libraries range from the ones which allow us to draw images, to SMS : +91-9845365845 ( leave a message and we will call you back )
the ones which add security to our systems. UPCOMING COURSES :
Some of the open source libraries widely used along Linux Device Drivers - Architecture, Internals and Programming
Dates - November 14, 15 and 16 ( 3 days program )
with the C language include OpenGL, OpenCV, OpenSSL,

www.OpenSourceForU.com  |  OPEN SOURCE For You  |  OCTOBER 2014  |  31


Developers Insight

Tornado: A Python Web Framework


That’s Simple and Quick

This article presents Tornado, the Python Web framework. Originally developed at FriendFeed,
Tornado is an asynchronous networking library. It is able to scale up to tens of thousands of
open connections with the help of its non-blocking network I/O.

A
part from introducing you to Tornado, this article is Facebook’s real time Python Web framework (we will go
explores the extent to which it can be scaled, its into this later). It enables a clean approach to Web server
features, the installation process, and its advantages programming, focuses on non-blocking operations and scales
compared to other Python Web frameworks. This article to an enormous number of open connections. Tornado is an
is meant for those interested in knowing more about Web asynchronous networking library that was originally developed
designing as well as Web developers. It may even be helpful at FriendFeed, a kind of social network that enables you to
to serious Python developers or contributors trying to explore share the issues you found on the Web and it allows discussions.
ways to improve their Web development skills. FriendFeed was acquired by Facebook in 2009 and Tornado
A framework is a collection of programs that uses was open sourced soon after. Django, CherryPy, web2Py, Grok,
a control mechanism to structure code to build a bigger Pylons and TurboGears are some of the other frameworks.
system. We can develop simple websites using basic
designing languages like HTML, CSS, Python, etc. However, Why Tornado?
considering the complex and dynamic nature of the Web, it is So why is Tornado preferred, even though Python has a
difficult to do this at a low cost and within the short deadlines number of frameworks? Well, Tornado is noted for its high
that sites are typically developed. Hence, developers want performance and supposedly has the capacity to solve the
something that empowers them and has fewer bugs. The C10k problem (problem of optimising network related issues
purpose of a Web framework is to provide some features that so that it can handle a large number of clients at the same
are essential for all kinds of applications, such as database time) that affects other servers. Tornado focuses on speed and
support, URL handling, HTML templating, etc. handling large volumes of simultaneous traffic.
Python is one of the most used general-purpose Let’s look at those features of Tornado that differentiate it
programming languages. It is also used as a scripting language from other frameworks.
but mostly in non-scripting contexts. Python’s environment Built-in support: Tornado comes with built-in support
consists of a number of Web frameworks, ranging from the and finds solutions for most of the tedious aspects of Web
minimalistic to the fully bloated. Tornado is one of the best development like templates, localisation, signed cookies, etc.
Web frameworks of the Python programming language. It Tornado also allows users to mix it with other frameworks,

32  |  OCTOBER 2014  |  OPEN SOURCE For You  |  www.OpenSourceForU.com


Insight Developers
with matching snippets, according to their needs.
Concurrent connections: Tornado offers real time services
and supports a large number of concurrent connections, HTTP Python
streaming (a communication protocol implemented by Apple
Inc) and long polling (it is a ‘push’ technology, which allows
an emulative push mechanism under circumstances in which a
real push is not possible). With Tornado, it is very easy to write
real time services. FriendFeed maintains an open connection, Django Flask Bottle
especially for its frequently involved users.
High performance: This is Tornado’s most attractive
feature. It is very fast compared to all other Python Web Figure 1: Python frameworks
frameworks. Considering its baseline output, it is around four
times higher in speed and pretty efficient also. To run your application in a terminal, use:

Getting started with Tornado python app.py


Tornado platforms: Tornado runs on most of the platforms
like UNIX, Windows, and so on. For better performance and Finally, you should be able to visit your website at http://
scalability, only Linux with EPoll (a Linux kernel system call localhost:8888
which replaced older calls to achieve better performance),
and BSD (Berkeley Standard Distribution) with KQueue (an Tornado and other Python Web frameworks
event-notification interface) are recommended for effective Pyramid, Flask, Bottle and Django are among the well known
production deployment. Windows is officially not supported frameworks of Python.
but is recommended only for development purposes. Pyramid is a small framework which makes real-world
Installation: Tornado is listed in PyPI, which is a Python Web applications productive. Its advantages over other
Package Index—a repository of software for the Python frameworks are:
programming language. As Tornado is listed in PyPI, it can be ƒƒ A quick start
installed easily using Pip: ƒƒ Flexibility
ƒƒ Compatible with Python 3
pip install tornado ƒƒ Ability to develop large Web applications, etc.
Flask is a micro framework of Python which is easy to set
As an example, let’s create a new project called up and comes with a built-in server. Flask’s main features are:
webappdemo. We have the app.py python file whose contents ƒƒ It implements most commonly used core components
are as follows: ƒƒ Provides users a choice for database access or validation
_app_: It is the main method for Python to start executing ƒƒ Flask extensions are available
and is the entry for the program. Bottle is a framework that provides minimal tools out-of-
tornado.ioloop: The ioloop class is the main event for the-box (routing, templating, etc).
any application which can create a non-blocking thread for an It also comes under the category of ‘micro’ , which enables
application. compilation in Python 3. Some of the other features of Bottle are:
tornado.web: This is the basic module of Tornado, which ƒƒ Ability to build simple projects
implements a lightweight Web development framework. It was ƒƒ Efficient in creating Web application interfaces
built in FriendFeed using their non-blocking HTTP server and ƒƒ Flexibility
low-level I/O modules. In this demo, MainHandler is the single Django is a powerful Web framework that is supported
handler mapped to the root path. by a large and active community. It offers model-based forms
MainHandler: This is a handler for a request, which refers and has its own excellent documentation. Django makes it
to the self.write() method. The MainHandler class returns the easier to build better Web applications, quickly and with
response using this method. less code. It is a high-level Python Web framework that
application listen (8888): We look at the specification 8888 encourages rapid development and perfect design.
first. It is just a port which the application considers (i.e., listens Some of the attractive features of Django are:
to). Any one can communicate with this application through ƒƒ Predefined powerful admin interface
this particular port (8888). ƒƒ Offers model-based forms
It’s now time to run the application. You can run this simple ƒƒ Django extensions are available
application in a terminal (if you are using Ubuntu). If you are ƒƒ Has useful applications
using the Windows platforms, you can run this application The purpose of a Web framework is to provide
using the command prompt. some common features that are essential for all kinds of

www.OpenSourceForU.com  |  OPEN SOURCE For You  |  OCTOBER 2014  |  33


Developers Insight
applications. The Model-View-Controller (or MVC) is software its template system efficiently.
for implementing user interfaces and is the de-facto standard The template system syntax of Tornado is a lot like Django’s
for developing Web applications. Both Tornado and Django and almost interchangeable: you get template inheritance, variable
provide some form of database support, HTML templating, binding, looping and localisation support just as with Django.
domain handling, etc. Yet, it executes a lot faster with less code under the hood. You
can also short-circuit template compilation for speed by carefully
Tornado vs Django instrumenting which files you’ll include conditionally. The
Even though both Tornado and Django provide the MVC template values are replaced in Django when you assign variables
architecture, they are at opposite ends of the spectrum. to an HTML template. This is also possible for the programs
Django is more mature and is one among the largest written outside of the Python code. This is fairly standard practice
Web-based frameworks for Python. It has a lot of features and these days and Django does a great job of it. The template
takes care of the details for the user, so that you do not need to inheritance is a simple yet powerful way of defining standard
understand all the basics when making a fully-featured website. headers and footers, as well as other features, so that they exist on
It is stable and user friendly too. But Django is very hard to every page. The templating is not the fastest on the Web, however;
customise and troubleshoot, in some situations, due to its all- so you should plan for additional processing time.
encompassing nature. This is one of its drawbacks. Since it is such a mature system, Django has all kinds
Tornado is lighter in weight and has a few more features of other features as well: user authentication, localisation,
than Django. As I said earlier, Tornado is known for its high Unicode handling, and the list goes on. If you want a
performance. It runs faster and provides an asynchronous framework that will cover everything you can possibly need
IOLoop for polling requests, and a variety of oauth and social and you just don’t have the time or skill to do a lot of the
media features. It is small in size and runs fast. And it is work to get it done, then Django is a great system for you. An
customisable to the tiniest detail. interesting fact about it is the way it’s described—Django is the
Django actually fits most of the platforms. HTTP requests Web framework for perfectionists with deadlines.
are a fundamental part of every Web application. This applies The real differentiating glory of Tornado is the IOLoop, an
to Django too. Controllers of this framework allow regular asynchronous software library that integrates directly with kernel
expression matching on URLs, to call the appropriate functions EPoll, KQueue and similar facilities. Also known as an Event
and field incoming requests. It assures sensible default requests Loop, this style of programming allows your program to detach
and responses, with the ability to override. Tornado is the leanest its flow control, so the system can respond to another Web request
and meanest among the featured Python Web frameworks. As I while you wait for the kernel to dispatch your event. Tornado gives
mentioned before, Tornado is fast, and is small too—in the sense you great access to the internals of the system to make it do exactly
that it is simple and yet efficient. These features make access what you want. The localisation and Unicode support is pretty
points easy for extending the framework itself and directly thorough - you can create CSV key/value pair files, and look up
managing the basic expectations of a Model View Controller the values based on the browser language headers. As long as you
framework. It also manages the basic operations of your website, design your system in an open manner, you can serve your whole
such as parameter parsing, HTTP handing, etc. URLs of both website in multiple languages and ensure it executes faster.
Django and Tornado are almost similar. The only difference is I do hope you’ve got a basic understanding of Python Web
that they use separate classes for each request. This makes it frameworks and familiarised yourself with Tornado. Now it’s
possible to create a class hierarchy for your requests, and then your turn to dive into the code and come up with amazing Web
you can paste together a series of pages into a single parent class. applications. If you’re starting a new project, I highly recommend
If you want to start a company or business that involves Python. It’s a great language with enough clarity, speed and
collecting data from users and storing it in a database, Django will features for you to bring together a global team to build a high-
really help you out. It has a form generator, which will allow you performance website. If you want to choose a Web framework that
to define patterns for the database, and it also helps in generating suits your team and project, the Python community members are
HTML for an application which validates data on submission. The there to help you out! They are really awesome!
sophisticated data model reads your existing database schema,
or creates one for you, and generates code to define the schema References
as software objects. In Tornado, the database connectivity is not [1] https://devcharm.com/articles/16/tornado-examples/
built in by default, but it does not exist in a separate package and [2] http://carlosgabaldon.com
[3] http://backchannel.org
is known by the name torndb. This database helps in connecting [4] https://wiki.python.org/moin/WebFrameworks
to MySQL and issues your queries. For example, if you want
to create your own environment for managing connections and By: Anjana S
retrying failed queries, then this is the one place you make real use
The author is an open source enthusiast. She can be reached at
of Tornado. It will work exactly how you want it to.
anjanasasindran123@gmail.com.
Django provides the ‘View’ part of MVC by making use of

34  |  OCTOBER 2014  |  OPEN SOURCE For You  |  www.OpenSourceForU.com


Let’s Try Developers

Building Web Applications


Using the Python Flask Microframework

Here’s an introduction to Flask Microframework, which can be used to easily build and deploy
good Web applications with the minimum of effort and time. Added security and functionality
for the app is provided by the Jinja 2 engine.

F
lask is a microframework written in Python. It is a entity tags, cache control headers, HTTP dates, cookie handling,
lightweight Web application framework, which uses the file uploads and a powerful URL routing system. It does not force
Werkzeug WSGI and Jinja2 template engine. There is you to use a specific template engine or any other extension, but
no database abstraction layer or form validation layer, because leaves everything else to you, the developer, to choose.
the core is kept simple and supports extensions, which can add
application features. There are many different extensions available Jinja2
for Flask to support databases, upload files, for authentications, This template engine is mainly used for creating static or
form validation, etc, which the user has to import and use. dynamic Web pages with minimal coding. A basic layout can be
set up and used for a large number of static or dynamic pages
The Werkzeug WSGI (Web Server Gateway Interface) with little coding. Flask uses the Jinja2 template engine, inspired
WSGI is the interface between Web servers and Web applications by the Django framework. The Jinja template adds sandboxed
for Python. At present, Werkzeug is one of the most advanced execution for security reasons. It features the automatic escape of
WSGI utility modules. It includes a powerful debugger, fully HTML from XSS Vulnerability and uses inheritances.
featured request and response objects, HTTP utilities to handle Flask is built on the above two libraries, the Jinja2

www.OpenSourceForU.com  |  OPEN SOURCE For You  |  OCTOBER 2014  |  35


Developers Let’s Try

template engine and Werkzeug WSGI. The remaining Our first app
decisions are left to you, as the developer. You can choose Let’s create a directory for our application to start off with
different extensions depending on your needs and interests. Flask, as follows:
Let’s create a simple Web application using Flask.
$ mkdir myapp
Flask installation $ cd myapp
As a prerequisite, you need Python 2.6 or higher to get
started, and Pip, which is a tool to install and manage Python File structure:
packages. Pip makes it easy for users to install and uninstall myapp
Python packages in a single command. For example: __init__.py
manage.py
$pip install PackageName templates/
$pip uninstall PackageName about.html
base.html
You have two ways to install Flask on your machine. You index.html
can either choose a virtual environment that allows you to work posts.html
in an isolated environment with a separate copy of Python, and static/
without worrying about affecting other projects if anything goes css/
wrong, or you can go for a direct installation of Python and Flask style.css
on your native machine. I have explained both the methods here.
Let us first try the virtual environment using Pip. Ubuntu Create the directories and files which are listed above.
users can try it directly without Pip. __init__.py will create an object for application using
Flask and will be ready to run the app.
$sudo pip install virtualenv manage.py will handle all URL routing properties and content.
The templates directory contains all HTML pages needed for the
Ubuntu users should use: applications and static contains all static resources like the style
sheet, images, etc; this is handled by the Jinja2 template engine.
$sudo apt-get install python-virtualenv
__init__.py file
…to begin the virtual environment, and activate it by
issuing the following command: from flask import Flask
app = Flask(__name__)
$ virtualenv venv
$ . venv/bin/activate if __name__ == ‘__main__’:
app.run(debug = True)
You can deactivate virtualenv as follows:
The above code will create an instance (app) for our app using the
$deactivate Flask class. The app.run method is used to run the local server with
our application; we have imported the app object via manage.py, so
Once you have activated virtualenv, you are ready to we can run the server from there.
install Flask in the virtual environment. Do so by using debug = True will automatically restart and reload the server if
Python package management. any modifications are done to any file of the application.
The app.run method is not actually needed here, because we
$pip install Flask are going to import app instance in the manage.py file and we
$pip install flask-script can run the server from the manage file.

You can install Flask directly in the system by avoiding the manage.py file
virtual environment (sometimes Flask comes with Python):
from flask import Flask, url_for, render_template
$ pip install Flask from flask.ext.script import Manager, Server
$ pip install flask-script
import os, sys
Once successfully installed, you can go ahead to create a sys.path.append(os.path.abspath(os.path.join(os.path.
simple Web application. dirname(‘__file__’),’..’)))

36  |  OCTOBER 2014  |  OPEN SOURCE For You  |  www.OpenSourceForU.com


Let’s Try Developers

#importing app from the __init__.py file, path can be obtained sys, and app object is imported from the __init__.py file.
from the above statement manage.py will take care of routing and content in our
from article import app application. Routing can be done using the @app.route()
manager = Manager(app) method, which takes string arguments and will be appended to
the URL, e.g., @app.route(‘/index’). You can load the index
# main page can load either url 127.0.0.0:5000/ or page with the help of http://127.0.0.0:5000/index.
127.0.0.0:5000/index render_template will, by default, look for HTML pages in
@app.route(‘/’) the template directory, which takes the first argument as a page
@app.route(‘/index’) name and passing key; value pairs are also possible in the render_
def index(): template method and values can be received using its key.
return render_template(“index.html”, title = “Myapp home”) Manager module in Flask-script allows the user to create a new
command. Using the add_command we can set up the server and
#About page new command. Here, we used runserver as our new command, and
@app.route(‘/about’) server settings like debugging, reloading and application IP address.
def about(): Enabling debugger (use_debugger = True) is recommended for the
return render_template(“about.html”, title= “About”) purpose of testing and not for the production environment. It will
display an error message if something goes wrong, and reloader
# load posts page and displays the content from the post array (use_reloader = True) will automatically reload the applications
@app.route(‘/posts’) after we have made changes to the code.
def posts(): You can run the application using ./manage.py runserver.
posts = [ runserver is our own command, which has been created using
{ the Manager module.
“title” : “Hello World”,
“body” : “Welcome to python flask tutorial” base.html
},
{ <!DOCTYPE html>
“title” : “Sample post”, <html>
“body” : “Sample post for testing python flask “ <head>
} {% if title %}
] <title> {{title}}</title>
return render_template(“posts.html”, title = “Posts”, {% else %}
posts = posts) <title> Myapp home</title>
{% endif %}
# Create a new command ‘runserver’ using Manager and set host <link rel=”stylesheet” type=”text/css” href=”{{ url_
and enable debugger module. for(‘static’, filename=’css/style.css’) }}”>
# Debugger module only for developing not for production </head>
server <body>
manager.add_command(‘runserver’, Server( <header>
use_debugger = True, <h1><a href=”{{url_for(‘index’)}}”>MyApp</a></h1>
use_reloader = True, </header>
host = ‘127.0.0.1’ <div class=”menu”>
)) <ul>
#manager.run will start the server, which holds the app object <li><a href=”{{url_for(‘index’)}}”>Home</a></
also from the file __init__.py registered using ‘Manager’ li>
if __name__ == “__main__”: <li><a href=”{{url_for(‘about’)}}”>About</a></
manager.run() li>
<li><a href=”{{url_for(‘posts’)}}”>Post</a></
Import all necessary modules for our app. The render_template li>
module in Flask uses the Jinja2 template, which automatically </ul>
locates the file from the templates directory in the app. You can pass </div>
the template name and arguments as well. url for is good for building <div class=”container”>
URLs. Instead of hard code, the URLs passing the function names {% block content %}{% endblock %}
will take care of everything and arguments will also be accepted. </div>
The application path can be obtained from modules os and </body>

www.OpenSourceForU.com  |  OPEN SOURCE For You  |  OCTOBER 2014  |  37


Developers Let’s Try

</html> margin-top: 10px;


width : 130px ;
Jinja2 supports control and loop structures in the template height: 70px;
by using flowerbraces {{ }}. base.html is the basic layout for border-radius: 5px;
our Web application. Other pages can simply extend this page background-color: #C2BABC;
and the rest of the operations will be handled by Jinja2. }

index.html ul li{
list-style: none;
{% extends “base.html” %} display: inline;
{% block content %} float: right;
<h1>Welcome to my app</h1> padding: 10px;
{% endblock %} }

The Jinja2 template allows inheritance, and the index file ul li a{


inherits the basic layout from base.html. background-color: #2E2E2E;
color :#FFF;
about.html
border-radius: 3px;
{% extends “base.html” %} }

{% block content %} .container {


<p>This is about page of flask</p> margin-top: 20px;
{% endblock %} margin-left: 70px;
width: 500px;
posts.html
}
{% extends “base.html” %}
.title {
{% block content %} background-color:#C2BABC;
{% for post in posts %} }
<div class=”title”>
<h2>{{post.title}} </h2> Creating Web applications using Flask is very simple
</div> and needs little or no experience, when compared to other
<div class=”content”> languages. The server part will be handled by Flask, and
<p>{{post.body}}</p> no extra server setup is needed. Flask is known for its
</div> simplicity. The core API is simple and is based on the
{% endfor %} Jinja2 template engine and the Werkzeug WSGI toolkit. It
allows developers to choose their own third party Python
{% endblock %} packages depending on their interests. Using Flask is a
good option for complex Web applications. It makes the
In manage.py, the content for the post page is passed using applications easy to understand and enables developers to
the render_template method and can be identified using its key. work on different modules efficiently.

style.css References
[1] http://en.wikipedia.org/wiki/Flask_(web_framework)
a { [2] http://werkzeug.pocoo.org/
text-decoration: none; [3] http://jinja.pocoo.org/
[4] http://flask.pocoo.org/
} [5] http://flask.pocoo.org/docs/installation/#installation

header { By: Boopathi K


The author can be reached at boopathi@boopathi.me and at his
padding : 2px; website http://www.boopathi.me.
margin-left: 50px;

38  |  OCTOBER 2014  |  OPEN SOURCE For You  |  www.OpenSourceForU.com


How To Developers

IBM
Worklight
A Mobile App
Development
Platform
IBM Worklight offers cross-
platform portability of the
application code, which is crucial
during apps development.
Worklight enables the
development of rich HTML 5 and
hybrid apps using native code.

I
BM Worklight provides an open, comprehensive including ACL and LDAP support;
and advanced mobile app development platform for ƒƒ Employees with a central location for the latest apps
smartphones and tablets. It can be used to create all needed by their department and optimised for their device;
kinds of native, Web-based or hybrid mobile apps very ƒƒ Developers with an easy way to distribute mobile
easily. It includes the IBM Worklight Studio―an Eclipse- builds and elicit feedback from development and test
based IDE (integrated development environment) in which team members.
all the coding and integration tasks are performed to develop
a fully functional mobile app. Device runtime
IBM Worklight consists of five main components as Device runtime is client-side runtime code that embeds server
shown in Figure 1. functionality within the target environment of deployed apps.

Worklight Studio IBM Worklight Server


This is one of the leading tools for cross-platform, hybrid The Java-based server is a scalable gateway between
development that maximises code reuse and enables per- applications, external services, and the enterprise backend
device optimisation. You can make apps for Android devices, infrastructure. The server contains security features to enable
the BlackBerry or other devices. connectivity, multi-source data extraction and manipulation,
authentication, the direct update of Web and hybrid apps,
Worklight Application Centre analytics and operational management functions.
The Worklight Application Centre enables companies to easily
set up an app store for their enterprise and development teams. Worklight Console
The application centre provides: This is a Web-based UI that allows application version
ƒƒ Administrators with fine-grained control over the management (installs, updates, disables and enables), and
distribution of mobile apps across the enterprise, push management that provides administrative dashboards for

www.OpenSourceForU.com  |  OPEN SOURCE For You  |  OCTOBER 2014  |  39


Developers How To
SDKs
Worklight Studio iOS Worklight Application Device Runtime
Center Cross-Platform
HTML5, Hybrid, and Android
Native Coding Compatibility Layer
Development Team Provisioning

Application Code
Optimization Blackberry Server Integration
Framework Enterprise App Provisioning
Build Engine Windows Framework
Integrated Device And Governance
Phone Encrypted and
SDKs Syncable Storage
3rd Party Library Windows 8 App Feedback Management
Integration Runtime Skinning
Java ME
WYSIWG Editor Public App Stores
and Simulator Mobile Web Reporting for Statistics
Functional and Diagnositics
Testing Desktop Web

4
Enterprise Backend Systems

Worklight Server

User Authentication Client-Side


& Cloud Services

and Mobile Trust App Resources


Stats Aggregation

Worklight Console
Mashups and Service Direct Update
Composition Unified Push and SMS Notification
JSON Translation Mobile
Web Apps Development and Operational Analytics
Geolocation Services
Unified Push App Version Management
Adapter Library for Notification
Backend Connectivity

Figure 1: Worklight’s structure

deployed applications and installs adapters.


I am not going into too many details because a lot of
information can be found on the IBM website.

Installing Worklight in Eclipse Figure 2: Eclipse marketplace


Open Eclipse and go to the Help tab. Click on it and select
Eclipse marketplace.
A window will open; search for worklight and press
Enter. You’ll find two products related to Worklight as
shown in Figure 2.
Click on the Install button; it'll check the product and the
Confirm button will appear. Click on it and the progress bar
of the download will be shown. After installation, you will
see the Update and Uninstall buttons; this means you have
installed Worklight successfully.
Figure 3: Android SDK manager
Installing the Android Development Kit (ADK)
Before installation, change the perspective of Eclipse. Go to
the Window tab ---> Open Perspective –> Java.
After changing the perspective, open the window tab
again, and check whether the ADK is there. If not, install the
ADK in the same way as we installed Worklight earlier.
After installing the ADK, check the Android SDK
manager. Some APIs would have been installed, while some
will have to be installed after some time as shown in Figure 3.
Figure 4: Android virtual device manager
Making an Android virtual device
Open the window tab and click on Android Virtual Device opens a screen as shown in
Manager as shown in Figure 4. When a window opens, Figure 6. While opening the
press New and fill in the details of the device—in this screen, sometimes, it changes
case your Android mobile phone. Next, press OK, select the perspective—which means
your newly created device and press the Start button. You it sets it to‘Java EE’ if this was
will be asked about the real size of the screen/display. not set yet. You can manually
Now, press Launch. After some time, a beautiful Android change the perspective.
screen will come up as shown in Figure 5. So we’ve finished with the
setting up, and it's time to make
Making and deploying Android apps our first app. We are going to
Let’s start off by creating a Worklight project called make a simple calculator.
Mohit_Android. Click Next and fill in the application’s Step 1: Given below is the
name, say mohit_android, and then press Finish. This Java script code. Figure 5: Home screen

40  |  OCTOBER 2014  |  OPEN SOURCE For You  |  www.OpenSourceForU.com


How To Developers

<html>
<body>
<font color = red> Mohit's Calculator </font>

<FORM NAME="Calc">
<TABLE BORDER=4>
<TR>
<TD>
<INPUT TYPE="text" NAME="Input" Size="16">
<br>
</TD>
</TR>
<TR>
<TD> Figure 6: IBM Worklight
<INPUT TYPE="button" NAME="one" VALUE=" 1 "
OnClick="Calc.Input.value += '1'">
<INPUT TYPE="button" NAME="two" VALUE=" 2 "
OnCLick="Calc.Input.value += '2'">
<INPUT TYPE="button" NAME="three" VALUE=" 3 "
OnClick="Calc.Input.value += '3'">
<INPUT TYPE="button" NAME="plus" VALUE=" + "
OnClick="Calc.Input.value += ' + '">
<br>
<INPUT TYPE="button" NAME="four" VALUE=" 4 "
OnClick="Calc.Input.value += '4'">
<INPUT TYPE="button" NAME="five" VALUE=" 5 " OnCLick="Calc.
Input.value += '5'">
<INPUT TYPE="button" NAME="six" VALUE=" 6 " Figure 7: A simple calculator
OnClick="Calc.Input.value += '6'"> </body>
<INPUT TYPE="button" NAME="minus" VALUE=" - " </html>
OnClick="Calc.Input.value += ' - '">
<br> Copy the above code and paste it in
<INPUT TYPE="button" NAME="seven" VALUE=" 7 " the index.html page as shown in Figure 7.
OnClick="Calc.Input.value += '7'"> Step 2: Create the Worklight
<INPUT TYPE="button" NAME="eight" VALUE=" 8 " Environment as shown in Figure 8.
OnCLick="Calc.Input.value += '8'"> When a window opens, select Project
<INPUT TYPE="button" NAME="nine" VALUE=" 9 " Name, then Application Name and check
OnClick="Calc.Input.value += '9'"> the Android Phone & Tablets box before
<INPUT TYPE="button" NAME="times" VALUE=" x " clicking on Finish.
OnClick="Calc.Input.value += ' * '"> Figure 8: The running app Step 3: Right click on the mohit_
<br> android folder (under the Apps folder); go
<INPUT TYPE="button" NAME="clear" VALUE=" c " to Run and then select Run on Worklight Development Server.
OnClick="Calc.Input.value = ''"> Step 4: After the successful build, right-click on the newly
<INPUT TYPE="button" NAME="zero" VALUE=" 0 " created Mohit_android_AppAndroid (it may be a different
OnClick="Calc.Input.value += '0'"> name, sometimes) Android project. Select Run As > Android
<INPUT TYPE="button" NAME="DoIt" VALUE=" = " Application to launch it on the emulator, and verify if it works.
OnClick="Calc.Input.value = eval(Calc.Input.value)"> Figure 8 shows the app is running successfully.
<INPUT TYPE="button" NAME="div" VALUE=" / "
By: Mohit
OnClick="Calc.Input.value += ' / '">
The author is a certified ethical hacker, EC Council certified
<br>
security analyst and IBM certified mobile application developer
</TD> with a master’s degree in computer science engineering.
</TR> He currently works at IBM India, and can be contacted at
</TABLE> mohitraj.cs@gmail.com and on LinkedIn at: https://www.
linkedin.com/profile/view?id=104187708
</FORM>

www.OpenSourceForU.com  |  OPEN SOURCE For You  |  OCTOBER 2014  |  41


Developers Let's Try

What’s the Android Open


Accessory Protocol All About?

This article helps you to start using the Android Open Accessory (AOA) protocol, and also
illustrates how to make use of a simple Linux machine (PC, notebook or any embedded
board) to communicate with Android apps via USB.

T
he Android Open Accessory (AOA) protocol support from Android versions 3.1 onwards, and with an add-
allows simple USB communication with two bulk on library for the Android versions 2.3.4 and above. This was
end points between two nodes, which are: demonstrated with a custom shield on top of an Atmega-based
ƒƒ An external hardware device with USB host Arduino Mega board.
capabilities and peripheral support known as an Later in 2012, version 2.0 of this protocol was released at
Accessory Development Kit (ADK) or Accessory Google I/O 2012 with additional support for communication over
Host, from now onwards. Bluetooth, apart from USB. Also, two new features were added
ƒƒ An Android gadget, which works in device mode. with Audio and Human Interface Devices (HID) capabilities
The ADK host should be capable of supplying 500mA from the ADK side. This was demonstrated with a custom kit
at 5V power to the device. We know that most Android made from the ARM Cortex-m3-based Arduino Due board with
gadgets come with USB device capabilities in order to open hardware specs, popularly known as the ADK 2012 kit.
support data transfer and debugging (adb); so this protocol
chooses external hardware in the host mode and an Android Supporting hardware
machine in device mode. This eliminates the need for host Here is a list of some boards which can act like ADK, with
support on the Android side as very few gadgets come with the availability of sample code or libraries:
such capabilities. Also, there is no need to root the device ƒƒ Arduino Mega board
for any changes to the Android kernel, as peripheral support ƒƒ Arduino Due board
is taken care of by external hardware. ƒƒ AOA kit from Embedded Artists
ƒƒ Microchip PIC24F series MCUs
History ƒƒ Sparkfun IOIO
AOA version 1.0 was launched at Google I/O 2011 with ƒƒ FTDI Vinculum - II

44  |  OCTOBER 2014  |  OPEN SOURCE For You  |  www.OpenSourceForU.com


Let's Try Developers
bmRequest TYPE_VENDOR | DIR_DEVICE_TO_HOST
type
bRequest 51
wValue 0 wIndex 0
wLength 2 Data base_address_of_two_
bye_buffer
Step 2: Send identity strings using request code 52(0x34)
with the suitable value for each string ID.

bmRequest TYPE_VENDOR | DIR_HOST_TO_DEVICE


type
bRequest 52
wValue 0 wIndex string id
wLength Length_of_string Data base_addr_of_
string

Figure 1: USB modes of an Android device Here, ‘string id’ is a value between 0 to 5, which
represents each type of identity string as listed below.

manufacturer 0 model 1 Description 2


version 3 url 4 Serial id 5
Step 3: The final step is to start the device in the accessory
mode using the request code 53(0x35) as follows:

bmRequest TYPE_VENDOR | DIR_HOST_TO_DEVICE


type
bRequest 53
wValue 0 wIndex 0
wLength 0 Data NULL
At this point, if essential identity strings (manufacturer,
model) are not sent, the device can start in the accessory
mode without associating with any application as allowed
in AOA 2.0.This is useful to start the device just in audio or
Figure 2: Launching an application after initialisation HID mode.
ADK can act as an audio accessory as supported in AOA 2.0,
ƒƒ BeagleBone powered with TI Starterware where audio output from the Android device is streamed to the
ƒƒ And currently, any hardware with USB host capabilities ADK host without the need of any application in two-channel
powered by Linux. 16-bit PCM format, i.e., the Android device can be identified as
So we decided to add external hardware as the ADK host a capture device by an audio sub-system like ALSA on the Linux
to an Android device. Let’s see how ADK can initialise the side. So if you are planning to use ADK as an audio dock for your
Android device in the accessory mode. Android device, you can send another request with the following
attributes, and if you do, this must be sent before starting in the
Initialising the Android device accessory mode (53) as per AOA specs.
Once the Android device is connected to the ADK host,
the device will enumerate with its original configuration, bRequest =58(0x3A), wValue=1
which may vary for each device. Initially, the device may be
connected in the camera (PTP support) or media device (MTP The rest is the same as above.
support) mode to the host. Now, ADK should initialise the Also, the ADK host can act as an HID event generator or
device to turn into the accessory mode. This can be done in HID proxy as supported in AOA 2.0, for that the following
the following few steps by sending various vendor (Google) request codes are available:
specific control requests through the control endpoint whose
address is zero. 54(0x36) register ADK as HID source 55(0x37)
Step 1: Query the protocol using request code 51(0x33), unregister the ADK
which returns 1 for AOA and 1.0 or 2 for AOA 2.0; other 56(0x38) set hid report descriptor 57(0x39) send a
attributes as per USB specifications are listed here. hid event

www.OpenSourceForU.com  |  OPEN SOURCE For You  |  OCTOBER 2014  |  45


Developers Let's Try

But in this article, we'll focus more on the bulk transfer Once we obtain references for input and output streams
between an Android app and accessory host, which is known as illustrated above, the rest of the flow depends on the
as custom accessory mode. communication between the app and ADK.

Re-enumeration of the device after initialisation Sample Android applications


Upon initialising the device as mentioned above, it Here is a listing of some applications designed to work with
will re-enumerate in the accessory mode with a unified various embedded targets as ADK,once your Android device
configuration, in which interface 0 comes with two end is turned into open accessory mode. You may use one of these
points meant for bulk transfer operations. If the device is in applications for initial work until you start designing your
audio or ADB mode, a few more interfaces will be detected. own Android apps like me, or customise those apps for which
The re-enumerated configuration can come with one of the source code is available.
following vendor ID-product ID combinations, depending
on the initialisation (accessory, audio support) and ADB From the Google Play store
mode of the device. • ADK 2012 by Google, https://dl- ssl.google.com/
android/adk/adk_release_20120606.zip
0x18D1:0x2D00 Accessory only
• Standard Android ADK Demo Ki t(ADK 2011) by
0x18D1:0x2D01 Accessory + ADB
DIY Phone Gadgets
0x18D1:0x2D02 Audio only
• Basic accessory demo from Microchip
0x18D1:0x2D03 Audio + ADB
0x18D1:0x2D04 Audio + Accessory From other sources
0x18D1:0x2D05 Audio + Accessory + ADB • T
I-ADKDemo from https://code.google.com/p/
Then the device will try to launch suitable applications rowboat/
that match with the manufacturer, model, and the version • http://www.embeddedartists.com/products/app/
identity strings specified as intent filters in the manifest files aoa_kit.php
of the Android app. If no suitable application is installed, a • Few apps from http://www.ftdichip.com/Android.htm
pop-up will be shown with a specific URL (if any) pointing to
the APK file or with details of the application.
Note: Some of these applications not starting or stop
responding in few devices, some debugging and fixing
Device side API and code flow may be required.
Here is a brief discussion on APIs and codeflow on the Android
side with a sample code from Google I/O 2012, which may be
helpful to develop new apps or customise existing ones. A case study–Linux as ADK
Once ADK initialises the device, the USB manager tries To turn a Linux machine to an ADK, I have written a skeleton
to match the sent identity strings with intent-filter content driver code, hosted at github.com/rajeshsola/adk-driver-
as mentioned in the manifest resource of an app. Upon skeleton based on Gary Bisson’s Linux ADK code. One can
verification and user permissions, the application's activity write user space apps on top of this driver or customise the
starts with USB_ACCESSORY_ATTACHED intent; and skeleton code for specific needs.
similarly, USB_ACCESSORY_DETACHED intent will be As a case study, I've chosen the SimpleAccessory app
sent when ADK is disconnected. available from nexus-computing.ch to test with Linux
as the ADK. By changing the simple slider in this app,
import android.hardware.usb.UsbAccessory; you can change some properties of ADK like volume,
import android.hardware.usb.UsbManager; brightness, etc.
mUSBManager = (UsbManager) getSystemService(Context. Load the driver adk-aoa-skeleton.ko using insmod or
USB_SERVICE ); modprobe. Preferably, you can use module params my_
UsbAccessory acc; acc=(UsbAccessory)intent. device_vid,my_device_pid with vendor ID and product ID
getParcelableExtra( UsbManager.EXTRA_ACCESSORY ); of the device in order to probe the device on detection, or
if (!mUSBManager.hasPermission(acc)) return; you can use the necessary udev rules to load the module on
ParcelFileDescriptor mFD = mUSBManager. connecting the device. Stop any storage related services and
openAccessory(acc); unload other modules that prevent association between this
if (mFD != null) { driver and the device, before connecting.
FileDescripter fd = mFD.getFileDescriptor(); Once the device has been probed, sysfs operations
mIS = new FileInputStream(fd); are enabled under /sys/kernel/adk_linux/aoa_init/ for
mOS = new FileOutputStream(fd); initialisation purposes; so, let’s use simple commands to
} initialise the device.

46  |  OCTOBER 2014  |  OPEN SOURCE For You  |  www.OpenSourceForU.com


Let's Try Developers

will be shown asking permission


to open the specified app;
otherwise, another pop-up will
be shown with a URL pointing to
APK or with app details.
Once initialised, you can
communicate with the app using
simple file operations like read and
write from userspace with the help
of the device file (/dev/aoa-skel0)
created by this driver.
This application comes
with a slider. You can control
Figure 3: Showing the URL in the absence of the application the brightness of your Linux
machine by changing the value
To query the version, type: Figure 4: SimpleAccessory application of /sys/class/backlight/acpi_
video0/brightness, as an example. A sample code (backlight-
cat /sys/kernel/adk_linux/aoa_init/version demo.c) to work with a skeleton driver is kept under the
‘Examples’ section of gitrepo. Also, with other examples like
Send the identity strings as follows: aoa-read-dump.c, simple-demo.c, etc, you can read raw data
coming from the app. In this case, a value between 0 to 255
echo “manufacturer=Nexus-Computing GmbH” > /sys/kernel/ will be printed each time slider moves.
adk_linux/aoa_init/identity Similarly, to work with the ADK 2012 app, you can send
echo “model=Simple Slider” > /sys/kernel/adk_linux/ Manufacturer=Google, Inc., Model=DemoKit, Version=2.0 as
aoa_init/identity identity strings.
echo “version=0.1” > /sys/kernel/adk_linux/aoa_init/ If you have any difficulties in building or loading
identity the kernel space module, you can customise libusb-
based user space codes like linux-adk by Gary Bisson or
likewise you can also send “description=A Simple Slider”, usbAccReadWrite.c by Jeremy Rosen, according to the
“URL=http://www.nexuscomputing.ch/SimpleAccessory.apk” and requirements of your own Android apps.
“serial=1337”, but optional
References
Start the device in audio/accessory mode: [1] http://source.android.com/accessories/
[2] ‘Leveraging the Android Accessory Protocol’ by Gary Bisson,
http://github.com/gibsson/linux-adk
echo “audio” > /sys/kernel/adk_linux/aoa_init/start
[3] Chapter 5: ‘USB Accessory’ from the book ‘Unboxing
echo “accessory” > /sys/kernel/adk_linux/aoa_init/start Android USB’ by Rajaram Regupathy
[4] Contents of Google I/O 2011 and 2012
This driver also supports initialisation through ioctl
operations with custom strings,or with module parameter By: Rajesh Sola
init_on_probe=1 with default identity strings. Please refer to The author is a faculty member of C-DAC's Advanced
the wiki page of gitrepo for more details about the driver. Computing Training School, Pune, in the embedded systems
At this moment, if a suitable app is installed, a pop-up domain. You can reach him at rajeshsola@gmail.com.

www.OpenSourceForU.com  |  OPEN SOURCE For You  |  OCTOBER 2014  |  47


For U & Me CaseStudy

Unotech helps Mahindra & Mahindra Financial Services Limited


to optimise 87 per cent of its proprietary field force solutions
Unotech Software Pvt Ltd provides enterprise business and mission critical products and
solutions for all segments. The firm offers the full gamut of services, ranging from consultancy
and outsourced product development to open source training.

M
MFSL (Mahindra & Mahindra reduced data rejection, better employee
Financial Services Ltd) has training with consistent processes, easier
adopted MFEKA (Mahindra access to data for quality decisions,
Finance Enterprise Key Access), which is improved relations with business users,
a structured approach to providing easy streamlined administration and optimal
accessibility to all the applications. It focuses trend analysis.
on business, customer, dealer and Intranet- Customer satisfaction: It was
based applications. Due to demanding needs, imperative that customer satisfaction
the complexity of portals and their technical should increase with the process in place.
and functional requirements have increased. Unotech gave the most robust structure
Even though there are tools available to to the system, which made it more user
build simple portals, the challenge lies in friendly and one of the best-in-class
integrating them. One such challenge is communication systems.
with authentication. In this competitive Risk management: Having
environment, it is imperative to have robust standardised procedures across the breadth
processes. To cope up with the ever growing Suresh A Shanamugam is the National of a company helped prevent errors.
number of users and to avoid technical Head of Business Information Technology Accurate information flow was provided.
complexities, MMFSL has always aspired Solutions (BITS) of Mahindra & Mahindra Traceability and due diligence:
Financial Services Limited
for excellence in all its products, services and In a growing business and market, the
processes. Unotech as a vendor began its partnership with solution ensured maintenance of the complete set of records
MMFSL in order to replace its existing mailing platform and to guarantee the delivery of the right information and
was eventually selected to develop the EKA Core Engine. credentials, with full documentation to support it.
The five major pillars on which EKA’S technology had Improved user service delivery: A major impact was seen in
to be designed are: sustainability, reliability, compliance, providing services, with authentic data given via a secured path.
scalability and robustness in the technology used. The Improved TAT: Due to established processes, users
growing business of MMFSL brought along with it more could manage their own approval channels and appropriate
complex rules, and the deployed solution had to be designed communications, leading to accurate TAT governance.
to sustain complex processes. The model preferred in such Well established processes: Common processes for all
a case was to adopt a partner like Unotech, who offered digital approvals helped users to keep up with the solution,
enterprise-ready open source solutions as a service. hence reducing the need for training.
Unotech helps Mahindra & Mahindra Financial Services Securing all requests: A four-layer and a multi-layer
Limited to optimise 87 per cent of its proprietary field force approval channel were established, which further eliminated
solutions. Unotech has also been maintaining the servers and the risks associated with insufficient documentation or vague
the core engine used for EKA, which has gained more than assignment of responsibility/ownership.
1000 million hits since its inception. The solution, with its
dynamic rule & role engine, which is a multi-level approval Unotech Software Pvt Ltd also provides:
engine, has serviced a quarter of a million EKA requests for ƒƒ Single sign-on solutions that can be integrated with
securing and fulfilling compliance needs. It is a single unified proprietary and open source product lines.
repository, resulting in great advantages to administrators ƒƒ An Enterprise Document Management System as a
when maintaining the systems. product line and support services for other open source
In a fast-growing business, there are a lot of factors product lines.
an organisation needs to deal with, and Unotech helped ƒƒ A mailing solution on open source platforms.
MMFSL in the following spheres. ƒƒ Implementation and customisation of enterprise-ready
Efficiency: By controlling critical points in production open source products.
systems, like the authorisation channel and in record- For more details, contact www.unotechsoft.com or info@
keeping, vast improvements were seen in communication, unotechsoft.com

48  |  october 2014  | OPEN SOURCE For You  |  www.OpenSourceForU.com


Let's Try Developers

to
An Introduction s and User
se
Haskell claasta
efined D Types
D
Continuing our series on Haskell, this
month, we focus on Haskell classes and
user defined data types.

H
askell is a purely functional programming language x /= y = not (x == y)
and it enforces strictness with the use of types. In x == y = not (x /= y)
this article, we shall explore type classes and user
defined data types. The keyword class is used to define a type class. This
Consider the elem function that takes an element of a type, is followed by the name of the class (starting with a capital
a list, and returns ‘true’ if the element is a member of the list; letter). A type variable (‘a’ here) is written after the class
and if not, it returns ‘false’. For example: name. Two functions are listed in this class for finding if
two values of a type are equal or not. A minimal definition
ghci> 2 `elem` [1, 2, 3] for the two functions is also provided. This code is available
True in libraries/ghc-prim/GHC/Classes.hs in the ghc (Glasgow
ghci> 5 `elem` [1, 2, 3] Haskell Compiler) source code.
False The example works for integers ‘2’ and ‘5’ in the example
above, because they are of type Int, which is an instance of
It’s type signature is shown below: Eq. Its corresponding definition is given below:

ghci> :t elem Instance Eq Int where


elem :: Eq a => a -> [a] -> Bool (==) = eqInt
(/=) = neInt
The type signature states that the type variable ‘a’ must
be an instance of class ‘Eq’. The class constraint is specified The keyword instance is used in the definition followed
after the ‘::’ symbol and before the ‘=>’ symbol in the type by the name of the class Eq, and a specific type Int. It uses two
signature. The elem function will thus work for all types that primitive functions eqInt and neInt for checking if the given
are instances of the Eq class. integers are equal or not. The detailed definition is available in
The word ‘class’ has a different meaning in functional libraries/ghc-prim/GHC/Classes.hs in the ghc source code.
programming. A type class is a parametrised interface that There are a number of pre-defined type classes available
defines functions. A type that is an instance of a type class in the Haskell platform.
needs to implement the defined functions of the type class. The Ord type class denotes types that can be compared.
The Eq class defines functions to assert if two type values are The ‘compare’ function will need to be implemented by types
equal or not. Its definition in Haskell is as follows: that want to be instances of this class. The resultant values of
‘compare’ are GT, LT, or EQ. For example:
class Eq a where
(==), (/=) :: a -> a -> Bool ghci> ‘p’ > ‘q’

www.OpenSourceForU.com  | OPEN SOURCE For You  |  october 2014  |  49


Developers Let's Try

False enumFrom x = map toEnum [fromEnum x ..]


ghci> 3 > 2 enumFromThen x y = map toEnum [fromEnum x, fromEnum
True y ..]
enumFromTo x y = map toEnum [fromEnum x ..
Its type class definition is as follows: fromEnum y]
enumFromThenTo x1 x2 y = map toEnum [fromEnum x1, fromEnum
class (Eq a) => Ord a where x2 .. fromEnum y]
compare :: a -> a -> Ordering
(<), (<=), (>), (>=) :: a -> a -> Bool The instance for type ordering for the Enum class is as follows:
max, min :: a -> a -> a
instance Enum Ordering where
compare x y = if x == y then EQ succ LT = EQ
else if x <= y then LT succ EQ = GT
else GT succ GT = error “Prelude.Enum.Ordering.succ: bad argument”

x < y = case compare x y of { LT -> True; _ -> False } pred GT = EQ


x <= y = case compare x y of { GT -> False; _ -> True } pred EQ = LT
x > y = case compare x y of { GT -> True; _ -> False } pred LT = error “Prelude.Enum.Ordering.pred: bad argument”
x >= y = case compare x y of { LT -> False; _ -> True }
toEnum n | n == 0 = LT
max x y = if x <= y then y else x | n == 1 = EQ
min x y = if x <= y then x else y | n == 2 = GT
toEnum _ = error “Prelude.Enum.Ordering.toEnum: bad
The Ord type class needs to be a sub-class of the Eq class argument”
because we should be able to test for equality of two values if
they need to be compared. This is also defined as a constraint fromEnum LT = 0
in the class definition. Seven functions are provided and a fromEnum EQ = 1
minimal definition given in the code snippet. The instance fromEnum GT = 2
definitions for Char and Int types are available from libraries/
ghc-prim/GHC/Classes.hs in the ghc source code. -- Use defaults for the rest
The Enum type class is for types whose values can be enumFrom = boundedEnumFrom
listed in an order for which you can find predecessor and enumFromThen = boundedEnumFromThen
successor elements. For example:
You can find the definition and instance definitions for
ghci> succ ‘a’ Char and Ordering in libraries/base/GHC/Enum.lhs in the ghc
b source code.
ghci> pred EQ The Show type class lists a show function to display or
LT print data. For example:

The class definition for Enum is given below: ghci> show 3.1415
“3.1415
class Enum a where ghci> show True
succ :: a -> a “True”
pred :: a -> a
toEnum :: Int -> a The above code works for both ‘Float’ and ‘Bool’ because
fromEnum :: a -> Int there are instance definitions for each for the Show type class.
The read function for the ‘Read’ type class takes as input a
enumFrom :: a -> [a] ‘String’ and converts it to an appropriate data type, if possible.
enumFromThen :: a -> a -> [a] For example:
enumFromTo :: a -> a -> [a]
enumFromThenTo :: a -> a -> a -> [a] ghci> read “1” + 2.0
3.0
succ = toEnum . (+ 1) . fromEnum ghci> read “False” || True
pred = toEnum . (subtract 1) . fromEnum True

50  |  october 2014  | OPEN SOURCE For You  |  www.OpenSourceForU.com


Let's Try Developers

You will find the class definitions and instances for Show In an equation for `it’: it = read “3”
and Read in libraries/base/GHC/Show.lhs and libraries/base/
GHC/Read.lhs respectively. The .lhs file is a literate Haskell The interpreter does not know what type to convert ‘3’ to,
source file in which you can combine both text and code. and hence you will need to explicitly specify the type:
You can also find the definition for a class, a function or type
inside GHCi using ‘:i’. For example: ghci> read “3” :: Int
3
ghci> :i Eq ghci> read “3” :: Float
class Eq a where 3.0
(==) :: a -> a -> Bool
(/=) :: a -> a -> Bool A type synonym is an alias that you can use for a type.
-- Defined in `GHC.Classes’ ‘String’ in the Haskell platform is an array of characters
instance Eq Integer -- Defined in `integer-gmp:GHC.Integer.Type’ defined using the type keyword:
instance Eq Ordering -- Defined in `GHC.Classes’
instance Eq Int -- Defined in `GHC.Classes’ type String = [Char]
instance Eq Float -- Defined in `GHC.Classes’
instance Eq Double -- Defined in `GHC.Classes’ You can also create a new user data type using the data
instance Eq Char -- Defined in `GHC.Classes’ keyword. Consider a Weekday data type that has the list of the
instance Eq Bool -- Defined in `GHC.Classes’ days in a week:
...
data Weekday = Monday
ghci> :i read | Tuesday
read :: Read a => String -> a -- Defined in `Text.Read’ | Wednesday
| Thursday
ghci> :i Int | Friday
data Int = GHC.Types.I# GHC.Prim.Int# -- Defined in `GHC. | Saturday
Types’ | Sunday
instance Bounded Int -- Defined in `GHC.Enum’
instance Enum Int -- Defined in `GHC.Enum’ The data keyword is followed by the name of the data
instance Eq Int -- Defined in `GHC.Classes’ type, starting with a capital letter. After the ‘equal to’ (‘=’)
instance Integral Int -- Defined in `GHC.Real’ sign, the various value constructors are listed. The different
instance Num Int -- Defined in `GHC.Num’ constructors are separated by a pipe (‘|’) symbol.
instance Ord Int -- Defined in `GHC.Classes’ If you load the above data type in GHCi, you can test the
instance Read Int -- Defined in `GHC.Read’ value constructors:
instance Real Int -- Defined in `GHC.Real’
instance Show Int -- Defined in `GHC.Show’ ghci> :t Monday
Monday :: Weekday
Let’s suppose you input the following in a GHCi prompt:
Each value constructor can have many type values. The user
ghci> read “3” defined data type can also derive from type classes. Since the
primitive data types already derive from the basic type classes,
<interactive>:5:1: the user defined data types can also be derived. Otherwise,
No instance for (Read a0) arising from a use of `read’ you will need to write instance definitions for the same. The
The type variable `a0’ is ambiguous following is an example for a user data type ‘Date’ that derives
Possible fix: add a type signature that fixes these type from the ‘Show’ type class for displaying the date:
variable(s)
Note: there are several potential instances: data Date = Int String Int deriving (Show)
instance Read () -- Defined in `GHC.Read’
instance (Read a, Read b) => Read (a, b) -- Defined in Loading the above in GHCi, you get:
`GHC.Read’
instance (Read a, Read b, Read c) => Read (a, b, c) ghci> Date 3 “September” 2014
-- Defined in `GHC.Read’ Date 3 “September” 2014
...plus 25 others
In the expression: read “3” The above code will work even if we swap the year and

www.OpenSourceForU.com  | OPEN SOURCE For You  |  october 2014  |  51


Developers Let's Try

day, because the syntax is correct but the semantics are not! year and day cannot be swapped:

ghci> Date 2014 “September” 3 instance Show Date where


Date 2014 “September” 3 show (Date d m y)
| d > 0 && d <= 31 = (show d ++ “ “ ++ show m ++ “ “
You can also use the record syntax that can give you ++ show y)
helper functions: | otherwise = error “Invalid day”

data Date = Date { day :: Int Load the code in GHCi, and run the following:
, month :: String
, year :: Int ghci> show (Date 3 September 2014)
} “3 September 2014”
ghci> show (Date 2014 September 2)
This gives you three helper functions to retrieve the day, “*** Exception: Invalid day
month and year from a ‘Date’.
Suppose you wish to support different Gregorian date
ghci> let d = Date {day = 14, month = “September”, year = formats, you can define a data type ‘GregorianDate’ as follows:
2014}
ghci> day d data GregorianDate = DMY Day Month Year | YMD Year Month Day
14
ghci> month d You can also define your own type classes for functions
“September” that define their own behaviour. For example, if you wish to
dump the output of a date that is separated by dashes, you can
You can also make data type definitions more explicit write a ‘Dashed’ class with a dash function.
with types:
class Dashed a where
data Date = Date Day Month Year deriving (Show) dash :: a -> String

type Year = Int instance Dashed Date where


dash (Date d m y) = show d ++ “-” ++ show m ++ “-” ++
type Day = Int show y

data Month = January Testing the above in GHCi will give the following output:
| February
| March ghci> dash (Date 14 September 2014)
| April “14-September-2014”
| May
| June Haskell allows you to define recursive data types also. A
| July parametrised list is defined as:
| August
| September data List a = Empty | Cons a (List a) deriving (Show)
| October
| November Lists for the above definition can be created in GHCi,
| December using the following commands:
deriving (Show)
ghci> Empty
Loading the above in GHCi, you can use: Empty
ghci> (Cons 3 (Cons 2 (Cons 1 Empty)))
ghci> Date 3 September 2014 (Cons 3 (Cons 2 (Cons 1 Empty)))
Date 3 September 2014

By: Shakthi Kannan


To support printing the date in a specific format, you can
The author is a free software enthusiast and blogs
implement an instance for the ‘Show’ type class. You can also
at shakthimaan.com.
add a check to ensure that the day is within a range, and the

52  |  october 2014  | OPEN SOURCE For You  |  www.OpenSourceForU.com


How To Developers

How to Contribute to GNOME


The open source community thrives on the involvement and support of users to make
open source a truly people’s movement. ‘Involvement’ has many aspects to it, and includes
monetary contributions, writing, designing, coding, translating or testing.

• For optimised builds: At least 1GB of free space (6GB


recommended)

Build tools and dependencies


In GNOME, it is not necessary to have the
dependencies. You only need to install JHBuild,
which is a tool developed and used to build the whole
GNOME desktop from the Git source. It can also
be used to build other projects, creating a moduleset
for it. Unlike some build scripts, JHBuild lets you specify
what modules you want to build and, accordingly, it will
build those modules, including the dependencies. JHBuild is
preferred by developers who install GNOME from source.

Installing JHBuild
JHBuild helps users by making the installation process much
easier. It needs the Python runtime environment, with version
2.3 as the least recommended.
The recommended way of downloading JHBuild is
via the Git version control system. This can be done
with the following command. It is recommended that
you run the command from a new directory where

G
NOME is one of the leading all the source code will be installed, for example, ~/
open source organisations jhbuild/checkout.
in the world. A lot of
people work for it, fixing bugs, git clone git://git.gnome.org/jhbuild
implementing new features,
etc. Since people use various This will download JHBuild into a new
platforms for this, here’s a simple folder named JHBuild under the current
guide to installing the source code working directory. To build and install JHBuild,
for GNOME on different platforms. use the following commands:
Also learn how you can begin with
your first contribution towards open cd jhbuild
source using GNOME and a few . . . .
of its developer tools. You can ./autogen.sh
contribute to different parts such . . . .
as the GNOME shell, GNOME- make
music, GNOME-games, Evolution, . . . .
Evolution data server, etc. make install

Hardware requirements If gnome-common, Yelp-tools and


While installing the GNOME source Autotools are available, autogen.sh will
code, you first need to install its configure JHBuild to install via Autotools.
dependencies. The minimum hardware If the three are not available, autogen.sh will
requirements for the build are: configure JHBuild to install them via a plain
• 2GB RAM and a lot of free space Makefile. To always use the plain Makefile method, pass
• To debug and to build: At least 8GB of free space --simple-install to autogen.sh

www.OpenSourceForU.com  |  OPEN SOURCE For You  |  October 2014  |  53


Developers How To

If the above steps complete successfully, a small shell   [9] Go to phase “distclean”
script will be installed in ~/.local/bin to start JHBuild. For the choice:
script to run, you need to add ~/.local/bin to the PATH.
It is also possible to build a different set of modules and
PATH = $PATH:~/.local/bin their dependencies by passing the module name as arguments to
the build command. For example, to build gtk+, use:
To permanently add ~/.local/bin to the PATH variable, run
the following command: jhbuild build gtk+

echo ‘PATH = $PATH:~/.local/bin’ >> ~/.bashrc If JHBuild is cancelled half way through a build, it is possible to
resume the build at a particular module using the --start-at option:
JHBuild prerequisites
Before any modules can be built, it is necessary to have jhbuild build --start-at = module-name
certain build tools installed. Common build tools include the
GNU Autotools (autoconf, automake, libtool and gettext), the To build one or more modules, ignoring their dependencies,
GNU toolchain (binutils, gcc, g++), make, pkg-config and JHBuild provides the buildone command. For the buildone command
Python, depending on which modules will be built. JHBuild to complete successfully, all the dependencies must be previously
can check the tools installed using the sanitycheck command: built and installed or provided by the distribution package.

jhbuild sanitycheck jhbuild buildone gtk+

If this command displays any messages, please install the When actively developing a module, you are likely to do so
required packages from the distribution’s repository. A list of in a source working directory. The ‘make’ will invoke the build
package names for different distributions is maintained on the system and install the module. This will be a key part of the
GNOME wiki. Run the sanitycheck command again after installing edit-compile-install-test cycle.
the distribution’s packages to ensure the required tools are present.
jhbuild make
Using JHBuild
After the set-up is complete, JHBuild can be used to build If JHBuild is cancelled half way through a build, it is
software. To build all the modules selected in the ~/.config/ possible to resume the build at a particular module using the
jhbuildrc file, run the following command: --start-at option. To get a list of the modules and dependencies
JHBuild will build and the order in which they will be built, use
jhbuild build the list command:

JHBuild will download, configure, compile and install each jhbuild list
of the modules. If an error occurs at any stage, JHBuild will
present a menu that asks you what needs to be done. The To get information about a particular module, use the info
choices include dropping to a shell to fix the error, rerunning command:
the build from various stages, giving up on the module, or
ignoring the error and continuing. jhbuild info module-name

Note: Giving up a module will cause other modules To download or update all the software sources without
that depend on it to fail. building, use the update command, which provides an
opportunity to modify the sources before building, and can be
Shown below is an example of the menu displayed when useful if Internet bandwidth varies:
you get an error message:
  [1] Return phase build jhbuild update
  [2] Ignore error and continue to install
  [3] Give up on module Later, JHBuild can build everything without downloading or
  [4] Start shell updating the sources:
  [5] Reload configuration
  [6] Go to phase “wipe directory and start over” jhbuild build --no-network
  [7] Go to phase “configure”
  [8] Go to phase “clean” To run a particular command with the same environment

54  |  October 2014  |  OPEN SOURCE For You  |  www.OpenSourceForU.com


How To Developers

from this, you can just press the Esc key.


Looking Glass has four major panes (Evaluator,
Windows, Errors and Extensions) and one tool (the
Picker).
Evaluator: This is an interactive JavaScript
prompt. You can type arbitrary JavaScript at the
prompt, and it will be evaluated. Try, in order:

1+1
global.get_window_actors( )
global.get_window_actors( ).forEach(function
Figure 1: Looking glass (w) {Tweener.addTween(w, {time:3,   transition:
‘easeOutQuad’, scale_x: 0.3, scale_y: 0.3 } ) } )
used by JHBuild, use the run command: global.get_window_actors( ).forEach(function (w) {w.set_
scale(1, 1) } )
jhbuild run program global.get_window_actor( ) [0]
it.scale_x
To start a shell with the same environment used by
JHBuild, use the shell command: Special Evaluator features: This last bit deserves more
explanation. One thing about the Evaluator that’s different
jhbuild shell from, say, Python’s default interactive prompt is that each
computed value is saved, by default, and can be referred back
Looking Glass (lg): A developer tool to. Typing ‘r (number)’ will get you back the result with that
Looking Glass (lg) is GNOME Shell’s integrated inspector number, and it is the last result.
tool and JavaScript console, which is useful for debugging. The evaluator also has a history feature; you can press
To access looking glass, type lg in the Alt+F2 prompt. To exit Up and Down to access previously used entries. The history

Please share your feedback/ thoughts/


views via email at osfyedit@efy.in

www.OpenSourceForU.com  |  OPEN SOURCE For You  |  October 2014  |  55


Developers How To

is automatically saved to the dconf key /apps/gnome-shell / In this command, -a means all the changes. The Git
looking-glass-history, and loaded when you restart the shell. commit command takes you to an editor where you can
Slowing down shell animations: You can use Looking add the commit message. Your commit message should
Glass to call the special function St.set_slow_down_ follow a standard format: a short title, followed by a longer
factor(factor) where ‘factor’ is a value greater than 1 to make explanation, followed by a link to the relevant bug. Your
all shell animations slower. This is particularly useful when commit message should look something like this:
implementing new animation behaviour.
The Picker: The Picker allows you to visually select any Short title describing your changes to the code.
object from the shell’s scene. When you do so, it is inserted as             Longer description and explanations if necessary.
a result into the Evaluator pane.             Bug link

Getting started with your first contribution Create a patch: To create a patch you need to give the
Now, after building the source code of the particular module, following command:
you can start with your first contribution. This process
basically consists of going through the source code and             git format-patch HEAD^
finding that part of the code responsible for the bug. For help,
you can contact the GNOME developers on the IRC. Submit a patch: Send the patch to the project by attaching
it to the relevant bug report in GNOME Bugzilla. Unless
Connecting to the GNOME IRC explicitly stated in the patch file, do not send the patches
If your browser is Mozilla Firefox, then you can install the privately to the maintainer. If your patch is an enhancement
ChatZilla extension for the IRC, which is basically an IRC client and not a bug, you can create a new bug report with severity ->
developed by Mozilla. If you are not interested in using ChatZilla, enhancement. Don’t forget to attach your (Git) patch.
you can try IRCCloud, Mibbit or XChat based on what suits you.
The next step is to connect to the GNOME IRC server. For this, Tips for creating a patch
connect to the GNOME server by using the following command: • In your commit messages, describe both what the patch
does and how it is done, unless the patch is very trivial.
/server irc.gnome.org • Strictly follow the coding style used in the code you are
working on. This may sound trivial, but consistency is very
Once you are connected to their IRC server, you can join a important. Many projects describe the preferred coding
channel where you can get help for the bug. To join a channel, style in the patch file; for other projects, just take a look at
just type: the surrounding code and try to use the same format.
• Avoid unrelated changes. This makes the patch easier to
/join #channel-name read and approve.
• Provide one patch per issue. Do not make big patches that
After you connect to any channel, you can start asking fix unrelated bugs.
questions regarding the bug or about anything else too. • Make sure the patch does not contain trailing
whitespace and spurious empty lines. You can use git
Starting with the first bug fix in GNOME diff --check for this.
Once you are ready with the build, go to Bugzilla to search • Do not compress the patch with gzip or similar tools,
for bugs. As a beginner, it is recommended that you start since it makes reviewing more painful. If the patch is
with minor or trivial bugs. Once you find a bug, just mention big enough to really require compression, chances are
that you are interested in working on this bug in the ‘bug that you need to carefully discuss your patch with the
comments’ section. After some time, you will get that bug maintainer anyway.
assigned to you. Once you are done with selecting a bug, you
can ask for any help regarding the bug in #gnome-love on the References
IRC. After you have fixed the bug, you have to make a patch, [1] https://wiki.gnome.org/GnomeLove/SubmittingPatches
for which you have to use Git. [2] https://wiki.gnome.org/action/show/Projects/Jhbuild

Submitting a patch using Git By: Anup Allamsetty


Commit a patch: After you’ve made changes to the code, The author is an open source enthusiast and an active FOSS
you are ready for a patch. For this, you need to commit the community member in Amrita University, Amritapuri, Kerala. He is
changes you have made locally. an active contributor to Mozilla and GNOME. He regularly blogs
at anup07.wordpress.com and you can contact him via email at
allamsetty.anup@gmail.com.
git commit -a

56  |  October 2014  |  OPEN SOURCE For You  |  www.OpenSourceForU.com


Let's Try Developers

Grails
An Agile and
Friendly Framework
Grails is an open source Web application framework for the Java Virtual Machine. In this article,
the author introduces developers to the ‘holy grail’ in software—the Grails Framework.

I
n the competitive world of start-ups and business you're using another distro, you can easily adapt the following
expansion, a software developer is always hunting for the steps accordingly.
best technology to build applications faster. This article 1. Installing JDK: On Ubuntu, you can type the following
is an introduction to Grails, which according to Wikipedia, command into the terminal to install the JDK.
“… is an open source Web application framework that uses
the Groovy programming language (which is in turn based sudo apt-get install openjdk-6-jdk
on the Java platform).” If you have never worked with
Groovy before, you shouldn't worry because standard Java You can alternatively use the Sun version of Java as well,
language constructs work as is, in Groovy. And if you know but use version 6 of the OpenJDK for maximum compatibility
scripting languages like Python or Ruby, you will find that with Grails.
Groovy is very intuitive and simple to use. Another obvious 2. Installing GVM (Groovy enVironment Manager): The
reason to use Grails is that it provides built-in support for GVM is a command line tool that helps you manage
well-developed Java technologies like Spring and Hibernate, different versions of the SDK on UNIX systems. Using
which makes migrating from a Java stack to Grails a very GVM, you can install multiple versions of Grails and
painless and simple process. Being a Web framework, it uses Switch easily. Let’s install GVM by first using curl
the well-tested MVC design paradigm. Quoting Wikipedia (a UNIX tool used to download files) to get the GVM
again, some of the other key features of Grails is that it offers script and then execute it. So before starting, ensure
documentation for key portions of the framework like: you have curl installed on your system by using the
ƒƒ The Persistence framework following command.
ƒƒ Templates using GSP (Groovy Server Pages)
ƒƒ Dynamic tag libraries for creating Web page components sudo apt-get install curl
ƒƒ Customisable and extensible Ajax support
As a consequence, Grails is one of the most productive After running the above command, you can use the following
amongst frameworks. command to download the GVM script and execute it.

Getting started curl -s get.gvmtool.net | bash


To get started with Grails on a Linux machine, follow the
steps shown below. I am using Ubuntu 12.04, so in case After the script completes, you will be asked to open a

www.OpenSourceForU.com  |  OPEN SOURCE For You  |  OCTOBER 2014  |  57


Developers Let's Try

Home test test


to be used with minimal changes. Since Grails follows a
‘code by convention’ paradigm, you can build an application
grails-app lib src test
script
very quickly if you get familiar with the Grails standard
wrapper application.properties grailsw grailsw.bat
conventions. The best way to figure out some of the more
obvious conventions used in Grails is to look at the boilerplate
application created for you. Figure 1 gives a screenshot of the
Figure 1: Grails folder files and folders Grails generates for you.
For your reference, here is a breakdown of the folder
new terminal and run a command in it, which will be similar structure of Grails.
to the one that follows: ƒƒ grails-app: Top level directory for Groovy sources
ƒƒ conf: Configuration sources
source "/home/username/.gvm/bin/gvm-init.sh" ƒƒ controllers: Web controllers - the ‘C’ in MVC
ƒƒ domain: The application domain
After you run the above script, you'll be able to use the ƒƒ i18n: Support for internationalisation (i18n)
GVM to install Grails. ƒƒ services: The service layer
ƒƒ taglib: Tag libraries
3. Installing Grails: Run the following command to install ƒƒ utils: Grails specific utilities
ƒƒ views: Groovy server pages - the ‘V’ in MVC
ƒƒ scripts: Gant scripts
gvm install grails ƒƒ src: Supporting sources
ƒƒ groovy: Other Groovy sources
To install a specific version of Grails (say, version 2.3.2), ƒƒ java: Other Java sources
you can run the following command. ƒƒ test: Unit and integration tests
Now let’s see Grails in action. To run the pre-built
gvm install grails-2.3.2 application, use the following commands.

4. Testing your installation: The simplest way to test your cd test
installation of Grails is to use it to create a project. Use grails run-app
the following command to create a new Grails project.
At this point, Grails will install all the dependencies and do
mkdir test a couple of complex optimisations, which it displays on your
cd test screen. When it is ready, it will print the following message.
grails create-app test
A sample project Server running. Browse to http://localhost:8080/test

The above command creates an application for you. In our At this point, you can fire up your browser and type that
above example, we used the name ‘test’ for our project. The URL into the URL bar (Pro tip: if you're feeling a bit lazy,
really nifty thing about Grails (or any other Web framework) clicking Control on the link in the terminal will open the link in
is that it provides a boilerplate application, which is ready your default browser).
When you go to the URL, you'll be able to see a page like
the screenshot given in Figure 2, which lists specifics about
various plugins and your application’s configuration details. If
you do see this screen, you've successfully installed Grails for
your development environment.
Warning: The run-app command is intended for
development purposes only. It isn't meant to be used for
production environments. In production, you could use Grails to
build WAR (Web Application Archive) files and then deploy it on
an Apache Tomcat server, for instance, because a lot of possible
optimisations aren't supported by the Grails’ run-app server.

GORM
GORM is Grails' object relational mapping (ORM)
Figure 2: Grails screenshot implementation. Under the hood, it uses Hibernate 3 (a

58  |  OCTOBER 2014  |  OPEN SOURCE For You  |  www.OpenSourceForU.com


Let's Try Developers

very popular and flexible open source ORM solution). The next step is to configure the environments variable to
Thanks to the dynamic nature of Groovy, with its use test_dev for development and test_prod for production.
static and dynamic typing, along with the convention Edit your environment’s variable as shown in the code
of Grails, there is much less configuration involved in snippet below.
creating Grails domain classes. While this is a topic
that requires a separate article and a lot of practice, I environments {
will try to cover the main points about GORM. Grails development {
is known as a domain driven language, which means dataSource {
that an application can be built in a bottom-up manner. dbCreate = "create-drop" // one of 'create',
Domain classes are the core of any business application. 'create-drop', 'update', 'validate', ''
They can be linked together through relationships which url = "jdbc:mysql://localhost/test_dev”
can be one-to-one, one-to-many or many-to-many. By username = "root"
default, Grails applications are configured to use an in- password = "root"
memory database called HSQLDB. For the purposes of }
this tutorial, I will walk you through setting up MySQL. }
To do so, follow the steps listed below. test {
dataSource {
1. Creating a database in MySQL: Use the following dbCreate = "update"
command in MySQL to create a database. url = "jdbc:mysql://localhost/test_prod"
username = "root"
CREATE DATABASE test_prod password = "root"
}
This will create a database called test_prod, which }
we will use in production. Additionally, we can create a production {
database called test_dev, which can be used in development dataSource {
mode for testing our application. dbCreate = "update"
2. Updating the BuildConfig.groovy file in grails-app/ url = "jdbc:mysql://localhost/test_prod"
conf: We do this to tell Grails that our application needs username = "root"
to use the MySQL connector, so we need to add that password = "root"
as a dependency to our application. All dependencies }
must be specified in this file. When your application is }
run, all dependencies specified here are automatically }
downloaded and installed so that your application can
use them. Open up the BuildConfig file located in the dbCreate deserves a special mention. It determines
grails-app/conf folder and find the line... what happens to your database between server restarts. For
example, a value of create-drop means that the database
// runtime 'mysql:mysql-connector-java:5.1.24' tables will be dropped and then recreated when you start the
server, so you lose any data that was in there. This is fine for
...and uncomment it. The complete BuildConfig file testing, but is definitely not what you want in production.
can be downloaded from http://www.opensourceforu.com/ 4. Creating a new domain class: We're done with setting
article_source_code/sept14/grails.zip up Grails to use MySQL; so now we can simply create
3. Updating DataSource.groovy in grails-app/conf: a domain class which will be persisted in our database.
After setting up the dependencies, we must set up our Let’s create a domain class that represents a user of our
application to use certain data sources. In our project, application, using the following command.
we'd like it to use our test_dev for development
purposes and test_prod for production. First, we must grails create-domain-class test.User
edit the DataSource variable so that it knows how to
use the InnoDB engine, as follows: After this, Grails will tell you that it created a few files.
Let’s now edit Grails app/domain/test/User.groovy file to
dataSource { store the information of our users. The following is the
pooled = true edited User.groovy file.
driverClassName = "com.mysql.jdbc.Driver"
dialect = "org.hibernate.dialect.MySQL5InnoDBDialect" package test
}

www.OpenSourceForU.com  |  OPEN SOURCE For You  |  OCTOBER 2014  |  59


Developers Let's Try

Let’s check everything out by running our application, so


run the following in your terminal:

grails run-app

Now, if you check out your MySQL databases, you'll


notice that a table called ‘user’ has been created. The userid
field has a constraint of being unique, while the ‘username’
and ‘password’ fields are strings that cannot be blank.
If you check the contents of the table called ‘user’,
user it'll be empty. You can check this with the following
command.

select * from user;

Let’s navigate to the http://localhost:8080/test URL.


There we will be able to see our new controller. Click on it to
Figure 3: MySQL screenshot start CRUD activities.
Next, let’s create a new user by clicking on the 'new
user' button.
Home New User
Finally, let’s check if our data has been inserted into our
User List
table in MySQL.
Userid Username Password This is how you integrate MySQL with a Grails
application. Grails is not limited to MySQL. You can also use
any other database like PostgreSQL or MongoDB.
Figure 4: UserController screenshot
Advice for the veterans
class User { This section gives you some of the best practices in Grails,
long userid which will help you rapidly develop applications and tools
String username with this framework.
String password 1. Always use a domain-driven design: First, create your
static constraints = { basic domain model classes and then use scaffolding to
userid(unique:true) get them online. This will help you stay motivated and
username(blank: false) understand your domain better.
password(blank:false) 2. Follow Grails conventions: Grails is a convention-driven
} development environment.
} 3. Use DataSource.groovy: Use DataSource.groovy to
configure data sources.
5. To create a controller for User.groovy, type: 4. Use BuildConfig.groovy: This is to install any plugin in your

grails create-controller test.User

Update the file UserController.groovy under grails-app/


controller/test.
Inside the controller, we will define a scaffold that will
automatically create the CRUD (Create, Read, Update,
Delete) function for our domain class.
Your final UserController.groovy will look like what follows:

package test
class UserController {
def scaffold = User
def index() { }
} Figure 5: New controller added to Grails

60  |  OCTOBER 2014  |  OPEN SOURCE For You  |  www.OpenSourceForU.com


Let's Try Developers

Split the repeated content into templates.


Home User List
8. Automate the process: Write scripts to automate any
Create User
repetitive tasks. This will reduce errors and improve
overall productivity.
Userid * 0
9. The location convention: Services go into the Services
Username * Sahil

Password * HelloWorld
folder. Controllers go into the Controller folder.
10. The naming convention: All models, services,
Create
controllers and scripts should be named consistently.
Figure 6: Create User screenshot
In our example application, we had a model
named ‘User’; hence, our controller was named
‘UserController’. Grails will link them based on the
naming convention.
With Grails, we can develop applications quickly and in
an agile manner. Since it is based on well tested paradigms
like ‘Convention over configuration’ and DRY, Grails
provides a robust platform for development. In a world
where developers race against the clock to meet vicious
Figure 7: MySQL query output deadlines, having a framework which provides so many
built-in features makes Grails an invaluable tool.
application rather than using the ‘install-plugin’ command.
5. Keep your view simple: Make your views as simple By: Sahil Chelaramani
as possible.
The author is a software developer at a reputed start-up in
6. Use layouts: Use a layout for a consistent look across your UI. Bengaluru. He loves to code.
7. DRY: Keep your views DRY (‘Don't repeat yourself’).

THE COMPLETE MAGAZINE


ON OPEN SOURCE

www.eb.efyindia.com www.OpenSourceForU.com

www.OpenSourceForU.com  |  OPEN SOURCE For You  |  OCTOBER 2014  |  61


Developers Let's Try

Getting Started with

Clo ure
The flexibility and simplicity offered by this programming language, which is hosted on
the Java Virtual Machine, is bound to make it very popular among developers.

C
lojure is a dynamically and strongly typed between state and identity, and help provide defined
programming language, created by Rich Hickey concurrency semantics to manual threading and locking
and hosted on the Java Virtual Machine. It was strategies.
formed by incorporating the finest features of a variety of ƒƒ It is very efficient when it comes to programming to small
programming languages, such as Python, Java, Haskell, interfaces.
etc. Clojure helps eliminate various issues faced by the ƒƒ Clojure is dynamically and strongly typed but when
programmer, while setting them right for the future. Hickey it comes to compiling, it's compiled to Java method
developed Clojure because he felt the need to develop a invocations, which makes it fast.
modern LISP for functional programming. The simple ƒƒ It offers a safe and simple method to handle mutability.
syntax that it has makes meta programming through macros ƒƒ The manner in which it models data makes it easy to
extremely simple. work on.
ƒƒ The REPL in Clojure has no runtime penalty and, hence,
Why Clojure? is faster in comparison to its counterparts.
The best part about Clojure is that it is hosted on JVM, which
has an efficient runtime environment. Hence, it would be Setting up Clojure
better to choose Clojure rather than select a completely new We need not install Clojure as such, but we need a build tool
language and work in a completely new environment. The capable of managing dependencies. The most recommended
other reasons to choose Clojure include: build tool is leningen. By following the steps mentioned
ƒƒ The great flexibility and strong metaprogramming below, you can easily set up leningen:
facilities it has, due to its LISP origins. 1. Confirm that you have a Java development kit (JDK)
ƒƒ The remarkable concurrency and parallelism semantics version 6 or higher.
that it provides. 2. Download the lein script from the most stable version of
ƒƒ The presence of persistent data structures whose the project. (Refer leningen.org for more information)
performance puts even the mutable data structures to 3. Place it in your $PATH.
shame. 4. Make it executable.
ƒƒ It's very useful when it comes to dealing with large 5. Run it.
amounts of data, because of which it is extensively used
in data mining and large scale predictions. A few simple programs in Clojure
ƒƒ Clojure's reference types ensure a clear separation Here, let’s look at two simple examples.

62  |  october 2014  | OPEN SOURCE For You  |  www.OpenSourceForU.com


Let's Try Developers

We can change the namespace we want to use by giving


the ‘require' command in REPL. After using the ‘require'
command, just use the namespace name while referring to any
function/variable described inside it.
The most recommended way to set up a new namespace
at the top of a Clojure source file is to use the ns macro. By
default, this will create a new namespace that will contain the
mappings for classnames in java.lang and the functions in
clojure.core.

Figure 1: What a REPL for Clojure looks like Data structures in Clojure
Maps, vectors, sets and lists are the basic data structures
1. Hello world that Clojure provides; the other data structures are present in
Clojure collection hashes, StructMaps, ArrayMaps, etc.
Type the following command in a terminal: In Clojure, there are seven primary abstractions whose
data structures are as follows.
$ lein repl 1. Collection: All data structures in Clojure follow the
common collection abstraction. A collection is a value that
You'll get something similar to what is shown in Figure 1. you can use with the set of core collection functions.
Now type the following command and press Enter. Notice * conj is used to add an item to a collection:
how it's similar to the System.out.println familiar to all in Java.
user=> (conj '(237 4 2) 5)
user=> (println “Hello World!”) (5 237 4 2)

You'll get the output as: * seq is to get a sequence of a collection:

user=> (println “Hello World!”) user=> (seq '(1 2 3) )


Hello World! (1 2 3)
nil
* count helps in getting the number of items in a
collection:
2. Defining two variables and finding their sum
The following code defines two variables and stores their sum user=> (def a (seq '(1 2 3 4 5 6))
in yet another variable: #'user/a
user=>(count a)
user=> (def a 432) 6
#'user/a
user=> (def b 123) * empty is used to obtain an empty instance, which has the
#'user/b same type as that of the collection:
user=> (def c (+ a b))
#'user/c user=> (def a (empty '[1 2 3 4]))
user=> c #'user/a
555 user=> a
user=> []

* = is used to check equality between one collection and


What are namespaces? another completely different collection:
Namespaces are usually used to group symbols and identifiers
around a particular functionality. user=> (= '[1 2 3] '[1 2 3])
Clojure has a large amount of namespaces and they all true
come with many functions, thus making Clojure easy to use. user=> (= '[1 2 3] '(1 2 3))
clojure.github.io/clojure gives the details of the functions true
and vars present in each namespace in Clojure, as well as user=>(= '[1 2 3] 1)
their documentation. false

www.OpenSourceForU.com  | OPEN SOURCE For You  |  october 2014  |  63


Developers Let's Try

2. Sequence: The sequence abstraction shows a way for 4. Indexed: The index abstraction here is similar to the
traversal on sequential views over some set of values one in C++. The index can be given to access an element
—either another collection or values that are the result present at that specific position. There is only one function
of some calculation. There are a few operations that here, nth, which acts like the get function and returns the
sequences undergo: element at the nth position. There are also exceptions to
ƒƒ seq produces a sequence over its argument. check the out-of-bounds condition.
ƒƒ The first, next and rest of the keywords help make
traversal through the seq an easy task.
user=> (def S '[1 2 3 4 5])
user=> (def a (seq '(1 2 3 4 5 6 7))) #'user/S
#'user/a user=> (nth a 2)
user=> (first a) 3
1
user=>(rest a) 5. Stack: Clojure does not have a stack data structure as
(2 3 4 5 6 7) such, but we can use lists and vectors to realise this data
structure. The three main operations here are:
ƒƒ It is possible for the contents of a sequence to be ƒƒ conj, to add an element to the top of the stack:
evaluated at leisure, where values are computed and
produced only when a user tries to access it. user=> (def stack '(5 4 3 2 1))
3. Associative: The associative abstraction is found in all #'user/stack
data structures that map keys to certain values in some user=> (conj stack 6)
way; so, it is mostly seen in various kinds of maps. It (6 5 4 3 2 1)
has four operations:
ƒƒ assoc, through which connections are made between a ƒƒ pop, to remove the element present at the top of the stack:
key and its value:
user=> (def stack '(5 4 3 2 1 ))
user=> (def S {:a 10 :b 20 :c 30}) #'user/stack
#'user/S user=> (pop stack )
user=> (assoc S :d 40) {4 3 2 1}
{:a 10 :b 20 :c 30 :d 40}
ƒƒ peek, for obtaining the value on the top of the stack:
ƒƒ dissoc, which cuts off the connections between a key
and its value: user=> (def stack '(5 4 3 2 1))
#'user/stack
user=> (def S {:a 10 :b 20 :c 30}) user=> (peek stack)
#'user/S 5
user=> (dissoc S :a )
{:b 20 :c 30} 6. Set: The set abstraction is technically a reusing of the
functions in a collection as well as associative semantics.
ƒƒ get, which searches the value for a specific key in the The clojure.set namespace provides a number of functions
collection: that can be performed on a set, including subset?,
superset?, union, etc.
user=> (def S {:a 10 :b 20 :c 30})
#'user/S user=> (require '[clojure.set :as t])
user=> (get S :a) nil
10 user=> (def a '[1 2 3 4 5 6 7 8])
#'user/a
ƒƒ contains?, which checks if a key has a specific value user=>(def b '[1 2 3])
and returns true if it does: #'user/b
user=>(t/subset? b a)
user=> (def S {:a 10 :b 20 :c 30}) true
#'user/S user=>(t/superset? a b)
user=> (contains? S :a ) true
true Continued on page no 68...

64  |  october 2014  | OPEN SOURCE For You  |  www.OpenSourceForU.com


Insight Developers

Application Testing Tools


You Should Know About
M
Mobile application testing is an important obile application testing refers to the specialised
phase of mobile app development. In this process with which the application software
article, the author explores a few open developed by software engineers can be tested
source mobile app testing tools and the for functionality, security, usability and consistency. The
types of tests that mobile apps undergo testing of mobile apps can be automated or manual. They
before they are marketed. may be pre-installed with a fresh handset, or be installed
from software distribution platforms and online repositories
launched by network service providers.
Security testing is considered the most important factor
of mobile apps testing, because with banking and financial
services going online, mobile apps need to be secure to
prevent malicious attacks.

Types of mobile application testing


Today, since almost every service is accessible via a mobile
phone, there are a number of parameters on which mobile
apps are tested, as any small error can ruin the reputation of
mobile app providers.
The following are the testing techniques used for rigorous
analysis of mobile apps.
Usability testing: This tests the user interface, and
ensures that the mobile app is easy to use and provides a good
user experience. Usability testing is carried out to verify if
the application is achieving its goals and getting a favourable
response from users. This is important, as the usability of an
application is the key to its commercial success.
Compatibility testing: This tests the app on multiple
platforms so that there is no problem linked
to compatibility or portability. The testing of
the application on multiple mobile devices,
Web browsers, screen resolutions and
operating system versions is done based
on requirements.
Interface testing: Interface testing is concerned with
the analysis and testing of menus, sub-menus, menu options,
buttons, hyper links, bookmarks, history, settings, navigation
flow and other related components of the application.
Services testing: This tests the mobile application under
different modes, including online and offline. With the help
of these tests, the predictive behaviour of the mobile app is
analysed.

www.OpenSourceForU.com  |  OPEN SOURCE For You  |  OCTOBER 2014  |  65


Developers Insight

Testing the system resources: In this testing technique, Use of emulators


aspects like memory usage, auto deletion of temporary files, Currently, almost every organisation makes use of
and issues linked to the growth of the local database are tested. emulators as well as simulators in its research and
In the process, the battery or power consumption issues are also development cells. Using such technologies, the look
analysed by the test engineers. and feel of the device or application can be experienced
Performance testing: This tests the performance or without using the actual infrastructure. With this method,
efficiency of the mobile app by transforming the network there is no damage or maintenance of actual infrastructure,
connection from 2G or 3G to Wi-Fi, sharing documents, because everything is tested virtually. The use of emulators
gauging battery consumption and other aspects. The mobile is extremely useful in the initial stages of development,
app is tested under different scenarios so that its behaviour as they allow quick and efficient checking of the app.
can be analysed under certain conditions such as low battery, An emulator is a system that runs software from one
bad network coverage, low available memory, simultaneous environment in another environment without changing the
access to the application’s server by several users, and other software itself. It imitates the features and behaviour of the
conditions. The performance of an application can be affected real or actual system to be used.
by what’s happening on the server side and client side. So Some mobile emulators are listed below.
performance testing is carried out to check both. ƒƒ Device emulator: Packaged and provided by device
Operational testing: This is done to test backups and manufacturers
recovery plans when the battery goes down. Or if data gets lost ƒƒ Browser emulator: Used to simulate mobile browser
while upgrading to a new application bought from the store. environments
Security testing: These tests are done to validate whether ƒƒ Operating systems emulator: Apple provides emulators for
the mobile app is fully secured against cross site scripting, iPhones, Microsoft for Windows phones, and Google for
SQL injection, session hijacking, cookie stealing and other Android phones
related attacks.
Functional testing: Functional testing makes sure that Challenges in mobile app testing
the application is working as per requirements. Many of Mobile app testing can be challenging because of the
the tests conducted for this are driven by the user interface following factors.
and call flows. The sheer variety of mobile devices: Mobile devices
Laboratory testing: Laboratory testing is usually done by differ in screen sizes, input methods (QWERTY, touch or
network carriers, by simulating the entire wireless network. normal) and have different hardware capabilities.
This test is performed to find out any glitches when a mobile Diverse mobile platforms/OSs: There are many different
application uses voice and/or data connections to perform mobile operating systems in the market. The major ones
some functions. are Android, iOS, BREW, BREWMP, Symbian, Windows
Testing for memory leakages: Memory leakage occurs Phone and BlackBerry (RIM). Each operating system has its
when a program or mobile app is unable to manage the own limitations. Testing a single application across multiple
memory allocated to it, resulting in poor performance of devices running on the same platform and then on every
the app and the overall slowing down of the system. As platform, poses a unique challenge for testers.
mobile devices have significant constraints on available Mobile network operators: There are over 400 mobile
memory, memory leakage testing is important for the proper network operators in the world, of which some are CDMA and
functioning of any application.
Interrupt testing: Mobile apps face different Online mobile device emulators and testing tools
interruptions like incoming calls, and problems related to Using mobile device emulators, any Web application can
battery power or network coverage. Interrupt testing ensures be tested on different platforms or mobile devices. The
the avoidance of these issues. following websites provide mobile device emulators.
Different types of mobile phone interrupts are: incoming https://appthwack.com/
https://testobject.com/
and outgoing SMS and MMS, incoming and outgoing calls,
http://www.testiphone.com/
incoming notifications, battery removal, cable insertion and http://iphone4simulator.com/
removal for data transfer, network outage and recovery, media http://iphone-emulator.org/
player being turned on or off, and the device’s power cycle. http://iphone5csimulator.com/
Installation testing: Many mobile apps come pre- http://www.mobilephoneemulator.com/
installed on the mobile phone, whereas others have to be http://ready.mobi
installed from the store. Installation testing ensures that the http://responsivepx.com/
installation process goes smoothly without any problems for http://quirktools.com/screenfly/
the user. This testing process covers installation, updation and http://ipadpeek.com
http://transmog.net/iphone-simulator/
uninstallation of the application.

66  |  OCTOBER 2014  |  OPEN SOURCE For You  |  www.OpenSourceForU.com


Insight Developers

some are GSM-based, while others use less common network URL: http://www.appium.io
standards like FOMA and TD-SCDMA. Each network Robotium: Robotium is the Android test automation
operator uses a different kind of network infrastructure and framework that offers full support for native and hybrid
this limits the flow of information. applications. Robotium makes it easy for engineers to
Scripting: The variety of devices being used makes write powerful and robust automatic black-box UI tests for
executing the test script (scripting) a key challenge. As Android applications. With the use of Robotium, the test case
devices differ in keystrokes, input methods, menu structure developers can write function, system and user acceptance
and display properties, a single script does not function on test scenarios, spanning multiple Android activities.
every device. The following are the features of Robotium:
ƒƒ It can test any type of Android app - native and hybrid.
Mobile application testing tools ƒƒ Detailed knowledge of the application under test is
Using specific as well as specialised tools, mobile apps can be not required.
tested on multiple parameters and dimensions. ƒƒ The framework handles multiple activities of Android
automatically.
iPhone ƒƒ Less time consuming when writing solid and complex
The following tools can be downloaded and used to test test cases.
mobile applications that run on the iPhone. ƒƒ Readability of test cases is greatly improved, compared to
Clang Static Analyzer: URL: http://clang-analyzer.llvm.org standard instrumentation tests.
XCode: URL: https://developer.apple.com/library/ ƒƒ Test cases are more efficient and robust due to the run-
prerelease/ios/documentation/ToolsLanguages/Conceptual/ time binding to UI components.
Xcode_Overview/UnitTestYourApp/UnitTestYourApp.html ƒƒ Speedy and accurate test case execution.
ƒƒ Integrates easily with Maven, Gradle or Ant to run tests as
Android part of continuous integration.
A wide range of tools can be downloaded and used for testing URL: https://code.google.com/p/robotium
mobile applications that run on Android. Some of these are MonkeyRunner: This tool provides an API for writing
listed here. the programs that can control the Android device or emulator.
Android Lint: This is integrated with the Eclipse IDE for Using MonkeyRunner, the test engineer can write a Python
Android app testing. This software highlights the potential program that installs an Android application or test package,
bugs and performance problems in the app. The Android Lint runs it, sends keystrokes, takes screenshots of its GUI, and
tool is a static code analysis tool that checks the Android stores the screenshots on the workstation.
project source files for potential bugs. It also optimises The MonkeyRunner tool was developed primarily to test
and improves the app’s performance, usability, security, applications and devices at the functional or framework level
accessibility and internationalisation features. and to run unit test suites, but test engineers are free to use it
URL: http://developer.android.com/tools/help/lint.html for other purposes.
FindBugs: This is an open source code library for static This software allows test engineers to perform functional
analysis. It is a special plugin for Android-specific coding, app testing by providing the API for managing the device.
and is a static code analysis tool for finding bugs in standard MonkeyRunner makes use of Jython, an implementation of
Java programs. Python that uses the Java programming language. Jython
URL: https://code.google.com/p/findbugs-for-android allows the MonkeyRunner API to interact directly and easily
Appium: Appium is an open source test automation with the Android framework. With the use of Jython, the
framework for use with native and hybrid mobile apps. test engineer can use Python syntax to access the constants,
It works for iOS and Android apps using the WebDriver classes, and methods of the API.
JSON wire protocol. Appium is cross-platform and allows MonkeyRunner does not have advanced features like
the writing of tests for multiple platforms (iOS, Android) Robotium. The tool has three modules:
using the same API. It enables code to be reused between ƒƒ MonkeyRunner, to manage connections to the devices.
iOS and Android test suites. It allows users to create test scripts with Python or just
Native apps are those written using the iOS or Android record and play them.
SDKs. Mobile Web apps are those accessed using a mobile ƒƒ MonkeyDevice, to manage apps and events.
browser (Appium supports Safari on iOS and Chrome, or ƒƒ MonkeyImage, to gather screenshots for advanced test
the built-in ‘Browser' app on Android). Hybrid apps have a reporting.
wrapper around a ‘webview’—a native control that enables The MonkeyRunner tool provides the following unique
interaction with Web content. Projects like Phonegap make features for Android testing:
it easy to build apps using Web technologies that are then ƒƒ Multiple device control: The MonkeyRunner API can
bundled into a native wrapper, creating a hybrid app. apply one or more test suites across multiple devices or

www.OpenSourceForU.com  |  OPEN SOURCE For You  |  OCTOBER 2014  |  67


Developers Insight

emulators. Test engineers can attach all the devices or start for automating GUI testing. It is an open cross-platform
up all the emulators at once, connect to each one, in turn, visual platform for creating the scripts, and is oriented
programmatically, and then run one or more tests. They can towards programming the graphic interface with the help of
also start up the emulator configuration programmatically, images or screenshots. Sikuli is a tool that can supplement
run one or more tests, and shut down the emulator. the testing toolbox. The scripts the test engineer creates
ƒƒ Functional testing: The MonkeyRunner software can execute with this tool are in the Sikuli Script language, which has a
an automated start-to-finish test of any Android application. Python (Jython) extension.
Test engineers can provide the input values with keystrokes URL: http://www.sikuli.org
or touch events, and view the results as screenshots. Calabash: Calabash enables test engineers to write and
ƒƒ Regression testing: The software can test the app’s stability execute automated acceptance tests for mobile apps. It is
by executing an app and comparing its output screenshots cross-platform, and supports Android and iOS native apps.
to a set of screenshots that are known to be correct. Calabash is free, being distributed as open source software,
ƒƒ Extensible automation: As MonkeyRunner is an API toolkit, with the company Xamarin backing and developing it.
test engineers can develop an entire system of Python-based URL: http://calaba.sh
modules and programs for controlling Android devices.
Besides using the MonkeyRunner API itself, engineers can By: Dr Gaurav Kumar
use the standard Python OS and sub-process modules to call The author is the MD of Magma Research & Consultancy Pvt
Android tools such as Android Debug Bridge. Ltd, Ambala. He is associated with a number of academic
URL: http://developer.android.com/tools/help/ institutes, and delivers lectures and conducts technical
monkeyrunner_concepts.html workshops on the latest technologies and tools. E-mail:
kumargaurav.in@gmail.com
Sikuli: This is another open source tool that is used

...Continued from page no 64

user=>(t/union a '[9 10 11]) options for anyone who wishes to work on it.
[1 2 3 4 5 6 7 8 9 10 11] ClojureScript: ClojureScript (github.com/clojure/
clojurescript) is mainly targeted at JavaScript (technically,
7. Sorted: Collections that follow sorted abstraction are ECMAScript 3), and therefore produces code that can
assured that their elements will be sorted. Only maps and be run in all the latest browsers, as well as in other
sets are available in the sorted variant. The main functions environments that execute JavaScript such as Node.js,
here are as follows. CoffeeScript, etc. There is a big difference between Clojure
ƒƒ rseq, which returns the sequence in the reverse order: and ClojureScript. This is not only because there is a major
difference between the hosts for JavaScript and the JVM,
user=> (vec (range 16)) but also due to the fact that ClojureScript is a source-to-
[0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16] source compilation. An overview of the differences between
user=> (rseq (vec (range 16))) Clojure and ClojureScript is available at github.com/clojure/
(15 14 13 12 11 10 9 8 7 6 5 4 3 2 1) clojurescript/wiki/Differences-from-Clojure.
Though Clojure has not reached its zenith of success and
ƒƒ subseq, which returns a subseq that's in a particular order: popularity yet, it's pretty certain that it will do so in a couple
of years. Many of the core companies have started adding
user=> (subseq (sorted-set 1 2 3 4 5 6 7 8) > 4) Clojure to the pre-requisites candidates need to have when it
( 5 6 7 8) comes to recruiting. So, we can say with certainty that Clojure
is indeed the future.
ƒƒ rsubseq, which is the same as subseq, but in reverse order:
References
user=>(rsubseq (sorted-set 10 20 30 40 50) < 29) [1] clojure.org
(20 10) [2] stackoverflow.com3.
[3] ‘Clojure in Action’ by Amit Rathore
[4] ‘Clojure Programming’ by Chas Emerick, Brian Carper
What next? and Christophe Grand
ClojureCLR: ClojureCLR1 is a port of Clojure to the .NET
CLR. It is not a simple cross-compilation; rather, it is maintained
By: Aravind K
separately and aims at providing the same level of usability for
CLR as it provides for JVM. Even though ClojureCLR is not The author is an open source enthusiast and is a contributor to
Mediawiki and Clojure. You can reach him at aravikn@gmail.com
as widely used as Clojure, it's well-tested and provides a lot of

68  |  OCTOBER 2014  |  OPEN SOURCE For You  |  www.OpenSourceForU.com


Admin How To

There are several ways to send bulk mail that’s not treated as spam. The easiest way is to sign
up for a service like Mailchimp. However, there is a great thrill in setting up your own bulk
mailing infrastructure, which is what this article is about.

M
ost organisations would like to engage with their $wget http://downloads.sourceforge.net/project/phplist/
customers or the community by sending out regular phplist/3.0.6/phplist-3.0.6.tgz?r=http%3A%2F%2Fwww.phplist.
product updates. As the volume of emails sent com%2Fdownload&ts=1403941429&use_mirror=jaist
grows, over-aggressive filters at the receiving end are likely
to flag these emails as ‘Spam’ and trash them, often without It’s a long URL, so rather than typing it, you can copy the
informing the sender of this action. As a consequence of this, URL from the direct link that appears when you download
the reputation of the organisation's domain may get tarnished, PHPList from Sourceforge. Alternatively, you can download
resulting in the domain being listed on one of the several it to your laptop and then upload it to your server, though I
online blacklists like Spamhaus. wouldn't recommend it.
To set up your own bulk mailing infrastructure, let’s Unpack the archive in your HOME folder. This should
assume that you have access to the command line, ideally on a create a directory called phplist-3.0.6. This directory has a
VPS or dedicated server. I have used a Centos 6.4 VPS, so the sub-directory called public_html/lists which contains the
commands are for Centos, but Ubuntu users can easily adapt files that are required to run PHPList; the rest of the files are
the steps. First, here’s an inventory of the things we need. not required for PHPList to work. However, we'll let these
ƒƒ A VPS or bare metal machine connected to the Internet files remain.
ƒƒ PHPList
ƒƒ MySQL $tar -zxvf phplist-3.0.6.tgz
ƒƒ A registered domain with access to change the DNS zone
entries MySQL
Now, let’s create a database for PHPList. Most Linux
PHPList distributions have MySQL installed by default. To check if
PHPList is a popular open source newsletter manager written MySQL is installed, type the following in your CLI:
in PHP. Let’s use this to set up our bulk mailing infrastructure
to manage our subscription lists. So get started and download $ mysql -V
the required files like the PHPlist TGZ from http://www. mysql Ver 14.14 Distrib 5.1.69, for redhat-linux-gnu (i386)
phplist.com into your home directory. using readline 5.1

70  |  OCTOBER 2014  |  OPEN SOURCE For You  |  www.OpenSourceForU.com


How To Admin

If you already haven't installed MySQL, you can do so by


running and following the online instructions:
DASHBOARD Navigation

Database has not been initialised. go to Initialise Database to continue


$yum install mysql English

Connect to MySQL and create the database ‘phplist’


as follows:

$mysql -u[your username] -p[your password]

Then, at the MySQL prompt, type: © phpList ltd. - v3.0.6 Resources

Figure 1: PHPList dashboard


mysql> create database phplist;
Query OK, 1 row affected (0.00 sec)

Configure PHPList to connect to MySQL


Let’s configure PHPList to connect to the database that we
just created. Open the config file available in the lists/config/
directory using Nano, and replace the values for the database
user and password.

nano phplist-3.0.6/public_html/lists/config/config.php

# what is your Mysql database server hostname


$database_host = "localhost";

# what is the name of the database we are using Figure 2: Installing the database
$database_name = "phplist";
PHPList will be installed within a few seconds (Figure 2). Do
# what user has access to this database the developers a favour and tell them that you have installed
$database_user = "your username"; PHPList by clicking the ‘Tell us about it’ button. Then click
‘phpList Setup’ to continue with the installation.
# and what is the password to login to control the database Click on Verify settings. Use admin for the login name and
$database_password = 'your password'; the password you provided during the installation in order to
log in. Let’s not change any other settings, for now.
# if test is true (not 0) it will not actually send ANY Click the Configure attributes. PHPList has a set of default
messages, but display what it would have sent lists that can be used while creating newsletters. We'll load
# this is here, to make sure you edited the config file and the following by clicking the Predefined Defaults and then
mails are not sent "accidentally" clicking Countries in the world and States in India. Then click
# on unmanaged systems on the Add button.
define ("TEST",0); Having done this, let’s create a Subscribe page. Click on
Create subscribe page and create a page to subscribe to your
DNS entries newsletter (Figure 3).
Now, set up a domain (www.yourdomain.in) and point the Let’s now add some subscribers to our list. Just copy and
A record to your IP address. Set up your Apache or NGINX paste a few emails in the box, click the Import button and you
server virtual host document root to point to the directory are done (Figure 4).
phplist-3.0.6/public_html/ and restart your server. (The Before we send out campaign mails, we should set a
Apache configuration files are available in /etc/httpd/conf.d few domain entries. This is to ensure that our bulk mails are
and those of Nginx are available under /etc/nginx/conf.d) not flagged as spam at the receiving end. For this, we have
to follow some of the best practices as espoused by large
PHPList configuration webmail providers like Gmail.
Fire up your browser and visit http://www.yourdomain.in/
admin. You should see the PHPList dashboard (Figure 1). Finalise an IP address
Click the initial database link and follow the instructions. The first step is to finalise the IP address for your PHPList. If

www.OpenSourceForU.com  |  OPEN SOURCE For You  |  OCTOBER 2014  |  71


Admin How To

you recall, at the beginning of the article, I did mention that


you should be on a VPS or dedicated server. These servers
should be on a static IP and not on a DHCP.
Your mail server should have a DNS and RDNS entry in
your DNS zone file
Earlier, we had created an ‘A’ record in the DNS zone file
that pointed to the server. An ‘A’ record is looked up by the
browser and other programs to resolve the domain name to
an IP address. You should create an RDNS or Reverse DNS
entry (also known as PTR) to let recipient mail servers look
up the URL from the IP address sent in the email packet. This
is one way of ensuring that the email is not spoofed and its
origin is trustworthy. To create a RDNS record:
1. Create an RDNS zone.
2. If your IP address is 123.456.789.81, drop the last octet
and reverse the string so that the RDNS is 789.456.123
3. Append .in-addr.arpa to the string above to get
789.456.123.in-addr.arpa. This is the hostname for the
RDNS zone.
4. Add a new PTR record and use the last octet of your IP
address (81) for the name. Enter the domain name for the
CNAME.

Have different mail IDs for different purposes


In an organisation, you will send email communications
for different purposes. As a good practice, you should use a
different ID for each of these purposes. If you send a monthly
newsletter, then the sender ID should be set to newsletters@
yourdomain.com. All promotional mailers should have a
sender ID like promotions@yourdomain.com, and so on. You
should ensure that this is configured in PHPList. Remember
that this is a ‘send only’ email ID and it need not exist. And
yes, any mails to this ID will result in a bounce, which is the
Figure 3: Subscription page settings reason for ensuring we have a ‘Reply to’ address.

Finalise the ‘From’ and ‘Reply to’ addresses


Even if you include a note telling people not to reply to the
email, it’s highly unlikely that someone will notice your note
before hitting the ‘Reply to’ button on their email clients.
So it’s a good practice to include a ‘Reply to’ header and
associate an address with it.
If you associate an address with it, then you should
ensure that you have an actual email box associated with this
address. You can do this by signing up with an email service
or by setting up Postfix, Dovecot or Squirrelmail on a server.
If you purchase an email service, then the MX records are set
up by the provider. If you roll out your own, ensure that you
create the MX records in your DNS Zone file. This is because
the email clients look up the MX records for transporting
email from the client PC to the mail server or MTA.

Have a different ‘Reply to’ address


Just as you have different email IDs for different purposes, it’s
Figure 4: Importing subscribers a good practice to have a different ‘Reply to' address for each

72  |  OCTOBER 2014  |  OPEN SOURCE For You  |  www.OpenSourceForU.com


How To Admin

type of email, so that when recipients respond to your mail by Ensure that you change the ownership of the key:
hitting the ‘Reply to' button on their email clients, they land in
the boxes designated for them. $mv default.private /etc/opendkim/keys/.
$chown opendkim /etc/opendkim/keys/default.private
Publish the SPF and PTR records
An SPF or Sender Policy Framework specifies which We need to instruct Opendkim to use the KeyTable
servers can send emails to ‘yourdomain.com’. In most file. So, open the DKIM configuration file and look for the
cases, an SPF record is created by your hosting providers following line and uncomment it:
but for the sake of this article, let's create one for our bulk
email server. KeyTable /etc/opendkim/KeyTable

yourdomain.com. IN TXT "v=spf1 a mx ptr -all" Create an entry in the KeyTable by editing the file using
Nano or any other editor. The domain key should be as
The v=spf1 is the version specification for the SPF shown below:
being used. ‘a' means that the IP address of yourdomain.
com is allowed to send emails while ‘mx’ means that $nano /etc/opendkim/KeyTable
even the ‘mx’ servers can send email. You can also
specify a different server for ‘mx’ by mentioning default._domainkey.sastratechnologies.in sastratechnologies.
‘mx:sastratechnologies.com’. The PTR mechanism means in:default:/etc/opendkim/keys/default.private
that if a host has a PTR record ending with mydomain.com,
then it can send email. Create a TXT record in your DNS Zone file, where you
set the HOST to default_domainkey and the value to the key
Sign with DKIM using a key that’s value. It should look something like what follows:
less than 1624 bits
DKIM stands for ‘Domain Key Identified Mail’. It v=DKIM1; g=*; k=rsa; p=MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBg
provides a method for validating a domain name identity QDrwLEIYP2BAC53zzJn3WPnC9oD
that is associated with the message through cryptographic Mq0l+b+zs5O2FtjXVqi0+Fs4gMLJDCdltOHpLU2hoPXpnyTFmi2/
authentication. We'll use ‘Opendkim Milter’ to sign our lwsF9KXS6MLt
outgoing email. dy/XpiwaXYbi+Zw68PMWhougUomF/XOkY0j2yTHF/9M+ZI0RVmR6eGWLWtB
PHPList is an email generator and Opendkim is a milter yjO7Y
or a mailfilter! The two must be bridged by an MTA or Mail Y7ED+lYOfRCYqLq57wIDAQAB
Transfer Agent. Most distributions of Linux have Sendmail
installed. We'll cover the process of installing DKIM and …where ‘p’ is the value of the public key that we
configuring Sendmail to use the DKIM milter. The process is generated, i.e., default.public
similar to using Postfix as your MTA. Now instruct Sendmail to use DKIM by editing submit.mc
Install Opendkim by using the following command: and adding the following line:

$yum install opendkim openssl nano /etc/mail/submit.mc


INPUT_MAIL_FILTER(`dk-filter', `S=inet:8891@localhost')dnl
Set it to run on startup:
Build a new submit.mc by running:
$chkconfig --levels 235 opendkim on
m4 /etc/mail/submit.mc > submit.cf
Generate a private key, as follows:
Restart Sendmail:
$openssl genrsa -out default.private 1024
/etc/init.d/sendmail restart
Generate a public key:
Now all mails that you send out using PHPList will be
openssl rsa -in default.private -pubout -out default.public signed by Sendmail using the Openssl keys we generated.
-outform PEM
Update contact information on WHOIS
As the root user, or by using sudo su, move the private and abuse.net
key to the directory for Opendkim to read the private key. It’s a good practice to have a listing on abuse.net to allow

www.OpenSourceForU.com  |  OPEN SOURCE For You  |  OCTOBER 2014  |  73


Admin How To

prefer to include a link rather than an email address


You received this email because your are registered on with the email
address: sridharpandu@gmail.com
We respect your privacy. View our Privacy Policy

for unsubscribing, to avoid the email ID from being


If you believe this has been sent to you in error, please safety unsubscribe

Figure 5: PHPlist unsubscribe option harvested (Figure 5).

non-intended recipients of your bulk mail to report abuse. To Send confirmation messages to subscribers
do that, send an email (TXT, not HTML) to update@abuse. that offer a facility to unsubscribe
net. Ideally, you should list the email address that recipients Periodically, send a summary mail of the newsletter
will use to report abuse, and the email should look similar to subscriptions and allow the recipient to unsubscribe by
the following: clicking a link from within this email.
sastratechnologies.com: abuse@sastratechnologies.com
Ensure that your contact information on WHOIS is up to Have an email ID for people to report abuse
date. You can do this via your domain registrar. Earlier in this article we created an email ID for abuse
This apart, there are certain last minute details that you reporting and listed it on abuse.net. So do ensure that this
should look into before you send your first email newsletter. email ID is monitored and any reports of abuse are dealt
For starters, make changes to the email text body, as with appropriately.
follows.
Use the precedence:bulk header field
Include a link to add the address in Though some people advocate the usage of a ‘precedence:
the address book bulk’ field in the header of your email messages, we have
Your email text body should have a link telling subscribers seen very few organisations use it. The Huffington Post sets
to add the sender ID to their address book, especially on a ‘precedence: bulk’ in its daily briefs but several others
public mail servers like Gmail and Yahoo. If the sender’s don't.
address is in your address book, the incoming mail is not RFC is the ‘Request For Change’, a mechanism by
classified as spam. which users request for changes in programs. The RFC 2076
deals with common Internet message headers and explains
Include an explanatory message in great detail the commonly occurring headers in email
At the bottom of the page, include a line to mention why the messages. It discourages the use of the precedence header,
recipient is receiving this email. Figure 5 gives an example of as many recipient servers will just filter that off.
a large online retailer using such a message in the footer of its
bulk email. Send your first newsletter
Now that you are set, create your first email campaign.
Include a link to unsubscribe Ensure that you include everything mentioned above in your
Include a link, which when clicked on, unsubscribes the email, and then send it out to a close circle of friends. Enjoy
recipient from the list. the response you receive!

Include a ‘Reply to’ email ID as a form References


of unsubscribing
You should have an email ID to which recipients can [1] PHPLIST: A popular open source newsletter manager –
http://www.phplist.com
send an email to unsubscribe. We find that most people [2] Sendmail: An industry standard MTA (Mail Transfer Agent) -
http://www.sendmail.com/
Blacklists [3] OpenDKIM: An open source milter service for providing DKIM
services - http://www.opendkim.org/
There are over a hundred blacklists. Here are a few of the most [4] OpenSSL: An open source project to develop a robust,
popular ones. commercial grade, full-featured and open source toolkit
• SORBS DUHL: The Spam and Open Relay Blocking System implementing SSL - http://www.openssl.org/
(SORBS) provides free access to a DNS-based block list - [5] MXToolBox: An online service for querying the DNS zone file
http://www.sorbs.net/lookup.shtml of your domain. It gives you an indication if your DNS server
• UCEPROTECTL3: The project's mission is to stop mail abuse changes have been propagated - http://mxtoolbox.com
globally - http://www.uceprotect.net/
• SPAMHAUS ZEN: Maintains a number of security intelligence
databases and real time spam blocking databases - http://
www.spamhaus.org/ By: Sridhar Pandurangiah
• RATS Dyna: Uses IP reputations to reduce bulk email - http:// The author is the co-founder and director of Sastra Technologies,
www.spamrats.com/ a start-up engaged in providing EDI solutions on the cloud.
• SEM BLACK: SpamEatingMonkey.com provides real time IP He can be contacted at sridhar@sastratechnologies.in /
and domain blacklists to prevent the delivery of unwanted sridharpandu@gmail.com. He maintains a technical blog at
mail - http://spameatingmonkey.com/index.html sridharpandu.wordpress.com

74  |  OCTOBER 2014  |  OPEN SOURCE For You  |  www.OpenSourceForU.com


How To Admin

Is Your Network Getting Slower?


This article addresses a very vexing problem that plagues most of us at some time or the
other. Internet speeds are a bone of contention between the user and the ISP. The author gives
examples of how problems linked to a slow network were resolved using Wireshark.

H
opefully, readers have learnt from and enjoyed the • Ethernet device driver
earlier articles in this series on Wireshark, which • Presence of worms (a type of malware which generates a
started in July 2014. The articles included discussions lot of network traffic)
on various important and interesting Wireshark features and • Insufficiently configured computer hardware
various protocols such as ARP and DHCP, capturing packets • Too many downloads initiated from a single system or network
in a switched environment, detecting an ARP spoofing attack, • All systems scheduled to update the anti-virus or the
etc. This article will discuss how to put Wireshark to use operating system simultaneously
when troubleshooting ‘slow network’ problems. • Simultaneous use of ERP software during a particular time
Computer users often say, “The network is slow” or “The To arrive at the correct troubleshooting approaches,
Internet is working very slowly.” Field engineers trying to consider the fundamental basis of networking –- the OSI/
troubleshoot such problems face an uphill task; first, to figure TCP–IP layers. I assume that readers are knowledgeable
out what exactly a ‘slow network’ means and further, to about them - a lot of excellent information is also available
locate and solve the actual problem. There are just too many on the Internet. Still, let me describe these layers in brief for
different aspects and variables to check. relevance and immediate reference.
The actual reasons for slow network speeds could be OSI layers separate network communication into seven
broadly classified as follows. different layers, each offering its services to its immediate
Network related issues: upper and lower layer. This enables structured and standardised
• Slow Internet bandwidth available from the ISP, communication between systems. The OSI model does not
especially in shared connections require presence of each one of these seven layers. Also,
• A faulty Ethernet switch multiple adjacent layers could be combined to form one layer.
• A fault in the Ethernet interface on the switch As of today, the most widely used model is TCP/IP, which has
• A defective Ethernet card on a computer system or device four layers. Do go through Table 1, which describes the four
in the network TCP/IP layers, their functions and corresponding OSI layer(s).
• The presence of electrical noise in the vicinity of the These OSI and TCP-IP layers are important from
network’s cabling troubleshooting perspective—depending upon the situation,
Problems linked to the operating system, drivers and one may use these layers as guidelines when selecting a
everything else: particular approach while troubleshooting.

www.OpenSourceForU.com  |  OPEN SOURCE For You  |  October 2014  |  75


Admin How To

The top down approach: The diagnosis starts from the switches always stabilises the network, but after a random
the operating system, device drivers, anti- virus software period of time, the problem reappears. To sum it up, the
and application software, before going down towards the problem reported was actually the non-functioning of the entire
network access layer. LAN and was not limited to just “the Internet is not working.”
The bottom up approach: In this case, troubleshooting The best approach to troubleshooting in this case would
starts from the Ethernet media (cabling), Ethernet card, MAC have been to use Wireshark if managed Ethernet switches with
address and IP address before moving up the layers towards a SPAN port (port mirroring) were available. With the help of a
the application layer. In short, this approach involves starting SPAN port, traffic from all the other ports on that switch could
by locating faults in the network infrastructure before moving be copied to one port. A system with Wireshark connected
up to the application layer. on this SPAN port would capture the entire switch traffic. An
Before deciding upon the approach and starting the actual analysis of this would lead to the faulty component or system
tests or hands-on diagnosis, discuss the problem with the end being detected. However, on this site, managed switches were
user or site engineer (if any). For example, when the problem not available; hence a different approach was followed:
of a slow network is reported, the actual problem could be 1. First, the stacking of the switches was disconnected.
non-accessibility (or slow speed) of a particular service (say, 2. Then, the Ping command was used continuously from one
FTP). Here, you can certainly select the top down approach server to the default gateway.
and proceed. As you troubleshoot more and more problems, 3. The stacking cables were connected, one by one.
you will develop ‘troubleshooting insight’, which helps to When one of the switches was stacked, the Ping response
take the correct approach and locate the exact problem in the started slowing down—thus the faulty switch was isolated
shortest possible time. quickly. Proceeding further, to confirm the diagnosis, the
This article describes three real-life network faulty switch was replaced using an additional switch; but,
troubleshooting scenarios. These will definitely be interesting, unfortunately, the problem reappeared. So the fault was not
readily applicable and helpful during day-to-day network with the switch. Troubleshooting continued further:
diagnostics, especially for field engineers. 4. All Ethernet cables from the switch located in Step 3 were
removed.
Scenario 1: The Internet is not working 5. One cable at a time was plugged – till the problem appeared.
The network setup had approximately 75 computer systems 6. The computer system/device (which had a faulty Ethernet
spread across four floors in one building. The server room card!) with a slow Internet speed was isolated.
was located on the second floor, which housed the networking
rack, the firewall, the router for Internet connectivity and the Scenario 2: Slow Internet speed
servers. Cabling was structured with patch panels in the rack The set-up had 10 computer systems connected to the Internet
and information outlets at the user end. Cables and passive using the GNU-based IPCop firewall via a DSL connection.
network components were of a reputed brand. The network Discussions with the systems administrator revealed that the
installation was approximately four years old. A total of LAN speed was perfect; however, the Internet speed was very
six 10/100MBps unmanaged Ethernet switches were used. slow. Trials had already been conducted to bypass the firewall by
Out of them, one switch connected all the servers and the connecting one laptop directly to the DSL connection. Here, the
remaining connected systems were located on various floors. Internet speed available for one PC was satisfactory.
Site inspection revealed that the cabling was done as per the The discussions clearly revealed that the issue arose only when
industry’s best practices—with numbering at both ends, cable the office computer systems were trying to access the Internet. So,
bend radius guidelines being followed, and patch cable being the following steps were taken to isolate the problem:
used at both the ends. (a) The firewall was the first suspect – a firewall installed on
Detailed discussions with the administrator revealed a very a PC, and that too, with GNU? It must be the culprit! But
interesting problem. First, the Internet stops functioning, then bypassing it did not resolve the problem. Internet speed
the network goes on becoming slower and slower, and finally, continued to be slow.
it comes to a complete halt. Even local copying of files and (b) Next, the possibility of a virus was explored.
accessing computer systems becomes impossible. The problem (c) To capture complete network traffic, the Ethernet switch
is random in nature and has developed gradually. Rebooting was replaced with an Ethernet hub (remember that
Table 1: TCP/IP layers, their functions and corresponding OSI layers
TCP/IP layers Function Corresponding OSI layer(s)
Application layer Interacts with actual applications such as http, ftp, etc. Application + presentation + session
Transport layer Defines TCP/UDP protocols Transport
Internet layer Understands IP addresses Network
Network access layer Incorporates media and MAC addresses Physical + data link

76  |  October 2014  |  OPEN SOURCE For You  |  www.OpenSourceForU.com


How To Admin

old device which was used in the


1980s?). And traffic was captured
using a Wireshark system connected
to one port on the Ethernet hub.
(d) This hit the jackpot (see Figure 1)
revealing interesting malware on
various computer systems. (Figure
1 shows only one malware, though
there were many more, which I
unfortunately could not capture.)
(e) Googling these links revealed a Figure 1: Malware in the capture
known malware (see Figure 2). IPv6 traffic in the network measuring almost 77 per
(f) Anti-virus and anti-spyware software were run on the cent of the total traffic, even though the network was
systems to clear it of malware. configured for IPv4. So, it appeared that the problem was
(g) Firewall black lists were updated to block these links. located—protocol IPv6 was disabled from all the systems
Thus, removing malware solved the issue. in the belief that there could be an unknown malware that
was using IPv6 to spread! But, again, there was no luck
Scenario 3: A slow network and systems here too. The problem persisted.
disconnect from it intermittently Wireshark Statistics menu: Here, let us take a small
The described problem was that any of the computer systems break to understand an interesting Wireshark menu – Protocol
connected to the network would disconnect from the LAN Hierarchy – which is available under Statistics. This could
intermittently. This would also lead to the complete network be used to arrive at high IPv6 bandwidth utilisation while
coming to a halt.
The in-house administrator had tried to diagnose the
problem for several days. Discussions revealed several
interesting facts. The installation had two 24-port Gigabit
unmanaged Ethernet switches in two rooms connected by a
crossover cable. LAN traffic was heavy with several large files
being copied or moved between various systems every now
and then. Each switch connected to 20 computer systems. The
problem was first observed after half the older computers had
been replaced with new systems. Network cabling and Ethernet
switches were not changed or even touched during the upgrade.
Operating system security updates were applied to the new
computer systems. Rebooting the Ethernet switches would start
the network, but the problem would reappear randomly.
The steps taken for troubleshooting were as follows:
• The first step was to check the operating systems – the
problem was reported after the change (of computers).
So, the latest drivers of the motherboard, particularly the
Network Interface Card (NIC) were downloaded and
applied. On various forums there were complaints about
similar problems for a specific model of NICs (which were
onboard for the new systems) supporting EEE (Energy
Efficient Ethernet). If connected to switches not supporting
EEE, random network disconnections were reported. So,
EEE features were disabled – it was expected that the
problem would be resolved, but that didn’t happen.
• Anti-virus signatures of all the systems were updated, and
the systems scanned for viruses. Some of the systems had
viruses which were removed, but the problem reappeared.
• Switches were replaced using the hub, turn by turn.
Wireshark was deployed to capture network traffic for
analysis. To our utmost surprise, there was very heavy Figure 2: Malware identified (Screenshot from Sophosh.com website)

www.OpenSourceForU.com  |  OPEN SOURCE For You  |  October 2014  |  77


Admin How To

troubleshooting scenarios such as the current


one. Protocol Hierarchy analyses captured
files using various parameters beginning with
Ethernet – IPv4 / IPv6, and drilling down TCP
and UDP to corresponding details—such as
http, ssl, pop for TCP and DNS, etc, for UDP.
These files are presented as % bytes used by
these protocols with respect to total traffic.
Look at Figure 3 for an interesting capture
showing too much IPv6 traffic. (Later, it
was concluded that the traffic was LAN file Figure 4: RST and ACK packets
transfer traffic.)
The traffic was further analysed to isolate TCP Keep–
Alive, TCP Retransmission, RST–ACK and DUP–ACK Warning
packets, which generally signify problems. Systems found
Packets captured using the test scenarios described in
with these packets (faulty systems) were identified and this series of articles are capable of revealing sensitive
isolated from the network. The systems were also scanned for information such as login names and passwords. Using
viruses, and the infected systems were removed. However, ARP spoofing, in particular, will disturb the network
with no further luck here too, troubleshooting had to continue. temporarily. Make sure to use these techniques only in
a test environment. If at all you wish to use them in a
Look carefully at Figure 4. To isolate RST and ACK
live environment, do not forget to avail explicit written
traffic, the display filter tcp.flags == 0x0014 was used. permission before doing so.
This was really frustrating and additional time was wasted
with the trial and error process. Yet, the problem was still Looking back
unresolved, and customer anxiety was increasing day by day. Though packets indicating network issues were present in the
Going back to the basics, it occurred to us that the issue capture, their percentage compared with good packets was just
could be with the NIC drivers or operating systems, primarily too low – which could not have affected the network to the
due to the fact that the problem started only after the new point of bringing it down completely. It was easy to conclude
computer systems were installed. So, a few old systems that from the Wireshark capture that the top down approach starting
were using the same NICs were checked, which revealed a from the operating system level and going down towards the
driver version that was different than the OS default drivers physical layer should have been adhered to before going ahead
and the current drivers available on the vendor’s website with removing the supposed ‘faulty systems’ from the network.
(which were applied in Step 1). Matching the old drivers on The end user was appreciated for his patience and
all the systems finally solved the issue. confidence in the troubleshooter.
For troubleshooters, ‘slow network’ issues are indeed a
challenging task. Apart from resourceful troubleshooters with
adequate tools, techniques, experience and insight, successful
troubleshooting also requires a lot of patience from the
engineer and the customer as well!

By: Rajesh Deodhar


The author has been an IS auditor and network security consultant
for the last two decades. He is a BE in industrial electronics, and
holds CISA, CISSP and DCL certifications. Please feel free to
contact him on rajesh at omegasystems dot co dot in
Figure 3: Protocol Hierarchy

The complete magazine on open source Your favourite Magazine on Open


Source is now on the Web, too.

OpenSourceForU.com
Follow us on Twitter@LinuxForYou

78  |  October 2014  |  OPEN SOURCE For You  |  www.OpenSourceForU.com


Let's Try Admin

Use
for an Extraordinary Surveying

LimeSurvey is a premier online, open source tool that


is downloaded thousands of times every week by
individuals, companies and universities to conduct
various types of surveys.

L
imeSurvey helps to set up surveys or questionnaires
with a click of the mouse and the minimum of
technical knowledge. According to Wikipedia,
LimeSurvey “…is a Web server-based software. It enables
users to develop and publish online surveys and collect
responses, without doing any programming.” It is written
in PHP and requires a database (MySQL, PostgreSQL,
etc) to function. LimeSurvey was initiated by Carsten
Schmitz, and is now available in its stable release 2.05
under the GNU General Public License. MS SQL is required. To set up a basic working environment,
I would recommend installing the WAMP server on your
Striking features machine, which is a complete development environment for
LimeSurvey offers exceptionally good features. As a Web applications and hence includes Web server (Apache)
surveying tool, it has everything that you’ll ever want. and database applications (MySQL).
Here are some of the features provided by LimeSurvey: You can download WAMP from
ƒƒ Multiple surveys at a time http://sourceforge.net/projects/wampserver/files/
ƒƒ No limit to the number of questions WampServer%202/WampServer%202.0/WampServer2.0i.exe/
ƒƒ Grouping of questions download
ƒƒ 20+ types of questions Make sure that after the installation of the WAMP server,
ƒƒ User profile management you have the directory c:\wamp and the access to it. I am
ƒƒ Unlimited participants assuming that you have a working WAMP server installed.
ƒƒ Support for 70+ languages
ƒƒ Token-based survey participation Installation
ƒƒ Support for printer-friendly version of surveys ƒƒ Download the latest stable release of the LimeSurvey
ƒƒ The capability to add images in surveys from the following link: http://www.limesurvey.org/en/
ƒƒ Multiple themes and support for WYSIWYG HTML stable-release
Editor ƒƒ Unzip the contents of the .zip file you downloaded, to the
folder C:\wamp\www\LimeSurvey.
Pre-requisites ƒƒ The installation part is done. Just start the WAMP server
LimeSurvey is compatible with Linux-based systems (Start menu->start wampserver).
as well as with Microsoft Windows platforms. For this ƒƒ Using any Web browser, go to http://localhost/ and
article, I will demonstrate a Windows installation to LimeSurvey should be listed under Your Projects.
keep things simple. LimeSurvey is server-based software On its first run, LimeSurvey needs certain parameters to
and hence requires a Web server to run on the hosting be set up. Follow the steps shown below:
machine. Also, a database like MySQL, PostgreSQL or ƒƒ Go to http://localhost/LimeSurvey, which will open up

www.OpenSourceForU.com  |  OPEN SOURCE For You  |  OCTOBER 2014  |  79


Admin Let's Try

the questions under certain categories. Each question group must


contain at least one question.
It gives you a choice of more than 20 question types. To
name a few:
ƒƒ List (Dropdown)
ƒƒ List (radio)
ƒƒ Arrays
ƒƒ Files
ƒƒ Ranking
ƒƒ Text display
ƒƒ Multiple choices (check boxes) and many others.
Figure 1: Wamp installation For questions like List and Multiple choice, you need
to provide options that are referred to as sub-questions in
LimeSurvey. It also provides you a way to add Other options,
which is often required while making surveys.

Managing conditions
LimeSurvey is capable of arranging dynamic or intelligent
surveys. Conditions are used to determine whether a question
will show up or not. Every question can be made to appear
when it satisfies all its prior conditions.

Exporting responses
LimeSurvey allows the administrator to get responses in one
place by providing support for exporting the responses in
formats that those in the industry are familiar with. Responses
of LimeSurvey can be exported in the following formats:
Figure 2: Preinstallation check ƒƒ CSV
ƒƒ Microsoft Excel sheets
a welcome screen. Choose the language you want to ƒƒ PDF
continue in and click Start Installation. ƒƒ HTML
ƒƒ On clicking ‘Accept’ in relation to the terms of the GNU ƒƒ Microsoft Word documents
General Public License, a pre-installation check will be
performed. This should be all green if the WAMP server Analysis of responses
was installed successfully. If the Next button appears, LimeSurvey also provides ways of analysing all your responses
it means you have met the requirements; otherwise, and viewing graphs. It allows users to see which options have
please check the manual of LimeSurvey (http://manual. been selected, and by what percentage of the respondents.
limesurvey.org/Installation). These analytics can help the organiser of the survey in various
ƒƒ In the database settings, most of
the fields will be filled by default.
Just provide a valid database name
(e.g., survey00, questionnaire, etc).
ƒƒ After this, an administration
panel will come up. Just fill in
the desired settings and continue.

Note: If you don’t have any


prior experience with MySQL,
just keep the fields for ‘Database
User: root’ and ‘password’ blank.

Question groups and types


LimeSurvey provides you an easy Figure 3: Managing conditions
way to manage questions, by grouping Continued on page no 83...

80  |  OCTOBER 2014  |  OPEN SOURCE For You  |  www.OpenSourceForU.com


Insight Admin

Make Your Own PBX with Asterisk


A Collage of Multiple Hardware Equipment
Asterisk is a software
switching platform,
capable of running on
standardised PC hardware
with accessories to connect
to various telecom networks.
In this second article in the
series, the author describes
various kinds of hardware
and accessories that are
needed to connect to
different kinds of networks.

protocol, which uses less bandwidth and has better jitter


buffer control to improve the audio quality. When starting,
the phones boot themselves and register with the configured
server and from then on, they can receive or make calls. The
phones are also capable of registering with multiple servers,
so that in redundancy scenarios, they can switch over to the
redundancy server with ease.

Headsets turn PCs into VoIP phones


Free software like X-lite/Eyebeam or open source software

T
o understand and use the full power of Asterisk, we like Blink can be downloaded and installed on a desktop. The
need to have a good understanding of the possible GUI resembles a dial pad, and with the help of a headset with
hardware accessories involved. The objective of this a microphone, the desktop can be turned into a phone. You
article is to introduce you to different kinds of hardware in the may also use the microphone and speaker of the desktop or
Asterisk world. laptop. After starting the software, it registers itself with the
Nowadays, any standard desktop or server comes with IP Asterisk PBX and starts receiving as well as making calls.
connectivity. So, if we are connecting IP phones to each other
through the PBX, we need not use any additional hardware. Smartphones as VoIP phones
However, we also need to connect to landlines, mobile phones, VoIP clients, available on smartphones, can connect to the
etc. For this, there is hardware to connect to a PSTN network or PBX server over Wi-Fi and function like any other phone.
a GSM network. Let us examine these devices, individually. One open source VoIP smartphone is the CSipClient,
which can be downloaded freely from the Google Android
VoIP phones Play Store. This client opens up innumerable application
VoIP phones are directly connected to the server over a LAN. possibilities, as follows.
The dominating protocol standard is SIP (Session Initiation Phoneless desktop: Users need not clutter their desks
Protocol). Some phones support IAX, a proprietary Asterisk with standard phones. Their mobile phones can serve as an

www.OpenSourceForU.com  |  OPEN SOURCE For You  |  OCTOBER 2014  |  81


Admin Insight

extension to the PBX. Outside the office, these can be normal only PRIs are used in the corporate scenario, and BRI is non-
GSM phones; inside the office, they turn into dual phones, existent, for all practical purposes.
which can also act as extensions. The PRI card can be inserted into the server PCI or PCIe
Roaming extension: Doctors roaming around hospitals, slot, and can be configured as NT (Network Terminator
work-site supervisors, hotel staff, hotel room guests, etc, are or trunk side equipment) or TE (Terminal Equipment or
rarely found at their desktops or in their rooms. With Wi-Fi subscriber side equipment). A PRI connection can have
technology, they are always logged into the IP PBX and are, one pilot number and multiple subscriber numbers or DIDs
therefore, reachable. (Direct Inward Dialling), typically 100.
Cost savings: The user is always logged into the PBX and
therefore can route all the calls through the PBX, which could VoIP GSM gateway or card
be cheaper, especially when the volume of calls is high. The mobile network, specially the GSM mobile network, is
the most popular and widespread network nowadays. The
FX or ‘foreign exchange’ GSM gateway or card makes it possible to connect Asterisk
FXO or FXS are used to denote various connections in directly to this network. This equipment resembles a mobile
analogue technology (or POTS – Plain Old Telephone phone, where a SIM card can be inserted, and comes in 1, 2
System), which is the most common SOHO (Small Office or 4 ports. The GSM network can also be used as a backup for
Home Office) technology prevalent in India today. FX stands the POTS or ISDN lines.
for Foreign eXchange. FXO (Foreign eXchange Office) is For large density connectivity, VoIP GSM gateways are
the line which connects to the local telecom switch and FXS suitable, which come in 8, 16 and 32 ports.
(Foreign eXchange Subscriber) connects to the phones or
other end user devices like fax machines. Echo cancellation hardware
An echo is the phenomenon by which sound is repeated,
VoIP FXS gateway or FXS card which in turn affects the clarity of the sound. Asterisk has
Analogue telephones are the cheapest user equipment built-in software routines to combat this problem. In cases
available, with prices starting as low as ` 300 compared to where the software routines are not effective, DSP-based
a VoIP telephone starting at ` 3000. An FXS gateway/card hardware is available for analogue as well as PRI hardware.
connects an analogue phone to the Asterisk server. Most of Most of them are ‘piggy back’ modules, which have to be
the interface hardware comes in two forms, i.e., PCI/PCIe plugged on to the existing boards.
cards, which can be inserted into the server or external
standalone gateways connected to the server over IP. These Voice logger
devices can have multiple ports—the common ones are Conversations can be logged within Asterisk without any
FXS cards with up to 16 ports or gateways with up to 48 additional device. A command in dialplan is enough to
ports. For a larger number of ports, it is advisable to use activate the voice logging feature in Asterisk for calls passing
multiple gateways. through the Asterisk equipment.
Asterisk can also operate as a voice logger system for other
VoIP FXO gateways or cards systems in an active or passive mode. In both cases, the line to
Analogue trunks are the most common trunk connection be tapped has to loop through the voice logger system. In the
available for PBX equipment to connect to the outside world. case of active voice loggers, interface cards with double ports
With the help of a VoIP FXO gateway or card, one can of the interfaces to be tapped are required, i.e., to tap one PRI,
connect the Asterisk equipment to the PSTN world. Their we need a 2-port PRI card. The line to be tapped is connected
dimensions or capabilities are given as 1-, 2-, 4-, 16-port, etc. to the voice logger system and the destination system also.
When a call comes, the connection is established to the voice
VoIP PRI gateway or card logger system, and then again a back-to-back connection is
ISDN (Integrated Services Digital Network), which is purely generated to the destination system. The calls are recorded in a
a digital network, is the next generation of telecommunication similar manner in an Asterisk system using dialplan.
networks, a step up from analogue networks. PRI (Primary In case of passive voice loggers, a passive interface
Rate Interface) and BRI (Basic Rate Interface) are the two card with double the number of interfaces to be tapped is
common connection types available. PRI is a 4-wire interface connected. The main difference is that there is no connection
to the customer, and can carry 30 B channels (voice channels) established to the voice logger system. The voice logger
and one D channel (control channel) in an E1 configuration, system passively taps the required information and stores it.
the most common in the Indian scenario. There is also a T1
configuration with 24 B channels and one D channel, which is Redundancy hardware
more prevalent in the US. The BRI with two B-channels and Redundancy hardware can be created easily by having a
one D-channel is meant for SOHO use. In India, generally mirror copy of the existing server. In case of a crisis, when

82  |  OCTOBER 2014  |  OPEN SOURCE For You  |  www.OpenSourceForU.com


Insight Admin

the primary server crashes, the situation is detected by systems also allow two-way communication, by allowing
noticing missing live messages between the systems; and then the receiver also to pass back messages.
redundancy hardware can take over the operations. The IP SIP-based paging systems are available, which will accept
phones and other IP-based equipment can be easily switched the call as soon as the call comes, amplify the voice and
over to the new server. A complicated case would involve output it through speakers. Asterisk supports creating multiple
switching over the physical layers of interfaces like FXO and groups of paging devices and also incorporates the two-way
FXS, which are directly connected to the server, for which messaging option.
physical switchover hardware is available.
Answering the front doorbell
Physical layer switchover hardware A visitor might ring the house bell, and one can pick up an
Manufacturers provide physical hardware where, for internal phone to communicate with him or her. There are a
example, the FXO line is connected. The output is few SIP door phones available. Else, it is possible to connect
duplicated and connected to the primary and secondary an analogue phone with an FXO card to Asterisk.
servers. The control signals to the device can come from We have now explored quite a lot of Asterisk hardware,
the primary and secondary servers through the USB port or which enhances its capabilities in the IP world by interfacing
the IP port. As soon as a critical situation is discovered, the with other telecom networks, and carrying out multiple tasks.
relays are activated and the physical connection is changed The power of applications on a simple switching platform is
to the secondary server. sometimes magical.

Paging systems By: Devasia Kurian


Paging systems could be overhead announcement
speakers, which switch on, when dialled, or a group The author is the founder and CEO of *astTECS, an Asterisk
‘software-based’ company providing IP PBX, call centre diallers,
of phones which automatically switch on the speaker etc. He can be contacted at d.kurian@asttecs.com.
when dialled from a particular extension. Newer paging

...Continued from page no 80...


tokens. These tokens can be generated and distributed via
e-mail to only the prospective group being surveyed.

Managing user groups


LimeSurvey can be set up on a server and can be accessed by
multiple people simultaneously. This helps organisations to create
a central hub for managing surveys. All users can access content
and manage their surveys. This means that a technical manager can
use the LimeSurvey for gathering a client’s requirements, whereas
the same server can be used by the HR department to deploy a
survey asking employees their preferences on a particular subject.

Exporting and importing surveys


LimeSurvey focuses on re-usability and hence provides an
easy way of exporting surveys. Exporting and importing
surveys means saving a complete survey in a file and storing
Figure 4: Exporting responses it, such that it can be used later. LimeSurvey exports surveys
ways. For example, if you need to distribute chocolates, you in the form of data-sets, which can be used when required.
can ask people to choose between KitKat and Galaxy and based LimeSurvey gives you complete flexibility in creating
on the percentages, buy the right number of each brand. and managing surveys. Right from adding questions to
releasing tokens, everything can be customised as per your
Token management requirements. Also, LimeSurvey allows you to add multiple
In an organisation, one obviously doesn’t want everyone themes by supporting plug-ins and survey themes.
to have access to every survey. For instance, the survey
meant for the HR team may have nothing to do with the By: Manish Jain
software developers in the firm. LimeSurvey provides an The author is an open source enthusiast who always seeks
easy approach, called the ‘token system’, which limits the open ways to get things done. He can be reached at manish.
msiclub@gmail.com.
participation in surveys to only those who submit the proper

www.OpenSourceForU.com  |  OPEN SOURCE For You  |  OCTOBER 2014  |  83


For U & Me CaseStudy

Sheela Foam Turns to Zimbra’s


Advanced Collaboration Platform
“We highly recommend Zimbra to businesses who want to reduce costs without compromising
on quality,” says Pertisth Mankotia, head, IT, at Sheela Foam Private Limited

Sheela Foam
Founded in 1972, Sheela Foam Pvt Ltd is India’s largest
mattress manufacturer and is ranked among the top five
manufacturers of Slabstock PU foam in South East Asia.
The firm has 11 manufacturing units using state-of-the- INDUSTRY CORPORATE HEADQUARTERS
art technology across India and five manufacturing units Manufacturing Ghaziabad, India
in Australia. Sheela Foam caters to a wide spectrum of EMPLOYEES PRODUCT
customers through an efficient distribution network of over 100 1,500 + Zimbra Collaboration
distributors and 4,500 dealers. Its products include Sleepwell in
KEY BENEFITS
India and Joyce in Australia. A combination of manufacturing
• Powerful user experience
excellence and a wide distribution network has helped it • Ease of management
acquire over 40 per cent of the Indian PU foam market. • Flexible licensing
• Cost-effective
The opportunity
Because Sheela Foam operates over a distributed The Zimbra team worked very closely with the Sheela Foam
geography and has a widespread network, the team to ensure that the transition was extremely easy. “The team
communication within the distribution channel had to be did a great job by providing us with all the support we needed
really quick for the network to work efficiently. The email during the transition. The solution has turned out to be a perfect
solution was an area of concern for Sheela Foam’s IT fit for our requirements, with the numerous benefits it offers us
department. The team was using a combination of email in comparison to our earlier set-up,” said Mankotia.
systems, including Microsoft Exchange. As the business
grew, the number of users increased as well, and Sheela The results
Foam began facing issues related to the burgeoning cost of Messaging and collaboration made easy: The feature-
Microsoft Exchange user licences. Sheela Foam’s IT team, rich browser-based experience of Zimbra allows users to
lead by Pertisth Mankotia, was looking at consolidating stay connected securely, anywhere, and to any device or
the email systems into a single email system that was platform. The briefcase feature also allows users to share
fast, efficient, cost-effective, user-friendly and scalable. large files. Zimlets gives users the ability to integrate third-
In addition, the team required the email solution to be party applications into the email client, thereby enhancing
compatible with a wide range of operating systems. productivity and the user experience.
Simple licensing: Zimbra’s uncomplicated licensing has
The solution allowed Sheela Foam to scale up its email system to include more
The IT team evaluated various email solutions, including users with the Starter or Professional editions. This helped the
Zimbra. The team members were very impressed with the company to lower the licensing costs by almost a tenth of what it
flexibility, scalability and economy Zimbra offered. Its simple would have otherwise spent on Microsoft Exchange licences.
licensing (based on mailboxes) offered additional flexibility, A lower total cost of ownership: Sheela Foam was able
compared to the existing set-up. to drastically reduce costs on licensing, hardware requirements
The Zimbra deployment was done in less than three and in-built features, such as storage tiering (HSM), file
days, during which 1,100 mailboxes were migrated to it. As sharing (briefcase) and backup tools, which would have
Zimbra is available in multiple editions (Starter, Standard and involved additional costs had the IT team chosen to go with
Professional), Sheela Foam was able to offer the Standard other competitive solutions, including Microsoft Exchange.
edition to non-power users and the Professional edition to Ease of migration: As Zimbra offers native migration tools,
power users. This helped Sheela Foam lower licensing costs Sheela Foam did not require a third-party tool for migrating its
further, and offer mailboxes to their dealers and distributors users from Microsoft Exchange to Zimbra.
as well. The IT team also leveraged Zimbra’s collaboration
features, such as file sharing, scheduling, instant messaging For more information, trial or demo please contact sales at
+91 20 6730 4731 or email india.marketing@zimbra.com
and the mobile Web client.

84  |  october 2014  | OPEN SOURCE For You  |  www.OpenSourceForU.com


Let's Try For U & Me

Eleven Features of Vim


That You Probably Aren't Using

For developers and other users of


Vim, here’s a list of useful features and
commands of Vim editor for same.

I
f you have a basic knowledge of Vim and are interested in hitting ‘u’ will undo the last change.
exploring some advanced ways to use it, but think you may be
missing some essential features of the GUI-based editor, this 4. The % key
article is for you. This is a really awesome feature for programmers. The % key
can be used for the following:
1. Word suggestion ƒƒ To jump to a matching opening or closing parenthesis,
Sometimes, when writing programs, you do need suggestions of square bracket or a curly brace: ( [ { }] )
variable/function names from the IDE. This is possible with Vim. In ƒƒ To jump to the start or end of a C-style comment: /* */.
insert mode, type the first couple of characters of a word, then press: ƒƒ To jump to a matching C/C++ pre-processor conditional:
ƒƒ Ctrl-N to insert the next matching word #if, #ifdef, #else, #elif, #endif.
ƒƒ Ctrl-P to insert the previous matching word In command mode, press ‘%’ to find the matching brace/
For a programmer, this is very useful when entering the names comment that is under the cursor.
of variables in a program.
Incidentally, if you really want CTRL-P or CTRL-N to scan a 5. Repeat the previous action
dictionary file, then try :set dictionary=/usr/. Multiple dictionaries The ‘.’ command repeats the last change made in normal
can be used as well. mode. For example, if you press dw to delete a word, you can
then press '.' to delete another word.
2. Find the next or previous occurrence of the word
under the cursor 6. Open multiple windows in Vim
Sometimes, it’s useful to find the next or previous occurrence of a It is a basic requirement for any programmer to open multiple
word in your file. This is possible with Vim. In command mode, hit files concurrently. Vim supports this too.
‘#’ or ‘*’ to find the previous or next occurrence of the word that is Vim has the ability to split its window into multiple panes
under the cursor. using the :sp or :vsp commands.
To open a different file in a newly split window, you can
3. Undo recent changes specify the filename as part of the command. For a horizontal split,
To undo changes, the ‘u’ command is used. In command mode, use :sp <filename> and for a vertical split, use :vsp <filename>.

www.OpenSourceForU.com  | OPEN SOURCE For You  |  Soctober 2014  |  85


For U & Me Let's Try

Figure 1: Completes any word


Figure 3: Vertical split

Figure 4: Execute shell commands without closing Vim

9. Open a file under the cursor


Often, a file contains the name of a second file, and you would
like to open that second file. Here, the ‘gf’ command can be of
great help. On using it, Vim will recognise the file name and
find the same file name in the path. When the cursor is on a local
variable or function, this command will jump to its declaration.
To return to the previous file/cursor location, use CTRL+o.
Figure 2: Horizontal split
10. Execute the terminal command from Vim
To move the cursor from one window to another, use While using Vim, you sometimes feel like you need to close the
TRL+w CTRL+w in normal mode. This will change the active file (Vim) and execute commands in a terminal. So let me tell you
file in a round robin manner. CTRL+w <arrow key> is also how to execute commands inside Vim without closing the file.
used to move the cursor from one window to another. Let’s assume you are inside the Vim editor and it has
opened somefile.
7. Open the same file in a split window Press ESC and type :! followed by the command. The
Sometimes, there is a need to open the same file in another output of the command will be listed in the terminal and after
split window. To do this in the normal mode, use CTRL+W pressing Enter, you will be redirected to the text editor.
v and CTRL+w s to open the same file in a vertical and Figure 4 shows the syntax for executing the ls command
horizontal split of the file that is open. on the shell through Vim.

8. Set abbreviations 11. View files in hex mode


Abbreviations are just short cuts that you type, which expand Many firmware developers need to view a file in hex mode.
to the full, normal version of themselves. Vim provides the Vim comes with a great feature to switch to hex mode when
flexibility to define new abbreviations. In normal mode, use editing a file. To enter into hex mode, open a file in vi as
the command ab to set new abbreviations. usual, hit Escape and type :%!xxd to switch to hex mode.
To define a new abbreviation, type: To come out of hex mode, hit Escape again and type
:%!xxd -r
:ab def #define
By: Bhargav Shah
When you type the abbreviation in Vim, as soon as you The author is a firmware developer at eInfochips, Ahmedabad. He is
hit the space bar, it will be expanded to the full text form. So, responsible for developing bare metal firmware, RTOS porting and
by typing ‘def’ in the file, Vim will expand this to ‘#define’, Linux device driver development. You can find his tutorials at http://
kerneltweaks.wordpress.com/ and https://ebonerobot.wordpress.com/.
which can make a programmer's life easier.

86  |  october 2014  | OPEN SOURCE For You  |  www.OpenSourceForU.com


Let’s Try For U & Me

Manage Your Finances with Maxima


This 22nd article in the series on mathematics through open source takes the reader into
personal financial management. The author demonstrates how personal financial computations
can be done easily by using Maxima.

I
n today’s credit-oriented world, loans, EMIs, the principal, norm when calculating interest rates.
interest rates, savings, etc, are commonly used terms.
How well do we really understand these terms, or for $ maxima -q
that matter, are we able to accurately compute the figures (%i1) load(finance);
related to such matters? Do we just accept what the other (%o1) /usr/share/maxima/5.24.0/share/contrib/finance/finance.
party has provided us? Or should one go into the details to mac
first understand and then double-check the numbers being (%i2) days360(2014, 1, 1, 2014, 10, 1);
presented to us? This is where Maxima’s finance package (%o2) 270
comes to your rescue; you can actually verify figures without (%i3) days360(2014, 1, 1, 2014, 12, 31);
much involvement in the computational details. This article is (%o3) 360
going to walk you through the details of this package. (%i4) days360(2014, 1, 1, 2014, 3, 1);
(%o4) 60
Basic operations (%i5) days360(2014, 1, 1, 2015, 1, 1);
To be able to use the finance package of Maxima, the first (%o5) 360
thing to do, after getting the Maxima prompt, is to load (%i6) quit();
the finance package, using load(). Then go ahead to do the
various computations. days360() is the simplest function to Note that days360() takes ‘from’ and ‘to’ dates, each as a
give the number of days between two dates, assuming there triplet of the year, month and date.
are 360 days per year and 30 days per month – this is the One common computation that we often deal with is the
final amount we would get after applying a particular rate
of compound interest on a particular principal amount –
just use fv(<rate>, <principal>, <period>) for
computing the future value of the <principal>, at
the compound interest <rate> , after a certain
<period>. As an example, what would be
the future value of investing `10,000 for
10 years at the compound interest rate of
15 per cent per year – just call fv(0.15,
10000, 10);

www.OpenSourceForU.com  |  OPEN SOURCE For You  |  October 2014  |  87


For U & Me Let’s Try
$ maxima -q (equated yearly instalment)
(%i1) load(finance)$ /* $ to suppress its output */ What is this EYI? We were supposed to talk only about
(%i2) fv(0.15, 10000, 10); EMI, right? Okay, in that case, we need to convert the rate
(%o2) 40455.57735707907 of interest and the period, in terms of months. So, we need
to divide the per annum rate of interest by 12 to get what it
If you are interested in how exactly this is calculated, or amounts to per month, and multiply the number of years by
what the formula is, Maxima is fun to play around with. Just 12 to get that in the number of months. That is exactly what
use some symbols, instead of actual numbers: the second example below shows. Note that it is 60 EMIs to
be paid out over the period of five years.
(%i3) string(fv(r, p, n));
(%o3) p*(r+1)^n $ maxima -q
(%i4) quit(); (%i1) load(finance)$
(%i2) amortization(0.0925, 2000000, 5)$
And, there you go. p*(r+1)^n is the future value when “n” “Balance” “Interest” “Amortization” “Payment”
investing ‘p’ amount for ‘n’ periods at the compounded 0.000 2000000.000 0.000 0.000 0.000
interest rate of ‘r’ per period. 1.000 1667475.420 185000.000 332524.580 517524.580
How about doing an inverse computation? Let’s suppose, 2.000 1304192.317 154241.476 363283.103 517524.580
I want to get `1,000,000 after five years from my investment 3.000 907305.527 120637.789 396886.790 517524.580
today at the interest rate of 10.75 per cent. Now, for that, how 4.000 473706.709 83925.761 433598.818 517524.580
much should I invest today? Don’t scratch your head, just call 5.000 0.000 43817.871 473706.709 517524.580
pv(<rate>, <future_val>, <period>);
(%i3) amortization(0.0925/12, 2000000, 5*12)$
(%i1) load(finance)$ “n” “Balance” “Interest” “Amortization” “Payment”
(%i2) pv(0.1075, 1000000, 5); 0.000 2000000.000 0.000 0.000 0.000
(%o2) 600179.7323625274 1.000 1973656.870 15416.667 26343.130 41759.797
(%i3) fv(0.1075, 600180, 5); 2.000 1947110.679 15213.605 26546.192 41759.797
(%o3) 1000000.445928875 3.000 1920359.860 15008.978 26750.818 41759.797
(%i4) quit(); 4.000 1893402.837 14802.774 26957.023 41759.797
5.000 1866238.021 14594.980 27164.816 41759.797
So you need to invest `600,180 to get a value of 6.000 1838863.809 14385.585 27374.212 41759.797
`1,000,000 after five years at a rate of interest of 10.75 per 7.000 1811278.588 14174.575 27585.221 41759.797
cent – that’s the check done above, using fv(). 8.000 1783480.730 13961.939 27797.857 41759.797
9.000 1755468.598 13747.664 28012.133 41759.797
Loans and EMIs 10.000 1727240.538 13531.737 28228.059 41759.797
Today, with access to easy credit, people plan on buying a 11.000 1698794.887 13314.146 28445.651 41759.797
house, a car, or even smaller items, with the thought, “Let’s 12.000 1670129.968 13094.877 28664.919 41759.797
buy it on loan and pay it off in EMIs (equated monthly 13.000 1641244.090 12873.919 28885.878 41759.797
instalments).” These terms would be familiar to most of you 14.000 1612135.550 12651.257 29108.540 41759.797
but how do you compute them? One assumes that there are 15.000 1582802.632 12426.878 29332.918 41759.797
some complicated formulae to do so, which is right. But, 16.000 1553243.605 12200.770 29559.026 41759.797
you don’t need to worry about any of them. Just instruct 17.000 1523456.728 11972.919 29786.877 41759.797
Maxima to give you the complete schedule for your loan, 18.000 1493440.244 11743.312 30016.484 41759.797
at a given rate of interest, for a given period of time, using 19.000 1463192.382 11511.935 30247.861 41759.797
amortization(). The first example below provides the schedule 20.000 1432711.360 11278.775 30481.022 41759.797
for a home loan of `2 million at an interest rate of 9.25 per 21.000 1401995.381 11043.817 30715.980 41759.797
cent per annum (p.a.) for five years. The various columns in 22.000 1371042.632 10807.048 30952.749 41759.797
the output schedule provide the following information: 23.000 1339851.289 10568.454 31191.343 41759.797
• n: instalment payment time – year, in the case of our example 24.000 1308419.513 10328.020 31431.776 41759.797
• Balance: principal + interest left over to be paid out, after 25.000 1276745.450 10085.734 31674.063 41759.797
the current instalment is paid out 26.000 1244827.233 9841.580 31918.217 41759.797
• Interest: interest part being paid out in the current instalment 27.000 1212662.979 9595.543 32164.253 41759.797
• Amortization: principal part being paid out in the current 28.000 1180250.793 9347.610 32412.186 41759.797
instalment 29.000 1147588.763 9097.767 32662.030 41759.797
• Payment: current instalment to be paid out, i.e., the EYI 30.000 1114674.963 8845.997 32913.800 41759.797

88  |  October 2014  |  OPEN SOURCE For You  |  www.OpenSourceForU.com


Let’s Try For U & Me
31.000 1081507.453 8592.286 33167.510 41759.797 0.000 100.000 0.000 0.000 0.000
32.000 1048084.276 8336.620 33423.177 41759.797 1.000 101.722 10.000 -1.722 8.278
33.000 1014403.463 8078.983 33680.814 41759.797 2.000 93.615 10.172 8.106 18.278
34.000 980463.026 7819.360 33940.437 41759.797 3.000 74.698 9.362 18.917 28.278
35.000 946260.965 7557.736 34202.061 41759.797 4.000 43.890 7.470 30.809 38.278
36.000 911795.264 7294.095 34465.702 41759.797 5.000 0.000 4.389 43.890 48.278
37.000 877063.889 7028.422 34731.375 41759.797
38.000 842064.793 6760.701 34999.096 41759.797 (%i4) geo_amortization(0.10, 0.05, 100, 5)$
39.000 806795.913 6490.916 35268.880 41759.797 “n” “Balance” “Interest” “Amortization” “Payment”
40.000 771255.168 6219.052 35540.745 41759.797 0.000 100.000 0.000 0.000 0.000
41.000 735440.463 5945.092 35814.705 41759.797 1.000 85.907 10.000 14.093 24.093
42.000 699349.687 5669.020 36090.776 41759.797 2.000 69.200 8.591 16.707 25.298
43.000 662980.711 5390.821 36368.976 41759.797 3.000 49.558 6.920 19.642 26.562
44.000 626331.390 5110.476 36649.320 41759.797 4.000 26.623 4.956 22.935 27.891
45.000 589399.565 4827.971 36931.825 41759.797 5.000 0.000 2.662 26.623 29.285
46.000 552183.057 4543.288 37216.508 41759.797
47.000 514679.671 4256.411 37503.386 41759.797 (%i5) quit();
48.000 476887.197 3967.322 37792.474 41759.797
49.000 438803.406 3676.005 38083.791 41759.797 %i2 has been provided for comparative analysis. %i3
50.000 400426.052 3382.443 38377.354 41759.797 shows the incremental payout with increments of `10 (the
51.000 361752.873 3086.617 38673.179 41759.797 second parameter of arit_amortization()). %i4 shows the
52.000 322781.588 2788.512 38971.285 41759.797 incremental payout with increments at the rate of 5 per cent
53.000 283509.900 2488.108 39271.689 41759.797 (the second parameter of geo_amortization()). Both these
54.000 243935.492 2185.389 39574.408 41759.797 computations could be done in decrements as well – just pass
55.000 204056.031 1880.336 39879.461 41759.797 the second parameter as negative.
56.000 163869.167 1572.932 40186.865 41759.797
57.000 123372.528 1263.158 40496.638 41759.797 Plan your savings
58.000 82563.728 950.997 40808.800 41759.797 Say, you have a savings account like the PPF (Public
59.000 41440.360 636.429 41123.368 41759.797 Provident Fund), giving you interest at a rate of 8 per cent
60.000 0.000 319.436 41440.360 41759.797 p.a., and at the end of five years, you want to have saved
`100,000. So, what should be your minimum yearly deposit
(%i4) quit(); into your account? It is not as simple as dividing by 5, as the
interest would be also added to your savings. saving() shows
If you want to be a little adventurous in your monthly you the complete schedule as follows:
payments, that is, instead of equal payments, you want to do
increasing payments, Maxima could help you with that as $ maxima -q
well. arit_amortization() and geo_amortization() are two such (%i1) load(finance)$
functions, which provide the schedule for increasing payments (%i2) saving(0.08 /* interest rate */, 100000 /* final savings */,
with fixed amount increments and fixed rate increments, 5 /* years */)$
respectively. Here’s a small demo of how it works: “n” “Balance” “Interest” “Payment”
0.000 0.000 0.000 0.000
$ maxima -q 1.000 17045.645 0.000 17045.645
(%i1) load(finance)$ 2.000 35454.943 1363.652 17045.645
(%i2) amortization(0.10, 100, 5)$ 3.000 55336.983 2836.395 17045.645
“n” “Balance” “Interest” “Amortization” “Payment” 4.000 76809.588 4426.959 17045.645
0.000 100.000 0.000 0.000 0.000 5.000 100000.000 6144.767 17045.645
1.000 83.620 10.000 16.380 26.380
2.000 65.603 8.362 18.01 26.380 And the minimum yearly deposit to be made is `17,046. The
3.000 45.783 6.560 19.819 26.380 ‘Balance’ and ‘Interest’ columns, respectively, tell you about the
4.000 23.982 4.578 21.801 26.380 balance and the interest accumulated in the corresponding year.
5.000 0.000 2.398 23.982 26.380 If you are only interested in knowing the minimum amount to
be deposited, you may just use the annuity_fv() function, which
(%i3) arit_amortization(0.10, 10, 100, 5)$ basically computes the annuity of `17,046 every year for five
“n” “Balance” “Interest” “Amortization” “Payment” years in order to have saved `100,000 after five years.

www.OpenSourceForU.com  |  OPEN SOURCE For You  |  October 2014  |  89


For U & Me Let’s Try
(%i3) annuity_fv(0.08, 100000, 5); using benefit_cost(). Here’s an example to demonstrate this,
(%o3) 17045.64545668365 assuming 18 per cent as the rate of interest:
(%i4) quit(); Project P1 (2 years): Yearly benefits (100, 200), yearly costs
(150, 50)
Project planning Project P2 (3 years): Yearly benefits (0, 200, 100), yearly
Finance management is a key element of planning any costs (100, 100, 0)
project, whether professional or personal. Assume a project Project P3 (4 years): Yearly benefits (0, 200, 200, 100), yearly
would take ‘n’ years, with given yearly expenses, and costs (100, 100, 50, 50)
say the available interest rate is ‘r’ p.a. Then, a common
question that every project manager needs to answer is: $ maxima -q
what is the net present value (NPV) of the project, which (%i1) load(finance)$
needs to be invested for the project. The answer to this basic (%i2) benefit_cost(0.18, [100, 200], [150, 50]);
question is, more often than not, one of the important factors (%o2) 1.400881057268722
for deciding whether or not to take up this project. Maxima (%i3) benefit_cost(0.18, [0, 200, 100], [100, 100, 0]);
provides npv() to compute the same. As an example, if a (%o3) 1.306173223448919
project needs `100, `200, `150 and `600 over four years, (%i4) benefit_cost(0.18, [0, 200, 200, 100], [100, 100, 50, 50]);
respectively, and the current interest rate is 7 per cent, what (%o4) 1.489492494361802
is the NPV? It would be `848 as shown below: (%i5) quit();

$ maxima -q And clearly, over the long run, the four-year project P3
(%i1) load(finance)$ has a better benefit-cost ratio. But if one is only looking
(%i2) npv(0.07, [100, 200, 150, 600]); for shorter term benefits, then you could go with project P1
(%o2) 848.3274983420189 as well.
(%i3) quit();

By: Anil Kumar Pugalia


Another common practice when choosing between various The
projects is to compute the benefit-to-cost ratio of the various
By:author
Anil is aKumar
gold medallist from NIT Warangal and IISc
Pugalia
Bengaluru. Mathematics and knowledge sharing are two of his
projects, and select the one with the best ratio. The benefit- many passions. Learn more about him at http://sysplay.in. He
can be reached at email@sarika-pugs.com.
to-cost ratio for a given interest rate <r> could be computed

90  |  October 2014  |  OPEN SOURCE For You  |  www.OpenSourceForU.com


Let's Try Open Gurus

MEAP MEAP!

OpenMEAP
Create Mobile Apps with Ease!
OpenMEAP is an open source HTML5 mobile application platform. It empowers
businesses and consumers with a little programming experience to create, manage, and
deploy mobile applications that can then be easily optimized for various devices such as
tablets, desktops, and smartphones.

L
et's understand the term MEAP before going into The MEAP approach is encouraged because organisations
further explanations on OpenMEAP. A mobile need the following mobile solutions:
enterprise application platform (MEAP) is a wide- ƒƒ Support for multiple mobile applications
ranging suite of products and services that enable the ƒƒ Support for multiple mobile operating systems (OS)
development of mobile applications across various platforms. ƒƒ Integration with multiple back-end data sources
The term MEAP was coined in a 2008 Gartner Magic OpenMEAP is an open source HTML5 mobile application
Quadrant report, which is a series of market research reports platform, which enables clients to easily create, manage and
published by Gartner Inc frequently. install mobile applications that are automatically optimised
MEAPs address the difficulties of developing mobile for almost every device. Organisations gain considerable
software by managing the user groups, as well as the range savings and advantages by using this flexible platform.
of devices and networks at the time of deployment and OpenMEAP is compatible with the Android, iOS and
throughout the mobile solution’s lifecycle. Unlike individual BlackBerry platforms. Currently, it is available only in
apps, a MEAP provides a widespread, long-term approach to English. It delivers productivity benefits like mobile data
deploying mobility. Cross-platform considerations are one access while maintaining a good amount of security and
of the main reasons for using MEAPs. Let us consider an Public Key Infrastructure compliance. It enables organisations
example in which an organisation uses a MEAP to develop of all sizes to proficiently develop, deliver and manage mobile
the mobile application and deploy it to a variety of mobile applications while using their existing Web development
devices such as smartphones, tablets and notebooks with no platform and resources. It provides flexibility to write the
changes to the underlying business logic. application in a preferred Web development environment

www.OpenSourceForU.com  |  OPEN SOURCE For You  |  OCTOBER 2014  |  91


Open Gurus Let's Try

using HTML5, CSS3 and JavaScript, and deploy OpenMEAP provides flexibility to use
it through the OpenMEAP interface. OpenMEAP is an integrated and
any HTML5 or CSS3 framework or
responsive design frameworks. It pro-
open sourcemobile technology vides freedom to use any mobile user
solution with less administrative
Features overhead; less need of upgrades
interface usch as browsers supporting
HTML5 and Css3. It alos provides free-
ƒƒ OpenMEAP is available with an open source that reduces management costs. dom to deploy OpenMEAP in the cloud,
licence, which allows all organisations to hosted or in onpremise environment
based on existing business strategy.
take an active role in ensuring the security
and quality of the product by providing
inputs in the development of various features. OpenMEAP avoids vendor lock-in
ƒƒ It can be used to enable existing teams to and open source code will allow to
modify features according to the Source code is available in public
create applications by using HTML 5, CSS3, business needs. Users can select in- domain hence there is better
and JavaScript for a device-agnostic solution tegrated development environments chance to ensure security claims by
of their own choice and they are not rigorous auditing.
or service offering. OpenMEAP mobile bound to use any specific IDE
clients remove the need for developing
mobile apps across various platforms such as
iOS, Android, Windows and BlackBerry. Figure 1: Benefits of OpenMEAP
ƒƒ It does not require any new ports to be opened
in the firewall. This allows the product to be implemented OpenMEAP is the flexibility to deploy it in the cloud
without creating unnecessary vulnerabilities. environment—either hosted or in an on-premise environment,
ƒƒ OpenMEAP offers end-to-end security, as it supports based on existing business strategies.
256 bits Advanced Encryption Standard (AES) and
Secure Socket Layer (SSL). It offers full Public Key OpenMEAP on the Amazon Web Services
Infrastructure (PKI) agreement and also provides an (AWS) public cloud
option to share it with the user’s existing Certificate The OpenMEAP 1.4.5 version is available in the AWS
Authority. Marketplace. It is available on Base Operating System Linux/
ƒƒ Its architecture is designed for high availability; UNIX and Amazon Linux 2012.03.3 as a 64-bit Amazon
applications developed and designed using proper best Machine Image (AMI). AMI is an encrypted machine image
practices can continue to function in a number of adverse of a specific virtual machine. It contains a base OS, and a set
situations, including network loss or power outages. of applications and services for achieving a specific purpose
ƒƒ The OpenMEAP admin interface manages application with a specific configuration. Amazon Web Services (AWS)
versions, device management, deployments and security is a public cloud service provider that provides a computing
policies. Administrators can also design a security profile environment for running instances of an AMI on a pay-as-
that is appropriate for the implementation. It allows users you-go basis. Amazon EC2 and Amazon EBS services are
to build, manage, test and install mobile applications. required to run open source OpenMEAP. There are multiple
ƒƒ OpenMEAP supports simple object access protocol OpenMEAP bundles available in the AWS Marketplace
and Web services that allow access to other systems or such as OpenMEAP - Small Business Support Bundle
services from the mobile application. [RedHat and Amazon Linux]; OpenMEAP - Enterprise
Support Bundle [Amazon Linux and Red Hat]; OpenMEAP
OpenMEAP installation - Developer Support Bundle [Amazon Linux and Red Hat];
Download OpenMEAP installer from http://www.openmeap. and OpenMEAP - Mobile Enterprise Application Platform
com/products/download/ based on the operating system you [Amazon Linux and Red Hat].
are using. The installer requires the Mac OS X 10.6+ 64 bits Here are the steps you need to follow to install
or Windows XP/Vista/7/8 or any Linux distribution. OpenMEAP on AWS:
Here is a list of OpenMEAP pre-requisites/software ƒƒ Visit AWS Marketplace to access an OpenMEAP bundle
requirements: ƒƒ Select an OpenMEAP version from AWS Marketplace
ƒƒ Eclipse IDE for Java EE developers (Windows or Mac) to deploy it
ƒƒ Windows Phone 8 SDK (Win 8) ƒƒ Configure it for an AWS server setup
ƒƒ Android SDK (Windows or Mac) ƒƒ Configure firewall rules for http, https and ssh
ƒƒ Xcode 4.2+ (Mac) ƒƒ Start the OpenMEAP virtual machine on AWS
ƒƒ Apache Tomcat 7.0 ƒƒ Log in with admin account OpenMEAP
ƒƒ Apache IvyDE ƒƒ Connect to EC2 instance with an ssh instance for any other
ƒƒ Apache Ant 1.8+ required configuration or modifications
ƒƒ Java JDK 1.6+
One of the most promising advantages of using To be continued on page 97...

92  |  OCTOBER 2014  |  OPEN SOURCE For You  |  www.OpenSourceForU.com


Let’s Try Open Gurus

Deploy Synergy
to Share Your Devices
This article discusses a program called Synergy, which is used for sharing the mouse and
keyboard of server with number of clients. By definition, the word ‘synergy’ implies that
the whole is greater than the sum of its parts. This awesome software program clearly
demonstrates this!

D
o you have two or more computers at your desk? using a wired or wireless network. As long as both systems
And how do you operate them? Like everyone are reachable over the network, Synergy will do its job. So let
else, by using the keyboard and mouse of each us get our hands dirty with it.
computer, right? Wouldn’t it be great if you could use
just a single keyboard and mouse to operate multiple An introduction to Synergy
computers? Well, you can do that with Synergy. So let’s go Synergy is a software application that allows you to share a
ahead and explore this software’s configuration and some keyboard and a mouse between multiple systems. It is somewhat
of its troubleshooting techniques. similar to the KVM (Keyboard, Video and Mouse) switch but
For demonstration purposes, I’ll use Windows 7 and is purely a software entity. It is convenient when a single user
Ubuntu GNU/Linux. Figure 1 depicts the details of my set-up. wants to operate multiple systems, and is also useful in situations
In my set-up, both the systems are laptops but any in which several systems are connected to a monitor and the user
combination of desktop/laptop is fine. An external keyboard wants to operate them using a single keyboard and mouse.
and mouse are connected to the Ubuntu machine. And Synergy follows the client-server model, in which there
with the help of Synergy, they will be used to operate both is a single server and one or more clients. The server is the
these machines. It doesn’t matter whether the keyboard or system to which the keyboard and mouse are physically
mouse are connected via PS2, USB or wireless; whether the connected. In my case, it is the Ubuntu machine. To operate
architecture is x86 or x64; or if the systems are connected another system, just move your mouse pointer to the other

www.OpenSourceForU.com  |  OPEN SOURCE For You  |  OCTOBER 2014  |  93


Open Gurus Let’s Try

system’s screen. Theoretically, there is no limit to the number


of clients that can be connected. Isn’t it an awesome concept?
Synergy supports all major platforms and works fine with
MS Windows, GNU/Linux and Mac OS X, allowing the user to
seamlessly move the mouse cursor between multiple sessions.
The operating system requirements for Synergy are given below:
ƒƒ MS Windows: Windows XP3 onwards
ƒƒ Ubuntu: Ubuntu 10.04 onwards
ƒƒ Mac OS X: Mac OS 10.5 onwards Figure 1: Synergy diagram
But if we can also share the keyboard and mouse by using a
KVM switch, then what is special about Synergy? Well, KVM [bash]$ sudo dpkg -i synergy-1.5.1-r2398-Linux-x86_64.deb
is hardware; hence, you have to purchase it, which adds to costs
and also occupies some space on your desk. On the other hand, For MS Windows, download the pre-compiled installer
Synergy is purely a software component. Hence, it doesn’t from the same location. Double click on the installer and
occupy space on your desk. Some of the salient features of follow the on-screen installation instructions.
Synergy are listed below:
1) It is a lightweight application with a very low footprint. Note: Please ensure that versions of both the Synergy
2) It is open source and entirely free of cost. As its source code applications are the same.
is available to the public, you can customise it according to
your requirements. Configuration steps
3) It is cross-platform and works fine with all major OS It takes only a few minutes to configure Synergy.
platforms. Configuration is required only at the Synergy server (hereafter
4) It has full encryption support, which keeps sensitive data referred to as just the server) side, and Synergy clients
safe on public networks. (hereafter called clients) can directly connect to it.
5) One of the great features of Synergy is that it shares the First, choose a server. Obviously, we will choose Ubuntu
clipboard between Synergy sessions. as the server because the external keyboard and mouse are
6) It allows one to move the mouse seamlessly between connected to it. We can configure the server either by creating
Synergy sessions. a configuration file or by using a GUI tool. This section
7) It doesn’t require any special hardware. Only network describes both methods.
connectivity is required. The server machine shares its keyboard and mouse with
8) It doesn’t require a high-speed network and works clients. It needs to know about all the clients that will connect
seamlessly with regular network bandwidth. to it. So, to inform the server about these clients, create a
configuration file. Synergy’s configuration file is a plain text
Installation steps file with two mandatory sections and one optional section.
Now that we are familiar with the use cases of Synergy, let us The configuration file for our set-up will look like this:
quickly go through the installation steps. The section below
describes the installation procedure on Ubuntu GNU/Linux and [bash]$ cat ~/synergy.conf
MS Windows. For any other option, refer to the installation section: screens
guide of the OS you’re interested in. ubuntu:
Synergy is available in Ubuntu’s official software windowspc:
repository. You can install it by using the following command: end

[bash]$ sudo apt-get update section: aliases


windowspc:
[bash]$ sudo apt-get install synergy xxx.xxx.xxx.xxx # Replace it with actual IP of Windows
machine
In addition, you can install a pre-compiled .deb package. To end
download the latest version of Synergy, visit its official website
http://synergy-project.org/ and download the appropriate section: links
version. The steps below describe the installation of the .deb ubuntu:
package on Ubuntu using the dpkg package manger. left = windowspc
windowspc:
[bash]$ ls right = ubuntu
synergy-1.5.1-r2398-Linux-x86_64.deb end

94  |  OCTOBER 2014  |  OPEN SOURCE For You  |  www.OpenSourceForU.com


Let’s Try Open Gurus

In the above configuration, ‘screens’ and ‘links’ are NOTE: connecting to ‘xxx.xxx.xxx.xxx’: xxx.xxx.xxx.xxx:24800
mandatory and ‘aliases’ are optional. The default syntax of NOTE: connected to server
any section is as follows: INFO: entering screen
INFO: leaving screen
section: name
arguments Congratulate yourself; the connection has been
end established successfully. You should now be able to move the
mouse between synergy sessions.
Section names can be ‘links’, ‘screens’, ‘aliases’ or
‘options’. Let us first understand the configuration file. Note: For security reasons in the article, I have used
The first section is ‘screens’, which simply lists the ‘x.x.x.x.’ Do replace this with the actual IP address of your
names of the systems participating in the Synergy session. server machine.
In our case, there are two systems and, hence, there are two
entries. In this section, you can either use the hostname or IP One of the advantages of the text configuration is that we
address of the system. can copy it to another machine, and Synergy can be started
The next section is ‘aliases’. Synergy clients provide the by doing just a little modification. But some people prefer the
hostname while establishing a connection with the server, so GUI tool instead. No problem! Synergy also has an intuitive
the server can find them in the configuration. Some systems GUI tool from which you can configure the server, and there
report FQDN (Fully Qualified Domain Names) and some report is also a GUI client. The section below illustrates the steps to
only hostnames, depending on their network configuration. configure the server using the GUI tool.
This section provides a list of names by which each computer 1) On the Ubuntu machine, first launch the Synergy
is known. To describe this section, we can either use the IP application from Unity dash. The first two screens don’t
address or the FQDN of the system. If you are using the FQDN require any special attention.
in the ‘screens’ and ‘links’ section, then this section is optional. 2) Select the server option from the third screen.
Our last section is ‘links’. This describes the virtual 3) Optionally, you can enable the encryption feature for
adjacency of the systems. If you remember, in the Synergy. After that, click the ‘Finish’ button.
configuration, the Windows 7 machine is to the left of the 4) From the main screen, ensure that the ‘Configure
Ubuntu machine or, you could say that the Ubuntu machine Interactively’ radio button is selected. Then click on the
is on the right side of the Windows 7 machine. The ‘links’ ‘Configure Server’ button.
section depicts this information. To know more about 5) To add a new client, drag a new screen onto the grid from
Synergy’s configuration options, go through the details on the spare ones at the upper right. By default, the name of
http://synergy2.sourceforge.net/configuration.html. the screen is shown as ‘Unnamed’. To rename it, double
Now let us test this configuration. On the Ubuntu click on it and give it an appropriate name. In my case,
machine, start the server in the foreground by using the the name is ‘windowspc’. Optionally, we can also define
following commands: aliases on this screen.
5) Similarly, to remove a client, drag the screen to the trash
[bash]$ synergys --config ~/synergy.conf --no-daemon --no- icon present in the upper left.
restart Figure 2 shows what our configuration screen will look like.
INFO: Synergy 1.5.1 Server on Linux 3.13.0-24-generic To activate the configuration, click the ‘OK’ button
#46-Ubuntu SMP Thu Apr 10 19:11:08 UTC 2014 x86_64
NOTE: started server, waiting for clients

Our server has started successfully and is waiting for the


client connection. Here the ‘--no-restart’ option implies: “Do
not try to restart the server upon failure.” Now switch to the
client, i.e., Windows 7, and execute the following commands
in the terminal:

[Windows CMD]$ cd “C:\Program Files\Synergy”

[Windows CMD]$ synergyc.exe --no-daemon --no-restart “xxx.


xxx.xxx.xxx”
INFO: Synergy 1.5.1 Client on Microsoft Windows 7 x86
NOTE: started client Figure 2: Server configuration

www.OpenSourceForU.com  |  OPEN SOURCE For You  |  OCTOBER 2014  |  95


Open Gurus Let’s Try

and start the server. That’s it! We have started the server
successfully. Now let us switch to the client. The section
below describes the steps to be performed on the client.
1) First, launch the Synergy application.
2) Select the ‘Client’ check-box, enter the IP address of the
Synergy server in the ‘Server IP’ text-box and click on the
‘Start’ button.
After establishing the connection, the screen will look like
what’s shown in Figure 3.

Auto-launching Synergy
Synergy is an awesome utility. By default, we have to launch
it explicitly, every time. Wouldn’t it be great if Synergy starts
automatically when you log in to the system? We can do this
too. In this section, we are going to explore auto-launching
the Synergy server after logging into a GNOME session.
We can also launch the Synergy GUI application from the
command prompt. Just type synergy at the command prompt Figure 3: Client
and that’s it. To auto-start Synergy, go to Unity Dash -> Startup
Application Preference -> Click on Add button. This will result Synergy’s official website.
in a pop-up message window. In place of the command, type 4) While copying text between multiple sessions, Synergy
‘absolute path of Synergy’. In my case, it is /usr/bin/synergy. automatically translates linefeeds between UNIX and
Click the Add button to save the configuration. Windows formats, enabling cutting and pasting across
If you want to use the configuration set-up with systems as easily as within a single one. In addition, it
‘synergys’, use the following instead: forces screensavers to activate and deactivate, in concert.

synergys --config ~/synergy.conf Troubleshooting


Sometimes, because of invalid user configuration or software
To auto-launch the client on Windows, go through the MS bugs, strange problems do occur. In this section, we are going
Windows documentation. to discuss a few common issues and how to work around them
without spending too much time.
Tips and tricks 1) Both the Synergy client and servers show that they are in
Now that we are familiar with Synergy, let us discuss a few a connected state, but the mouse doesn’t appear on the
tips and tricks that will make our lives easier. second screen.
1) If we use a static IP for the Synergy server instead of Check whether the ‘Scroll Lock’ key is activated or not. As
DHCP, we can configure both the Synergy client and stated earlier, the ‘Scroll Lock’ key restricts the cursor to the
the server to auto-start and also establish a connection current screen. This is the default behaviour of Synergy.
whenever we log in to a session. This is a one-time 2) Why does the Synergy server refuse to accept a
procedure; once you have automated this process, you connection to the client?
don’t have to do anything. This problem may occur because of multiple reasons. First,
2) Using Synergy, we can seamlessly move the cursor from it can be because of a strict firewall rule. By default, Synergy
one monitor to another, but sometimes we may want to runs on port number 24800. Check whether a firewall rule is
restrict the cursor to only one monitor—for instance, added for that port or not. Additionally, with the ‘-a’ option, we
while playing video games. To achieve this, press the can run it on any other available port.
‘Scroll Lock’ key, which will restrict the cursor to the This issue can also occur because of different client and
present screen. Users who don’t have a ‘Scroll Lock’ key server versions. Please ensure that both client and server are of
can re-assign the Scroll Lock key by clicking ‘Configure the same version. Also, double check the ‘aliases’ settings.
Server’ and selecting the ‘Hotkeys’ tab. 3) Certain programs stop me from moving the mouse off screen.
3) Synergy shares the clipboard between its sessions. For This usually occurs in Windows Vista and later versions,
instance, in our case we can copy text from Windows 7 and is due to UAC in Windows. We can get rid of this problem
and paste it in Ubuntu and vice-versa. Additionally, we by running Synergy in an ‘Elevated’ mode. This option is
can also drag and drop files between two MS Windows available at the bottom of the main Synergy window.
sessions. This feature is available only with the premium 4) Why is the mouse over sensitive during games on the client?
edition. To know more details about this, go through To solve this issue, we first need to enable the relative

96  |  OCTOBER 2014  |  OPEN SOURCE For You  |  www.OpenSourceForU.com


Let’s Try Open Gurus

mouse movements on the server. Please follow the steps • Click on the ‘Edit’ menu and select ‘Settings’.
given below to do so. • Change the ‘Logging level’ drop-down box to ‘Debug’ or
• Click on the ‘Configure Server’ button. higher. The debug output should appear in the ‘Log’ area
• Then click on the ‘Advanced server settings’ tab. of the main window (if not, try restarting the program).
• Tick the ‘Use relative mouse moves’ check-box and You can copy and paste the text from this window.
press the ‘OK’ button. If you want to delve deeper into Synergy or want to
In addition to this, you can try to lock the mouse to your contribute to the Synergy project, visit the official website
client screen by pressing the ‘Scroll Lock’ key. http://synergy-project.org/.
5) How do I send a debug output to the developers?
If Synergy is not working as expected and you want help By: Narendra Kangralkar
from the community, then provide some debug logs while The author is a FOSS enthusiast and loves exploring
describing the problem. That makes troubleshooting really easy. anything related to open source. He can be reached at
narendrakangralkar@gmail.com
Please follow the steps below to capture and send debug logs.

...continued from page 92


Table 1: A comparison of mobile application development platforms

OpenMEAP iOS SDK Java ME


Licensing Open Source LGPL Apple tools are free for an Free
model license Intel-based Mac. AppCode
- Commercial licenses
available.
Programming HTML5, CSS3, JavaS- Objective-C Java
language cript
Cross-platform iOS (iPhone, iPad, iPhone, iPad, iPod Touch Yes, although many VM implementa-
deployment iPod Touch), Android, tions have device specific bugs neces-
BlackBerry sitating separate builds
Availability of Emulator is available Bundled with iPhone SDK, Free emulator, Sun Java Wireless
emulator using native emulators integrated with Xcode IDE Toolkit, mpowerplayer
Availability of IDE Xcode, Eclipse Xcode, AppCode Eclipse, LMA NetBeans Mobility Pack

OpenMEAP on OpenShift (Platform as a Service) References


The following are some abstract level steps for the installation
[1] http://en.wikipedia.org/wiki/Mobile_enterprise_application_
of OpenMEAP on OpenShift: platform
ƒƒ Create an account on http://openshift.redhat.com and [2] http://www.openmeap.com/faq/
namespace; install Git and Ruby. [3] http://wiki.openmeap.com/index.php?title=Get_-_Started_-_
ƒƒ Install rhc client tools: Guide
[4] https://aws.amazon.com/marketplace/pp/B00DNF8EC0/
ref=tsm_openmeap
sudo gem install rhc [5] http://wiki.openmeap.com/index.php?title=OpenMEAP_-_
OpenShift_-_Install
ƒƒ Create an application: [6] https://aws.amazon.com/marketplace/seller-profile/ref=dtl_
pcp_sold_by?ie=UTF8&id=ab3d9d85-c879-45d4-bbeb-
07ca97f3018d
rhc app create -a openmeap -t jbossews-2.0 --from-code git:// [7] http://en.wikipedia.org/wiki/Mobile_application_development
github.com/OpenMEAP/openshift-openmeap-quickstart

ƒƒ Start the server: By: Priyanka Agashe and Mitesh Soni


Priyanka Agashe is a software engineer and she loves to explore
rhc app start -a openmeap new technologies. Her professional spheres of interests include
Oracle Apps, Electronics, and Robotics.
ƒƒ Check out your OpenMEAP install. Mitesh Soni is a Technical Lead and he likes to explore new
technologies and open source products. Blog: http://clean-
ƒƒ Update Global Settings and Cluster Nodes.
clouds.com
ƒƒ Build the mobile clients.

www.OpenSourceForU.com  |  OPEN SOURCE For You  |  OCTOBER 2014  |  97


For U & Me Open Strategy

“Android has been ruling and will


continue to rule in the future as well”
Motorola has been faring very well in the Indian smartphone market with the launch of Moto E,
Moto G and Moto X. The company wants to take its success to another level with the new Moto
G and new Moto X smartphones, and the Moto 360 smartwatch. Motorola launched these three
devices in India recently and is still banking on the pure Android experience. Diksha P Gupta
from Open Source For You caught up with Amit Boni, General Manager, Motorola, during the
launch event in New Delhi and discussed the company’s Android strategy. Read on...

Q When you launched the first edition of Moto G in India,


you faced a stock crunch. How do you plan to handle
that situation with the new Moto G2 (2014)?
When we brought Moto G to India, we clearly
underestimated the demand. But this time, we have better
plans and better estimates. We have evolved much beyond
the stage we were at during the launch of Moto G and Moto
E. So hopefully, we will not face a supply crunch this time,
although we don’t have a sales target, as such. We would
like to focus on products that deliver value and on our
promises to the end consumers. We have been able to sell
over a million Motorola devices up till now, including the
Moto G, Moto E and Moto X. We hope to build upon what
we have already achieved.

Q Motorola has always believed in Stock Android, but will


things change after Lenovo completes its acquisition of
your firm?
We are very focused on delivering the pure Android experience.
So we are totally sure that we are not going to do any tweaking
of pure Android. Having Stock Android helps us do a lot of
things. People truly love the purest form of Android. Lots of
companies think that putting a skin on Android gives them an
edge, but I don’t think so. The skins added to Android by the
Amit Boni, India head, Motorola OEMs just make the devices bulky and slows them down. Stock
Android is really helping us bring the latest and greatest Google

Q What was the response to Motorola’s recent brand re-


launch?
We re-launched the brand in February. At that time we believed
experiences to our customers. I think this is something that has
really worked well and so we will continue doing the same in
the future as well. What we focus on is bringing out amazing
we were purely re-launching the brand but it turned into devices, which are better than the previous ones. For us, that is
something much beyond that. Consumers just went crazy over the only war we have to fight.
our products. I think what we have been able to accomplish in
the past 6-7 months was beyond our imagination. I am pretty
sure that most of the people did not think that Motorola would
be able to create such a benchmark with its products. I think
Q So, since you are not working on the software part of the
device, what do you think is the differentiator for your
devices? Are you focusing on the hardware side of things?
we have had an absolutely smashing bunch of products. Our Hardware is not just about the specs. The best specs do not
partnership with Flipkart has been phenomenal. We have made necessarily mean the biggest processor or RAM. People
sure that we take care of the customers very well, not only at can give you octa-core and then you will realise that your
the time of buying, but even beyond that. These are the few battery is draining in barely two hours. So we make sure that
things that are really paying back. when we offer a device, you live it throughout the day and

98  |  october 2014  | OPEN SOURCE For You  |  www.OpenSourceForU.com


Open Strategy For U & Me

it gives you optimum performance. Even if we offer a quad-


core device, the battery consumed will still last for 18-24
hours. The display is such that it doesn’t eat up the battery’s
charge. It doesn’t break easily. So it is not just about spec-
to-spec comparisons, it is the whole package of what the
device really offers in terms of the software and hardware
combination. Our build quality speaks for itself, and I would
like to say that people were pleasantly shocked to see the
build quality that we offered in Moto E at such an affordable
price. We believe that consumers deserve good products and
that is why we build them.

Q Since you bank on the Stock Android experience, do


developers have some part to play in building these devices?
We have a large engineering team in India, the largest outside
the US. Our team of developers in India is responsible for an
essential part of the devices that come out from our stable.
And we are constantly looking at opportunities to leverage
the fabulous engineering talent that India has to offer.

Q Xiaomi has also received a great response in the Indian


market and is following the same online selling model
as you did. How do you plan to counter such situations?
As I said, as long as we keep on providing the best possible
devices and value, and make sure that we take care of our
consumers, we know that we will continue to get the same
acceptance that we received in the last six months. Our
success story bears testimony to the fact that it is the best way
to go; so we will continue on the same path.

Q When Android was first introduced, people liked it for many


reasons. Apart from an ecosystem for free apps, Android
became a reason for many to step into the smartphone domain.
Have the reasons people look at Android changed over time?
I think the Android ecosystem has matured considerably
over a period of time. A lot of developers have realised
that there are more monetisation opportunities than just
directly pricing the app. The ecosystem has matured so
much that the interactions, which two years back were very
app-centric, have become very app-network-centric. People
now play games with their friends, through the apps. So, the
ecosystem has evolved in a wonderful way, paving the way
for a lot more opportunities for developers and connecting
users. If I want to play chess, I can play a standalone game
or I can play with my friends. So interactivity between apps
and between people has increased due to this ecosystem.
Android has been ruling this space and will continue to do
so in the future as well.

Q What is your opinion about the Android One platform?


It is a great initiative from Google. I will not be able to
disclose whether or not we will adopt that platform, but I
can say that in a way, Moto E was the benchmark for a lot of
things done today.

www.OpenSourceForU.com  | OPEN SOURCE For You  |  october 2014  |  99


TIPS
& TRICKS

Viewing changes as often as you choose GRUB_CMDLINE_LINUX_DEFAULT=”quiet splash”


Very often, we need to execute a command every
few seconds to view the changes made. Most of the Linux- …to:
based OSs come with a utility that enables you to view the
output of a command after a set time. GRUB_CMDLINE_LINUX_DEFAULT=”quiet splash acpi=force”

watch -n<Seconds> ‘your command here’ Save it and update Grub by using the following
command:
For example, if you want to view a DB table in PostgreSQL
every two seconds, you can use the following command: $sudo update-grub

watch -n2 ‘psql -U postgres -d my_db -c select count(*) If this does not work out, please downgrade your
from order;’ kernel to the 3.2.0-* version. To do that, first install the
—Deepak Gupta, kernel version by using the following command:
deepakgupta101@yahoo.co.in
$ sudo apt-get install linux-headers-3.2.0-25-generic
Repositioning the cursor in Vim linux-headers-3.2.0-25 linux-image-3.2.0-25-generic
Here is a tip that will help you to move the cursor on
the screen: Now, to make this as a default boot kernel, edit /etc/
H – Makes it jump to the top of the screen. default/grub and change the line…
M – Makes it jump to the middle of the screen.
L – Takes it to the bottom of the screen. GRUB_DEFAULT=0
Now, if you want to reposition the cursor along with
the line, you may have to try this: …to:
z. => Repositions the cursor along with the line to the
centre of the screen GRUB_DEFAULT=2>0
z+ => Repositions the cursor along with the line to the
top of the screen Save it and update Grub using the following
z- => Repositions the cursor along with the line to the command:
bottom of the screen
—Ahmed Sharif, $ sudo update-grub
ahsh767@gmail.com
Reboot the machine and check that you have the
Power-off after shutdown correct Linux kernel by using the following command:
In some Linux systems with kernel 3.5.0-*, the
system will not power off after the shutdown command $uname -r
is passed to it. You need to press the power button
continuously to halt the machine. After downgrading the kernel, powering off will work
One possible way to fix this issue is by editing the /etc/ perfectly.
default/grub file and changing the line … —Nagaraja T,
naga2raja@gmail.com

100  |  october 2014  | OPEN SOURCE For You  |  www.OpenSourceForU.com


Delete files of the same filetypes in a unix_file.txt: ASCII text
folder and its sub-folders —Narendra Kangralkar,
Under Linux, you can delete files of a specific file type narendrakangralkar@gmail.com
located in a folder and its sub-folders using the simple
combination of the find and rm commands. Get a list of the devices connected via
For example, if file types like .inf need to be deleted the USB port
from all folders, we can execute the following command: Many a time, we want to know details about the device
connected to our system via the USB port. Here is a command
#find /path/to/the/folder/ -type f -iname “*.inf” -exec rm that will list all the devices connected via the USB port:
-vf {} \;
#lsusb
Or, if we want to remove files one by one, then we can use:
To get more information about each of the devices, you
#find /path/to/the/folder/ -type f -iname “*.inf” -exec rm can run the following command:
-iv {} \;
#usb-devices

Note: Care should be taken while executing the – Mohammad Jamal Mohiuddin,
above commands as wrong usage can lead to loss of data. md.jamalmohiuddin@gmail.com

—Raghava Karthik Reddy, Unmount a file system even with a


rkartihk@gmail.com ‘Device is busy’ error
Sometimes, when unmounting a mounted file system, one
Convert a DOS file to the UNIX format gets the ‘Device busy’ error and the file system does not get
If you want to convert a DOS file to the UNIX file unmounted. Here are the steps to unmount the file system
format, you can use the following command: in such conditions. Type the following command in the
terminal:
dos2unix
#fuser -k /device
But since this command is not available in GNU/Linux
by default, you have to install this package explicitly. By Here, you need to type your mount point name instead
using the tr command, you can do this conversion. of /device
Remember that in the DOS file format, each line ends In my case this was sdc1
with the ‘\r\n’ combination and in the UNIX file format,
each line ends with only ‘\n’. To convert a file to the UNIX #fuser -k /mnt/sdc1
file format, delete the ‘\r’ character. Here is how we do it.
First of all, check the file type by running the following The output of the above command will give a
command: PID number of the process that is stopping you from
unmounting the file system, like 5133.
[bash]$ file dos_file.txt Kill that process as shown below and try to unmount
again.
The output will be as follows:
#kill -9 5133
dos_file.txt: ASCII text, with CRLF, LF line terminators – Amar Gehlot,
amar281494@gmail.com
Now use the ‘tr’ command to remove the ‘\r’ character,
as shown below:

[bash]$ tr -d ‘\r’ < dos_file.txt > unix_file.txt Share Your Linux Recipes!
The joy of using Linux is in finding ways to get around
Check the new file format: problems—take them head on, defeat them! We invite you to
share your tips and tricks with us for publication in OSFY so
that they can reach a wider audience. Your tips could be related
[bash]$ file unix_file.txt to administration, programming, troubleshooting or general
tweaking. Submit them at www.opensourceforu.com. The sender
of each published tip will get a T-shirt.
As expected, the output will be as shown below:

www.OpenSourceForU.com  | OPEN SOURCE For You  |  october 2014  |  101


For U & Me Interview

Ravi Gupta, Vertical Head


–Public sector and enterprise,
Intel India

102  |  october 2014  | OPEN SOURCE For You  |  www.OpenSourceForU.com


Interview For U & Me

“Software defined
infrastructure is set to
make the lives of IT
heads easy!”
Intel has recently introduced its Xeon The Intel Xeon processor E5-2600 v3 product family
processor E5-2600/1600 v3 product introduces new features that provide greater visibility into
families to address the requirements the system than ever before. A new cache monitoring feature
of diverse workloads and the rapidly provides data to enable orchestration tools to intelligently
evolving needs of data centres. The new place and rebalance workloads, resulting in faster completion
processor families include performance times. This also provides the ability to analyse performance
increases of up to 3x over the previous anomalies due to competition for cache in a multi-tenant
generation, world-class energy efficiency cloud environment, where there is little visibility into what
and enhanced security. To facilitate the workloads consumers are running.
explosive demand for software defined The new processors also include platform telemetry
infrastructure (SDI), the processors sensors and metrics for CPU, memory and I/O utilisation.
expose key metrics, through telemetry, With the addition of thermal sensors for airflow and
which enable the infrastructure to deliver outlet temperature, the visibility and control has increased
services with the best performance, significantly from the prior generation. The processors
resilience and optimised total cost offer a holistic set of sensors and telemetry for any SDI
of ownership. Diksha P Gupta from orchestration solution to more closely monitor, manage
Open Source For You spoke to Ravi and control system utilisation to help maximise data centre
Gupta, vertical head–public sector and efficiency for a lower total cost of ownership.
enterprise, enterprise solutions group,
Intel India, about how SDI’s evolution will
impact data centres in India and how they
will change the IT world. Excerpts:
Q Why do you think that software defined infrastructure is
poised to change the current state of IT?
Right now, IT involves a lot of intervention from
systems administrators and systems. It needs to be more
intelligent, wherein the infrastructure itself takes the
decisions on resourcing and orchestration, as it is known

Q How does Intel plan to be a part of the revolution called


software defined infrastructure?
Software defined infrastructure (SDI) is the foundation for
as, in the IT language. Software defined infrastructure
is the key for that, because once the policies are defined
in the software layer, then the software can trigger the
cloud computing. The digital services economy requires hardware to change configurations based on what is
agility and scale, which demand that all infrastructure needed, who needs more resources, RAM, et al, versus
resources be programmable and highly configurable. These the current state of affairs, wherein the administrator does
abilities, coupled with telemetry, analytics and automated it manually. With SDI, what we see is that whether it is
actions, allow the data centre to become highly optimised. for storage, networks or computing, the software itself
Intel continues to invest in delivering this vision of an will be intelligent enough to take the decision, or it will
automated data centre, and with the new Xeon E5-2600 v3 be able to trigger the decision in the required manner.
product family, the company has introduced key sensors This is already happening and we foresee the technology
and telemetry that further enhance SDI. taking over in the next 12-18 months.

www.OpenSourceForU.com  | OPEN SOURCE For You  |  october 2014  |  103


For U & Me Interview

Q Does that mean SDI is poised to replace IT


administrators at a certain stage?
I would say that it is poised to make the IT administrator’s life
case now. So, when a provision of resources is made in the
current scenario, the provision is made based on dynamic needs.
It means that when the need is there in a specific month or a
easy! With SDI coming in, an IT administrator should be able time period, the resources are automatically provisioned. The
to spend much more time doing something more productive, resources are also provisioned based on triggers. For example,
like forecasts on how much resources he may need in if the IT head sees the RAM running out of stock for a specific
the coming months. If businesses say that they need more application, the servers will pull out more RAM from the
resources in a specific month, for instance, in March, because virtualised infrastructure and give it to that particular application,
maximum billing happens in that month, then IT is the one automatically. This is the concept of a dynamic data centre.
arm that has to arrange for the resources for this. So, in a way, In the traditional IT space, things were different, but now,
SDI would make a systems administrator’s life easy. SDI is a the clients are offered a choice between a static or a dynamic
tool; it is not going to replace the traditional IT job, but will set-up. Static set-ups have a higher billing, because that
make that job more intelligent. configuration is assigned specifically to a company, only to be
used by that company. But in the case of a dynamic set-up, it

Q What is the demand like for SDI in today’s data centres?


If someone is running a big data centre with thousands
of servers and has to perform the same job on all the servers,
means that as and when the company is not using those assigned
resources, some other firm might use it as well. Yet, the data
centre will ensure that the terms of the SLA signed with the
then obviously he will run short of manpower at some stage. company are met and the configurations cannot drop below the
So, from that perspective, if I run big data centres, and if set SLA. What we see as a trend is that dynamic set-ups are
my data centre is SDI-enabled, I can make provisions for more in demand because they require less intervention, take less
more resources and also release these resources once the time to provision and are need-based.
job is done, automatically. SDI enables automation of data
centres for resources, which is today done manually. Manual
resource allocation is difficult, because most of the time, it
is done only when some applications fail and the IT head
Q So how is SDI evolving in India?
Today the telecom sector is a high adopter of SDI, and
enterprises have started following suit. Going forward, there
comes to know that he needs to scale up his resources for is bound to be a huge paradigm shift in the enterprise data
that application. But can he make his software intelligent centres and e-commerce data centres, and as I said, telecom
enough to reconfigure the resources based on those triggers? has already taken the lead because it is largely in the Internet
That is what SDI will handle. So, eventually, for all large hosting space as well.
data centres and servers, SDI is the answer.

Q It is said that data centres cannot be static any more. Do


you agree? If so, please explain why.
Q Do we see SDI entering the SMB space anytime soon?
Not really. It is more related to who wants the
infrastructure. SMBs today usually go for the infrastructure-
‘Static’ implies having the same configurations all the time. So, as-a-service (IAAS) model, which is ideally someone
it means that a User X retains the set configurations assigned else’s infrastructure. SMBs either want to have their
to him initially, all the time. That is not the case any more. Till own infrastructure, which could be a small compute
two years back, whatever was given to User X was fixed. The infrastructure, or it is based on somebody who is servicing
data centre guys used to delete the resources assigned from them, which is IaaS. SDI is more effective when you use a
the ‘resources table’ after they were assigned, which is not the large number of servers and storage.

EB Times
• Electronics • Trade Channel • Updates
An EFY Group publication

is Becoming Regional
Get East, West, North & South Editions at you
doorstep. Write to us at myeb@efy.in and get EB
Times regularly
This monthly B2B Newspaper is a resource for traders, distributors, dealers, and those
who head channel business, as it aims to give an impetus to channel sales

104  |  october 2014  | OPEN SOURCE For You  |  www.OpenSourceForU.com


R N I No. DELENG/2012/49440, Mailed on 27/28th of Advance month Delhi Postal Regd. No. DL(S)-01/3443/2013-15
Published on 27th of Advance month

There is a place for Postgres in every datacenter.


WE CAN HELP YOU FIND IT.

Postgres delivers. Enterprise class Performance, Security, Success.


For 80% less.
EnterpriseDB - The Postgres Database Company
Sales-india@enterprisedb.com

EnterpriseDB Software India Pvt Ltd


Unit #3, Godrej Castlemaine
Pune - 411 01 India
T +91 20 30589500/01

You might also like