Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

luci-app-adguardhome: Add new app #5853

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

cricalix
Copy link
Contributor

@cricalix cricalix commented Jun 25, 2022

Summary

There is no integration into the web UI for AdGuard Home. This PR adds

  • A Lua script for rpcd to interface with the AGH REST API
  • ACL controls allowing JS code to call rpcd, uci, logread
  • Menu entries to put AdGuard Home under Services
  • Three UIs - status, logs, config

The Lua script supports three API calls:

  • get_status - maps to /control/status in the AGH REST API
  • get_statistics - maps to /control/stats in the AGH REST API
  • get_config - converts /etc/adguardhome.yaml to JSON

Authentication details must be provided by the user, as the password in the YAML file is encrypted. This results in the AGH password being stored cleartext in /etc/config/adguardhome.

The Lua script will log if it encounters an error, in an effort to make it easier to debug. These logs are visible in the Logs UI of the application.

Testing

I could not find any unit testing for things like the UI or the Lua code, so the only testing done was by hand.

The credentials were removed from the config, and both the ubus call and the web UI render the failure to acquire the credentials.

Incorrect credentials were supplied, and the UI was verified as showing a RPC error message.

ACLs were checked by removing luci-compat.json (which wildcard allows saving/reading), and ensuring that the UI could read and save the config.

Package was built and tested with

 make package/luci-app-adguardhome/compile  -j20
 scp bin/packages/i386_pentium4/cricalixluci/luci-app-adguardhome_unknown_all.ipk root@192.168.0.1:
 ssh root@192.168.0.1
 opkg remove luci-app-adguardhome && opkg install luci-app-adguardhome_unknown_all.ipk && rm luci-app-adguardhome_unknown_all.ipk

and then browsing the UI to make sure the deployment was clean and behaved as expected.

Signed-off-by: Duncan Hill github.com@cricalix.net

@cricalix
Copy link
Contributor Author

What's missing is translations; I haven't worked out how to set up the master template for that yet.

@jow-
Copy link
Contributor

jow- commented Jun 25, 2022

./build/i18n-scan.pl applications/luci-app-adguardhome/ > applications/luci-app-adguardhome/po/templates/adguardhome.pot

@cricalix
Copy link
Contributor Author

./build/i18n-scan.pl applications/luci-app-adguardhome/ > applications/luci-app-adguardhome/po/templates/adguardhome.pot

Thanks @jow- ; done and squashed in.

@cricalix cricalix force-pushed the luci-app-adguardhome branch 5 times, most recently from ae97242 to 6e51693 Compare June 27, 2022 12:53
@cricalix cricalix changed the title Add new LuCI app - luci-app-adguardhome luci-app-adguardhome: Add new app Jun 27, 2022
@cricalix cricalix marked this pull request as draft June 27, 2022 13:24
@cricalix cricalix marked this pull request as ready for review June 27, 2022 13:47
@cricalix
Copy link
Contributor Author

OpenWrt2020

Status
Screenshot_20220627_140044

Logs
Screenshot_20220627_145002

Configuration
Screenshot_20220627_140108

BootstrapDark

Status
Screenshot_20220627_145345

Logs
Screenshot_20220627_145420

Configuration
Screenshot_20220627_145429

Material

Status
Screenshot_20220627_145550

Logs
Screenshot_20220627_145601

Configuration
Screenshot_20220627_145610

There is no integration into the web UI for AdGuard Home. This PR adds
* A Lua script for rpcd to interface with the AGH REST API
* ACL controls allowing JS code to call rpcd, uci, logread
* Menu entries to put AdGuard Home under Services
* Three UIs - status, logs, config

The Lua script supports three API calls:
* get_status - maps to /control/status in the AGH REST API
* get_statistics - maps to /control/stats in the AGH REST API
* get_config - converts /etc/adguardhome.yaml to JSON

Authentication details must be provided by the user, as the password in the YAML file is encrypted. This results in the AGH password being stored cleartext in /etc/config/adguardhome.

The Lua script will log if it encounters an error, in an effort to make it easier to debug. These logs are visible in the Logs UI of the application.

I could not find any unit testing for things like the UI or the Lua code, so the only testing done was by hand.

The credentials were removed from the config, and both the ubus call and the web UI render the failure to acquire the credentials.

Incorrect credentials were supplied, and the UI was verified as showing a RPC error message.

ACLs were checked by removing luci-compat.json (which wildcard allows saving/reading), and ensuring that the UI could read and save the config.

Package was built and tested with
```
 make package/luci-app-adguardhome/compile  -j20
 scp bin/packages/i386_pentium4/cricalixluci/luci-app-adguardhome_unknown_all.ipk root@192.168.0.1:
 ssh root@192.168.0.1
 opkg remove luci-app-adguardhome && opkg install luci-app-adguardhome_unknown_all.ipk && rm luci-app-adguardhome_unknown_all.ipk
```
and then browsing the UI to make sure the deployment was clean and behaved as expected.

