Sunday, October 25, 2015

A Raspberry Pi Robocall Blocker

Calls I don't want

We get a lot of robocalls and other unwanted traffic on our landline at home.  Some of those are scammers, marketers who ignore the FTC's Do Not Call Registry, debt collectors for people who do not live in our house (such as neighbors), and other low-life.  I've been following the FCC's war on robocalls and similar marketing calls. They are illegal, but hard to stop, since those who are doing it are making money and probably won't ever get caught.  The FCC held a contest a while back.  They were asking for ideas for ending the violations of the do-not-call-list - including robocalls.  The best idea, I think, was the suggestion to offer a bounty for anyone who turns in the owner of a business that is in violation.  A disgruntled employee or just one that's leaving could narc on the owner and make some bucks.  So far as I can tell, this never happened.  Two other people won with projects using hardware and software.  Funny thing - that's my approach, too.

The telcos take no action

The telcos were reluctant to block the calls since they couldn't tell which ones were legit (such as political calls or notifications: a shop telling you your order is in or a drugstore advising you about your prescriptions), and they were afraid of getting sued on Second Amendment issues.  But the FCC recently said they could, indeed, block the calls, so maybe the telcos will actually do something.

What to do?

I'd like to shut my landline down and just use my cell phone, but some of the legitimate people who call us use it.  So I found this kinda fun project on-line.  Chris Murphy, the author, did a good job with the article, accurately describing the steps to take to build the project.  However, the article is getting a bit old.  It was posted in November of 2013.  Since then the hardware and software has improved, and some things have gotten a little simpler.  So here is an updated version of Murphy's project.

Hardware and software

