This commit is contained in:
root
2025-07-19 16:50:53 +02:00
parent e8502779f0
commit dc6efef922
3 changed files with 26 additions and 12 deletions

View File

@@ -27,8 +27,9 @@ struct CreateTemplate<'a> {
ts3_server_port: u16, ts3_server_port: u16,
client_ip: &'a str, client_ip: &'a str,
client_uuid: &'a str, client_uuid: &'a str,
now: &'a str,
year: i32, year: i32,
flash_message: Option<&'a str>, flash_message: &'a str, // Zawsze string! pusty lub z komunikatem.
} }
#[derive(Template)] #[derive(Template)]
@@ -37,6 +38,7 @@ struct StatsTemplate<'a> {
graphs: &'a [Graph], graphs: &'a [Graph],
last_update: &'a str, last_update: &'a str,
server_name: &'a str, server_name: &'a str,
now: &'a str,
year: i32, year: i32,
} }
@@ -54,7 +56,6 @@ async fn create_handler(data: web::Json<ChannelData>) -> HttpResponse {
} }
}; };
// Pobierz client_info jak w app.py[1]
let client_info = get_client_info(&mut stream, "127.0.0.1"); let client_info = get_client_info(&mut stream, "127.0.0.1");
let (client_uuid, client_dbid, client_clid) = match &client_info { let (client_uuid, client_dbid, client_clid) = match &client_info {
Some(info) => (info.uid.as_str(), info.dbid, info.clid), Some(info) => (info.uid.as_str(), info.dbid, info.clid),
@@ -70,17 +71,21 @@ async fn create_handler(data: web::Json<ChannelData>) -> HttpResponse {
client_clid, client_clid,
); );
let flash_message = match result { let flash_message = match result {
Ok(_) => Some("Kanał utworzony pomyślnie"), Ok(_) => "Kanał utworzony pomyślnie",
Err(_e) => Some("Błąd tworzenia kanału"), Err(_e) => "Błąd tworzenia kanału",
}; };
let now = Utc::now(); let now_dt = Utc::now();
let now_str = now_dt.format("%Y-%m-%d %H:%M:%S").to_string();
let year = now_dt.year();
let template = CreateTemplate { let template = CreateTemplate {
ts3_server: &config.ts3_server, ts3_server: &config.ts3_server,
ts3_server_port: config.ts3_query_port, ts3_server_port: config.ts3_query_port,
client_ip: "127.0.0.1", client_ip: "127.0.0.1",
client_uuid, client_uuid,
year: now.year(), now: &now_str,
year,
flash_message, flash_message,
}; };
HttpResponse::Ok().content_type("text/html").body(template.render().unwrap()) HttpResponse::Ok().content_type("text/html").body(template.render().unwrap())
@@ -95,13 +100,17 @@ async fn stats_handler() -> HttpResponse {
Graph { file: "72h.gif".to_string(), title: "Ostatnie 72 godziny".to_string() }, Graph { file: "72h.gif".to_string(), title: "Ostatnie 72 godziny".to_string() },
Graph { file: "week.gif".to_string(), title: "Ostatni tydzień".to_string() }, Graph { file: "week.gif".to_string(), title: "Ostatni tydzień".to_string() },
]; ];
let now = Utc::now(); let now_dt = Utc::now();
let last_update = now.format("%Y-%m-%d %H:%M:%S").to_string(); let now_str = now_dt.format("%Y-%m-%d %H:%M:%S").to_string();
let year = now_dt.year();
let last_update = &now_str;
let template = StatsTemplate { let template = StatsTemplate {
graphs: &graphs, graphs: &graphs,
last_update: &last_update, last_update,
server_name: "linuxiarz.pl", server_name: "linuxiarz.pl",
year: now.year(), now: &now_str,
year,
}; };
HttpResponse::Ok().content_type("text/html").body(template.render().unwrap()) HttpResponse::Ok().content_type("text/html").body(template.render().unwrap())
} }

View File

@@ -20,7 +20,12 @@
</div> </div>
<button type="submit" class="btn btn-primary">Utwórz</button> <button type="submit" class="btn btn-primary">Utwórz</button>
</form> </form>
{% if flash_message %}<div class="alert alert-success mt-3">{{ flash_message }}</div>{% endif %}
{% if flash_message %}
<div class="alert alert-success">{{ flash_message }}</div>
{% endif %}
<p class="mt-3">Twój IP: {{ client_ip }} | UUID: {{ client_uuid }} | Data: {{ now }}</p> <p class="mt-3">Twój IP: {{ client_ip }} | UUID: {{ client_uuid }} | Data: {{ now }}</p>
</div> </div>
</div> </div>

View File

@@ -10,7 +10,7 @@
<h6>{{ graph.title }}</h6> <h6>{{ graph.title }}</h6>
<img src="/static/graphs/{{ graph.file }}" alt="{{ graph.title }}" class="img-fluid graph"> <img src="/static/graphs/{{ graph.file }}" alt="{{ graph.title }}" class="img-fluid graph">
{% endfor %} {% endfor %}
<p class="mt-3">Aktualny czas: {{ now }}</p> <p class="mt-3">Aktualny czas: {{ now_str }}</p>
</div> </div>
</div> </div>
{% endblock %} {% endblock %}