security: remove chaves Supabase hardcoded; use self.diferenca do frontend no recibo
This commit is contained in:
+11
-15
@@ -19,7 +19,7 @@ fn data_dir_path() -> PathBuf {
|
|||||||
.join("FechamentoCaixa")
|
.join("FechamentoCaixa")
|
||||||
}
|
}
|
||||||
|
|
||||||
fn load_config() -> (String, String) {
|
fn load_config() -> Result<(String, String), String> {
|
||||||
let cfg_path = data_dir_path().join("config.json");
|
let cfg_path = data_dir_path().join("config.json");
|
||||||
if let Ok(content) = fs::read_to_string(&cfg_path) {
|
if let Ok(content) = fs::read_to_string(&cfg_path) {
|
||||||
if let Ok(cfg) = serde_json::from_str::<serde_json::Value>(&content) {
|
if let Ok(cfg) = serde_json::from_str::<serde_json::Value>(&content) {
|
||||||
@@ -32,15 +32,17 @@ fn load_config() -> (String, String) {
|
|||||||
.unwrap_or("")
|
.unwrap_or("")
|
||||||
.to_string();
|
.to_string();
|
||||||
if !anon.is_empty() && !service.is_empty() {
|
if !anon.is_empty() && !service.is_empty() {
|
||||||
return (anon, service);
|
return Ok((anon, service));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Fallback 3: chaves embedadas no binário (funciona em qualquer PC sem config)
|
Err(format!(
|
||||||
(
|
"SUPABASE_ANON_KEY e SUPABASE_SERVICE_KEY nao encontradas em config.json.\n\
|
||||||
"sb_publishable_NCUGwstslOvVt5JtGxKB9A_p-BERG57".to_string(),
|
Crie o arquivo {:?} com o seguinte formato:\n\
|
||||||
"sb_secret_T6eHIKJDGaH53HMTG6UUKa_6ou6KfEW".to_string(),
|
{{\"SUPABASE_ANON_KEY\": \"sua_chave_anon\", \"SUPABASE_SERVICE_KEY\": \"sua_chave_service\"}}\n\
|
||||||
)
|
Gere as chaves em: https://supabase.ofrangao.com.br/project/default/settings/api",
|
||||||
|
cfg_path
|
||||||
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
@@ -55,17 +57,11 @@ fn main() {
|
|||||||
fs::create_dir_all(&data_dir).expect("não foi possível criar diretório de dados");
|
fs::create_dir_all(&data_dir).expect("não foi possível criar diretório de dados");
|
||||||
log::info!("Data dir: {:?}", data_dir);
|
log::info!("Data dir: {:?}", data_dir);
|
||||||
|
|
||||||
// Carrega chaves do Supabase
|
// Carrega chaves do Supabase — obrigatório vir do config.json
|
||||||
let (anon_key, service_key) = load_config();
|
let (anon_key, service_key) = load_config().expect("falha ao carregar configuracao do Supabase");
|
||||||
if anon_key.is_empty() || service_key.is_empty() {
|
|
||||||
log::warn!("SUPABASE_ANON_KEY ou SUPABASE_SERVICE_KEY não encontradas!");
|
|
||||||
log::warn!("Cole-as em: {:?}", data_dir.join("config.json"));
|
|
||||||
log::warn!("Formato: {{\"SUPABASE_ANON_KEY\": \"...\", \"SUPABASE_SERVICE_KEY\": \"...\"}}");
|
|
||||||
} else {
|
|
||||||
log::info!("Supabase: keys carregadas (anon={}..., service={}...)",
|
log::info!("Supabase: keys carregadas (anon={}..., service={}...)",
|
||||||
&anon_key[..8.min(anon_key.len())],
|
&anon_key[..8.min(anon_key.len())],
|
||||||
&service_key[..8.min(service_key.len())]);
|
&service_key[..8.min(service_key.len())]);
|
||||||
}
|
|
||||||
|
|
||||||
// Inicializa plugins
|
// Inicializa plugins
|
||||||
let storage = storage::init(data_dir.clone())
|
let storage = storage::init(data_dir.clone())
|
||||||
|
|||||||
@@ -322,9 +322,10 @@ impl ReciboData {
|
|||||||
out.extend(escpos::divider());
|
out.extend(escpos::divider());
|
||||||
|
|
||||||
// ── DIFERENÇA ──
|
// ── DIFERENÇA ──
|
||||||
// Diferença = TOTAL SISTEMA - saldo_esperado - cancelamentos
|
// Usa o valor calculado pelo frontend (self.diferenca).
|
||||||
|
// O frontend já subtrai saldo_esperado e cancelamentos de sys_total.
|
||||||
out.extend(escpos::line_bold("DIFERENCA"));
|
out.extend(escpos::line_bold("DIFERENCA"));
|
||||||
let diff = self.sys_total - self.saldo_esperado - self.cancelamentos;
|
let diff = self.diferenca;
|
||||||
let diff_str = if diff >= 0.0 {
|
let diff_str = if diff >= 0.0 {
|
||||||
format!("+{}", self.fmt_money(diff))
|
format!("+{}", self.fmt_money(diff))
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in New Issue
Block a user