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 1a11f7d
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 41 deletions.
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
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"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": {
Expand All @@ -21,7 +21,7 @@
"js-yaml": "^4.1.0",
"node-downloader-helper": "^2.0.0",
"readdirp": "^3.6.0",
"request": "^2.88.0",
"node-fetch": "2.7.0",
"socket.io": "^4.0.1",
"systeminformation": "^5.6.12"
}
Expand Down
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.
4 changes: 2 additions & 2 deletions public/index.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<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>
<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 1a11f7d

Please sign in to comment.