Skip to content

Instantly share code, notes, and snippets.

@sanvu88
sanvu88 / purge.lua
Created February 3, 2025 04:21 — forked from rming/purge.lua
Delete NGINX cached items from a PURGE request
-- Tit Petric, Monotek d.o.o., Thu 27 Oct 2016 10:43:38 AM CEST
--
-- Delete nginx cached assets with a PURGE request against an endpoint
--
local md5 = require 'md5'
function file_exists(name)
local f = io.open(name, "r")
if f~=nil then io.close(f) return true else return false end
@sanvu88
sanvu88 / strongswan.md
Created November 18, 2024 06:42 — forked from Horat1us/strongswan.md
Configuring Site-to-Site IPSec VPN

Configuring Site-to-Site IPSec VPN on Ubuntu using Strongswan

Requirements

This instruction is tested on Ubuntu 22.04 LTS

Open ports

  • UDP 4500
  • UDP 500
  • Custom protocol 50
@sanvu88
sanvu88 / ssacli_to_json.py
Created August 27, 2024 08:44 — forked from XReyRobert/ssacli_to_json.py
ssacli_to_json.py
#!/usr/bin/env python3
import sys
import json
def parse_value(value):
try:
# Try converting to integer
return int(value)
except ValueError:
try:
@sanvu88
sanvu88 / extend-trial-jetbrains-windows.bat
Created August 16, 2024 04:27 — forked from rjescobar/extend-trial-jetbrains-windows.bat
JetBrains IDE trial reset windows
REM Delete eval folder with licence key and options.xml which contains a reference to it
for %%I in ("WebStorm", "IntelliJ", "CLion", "Rider", "GoLand", "PhpStorm", "Resharper", "PyCharm") do (
for /d %%a in ("%USERPROFILE%\.%%I*") do (
rd /s /q "%%a/config/eval"
del /q "%%a\config\options\other.xml"
)
)
REM Delete registry key and jetbrains folder (not sure if needet but however)
rmdir /s /q "%APPDATA%\JetBrains"
@sanvu88
sanvu88 / install-multi-php-debian.sh
Created May 21, 2024 15:43 — forked from jniltinho/install-multi-php-debian.sh
Install Multi PHP Debian 12
#!/bin/bash
## Install Debian/Ubuntu
## https://think.unblog.ch/en/multiple-php-fpm-versions-with-apache-on-debian-12/
## https://tecadmin.net/how-to-install-php-on-debian-11/
## https://shape.host/resources/how-to-install-multiple-versions-of-php-on-debian-with-ispconfig
apt install -y lsb-release apt-transport-https ca-certificates wget gnupg
wget -O /etc/apt/trusted.gpg.d/php.gpg https://packages.sury.org/php/apt.gpg
@sanvu88
sanvu88 / ip_blacklist.lua
Created March 20, 2024 19:16 — forked from chrisboulton/ip_blacklist.lua
Redis based IP blacklist for Nginx (LUA)
-- a quick LUA access script for nginx to check IP addresses against an
-- `ip_blacklist` set in Redis, and if a match is found send a HTTP 403.
--
-- allows for a common blacklist to be shared between a bunch of nginx
-- web servers using a remote redis instance. lookups are cached for a
-- configurable period of time.
--
-- block an ip:
-- redis-cli SADD ip_blacklist 10.1.1.1
-- remove an ip:
@sanvu88
sanvu88 / gunicorn_callbacks_for_worker_id.py
Created March 6, 2024 04:55 — forked from hynek/gunicorn_callbacks_for_worker_id.py
This is an attempt to emulate uWSGI’s uwsgi.worker_id() that ensures that I have worker IDs from 1…--workers which is useful in logging and instrumentation where changing PIDs are annoying.
import os
def on_starting(server):
"""
Attach a set of IDs that can be temporarily re-used.
Used on reloads when each worker exists twice.
"""
server._worker_id_overload = set()
@sanvu88
sanvu88 / nginx
Created December 6, 2023 13:58 — forked from knapo/nginx
nginx start-stop-daemon
#!/bin/sh
### BEGIN INIT INFO
# Provides: nginx
# Required-Start: $all
# Required-Stop: $all
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: starts the nginx web server
# Description: starts nginx using start-stop-daemon
#!/bin/bash -e
# Quick start-stop-daemon example, derived from Debian /etc/init.d/ssh
NAME=blink
DIR=/home/pi
PIDFILE=/home/pi/$NAME.pid
DAEMON=/home/pi/pi_gpio_hack.py
DAEMON_ARGS="[[31,0,37,1],[31,1,37,0]]"
STOP_SIGNAL=INT
@sanvu88
sanvu88 / iptables.sh
Created August 2, 2023 04:57 — forked from einyx/iptables.sh
Anti DDos kernel settings
### 1: Drop invalid packets ###
/sbin/iptables -t mangle -A PREROUTING -m conntrack --ctstate INVALID -j DROP
### 2: Drop TCP packets that are new and are not SYN ###
/sbin/iptables -t mangle -A PREROUTING -p tcp ! --syn -m conntrack --ctstate NEW -j DROP
### 3: Drop SYN packets with suspicious MSS value ###
/sbin/iptables -t mangle -A PREROUTING -p tcp -m conntrack --ctstate NEW -m tcpmss ! --mss 536:65535 -j DROP
### 4: Block packets with bogus TCP flags ###