The idea is to use a Raspberry Pi with a USB-connected modem to hang up when it finds a number in a blacklist file.  More about the hardware below.  The software is already written and, for me, works very well.  It is the Network Caller ID project.  You get it from Sourceforge - the specific link is below.  To run NCID, you could use a variety of hardware and operating systems: Linux (Red Hat's Fedora and Debian systems such as Ubuntu), Apple Macs, MS Windows, and FreeBSD.  There's an interface for TiVos to display the caller ID info on your television screen.  Oh, and it runs very well on the Raspberry Pi running the Raspbian OS.  

Hardware list

If you don't want to use the Raspberry Pi, with or without Raspbian, you'll probably perform an analog of the steps below.  These instructions are specific to using NCID on the Pi with Raspbian.  

  • Raspberry Pi 2 Model B.  This is the second generation Pi replacing the Raspberry Pi 1 Model B+ in February 2015.  
      • A 900MHz quad-core ARM Cortex-A7 CPU
      • 1GB RAM
      • 4 USB ports
      • 40 GPIO pins
      • Full HDMI port
      • Ethernet port
      • Combined 3.5mm audio jack and composite video
      • Camera interface (CSI)
      • Display interface (DSI)
      • Micro SD card slot
      • VideoCore IV 3D graphics core
  • Things you'll need to make the Pi work
    • Micro SD card: minimum size 4Gb; class 4 (the class indicates how fast the card is).  If you get the 8GByte NOOBS Micro SD card, you'll have a choice of OS installations as well as extra space.
    • HDMI cable for HD TVs and monitors with HDMI input - or HDMI to DVI cable for monitors with DVI input (get cheap ones!) - or an RCA video cable if all you have is an old TV.
    • Some kind of monitor - HDMI is best, but an old TV will work.
    • Keyboard and mouse - any standard USB keyboard and mouse should work. Keyboards or mice that take a lot of power from the USB ports, however, may need a powered USB hub. This may include some wireless devices.  Regular keyboards and mice work fine without a powered hub.
    • Ethernet cable - you may want this at least temporarily during OS installation, though you can probably dispense with it.
    • Power adapter - a good quality, micro USB power supply that can provide at least 700mA at 5V is essential.  Many mobile phone chargers are suitable—check the label on the plug.  If your supply provides less than 5V then your Raspberry Pi may not work at all, or it may behave erratically.  Be wary of very cheap chargers: some are not what they claim to be. It does not matter if your supply is rated at more than 700mA.
    • You might want a USB-WiFi dongle.  This will allow you to dispense with the Ethernet cable if you have WiFi, but it won't be of use until after the Raspbian OS install.
  • Update Nov 20, 2015
    I had some problems with the Zoom 3095 modem recommended below.  After much work with the NCID developers (see info about NCID below), we discovered that the Zoom 3095 needed a powered USB hub when working with the Raspberry Pi 2 model B.  It's also possible that the power supply for the Pi needed to be able to provide more current.  The power supply provided with the kit I used was rated at 2.5 A, which should have been plenty.  In any case, with a powered USB hub the Zoom 3095 should work fine.  I had replaced this modem with the US Robotics model 5637 which also works well.  The US Robotics modem seems to be able to work on the Pi without a powered USB hub as well.  But I haven't confirmed that all features of the modem necessary for NCID to function will work on the US Robotics modem without the powered USB hub.
    End of Update
  • Zoom 3095 modem  This modem is the one I used based on several recommendations: from Chris Murphy's blog and a review of various on-line discussions.  This modem works on a variety of systems.  It plugs into one of the Pi's USB ports.
    Update Nov 20, 2015 Alternatively the US Robotics model 5637 modem will work.  
  • Powered USB hub.  I used an oldish Belkin I had laying around, but any decent powered USB hub should work (you'll only need USB 2.0, but USB 3.0 should work as well).  This powered USB hub might work for you.  Plenty of good reviews.  This one might work also.  I have not tried either hub, however.
  • End of update
  • You'll also need a local network with a router that can assign IP addresses and DNS information dynamically on request.  Most home routers will do this as a matter of course.  To get the blacklist data from the FCC you'll need your network to connect to the Internet: wired or WiFi.

Hardware sources

Being lazy, I just ordered the Raspberry PI, it's supporting pieces, and the Zoom 3095 modem and the US Robotics modem from Amazon.com. The Raspberry Pi and supporting pieces can be had with the CanaKit. When I bought it in October 2015, it was about $70. You can also buy the pieces separately from various sources. Do some Web searches to find them. This CanaKit has everything you'll need except the modem, powered USB hub, keyboard, mouse, and monitor. It also has a box for the Pi, a WiFi dongle, and some teeny heat sinks for a couple of the Pi chips. (You don't really need these.) It comes with the NOOBS 8GByte SD card.

I also got the Zoom 3095 modem from Amazon.com.  I bought this one.  It cost $47.99.  But it looks like this one is the same costing $32.29.  Damn.  The US Robotics modem ran $45.

Building the hardware

This is simple.  If you got the CanaKit, there are instructions included.  If not, then you've probably done this before.  

1.  If you have the little heat sinks and want to use them, strip off the film covering the adhesive backing and stick them onto the chips - one big and one little.  

2.  Then put the Pi in its box (if you have a box), paying attention to how the Pi's ports align with the box's holes.  It'll take some fiddling.  Be gentle with the box.  I've read reports of the tabs breaking during a forceful installation.

3.  Stick the micro SD card in its slot.  This is the small opening on the opposite end of the Pi from the USB ports.  The card only goes in one way.  The slot is spring-loaded.  Don't force it, but be sure you fully insert it.  

4.  If you're using an Ethernet cable, plug it in and connect it to your network.  You'll either need your router to automatically assign the Pi an IP address (via dynamic IP) and provide DNS data, or you will need to assign the Pi a permanent IP address and give it an IP for DNS data.  The Raspbian OS is included on the NOOBS micro SD chip (along with several others), so you won't need to hook the Pi up to your network until later.

5.  Connect the Pi to its monitor either using the HDMI port or the 3.5 mm port (the 3.5 mm port is on the same side of the Pi as the HDMI port and is a composite video and audio port).  Turn on the monitor/TV and be sure you have the proper source selected.   Connect your keyboard and mouse.  Plug in the powered USB hub and into that, the Zoom 3095 or the US Robotics modem, but the modem doesn't have to be connected to the telephone system yet.

6. Plug in the Pi's USB power supply and connect it to the Pi.  After a little start-up stuff appears on your monitor, a dialog box something like the one below will appear.  
OS Selection
Select the Raspbian OS (check the box) and click the install icon.  After a bunch of startup stuff, the first important screen you'll see is this one, below.  The Expand Filesystem option may be grayed-out  since this has already been done.  Initially, anyway, you may want to select option 3.  To do this use the arrow keys on your keyboard to move the highlight down to option 3.  Then use the tab key to move the highlight to <Select>.  Option 3 will remain highlighted. 

raspi-config
Chose boot option
Press Enter and you'll see the Chose boot option dialog box.  If you plan to continue to follow these directions, select the Desktop log in ... option.  When <Ok> is selected, the "raspi-config" box will return.  Make other changes as you see fit: keyboard layout, locale, and timezone.  You will probably want to leave ssh enabled to allow you to do things on the Pi after you disconnect the monitor, keyboard, and mouse.  If you don't understand what an option is about, you can read about these here.  On my Pi, I just changed the locale and timezone.  These options can be changed later.  To do this, in a terminal window, type sudo raspi-config.  The sudo just allows you to execute the command as if you were the super user, the administrator.  Then the menu above will appear.

7.  Select <finish> and the next screen, something like the one below, will appear.  

Raspbian GUI
8. Raspbian on the Raspberry Pi is set up to get an IP address automatically from the network via DHCP, whether for wired Ethernet or wireless WiFi (via the USB wireless dongle).  Raspbian can support both IPv4 and IPv6.  IPv4 is ready for use by default, but IPv6 must be enabled manually.  If you want to give the Pi a static IP address at this time, see this article on Xmodulo.

Now find the browser.  It should be the icon in the top horizontal bar next to "Menu."  Or you can select it from the menu.  
In the browser, go to the NCID repository on Sourceforge and download the latest NCID source code package (where it says, "Looking for the latest version? Download ncid-1.2-src.tar.gz (1.6 MB)").   The exact version isn't too important and may have increased from 1.2 to something greater when you read this.  After you download this package, it should appear in your Downloads folder.  Create a folder in your Documents folder - I'll call it "source" when I refer to it here.  Drag the ncid-1.2-src.tar.gz file into source and extract the ncid source.  You'll probably have to tell Raspbian what to use to do this.  Explore the Raspbian menu.  Under Accessories select Archiver.  Use it to extract the ncid folder into source.  

9.  Now you'll need to get the libpcap library.  libpcap is a link to some POSIX capabilities in Linux. This is a set of standard operating system interfaces based on the Unix standards.  Open a terminal window by clicking on the terminal icon in the top menu bar.  Then type in the following ....
  • sudo apt-get install libpcap0.8* 
The asterisk (star) is important, so don't forget to type it.  This command will download the library from the correct repository and install it in /usr/lib/arm-linux-gnueabihf.  Documentation for it goes in /usr/share/doc.  If you are asked to approve some action enter a "Y".

10.  Now compile the system.  Type the following into the terminal window ....
  • cd source/ncid
  • sudo make ubuntu-install
ubuntu-install is one of the scripts in Makefile.  Text will scroll by and then the prompt will appear.  If you are asked to approve an action enter a "Y".

11.  You now have a working system.  The configuration files are in /etc/ncid.  First alter ncidd.conf.   The file permissions are read-only for group and others, and read/write for root.  Since you (user pi) have root permissions you can modify these files, but since you're not actually rootyou'll have to either change the permissions (using chmod) or execute the editor with sudo.  You may want to modify the ncidd.conf settings later via a remote, ssh, terminal window.  The sudo command does't work through this window, so modifying the ncidd.conf permissions now may be a good idea.  If you want to do this, execute the following.

  • cd /etc/ncid
  • sudo chmod ugo+w ncidd.conf

Now, in the terminal window type the following commands to edit ncidd.conf.
  • cd /etc/ncid
  • sudo gedit ncidd.conf
Now make the following modifications to ncidd.conf.  If you read through the configuration file, you'll find that these have (mostly) all been entered, and all you have to do is remove the "#" comment delimiter.
  • set ignore = 1
  • set hangup = 2
  • set ttyport = /dev/ttyACM0
  • set lockfile = /var/lock/LCK..ttyACM0
Setting hangup = 2 will cause ncid to emit a fax tone before hanging up.  This sometimes discourages repeat calls since the caller (usually an autodialer) thinks it connected to a fax machine.  Now open ncidd.alias in your already open gedit window.  This will create a tab for ncidd.alias.  Make the following modification:  comment out the alias for our POTS line by putting a # at the head of it.
  • #alias LINE - = POTS
Save and close gedit.

12.  You can manually add numbers to ncidd.blacklist  by editing it with sudo gedit (the documentation is at the head of the file).  Again, you may want to modify the permissions on this file to enable you to edit the file remotely through an ssh terminal window when you encounter new numbers that you want to block.  To do this, execute the following.


  • cd /etc/ncid
  • sudo chmod ugo+rw ncidd.blacklist
13.  There is a way to preload your blacklist.  The FCC has created a spreadsheet (in CSV, comma-separated-value, format) containing a week's complaints of violations of the do-not-call-list or of robocalls.  To add these numbers to your blacklist, do the following.  In your browser go to  the FCC Consumer Help Center, Consumer Complaints at the FCC, Data on Unwanted Calls.  The URL is ...

https://consumercomplaints.fcc.gov/hc/en-us/articles/205239443-Data-on-Unwanted-Calls 

Click the Download Spreadsheet Data (csv) link.  The file will go into your Downloads folder.  Move it to the ncid folder in source.  Open the file with LibreOffice Calc.  This is the spreadsheet icon on the desktop menu.  Delete all the columns except the first, containing telephone numbers.  Sort this column thus grouping all the blank lines at the top.  Delete these empty rows.  Save this file as Column1.txt.  Open the file again and delete all the columns except the second, also containing telephone numbers.  Sort this column and delete all the blank rows.  Save this file as Column2.txt.  Close LibreOffice Calc without saving the original file, keeping it intact.  Open Column1.txt and Column2.text in LibreOffice Writer (also on the Desktop menu).  Copy the contents of Column2.txt and paste them into Column1.txt - either at the head of the file or the end.  It doesn't matter.  Delete all the hyphens (these will be between the groups of numbers).  You can use the Edit>Find & Replace dialog. Insert a carat (^) at the head of each number.  You can do this also through the Edit>Find & Replace dialog.  In this dialog, select "Other options" and check-mark "Regular expressions."  In the "Search For" box enter the following.


  • [:digit:]{10} 
This will select the 10-digit numbers.  Then enter the following in the "Replace With" box.

  • ^&
This will insert a carat ("^") at the beginning of each ten digit number.   Now click "Replace All."  You will have a long list of ten digit numbers starting with a carat.  The carat is a regular expression element that tells ncid to match the number starting at the beginning only.  This regular expression ability allows you to enter groups of numbers into the blacklist.

Save the file as Column1.txt.  Be sure you keep the text (txt) format rather than an ODF format.  


 Open a terminal window and enter the following commands ....
  • cd /home/pi/Documents/source/ncid
  • sort Column1.txt | uniq blacklist
This sorts Column1.txt and pipes the result into uniq which removes duplicates. The result will be a sorted file (blacklist) with unique telephone numbers each with a leading carat.  In your terminal window use sudo gedit to add your blacklist file to the end of /etc/ncidd.blacklist.  You will now have a blacklist of over a thousand entries.  I've found that new ones are always popping up, so you will need to add to this.

14.  In your terminal window enter the following to set ncidd to run automatically after a reboot.
  • sudo update-rc.d ncidd defaults
15.  Restart ncidd:
  • sudo invoke-rc.d ncidd restart
16.  You're now almost ready to go.  Disconnect the Ethernet cable (if you have one connected) and plug the WiFi dongle into a USB port (if you haven't already done this).  In the WiFi icon in the top right menu bar, select the WiFi network to which you wish to connect, click on it, and enter any password.  You should now be re-connected to the Internet.  Look at the connection properties and determine the IP address.  This will change from time to time.  You may want to assign the Pi a permanent address.

17.  Shutdown the Pi by invoking Shutdown from the menu.  Do not just pull the plug.  Doing this may screw up a file.  Pull the monitor, keyboard, and mouse plugs.  If you want to move the Pi to another location do so now.  Plug the Zoom or US Robotics modem into the phone system (just connect the modem with a telephone cable to a wall jack).  Plug in the USB power module.  Your Pi is now booting.

18.  From another computer on the same network, connect to your Pi using ssh with the Pi's IP address (without the pointy brackets):
  • ssh -X -l pi <Pi's IP address>
The option -l specifies the user ID.  The -X option allows you to send an X-window to a remote desktop.  Remember that your password is raspberry - you'll be asked for it.  If this is the first time you've connected to the Pi, your system may ask if you really want to do this.  Tell it yes.  An example ssh connection looks like this:
  • ssh -l pi 192.168.1.108
You can transfer files to and from the Pi using sftp (sftp pi@<Pi's IP address>).  During the install, a program, cidcall, has been compiled and installed.  Run it in a terminal (e.g., your ssh window) to see what numbers have called the phone so far.  In /var/log/cidcall.log is information about each invocation of ncidd.

To test ncidI put my cell number in ncidd.blacklist then ran sudo invoke-rc.d ncidd restart to restart ncid so it would read the new blacklist info.  Then I called home.  The landline phone rang once then I got a fax tone in the cell phone. Then it hung up.  If you do this test, be sure to remember to take your number off the blacklist.  Then restart ncidd (sudo invoke-rc.d ncidd restart). 


Good luck.

Monday, June 8, 2015

LibreOffice v. OpenOffice

This is a semi-interesting story.  Since I have space limited only by my lifespan, I'll tell the long version.

Years ago, there was an "office" suite, popular in Europe, known as StarOffice.  You can read about StarOffice in Wikipedia.  Version 1.0 ran on DOS and hit the streets in 1985.  It had a nice GUI similar to what Apple developed for the Lisa (January 1983) and Macintosh (January 1984).  This GUI ran on top of DOS.  It had StarWriter, StarBase, and StarDraw.  These had pretty basic features, but, then, it ran on DOS.  You expected fast?

As an aside, Microsoft Word for DOS and Xenix (remember Microsoft's Unix version?) was released in October 1983.  This version and four subsequent versions were not very popular - nor did it have a GUI, though it was a full-screen editor.  On the other hand, WordStar was pretty popular.  We used it on CP/M-80 (so kindly ported to our custom hardware by Steve Sidner).  But the real powerhouse was WordPerfect.  Alas, through screwups by Novell (who bought WordPerfect) as well as shenanigans by Microsoft, Word, then Office, became the dominant word processing suite.  StarOffice focused on Europe and never had a big play in the US.

In 1995, StarOffice had StarWriter, StarCalc, StarDraw, StarImage, and StarChart - a pretty comprehensive set of programs each with many nice features. It ran on DOS, Windows 3.1, OS/2, Solaris SPARC, and Power Macintosh.  In 1996 they added support for Linux.  I bought a copy of StarOffice in 1997 when I kicked Microsoft out the door.  StarOffice kept their GUI despite now running on multiple platforms, each with its own GUI.  I think they might have done this because the individual programs were so tied to the GUI and perhaps, also, that it gave a common interface among all the platforms they supported.

Fast-forward to August 1999.  Sun Microsystems bought Star Division Corporation, makers of StarOffice.  We used a lot of Sun equipment back then.  It was a favorite of our customer (the Federal Government).  The fighting between Sun and Microsoft was highly amusing.  I especially liked (and agreed-with) Sun's evaluation of Microsoft and their crappy OS.  The Sun v. Microsoft lawsuit was over Microsoft's implementation of Java.  Microsoft had tried their famous and ubiquitous strategy of Embrace, Extend, and Extinguish.  The Extend part, though, was a no-no.  It was explicitly forbidden in the license.  Eventually Microsoft gave Sun a huge chunk of money and the lawsuit went away.

Sun computed that the cost of the Star Division purchase and subsequent modifications would be (as I remember) $90 million - which was quite a lot back then.  They also compared this number to what they were paying for Microsoft Office licenses and figured they would start saving money in just one year.

Sun attacked Microsoft any way they could - so long as it didn't cost them a lot.  (Even then they had cash-flow problems.) It was a pretty slick maneuver when they provided StarOffice for free over the Internet. This, of course, bypassed the need for Windows and for Microsoft Office.  StarOffice code was released as open source.  Sun had always been a major contributer to open source (e.g., Java, MySQL, and lots of others).  They named it OpenOffice and established an OpenOffice.org Web site. Sun had ditched the StarOffice GUI and released the individual programs (somewhat) independently.  I migrated away from my StarOffice package to OpenOffice. 

In 2009, Oracle bought Sun.  No one likes Oracle.  But they are efficient at making money - lots of it.  No one trusts Oracle.  Almost immediately after Oracle took over Sun, the open source developers and maintainers of OpenOffice left, took a copy of the software, and started LibreOffice.  If you look around the LibreOffice Web site, you'll find a long list of companies and organizations that support LibreOffice - both financially and with labor.  This turned out to be a good move for the software - Sun had been highly conservative about making changes to OpenOffice.  The new LibreOffice organization wanted faster development and better maintenance.  So LibreOffice quickly developed beyond what OpenOffice had been.

Oracle couldn't figure out how to make much money from OpenOffice so they gave the software to Apache, who now maintain it.  Oracle could have given the code to the new LibreOffice organization, but didn't - I think out of spite. However, changes made to OpenOffice by the Apache developers are reviewed and sometimes incorporated into LibreOffice - and vice versa.

So LibreOffice and OpenOffice are quite similar.  But you can probably find specific differences if you look.  One thing that did happen almost immediately in LibreOffice was the great improvement in the compatibility between Microsoft Office formats and LibreOffice formats.  There are probably a few problems left, but there won't be many.

Most people seem to be sticking with Microsoft Office for two reasons: FUD (fear, uncertainty, and doubt), and loathing to learn anything new - even coping with minor differences in the way you run the programs.  Plus, perhaps, the feeling that if you don't pay a lot for something, it isn't worth very much.

LibreOffice is a jewel.  I use it daily.  I like it.  It works.  It's free.

Roy