|
| 1 | +# LDAP Management Portal |
| 2 | + |
| 3 | +A comprehensive Flask-based web application for LDAP administration and user self-service portal built with Bootstrap 5. |
| 4 | + |
| 5 | +## Features |
| 6 | + |
| 7 | +### 👤 User Self-Service Portal |
| 8 | +- **User Login**: Normal users can login with their LDAP credentials |
| 9 | +- **Profile Management**: Users can update their personal information (email, phone, description, etc.) |
| 10 | +- **Profile Photos**: Upload and manage profile photos using jpegPhoto attribute with automatic resizing |
| 11 | +- **Password Change**: Secure password change functionality with SSHA encryption |
| 12 | +- **Password Expiry Information**: View password expiry status and remaining days (POSIX users) |
| 13 | +- **User Directory**: Browse and search other users in the organization |
| 14 | +- **Clean Dashboard**: Intuitive interface showing account status and quick actions |
| 15 | + |
| 16 | +### 🛡️ Multi-Tier Admin System |
| 17 | +#### Super Administrator (`cn=admin,dc=mylab,dc=lan`) |
| 18 | +- **Full system access** with all administrative privileges |
| 19 | +- **System account protection** (cannot modify own profile) |
| 20 | +- **Login**: Use username `admin` with admin DN credentials |
| 21 | + |
| 22 | +#### Group Administrators (members of `cn=admins` group) |
| 23 | +- **User management** capabilities |
| 24 | +- **Group management** access |
| 25 | +- **Limited administrative privileges** |
| 26 | +- **Self-profile modification** allowed |
| 27 | + |
| 28 | +### 🔧 Administrative Features |
| 29 | +- ✅ **Complete User Management**: Create, read, update, delete user accounts |
| 30 | +- ✅ **POSIX User Support**: Create users with POSIX attributes (UID, GID, home directory, shell) |
| 31 | +- ✅ **Complete Group Management**: |
| 32 | + - Create both standard and POSIX groups |
| 33 | + - Delete existing groups |
| 34 | + - Add/remove members from groups |
| 35 | + - View group membership details |
| 36 | +- ✅ **Bulk User Creation**: Upload CSV files to create multiple users at once |
| 37 | +- ✅ **Profile Photo Management**: Upload, preview, and manage user photos (jpegPhoto attribute) |
| 38 | +- ✅ **Password Expiry Management**: View and manage password expiration for POSIX users |
| 39 | +- ✅ **User Search & Filtering**: Search users by name, email, or other attributes |
| 40 | +- ✅ **Comprehensive Statistics**: LDAP server statistics dashboard with user/group counts |
| 41 | +- ✅ **Generic Entry Editor**: Edit any LDAP entry with all attributes |
| 42 | +- ✅ **Lock/Unlock Users**: Temporarily disable user accounts |
| 43 | +- ✅ **Admin Dashboard**: Comprehensive administrative interface with real-time statistics |
| 44 | +- ✅ **Security Features**: Environment-based configuration, secure password handling |
| 45 | + |
| 46 | +## Technology Stack |
| 47 | + |
| 48 | +- **Backend**: Python 3.12+ with Flask |
| 49 | +- **Frontend**: Bootstrap 5 with Font Awesome icons |
| 50 | +- **LDAP Client**: ldap3 library for robust LDAP operations |
| 51 | +- **Authentication**: Session-based authentication with LDAP bind |
| 52 | +- **Security**: Environment variable configuration, no hardcoded passwords |
| 53 | + |
| 54 | +## Quick Start |
| 55 | + |
| 56 | +1. **Set up environment variables**: |
| 57 | + ```bash |
| 58 | + export LDAP_ADMIN_PASSWORD="your_admin_password" |
| 59 | + ``` |
| 60 | + Or use the interactive setup script: |
| 61 | + ```bash |
| 62 | + ./setup_env.sh |
| 63 | + ``` |
| 64 | + |
| 65 | +2. **Install dependencies**: |
| 66 | + ```bash |
| 67 | + python -m venv .venv |
| 68 | + source .venv/bin/activate |
| 69 | + pip install -r requirements.txt |
| 70 | + ``` |
| 71 | + |
| 72 | +3. **Run the application**: |
| 73 | + ```bash |
| 74 | + python app.py |
| 75 | + ``` |
| 76 | + |
| 77 | +4. **Access the portal**: |
| 78 | + - **URL**: http://localhost:5000 |
| 79 | + - **Admin Login**: Username `admin` + your LDAP admin password |
| 80 | + - **User Login**: Any valid LDAP user credentials |
| 81 | + |
| 82 | +## Production Deployment |
| 83 | + |
| 84 | +For production deployment with systemd service, Nginx proxy, and complete LDAP server setup, see the comprehensive [SETUP.md](SETUP.md) guide. |
| 85 | + |
| 86 | +## Configuration |
| 87 | + |
| 88 | +The application supports environment-based configuration: |
| 89 | + |
| 90 | +| Environment Variable | Default Value | Description | |
| 91 | +|---------------------|---------------|-------------| |
| 92 | +| `LDAP_SERVER` | `192.168.1.1` | LDAP server hostname/IP | |
| 93 | +| `LDAP_PORT` | `389` | LDAP server port | |
| 94 | +| `LDAP_BASE_DN` | `dc=mylab,dc=lan` | LDAP base DN | |
| 95 | +| `LDAP_ADMIN_DN` | `cn=admin,dc=mylab,dc=lan` | LDAP admin DN | |
| 96 | +| `LDAP_ADMIN_PASSWORD` | **(Required)** | LDAP admin password | |
| 97 | +| `DEBUG_MODE` | `False` | Enable debug logging (set to `true` only for development) | |
| 98 | + |
| 99 | +## Security Features |
| 100 | + |
| 101 | +- ✅ **No hardcoded passwords** - All credentials via environment variables |
| 102 | +- ✅ **Secure session management** - Flask-Session with filesystem storage |
| 103 | +- ✅ **LDAP authentication** - Direct LDAP bind for user verification |
| 104 | +- ✅ **Multi-tier access control** - Super admin vs Group admin privileges |
| 105 | +- ✅ **Input validation** - Form validation and LDAP injection prevention |
| 106 | +- ✅ **Secure configuration** - Environment-based sensitive data handling |
| 107 | + |
| 108 | +## File Structure |
| 109 | + |
| 110 | +``` |
| 111 | +pythonldapman/ |
| 112 | +├── app.py # Main Flask application |
| 113 | +├── requirements.txt # Python dependencies |
| 114 | +├── setup_env.sh # Environment setup script |
| 115 | +├── INSTALLATION.md # Complete installation guide |
| 116 | +├── static/ # Frontend assets (CSS, JS, images) |
| 117 | +├── templates/ # Jinja2 HTML templates |
| 118 | +└── config/ # Configuration files (created during setup) |
| 119 | +``` |
| 120 | + |
| 121 | +## License |
| 122 | + |
| 123 | +This project is developed for LDAP administration and user self-service purposes. |
| 124 | + |
| 125 | +## Support |
| 126 | + |
| 127 | +For installation and configuration issues, refer to [SETUP.md](SETUP.md) or check the application logs. |
| 128 | + ```bash |
| 129 | + python app.py |
| 130 | + ``` |
| 131 | + |
| 132 | +2. Open your web browser and go to: `http://localhost:5000` |
| 133 | + |
| 134 | +3. Login credentials: |
| 135 | + - **Admin**: Username `admin` with your admin password |
| 136 | + - **Users**: Use their LDAP username and password |
| 137 | + |
| 138 | +## User Guide |
| 139 | + |
| 140 | +### For Regular Users |
| 141 | +1. Login with your LDAP username and password |
| 142 | +2. Navigate to "My Profile" to update your information |
| 143 | +3. Use "Change Password" to update your password |
| 144 | +4. All changes are saved directly to the LDAP directory |
| 145 | + |
| 146 | +### For Administrators |
| 147 | +1. Login with username `admin` and your admin password |
| 148 | +2. Access the "Admin Panel" from the navigation menu |
| 149 | +3. Manage users through "Manage Users" |
| 150 | +4. Create new users with "Add New User" |
| 151 | +5. Edit any LDAP entry with the generic entry editor |
| 152 | +6. Delete entries with confirmation dialogs |
| 153 | + |
| 154 | +## Security Features |
| 155 | + |
| 156 | +- **LDAP Authentication**: All logins verified against LDAP server |
| 157 | +- **Session Management**: Secure session handling with Flask-Session |
| 158 | +- **Password Hashing**: SSHA password hashing for new passwords |
| 159 | +- **Access Control**: Role-based access with user/admin separation |
| 160 | +- **Input Validation**: Form validation and sanitization |
| 161 | + |
| 162 | +## LDAP Schema Support |
| 163 | + |
| 164 | +The application supports standard LDAP object classes: |
| 165 | + |
| 166 | +### User Accounts (inetOrgPerson) |
| 167 | +- uid (username) |
| 168 | +- cn (common name) |
| 169 | +- sn (surname) |
| 170 | +- givenName (first name) |
| 171 | +- mail (email) |
| 172 | +- telephoneNumber (phone) |
| 173 | +- userPassword (password) |
| 174 | +- description |
| 175 | + |
| 176 | +### Groups (groupOfNames) |
| 177 | +- cn (group name) |
| 178 | +- description |
| 179 | +- member (group members) |
| 180 | + |
| 181 | +## File Structure |
| 182 | + |
| 183 | +``` |
| 184 | +pythonldapman/ |
| 185 | +├── app.py # Main Flask application |
| 186 | +├── requirements.txt # Python dependencies |
| 187 | +├── templates/ # Jinja2 templates |
| 188 | +│ ├── base.html # Base template with Bootstrap |
| 189 | +│ ├── login.html # Login page |
| 190 | +│ ├── dashboard.html # User dashboard |
| 191 | +│ ├── profile.html # User profile editor |
| 192 | +│ ├── change_password.html # Password change form |
| 193 | +│ └── admin/ # Admin templates |
| 194 | +│ ├── panel.html # Admin dashboard |
| 195 | +│ ├── users.html # User management |
| 196 | +│ ├── groups.html # Group management |
| 197 | +│ ├── add_user.html # Add user form |
| 198 | +│ └── edit_entry.html # Generic entry editor |
| 199 | +└── static/ # Static files (if needed) |
| 200 | +``` |
| 201 | + |
| 202 | +## Customization |
| 203 | + |
| 204 | +### LDAP Configuration |
| 205 | +Edit the configuration variables in `app.py`: |
| 206 | + |
| 207 | +```python |
| 208 | +LDAP_SERVER = '192.168.1.1' |
| 209 | +LDAP_PORT = 389 |
| 210 | +LDAP_BASE_DN = 'dc=mylab,dc=lan' |
| 211 | +LDAP_ADMIN_DN = 'cn=admin,dc=mylab,dc=com' |
| 212 | +``` |
| 213 | + |
| 214 | +### UI Customization |
| 215 | +- Templates use Bootstrap 5 classes for easy customization |
| 216 | +- Modify `templates/base.html` for global layout changes |
| 217 | +- Add custom CSS in the `static/` directory |
| 218 | + |
| 219 | +## Error Handling |
| 220 | + |
| 221 | +The application includes comprehensive error handling: |
| 222 | +- LDAP connection errors |
| 223 | +- Authentication failures |
| 224 | +- Invalid form data |
| 225 | +- Missing entries |
| 226 | +- Permission denied scenarios |
| 227 | + |
| 228 | +## Development |
| 229 | + |
| 230 | +To contribute or modify the application: |
| 231 | + |
| 232 | +1. The main application logic is in `app.py` |
| 233 | +2. Templates are in the `templates/` directory |
| 234 | +3. Use the Flask development server for testing |
| 235 | +4. All LDAP operations go through the `LDAPManager` class |
| 236 | + |
| 237 | +## License |
| 238 | + |
| 239 | +This project is open-source and available for modification and distribution. |
| 240 | + |
| 241 | +## Support |
| 242 | + |
| 243 | +For issues or questions: |
| 244 | +1. Check the LDAP server connectivity |
| 245 | +2. Verify credentials and DN configuration |
| 246 | +3. Review Flask application logs |
| 247 | +4. Test LDAP operations manually with ldapsearch |
0 commit comments