Category Archives: command line

Command Line JSON

I just stumbled across a wonderful tool: command line JSON validation/pretty-print.

https://docs.python.org/3/library/json.html#module-json.tool

I often work with JSON with our routers. I use curl to read from our API endpoints which return JSON. Getting back large blobs of JSON is useful but hard to read all jumbled together.

% curl –basic –user admin:${CP_PASSWORD} http://172.16.22.1/api/status/wlan/radio/0

Command line output of router wifi survey api output.

Now instead I can pipe to python3 -m json.tool and the JSON will be cleanly formatted and humanly readable.

autoreconf

I love GNU autoconf. I remember the days of downloading a .zip or a .tar.Z of source and having to manually edit a config.h, full of symbols I didn’t understand. GNU autoconf came along and now we just ./configure && make && make install.

Building Kismet from source, I had a difficulty with libusb which is not installed on my linux laptop. I hadn’t installed libusb because I hadn’t needed it yet. Building Kismet on another machine worked fine (libusb installed).

./configure
...
checking for libusb... no
configure: error: Package requirements (libusb-1.0) were not met:

Package 'libusb-1.0', required by 'virtual:world', not found

I was curious about Kismet’s modularity. OK, probably just need to check the configure flags. Usually a properly modular program would allow me to disable USB.

% ./configure --help...
 --disable-usb Disable libUSB support
...

However, “./configure -disable-usb” still gave me the libusb error. Puzzling. I finally noticed the ./configure was reporting an error, right after starting.

% ./configure --disable-usb
configure: WARNING: unrecognized options: --disable-usb
...

Debugging the generated configure script is a pain. Time to dust off my ancient autoconf knowledge. The configure script starts with the configure.ac. I opened that up and searched for the disable-usb;

AC_ARG_ENABLE(libusb,
  AS_HELP_STRING([--disable-usb], [Disable libUSB support]),

The help string is there. But why doesn’t it work? Is it something simple?

 AC_ARG_ENABLE(libusb,
- AS_HELP_STRING([--disable-usb], [Disable libUSB support]),
+ AS_HELP_STRING([--disable-libusb], [Disable libUSB support]),

It might be this simple. Now how do I rebuild the configure script from the configure.ac? It’s been a long time but I remember a magic ‘autoreconf’.

% sudo dnf install autoconf automake
% autoreconf

The autoreconf failed with a complaint about AC_PYTHON_MODULE macro. (I’ve lost the actual message to the mists of scrollback.) Autoconf is built around m4. A quick Google search for AC_PYTHON_MODULE leads to an m4 macro library: https://www.gnu.org/software/autoconf-archive/

Download the tarball, ./configure && make && make install and then try autoreconf again. Works! git diff shows the Kismet configure script updated. Run the configure again with –disable-libusb and no complaints.

 

Download your Yahoo Email, Unix Edition

First Off.

I am providing this information because I found it useful. I was inspired by Iain Thompson of The Register (http://www.theregister.co.uk/Author/2395/) to retrieve and delete my 15+ years of email.

Disclaimer: Computers suck. Also, I could be a complete idiot. I’m just some rando blog on the internets. Do the following at your own risk and please don’t hurt me if something goes wrong.

Prepare Your Account

https://login.yahoo.com/account/security

Disable Two-Step Verification

Enable “Allow apps that use less secure sign in”.

screen-shot-2016-10-10-at-7-51-42-am

Remember to turn them back once email download is done. Then delete your Yahoo account anyway.

Requirements.

Need to have fetchmail and maildrop installed. I’m an Ubuntu user so I just did:

sudo apt install fetchmail maildrop

 

fetchmail

~/.fetchmailrc

poll pop.mail.yahoo.com
   service 995
   protocol POP3
   user "myemail@yahoo.com"
   ssl
   password "mypassword"
   fetchall
   mda "/usr/bin/maildrop"

Verify with ‘fetchmail -v -c’  (verbose and check). Should see a successful login to your Yahoo email.

NOTE: fetchmail’s default behavior over POP3 is to *DELETE* your email once retrieved. I’ve left this behavior in place. If that’s not what you want, consult the fetchmail man page.

Maildrop

/etc/droprc

Enable DEFAULT=”$HOME/Maildir” to push mail straight to my account instead of through a MDA.

~/.mailfilter

Not needed.

Build a Maildir

From home directory, run

maildirmake.maildrop Maildir

Will create the necessary Maildir tree. Use Maildir rather than mbox format because writing to a single file (mbox) is risky; could be corrupted in event of a crash. Maildir writes every email to a separate file.

Test Test Test!

Run  fetchmail -v -B 1

Will fetch verbose ONE message for testing the configuration. Should see login and one message downloaded. (deep-thought is my hostname)

Here’s me after downloading three messages:

…deep-thought:~% find Maildir

Maildir
Maildir/cur
Maildir/new
Maildir/new/1476108117.M788587P6060V0000000000000801I0000000002F42B11_0.deep-thought,S=34486
Maildir/new/1476107958.M23066P5120V0000000000000801I0000000002F42B10_0.deep-thought,S=49456
Maildir/new/1476107905.M287749P5102V0000000000000801I0000000002F42B0F_0.deep-thought,S=25386
Maildir/tmp

 

Release the Hounds.

Let’s go for it. Run

fetchmail -v | tee log.txt

|tee log.txt to save a log of the run in case anything goes wrong.