summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--server/api/ipxe.js5
-rw-r--r--server/api/registration.js117
-rw-r--r--server/app.js1
-rw-r--r--server/config/config.template.json8
-rw-r--r--server/ipxe/exitTestScript.ipxe14
-rw-r--r--server/ipxe/registration.ipxe12
-rw-r--r--server/lib/tftp.js50
-rw-r--r--server/package-lock.json27
-rw-r--r--server/package.json3
9 files changed, 104 insertions, 133 deletions
diff --git a/server/api/ipxe.js b/server/api/ipxe.js
index bed61a1..285a426 100644
--- a/server/api/ipxe.js
+++ b/server/api/ipxe.js
@@ -27,10 +27,7 @@ noAuthRouter.get('/load/script', (req, res) => {
noAuthRouter.get('/load/registration', (req, res) => {
res.setHeader('content-type', 'text/plain')
- fs.readFile(path.join(__appdir, 'ipxe', 'registration.ipxe'), 'utf-8', function (err, content) {
- if (err) res.end()
- res.send(content)
- })
+ res.sendFile(path.join(__appdir, 'ipxe', 'registration.ipxe'))
})
module.exports.noAuthRouter = noAuthRouter
diff --git a/server/api/registration.js b/server/api/registration.js
index c87431c..a5c1b6f 100644
--- a/server/api/registration.js
+++ b/server/api/registration.js
@@ -5,6 +5,7 @@ var express = require('express')
var router = express.Router()
var noAuthRouter = express.Router()
var db = require(path.join(__appdir, 'lib', 'sequelize'))
+var dhcp = require(path.join(__appdir, 'config', 'config')).dhcp
// GET requests.
@@ -16,10 +17,33 @@ router.get('/', (req, res) => {
ip: 'dhcp.uni-freiburg.de',
apiVersion: '1.7.1'
})
- ipam.login('js1456', 'Test12345!').then(function (r) {
+ ipam.login(dhcp.user, dhcp.password).then(function (r) {
if (r) {
- ipam.getIpsFromSubnet('10.21.9.0/24').then(function (response) {
- console.log(response)
+ // Get the network from the ip.
+ // ipam.getHost('10.21.9.78').then(function (response) {
+ ipam.getNetworkFromIp('10.21.9.78').then(function (response) {
+ // ipam.getIpsFromSubnet('10.21.9.0/24').then(function (response) {
+ // ipam.list('record:host').then(function (response) {
+ // ipam.getDomain().then(function (response) {
+ response = JSON.parse(response)
+ // ipam.getNext(response[0]._ref, 1).then(r => {
+ res.send(response)
+ // })
+ // res.send(JSON.parse(response))
+ })
+ }
+ // res.status(200).send({ status: 'work in progress ...' })
+ })
+})
+
+router.get('/setdhcptest', (req, res) => {
+ var ipam = new Infoblox({
+ ip: 'dhcp.uni-freiburg.de',
+ apiVersion: '1.7.1'
+ })
+ ipam.login('js603', 'Iwjp!DFhk4').then(function (r) {
+ if (r) {
+ ipam.create('record:host?_return_fields%2B=na13me,ipv4addrs&_return_as_object=1', {'name': 'wapiTest.lp.privat', 'ipv4addrs': [{'ipv4addr': '10.21.9.141', 'mac': 'aa:bb:cc:11:22:21'}]}).then(function (response) {
res.send(response)
})
}
@@ -38,13 +62,14 @@ module.exports.router = router
* @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))
+ // 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'
+ script.concat(`console --picture \${img} --x 800 --y 600 || shell\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')
@@ -52,9 +77,7 @@ noAuthRouter.post('/client', (req, res) => {
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(`param id \${group}\r\n`)
script = script.concat('chain https://bas.stfu-kthx.net:8888/api/registration/group##params\r\n')
res.status(200).send(script)
})
@@ -62,25 +85,63 @@ noAuthRouter.post('/client', (req, res) => {
noAuthRouter.post('/group', (req, res) => {
const id = req.body.id
+ console.log(id)
+ if (id === '0') {
+ db.group.findAll({ where: { '$parents.id$': null }, include: ['parents'] }).then(groups => {
+ if (groups) {
+ res.send(buildIpxeMenu(id, 'Root', groups))
+ } else {
+ res.status(404).end()
+ }
+ })
+ } else {
+ db.group.findOne({ where: { id: id }, include: ['parents', 'subgroups', 'clients'] }).then(group => {
+ if (group) {
+ res.send(buildIpxeMenu(id, group.name, group.subgroups))
+ } else {
+ res.status(404).end()
+ }
+ })
+ }
+})
- 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()
- }
+noAuthRouter.post('/add', (req, res) => {
+ const mac = req.body.mac
+ const uuid = req.body.uuid
+ const ip = req.body.ip
+ const name = req.body.name
+ const parentId = req.body.id
+ db.client.create({ name: name, ip: ip, mac: mac, uuid: uuid }).then(client => {
+ client.addGroup(parentId)
+ res.send('#ipxe\r\nshell')
})
+ console.log(name.concat(' ', ip, ' ', mac, ' ', uuid))
})
module.exports.noAuthRouter = noAuthRouter
+
+function buildIpxeMenu (id, name, groups) {
+ var script = '#!ipxe\r\n'
+ script.concat(`console --picture \${img} --x 800 --y 600 || shell\r\n`)
+ var menuscript = ''
+ script = script.concat(':start\r\n')
+ script = script.concat('menu Choose the group you want the client to be saved in\r\n')
+ var counter = '1'
+ groups.forEach(group => {
+ // script = script.concat('echo', ' [', subgroup.id, '] ', subgroup.name, '\r\n')
+ script = script.concat('item --key ', counter, ' ', counter, ' [', group.id, '] ', group.name, '\r\n')
+ menuscript = menuscript.concat(':', counter, '\r\n', 'params\r\nparam id ', group.id, '\r\nchain https://bas.stfu-kthx.net:8888/api/registration/group##params\r\n\r\n')
+ counter++
+ })
+ script = script.concat('item select Add client to ', name, '\r\n')
+ menuscript = menuscript.concat(`:select\r\necho Enter client name\r\nread clientname\r\nparams\r\nparam name \${clientname}\r\n`)
+ menuscript = menuscript.concat('param id ', id, `\r\nparam mac \${net0/mac}\r\nparam uuid \${uuid}\r\nparam ip \${net0/ip}\r\n`)
+ menuscript = menuscript.concat('chain https://bas.stfu-kthx.net:8888/api/registration/add##params\r\n\r\n')
+ if (id !== '0') {
+ script = script.concat('item reset Go to start\r\n')
+ menuscript = menuscript.concat(':reset\r\nparams\r\nparam id ', 0, '\r\nchain --replace https://bas.stfu-kthx.net:8888/api/registration/group##params\r\n\r\n')
+ }
+ script = script.concat(`choose target && goto \${target}\r\n\r\n`)
+ script = script.concat(menuscript)
+ return script
+}
diff --git a/server/app.js b/server/app.js
index f9b0845..bc4a58b 100644
--- a/server/app.js
+++ b/server/app.js
@@ -10,7 +10,6 @@ var app = express()
global.__appdir = __dirname
-require('./lib/tftp')
// Read permissions from JSON and update the database
require('./lib/permissions/index.js')
diff --git a/server/config/config.template.json b/server/config/config.template.json
index 901454c..6ad7ad5 100644
--- a/server/config/config.template.json
+++ b/server/config/config.template.json
@@ -1,10 +1,8 @@
{
"https": {
"port": "<HTTPS_PORT>"
- },
- "tftp": {
- "host": "<TFTP_HOST>",
- "port": "<TFTP_PORT>",
- "root": "<TFTP_ROOTPATH>"
+ }, "dhcp": {
+ "user": "<DHCP_USER>",
+ "password": "<DHCP_PASSWORD>"
}
}
diff --git a/server/ipxe/exitTestScript.ipxe b/server/ipxe/exitTestScript.ipxe
index 7bf1df6..51ca1bc 100644
--- a/server/ipxe/exitTestScript.ipxe
+++ b/server/ipxe/exitTestScript.ipxe
@@ -36,9 +36,9 @@ goto start
# set next-server bas-stfu-kthx.net:8888
# set 209:string https://bas.stfu-kthx.net:8888/pxelinux.cfg
# 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 net0/next-server 10.8.102.124 ||
+set netX/next-server 10.8.102.124 ||
+set next-server 10.8.102.124 ||
# set 209:string pxelinux.cfg/default
# set 210:string bas.stfu-kthx.net
# shell ||
@@ -46,10 +46,10 @@ boot tftp://bas.stfu-kthx.net/pxelinux.0 ||
goto start
:c32boot
-set net0/next-server 192.52.3.91 ||
-set netX/next-server 192.52.3.91 ||
-set next-server 192.52.3.91 ||
-boot tftp://bas.stfu-kthx.net/chain.c32 ||
+set net0/next-server 10.8.102.124 ||
+set netX/next-server 10.8.102.124 ||
+set next-server 10.8.102.124 ||
+boot tftp://10.8.102.124/chain.c32 ||
goto start
:sh
diff --git a/server/ipxe/registration.ipxe b/server/ipxe/registration.ipxe
index 88dc58f..51d89f2 100644
--- a/server/ipxe/registration.ipxe
+++ b/server/ipxe/registration.ipxe
@@ -5,7 +5,7 @@ dhcp
set crosscert http://ca.ipxe.org/auto/
#set img https://ife-server.com/b4db0y/ipxeWallpaper4.png || shell
#set img tftp://bas.stfu-kthx.net/ipxeWallpaper4.png || shell
-set img tftp://bas.stfu-kthx.net/ipxeWallpaper3_scale.png || shell
+set img tftp://10.8.102.124/ipxeWallpaper3_scale.png || shell
console --picture ${img} --x 800 --y 600 || shell
:start
@@ -23,15 +23,9 @@ exit1 ||
goto start
:init
-echo Enter PC name
-read pcname
params
-param mac ${net0/mac}
-param uuid ${uuid}
-param ip ${net0/ip}
-param name ${pcname}
-chain https://bas.stfu-kthx.net:8888/api/registration/client##params ||
-shell
+param id 0
+chain https://bas.stfu-kthx.net:8888/api/registration/group##params ||
goto start
:reboot
diff --git a/server/lib/tftp.js b/server/lib/tftp.js
deleted file mode 100644
index 104f984..0000000
--- a/server/lib/tftp.js
+++ /dev/null
@@ -1,50 +0,0 @@
-'use strict'
-
-/* global __appdir */
-var path = require('path')
-var config = require(path.join(__appdir, 'config', 'config')).tftp
-
-var envPort = process.env.PORT
-envPort++
-
-var port = normalizePort(config.port || envPort || '69')
-var host = config.host
-var root = config.root
-
-var tftp = require('tftp')
-var server = tftp.createServer({
- host: host,
- port: port,
- root: root,
- denyPut: true
-})
-
-server.on('error', function (error) {
- // Errors from the main socket
- console.error(error)
-})
-
-server.on('request', function (req) {
- req.on('error', function (error) {
- // Error from the request
- console.error(error)
- })
-})
-
-server.listen()
-
-function normalizePort (val) {
- var port = parseInt(val, 10)
-
- if (isNaN(port)) {
- // named pipe
- return val
- }
-
- if (port >= 0) {
- // port number
- return port
- }
-
- return false
-}
diff --git a/server/package-lock.json b/server/package-lock.json
index a7fdb87..5acb554 100644
--- a/server/package-lock.json
+++ b/server/package-lock.json
@@ -84,11 +84,6 @@
"resolved": "https://registry.npmjs.org/ansicolors/-/ansicolors-0.2.1.tgz",
"integrity": "sha1-vgiVmQl7dKXJxKhKDNvNtivYeu8="
},
- "argp": {
- "version": "1.0.4",
- "resolved": "https://registry.npmjs.org/argp/-/argp-1.0.4.tgz",
- "integrity": "sha1-sxxzB1rW1syx2MhqzWn/MAMFsZQ="
- },
"argparse": {
"version": "1.0.10",
"resolved": "https://registry.npmjs.org/argparse/-/argparse-1.0.10.tgz",
@@ -2389,11 +2384,6 @@
"resolved": "https://registry.npmjs.org/progress/-/progress-2.0.0.tgz",
"integrity": "sha1-ihvjZr+Pwj2yvSPxDG/pILQ4nR8="
},
- "progress-bar-formatter": {
- "version": "2.0.1",
- "resolved": "https://registry.npmjs.org/progress-bar-formatter/-/progress-bar-formatter-2.0.1.tgz",
- "integrity": "sha1-DZfrsWRn4sIwg3NXIXa3w1UeVW4="
- },
"prop-types": {
"version": "15.6.2",
"resolved": "https://registry.npmjs.org/prop-types/-/prop-types-15.6.2.tgz",
@@ -2988,14 +2978,6 @@
}
}
},
- "status-bar": {
- "version": "2.0.3",
- "resolved": "https://registry.npmjs.org/status-bar/-/status-bar-2.0.3.tgz",
- "integrity": "sha1-DSaAIixFfhLeN86+FDjdScTgbhQ=",
- "requires": {
- "progress-bar-formatter": "^2.0.1"
- }
- },
"statuses": {
"version": "1.4.0",
"resolved": "https://registry.npmjs.org/statuses/-/statuses-1.4.0.tgz",
@@ -3101,15 +3083,6 @@
"resolved": "https://registry.npmjs.org/text-table/-/text-table-0.2.0.tgz",
"integrity": "sha1-f17oI66AUgfACvLfSoTsP8+lcLQ="
},
- "tftp": {
- "version": "0.1.2",
- "resolved": "https://registry.npmjs.org/tftp/-/tftp-0.1.2.tgz",
- "integrity": "sha1-lWdMCn/Ku1N1Wr7wutP55U/gt7U=",
- "requires": {
- "argp": "1.0.x",
- "status-bar": "2.0.x"
- }
- },
"through": {
"version": "2.3.8",
"resolved": "https://registry.npmjs.org/through/-/through-2.3.8.tgz",
diff --git a/server/package.json b/server/package.json
index f7b967d..037e19f 100644
--- a/server/package.json
+++ b/server/package.json
@@ -23,8 +23,7 @@
"sequelize": "^4.37.7",
"sequelize-cli": "^4.0.0",
"shelljs": "^0.8.2",
- "standard": "^11.0.1",
- "tftp": "^0.1.2"
+ "standard": "^11.0.1"
},
"devDependencies": {
"eslint-config-standard": "^11.0.0",