summaryrefslogtreecommitdiffstats
path: root/server/lib/external-backends/backendhelper.js
diff options
context:
space:
mode:
Diffstat (limited to 'server/lib/external-backends/backendhelper.js')
-rw-r--r--server/lib/external-backends/backendhelper.js28
1 files changed, 27 insertions, 1 deletions
diff --git a/server/lib/external-backends/backendhelper.js b/server/lib/external-backends/backendhelper.js
index d8d4b24..b7a8a9b 100644
--- a/server/lib/external-backends/backendhelper.js
+++ b/server/lib/external-backends/backendhelper.js
@@ -4,7 +4,7 @@ const ExternalBackends = require(path.join(__appdir, 'lib', 'external-backends')
const db = require(path.join(__appdir, 'lib', 'sequelize'))
const log = require(path.join(__appdir, 'lib', 'log'))
-module.exports = { addClient, updateClient, deleteClients, uploadFiles }
+module.exports = { addClient, getDhcp, updateClient, deleteClients, uploadFiles }
async function addClient (client) {
// Get all backends and call addClient for each instance.
@@ -123,3 +123,29 @@ async function uploadFiles (clientId, files) {
}
return results
}
+
+async function getDhcp () {
+ const backends = await db.backend.findAll()
+
+ let dhcp = false
+ for (let b in backends) {
+ const backend = backends[b]
+ const ba = new ExternalBackends()
+ const instance = ba.getInstance(backend.type)
+
+ const isDHCP = await instance.isDhcp(backend.credentials)
+ if (isDHCP) {
+ if (!dhcp) dhcp = { instance: instance, backend: backend }
+ else {
+ // Conflict occured!
+ const conflict = await db.conflict.create({ description: 'Multiple dhcp backends found' })
+
+ // Add both backends to the conflict.
+ conflict.createObject({ objectType: 'BACKEND', objectId: backend.id })
+ conflict.createObject({ objectType: 'BACKEND', objectId: dhcp.backend.id })
+ return false
+ }
+ }
+ }
+ return dhcp
+}