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.

77 lines
2.4 KiB

4 years ago
CREATE EXTENSION IF NOT EXISTS "uuid-ossp";
CREATE TYPE JobType AS ENUM ('shell', 'manage', 'python');
4 years ago
CREATE TYPE JobState AS ENUM ('queued', 'running', 'finished');
CREATE TYPE AgentState AS ENUM ('new', 'active', 'banned');
4 years ago
CREATE TABLE IF NOT EXISTS agents (
alias TEXT
, hostname TEXT NOT NULL
4 years ago
, id UUID NOT NULL DEFAULT uuid_generate_v4()
, is_root BOOLEAN NOT NULL DEFAULT false
, is_root_allowed BOOLEAN NOT NULL DEFAULT false
, last_active TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
-- target triplet
, platform TEXT NOT NULL
, regtime TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
, state AgentState NOT NULL DEFAULT 'new'
-- is needed to processing requests
, token TEXT
, username TEXT NOT NULL
4 years ago
, PRIMARY KEY(id)
);
CREATE TABLE IF NOT EXISTS ip_addrs (
agent_id UUID NOT NULL
4 years ago
, check_ts TIMESTAMP NOT NULL
, gateway TEXT
, id UUID NOT NULL DEFAULT uuid_generate_v4()
, iface TEXT NOT NULL
, ip_addr TEXT NOT NULL
4 years ago
, is_gray BOOLEAN NOT NULL DEFAULT true
, netmask TEXT NOT NULL
4 years ago
, PRIMARY KEY(id)
, FOREIGN KEY(agent_id) REFERENCES agents(id)
);
CREATE TABLE IF NOT EXISTS jobs (
alias TEXT
, argv TEXT NOT NULL
, id UUID NOT NULL DEFAULT uuid_generate_v4()
4 years ago
, exec_type JobType NOT NULL DEFAULT 'shell'
, platform TEXT NOT NULL
4 years ago
, payload BYTEA
4 years ago
, 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 DEFAULT uuid_generate_v4()
4 years ago
, job_id UUID NOT NULL
, result BYTEA
4 years ago
, state JobState NOT NULL DEFAULT 'queued'
4 years ago
, 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
4 years ago
, PRIMARY KEY(id)
);
CREATE TABLE IF NOT EXISTS certificates (
agent_id UUID NOT NULL
, id UUID NOT NULL DEFAULT uuid_generate_v4()
, is_revoked BOOLEAN NOT NULL DEFAULT FALSE
4 years ago
, PRIMARY KEY(id)
, FOREIGN KEY(agent_id) REFERENCES agents(id)
);
CREATE TABLE IF NOT EXISTS errors (
agent_id UUID NOT NULL
, created TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
, id UUID NOT NULL DEFAULT uuid_generate_v4()
, msg TEXT
, FOREIGN KEY(agent_id) REFERENCES agents(id) ON DELETE CASCADE
, PRIMARY KEY(id)
);