mirror of
https://github.com/kiddin9/op-packages.git
synced 2026-11-17 05:53:03 +08:00
🦄 Sync 2026-09-27 22:25:23
This commit is contained in:
1 parent
67a7165b7e
commit
4c6d0df36f
67 files changed
+415
-8397
No files matched your search
@@ -0,0 +1,356 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
'use strict';
|
||||
'require form';
|
||||
'require fs';
|
||||
'require ui';
|
||||
'require view';
|
||||
'require rpc';
|
||||
'require uci';
|
||||
|
||||
var callFileWrite = rpc.declare({
|
||||
object: 'file',
|
||||
method: 'write',
|
||||
params: [ 'path', 'data' ]
|
||||
});
|
||||
|
||||
var configFile = '/etc/meow/config.yaml';
|
||||
|
||||
return view.extend({
|
||||
editorInstance: null,
|
||||
|
||||
handleSaveApply: function (ev, mode) {
|
||||
var value = document.getElementById('cbid_meow_config__configuration').value;
|
||||
|
||||
if (!value) {
|
||||
ui.addNotification(null, E('p', _('Configuration cannot be empty!')), 'error');
|
||||
return Promise.reject(new Error('Empty configuration'));
|
||||
}
|
||||
|
||||
if (this.editorInstance) {
|
||||
var model = this.editorInstance.getModel();
|
||||
var markers = monaco.editor.getModelMarkers({
|
||||
owner: 'meow-validator',
|
||||
resource: model.uri
|
||||
});
|
||||
|
||||
if (markers && markers.length > 0) {
|
||||
var errorMessages = markers.map(function (marker) {
|
||||
return marker.message + ' ' + _('(Line: %d)').format(marker.startLineNumber);
|
||||
}).join('<br>');
|
||||
|
||||
ui.addNotification(null, E('p', [
|
||||
_('Configuration validation failed!'),
|
||||
E('br'),
|
||||
E('small', errorMessages)
|
||||
]), 'error');
|
||||
|
||||
return Promise.reject(new Error('Invalid configuration'));
|
||||
}
|
||||
}
|
||||
|
||||
return callFileWrite(configFile, value)
|
||||
.then(function () {
|
||||
return L.resolveDefault(
|
||||
fs.exec_direct('/bin/chmod', [ '0600', configFile ]),
|
||||
null
|
||||
);
|
||||
})
|
||||
.then(function () {
|
||||
/*
|
||||
* fs.exec_direct resolves with stdout and rejects
|
||||
* on non-zero exit code.
|
||||
*
|
||||
* It does not return an object containing `code`.
|
||||
* Reload first, restart only when reload fails.
|
||||
*/
|
||||
return fs.exec_direct('/etc/init.d/meow', [ 'reload' ])
|
||||
.catch(function () {
|
||||
return fs.exec_direct('/etc/init.d/meow', [ 'restart' ]);
|
||||
});
|
||||
})
|
||||
.catch(function (e) {
|
||||
ui.addNotification(
|
||||
null,
|
||||
E('p', _('Failed to save configuration: %s').format(e.message))
|
||||
);
|
||||
|
||||
return Promise.reject(e);
|
||||
});
|
||||
},
|
||||
|
||||
load: function () {
|
||||
return fs.read_direct(configFile, 'text')
|
||||
.then(function (content) {
|
||||
return content ?? '';
|
||||
})
|
||||
.catch(function (e) {
|
||||
ui.addNotification(null, E('p', e.message));
|
||||
return '';
|
||||
});
|
||||
},
|
||||
|
||||
render: function (content) {
|
||||
var m, s;
|
||||
var self = this;
|
||||
|
||||
self.formvalue = {};
|
||||
|
||||
var css = E('style', {}, `
|
||||
#code_editor {
|
||||
height: 500px;
|
||||
width: 100%;
|
||||
border: 1px solid #ccc;
|
||||
}
|
||||
#fallback_editor {
|
||||
height: 500px;
|
||||
width: 100%;
|
||||
font-family: monospace;
|
||||
white-space: pre;
|
||||
}
|
||||
@media (prefers-color-scheme: dark) {
|
||||
#code_editor {
|
||||
border-color: #555;
|
||||
}
|
||||
#fallback_editor {
|
||||
background: #1e1e1e;
|
||||
color: #d4d4d4;
|
||||
}
|
||||
}
|
||||
`);
|
||||
|
||||
var editorDiv = E('div', { id: 'code_editor' });
|
||||
|
||||
var hiddenInput = E('input', {
|
||||
type: 'hidden',
|
||||
id: 'cbid_meow_config__configuration',
|
||||
name: 'cbid.meow.config._configuration',
|
||||
value: content
|
||||
});
|
||||
|
||||
m = new form.Map(
|
||||
'meow',
|
||||
_('Configuration'),
|
||||
_('Here you can edit the meow YAML configuration. It will be automatically validated and the service reloaded after apply.')
|
||||
);
|
||||
|
||||
m.onValidate = function (map, data) {
|
||||
self.formvalue = data;
|
||||
};
|
||||
|
||||
m.submitSave = function () {
|
||||
return false;
|
||||
};
|
||||
|
||||
s = m.section(form.TypedSection);
|
||||
s.anonymous = true;
|
||||
|
||||
s.render = function () {
|
||||
return E('div', { 'class': 'cbi-section' }, [
|
||||
css,
|
||||
editorDiv,
|
||||
hiddenInput
|
||||
]);
|
||||
};
|
||||
|
||||
var formEl = m.render();
|
||||
|
||||
window.setTimeout(function () {
|
||||
|
||||
function buildFallbackTextarea(initialValue) {
|
||||
var ta = E('textarea', {
|
||||
id: 'fallback_editor',
|
||||
'style': 'height:500px;width:100%'
|
||||
});
|
||||
|
||||
ta.value = initialValue;
|
||||
|
||||
ta.addEventListener('input', function () {
|
||||
hiddenInput.value = ta.value;
|
||||
self.formvalue.cbid_meow_config__configuration = ta.value;
|
||||
});
|
||||
|
||||
editorDiv.parentNode.replaceChild(ta, editorDiv);
|
||||
}
|
||||
|
||||
var loaderScript = document.createElement('script');
|
||||
loaderScript.src = '/luci-static/resources/monaco-editor/min/vs/loader.js';
|
||||
document.head.appendChild(loaderScript);
|
||||
|
||||
loaderScript.onerror = function () {
|
||||
buildFallbackTextarea(content);
|
||||
};
|
||||
|
||||
loaderScript.onload = function () {
|
||||
require.config({
|
||||
paths: {
|
||||
'vs': '/luci-static/resources/monaco-editor/min/vs'
|
||||
},
|
||||
'vs/nls': {
|
||||
availableLanguages: {
|
||||
'*': 'zh-cn'
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
require([ 'vs/editor/editor.main' ], function () {
|
||||
var prefersDarkMode =
|
||||
window.matchMedia('(prefers-color-scheme: dark)').matches;
|
||||
|
||||
self.editorInstance = monaco.editor.create(
|
||||
document.getElementById('code_editor'),
|
||||
{
|
||||
value: content,
|
||||
language: 'yaml',
|
||||
theme: prefersDarkMode ? 'vs-dark' : 'vs',
|
||||
automaticLayout: true,
|
||||
minimap: { enabled: false },
|
||||
scrollBeyondLastLine: false,
|
||||
lineNumbers: 'on',
|
||||
tabSize: 2,
|
||||
wordWrap: 'on'
|
||||
}
|
||||
);
|
||||
|
||||
var validateTimer = null;
|
||||
|
||||
function validateYamlConfig() {
|
||||
var model = self.editorInstance.getModel();
|
||||
var value = model.getValue();
|
||||
var lines = value.split('\n');
|
||||
var markers = [];
|
||||
|
||||
monaco.editor.setModelMarkers(
|
||||
model,
|
||||
'meow-validator',
|
||||
[]
|
||||
);
|
||||
|
||||
var bracketStack = [];
|
||||
var unmatchedBrackets = [];
|
||||
|
||||
for (var i = 0; i < lines.length; i++) {
|
||||
var line = lines[i];
|
||||
var trimmed = line.trim();
|
||||
|
||||
if (/^\t/.test(line)) {
|
||||
markers.push({
|
||||
severity: monaco.MarkerSeverity.Error,
|
||||
message: _('YAML does not allow tab characters for indentation'),
|
||||
startLineNumber: i + 1,
|
||||
startColumn: 1,
|
||||
endLineNumber: i + 1,
|
||||
endColumn: 2
|
||||
});
|
||||
}
|
||||
|
||||
if (
|
||||
trimmed.startsWith('#') ||
|
||||
trimmed.startsWith('//') ||
|
||||
trimmed === ''
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
|
||||
for (var j = 0; j < line.length; j++) {
|
||||
var ch = line[j];
|
||||
|
||||
if (ch === '{' || ch === '[' || ch === '(') {
|
||||
bracketStack.push({
|
||||
line: i + 1,
|
||||
char: ch,
|
||||
pos: j
|
||||
});
|
||||
} else if (ch === '}' || ch === ']' || ch === ')') {
|
||||
var openChar = {
|
||||
'}': '{',
|
||||
']': '[',
|
||||
')': '('
|
||||
}[ch];
|
||||
|
||||
if (
|
||||
bracketStack.length > 0 &&
|
||||
bracketStack[bracketStack.length - 1].char === openChar
|
||||
) {
|
||||
bracketStack.pop();
|
||||
} else {
|
||||
unmatchedBrackets.push({
|
||||
line: i + 1,
|
||||
pos: j,
|
||||
type: 'closing'
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
unmatchedBrackets.forEach(function (bracket) {
|
||||
markers.push({
|
||||
severity: monaco.MarkerSeverity.Error,
|
||||
message: _('Found unmatched closing bracket'),
|
||||
startLineNumber: bracket.line,
|
||||
startColumn: bracket.pos + 1,
|
||||
endLineNumber: bracket.line,
|
||||
endColumn: bracket.pos + 2
|
||||
});
|
||||
});
|
||||
|
||||
bracketStack.forEach(function (bracket) {
|
||||
markers.push({
|
||||
severity: monaco.MarkerSeverity.Error,
|
||||
message: _('Unclosed bracket'),
|
||||
startLineNumber: bracket.line,
|
||||
startColumn: bracket.pos + 1,
|
||||
endLineNumber: bracket.line,
|
||||
endColumn: bracket.pos + 2
|
||||
});
|
||||
});
|
||||
|
||||
monaco.editor.setModelMarkers(
|
||||
model,
|
||||
'meow-validator',
|
||||
markers
|
||||
);
|
||||
}
|
||||
|
||||
self.editorInstance.onDidChangeModelContent(function () {
|
||||
var value = self.editorInstance.getValue();
|
||||
|
||||
hiddenInput.value = value;
|
||||
|
||||
document.getElementById(
|
||||
'cbid_meow_config__configuration'
|
||||
).value = value;
|
||||
|
||||
self.formvalue.cbid_meow_config__configuration = value;
|
||||
|
||||
if (validateTimer) {
|
||||
clearTimeout(validateTimer);
|
||||
}
|
||||
|
||||
validateTimer = setTimeout(
|
||||
validateYamlConfig,
|
||||
500
|
||||
);
|
||||
});
|
||||
|
||||
setTimeout(validateYamlConfig, 1000);
|
||||
|
||||
window.matchMedia(
|
||||
'(prefers-color-scheme: dark)'
|
||||
).addEventListener('change', function (e) {
|
||||
monaco.editor.setTheme(
|
||||
e.matches ? 'vs-dark' : 'vs'
|
||||
);
|
||||
});
|
||||
|
||||
window.addEventListener('resize', function () {
|
||||
self.editorInstance.layout();
|
||||
});
|
||||
});
|
||||
};
|
||||
}, 100);
|
||||
|
||||
return formEl;
|
||||
}
|
||||
});
|
||||
@@ -0,0 +1,479 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
'use strict';
|
||||
'require dom';
|
||||
'require poll';
|
||||
'require rpc';
|
||||
'require ui';
|
||||
'require view';
|
||||
|
||||
/*
|
||||
* meow (meow-rs) does NOT write a log file on OpenWrt:
|
||||
* its procd init script enables `stdout 1` / `stderr 1`, so all service
|
||||
* output goes into the system log (syslog/logd ring buffer, in /tmp).
|
||||
* This view therefore reads the syslog via the ubus `log` object and
|
||||
* filters lines belonging to the meow service in the frontend.
|
||||
*/
|
||||
|
||||
var callSystemLog = rpc.declare({
|
||||
object: 'log',
|
||||
method: 'read',
|
||||
params: [ 'lines', 'stream' ],
|
||||
expect: {}
|
||||
});
|
||||
|
||||
var serviceTag = 'meow';
|
||||
|
||||
/* syslog is a ring buffer shared by ALL services; read a large window */
|
||||
var LOG_READ_LINES = 500;
|
||||
|
||||
return view.extend({
|
||||
render: function () {
|
||||
/* Thanks to luci-app-aria2 */
|
||||
var css = ' \
|
||||
#log_textarea { \
|
||||
text-align: left; \
|
||||
max-height: 70vh; \
|
||||
overflow-y: auto; \
|
||||
color-scheme: light dark; \
|
||||
background-color: #f8f9fa; \
|
||||
border-radius: 8px; \
|
||||
border: 1px solid #ddd; \
|
||||
font-size: 13px; \
|
||||
box-shadow: 0 2px 5px rgba(0,0,0,0.05); \
|
||||
} \
|
||||
#log_textarea pre { \
|
||||
padding: .7rem; \
|
||||
word-break: break-all; \
|
||||
margin: 0; \
|
||||
font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace; \
|
||||
line-height: 1.4; \
|
||||
} \
|
||||
.log-info { color: #0366d6; } \
|
||||
.log-warn { color: #f59f00; } \
|
||||
.log-error { color: #d73a49; font-weight: bold; } \
|
||||
.log-debug { color: #6f42c1; } \
|
||||
.log-ip { color: #22863a; font-weight: bold; } \
|
||||
.log-container { \
|
||||
padding: 2px 0; \
|
||||
} \
|
||||
.log-container:hover { \
|
||||
background-color: rgba(0,0,0,0.03); \
|
||||
} \
|
||||
.controls-container { \
|
||||
margin-bottom: 15px; \
|
||||
display: flex; \
|
||||
flex-wrap: wrap; \
|
||||
gap: 10px; \
|
||||
} \
|
||||
.controls-row { \
|
||||
display: flex; \
|
||||
gap: 10px; \
|
||||
flex-wrap: wrap; \
|
||||
margin-bottom: 10px; \
|
||||
} \
|
||||
.controls-row:last-child { \
|
||||
margin-bottom: 0; \
|
||||
} \
|
||||
#filterInput { \
|
||||
max-width: 200px; \
|
||||
flex: 1; \
|
||||
min-width: 120px; \
|
||||
padding: 5px; \
|
||||
border-radius: 4px; \
|
||||
border: 1px solid #ddd; \
|
||||
} \
|
||||
.filter-highlight { \
|
||||
background-color: #ffeb3b; \
|
||||
color: black; \
|
||||
padding: 0 2px; \
|
||||
border-radius: 3px; \
|
||||
font-weight: bold; \
|
||||
} \
|
||||
#log_textarea::-webkit-scrollbar { \
|
||||
width: 10px; \
|
||||
} \
|
||||
#log_textarea::-webkit-scrollbar-track {\
|
||||
background: rgba(0, 0, 0, 0.03); \
|
||||
border-radius: 4px; \
|
||||
} \
|
||||
#log_textarea::-webkit-scrollbar-thumb {\
|
||||
background: rgba(0, 0, 0, 0.15); \
|
||||
border-radius: 4px; \
|
||||
border: 2px solid #f8f9fa; \
|
||||
} \
|
||||
#log_textarea::-webkit-scrollbar-thumb:hover {\
|
||||
background: rgba(0, 0, 0, 0.25); \
|
||||
} \
|
||||
@media (prefers-color-scheme: dark) { \
|
||||
#log_textarea { \
|
||||
background-color: #252a30; \
|
||||
border-color: #444; \
|
||||
color: #e6e6e6; \
|
||||
} \
|
||||
.log-container:hover { \
|
||||
background-color: rgba(255,255,255,0.05); \
|
||||
} \
|
||||
.filter-highlight { \
|
||||
background-color: #b58b00; \
|
||||
color: #ffffff; \
|
||||
} \
|
||||
.log-info { color: #58a6ff; } \
|
||||
.log-warn { color: #ffab70; } \
|
||||
.log-error { color: #f97583; } \
|
||||
.log-debug { color: #d2a8ff; } \
|
||||
.log-ip { color: #7ee787; } \
|
||||
#log_textarea::-webkit-scrollbar-track {\
|
||||
background: rgba(255, 255, 255, 0.03);\
|
||||
} \
|
||||
#log_textarea::-webkit-scrollbar-thumb {\
|
||||
background: rgba(255, 255, 255, 0.15);\
|
||||
border: 2px solid #252a30; \
|
||||
} \
|
||||
#log_textarea::-webkit-scrollbar-thumb:hover {\
|
||||
background: rgba(255, 255, 255, 0.25);\
|
||||
} \
|
||||
#filterInput { \
|
||||
background-color: #252a30; \
|
||||
border-color: #444; \
|
||||
color: #e6e6e6; \
|
||||
} \
|
||||
} \
|
||||
@media (min-width: 768px) { \
|
||||
.controls-container { \
|
||||
flex-direction: row; \
|
||||
flex-wrap: nowrap; \
|
||||
} \
|
||||
.controls-row { \
|
||||
margin-bottom: 0; \
|
||||
flex: 1; \
|
||||
} \
|
||||
.controls-row:first-child { \
|
||||
flex: 2; \
|
||||
} \
|
||||
}';
|
||||
|
||||
var log_textarea = E('div', { 'id': 'log_textarea' },
|
||||
E('img', {
|
||||
'src': L.resource('icons/loading.gif'),
|
||||
'alt': _('Loading...'),
|
||||
'style': 'vertical-align:middle'
|
||||
}, _('Collecting data…'))
|
||||
);
|
||||
|
||||
function escapeHtml(s) {
|
||||
return s.replace(/&/g, '&')
|
||||
.replace(/</g, '<')
|
||||
.replace(/>/g, '>');
|
||||
}
|
||||
|
||||
function formatLogLine(line) {
|
||||
/* strip ANSI escape sequences (meow writes colored tracing
|
||||
* output to stderr; procd captures it verbatim into syslog) */
|
||||
line = line.replace(/\x1b\[[0-9;]*m/g, '');
|
||||
|
||||
line = escapeHtml(line);
|
||||
|
||||
line = line
|
||||
.replace(/\b(error|failed)\b/g, '<span class="log-error">$1</span>')
|
||||
.replace(/\b(warn|warning)\b/g, '<span class="log-warn">$1</span>')
|
||||
.replace(/\b(info|INFO)\b/g, '<span class="log-info">$1</span>')
|
||||
.replace(/\b(debug|DEBUG)\b/g, '<span class="log-debug">$1</span>');
|
||||
|
||||
line = line.replace(/(\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b)/g,
|
||||
'<span class="log-ip">$1</span>');
|
||||
|
||||
return '<div class="log-container">' + line + '</div>';
|
||||
}
|
||||
|
||||
var originalLogContent = '';
|
||||
var logEntriesCache = null;
|
||||
var debounceTimeout = null;
|
||||
var isPaused = false;
|
||||
|
||||
/* ---- Clear Log (view-level) state ----
|
||||
* clearCutoff: null = never cleared; otherwise either
|
||||
* { id: <max syslog entry id> } (preferred, logd provides `id`)
|
||||
* { time: <max epoch sec> } (fallback when `id` is absent) */
|
||||
var clearCutoff = null;
|
||||
var maxSeenId = -1;
|
||||
var maxSeenTime = -1;
|
||||
|
||||
function debounce(func, wait) {
|
||||
return function (...args) {
|
||||
const context = this;
|
||||
clearTimeout(debounceTimeout);
|
||||
debounceTimeout = setTimeout(() => {
|
||||
func.apply(context, args);
|
||||
}, wait);
|
||||
};
|
||||
}
|
||||
|
||||
var tagRegex = new RegExp('\\b' + serviceTag + '\\b');
|
||||
|
||||
poll.add(L.bind(function () {
|
||||
if (isPaused) {
|
||||
return Promise.resolve();
|
||||
}
|
||||
|
||||
return callSystemLog(LOG_READ_LINES, false)
|
||||
.then(function (res) {
|
||||
var entries;
|
||||
if (Array.isArray(res))
|
||||
entries = res;
|
||||
else if (res && Array.isArray(res.log))
|
||||
entries = res.log;
|
||||
else if (res && Array.isArray(res.lines))
|
||||
entries = res.lines;
|
||||
else
|
||||
entries = [];
|
||||
|
||||
var meowLines = [];
|
||||
|
||||
for (var i = 0; i < entries.length; i++) {
|
||||
var e = entries[i];
|
||||
if (!e) continue;
|
||||
|
||||
/* Track newest id/time seen; Clear uses them as cut-off. */
|
||||
if (typeof e.id === 'number' && e.id > maxSeenId)
|
||||
maxSeenId = e.id;
|
||||
if (typeof e.time === 'number' && e.time > maxSeenTime)
|
||||
maxSeenTime = e.time;
|
||||
|
||||
/* Hide everything at/below the clear point. */
|
||||
if (clearCutoff) {
|
||||
if (clearCutoff.id !== undefined &&
|
||||
typeof e.id === 'number' && e.id <= clearCutoff.id)
|
||||
continue;
|
||||
if (clearCutoff.time !== undefined &&
|
||||
typeof e.time === 'number' && e.time < clearCutoff.time)
|
||||
continue;
|
||||
}
|
||||
|
||||
var data = e.msg || e.data || '';
|
||||
if (data && tagRegex.test(data))
|
||||
meowLines.push(data);
|
||||
}
|
||||
|
||||
/* Show newest syslog entries first, newest at top. */
|
||||
meowLines.reverse();
|
||||
|
||||
var formattedLines = meowLines.map(function (line) {
|
||||
return formatLogLine(line);
|
||||
});
|
||||
|
||||
var formattedContent = formattedLines.join('');
|
||||
originalLogContent = formattedContent;
|
||||
logEntriesCache = null;
|
||||
|
||||
var logContainer = E('pre', {});
|
||||
logContainer.innerHTML = formattedContent ||
|
||||
(clearCutoff
|
||||
? _('Log cleared. New meow entries will appear below.')
|
||||
: _('Log is empty (no meow entries in the system log yet).'));
|
||||
|
||||
dom.content(log_textarea, logContainer);
|
||||
|
||||
var filterInput = document.getElementById('filterInput');
|
||||
if (filterInput && filterInput.value) {
|
||||
applyFilter(filterInput.value);
|
||||
}
|
||||
}).catch(function (e) {
|
||||
var log;
|
||||
|
||||
if (e.toString().includes('AccessDenied'))
|
||||
log = E('pre', { 'wrap': 'pre' }, [
|
||||
_('Access denied: add "log": ["read"] to the ACL of luci-app-meow, then log in again.')
|
||||
]);
|
||||
else
|
||||
log = E('pre', { 'wrap': 'pre' }, [
|
||||
_('Unknown error: %s').format(e)
|
||||
]);
|
||||
|
||||
dom.content(log_textarea, log);
|
||||
});
|
||||
}));
|
||||
|
||||
function cacheLogEntries() {
|
||||
if (logEntriesCache) return logEntriesCache;
|
||||
|
||||
var logContainer = document.getElementById('log_textarea');
|
||||
var entries = logContainer.querySelectorAll('.log-container');
|
||||
logEntriesCache = [];
|
||||
|
||||
entries.forEach(function (entry) {
|
||||
logEntriesCache.push({
|
||||
element: entry,
|
||||
text: entry.textContent.toLowerCase(),
|
||||
originalHtml: entry.innerHTML
|
||||
});
|
||||
});
|
||||
|
||||
return logEntriesCache;
|
||||
}
|
||||
|
||||
function applyFilter(filter) {
|
||||
if (!filter) {
|
||||
var logContainer = document.getElementById('log_textarea');
|
||||
var preElem = logContainer.querySelector('pre');
|
||||
if (preElem) {
|
||||
preElem.innerHTML = originalLogContent ||
|
||||
_('Log is empty.');
|
||||
logEntriesCache = null;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
filter = filter.toLowerCase();
|
||||
var entries = cacheLogEntries();
|
||||
var matchCount = 0;
|
||||
|
||||
requestAnimationFrame(function () {
|
||||
entries.forEach(function (entry) {
|
||||
if (entry.text.includes(filter)) {
|
||||
matchCount++;
|
||||
|
||||
/* Rebuild from plain textContent (already escaped
|
||||
* source); never run a regex over the highlighted
|
||||
* HTML itself. */
|
||||
var plain = entry.element.textContent;
|
||||
var safeText = escapeHtml(plain);
|
||||
var safeFilter = escapeHtml(filter)
|
||||
.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
||||
var re = new RegExp('(' + safeFilter + ')', 'gi');
|
||||
|
||||
entry.element.innerHTML =
|
||||
safeText.replace(re,
|
||||
'<span class="filter-highlight">$1</span>');
|
||||
entry.element.style.display = '';
|
||||
} else {
|
||||
entry.element.style.display = 'none';
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
var scrollDownButton = E('button', {
|
||||
'id': 'scrollDownButton',
|
||||
'class': 'cbi-button cbi-button-neutral',
|
||||
}, _('Scroll to tail', 'scroll to bottom (the tail) of the log file')
|
||||
);
|
||||
scrollDownButton.addEventListener('click', function () {
|
||||
var logContainer = document.getElementById('log_textarea');
|
||||
if (logContainer) {
|
||||
logContainer.scrollTop = logContainer.scrollHeight;
|
||||
}
|
||||
});
|
||||
|
||||
var scrollUpButton = E('button', {
|
||||
'id': 'scrollUpButton',
|
||||
'class': 'cbi-button cbi-button-neutral',
|
||||
}, _('Scroll to head', 'scroll to top (the head) of the log file')
|
||||
);
|
||||
scrollUpButton.addEventListener('click', function () {
|
||||
var logContainer = document.getElementById('log_textarea');
|
||||
if (logContainer) {
|
||||
logContainer.scrollTop = 0;
|
||||
}
|
||||
});
|
||||
|
||||
var clearFilterButton = E('button', {
|
||||
'id': 'clearFilterButton',
|
||||
'class': 'cbi-button cbi-button-neutral',
|
||||
}, _('Clear Filter')
|
||||
);
|
||||
|
||||
var refreshToggleButton = E('button', {
|
||||
'id': 'refreshToggleButton',
|
||||
'class': 'cbi-button cbi-button-neutral',
|
||||
}, '⏸ ' + _('Pause Refresh'));
|
||||
|
||||
refreshToggleButton.addEventListener('click', function () {
|
||||
isPaused = !isPaused;
|
||||
if (isPaused) {
|
||||
refreshToggleButton.innerHTML = '▶ ' + _('Resume Refresh');
|
||||
refreshToggleButton.className = 'cbi-button cbi-button-positive';
|
||||
} else {
|
||||
refreshToggleButton.innerHTML = '⏸ ' + _('Pause Refresh');
|
||||
refreshToggleButton.className = 'cbi-button cbi-button-neutral';
|
||||
}
|
||||
});
|
||||
|
||||
var filterInput = E('input', {
|
||||
'id': 'filterInput',
|
||||
'type': 'text',
|
||||
'placeholder': _('Filter logs...'),
|
||||
'style': 'padding: 5px; border-radius: 4px; border: 1px solid #ddd; width: 200px;'
|
||||
});
|
||||
|
||||
filterInput.addEventListener('input', debounce(function () {
|
||||
var filter = this.value;
|
||||
applyFilter(filter);
|
||||
}, 200));
|
||||
|
||||
clearFilterButton.addEventListener('click', function () {
|
||||
var filterInput = document.getElementById('filterInput');
|
||||
if (filterInput) {
|
||||
filterInput.value = '';
|
||||
applyFilter('');
|
||||
logEntriesCache = null;
|
||||
}
|
||||
});
|
||||
|
||||
/* ---- Clear Log button (view-level, no modal) ----
|
||||
* Uses addEventListener — the same mechanism as every other button on
|
||||
* this page, which is proven to work on this build. */
|
||||
var clearLogButton = E('button', {
|
||||
'id': 'clearLogButton',
|
||||
'class': 'cbi-button cbi-button-negative',
|
||||
'title': _('Hides all currently displayed meow entries in this view. The system log itself is not modified.')
|
||||
}, _('Clear Log'));
|
||||
|
||||
clearLogButton.addEventListener('click', function () {
|
||||
if (maxSeenId >= 0)
|
||||
clearCutoff = { id: maxSeenId };
|
||||
else if (maxSeenTime >= 0)
|
||||
clearCutoff = { time: maxSeenTime };
|
||||
else
|
||||
clearCutoff = { time: Math.floor(Date.now() / 1000) };
|
||||
|
||||
logEntriesCache = null;
|
||||
|
||||
dom.content(log_textarea,
|
||||
E('pre', {}, _('Log cleared. New meow entries will appear below.')));
|
||||
|
||||
ui.addNotification(null,
|
||||
E('p', {}, _('Meow log view cleared (system log untouched).')),
|
||||
'info');
|
||||
});
|
||||
|
||||
return E([
|
||||
E('style', [css]),
|
||||
E('h2', {}, [_('Log')]),
|
||||
E('div', { 'class': 'cbi-map' }, [
|
||||
E('div', { 'class': 'controls-container' }, [
|
||||
E('div', { 'class': 'controls-row' }, [
|
||||
filterInput,
|
||||
clearFilterButton,
|
||||
refreshToggleButton
|
||||
]),
|
||||
E('div', { 'class': 'controls-row' }, [
|
||||
scrollUpButton,
|
||||
scrollDownButton,
|
||||
clearLogButton
|
||||
])
|
||||
]),
|
||||
E('div', { 'class': 'cbi-section' }, [
|
||||
log_textarea,
|
||||
E('div', { 'style': 'text-align:right; margin-top: 5px;' },
|
||||
E('small', {}, _('Refresh every %s seconds.').format(L.env.pollinterval))
|
||||
)
|
||||
])
|
||||
])
|
||||
]);
|
||||
},
|
||||
|
||||
handleSaveApply: null,
|
||||
handleSave: null,
|
||||
handleReset: null
|
||||
});
|
||||
@@ -0,0 +1,39 @@
|
||||
'use strict';
|
||||
'require view';
|
||||
'require uci';
|
||||
|
||||
// Embeds meow's built-in web panel (served by the meow REST API at /ui)
|
||||
// instead of reimplementing a dashboard in LuCI. The panel port comes from
|
||||
// the `panel_port` UCI option, which must match the `external-controller`
|
||||
// port in the meow YAML config.
|
||||
|
||||
return view.extend({
|
||||
load: function() {
|
||||
return uci.load('meow');
|
||||
},
|
||||
|
||||
render: function() {
|
||||
var port = uci.get('meow', 'main', 'panel_port') || '9090';
|
||||
var url = window.location.protocol + '//' +
|
||||
window.location.hostname + ':' + port + '/ui';
|
||||
|
||||
return E('div', { 'class': 'cbi-map' }, [
|
||||
E('h2', {}, _('meow Panel')),
|
||||
E('div', { 'class': 'cbi-map-descr' }, [
|
||||
_('Built-in web panel served by the meow REST API. '),
|
||||
E('a', { 'href': url, 'target': '_blank', 'rel': 'noopener' },
|
||||
_('Open in a new tab')),
|
||||
' — ', url
|
||||
]),
|
||||
E('iframe', {
|
||||
'src': url,
|
||||
'style': 'width: 100%; min-height: 75vh; border: none;' +
|
||||
' border-radius: 3px; background: #0f1923;'
|
||||
})
|
||||
]);
|
||||
},
|
||||
|
||||
handleSave: null,
|
||||
handleSaveApply: null,
|
||||
handleReset: null
|
||||
});
|
||||
@@ -0,0 +1,112 @@
|
||||
'use strict';
|
||||
'require view';
|
||||
'require form';
|
||||
'require rpc';
|
||||
'require poll';
|
||||
'require uci';
|
||||
|
||||
var callServiceList = rpc.declare({
|
||||
object: 'service',
|
||||
method: 'list',
|
||||
params: [ 'name' ],
|
||||
expect: { '': {} }
|
||||
});
|
||||
|
||||
function getServiceStatus() {
|
||||
return L.resolveDefault(callServiceList('meow'), {}).then(function(res) {
|
||||
try {
|
||||
var instances = res.meow.instances;
|
||||
if (!instances)
|
||||
return false;
|
||||
|
||||
for (var key in instances) {
|
||||
if (instances[key].running === true)
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
catch (e) {
|
||||
return false;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function renderStatus(running) {
|
||||
return running
|
||||
? E('span', { 'style': 'color:#2e7d32;font-weight:bold;' }, _('RUNNING'))
|
||||
: E('span', { 'style': 'color:#c62828;font-weight:bold;' }, _('NOT RUNNING'));
|
||||
}
|
||||
|
||||
return view.extend({
|
||||
load: function() {
|
||||
return uci.load('meow');
|
||||
},
|
||||
|
||||
render: function() {
|
||||
var m, s, o;
|
||||
|
||||
m = new form.Map(
|
||||
'meow',
|
||||
_('meow'),
|
||||
_('Rule-based tunneling proxy kernel, compatible with mihomo (Clash Meta). ' +
|
||||
'Proxies, rules and DNS are configured in the YAML file below; ' +
|
||||
'use the Panel tab for runtime control.'));
|
||||
|
||||
s = m.section(form.NamedSection, 'main', 'meow');
|
||||
|
||||
/* ---- Status ---- */
|
||||
o = s.option(form.DummyValue, '_status', _('Status'));
|
||||
o.rawhtml = true;
|
||||
o.cfgvalue = function() {
|
||||
var node = E('span', {}, _('Collecting data…'));
|
||||
|
||||
poll.add(function() {
|
||||
return getServiceStatus().then(function(running) {
|
||||
while (node.firstChild)
|
||||
node.removeChild(node.firstChild);
|
||||
|
||||
node.appendChild(renderStatus(running));
|
||||
});
|
||||
});
|
||||
|
||||
return node;
|
||||
};
|
||||
|
||||
/* ---- Basic ---- */
|
||||
o = s.option(form.Flag, 'enabled', _('Enable'), _('Start the service at boot.'));
|
||||
o.rmempty = false;
|
||||
|
||||
o = s.option(form.Value, 'config_file', _('Configuration file'));
|
||||
o.default = '/etc/meow/config.yaml';
|
||||
o.rmempty = false;
|
||||
|
||||
o = s.option(form.Value, 'work_dir', _('Working directory'));
|
||||
o.default = '/etc/meow';
|
||||
o.rmempty = false;
|
||||
|
||||
o = s.option(form.Value, 'panel_port', _('Panel port'));
|
||||
o.datatype = 'port';
|
||||
o.default = '9090';
|
||||
o.rmempty = false;
|
||||
|
||||
/* ---- Transparent gateway ---- */
|
||||
o = s.option(form.Flag, 'gateway', _('Transparent gateway'));
|
||||
o.default = false;
|
||||
o.enabled = '1';
|
||||
o.disabled = '0';
|
||||
o.rmempty = false;
|
||||
|
||||
o = s.option(form.Value, 'tproxy_port', _('tproxy port'));
|
||||
o.datatype = 'port';
|
||||
o.default = '7893';
|
||||
o.depends('gateway', '1');
|
||||
|
||||
o = s.option(form.Value, 'dns_port', _('DNS hijack port'));
|
||||
o.datatype = 'port';
|
||||
o.default = '1053';
|
||||
o.depends('gateway', '1');
|
||||
|
||||
return m.render();
|
||||
}
|
||||
});
|
||||
Reference in new issue
Block a user