View tree.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from json import JSONEncoder | |
# | |
# Node class: it just consists of a name and a list of children. | |
# | |
class Node: | |
def __init__(self, name: str): | |
self.name = name | |
self.children = [] |
View .htaccess
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# 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\. |
View ssh-autocomplete
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
View freeradius-translate-attributes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# /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. |
View freeradius-lns-load-balancing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# /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 { | |
# |
View freeradius-force-accept
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# /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. |
View logger-exithandler.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import logging | |
import logging.handlers | |
import sys | |
# | |
# The logger and the logging level | |
# | |
logger = logging.getLogger('mylogger') | |
logger.setLevel(logging.DEBUG) |
View logger-username.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
View ripe-bulk-update.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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') |
View raw2pcap.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |