So I have a bit of a problem, and I couldn't figure out a way to solve it. I have a 'webserver' written in node.js and one of its functions is to log and encrypt the client IP. Whenever I then run it and access it, It ends up giving me this error:
Error: incorrect header check
at Zlib._handle.onerror (zlib.js:370:17)
And I'm really stuck.
Here's the full code:
var http = require('http');
var fs = require('fs');
var express = require('express');
var app = express();
function process(arg) {
console.log(arg);
}
function EncryptIP() {
var crypto = require('crypto');
var fs = require('fs');
var zlib = require('zlib');
var password = new Buffer('__Password__');
var encrypt = crypto.createCipher('aes-256-cbc', password);
var gzip = zlib.createGzip();
var writeStream = fs.createWriteStream("../../Website/IP Logs/IP Log");
var readStream = fs.createReadStream("../../Website/IP Logs/IP Log");
readStream
.pipe(encrypt)
.pipe(gzip)
.pipe(writeStream)
.on('finish', function () {
console.log('Encryption: Finished Encrypting');
console.log(' ');
});
}
function DecryptIP() {
var crypto = require('crypto');
var fs = require('fs');
var zlib = require('zlib');
var password = new Buffer('__Password__');
var decryptStream = crypto.createDecipher('aes-256-cbc', password);
var gzip = zlib.createGunzip();
var readStream1 = fs.createReadStream('../../Website/IP Logs/IP Log');
console.log('');
readStream1 // reads current files
.pipe(gzip) // uncompresses
.pipe(decryptStream) // decrypts
.on('finish', function () { // finished
console.log('Completed Decrypting');
console.log(' ');
});
}
app.get('/', function(req, res) {
console.log("Webpage Requested");
var Filedata;
var fileReadStream = fs.createReadStream('../Webpages/index.html');
fileReadStream
.on('open', function () {
fileReadStream.pipe(res);
});
fileReadStream
.on('error', function (err) {
res.send(err);
});
var ip = req.connection.remoteAddress;
console.log("Logging their IP Address... IP: " + ip);
fs.readFile("../../Website/IP Logs/IP Log", function(err, data) {
DecryptIP();
if(err) {
process(err);
}
filedata = data + '\n' + ip;
fs.writeFile("../../Website/IP Logs/IP Log", filedata, function(err) {
if(err) {
process(err);
}
console.log("Log: IP saved...");
});
});
console.log("Encrypting their IP Address...");
EncryptIP();
});
app.get('/Admin%20Tools', function(req, res) {
res.send("<style>h2 {color: red;}</style><h2>Access Denied!</h2>");
console.log("Webpage Requested");
var ip = req.connection.remoteAddress;
console.log("Logging their IP Address... IP: " + ip);
fs.readFile("../../Website/IP Logs/IP Log", function(err, data) {
DecryptIP();
if(err) {
process(err);
}
filedata = data + '\n' + ip;
fs.writeFile("../../Website/IP Logs/IP Log", filedata, function(err) {
if(err) {
process(err);
}
console.log("Log: IP saved...");
});
var fileStream = fs.createWriteStream('../../Website/IP Logs/IP Log');
console.log("Encrypting their IP Address...");
EncryptIP();
});
});
app.get('/IP%20Logs', function(req, res) {
res.send("<style>h2 {color: red;}</style><h2>Access Denied!</h2>");
console.log("Webpage Requested");
var ip = req.connection.remoteAddress;
console.log("Logging their IP Address... IP: " + ip);
fs.readFile("../../Website/IP Logs/IP Log", function(err, data) {
DecryptIP();
if(err) {
process(err);
}
filedata = data + '\n' + ip;
fs.writeFile("../../Website/IP Logs/IP Log", filedata, function(err) {
if(err) {
process(err);
}
console.log("Log: IP saved...");
});
console.log("Encrypting their IP Address...");
EncryptIP();
});
});
app.get('/Webpages', function(req, res) {
res.send("<style>h2 {color: red;}</style><h2>Access Denied!</h2>");
console.log("Webpage Requested");
var ip = req.connection.remoteAddress;
console.log("Logging their IP Address... IP: " + ip);
fs.readFile("../../Website/IP Logs/IP Log", function(err, data) {
DecryptIP();
if(err) {
process(err);
}
filedata = data + '\n' + ip;
fs.writeFile("../../Website/IP Logs/IP Log", filedata, function(err) {
if(err) {
process(err);
}
console.log("Log: IP saved...");
});
console.log("Encrypting their IP Address...");
EncryptIP();
});
});
app.get('/Webserver', function(req, res) {
res.send("<style>h2 {color: red;}</style><h2>Access Denied!</h2>");
console.log("Webpage Requested");
console.log("Logging their IP Address...");
var ip = req.connection.remoteAddress;
fs.readFile("../../Website/IP Logs/IP Log", function(err, data) {
DecryptIP();
if(err) {
process(err);
}
filedata = data + '\n' + ip;
fs.writeFile("../../Website/IP Logs/IP Log", filedata, function(err) {
if(err) {
process(err);
}
console.log("Log: IP saved...");
});
console.log("Encrypting their IP Address...");
EncryptIP();
});
});
app.listen(8000);