From 7cf4666ba0f976fe1929a15efc8029e8952b2e5b Mon Sep 17 00:00:00 2001 From: Michele Marcucci Date: Fri, 12 Apr 2024 10:42:38 +0200 Subject: [PATCH 01/21] Fix change rpc password --- src/init.js | 2 +- src/utils.js | 111 ++++++++++++++++++++++++++++++--------------------- 2 files changed, 66 insertions(+), 47 deletions(-) diff --git a/src/init.js b/src/init.js index 2fe76a8..237b0a8 100644 --- a/src/init.js +++ b/src/init.js @@ -139,7 +139,7 @@ uacomment=FutureBit-Apollo-Node`; if (settings && settings.nodeRpcPassword) { exec( - `sudo sed -i s/rpcpassword.*/rpcpassword=${settings.nodeRpcPassword}/g ${configFilePath}` + `sudo sed -i 's/rpcpassword.*/rpcpassword=${settings.nodeRpcPassword}/g' ${configFilePath}` ); } } diff --git a/src/utils.js b/src/utils.js index a775c72..77749ff 100644 --- a/src/utils.js +++ b/src/utils.js @@ -7,6 +7,21 @@ const { knex } = require('./db'); const fsPromises = require('fs').promises; const path = require('path'); +const configBitcoinFilePath = path.resolve( + __dirname, + '../backend/node/bitcoin.conf' +); + +const configCkpoolFilePath = path.resolve( + __dirname, + '../backend/ckpool/ckpool.conf' +); + +const configCkpoolServiceFilePath = path.resolve( + __dirname, + '../backend/systemd/ckpool.service' +); + module.exports.auth = { hashPassword(password) { return bcrypt.hash(password, 12); @@ -36,21 +51,11 @@ module.exports.auth = { node_rpc_password: password, }); - const configFilePath = path.resolve( - __dirname, - '../backend/node/bitcoin.conf' - ); - - const configCkpoolFilePath = path.resolve( - __dirname, - '../backend/ckpool/ckpool.conf' - ); - - await fs.access(configFilePath); - await fs.access(configCkpoolFilePath); + await fsPromises.access(configBitcoinFilePath); + await fsPromises.access(configCkpoolFilePath); exec( - `sudo sed -i s/rpcpassword.*/rpcpassword=${password}/g ${configFilePath}` + `sudo sed -i s/rpcpassword.*/rpcpassword=${password}/g ${configBitcoinFilePath}` ); exec( @@ -74,13 +79,8 @@ module.exports.auth = { }; }, - async manageBitcoinConf(settings) { - const defaultConf = `server=1\nrpcuser=futurebit\nrpcpassword=${settings.nodeRpcPassword}\ndaemon=0\nmaxconnections=32\nupnp=1\nuacomment=FutureBit-Apollo-Node`; - let conf = defaultConf; - - if (settings.nodeEnableSoloMining) { - conf += `\n#SOLO_START\nzmqpubhashblock=tcp://127.0.0.1:28332\n#SOLO_END`; - + async manageCkpoolConf(settings) { + try { const ckpoolConf = { btcd: [ { @@ -96,37 +96,56 @@ module.exports.auth = { }; await fsPromises.writeFile( - '/opt/apolloapi/backend/ckpool/ckpool.conf', + configCkpoolFilePath, JSON.stringify(ckpoolConf, null, 2) ); + } catch (err) { + console.log('ERR manageCkpoolConf', err); + } + }, + + async manageBitcoinConf(settings) { + try { + const defaultConf = `server=1\nrpcuser=futurebit\nrpcpassword=${settings.nodeRpcPassword}\ndaemon=0\nmaxconnections=32\nupnp=1\nuacomment=FutureBit-Apollo-Node`; + let conf = defaultConf; + + if (settings.nodeEnableSoloMining) { + conf += `\n#SOLO_START\nzmqpubhashblock=tcp://127.0.0.1:28332\n#SOLO_END`; + + this.manageCkpoolConf(settings); + + exec( + `sudo cp ${configCkpoolServiceFilePath} /etc/systemd/system/ckpool.service` + ); + exec('sudo systemctl daemon-reload'); + exec('sudo systemctl enable ckpool'); + exec('sudo systemctl restart ckpool'); + } else { + exec('sudo systemctl stop ckpool'); + exec('sudo systemctl disable ckpool'); + } + + if (settings.nodeEnableTor) { + conf += `\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`; + exec('sudo systemctl enable tor'); + exec('sudo systemctl restart tor'); + } else { + exec('sudo systemctl stop tor'); + exec('sudo systemctl disable tor'); + } + + if (settings.nodeUserConf) + conf += `\n#USER_INPUT_START\n${settings.nodeUserConf}\n#USER_INPUT_END`; + + console.log('Writing Bitcoin conf file', conf); exec( - 'sudo cp /opt/app/backend/systemd/ckpool.service /etc/systemd/system/ckpool.service' + `echo "${conf}" | sudo tee ${configBitcoinFilePath}` ); - exec('sudo systemctl daemon-reload'); - exec('sudo systemctl enable ckpool'); - exec('sudo systemctl restart ckpool'); - } else { - exec('sudo systemctl stop ckpool'); - exec('sudo systemctl disable ckpool'); + + exec('sudo systemctl restart node'); + } catch (err) { + console.log('ERR manageBitcoinConf', err); } - - if (settings.nodeEnableTor) { - conf += `\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`; - exec('sudo systemctl enable tor'); - exec('sudo systemctl restart tor'); - } else { - exec('sudo systemctl stop tor'); - exec('sudo systemctl disable tor'); - } - - if (settings.nodeUserConf) - conf += `\n#USER_INPUT_START\n${settings.nodeUserConf}\n#USER_INPUT_END`; - - console.log('Writing Bitcoin conf file', conf); - - exec(`echo "${conf}" | sudo tee /opt/apolloapi/backend/node/bitcoin.conf`); - - exec('sudo systemctl restart node'); }, }; From 24204f2ec3c50d4d9ac199f9486f148520df2841 Mon Sep 17 00:00:00 2001 From: Michele Marcucci Date: Fri, 12 Apr 2024 10:46:05 +0200 Subject: [PATCH 02/21] Removed log --- src/utils.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/utils.js b/src/utils.js index 0a8044c..77749ff 100644 --- a/src/utils.js +++ b/src/utils.js @@ -62,8 +62,6 @@ module.exports.auth = { `sudo sed -i 's#"pass": ""#"pass": "${password}"#g' ${configCkpoolFilePath}` ); - console.log(password, configFilePath); - exec('sudo systemctl restart node'); exec('sudo systemctl restart ckpool'); } catch (err) { From c5ff3622eaeba0cc675434fa10e83f55b73bedce Mon Sep 17 00:00:00 2001 From: Michele Marcucci Date: Fri, 12 Apr 2024 11:31:46 +0200 Subject: [PATCH 03/21] Removed redundant code --- src/init.js | 112 ++++---------------------------- src/store/api/auth/authSetup.js | 1 - src/utils.js | 13 ++-- 3 files changed, 18 insertions(+), 108 deletions(-) diff --git a/src/init.js b/src/init.js index fcd751b..1b2e17f 100644 --- a/src/init.js +++ b/src/init.js @@ -30,23 +30,22 @@ const initEnvFile = async () => { const runMigrations = async () => { try { console.log('Run migrations'); - const resp = await knex.migrate.latest(); - await createCkpoolConfigFile(); - await createBitcoinConfigFile(); - await runGenerateBitcoinPassword(); - } catch (err) { - console.log(err); - } -}; - -const runGenerateBitcoinPassword = async () => { - try { - console.log('Checking bitcoin password existence'); + await knex.migrate.latest(); const [settings] = await knex('settings') .select(['node_rpc_password as nodeRpcPassword']) .orderBy('created_at', 'desc') .orderBy('id', 'desc') .limit(1); + await utils.auth.manageBitcoinConf(settings); + await runGenerateBitcoinPassword(settings); + } catch (err) { + console.log(err); + } +}; + +const runGenerateBitcoinPassword = async (settings) => { + try { + console.log('Checking bitcoin password existence'); if (settings && settings.nodeRpcPassword) return console.log('Bitcoin password found'); @@ -56,95 +55,6 @@ const runGenerateBitcoinPassword = async () => { } }; -const createCkpoolConfigFile = async () => { - const configFilePath = path.resolve( - __dirname, - '../backend/ckpool/ckpool.conf' - ); - const configContent = `{ - "btcd": [ - { - "url": "127.0.0.1:8332", - "auth": "futurebit", - "pass": "", - "notify": true - } - ], - "logdir": "/opt/apolloapi/backend/ckpool/logs" -}`; - - try { - // Check if the file exists - await fs.access(configFilePath); - console.log('File ckpool.conf already exists.'); - } catch (error) { - try { - // Create the file - await fs.writeFile(configFilePath, configContent, 'utf-8'); - console.log('File ckpool.conf created.'); - } catch (error) { - console.error( - `Error during the creation of the file ckpool.conf: ${error.message}` - ); - } - } finally { - const [settings] = await knex('settings') - .select(['node_rpc_password as nodeRpcPassword']) - .orderBy('created_at', 'desc') - .orderBy('id', 'desc') - .limit(1); - - if (settings && settings.nodeRpcPassword) { - exec( - `sudo sed -i 's#"pass":.*#"pass": "${settings.nodeRpcPassword}",#g' ${configFilePath}` - ); - } - } -}; - -const createBitcoinConfigFile = async () => { - const configFilePath = path.resolve( - __dirname, - '../backend/node/bitcoin.conf' - ); - const configContent = `server=1 -rpcuser=futurebit -rpcpassword= -daemon=0 -maxconnections=32 -upnp=1 -uacomment=FutureBit-Apollo-Node`; - - try { - // Check if the file exists - await fs.access(configFilePath); - console.log('File bitcoin.conf already exists.'); - } catch (error) { - try { - // Create the file - await fs.writeFile(configFilePath, configContent, 'utf-8'); - console.log('File bitcoin.conf created.'); - await utils.auth.changeNodeRpcPassword(); - } catch (error) { - console.error( - `Error during the creation of the file bitcoin.conf: ${error.message}` - ); - } - } finally { - const [settings] = await knex('settings') - .select(['node_rpc_password as nodeRpcPassword']) - .orderBy('created_at', 'desc') - .orderBy('id', 'desc') - .limit(1); - - if (settings && settings.nodeRpcPassword) { - exec( - `sudo sed -i 's/rpcpassword.*/rpcpassword=${settings.nodeRpcPassword}/g' ${configFilePath}` - ); - } - } -}; - initEnvFile(); runMigrations().then(startServer); diff --git a/src/store/api/auth/authSetup.js b/src/store/api/auth/authSetup.js index 6bf54a6..549678f 100644 --- a/src/store/api/auth/authSetup.js +++ b/src/store/api/auth/authSetup.js @@ -11,7 +11,6 @@ module.exports = ({ define }) => { }) utils.auth.changeSystemPassword(password) - await utils.auth.changeNodeRpcPassword() } catch (err) { console.log('ERROR', err); } diff --git a/src/utils.js b/src/utils.js index 77749ff..af2f146 100644 --- a/src/utils.js +++ b/src/utils.js @@ -55,11 +55,11 @@ module.exports.auth = { await fsPromises.access(configCkpoolFilePath); exec( - `sudo sed -i s/rpcpassword.*/rpcpassword=${password}/g ${configBitcoinFilePath}` + `sudo sed -i 's/rpcpassword.*/rpcpassword=${password}/g' ${configBitcoinFilePath}` ); exec( - `sudo sed -i 's#"pass": ""#"pass": "${password}"#g' ${configCkpoolFilePath}` + `sudo sed -i 's#"pass":.*#"pass": "${password}",#g' ${configCkpoolFilePath}` ); exec('sudo systemctl restart node'); @@ -109,11 +109,11 @@ module.exports.auth = { const defaultConf = `server=1\nrpcuser=futurebit\nrpcpassword=${settings.nodeRpcPassword}\ndaemon=0\nmaxconnections=32\nupnp=1\nuacomment=FutureBit-Apollo-Node`; let conf = defaultConf; + this.manageCkpoolConf(settings); + if (settings.nodeEnableSoloMining) { conf += `\n#SOLO_START\nzmqpubhashblock=tcp://127.0.0.1:28332\n#SOLO_END`; - this.manageCkpoolConf(settings); - exec( `sudo cp ${configCkpoolServiceFilePath} /etc/systemd/system/ckpool.service` ); @@ -139,8 +139,9 @@ module.exports.auth = { console.log('Writing Bitcoin conf file', conf); - exec( - `echo "${conf}" | sudo tee ${configBitcoinFilePath}` + await fsPromises.writeFile( + configBitcoinFilePath, + conf ); exec('sudo systemctl restart node'); From c01fbee47af6279f999e41f11e135a330b4b5339 Mon Sep 17 00:00:00 2001 From: Michele Marcucci Date: Fri, 12 Apr 2024 14:07:13 +0200 Subject: [PATCH 04/21] =?UTF-8?q?Fix=20ckpool=20doesn=E2=80=99t=20need=20r?= =?UTF-8?q?estart=20if=20not=20enabled?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/init.js | 2 +- src/utils.js | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/init.js b/src/init.js index 1b2e17f..afefcd5 100644 --- a/src/init.js +++ b/src/init.js @@ -49,7 +49,7 @@ const runGenerateBitcoinPassword = async (settings) => { if (settings && settings.nodeRpcPassword) return console.log('Bitcoin password found'); - else await utils.auth.changeNodeRpcPassword(); + else await utils.auth.changeNodeRpcPassword(settings); } catch (err) { console.log(err); } diff --git a/src/utils.js b/src/utils.js index af2f146..86963dd 100644 --- a/src/utils.js +++ b/src/utils.js @@ -38,7 +38,7 @@ module.exports.auth = { exec(`echo 'futurebit:${password}' | sudo chpasswd`); }, - async changeNodeRpcPassword() { + async changeNodeRpcPassword(settings) { try { console.log('Generating and saving bitcoin password'); @@ -63,7 +63,7 @@ module.exports.auth = { ); exec('sudo systemctl restart node'); - exec('sudo systemctl restart ckpool'); + if (settings?.nodeEnableSoloMining) exec('sudo systemctl restart ckpool'); } catch (err) { console.log('ERR changeNodeRpcPassword', err); } From b429cab21a42fa0cfc14bcb6cd37c4377472591d Mon Sep 17 00:00:00 2001 From: Michele Marcucci Date: Mon, 15 Apr 2024 14:28:09 +0200 Subject: [PATCH 05/21] Gitignore --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitignore b/.gitignore index 683633f..239ded1 100644 --- a/.gitignore +++ b/.gitignore @@ -60,6 +60,7 @@ typings/ # dotenv environment variables file .env +.env.staging .env*.local # next.js build output @@ -67,6 +68,7 @@ typings/ # sqlite *.sqlite +*.sqlite.* #backed backend/apollo-miner/apollo-miner* @@ -77,3 +79,4 @@ backend/node/bitcoind backend/node/bitcoin.conf backend/ckpool/ckpool.conf backend/start_swap.sh +backend/apollo-miner/mode From 0067f4339eccd2ca8171b815062b928b9c5c8345 Mon Sep 17 00:00:00 2001 From: Michele Marcucci Date: Mon, 15 Apr 2024 15:01:15 +0200 Subject: [PATCH 06/21] [WIP] Extra node options --- backend/default-configs/bitcoin.conf | 1 - backend/node/bin/bitcoin.conf | 1 - .../20240415123117_node_extra_options.js | 13 +++++ .../graphqlModules/Settings/Settings.js | 4 +- .../graphqlModules/Settings/SettingsUpdate.js | 4 +- .../api/settings/collection/settingsList.js | 4 +- .../api/settings/collection/settingsRead.js | 4 +- .../api/settings/collection/settingsUpdate.js | 4 +- src/utils.js | 58 ++++++++++++++++--- 9 files changed, 78 insertions(+), 15 deletions(-) create mode 100644 migrations/20240415123117_node_extra_options.js diff --git a/backend/default-configs/bitcoin.conf b/backend/default-configs/bitcoin.conf index 3cc0ddd..81273e8 100644 --- a/backend/default-configs/bitcoin.conf +++ b/backend/default-configs/bitcoin.conf @@ -2,7 +2,6 @@ server=1 rpcuser=futurebit rpcpassword= daemon=0 -maxconnections=32 upnp=1 uacomment=FutureBit-Apollo-Node zmqpubhashblock=tcp://127.0.0.1:28332 \ No newline at end of file diff --git a/backend/node/bin/bitcoin.conf b/backend/node/bin/bitcoin.conf index e53308b..b3923f3 100755 --- a/backend/node/bin/bitcoin.conf +++ b/backend/node/bin/bitcoin.conf @@ -2,6 +2,5 @@ server=1 rpcuser=futurebit rpcpassword=futurebit daemon=0 -maxconnections=32 upnp=1 uacomment=FutureBit-Apollo-Node diff --git a/migrations/20240415123117_node_extra_options.js b/migrations/20240415123117_node_extra_options.js new file mode 100644 index 0000000..fe24166 --- /dev/null +++ b/migrations/20240415123117_node_extra_options.js @@ -0,0 +1,13 @@ +exports.up = function (knex, Promise) { + return knex.schema.table('settings', function (t) { + t.boolean('node_max_connections').defaultTo(32); + t.boolean('node_allow_lan').defaultTo(false); + }); +}; + +exports.down = function (knex, Promise) { + return knex.schema.table('settings', function (t) { + t.dropColumn('node_max_connections'); + t.dropColumn('node_allow_lan'); + }); +}; \ No newline at end of file diff --git a/src/graphql/graphqlModules/Settings/Settings.js b/src/graphql/graphqlModules/Settings/Settings.js index c8ee7d7..822dab4 100644 --- a/src/graphql/graphqlModules/Settings/Settings.js +++ b/src/graphql/graphqlModules/Settings/Settings.js @@ -23,11 +23,13 @@ module.exports.typeDefs = ` leftSidebarExtended: Boolean! rightSidebarVisibility: Boolean! temperatureUnit: TemperatureUnit! + powerLedOff: Boolean nodeRpcPassword: String nodeEnableTor: Boolean nodeUserConf: String nodeEnableSoloMining: Boolean - powerLedOff: Boolean + nodeMaxConnections: Int + nodeAllowLan: Boolean } ` diff --git a/src/graphql/graphqlModules/Settings/SettingsUpdate.js b/src/graphql/graphqlModules/Settings/SettingsUpdate.js index 1376289..e56f716 100644 --- a/src/graphql/graphqlModules/Settings/SettingsUpdate.js +++ b/src/graphql/graphqlModules/Settings/SettingsUpdate.js @@ -18,11 +18,13 @@ module.exports.typeDefs = ` leftSidebarExtended: Boolean rightSidebarVisibility: Boolean temperatureUnit: TemperatureUnit + powerLedOff: Boolean nodeRpcPassword: String nodeEnableTor: Boolean nodeUserConf: String nodeEnableSoloMining: Boolean - powerLedOff: Boolean + nodeMaxConnections: Int + nodeAllowLan: Boolean } type SettingsUpdateOutput { diff --git a/src/store/api/settings/collection/settingsList.js b/src/store/api/settings/collection/settingsList.js index 4e35c8d..ab2f5ff 100644 --- a/src/store/api/settings/collection/settingsList.js +++ b/src/store/api/settings/collection/settingsList.js @@ -28,11 +28,13 @@ module.exports = ({ define }) => { 'left_sidebar_extended as leftSidebarExtended', 'right_sidebar_visibility as rightSidebarVisibility', 'temperature_unit as temperatureUnit', + 'power_led_off as powerLedOff', 'node_rpc_password as nodeRpcPassword', 'node_enable_tor as nodeEnableTor', 'node_user_conf as nodeUserConf', 'node_enable_solo_mining as nodeEnableSoloMining', - 'power_led_off as powerLedOff', + 'node_max_connections as nodeMaxConnections', + 'node_allow_lan as nodeAllowLan', ) readQ.orderBy('created_at', 'desc') diff --git a/src/store/api/settings/collection/settingsRead.js b/src/store/api/settings/collection/settingsRead.js index bd3f073..433285e 100644 --- a/src/store/api/settings/collection/settingsRead.js +++ b/src/store/api/settings/collection/settingsRead.js @@ -13,11 +13,13 @@ module.exports = ({ define }) => { 'left_sidebar_extended as leftSidebarExtended', 'right_sidebar_visibility as rightSidebarVisibility', 'temperature_unit as temperatureUnit', + 'power_led_off as powerLedOff', 'node_rpc_password as nodeRpcPassword', 'node_enable_tor as nodeEnableTor', 'node_user_conf as nodeUserConf', 'node_enable_solo_mining as nodeEnableSoloMining', - 'power_led_off as powerLedOff', + 'node_max_connections as nodeMaxConnections', + 'node_allow_lan as nodeAllowLan', ]) .orderBy('created_at', 'desc') .orderBy('id', 'desc') diff --git a/src/store/api/settings/collection/settingsUpdate.js b/src/store/api/settings/collection/settingsUpdate.js index b897c26..261ef74 100644 --- a/src/store/api/settings/collection/settingsUpdate.js +++ b/src/store/api/settings/collection/settingsUpdate.js @@ -12,11 +12,13 @@ const updateFields = { leftSidebarExtended: 'left_sidebar_extended', rightSidebarVisibility: 'right_sidebar_visibility', temperatureUnit: 'temperature_unit', + powerLedOff: 'power_led_off', nodeRpcPassword: 'node_rpc_password', nodeEnableTor: 'node_enable_tor', nodeUserConf: 'node_user_conf', nodeEnableSoloMining: 'node_enable_solo_mining', - powerLedOff: 'power_led_off' + nodeMaxConnections: 'node_max_connections', + nodeAllowLan: 'node_allow_lan' } module.exports = ({ define }) => { diff --git a/src/utils.js b/src/utils.js index 86963dd..2e11f99 100644 --- a/src/utils.js +++ b/src/utils.js @@ -6,6 +6,7 @@ const config = require('config'); const { knex } = require('./db'); const fsPromises = require('fs').promises; const path = require('path'); +const os = require('os'); const configBitcoinFilePath = path.resolve( __dirname, @@ -63,7 +64,7 @@ module.exports.auth = { ); exec('sudo systemctl restart node'); - if (settings?.nodeEnableSoloMining) exec('sudo systemctl restart ckpool'); + if (settings?.nodeEnableSoloMining) exec('sudo systemctl restart ckpool'); } catch (err) { console.log('ERR changeNodeRpcPassword', err); } @@ -79,6 +80,29 @@ module.exports.auth = { }; }, + getSystemNetwork() { + // Get network interface information + const interfaces = os.networkInterfaces(); + let network = null; + + console.log(interfaces); + + // Check if wlan0 has an associated IP address + if (interfaces['wlan0'] && interfaces['wlan0'].some(info => info.family === 'IPv4')) { + // If wlan0 has an associated IP address, use wlan0 + network = interfaces['wlan0'].find(info => info.family === 'IPv4').address; + } else if (interfaces['eth0'] && interfaces['eth0'].some(info => info.family === 'IPv4')) { + // If wlan0 doesn't have an associated IP address but eth0 does, use eth0 + network = interfaces['eth0'].find(info => info.family === 'IPv4').address; + } else { + console.log('No IP address associated with wlan0 or eth0'); + } + + console.log('LAN IP Address:', network); + + return network; + }, + async manageCkpoolConf(settings) { try { const ckpoolConf = { @@ -106,7 +130,7 @@ module.exports.auth = { async manageBitcoinConf(settings) { try { - const defaultConf = `server=1\nrpcuser=futurebit\nrpcpassword=${settings.nodeRpcPassword}\ndaemon=0\nmaxconnections=32\nupnp=1\nuacomment=FutureBit-Apollo-Node`; + const defaultConf = `server=1\nrpcuser=futurebit\nrpcpassword=${settings.nodeRpcPassword}\ndaemon=0\nupnp=1\nuacomment=FutureBit-Apollo-Node`; let conf = defaultConf; this.manageCkpoolConf(settings); @@ -134,15 +158,33 @@ module.exports.auth = { exec('sudo systemctl disable tor'); } - if (settings.nodeUserConf) - conf += `\n#USER_INPUT_START\n${settings.nodeUserConf}\n#USER_INPUT_END`; + if (settings.nodeMaxConnections) + conf += `\nmaxconnections=${settings.nodeMaxConnections}`; + else conf += '\nmaxconnections=32'; + + if (settings.nodeAllowLan) { + const lanNetwork = this.getSystemNetwork(); + conf += `\nrpcallowip=${lanNetwork || '127.0.0.1'}`; + } + + if (settings.nodeUserConf) { + // Split settings.nodeUserConf and defaultConf into arrays of lines + const userConfLines = settings.nodeUserConf.split('\n'); + const defaultConfLines = defaultConf.split('\n'); + + // Exclude lines from settings.nodeUserConf that are also present in defaultConf + const filteredUserConfLines = userConfLines.filter(line => !defaultConfLines.includes(line)); + + // Join the remaining lines back into a single string + const filteredUserConf = filteredUserConfLines.join('\n'); + + // Append the filtered user configuration to the overall configuration + conf += `\n#USER_INPUT_START\n${filteredUserConf}\n#USER_INPUT_END`; + } console.log('Writing Bitcoin conf file', conf); - await fsPromises.writeFile( - configBitcoinFilePath, - conf - ); + await fsPromises.writeFile(configBitcoinFilePath, conf); exec('sudo systemctl restart node'); } catch (err) { From 7e68cc3c0b86abefd7c37b08ed2c26cc3ce937de Mon Sep 17 00:00:00 2001 From: Michele Marcucci Date: Mon, 15 Apr 2024 16:09:35 +0200 Subject: [PATCH 07/21] Fix migration --- migrations/20240415123117_node_extra_options.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/migrations/20240415123117_node_extra_options.js b/migrations/20240415123117_node_extra_options.js index fe24166..1adb0b6 100644 --- a/migrations/20240415123117_node_extra_options.js +++ b/migrations/20240415123117_node_extra_options.js @@ -1,6 +1,6 @@ exports.up = function (knex, Promise) { return knex.schema.table('settings', function (t) { - t.boolean('node_max_connections').defaultTo(32); + t.integer('node_max_connections').defaultTo(32); t.boolean('node_allow_lan').defaultTo(false); }); }; From 3c632e55471d2eb057d805a5210d6b683d78eb80 Mon Sep 17 00:00:00 2001 From: Michele Marcucci Date: Mon, 15 Apr 2024 16:26:47 +0200 Subject: [PATCH 08/21] Fix node extra options --- src/init.js | 15 +++++++++------ src/utils.js | 4 ++-- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/init.js b/src/init.js index afefcd5..61a35b0 100644 --- a/src/init.js +++ b/src/init.js @@ -1,12 +1,8 @@ -const { writeFileSync, readFileSync, existsSync } = require('fs'); +const { writeFileSync, existsSync } = require('fs'); const { join } = require('path'); const crypto = require('crypto'); -const { exec } = require('child_process'); -const generator = require('generate-password'); const utils = require('./utils'); const { knex } = require('./db'); -const fs = require('fs').promises; -const path = require('path'); const initEnvFile = async () => { const envPath = join(__dirname, '..', '.env'); @@ -32,7 +28,14 @@ const runMigrations = async () => { console.log('Run migrations'); await knex.migrate.latest(); const [settings] = await knex('settings') - .select(['node_rpc_password as nodeRpcPassword']) + .select([ + 'node_rpc_password as nodeRpcPassword', + 'node_enable_tor as nodeEnableTor', + 'node_user_conf as nodeUserConf', + 'node_enable_solo_mining as nodeEnableSoloMining', + 'node_max_connections as nodeMaxConnections', + 'node_allow_lan as nodeAllowLan', + ]) .orderBy('created_at', 'desc') .orderBy('id', 'desc') .limit(1); diff --git a/src/utils.js b/src/utils.js index 2e11f99..fd5e216 100644 --- a/src/utils.js +++ b/src/utils.js @@ -90,10 +90,10 @@ module.exports.auth = { // Check if wlan0 has an associated IP address if (interfaces['wlan0'] && interfaces['wlan0'].some(info => info.family === 'IPv4')) { // If wlan0 has an associated IP address, use wlan0 - network = interfaces['wlan0'].find(info => info.family === 'IPv4').address; + network = interfaces['wlan0'].find(info => info.family === 'IPv4').cidr; } else if (interfaces['eth0'] && interfaces['eth0'].some(info => info.family === 'IPv4')) { // If wlan0 doesn't have an associated IP address but eth0 does, use eth0 - network = interfaces['eth0'].find(info => info.family === 'IPv4').address; + network = interfaces['eth0'].find(info => info.family === 'IPv4').cidr; } else { console.log('No IP address associated with wlan0 or eth0'); } From a90a60a9eb92c94cd73d407b50c1a8dbe6bd0363 Mon Sep 17 00:00:00 2001 From: Michele Marcucci Date: Mon, 15 Apr 2024 17:37:21 +0200 Subject: [PATCH 09/21] Filter disallowed node conf from user --- src/utils.js | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/utils.js b/src/utils.js index fd5e216..5870873 100644 --- a/src/utils.js +++ b/src/utils.js @@ -168,15 +168,17 @@ module.exports.auth = { } if (settings.nodeUserConf) { - // Split settings.nodeUserConf and defaultConf into arrays of lines - const userConfLines = settings.nodeUserConf.split('\n'); - const defaultConfLines = defaultConf.split('\n'); + // Extract variable names from settings.nodeUserConf using regex + const userConfVariables = settings.nodeUserConf.match(/^[^=\r\n]+/gm); - // Exclude lines from settings.nodeUserConf that are also present in defaultConf - const filteredUserConfLines = userConfLines.filter(line => !defaultConfLines.includes(line)); + // Extract variable names from defaultConf using regex + const defaultConfVariables = defaultConf.match(/^[^=\r\n]+/gm); - // Join the remaining lines back into a single string - const filteredUserConf = filteredUserConfLines.join('\n'); + // Remove variables from settings.nodeUserConf that are also present in defaultConf + const filteredUserConfVariables = userConfVariables.filter(variable => !defaultConfVariables.includes(variable)); + + // Join the remaining variables back into a single string + const filteredUserConf = filteredUserConfVariables.join('\n'); // Append the filtered user configuration to the overall configuration conf += `\n#USER_INPUT_START\n${filteredUserConf}\n#USER_INPUT_END`; From d42d58ecf8ce7da2647f18a15809109b1cf2b9f0 Mon Sep 17 00:00:00 2001 From: Michele Marcucci Date: Wed, 17 Apr 2024 16:54:39 +0200 Subject: [PATCH 10/21] Get network from system for node conf --- src/utils.js | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/src/utils.js b/src/utils.js index 5870873..46b4388 100644 --- a/src/utils.js +++ b/src/utils.js @@ -85,21 +85,23 @@ module.exports.auth = { const interfaces = os.networkInterfaces(); let network = null; - console.log(interfaces); - // Check if wlan0 has an associated IP address - if (interfaces['wlan0'] && interfaces['wlan0'].some(info => info.family === 'IPv4')) { + if ( + interfaces['wlan0'] && + interfaces['wlan0'].some((info) => info.family === 'IPv4') + ) { // If wlan0 has an associated IP address, use wlan0 - network = interfaces['wlan0'].find(info => info.family === 'IPv4').cidr; - } else if (interfaces['eth0'] && interfaces['eth0'].some(info => info.family === 'IPv4')) { + network = interfaces['wlan0'].find((info) => info.family === 'IPv4').cidr; + } else if ( + interfaces['eth0'] && + interfaces['eth0'].some((info) => info.family === 'IPv4') + ) { // If wlan0 doesn't have an associated IP address but eth0 does, use eth0 - network = interfaces['eth0'].find(info => info.family === 'IPv4').cidr; + network = interfaces['eth0'].find((info) => info.family === 'IPv4').cidr; } else { console.log('No IP address associated with wlan0 or eth0'); } - console.log('LAN IP Address:', network); - return network; }, @@ -175,13 +177,17 @@ module.exports.auth = { const defaultConfVariables = defaultConf.match(/^[^=\r\n]+/gm); // Remove variables from settings.nodeUserConf that are also present in defaultConf - const filteredUserConfVariables = userConfVariables.filter(variable => !defaultConfVariables.includes(variable)); + const filteredUserConfVariables = userConfVariables.filter( + (variable) => !defaultConfVariables.includes(variable) + ); - // Join the remaining variables back into a single string - const filteredUserConf = filteredUserConfVariables.join('\n'); + if (filteredUserConfVariables.length) { + // Join the remaining variables back into a single string + const filteredUserConf = filteredUserConfVariables.join('\n'); - // Append the filtered user configuration to the overall configuration - conf += `\n#USER_INPUT_START\n${filteredUserConf}\n#USER_INPUT_END`; + // Append the filtered user configuration to the overall configuration + conf += `\n#USER_INPUT_START\n${filteredUserConf}\n#USER_INPUT_END`; + } } console.log('Writing Bitcoin conf file', conf); From 0131c94b582b6e65cf47aca38c230657905761f5 Mon Sep 17 00:00:00 2001 From: Michele Marcucci Date: Wed, 17 Apr 2024 18:18:57 +0200 Subject: [PATCH 11/21] Fix network rpcallow, fix ckpool users --- .../graphqlModules/Miner/MinerStats.js | 2 +- src/store/api/miner/minerStats.js | 61 ++++++++------- src/utils.js | 78 ++++++++++++++++++- 3 files changed, 108 insertions(+), 33 deletions(-) diff --git a/src/graphql/graphqlModules/Miner/MinerStats.js b/src/graphql/graphqlModules/Miner/MinerStats.js index a66e3d5..26d924b 100644 --- a/src/graphql/graphqlModules/Miner/MinerStats.js +++ b/src/graphql/graphqlModules/Miner/MinerStats.js @@ -185,7 +185,7 @@ module.exports.typeDefs = ` type MinerStatsCkpool { pool: MinerStatsCkpoolPool - users: MinerStatsCkpoolUsers + users: [MinerStatsCkpoolUsers] } type MinerStatsCkpoolPool { diff --git a/src/store/api/miner/minerStats.js b/src/store/api/miner/minerStats.js index cb01c29..042f352 100644 --- a/src/store/api/miner/minerStats.js +++ b/src/store/api/miner/minerStats.js @@ -1,10 +1,7 @@ -const { join } = require('path'); -const { exec } = require('child_process'); const fs = require('fs').promises; const path = require('path'); const _ = require('lodash'); const moment = require('moment'); -const { existsSync } = require('fs'); const c = require('config'); module.exports = ({ define }) => { @@ -69,40 +66,48 @@ const getCkpoolStats = async (errors, settings, pools) => { try { if (settings?.nodeEnableSoloMining) { - const poolUsername = pools[0] && pools[0].username; const ckpoolPoolStatsFile = path.resolve( __dirname, '../../../../backend/ckpool/logs/pool/pool.status' ); - const ckpoolUsersStatsFile = path.resolve( + const ckpoolUsersStatsDir = path.resolve( __dirname, - `../../../../backend/ckpool/logs/users/${poolUsername}` + '../../../../backend/ckpool/logs/users/' ); - if ( - existsSync(ckpoolPoolStatsFile) && - existsSync(ckpoolUsersStatsFile) - ) { - await Promise.all([ - (async () => { - let ckpoolPoolData = await parseFileToJsonArray( - ckpoolPoolStatsFile - ); - let ckpoolUsersData = await fs.readFile( - ckpoolUsersStatsFile, - 'utf8' - ); - - ckpoolUsersData = JSON.parse(ckpoolUsersData); - - ckpoolData = { - pool: ckpoolPoolData, - users: ckpoolUsersData, - }; - })(), - ]); + try { + // Check if the directory exists + await fs.stat(ckpoolUsersStatsDir); + } catch (err) { + if (err.code === 'ENOENT') { + // Directory does not exist + resolve(ckpoolData); // Resolve with null data + return; + } + throw err; // Re-throw other errors } + + const filenames = await fs.readdir(ckpoolUsersStatsDir); + + const usersDataPromises = filenames.map(async (filename) => { + const ckpoolUsersStatsFile = path.resolve( + ckpoolUsersStatsDir, + filename + ); + const ckpoolUsersData = await fs.readFile( + ckpoolUsersStatsFile, + 'utf8' + ); + return JSON.parse(ckpoolUsersData); + }); + + const usersData = await Promise.all(usersDataPromises); + + ckpoolData = { + pool: await parseFileToJsonArray(ckpoolPoolStatsFile), + users: usersData, + }; } resolve(ckpoolData); diff --git a/src/utils.js b/src/utils.js index 46b4388..9cb48aa 100644 --- a/src/utils.js +++ b/src/utils.js @@ -64,6 +64,7 @@ module.exports.auth = { ); exec('sudo systemctl restart node'); + if (settings?.nodeEnableSoloMining) exec('sudo systemctl restart ckpool'); } catch (err) { console.log('ERR changeNodeRpcPassword', err); @@ -80,9 +81,46 @@ module.exports.auth = { }; }, + networkAddressWithCIDR(ipAddress, netmask) { + // Converti l'indirizzo IP e la netmask in forma binaria + const ipBinary = ipAddress + .split('.') + .map((part) => parseInt(part, 10).toString(2).padStart(8, '0')) + .join(''); + const netmaskBinary = netmask + .split('.') + .map((part) => parseInt(part, 10).toString(2).padStart(8, '0')) + .join(''); + + // Applica l'operazione bitwise AND + const networkBinary = ipBinary + .split('') + .map((bit, index) => bit & netmaskBinary[index]) + .join(''); + + // Converti il risultato in forma di stringa + const networkAddress = networkBinary + .match(/.{1,8}/g) + .map((byte) => parseInt(byte, 2)) + .join('.'); + + // Calcola il numero di bit della netmask + const cidrPrefix = netmask + .split('.') + .reduce( + (acc, byte) => + acc + (parseInt(byte, 10).toString(2).match(/1/g) || '').length, + 0 + ); + + return `${networkAddress}/${cidrPrefix}`; + }, + getSystemNetwork() { // Get network interface information const interfaces = os.networkInterfaces(); + let address = null; + let netmask = null; let network = null; // Check if wlan0 has an associated IP address @@ -91,17 +129,30 @@ module.exports.auth = { interfaces['wlan0'].some((info) => info.family === 'IPv4') ) { // If wlan0 has an associated IP address, use wlan0 - network = interfaces['wlan0'].find((info) => info.family === 'IPv4').cidr; + address = interfaces['wlan0'].find( + (info) => info.family === 'IPv4' + ).address; + netmask = interfaces['wlan0'].find( + (info) => info.family === 'IPv4' + ).netmask; } else if ( interfaces['eth0'] && interfaces['eth0'].some((info) => info.family === 'IPv4') ) { // If wlan0 doesn't have an associated IP address but eth0 does, use eth0 - network = interfaces['eth0'].find((info) => info.family === 'IPv4').cidr; + address = interfaces['eth0'].find( + (info) => info.family === 'IPv4' + ).address; + netmask = interfaces['eth0'].find( + (info) => info.family === 'IPv4' + ).netmask; } else { console.log('No IP address associated with wlan0 or eth0'); } + if (address && netmask) + network = this.networkAddressWithCIDR(address, netmask); + return network; }, @@ -182,8 +233,27 @@ module.exports.auth = { ); if (filteredUserConfVariables.length) { - // Join the remaining variables back into a single string - const filteredUserConf = filteredUserConfVariables.join('\n'); + // Initialize an empty array to store formatted user configurations + const formattedUserConf = []; + + // Iterate through filtered variables and format them + filteredUserConfVariables.forEach((variable) => { + // If the variable has a value, format it as "variable=value" + // Otherwise, format it as "variable" + const formattedVariable = settings.nodeUserConf.includes( + `${variable}=` + ) + ? `${variable}=${ + settings.nodeUserConf.match(new RegExp(`${variable}=(.*)`))[1] + }` + : variable; + + // Push the formatted variable to the array + formattedUserConf.push(formattedVariable); + }); + + // Join the formatted variables into a single string with newlines + const filteredUserConf = formattedUserConf.join('\n'); // Append the filtered user configuration to the overall configuration conf += `\n#USER_INPUT_START\n${filteredUserConf}\n#USER_INPUT_END`; From 9bc6a5ab84ec7f46a7f2f98952e1e60d8d4ed1e0 Mon Sep 17 00:00:00 2001 From: Michele Marcucci Date: Fri, 19 Apr 2024 09:09:21 +0200 Subject: [PATCH 12/21] Fix node conf --- src/store/api/settings/settingsUpdate.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/store/api/settings/settingsUpdate.js b/src/store/api/settings/settingsUpdate.js index cfdd989..5900da4 100644 --- a/src/store/api/settings/settingsUpdate.js +++ b/src/store/api/settings/settingsUpdate.js @@ -11,7 +11,10 @@ module.exports = ({ define }) => { if ( oldSettings.nodeEnableTor !== newSettings.nodeEnableTor || oldSettings.nodeUserConf !== newSettings.nodeUserConf || - oldSettings.nodeEnableSoloMining !== newSettings.nodeEnableSoloMining + oldSettings.nodeEnableSoloMining !== newSettings.nodeEnableSoloMining || + oldSettings.nodeRpcPassword !== newSettings.nodeRpcPassword || + oldSettings.nodeAllowLan !== newSettings.nodeAllowLan || + oldSettings.nodeMaxConnections !== newSettings.nodeMaxConnections ) await utils.auth.manageBitcoinConf(newSettings); From a34dfb5d0152f86a147966bbecb3ee6221ce6665 Mon Sep 17 00:00:00 2001 From: Michele Marcucci Date: Wed, 24 Apr 2024 07:59:10 +0200 Subject: [PATCH 13/21] Small fixes --- src/graphql/graphqlModules/Miner/MinerStats.js | 2 +- src/utils.js | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/graphql/graphqlModules/Miner/MinerStats.js b/src/graphql/graphqlModules/Miner/MinerStats.js index 26d924b..4773cd2 100644 --- a/src/graphql/graphqlModules/Miner/MinerStats.js +++ b/src/graphql/graphqlModules/Miner/MinerStats.js @@ -189,7 +189,7 @@ module.exports.typeDefs = ` } type MinerStatsCkpoolPool { - runtime: Int + runtime: Float lastupdate: Int Users: Int Workers: Int diff --git a/src/utils.js b/src/utils.js index 9cb48aa..afa2e4e 100644 --- a/src/utils.js +++ b/src/utils.js @@ -264,7 +264,8 @@ module.exports.auth = { await fsPromises.writeFile(configBitcoinFilePath, conf); - exec('sudo systemctl restart node'); + exec('sudo systemctl stop node'); + exec('sudo systemctl start node'); } catch (err) { console.log('ERR manageBitcoinConf', err); } From 585992fa9677df0b9595cad1ccef930ca7ab0b17 Mon Sep 17 00:00:00 2001 From: Michele Marcucci Date: Fri, 3 May 2024 09:10:27 +0200 Subject: [PATCH 14/21] =?UTF-8?q?Check=20conf=20doesn=E2=80=99t=20change.?= =?UTF-8?q?=20Fix=20bit32=20variable?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/graphql/graphqlModules/Miner/MinerStats.js | 6 +++--- src/store/store.js | 2 +- src/utils.js | 11 +++++++++-- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/graphql/graphqlModules/Miner/MinerStats.js b/src/graphql/graphqlModules/Miner/MinerStats.js index 4773cd2..194a72a 100644 --- a/src/graphql/graphqlModules/Miner/MinerStats.js +++ b/src/graphql/graphqlModules/Miner/MinerStats.js @@ -62,7 +62,7 @@ module.exports.typeDefs = ` byDiff: Float byPool: Float byJobs: Float - solutions: Int + solutions: Float errors: Int errorRate: Float chipSpeed: Float @@ -156,8 +156,8 @@ module.exports.typeDefs = ` lowCurrRst: Int currents: [Int] brokenPwc: Int - solutions: Int - errors: Int + solutions: Float + errors: Float ghs: Float errorRate: Float chipRestarts: Int diff --git a/src/store/store.js b/src/store/store.js index 54c4d8b..1fb9fa5 100644 --- a/src/store/store.js +++ b/src/store/store.js @@ -20,7 +20,7 @@ const store = loadStore({ return !['index.js', 'store.js'].includes(relativePath) && relativePath.match(/\.js$/) } }, - logger: logger, + logger: process.env.NODE_ENV !== 'development' && logger, methodContext: { knex, utils diff --git a/src/utils.js b/src/utils.js index afa2e4e..71a1ee1 100644 --- a/src/utils.js +++ b/src/utils.js @@ -183,6 +183,10 @@ module.exports.auth = { async manageBitcoinConf(settings) { try { + // CHecking current conf file + const currentConf = await fsPromises.readFile(configBitcoinFilePath, 'utf8'); + const currentConfBase64 = Buffer.from(currentConf).toString('base64'); + const defaultConf = `server=1\nrpcuser=futurebit\nrpcpassword=${settings.nodeRpcPassword}\ndaemon=0\nupnp=1\nuacomment=FutureBit-Apollo-Node`; let conf = defaultConf; @@ -260,12 +264,15 @@ module.exports.auth = { } } + const confBase64 = Buffer.from(conf).toString('base64'); + + if (currentConfBase64 === confBase64) return console.log('No changes to bitcoin.conf file'); + console.log('Writing Bitcoin conf file', conf); await fsPromises.writeFile(configBitcoinFilePath, conf); - exec('sudo systemctl stop node'); - exec('sudo systemctl start node'); + exec('sudo systemctl restart node'); } catch (err) { console.log('ERR manageBitcoinConf', err); } From ef17a5e0456d3167a2b4fc885cb71c3818575d5e Mon Sep 17 00:00:00 2001 From: Michele Marcucci Date: Fri, 3 May 2024 10:44:20 +0200 Subject: [PATCH 15/21] Better error handling --- src/store/api/mcu/mcuUpdateProgress.js | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/src/store/api/mcu/mcuUpdateProgress.js b/src/store/api/mcu/mcuUpdateProgress.js index 0de2cfc..208e191 100644 --- a/src/store/api/mcu/mcuUpdateProgress.js +++ b/src/store/api/mcu/mcuUpdateProgress.js @@ -1,15 +1,30 @@ -const { join } = require('path'); -const { exec } = require('child_process'); const fs = require('fs').promises; -const path = require('path'); -const _ = require('lodash'); module.exports = ({ define }) => { define( 'updateProgress', async (payload, { knex, errors, utils }) => { try { - const data = await fs.readFile(`/tmp/update_progress`); + // 1. Check if the file exists + const filePath = '/tmp/update_progress'; + let fileExists = true; + try { + await fs.access(filePath, fs.constants.F_OK); + } catch (error) { + if (error.code === 'ENOENT') { + // File doesn't exist + console.log('update_progress file not found. Returning default progress.'); + fileExists = false; + } else { + throw error; + } + } + + if (!fileExists) { + return { value: 0 }; + } + + const data = await fs.readFile(filePath); const progress = parseInt(data.toString()); return { value: progress }; } catch (error) { From 739b6b39da0e127edced1d465728987e4598b7a8 Mon Sep 17 00:00:00 2001 From: Michele Marcucci Date: Tue, 7 May 2024 07:27:08 +0200 Subject: [PATCH 16/21] Fix restart node --- src/utils.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/utils.js b/src/utils.js index 71a1ee1..06f0c21 100644 --- a/src/utils.js +++ b/src/utils.js @@ -272,7 +272,7 @@ module.exports.auth = { await fsPromises.writeFile(configBitcoinFilePath, conf); - exec('sudo systemctl restart node'); + exec('sleep 3 && sudo systemctl restart node'); } catch (err) { console.log('ERR manageBitcoinConf', err); } From f4c3a6862a128aad786c543cf1acac85792eb070 Mon Sep 17 00:00:00 2001 From: Michele Marcucci Date: Thu, 23 May 2024 08:19:11 +0200 Subject: [PATCH 17/21] Added comport stats for miner --- src/graphql/graphqlModules/Miner/MinerStats.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/graphql/graphqlModules/Miner/MinerStats.js b/src/graphql/graphqlModules/Miner/MinerStats.js index 194a72a..6c246c9 100644 --- a/src/graphql/graphqlModules/Miner/MinerStats.js +++ b/src/graphql/graphqlModules/Miner/MinerStats.js @@ -17,6 +17,7 @@ module.exports.typeDefs = ` uuid: String version: String date: String + comport: String statVersion: String versions: MinerStatsVersion master: MinerStatsMaster From 59068338cfe432200d345be3981fdd17b9c013fa Mon Sep 17 00:00:00 2001 From: Michele Marcucci Date: Fri, 24 May 2024 09:51:13 +0200 Subject: [PATCH 18/21] Better network devices discovery --- backend/os_stats | 45 +++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 41 insertions(+), 4 deletions(-) diff --git a/backend/os_stats b/backend/os_stats index 205958f..2267ddb 100755 --- a/backend/os_stats +++ b/backend/os_stats @@ -50,12 +50,47 @@ then MINER_FAN_SPEED=$(cat /var/local/apollo/hwmon/fan_rpm) fi -#Network +# Function to check if an interface is up or down +get_interface_status() { + local interface=$1 + ip link show "$interface" | grep -q "state UP" + if [ $? -eq 0 ]; then + echo "true" + else + echo "false" + fi +} + +# Retrieve IP, MAC and status of eth0 and wlan0 interfaces ETH_IP=$(ip addr show eth0 | awk '/inet / {print $2}' | cut -d/ -f 1) ETH_MAC=$(ip link show eth0 | awk '/ether/ {print $2}') +ETH_STATUS=$(get_interface_status eth0) + WLAN_IP=$(ip addr show wlan0 | awk '/inet / {print $2}' | cut -d/ -f 1) WLAN_MAC=$(ip link show wlan0 | awk '/ether/ {print $2}') - +WLAN_STATUS=$(get_interface_status wlan0) + +# Variable to track the first IP of wlx interfaces +FIRST_WLX_IP="" +FIRST_WLX_MAC="" +FIRST_WLX_STATUS="" + +# Retrieve IP, MAC and status of WiFi interfaces starting with wlx +for interface in $(ip -o link show | awk -F': ' '{print $2}' | grep ^wlx); do + WLX_IP=$(ip addr show "$interface" | awk '/inet / {print $2}' | cut -d/ -f 1) + WLX_MAC=$(ip link show "$interface" | awk '/ether/ {print $2}') + WLX_STATUS=$(get_interface_status "$interface") + + # If WLAN_IP is empty and FIRST_WLX_IP is not yet assigned, use WLX_IP + if [ -z "$WLAN_IP" ] && [ -z "$FIRST_WLX_IP" ] && [ -n "$WLX_IP" ]; then + FIRST_WLX_IP=$WLX_IP + FIRST_WLX_MAC=$WLX_MAC + FIRST_WLX_STATUS=$WLX_STATUS + WLAN_IP=$WLX_IP + WLAN_MAC=$WLX_MAC + WLAN_STATUS=$WLX_STATUS + fi +done # Memory memTotal=$(egrep '^MemTotal:' /proc/meminfo | awk '{print $2}') @@ -98,11 +133,13 @@ JSON="{ \"network\": [{ \"name\": \"eth0\", \"address\": \"$ETH_IP\", - \"mac\": \"$ETH_MAC\" + \"mac\": \"$ETH_MAC\", + \"status\": \"$ETH_STATUS\" }, { \"name\": \"wlan0\", \"address\": \"$WLAN_IP\", - \"mac\": \"$WLAN_MAC\" + \"mac\": \"$WLAN_MAC\", + \"status\": \"$WLAN_STATUS\" }], \"memory\": { From fce65a50d6fe0d17477e56d50b686103e0df841e Mon Sep 17 00:00:00 2001 From: Michele Marcucci Date: Mon, 27 May 2024 08:08:57 +0200 Subject: [PATCH 19/21] Solo conf in default one --- backend/default-configs/bitcoin.conf | 4 +++- src/utils.js | 3 +-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/backend/default-configs/bitcoin.conf b/backend/default-configs/bitcoin.conf index 81273e8..984698d 100644 --- a/backend/default-configs/bitcoin.conf +++ b/backend/default-configs/bitcoin.conf @@ -4,4 +4,6 @@ rpcpassword= daemon=0 upnp=1 uacomment=FutureBit-Apollo-Node -zmqpubhashblock=tcp://127.0.0.1:28332 \ No newline at end of file +#SOLO_START +zmqpubhashblock=tcp://127.0.0.1:28332 +#SOLO_END \ No newline at end of file diff --git a/src/utils.js b/src/utils.js index 06f0c21..0034071 100644 --- a/src/utils.js +++ b/src/utils.js @@ -189,12 +189,11 @@ module.exports.auth = { const defaultConf = `server=1\nrpcuser=futurebit\nrpcpassword=${settings.nodeRpcPassword}\ndaemon=0\nupnp=1\nuacomment=FutureBit-Apollo-Node`; let conf = defaultConf; + conf += `\n#SOLO_START\nzmqpubhashblock=tcp://127.0.0.1:28332\n#SOLO_END`; this.manageCkpoolConf(settings); if (settings.nodeEnableSoloMining) { - conf += `\n#SOLO_START\nzmqpubhashblock=tcp://127.0.0.1:28332\n#SOLO_END`; - exec( `sudo cp ${configCkpoolServiceFilePath} /etc/systemd/system/ckpool.service` ); From 5fd19098480433d2d377292db47f9b47369bde2b Mon Sep 17 00:00:00 2001 From: Michele Marcucci Date: Tue, 28 May 2024 07:38:50 +0200 Subject: [PATCH 20/21] Fix rpc conn from external LAN --- src/utils.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/utils.js b/src/utils.js index 0034071..f404309 100644 --- a/src/utils.js +++ b/src/utils.js @@ -220,7 +220,7 @@ module.exports.auth = { if (settings.nodeAllowLan) { const lanNetwork = this.getSystemNetwork(); - conf += `\nrpcallowip=${lanNetwork || '127.0.0.1'}`; + conf += `\nrpcbind=0.0.0.0\nrpcallowip=0.0.0.0/0`; } if (settings.nodeUserConf) { From 55f3209afcdbc3c1e731a40f865a5e6f61bebab5 Mon Sep 17 00:00:00 2001 From: jstefanop Date: Tue, 28 May 2024 13:13:01 -0400 Subject: [PATCH 21/21] Update package.json --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index debdb9e..8b4aef8 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "apolloapi-v2", - "version": "2.0.4", + "version": "2.0.5", "main": "index.js", "repository": "https://github.com/jstefanop/apolloapi-v2.git", "author": "FutureBit LLC",