Sikuliaq IT Asset Manager (skqitam)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

59 lines
2.5 KiB

var path = require('path')
var fs = require('fs')
const express = require('express')
const app = express()
var skqlib = require('./skq_modules/skq-lib')
// GLOBAL CONFIG
process['CONFIG'] = JSON.parse(fs.readFileSync(path.join(__dirname, 'config','skq-it-am-config.json'), 'utf8'))
process['CONFIG']['GLOBAL']['RUN_DIR'] = __dirname
process['CONFIG']['LOCAL']= skqlib.it_am_init()
// console.log(JSON.stringify(process['CONFIG'], null, 2))
// BEGIN DEV TEST FUNCTIONS - Disable for security purpose before deploying
app.use('/api/config', function(req, res) {
res.writeHead(200, {'Content-Type': 'application/json'})
res.end(JSON.stringify(process['CONFIG'], null, 2))
})
// END DEV TEST FUNCTIONS - Disable for security purpose before deploying
// API
// Web Config
app.use('/api/webconfig', function(req, res) {
res.writeHead(200, {'Content-Type': 'application/json'})
res.end(JSON.stringify(process['CONFIG']['LOCAL']['WEB'], null, 2))
})
// WebUI Admin
app.use('/admin', express.static(path.join(__dirname, process['CONFIG']['GLOBAL']['WEBUI_ADMIN']['WEB_ROOT_DIR'])))
// WebUI Root
app.use('/', express.static(path.join(__dirname, process['CONFIG']['GLOBAL']['WEBUI_ROOT']['WEB_ROOT_DIR'])))
// 404 Errors
app.use(function (req, res, next) {
res.status(404).send("404 Page not found: " + req.url )
var remote_ip = req.headers['x-forwarded-for'] || req.connection.remoteAddress
remote_ip = remote_ip.replace(/^\:\:ffff\:/, '') // IPv4 part only
console.log('ERR ' + res.statusCode + ' ' + req.method + ' ' + remote_ip + ' [' + req.headers['user-agent'] + '] ' + ' ' + req.url)
})
// Starting Express Web Service
app.listen(process['CONFIG']['GLOBAL']['WEBUI_PORT'], function () {
console.log("Sikuliaq Cyber Asset Manager Server")
console.log(" - Copyright (C) 2021 University of Alaska Fairbanks\n")
console.log("Status: STARTED")
for (i in process['CONFIG']['LOCAL']['HOST']['NETWORK']['IP_ADDR']['IPv4']) {
console.log(" WebUI: http://" + process['CONFIG']['LOCAL']['HOST']['NETWORK']['IP_ADDR']['IPv4'][i] + ':' + process['CONFIG']['GLOBAL']['WEBUI_PORT'])
}
for (i in process['CONFIG']['LOCAL']['HOST']['NETWORK']['IP_ADDR']['IPv6']) {
console.log(" WebUI: http://[" + process['CONFIG']['LOCAL']['HOST']['NETWORK']['IP_ADDR']['IPv6'][i] + ']:' + process['CONFIG']['GLOBAL']['WEBUI_PORT'])
}
console.log("\nNOTE: Be sure to open port " + process['CONFIG']['GLOBAL']['WEBUI_PORT'] + " to the above IP's\n on server and network firewalls.")
})