Skip to content

Commit

Permalink
ADD LDAP configuration script
Browse files Browse the repository at this point in the history
  • Loading branch information
eLBati committed Apr 10, 2024
1 parent 3b7567e commit b69d080
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 11 deletions.
11 changes: 0 additions & 11 deletions imageroot/actions/configure-module/40ldap

This file was deleted.

3 changes: 3 additions & 0 deletions imageroot/actions/configure-module/80start_services
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,6 @@ exec 1>&2
# Enable and restart the service
systemctl --user enable odoo.service postgres.service odoo-app.service
systemctl --user restart odoo.service postgres.service odoo-app.service

# Let services be responsive, to run 90ldap
sleep 10
9 changes: 9 additions & 0 deletions imageroot/actions/configure-module/81requirements
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/bash

set -e

# Redirect any output to the journal (stderr)
exec 1>&2

# Requirement for LDAP
pip install OdooRPC==0.10.1
59 changes: 59 additions & 0 deletions imageroot/actions/configure-module/90ldap
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import json
import sys
import os
import odoorpc
from agent.ldapproxy import Ldapproxy

# Try to parse the stdin as JSON.
# If parsing fails, output everything to stderr
data = json.load(sys.stdin)

# setup PG values
odoo_host = data.get("odoo_host", "localhost")
odoo_port = os.environ["TCP_PORT"]
odoo_user = data.get("odoo_user", "admin")
odoo_password = data.get("odoo_password", "admin")
odoo_db_name = data.get("odoo_db_name", "odoo")

# Setup LDAP values
ldap_domain = data.get("ldap_domain", "127.0.0.1")
lp = Ldapproxy()
domain = lp.get_domain(ldap_domain)

ldap_server = domain.get("host")
ldap_server_port = domain.get("port")
ldap_tls = False

# Account utente sul server LDAP, utilizzato per interrogare la directory.
# Lasciare vuoto per connettersi in modo anonimo
ldap_binddn = domain.get("bind_dn")

# Password dell'account utente sul server LDAP, utilizzata per interrogare la directory
ldap_password = domain.get("bind_password")

# DN dell'ambito di ricerca dell'utente: tutti i discendenti di questa base verranno cercati per gli utenti.
# Enter the domain name of the LDAP server in LDAP nomenclature (e.g. dc=example,dc=com).
ldap_base = domain.get("base_dn")

# Filtro utilizzato per cercare gli account degli utenti nel database LDAP.
# È un filtro LDAP arbitrario nella rappresentazione delle stringhe.
ldap_filter = "uid=%s"

odoo = odoorpc.ODOO(odoo_host, port=odoo_port)
odoo.login(odoo_db_name, odoo_user, odoo_password)

company_id = odoo.env.ref("base.main_company").id
ldap_model = odoo.env["res.company.ldap"]
server_ids = ldap_model.search([])
for server in ldap_model.browse(server_ids):
server.unlink()
ldap_model.create({
"company": company_id,
"ldap_server": ldap_server,
"ldap_server_port": ldap_server_port,
"ldap_tls": ldap_tls,
"ldap_binddn": ldap_binddn,
"ldap_password": ldap_password,
"ldap_base": ldap_base,
"ldap_filter": ldap_filter,
})

0 comments on commit b69d080

Please sign in to comment.