Skip to content

Instantly share code, notes, and snippets.

#!/bin/bash
# don't use this if all your need is a route that goes through your ISP router
# instead of an openvpn tunnel. OpenVPN has this as a built-in feature!
if [ "$EUID" -ne 0 ]
then echo "Please run as root"
exit 1
fi
#!/bin/bash
# https://gist.github.com/koenpunt/40c0b042c453a1add0e8
#
# Check if the user is in the right group
# and afterwards retrieve the SSH public key from LDAP
# Logs directly in Syslog
# requires ldap-utils
#
# sshd_config for OpenSSH 6.2 or higher:
#
@app.get("/sse/stream")
async def stream(req: Request, channel: str = "default", redis: Redis = Depends(depends_redis)):
# return EventSourceResponse(subscribe(channel, redis))
async def event_publisher():
_log.info(f"Subscribing for client {req.client}")
(channel_subscription,) = await redis.subscribe(channel=Channel(channel, False))
try:
from queue import Queue
from collections import defaultdict
class Publisher(object):
"""
Contains a list of subscribers that can can receive updates.
Each subscriber can have its own private data and may subscribe to
different channel.
"""
import asyncio
import uvicorn
from starlette.applications import Starlette
from starlette.requests import Request
from starlette.responses import HTMLResponse
from starlette.routing import Route
from sse_starlette.sse import EventSourceResponse, unpatch_uvicorn_signal_handler
# unpatch_uvicorn_signal_handler() # if you want to rollback monkeypatching of uvcorn signal-handler
#!/usr/bin/env python3
import ipaddress
from SPF2IP import SPF2IP
ignore_list = set({'127.0.0.1/32'})
ignore_list.update({ # Microsoft O365
'40.92.0.0/15',
import logging
import ssl
import uuid
from urllib.parse import urlparse
from cryptography import x509
from cryptography.hazmat.backends import default_backend
from django.db import models
from django.utils.functional import cached_property
#!/usr/bin/env bash
# parse-usb-devices.sh
#
# Parse the output of the "usb-devices" bash script and filter
# only for Mass Storage devices (Class 08). Include the active
# device speed (to see whether it is USB2 or USB3.
set -e
from channels.auth import AuthMiddlewareStack
from channels.db import database_sync_to_async
from django.contrib.auth import get_user_model
from django.contrib.auth.models import AnonymousUser
from django.http.cookie import parse_cookie
@database_sync_to_async
def get_user(token_key):
try:
#!/bin/bash
# store values from environment
env_IP2TOR_SHOP_URL=${IP2TOR_SHOP_URL-notset}
env_IP2TOR_HOST_ID=${IP2TOR_HOST_ID-notset}
env_IP2TOR_HOST_TOKEN=${IP2TOR_HOST_TOKEN-notset}
# if config file exists use it (but vars set from environment overwrite file vars)
if [ -f /etc/ip2tor.conf ]; then
unset IP2TOR_SHOP_URL