From 092ab264bcfadee2f982e091afb73554d1a79285 Mon Sep 17 00:00:00 2001 From: Valentin Date: Wed, 13 Sep 2023 15:46:40 +0200 Subject: [PATCH] dynamic user for authorized keys and bug fix --- index.js | 7 ++----- routes/admin/servers.route.js | 4 +++- routes/endpoint/update.route.js | 3 +++ services/auth.service.js | 6 ++++++ services/groups.service.js | 2 -- views/admin/servers.ejs | 4 ++-- views/admin/user_edit.ejs | 22 ++++++++++++++++++++-- views/footer.ejs | 14 ++++++++++++++ views/index.ejs | 5 ++++- views/keys.ejs | 2 +- 10 files changed, 55 insertions(+), 14 deletions(-) diff --git a/index.js b/index.js index fb53fac..96ff4c5 100644 --- a/index.js +++ b/index.js @@ -12,16 +12,13 @@ serverService = require("./services/server.service"); const User = require('./model/user.model') const Key = require('./model/key.model') const Member = require("./model/member.model"); - +const {makeAdmin} = require("./services/users.service"); const app = express(); - databaseService.sync().then(() => { console.log("Database ready"); }) - - app.use(bodyParser.urlencoded({ extended: false })) // parse application/json @@ -78,7 +75,7 @@ app.get("/login", (req, res) => { res.render('login') }); -userService.makeAdmin("itsmrval") + app.use('/admin/', require('./routes/admin.route')); app.use('/auth/', require('./routes/auth.route')); diff --git a/routes/admin/servers.route.js b/routes/admin/servers.route.js index 8c7b373..7e19a28 100644 --- a/routes/admin/servers.route.js +++ b/routes/admin/servers.route.js @@ -20,7 +20,9 @@ router.get("/", (req, res) => { if (server.hostname === req.query.server) { secret_display.content = server.tmp secret_display.url = process.env.APP_URL - secret_display.name = server.hostname + secret_display.name = server.hostname, + secret_display.user = server.username + } }) } diff --git a/routes/endpoint/update.route.js b/routes/endpoint/update.route.js index eeea21b..d913d3c 100644 --- a/routes/endpoint/update.route.js +++ b/routes/endpoint/update.route.js @@ -19,6 +19,9 @@ router.get("/:server", async (req, res) => { raw += '# ' + x + '\n' + result[x] + '\n\n' } res.send(raw) + server.lastPull = + server.save() + }) } else { res.send("invalid request") diff --git a/services/auth.service.js b/services/auth.service.js index dd3c7f0..6ca7644 100644 --- a/services/auth.service.js +++ b/services/auth.service.js @@ -1,5 +1,6 @@ const {default: axios} = require("axios"); const User = require('../model/user.model') +const userService = require("./users.service"); async function getToken(code) { var client_id = process.env.GITHUB_CLIENT_ID @@ -37,6 +38,11 @@ async function syncUser(user) { avatar: user.avatar_url, displayName: user.name }).then(() => { + User.findAll().then((users) => { + if (users.length === 1) { + userService.makeAdmin(user.login) + } + }) console.log('user ' + user.login + ' added to database') }); } diff --git a/services/groups.service.js b/services/groups.service.js index 390fb59..0ddf613 100644 --- a/services/groups.service.js +++ b/services/groups.service.js @@ -27,8 +27,6 @@ async function addGroup(name) { }); } - - async function delGroup(name) { Group.findOne({where: { name: name}}).then((result) => { if (result && regexp_space.test(name)) { diff --git a/views/admin/servers.ejs b/views/admin/servers.ejs index 2e3f2d8..4bff0f5 100644 --- a/views/admin/servers.ejs +++ b/views/admin/servers.ejs @@ -17,7 +17,7 @@ ⚠️ The installation command will not be shown again later. ⚠️ <% } %> @@ -54,7 +54,7 @@ <%= server.ip %> <%= server.username %> - <%= server.lastPull %> <% if (!server.lastPull) { %>never<% } %> + <%= server.lastPull.toISOString().replace(/T/, ' ').replace(/\..+/, '') %> <% if (!server.lastPull) { %>never<% } %> <% }) %> diff --git a/views/admin/user_edit.ejs b/views/admin/user_edit.ejs index 6351f6f..937f60c 100644 --- a/views/admin/user_edit.ejs +++ b/views/admin/user_edit.ejs @@ -26,9 +26,7 @@ <% keys.forEach(function (key) { %> <%= key.name %> - <%= key.content %> - <% }) %> @@ -45,6 +43,26 @@
+ + + +
+
+

Other

+
+
+
+
+
+ checked <% }%> /> + +
+
+
+
+ + +
diff --git a/views/footer.ejs b/views/footer.ejs index d25af83..0654557 100644 --- a/views/footer.ejs +++ b/views/footer.ejs @@ -28,6 +28,20 @@ } } + + function resizeTextArea(textarea) { + const { style, value } = textarea; + style.height = style.minHeight = 'auto'; + style.minHeight = `${ Math.min(textarea.scrollHeight + 4, parseInt(textarea.style.maxHeight)) }px`; + style.height = `${ textarea.scrollHeight + 4 }px`; + } + + const textarea = document.getElementById('textarea'); + + textarea.addEventListener('input', () => { + resizeTextArea(textarea); + }); + \ No newline at end of file diff --git a/views/index.ejs b/views/index.ejs index c3e4bf8..5c76dbf 100644 --- a/views/index.ejs +++ b/views/index.ejs @@ -63,7 +63,10 @@
<%= x %>
Last pull: <%= servers[x].lastPull %>
-
<%= servers[x].username %>@<%= servers[x].ip %>
+
<%= servers[x].username %>@<%= servers[x].ip %>
+ +
Connect
+ <% } %> diff --git a/views/keys.ejs b/views/keys.ejs index ff05a36..958675e 100644 --- a/views/keys.ejs +++ b/views/keys.ejs @@ -27,7 +27,7 @@ <%= key.name %> - <%= key.content %> +