Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use callouts for IP data #46

Merged
merged 1 commit into from
Feb 3, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 19 additions & 20 deletions main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -512,15 +512,15 @@ class IvreSearchData extends IvreSearch {
options.push(address);
const ivre_ipdata = spawnSync("ivre", options);
const data = JSON.parse(ivre_ipdata.stdout.toString());
let answer = "\n# IP Data #\n";
let answer = "> [!ABSTRACT] IP Data\n";
if ("as_num" in data) {
ivre_create_as(
data.as_num,
data.as_name || "-",
vault,
settings.base_directory
);
answer += `\n## Autonomous System ##\n[[${
answer += `> ## Autonomous System ##\n> [[${
settings.base_directory
}/AS/AS${data.as_num}|AS${data.as_num} - ${
data.as_name || "-"
Expand All @@ -533,25 +533,24 @@ class IvreSearchData extends IvreSearch {
vault,
settings.base_directory
);
answer += `\n## Geography ##\n\n### Country ###\n[[${
answer += `> ## Geography ##\n> Country: [[${
settings.base_directory
}/Country/${data.country_code}|${flag_emoji(data.country_code)} - ${
data.country_code
} - ${data.country_name || "-"}]]\n`;
if ("region_code" in data) {
answer += "\n### Region ###\n";
data.region_code.forEach((code: string, index: number) => {
answer += `${code} - ${data.region_name[index] || "-"}\n`;
answer += `> Region: ${code} - ${
data.region_name[index] || "-"
}\n`;
});
}
if ("city" in data) {
answer += `\n### City ###\n${data.city} - ${
data.postal_code || "-"
}\n`;
answer += `> City: ${data.city} - ${data.postal_code || "-"}\n`;
}
}
if ("address_type" in data) {
answer += `\n## Address type ##\n${data.address_type}\n`;
answer += `> ## Address type ##\n> ${data.address_type}\n`;
}
return answer;
}
Expand All @@ -573,11 +572,11 @@ class IvreSearchView extends IvreSearch {
let answer = "";
let tmp_answer = "";
(data.tags || []).forEach((tag: IvreTag) => {
tmp_answer += `\n> [!${tag_type(tag)}]- ${
tmp_answer += `> [!${tag_type(tag)}]- ${
tag.value
}\n> #${tag.value.replace(/ /g, "_")}\n> ${tag.info.join(
"\n> "
)}\n`;
)}\n\n`;
});
if (tmp_answer) {
answer += tmp_answer;
Expand All @@ -588,7 +587,7 @@ class IvreSearchView extends IvreSearch {
ivre_create_category(category, vault, settings.base_directory);
});
if (tmp_answer) {
answer += `\n## Categories ##\n${tmp_answer}`;
answer += `\n# Categories #\n${tmp_answer}`;
}
tmp_answer = "";
((data.addresses || {}).mac || []).forEach((addr: string) => {
Expand All @@ -598,22 +597,22 @@ class IvreSearchView extends IvreSearch {
.replace(/:/g, "")}|${addr}]]\n`;
});
if (tmp_answer) {
answer += `\n## MAC addresses ##\n${tmp_answer}`;
answer += `\n# MAC addresses #\n${tmp_answer}`;
}
tmp_answer = "";
(data.hostnames || []).forEach((hname: IvreHostname) => {
tmp_answer += `- [[${settings.base_directory}/Hostname/${hname.name}|${hname.name}]] (${hname.type})\n`;
ivre_create_hostname(hname.name, vault, settings.base_directory);
});
if (tmp_answer) {
answer += `\n## Hostnames ##\n${tmp_answer}`;
answer += `\n# Hostnames #\n${tmp_answer}`;
}
tmp_answer = "";
(data.ports || []).forEach((port: IvrePort) => {
if (port.port === -1) {
return;
}
tmp_answer += `\n### ${port.protocol}/${port.port} ###\n`;
tmp_answer += `\n## ${port.protocol}/${port.port} ##\n`;
tmp_answer += `- Status: ${port.state_state}\n`;
if (port.service_name) {
tmp_answer += `- Service: ${port.service_name}`;
Expand Down Expand Up @@ -654,7 +653,7 @@ class IvreSearchView extends IvreSearch {
tmp_answer += "\n";
});
if (tmp_answer) {
answer += `\n## Ports ##\n${tmp_answer.substring(
answer += `\n# Ports #\n${tmp_answer.substring(
0,
tmp_answer.length - 1
)}`;
Expand All @@ -675,7 +674,7 @@ class IvreSearchView extends IvreSearch {
for (const line of ivre_view.stdout.toString().split(/\r?\n/)) {
const data = this.process_line(line, vault, settings);
if (data) {
return `\n# View #\n${data}`;
return data;
}
}
return undefined;
Expand All @@ -699,7 +698,7 @@ class IvreSearchView extends IvreSearch {
if (data) {
yield {
address: JSON.parse(line).addr,
data: `\n# View #\n${data}`,
data: data,
};
}
}
Expand All @@ -720,7 +719,7 @@ class IvreSearchView extends IvreSearch {
if (data) {
yield {
address: JSON.parse(line).addr,
data: `\n# View #\n${data}`,
data: data,
};
}
}
Expand All @@ -741,7 +740,7 @@ class IvreSearchView extends IvreSearch {
if (data) {
yield {
address: JSON.parse(line).addr,
data: `\n# View #\n${data}`,
data: data,
};
}
}
Expand Down