Deployment: Backend Script
Relevant source files
The following files were used as context for generating this wiki page:Introduction
The LLaMa Leaks project is a passive AI security dashboard designed to highlight publicly exposed Ollama servers. It operates on the principle of observing and reporting what is already publicly accessible, without any active hacking or exploitation. The goal is to foster security awareness and encourage developers to secure their AI infrastructure.
Sources: README.md, frontend/src/pages/About.tsx:45-56
This document outlines the requirements and data contract for the backend script. While the script's implementation is not present in the provided files, its primary function can be inferred from the frontend application that consumes its output. The backend script is responsible for identifying exposed servers and generating a static JSON data file, which is then used by the frontend to display the findings.
Sources: frontend/src/components/Hero.tsx:45, frontend/src/components/LocationInfo.tsx:47
System Architecture and Data Flow
The backend script's core responsibility is to produce a static data file named live_servers.json. The frontend application fetches this file upon loading to display information about a randomly selected exposed server. This architecture decouples the data collection process (backend) from the data presentation layer (frontend).
The following diagram illustrates the data flow from the backend script to the user interface.
This flow shows that the backend script's final artifact is the JSON file, which serves as the single source of truth for the frontend application.
Sources: frontend/src/components/Hero.tsx:45-48, frontend/src/components/LocationInfo.tsx:47-50
Data Schema
The backend script must generate a JSON file containing an object where each value is a server data object. The structure of this data is defined by the ServerData and ServerModel interfaces in the frontend code.
ServerData Object
This is the main data structure for each exposed server identified by the script.
| Field | Type | Description | Source File |
|---|---|---|---|
ip | string | The masked IP address of the server. | Hero.tsx:18 |
port | number | The port number the Ollama service is running on. | Hero.tsx:19 |
version | string | The version of the Ollama instance. | Hero.tsx:20 |
city | string | The city where the server is located. | Hero.tsx:21 |
country | string | The two-letter country code (e.g., 'US'). | Hero.tsx:22 |
country_name | string | The full country name (e.g., 'United States'). | Hero.tsx:23 |
region | string | The region or state where the server is located. | Hero.tsx:24 |
latitude | string | The geographical latitude of the server. | Hero.tsx:25 |
longitude | string | The geographical longitude of the server. | Hero.tsx:26 |
local | ServerModel[] | An array of AI models available locally on the server. | Hero.tsx:27 |
running | ServerModel[] | An array of AI models currently running on the server. | Hero.tsx:28 |
first_seen_online | string | ISO timestamp of when the server was first observed. | Hero.tsx:29 |
last_observed | string | ISO timestamp of when the server was last observed. | Hero.tsx:30 |
age | string | A human-readable string representing how long the server has been observed (e.g., "2 days"). | Hero.tsx:31 |
status | string | The current status of the server (e.g., 'live'). | Hero.tsx:32 |
ServerModel Object
This structure details the AI models found on a server. It is used within the local and running arrays of the ServerData object.
| Field | Type | Description | Source File |
|---|---|---|---|
name | string | The name of the AI model (e.g., 'llama3:latest'). | Hero.tsx:13 |
model | string | The model identifier. | Hero.tsx:14 |
size | number | The size of the model in bytes. | Hero.tsx:15 |
Entity Relationship Diagram
This diagram shows the relationship between the ServerData and ServerModel structures.
Frontend Interaction
The frontend's primary interaction with the backend's data is through a fetch request inside the Hero and LocationInfo components.
Data Fetching Logic
On page load, the fetchRandomServer function is called. It retrieves the live_servers.json file, converts the JSON object of servers into an array, and selects a random server to display.
// Source: frontend/src/components/Hero.tsx:39-63
const fetchRandomServer = async (isRefresh = false) => {
try {
// ... set loading state ...
const response = await fetch('/data/live_servers.json');
if (!response.ok) {
throw new Error(`Failed to fetch server data: ${response.status}`);
}
const serversObject = await response.json();
const serverEntries = Object.values(serversObject) as ServerData[];
if (serverEntries.length === 0) {
throw new Error('No servers found in the data');
}
const randomIndex = Math.floor(Math.random() * serverEntries.length);
const randomServer = serverEntries[randomIndex];
setServerData(randomServer);
} catch (err) {
// ... handle error ...
} finally {
// ... set loading state ...
}
};
Data Consumption Flow
The sequence diagram below details the interaction between the user, the frontend, and the web server hosting the data file.
Project Objective: Promoting Security
The ultimate purpose of the backend script is to provide the necessary data to fulfill the project's mission: raising security awareness. The frontend uses this data to advise developers on how to secure their servers.
The key security measures promoted by the application include:
- Bind to localhost: Restrict server access to
127.0.0.1. - Use a reverse proxy: Implement an authentication layer in front of the server.
- Set up firewall rules: Block all unnecessary ports.
- Monitor access logs: Regularly check for suspicious activity.
- API key authentication: Secure endpoints to prevent unauthorized use.
- Use a VPN: Ensure secure remote access.
- Set up rate limiting: Prevent abuse and control request frequency.
- Conduct regular security audits: Proactively scan and test infrastructure.
Sources: frontend/src/components/Solutions.tsx:25-136, frontend/src/pages/About.tsx:142-192