Changing from GPT to MBR

Run gdisk /dev/had and type r and press enter followed by g and press enter, quit the program and restart the system.

Udgivet i Uncategorized | Skriv en kommentar

Wiping the partition table on a USB Stick in Windows

When you try to flash a Linux boot USB Stick from Windows, typically using Balena Etcher, the process will fail due to there already being partitions on the stick.

If you open up Windows Disk Management it will typically show up like this:

Windows Disk Management does not play nice with Linux Partitioned USB Sticks

The solution is to Windows program “diskpart”, by pressing Meta key + R, typing “diskpart” and pressing enter. Here you can list the hard drives in your system and select the one you which to wipe, or clean, and have it done for you, like so:

The above commands should then result in an empty partition table which you can now either partition using Windows Disk Management, or flash an image onto using Balena Etcher, to verify this you can check the partition table with Windows Disk Management:

How a cleaned partition looks in Windows Disk Management

Udgivet i Windows | Skriv en kommentar

Auto-updating timestamp column i MariaDB/MySQL

If you need a colum that will automagically show when a row was created or changed you can use the following:

 CREATE TABLE `vars` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `key` varchar(45) DEFAULT NULL,
  `value` longtext DEFAULT NULL,
  `timestamp` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
  PRIMARY KEY (`id`),
  UNIQUE KEY `key_UNIQUE` (`key`)
); 

Now try to insert some data:

MariaDB [portal]> insert into vars (`key`,`value`) values ('foo','bar');
Query OK, 1 row affected (0.010 sec)

MariaDB [portal]> select * from vars;
+----+------+-------+---------------------+
| id | key  | value | timestamp           |
+----+------+-------+---------------------+
|  1 | foo  | bar   | 2021-08-09 10:43:30 |
+----+------+-------+---------------------+
1 row in set (0.001 sec)

MariaDB [portal]>

And then change those data:

MariaDB [portal]> update vars set value = "BAR" where id=1;
Query OK, 1 row affected (0.005 sec)
Rows matched: 1  Changed: 1  Warnings: 0

MariaDB [portal]> select * from vars;
+----+------+-------+---------------------+
| id | key  | value | timestamp           |
+----+------+-------+---------------------+
|  1 | foo  | BAR   | 2021-08-09 10:44:44 |
+----+------+-------+---------------------+
1 row in set (0.001 sec)

MariaDB [portal]>

Enjoy 😉

Udgivet i Uncategorized | Skriv en kommentar

Nagios / Incinga plugin for verifying ssl certificates

#!/usr/bin/php7.3
<?php

function usage()
{
        print "Usage: check_ssl_certificate <FQDN>[:port number] <Warning Threshold> <Critical Threshold>\n";
        die();
}

# Check for parameters

if (!isset($argv))
        usage();

if (count($argv) != 4)
        usage();

list ($null, $hostname, $warning, $critical) = $argv;

$portnumber = 443; // Default

# Did we get a port number?
if (preg_match("/(.+):([0-9]+)/", $hostname, $matches)) # We got a port number
        list ($null, $hostname, $portnumber) = $matches;

# Are the thressholds numeric?
if ((!is_numeric($warning)) or (!is_numeric($critical)))
        usage();

# Fetching certificate
$get = stream_context_create(array("ssl" => array("capture_peer_cert" => TRUE)));
if (!@$read = stream_socket_client("ssl://".$hostname.":".$portnumber, $errno, $errstr, 30, STREAM_CLIENT_CONNECT, $get))
{
        print "CRITICAL: Could not connect to $hostname($portnumber): $errstr.\n";
        die(2);
}


$cert = stream_context_get_params($read);
$validTo = openssl_x509_parse($cert['options']['ssl']['peer_certificate'])["validTo_time_t"];

#calculate difference
$diff = $validTo - time();
$days = floor( $diff / 60 / 60 / 24);

