Repostcheck via Checksum

This commit is contained in:
Flummi 2016-08-15 09:18:09 +02:00
parent 2018167d49
commit 4063ccd706

View File

@ -5,6 +5,7 @@ var https = require('https');
var mysql = require('mysql');
var bot = require('coffea')();
var uuid = require('uuid');
var crypto = require('crypto');
const path = require('path');
var sql;
@ -48,9 +49,15 @@ bot.on('message', (e) => {
dl(entry, "./b/"+tmpdest, (cb) => { // download item
if(cb.status === true) {
var tmpuser = getUser(e.user.getNick(), e.network);
sql.query("insert into `f0ck`.`items` (`src`,`dest`,`username`,`userchannel`,`usernetwork`,`stamp`,`active`) values (?,?,?,?,?,?,?)", [
getCheckSum("./b/"+tmpdest+"."+cb.infos.ext, (cbcs) => {
checkRepostCheckSum(cbcs, (cbcrcs) => {
if(cbcrcs) {
sql.query("insert into `f0ck`.`items` (`src`,`dest`,`mime`,`size`,`checksum`,`username`,`userchannel`,`usernetwork`,`stamp`,`active`) values (?,?,?,?,?,?,?,?,?,?)", [
entry,
"./b/"+tmpdest+"."+cb.infos.ext,
cb.infos.mime,
cb.infos.size,
cbcs,
tmpuser['nick'],
e.channel.getName(),
e.network,
@ -62,6 +69,11 @@ bot.on('message', (e) => {
e.reply(msg);
});
}
else
e.reply("repost motherf0cker");
});
});
}
else
if(cb.type == 1)
e.reply(cb.msg);
@ -80,6 +92,11 @@ bot.on('message', (e) => {
e.reply(msg);
});
}
else if(orig.match(/^\.hash/) && e.channel.getName() == "#f0ck") {
getCheckSum('./b/1fbd8b80.png', (cbcs) => {
e.reply(cbcs);
});
}
});
var getUser = (u, n) => {
@ -127,12 +144,28 @@ var checkRepost = (url, cbcr) => {
cbcr((rows[0].count == 0)?true:false);
});
};
var checkRepostCheckSum = (cs, cbcrcs) => {
sql.query("select count(*) as count from `f0ck`.`items` where `checksum` = ?", cs, (err, rows, fields) => {
cbcrcs((rows[0].count == 0)?true:false);
});
};
var formatSize = (size) => {
var i = Math.floor(Math.log(size) / Math.log(1024));
return (size / Math.pow(1024, i)).toFixed(2) * 1 + ' ' + ['B', 'kB', 'MB', 'GB', 'TB'][i];
};
var getCheckSum = (file, cbcs) => {
var sha256sum = crypto.createHash('sha256');
var s = fs.ReadStream(file);
s.on('data', (d) => {
sha256sum.update(d);
});
s.on('end', () => {
var generated_hash = sha256sum.digest('hex');
cbcs(generated_hash);
});
};
// Webserver