Skip to content

Instantly share code, notes, and snippets.

@angely-dev
angely-dev / .htaccess
Created Oct 7, 2022
.htaccess redirect http2https and nonwww2www (meeting HSTS requirements)
View .htaccess
#
# As required by HSTS, two redirects:
# 1) http2https (MUST be first)
# 2) nonwww2www
#
# https://webmasters.stackexchange.com/questions/84757/htaccess-redirect-non-www-to-www-with-ssl-https
#
RewriteCond %{HTTPS} off
RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{HTTP_HOST} !^www\.
@angely-dev
angely-dev / ssh-autocomplete
Last active Oct 10, 2022
Autocomplete SSH, SCP, ping, ..., based on known hosts.
View ssh-autocomplete
#!/usr/bin/env bash
get_ssh_known_hosts() {
known_hosts=$(cat ~/.ssh/known_hosts | cut -d' ' -f1)
starts_with=$2
COMPREPLY=( $(compgen -W "$known_hosts" -- "$starts_with") )
return 0
}
complete -F get_ssh_known_hosts ssh scp ping nslookup my-custom-command
@angely-dev
angely-dev / freeradius-translate-attributes
Last active Oct 14, 2021
Translate RADIUS attributes from one vendor (say, Cisco) to another one (say, Huawei), using FreeRADIUS and a custom module (UNLANG).
View freeradius-translate-attributes
#
# /etc/freeradius/policy.d/cisco2huawei
#
# Attributes adaptation from Cisco to Huawei.
#
cisco2huawei {
foreach &reply:Cisco-AVPair {
if ("%{Foreach-Variable-0}" =~ /ip:vrf-id=(.*)/) {
#
# Adapt the VRF attribute.
@angely-dev
angely-dev / freeradius-lns-load-balancing
Last active Oct 19, 2022
Load balancing between LNS (L2TP), using FreeRADIUS and a custom module (UNLANG).
View freeradius-lns-load-balancing
#
# /etc/freeradius/policy.d/lns_load_balancing
#
# Random load balancing between two LNS.
# Note: the same LNS can be returned twice in a row.
# If it's an issue, feel free to use a non-binary rand interval (e.g., rand:9 instead of rand:2)
# and adapt below conditions (e.g., 0..4 is first LNS, 5..9 is second LNS).
#
lns_load_balancing {
#
@angely-dev
angely-dev / freeradius-force-accept
Created Oct 14, 2021
Force accept a RADIUS user, using FreeRADIUS and a custom module (UNLANG).
View freeradius-force-accept
#
# /etc/freeradius/policy.d/force_accept
#
# Force accept a user.
#
# Two scenarios:
# - the user does NOT exist in the database => trigger FORCE-ACCEPT-USERNAME-NOT-FOUND
# - the user does exist but password is incorrect => trigger FORCE-ACCEPT-PASSWORD-INCORRECT
#
# This can be implemented with two modules, called at different sections in the FreeRADIUS sequence.
@angely-dev
angely-dev / logger-exithandler.py
Last active Sep 3, 2021
Python logging exit on error or critical levels
View logger-exithandler.py
import logging
import logging.handlers
import sys
#
# The logger and the logging level
#
logger = logging.getLogger('mylogger')
logger.setLevel(logging.DEBUG)
@angely-dev
angely-dev / logger-username.py
Last active Sep 2, 2021
Python logging current username
View logger-username.py
import coloredlogs # OPTIONAL (see end of the file)
import getpass
import logging
import logging.handlers
#
# The logger and the logging level
#
logger = logging.getLogger('mylogger')
logger.setLevel(logging.DEBUG)
@angely-dev
angely-dev / ripe-bulk-update.py
Created Dec 10, 2020
RIPE API bulk update of attributes (maintainer and contact)
View ripe-bulk-update.py
import argparse
import requests
import urllib
#
# Usage
#
parser = argparse.ArgumentParser(description='RIPE bulk update of attributes')
parser.add_argument('--mntner', help='the current maintainer username', required=True)
parser.add_argument('--passwd', help='the current maintainer password', required=True)
parser.add_argument('--commit', help='to commit the RIPE bulk changes', action='store_true')
@angely-dev
angely-dev / raw2pcap.py
Created Feb 13, 2020
Convert Huawei capture-packet output to Wireshark.
View raw2pcap.py
from os import remove
from re import search
from scapy.all import *
import argparse
# Usage
parser = argparse.ArgumentParser(description='Convert raw Huawei hex packets to cap file.')
parser.add_argument('--raw-file', help='the raw file location (source)', default='raw.txt')
parser.add_argument('--cap-file', help='the cap file location (destination)', default='cap.pcap')
args = parser.parse_args()