summaryrefslogtreecommitdiffstats
path: root/server/api/registration.js
diff options
context:
space:
mode:
authorChristian Hofmaier2018-08-19 19:58:58 +0200
committerChristian Hofmaier2018-08-19 19:58:58 +0200
commit1ea7756dee94628cceb2d60af27df4dc62dc5cfd (patch)
tree2640591f8eb980751f8bea9b93dc4fa0016c7a42 /server/api/registration.js
parentAdd Snackbars to Events (diff)
parent[firstregistration] First start of the new client registration (diff)
downloadbas-1ea7756dee94628cceb2d60af27df4dc62dc5cfd.tar.gz
bas-1ea7756dee94628cceb2d60af27df4dc62dc5cfd.tar.xz
bas-1ea7756dee94628cceb2d60af27df4dc62dc5cfd.zip
merge
Diffstat (limited to 'server/api/registration.js')
-rw-r--r--server/api/registration.js86
1 files changed, 86 insertions, 0 deletions
diff --git a/server/api/registration.js b/server/api/registration.js
new file mode 100644
index 0000000..c87431c
--- /dev/null
+++ b/server/api/registration.js
@@ -0,0 +1,86 @@
+/* global __appdir */
+var path = require('path')
+const Infoblox = require('infoblox')
+var express = require('express')
+var router = express.Router()
+var noAuthRouter = express.Router()
+var db = require(path.join(__appdir, 'lib', 'sequelize'))
+
+// GET requests.
+
+/*
+ * @return:
+ */
+router.get('/', (req, res) => {
+ var ipam = new Infoblox({
+ ip: 'dhcp.uni-freiburg.de',
+ apiVersion: '1.7.1'
+ })
+ ipam.login('js1456', 'Test12345!').then(function (r) {
+ if (r) {
+ ipam.getIpsFromSubnet('10.21.9.0/24').then(function (response) {
+ console.log(response)
+ res.send(response)
+ })
+ }
+ // res.status(200).send({ status: 'work in progress ...' })
+ })
+})
+
+module.exports.router = router
+
+// GET requests.
+
+// POST requests.
+
+/*
+ *
+ * @return:
+ */
+noAuthRouter.post('/client', (req, res) => {
+ const mac = req.body.mac
+ const uuid = req.body.uuid
+ const ip = req.body.ip
+ const name = req.body.name
+ console.log(name.concat(' ', ip, ' ', mac, ' ', uuid))
+
+ var script = '#!ipxe\r\n'
+ db.group.findAll({ where: { '$parents.id$': null }, include: ['parents'] }).then(groups => {
+ groups.forEach(g => {
+ script = script.concat('echo', ' [', g.id, '] ', g.name, '\r\n')
+ })
+
+ script = script.concat('read group\r\n')
+ script = script.concat('params\r\n')
+ /*eslint-disable */
+ script = script.concat('param id ${group}\r\n')
+ /* eslint-enable */
+ script = script.concat('chain https://bas.stfu-kthx.net:8888/api/registration/group##params\r\n')
+ res.status(200).send(script)
+ })
+})
+
+noAuthRouter.post('/group', (req, res) => {
+ const id = req.body.id
+
+ var script = '#!ipxe\r\n'
+ db.group.findOne({ where: { id: id }, include: ['parents', 'subgroups', 'clients'] }).then(group => {
+ if (group) {
+ group.subgroups.forEach(subgroup => {
+ script = script.concat('echo', ' [', subgroup.id, '] ', subgroup.name, '\r\n')
+ })
+
+ script = script.concat('read group\r\n')
+ script = script.concat('params\r\n')
+ /*eslint-disable */
+ script = script.concat('param id ${group}\r\n')
+ /* eslint-enable */
+ script = script.concat('chain https://bas.stfu-kthx.net:8888/api/registration/group##params\r\n')
+ res.send(script)
+ } else {
+ res.status(404).end()
+ }
+ })
+})
+
+module.exports.noAuthRouter = noAuthRouter