- Add config.py for environment configuration management - Add utils.py with utility functions - Add .env.example for environment variable reference - Add routes_example.py as route reference - Add login.html template for authentication - Update server.py with enhancements - Update all dashboard and log templates - Move documentation to 'explanations and old code' directory - Update database schema
3.7 KiB
3.7 KiB
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/<device_ip>- 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 listssudo apt upgrade -y- Upgrade packagessudo apt autoremove -y- Remove unused packagessudo apt autoclean- Clean package cachesudo reboot- Reboot devicesudo shutdown -h now- Shutdown devicedf -h- Check disk spacefree -m- Check memory usageuptime- Check system uptimesystemctl status- Check system servicessudo systemctl restart networking- Restart network servicessudo systemctl restart ssh- Restart SSH service
File Structure Changes
New Files:
Server_Monitorizare/templates/device_management.html- Device management interfaceprezenta/data/device_info.txt- Device configuration cache (auto-created)
Modified Files:
prezenta/app.py- Added command execution server and network error handlingServer_Monitorizare/server.py- Added command execution endpointsServer_Monitorizare/templates/dashboard.html- Added device management link
Usage Instructions
Starting the Services
-
Start the monitoring server (port 80):
cd Server_Monitorizare sudo python3 server.py -
Start the device app (ports 5000 for commands + normal operation):
cd prezenta python3 app.py
Using the Web Interface
- Navigate to
http://server-ip:80/dashboard - Click "Device Management" to access the new interface
- Use the dropdown menus to select commands
- Execute on single devices or use bulk operations
Benefits
- Centralized device management - Control all devices from one interface
- Automated maintenance - Schedule updates and maintenance tasks
- Real-time monitoring - Check device status and performance
- Improved reliability - Network error handling prevents app crashes
- Security - Controlled command execution with comprehensive logging