Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
cn-kali-team committed Feb 27, 2024
1 parent 478820b commit 5929372
Show file tree
Hide file tree
Showing 13 changed files with 77 additions and 39 deletions.
2 changes: 2 additions & 0 deletions nvd-model/migrations/.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-- we don't know how to generate root <with-no-name> (class Root) :(

12 changes: 0 additions & 12 deletions nvd-model/migrations/nvd/cve_exploit.sql

This file was deleted.

8 changes: 4 additions & 4 deletions nvd-model/migrations/nvd/cve_product.sql
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
create table cve_product
create table nvd.cve_product
(
cve_id varchar(16) not null comment 'CVE编号',
product_id binary(16) not null comment '产品ID',
primary key (cve_id, product_id),
constraint cve_id
foreign key (cve_id) references cves (id),
foreign key (cve_id) references nvd.cves (id),
constraint product_id
foreign key (product_id) references products (id)
foreign key (product_id) references nvd.products (id)
)
comment 'cve_match表';

create index product_id_idx
on cve_product (product_id);
on nvd.cve_product (product_id);

4 changes: 2 additions & 2 deletions nvd-model/migrations/nvd/cves.sql
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
create table cves
create table nvd.cves
(
id varchar(32) not null comment 'CVE编号'
primary key,
Expand All @@ -18,5 +18,5 @@ create table cves
comment 'CVE表';

create index year_idx
on cves (year);
on nvd.cves (year);

2 changes: 1 addition & 1 deletion nvd-model/migrations/nvd/cwes.sql
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
create table cwes
create table nvd.cwes
(
id int not null comment 'CWE ID'
primary key,
Expand Down
4 changes: 2 additions & 2 deletions nvd-model/migrations/nvd/exploits.sql
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
create table exploits
create table nvd.exploits
(
id binary(16) not null comment 'exploits表ID'
primary key,
name varchar(128) not null comment '名称',
description text not null comment 'exploit描述',
description text not null comment 'exploit描述',
source varchar(32) not null comment '来源',
path varchar(512) not null comment '路径',
meta json not null comment '元数据',
Expand Down
4 changes: 2 additions & 2 deletions nvd-model/migrations/nvd/knowledge_base.sql
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
create table knowledge_base
create table nvd.knowledge_base
(
id binary(16) not null comment '知识库表ID'
primary key,
Expand All @@ -14,7 +14,7 @@ create table knowledge_base
constraint knowledge_base_UNIQUE
unique (name, source, links),
constraint kb_cve
foreign key (name) references cves (id)
foreign key (name) references nvd.cves (id)
)
comment '知识库表';

8 changes: 4 additions & 4 deletions nvd-model/migrations/nvd/products.sql
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
create table products
create table nvd.products
(
id binary(16) not null comment '产品ID'
primary key,
vendor_id binary(16) not null comment '提供商外键',
official tinyint(4) unsigned default 0 not null comment '是否为官方数据',
part char default '*' not null comment '硬件设备 h,操作系统 o,应用程序 a',
name varchar(128) not null comment '产品名字',
description text not null comment '产品描述',
description text not null comment '产品描述',
meta json not null comment '元数据',
created_at timestamp default CURRENT_TIMESTAMP not null comment '创建时间',
updated_at timestamp default CURRENT_TIMESTAMP not null on update CURRENT_TIMESTAMP comment '最后更新时间',
Expand All @@ -15,11 +15,11 @@ create table products
constraint name_UNIQUE
unique (vendor_id, name),
constraint product_vendor
foreign key (vendor_id) references vendors (id)
foreign key (vendor_id) references nvd.vendors (id)
on delete cascade
)
comment '产品表';

create index vendor_idx
on products (vendor_id);
on nvd.products (vendor_id);

4 changes: 2 additions & 2 deletions nvd-model/migrations/nvd/vendors.sql
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
create table vendors
create table nvd.vendors
(
id binary(16) not null comment '供应商ID'
primary key,
official tinyint(4) unsigned default 0 not null comment '是否为官方数据',
name varchar(128) not null comment '供应商名字',
description text not null comment '供应商描述',
description text not null comment '供应商描述',
meta json not null comment '元数据',
updated_at timestamp default CURRENT_TIMESTAMP not null on update CURRENT_TIMESTAMP comment '最后更新时间',
created_at timestamp default CURRENT_TIMESTAMP not null comment '创建时间',
Expand Down
40 changes: 40 additions & 0 deletions nvd-yew/src/component/i18n.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
use std::collections::HashMap;
use yew::{Html, Properties};

#[derive(Debug, Clone, PartialEq)]
struct I18nTranslation {
pub lang: Vec<String>,
pub translations: HashMap<String, HashMap<String, String>>,
}

#[derive(Debug, Clone, PartialEq, Properties)]
pub struct I18nTranslationProp {
#[prop_or_else(|| vec ! ["en".to_string(), "zh".to_string()])]
pub lang: Vec<String>,
pub translations: HashMap<String, HashMap<String, String>>,
pub children: Html,
}

#[derive(Clone, PartialEq)]
pub struct I18n {
pub config: I18nTranslation,
current_lang: String,
}

impl I18n {
pub fn new(config: I18nTranslation) -> Self {
let current_lang = config.lang.get(0).unwrap_or(&"en".to_string()).to_string();
Self { config, current_lang }
}
pub fn set_lang(&mut self, lang: String) {
if self.config.lang.contains(&lang) {
self.current_lang = lang;
}
}
pub fn t(&self, text: &str) -> String {
if let Some(dict) = self.config.translations.get(&self.current_lang) {
return dict.get(text).unwrap_or(&text.to_string()).to_string();
}
return text.to_string();
}
}
1 change: 1 addition & 0 deletions nvd-yew/src/component/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,4 @@ mod knowledge_base;
mod pagination;
mod tooltip_popover;
mod weaknesses;
mod i18n;
12 changes: 2 additions & 10 deletions nvd-yew/src/layout/nav.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ pub fn set_title(title: &str) {
if let Some(window) = web_sys::window() {
if let Some(doc) = window.document() {
if let Ok(Some(title_el)) = doc.query_selector("title") {
title_el.set_inner_html(title);
title_el.set_text_content(Some(title));
};
}
};
Expand All @@ -38,15 +38,7 @@ impl Component for Nav {
match msg {
NavMsg::Title => {
let route = ctx.link().route::<Route>().unwrap(); // handle event
let title = match route {
Route::Cve { id } => id,
Route::CveList => String::from("CVE"),
Route::Cpe => String::from("CPE"),
Route::Kb => String::from("KB"),
Route::Home => String::from("Home"),
Route::NotFound => String::from("NotFound"),
};
set_title(&title);
set_title(&route.to_string());
}
}
true
Expand Down
15 changes: 15 additions & 0 deletions nvd-yew/src/routes/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use std::fmt::{Display, Formatter};
use yew::prelude::*;
use yew_router::prelude::*;

Expand Down Expand Up @@ -33,6 +34,20 @@ pub enum Route {
NotFound,
}

impl Display for Route {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
let s = match self {
Route::Cve { id } => { id }
Route::CveList => { "CVE" }
Route::Cpe => { "CPE" }
Route::Kb => { "KB" }
Route::Home => { "Home" }
Route::NotFound => { "Not Found" }
};
f.write_str(s)
}
}

impl Route {
pub(crate) fn switch(routes: Route) -> Html {
match routes {
Expand Down

0 comments on commit 5929372

Please sign in to comment.