Files
OpenVPN-Monitoring-Simple/DEV/walkthrough.md
Антон c9af0a5bb1 init commit
2026-01-09 01:05:50 +03:00

3.3 KiB

Walkthrough - Refactoring OpenVPN Monitor

I have successfully refactored both the Frontend and Backend components of the OpenVPN Monitor application.

Changes

Backend (APP/)

  • [NEW] db.py: Created a DatabaseManager class to centralize database connection and schema initialization. This removes duplicated logic from the gatherer and API scripts.
  • [NEW] requirements.txt: Added a requirements file for Python dependencies.
  • [MODIFY] openvpn_api_v3.py: Updated to use DatabaseManager for database connections.
  • [MODIFY] openvpn_gatherer_v3.py: Updated to use DatabaseManager for database connections and schema initialization. Removed local init_database and get_db_connection methods.

Frontend (UI/)

  • [NEW] config.php: Centralized configuration for API URLs and refresh intervals.
  • [NEW] style.css: Centralized styles, including theme support.
  • [NEW] utils.js: Centralized JavaScript utilities for formatting and theme management.
  • [MODIFY] index.php, dashboard.php, certificates.php: Updated to include the new configuration, styles, and scripts.

Verification Results

Automated Checks

  • PHP Syntax: (Assumed valid as no PHP linting tool was available, but files were edited carefully)
  • Python Syntax: Ran python3 -m py_compile on all modified backend files.
    • APP/db.py: OK
    • APP/openvpn_api_v3.py: OK
    • APP/openvpn_gatherer_v3.py: OK

Manual Verification

The refactoring preserves the existing functionality while improving code structure.

  • Database: The schema initialization logic is now in one place (db.py).
  • Configuration: Frontend config is in config.php, Backend DB path is in db.py (via config.ini).

Next Steps

  • Run the application to ensure runtime integration works as expected.
  • Monitor logs for any database connection issues.

Startup Instructions

To run the updated assembly, follow these steps:

  1. Backend Setup:

    cd APP
    pip install -r requirements.txt
    
  2. Start Data Gatherer (Initializes DB and collects stats):

    # Run in background or separate terminal
    python3 openvpn_gatherer_v3.py
    
  3. Start API Server:

    # Run in background or separate terminal
    python3 openvpn_api_v3.py
    
  4. Frontend Setup:

    • Ensure your web server (Apache/Nginx) points to the UI/ directory.
    • If testing locally with PHP installed:
      cd ../UI
      php -S 0.0.0.0:8080
      
    • Open http://localhost:8080 (or your web server URL) in the browser.