added an endpoint to update tor node list
This commit is contained in:
parent
bcca1e1df2
commit
6aaa6bd0aa
3 changed files with 59 additions and 1 deletions
51
server/controllers/api/tor/index.js
Normal file
51
server/controllers/api/tor/index.js
Normal file
|
@ -0,0 +1,51 @@
|
||||||
|
const logger = require('winston');
|
||||||
|
const db = require('../../../models');
|
||||||
|
|
||||||
|
const ipAddress = '54.236.53.10';
|
||||||
|
|
||||||
|
/*
|
||||||
|
|
||||||
|
Route to update and return tor exit nodes that can connect to this ip address
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
const getTorList = (req, res) => {
|
||||||
|
return fetch(`https://check.torproject.org/api/bulk?ip=${ipAddress}&port=80`)
|
||||||
|
.then(response => {
|
||||||
|
return response.json();
|
||||||
|
})
|
||||||
|
.then( jsonResponse => {
|
||||||
|
const torList = [];
|
||||||
|
for (let i = 0; i < jsonResponse.length; i++) {
|
||||||
|
torList.push({
|
||||||
|
address: jsonResponse[i].Address,
|
||||||
|
fingerprint: jsonResponse[i].Fingerprint,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return db.Tor.destroy({
|
||||||
|
truncate: true,
|
||||||
|
})
|
||||||
|
.then(() => {
|
||||||
|
return db.Tor.bulkCreate(torList)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
.then(() => {
|
||||||
|
return db.Tor.findAll({
|
||||||
|
attributes: ['address', 'fingerprint'],
|
||||||
|
})
|
||||||
|
.map(el => el.get({ plain: true }));
|
||||||
|
})
|
||||||
|
.then( result => {
|
||||||
|
logger.debug('number of records', result.length);
|
||||||
|
res.status(200).json(result);
|
||||||
|
})
|
||||||
|
.catch((error) => {
|
||||||
|
logger.error(error);
|
||||||
|
res.status(500).json({
|
||||||
|
success: false,
|
||||||
|
error,
|
||||||
|
})
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports = getTorList;
|
|
@ -2,10 +2,14 @@ module.exports = (sequelize, { STRING }) => {
|
||||||
return sequelize.define(
|
return sequelize.define(
|
||||||
'Tor',
|
'Tor',
|
||||||
{
|
{
|
||||||
ip: {
|
address: {
|
||||||
type : STRING,
|
type : STRING,
|
||||||
allowNull: false,
|
allowNull: false,
|
||||||
},
|
},
|
||||||
|
fingerprint: {
|
||||||
|
type : STRING,
|
||||||
|
allowNull: true,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
freezeTableName: true,
|
freezeTableName: true,
|
||||||
|
|
|
@ -14,6 +14,7 @@ const claimShortId = require('../../controllers/api/claim/shortId');
|
||||||
const fileAvailability = require('../../controllers/api/file/availability');
|
const fileAvailability = require('../../controllers/api/file/availability');
|
||||||
const userPassword = require('../../controllers/api/user/password');
|
const userPassword = require('../../controllers/api/user/password');
|
||||||
const publishingConfig = require('../../controllers/api/config/site/publishing');
|
const publishingConfig = require('../../controllers/api/config/site/publishing');
|
||||||
|
const getTorList = require('../../controllers/api/tor');
|
||||||
|
|
||||||
const multipartMiddleware = require('../../middleware/multipartMiddleware');
|
const multipartMiddleware = require('../../middleware/multipartMiddleware');
|
||||||
const torCheckMiddleware = require('../../middleware/torCheckMiddleware');
|
const torCheckMiddleware = require('../../middleware/torCheckMiddleware');
|
||||||
|
@ -40,4 +41,6 @@ module.exports = (app) => {
|
||||||
app.put('/api/user/password/', userPassword);
|
app.put('/api/user/password/', userPassword);
|
||||||
// configs
|
// configs
|
||||||
app.get('/api/config/site/publishing', publishingConfig);
|
app.get('/api/config/site/publishing', publishingConfig);
|
||||||
|
// tor
|
||||||
|
app.get('/api/tor', getTorList);
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue