Compare commits
1 Commits
renovate/t
...
f9a43763b9
Author | SHA1 | Date | |
---|---|---|---|
f9a43763b9 |
@@ -5,7 +5,7 @@ name: default
|
||||
|
||||
steps:
|
||||
- name: web_build
|
||||
image: node:23
|
||||
image: node:21
|
||||
volumes:
|
||||
- name: web_app
|
||||
path: /tmp/web_build
|
||||
@@ -56,7 +56,7 @@ steps:
|
||||
- ls -lah target/release/central_backend
|
||||
|
||||
- name: esp32_compile
|
||||
image: espressif/idf:v5.4.2
|
||||
image: espressif/idf:v5.3.1
|
||||
commands:
|
||||
- cd esp32_device
|
||||
- /opt/esp/entrypoint.sh idf.py build
|
||||
|
1316
central_backend/Cargo.lock
generated
1316
central_backend/Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
@@ -1,46 +1,46 @@
|
||||
[package]
|
||||
name = "central_backend"
|
||||
version = "1.0.2"
|
||||
edition = "2024"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
log = "0.4.28"
|
||||
env_logger = "0.11.8"
|
||||
log = "0.4.22"
|
||||
env_logger = "0.11.5"
|
||||
lazy_static = "1.5.0"
|
||||
dotenvy = "0.15.7"
|
||||
clap = { version = "4.5.47", features = ["derive", "env"] }
|
||||
anyhow = "1.0.99"
|
||||
thiserror = "2.0.16"
|
||||
openssl = { version = "0.10.73" }
|
||||
openssl-sys = "0.9.109"
|
||||
libc = "0.2.175"
|
||||
clap = { version = "4.5.20", features = ["derive", "env"] }
|
||||
anyhow = "1.0.89"
|
||||
thiserror = "2.0.3"
|
||||
openssl = { version = "0.10.66" }
|
||||
openssl-sys = "0.9.102"
|
||||
libc = "0.2.159"
|
||||
foreign-types-shared = "0.1.1"
|
||||
asn1 = "0.22.0"
|
||||
actix-web = { version = "4.11.0", features = ["openssl"] }
|
||||
asn1 = "0.20"
|
||||
actix-web = { version = "4", features = ["openssl"] }
|
||||
futures = "0.3.31"
|
||||
serde = { version = "1.0.219", features = ["derive"] }
|
||||
reqwest = { version = "0.12.23", features = ["json"] }
|
||||
serde_json = "1.0.143"
|
||||
rand = "0.9.2"
|
||||
serde = { version = "1.0.215", features = ["derive"] }
|
||||
reqwest = { version = "0.12.7", features = ["json"] }
|
||||
serde_json = "1.0.131"
|
||||
rand = "0.8.5"
|
||||
actix = "0.13.5"
|
||||
actix-identity = "0.8.0"
|
||||
actix-session = { version = "0.10.1", features = ["cookie-session"] }
|
||||
actix-cors = "0.7.1"
|
||||
actix-cors = "0.7.0"
|
||||
actix-multipart = { version = "0.7.2", features = ["derive"] }
|
||||
actix-remote-ip = "0.1.0"
|
||||
futures-util = "0.3.31"
|
||||
uuid = { version = "1.17.0", features = ["v4", "serde"] }
|
||||
semver = { version = "1.0.27", features = ["serde"] }
|
||||
lazy-regex = "3.4.1"
|
||||
tokio = { version = "1.47.1", features = ["full"] }
|
||||
uuid = { version = "1.11.0", features = ["v4", "serde"] }
|
||||
semver = { version = "1.0.23", features = ["serde"] }
|
||||
lazy-regex = "3.3.0"
|
||||
tokio = { version = "1.40.0", features = ["full"] }
|
||||
tokio_schedule = "0.3.2"
|
||||
mime_guess = "2.0.5"
|
||||
rust-embed = "8.7.2"
|
||||
jsonwebtoken = { version = "9.3.1", features = ["use_pem"] }
|
||||
rust-embed = "8.5.0"
|
||||
jsonwebtoken = { version = "9.3.0", features = ["use_pem"] }
|
||||
prettytable-rs = "0.10.0"
|
||||
chrono = "0.4.42"
|
||||
chrono = "0.4.38"
|
||||
serde_yml = "0.0.12"
|
||||
bincode = "2.0.1"
|
||||
fs4 = { version = "0.13.1", features = ["sync"] }
|
||||
bincode = "=2.0.0-rc.3"
|
||||
fs4 = { version = "0.12.0", features = ["sync"] }
|
||||
zip = { version = "2.2.0", features = ["bzip2"] }
|
||||
walkdir = "2.5.0"
|
||||
walkdir = "2.5.0"
|
@@ -16,13 +16,11 @@ impl CRLDistributionPointExt {
|
||||
let crl_bytes = asn1::write(|w| {
|
||||
w.write_element(&asn1::SequenceWriter::new(&|w| {
|
||||
w.write_element(&asn1::SequenceWriter::new(&|w| {
|
||||
w.write_tlv(tag_a0, None, |w: &mut asn1::WriteBuf| {
|
||||
w.write_tlv(tag_a0, |w| {
|
||||
w.push_slice(&asn1::write(|w| {
|
||||
w.write_tlv(tag_a0, None, |w: &mut asn1::WriteBuf| {
|
||||
w.write_tlv(tag_a0, |w| {
|
||||
w.push_slice(&asn1::write(|w| {
|
||||
w.write_tlv(tag_86, None, |b| {
|
||||
b.push_slice(self.url.as_bytes())
|
||||
})?;
|
||||
w.write_tlv(tag_86, |b| b.push_slice(self.url.as_bytes()))?;
|
||||
Ok(())
|
||||
})?)
|
||||
})?;
|
||||
|
@@ -13,10 +13,10 @@ use openssl::pkey::{PKey, Private};
|
||||
use openssl::x509::extension::{
|
||||
BasicConstraints, ExtendedKeyUsage, KeyUsage, SubjectAlternativeName, SubjectKeyIdentifier,
|
||||
};
|
||||
use openssl::x509::{CrlStatus, X509, X509Crl, X509Name, X509NameBuilder, X509Req};
|
||||
use openssl::x509::{CrlStatus, X509Crl, X509Name, X509NameBuilder, X509Req, X509};
|
||||
use openssl_sys::{
|
||||
X509_CRL_add0_revoked, X509_CRL_new, X509_CRL_set_issuer_name, X509_CRL_set_version,
|
||||
X509_CRL_set1_lastUpdate, X509_CRL_set1_nextUpdate, X509_CRL_sign, X509_REVOKED_dup,
|
||||
X509_CRL_add0_revoked, X509_CRL_new, X509_CRL_set1_lastUpdate, X509_CRL_set1_nextUpdate,
|
||||
X509_CRL_set_issuer_name, X509_CRL_set_version, X509_CRL_sign, X509_REVOKED_dup,
|
||||
X509_REVOKED_new, X509_REVOKED_set_revocationDate, X509_REVOKED_set_serialNumber,
|
||||
};
|
||||
|
||||
@@ -174,16 +174,17 @@ fn gen_certificate(req: GenCertificateReq) -> anyhow::Result<(Option<Vec<u8>>, V
|
||||
cert_builder.set_not_after(¬_after)?;
|
||||
|
||||
// Specify CRL URL
|
||||
if let Some(issuer) = req.issuer
|
||||
&& let Some(crl) = &issuer.crl
|
||||
{
|
||||
let crl_url = format!(
|
||||
"{}/pki/{}",
|
||||
AppConfig::get().unsecure_origin(),
|
||||
crl.file_name().unwrap().to_string_lossy()
|
||||
);
|
||||
if let Some(issuer) = req.issuer {
|
||||
if let Some(crl) = &issuer.crl {
|
||||
let crl_url = format!(
|
||||
"{}/pki/{}",
|
||||
AppConfig::get().unsecure_origin(),
|
||||
crl.file_name().unwrap().to_string_lossy()
|
||||
);
|
||||
|
||||
cert_builder.append_extension(CRLDistributionPointExt { url: crl_url }.as_extension()?)?;
|
||||
cert_builder
|
||||
.append_extension(CRLDistributionPointExt { url: crl_url }.as_extension()?)?;
|
||||
}
|
||||
}
|
||||
|
||||
// If cert is a CA or not
|
||||
@@ -423,12 +424,12 @@ fn refresh_crl(d: &CertData, new_cert: Option<&X509>) -> anyhow::Result<()> {
|
||||
}
|
||||
|
||||
// Add old entries
|
||||
if let Some(old_crl) = old_crl
|
||||
&& let Some(entries) = old_crl.get_revoked()
|
||||
{
|
||||
for entry in entries {
|
||||
if X509_CRL_add0_revoked(crl, X509_REVOKED_dup(entry.as_ptr())) == 0 {
|
||||
return Err(PKIError::GenCRLError("X509_CRL_add0_revoked").into());
|
||||
if let Some(old_crl) = old_crl {
|
||||
if let Some(entries) = old_crl.get_revoked() {
|
||||
for entry in entries {
|
||||
if X509_CRL_add0_revoked(crl, X509_REVOKED_dup(entry.as_ptr())) == 0 {
|
||||
return Err(PKIError::GenCRLError("X509_CRL_add0_revoked").into());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -325,11 +325,9 @@ mod tests {
|
||||
..Default::default()
|
||||
};
|
||||
dep_cycle_1.depends_on = vec![dep_cycle_3.id];
|
||||
assert!(
|
||||
dep_cycle_1
|
||||
.error(&[dep_cycle_2.clone(), dep_cycle_3.clone()])
|
||||
.is_some()
|
||||
);
|
||||
assert!(dep_cycle_1
|
||||
.error(&[dep_cycle_2.clone(), dep_cycle_3.clone()])
|
||||
.is_some());
|
||||
|
||||
dep_cycle_1.depends_on = vec![];
|
||||
assert!(dep_cycle_1.error(&[dep_cycle_2, dep_cycle_3]).is_none());
|
||||
@@ -353,29 +351,21 @@ mod tests {
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
assert!(
|
||||
target_relay
|
||||
.error(&[other_dep.clone(), second_dep.clone()])
|
||||
.is_some()
|
||||
);
|
||||
assert!(
|
||||
target_relay
|
||||
.error(&[other_dep.clone(), second_dep.clone(), target_relay.clone()])
|
||||
.is_some()
|
||||
);
|
||||
assert!(target_relay
|
||||
.error(&[other_dep.clone(), second_dep.clone()])
|
||||
.is_some());
|
||||
assert!(target_relay
|
||||
.error(&[other_dep.clone(), second_dep.clone(), target_relay.clone()])
|
||||
.is_some());
|
||||
|
||||
second_dep.conflicts_with = vec![];
|
||||
|
||||
assert!(
|
||||
target_relay
|
||||
.error(&[other_dep.clone(), second_dep.clone()])
|
||||
.is_none()
|
||||
);
|
||||
assert!(
|
||||
target_relay
|
||||
.error(&[other_dep.clone(), second_dep.clone(), target_relay.clone()])
|
||||
.is_none()
|
||||
);
|
||||
assert!(target_relay
|
||||
.error(&[other_dep.clone(), second_dep.clone()])
|
||||
.is_none());
|
||||
assert!(target_relay
|
||||
.error(&[other_dep.clone(), second_dep.clone(), target_relay.clone()])
|
||||
.is_none());
|
||||
|
||||
// self loop
|
||||
let mut self_loop = DeviceRelay {
|
||||
|
@@ -4,7 +4,7 @@ use crate::devices::device::{
|
||||
Device, DeviceGeneralInfo, DeviceId, DeviceInfo, DeviceRelay, DeviceRelayID,
|
||||
};
|
||||
use crate::utils::time_utils::time_secs;
|
||||
use openssl::x509::{X509, X509Req};
|
||||
use openssl::x509::{X509Req, X509};
|
||||
use std::collections::HashMap;
|
||||
|
||||
#[derive(thiserror::Error, Debug)]
|
||||
|
@@ -1,5 +1,5 @@
|
||||
use crate::app_config::{AppConfig, ConsumptionBackend};
|
||||
use rand::{Rng, rng};
|
||||
use rand::{thread_rng, Rng};
|
||||
use std::num::ParseIntError;
|
||||
use std::path::Path;
|
||||
|
||||
@@ -49,7 +49,7 @@ pub async fn get_curr_consumption() -> anyhow::Result<EnergyConsumption> {
|
||||
match backend {
|
||||
ConsumptionBackend::Constant { value } => Ok(*value),
|
||||
|
||||
ConsumptionBackend::Random { min, max } => Ok(rng().random_range(*min..*max)),
|
||||
ConsumptionBackend::Random { min, max } => Ok(thread_rng().gen_range(*min..*max)),
|
||||
|
||||
ConsumptionBackend::File { path } => {
|
||||
let path = Path::new(path);
|
||||
|
@@ -1,7 +1,7 @@
|
||||
use std::collections::HashMap;
|
||||
|
||||
use crate::app_config::AppConfig;
|
||||
use prettytable::{Table, row};
|
||||
use prettytable::{row, Table};
|
||||
|
||||
use crate::constants;
|
||||
use crate::devices::device::{Device, DeviceId, DeviceRelay, DeviceRelayID};
|
||||
@@ -289,11 +289,7 @@ impl EnergyEngine {
|
||||
continue;
|
||||
}
|
||||
|
||||
log::info!(
|
||||
"Forcefully turn on relay {} to catch up running constraints (only {}s this day)",
|
||||
r.name,
|
||||
total_runtime
|
||||
);
|
||||
log::info!("Forcefully turn on relay {} to catch up running constraints (only {}s this day)", r.name, total_runtime);
|
||||
new_relays_state.get_mut(&r.id).unwrap().on = true;
|
||||
}
|
||||
}
|
||||
|
@@ -1,7 +1,7 @@
|
||||
use crate::app_config::AppConfig;
|
||||
use crate::devices::device::{DeviceRelay, DeviceRelayID};
|
||||
use crate::utils::files_utils;
|
||||
use crate::utils::time_utils::{day_number, time_secs, time_start_of_day};
|
||||
use crate::utils::time_utils::{day_number, time_start_of_day};
|
||||
|
||||
const TIME_INTERVAL: usize = 30;
|
||||
|
||||
@@ -128,26 +128,15 @@ pub fn relay_total_runtime_adjusted(relay: &DeviceRelay) -> usize {
|
||||
.unwrap_or(0);
|
||||
|
||||
let time_start_day = time_start_of_day().unwrap_or(1726696800);
|
||||
|
||||
// Check if we have reached reset_time today yet or not
|
||||
if time_start_day + reset_time as u64 <= time_secs() {
|
||||
let start_time = time_start_day + reset_time as u64;
|
||||
let end_time = time_start_day + 3600 * 24 + reset_time as u64;
|
||||
relay_total_runtime(relay.id, start_time, end_time).unwrap_or(3600 * 24)
|
||||
}
|
||||
// If we have not reached reset time yet, we need to focus on previous day
|
||||
else {
|
||||
let time_start_yesterday = time_start_day - 3600 * 24;
|
||||
let start_time = time_start_yesterday + reset_time as u64;
|
||||
let end_time = time_start_day + reset_time as u64;
|
||||
relay_total_runtime(relay.id, start_time, end_time).unwrap_or(3600 * 24)
|
||||
}
|
||||
let start_time = time_start_day + reset_time as u64;
|
||||
let end_time = time_start_day + 3600 * 24 + reset_time as u64;
|
||||
relay_total_runtime(relay.id, start_time, end_time).unwrap_or(3600 * 24)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use crate::devices::device::DeviceRelayID;
|
||||
use crate::energy::relay_state_history::{RelayStateHistory, relay_total_runtime};
|
||||
use crate::energy::relay_state_history::{relay_total_runtime, RelayStateHistory};
|
||||
|
||||
#[test]
|
||||
fn test_relay_state_history() {
|
||||
|
@@ -35,7 +35,7 @@ pub fn save_log(
|
||||
.as_bytes(),
|
||||
)?;
|
||||
file.flush()?;
|
||||
fs4::fs_std::FileExt::unlock(&file)?;
|
||||
file.unlock()?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
@@ -5,7 +5,7 @@ use central_backend::energy::energy_actor::EnergyActor;
|
||||
use central_backend::server::servers;
|
||||
use central_backend::utils::files_utils::create_directory_if_missing;
|
||||
use futures::future;
|
||||
use tokio_schedule::{Job, every};
|
||||
use tokio_schedule::{every, Job};
|
||||
|
||||
#[actix_web::main]
|
||||
async fn main() -> std::io::Result<()> {
|
||||
|
@@ -1,5 +1,5 @@
|
||||
use actix_identity::Identity;
|
||||
use std::future::{Ready, ready};
|
||||
use std::future::{ready, Ready};
|
||||
use std::rc::Rc;
|
||||
|
||||
use crate::app_config::AppConfig;
|
||||
@@ -7,8 +7,8 @@ use crate::constants;
|
||||
use actix_web::body::EitherBody;
|
||||
use actix_web::dev::Payload;
|
||||
use actix_web::{
|
||||
dev::{forward_ready, Service, ServiceRequest, ServiceResponse, Transform},
|
||||
Error, FromRequest, HttpResponse,
|
||||
dev::{Service, ServiceRequest, ServiceResponse, Transform, forward_ready},
|
||||
};
|
||||
use futures_util::future::LocalBoxFuture;
|
||||
|
||||
|
@@ -1,8 +1,9 @@
|
||||
use actix_web::HttpResponse;
|
||||
use actix_web::body::BoxBody;
|
||||
use actix_web::http::StatusCode;
|
||||
use actix_web::HttpResponse;
|
||||
use std::error::Error;
|
||||
use std::fmt::{Display, Formatter};
|
||||
use std::io::ErrorKind;
|
||||
use zip::result::ZipError;
|
||||
|
||||
/// Custom error to ease controller writing
|
||||
@@ -31,7 +32,7 @@ impl actix_web::error::ResponseError for HttpErr {
|
||||
}
|
||||
}
|
||||
fn error_response(&self) -> HttpResponse<BoxBody> {
|
||||
log::error!("Error while processing request! {self}");
|
||||
log::error!("Error while processing request! {}", self);
|
||||
|
||||
HttpResponse::InternalServerError().body("Failed to execute request!")
|
||||
}
|
||||
@@ -51,7 +52,7 @@ impl From<serde_json::Error> for HttpErr {
|
||||
|
||||
impl From<Box<dyn Error>> for HttpErr {
|
||||
fn from(value: Box<dyn Error>) -> Self {
|
||||
HttpErr::Err(std::io::Error::other(value.to_string()).into())
|
||||
HttpErr::Err(std::io::Error::new(ErrorKind::Other, value.to_string()).into())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -81,43 +82,43 @@ impl From<reqwest::header::ToStrError> for HttpErr {
|
||||
|
||||
impl From<actix_web::Error> for HttpErr {
|
||||
fn from(value: actix_web::Error) -> Self {
|
||||
HttpErr::Err(std::io::Error::other(value.to_string()).into())
|
||||
HttpErr::Err(std::io::Error::new(ErrorKind::Other, value.to_string()).into())
|
||||
}
|
||||
}
|
||||
|
||||
impl From<actix::MailboxError> for HttpErr {
|
||||
fn from(value: actix::MailboxError) -> Self {
|
||||
HttpErr::Err(std::io::Error::other(value.to_string()).into())
|
||||
HttpErr::Err(std::io::Error::new(ErrorKind::Other, value.to_string()).into())
|
||||
}
|
||||
}
|
||||
|
||||
impl From<actix_identity::error::GetIdentityError> for HttpErr {
|
||||
fn from(value: actix_identity::error::GetIdentityError) -> Self {
|
||||
HttpErr::Err(std::io::Error::other(value.to_string()).into())
|
||||
HttpErr::Err(std::io::Error::new(ErrorKind::Other, value.to_string()).into())
|
||||
}
|
||||
}
|
||||
|
||||
impl From<actix_identity::error::LoginError> for HttpErr {
|
||||
fn from(value: actix_identity::error::LoginError) -> Self {
|
||||
HttpErr::Err(std::io::Error::other(value.to_string()).into())
|
||||
HttpErr::Err(std::io::Error::new(ErrorKind::Other, value.to_string()).into())
|
||||
}
|
||||
}
|
||||
|
||||
impl From<openssl::error::ErrorStack> for HttpErr {
|
||||
fn from(value: openssl::error::ErrorStack) -> Self {
|
||||
HttpErr::Err(std::io::Error::other(value.to_string()).into())
|
||||
HttpErr::Err(std::io::Error::new(ErrorKind::Other, value.to_string()).into())
|
||||
}
|
||||
}
|
||||
|
||||
impl From<ZipError> for HttpErr {
|
||||
fn from(value: ZipError) -> Self {
|
||||
HttpErr::Err(std::io::Error::other(value.to_string()).into())
|
||||
HttpErr::Err(std::io::Error::new(ErrorKind::Other, value.to_string()).into())
|
||||
}
|
||||
}
|
||||
|
||||
impl From<walkdir::Error> for HttpErr {
|
||||
fn from(value: walkdir::Error) -> Self {
|
||||
HttpErr::Err(std::io::Error::other(value.to_string()).into())
|
||||
HttpErr::Err(std::io::Error::new(ErrorKind::Other, value.to_string()).into())
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -1,9 +1,9 @@
|
||||
use crate::logs::logs_manager;
|
||||
use crate::logs::severity::LogSeverity;
|
||||
use crate::server::WebEnergyActor;
|
||||
use crate::server::custom_error::HttpResult;
|
||||
use crate::server::devices_api::jwt_parser::JWTRequest;
|
||||
use actix_web::{HttpResponse, web};
|
||||
use crate::server::WebEnergyActor;
|
||||
use actix_web::{web, HttpResponse};
|
||||
|
||||
#[derive(Debug, serde::Deserialize)]
|
||||
pub struct LogRequest {
|
||||
|
@@ -1,7 +1,7 @@
|
||||
use crate::ota::ota_manager;
|
||||
use crate::ota::ota_update::OTAPlatform;
|
||||
use crate::server::custom_error::HttpResult;
|
||||
use actix_web::{HttpResponse, web};
|
||||
use actix_web::{web, HttpResponse};
|
||||
|
||||
#[derive(serde::Deserialize)]
|
||||
pub struct FirmwarePath {
|
||||
|
@@ -4,10 +4,10 @@ use crate::energy::energy_actor;
|
||||
use crate::energy::energy_actor::RelaySyncStatus;
|
||||
use crate::ota::ota_manager;
|
||||
use crate::ota::ota_update::OTAPlatform;
|
||||
use crate::server::WebEnergyActor;
|
||||
use crate::server::custom_error::HttpResult;
|
||||
use crate::server::devices_api::jwt_parser::JWTRequest;
|
||||
use actix_web::{HttpResponse, web};
|
||||
use crate::server::WebEnergyActor;
|
||||
use actix_web::{web, HttpResponse};
|
||||
use openssl::nid::Nid;
|
||||
use openssl::x509::X509Req;
|
||||
use std::str::FromStr;
|
||||
@@ -155,11 +155,12 @@ pub async fn sync_device(body: web::Json<JWTRequest>, actor: WebEnergyActor) ->
|
||||
let mut available_update = None;
|
||||
|
||||
// Check if the version is available
|
||||
if let Some(desired) = device.desired_version
|
||||
&& claims.info.version < desired
|
||||
&& ota_manager::update_exists(OTAPlatform::from_str(&claims.info.reference)?, &desired)?
|
||||
{
|
||||
available_update = Some(desired);
|
||||
if let Some(desired) = device.desired_version {
|
||||
if claims.info.version < desired
|
||||
&& ota_manager::update_exists(OTAPlatform::from_str(&claims.info.reference)?, &desired)?
|
||||
{
|
||||
available_update = Some(desired);
|
||||
}
|
||||
}
|
||||
|
||||
Ok(HttpResponse::Ok().json(SyncResult {
|
||||
|
@@ -10,14 +10,14 @@ use crate::server::unsecure_server::*;
|
||||
use crate::server::web_api::*;
|
||||
use crate::server::web_app_controller;
|
||||
use actix_cors::Cors;
|
||||
use actix_identity::IdentityMiddleware;
|
||||
use actix_identity::config::LogoutBehaviour;
|
||||
use actix_identity::IdentityMiddleware;
|
||||
use actix_remote_ip::RemoteIPConfig;
|
||||
use actix_session::SessionMiddleware;
|
||||
use actix_session::storage::CookieSessionStore;
|
||||
use actix_session::SessionMiddleware;
|
||||
use actix_web::cookie::{Key, SameSite};
|
||||
use actix_web::middleware::Logger;
|
||||
use actix_web::{App, HttpServer, web};
|
||||
use actix_web::{web, App, HttpServer};
|
||||
use openssl::ssl::{SslAcceptor, SslMethod};
|
||||
use std::time::Duration;
|
||||
|
||||
|
@@ -1,6 +1,6 @@
|
||||
use crate::app_config::AppConfig;
|
||||
use crate::server::custom_error::HttpResult;
|
||||
use actix_web::{HttpResponse, web};
|
||||
use actix_web::{web, HttpResponse};
|
||||
|
||||
#[derive(serde::Deserialize)]
|
||||
pub struct ServeCRLPath {
|
||||
|
@@ -1,8 +1,8 @@
|
||||
use crate::devices::device::DeviceRelayID;
|
||||
use crate::energy::{energy_actor, relay_state_history};
|
||||
use crate::server::WebEnergyActor;
|
||||
use crate::server::custom_error::HttpResult;
|
||||
use actix_web::{HttpResponse, web};
|
||||
use crate::server::WebEnergyActor;
|
||||
use actix_web::{web, HttpResponse};
|
||||
|
||||
#[derive(serde::Deserialize)]
|
||||
pub struct LegacyStateRelay {
|
||||
|
@@ -2,7 +2,7 @@ use crate::app_config::AppConfig;
|
||||
use crate::server::custom_error::HttpResult;
|
||||
use actix_identity::Identity;
|
||||
use actix_remote_ip::RemoteIP;
|
||||
use actix_web::{HttpMessage, HttpRequest, HttpResponse, web};
|
||||
use actix_web::{web, HttpMessage, HttpRequest, HttpResponse};
|
||||
|
||||
#[derive(serde::Deserialize)]
|
||||
pub struct AuthRequest {
|
||||
@@ -17,11 +17,11 @@ pub async fn password_auth(
|
||||
remote_ip: RemoteIP,
|
||||
) -> HttpResult {
|
||||
if r.user != AppConfig::get().admin_username || r.password != AppConfig::get().admin_password {
|
||||
log::error!("Failed login attempt from {}!", remote_ip.0);
|
||||
log::error!("Failed login attempt from {}!", remote_ip.0.to_string());
|
||||
return Ok(HttpResponse::Unauthorized().json("Invalid credentials!"));
|
||||
}
|
||||
|
||||
log::info!("Successful login attempt from {}!", remote_ip.0);
|
||||
log::info!("Successful login attempt from {}!", remote_ip.0.to_string());
|
||||
Identity::login(&request.extensions(), r.user.to_string())?;
|
||||
Ok(HttpResponse::Ok().finish())
|
||||
}
|
||||
|
@@ -1,8 +1,8 @@
|
||||
use crate::devices::device::{DeviceGeneralInfo, DeviceId};
|
||||
use crate::energy::energy_actor;
|
||||
use crate::server::WebEnergyActor;
|
||||
use crate::server::custom_error::HttpResult;
|
||||
use actix_web::{HttpResponse, web};
|
||||
use crate::server::WebEnergyActor;
|
||||
use actix_web::{web, HttpResponse};
|
||||
|
||||
/// Get the list of pending (not accepted yet) devices
|
||||
pub async fn list_pending(actor: WebEnergyActor) -> HttpResult {
|
||||
|
@@ -2,8 +2,8 @@ use crate::app_config::ConsumptionHistoryType;
|
||||
use crate::energy::consumption::EnergyConsumption;
|
||||
use crate::energy::consumption_history_file::ConsumptionHistoryFile;
|
||||
use crate::energy::{consumption, energy_actor};
|
||||
use crate::server::WebEnergyActor;
|
||||
use crate::server::custom_error::HttpResult;
|
||||
use crate::server::WebEnergyActor;
|
||||
use crate::utils::time_utils::time_secs;
|
||||
use actix_web::HttpResponse;
|
||||
|
||||
|
@@ -3,7 +3,7 @@ use crate::logs::logs_manager;
|
||||
use crate::logs::severity::LogSeverity;
|
||||
use crate::server::custom_error::HttpResult;
|
||||
use crate::utils::time_utils::curr_day_number;
|
||||
use actix_web::{HttpResponse, web};
|
||||
use actix_web::{web, HttpResponse};
|
||||
|
||||
#[derive(serde::Deserialize)]
|
||||
pub struct LogRequest {
|
||||
|
@@ -3,11 +3,11 @@ use crate::devices::device::DeviceId;
|
||||
use crate::energy::energy_actor;
|
||||
use crate::ota::ota_manager;
|
||||
use crate::ota::ota_update::OTAPlatform;
|
||||
use crate::server::WebEnergyActor;
|
||||
use crate::server::custom_error::HttpResult;
|
||||
use actix_multipart::form::MultipartForm;
|
||||
use crate::server::WebEnergyActor;
|
||||
use actix_multipart::form::tempfile::TempFile;
|
||||
use actix_web::{HttpResponse, web};
|
||||
use actix_multipart::form::MultipartForm;
|
||||
use actix_web::{web, HttpResponse};
|
||||
|
||||
pub async fn supported_platforms() -> HttpResult {
|
||||
Ok(HttpResponse::Ok().json(OTAPlatform::supported_platforms()))
|
||||
@@ -123,17 +123,17 @@ pub async fn set_desired_version(
|
||||
|
||||
for d in devices {
|
||||
// Filter per platform
|
||||
if let Some(p) = body.platform
|
||||
&& d.info.reference != p.to_string()
|
||||
{
|
||||
continue;
|
||||
if let Some(p) = body.platform {
|
||||
if d.info.reference != p.to_string() {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
// Filter per device
|
||||
if let Some(ids) = &body.devices
|
||||
&& !ids.contains(&d.id)
|
||||
{
|
||||
continue;
|
||||
if let Some(ids) = &body.devices {
|
||||
if !ids.contains(&d.id) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
actor
|
||||
|
@@ -1,8 +1,8 @@
|
||||
use crate::devices::device::{DeviceId, DeviceRelay, DeviceRelayID};
|
||||
use crate::energy::energy_actor;
|
||||
use crate::server::WebEnergyActor;
|
||||
use crate::server::custom_error::HttpResult;
|
||||
use actix_web::{HttpResponse, web};
|
||||
use crate::server::WebEnergyActor;
|
||||
use actix_web::{web, HttpResponse};
|
||||
|
||||
/// Get the full list of relays
|
||||
pub async fn get_list(actor: WebEnergyActor) -> HttpResult {
|
||||
|
@@ -19,7 +19,7 @@ mod serve_static_debug {
|
||||
|
||||
#[cfg(not(debug_assertions))]
|
||||
mod serve_static_release {
|
||||
use actix_web::{HttpResponse, Responder, web};
|
||||
use actix_web::{web, HttpResponse, Responder};
|
||||
use rust_embed::RustEmbed;
|
||||
|
||||
#[derive(RustEmbed)]
|
||||
|
@@ -1,7 +1,7 @@
|
||||
use chrono::prelude::*;
|
||||
use std::time::{SystemTime, UNIX_EPOCH};
|
||||
|
||||
/// Get the current time since epoch, in seconds
|
||||
/// Get the current time since epoch
|
||||
pub fn time_secs() -> u64 {
|
||||
SystemTime::now()
|
||||
.duration_since(UNIX_EPOCH)
|
||||
|
@@ -1,28 +0,0 @@
|
||||
import js from '@eslint/js'
|
||||
import globals from 'globals'
|
||||
import reactHooks from 'eslint-plugin-react-hooks'
|
||||
import reactRefresh from 'eslint-plugin-react-refresh'
|
||||
import tseslint from 'typescript-eslint'
|
||||
|
||||
export default tseslint.config(
|
||||
{ ignores: ['dist'] },
|
||||
{
|
||||
extends: [js.configs.recommended, ...tseslint.configs.recommended],
|
||||
files: ['**/*.{ts,tsx}'],
|
||||
languageOptions: {
|
||||
ecmaVersion: 2020,
|
||||
globals: globals.browser,
|
||||
},
|
||||
plugins: {
|
||||
'react-hooks': reactHooks,
|
||||
'react-refresh': reactRefresh,
|
||||
},
|
||||
rules: {
|
||||
...reactHooks.configs.recommended.rules,
|
||||
'react-refresh/only-export-components': [
|
||||
'warn',
|
||||
{ allowConstantExport: true },
|
||||
],
|
||||
},
|
||||
},
|
||||
)
|
2425
central_frontend/package-lock.json
generated
2425
central_frontend/package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -6,40 +6,38 @@
|
||||
"scripts": {
|
||||
"dev": "vite",
|
||||
"build": "tsc -b && vite build",
|
||||
"lint": "eslint .",
|
||||
"lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
|
||||
"preview": "vite preview"
|
||||
},
|
||||
"dependencies": {
|
||||
"@emotion/react": "^11.14.0",
|
||||
"@emotion/styled": "^11.14.1",
|
||||
"@fontsource/roboto": "^5.2.8",
|
||||
"@emotion/react": "^11.13.3",
|
||||
"@emotion/styled": "^11.13.0",
|
||||
"@fontsource/roboto": "^5.1.0",
|
||||
"@mdi/js": "^7.4.47",
|
||||
"@mdi/react": "^1.6.1",
|
||||
"@mui/icons-material": "^7.0.2",
|
||||
"@mui/material": "^7.0.2",
|
||||
"@mui/x-charts": "^7.29.1",
|
||||
"@mui/x-date-pickers": "^7.29.4",
|
||||
"@mui/icons-material": "^6.1.4",
|
||||
"@mui/material": "^6.1.4",
|
||||
"@mui/x-charts": "^7.21.0",
|
||||
"@mui/x-date-pickers": "^7.21.0",
|
||||
"@types/semver": "^7.5.8",
|
||||
"date-and-time": "^3.6.0",
|
||||
"dayjs": "^1.11.18",
|
||||
"dayjs": "^1.11.13",
|
||||
"filesize": "^10.1.6",
|
||||
"react": "^19.1.1",
|
||||
"react-dom": "^19.1.1",
|
||||
"react-router-dom": "^7.7.1",
|
||||
"semver": "^7.7.2"
|
||||
"react": "^18.3.1",
|
||||
"react-dom": "^18.3.1",
|
||||
"react-router-dom": "^7.0.0",
|
||||
"semver": "^7.6.3"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/react": "^19.1.13",
|
||||
"@types/react-dom": "^19.1.9",
|
||||
"@types/semver": "^7.7.1",
|
||||
"@typescript-eslint/eslint-plugin": "^8.44.0",
|
||||
"@typescript-eslint/parser": "^8.41.0",
|
||||
"@vitejs/plugin-react": "^4.7.0",
|
||||
"eslint": "^9.33.0",
|
||||
"eslint-plugin-react-hooks": "^5.2.0",
|
||||
"eslint-plugin-react-refresh": "^0.4.20",
|
||||
"globals": "^16.3.0",
|
||||
"typescript": "^5.8.3",
|
||||
"typescript-eslint": "^8.24.1",
|
||||
"vite": "^6.3.6"
|
||||
"@types/react": "^18.3.11",
|
||||
"@types/react-dom": "^18.3.1",
|
||||
"@typescript-eslint/eslint-plugin": "^8.15.0",
|
||||
"@typescript-eslint/parser": "^8.10.0",
|
||||
"@vitejs/plugin-react": "^4.3.2",
|
||||
"eslint": "^9.0.0",
|
||||
"eslint-plugin-react-hooks": "^5.0.0",
|
||||
"eslint-plugin-react-refresh": "^0.4.12",
|
||||
"typescript": "^5.6.3",
|
||||
"vite": "^5.4.9"
|
||||
}
|
||||
}
|
||||
|
@@ -84,7 +84,7 @@ export function DeployOTAUpdateDialogProvider(p: {
|
||||
</DialogContentText>
|
||||
|
||||
<FormControl>
|
||||
<FormLabel>Deployment target</FormLabel>
|
||||
<FormLabel>Gender</FormLabel>
|
||||
<RadioGroup
|
||||
name="radio-buttons-group"
|
||||
value={allDevices}
|
||||
|
@@ -6,7 +6,7 @@ import {
|
||||
DialogTitle,
|
||||
Typography,
|
||||
} from "@mui/material";
|
||||
import Grid from "@mui/material/Grid";
|
||||
import Grid from "@mui/material/Grid2";
|
||||
import { TimePicker } from "@mui/x-date-pickers";
|
||||
import React from "react";
|
||||
import { Device, DeviceRelay } from "../api/DeviceApi";
|
||||
|
@@ -1,7 +1,7 @@
|
||||
import DeleteIcon from "@mui/icons-material/Delete";
|
||||
import RefreshIcon from "@mui/icons-material/Refresh";
|
||||
import { IconButton, Tooltip } from "@mui/material";
|
||||
import Grid from "@mui/material/Grid";
|
||||
import Grid from "@mui/material/Grid2";
|
||||
import React from "react";
|
||||
import { useNavigate, useParams } from "react-router-dom";
|
||||
import { Device, DeviceApi } from "../../api/DeviceApi";
|
||||
|
@@ -1,6 +1,6 @@
|
||||
import { Typography } from "@mui/material";
|
||||
import { CurrConsumptionWidget } from "./HomeRoute/CurrConsumptionWidget";
|
||||
import Grid from "@mui/material/Grid";
|
||||
import Grid from "@mui/material/Grid2";
|
||||
import { CachedConsumptionWidget } from "./HomeRoute/CachedConsumptionWidget";
|
||||
import { RelayConsumptionWidget } from "./HomeRoute/RelayConsumptionWidget";
|
||||
import { RelaysListRoute } from "./RelaysListRoute";
|
||||
|
@@ -11,7 +11,7 @@ import Typography from "@mui/material/Typography";
|
||||
import * as React from "react";
|
||||
import { useLoadingMessage } from "../hooks/context_providers/LoadingMessageProvider";
|
||||
import { AuthApi } from "../api/AuthApi";
|
||||
import Grid from "@mui/material/Grid";
|
||||
import Grid from "@mui/material/Grid2";
|
||||
|
||||
function Copyright(props: any) {
|
||||
return (
|
||||
|
@@ -1,5 +1,6 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"composite": true,
|
||||
"tsBuildInfoFile": "./node_modules/.tmp/tsconfig.app.tsbuildinfo",
|
||||
"target": "ES2020",
|
||||
"useDefineForClassFields": true,
|
||||
@@ -10,6 +11,7 @@
|
||||
/* Bundler mode */
|
||||
"moduleResolution": "bundler",
|
||||
"allowImportingTsExtensions": true,
|
||||
"resolveJsonModule": true,
|
||||
"isolatedModules": true,
|
||||
"moduleDetection": "force",
|
||||
"noEmit": true,
|
||||
@@ -19,8 +21,7 @@
|
||||
"strict": true,
|
||||
"noUnusedLocals": true,
|
||||
"noUnusedParameters": true,
|
||||
"noFallthroughCasesInSwitch": true,
|
||||
"noUncheckedSideEffectImports": true
|
||||
"noFallthroughCasesInSwitch": true
|
||||
},
|
||||
"include": ["src"]
|
||||
}
|
||||
|
@@ -1,7 +1,11 @@
|
||||
{
|
||||
"files": [],
|
||||
"references": [
|
||||
{ "path": "./tsconfig.app.json" },
|
||||
{ "path": "./tsconfig.node.json" }
|
||||
{
|
||||
"path": "./tsconfig.app.json"
|
||||
},
|
||||
{
|
||||
"path": "./tsconfig.node.json"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
@@ -1,24 +1,13 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"composite": true,
|
||||
"tsBuildInfoFile": "./node_modules/.tmp/tsconfig.node.tsbuildinfo",
|
||||
"target": "ES2022",
|
||||
"lib": ["ES2023"],
|
||||
"module": "ESNext",
|
||||
"skipLibCheck": true,
|
||||
|
||||
/* Bundler mode */
|
||||
"module": "ESNext",
|
||||
"moduleResolution": "bundler",
|
||||
"allowImportingTsExtensions": true,
|
||||
"isolatedModules": true,
|
||||
"moduleDetection": "force",
|
||||
"noEmit": true,
|
||||
|
||||
/* Linting */
|
||||
"allowSyntheticDefaultImports": true,
|
||||
"strict": true,
|
||||
"noUnusedLocals": true,
|
||||
"noUnusedParameters": true,
|
||||
"noFallthroughCasesInSwitch": true,
|
||||
"noUncheckedSideEffectImports": true
|
||||
"noEmit": true
|
||||
},
|
||||
"include": ["vite.config.ts"]
|
||||
}
|
||||
|
@@ -1,7 +1,7 @@
|
||||
import { defineConfig } from 'vite'
|
||||
import react from '@vitejs/plugin-react'
|
||||
|
||||
// https://vite.dev/config/
|
||||
// https://vitejs.dev/config/
|
||||
export default defineConfig({
|
||||
plugins: [react()],
|
||||
})
|
||||
|
1853
custom_consumption/Cargo.lock
generated
1853
custom_consumption/Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
@@ -1,12 +1,12 @@
|
||||
[package]
|
||||
name = "custom_consumption"
|
||||
version = "0.1.0"
|
||||
edition = "2024"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
env_logger = "0.11.8"
|
||||
log = "0.4.28"
|
||||
clap = { version = "4.5.47", features = ["derive", "env"] }
|
||||
egui = "0.32.3"
|
||||
eframe = "0.32.3"
|
||||
env_logger = "0.11.5"
|
||||
log = "0.4.22"
|
||||
clap = { version = "4.5.18", features = ["derive", "env"] }
|
||||
egui = "0.29.1"
|
||||
eframe = "0.29.1"
|
||||
lazy_static = "1.5.0"
|
||||
|
@@ -2,11 +2,6 @@
|
||||
|
||||
ESP32 client device, using `W32-ETH01` device
|
||||
|
||||
## Pins for relays
|
||||
The pins are the following (in the order of definition): 4, 14, 15, 2
|
||||
|
||||
**WARNING!** The Pin 2 MUST be disconnect to reflash the card!
|
||||
|
||||
## Some commands
|
||||
|
||||
Create a new firmware build:
|
||||
|
@@ -9,7 +9,7 @@ static const char *TAG = "relays";
|
||||
/**
|
||||
* Device relays GPIO ids
|
||||
*/
|
||||
static int DEVICE_GPIO_IDS[4] = {4, 14, 15, 2};
|
||||
static int DEVICE_GPIO_IDS[3] = {4, 14, 15};
|
||||
|
||||
int relays_count()
|
||||
{
|
||||
|
@@ -1 +1 @@
|
||||
1.0.2
|
||||
1.0.2-b1
|
@@ -1,3 +1,9 @@
|
||||
{
|
||||
"extends": ["local>renovate/presets"]
|
||||
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
|
||||
"packageRules": [
|
||||
{
|
||||
"matchUpdateTypes": ["major", "minor", "patch"],
|
||||
"automerge": true
|
||||
}
|
||||
]
|
||||
}
|
Reference in New Issue
Block a user