Skip to content

Instantly share code, notes, and snippets.

@alvarow
alvarow / openssl-cheat.sh
Last active April 11, 2024 04:30
OpenSSL and Keytool cheat sheet
# Generate a new key
openssl genrsa -out server.key 2048
# Generate a new CSR
openssl req -sha256 -new -key server.key -out server.csr
# Check certificate against CA
openssl verify -verbose -CApath ./CA/ -CAfile ./CA/cacert.pem cert.pem
# Self Signed
@alvarow
alvarow / squid-xff-log.conf
Created February 9, 2017 21:49
Sets Squid Proxy to log IP address from X-Forwarded-For header instead of the real client ip address if the X-Forwarded-For header exists.
# Has XFF header with a value
acl has-xff req_header X-Forwarded-For ^(([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)|(\[([0-9a-f]+)?:([0-9a-f:]+)?:([0-9a-f]+|0-9\.]+)?\]))
# default logformat
logformat squid %ts.%03tu %6tr %>a %Ss/%03>Hs %<st %rm %ru %[un %Sh/%<a %mt
# default logformat using XFF instead of client IP address
logformat squid-xff %ts.%03tu %6tr %{X-Forwarded-For}>h %Ss/%03>Hs %<st %rm %ru %[un %Sh/%<a %mt
@alvarow
alvarow / aws-cli-ecs-cheat.sh
Created February 9, 2017 17:55
My AWS CLI ECS cheat sheet
# Get number of running containers of a service
aws --profile saml --output json ecs describe-services --cluster DIT-DMZ --service adp-e-bot-kafka | jq '.services[]|.desiredCount'
# Get a list of all task definitions
aws --profile saml --output text ecs list-task-definition-families
# Get the JSONs of a task definition
aws --profile saml --output json ecs describe-task-definition --task-def DIT-adp-e-bot | jq '.taskDefinition|if .networkMode then {family: .family, volumes: .volumes, containerDefinitions: .containerDefinitions, networkMode: .networkMode} else {family: .family, volumes: .volumes, containerDefinitions: .containerDefinitions} end'
# Get all task definition and save each as a JSON
@alvarow
alvarow / letsencryt-subsonic.md
Created August 20, 2018 15:49
Using Let's Encrypt SSL with Subsonic
@alvarow
alvarow / print-headers.jsp
Last active April 10, 2020 20:13
Print HTTP request headers in JSP
<%@ page import="java.util.*" %>
<html>
<head>
<title>Http Request Headers Example in JSP</title>
</head>
<body>
<h2>HTTP Request Headers Received</h2>
<table>
@alvarow
alvarow / openssl-file-encrypt.sh
Created October 24, 2017 13:20
Encrypts & Decrypts single files using OpenSSL
# Source it on .bash_profile
# run with "encrypt a.file" or "decrypt a.file.aes-128-cbc"
# You can adjust encryption cipher (say aes-256-cbc) to your needs
function encrypt() {
if [ $# -eq 0 ]; then
echo "Provide a filename to encrypt"
exit 1
fi
# SHA256 the given file
openssl dgst -sha256 "$1" > "$1.sha256"
@alvarow
alvarow / jenkins-rocket-status.py
Last active April 2, 2019 20:13
Send status of a given Jenkins build to a Rocket.chat webhook
#!/usr/bin/python2
# -*- coding: utf-8 -*-
import json
import sys
import urllib2
proxy = urllib2.ProxyHandler({ "http": "127.0.0.1:3128", "https": "127.0.0.1:3128" })
jenkinsUrl = "http://labs-jenkins/jenkins/job/"
rocketUrl ="https://your-rocket.chat/hooks/sasdfafsa"
@alvarow
alvarow / apache-xff-log.conf
Created February 9, 2017 17:48
Sets Apache Log of the X-Forwarded-For client IP address or the real client ip address if the X-Forwarded-For header does not exist.
# Log the X-Forwarded-For client IP address or the real client ip address if the X-Forwarded-For header does not exist.
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
LogFormat "%{X-Forwarded-For}i %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" proxy
SetEnvIf X-Forwarded-For "^.*\..*\..*\..*" forwarded
CustomLog "logs/access_log" combined env=!forwarded
CustomLog "logs/access_log" proxy env=forwarded
@alvarow
alvarow / tunnelbroker-update.cron
Created December 18, 2016 17:05
Crontab to update Hurricane Electric's IPv6 listed tunnel's client endpoint to the IP address making the update request.
*/15 * * * * alvaro /usr/bin/curl -q https://USERNAME:PASSWORD@ipv4.tunnelbroker.net/nic/update?hostname=TUNNELID -o /dev/null
@alvarow
alvarow / lvm2-cheat.sh
Last active August 19, 2018 15:42
Linux LVM Cheat sheet
# creates an LVM under a single device
dd if=/dev/zero of=/dev/sdb bs=512 count=64
pvcreate /dev/sdb
pvs
vgcreate timeline /dev/sdb
lvcreate -n app -l 100%FREE timeline
mkfs.xfs -L APP /dev/timeline/app
echo '/dev/timeline/app /app xfs noatime 1 2' >> /etc/fstab
mkdir -p /app && mount /app