# Device Management System Update - Version 2.4 ## Overview This update adds remote command execution capabilities between the Server_Monitorizare and the prezenta devices, along with improved error handling for network connectivity issues. ## New Features ### 1. Robust Network Configuration (app.py) - **File-based fallback system**: Device hostname and IP are saved to `./data/device_info.txt` - **Automatic error recovery**: When socket.gaierror occurs, the system loads previously saved values - **No external dependencies**: Uses only built-in Python modules - **Graceful degradation**: App continues to run even with network issues ### 2. Remote Command Execution System #### Server Side (server.py) New endpoints added: - `/device_management` - Web interface for managing devices - `/execute_command` - Execute command on single device - `/execute_command_bulk` - Execute command on multiple devices - `/device_status/` - Get device status information #### Device Side (app.py) New Flask server running on port 5000: - `/execute_command` - Receive and execute system commands - `/status` - Provide device status information ### 3. Security Features - **Whitelisted commands only**: Prevents execution of arbitrary commands - **Command logging**: All command execution attempts are logged - **Timeout protection**: Commands have 5-minute timeout limit - **Error handling**: Comprehensive error reporting ### 4. Web Interface Improvements - **Device Management Dashboard**: Complete interface for managing all devices - **Real-time status checking**: Check if devices are online/offline - **Bulk operations**: Execute commands on multiple devices simultaneously - **Search functionality**: Filter devices by hostname or IP - **Command selection**: Dropdown menus for common system commands ## Allowed Commands For security, only these commands can be executed remotely: - `sudo apt update` - Update package lists - `sudo apt upgrade -y` - Upgrade packages - `sudo apt autoremove -y` - Remove unused packages - `sudo apt autoclean` - Clean package cache - `sudo reboot` - Reboot device - `sudo shutdown -h now` - Shutdown device - `df -h` - Check disk space - `free -m` - Check memory usage - `uptime` - Check system uptime - `systemctl status` - Check system services - `sudo systemctl restart networking` - Restart network services - `sudo systemctl restart ssh` - Restart SSH service ## File Structure Changes ### New Files: - `Server_Monitorizare/templates/device_management.html` - Device management interface - `prezenta/data/device_info.txt` - Device configuration cache (auto-created) ### Modified Files: - `prezenta/app.py` - Added command execution server and network error handling - `Server_Monitorizare/server.py` - Added command execution endpoints - `Server_Monitorizare/templates/dashboard.html` - Added device management link ## Usage Instructions ### Starting the Services 1. **Start the monitoring server** (port 80): ```bash cd Server_Monitorizare sudo python3 server.py ``` 2. **Start the device app** (ports 5000 for commands + normal operation): ```bash cd prezenta python3 app.py ``` ### Using the Web Interface 1. Navigate to `http://server-ip:80/dashboard` 2. Click "Device Management" to access the new interface 3. Use the dropdown menus to select commands 4. Execute on single devices or use bulk operations ## Benefits 1. **Centralized device management** - Control all devices from one interface 2. **Automated maintenance** - Schedule updates and maintenance tasks 3. **Real-time monitoring** - Check device status and performance 4. **Improved reliability** - Network error handling prevents app crashes 5. **Security** - Controlled command execution with comprehensive logging