2020-05-29 01:05:53 +02:00
|
|
|
// Init of configuration files could also be done via Config crate.
|
|
|
|
|
// But at this point of development it seems like unjustified overhead.
|
|
|
|
|
|
|
|
|
|
extern crate serde_json;
|
|
|
|
|
use std::fs::File;
|
|
|
|
|
|
|
|
|
|
pub struct Config {
|
|
|
|
|
pub filter: String,
|
|
|
|
|
pub insert_max: usize,
|
|
|
|
|
pub pcap_file: String,
|
|
|
|
|
pub connection: String,
|
2020-05-31 00:44:47 +02:00
|
|
|
pub device: String,
|
2020-05-29 01:05:53 +02:00
|
|
|
pub is_device: bool,
|
|
|
|
|
pub pcap_dir: String,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn from_json_file() -> Option<Config> {
|
2020-05-31 00:44:47 +02:00
|
|
|
let config_file = File::open("parser.json").expect("file should open read only");
|
|
|
|
|
let json: serde_json::Value = serde_json::from_reader(config_file).unwrap();
|
|
|
|
|
Some(Config {
|
|
|
|
|
filter: json.get("filter").unwrap().as_str().unwrap().to_owned(),
|
|
|
|
|
insert_max: json.get("insert_max").unwrap().as_u64().unwrap() as usize,
|
|
|
|
|
pcap_file: json.get("pcap_file").unwrap().as_str().unwrap().to_owned(),
|
|
|
|
|
connection: format!(
|
|
|
|
|
"host={} user={} password={}",
|
|
|
|
|
json.get("database_host").unwrap().as_str().unwrap(),
|
|
|
|
|
json.get("database_user").unwrap().as_str().unwrap(),
|
|
|
|
|
json.get("database_password").unwrap().as_str().unwrap(),
|
|
|
|
|
),
|
|
|
|
|
device: json
|
|
|
|
|
.get("parse_device")
|
|
|
|
|
.unwrap()
|
|
|
|
|
.as_str()
|
|
|
|
|
.unwrap()
|
|
|
|
|
.to_owned(),
|
|
|
|
|
is_device: json.get("from_device").unwrap().as_bool().unwrap(),
|
|
|
|
|
pcap_dir: json.get("pcap_dir").unwrap().as_str().unwrap().to_owned(),
|
|
|
|
|
})
|
2020-05-29 01:05:53 +02:00
|
|
|
}
|