Skip to content

Commit dcd95ec

Browse files
committed
Merge pull request OpenUserJS#320 from Martii/documentPageFixes
Resubmitting OpenUserJS#318
2 parents 2663aae + a013abe commit dcd95ec

File tree

3 files changed

+27
-0
lines changed

3 files changed

+27
-0
lines changed

app.js

+1
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@ app.get('/admin/authas', admin.authAsUser);
184184
app.get('/admin/json', admin.adminJsonView);
185185
app.get('/admin/user/:id', admin.adminUserView);
186186
app.get('/admin/api', admin.adminApiKeysPage);
187+
app.get('/admin/npmls', admin.adminNpmLsView);
187188
app.post('/admin/api/update', admin.apiAdminUpdate);
188189

189190
// Moderation routes

controllers/admin.js

+23
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
'use strict';
22

33
var async = require('async');
4+
var exec = require('child_process').exec;
45

56
var Comment = require('../models/comment').Comment;
67
var Discussion = require('../models/discussion').Discussion;
@@ -289,6 +290,28 @@ exports.adminApiKeysPage = function (aReq, aRes, aNext) {
289290
});
290291
};
291292

293+
// View everything about current modules for the server
294+
// This is mostly for debugging in production
295+
exports.adminNpmLsView = function (aReq, aRes, aNext) {
296+
var authedUser = aReq.session.user;
297+
298+
//
299+
var options = {};
300+
301+
// Session
302+
authedUser = options.authedUser = modelParser.parseUser(authedUser);
303+
options.isMod = authedUser && authedUser.isMod;
304+
options.isAdmin = authedUser && authedUser.isAdmin;
305+
306+
if (!options.isAdmin)
307+
return aRes.send(403, { status: 403, message: 'Not an admin.' });
308+
309+
exec('npm ls --json', function(aErr, aStdout, aStderr) {
310+
if (aErr) return aRes.send(501, { status: 501, message: 'Not implemented.' });
311+
aRes.json(JSON.parse(aStdout));
312+
});
313+
}
314+
292315
// Manage oAuth strategies without having to restart the server
293316
// When new keys are added, we load the new strategy
294317
// When keys are removed, we remove the strategy

views/pages/adminPage.html

+3
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313
<a href="/admin/api" class="list-group-item">
1414
API Keys
1515
</a>
16+
<a href="/admin/npmls" class="list-group-item">
17+
Raw <code>npm ls --json</code> Data
18+
</a>
1619
</div>
1720
</div>
1821
</div>

0 commit comments

Comments
 (0)