Skip to content

Instantly share code, notes, and snippets.

@EinPinsel
EinPinsel / Get-CertChain.ps1
Created December 19, 2019 20:53
Get-Certificate in base64 format
function Get-CertChain {
param (
[string]$computername,
[int]$port = 443
)
#Create a TCP Socket to the computer and a port number
$tcpsocket = New-Object Net.Sockets.TcpClient($computerName, $port)
#test if the socket got connected
if (!$tcpsocket) {
@EinPinsel
EinPinsel / pihole.sh
Created October 22, 2019 14:43
PiHole HA Setup
#!/bin/bash -x
# README
:'
Credit to redditor /u/jvinch76 https://www.reddit.com/user/jvinch76 for creating the basis for this modification.
I had been thinking of a script like his to keep my primary and secondary pihole raspberry pis in sync, but could not find the motivation to create it.
/u/jvinch76 did the heavy lifting and I made changes I hope you find useful.
I modified the code to increase the frequency of the sync to every 5 minutes and reduce the file writes by using rsync to compare the files and only transfer changes.
Furthermore, gravity will be updated and services restarted only if files are modified and a sync occurs.
# Fill in details to remember them. Or use them during setup. Whatever
$address = "vpn.vpn.io"
$psk = "verysecurepsk"
Add-VpnConnection -Name "veryvpn" -ServerAddress $address -TunnelType L2tp -RememberCredential -L2tpPsk $psk -AuthenticationMethod MSChapv2 -EncryptionLevel Required
1) Check logs in /var/log/unifi/ for clear errors
2) stop unifi service (systemctl stop unifi)
3) Potentially recover the crashed mongodb database (was crashed in my case) by starting it once from cmdline with a custom data directory (mongod --dbpath /var/lib/unifi/data/db). Then check the output of it to see if the DB was recovered. If it was, continue. If there was no problem, continue.
4) Connect to the database (mongo mongodb://127.0.0.1:27017( and run the following command:
db.adminCommand( { setFeatureCompatibilityVersion: "3.4" } )
That should give you the output
{ "ok" : 1 }
5) Stop the mongodb database
function Unzip
{
param([string]$zipfile, [string]$outpath)
[System.IO.Compression.ZipFile]::ExtractToDirectory($zipfile, $outpath)
}
@EinPinsel
EinPinsel / G-Series G Keys
Last active May 4, 2017 15:52
Make F13-F18 available on a G-Series Keyboard (Apply in Profile->Scripting)
function GToFNKey(keyName)
return "F" .. (keyName + 12)
end
function OnEvent(event, arg)
if event == "G_PRESSED" then
local key = GToFNKey(arg)
PressKey(key)
end
if event == "G_RELEASED" then
@EinPinsel
EinPinsel / Microsoft.PowerShell_profile.ps1
Last active October 1, 2018 07:15
Powershell Profile for Proxy Configuration from IE
# Make install of modules a little bit more easier
$PSDefaultParameterValues['Install-Module:Scope'] = 'CurrentUser'
# For VS:Code
$ErrorActionPreference = "Silentlycontinue"
# Make the shell nice and h4x0r-style
$Shell = $Host.UI.RawUI
$Shell.BackgroundColor="Black"
@EinPinsel
EinPinsel / Upload-Mods-to-SFTP-Server.ps1
Created February 8, 2017 19:12
Upload-Factorio-Mods to a SFTP Server from Windows
# Save Factorio-Mod-Pack and probably upload it to a http server via sftp
# Assume "normal" installation
$SftpServer = 'server.blah.com'
$UserName = 'username'
$KeyFile = '$env:userprofile\key.pem' # Make sure the keyfile has no password, because posh-ssh is not ready yet
$SftpPath = '/var/www/mods.server.blah.com'
$FilePath = "$env:appdata\factorio\_mods.zip"
# Create an empty Credential-Object because reasons. (to be honest: posh-ssh is not ready yet)
# Remove duplicate lines
^(.*)(\r?\n\1)+$ -> Replace with $1
# Get the third octett of an IP-Adress:
\b\d{1,3}\.\d{1,3}\.\K\d{1,3}(?=\.\d{1,3}\b)
$Mac = "1A:2B:3C:4D:5E:6F"
$MacByteArray = $Mac -split "[:-]" | ForEach-Object { [Byte] "0x$_"}
[Byte[]] $MagicPacket = (,0xFF * 6) + ($MacByteArray  * 16)
$UdpClient = New-Object System.Net.Sockets.UdpClient
$UdpClient.Connect(([System.Net.IPAddress]::Broadcast),7)
$UdpClient.Send($MagicPacket,$MagicPacket.Length)
$UdpClient.Close()