diff --git a/lib/notifier/codes.js b/lib/notifier/codes.js index a278ecee..10a68be4 100644 --- a/lib/notifier/codes.js +++ b/lib/notifier/codes.js @@ -6,6 +6,7 @@ const LOW_CRYPTO_BALANCE = 'LOW_CRYPTO_BALANCE' const HIGH_CRYPTO_BALANCE = 'HIGH_CRYPTO_BALANCE' const CASH_BOX_FULL = 'CASH_BOX_FULL' const LOW_CASH_OUT = 'LOW_CASH_OUT' +const SECURITY = 'SECURITY' const CODES_DISPLAY = { PING: 'Machine Down', @@ -13,7 +14,8 @@ const CODES_DISPLAY = { LOW_CRYPTO_BALANCE: 'Low Crypto Balance', HIGH_CRYPTO_BALANCE: 'High Crypto Balance', CASH_BOX_FULL: 'Cash box full', - LOW_CASH_OUT: 'Low Cash-out' + LOW_CASH_OUT: 'Low Cash-out', + CASHBOX_REMOVED: 'Cashbox removed' } const NETWORK_DOWN_TIME = 1 * T.minute @@ -26,7 +28,8 @@ const NOTIFICATION_TYPES = { FIAT_BALANCE: 'fiatBalance', CRYPTO_BALANCE: 'cryptoBalance', COMPLIANCE: 'compliance', - ERROR: 'error' + ERROR: 'error', + SECURITY: 'security' } module.exports = { @@ -36,6 +39,7 @@ module.exports = { HIGH_CRYPTO_BALANCE, CASH_BOX_FULL, LOW_CASH_OUT, + SECURITY, CODES_DISPLAY, NETWORK_DOWN_TIME, STALE_STATE, diff --git a/lib/notifier/email.js b/lib/notifier/email.js index 289180c0..5ad4b774 100644 --- a/lib/notifier/email.js +++ b/lib/notifier/email.js @@ -9,7 +9,8 @@ const { LOW_CRYPTO_BALANCE, HIGH_CRYPTO_BALANCE, CASH_BOX_FULL, - LOW_CASH_OUT + LOW_CASH_OUT, + SECURITY } = require('./codes') function alertSubject (alertRec, config) { @@ -79,6 +80,8 @@ function emailAlert (alert) { return `Cash box full on ${alert.machineName} [${alert.notes} banknotes]` case LOW_CASH_OUT: return `Cassette for ${alert.denomination} ${alert.fiatCode} low [${alert.notes} banknotes]` + case SECURITY: + return `Cashbox removed on ${alert.machineName}` } } diff --git a/lib/notifier/index.js b/lib/notifier/index.js index d2c33203..e44ec1a6 100644 --- a/lib/notifier/index.js +++ b/lib/notifier/index.js @@ -246,6 +246,41 @@ function sendTransactionMessage (rec, isHighValueTx) { }) } +function cashboxNotify (deviceId) { + return Promise.all([ + settingsLoader.loadLatest(), + queries.getMachineName(deviceId) + ]) + .then(([settings, machineName]) => { + const notifications = configManager.getGlobalNotifications(settings.config) + const rec = { + sms: { + body: `Cashbox removed - ${machineName}` + }, + email: { + subject: `Cashbox removal`, + body: `Cashbox removed in machine ${machineName}` + } + } + + const promises = [] + + const emailActive = + notifications.email.active && + notifications.email.security + + const smsActive = + notifications.sms.active && + notifications.sms.security + + if (emailActive) promises.push(emailFuncs.sendMessage(settings, rec)) + if (smsActive) promises.push(smsFuncs.sendMessage(settings, rec)) + notifyIfActive('security', 'cashboxNotify', deviceId) + + return Promise.all(promises) + }) +} + // for notification center, check if type of notification is active before calling the respective notify function const notifyIfActive = (type, fnName, ...args) => { return settingsLoader.loadLatest().then(settings => { @@ -263,5 +298,6 @@ module.exports = { checkPings, checkStuckScreen, sendRedemptionMessage, + cashboxNotify, notifyIfActive } diff --git a/lib/notifier/notificationCenter.js b/lib/notifier/notificationCenter.js index b16bdff0..725342ea 100644 --- a/lib/notifier/notificationCenter.js +++ b/lib/notifier/notificationCenter.js @@ -6,6 +6,7 @@ const codes = require('./codes') const customers = require('../customers') const { NOTIFICATION_TYPES: { + SECURITY, COMPLIANCE, CRYPTO_BALANCE, FIAT_BALANCE, @@ -177,11 +178,18 @@ const blacklistNotify = (tx, isAddressReuse) => { return queries.addNotification(COMPLIANCE, message, detailB) } +const cashboxNotify = deviceId => { + const detailB = utils.buildDetail({ deviceId: deviceId }) + const message = `Cashbox removed` + return queries.addNotification(SECURITY, message, detailB) +} + module.exports = { sanctionsNotify, customerComplianceNotify, balancesNotify, errorAlertsNotify, notifCenterTransactionNotify, - blacklistNotify + blacklistNotify, + cashboxNotify } diff --git a/migrations/1621430588944-notify-cashbox-removal.js b/migrations/1621430588944-notify-cashbox-removal.js new file mode 100644 index 00000000..3be125b0 --- /dev/null +++ b/migrations/1621430588944-notify-cashbox-removal.js @@ -0,0 +1,35 @@ +const db = require('./db') +const { saveConfig, loadLatest } = require('../lib/new-settings-loader') + +exports.up = function (next) { + const sql = [ + `ALTER TYPE notification_type ADD VALUE 'security'` + ] + + return loadLatest() + .then(config => { + const newConfig = {} + if(config.notifications_email_active) { + newConfig.notifications_email_security = true + } + if(config.notifications_sms_active) { + newConfig.notifications_sms_security = true + } + if(config.notifications_notificationCenter_active) { + newConfig.notifications_notificationCenter_security = true + } + + return saveConfig(newConfig) + .then(() => db.multi(sql, next)) + .catch(err => { + if (err.message === 'lamassu-server is not configured') { + return next() + } + return next(err) + }) + }) +} + +module.exports.down = function (next) { + next() +} diff --git a/new-lamassu-admin/src/pages/Notifications/sections/Setup.js b/new-lamassu-admin/src/pages/Notifications/sections/Setup.js index 3ae0fbeb..0ccaed8b 100644 --- a/new-lamassu-admin/src/pages/Notifications/sections/Setup.js +++ b/new-lamassu-admin/src/pages/Notifications/sections/Setup.js @@ -22,6 +22,7 @@ const sizes = { transactions: 184, compliance: 178, errors: 142, + security: 152, active: 263 } @@ -57,6 +58,7 @@ const Row = ({ namespace, forceDisable }) => { + )