Signed-off-by: Duncan Hill <openwrt-dev@cricalix.net>
@systemcrash
Copy link
Contributor

Can't this go in, as-is?

@cricalix
Copy link
Contributor Author

Can't this go in, as-is?

I would have thought so, but apparently no one responsible for luci agrees (or has seen this PR).

@systemcrash
Copy link
Contributor

OK by me, if you commit to keeping this working. Have you verified this works with the latest (master, 23.05)? Could you please summarize what the LUA does?

@systemcrash
Copy link
Contributor

If possible, remove those merge commits, and just rebase your original commits onto a current master.

@systemcrash systemcrash added feature pull request adding a new feature Work needed Needs work by the pullrequest creator labels Dec 5, 2023
@systemcrash
Copy link
Contributor

ping @cricalix

@cricalix
Copy link
Contributor Author

cricalix commented Jan 6, 2024

ping @cricalix

Yeah, back now. Christmas period was very busy with an international move in play.

Let me work out how to remove merge commits; not used to Github/git - use Mercurial in my day-to-day work.

Happy to keep it supported as LuCI/OpenWrt move onwards.

What kind of clarification on the Lua do you want to see, and where (inline, README, other)?

@cricalix
Copy link
Contributor Author

cricalix commented Jan 6, 2024

root@OpenWrt:~# opkg install luci-app-adguardhome_git-23.217.49857-0efa0b3_all.ipk 
Installing luci-app-adguardhome (git-23.217.49857-0efa0b3) to root...
Installing luasocket (3.1.0-1) to root...
Downloading https://downloads.openwrt.org/releases/23.05.2/packages/x86_64/packages/luasocket_3.1.0-1_x86_64.ipk
Installing libyaml (0.2.5-1) to root...
Downloading https://downloads.openwrt.org/releases/23.05.2/packages/x86_64/packages/libyaml_0.2.5-1_x86_64.ipk
Installing lyaml (6.2.7-2) to root...
Downloading https://downloads.openwrt.org/releases/23.05.2/packages/x86_64/packages/lyaml_6.2.7-2_x86_64.ipk
Configuring luasocket.
Configuring libyaml.
Configuring lyaml.
Configuring luci-app-adguardhome.

Testing config file parsing failure handling:
20240106_180401

Page renders on 23.05 with update for AGH config changes:
image

@stangri
Copy link
Member

stangri commented Jan 6, 2024

@jow- are you OK with the lua dependency in the new luci package?

@cricalix
Copy link
Contributor Author

cricalix commented Jan 7, 2024

If there are other preferred languages, I can probably rewrite the RPC portion (though it depends if I have to go learn that language first). At the time this was first offered, the example app and a lot of other apps used Lua for the RPC side.

@cricalix
Copy link
Contributor Author

cricalix commented Jan 7, 2024

I also get the feeling that, to pass "Test formalities", I should probably just take all the code in this PR, export it out, and start a new PR with a single commit (and a pointer to this PR for discussion history). I don't see how I can fix the intermediate commits to have the right prefix, and a signed-off line.

@stangri
Copy link
Member

stangri commented Jan 7, 2024

If there are other preferred languages, I can probably rewrite the RPC portion (though it depends if I have to go learn that language first). At the time this was first offered, the example app and a lot of other apps used Lua for the RPC side.

As far as I understand, the ucode or shell script are preferred as there's a goal of decreasing dependency on lua. I know the new luci apps are not accepted if the WebUI is written in lua, not sure what the policy is for use of lua in the RPCD scripts.

@systemcrash
Copy link
Contributor

systemcrash commented Jan 7, 2024 via email

@cricalix
Copy link
Contributor Author

As far as I understand, the ucode or shell script are preferred as there's a goal of decreasing dependency on lua. I know the new luci apps are not accepted if the WebUI is written in lua, not sure what the policy is for use of lua in the RPCD scripts.

Parsing yaml in shell will be unfun. Ditto in ucode, which doesn't appear to have yaml support (given the origins, why would it?). Python would be trivial (if you're running AGH on OpenWrt, you're probably on a device with enough CPU to run a small Python script quickly enough).

@MkQtS
Copy link
Contributor

MkQtS commented Jan 13, 2024

Parsing yaml in shell will be unfun

How about using yq?

@stangri stangri requested a review from jow- January 13, 2024 17:43
@systemcrash
Copy link
Contributor

systemcrash commented Jul 26, 2024

Hi @cricalix if you can amend your commits to correct the subject lines, we can merge this. Also remove merge commits, just rebase on master.

@systemcrash systemcrash removed the request for review from jow- July 26, 2024 00:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature pull request adding a new feature Work needed Needs work by the pullrequest creator
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants