mirror of
https://github.com/LibreQoE/LibreQoS.git
synced 2025-02-25 18:55:32 -06:00
Support more license valid data, and the test license
This commit is contained in:
parent
2cb68ce06b
commit
ac97eb450e
@ -68,7 +68,10 @@ async fn check_license(
|
||||
log::info!("Checking license from {address:?}, key: {}", request.key);
|
||||
if request.key == "test" {
|
||||
log::info!("License is valid");
|
||||
Ok(LicenseReply::Valid)
|
||||
Ok(LicenseReply::Valid {
|
||||
expiry: 0, // Temporary value
|
||||
stats_host: "127.0.0.1:9127".to_string(), // Also temporary
|
||||
})
|
||||
} else {
|
||||
log::info!("License is denied");
|
||||
Ok(LicenseReply::Denied)
|
||||
|
@ -83,7 +83,12 @@ pub enum LicenseReply {
|
||||
/// The license is denied
|
||||
Denied,
|
||||
/// The license is valid
|
||||
Valid,
|
||||
Valid {
|
||||
/// When does the license expire?
|
||||
expiry: u64,
|
||||
/// Address to which statistics should be submitted
|
||||
stats_host: String,
|
||||
},
|
||||
}
|
||||
|
||||
/// Errors that can occur when checking licenses
|
||||
|
@ -11,12 +11,17 @@ struct LicenseStatus {
|
||||
last_check: u64,
|
||||
}
|
||||
|
||||
#[derive(Default, Clone, Copy, PartialEq, Debug)]
|
||||
#[derive(Default, Clone, PartialEq, Debug)]
|
||||
pub(crate) enum LicenseState {
|
||||
#[default]
|
||||
Unknown,
|
||||
Denied,
|
||||
Valid,
|
||||
Valid {
|
||||
/// When does the license expire?
|
||||
expiry: u64,
|
||||
/// Host to which to send stats
|
||||
stats_host: String,
|
||||
},
|
||||
}
|
||||
|
||||
static LICENSE_STATUS: Lazy<RwLock<LicenseStatus>> =
|
||||
@ -35,10 +40,17 @@ pub(crate) async fn get_license_status() -> LicenseState {
|
||||
LicenseState::Unknown
|
||||
}
|
||||
|
||||
const MISERLY_NO_KEY: &str = "IDontSupportDevelopersAndShouldFeelBad";
|
||||
|
||||
async fn check_license(unix_time: u64) -> LicenseState {
|
||||
if let Ok(cfg) = EtcLqos::load() {
|
||||
if let Some(cfg) = cfg.long_term_stats {
|
||||
if let Some(key) = cfg.license_key {
|
||||
if key == MISERLY_NO_KEY {
|
||||
log::warn!("You are using the self-hosting license key. We'd be happy to sell you a real one.");
|
||||
return LicenseState::Valid { expiry: 0, stats_host: "127.0.0.1:9127".to_string() }
|
||||
}
|
||||
|
||||
let mut lock = LICENSE_STATUS.write().await;
|
||||
lock.last_check = unix_time;
|
||||
lock.key = key.clone();
|
||||
@ -49,12 +61,14 @@ async fn check_license(unix_time: u64) -> LicenseState {
|
||||
log::warn!("License is in state: DENIED.");
|
||||
lock.state = LicenseState::Denied;
|
||||
}
|
||||
LicenseReply::Valid => {
|
||||
LicenseReply::Valid{expiry, stats_host} => {
|
||||
log::info!("License is in state: VALID.");
|
||||
lock.state = LicenseState::Valid;
|
||||
lock.state = LicenseState::Valid{
|
||||
expiry, stats_host
|
||||
};
|
||||
}
|
||||
}
|
||||
return lock.state;
|
||||
return lock.state.clone();
|
||||
}
|
||||
Err(e) => {
|
||||
log::error!("Error checking licensing server");
|
||||
|
@ -16,8 +16,9 @@ pub(crate) async fn new_submission(data: StatsSubmission) {
|
||||
LicenseState::Denied => {
|
||||
log::error!("Your license is invalid. Please contact support.");
|
||||
}
|
||||
LicenseState::Valid => {
|
||||
LicenseState::Valid{ expiry, stats_host } => {
|
||||
// TODO: Send to server
|
||||
println!("Send stats to {stats_host} before {expiry}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user