Update modules/SecurityLogger.js
Browse files- 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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
this.alertsPath = path.join(this.logsPath, 'alerts.json');
|
| 21 |
this.opsPath = path.join(this.logsPath, 'operations.json');
|
| 22 |
|
| 23 |
-
// Cria diretΓ³rios
|
| 24 |
-
|
| 25 |
-
fs.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
}
|