Moved script/tool prototypes to a separated directory.

This commit is contained in:
2026-05-04 07:27:10 +02:00
parent a3f3105081
commit 1c9ba9e92c
2 changed files with 0 additions and 0 deletions

26
prototypes/login.py Normal file
View File

@@ -0,0 +1,26 @@
from getpass import getpass
from ldap3 import Server, Connection, ALL
from ldap3 import ObjectDef, AttrDef, Reader, Writer, Entry, Attribute, OperationalAttribute
import keyring
import argparse
parser = argparse.ArgumentParser(description="LDAP Test Script")
# Generic LDAP connection parameters
parser.add_argument("--host", "-H", default="gra-01.koszewscy.waw.pl", help="LDAP server host")
parser.add_argument("--port", "-p", type=int, default=389, help="LDAP server port")
parser.add_argument("--base-dn", "-b", default="dc=koszewscy,dc=waw,dc=pl", help="Base DN for LDAP operations")
parser.add_argument("--user", "-u", default="cn=admin,dc=koszewscy,dc=waw,dc=pl", help="Bind DN for LDAP connection")
# Specific parameters
parser.add_argument("--object-class", "-c", nargs='*', default=["inetOrgPerson"], help="Object class(es) to work with")
args = parser.parse_args()
server = Server(args.host, port=args.port, get_info=ALL)
password = keyring.get_password("Home Lab Password", "admin") or getpass("Password: ")
conn = Connection(server, user=args.user, password=password, auto_bind=True)
person = ObjectDef(args.object_class, conn)
print(person)
conn.unbind()

31
prototypes/search.py Normal file
View File

@@ -0,0 +1,31 @@
from ldap3 import Server, Connection, ALL
import streamlit as st
BASE_DN = "dc=koszewscy,dc=waw,dc=pl"
LDAP_HOST = "gra-01.koszewscy.waw.pl"
LDAP_PORT = 389
st.set_page_config(page_title="LDAP Search", layout="wide")
host = st.text_input("Host", LDAP_HOST)
port = st.number_input("Port", value=LDAP_PORT, step=1)
bind_dn = st.text_input("Bind DN", f"cn=admin,{BASE_DN}")
password = st.text_input("Password", type="password")
base_dn = st.text_input("Base DN", BASE_DN)
search_filter = st.text_input("Filter", "(objectClass=*)")
if st.button("Search"):
server = Server(host, port=port, get_info=ALL)
conn = Connection(server, user=bind_dn, password=password, auto_bind=True)
ok = conn.search(
search_base=base_dn,
search_filter=search_filter,
attributes=["*"]
)
if ok:
st.write(f"Entries: {len(conn.entries)}")
for e in conn.entries:
st.code(e.entry_to_ldif())
else:
st.error(conn.result)
conn.unbind()