Remove ESET Management Agent / ESET Remote Administrator Agent – Batch File for GPO

I’ve got a customer who used to have an ESET Remote Administrator 6 server, and about 85 computers connected to it. That server was deprecated, but a client task was not initiated to remove the old agent first. So essentially, they ended up with 85 machines with an agent pointing to a dead server.

A new ESET Security Management Center server was deployed, and a new agent installer created. However, because ESET changed the name of the agent, installing the new ESMC agent does not in fact upgrade the old agent. So you either end up with two agents, or just remain with the old one pointing to a non-existent server.

You could go around to every workstation and manually uninstall the ERA agent. But yikes, that’d be brutal. You can’t do it unattended even, because the uninstaller asks for a password.

The customer’s site doesn’t have a password to remove it, so you just push enter. But the prompt still appears.

So I wanted to help them do this via a GPO. After all, what’s the point in having a network if you still have to treat each system as independent?

wmic product get name

This command gives me a list of all applications that can be uninstalled. I ran it on my own system and see ESET Management Agent. I have ESMC 7. I ran it on an older system we have here, and it shows “ESET Remote Administrator Agent”. So I wrote a quick batch file to remove either of those two applications.

You can find that batch file here: https://github.com/Cat5TV/eset/blob/master/uninstallers/eset-uninstall-agent.bat

I figure there are probably various names for various versions of the agent, and I’ll add them as I find them.

ESET is currently evaluating my solution, as their support team says they have been encountering this problem more and more and had yet to come up with a solution. I hope it’s able to help some folks.

Robbie // Bald Nerd

Backup a Linux machine with LVM Snapshots and rdiff-backup

Here is the completed script I wrote on Episode 461. Make sure you check out the full episode for details on how to make this work for you.

#!/bin/sh
/sbin/lvcreate -L10G -s -n lvm_snapshot /dev/ubuntu-mate-vg/root
/bin/mount /dev/ubuntu-mate-vg/lvm_snapshot /mnt/snapshot

/usr/bin/rdiff-backup -v5 --print-statistics \
  --exclude /mnt/backup/ \
  --include /mnt/snapshot/home/ \
  --include /mnt/snapshot/etc/fstab \
  --include /mnt/snapshot/var/log/ \
  --exclude '**' \
  / \
  /mnt/backup/

/bin/umount /mnt/snapshot
/sbin/lvremove -f /dev/ubuntu-mate-vg/lvm_snapshot

And of course, here is the episode:

Convert Minecraft 1.8+ Skin to 1.6/1.7/Minetest Skin in PHP

RobbieF's Minetest SkinAs we build up #ThePixelShadow on Category5 TV, and introduce a creative Minetest server specifically for playing Minetest (the free Minecraft alternative), it became apparent that our users/viewers would like to be able to have their own custom skins.

We’re making it easy with a nice little interface to upload your own skins, but part of the process requires making a skin which is compatible with sdzen’s/PilzAdam’s player_textures mod … basically, these skins are Minecraft 1.6/1.7 skins… 64×32. Great Minecraft skin creator sites such as minecraftskins.com now generate Minecraft 1.8 skin files, which are 64×64.

The difference is essentially that the skins now support overlays (eg., removable headphones or glasses) and your left and right arms and legs can have different textures. Not the case with 1.6/1.7/Minetest… so we must convert the skin file to make it compatible.

Since we’re building a web interface to do this all automatically for you and place your player skin on our server automatically, I’m building the program in PHP. Since there are a lot of tutorials out there that simply instruct you to change your canvas size to 64×32 (which is wrong – you will lose your overlays!) I thought I would share my method with you in case it comes in handy.

And hey, it’s a fun exercise in PHP/GD anyways  🙂

