summaryrefslogtreecommitdiffstats
path: root/server
diff options
context:
space:
mode:
authorUdo Walter2018-07-30 01:31:37 +0200
committerUdo Walter2018-07-30 01:31:37 +0200
commit8e70df54f1b3ca4be94d5d3633351aa7f4a38fa1 (patch)
tree6eb0d1cd91f5bc571b2fe8fd7841f92f47f1d99f /server
parent[server/router] changed api routing from query keyword to url parameter for g... (diff)
parent[webapp/backends] Reworked Dynamic fields to work with the new recursive stru... (diff)
downloadbas-8e70df54f1b3ca4be94d5d3633351aa7f4a38fa1.tar.gz
bas-8e70df54f1b3ca4be94d5d3633351aa7f4a38fa1.tar.xz
bas-8e70df54f1b3ca4be94d5d3633351aa7f4a38fa1.zip
merge
Diffstat (limited to 'server')
-rw-r--r--server/api/backends.js40
-rw-r--r--server/api/ipxe-loader.js18
-rw-r--r--server/lib/external-backends/backends/another-backend.js4
-rw-r--r--server/lib/external-backends/backends/dummy-backend.js4
-rw-r--r--server/lib/external-backends/backends/idoit-backend.js27
-rw-r--r--server/lib/external-backends/backends/template-backend.js14
-rw-r--r--server/lib/external-backends/external-backends.js8
-rw-r--r--server/router.js3
8 files changed, 94 insertions, 24 deletions
diff --git a/server/api/backends.js b/server/api/backends.js
index b744bd2..a5d1233 100644
--- a/server/api/backends.js
+++ b/server/api/backends.js
@@ -47,19 +47,21 @@ module.exports = {
})
},
- checkConnection: function (req, res) {
- var x = Math.floor(Math.random() * Math.floor(2))
- var y = ''
- if (x === 0) {
- y = 'success'
- } else {
- y = 'error'
- }
- var w = 'Oh noes! An error occurred.'
- var z = Math.floor(Math.random() * Math.floor(5000))
-
-
- setTimeout(function() { res.status(200).send({ status: y, msg: w }) }, 0)
+ checkConnectionById: function (req, res) {
+ const backendId = req.query.id
+ db.backend.findOne({ where: { id: backendId } }).then(backend => {
+ const bCredentials = {
+ backendId: backendId,
+ backendName: backend.name,
+ backendType: backend.type,
+ backendCredentials: backend.credentials
+ }
+ const b = new ExternalBackends()
+ const instance = b.getInstance(bCredentials.backendType)
+ instance.checkConnection().then(connection => {
+ res.status(200).send({ success: connection.success, msg: connection.msg })
+ })
+ })
},
// POST REQUESTS
@@ -86,5 +88,17 @@ module.exports = {
db.backend.destroy({ where: { id: backendIds } }).then(function () {
res.status(200).send('success')
})
+ },
+
+ checkConnection: function (req, res) {
+ const type = req.body.backendType
+ // const credentials = req.body.backendCredentials
+
+ const b = new ExternalBackends()
+ const instance = b.getInstance(type)
+ instance.checkConnection().then(connection => {
+ res.status(200).send({ success: connection.success, msg: connection.msg })
+ })
+ // TODO: Set credentials
}
}
diff --git a/server/api/ipxe-loader.js b/server/api/ipxe-loader.js
index e75ce72..c484578 100644
--- a/server/api/ipxe-loader.js
+++ b/server/api/ipxe-loader.js
@@ -22,18 +22,18 @@ exit 1
:pxelnx
# set 210:string https://bas.stfu-kthx.net:8888/
# chain \${210:string}pxelinux.0 || goto start
-#chain https://bas.stfu-kthx.net:8888/pxelinux.0
+# chain https://bas.stfu-kthx.net:8888/pxelinux.0
# set next-server bas-stfu-kthx.net:8888
# set 209:string https://bas.stfu-kthx.net:8888/pxelinux.cfg
-#imgload pxelinux.0
-#boot pxelinux.0
+# imgload pxelinux.0
+set net0/next-server 192.52.3.91 ||
+set netX/next-server 192.52.3.91 ||
+set next-server 192.52.3.91 ||
-set 209:string pxelinux.cfg/default
-set 210:string bas.stfu-kthx.net
-# chain tftp://bas.stfu-kthx.net/pxelinux.0 || goto start
-kernel tftp://bas.stfu-kthx.net/ldlinux.c32
-imgload tftp://bas.stfu-kthx.net/pxelinux.0
-boot
+# set 209:string pxelinux.cfg/default
+# set 210:string bas.stfu-kthx.net
+shell ||
+boot tftp://bas.stfu-kthx.net/pxelinux.0 || goto start
:sh
shell
diff --git a/server/lib/external-backends/backends/another-backend.js b/server/lib/external-backends/backends/another-backend.js
index eb329ae..90b8f8b 100644
--- a/server/lib/external-backends/backends/another-backend.js
+++ b/server/lib/external-backends/backends/another-backend.js
@@ -4,6 +4,10 @@ class AnotherBackend extends ExternalBackends {
getCredentials () {
return [{ type: 'text', id: 1, name: 'text 1' }, { type: 'text', id: 2, name: 'text 2' }, { type: 'password', id: 3, name: 'password 1', show: false }, { type: 'password', id: 4, name: 'password 2', show: true }, { type: 'password', id: 5, name: 'password 3', show: false }]
}
+
+ async checkConnection () {
+ return { success: true }
+ }
}
module.exports = AnotherBackend
diff --git a/server/lib/external-backends/backends/dummy-backend.js b/server/lib/external-backends/backends/dummy-backend.js
index 6052953..99d27c1 100644
--- a/server/lib/external-backends/backends/dummy-backend.js
+++ b/server/lib/external-backends/backends/dummy-backend.js
@@ -4,6 +4,10 @@ class DummyBackend extends ExternalBackends {
getCredentials () {
return [{ type: 'switch', id: 1, name: 'switch 1', value: false }, { type: 'switch', id: 2, name: 'switch 2', value: false }, { type: 'switch', id: 3, name: 'switch 3', value: true }, { type: 'select', id: 4, name: 'selection 1', items: ['wasd', 'asdf', 'qwertz'] }, { type: 'select', id: 5, name: 'selection 2', items: ['1', '2', '3'] }]
}
+
+ async checkConnection () {
+ return { success: false, msg: 'This is a test where success was intentionally set to false!' }
+ }
}
module.exports = DummyBackend
diff --git a/server/lib/external-backends/backends/idoit-backend.js b/server/lib/external-backends/backends/idoit-backend.js
new file mode 100644
index 0000000..2520b07
--- /dev/null
+++ b/server/lib/external-backends/backends/idoit-backend.js
@@ -0,0 +1,27 @@
+var ExternalBackends = require('../external-backends.js')
+
+class IdoitBackend extends ExternalBackends {
+ getCredentials () {
+ // I do it only needs the API-key.
+ return [
+ { type: 'text', id: 1, name: 'API url', icon: 'link' },
+ { type: 'password', id: 2, name: 'API token', icon: 'vpn_key', show: false },
+ { type: 'switch',
+ id: 3,
+ name: 'Login',
+ icon: 'lock_open',
+ elements: [
+ { type: 'text', id: 4, name: 'username', icon: 'person_outline' },
+ { type: 'password', id: 5, name: 'password', icon: 'lock', show: false }
+ ]
+ }
+ ]
+ }
+
+ async checkConnection () {
+ // Make a simple login and check if the connection works.
+ return { success: false, msg: 'TODO: IMPLEMENT' }
+ }
+}
+
+module.exports = IdoitBackend
diff --git a/server/lib/external-backends/backends/template-backend.js b/server/lib/external-backends/backends/template-backend.js
index 19f1d76..ceab46a 100644
--- a/server/lib/external-backends/backends/template-backend.js
+++ b/server/lib/external-backends/backends/template-backend.js
@@ -4,6 +4,20 @@ class TemplateBackend extends ExternalBackends {
getCredentials () {
return [{ type: 'text', id: 1, name: 'text test', icon: 'bug_report' }, { type: 'password', id: 2, name: 'password test', show: true }, { type: 'password', id: 3, name: 'password test nr2', show: false }, { type: 'switch', id: 4, name: 'bool test', value: false }, { type: 'select', id: 5, name: 'selection test', items: ['wasd', 'asdf', 'qwertz'] }]
}
+
+ async checkConnection () {
+ var result = await x()
+ console.log(result)
+ return result
+ }
+}
+
+function x () {
+ return new Promise(resolve => {
+ setTimeout(() => {
+ resolve({ success: true })
+ }, 5000)
+ })
}
module.exports = TemplateBackend
diff --git a/server/lib/external-backends/external-backends.js b/server/lib/external-backends/external-backends.js
index 0bf891e..a1264a0 100644
--- a/server/lib/external-backends/external-backends.js
+++ b/server/lib/external-backends/external-backends.js
@@ -9,7 +9,8 @@ class ExternalBackends {
}
getCredentials () {
- return 'If this method gets called the backend class has NOT IMPLEMENTED the getCredentials method!'
+ console.log('If this method gets called the backend class has NOT IMPLEMENTED the getCredentials method!')
+ return null
}
getInstance (type) {
@@ -25,6 +26,11 @@ class ExternalBackends {
const backend = new (require(path.join(__appdir, 'lib', 'external-backends', 'backends', bType)))()
return backend
}
+
+ async checkConnection () {
+ console.log('If this method gets called the backend class has NOT IMPLEMENTED the checkConnection method!')
+ return null
+ }
}
module.exports = ExternalBackends
diff --git a/server/router.js b/server/router.js
index 6c0e4cd..9e29f93 100644
--- a/server/router.js
+++ b/server/router.js
@@ -53,9 +53,10 @@ router.get('/backends/getCredentialsByType', auth.verifyToken, backends.getCrede
router.get('/backends/getBackendInfoById', auth.verifyToken, backends.getBackendInfoById)
router.get('/backends/getBackendList', auth.verifyToken, backends.getBackendList)
router.get('/backends/getBackendTypes', backends.getBackendTypes)
-router.get('/backends/checkConnection', auth.verifyToken, backends.checkConnection)
+router.get('/backends/checkConnection', auth.verifyToken, backends.checkConnectionById)
router.post('/backends/saveBackend', auth.verifyToken, backends.saveBackend)
router.post('/backends/deleteBackends', auth.verifyToken, backends.deleteBackends)
+router.post('/backends/checkConnection', auth.verifyToken, backends.checkConnection)
// Load ipxe scipts API
var ipxeloader = require(path.join(__dirname, 'api', 'ipxe-loader'))