Linux

Script to Rid Thyself of Autocomplete = Off in Firefox

I took some time today and wrote up a script that can be run to eliminate autocomplete=off in Firefox. It basically does the same thing as is described here, but it automates it.

The script can be run with one of five arguments:

  • You can choose to use find (--find) or locate (--locate) to find the files that need to be changed on your system;
  • You can dictate the location of the file if you want to modify a specific one or know exactly where it's located (--dictate);
  • You can choose to use the Ubuntu default location (--default); or
  • You can print the help information (--help)

Once the program is run, it will make a back up, and modify it the original versions of the file. Once that's complete, all you have to do is restart Firefox.

It has been pointed out to me by some security folks that removing autocomplete's functionality from the browser might not be the best thing, since it will allow you to save your passwords in the browser. There's some truth to that: Anything that's on your computer can be hacked. So, if you're going to use this script, use it wisely.

Here's the code. I've attached it to this message as well. Any bugs or comments are greatly appreciated.

#!/bin/bash
# a simple script to destroy autocomplete in linux installations. 
 
 
##############
# We begin with our functions, it's not efficient, but it works
##############
 
# a function to print the help message.
function printHelp {
cat <<EOF
NAME
    autocompleteDestroyer.sh
 
SYNOPSIS
    autocompleteDestroyer.sh [ --find | --default | --help | --locate | --dictate ] 
 
OPTIONS
    This program will find the nsLoginManager.js file on your computer, and will fix it so that autocomplete is disabled in your installation of Firefox. Since this program will be altering your installation of Firefox, it will require your root password. 
 
    --help     Print this help file
 
    --default  Attempt to use the default location of the files (/usr/lib/xulrunner*/components/nsLoginManager.js)
 
    --locate   Use the locate database, if installed, to find the files. This will only find the files that were added before the last time the locate database was updated (which is typically once a day). It is faster than the --find option, but might not find all versions.
 
    --find     Use the find command to locate the nsLoginManager.js files. This will search in /usr/lib by default. Edit the script if you would like to change this. This is the slowest, but most thorough option.
 
    --dictate  Allows input of a known location.
 
EXIT STATUS
    autocompleteDestroyer.sh exists with a status of 0 if it encounters no problems. An exit status of 1 means incorrect usage. An exit status of 2 indicates it was unable to find your files. An exit status of 3 indicates the user terminated the program. An exit status of 4 means it encountered problems editing your file.
 
BUGS
    If any bugs are encountered, please see michaeljaylissner.com/contact
 
AUTHOR AND COPYRIGHT
    This script was authored by Michael Lissner and is released under GNU GPLv3.
 
EOF
}
 
# takes an argument, and creates an array containing the files to be modified.
function identifyEvilFiles {
    if [ $1 == "find" ]
    then
        files=$(find /usr/lib -name nsLoginManager.js 2> /dev/null)
        if [[ ! $files ]]
        then
            # Test if files has been set.
            echo "autocompleteDestroyer.sh: No files found. Try loosening the find parameter in the script, per the help file."
            exit 2
        fi
    elif [ $1 == "default" ]
    then
        # We assume the default location of nsLoginManager.js
        files=$(ls /usr/lib/xulrunner*/components/nsLoginManager.js 2> /dev/null)
        if [[ ! $files ]]
        then
            # We didn't have any hits. Exit.
            echo "autocompleteDestroyer.sh: We didn't find anything at the default locations. Perhaps try the --locate or --find arguments."
            exit 2
        fi
    elif [ $1 == "locate" ]
    then
        # We run the locate command, see if we have any hits.
        files=$(locate -b '\nsLoginManager.js' 2> /dev/null)
        if [[ ! $files ]]
        then
            # No hits. Exit.
            echo "autocompleteDestroyer.sh: We didn't find anything using the locate command. Perhaps try the --find argument."
            exit 2
        fi
    elif [ $1 == "dictate" ]
    then
        # "Why don't you just tell me what movie you'd like to see?" --Kramer.
        read -p "Where is the file nsLoginManager.js located on your machine: " files
        if [ -f $files ]
        then
            # Good. The file exists. We press on.
            echo "Thank you. That file exists, and we will modify it."
        else
            echo "autocomplete.sh: That file doesn't seem to exist. Please try again."
            exit 2
        fi
     fi
}
 
 
 
