You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

62 lines
1.7 KiB

CREATE EXTENSION IF NOT EXISTS "uuid-ossp";
CREATE TYPE JobType AS ENUM ('shell', 'init', 'python', 'service');
CREATE TYPE JobState AS ENUM ('queued', 'running', 'finished');
CREATE TYPE AgentState AS ENUM ('new', 'active', 'banned');
CREATE TABLE IF NOT EXISTS agents (
alias TEXT,
hostname TEXT NOT NULL,
host_info TEXT NOT NULL,
id UUID NOT NULL,
ip_gray TEXT,
ip_white TEXT,
is_root BOOLEAN NOT NULL DEFAULT false,
is_root_allowed BOOLEAN NOT NULL DEFAULT false,
last_active TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
platform TEXT NOT NULL,
regtime TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
state AgentState NOT NULL DEFAULT 'new',
token TEXT,
username TEXT NOT NULL,
PRIMARY KEY(id)
);
CREATE TABLE IF NOT EXISTS payloads (
id UUID NOT NULL,
mime_type TEXT NOT NULL,
name TEXT NOT NULL UNIQUE,
size BIGINT NOT NULL,
PRIMARY KEY(id)
);
CREATE TABLE IF NOT EXISTS jobs (
alias TEXT,
argv TEXT NOT NULL,
id UUID NOT NULL,
exec_type JobType NOT NULL DEFAULT 'shell',
target_platforms TEXT NOT NULL,
payload UUID,
schedule TEXT,
FOREIGN KEY(payload) REFERENCES payloads(id) ON DELETE SET NULL,
PRIMARY KEY(id)
);
CREATE TABLE IF NOT EXISTS results (
agent_id UUID NOT NULL,
alias TEXT,
created TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
id UUID NOT NULL,
job_id UUID NOT NULL,
result BYTEA,
state JobState NOT NULL DEFAULT 'queued',
exec_type JobType NOT NULL DEFAULT 'shell',
retcode INTEGER,
updated TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY(agent_id) REFERENCES agents(id) ON DELETE CASCADE,
FOREIGN KEY(job_id) REFERENCES jobs(id) ON DELETE CASCADE,
PRIMARY KEY(id)
);