Skip to content

Instantly share code, notes, and snippets.

@TomCan
TomCan / gist:9ab3234948a73859a5660d558b10bb3f
Created January 18, 2024 09:15
Debian 12 NTP alternative using systemd-timesyncd
# install systemd-timesyncd
apt-get install systemd-timesyncd
# configure NTP server, or keep defaults
nano /etc/systemd/timesyncd.conf
# restart daemon
systemctl restart systemd-timesyncd
# check service status
systemctl status systemd-timesyncd
@TomCan
TomCan / get-key.php
Last active September 12, 2023 18:21
Convert public part of OpenSSL RSA private key to SSH authorized_keys format
<?php
function encodeMPINT($binary)
{
// If the most significant bit is set, prepend a zero byte to make it positive
if (ord($binary[0]) & 0x80) {
$binary = "\x00".$binary;
}
// Encode the length as a 32-bit big-endian integer
@TomCan
TomCan / matchkeys.sh
Created March 21, 2023 15:45
Match SSH key fingerprints from auth.log with authorized_keys file
#
# Get loglines from /var/log/auth.log containing accepted SSH key hashes.
# Then match that hash with the keys in the users' authorized_keys file.
#
# Caveats:
# - Expects specific format of auth.log, only tested on Debian
# - Expects authorized_keys to be in .ssh/authorized_keys in user homefolder
# - Uses eval to get home folder (potentially insecure)
#
while read -r D1 D2 D3 U K; do
@TomCan
TomCan / gist:7bd92f4a58bf5b74f469531715b20768
Last active February 18, 2022 08:44
Fixing unusable table due to "ERROR 1709 (HY000): Index column size too large. The maximum column size is 767 bytes."
If you find yourself locked in a situation where you can't do anything on a table (not even select) when getting
```ERROR 1709 (HY000): Index column size too large. The maximum column size is 767 bytes.```
then this on is for you.
Cause: Your key field is utf8mb4, which uses 4 bytes per character, and row_format isn't set to Dymanic.
Problem: you can't do anything with the table data (SELECT, UPDATE, DELETE,ALTER,DROP,...
Solution:
- stop mysqld and start mysqld in debug mode through (/usr/bin/mysqld-debug)
- connect to mysql, and set debugging options:
@TomCan
TomCan / mysql-group-replication-docker.sh
Created September 24, 2021 06:39
Setting up MySQL group replication in docker
#!/bin/bash
#
# This will create and setup a MySQL group replication cluster with a given number of members.
# Set the number of members below, and then execute this file. You probably want at least 3 members.
#
# This will create volumes and containers named mysql-X, where X is the number of the member.
# If you currently have volumes with the same name, these might be destroyed!
#
MEMBERS=3
@TomCan
TomCan / reverse-proxy-rewrite-content
Created September 2, 2021 07:13
Apache reverse proxy with content rewrite
#
# use case: Reverse proxy for system that returns fully-qualified URLS in the content (eg. wsdl file)
#
# Requires: mod_proxy, mod_proxy_http and mod_substitute
#
ProxyPass / http://backend-server/Some/API/On/Some/Path/
ProxyPassReverse / http://backend-server/Some/API/On/Some/Path/
# Rewrite URLs in wsdl
@TomCan
TomCan / lowercase.conf
Created June 16, 2021 11:21
Rewrite to lowercase
# Apache Rewrite all requests to lowercase URLs
RewriteEngine On
RewriteMap lc int:tolower
RewriteCond %{REQUEST_URI} [A-Z]
RewriteRule (.*) ${lc:$1} [R=301,L]
@TomCan
TomCan / listsites.ps1
Last active June 11, 2021 10:46
Powershell: list IIS websites with state and bindings
Foreach ($Site in get-website) {
Foreach ($Bind in $Site.bindings.collection) {
Write-Host $Site.name ":" $Site.state ":" $Bind.Protocol ":" $Bind.BindingInformation
}
}
@TomCan
TomCan / websocket.sh
Last active October 9, 2020 10:57
Check websocket connection (eg. from monitoring software)
#!/bin/bash
#
# Check a websocket connection with curl. Pass URL to check as parameter.
# In normal conditions, this should return a 101 (Switching protocol).
#
CODE=$(timeout 3 curl -s --http1.1 \
--include \
--no-buffer \
--header "Connection: Upgrade" \
@TomCan
TomCan / ssh-association.sh
Created November 22, 2019 08:10
xdg-open ssh://
xdg-mime default ssh.desktop x-scheme-handler/ssh
cat << EOF > ~/.local/share/applications/ssh.desktop
[Desktop Entry]
Version=1.0
Name=SSH Launcher
Exec=bash -c '(URL="%U" HOST="\${URL:6}"; ssh \$HOST); bash'
Terminal=true
Type=Application
Icon=utilities-terminal
EOF