Auto-rotate images based on their Exif data with ImageMagick (BASH)

Most modern cameras will store orientation details in the EXIF data of images taken on them. So if you turn the camera portrait to take an image, software can tell that this image should be displayed portrait.

However, not all software checks the EXIF data first, so you can wind up with portrait images being displayed lying on their side in some software - this is an easy trap to fall into if your file manager does honour the EXIF data.

ImageMagick's convert command can be used to read in the EXIF data, check the orientation and then rotate the image if required.

Read more…

Automatically resolving Gluster GFID Mismatch (BASH)

GFID mismatch is something that can occur on nodes running GlusterFS, particularly after a split-brain or similar incident.

The symptoms of a GFID mismatch are I/O errors for certain files within the Gluster filesystem, and/or question marks in the output of ls. Ultimately, though within Glusters logs you'll find Gfid mismatch detected.

The technically correct way to resolve GFID mismatch is to compare mtimes for each affected GFID in order to identify which node has the most recent copy.

However, where a lot of file are affected, this may not be possible due to the time/effort required - particularly if there's a reasonable certainty that the files themselves don't differ between the nodes

This snippet provides a script which will pull affected GFIDs from the Gluster logs, resolve those GFIDs back to a path and then move that path. It should be run on all but one of your Gluster nodes

Read more…

Resolving Gluster GFIDs back to real files and directories (BASH)

When dealing with Gluster, you'll inevitably stumble across output which provides a Gluster File ID (GFID) rather than a real path - whether that's when dealing with a split-brain or when checking logs.

This script can be used to turn a GFID (such as 54fa66cc-ccdd-42f4-8eb2-6083e9121de5) back into a more recognisable path (such as /brick1/gluster/foo/bar.jpg), this can then be used to help resolve split-brain issues etc.

Read more…

Convert Hex to Dec and back again (BASH)

Hex gets used a lot, and it's more than possible to figure it out in your head - up to a point

This snippet contains 2 simple routes to convert between Hexidecimal and Decimal with a slightly modified version at the end which converts a hex string into ascii chars

Read more…

Detect when Enter is pressed within an Input Element (Javascript)

If a user presses enter on an input field in a HTML form, then by default the browser will seek out the first submit button within the parent form and then trigger that (essentially simulating the click).

In today's Javascript heavy world though, it may be that your <input> doesn't sit within a <form> and you instead want to replicate the behaviour.

This javascript snippet attaches an event handler to an element in order to detect when the Enter key is pressed within that element - most usually a text input, but it should work on any input

Read more…

Intercept Console Messages in Javascript (Javascript)

Sometimes you want to intercept messages sent to console with console.log(), console.warn() etc. This might be so that you can use the messages in a JS originated error report form, or otherwise need to make the messages available to users without needing to explain about developer tools to them

This short snippet will collect messages in an array window.logs so that you can then access the messages from other javascript functions

Certain forms of message will not be caught however. For example CORS errors, whilst visible in the console, are deliberately not made available in the DOM by the browser for security reasons.

Read more…

Extract ASCII from a packet capture Hex dump (BASH)

Just occasionally, you'll ask someone for a packet capture, and rather than being sent a PCAP you'll get sent pasted output like this:

< 2019/10/10 09:01:12.589497  length=250 from=0 to=249
 48 54 54 50 2f 31 2e 30 20 32 30 30 20 4f 4b 0d  HTTP/1.0 200 OK.
 0a                                               .
 53 65 72 76 65 72 3a 20 67 75 6e 69 63 6f 72 6e  Server: gunicorn
 2f 31 39 2e 39 2e 30 0d 0a                       /19.9.0..
 44 61 74 65 3a 20 54 68 75 2c 20 31 30 20 4f 63  Date: Thu, 10 Oc
 74 20 32 30 31 39 20 30 39 3a 30 31 3a 31 32 20  t 2019 09:01:12
 47 4d 54 0d 0a                                   GMT..
 43 6f 6e 6e 65 63 74 69 6f 6e 3a 20 63 6c 6f 73  Connection: clos
 65 0d 0a                                         e..
 43 6f 6e 74 65 6e 74 2d 54 79 70 65 3a 20 74 65  Content-Type: te
 78 74 2f 68 74 6d 6c 3b 20 63 68 61 72 73 65 74  xt/html; charset
 3d 75 74 66 2d 38 0d 0a                          =utf-8..
 58 2d 46 72 61 6d 65 2d 4f 70 74 69 6f 6e 73 3a  X-Frame-Options:
 20 44 45 4e 59 0d 0a                              DENY..
 43 6f 6e 74 65 6e 74 2d 4c 65 6e 67 74 68 3a 20  Content-Length:
 32 0d 0a                                         2..
 58 2d 43 6f 6e 74 65 6e 74 2d 54 79 70 65 2d 4f  X-Content-Type-O
 70 74 69 6f 6e 73 3a 20 6e 6f 73 6e 69 66 66 0d  ptions: nosniff.
 0a                                               .
 58 2d 58 53 53 2d 50 72 6f 74 65 63 74 69 6f 6e  X-XSS-Protection
 3a 20 31 3b 20 6d 6f 64 65 3d 62 6c 6f 63 6b 0d  : 1; mode=block.
 0a                                               .
 0d 0a                                            ..
 6f 6b                                            ok

Whilst readable, it can be less than helpful if you wanted to just extract the payload (for example)

This snippet details how to extract the Hex values and then convert to ASCII to give you a plain ASCII dump. You will get a few unprintable chars at the beginning from the TCP headers.

Read more…