mirror of
https://github.com/openwrt/luci.git
synced 2025-12-21 21:24:35 +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){
|
function isFileInSafeList(file){
|
||||||
for (name of safeList) {
|
for (let name of safeList) {
|
||||||
if (file === name)
|
if (file === name)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -27,7 +27,7 @@ function isFileInSafeList(file){
|
|||||||
}
|
}
|
||||||
|
|
||||||
function normalizeKey(s) {
|
function normalizeKey(s) {
|
||||||
return s.replace(/\s+/g, ' ').trim();
|
return s?.replace(/\s+/g, ' ')?.trim();
|
||||||
}
|
}
|
||||||
|
|
||||||
function determineKeyEnv() {
|
function determineKeyEnv() {
|
||||||
@@ -51,10 +51,16 @@ function listKeyFiles() {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function safeText(str) {
|
||||||
|
return String(str).replace(/[&<>"']/g, s => ({
|
||||||
|
'&': '&', '<': '<', '>': '>', '"': '"', "'": '''
|
||||||
|
}[s]));
|
||||||
|
}
|
||||||
|
|
||||||
function renderKeyItem(pubkey) {
|
function renderKeyItem(pubkey) {
|
||||||
const safeFile = isFileInSafeList(pubkey?.filename);
|
const safeFile = isFileInSafeList(pubkey?.filename);
|
||||||
const lines = pubkey?.key?.trim()?.split('\n').map(line =>
|
const lines = pubkey?.key?.trim()?.split('\n').map(line =>
|
||||||
[ E('br'), E('code', line) ]
|
[ E('br'), E('code', {}, [ safeText(line) ]) ]
|
||||||
).flat();
|
).flat();
|
||||||
return E('div', {
|
return E('div', {
|
||||||
class: 'item',
|
class: 'item',
|
||||||
@@ -62,7 +68,7 @@ function renderKeyItem(pubkey) {
|
|||||||
'data-file': pubkey?.filename,
|
'data-file': pubkey?.filename,
|
||||||
'data-key': normalizeKey(pubkey?.key)
|
'data-key': normalizeKey(pubkey?.key)
|
||||||
}, [
|
}, [
|
||||||
E('strong', [ pubkey?.filename || _('Unnamed key') ]),
|
E('strong', {}, [ pubkey?.filename || _('Unnamed key') ]),
|
||||||
...lines
|
...lines
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -118,14 +118,14 @@ function renderKeyItem(pubkey) {
|
|||||||
click: isReadonlyView ? null : removeKey,
|
click: isReadonlyView ? null : removeKey,
|
||||||
'data-key': pubkey.src
|
'data-key': pubkey.src
|
||||||
}, [
|
}, [
|
||||||
E('strong', [ pubkey.comment || _('Unnamed key') ]), E('br'),
|
E('strong', {}, [ pubkey.comment || _('Unnamed key') ]), E('br'),
|
||||||
E('small', [
|
E('small', {}, [
|
||||||
'%s, %s'.format(pubkey.type, pubkey.curve || _('%d Bit').format(pubkey.bits)),
|
'%s, %s'.format(pubkey.type, pubkey.curve || _('%d Bit').format(pubkey.bits)),
|
||||||
pubkey.options ? E([], [
|
pubkey.options ? E([], {}, [
|
||||||
' / ', _('Options:'), ' ',
|
' / ', _('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