Skip to content
Store HTML docuements as LDAP entries
Python
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.vscode
ldap2html
sample
schema
.gitignore
LICENSE
README.md
poetry.lock
pyproject.toml

README.md

ldap2html

Schemas and tools to store HTML documents in LDAP.

Sample

Requirements

  • Python 3.7 or later
  • LDAP server installed with schema

Install

You can install from PyPI.

$ pip install ldap2html

Schemas

HTML File

ObjectClass: htmlFile

  • o: Filename.

HTML Element

ObjectClass: htmlNormalElement, HTMLVoidElement (for elements without children like br)

  • ou: Element name. dn will be the id of the element!
  • htmlTagName: Tag name.
  • htmlNthChild: (Optional) Position among the children (elements and texts).

Element attributes

You can set pre-defined HTML Element attributes to LDAP elements. Each LDAP attribute is named like htmlAttr{HTMLAttribute}.

Available LDAP attributes:

  • htmlAttrClass
  • htmlAttrHref
  • htmlAttrLang
  • htmlAttrSrc
  • htmlAttrAlt
  • htmlAttrWidth

Text

ObjectClass: htmlText

  • cn: Identifier (required to set dn on LDAP, but is ignored on ldap2html).
  • htmlTextValue: Text value.
  • htmlNthChild: (Optional) Position among the children (elements and texts).

Tools

LDAP -> HTML

$ poetry run ldap2html -h
usage: main.py [-h] [-H LDAP_URI] -b SEARCH_BASE -D BIND_DN -w BIND_DN_PASSWD
               [-d DIRECTORY]

Convert LDAP entries to HTML file

optional arguments:
  -h, --help            show this help message and exit
  -H LDAP_URI, --uri LDAP_URI
                        LDAP uri
  -b SEARCH_BASE, --searchbase SEARCH_BASE
                        LDAP search base
  -D BIND_DN, --binddn BIND_DN
                        LDAP bind dn
  -w BIND_DN_PASSWD, --passwd BIND_DN_PASSWD
                        LDAP bind dn password
  -d DIRECTORY, --dir DIRECTORY
                        Target directory to save files
  -v, --verbose         Verbose output

HTML -> LDIF

$ poetry run html2ldif -h
usage: html2ldif [-h] -n DOMAIN [-d DIRECTORY] [-m] [-v] file [file ...]

Convert LDAP entries to HTML file

positional arguments:
  file                  HTML files

optional arguments:
  -h, --help            show this help message and exit
  -n DOMAIN, --domain DOMAIN
                        Domain name for HTML files
  -d TARGET_DIRECTORY, --dir TARGET_DIRECTORY
                        Target directory to save files. Default value is
                        out/ldif.
  -b BASE_DIRECTORY, --basedir BASE_DIRECTORY
                        Base (prefix) directory for html files.
  -m, --modify          Generate LDIF for ldapmodify
  -v, --verbose         Verbose output

Develop

Setup

$ pip3 install poetry
$ poetry install

Setup LDAP environment via Docker

$ docker run -p 389:389 -p 636:636 -v `pwd`:/app -v `pwd`/schema:/container/service/slapd/assets/config/bootstrap/ldif/custom \
    --env LDAP_DOMAIN="example.com" --rm --name ldap -it \
    osixia/openldap --copy-service
$ docker exec ldap2html ldapadd -x -H ldap://localhost -D "cn=admin,dc=example,dc=com" -w admin  -f /app/sample/helloworld.html.ldif

How to add HTML element attributes

  1. Add htmlAttr{AttrName} LDAP attribute in schema.
  2. Add python model mapping to LdapHTMLElement in ldap/model.py.
  3. Add python LDAP-HTML convertion mapping to ELEMENT_ATTR_DICT in ldap/model.py.
  4. Document new attributes in README.

How to bump up version

  1. Put new version in pyproject.toml
  2. git tag v{version} && git push v{version}
  3. poetry build && poetry publish
You can’t perform that action at this time.