function modifyFiles {
    echo  "The following files will be modified: 
$files "
    echo 
    read -p "Shall we proceed (y/n): " proceed
 
    if [ $proceed == "y" -o $proceed == "Y" ]
    then
        # Here we go!
        while read -r line
        do
            echo Now processing $line
            #find the function in the file, label it with FILLERWORD, then replace the first line, and delete the rest. A messy approach, but functional
            sed -i.bak '/[[:space:]]*_isAutocompleteDisabled[[:space:]]*:[[:space:]]*function.*{[[:space:]]*$/,/^[[:space:]]*},[[:space:]]*$/s/^/FILLERWORD/' $line
            sed -r -i 's/FILLERWORD.*_isAutocomplete.*/    _isAutocompleteDisabled :  function (element) { return false; },/' $line
            sed -i '/FILLERWORD/d' $line
 
            # test if it worked
            grep -i -q 'isautocompletedisabled.*return false' $line
            if [ $? != 0 ]
            then
                # something failed...probably. Tell the user
                echo "Unable to successfully edit the file. Exiting"
                exit 4
            fi
        done <<< "$files"
        echo "All the files have been processed properly. Please restart Firefox, and thanks for using this script."
        exit 0
    else
        # It appears they'd like to abort. Let's exit.
        echo "OK. You know what to do if you change your mind."
        exit 3
    fi
 
}
 
 
#initiation sequence
if [ $# -eq 0 -o $# -gt 1 ]
then 
    # We need to give them help using the program. 
    echo "autocompleteDestroyer.sh:  Invalid number of arguments."
    echo "Usage: autocompleteDestroyer.sh [ --help | --default | --locate | --find | --dictate ] "
    exit 1
elif [[ $EUID -ne 0 ]]; 
then
    echo "autoCompleteDestroyer.sh: This script must be run as root" 1>&2
    exit 1
else
    case $1 in
        --help) printHelp;;
        --find) identifyEvilFiles find; modifyFiles;;
        --default) identifyEvilFiles default; modifyFiles;;
        --locate) identifyEvilFiles locate; modifyFiles;;
        --dictate)identifyEvilFiles dictate; modifyFiles;;
        *) echo "autocompleteDestroyer.sh: Invalid argument. Try the --help argument."
           exit 1;
    esac
fi

Linux Tip - Route Standard Output Into to the Clipboard

Tagged:  

A friendly online stranger just taught me how to do something that has been plaguing me for some time. Ever since I learned how to use pipes in the unix commandline, I have wanted to know how to pipe the output of a command into the system clipboard.

For example, the echo command simply repeats whatever you tell it to. So if I run

echo hello
the computer will give me the output
hello
By using a pipe (this symbol: |) I can route the output of one command into the input of another.

For example, if I run:

echo hello | helloprogram
The helloprogram will receive the value of 'hello' as an input, and will do something with it. This allows stringing together small commands into long ones, which sometimes is incredibly handy.

Anyway, if you want to route standard output into the system clipboard, you will need to install an application called xclip. Once that is installed, a command such as:

echo hello | xclip -i -selection clipboard

will put the word hello into the clipboard. Ctrl + V will then paste that value into whatever application desired.

Thanks to aaron at http://www.cyberciti.biz/faq/linux-copying-with-middle-mouse-button/#comment-38676 for help with this question.

Ubuntu Disk Usage Analyzer

Tagged:  

One of my favorite utilities lately is the Disk Usage Analyzer that comes installed on Ubuntu. It can be run either locally or remotely.

It's pretty awesome. I have been playing with my backups lately, and this utility allows me not only to see which directories are large, but also where my files are taking up the most space. For example, the picture at right depicts my home directory. By mousing over the slices of the pie, you can see what's in them, and how big they are. By clicking on a slice, it becomes the center of the pie, and you can see which directories are within it (and how big they are).

In terms of UI, I have to say this one works very well for me. I have yet to see another app for this purpose anywhere else, though admittedly I have not been looking that hard.

My Linux Story

Tagged:  

I thought I would post a quick entry today about how I came to be a Linux user and enthusiast. I guess it's a combination of a couple things.

Historically, what happened was that I was using XP and looking at thumbnails of some pictures in their file navigator. I was looking at about 300 pictures, and I didn't want to open them all up individually (this was before useful apps like Picasa came around). I just wanted to look at the thumbnails. Except those were too small, so I wanted to make them bigger. I spent about two hours searching online to try to figure out how to make such an adjustment. Eventually, I discovered a Windows "Powertool" that you could install. It seemed like overkill, but it did the job. What bugged me though about it was that obviously it didn't require a Powertool to adjust image size. It just required a tweak of some bit of code somewhere in the system. That was my tipping point. I decided I couldn't take the viruses, the expense and the closed product anymore, and promptly decided it was time for a new OS.

