mirror of
https://github.com/wekan/wekan.git
synced 2026-11-24 09:59:47 -05:00
Azure DevOps Boards: a query's "Export to CSV" is imported (Board Column or State as lists, Board Lane as swimlanes, Title 1/2/3 tree levels as parent cards, "Name <address>" people, regional dates, other columns as custom fields), and a board exports as the CSV "Import from CSV" reads. Microsoft Lists: a list's "Export to CSV" is imported (Status or Progress as the lists, people, dates, tags, other columns as custom fields), and a board exports as a CSV that "New list - From CSV" makes a list of. Microsoft Project: the "XML Format" (MSPDI) plan is imported (summary tasks as swimlanes, progress as lists, subtasks, resources, predecessors), read by a small XML reader that never resolves a DTD or an entity, and a board exports as a plan Project opens. Outlook: .msg files are read without a library - the Compound File Binary format (MS-CFB) and the message's properties (MS-OXMSG) - into the mail import, threads and attachments included, alone or in a .zip with .eml files; a board exports as .eml files Outlook opens. The reader was checked against .msg files saved by Outlook. Teams and OneNote: fetched from Microsoft Graph with the member's token (chats and channels; notebooks with their pages' HTML, to-do boxes as a checklist), or read from a file - Teams' personal export .tar, Graph chat messages, and the files WeKan exports: Teams chats as Graph chat messages, OneNote pages as Graph's create-page XHTML in a .zip. All six are under the Microsoft heading of Import and Export, with tests, negative tests, live tests for the two Graph imports, documentation and the import instruction in every language. Low confidence translations include ace, ak, ay, bm, bo, bua, chr, csb, cv, dz, ee, ff, fj, gn, gv, haw, ig, iu, kl, ks, kok, kw, ht, hsb, fur, fo, ga, gd, ku, lld, nah, nap, rup, sah, sc, scn, se, nd, nso, ss, om, rn, rw, sm, sn, qu, pap, lg, mg, mi, ny, so, mai, sd, ps, or_IN, my, si, rm, la, lb, tig, tlh, uz-AR, ve, ve-PP, ve-CC, vo, wa, wal, wo, zgh, to, tpi, wa-RR and ts. Thanks to xet7 !
60 lines
3.1 KiB
JavaScript
60 lines
3.1 KiB
JavaScript
// The `request` the API importers' clients (models/lib/apiImport/<key>.js)
|
|
// are given on the server: one JSON request through the SSRF guard - the
|
|
// address checked and pinned, no redirects, bounded in time and size - so a
|
|
// self-hosted address (Planka) cannot point the server at its own network.
|
|
// Resolves to the parsed body; a non-2xx answer rejects with `.status` and a
|
|
// message that names only the origin and the status, never the answer.
|
|
import { fetchSafe } from '/server/lib/ssrfGuard';
|
|
|
|
const TIMEOUT_MS = 30000;
|
|
const MAX_RESPONSE_BYTES = 32 * 1024 * 1024;
|
|
|
|
// A self-hosted service on the server's own network (a Planka at
|
|
// 192.168.1.20) is refused by the guard; only the server's administrator may
|
|
// allow its host, as LIST_SYNC_ALLOWED_PRIVATE_HOSTS does for List Sync.
|
|
export function operatorAllowedImportHost(url, env = process.env) {
|
|
const allowed = String(env.API_IMPORT_ALLOWED_PRIVATE_HOSTS || '').split(',')
|
|
.map(host => host.trim().toLowerCase()).filter(Boolean);
|
|
return allowed.length > 0 && allowed.includes(new URL(url).hostname.toLowerCase());
|
|
}
|
|
|
|
export async function apiImportRequest(url, { method = 'GET', headers = {}, body } = {}) {
|
|
const origin = new URL(url).origin;
|
|
const payload = body === undefined ? undefined : JSON.stringify(body);
|
|
let response;
|
|
try {
|
|
if (operatorAllowedImportHost(url)) {
|
|
response = await fetch(url, { method, redirect: 'error', signal: AbortSignal.timeout(TIMEOUT_MS),
|
|
headers: { Accept: 'application/json', ...headers, ...(payload === undefined ? {} : { 'Content-Type': 'application/json' }) },
|
|
...(payload === undefined ? {} : { body: payload }) });
|
|
const length = Number(response.headers.get('content-length'));
|
|
if (Number.isFinite(length) && length > MAX_RESPONSE_BYTES) throw new Error('too large');
|
|
} else response = await fetchSafe(url, {
|
|
method,
|
|
headers: { Accept: 'application/json', ...headers,
|
|
...(payload === undefined ? {} : { 'Content-Type': 'application/json', 'Content-Length': String(Buffer.byteLength(payload)) }) },
|
|
...(payload === undefined ? {} : { body: payload }),
|
|
timeoutMs: TIMEOUT_MS, totalTimeoutMs: TIMEOUT_MS, maxRedirects: 0, maxResponseBytes: MAX_RESPONSE_BYTES,
|
|
});
|
|
} catch (error) {
|
|
const failed = new Error(/^SSRF_GUARD:/.test(error && error.message) ? `${origin} is not an address WeKan may reach` : `${origin} could not be reached`);
|
|
failed.status = 0;
|
|
throw failed;
|
|
}
|
|
if (!response.ok) {
|
|
const error = new Error(`${origin} answered HTTP ${response.status}`);
|
|
error.status = response.status;
|
|
throw error;
|
|
}
|
|
if (response.status === 204) return null;
|
|
// A text answer asked for by its Accept header (a OneNote page's HTML,
|
|
// models/lib/apiImport/onenote.js) is the text itself.
|
|
const accept = String(headers.Accept || headers.accept || '');
|
|
if (/^text\//i.test(accept)) {
|
|
try { return await response.text(); } catch (error) { throw new Error(`${origin} did not answer with text`); }
|
|
}
|
|
try { return await response.json(); } catch (error) { throw new Error(`${origin} did not answer with JSON`); }
|
|
}
|
|
|
|
export default apiImportRequest;
|