spiderfootClient.ts•2.75 kB
import axios, { AxiosInstance } from 'axios';
export interface SpiderfootClientOptions {
baseUrl: string;
username?: string;
password?: string;
timeoutMs?: number;
}
export class SpiderfootClient {
private http: AxiosInstance;
constructor(opts: SpiderfootClientOptions) {
this.http = axios.create({
baseURL: opts.baseUrl.replace(/\/$/, ''),
timeout: opts.timeoutMs ?? 30000,
// Note: Local dev runs without auth; digest auth could be added later if configured.
// axios doesn't support digest out of the box; we intentionally skip until needed.
// httpsAgent/insecure SSL not needed for http://127.0.0.1:5001.
validateStatus: (s) => s >= 200 && s < 300,
});
}
async ping() {
const { data } = await this.http.get('/ping');
return data;
}
async modules() {
const { data } = await this.http.get('/modules');
return data;
}
async eventTypes() {
const { data } = await this.http.get('/eventtypes');
return data;
}
async scans() {
const { data } = await this.http.get('/scanlist');
return data;
}
async scanInfo(id: string) {
const { data } = await this.http.get('/scanopts', { params: { id } });
return data;
}
async startScan(args: {
scanname: string;
scantarget: string;
modulelist?: string; // comma separated module names
typelist?: string; // comma separated event types
usecase?: string; // all|investigate|passive|footprint
}) {
const { data } = await this.http.post('/startscan', args);
return data;
}
async scanEventResults(args: { id: string; eventType?: string }) {
const { data } = await this.http.post('/scaneventresults', {
id: args.id,
eventType: args.eventType ?? 'ALL',
});
return data;
}
async scanEventResultsUnique(args: { id: string; eventType?: string }) {
const { data } = await this.http.post('/scaneventresultsunique', {
id: args.id,
eventType: args.eventType ?? 'ALL',
});
return data;
}
async scanLogs(args: { id: string; limit?: number; reverse?: '0' | '1'; rowId?: number }) {
const { data } = await this.http.post('/scanlog', {
id: args.id,
limit: args.limit,
reverse: args.reverse,
rowId: args.rowId,
});
return data;
}
async exportJson(idsCsv: string) {
const { data } = await this.http.post('/scanexportjsonmulti', { ids: idsCsv });
return data;
}
}
export function makeSpiderfootClientFromEnv() {
const baseUrl = process.env.SPIDERFOOT_BASE_URL || 'http://127.0.0.1:5001';
const username = process.env.SPIDERFOOT_USER;
const password = process.env.SPIDERFOOT_PASS;
return new SpiderfootClient({ baseUrl, username, password });
}