So that's what brought me to Linux. What kept me here is the openness and the philosophy. Sure, at times it's a bit trickier to get certain things done, but I love the philosophy that if I want a change, I can either make it myself if I am a programmer, or I can file a feature request with the developers. Somebody will read that request, and maybe it will get integrated, if it's a good enough idea.

I also love the fact that I can download, install and run an excellent email server, and a top-notch web server. For free. Also, no viruses. Ever. Nor any anti-virus software to pay for. And did I mention the whole thing is free?

As for the day to day stuff, I really don't notice much difference. At work, I use XP, which involves using Firefox, Word, Excel and Outlook (the latter three of which my work paid good money for). At home it's Firefox, Open Office and Evolution, all of which are very similar to the Microsoft package, only with better compatibility with other programs.

The other thing I really like about my Linux system is the ability to set things up like in the previous tutorial. I did an Internet search for "Linux wake on USB", and knew exactly how to adjust the system in a matter of moments. That kind of customization is a power you just don't have in Windows.

Wake Your Computer by USB

Tagged:  

I recently began using my laptop at my desk with a USB keyboard and mouse, and I thought I would explain how to set up Ubuntu so that USB peripherals will wake up your computer from sleep mode. This is convenient if you have your laptop set up such that the lid is closed and inaccessible.

In Ubuntu, the way to set this up is to edit the file located at /proc/acpi/wakeup. To see the current contents of this file do this:

% cat /proc/acpi/wakeup
Device	S-state	  Status   Sysfs node
P0P2	  S4	 disabled  
P0P1	  S4	 disabled  pci:0000:00:1e.0
MC97	  S4	 disabled  
HDAC	  S4	 disabled  pci:0000:00:1b.0
P0P4	  S4	 disabled  pci:0000:00:1c.0
P0P5	  S4	 disabled  pci:0000:00:1c.1
P0P7	  S4	 disabled  
P0P8	  S4	 disabled  
P0P9	  S4	 disabled  
USB0	  S3	 disabled  pci:0000:00:1d.0
USB1	  S3	 disabled  pci:0000:00:1d.1
USB2	  S3	 disabled  pci:0000:00:1d.2
USB3	  S3	 disabled  pci:0000:00:1d.3
EUSB	  S3	 disabled  pci:0000:00:1d.7
P0P6	  S4	 disabled  pci:0000:00:1c.2
SLPB	  S4	*enabled
This shows you a number of devices, most of which I don't claim to understand. The ones to notice are the USB ones, which you will see are disabled by default.

Once these are toggled on, your computer will wake up from sleep when USB peripherals are used. To toggle one of these on, as root, run:

echo "USB0" > /proc/acpi/wakeup
This will toggle USB0 from disabled to enabled. To check this, run cat /proc/acpi/wakeup again. You should see that it's enabled, and you should be able to test this by suspending your computer.

This will set up your computer to wake up from USB...for now. To make it work after your computer has been restarted, you will need to write a short init script named wake.sh with the following contents:

#!/bin/bash
echo "USB0" > /proc/acpi/wakeup
Save this file to /etc/init.d, and make it executable by running:chmod +x wake.shFinally, once this file is in /etc/init.d, and is executable, as root run:update-rc.d wake.sh defaultsThat will make init know about the file, and run it at startup. Happy awakenings!

Source: http://ubuntuforums.org/showthread.php?t=711747

Install Citrix In Ubuntu Hardy Heron

Tagged:  

For a while there, I was struggling to get the Citrix client installed on my computer. It was frustrating, and I put hours into debugging it, and trying to get it to work. In the end, I took a circuitous route, installing VirtualBox in Ubuntu, Windows in VirtualBox, Firefox in Windows, and finally Citrix in Firefox.

Last week, I took another stab at getting this done, and for some reason it went very smoothly. To install Citrix in Ubuntu Hardy Heron:

  • Begin by downloading the Citrix client as a .tar.gz.
  • Next, unpack the install file using the terminal by running:
    sudo tar xvfz en.linuxx86.tar.gz
  • Change into the Citrix directory, and run
    sudo ./setupwfc
    This will begin the install script. As it proceeds, simply allow the default settings, and you should be good.
  • The final step is to install the root certificates. To do this, attempt to start a Citrix program, and it may fail, reporting an error message. In the message, it will tell you what certificates it needs installed. Go to this website, and download the certificates the error message informed you that you need by right clicking their download links, and selecting "Save as..." Once those are downloaded, rename their extension so they are .crt files, and move them to /usr/lib/ICAClient/keystore/cacerts
  • Restart Firefox, and you should be good.

Thanks to Skarh for this how to.

Drag a Screenshot Using ImageMagick

Tagged:  

