Linux DevCenter    
 Published on Linux DevCenter (http://www.linuxdevcenter.com/)
 See this if you're having trouble printing code examples


O'Reilly Book Excerpts: Linux Desktop Hacks

Hacking the Linux Desktop, Part 2

Editor's note: If you didn't get enough Linux tweaks last week from O'Reilly's Linux Desktop Hacks, here are two more hacks from the book to satiate your hacking needs.

View Microsoft Word Documents in a Terminal

moderate icon hack 52 icon

Avoid the load time of OpenOffice.org and view Microsoft Word documents in a terminal.

The simplest way to view a Microsoft Word document in a terminal is to use the catdoc command. But catdoc turns a Word document to plain text, which does little or nothing to preserve the format of the original Word document. Obviously, it's nearly impossible to view a Word document in a terminal exactly the way it would look in Word. Heck, competing word processors have trouble importing Word documents without upsetting the format, and they have the advantage of being a graphical desktop application. But this hack is still a vast improvement over the popular catdoc program, because it preserves at least some of the formatting of the original document by converting the Word document to HTML.

You'll need both the wvWare set of file conversion utilities and the hybrid web browser/pager w3m, along with a little scripting magic to view Word documents in a terminal or console while retaining at least some of the original formatting.

wv, the All-Purpose Word Converter

There is a way to retain at least some of the original formatting while printing the document to the screen. For this, you need a set of utilities under the name of wvWare. You can find the home page for wvWare at http://wvware.sourceforge.net. Packages of wvWare are readily available for almost all Linux distributions, although the package name is usually just wv. For example, if you don't already have it installed on your system, you can install wv in Debian Linux with this command:


# apt-get install wv

Users of the yum package can get the RPM version of wv with this command:


# yum install wv

w3m, the All-Purpose Web Browser/Pager

That's not all you need for this hack. You also need a popular pager/browser called w3m. Packages of w3m should be available for most Linux distributions, and the package name is usually w3m. For example, you can install w3m in Debian Linux with this command:


# apt-get install w3m

Users of the yum package can get the RPM version of w3m with:


# yum install w3m

The w3m program is rather unique in that it is a web browser that works like a pager--that is, you can pipe text into w3m and use w3m to simply page back and forth through the text. Some versions of w3m even render graphics in a frame-buffer console without having an X Windows desktop running.

You can combine the two utilities to get the desired result of viewing a Word document in a terminal. Use wvWare to convert a Microsoft Word document to HTML format, and then pipe the output into the w3m pager to view it. Here's the full command you need to make it work (this command assumes wvHtml.xml is stored in the /usr/lib/wv directory, which might not be the case on your Linux system):


$ wvWare -x /usr/lib/wv/wvHtml.xml document.doc | w3m -T text/html

That's a lot of typing every time you want to view a Word document, so turn it into a script called viewdoc to make it easier to use in the future. Log in as root and use your favorite editor to create the following script:


#!/bin/bash

wvWare -x /usr/lib/wv/wvHtml.xml $1 2>/dev/null | w3m -T text/html

Note the one subtle addition, 2>/dev/null. This simply redirects any error messages to the twilight zone so that they do not interfere with the presentation of the Word document. Store it as /usr/local/bin/viewdoc and make the script executable with this command:


# chmod +x /usr/local/bin/viewdoc

Now all you have to do to view a Word document in a text console or terminal is issue this command:


$ viewdocdocument.doc

Not only does this technique preserve at least some of the formatting of a Word document, but also, hyperlinks are live and you can activate them to visit the URL from within the w3m viewer you're using to view the document. Figure 7-3 shows an example of a Word document viewed with w3m. Note both the bold headings and the live link to http://www.bootsplash.de/files.

A Word document viewed in HTML text format
Figure 7-3. A Word document viewed in HTML text format

Linux Desktop Hacks

Related Reading

Linux Desktop Hacks
Tips & Tools for Customizing and Optimizing your OS
By Nicholas Petreley, Jono Bacon

Create an Internet Phone

beginner icon hack 63 icon

Talk to the world and save money while doing so.

As the number of broadband installs increases and the connections get faster and faster, the potential to use quality audio and video applications over the Internet has become more feasible. These kinds of heavy-bandwidth applications are no longer the domain of just large corporations with money to spend on expensive Internet access; cable modems and DSL lines bring the technology to the home.

This hack explores how to use two applications to make phone calls to others over the Internet. Although using these applications is fairly straightforward, the configuration of firewalls and security can be a barrier to getting started. In addition to exploring Internet-based calls, I also discuss what options are available to call regular phones from the Internet. A number of services offer PC-to-phone and vice-versa services, and the cost compared to regular phones is often minimal.

GnomeMeeting

GnomeMeeting is a fully open source audio and video conferencing tool. This hack focuses on audio; [Hack #64] focuses on the use of GnomeMeeting as a video conferencing tool.

When you use GnomeMeeting, a gatekeeper manages your connection. This central server provides a directory of connected clients and their call status. The gatekeeper offers a telephone directory-type service for users, complete with a user profile. This hack doesn't cover how to set up a gatekeeper, but information on this is available at http://opengatekeeper.sourceforge.net.

Using GnomeMeeting is fairly simple if you have a working sound card--just connect to the default gatekeeper and go. Using GnomeMeeting gets more complex when you roll a firewall into the mix. GnomeMeeting requires a number of ports to be open on the firewall for the software to work. Opening these ports can be a concern for those who feel uncomfortable about providing additional access past the firewall. Unfortunately, to use GnomeMeeting, you must ensure these ports are forwarded to the machine running GnomeMeeting (or are opened entirely if more than one machine will run GnomeMeeting), or it won't work. One slight consolation is that you can change some of the ports for different numbers by adjusting some settings in GConf (the GNOME Configuration program that comes with most GNOME installs). The ports to be forwarded are as follows:

TCP port 1720

You can change this port if you modify the /apps/gnomemeeting/ports/listen_port key in GConf.

TCP port range 30000-30010

If you and the remote connection are using H.245 Tunneling, you don't need to forward this range of ports. Microsoft Netmeeting does not support H.245 Tunneling, so you do need to allow and forward this range of ports if you need to connect to Netmeeting clients. You can adjust this range of ports if you modify the /apps/gnomemeeting/ports/tcp_port_range key in GConf.

UDP port range 5000-5007

This mandatory range of ports is used for audio and video transmission and reception.

UDP port range 5010-5013

These ports are used when registering to a gatekeeper. You don't need to allow and forward these ports if you don't plan on using a gatekeeper. You can change this range of ports if you modify the /apps/gnomemeeting/ports/udp_port_range key using GConf.

Once you have set up your firewall to forward these ports [Hack #81], you must also ensure that these ports are available to the outside world. Smoothwall includes an External Services Access screen where you can configure this. If you're accessing the Internet from a LAN, you should turn on "Enable IP translation" in the H.323 Advanced section of the GnomeMeeting preferences so that GnomeMeeting can apply some processing to work over Network Address Translation (NAT) routers. Previous versions of GnomeMeeting (0.94 and before) required that a special library called RSIP (http://openresources.info.ucl.ac.be/rsip/) be installed to achieve the same feature.

With the network settings complete, you can plug in your microphone. Make sure the mic volume is turned up; many people forget to do this. If you are using an ALSA-based setup, you can adjust the volume by using alsamixer or the volume controls on your desktop. With all of this complete, GnomeMeeting is ready to make calls.

Skype

The new kid on the block in the Voice over IP world is Skype (http://www.skype.com). This multiplatform Internet phone uses proprietary peer-to-peer technology to provide an efficient way of connecting to another client. If you don't have a problem with the proprietary nature of Skype, it is a highly recommended tool. The sound quality and performance are simply incredible. One particularly interesting feature about Skype is that it requires no port-forwarding or adjustments to your firewall. This feature can be a saving grace for those who have battled to get GnomeMeeting working and have found the hill too steep to climb. Skype, by comparison, is a breeze to set up.

Calling Regular Phones

Both GnomeMeeting and Skype support PC-to-phone calls, but each has a different method of dealing with these types of calls. In Skype, you simply need to register a SkypeOut account, and then buy credits that allow you to call regular phones. No additional software or hardware is required.

If you want to call phones with GnomeMeeting, the process is more complicated. First, you need to purchase some Quicknet hardware at http://www.linuxjack.com. Due to the patented nature of the G.723.1 audio codec that is required to make phone calls, the codec cannot be included in the GnomeMeeting code. But if you buy the Quicknet hardware, the codec is included in the hardware itself, along with features, such as a speaker phone, hardware support, and other niceties. Once you have installed the hardware and it is working, you need to install the latest version of the Open H323 driver from http://www.openh323.org. It is required to make PC-to-phone calls. To actually make calls with GnomeMeeting you need to register a MicroTelco account on http://www.linuxjack.com. This gives you a login and PIN number that you can enter into the GnomeMeeting settings. Finally, plug your normal phone device (analog phone, cordless phone, etc.) into the Quicknet hardware, and dial the phone as normal.


View catalog information for Linux Desktop Hacks

Return to LinuxDevCenter.

Copyright © 2009 O'Reilly Media, Inc.