summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--server/api/configloader.js9
-rw-r--r--server/api/registrations.js56
-rw-r--r--server/ipxe/grepSystemInfo.sh75
-rw-r--r--server/ipxe/minilinux.ipxe6
4 files changed, 127 insertions, 19 deletions
diff --git a/server/api/configloader.js b/server/api/configloader.js
index 4a6f58e..dab2bd8 100644
--- a/server/api/configloader.js
+++ b/server/api/configloader.js
@@ -11,6 +11,15 @@ noAuthRouter.get('/:uuid', (req, res) => {
db.client.findOne({ where: { uuid: uuid }, include: ['groups'] }).then(client => {
if (client !== null) {
+ // Check for registration hooks.
+ if (client.registrationState !== null) {
+ db.registrationhook.findOne({ where: { id: client.registrationState } }).then(hook => {
+ if (hook.type === 'IPXE') res.send(hook.script)
+ else if (hook.type === 'BASH') res.sendFile(path.join(__appdir, 'ipxe', 'minilinux.ipxe'))
+ })
+ return
+ }
+
// client is in db
if (client.configId !== null) {
// client has a config
diff --git a/server/api/registrations.js b/server/api/registrations.js
index 3c5c8d8..492118e 100644
--- a/server/api/registrations.js
+++ b/server/api/registrations.js
@@ -67,12 +67,17 @@ noAuthRouter.post('/add', (req, res) => {
db.client.findOne({ where: { uuid: uuid } }).then(client => {
if (client) res.status(200).send('#!ipxe\r\necho Client already exists\r\necho Press any key to continue ...\r\nread x\r\nreboot')
else {
- db.client.create({ name: name, ip: ip, mac: mac, uuid: uuid }).then(client => {
- if (parentId) {
- client.addGroup(parentId)
- }
- res.send('#!ipxe\r\nreboot')
+ var groupids = []
+ if (parentId) groupids = [parentId]
+ getNextHookScript(groupids, 0).then(resId => {
+ db.client.create({ name: name, ip: ip, mac: mac, uuid: uuid, registrationState: resId }).then(client => {
+ if (parentId) {
+ client.addGroup(parentId)
+ }
+ res.send('#!ipxe\r\nreboot')
+ })
})
+
}
})
})
@@ -80,10 +85,9 @@ noAuthRouter.post('/add', (req, res) => {
/*
* Open api method for setting the registration state of a given uuid.
*/
-noAuthRouter.post('/:uuid/state', (req, res) => {
+noAuthRouter.post('/:uuid/success', (req, res) => {
const uuid = req.params.uuid
- const state = parseInt(req.body.state)
-
+ const id = parseInt(req.body.id)
db.client.findOne({ where: { uuid: uuid }, include: ['groups'] }).then(client => {
// Client not found handling
if (client === null) {
@@ -91,8 +95,8 @@ noAuthRouter.post('/:uuid/state', (req, res) => {
return
}
- // Check if the finished script id (state) matches the current state of the client.
- if (client.registrationState !== state) {
+ // Check if the finished script id (id) matches the current state of the client.
+ if (client.registrationState !== id) {
res.status(400).send({ status: 'INVALID_SCRIPT', error: 'This script should not have been executed.' })
return
}
@@ -106,16 +110,12 @@ noAuthRouter.post('/:uuid/state', (req, res) => {
// Get the sort value of the current hook.
db.registrationhook.findOne({ where: { id: client.registrationState } }).then(hook => {
- // Gets the list of all groupids inclusive the recursive parents.
- getRecursiveParents(groupids).then(gids => {
- // Get the list of all hooks where the parent is null or those who fullfill the group dependency.
- db.registrationhook.findAll({ where: { '$groups.id$': { $or: [null, gids] }, sortvalue: { $gt: hook.sortvalue } }, include: ['groups'], order: [['sortvalue', 'ASC']] }).then(result => {
- // Update the client's registration state
- client.updateAttributes({
- registrationState: result[0].id
- })
- res.send({ status: 'SUCCESS' })
+ getNextHookScript(groupids, hook.sortvalue).then(resID => {
+ // Update the client's registration state
+ client.updateAttributes({
+ registrationState: resID
})
+ res.send({ status: 'SUCCESS' })
})
})
})
@@ -136,6 +136,7 @@ noAuthRouter.get('/:uuid/nexthook', (req, res) => {
if (hook.type !== 'BASH') {
res.send()
} else {
+ res.set('id', client.registrationState)
res.send(hook.script)
}
})
@@ -145,6 +146,23 @@ noAuthRouter.get('/:uuid/nexthook', (req, res) => {
module.exports.noAuthRouter = noAuthRouter
/*
+ * parentIds:
+ * sortvalue:
+ *
+ */
+function getNextHookScript (groupids, sortvalue) {
+ // Gets the list of all groupids inclusive the recursive parents.
+ return getRecursiveParents(groupids).then(gids => {
+ // Get the list of all hooks where the parent is null or those who fullfill the group dependency.
+ return db.registrationhook.findAll({ where: { '$groups.id$': { $or: [null, gids] }, sortvalue: { $gt: sortvalue } }, include: ['groups'], order: [['sortvalue', 'ASC']] }).then(result => {
+ var resID = null
+ if (result.length >= 1) resID = result[0].id
+ return resID
+ })
+ })
+}
+
+/*
* groupids: Array of group ids to get the parents from.
*
* Returns a list of the grop ids and all recursive ids of their parents.
diff --git a/server/ipxe/grepSystemInfo.sh b/server/ipxe/grepSystemInfo.sh
new file mode 100644
index 0000000..024fb52
--- /dev/null
+++ b/server/ipxe/grepSystemInfo.sh
@@ -0,0 +1,75 @@
+#!/bin/bash
+
+#dmidecode | grep -i UUID
+
+# MAC
+MAC=$(ip addr show | grep -Eo -m 1 'ether\s.*\sbrd')
+MAC=${MAC#"ether "}
+MAC=${MAC%" brd"}
+echo "MAC: $MAC"
+
+# UUID
+UUID=$(dmidecode -q -s system-uuid | grep -v '^#' | head -n 1 | tr '[a-z]' '[A-Z]')
+echo "UUID: $UUID"
+
+# System Information
+echo ""
+echo "######## System Informations ########"
+MANUFACTURER=$(dmidecode -q -s system-manufacturer)
+echo "Manufacturer: $MANUFACTURER"
+
+MODEL=$(dmidecode -q -s system-product-name)
+echo "Model: $MODEL"
+
+SERIAL=$(dmidecode -q -s system-serial-number)
+echo "Serial number: $SERIAL"
+
+VENDOR=$(dmidecode | grep -Eo '(Vendor).*')
+VENDOR=${VENDOR#Vendor: }
+echo "Vendor: $VENDOR"
+
+# Mainboard
+echo ""
+echo "######## Mainboard Informations ########"
+MAINBOARD_MANUFACTURER=$(dmidecode -q -s baseboard-manufacturer)
+echo "Manufacturer: $MAINBOARD_MANUFACTURER"
+MAINBOARD_MODEL=$(dmidecode -q -s baseboard-product-name)
+echo "Model: $MAINBOARD_MODEL"
+MAINBOARD_SERIAL_NUMBER=$(dmidecode -q -s baseboard-serial-number)
+echo "Serial: $MAINBOARD_SERIAL_NUMBER"
+
+# CPU
+echo ""
+echo "######## CPU Informations ########"
+CPU_MODEL=$(dmidecode -q -s processor-version)
+echo "Model: $CPU_MODEL"
+CPU_MANUFACTURER=$(dmidecode -q -s processor-manufacturer)
+echo "Manufacturer: $CPU_MANUFACTURER"
+CPU_TYPE=$(dmidecode -q -s processor-family)
+echo "Type: $CPU_TYPE"
+CPUCORES=$(cat /sys/devices/system/cpu/cpu*/topology/thread_siblings_list | sort -u | wc -l)
+echo "$CPUCORES Cores"
+#CPUMODEL=$(grep -m1 '^model name\s*:' /proc/cpuinfo | sed 's/^model name\s*:\s*//;s/\s\s*/ /g;s/^ //;s/ $//')
+#echo "$CPUMODEL"
+CPU_FREQUENCY=$(dmidecode -q -s processor-frequency)
+echo "Frequency: $CPU_FREQUENCY"
+
+# RAM
+echo ""
+echo "######## RAM Informations ########"
+RAM=$(grep -m1 '^MemTotal:' /proc/meminfo | awk '{print $2}')
+RAM=$(( $RAM / 1024 ))
+if [ -z "$RAM" ] || [ "$RAM" -lt 500 ]; then
+ # Fallback to dmidecode
+ RAM=0
+ for c in $(dmidecode -t 17 | grep -o 'Size:.*MB$' | awk '{print $2}'); do
+ RAM=$(( $RAM + $c ))
+ done
+fi
+echo "$RAM MB RAM"
+
+echo ""
+#echo "######## CURL ########"
+#curl --data "state=6" --insecure https://bas.stfu-kthx.net:8888/api/registrations/$UUID/state
+#echo ""
+#echo ""
diff --git a/server/ipxe/minilinux.ipxe b/server/ipxe/minilinux.ipxe
new file mode 100644
index 0000000..9d05ccc
--- /dev/null
+++ b/server/ipxe/minilinux.ipxe
@@ -0,0 +1,6 @@
+#!ipxe
+
+kernel tftp://10.8.102.124/kernel/kernel
+initrd tftp://10.8.102.124/initramfs-stage31-bss
+imgargs kernel ip=${net0/ip}:10.8.102.124:${net0/gateway}:${net0/netmask} BOOTIF=01-${net0/mac} bas=bas.stfu-kthx.net:8888
+boot \ No newline at end of file