Hello. I am a novice developer working on building a router using OpenWrt.
I'm trying to add a feature to LuCI that allows users to send logs from the router I'm developing via email. This router will be used on a ship where remote logging methods are challenging due to connectivity issues. Therefore, the idea is to enable logs to be sent directly by email from a location where the user has data access.
To achieve this, I wrote a script to collect logs and send them by email (named log_user_send.sh
). I want this script to be executed when a "Send Log.." button is pressed in LuCI.
For this purpose, I modified the www/luci-static/resources/view/system/flash.js
file as follows:
handleSendMailConfirm: function (ev) {
// Execute your custom script instead of the sysupgrade command
return fs.exec('/etc/log_user_send.sh').then(function (res) {
if (res.code != 0) {
// Notification when script execution fails
ui.addNotification(null, [E('p', _('The script execution failed with code %d').format(res.code)), res.stderr ? E('pre', {}, [res.stderr]) : '']);
L.raise('Error', 'Script execution failed');
} else {
// Notification when script execution succeeds
ui.addNotification(null, E('p', _('Script executed successfully')));
}
}).catch(function (e) {
// Error handling
ui.addNotification(null, E('p', e.message));
}).finally(function () {
// Reset the button text
btn.firstChild.data = _('Original button text');
});
},
.....
o = s.option(form.SectionValue, 'actions', form.NamedSection, 'actions', 'actions', _('Send log mail'), _('In the event of a malfunction, the system automatically sends log files to the manufacturer for diagnostic purposes. Be aware that utilizing this feature could lead to communication fees.')); ss = o.subsection; o = ss.option(form.Button, 'dl_backup', _('Send Email')); o.inputstyle = 'action important'; o.inputtitle = _('Send log...'); o.onclick = L.bind(this.handleSendMailConfirm, this);
The problem I'm encountering is that the script doesn't run due to a "Permission denied" error.
I suspect it's a permission issue. I've already tried:
chmod 755 /sbin/log_user_send.sh
chown root.root /etc/log_user_send.sh
But I'm still facing the same error.
I need guidance on how to resolve this issue. I'm looking forward to your helpful suggestions. Please assist me in solving this problem so that clicking the “Send Log..” button will successfully execute the script.