Skip to content

Commit

Permalink
fixed displayed info from db, schema fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
z-priest committed Jun 15, 2021
1 parent f99f735 commit 90520fb
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 29 deletions.
7 changes: 7 additions & 0 deletions src/db/create-db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ async function class_query(db: OrientDB.ODatabase, options: IOrientJSONClassOpti
if (idx > -1) {
alias = name;
const replaced = name.replace(/-/g, '');
console.log('found aliases: ', replaced);

name = replaced;
}
try {
Expand All @@ -70,14 +72,19 @@ async function class_query(db: OrientDB.ODatabase, options: IOrientJSONClassOpti
const query = `ALTER CLASS ${name} SHORTNAME ${alias}`;
await db.exec(query);
}
console.log('done with creating superclasses');
return cls;
}

async function create_classes(db: OrientDB.ODatabase) {

for (const cls of schema.classes) {
const c = await class_query(db, cls);
await create_properties(c, cls.properties);
}

console.log('done creating db');
//TODO give user some indication db is being created
}

async function create_properties(cls: OrientDB.Class, props: OrientDB.PropertyCreateConfig[]): Promise<OrientDB.Property[]> {
Expand Down
42 changes: 20 additions & 22 deletions src/db/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ export const schema: ISchemaFile = {
},
{
name: "artifact",
superClasses: ["cyber-observable-core"],
superClasses: ["cyberobservablecore"],
properties: [
{ name: "mime_type", type: "String", collate: "default" },
{ name: "payload_bin", type: "Binary", collate: "default" },
Expand Down Expand Up @@ -175,7 +175,6 @@ export const schema: ISchemaFile = {
name: "attack-pattern",
superClasses: ["core"],
properties: [
{ name: "external_references", type: "EmbeddedList", collate: "default" },
{ name: "name", type: "String", mandatory: true, notNull: true, collate: "default" },
{ name: "description", type: "String", collate: "default" },
{ name: "aliases", type: "EmbeddedList", collate: "default" },
Expand All @@ -190,7 +189,7 @@ export const schema: ISchemaFile = {
},
{
name: "autonomous-system",
superClasses: ["cyber-observable-core"],
superClasses: ["cyberobservablecore"],
properties: [
{ name: "number", type: "Integer", mandatory: true, notNull: true, collate: "default"},
{ name: "name", type: "String", collate: "default" },
Expand Down Expand Up @@ -272,7 +271,7 @@ export const schema: ISchemaFile = {
},
{
name: "directory",
superClasses: ["cyber-observable-core"],
superClasses: ["cyberobservablecore"],
properties: [
{ name: "path", type: "String", mandatory: true, notNull: true, collate: "default" },
{ name: "path_enc", type: "String", collate: "default" },
Expand All @@ -284,7 +283,7 @@ export const schema: ISchemaFile = {
},
{
name: "domain-name",
superClasses: ["cyber-observable-core"],
superClasses: ["cyberobservablecore"],
properties: [
{ name: "value", type: "String", mandatory: true, notNull: true, collate: "default" },
{ name: "resolves_to_refs", type: "EmbeddedList", collate: "default" },
Expand All @@ -310,7 +309,7 @@ export const schema: ISchemaFile = {
},
{
name: "email-addr",
superClasses: ["cyber-observable-core"],
superClasses: ["cyberobservablecore"],
properties: [
{ name: "value", type: "String", mandatory: true, notNull: true, collate: "default" },
{ name: "display_name", type: "String", collate: "default" },
Expand All @@ -319,7 +318,7 @@ export const schema: ISchemaFile = {
},
{
name: "email-message",
superClasses: ["cyber-observable-core"],
superClasses: ["cyberobservablecore"],
properties: [
{ name: "is_multipart", type: "Boolean", mandatory: true, notNull:true , collate: "default" },
{ name: "date", type: "DateTime", collate: "default" },
Expand Down Expand Up @@ -352,7 +351,7 @@ export const schema: ISchemaFile = {
},
{
name: "file",
superClasses: ["cyber-observable-core"],
superClasses: ["cyberobservablecore"],
properties: [
{ name: "hashes", type: "EmbeddedMap", collate: "default" },
{ name: "size", type: "Integer", collate: "default" },
Expand Down Expand Up @@ -465,7 +464,7 @@ export const schema: ISchemaFile = {
},
{
name: "ipv4-addr",
superClasses: ["cyber-observable-core"],
superClasses: ["cyberobservablecore"],
properties: [
{ name: "value", type: "String", mandatory: true, notNull: true, collate: "default" },
{ name: "resolves_to_refs", type: "EmbeddedList", collate: "default" },
Expand All @@ -474,7 +473,7 @@ export const schema: ISchemaFile = {
},
{
name: "ipv6-addr",
superClasses: ["cyber-observable-core"],
superClasses: ["cyberobservablecore"],
properties: [
{ name: "value", type: "String", mandatory: true, notNull: true, collate: "default" },
{ name: "resolves_to_refs", type: "EmbeddedList", collate: "default" },
Expand All @@ -483,7 +482,7 @@ export const schema: ISchemaFile = {
},
{
name: "language-content",
superClasses: ["language-meta-core"],
superClasses: ["languagemetacore"],
properties: [
{ name: "object_ref", type: "String", mandatory: true , notNull: true, collate: "default"},
{ name: "object_modified", type: "DateTime", collate: "default"},
Expand All @@ -509,7 +508,7 @@ export const schema: ISchemaFile = {
},
{
name: "mac-addr",
superClasses: ["cyber-observable-core"],
superClasses: ["cyberobservablecore"],
properties: [
{ name: "value", type: "String", mandatory: true, notNull: true, collate: "default" }
],
Expand Down Expand Up @@ -558,7 +557,7 @@ export const schema: ISchemaFile = {
},
{
name: "marking-definition",
superClasses: ["marking-meta-core"],
superClasses: ["markingmetacore"],
properties: [
{ name: "name", type: "String", collate: "default" },
{ name: "definition_type", type: "String", mandatory: true, notNull: true , collate: "default" },
Expand All @@ -573,14 +572,14 @@ export const schema: ISchemaFile = {
},
{
name: "mutex",
superClasses: ["cyber-observable-core"],
superClasses: ["cyberobservablecore"],
properties: [
{ name: "name", type: "String", mandatory: true, notNull: true, collate: "default" }
],
},
{
name: "network-traffic",
superClasses: ["cyber-observable-core"],
superClasses: ["cyberobservablecore"],
properties: [
{ name: "start", type: "DateTime", collate: "default" },
{ name: "end", type: "DateTime", collate: "default" },
Expand Down Expand Up @@ -645,7 +644,7 @@ export const schema: ISchemaFile = {
},
{
name: "process",
superClasses: ["cyber-observable-core"],
superClasses: ["cyberobservablecore"],
properties: [
{ name: "is_hidden", type: "Boolean", collate: "default" },
{ name: "pid", type: "Integer", collate: "default" },
Expand Down Expand Up @@ -680,7 +679,7 @@ export const schema: ISchemaFile = {
},
{
name: "software",
superClasses: ["cyber-observable-core"],
superClasses: ["cyberobservablecore"],
properties: [
{ name: "name", type: "String", mandatory: true, notNull: true, collate: "default"},
{ name: "cpe", type: "String", collate: "default" },
Expand Down Expand Up @@ -734,14 +733,14 @@ export const schema: ISchemaFile = {
},
{
name: "url",
superClasses: ["cyber-observable-core"],
superClasses: ["cyberobservablecore"],
properties: [
{ name: "value", type: "String", mandatory: true, notNull: true, collate: "default" }
],
},
{
name: "user-account",
superClasses: ["cyber-observable-core"],
superClasses: ["cyberobservablecore"],
properties: [
{ name: "user_id", type: "String", collate: "default" },
{ name: "credential", type: "String", collate: "default" },
Expand Down Expand Up @@ -775,14 +774,13 @@ export const schema: ISchemaFile = {
name: "vulnerability",
superClasses: ["core"],
properties: [
{ name: "external_references", type: "EmbeddedList", collate: "default" },
{ name: "name", type: "String", mandatory: true, notNull: true, collate: "default" },
{ name: "description", type: "String", collate: "default" },
],
},
{
name: "windows-registry-key",
superClasses: ["cyber-observable-core"],
superClasses: ["cyberobservablecore"],
properties: [
{ name: "key", type: "String", collate: "default" },
{ name: "values", type: "EmbeddedList", collate: "default" },
Expand All @@ -793,7 +791,7 @@ export const schema: ISchemaFile = {
},
{
name: "x509-certificate",
superClasses: ["cyber-observable-core"],
superClasses: ["cyberobservablecore"],
properties: [
{ name: "is_self_signed", type: "Boolean", collate: "default" },
{ name: "hashes", type: "EmbeddedMap", collate: "default" },
Expand Down
4 changes: 2 additions & 2 deletions src/graph/graphFunctions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ export class GraphUtils {
}

/**
* pkg should be a JSON object complying to the Stix2.0 bundle schema
* pkg should be a JSON object complying to the Stix2.1 bundle schema
*
* @param {BundleType} pkg
* @returns {Promise<cytoscape.CollectionElements>}
Expand All @@ -160,7 +160,7 @@ export class GraphUtils {
try {
// Add relationships to graph
for (const r of relationships) {
// console.log(`adding relationship ${r.id}`);
console.log(`adding relationship ${r.id}`);
let to_node = this.cy.getElementById(r.target_ref);
let from_node = this.cy.getElementById(r.source_ref);
if (from_node.length === 0) {
Expand Down
15 changes: 10 additions & 5 deletions src/stix/stixnode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export let node_img: { [index: string]: string } = {};
export interface StixNodeData extends cytoscape.NodeDataDefinition {
name?: string; // the_data.name,
id: Identifier; // the_data.id,
label?: string; // the_data.name,
label?: string; // the_data.label,
type: StixType; // the_type,
level?: 1;
// version: the_data.version,
Expand Down Expand Up @@ -46,9 +46,9 @@ export class StixNode implements IStixNode {
* Represents a stix node in the graph. One of these is attached to each node on the canvas.
* The actual data is stored here for easy access. stixNode.raw_data should hold the actual
* stix JSON
* @param {StixNodeData} the_data
* @param {StixType} the_type
* @param {DataSourceType} d_source
* @param {StixNodeData} the_data Object Thrown to Cytoscape Node
* @param {StixType} the_type - Object From Database
* @param {DataSourceType} d_source - Whether we are drag and drop or queried from DB.
*/
constructor(the_data: StixNodeData, the_type: StixType, d_source: DataSourceType) {

Expand All @@ -64,7 +64,12 @@ export class StixNode implements IStixNode {
data_source: d_source,
};
if (the_type !== 'marking-definition') {
this.data.name = the_data.name;
if(the_data.name == undefined){
console.log('the data does not have a name: ', the_data)
this.data.name = the_data.type;
}else{
this.data.name = the_data.name;
}
this.data.modified = the_data.modified;
}

Expand Down
1 change: 1 addition & 0 deletions src/ui/database-config-widget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ class DatabaseConfigDialog {
this.useConfig = $( "#db-config-list input:checked" ).val() as string;
this._storage.current = this.useConfig;
ipcRenderer.send('useDatabase', this._storage.get(this.useConfig));
//add progress bar here tied to
this._anchor.dialog("close");
}

Expand Down

0 comments on commit 90520fb

Please sign in to comment.