diff --git a/src/api2/node.rs b/src/api2/node.rs index cb51f056..4147a02e 100644 --- a/src/api2/node.rs +++ b/src/api2/node.rs @@ -5,6 +5,7 @@ use serde_json::{json}; mod time; mod network; mod dns; +mod syslog; pub fn router() -> Router { @@ -12,11 +13,13 @@ pub fn router() -> Router { .get(ApiMethod::new( |_,_| Ok(json!([ {"subdir": "network"}, - {"subdir": "time"}, + {"subdir": "syslog"}, + {"subdir": "time"}, ])), ObjectSchema::new("Directory index."))) .subdir("dns", dns::router()) .subdir("network", network::router()) + .subdir("syslog", syslog::router()) .subdir("time", time::router()); route diff --git a/src/api2/node/syslog.rs b/src/api2/node/syslog.rs new file mode 100644 index 00000000..966c1dd1 --- /dev/null +++ b/src/api2/node/syslog.rs @@ -0,0 +1,64 @@ +use failure::*; + +use crate::tools; +use crate::api::schema::*; +use crate::api::router::*; +use serde_json::{json, Value}; + +use std::sync::Arc; +use lazy_static::lazy_static; +use crate::tools::common_regex; + +fn get_syslog(param: Value, _info: &ApiMethod) -> Result { + + let result = json!({}); + + Ok(result) +} + +lazy_static! { + pub static ref SYSTEMD_DATETIME_FORMAT: Arc = + ApiStringFormat::Pattern(&common_regex::SYSTEMD_DATETIME_REGEX).into(); +} + +pub fn router() -> Router { + + let route = Router::new() + .get( + ApiMethod::new( + get_syslog, + ObjectSchema::new("Read server time and time zone settings.") + .optional( + "start", + IntegerSchema::new("Start line number.") + .minimum(0) + ) + .optional( + "limit", + IntegerSchema::new("Max. number of lines.") + .minimum(0) + ) + .optional( + "since", + StringSchema::new("Display all log since this date-time string.") + .format(SYSTEMD_DATETIME_FORMAT.clone()) + ) + .optional( + "until", + StringSchema::new("Display all log until this date-time string.") + .format(SYSTEMD_DATETIME_FORMAT.clone()) + ) + .optional( + "service", + StringSchema::new("Service ID.") + .max_length(128) + ) + ).returns( + ObjectSchema::new("Returns a list of syslog entries.") + .required("n", IntegerSchema::new("Line number.")) + .required("t", StringSchema::new("Line text.")) + ) + ); + + route +} diff --git a/src/tools/common_regex.rs b/src/tools/common_regex.rs index 322476be..a3fb655c 100644 --- a/src/tools/common_regex.rs +++ b/src/tools/common_regex.rs @@ -35,5 +35,11 @@ macro_rules! IPRE { () => (concat!(r"(?:", IPV4RE!(), "|", IPV6RE!(), ")")) } lazy_static! { pub static ref IP_REGEX: Regex = Regex::new(IPRE!()).unwrap(); - pub static ref SHA256_HEX_REGEX: Regex = Regex::new("^[a-f0-9]{64}$").unwrap(); + pub static ref SHA256_HEX_REGEX: Regex = + Regex::new(r"^[a-f0-9]{64}$") + .unwrap(); + + pub static ref SYSTEMD_DATETIME_REGEX: Regex = + Regex::new(r"^\d{4}-\d{2}-\d{2}( \d{2}:\d{2}(:\d{2})?)?$") + .unwrap(); }