# Report back to nagios
if ($days < $critical)
{
        print "CRITICAL: $hostname expires in $days days.\n";
        die(2);
}
else if ($days < $warning)
{

        print "WARNING: $hostname expires in $days days.\n";
        die(1);
}
else
{
        print "OK: $hostname expires in $days days.\n";
        die(0);
}
Udgivet i Nagios, PHP, Uncategorized | Skriv en kommentar

Fixing broken ini_parser in PHP7

The cause if this problem is a broken brain somewhere in the PHP Developer comunity, for some reason they have removed support for using hash-marks (#) for comments in PHP 7.

Theres no valid reason for this, it’s not like that character has some other meaning now, it’s just removed. It’s also pretty arrogant to try and dictate changes like this, i do not decide what format the files i need to read are in, i just need to read them – and now i cannot do that with the built in functions and needs to use ugly hacks like this:

function real_ini_parser($file)
{
    return parse_ini_string(preg_replace('/^#.*?\n/m',
                          '',file_get_contents($file)),true);
}

Yet another reason to switch to a more modern programming language!

Udgivet i Uncategorized | Skriv en kommentar

OpenVPN på FreeNAS

FreeNAS kommer med OpenVPN som en del af basedist, men den skal sættes manuelt op, der er ikke gui til det (endnu?). Ved hver reboot overskrives /etc, derfor skal persistent config oprettes i /conf/base istedet.

Opret mappen /conf/base/etc/local/openvpn og placer din .ovpn fil der.

Ret herefter /conf/base/etc/rc.conf og tilføj:

openvpn_enable="YES"
openvpn_configfile="/usr/local/etc/openvpn/vpn-profile.ovpn"

Evt. kan du teste at alting virker med:

/usr/local/etc/rc.d/openvpn status

Nu burde VPN’en komme op automatisk ved genstart.

Udgivet i Uncategorized | Skriv en kommentar

Autostart browser on Raspberry Pi

First use this approach to create a python based browser, call it browser.py and leave it in pi’s home directory.

Set up .xinitrc to contain the following:

#!/bin/sh
xset s off
xset -dpms
xset s noblack
/home/pi/loop

The first three commands disable screen-blanking and the last one runs a script called loop, which looks like this:

#!/bin/bash
while :
do
	./browser.py
done

This makes sure that the browser automaticly restarts if it crashes, or if you kill the process manually, in order to reload the website. Finally take care of permissions:

chmod 755 .xinitrc browser.py loop

Then use raspi-config to make sure that the system logs in as “pi” without waiting for password, and you’re done.

Udgivet i Uncategorized | Skriv en kommentar

Croping video with FFMPEG

# ffmpeg -i test.mp4 -vf "crop=540:305:0:388" -t 5:00 out.mp4

Crops a rectangle with the dimensions 580×304 out of test.mp4 with an offset of 0 (left) and 388 (down) into out.php and skips everything after 5 minuttes, use this for testing your cut, when sattisfied, run command without “-t 5:00” to do entire video.

Udgivet i Uncategorized | Skriv en kommentar

Manual TLS Certificate Verification

$ openssl s_client -connect server.com:443 -crlf

imaps 443

pop3s 995

https 443

Udgivet i Uncategorized | Skriv en kommentar

Irssi channel-list

First install scriptassists (https://scripts.irssi.org/)

/run scriptassist

Now install adv_windowlist

/script install adv_windowlist

Setup adv_list, heres my config:

/toggle awl_viewer
/toggle awl_mouse
/set awl_block -19
/format awl_display_header 0

Enjoy 😉

Finish up by running

/save

And finaly move adv_windowlist from .irssi/script to .irssi/scripts/autorun to run at startup 🙂

 

Note (I was told that im doing it wrong):

15:09 <+vague> mikjaer, you mean you want to remove awl_display_header? /format -delete awl_display_header then /save

Udgivet i Irssi | Skriv en kommentar