mirror of
https://github.com/openwrt/luci.git
synced 2025-12-21 19:14:34 +04:00
luci-mod-system: minor code fixes for repokeys and sshkeys
Signed-off-by: Paul Donald <newtwen+github@gmail.com>
(cherry picked from commit 850867b6e4)
This commit is contained in:
@@ -19,7 +19,7 @@ const safeList = [
|
||||
];
|
||||
|
||||
function isFileInSafeList(file){
|
||||
for (name of safeList) {
|
||||
for (let name of safeList) {
|
||||
if (file === name)
|
||||
return true;
|
||||
}
|
||||
@@ -27,7 +27,7 @@ function isFileInSafeList(file){
|
||||
}
|
||||
|
||||
function normalizeKey(s) {
|
||||
return s.replace(/\s+/g, ' ').trim();
|
||||
return s?.replace(/\s+/g, ' ')?.trim();
|
||||
}
|
||||
|
||||
function determineKeyEnv() {
|
||||
@@ -51,10 +51,16 @@ function listKeyFiles() {
|
||||
);
|
||||
}
|
||||
|
||||
function safeText(str) {
|
||||
return String(str).replace(/[&<>"']/g, s => ({
|
||||
'&': '&', '<': '<', '>': '>', '"': '"', "'": '''
|
||||
}[s]));
|
||||
}
|
||||
|
||||
function renderKeyItem(pubkey) {
|
||||
const safeFile = isFileInSafeList(pubkey?.filename);
|
||||
const lines = pubkey?.key?.trim()?.split('\n').map(line =>
|
||||
[ E('br'), E('code', line) ]
|
||||
[ E('br'), E('code', {}, [ safeText(line) ]) ]
|
||||
).flat();
|
||||
return E('div', {
|
||||
class: 'item',
|
||||
@@ -62,7 +68,7 @@ function renderKeyItem(pubkey) {
|
||||
'data-file': pubkey?.filename,
|
||||
'data-key': normalizeKey(pubkey?.key)
|
||||
}, [
|
||||
E('strong', [ pubkey?.filename || _('Unnamed key') ]),
|
||||
E('strong', {}, [ pubkey?.filename || _('Unnamed key') ]),
|
||||
...lines
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -118,14 +118,14 @@ function renderKeyItem(pubkey) {
|
||||
click: isReadonlyView ? null : removeKey,
|
||||
'data-key': pubkey.src
|
||||
}, [
|
||||
E('strong', [ pubkey.comment || _('Unnamed key') ]), E('br'),
|
||||
E('small', [
|
||||
E('strong', {}, [ pubkey.comment || _('Unnamed key') ]), E('br'),
|
||||
E('small', {}, [
|
||||
'%s, %s'.format(pubkey.type, pubkey.curve || _('%d Bit').format(pubkey.bits)),
|
||||
pubkey.options ? E([], [
|
||||
pubkey.options ? E([], {}, [
|
||||
' / ', _('Options:'), ' ',
|
||||
E('code', Object.keys(pubkey.options).sort().join(', '))
|
||||
E('code', {}, [Object.keys(pubkey.options).sort().join(', ')])
|
||||
]) : '',
|
||||
E('br'), E('code', pubkey.fprint)
|
||||
E('br'), E('code', {}, [pubkey.fprint])
|
||||
])
|
||||
]);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user