hagaygo / OpenWrtManager

Mobile app for interacting with your OpenWrt device.
GNU General Public License v3.0
185 stars 13 forks source link

Actions #31

Closed d687r02j8g closed 1 year ago

d687r02j8g commented 2 years ago

Would it be possible to add actions into this app. I can see an issue was raised where someone suggested system reset which I agree shouldn't be done via the app.

The actions I was thinking of were to restart a device or service. The one I tend to do frequently is to stop/start/reload adblock.

I can see you suggested the person find the right web call. Would it be possible to add the ability to add custom actions where the user can specify the call they'd like to do and a name for the action? I'll use the web inspector to find the ones to control adblock to see if they're generic.

d687r02j8g commented 2 years ago

Restarting Adblock

curl 'https://192.168.1.1/cgi-bin/cgi-exec?1660983667724' \ -H 'Content-Type: application/x-www-form-urlencoded' \ -H 'Referer: https://192.168.1.1/cgi-bin/luci/admin/services/adblock' \ -H 'Sec-Fetch-Dest: empty' \ -H 'Sec-Fetch-Mode: cors' \ -H 'Sec-Fetch-Site: same-origin' \ --data-raw 'sessionid=4e09c4f400ab20e6ea3ea618d28ab3a2&command=%2Fetc%2Finit.d%2Fadblock%20restart'

Reload Adblock

curl 'https://192.168.1.1/cgi-bin/cgi-exec?1660983812991' \ -H 'Content-Type: application/x-www-form-urlencoded' \ -H 'Referer: https://192.168.1.1/cgi-bin/luci/admin/services/adblock' \ -H 'Sec-Fetch-Dest: empty' \ -H 'Sec-Fetch-Mode: cors' \ -H 'Sec-Fetch-Site: same-origin' \ --data-raw 'sessionid=4e09c4f400ab20e6ea3ea618d28ab3a2&command=%2Fetc%2Finit.d%2Fadblock%20reload'

Restart DDNS

curl 'https://192.168.1.1/ubus/?1660983916812' \ -H 'Content-Type: application/json' \ -H 'Referer: https://192.168.1.1/cgi-bin/luci/admin/services/ddns' \ -H 'Sec-Fetch-Dest: empty' \ -H 'Sec-Fetch-Mode: cors' \ -H 'Sec-Fetch-Site: same-origin' \ --data-raw '[{"jsonrpc":"2.0","id":23,"method":"call","params":["4e09c4f400ab20e6ea3ea618d28ab3a2","luci","setInitAction",{"name":"ddns","action":"restart"}]}]'

Reload HTTPS DNS Proxy

curl 'https://192.168.1.1/cgi-bin/luci/admin/services/https-dns-proxy/action/action?1660984069924' \ -H 'Cookie: sysauth=4e09c4f400ab20e6ea3ea618d28ab3a2' \ -H 'Referer: https://192.168.1.1/cgi-bin/luci/admin/services/https-dns-proxy' \ -H 'Sec-Fetch-Dest: empty' \ -H 'Sec-Fetch-Mode: cors' \ -H 'Sec-Fetch-Site: same-origin'

Reboot OpenWRT

curl 'https://192.168.1.1/ubus/?1660984282829' \ -H 'Content-Type: application/json' \ -H 'Referer: https://192.168.1.1/cgi-bin/luci/admin/system/reboot' \ -H 'Sec-Fetch-Dest: empty' \ -H 'Sec-Fetch-Mode: cors' \ -H 'Sec-Fetch-Site: same-origin' \ --data-raw '[{"jsonrpc":"2.0","id":3,"method":"call","params":["16bd6c2ae4ce8983e4c89d8ff685972d","system","reboot",{}]}]'

d687r02j8g commented 2 years ago

Looks like there are a couple of different types.

  1. Json calls
  2. Calls to an action?
  3. Command call?

When I tried to use the command call with a random service, it was denied by ACL it said. So I guess OpenWRT has a list of commands that luci is allowed to run.

hagaygo commented 2 years ago

Hi,

The app already supports rebooting the device , it is available on the "Devices Page" a red button near the device.

As for stopping/restarting/starting a service , It is available by LuCI web interface so it should be doable via the app , only needed to be implemented. (maybe it would be wise to exclude LuCI services from being stopped by the application)

If I'll find time , I will add it to the app , not sure when.

hagaygo commented 1 year ago

Action page added for device on 1.20