I learned an interesting trick while working on the Fuji water article. We all know that if you want to take a screenshot in Linux, all you usually have to do is press the "printscreen" button. That, however, takes a screenshot of the entire screen, which you then have to trim down into a useful bit of picture.

The trick I learned to make this easy is to simply type:

import screenshot.png
That will turn your cursor into a little crosshair, which you can drag across a section of the screen.

If you want to do that after a delay, the trick is to use the sleep command like so:

sleep 10; import screenshot.png

I found this tip along with a lot of others on this blog. There are some other interesting techniques there as well.

Remap Caps Lock as Backspace in Windows and Linux

A while back my wrist started hurting from reaching for the cursed backspace key. I was making too many mistakes. My solution was to remap the caps lock key on all the computers I use to act as an additional backspace key. How did I do it? Well, I'm glad you asked. I'll tell you.

In Windows
EDIT: I noticed that the picture doesn't have all the detail you need. The easier way to do this, is to download the registry key attached to this post, and to right click it, selecting merge. After that, restart the computer, and you should be all set.

To remap the caps lock to function as a backspace key in Windows, one must edit the registry keys. To do that, go to Start > Run..., and type in regedit. In the editor that opens up, navigate to the key shown in the picture below, and create a new key named Scancode Map of the type REG_BINARY. Give it the value shown in the picture, restart, and you're set. If things get wacky, delete the key and try again.

In Linux
I have tested the following in Ubuntu 7.04, 7.10, 8.04, 8.10, and 9.04. Start by opening a terminal, and running the xev program. Once that is running, press the caps lock key, and it will tell you the numerical value of that key. For example, my output from that command looks like this:

mlissner@opal2% xev
KeyPress event, serial 28, synthetic NO, window 0x4800001,
    root 0x59, subw 0x0, time 2775892, (373,636), root:(376,685),
    state 0x0, <strong>keycode 66</strong> (keysym 0xff08, Caps_Lock), same_screen YES,
    XKeysymToKeycode returns keycode: 22
    XLookupString gives 1 bytes: (08) "
    XmbLookupString gives 1 bytes: (08) "
    XFilterEvent returns: False

In there, you will see the keycode for the capslock key, in my case, number 66. Using that, create a file in your home directory called .Xmodmap, and put the following in it:

!
! Make the caps lock button a backspace button
!
remove Lock = Caps_Lock
keycode 66 = BackSpace

Once that is done, the next time you log in, your caps lock will function as a backspace. The only remaining problem is that it still does not have the auto-repeat function that backspace should have. To fix that, run:

xset r 66

That will make things work properly, but you need to run that every time you log in, or else it won't work properly. To fix that run:
sudo gedit /etc/X11/Xsession.d/50x11-common_determine-startup

And add xset r 66 to the bottom.

That should do it.

Source: http://ubuntuforums.org/showthread.php?t=369402

Install Garmin Topo! in Linux

Tagged:  

I'm planning a quick trip out to Yosemite for next weekend, and I wanted to print out a couple of maps from Garmin Topo! beforehand. The last time I used Topo! was about four years ago, when I had Windows XP installed. I don't remember how I installed it then, but that probably means it wasn't too challenging.

This time, however, I don't have a computer running Windows except for as a virtual client within Ubuntu, so I figured that would be the best place to begin. I booted up Windows XP, popped in the CD, mounted it within the virtual client, and tried to install. No dice: some error message. I played with it for a while, and I eventually decided that for some reason, it just wasn't going to work.

My next idea was to try installing Topo! within Ubuntu via Wine (Wine Is Not an Emulator). Wine is an application that attempts (and often fails, sometimes works) to allow Windows applications a method of working within Linux. I closed down Windows, opened the install CD within Ubuntu, and double-clicked the Setup.exe file. Amazingly, the Windows Install Shield business popped up, and the installation proceeded with no problems whatsoever.

Once that was done, the only remaining step was to make myself a nice link/alias/launcher. Once it's installed, the Topo! executable is located at ~/.wine/drive_c/TOPO!/TOPO.EXE, so it's just a matter of making a link to that, and you're all done.

Personal Music Collections

Tagged:  

I was curious which artists of mine had the most songs, so I ran:

du Music/ | sort -nr | head -11

Now we know that my top ten artists are:

% du Music/ | sort -nr | head -11
17582796        Music/
490928  Music/Radiohead
378148  Music/Daft Punk
315856  Music/Red Hot Chili Peppers
313032  Music/Massive Attack
306228  Music/Kanye West
305796  Music/Outkast
289288  Music/Nirvana
276416  Music/Beck
258544  Music/Nine Inch Nails
248608  Music/Beatles, The

Syndicate content