🚀 Sync 2026-03-20 14:18:42

This commit is contained in:
github-actions[bot] committed 2026-03-20 14:18:42 +08:00
1 parent 3f5e547363
commit 72b1d9508b
81 files changed
+2797 -975

No files matched your search

@@ -70,31 +70,42 @@ async function loadCodeMirrorResources() {
await loadScripts();
}
var callMosdns = rpc.declare({
object: 'luci.mosdns',
method: 'get_version',
expect: { '': {} }
});
var callFlushCache = rpc.declare({
object: 'luci.mosdns',
method: 'flush_cache',
expect: { '': {} }
});
return view.extend({
load: function () {
return Promise.all([
L.resolveDefault(fs.exec('/usr/bin/mosdns', ['version']), null),
L.resolveDefault(callMosdns(), null),
]);
},
handleFlushCache: function (m, section_id, ev) {
return fs.exec('/usr/share/mosdns/mosdns.sh', ['flush'])
.then(function (lazy_cache) {
var res = lazy_cache.code;
if (res === 0) {
ui.addNotification(null, E('p', _('Flushing DNS Cache Success.')), 'info');
} else {
ui.addNotification(null, E('p', _('Flushing DNS Cache Failed, Please check if MosDNS is running.')), 'error');
}
});
handleFlushCache: function () {
return callFlushCache().then(function(res) {
if (res.success) {
ui.addNotification(null, E('p', _('Flushing DNS Cache Success.')), 'info');
} else {
ui.addNotification(null, E('p', _('Flushing DNS Cache Failed, Please check if MosDNS is running.') + (res.error ? ': ' + res.error : '')), 'error');
}
});
},
render: function (basic) {
render: function (data) {
var m, s, o, v;
v = '';
if (basic[0] && basic[0].code === 0) {
v = basic[0].stdout.trim();
var version = (data[0] && data[0].version) ? data[0].version : null;
if (version) {
v = version;
}
m = new form.Map('mosdns', _('MosDNS') + ' ' + v,
_('MosDNS is a plugin-based DNS forwarder/traffic splitter.'));
@@ -147,6 +158,7 @@ return view.extend({
o.depends('configfile', '/var/etc/mosdns.json');
o = s.taboption('basic', form.Value, 'listen_address', _('Listen Address'));
o.default = '0.0.0.0';
o.depends('configfile', '/var/etc/mosdns.json');
o = s.taboption('basic', form.ListValue, 'log_level', _('Log Level'));
@@ -389,7 +401,7 @@ return view.extend({
/* api */
o = s.taboption('api', form.Value, 'listen_port_api', _('API Listen port'));
o.datatype = 'and(port,min(1))';
o.default = 9091;
o.default = 52001;
o.depends('configfile', '/var/etc/mosdns.json');
o = s.taboption('api', form.Button, '_flush_cache', null,
@@ -397,7 +409,7 @@ return view.extend({
o.title = ' ';
o.inputtitle = _('Flush DNS Cache');
o.inputstyle = 'apply';
o.onclick = L.bind(this.handleFlushCache, this, m);
o.onclick = L.bind(this.handleFlushCache, this);
o.depends('cache', '1');
/* configuration */
@@ -3,18 +3,28 @@
'require fs';
'require poll';
'require view';
'require rpc';
'require ui';
var callPrintLog = rpc.declare({
object: 'luci.mosdns',
method: 'print_log',
expect: { '': {} }
});
var callCleanLog = rpc.declare({
object: 'luci.mosdns',
method: 'clean_log',
expect: { '': {} }
});
var scrollPosition = 0;
var userScrolled = false;
var logTextarea;
function pollLog() {
return Promise.all([
fs.exec_direct('/usr/share/mosdns/mosdns.sh', ['printlog']).then(function (res) {
return res.trim().split(/\n/).join('\n');
}),
]).then(function (data) {
logTextarea.value = data[0] || _('No log data.');
return callPrintLog().then(function (res) {
logTextarea.value = res.log || _('No log data.');
if (!userScrolled) {
logTextarea.scrollTop = logTextarea.scrollHeight;
@@ -26,8 +36,13 @@ function pollLog() {
return view.extend({
handleCleanLogs: function () {
return fs.exec('/usr/share/mosdns/mosdns.sh', ['cleanlog'])
.catch(function (e) { ui.addNotification(null, E('p', e.message)) });
return callCleanLog().then(function(res) {
if (res.success) {
logTextarea.value = ''; // Clear textarea on success
} else {
ui.addNotification(null, E('p', _('Failed to clean logs.') + (res.error ? ': ' + res.error : '')), 'error');
}
}).catch(function (e) { ui.addNotification(null, E('p', e.message)) });
},
render: function () {
@@ -3,6 +3,12 @@
'require fs';
'require ui';
'require view';
'require rpc';
var callRestart = rpc.declare({
object: 'luci.mosdns',
method: 'restart'
});
return view.extend({
render: function () {
@@ -24,6 +30,7 @@ return view.extend({
s.tab('localptrlist', _('Block PTR'));
s.tab('streamingmedialist', _('Streaming Media'));
// --- White Lists ---
o = s.taboption('whitelist', form.TextValue, '_whitelist',
null,
'<font color=\'red\'>'
@@ -41,13 +48,19 @@ return view.extend({
if (value == formvalue) {
return;
}
return fs.write('/etc/mosdns/rule/whitelist.txt', formvalue.trim().replace(/\r\n/g, '\n') + '\n')
return fs.write('/etc/mosdns/rule/whitelist.txt', (formvalue.trim() ? formvalue.trim().replace(/\r\n/g, '\n') + '\n' : ''))
.catch(function (e) {
ui.addNotification(null, E('p', _('Unable to save contents: %s').format(e.message)));
});
});
};
o.remove = function (section_id) {
return fs.write('/etc/mosdns/rule/whitelist.txt', '').catch(function (e) {
ui.addNotification(null, E('p', _('Unable to save contents: %s').format(e.message)));
});
};
// --- Block Lists ---
o = s.taboption('blocklist', form.TextValue, '_blocklist',
null,
'<font color=\'red\'>'
@@ -65,13 +78,19 @@ return view.extend({
if (value == formvalue) {
return;
}
return fs.write('/etc/mosdns/rule/blocklist.txt', formvalue.trim().replace(/\r\n/g, '\n') + '\n')
return fs.write('/etc/mosdns/rule/blocklist.txt', (formvalue.trim() ? formvalue.trim().replace(/\r\n/g, '\n') + '\n' : ''))
.catch(function (e) {
ui.addNotification(null, E('p', _('Unable to save contents: %s').format(e.message)));
});
});
};
o.remove = function (section_id) {
return fs.write('/etc/mosdns/rule/blocklist.txt', '').catch(function (e) {
ui.addNotification(null, E('p', _('Unable to save contents: %s').format(e.message)));
});
};
// --- Grey Lists ---
o = s.taboption('greylist', form.TextValue, '_greylist',
null,
'<font color=\'red\'>'
@@ -89,13 +108,19 @@ return view.extend({
if (value == formvalue) {
return;
}
return fs.write('/etc/mosdns/rule/greylist.txt', formvalue.trim().replace(/\r\n/g, '\n') + '\n')
return fs.write('/etc/mosdns/rule/greylist.txt', (formvalue.trim() ? formvalue.trim().replace(/\r\n/g, '\n') + '\n' : ''))
.catch(function (e) {
ui.addNotification(null, E('p', _('Unable to save contents: %s').format(e.message)));
});
});
};
o.remove = function (section_id) {
return fs.write('/etc/mosdns/rule/greylist.txt', '').catch(function (e) {
ui.addNotification(null, E('p', _('Unable to save contents: %s').format(e.message)));
});
};
// --- DDNS Lists ---
o = s.taboption('ddnslist', form.TextValue, '_ddnslist',
null,
'<font color=\'red\'>'
@@ -113,13 +138,19 @@ return view.extend({
if (value == formvalue) {
return;
}
return fs.write('/etc/mosdns/rule/ddnslist.txt', formvalue.trim().replace(/\r\n/g, '\n') + '\n')
return fs.write('/etc/mosdns/rule/ddnslist.txt', (formvalue.trim() ? formvalue.trim().replace(/\r\n/g, '\n') + '\n' : ''))
.catch(function (e) {
ui.addNotification(null, E('p', _('Unable to save contents: %s').format(e.message)));
});
});
};
o.remove = function (section_id) {
return fs.write('/etc/mosdns/rule/ddnslist.txt', '').catch(function (e) {
ui.addNotification(null, E('p', _('Unable to save contents: %s').format(e.message)));
});
};
// --- Hosts ---
o = s.taboption('hostslist', form.TextValue, '_hostslist',
null,
'<font color=\'red\'>'
@@ -137,13 +168,19 @@ return view.extend({
if (value == formvalue) {
return;
}
return fs.write('/etc/mosdns/rule/hosts.txt', formvalue.trim().replace(/\r\n/g, '\n') + '\n')
return fs.write('/etc/mosdns/rule/hosts.txt', (formvalue.trim() ? formvalue.trim().replace(/\r\n/g, '\n') + '\n' : ''))
.catch(function (e) {
ui.addNotification(null, E('p', _('Unable to save contents: %s').format(e.message)));
});
});
};
o.remove = function (section_id) {
return fs.write('/etc/mosdns/rule/hosts.txt', '').catch(function (e) {
ui.addNotification(null, E('p', _('Unable to save contents: %s').format(e.message)));
});
};
// --- Redirect ---
o = s.taboption('redirectlist', form.TextValue, '_redirectlist',
null,
'<font color=\'red\'>'
@@ -161,13 +198,19 @@ return view.extend({
if (value == formvalue) {
return;
}
return fs.write('/etc/mosdns/rule/redirect.txt', formvalue.trim().replace(/\r\n/g, '\n') + '\n')
return fs.write('/etc/mosdns/rule/redirect.txt', (formvalue.trim() ? formvalue.trim().replace(/\r\n/g, '\n') + '\n' : ''))
.catch(function (e) {
ui.addNotification(null, E('p', _('Unable to save contents: %s').format(e.message)));
});
});
};
o.remove = function (section_id) {
return fs.write('/etc/mosdns/rule/redirect.txt', '').catch(function (e) {
ui.addNotification(null, E('p', _('Unable to save contents: %s').format(e.message)));
});
};
// --- Block PTR ---
o = s.taboption('localptrlist', form.TextValue, '_localptrlist',
null,
'<font color=\'red\'>'
@@ -185,13 +228,19 @@ return view.extend({
if (value == formvalue) {
return;
}
return fs.write('/etc/mosdns/rule/local-ptr.txt', formvalue.trim().replace(/\r\n/g, '\n') + '\n')
return fs.write('/etc/mosdns/rule/local-ptr.txt', (formvalue.trim() ? formvalue.trim().replace(/\r\n/g, '\n') + '\n' : ''))
.catch(function (e) {
ui.addNotification(null, E('p', _('Unable to save contents: %s').format(e.message)));
});
});
};
o.remove = function (section_id) {
return fs.write('/etc/mosdns/rule/local-ptr.txt', '').catch(function (e) {
ui.addNotification(null, E('p', _('Unable to save contents: %s').format(e.message)));
});
};
// --- Streaming Media ---
o = s.taboption('streamingmedialist', form.TextValue, '_streamingmedialist',
null,
'<font color=\'red\'>'
@@ -209,12 +258,17 @@ return view.extend({
if (value == formvalue) {
return;
}
return fs.write('/etc/mosdns/rule/streaming.txt', formvalue.trim().replace(/\r\n/g, '\n') + '\n')
return fs.write('/etc/mosdns/rule/streaming.txt', (formvalue.trim() ? formvalue.trim().replace(/\r\n/g, '\n') + '\n' : ''))
.catch(function (e) {
ui.addNotification(null, E('p', _('Unable to save contents: %s').format(e.message)));
});
});
};
o.remove = function (section_id) {
return fs.write('/etc/mosdns/rule/streaming.txt', '').catch(function (e) {
ui.addNotification(null, E('p', _('Unable to save contents: %s').format(e.message)));
});
};
return m.render();
},
@@ -222,9 +276,13 @@ return view.extend({
handleSaveApply: function (ev) {
var m = this.map;
onclick = L.bind(this.handleSave, this, m);
return fs.exec('/etc/init.d/mosdns', ['restart'])
.then(function () {
window.location.reload();
return callRestart()
.then(function (res) {
if (res && res.code === 0) {
window.location.reload();
} else {
ui.addNotification(null, E('p', _('Failed to restart mosdns: %s').format(res.output || 'Unknown error')));
}
})
.catch(function (e) {
ui.addNotification(null, E('p', _('Failed to restart mosdns: %s').format(e.message)));
@@ -5,16 +5,22 @@
'require view';
return view.extend({
handleUpdate: function (m, section_id, ev) {
return fs.exec('/usr/share/mosdns/mosdns.sh', ['geodata'])
.then(function (i) {
var res = i.code;
if (res === 0) {
handleUpdate: function () {
ui.showModal(_('Updating...'), [
E('p', { 'class': 'spinning' }, _('Please wait, this may take a few moments...')),
]);
return fs.exec('/usr/share/mosdns/mosdns.uc', ['update'])
.then(function (res) {
ui.hideModal();
if (res.code === 0) {
ui.addNotification(null, E('p', _('Update success')), 'info');
} else {
ui.addNotification(null, E('p', i.stderr + '<br />' + i.stdout), 'warn');
ui.addNotification(null, E('p', res.stderr + '<br />' + res.stdout), 'warn');
ui.addNotification(null, E('p', _('Update failed, Please check the network status')), 'error');
}
}).catch(function (e) {
ui.hideModal();
ui.addNotification(null, E('p', _('Update failed: %s').format(e.message)), 'error');
});
},
@@ -68,7 +74,7 @@ return view.extend({
o.title = _('Database Update');
o.inputtitle = _('Check And Update');
o.inputstyle = 'apply';
o.onclick = L.bind(this.handleUpdate, this, m);
o.onclick = L.bind(this.handleUpdate, this);
return m.render();
}