Skip to content

Commit d5616c3

Browse files
authored
Merge pull request #32 from netbootxyz/remove_requests
Switch deprecated requests for node-fetch
2 parents 191fa0d + 72dd622 commit d5616c3

File tree

7 files changed

+115
-79
lines changed

7 files changed

+115
-79
lines changed

Dockerfile

+45-28
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,52 @@
1-
FROM lsiobase/cloud9:alpine
1+
FROM alpine:3.18
2+
3+
# set version label
4+
ARG BUILD_DATE
5+
ARG VERSION
6+
ARG WEBAPP_VERSION
7+
LABEL build_version="netboot.xyz version: ${VERSION} Build-date: ${BUILD_DATE}"
8+
LABEL maintainer="antonym"
29

310
RUN \
4-
echo "**** install build packages ****" && \
11+
apk upgrade --no-cache && \
512
apk add --no-cache --virtual=build-dependencies \
6-
curl \
7-
nodejs-npm && \
13+
nodejs npm && \
814
echo "**** install runtime packages ****" && \
915
apk add --no-cache \
10-
git \
11-
logrotate \
12-
jq \
13-
nghttp2-dev \
14-
nginx \
15-
nodejs \
16-
sudo \
17-
tftp-hpa && \
18-
echo "**** install WebApp ****" && \
19-
git clone https://github.com/netbootxyz/webapp.git /code && \
20-
npm config set unsafe-perm true && \
21-
npm i npm@latest -g && \
22-
npm install --prefix /code && \
23-
npm install -g nodemon && \
24-
echo "**** cleanup ****" && \
25-
apk del --purge \
26-
build-dependencies && \
27-
rm -rf \
28-
/tmp/*
29-
30-
# copy local files
31-
COPY root/ /
16+
bash \
17+
busybox \
18+
curl \
19+
git \
20+
jq \
21+
nghttp2-dev \
22+
nginx \
23+
nodejs \
24+
shadow \
25+
sudo \
26+
supervisor \
27+
syslog-ng \
28+
tar \
29+
tftp-hpa
30+
31+
RUN \
32+
groupmod -g 1000 users && \
33+
useradd -u 911 -U -d /config -s /bin/false nbxyz && \
34+
usermod -G users nbxyz && \
35+
mkdir /app \
36+
/config \
37+
/defaults
38+
39+
COPY . /app
40+
41+
RUN \
42+
npm install --prefix /app
43+
44+
ENV TFTPD_OPTS=''
3245

33-
#App runs on port 3000 development interface on port 8000
3446
EXPOSE 3000
35-
EXPOSE 8000
47+
EXPOSE 8080
48+
49+
COPY root/ /
50+
51+
# default command
52+
CMD ["sh","/start.sh"]

README.md

+22-11
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,30 @@
1-
Basic run example:
1+
# netboot.xyz webapp
22

3+
This repo houses the netboot.xyz webapp that
4+
provides a web interface for editing iPXE files
5+
and downloading assets locally to the app.
6+
7+
## Building netboot.xyz webapp locally
8+
9+
```bash
10+
docker build . -t netbootxyz-webapp
311
```
12+
13+
## Running it locally
14+
15+
```bash
416
docker run -d \
5-
-e PUID=1000 \
6-
-e PGID=1000 \
7-
-v <path to menu/config>:/config \
8-
-v <path to mirrored assets>:/assets `#optional` \
9-
-p 69:69/udp \
10-
-p 8080:80 \
11-
-p 3000:3000 \
12-
-p 8000:8000 \
13-
ghcr.io/netbootxyz/webapp-dev
17+
--name=netbootxyz-webapp \
18+
-e MENU_VERSION=2.0.73 `# optional` \
19+
-p 3000:3000 `# sets webapp port` \
20+
-p 69:69/udp `# sets tftp port` \
21+
-p 8080:80 `# optional` \
22+
-v /local/path/to/config:/config `# optional` \
23+
-v /local/path/to/assets:/assets `# optional` \
24+
--restart unless-stopped \
25+
netbootxyz-webapp
1426
```
1527

16-
* Port 8000- Development interface
1728
* Port 3000- Web Application
1829
* Port 8080- NGINX Webserver for local asset hosting
1930
* Port 69- TFTP server for menus/kpxe files

app.js

+32-24
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Netboot.xyz
1+
// netboot.xyz
22
// Main Node.js app
33

44
var baseurl = process.env.SUBFOLDER || '/';
@@ -12,7 +12,7 @@ var io = require('socket.io')(http, {path: baseurl + 'socket.io'});
1212
var isBinaryFile = require("isbinaryfile").isBinaryFile;
1313
var path = require('path');
1414
var readdirp = require('readdirp');
15-
var request = require('request');
15+
var fetch = require('node-fetch');
1616
var si = require('systeminformation');
1717
const util = require('util');
1818
var { version } = require('./package.json');
@@ -62,26 +62,36 @@ io.on('connection', function(socket){
6262
var dashinfo = {};
6363
dashinfo['webversion'] = version;
6464
dashinfo['menuversion'] = fs.readFileSync('/config/menuversion.txt', 'utf8');
65-
request.get('https://api.github.com/repos/netbootxyz/netboot.xyz/releases/latest', {headers: {'user-agent': 'node.js'}}, function (error, response, body) {
66-
dashinfo['remotemenuversion'] = JSON.parse(body).tag_name;
67-
si.cpu(function(cpu) {
68-
dashinfo['cpu'] = cpu;
69-
si.mem(function(mem) {
70-
dashinfo['mem'] = mem;
71-
si.currentLoad(function(currentLoad) {
72-
dashinfo['CPUpercent'] = currentLoad.currentload_user;
73-
exec(tftpcmd, function (err, stdout) {
74-
dashinfo['tftpversion'] = stdout;
75-
exec(nginxcmd, function (err, stdout, stderr) {
76-
dashinfo['nginxversion'] = stderr;
77-
io.sockets.in(socket.id).emit('renderdash',dashinfo);
78-
});
79-
});
65+
fetch('https://api.github.com/repos/netbootxyz/netboot.xyz/releases/latest', {headers: {'user-agent': 'node.js'}})
66+
.then(response => {
67+
if (!response.ok) {
68+
throw new Error(`HTTP error! status: ${response.status}`);
69+
}
70+
return response.json();
71+
})
72+
.then(body => {
73+
dashinfo['remotemenuversion'] = body.tag_name;
74+
si.cpu(function(cpu) {
75+
dashinfo['cpu'] = cpu;
76+
si.mem(function(mem) {
77+
dashinfo['mem'] = mem;
78+
si.currentLoad(function(currentLoad) {
79+
dashinfo['CPUpercent'] = currentLoad.currentload_user;
80+
exec(tftpcmd, function (err, stdout) {
81+
dashinfo['tftpversion'] = stdout;
82+
exec(nginxcmd, function (err, stdout, stderr) {
83+
dashinfo['nginxversion'] = stderr;
84+
io.sockets.in(socket.id).emit('renderdash',dashinfo);
85+
});
86+
});
87+
});
8088
});
81-
});
89+
});
90+
})
91+
.catch(error => {
92+
console.log('There was a problem with the fetch operation: ' + error.message);
8293
});
8394
});
84-
});
8595
// When upgrade is requested run it
8696
socket.on('upgrademenus', function(version){
8797
upgrademenu(version, function(response){
@@ -177,9 +187,8 @@ io.on('connection', function(socket){
177187
socket.on('devgetbrowser', async function(){
178188
var api_url = 'https://api.github.com/repos/netbootxyz/netboot.xyz/';
179189
var options = {headers: {'user-agent': 'node.js'}};
180-
var requestPromise = util.promisify(request);
181-
var releases = await requestPromise(api_url + 'releases', options);
182-
var commits = await requestPromise(api_url + 'commits', options);
190+
var releases = await fetch(api_url + 'releases', options).then(res => res.json());
191+
var commits = await fetch(api_url + 'commits', options).then(res => res.json());
183192
io.sockets.in(socket.id).emit('devrenderbrowser', JSON.parse(releases.body), JSON.parse(commits.body));
184193
});
185194
});
@@ -293,8 +302,7 @@ async function downloader(downloads){
293302
await dl.start();
294303
if ( ! url.includes('s3.amazonaws.com')){
295304
// Part 2 if exists repeat
296-
var requestPromise = util.promisify(request);
297-
var response = await requestPromise(url + '.part2', {method: 'HEAD'});
305+
var response = await fetch(url + '.part2', {method: 'HEAD'});
298306
var urltest = response.headers.server;
299307
if (urltest == 'AmazonS3' || urltest == 'Windows-Azure-Blob/1.0 Microsoft-HTTPAPI/2.0') {
300308
var dl2 = new DownloaderHelper(url + '.part2', path, dloptions);

package.json

+11-11
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "WebApp",
3-
"version": "0.6.8",
3+
"version": "0.6.9",
44
"description": "Configuration and mirroring application for netboot.xyz stack",
55
"main": "app.js",
66
"scripts": {
@@ -10,19 +10,19 @@
1010
"type": "git",
1111
"url": "git+https://github.com/netbootxyz/webapp.git"
1212
},
13-
"author": "Netboot.xyz",
13+
"author": "netboot.xyz",
1414
"license": "Apache-2.0",
1515
"homepage": "https://netboot.xyz",
1616
"dependencies": {
17-
"ejs": "^3.1.6",
18-
"express": "^4.17.1",
17+
"ejs": "3.1.6",
18+
"express": "4.17.1",
1919
"http": "0.0.0",
20-
"isbinaryfile": "^5.0.0",
21-
"js-yaml": "^4.1.0",
22-
"node-downloader-helper": "^2.0.0",
23-
"readdirp": "^3.6.0",
24-
"request": "^2.88.0",
25-
"socket.io": "^4.0.1",
26-
"systeminformation": "^5.6.12"
20+
"isbinaryfile": "5.0.0",
21+
"js-yaml": "4.1.0",
22+
"node-downloader-helper": "2.0.0",
23+
"readdirp": "3.6.0",
24+
"node-fetch": "2.7.0",
25+
"socket.io": "4.0.1",
26+
"systeminformation": "5.6.12"
2727
}
2828
}

public/img/logo.png

479 Bytes
Loading

public/index.ejs

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
<meta http-equiv="X-UA-Compatible" content="IE=edge">
66
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
77
<meta name="description" content="Web Application for customizing netboot.xyz">
8-
<meta name="author" content="Netboot.xyz">
9-
<title>NETBOOT.XYZ Configuration</title>
8+
<meta name="author" content="netboot.xyz">
9+
<title>netboot.xyz Configuration</title>
1010
<!-- Favicon stuff -->
1111
<link rel="apple-touch-icon" sizes="57x57" href="<%= baseurl %>public/img/favicon/apple-icon-57x57.png">
1212
<link rel="apple-touch-icon" sizes="60x60" href="<%= baseurl %>public/img/favicon/apple-icon-60x60.png">
@@ -35,7 +35,7 @@
3535
<nav class="navbar navbar-expand-lg navbar-light bg-light">
3636
<div class="navbar-brand" style="cursor:pointer;" onclick="renderdash()">
3737
<img src="<%= baseurl %>public/img/logo.png" width="30" height="30" class="d-inline-block align-top" alt="">
38-
NETBOOT.XYZ
38+
netboot.xyz
3939
</div>
4040
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
4141
<span class="navbar-toggler-icon"></span>

public/netbootxyz-web.ejs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Netboot.xyz
1+
// netboot.xyz
22
// Client side javascript
33

44

@@ -44,7 +44,7 @@ socket.on('renderdash', function(response){
4444
<div class="card-body card-deck">\
4545
<div class="card mb-3">\
4646
<div class="card-header">\
47-
NETBOOT.XYZ\
47+
Versions\
4848
</div>\
4949
<div class="card-body">\
5050
<table class="table table-hover">\

0 commit comments

Comments
 (0)