Skip to content

mirkochipdotcom/LdavSync

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

4 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

LdavSync - Corporate Directory with CardDAV

Go Version License Docker

LdavSync is a corporate directory application with automatic LDAP synchronization, centralized group phone numbers, and CardDAV protocol support for Thunderbird and external clients.

๐Ÿ‡ฎ๐Ÿ‡น Versione Italiana

Features

  • โœจ Automatic LDAP Sync: Hourly synchronization of contacts from LDAP directory
  • ๐Ÿ“ž Group Numbers: Centralized management of group phone numbers (e.g., Reception, Protocol Office)
  • ๐Ÿ” Live Search: Google Contacts-style search with HTMX
  • ๐Ÿ“ฑ CardDAV Server: Native integration with Thunderbird, iOS, Android
  • ๐ŸŒ Multilingual: Italian and English interface
  • ๐Ÿ” LDAP Authentication: Secure admin access with LDAP credentials
  • ๐Ÿณ Single Container: Easy deployment with Docker/Podman
  • ๐Ÿ’พ Embedded SQLite: Zero-configuration database

Quick Start

With Docker Compose

# Clone repository
git clone https://github.com/mirkochipdotcom/ldavsync.git
cd ldavsync

# Copy and configure environment
cp .env.example .env
nano .env  # Edit LDAP settings

# Start service
docker compose up -d

# Check logs
docker compose logs -f

Access the application at http://localhost:8080

With Podman

# Build image
podman build -t ldavsync:latest .

# Run container
podman run -d \
   --name ldavsync \
   -p 8080:8080 \
   -v ./data:/data:Z \
   --env-file .env \
   ldavsync:latest

Configuration

All configuration is via environment variables (.env file):

Variable Description Example
LDAP_HOST LDAP server URL ldap://ldap.example.com:389
LDAP_BASE_DN Base DN for searches dc=example,dc=com
LDAP_BIND_DN Service account DN cn=admin,dc=example,dc=com
LDAP_BIND_PASSWORD Service account password secret
ADMIN_USERS Admin usernames (; separated) admin;mario.rossi
SYNC_INTERVAL_HOURS Sync frequency (hours) 1
PRIMARY_NUMBER_PREFIX_TEMPLATE Phone number template 0854321{ext}
SESSION_SECRET Session encryption key Random string

See .env.example for complete configuration.

Architecture

ldavsync/
โ”œโ”€โ”€ cmd/server/           # Main application
โ”‚   โ””โ”€โ”€ main.go
โ”œโ”€โ”€ internal/             # Internal packages
โ”‚   โ”œโ”€โ”€ config/          # Configuration
โ”‚   โ”œโ”€โ”€ database/        # SQLite operations
โ”‚   โ”œโ”€โ”€ ldap/            # LDAP auth & sync
โ”‚   โ”œโ”€โ”€ phonebook/       # Business logic
โ”‚   โ”œโ”€โ”€ carddav/         # CardDAV protocol
โ”‚   โ””โ”€โ”€ i18n/            # Internationalization
โ”œโ”€โ”€ web/                 # Frontend assets
โ”‚   โ”œโ”€โ”€ templates/       # HTML templates
โ”‚   โ””โ”€โ”€ static/          # CSS, JS
โ”œโ”€โ”€ Dockerfile           # Multi-stage build
โ””โ”€โ”€ compose.yml          # Docker Compose

Usage

Public Access

  • Search: Available at / - no authentication required
  • Contact Details: Click on any contact to view full details
  • Export vCard: Download individual contacts as .vcf files

Admin Panel

  1. Login at /login with LDAP credentials
  2. Configure primary number prefix template
  3. Manage group numbers (create, edit, delete)
  4. Associate contacts with groups
  5. Override contact information manually
  6. Trigger manual LDAP sync

CardDAV Integration

Thunderbird

  1. Go to Address Book
  2. File โ†’ New โ†’ CardDAV Address Book
  3. Enter:
    • URL: http://your-server:8080/carddav/
    • Username: Your LDAP username
    • Password: Your LDAP password
  4. Click Continue

iOS

  1. Settings โ†’ Contacts โ†’ Accounts โ†’ Add Account โ†’ Other
  2. Select CardDAV Account
  3. Enter:
    • Server: your-server:8080
    • Username: Your LDAP username
    • Password: Your LDAP password
  4. Save

Android

For Android, use a CardDAV-compatible app like DAVxโต:

  1. Install DAVxโต from Play Store
  2. Add new account โ†’ CardDAV
  3. Enter server URL and credentials

Development

Prerequisites

  • Go 1.22+
  • Docker/Podman (optional)
  • LDAP server for testing

Local Development

# Install dependencies
go mod download

# Run locally
cp .env.example .env
# Edit .env with your LDAP settings
go run cmd/server/main.go

# Build
go build -o ldavsync cmd/server/main.go

# Run tests
go test ./...

Build Docker Image

# Build with version tag
docker build --build-arg VERSION=0.1.0 -t ldavsync:0.1.0 .

# Run
docker run -p 8080:8080 -v $(pwd)/data:/data --env-file .env ldavsync:0.1.0

API Endpoints

Public

  • GET / - Main phonebook interface
  • GET /search?q={query} - Search contacts (HTMX partial)
  • GET /contacts - List contacts (JSON)
  • GET /contacts/{uid} - Contact details
  • GET /contacts/{uid}/export - Export vCard
  • GET /health - Health check

Admin (requires authentication)

  • POST /admin/sync - Trigger manual sync
  • GET/POST /admin/config - Manage configuration
  • GET/POST /admin/groups - Manage groups
  • GET /admin/groups/{id}/members - View group members
  • POST /admin/groups/{id}/members - Add member
  • POST /admin/contacts/{uid}/override - Override contact data

CardDAV

  • PROPFIND /carddav/ - List address book
  • REPORT /carddav/ - Query contacts
  • GET /carddav/{uid}.vcf - Get vCard
  • GET /.well-known/carddav - Discovery

Troubleshooting

LDAP Sync Not Working

Check logs:

docker compose logs -f ldavsync

Look for [SYNC] entries. Common issues:

  • Incorrect LDAP_BASE_DN
  • Service account permissions
  • Firewall blocking LDAP port

CardDAV Authentication Failed

Ensure:

  1. LDAP authentication is working (test with web login)
  2. LDAP credentials are correct
  3. Server is reachable from client

Database Locked Errors

Check:

  • Volume permissions: chown -R 1001:1001 ./data
  • No multiple instances accessing same database

Contributing

Contributions welcome! Please:

  1. Fork the repository
  2. Create a feature branch
  3. Commit your changes
  4. Push to the branch
  5. Open a Pull Request

License

MIT License - see LICENSE file for details

Credits

Built with:

Support

For issues and questions:


Made with โค๏ธ by mirkochipdotcom

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors