fedimint_server_ui/dashboard/
mod.rs1pub mod audit;
2pub mod bitcoin;
3pub(crate) mod consensus_explorer;
4pub mod general;
5pub mod invite;
6pub mod latency;
7pub mod modules;
8
9use axum::Router;
10use axum::body::Body;
11use axum::extract::{Form, State};
12use axum::http::header;
13use axum::response::{Html, IntoResponse, Response};
14use axum::routing::{get, post};
15use axum_extra::extract::cookie::CookieJar;
16use consensus_explorer::consensus_explorer_view;
17use fedimint_server_core::dashboard_ui::{DashboardApiModuleExt, DynDashboardApi};
18use maud::{DOCTYPE, Markup, html};
19use {fedimint_lnv2_server, fedimint_meta_server, fedimint_wallet_server};
20
21use crate::assets::WithStaticRoutesExt as _;
22use crate::auth::UserAuth;
23use crate::dashboard::modules::{lnv2, meta, wallet};
24use crate::{
25 DOWNLOAD_BACKUP_ROUTE, EXPLORER_IDX_ROUTE, EXPLORER_ROUTE, LOGIN_ROUTE, LoginInput, ROOT_ROUTE,
26 UiState, common_head, login_form_response, login_submit_response,
27};
28
29pub fn dashboard_layout(content: Markup) -> Markup {
30 html! {
31 (DOCTYPE)
32 html {
33 head {
34 (common_head("Dashboard"))
35 }
36 body {
37 div class="container" {
38 header class="text-center" {
39 h1 class="header-title" { "Fedimint Guardian UI" }
40 }
41
42 (content)
43 }
44 script src="/assets/bootstrap.bundle.min.js" integrity="sha384-C6RzsynM9kWDrMNeT87bh95OGNyZPhcTNXj1NW7RuBCsyN/o0jlpcV8Qyq46cDfL" crossorigin="anonymous" {}
45 }
46 }
47 }
48}
49
50async fn login_form(State(_state): State<UiState<DynDashboardApi>>) -> impl IntoResponse {
52 login_form_response()
53}
54
55async fn login_submit(
57 State(state): State<UiState<DynDashboardApi>>,
58 jar: CookieJar,
59 Form(input): Form<LoginInput>,
60) -> impl IntoResponse {
61 login_submit_response(
62 state.api.auth().await,
63 state.auth_cookie_name,
64 state.auth_cookie_value,
65 jar,
66 input,
67 )
68 .into_response()
69}
70
71async fn download_backup(
73 State(state): State<UiState<DynDashboardApi>>,
74 user_auth: UserAuth,
75) -> impl IntoResponse {
76 let api_auth = state.api.auth().await;
77 let backup = state
78 .api
79 .download_guardian_config_backup(&api_auth.0, &user_auth.guardian_auth_token)
80 .await;
81 let filename = "guardian-backup.tar";
82
83 Response::builder()
84 .header(header::CONTENT_TYPE, "application/x-tar")
85 .header(
86 header::CONTENT_DISPOSITION,
87 format!("attachment; filename=\"{filename}\""),
88 )
89 .body(Body::from(backup.tar_archive_bytes))
90 .expect("Failed to build response")
91}
92
93async fn dashboard_view(
95 State(state): State<UiState<DynDashboardApi>>,
96 _auth: UserAuth,
97) -> impl IntoResponse {
98 let guardian_names = state.api.guardian_names().await;
99 let federation_name = state.api.federation_name().await;
100 let session_count = state.api.session_count().await;
101 let consensus_ord_latency = state.api.consensus_ord_latency().await;
102 let p2p_connection_status = state.api.p2p_connection_status().await;
103 let invite_code = state.api.federation_invite_code().await;
104 let audit_summary = state.api.federation_audit().await;
105 let bitcoin_rpc_url = state.api.bitcoin_rpc_url().await;
106 let bitcoin_rpc_status = state.api.bitcoin_rpc_status().await;
107
108 let content = html! {
109 div class="row gy-4" {
110 div class="col-md-6" {
111 (general::render(&federation_name, session_count, &guardian_names))
112 }
113
114 div class="col-md-6" {
115 (invite::render(&invite_code))
116 }
117 }
118
119 div class="row gy-4 mt-2" {
120 div class="col-lg-6" {
121 (audit::render(&audit_summary))
122 }
123
124 div class="col-lg-6" {
125 (latency::render(consensus_ord_latency, &p2p_connection_status))
126 }
127 }
128
129 div class="row gy-4 mt-2" {
130 div class="col-12" {
131 (bitcoin::render(bitcoin_rpc_url, &bitcoin_rpc_status))
132 }
133 }
134
135 @if let Some(lightning) = state.api.get_module::<fedimint_lnv2_server::Lightning>() {
137 div class="row gy-4 mt-2" {
138 div class="col-12" {
139 (lnv2::render(lightning).await)
140 }
141 }
142 }
143
144 @if let Some(wallet_module) = state.api.get_module::<fedimint_wallet_server::Wallet>() {
146 div class="row gy-4 mt-2" {
147 div class="col-12" {
148 (wallet::render(wallet_module).await)
149 }
150 }
151 }
152
153 @if let Some(meta_module) = state.api.get_module::<fedimint_meta_server::Meta>() {
155 div class="row gy-4 mt-2" {
156 div class="col-12" {
157 (meta::render(meta_module).await)
158 }
159 }
160 }
161
162 div class="row gy-4 mt-4" {
164 div class="col-12" {
165 div class="card" {
166 div class="card-header bg-warning text-dark" {
167 h5 class="mb-0" { "Guardian Configuration Backup" }
168 }
169 div class="card-body" {
170 div class="row" {
171 div class="col-lg-6 mb-3 mb-lg-0" {
172 p {
173 "You only need to download this backup once."
174 }
175 p {
176 "Use it to restore your guardian if your server fails."
177 }
178 a href="/download-backup" class="btn btn-outline-warning btn-lg mt-2" {
179 "Download Guardian Backup"
180 }
181 }
182 div class="col-lg-6" {
183 div class="alert alert-warning mb-0" {
184 strong { "Security Warning" }
185 br;
186 "Store this file securely since anyone with it and your password can run your guardian node."
187 }
188 }
189 }
190 }
191 }
192 }
193 }
194 };
195
196 Html(dashboard_layout(content).into_string()).into_response()
197}
198
199pub fn router(api: DynDashboardApi) -> Router {
200 let mut app = Router::new()
201 .route(ROOT_ROUTE, get(dashboard_view))
202 .route(LOGIN_ROUTE, get(login_form).post(login_submit))
203 .route(EXPLORER_ROUTE, get(consensus_explorer_view))
204 .route(EXPLORER_IDX_ROUTE, get(consensus_explorer_view))
205 .route(DOWNLOAD_BACKUP_ROUTE, get(download_backup))
206 .with_static_routes();
207
208 if api
210 .get_module::<fedimint_lnv2_server::Lightning>()
211 .is_some()
212 {
213 app = app
214 .route(lnv2::LNV2_ADD_ROUTE, post(lnv2::post_add))
215 .route(lnv2::LNV2_REMOVE_ROUTE, post(lnv2::post_remove));
216 }
217
218 if api.get_module::<fedimint_meta_server::Meta>().is_some() {
220 app = app
221 .route(meta::META_SUBMIT_ROUTE, post(meta::post_submit))
222 .route(meta::META_SET_ROUTE, post(meta::post_set))
223 .route(meta::META_RESET_ROUTE, post(meta::post_reset))
224 .route(meta::META_DELETE_ROUTE, post(meta::post_delete));
225 }
226
227 app.with_state(UiState::new(api))
229}