Skip to content

Commit

Permalink
Switch deprecated requests for node-fetch
Browse files Browse the repository at this point in the history
Update logo, clean up netboot.xyz naming
  • Loading branch information
antonym committed Oct 21, 2023
1 parent 191fa0d commit 72dd622
Show file tree
Hide file tree
Showing 7 changed files with 115 additions and 79 deletions.
73 changes: 45 additions & 28 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,35 +1,52 @@
FROM lsiobase/cloud9:alpine
FROM alpine:3.18

# set version label
ARG BUILD_DATE
ARG VERSION
ARG WEBAPP_VERSION
LABEL build_version="netboot.xyz version: ${VERSION} Build-date: ${BUILD_DATE}"
LABEL maintainer="antonym"

RUN \
echo "**** install build packages ****" && \
apk upgrade --no-cache && \
apk add --no-cache --virtual=build-dependencies \
curl \
nodejs-npm && \
nodejs npm && \
echo "**** install runtime packages ****" && \
apk add --no-cache \
git \
logrotate \
jq \
nghttp2-dev \
nginx \
nodejs \
sudo \
tftp-hpa && \
echo "**** install WebApp ****" && \
git clone https://github.com/netbootxyz/webapp.git /code && \
npm config set unsafe-perm true && \
npm i npm@latest -g && \
npm install --prefix /code && \
npm install -g nodemon && \
echo "**** cleanup ****" && \
apk del --purge \
build-dependencies && \
rm -rf \
/tmp/*

# copy local files
COPY root/ /
bash \
busybox \
curl \
git \
jq \
nghttp2-dev \
nginx \
nodejs \
shadow \
sudo \
supervisor \
syslog-ng \
tar \
tftp-hpa

RUN \
groupmod -g 1000 users && \
useradd -u 911 -U -d /config -s /bin/false nbxyz && \
usermod -G users nbxyz && \
mkdir /app \
/config \
/defaults

COPY . /app

RUN \
npm install --prefix /app

ENV TFTPD_OPTS=''

#App runs on port 3000 development interface on port 8000
EXPOSE 3000
EXPOSE 8000
EXPOSE 8080

COPY root/ /

# default command
CMD ["sh","/start.sh"]
33 changes: 22 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,30 @@
Basic run example:
# netboot.xyz webapp

This repo houses the netboot.xyz webapp that
provides a web interface for editing iPXE files
and downloading assets locally to the app.

## Building netboot.xyz webapp locally

```bash
docker build . -t netbootxyz-webapp
```

## Running it locally

```bash
docker run -d \
-e PUID=1000 \
-e PGID=1000 \
-v <path to menu/config>:/config \
-v <path to mirrored assets>:/assets `#optional` \
-p 69:69/udp \
-p 8080:80 \
-p 3000:3000 \
-p 8000:8000 \
ghcr.io/netbootxyz/webapp-dev
--name=netbootxyz-webapp \
-e MENU_VERSION=2.0.73 `# optional` \
-p 3000:3000 `# sets webapp port` \
-p 69:69/udp `# sets tftp port` \
-p 8080:80 `# optional` \
-v /local/path/to/config:/config `# optional` \
-v /local/path/to/assets:/assets `# optional` \
--restart unless-stopped \
netbootxyz-webapp
```

* Port 8000- Development interface
* Port 3000- Web Application
* Port 8080- NGINX Webserver for local asset hosting
* Port 69- TFTP server for menus/kpxe files
56 changes: 32 additions & 24 deletions app.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Netboot.xyz
// netboot.xyz
// Main Node.js app

var baseurl = process.env.SUBFOLDER || '/';
Expand All @@ -12,7 +12,7 @@ var io = require('socket.io')(http, {path: baseurl + 'socket.io'});
var isBinaryFile = require("isbinaryfile").isBinaryFile;
var path = require('path');
var readdirp = require('readdirp');
var request = require('request');
var fetch = require('node-fetch');
var si = require('systeminformation');
const util = require('util');
var { version } = require('./package.json');
Expand Down Expand Up @@ -62,26 +62,36 @@ io.on('connection', function(socket){
var dashinfo = {};
dashinfo['webversion'] = version;
dashinfo['menuversion'] = fs.readFileSync('/config/menuversion.txt', 'utf8');
request.get('https://api.github.com/repos/netbootxyz/netboot.xyz/releases/latest', {headers: {'user-agent': 'node.js'}}, function (error, response, body) {
dashinfo['remotemenuversion'] = JSON.parse(body).tag_name;
si.cpu(function(cpu) {
dashinfo['cpu'] = cpu;
si.mem(function(mem) {
dashinfo['mem'] = mem;
si.currentLoad(function(currentLoad) {
dashinfo['CPUpercent'] = currentLoad.currentload_user;
exec(tftpcmd, function (err, stdout) {
dashinfo['tftpversion'] = stdout;
exec(nginxcmd, function (err, stdout, stderr) {
dashinfo['nginxversion'] = stderr;
io.sockets.in(socket.id).emit('renderdash',dashinfo);
});
});
fetch('https://api.github.com/repos/netbootxyz/netboot.xyz/releases/latest', {headers: {'user-agent': 'node.js'}})
.then(response => {
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
return response.json();
})
.then(body => {
dashinfo['remotemenuversion'] = body.tag_name;
si.cpu(function(cpu) {
dashinfo['cpu'] = cpu;
si.mem(function(mem) {
dashinfo['mem'] = mem;
si.currentLoad(function(currentLoad) {
dashinfo['CPUpercent'] = currentLoad.currentload_user;
exec(tftpcmd, function (err, stdout) {
dashinfo['tftpversion'] = stdout;
exec(nginxcmd, function (err, stdout, stderr) {
dashinfo['nginxversion'] = stderr;
io.sockets.in(socket.id).emit('renderdash',dashinfo);
});
});
});
});
});
});
})
.catch(error => {
console.log('There was a problem with the fetch operation: ' + error.message);
});
});
});
// When upgrade is requested run it
socket.on('upgrademenus', function(version){
upgrademenu(version, function(response){
Expand Down Expand Up @@ -177,9 +187,8 @@ io.on('connection', function(socket){
socket.on('devgetbrowser', async function(){
var api_url = 'https://api.github.com/repos/netbootxyz/netboot.xyz/';
var options = {headers: {'user-agent': 'node.js'}};
var requestPromise = util.promisify(request);
var releases = await requestPromise(api_url + 'releases', options);
var commits = await requestPromise(api_url + 'commits', options);
var releases = await fetch(api_url + 'releases', options).then(res => res.json());
var commits = await fetch(api_url + 'commits', options).then(res => res.json());
io.sockets.in(socket.id).emit('devrenderbrowser', JSON.parse(releases.body), JSON.parse(commits.body));
});
});
Expand Down Expand Up @@ -293,8 +302,7 @@ async function downloader(downloads){
await dl.start();
if ( ! url.includes('s3.amazonaws.com')){
// Part 2 if exists repeat
var requestPromise = util.promisify(request);
var response = await requestPromise(url + '.part2', {method: 'HEAD'});
var response = await fetch(url + '.part2', {method: 'HEAD'});
var urltest = response.headers.server;
if (urltest == 'AmazonS3' || urltest == 'Windows-Azure-Blob/1.0 Microsoft-HTTPAPI/2.0') {
var dl2 = new DownloaderHelper(url + '.part2', path, dloptions);
Expand Down
22 changes: 11 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "WebApp",
"version": "0.6.8",
"version": "0.6.9",
"description": "Configuration and mirroring application for netboot.xyz stack",
"main": "app.js",
"scripts": {
Expand All @@ -10,19 +10,19 @@
"type": "git",
"url": "git+https://github.com/netbootxyz/webapp.git"
},
"author": "Netboot.xyz",
"author": "netboot.xyz",
"license": "Apache-2.0",
"homepage": "https://netboot.xyz",
"dependencies": {
"ejs": "^3.1.6",
"express": "^4.17.1",
"ejs": "3.1.6",
"express": "4.17.1",
"http": "0.0.0",
"isbinaryfile": "^5.0.0",
"js-yaml": "^4.1.0",
"node-downloader-helper": "^2.0.0",
"readdirp": "^3.6.0",
"request": "^2.88.0",
"socket.io": "^4.0.1",
"systeminformation": "^5.6.12"
"isbinaryfile": "5.0.0",
"js-yaml": "4.1.0",
"node-downloader-helper": "2.0.0",
"readdirp": "3.6.0",
"node-fetch": "2.7.0",
"socket.io": "4.0.1",
"systeminformation": "5.6.12"
}
}
Binary file modified public/img/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 3 additions & 3 deletions public/index.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta name="description" content="Web Application for customizing netboot.xyz">
<meta name="author" content="Netboot.xyz">
<title>NETBOOT.XYZ Configuration</title>
<meta name="author" content="netboot.xyz">
<title>netboot.xyz Configuration</title>
<!-- Favicon stuff -->
<link rel="apple-touch-icon" sizes="57x57" href="<%= baseurl %>public/img/favicon/apple-icon-57x57.png">
<link rel="apple-touch-icon" sizes="60x60" href="<%= baseurl %>public/img/favicon/apple-icon-60x60.png">
Expand Down Expand Up @@ -35,7 +35,7 @@
<nav class="navbar navbar-expand-lg navbar-light bg-light">
<div class="navbar-brand" style="cursor:pointer;" onclick="renderdash()">
<img src="<%= baseurl %>public/img/logo.png" width="30" height="30" class="d-inline-block align-top" alt="">
NETBOOT.XYZ
netboot.xyz
</div>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
Expand Down
4 changes: 2 additions & 2 deletions public/netbootxyz-web.ejs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Netboot.xyz
// netboot.xyz
// Client side javascript


Expand Down Expand Up @@ -44,7 +44,7 @@ socket.on('renderdash', function(response){
<div class="card-body card-deck">\
<div class="card mb-3">\
<div class="card-header">\
NETBOOT.XYZ\
Versions\
</div>\
<div class="card-body">\
<table class="table table-hover">\
Expand Down

0 comments on commit 72dd622

Please sign in to comment.