-
Notifications
You must be signed in to change notification settings - Fork 4
Add endpoint to allow pulling log files from the web_interface #24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
pwcushman
wants to merge
2
commits into
master
Choose a base branch
from
paul-getlogs
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ const fs = require("fs") | |
const app = express() | ||
app.use(helmet()) //security http headers | ||
const multer = require("multer") | ||
const tar = require("tar") | ||
|
||
const bot = new WickrIOBotAPI.WickrIOBot() | ||
|
||
|
@@ -688,6 +689,101 @@ async function main() { | |
} | ||
}) | ||
|
||
app.get(endpoint + "/Logs", function (req, res) { | ||
var authHeader = req.get("Authorization") | ||
var authToken | ||
if (authHeader) { | ||
if (authHeader.indexOf(" ") == -1) { | ||
authToken = authHeader | ||
} else { | ||
authHeader = authHeader.split(" ") | ||
authToken = authHeader[1] | ||
} | ||
} else { | ||
res.set("Authorization", "Basic base64_auth_token") | ||
return res | ||
.type("txt") | ||
.status(401) | ||
.send( | ||
'Access denied: invalid Authorization Header format. Correct format: "Authorization: Basic base64_auth_token"' | ||
) | ||
} | ||
if (!checkCreds(authToken)) { | ||
res.set("Authorization", "Basic base64_auth_token") | ||
return res | ||
.type("txt") | ||
.status(401) | ||
.send("Access denied: invalid basic-auth token.") | ||
} | ||
|
||
try { | ||
var logAndOutputFiles = [] | ||
const tarFile = 'LogAndOutputFiles.tar' | ||
const userAttachments = process.cwd() + "/attachments" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This will not work at Windows OS. You should use |
||
const tempDir = userAttachments + '/logs' | ||
|
||
fs.mkdirSync(tempDir, { recursive: true }) | ||
|
||
|
||
const clientLogsDir = process.cwd() + '/../../logs' | ||
const serverLogsDir = process.cwd() + '/../../../../logs' | ||
if (!fs.existsSync(clientLogsDir)) { | ||
console.log('get logs: cannot find:' + clientLogsDir) | ||
res.status(400).send('Cannot find:' + clientLogsDir) | ||
return | ||
} | ||
|
||
// Get the WickrIO client output file | ||
const wickrClientOutputFile = 'WickrIO' + bot_username + '.output' | ||
const wickrClientOutputPath = clientLogsDir + '/' + wickrClientOutputFile | ||
checkForLog( wickrClientOutputFile, wickrClientOutputPath, tempDir, logAndOutputFiles) | ||
|
||
// Get the WickrIO server output file | ||
const wickrServerOutputFile = 'WickrIOSvr.output' | ||
const wickrServerOutputPath = serverLogsDir + '/' + wickrServerOutputFile | ||
checkForLog( wickrServerOutputFile, wickrServerOutputPath, tempDir, logAndOutputFiles) | ||
|
||
// Get the WickrIODebug server output file | ||
const wickrServerDebugOutputFile = 'WickrIOSvrDebug.output' | ||
const wickrServerDebugOutputPath = serverLogsDir + '/' + wickrServerDebugOutputFile | ||
checkForLog( wickrServerDebugOutputFile, wickrServerDebugOutputPath, tempDir, logAndOutputFiles) | ||
|
||
// Get the log.output | ||
const integrationLogOutputFile = 'log.output' | ||
const integrationLogOutputPath = process.cwd() + '/' + integrationLogOutputFile | ||
checkForLog( integrationLogOutputFile, integrationLogOutputPath, tempDir, logAndOutputFiles) | ||
|
||
// Get the err.output | ||
const integrationErrOutputFile = 'err.output' | ||
const integrationErrOutputPath = process.cwd() + '/' + integrationErrOutputFile | ||
checkForLog( integrationErrOutputFile, integrationErrOutputPath, tempDir, logAndOutputFiles) | ||
|
||
// If there are not logs/output files found then return error | ||
if (logAndOutputFiles.length === 0) { | ||
console.log('get logs: there are not log or output files!') | ||
res.status(400).send('Cannot find any log or output files') | ||
return | ||
} | ||
|
||
/* | ||
* Create a tar with all the log/output files in it | ||
*/ | ||
tar.c( { file: tarFile, cwd: tempDir, sync: true }, logAndOutputFiles) | ||
|
||
const stat = fs.statSync(tarFile) | ||
res.writeHead(200, { | ||
'Content-Type': 'application/x-tar', | ||
'Content-Length': stat.size | ||
}); | ||
var readStream = fs.createReadStream(tarFile); | ||
readStream.pipe(res); | ||
} catch (err) { | ||
console.log(err) | ||
res.statusCode = 400 | ||
res.type("txt").send(err.toString()) | ||
} | ||
}) | ||
|
||
// What to do for ALL requests for ALL Paths | ||
// that are not handled above | ||
app.all("*", function (req, res) { | ||
|
@@ -724,5 +820,15 @@ function isJson(str) { | |
return str | ||
} | ||
|
||
function checkForLog(fileName, pathName, destDir, list) { | ||
if (!fs.existsSync(pathName)) { | ||
console.log('get logs: cannot find:' + pathName) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is much better to use |
||
} else { | ||
const newOutput = destDir + '/' + fileName | ||
list.push(fileName) | ||
fs.copyFileSync(pathName, newOutput) | ||
} | ||
} | ||
|
||
main() | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I absolutely sure that this part can be carried out from each route, avoiding terrible code repetition!!!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes that is true. We will add that to the list of things to address.