Skip to content

Instantly share code, notes, and snippets.

@lanbugs
lanbugs / disable_users_mattermost.py
Created April 19, 2024 13:35
Search users in AD, disable users in Mattermost which are in the wrong department
#!/usr/bin/env python3
# Disable users which are in the wrong department in Mattermost
# Written by Maximilian Thoma 2024
# Free to use for everyone :-)
# Required packages: ldap3, mattermostdriver
from mattermostdriver import Driver
from ldap3 import Server, Connection, SUBTREE, ALL
@lanbugs
lanbugs / app.py
Created April 8, 2024 19:59
APIFlask and MongoDB use of Marshmallow Schemas to read and write directly to database
from apiflask import APIFlask
from apiflask import Schema
from apiflask import fields
from bson import ObjectId
from pymongo import MongoClient
class DB():
def __init__(self, app=None):
if app is not None:
self.init_app(app)
@lanbugs
lanbugs / analyse_top5_lang.py
Created March 23, 2024 22:03
Analyze TOP 5 programming languages of a given userlist @github - Single result pie charts + total summary pie chart
import matplotlib.pyplot as plt
import requests
import os
# Analyze TOP 5 programming languages of a given userlist @GITHUB
# Single result pie charts + total summary
# Written by Maximilian Thoma 2024
# Required libs: requests, matplotlib
@lanbugs
lanbugs / create_computer_object.py
Last active September 11, 2023 15:40
Python LDAP3 and Active Directory - Collection of some snippets, helpers ....
# Create computer object in OU
# Written by Maximilian Thoma 2023
# More infos at https://lanbugs.de
from ldap3 import Connection
from ldap3.core.exceptions import LDAPException
import random
BACKEND_USER = "CN=Backend User,CN=Users,DC=ad,DC=local"
BACKEND_PASS = "SuperSecret"
@lanbugs
lanbugs / flask_ad_ldap3_auth_and_autorization.py
Created September 9, 2023 22:42
FLASK with LDAP3 authentication against active directory and authorization check for group membership
#!/usr/bin/env python3
# FLASK with LDAP3 authentication against active directory and authorization check for group membership
# Written by Maximilian Thoma 2023
# Visit: https://lanbugs.de for more ...
from functools import wraps
from flask import Flask, request, redirect, url_for, render_template, abort
from flask_login import LoginManager, UserMixin, login_user, login_required, logout_user, current_user
from ldap3 import Server, Connection, SUBTREE, SIMPLE
@lanbugs
lanbugs / subnet_merge.py
Created May 12, 2023 18:00
Subnet merge show right subnets which are not in left subnets
import sys
from netaddr import IPNetwork
from pprint import pprint
# right must be in left
def main(left_side, right_side):
with open(right_side, "r") as f:
raw_right = f.readlines()
@lanbugs
lanbugs / merge_subnets.py
Created May 12, 2023 17:58
Compress list of subnets and ips
import sys
from netaddr import cidr_merge
def main(FILE):
with open(FILE) as f:
raw_lines = f.readlines()
subnets = []
@lanbugs
lanbugs / cpl_merge.py
Created May 12, 2023 17:57
Broadcom ProxySG CPL Multimerge
import re
import yaml
from loguru import logger
import glob
from pprint import pprint
import json
from netaddr import cidr_merge
import ipaddress
@logger.catch
@lanbugs
lanbugs / cpl_delta.py
Created May 12, 2023 17:56
Broadcom ProxySG CPL Delta
import re
import sys
from loguru import logger
@logger.catch
def cpl_parser(lines):
root = {}
@lanbugs
lanbugs / netbox_webhook_listener.py
Created December 28, 2022 11:27
Netbox Webhook Listener written with APIFlask
import hmac
from apiflask import APIFlask
import logging
from flask import request
from apiflask import Schema, abort
from apiflask.fields import String, Dict, DateTime, UUID
APP_NAME = "netbox-webhook-listener"
WEBHOOK_SECRET = "secret"