<?php
 // Convert Minecraft 1.8+ skin to 1.7-/Minetest skin.
 // From Robbie Ferguson // www.baldnerd.com
 // Requires PHP, GD
 // By default outputs png to browser window AND saves a file for future use. Edit below to change behaviour.
 // v1.1

 $input = './uploads/player_RobbieF.png'; // your 1.8 skin file
 $output = 'newskin.png'; // your new 1.7/Minetest skin file

 // Create image instances
 $src = imagecreatefrompng($input);
 $dest = imagecreatetruecolor(64, 32);

 // Make it transparent
 imagesavealpha($dest, true);
 $trans_colour = imagecolorallocatealpha($dest, 0, 0, 0, 127);
 imagefill($dest, 0, 0, $trans_colour);

 // Learn the dimensions of the input image
 $size = getimagesize($input);

 if ($size[0] == 64 && $size[1] == 64) { // it has Minecraft 1.8 skin dimensions - convert!
 
 // Copy - Syntax is Dest X,Y, Source X,Y, Width,Height

 // Head
 imagecopy($dest, $src, 0,0, 0,0, 32,16);
 // Head overlay
 imagecopy($dest, $src, 0,0, 32,0, 32,16);

 // Right leg, Body, Right Arm
 // The Leg and Arm become both left and right in 1.7-
 // We'll simply discard the left arm and leg since it's not used.
 // If you have an overlay on your left arm/leg but not right arm/leg, you might want to edit your skin since that will be discarded.
 imagecopy($dest, $src, 0,16, 0,16, 64,16);

 // Leg, Body and Arm overlay
 imagecopy($dest, $src, 0,16, 0,32, 64,16);

 } else { // already compatible. Just copy it.
 imagecopy($dest, $src, 0,0, 0,0, 64,32);
 }

 // Output to browser
 header('Content-Type: image/png');
 imagepng($dest);

 // Save to a file
 imagepng($dest,$output,0); // 0-9. 0=faster, 9=smaller.

 // Free up memory
 imagedestroy($dest);
 imagedestroy($src);
 
?>

If you find a good use for it in your project, please comment below. If you really love what I do, please consider supporting my Patreon profile, or throw a little something in the tip jar.

Hope to see you on #ThePixelShadow Minetest server soon, custom skin and all!

-Robbie

Make it so mountpoint can’t be written to if not mounted.

Have you ever accidentally saved files to a Linux mountpoint when the drive wasn’t mounted, and then couldn’t mount the drive thereafter? Or worse, had a backup run when the backup drive wasn’t mounted, only to fill your filesystem and crash the server?

These problems can be avoided by simply making your mountpoint immutable! What this means is, your mountpoint (the folder itself) cannot be written to. However, even as an immutable folder, it can be mounted to, and the filesystem of the mounted drive then controls the permissions of the folders therein.

It’s a simple Linux command. We’ll pretend our mountpoint is simply /mountpoint. Here’s all you have to do:

chattr +i /mountpoint

Brilliant! And oh, so simple.

Here’s a sample of what happens when I do this as root. Note that ‘mymountpoint’ is setup for me in my /etc/fstab file so it normally auto-mounts.

