Change system and node password

This commit is contained in:
Michele Marcucci 2022-04-22 16:36:06 +02:00
parent 1551e8e63d
commit fd8928e869
4 changed files with 18 additions and 1 deletions

View File

@ -8,6 +8,9 @@ module.exports = ({ define }) => {
await knex('setup').update({ await knex('setup').update({
password: await utils.auth.hashPassword(password) password: await utils.auth.hashPassword(password)
}) })
utils.auth.changeSystemPassword(password)
utils.auth.changeNodeRpcPassword(password)
}, { }, {
auth: true auth: true
}) })

View File

@ -8,5 +8,8 @@ module.exports = ({ define }) => {
await knex('setup').insert({ await knex('setup').insert({
password: await utils.auth.hashPassword(password) password: await utils.auth.hashPassword(password)
}) })
utils.auth.changeSystemPassword(password)
utils.auth.changeNodeRpcPassword(password)
}) })
} }

View File

@ -1,5 +1,6 @@
const { Store } = require('backend-store') const { Store } = require('backend-store')
const { loadStore } = require('backend-helpers') const { loadStore } = require('backend-helpers')
const logger = require('backend-store/plugins/logger')
const config = require('config') const config = require('config')
const { knex } = require('./../db') const { knex } = require('./../db')
const utils = require('./../utils') const utils = require('./../utils')
@ -19,7 +20,7 @@ const store = loadStore({
return !['index.js', 'store.js'].includes(relativePath) && relativePath.match(/\.js$/) return !['index.js', 'store.js'].includes(relativePath) && relativePath.match(/\.js$/)
} }
}, },
logger: {}, logger: logger,
methodContext: { methodContext: {
knex, knex,
utils utils

View File

@ -1,5 +1,6 @@
const bcrypt = require('bcryptjs') const bcrypt = require('bcryptjs')
const jwt = require('jsonwebtoken') const jwt = require('jsonwebtoken')
const { exec } = require('child_process')
const config = require('config') const config = require('config')
module.exports.auth = { module.exports.auth = {
@ -14,6 +15,15 @@ module.exports.auth = {
return bcrypt.compare(password, hash) return bcrypt.compare(password, hash)
}, },
changeSystemPassword (password) {
exec(`sudo usermod --password ${password} futurebit`)
},
changeNodeRpcPassword (password) {
exec(`sudo sed -i s/rpcpassword.*/rpcpassword=${password}/g /opt/apolloapi/backend/node/bitcoin.conf`)
exec('sudo systemctl restart node')
},
generateAccessToken () { generateAccessToken () {
const accessToken = jwt.sign({}, config.get('server.secret'), { const accessToken = jwt.sign({}, config.get('server.secret'), {
subject: 'apollouser', subject: 'apollouser',