-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathdatabase-fill.ts
More file actions
executable file
·73 lines (65 loc) · 3.22 KB
/
Copy pathdatabase-fill.ts
File metadata and controls
executable file
·73 lines (65 loc) · 3.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import config from "../config";
import { sequelize } from "../database/db";
import { Domain } from "../database/models/domain";
import { SubjectType } from "../database/models/subject";
import { CrawlingStatus } from "../database/models/url";
import { DomainFactory } from "../utils/factories/domain-factory";
import { SubjectFactory } from "../utils/factories/subject-factory";
import { URLFactory } from "../utils/factories/url-factory";
import { Logging } from "../utils/logging";
/**
* Fill database with hard coded sample pages
*/
const fill = async () => {
const t = await sequelize.transaction();
try {
// Create empty domain for DB hierarchy (ignore url value)
let domain = await DomainFactory.createDomainFromUrl("http://example.com", 0, 0, undefined, t)
let urls: string[] = [];
// Define urls list for module (access module name at config.dynamic.module)
if (config.dynamic.module === "cxss") {
urls = [
"http://localhost:3000/cxss/index.html",
"http://localhost:3000/cxss/cookie.html",
"http://localhost:3000/cxss/localstorage.html",
"http://localhost:3000/cxss/script-src.html",
"http://localhost:3000/cxss/sessionstorage.html"
];
} else if (config.dynamic.module === "pmsecurity") {
urls = [
"http://localhost:3000/pm/conditionalOr.html",
"http://localhost:3000/pm/cookie.html",
"http://localhost:3000/pm/doubleInjection.html",
"http://localhost:3000/pm/externalFun.html",
"http://localhost:3000/pm/forLoopArray.html",
"http://localhost:3000/pm/ifPropertyExists.html",
"http://localhost:3000/pm/indexOfOriginCheck.html",
"http://localhost:3000/pm/lazyExpression.html",
"http://localhost:3000/pm/localStorageAssign.html",
"http://localhost:3000/pm/localStorageSetItem.html",
"http://localhost:3000/pm/multiReplace.html",
"http://localhost:3000/pm/popupWrite.html",
"http://localhost:3000/pm/regexMatch.html",
"http://localhost:3000/pm/regexObj.html",
"http://localhost:3000/pm/sliceAndSearch.html",
"http://localhost:3000/pm/ternary.html",
]
}
// Create DB entries for all urls in question in transaction (if one fails, all fail)
for (let index = 0; index < urls.length; index++) {
const element = urls[index];
const url = await URLFactory.createUrl(element, domain, 0, undefined, t);
domain = await Domain.findOne({ where: { id: url.domain_id }, transaction: t }) as Domain;
for (let index = 0; index < 1; index++) {
if (url.crawling_status !== CrawlingStatus.IGNORE) {
await SubjectFactory.createSubjectFromUrl(url, SubjectType.RECONNAISSANCE, {}, undefined, undefined, t)
}
}
}
await t.commit();
} catch (err: unknown) {
Logging.error(`(fill) Error occured during database setup. Error: ${(err as Error).toString()}`)
await t.rollback();
}
}
export { fill };