mirror of
https://github.com/Retropex/apolloapi-v2.git
synced 2025-05-15 12:40:47 +02:00
[WIP] Node settings, Node TOR, misc
This commit is contained in:
parent
43dadd7d87
commit
105ed38d7c
2
apolloui
2
apolloui
@ -1 +1 @@
|
||||
Subproject commit 79b38394821d3307f3b44126086ce21e96cd00ca
|
||||
Subproject commit 2c4618f2bf01a078b6204f48f9a05d836b40daad
|
13
migrations/20220630134208_add_node_settings.js
Normal file
13
migrations/20220630134208_add_node_settings.js
Normal file
@ -0,0 +1,13 @@
|
||||
exports.up = function(knex, Promise) {
|
||||
return knex.schema.table('settings', function(t) {
|
||||
t.text('node_rpc_password').defaultTo(null);
|
||||
t.boolean('node_enable_tor').notNull().defaultTo(false);
|
||||
});
|
||||
};
|
||||
|
||||
exports.down = function(knex, Promise) {
|
||||
return knex.schema.table('settings', function(t) {
|
||||
t.dropColumn('node_rpc_password');
|
||||
t.dropColumn('node_enable_tor');
|
||||
});
|
||||
};
|
4923
package-lock.json
generated
4923
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -23,6 +23,7 @@
|
||||
"diskusage": "^1.1",
|
||||
"dotenv": "^6.1.0",
|
||||
"express": "^4.16.4",
|
||||
"generate-password": "^1.7.0",
|
||||
"ip": "^1.1.5",
|
||||
"knex": "^0.95",
|
||||
"litecoin": "github:jstefanop/node-litecoin",
|
||||
|
@ -23,6 +23,8 @@ module.exports.typeDefs = `
|
||||
leftSidebarExtended: Boolean!
|
||||
rightSidebarVisibility: Boolean!
|
||||
temperatureUnit: TemperatureUnit!
|
||||
nodeRpcPassword: String!
|
||||
nodeEnableTor: Boolean!
|
||||
}
|
||||
`
|
||||
|
||||
|
@ -18,6 +18,8 @@ module.exports.typeDefs = `
|
||||
leftSidebarExtended: Boolean
|
||||
rightSidebarVisibility: Boolean
|
||||
temperatureUnit: TemperatureUnit
|
||||
nodeRpcPassword: String
|
||||
nodeEnableTor: Boolean
|
||||
}
|
||||
|
||||
type SettingsUpdateOutput {
|
||||
|
@ -10,7 +10,6 @@ module.exports = ({ define }) => {
|
||||
})
|
||||
|
||||
utils.auth.changeSystemPassword(password)
|
||||
utils.auth.changeNodeRpcPassword(password)
|
||||
}, {
|
||||
auth: true
|
||||
})
|
||||
|
@ -1,5 +1,8 @@
|
||||
const generator = require('generate-password')
|
||||
|
||||
module.exports = ({ define }) => {
|
||||
define('setup', async ({ password }, { knex, errors, utils }) => {
|
||||
try {
|
||||
// TODO transaction
|
||||
const [ setup ] = await knex('setup').select('*').limit(1)
|
||||
if (setup) {
|
||||
@ -9,7 +12,19 @@ module.exports = ({ define }) => {
|
||||
password: await utils.auth.hashPassword(password)
|
||||
})
|
||||
|
||||
const rpcPassword = generator.generate({
|
||||
length: 12,
|
||||
numbers: true
|
||||
})
|
||||
|
||||
await knex('settings').update({
|
||||
node_rpc_password: rpcPassword
|
||||
})
|
||||
|
||||
utils.auth.changeSystemPassword(password)
|
||||
utils.auth.changeNodeRpcPassword(password)
|
||||
await utils.auth.changeNodeRpcPassword(rpcPassword)
|
||||
} catch (err) {
|
||||
console.log('ERROR', err);
|
||||
}
|
||||
})
|
||||
}
|
||||
|
@ -27,7 +27,9 @@ module.exports = ({ define }) => {
|
||||
'left_sidebar_visibility as leftSidebarVisibility',
|
||||
'left_sidebar_extended as leftSidebarExtended',
|
||||
'right_sidebar_visibility as rightSidebarVisibility',
|
||||
'temperature_unit as temperatureUnit'
|
||||
'temperature_unit as temperatureUnit',
|
||||
'node_rpc_password as nodeRpcPassword',
|
||||
'node_enable_tor as nodeEnableTor'
|
||||
)
|
||||
|
||||
readQ.orderBy('created_at', 'desc')
|
||||
|
@ -13,6 +13,8 @@ module.exports = ({ define }) => {
|
||||
'left_sidebar_extended as leftSidebarExtended',
|
||||
'right_sidebar_visibility as rightSidebarVisibility',
|
||||
'temperature_unit as temperatureUnit',
|
||||
'node_rpc_password as nodeRpcPassword',
|
||||
'node_enable_tor as nodeEnableTor'
|
||||
])
|
||||
.orderBy('created_at', 'desc')
|
||||
.orderBy('id', 'desc')
|
||||
|
@ -11,7 +11,9 @@ const updateFields = {
|
||||
leftSidebarVisibility: 'left_sidebar_visibility',
|
||||
leftSidebarExtended: 'left_sidebar_extended',
|
||||
rightSidebarVisibility: 'right_sidebar_visibility',
|
||||
temperatureUnit: 'temperature_unit'
|
||||
temperatureUnit: 'temperature_unit',
|
||||
nodeRpcPassword: 'node_rpc_password',
|
||||
nodeEnableTor: 'node_enable_tor'
|
||||
}
|
||||
|
||||
module.exports = ({ define }) => {
|
||||
|
@ -2,9 +2,12 @@ const generateConf = require('../../../configurator');
|
||||
|
||||
module.exports = ({ define }) => {
|
||||
define('update', async (settings, { dispatch, errors, utils }) => {
|
||||
const oldSettings = await dispatch('api/settings/collection/read')
|
||||
await dispatch('api/settings/collection/update', settings)
|
||||
const newSettings = await dispatch('api/settings/collection/read')
|
||||
|
||||
if (oldSettings.nodeEnableTor !== newSettings.nodeEnableTor) await utils.auth.manageTor(newSettings);
|
||||
|
||||
await generateConf(null, newSettings);
|
||||
|
||||
return {
|
||||
|
13
src/utils.js
13
src/utils.js
@ -19,10 +19,10 @@ module.exports.auth = {
|
||||
exec(`sudo usermod --password ${password} futurebit`)
|
||||
},
|
||||
|
||||
changeNodeRpcPassword (password) {
|
||||
async changeNodeRpcPassword (password) {
|
||||
exec(`sudo sed -i s/rpcpassword.*/rpcpassword=${password}/g /opt/apolloapi/backend/node/bitcoin.conf`)
|
||||
if (process.env.BITCOIND_PASSWORD) exec(`sudo sed -i s/BITCOIND_PASSWORD.*/BITCOIND_PASSWORD=${password}/g /opt/apolloapi/.env`)
|
||||
else exec(`sudo echo "BITCOIND_PASSWORD=${password}" >> /opt/apolloapi/.env`)
|
||||
else exec(`echo "BITCOIND_PASSWORD=${password}" | sudo tee -a /opt/apolloapi/.env`)
|
||||
exec('sudo systemctl restart node')
|
||||
exec('sudo systemctl restart apollo-ui')
|
||||
},
|
||||
@ -36,5 +36,14 @@ module.exports.auth = {
|
||||
accessToken
|
||||
}
|
||||
},
|
||||
|
||||
async manageTor (settings) {
|
||||
if (settings.nodeEnableTor) {
|
||||
exec(`echo "server=1\nrpcuser=futurebit\nrpcpassword=${settings.nodeRpcPassword}\ndaemon=0\nmaxconnections=32\nupnp=1\nuacomment=FutureBit-Apollo-Node\n#TOR_START\nproxy=127.0.0.1:9050\nlisten=1\nbind=127.0.0.1\nonlynet=onion\ndnsseed=0\ndns=0\n#TOR_END" | sudo tee /opt/apolloapi/backend/node/bitcoin.conf`)
|
||||
} else {
|
||||
exec(`echo "server=1\nrpcuser=futurebit\nrpcpassword=${settings.nodeRpcPassword}\ndaemon=0\nmaxconnections=32\nupnp=1\nuacomment=FutureBit-Apollo-Node" | sudo tee /opt/apolloapi/backend/node/bitcoin.conf`)
|
||||
}
|
||||
|
||||
exec('sudo systemctl restart node')
|
||||
}
|
||||
}
|
||||
|
@ -1240,6 +1240,11 @@ gauge@~2.7.3:
|
||||
strip-ansi "^3.0.1"
|
||||
wide-align "^1.1.0"
|
||||
|
||||
generate-password@^1.7.0:
|
||||
version "1.7.0"
|
||||
resolved "https://registry.yarnpkg.com/generate-password/-/generate-password-1.7.0.tgz#00ba4eb1e71f89a72307b0d6604ee0d4e7f5770c"
|
||||
integrity sha512-WPCtlfy0jexf7W5IbwxGUgpIDvsZIohbI2DAq2Q6TSlKKis+G4GT9sxvPxrZUGL8kP6WUXMWNqYnxY6DDKAdFA==
|
||||
|
||||
get-stream@^3.0.0:
|
||||
version "3.0.0"
|
||||
resolved "https://registry.yarnpkg.com/get-stream/-/get-stream-3.0.0.tgz#8e943d1358dc37555054ecbe2edb05aa174ede14"
|
||||
|
Loading…
Reference in New Issue
Block a user