How to run a executable in ui.js file

Hi, i want to run a command using fs.exec_direct() in ui.js file.
i show error "Access Denied by ACL".
How i add permission for my executable fro ui.js?

By adding an appropriate ACL definition. The most minimal one would be:

root@OpenWrt:~# cat /usr/share/rpcd/acl.d/my-package-acl.json
{
	"my-package-name": {
		"description": "Grant access to command required by my package",
		"write": {
			"file": {
				"/usr/bin/my_command --my --args 123 etc.": [ "exec" ]
			}
		}
	}
}

The /usr/bin/my_command --my --args 123 etc. key string must match the command line you're going to invoke exactly. You may use wildcards (* and ?) if needed, e.g. /usr/bin/my_command --foo * to allow executing /usr/bin/my_command with the argument --foo followed by arbitrary other arguments.

To apply the new ACL, log out and in again or issue a service rpcd reload.

thank you so much @jow

i want to run this command, in console it show done but it is not actually writing it in file.

fs.exec('/bin/echo',[res, '>> /var/log/messages']).then(console.log("**********done "));

/usr/share/rpcd/acl.d/for_ui_file.json

{
	"my-package-name": {
		"description": "Grant access to command required by my package",
		"write": {
			"file": {
				"/var/log/messages": [ "write" ],
				"/bin/echo": [ "exec" ]
			}
		}
	}
}

Stdio redirection is a shell feature, you cannot use it directly in an argument vector. You could invoke a command like that:
ACL: "/bin/sh -c 'echo "$@" >> /var/log/messages' -- *": [ "exec" ]
Call: fs.exec('/bin/sh', ['-c', 'echo "$@" >> /var/log/messages', '--', res])

However this is very risky and prone to undesired shell code injections, it is better to ship a specialized wrapper script which only exposes the desired functionality.

Example:

root@OpenWrt:~# cat /usr/libexec/my-package-helper
#!/bin/sh

case "$1" in
--help)
  echo "Usage: $0 {--help|--append-log message}" >&2
  exit 1
;;
--append-log)
  shift
  echo "$1" >> /var/log/messages
;;
esac

Then allow access to /usr/libexec/my-package-helper --append-log * and invoke it as fs.exec('/usr/libexec/my-package-helper', ['--append-log', res])

See other existing scripts in /usr/libexec/ for inspiration, e.g.

or

or

hi @jow i want to get username in ui.js file. i follow this

but this works for js files in view.

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.