summaryrefslogtreecommitdiffstats
path: root/server/api/ipxe.js
diff options
context:
space:
mode:
Diffstat (limited to 'server/api/ipxe.js')
-rw-r--r--server/api/ipxe.js44
1 files changed, 42 insertions, 2 deletions
diff --git a/server/api/ipxe.js b/server/api/ipxe.js
index 7b5ad85..b7e1970 100644
--- a/server/api/ipxe.js
+++ b/server/api/ipxe.js
@@ -5,6 +5,7 @@ var shell = require(path.join(__appdir, 'lib', 'shell'))
var express = require('express')
var router = express.Router()
var noAuthRouter = express.Router()
+const log = require(path.join(__appdir, 'lib', 'log'))
// GET requests.
router.get('/script', (req, res) => {
@@ -72,22 +73,45 @@ router.post('/config', (req, res) => {
router.put('/:filename', (req, res) => {
var filepath = null
+ let filename = ''
+
// Set the file path
if (req.params.filename === 'script') {
filepath = path.join(__appdir, 'ipxe', 'embedded.ipxe')
+ filename = 'embedded.ipxe'
} else if (req.params.filename === 'console' || req.params.filename === 'general') {
filepath = path.join(__appdir, 'ipxe', req.params.filename + '.h')
+ filename = req.params.filename + '.h'
} else if (req.params.filename === 'certificate') {
filepath = path.join(__appdir, 'bin', 'fullchain.pem')
+ filename = 'fullchain.pem'
} else {
+ log({
+ category: 'ERROR_IPXEBUILDER_SAVE',
+ description: filename + ' cannot be saved. Filename unknown',
+ userId: req.user.id
+ })
res.status(500).send({ status: 'UNKNOWN_FILENAME', error: 'The provided filename is unknown' })
return
}
// Write File
fs.writeFile(filepath, req.body.data, err => {
- if (err) res.status(500).send({ status: 'WRITE_FILE_ERROR', error: err })
- else res.status(200).send({ status: 'SUCCESS' })
+ if (err) {
+ log({
+ category: 'ERROR_IPXEBUILDER_SAVE',
+ description: 'Error while saving ' + filename + '. ' + err,
+ userId: req.user.id
+ })
+ res.status(500).send({ status: 'WRITE_FILE_ERROR', error: err })
+ } else {
+ log({
+ category: 'IPXEBUILDER_SAVE',
+ description: 'User has saved ' + filename,
+ userId: req.user.id
+ })
+ res.status(200).send({ status: 'SUCCESS' })
+ }
})
})
@@ -95,6 +119,12 @@ router.put('/:filename', (req, res) => {
* @return: Rebuild the ipxe.
*/
router.get('/build', async (req, res) => {
+ log({
+ category: 'IPXEBUILDER_BUILD',
+ description: 'User initiated the ipxe building process.',
+ userId: req.user.id
+ })
+
delete require.cache[require.resolve(path.join(__appdir, 'config', 'ipxe'))]
const config = require(path.join(__appdir, 'config', 'ipxe'))
const build = await shell.buildIpxe(config.targets.build.join(' '), config.repository, config.branch)
@@ -102,11 +132,21 @@ router.get('/build', async (req, res) => {
})
router.get('/cancel', async (req, res) => {
+ log({
+ category: 'IPXEBUILDER_CANCEL',
+ description: 'User canceled the ipxe building process.',
+ userId: req.user.id
+ })
const result = await shell.cancelBuilding(req, res)
res.send(result)
})
router.get('/clean', async (req, res) => {
+ log({
+ category: 'IPXEBUILDER_CLEAN',
+ description: 'User initiated ipxe cleaning process.',
+ userId: req.user.id
+ })
const result = await shell.clean()
res.send(result)
})