Skip to content

Instantly share code, notes, and snippets.

@voice1
voice1 / switchvox-clear-blocked-ips.py
Last active November 23, 2021 18:19
Switchvox clear all blocked IP's
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Clear blocked IP addresses in switchvox.
Requires pyswitchvox
Feel free to adjust logger if desired.
"""
from pyswitchvox.client import Client
from fastapi import FastAPI
from fastapi.openapi.utils import get_openapi
import os
app = FastAPI()
lable_lang_mapping = {"Plain JS": "JavaScript", "NodeJS": "JavaScript"}
@app.get("/hello")
async def hello():
@lucasgrelaud
lucasgrelaud / pfsense-ldap-freeipa.md
Last active April 7, 2024 00:00
pfSense configuration for FreeIPA 4.8.0

pfSense LDAP configuration for FreeIPA 4.8.0

This is a small guide on how to configure Netgate's pfSense firewall to use the FreeIPA LDAP service.

I. FreeIPA Configuration

I.1. Create a dedicated group

The first step is to create a user group in FreeIPA to manage which user can access the pfSense admin interface. You will be able to create some others groups later if you need to get different profiles on the pfSense admin interface (full admin, vpn admin, etc...).

@stephen-mw
stephen-mw / install_python38_on_pi.sh
Last active August 22, 2023 03:55
Install python3.8 and make the system default on Raspberry Pi
#!/usr/bin/env bash
set -euo pipefail
# This script downloads, compiles, and installs python3.8 as the system default
export VERSION=3.8.5
apt install -y \
build-essential \
libbz2-dev \
@nkhitrov
nkhitrov / logger.py
Last active May 6, 2024 15:18
Configure uvicorn logs with loguru for FastAPI
"""
WARNING: dont use loguru, use structlog
https://gist.github.com/nkhitrov/38adbb314f0d35371eba4ffb8f27078f
Configure handlers and formats for application loggers.
"""
import logging
import sys
from pprint import pformat
@philippegirard
philippegirard / main.py
Created April 18, 2020 20:18
fastapi logging middleware
import logging
from fastapi import FastAPI
from uicheckapp.services import EchoService
logging.config.fileConfig('logging.conf', disable_existing_loggers=False)
logger = logging.getLogger(__name__)
app = FastAPI()
@jvtrisso
jvtrisso / blog.py
Last active July 7, 2023 02:36
Blog example showing how to integrate pydantic with the peewee ORM
import pydantic
import peewee
from playhouse.db_url import connect
from typing import List
import logging
logger = logging.getLogger('peewee')
logger.addHandler(logging.StreamHandler())
logger.setLevel(logging.DEBUG)
from typing import Optional
import base64
from passlib.context import CryptContext
from datetime import datetime, timedelta
import jwt
from jwt import PyJWTError
from pydantic import BaseModel
assumption:
/etc/openldap/ldap.conf is correct:
SASL_NOCANON on
URI ldaps://ipa.foo.com
BASE dc=foo,dc=com
TLS_CACERT /etc/ipa/ca.crt
check LDAP: