Skip to content

Commit 2c100d1

Browse files
authored
Merge pull request #13 from MasseranoLabs/adminapi
Added admin web API skeleton, add node endpoint
2 parents 414704a + c86ad97 commit 2c100d1

File tree

5 files changed

+70
-6
lines changed

5 files changed

+70
-6
lines changed

Diff for: adminweb.js

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/**
2+
* nodeodm-proxy - A reverse proxy, load balancer and task tracker for NodeODM
3+
* Copyright (C) 2018-present MasseranoLabs LLC
4+
*
5+
* This program is free software: you can redistribute it and/or modify
6+
* it under the terms of the GNU Affero General Public License as
7+
* published by the Free Software Foundation, either version 3 of the
8+
* License, or (at your option) any later version.
9+
*
10+
* This program is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU Affero General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU Affero General Public License
16+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
17+
*/
18+
const logger = require('./libs/logger');
19+
const express = require('express');
20+
const basicAuth = require('express-basic-auth');
21+
const nodes = require('./libs/nodes');
22+
23+
module.exports = {
24+
create: function(options){
25+
logger.info("Starting admin web interface on " + options.port);
26+
const app = express();
27+
28+
if (!options.password){
29+
logger.warn(`No admin password specified, make sure port ${options.port} is secured`);
30+
}else{
31+
app.use(basicAuth({
32+
users: { 'admin': options.password },
33+
challenge: true,
34+
realm: "nodeodm-proxy"
35+
}));
36+
}
37+
38+
app.use(express.static('public'));
39+
app.use(express.json());
40+
41+
// API
42+
app.post('/r/node/add', (req, res) => {
43+
const { hostname, port, token } = req.body;
44+
const node = nodes.add(hostname, port, token);
45+
if (node) {
46+
node.updateInfo();
47+
res.send({success: true});
48+
}else{
49+
res.send({error: "Invalid"});
50+
}
51+
});
52+
53+
app.listen(options.port);
54+
}
55+
}
56+

Diff for: config.js

+8-5
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
'use strict';
1919

2020
let argv = require('minimist')(process.argv.slice(2), {
21-
string: ['port', 'admin-cli-port', 'admin-cli-pass',
21+
string: ['port', 'admin-cli-port', 'admin-pass', 'admin-web-port',
2222
'cloud-provider', 'downloads-from-s3', 'log-level',
2323
'upload-max-speed', 'ssl-key', 'ssl-cert', 'secure-port',
2424
'cluster-address'],
@@ -31,7 +31,8 @@ let argv = require('minimist')(process.argv.slice(2), {
3131
'port': 3000,
3232
'secure-port': 0,
3333
'admin-cli-port': 8080,
34-
'admin-cli-pass': '',
34+
'admin-web-port': 10000,
35+
'admin-pass': '',
3536
'cloud-provider': 'local',
3637
'downloads-from-s3': '',
3738
'no-cluster': false,
@@ -51,8 +52,9 @@ Usage: node index.js [options]
5152
Options:
5253
-p, --port <number> Port to bind the server to (default: 3000)
5354
--secure-port <number> If SSL is enabled and you want to expose both a secure and non-secure service, set this value to the secure port. Otherwise only SSL will be enabled using the --port value. (default: none)
54-
--admin-cli-port <number> Port to bind the admin CLI to (default: 8080)
55-
--admin-cli-pass <string> Password to log-in to the admin CLI (default: none)
55+
--admin-cli-port <number> Port to bind the admin CLI to. Set to zero to disable. (default: 8080)
56+
--admin-web-port <number> Port to bind the admin web interface to. Set to zero to disable. (default: 10000)
57+
--admin-pass <string> Password to log-in to the admin functions (default: none)
5658
--log-level <logLevel> Set log level verbosity (default: info)
5759
-c, --cloud-provider Cloud provider to use (default: local)
5860
--upload-max-speed <number> Upload to processing nodes speed limit in bytes / second (default: no limit)
@@ -79,7 +81,8 @@ config.logger.logDirectory = '' // Set this to a full path to a directory - if n
7981
config.port = parseInt(argv.port);
8082
config.secure_port = parseInt(argv['secure-port']);
8183
config.admin_cli_port = parseInt(argv['admin-cli-port']);
82-
config.admin_cli_pass = argv['admin-cli-pass'];
84+
config.admin_web_port = parseInt(argv['admin-web-port']);
85+
config.admin_pass = argv['admin-pass'];
8386
config.cloud_provider = argv['cloud-provider'];
8487
config.no_cluster = argv['no-cluster'];
8588
config.cluster_address = argv['cluster-address'];

Diff for: index.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
*/
1818
const config = require('./config');
1919
const admincli = require('./admincli');
20+
const adminweb = require('./adminweb');
2021
const logger = require('./libs/logger');
2122
const package_info = require('./package_info');
2223
const nodes = require('./libs/nodes');
@@ -26,7 +27,8 @@ const routetable = require('./libs/routetable');
2627
(async function(){
2728
if (config.debug) logger.warn("Running in debug mode");
2829
logger.info(package_info.name + " " + package_info.version);
29-
admincli.create({port: config.admin_cli_port, password: config.admin_cli_pass});
30+
if (config.admin_cli_port !== 0) admincli.create({port: config.admin_cli_port, password: config.admin_pass});
31+
if (config.admin_web_port !== 0) adminweb.create({port: config.admin_web_port, password: config.admin_pass});
3032
const cloudProvider = (require('./libs/cloudProvider')).initialize(config.cloud_provider);
3133
await nodes.initialize();
3234

Diff for: package.json

+2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
"async": "^2.6.1",
1717
"axios": "^0.18.0",
1818
"busboy": "^0.2.14",
19+
"express": "^4.16.4",
20+
"express-basic-auth": "^1.2.0",
1921
"http-proxy": "^1.17.0",
2022
"minimist": "^1.2.0",
2123
"node-libcurl": "^1.3.3",

Diff for: public/index.html

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
TODO

0 commit comments

Comments
 (0)