-
Notifications
You must be signed in to change notification settings - Fork 240
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: sbwml <admin@cooluc.com>
- Loading branch information
Showing
36 changed files
with
956 additions
and
698 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
359 changes: 359 additions & 0 deletions
359
luci-app-mosdns/htdocs/luci-static/resources/view/mosdns/basic.js
Large diffs are not rendered by default.
Oops, something went wrong.
77 changes: 77 additions & 0 deletions
77
luci-app-mosdns/htdocs/luci-static/resources/view/mosdns/logs.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
'use strict'; | ||
'require dom'; | ||
'require fs'; | ||
'require poll'; | ||
'require view'; | ||
|
||
function pollLog(e) { | ||
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) { | ||
var logTextarea = E('textarea', { 'class': 'cbi-input-textarea', 'wrap': 'off', 'readonly': 'readonly', 'style': 'width: calc(100% - 20px);height: 645px;margin: 10px;overflow-y: scroll;' }, [ | ||
data[0] || _('No log data.') | ||
]); | ||
|
||
// Store the current scroll position | ||
var storedScrollTop = e.querySelector('textarea') ? e.querySelector('textarea').scrollTop : null; | ||
|
||
dom.content(e, logTextarea); | ||
|
||
// If the storedScrollTop is not null, it means we have a previous scroll position | ||
if (storedScrollTop !== null) { | ||
logTextarea.scrollTop = storedScrollTop; | ||
} | ||
|
||
// Add event listener to save the scroll position when scrolling stops | ||
var timer; | ||
logTextarea.addEventListener('scroll', function () { | ||
clearTimeout(timer); | ||
timer = setTimeout(function () { | ||
storeScrollPosition(logTextarea.scrollTop); | ||
}, 150); | ||
}); | ||
|
||
function storeScrollPosition(scrollPos) { | ||
localStorage.setItem("scrollPosition", JSON.stringify({ "log": scrollPos })); | ||
} | ||
|
||
}); | ||
}; | ||
|
||
return view.extend({ | ||
handleCleanLogs: function () { | ||
return fs.exec('/usr/share/mosdns/mosdns.sh', ['cleanlog']) | ||
.catch(function (e) { ui.addNotification(null, E('p', e.message)) }); | ||
}, | ||
|
||
render: function () { | ||
var log_textarea = E('div', { 'id': 'log_textarea' }, | ||
E('img', { | ||
'src': L.resource(['icons/loading.gif']), | ||
'alt': _('Loading'), | ||
'style': 'vertical-align:middle' | ||
}, _('Collecting data...')) | ||
); | ||
|
||
poll.add(pollLog.bind(this, log_textarea)); | ||
var clear_logs_button = E('input', { 'class': 'btn cbi-button-action', 'type': 'button', 'style': 'margin-left: 10px; margin-top: 10px;', 'value': _('Clear logs') }); | ||
clear_logs_button.addEventListener('click', this.handleCleanLogs.bind(this)); | ||
return E([ | ||
E('div', { 'class': 'cbi-map' }, [ | ||
E('h2', { 'name': 'content' }, '%s - %s'.format(_('MosDNS'), _('Log Data'))), | ||
E('div', { 'class': 'cbi-section' }, [ | ||
clear_logs_button, | ||
log_textarea, | ||
E('div', { 'style': 'text-align:right' }, | ||
E('small', {}, _('Refresh every %s seconds.').format(L.env.pollinterval)) | ||
) | ||
])]) | ||
]); | ||
}, | ||
|
||
handleSave: null, | ||
handleSaveApply: null, | ||
handleReset: null | ||
}); |
251 changes: 251 additions & 0 deletions
251
luci-app-mosdns/htdocs/luci-static/resources/view/mosdns/rules.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,251 @@ | ||
'use strict'; | ||
'require form'; | ||
'require fs'; | ||
'require ui'; | ||
'require view'; | ||
|
||
return view.extend({ | ||
render: function () { | ||
var m, s, o; | ||
|
||
m = new form.Map("mosdns", _("Rule Settings"), | ||
_('The list of rules only apply to \'Default Config\' profiles.')); | ||
|
||
s = m.section(form.TypedSection); | ||
s.anonymous = true; | ||
s.sortable = true; | ||
|
||
s.tab('whitelist', _('White Lists')); | ||
s.tab('blocklist', _('Block Lists')); | ||
s.tab('greylist', _('Grey Lists')); | ||
s.tab('ddnslist', _('DDNS Lists')); | ||
s.tab('hostslist', _('Hosts')); | ||
s.tab('redirectlist', _('Redirect')); | ||
s.tab('localptrlist', _('Block PTR')); | ||
s.tab('streamingmedialist', _('Streaming Media')); | ||
|
||
o = s.taboption('whitelist', form.TextValue, '_whitelist', | ||
null, | ||
'<font color=\'red\'>' | ||
+ _('Added domain names always permit resolution using \'local DNS\' with the highest priority (one domain per line, supports domain matching rules).') | ||
+ '</font>' | ||
); | ||
o.rows = 25; | ||
o.cfgvalue = function (section_id) { | ||
return fs.trimmed('/etc/mosdns/rule/whitelist.txt').catch(function (e) { | ||
return ""; | ||
}); | ||
}; | ||
o.write = function (section_id, formvalue) { | ||
return this.cfgvalue(section_id).then(function (value) { | ||
if (value == formvalue) { | ||
return; | ||
} | ||
return fs.write('/etc/mosdns/rule/whitelist.txt', formvalue.trim().replace(/\r\n/g, '\n') + '\n') | ||
.then(function (i) { | ||
ui.addNotification(null, E('p', _('Rules have been saved.')), 'info'); | ||
}) | ||
.catch(function (e) { | ||
ui.addNotification(null, E('p', _('Unable to save contents: %s').format(e.message))); | ||
}); | ||
}); | ||
}; | ||
|
||
o = s.taboption('blocklist', form.TextValue, '_blocklist', | ||
null, | ||
'<font color=\'red\'>' | ||
+ _('Added domain names will block DNS resolution (one domain per line, supports domain matching rules).') | ||
+ '</font>' | ||
); | ||
o.rows = 25; | ||
o.cfgvalue = function (section_id) { | ||
return fs.trimmed('/etc/mosdns/rule/blocklist.txt').catch(function (e) { | ||
return ""; | ||
}); | ||
}; | ||
o.write = function (section_id, formvalue) { | ||
return this.cfgvalue(section_id).then(function (value) { | ||
if (value == formvalue) { | ||
return; | ||
} | ||
return fs.write('/etc/mosdns/rule/blocklist.txt', formvalue.trim().replace(/\r\n/g, '\n') + '\n') | ||
.then(function (i) { | ||
ui.addNotification(null, E('p', _('Rules have been saved.')), 'info'); | ||
}) | ||
.catch(function (e) { | ||
ui.addNotification(null, E('p', _('Unable to save contents: %s').format(e.message))); | ||
}); | ||
}); | ||
}; | ||
|
||
o = s.taboption('greylist', form.TextValue, '_greylist', | ||
null, | ||
'<font color=\'red\'>' | ||
+ _('Added domain names will always use \'Remote DNS\' for resolution (one domain per line, supports domain matching rules).') | ||
+ '</font>' | ||
); | ||
o.rows = 25; | ||
o.cfgvalue = function (section_id) { | ||
return fs.trimmed('/etc/mosdns/rule/greylist.txt').catch(function (e) { | ||
return ""; | ||
}); | ||
}; | ||
o.write = function (section_id, formvalue) { | ||
return this.cfgvalue(section_id).then(function (value) { | ||
if (value == formvalue) { | ||
return; | ||
} | ||
return fs.write('/etc/mosdns/rule/greylist.txt', formvalue.trim().replace(/\r\n/g, '\n') + '\n') | ||
.then(function (i) { | ||
ui.addNotification(null, E('p', _('Rules have been saved.')), 'info'); | ||
}) | ||
.catch(function (e) { | ||
ui.addNotification(null, E('p', _('Unable to save contents: %s').format(e.message))); | ||
}); | ||
}); | ||
}; | ||
|
||
o = s.taboption('ddnslist', form.TextValue, '_ddnslist', | ||
null, | ||
'<font color=\'red\'>' | ||
+ _('Added domain names will always use \'Local DNS\' for resolution, with a forced TTL of 5 seconds, and results will not be cached (one domain per line, supports domain matching rules).') | ||
+ '</font>' | ||
); | ||
o.rows = 25; | ||
o.cfgvalue = function (section_id) { | ||
return fs.trimmed('/etc/mosdns/rule/ddnslist.txt').catch(function (e) { | ||
return ""; | ||
}); | ||
}; | ||
o.write = function (section_id, formvalue) { | ||
return this.cfgvalue(section_id).then(function (value) { | ||
if (value == formvalue) { | ||
return; | ||
} | ||
return fs.write('/etc/mosdns/rule/ddnslist.txt', formvalue.trim().replace(/\r\n/g, '\n') + '\n') | ||
.then(function (i) { | ||
ui.addNotification(null, E('p', _('Rules have been saved.')), 'info'); | ||
}) | ||
.catch(function (e) { | ||
ui.addNotification(null, E('p', _('Unable to save contents: %s').format(e.message))); | ||
}); | ||
}); | ||
}; | ||
|
||
o = s.taboption('hostslist', form.TextValue, '_hostslist', | ||
null, | ||
'<font color=\'red\'>' | ||
+ _('Custom Hosts rewrite, for example: baidu.com 10.0.0.1 (one rule per line, supports domain matching rules).') | ||
+ '</font>' | ||
); | ||
o.rows = 25; | ||
o.cfgvalue = function (section_id) { | ||
return fs.trimmed('/etc/mosdns/rule/hosts.txt').catch(function (e) { | ||
return ""; | ||
}); | ||
}; | ||
o.write = function (section_id, formvalue) { | ||
return this.cfgvalue(section_id).then(function (value) { | ||
if (value == formvalue) { | ||
return; | ||
} | ||
return fs.write('/etc/mosdns/rule/hosts.txt', formvalue.trim().replace(/\r\n/g, '\n') + '\n') | ||
.then(function (i) { | ||
ui.addNotification(null, E('p', _('Rules have been saved.')), 'info'); | ||
}) | ||
.catch(function (e) { | ||
ui.addNotification(null, E('p', _('Unable to save contents: %s').format(e.message))); | ||
}); | ||
}); | ||
}; | ||
|
||
o = s.taboption('redirectlist', form.TextValue, '_redirectlist', | ||
null, | ||
'<font color=\'red\'>' | ||
+ _('Redirecting requests for domain names. Request domain A, but return records for domain B, for example: baidu.com qq.com (one rule per line).') | ||
+ '</font>' | ||
); | ||
o.rows = 25; | ||
o.cfgvalue = function (section_id) { | ||
return fs.trimmed('/etc/mosdns/rule/redirect.txt').catch(function (e) { | ||
return ""; | ||
}); | ||
}; | ||
o.write = function (section_id, formvalue) { | ||
return this.cfgvalue(section_id).then(function (value) { | ||
if (value == formvalue) { | ||
return; | ||
} | ||
return fs.write('/etc/mosdns/rule/redirect.txt', formvalue.trim().replace(/\r\n/g, '\n') + '\n') | ||
.then(function (i) { | ||
ui.addNotification(null, E('p', _('Rules have been saved.')), 'info'); | ||
}) | ||
.catch(function (e) { | ||
ui.addNotification(null, E('p', _('Unable to save contents: %s').format(e.message))); | ||
}); | ||
}); | ||
}; | ||
|
||
o = s.taboption('localptrlist', form.TextValue, '_localptrlist', | ||
null, | ||
'<font color=\'red\'>' | ||
+ _('Added domain names will block PTR requests (one domain per line, supports domain matching rules).') | ||
+ '</font>' | ||
); | ||
o.rows = 25; | ||
o.cfgvalue = function (section_id) { | ||
return fs.trimmed('/etc/mosdns/rule/local-ptr.txt').catch(function (e) { | ||
return ""; | ||
}); | ||
}; | ||
o.write = function (section_id, formvalue) { | ||
return this.cfgvalue(section_id).then(function (value) { | ||
if (value == formvalue) { | ||
return; | ||
} | ||
return fs.write('/etc/mosdns/rule/local-ptr.txt', formvalue.trim().replace(/\r\n/g, '\n') + '\n') | ||
.then(function (i) { | ||
ui.addNotification(null, E('p', _('Rules have been saved.')), 'info'); | ||
}) | ||
.catch(function (e) { | ||
ui.addNotification(null, E('p', _('Unable to save contents: %s').format(e.message))); | ||
}); | ||
}); | ||
}; | ||
|
||
o = s.taboption('streamingmedialist', form.TextValue, '_streamingmedialist', | ||
null, | ||
'<font color=\'red\'>' | ||
+ _('When enabling \'Custom Stream Media DNS\', added domains will always use the \'Streaming Media DNS server\' for resolution (one domain per line, supports domain matching rules).') | ||
+ '</font>' | ||
); | ||
o.rows = 25; | ||
o.cfgvalue = function (section_id) { | ||
return fs.trimmed('/etc/mosdns/rule/streaming.txt').catch(function (e) { | ||
return ""; | ||
}); | ||
}; | ||
o.write = function (section_id, formvalue) { | ||
return this.cfgvalue(section_id).then(function (value) { | ||
if (value == formvalue) { | ||
return; | ||
} | ||
return fs.write('/etc/mosdns/rule/streaming.txt', formvalue.trim().replace(/\r\n/g, '\n') + '\n') | ||
.then(function (i) { | ||
ui.addNotification(null, E('p', _('Rules have been saved.')), 'info'); | ||
}) | ||
.catch(function (e) { | ||
ui.addNotification(null, E('p', _('Unable to save contents: %s').format(e.message))); | ||
}); | ||
}); | ||
}; | ||
|
||
return m.render(); | ||
}, | ||
|
||
handleSaveApply: function (ev) { | ||
onclick = L.bind(this.handleSave, this, m); | ||
return fs.exec('/etc/init.d/mosdns', ['restart']); | ||
}, | ||
handleReset: null | ||
}); |
Oops, something went wrong.