2024-06-29 12:43:56 +00:00
|
|
|
/// Name of the cookie that contains session information
|
|
|
|
pub const SESSION_COOKIE_NAME: &str = "X-session-cookie";
|
|
|
|
|
2024-09-09 19:05:52 +00:00
|
|
|
/// Maximum time after a ping during which a device is considered "up"
|
|
|
|
pub const DEVICE_MAX_PING_TIME: u64 = 30;
|
|
|
|
|
2024-06-29 09:45:39 +00:00
|
|
|
/// Fallback value to use if production cannot be fetched
|
|
|
|
pub const FALLBACK_PRODUCTION_VALUE: i32 = 5000;
|
2024-06-29 12:43:56 +00:00
|
|
|
|
|
|
|
/// Maximum session duration after inactivity, in seconds
|
|
|
|
pub const MAX_INACTIVITY_DURATION: u64 = 3600;
|
|
|
|
|
|
|
|
/// Maximum session duration (1 day)
|
|
|
|
pub const MAX_SESSION_DURATION: u64 = 3600 * 24;
|
|
|
|
|
2024-10-05 13:50:46 +00:00
|
|
|
/// Maximum firmware size (in bytes)
|
|
|
|
pub const MAX_FIRMWARE_SIZE: usize = 50 * 1000 * 1000;
|
|
|
|
|
2024-06-29 12:43:56 +00:00
|
|
|
/// List of routes that do not require authentication
|
|
|
|
pub const ROUTES_WITHOUT_AUTH: [&str; 2] =
|
|
|
|
["/web_api/server/config", "/web_api/auth/password_auth"];
|
2024-07-22 20:19:48 +00:00
|
|
|
|
|
|
|
#[derive(serde::Serialize)]
|
|
|
|
pub struct SizeConstraint {
|
|
|
|
/// Minimal string length
|
|
|
|
min: usize,
|
|
|
|
/// Maximal string length
|
|
|
|
max: usize,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl SizeConstraint {
|
|
|
|
pub fn new(min: usize, max: usize) -> Self {
|
|
|
|
Self { min, max }
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn validate(&self, val: &str) -> bool {
|
|
|
|
let len = val.trim().len();
|
|
|
|
len >= self.min && len <= self.max
|
|
|
|
}
|
2024-07-31 21:33:58 +00:00
|
|
|
|
|
|
|
pub fn validate_usize(&self, val: usize) -> bool {
|
|
|
|
val >= self.min && val <= self.max
|
|
|
|
}
|
2024-07-22 20:19:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Backend static constraints
|
|
|
|
#[derive(serde::Serialize)]
|
|
|
|
pub struct StaticConstraints {
|
|
|
|
/// Device name constraint
|
|
|
|
pub dev_name_len: SizeConstraint,
|
|
|
|
/// Device description constraint
|
|
|
|
pub dev_description_len: SizeConstraint,
|
2024-07-29 20:11:13 +00:00
|
|
|
/// Relay name constraint
|
|
|
|
pub relay_name_len: SizeConstraint,
|
|
|
|
/// Relay priority constraint
|
|
|
|
pub relay_priority: SizeConstraint,
|
|
|
|
/// Relay consumption constraint
|
|
|
|
pub relay_consumption: SizeConstraint,
|
|
|
|
/// Relay minimal uptime
|
|
|
|
pub relay_minimal_uptime: SizeConstraint,
|
|
|
|
/// Relay minimal downtime
|
|
|
|
pub relay_minimal_downtime: SizeConstraint,
|
|
|
|
/// Relay daily minimal uptime
|
|
|
|
pub relay_daily_minimal_runtime: SizeConstraint,
|
2024-07-22 20:19:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Default for StaticConstraints {
|
|
|
|
fn default() -> Self {
|
|
|
|
Self {
|
|
|
|
dev_name_len: SizeConstraint::new(1, 50),
|
|
|
|
dev_description_len: SizeConstraint::new(0, 100),
|
2024-07-29 20:11:13 +00:00
|
|
|
relay_name_len: SizeConstraint::new(1, 100),
|
|
|
|
relay_priority: SizeConstraint::new(0, 999999),
|
|
|
|
relay_consumption: SizeConstraint::new(0, 999999),
|
|
|
|
relay_minimal_uptime: SizeConstraint::new(0, 9999999),
|
|
|
|
relay_minimal_downtime: SizeConstraint::new(0, 9999999),
|
|
|
|
relay_daily_minimal_runtime: SizeConstraint::new(0, 3600 * 24),
|
2024-07-22 20:19:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|