root@server:/# umount mymountpoint
root@server:/# chattr +i mymountpoint
root@server:/# cd mymountpoint
root@server:/mymountpoint# touch test
touch: cannot touch `test': Permission denied
root@server:/mymountpoint# mount -a
root@server:/mymountpoint# touch test
root@server:/mymountpoint#

Enjoy that little tidbit!

As a side note, you might want to also get a notification if your drive isn’t mounted… so you could use the mountpoint command to send you an email if there’s a problem. Just add something like this to your backup script:

mountpoint -q /mymountpoint || mail -s "/mountpoint is not mounted for the backup" [email protected]

That simply checks if /mountpoint is a mounted mountpoint. If yes, it does nothing. If no, it will send you an email.

-Robbie

Convert numbers to words the easy way with PHP

Sometimes we want words rather than numbers, but it used to be a very onerous task to do this. Since PHP 5.3.0 however, the NumberFormatter Class was introduced, allowing us to do this conversion quickly, with a single line of code.

A good example of the need for a this would be a business web site that says “We’ve been in business for 18 years.” To keep the site current, they’re doing echo ‘We\’ve been in business for ‘ . (date(‘Y’) – 1997) . ‘ years.’; It would look much better to say “We’ve been in business for eighteen years. This bit of code will do that for you.

Search Goblin Number to Words in PHP Screenshot

With the new Number to Words in PHP system at Search Goblin (my little helper script site), you can enter any number and the script will be demonstrated for you, converting your number to plain text. The code is provided there so you can start using this technique on your own site.

Check it out: https://searchgoblin.com/php-numbertowords/

Convert video to several JPG images on Linux without ffmpeg.

These days I just use this command and hit CTRL-C when the video frames (V:) stop moving:

mplayer -vo jpeg:outdir=screenshots -sstep 10 filename.mp4

But, this post remains for the sake of historical record – lol!


I admit… I do love PHP in the command line. Does that make me a bad person? 😉

Here’s a tiny little script that I wrote to create many JPG screenshots of a video file. I use this each week to create a bunch of stills from our broadcast so I can use them as thumbnails and so-on. I didn’t want it to depend on ffmpeg since I don’t have that on any of my modern systems.

It requires just three packages: mplayer mediainfo php-5

Save it as whatever.php and run it like this: php whatever.php file.wmv

It will create a folder called file-Screenshots/ and will save one picture per 10 seconds for any video source. Just change “file.wmv” to the name of your video. Include the path if it’s not in the current folder.

<?php
  // Depends: mplayer mediainfo
  // Does not need ffmpeg (deprecated)

  if ($_GET) {
    $file = $_GET['file'];
  } else {
    $file = $argv[1];
  }
  
  if (strlen($file) < 3) exit('Need a proper filename for input.' . PHP_EOL);  
  $dir = array_shift(explode('.',$file)) . '-Screenshots';

  $duration = duration($file);
  echo 'Duration in Seconds: ' . $duration . PHP_EOL;
  echo 'Saving to folder:    ' . $dir . PHP_EOL;
  echo 'Creating ' . ($duration/10) . ' JPG images from source...';
  exec('mplayer -vo jpeg:outdir=' . $dir . ' -sstep 10 -endpos ' . ($duration-2) . ' ' . $file . ' > /dev/null 2>&1');
  echo ' Done.' . PHP_EOL; 

  function duration($file) {
    if (file_exists($file)) {
      exec('mediainfo -Inform="Audio;%ID%:%Format%:%Language/String%\n" ' . $file . ' | grep -m1 Duration | cut -d\':\' -f2',$result);
      $tmp = explode('h',$result[0]);
      $seconds = ((intval($tmp[0]*60)+intval($tmp[1]))*60);
      return intval(trim($seconds));
    } else {
      exit('File ' . $file . ' not found.' . PHP_EOL);
    }
  }
?>

Hope it helps you out.

-Robbie

Automated cache-buster on images in PHP

I have a particular site I manage where one particular image (a grid of sponsors) gets updated quite regularly.

Rather than edit my source code each time I upload a new image, I thought I’d let PHP do the work for me.

<img class="img-responsive" src="images/sponsors/silver.jpg?<?= date('U',filemtime('images/sponsors/silver.jpg')) ?>" />

Now, every time I upload a new image, replacing silver.jpg, it will automatically update the image in the users’ cache.

Just a silly little time saver.

Note: I wouldn’t do this on every image on a site since it means an extra hit to the filesystem. That could mean a performance drop if a site is checking the filemtime of 100 images. In my case, it’s just a single image, so it’s okay.

Unify Theme ERROR! on CAPTCHA form.

For the life of me, I couldn’t figure out why the Sky Forms CAPTCHA was showing ERROR! on my Unify Theme Bootstrap 3 deployment.

Turns out this was just a rookie mistake… I wasn’t looking closely enough at the “how it works” and I was missing some code from the demo-contacts.php sample file that was crucial to the operation of the CAPTCHA. This code generates the CAPTCHA itself and stores it in SESSION data. Since it was missing, the CAPTCHA system’s image.php was turning out an ERROR!

// Make the page validate
ini_set('session.use_trans_sid', '0');

// Create a random string, leaving out 'o' to avoid confusion with '0'
$char = strtoupper(substr(str_shuffle('abcdefghjkmnpqrstuvwxyz'), 0, 4));

// Concatenate the random string onto the random numbers
// The font 'Anorexia' doesn't have a character for '8', so the numbers will only go up to 7
// '0' is left out to avoid confusion with 'O'
$str = rand(1, 7) . rand(1, 7) . $char;

// Begin the session
session_start();

// Set the session contents
$_SESSION['captcha_id'] = $str;

That $_SESSION[‘captcha_id’] is what the image.php file is looking for. If it doesn’t find it, ERROR!

Refresh, and we’re good to go!

-Robbie

Calculate the size of a VARBINARY field required for AES_ENCRYPT

Here’s a simple Open Document Format spreadsheet tool to help you calculate 16 × (trunc(string_length / 16) + 1) without having to be a mathematical genius.

Download: AES_ENCRYPT Size Calculator

You can use an ODS compatible spreadsheet program such as LibreOffice or OpenOffice.

Why you may desire to use VARBINARY() instead of VARCHAR(), see this great post from Mahmud Ahsan: http://thinkdiff.net/mysql/encrypt-mysql-data-using-aes-techniques/

Preventing rsync from doubling–or even tripling–your S3 fees.

Using rsync to upload files to Amazon S3 over s3fs?  You might be paying double–or even triple–the S3 fees.

I was observing the file upload progress on the transcoder server this morning, curious how it was moving along, and I noticed something: the currently uploading file had an odd name.

My file, CAT5TV-265-Writing-Without-Distractions-With-Free-Software-HD.m4v was being uploaded as .CAT5TV-265-Writing-Without-Distractions-With-Free-Software-HD.m4v.f100q3.

I use rsync to upload the files to the S3 folder over S3FS on Debian, because it offers good bandwidth control.  I can restrict how much of our upstream bandwidth is dedicated to the upload and prevent it from slowing down our other services.

Noticing the filename this morning, and understanding the way rsync works, I know the random filename gets renamed the instant the upload is complete.

In a normal disk-to-disk operation, or when rsync’ing over something such as SSH, that’s fine, because a mv this that doesn’t use any resources, and certainly doesn’t cost anything: it’s a simple rename operation. So why did my antennae go up this morning? Because I also know how S3FS works.

A rename operation over S3FS means the file is first downloaded to a file in /tmp, renamed, and then re-uploaded.  So what rsync is effectively doing is:

  1. Uploading the file to S3 with a random filename, with bandwidth restrictions.
  2. Downloading the file to /tmp with no bandwidth restrictions.
  3. Renaming the /tmp file.
  4. Re-uploading the file to S3 with no bandwidth restrictions.
  5. Deleting the temp files.

Fortunately, this is 2013 and not 2002.  The developers of rsync realized at some point that direct uploading may be desired in some cases.  I don’t think they had S3FS in mind, but it certainly fits the bill.

The option is –inplace.

Here is what the manpage says about —inplace:

This option changes how rsync transfers a file when its data needs to be updated: instead of the default method of creating a new copy of the file and moving it into place when it is complete, rsync instead writes the update data directly  to  the destination file.

It’s that simple!  Adding –inplace to your rsync command will cut your Amazon S3 transfer fees by as much as 2/3 for future rsync transactions!

I’m glad I caught this before the transcoders transferred all 314 episodes of Category5 Technology TV to S3.  I just saved us a boatload of cash.

Happy coding!

– Robbie