Skip to content

Commit

Permalink
fly:query
Browse files Browse the repository at this point in the history
  • Loading branch information
cn-kali-team committed Apr 11, 2024
1 parent 79045f6 commit 8bff5f6
Show file tree
Hide file tree
Showing 9 changed files with 403 additions and 397 deletions.
2 changes: 1 addition & 1 deletion cnvd/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ pub fn add(left: usize, right: usize) -> usize {
#[cfg(test)]
mod tests {
use super::*;
use crate::cnnvd::CNNVDResult;


#[test]
fn it_works() {
Expand Down
2 changes: 1 addition & 1 deletion nvd-yew/i18n.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"Access Complexity":{"zh":"访问复杂度"},"Access Vector":{"zh":"访问途径"},"AdjacentNetwork":{"zh":"相邻网络"},"Attack Complexity":{"zh":"攻击复杂度"},"Attack Vector":{"zh":"攻击途径"},"Authentication":{"zh":"认证"},"Availability Impact":{"zh":"可用性影响度"},"CPE":{"zh":"通用平台枚举"},"CVE":{"zh":"CVE编号"},"CVSS":{"zh":"评分"},"CWE":{"zh":"脆弱点"},"Changed":{"zh":"更改"},"Comments":{"zh":"评论"},"Complete":{"zh":"完全"},"Confidentiality Impact":{"zh":"机密性影响度"},"Configurations":{"zh":"影响产品"},"Count":{"zh":"条"},"Deprecated":{"zh":"废弃"},"Draft":{"zh":"草稿"},"Entries":{"zh":"共"},"High":{"zh":"高"},"Home":{"zh":"主页"},"Incomplete":{"zh":"不完整的"},"Integrity Impact":{"zh":"完整性影响度"},"KnowledgeBase":{"zh":"知识库"},"Lang":{"zh":"语言"},"Link":{"zh":"链接"},"Local":{"zh":"本地网络"},"Low":{"zh":"低"},"Match":{"zh":"影响版本"},"Medium":{"zh":"中"},"Meta":{"zh":"元数据"},"Multiple":{"zh":"多个"},"Name":{"zh":"名称"},"Network":{"zh":"网络"},"Next":{"zh":"下一页"},"None":{"zh":"无"},"Obsolete":{"zh":"过时的"},"Operator":{"zh":"逻辑"},"Partial":{"zh":"部分"},"Path":{"zh":"路径"},"Physical":{"zh":"物理"},"Prev":{"zh":"上一页"},"Privileges Required":{"zh":"权限要求"},"Product":{"zh":"产品"},"Products":{"zh":"产品"},"References":{"zh":"参考"},"Required":{"zh":"需要"},"Resource":{"zh":"资源"},"Scope":{"zh":"作用域属性"},"Show":{"zh":"展示"},"Single":{"zh":"单个"},"Source":{"zh":"来源"},"Source Code":{"zh":"源码"},"Sponsor":{"zh":"赞助"},"Stable":{"zh":"稳定的"},"Tags":{"zh":"标签"},"To":{"zh":"到"},"Unchanged":{"zh":"未更改"},"Updated":{"zh":"更新时间"},"User Interaction":{"zh":"用户交互"},"Vendor":{"zh":"厂商"},"Vendors":{"zh":"厂商"},"Verified":{"zh":"是否已验证"},"Version":{"zh":"版本"},"Weaknesses":{"zh":"脆弱点"}}
{"Access Complexity":{"zh":"访问复杂度"},"Access Vector":{"zh":"访问途径"},"AdjacentNetwork":{"zh":"相邻网络"},"Attack Complexity":{"zh":"攻击复杂度"},"Attack Vector":{"zh":"攻击途径"},"Authentication":{"zh":"认证"},"Availability Impact":{"zh":"可用性影响度"},"CPE":{"zh":"通用平台枚举"},"CVE":{"zh":"CVE编号"},"CVSS":{"zh":"评分"},"CWE":{"zh":"脆弱点"},"Changed":{"zh":"更改"},"Comments":{"zh":"评论"},"Complete":{"zh":"完全"},"Confidentiality Impact":{"zh":"机密性影响度"},"Configurations":{"zh":"影响产品"},"Count":{"zh":"条"},"Deprecated":{"zh":"废弃"},"Draft":{"zh":"草稿"},"Entries":{"zh":"共"},"High":{"zh":"高"},"Home":{"zh":"主页"},"Incomplete":{"zh":"不完整的"},"Integrity Impact":{"zh":"完整性影响度"},"KnowledgeBase":{"zh":"知识库"},"Lang":{"zh":"语言"},"Link":{"zh":"链接"},"Local":{"zh":"本地网络"},"Low":{"zh":"低"},"Match":{"zh":"影响版本"},"Medium":{"zh":"中"},"Meta":{"zh":"元数据"},"Multiple":{"zh":"多个"},"Name":{"zh":"名称"},"Network":{"zh":"网络"},"Next":{"zh":"下一页"},"None":{"zh":"无"},"Obsolete":{"zh":"过时的"},"Operator":{"zh":"逻辑"},"Part":{"zh":"分类"},"Partial":{"zh":"部分"},"Path":{"zh":"路径"},"Physical":{"zh":"物理"},"Prev":{"zh":"上一页"},"Privileges Required":{"zh":"权限要求"},"Product":{"zh":"产品"},"Products":{"zh":"产品"},"References":{"zh":"参考"},"Required":{"zh":"需要"},"Resource":{"zh":"资源"},"Scope":{"zh":"作用域属性"},"Severity":{"zh":"危害等级"},"Show":{"zh":"展示"},"Single":{"zh":"单个"},"Source":{"zh":"来源"},"Source Code":{"zh":"源码"},"Sponsor":{"zh":"赞助"},"Stable":{"zh":"稳定的"},"Tags":{"zh":"标签"},"To":{"zh":"到"},"Unchanged":{"zh":"未更改"},"Updated":{"zh":"更新时间"},"User Interaction":{"zh":"用户交互"},"Vendor":{"zh":"厂商"},"Vendors":{"zh":"厂商"},"Verified":{"zh":"是否已验证"},"Version":{"zh":"版本"},"Weaknesses":{"zh":"脆弱点"},"application":{"zh":"应用软件"},"critical":{"zh":"严重"},"hardware devices":{"zh":"硬件设备"},"high":{"zh":"高危"},"low":{"zh":"低危"},"medium":{"zh":"中危"},"none":{"zh":"置空"},"operating system":{"zh":"操作系统"}}
22 changes: 21 additions & 1 deletion nvd-yew/i18n.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -129,4 +129,24 @@ Incomplete:
Obsolete:
zh: 过时的
Stable:
zh: 稳定的
zh: 稳定的
Severity:
zh: 危害等级
none:
zh: 置空
low:
zh: 低危
medium:
zh: 中危
high:
zh: 高危
critical:
zh: 严重
Part:
zh: 分类
application:
zh: 应用软件
"operating system":
zh: 操作系统
"hardware devices":
zh: 硬件设备
251 changes: 122 additions & 129 deletions nvd-yew/src/component/cpe_query.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use crate::component::use_translation;
use nvd_model::product::QueryProduct;
use web_sys::{HtmlButtonElement, HtmlInputElement};
use yew::prelude::*;
Expand All @@ -11,146 +12,138 @@ pub struct CPEQueryProps {
pub query_part: Callback<MouseEvent>,
pub query: Callback<QueryProduct>,
}
pub struct CPEQuery;
impl Component for CPEQuery {
type Message = ();
type Properties = CPEQueryProps;

fn create(_ctx: &Context<Self>) -> Self {
Self
}

fn view(&self, ctx: &Context<Self>) -> Html {
let is_product = ctx.props().is_product.unwrap_or_default();
let query = ctx.props().props.clone();
let query_part = ctx.props().query_part.clone();
let part_input = NodeRef::default();
let vendor_input = NodeRef::default();
let product_input = NodeRef::default();
let search_input = NodeRef::default();
let submit_button = NodeRef::default();
// 点击的是b标签,但是事件冒泡会将事件传到按钮
let on_submit = {
let part_input = part_input.clone();
let vendor_input = vendor_input.clone();
let product_input = product_input.clone();
let query = query.clone();
let query_callback = ctx.props().query.clone();
Callback::from(move |event: SubmitEvent| {
event.prevent_default();
let part = if is_product {
part_input.cast::<HtmlInputElement>().unwrap().value()
} else {
String::new()
};
let vendor = vendor_input
#[function_component]
pub fn CPEQuery(props: &CPEQueryProps) -> Html {
let i18n = use_translation();
let is_product = props.is_product.unwrap_or_default();
let query = props.props.clone();
let query_part = props.query_part.clone();
let part_input = NodeRef::default();
let vendor_input = NodeRef::default();
let product_input = NodeRef::default();
let search_input = NodeRef::default();
let submit_button = NodeRef::default();
// 点击的是b标签,但是事件冒泡会将事件传到按钮
let on_submit = {
let part_input = part_input.clone();
let vendor_input = vendor_input.clone();
let product_input = product_input.clone();
let query = query.clone();
let query_callback = props.query.clone();
Callback::from(move |event: SubmitEvent| {
event.prevent_default();
let part = if is_product {
part_input.cast::<HtmlInputElement>().unwrap().value()
} else {
String::new()
};
let vendor = vendor_input
.cast::<HtmlInputElement>()
.unwrap()
.value()
.trim()
.to_string();
let product = if is_product {
product_input
.cast::<HtmlInputElement>()
.unwrap()
.value()
.trim()
.to_string();
let product = if is_product {
.to_string()
} else {
String::new()
};
// let search = search_input.cast::<HtmlInputElement>().unwrap().value();
query_callback.emit(QueryProduct {
vendor_id: None,
vendor_name: if vendor.is_empty() {
None
} else {
Some(vendor)
},
name: if product.is_empty() {
None
} else {
Some(product)
},
part: if part.is_empty() { None } else { Some(part) },
size: query.size,
page: None,
official: None,
})
})
};
let clean = {
let part_input = part_input.clone();
let vendor_input = vendor_input.clone();
let product_input = product_input.clone();
let search_input = search_input.clone();
let submit_button = submit_button.clone();
Callback::from(move |event: MouseEvent| {
let target = event
.target_unchecked_into::<HtmlButtonElement>()
.parent_element()
.unwrap();
let v = target.get_attribute("value").unwrap_or_default();
match v.as_str() {
"part_input" => {
part_input.cast::<HtmlInputElement>().unwrap().set_value("");
}
"vendor_input" => {
vendor_input
.cast::<HtmlInputElement>()
.unwrap()
.set_value("");
}
"product_input" => {
product_input
.cast::<HtmlInputElement>()
.unwrap()
.value()
.trim()
.to_string()
} else {
String::new()
};
// let search = search_input.cast::<HtmlInputElement>().unwrap().value();
query_callback.emit(QueryProduct {
vendor_id: None,
vendor_name: if vendor.is_empty() {
None
} else {
Some(vendor)
},
name: if product.is_empty() {
None
} else {
Some(product)
},
part: if part.is_empty() { None } else { Some(part) },
size: query.size,
page: None,
official: None,
})
})
};
let clean = {
let part_input = part_input.clone();
let vendor_input = vendor_input.clone();
let product_input = product_input.clone();
let search_input = search_input.clone();
let submit_button = submit_button.clone();
Callback::from(move |event: MouseEvent| {
let target = event
.target_unchecked_into::<HtmlButtonElement>()
.parent_element()
.unwrap();
let v = target.get_attribute("value").unwrap_or_default();
match v.as_str() {
"part_input" => {
part_input.cast::<HtmlInputElement>().unwrap().set_value("");
}
"vendor_input" => {
vendor_input
.cast::<HtmlInputElement>()
.unwrap()
.set_value("");
}
"product_input" => {
product_input
.cast::<HtmlInputElement>()
.unwrap()
.set_value("");
}
"search_input" => {
search_input
.cast::<HtmlInputElement>()
.unwrap()
.set_value("");
}
_ => {}
.set_value("");
}
submit_button.cast::<HtmlButtonElement>().unwrap().click();
})
};
html! {
<div class="card-body border-bottom py-1">
<div class="d-flex">
<form class="row g-1 d-flex" onsubmit={on_submit}>
<div class="col input-icon input-group input-group-flat text-muted">
<input type="text" class="form-control" aria-label="vendor" placeholder="Vendor" ref={vendor_input} value={query.vendor_name.clone()}/>
<button class="input-group-text" onclick={clean.clone()} value="vendor_input"><i class="ti ti-x link-danger"></i></button>
</div>
if is_product{
<div class="col input-icon input-group input-group-flat text-muted">
<input type="text" class="form-control" aria-label="product" placeholder="Product" ref={product_input} value={query.name.clone()}/>
<button class="input-group-text" onclick={clean.clone()} value="product_input"><i class="ti ti-x link-danger"></i></button>
</div>
<div class="col input-group input-group-flat">
<button type="button" class="btn dropdown-toggle" data-bs-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
{"Part"}
</button>
<ul class="dropdown-menu">
<li><button onclick={query_part.clone()} type="button" class="dropdown-item btn bg-secondary btn-sm" value="none">{"none"}</button></li>
<li><button onclick={query_part.clone()} type="button" class="dropdown-item btn bg-info btn-sm" value="a">{"application"}</button></li>
<li><button onclick={query_part.clone()} type="button" class="dropdown-item btn bg-warning btn-sm" value="o">{"operating system"}</button></li>
<li><button onclick={query_part.clone()} type="button" class="dropdown-item btn bg-danger btn-sm" value="h">{"hardware devices"}</button></li>
</ul>
<input type="text" class="form-control" readonly=true ref={part_input} value={query.part.clone()}/>
<button class="input-group-text" onclick={clean.clone()} value="part_input"><i class="ti ti-x link-danger"></i></button>
"search_input" => {
search_input
.cast::<HtmlInputElement>()
.unwrap()
.set_value("");
}
_ => {}
}
submit_button.cast::<HtmlButtonElement>().unwrap().click();
})
};
html! {
<div class="card-body border-bottom py-1">
<div class="d-flex">
<form class="row g-1 d-flex" onsubmit={on_submit}>
<div class="col input-icon input-group input-group-flat text-muted">
<input type="text" class="form-control" aria-label="vendor" placeholder="Vendor" ref={vendor_input} value={query.vendor_name.clone()}/>
<button class="input-group-text" onclick={clean.clone()} value="vendor_input"><i class="ti ti-x link-danger"></i></button>
</div>
if is_product{
<div class="col input-icon input-group input-group-flat text-muted">
<input type="text" class="form-control" aria-label="product" placeholder="Product" ref={product_input} value={query.name.clone()}/>
<button class="input-group-text" onclick={clean.clone()} value="product_input"><i class="ti ti-x link-danger"></i></button>
</div>
<div class="col">
<button type="button" class="btn dropdown-toggle" data-bs-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
<i class="ti ti-separator"></i>{i18n.t("Part")}
</button>
<div class="dropdown-menu">
<li><button onclick={query_part.clone()} type="button" value="none"><span class="dropdown-item btn bg-secondary btn-sm" style="pointer-events: none;"></span>{i18n.t("none")}</button></li>
<li><button onclick={query_part.clone()} type="button" value="a"><span class="dropdown-item btn bg-info btn-sm" style="pointer-events: none;"></span>{i18n.t("application")}</button></li>
<li><button onclick={query_part.clone()} type="button" value="o"><span class="dropdown-item btn bg-warning btn-sm" style="pointer-events: none;"></span>{i18n.t("operating system")}</button></li>
<li><button onclick={query_part.clone()} type="button" value="h"><span class="dropdown-item btn bg-danger btn-sm" style="pointer-events: none;"></span>{i18n.t("hardware devices")}</button></li>
</div>
}
<div class="col-auto d-flex">
<button class="btn" type="submit" ref={submit_button}><i class="ti ti-search"></i></button>
<input type="text" class="form-control" style="display: none;" readonly=true ref={part_input} value={query.part.clone()}/>
</div>
</form>
}
<div class="col-auto d-flex">
<button class="btn" type="submit" ref={submit_button}><i class="ti ti-search"></i></button>
</div>
</form>
</div>
}
}
</div>
}
}
Loading

0 comments on commit 8bff5f6

Please sign in to comment.