Skip to content

Commit

Permalink
Fix error with zipped log files
Browse files Browse the repository at this point in the history
  • Loading branch information
GermanBluefox committed Apr 17, 2020
1 parent 160d954 commit 8e8f6bf
Show file tree
Hide file tree
Showing 8 changed files with 486 additions and 227 deletions.
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -87,7 +87,7 @@ This project uses some icons from [Flaticon](https://www.flaticon.com/):
- <img src="src/img/rooms/toilet.svg" height="48" /> - Icons made by [Freepik](http://www.freepik.com) from [www.flaticon.com](https://www.flaticon.com/) is licensed by [CC 3.0 BY](http://creativecommons.org/licenses/by/3.0/)

## Changelog
### 4.0.6 (2020-04-18)
### 4.0.7 (2020-04-18)
* (bluefox) The attempt to process error by the log show.

### 4.0.5 (2020-02-23)
Expand Down
4 changes: 2 additions & 2 deletions io-package.json
Expand Up @@ -2,9 +2,9 @@
"common": {
"name": "admin",
"title": "Admin",
"version": "4.0.6",
"version": "4.0.7",
"news": {
"4.0.6": {
"4.0.7": {
"en": "The attempt to process error by the log show.",
"de": "Der Versuch, Fehler durch das Protokoll zu verarbeiten, wird angezeigt.",
"ru": "Попытка обработать ошибку в журнале.",
Expand Down
8 changes: 6 additions & 2 deletions lib/socket.js
Expand Up @@ -1063,10 +1063,14 @@ function IOSocket(server, settings, adapter, objects, store) {
}
if (fs.existsSync(filename)) {
const files = fs.readdirSync(filename);

for (let f = 0; f < files.length; f++) {
try {
if (!files[f].endsWith('-audit.json') && !fs.lstatSync(filename + '/' + files[f]).isDirectory()) {
result.list.push('log/' + transport + '/' + files[f]);
if (!files[f].endsWith('-audit.json')) {
const stat = fs.lstatSync(filename + '/' + files[f]);
if (!stat.isDirectory()) {
result.list.push({fileName: 'log/' + transport + '/' + files[f], size: stat.size});
}
}
} catch (e) {
// push unchecked
Expand Down
46 changes: 10 additions & 36 deletions lib/web.js
Expand Up @@ -12,7 +12,7 @@ const util = require('util');
const path = require('path');
const stream = require('stream');

let tar = null;
let zlib = null;

let session;
let bodyParser;
Expand Down Expand Up @@ -611,44 +611,18 @@ function Web(settings, adapter, onReady) {
res.header('Content-Type', 'application/gzip');
res.sendFile(filename);
} else {
tar = tar || require('tar');
zlib = zlib || require('zlib');

// extract the file
let cs = new MemoryWriteStream();
try {
tar.x({
file: filename,
strict: false,
transform: entry => {
// do not store file on disk
//entry.absolute = '/dev/null';
return cs;
}
})
.then(() => {
if (cs) {
const text = cs.collect().toString('utf8');
cs = null;
if (text.length > 2 * 1024 * 1024) {
res.header('Content-Type', 'text/plain');
res.send(text);
} else {
res.header('Content-Type', 'text/html');
res.send(decorateLogFile(null, text));
}
}
})
.catch(e => {
if (e && e.toString().includes('TAR_BAD_ARCHIVE')) {
disableTar();
}

if (cs) {
cs = null;
res.sendFile(filename);
}
adapter.log.error(`Cannot extract file ${filename}: ${e}`);
});
const text = zlib.gunzipSync(fs.readFileSync(filename)).toString('utf8');
if (text.length > 2 * 1024 * 1024) {
res.header('Content-Type', 'text/plain');
res.send(text);
} else {
res.header('Content-Type', 'text/html');
res.send(decorateLogFile(null, text));
}
} catch (e) {
if (cs) {
cs = null;
Expand Down

0 comments on commit 8e8f6bf

Please sign in to comment.