Skip to content

Enhancing-threat-intelligence-for-iot/Backend

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 

Repository files navigation

IoT Backend (Django + DRF)

Django REST API powering the IoT device explorer. Provides device and sector management, CVE enrichment, and AI‑assisted threat summaries via Ollama.

Stack

  • Django, Django REST Framework
  • SQLite
  • Ollama for AI summaries

Quick Start (Docker)

Run the backend by itself (useful for local development without the root compose):

  • cd iot_backend
  • Build and start:
    • docker compose up -d --build
  • Stop:
    • docker compose down

Local Development (without Docker)

Prerequisites:

  • Python 3.11+ recommended
  • pip
  1. Create and activate a virtual environment
  • Windows PowerShell:
    • python -m venv venv-backend
    • .\venv-backend\Scripts\Activate.ps1
  • macOS/Linux:
    • python -m venv venv-backend
    • source venv-backend/bin/activate
  1. Install dependencies
  • pip install -r iot_backend/requirements.txt
  1. Configure environment

Create a .env file (loaded by settings) and enable debug.

  • Windows PowerShell:
    • Set-Content -Path .\.env -Value 'DJANGO_DEBUG="True"'
  • macOS/Linux:
    • printf 'DJANGO_DEBUG="True"\n' > .env

Optional environment variables:

  • DJANGO_DEBUG: True/False (default False in production)
  • ALLOWED_HOSTS: e.g. localhost,127.0.0.1
  • CORS_ALLOWED_ORIGINS: e.g. http://localhost:5173,http://localhost:4173
  • OLLAMA_BASE_URL: e.g. http://localhost:11434 (local) or http://ollama:11434 (Docker)
  1. Migrate and run
  • python iot_backend/manage.py migrate
  • python iot_backend/manage.py runserver 0.0.0.0:8080

Create a superuser (optional):

  • python iot_backend/manage.py createsuperuser

Threat Enrichment and AI Summaries

The backend can pull CVE/threat data and generate AI summaries via Ollama.

  • Ensure an Ollama model is available (example: llama3.2):
    • POST http://localhost:11434/api/pull with body { "model": "llama3.2" }
    • More examples: iot_backend/api.md

Batch update enrichment:

  • Management command:
    • python iot_backend/manage.py update_threats
  • Utility script (optional):
    • python iot_backend/update_all_device_threats.py

API Endpoints

Explore the schema and try requests:

Project Structure

  • iot_backend/manage.py — Django entry point
  • iot_backend/iot_backend/ — project settings and URLs
  • iot_backend/iot/ — main app (models, serializers, views, signals, management commands)
  • iot_backend/requirements.txt — Python deps
  • iot_backend/dockerfile, iot_backend/docker-compose.yml — containerization
  • iot_backend/update_all_device_threats.py — optional utility script

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages