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 fastapi import Request, Response, HTTPException | |
from fastapi.exceptions import RequestValidationError | |
from fastapi.routing import APIRoute | |
from http.client import responses | |
from json import JSONDecodeError | |
from starlette.exceptions import HTTPException as StarletteHTTPException | |
from traceback import format_exc | |
from typing import Callable | |
import logging |
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 = [] |
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\. |
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 |
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. |
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 { | |
# |
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. |
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) |
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) |
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') |
NewerOlder