akra35567 commited on
Commit
1fdbae7
Β·
verified Β·
1 Parent(s): 22dcb40

Update modules/SecurityLogger.js

Browse files
Files changed (1) hide show
  1. modules/SecurityLogger.js +31 -6
modules/SecurityLogger.js CHANGED
@@ -16,18 +16,43 @@ const path = require('path');
16
  class SecurityLogger {
17
  constructor(config) {
18
  this.config = config;
19
- this.logsPath = path.join(config.DATABASE_FOLDER, 'security_logs');
 
 
 
 
 
 
 
20
  this.alertsPath = path.join(this.logsPath, 'alerts.json');
21
  this.opsPath = path.join(this.logsPath, 'operations.json');
22
 
23
- // Cria diretΓ³rios
24
- if (!fs.existsSync(this.logsPath)) {
25
- fs.mkdirSync(this.logsPath, { recursive: true });
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
26
  }
27
 
28
  // Carrega logs
29
- this.operations = this._loadJSON(this.opsPath, []);
30
- this.alerts = this._loadJSON(this.alertsPath, []);
31
 
32
  console.log('βœ… SecurityLogger inicializado');
33
  }
 
16
  class SecurityLogger {
17
  constructor(config) {
18
  this.config = config;
19
+
20
+ // ═══════════════════════════════════════════════════════════════════
21
+ // HF SPACES: Usar /tmp para garantir permissΓ΅es de escrita
22
+ // O HF Spaces tem sistema de arquivos somente-leitura em /
23
+ // ═══════════════════════════════════════════════════════════════════
24
+
25
+ // ForΓ§ar uso de /tmp no HF Spaces (sistema read-only)
26
+ this.logsPath = '/tmp/akira_data/security_logs';
27
  this.alertsPath = path.join(this.logsPath, 'alerts.json');
28
  this.opsPath = path.join(this.logsPath, 'operations.json');
29
 
30
+ // Cria diretΓ³rios com tratamento de erro
31
+ try {
32
+ if (!fs.existsSync(this.logsPath)) {
33
+ fs.mkdirSync(this.logsPath, { recursive: true });
34
+ console.log(`βœ… SecurityLogger: DiretΓ³rio criado: ${this.logsPath}`);
35
+ }
36
+ } catch (error) {
37
+ console.warn(`⚠️ SecurityLogger: Não foi possível criar diretório em ${this.logsPath}:`, error.message);
38
+
39
+ // Fallback para /tmp direto
40
+ const tmpPath = '/tmp/security_logs';
41
+ try {
42
+ fs.mkdirSync(tmpPath, { recursive: true });
43
+ this.logsPath = tmpPath;
44
+ this.alertsPath = path.join(this.logsPath, 'alerts.json');
45
+ this.opsPath = path.join(this.logsPath, 'operations.json');
46
+ console.log(`βœ… SecurityLogger: Usando fallback: ${this.logsPath}`);
47
+ } catch (fallbackError) {
48
+ console.error('❌ SecurityLogger: Erro crítico ao criar diretório:', fallbackError.message);
49
+ this.logsPath = null;
50
+ }
51
  }
52
 
53
  // Carrega logs
54
+ this.operations = this.logsPath ? this._loadJSON(this.opsPath, []) : [];
55
+ this.alerts = this.logsPath ? this._loadJSON(this.alertsPath, []) : [];
56
 
57
  console.log('βœ… SecurityLogger inicializado');
58
  }