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-squid: convert to JavaScript #7320

Merged
merged 1 commit into from
Oct 17, 2024
Merged

Conversation

dannil
Copy link
Contributor

@dannil dannil commented Oct 10, 2024

The conversion adds the missing parameters in the UI which is configurable in the principal package.

Assumption has been made that the config file is stored in /etc/squid since the principal package limits the sysconfdir to this directory. If that assumption is changed in the future we need to adjust the ACL.

Screenshot_1
Screenshot_2
Screenshot_3

Values are updated appropriately which the squid logs also indicates.

root@labmouse:~# uci show squid
squid.squid=squid
squid.squid.config_file='/etc/squid/squid.conf'
squid.squid.http_port='12345'
squid.squid.coredump_dir='/tmp/customsquid'
squid.squid.visible_hostname='foobar'
squid.squid.mime_table='/etc/squid/mime.conf'
squid.squid.pinger_enable='off'
Thu Oct 17 18:03:13 2024 daemon.notice squid[4163]: Processing Configuration File: /tmp/squid/squid.conf (depth 0)
Thu Oct 17 18:03:13 2024 daemon.notice squid[4163]: ERROR: 'pinger_enable' requires --enable-icmp
Thu Oct 17 18:03:13 2024 daemon.warn squid[4163]: FATAL: Squid is already running: Found fresh instance PID file (/var/run/squid.pid) with PID 4095     exception location: Instance.cc(122) ThrowIfAlreadyRunningWith
Thu Oct 17 18:03:13 2024 daemon.notice squid[4095]: Preparing for shutdown after 0 requests
Thu Oct 17 18:03:13 2024 daemon.notice squid[4095]: Waiting 30 seconds for active connections to finish
Thu Oct 17 18:03:13 2024 daemon.notice squid[4095]: Closing HTTP(S) port [::]:1337     listening port: 1337
Thu Oct 17 18:03:18 2024 daemon.info procd: Instance squid::instance1 pid 4095 not stopped on SIGTERM, sending SIGKILL instead
Thu Oct 17 18:03:18 2024 daemon.notice squid[4220]: Processing Configuration File: /tmp/squid/squid.conf (depth 0)
Thu Oct 17 18:03:18 2024 daemon.notice squid[4220]: ERROR: 'pinger_enable' requires --enable-icmp
Thu Oct 17 18:03:18 2024 daemon.notice squid[4220]: Created PID file (/var/run/squid.pid)
Thu Oct 17 18:03:18 2024 daemon.notice squid[4220]: Set Current Directory to /tmp/customsquid
Thu Oct 17 18:03:18 2024 daemon.warn squid[4220]: Starting Squid Cache version 6.11 for x86_64-openwrt-linux-gnu...
Thu Oct 17 18:03:18 2024 daemon.warn squid[4220]: Service Name: squid
Thu Oct 17 18:03:18 2024 daemon.notice squid[4220]: Process ID 4220
Thu Oct 17 18:03:18 2024 daemon.notice squid[4220]: Process Roles: master worker
Thu Oct 17 18:03:18 2024 daemon.notice squid[4220]: With 1024 file descriptors available
Thu Oct 17 18:03:18 2024 daemon.notice squid[4220]: Initializing IP Cache...
Thu Oct 17 18:03:18 2024 daemon.notice squid[4220]: DNS IPv6 socket created at [::], FD 9
Thu Oct 17 18:03:18 2024 daemon.notice squid[4220]: DNS IPv4 socket created at 0.0.0.0, FD 10
Thu Oct 17 18:03:18 2024 daemon.notice squid[4220]: Adding domain lan from /etc/resolv.conf
Thu Oct 17 18:03:18 2024 daemon.notice squid[4220]: Adding nameserver 127.0.0.1 from /etc/resolv.conf
Thu Oct 17 18:03:18 2024 daemon.notice squid[4220]: Adding nameserver ::1 from /etc/resolv.conf
Thu Oct 17 18:03:18 2024 daemon.notice squid[4220]: Local cache digest enabled; rebuild/rewrite every 3600/3600 sec
Thu Oct 17 18:03:18 2024 daemon.notice squid[4220]: Store logging disabled
Thu Oct 17 18:03:18 2024 daemon.notice squid[4220]: Swap maxSize 0 + 262144 KB, estimated 20164 objects
Thu Oct 17 18:03:18 2024 daemon.notice squid[4220]: Target number of buckets: 1008
Thu Oct 17 18:03:18 2024 daemon.notice squid[4220]: Using 8192 Store buckets
Thu Oct 17 18:03:18 2024 daemon.notice squid[4220]: Max Mem  size: 262144 KB
Thu Oct 17 18:03:18 2024 daemon.notice squid[4220]: Max Swap size: 0 KB
Thu Oct 17 18:03:18 2024 daemon.notice squid[4220]: Using Least Load store dir selection
Thu Oct 17 18:03:18 2024 daemon.notice squid[4220]: Set Current Directory to /tmp/customsquid
Thu Oct 17 18:03:18 2024 daemon.notice squid[4220]: Finished loading MIME types and icons.
Thu Oct 17 18:03:18 2024 daemon.notice squid[4220]: HTCP Disabled.
Thu Oct 17 18:03:18 2024 daemon.notice squid[4220]: Squid plugin modules loaded: 0
Thu Oct 17 18:03:18 2024 daemon.notice squid[4220]: Accepting HTTP Socket connections at conn3 local=[::]:12345 remote=[::] FD 11 flags=9     listening port: 12345
Thu Oct 17 18:03:19 2024 daemon.notice squid[4220]: storeLateRelease: released 0 objects

Updating the files via advanced settings also works.

Screenshot_4
Screenshot_5

root@labmouse:~# cat /etc/squid/squid.conf
# this is the config file

root@labmouse:~# cat /etc/squid/mime.conf
# this is the mime table

As discussed in #7320 (comment), if squid is compiled with --enable-icmp, the option will be enabled, otherwise it'll be disabled with a tool tip explaining why.

Screenshot_6
Screenshot_7

  • This PR is not from my main or master branch 💩, but a separate branch ✅
  • Each commit has a valid ✒️ Signed-off-by: <[email protected]> row (via git commit --signoff)
  • Each commit and PR title has a valid 📝 <package name>: title first line subject for packages
  • Incremented 🆙 any PKG_VERSION in the Makefile N/A
  • Tested on: (x86/64, SNAPSHOT r27707-084665698b, Firefox) ✅
  • ( Preferred ) Mention: @ the original code author for feedback @ratkaj
  • ( Preferred ) Screenshot or mp4 of changes:
  • ( Optional ) Closes: e.g. openwrt/luci#issue-number
  • ( Optional ) Depends on: e.g. openwrt/packages#pr-number in sister repo
  • Description: (describe the changes proposed in this PR)

@systemcrash
Copy link
Contributor

This looks fine as-is. If you're feeling up to it, could you also add the extra variables found in the squid package please ( as at 23.05 ):

validate_squid_section() {
	uci_load_validate squid squid "$1" "$2" \
		'config_file:string' \
		'http_port:port:3128' \
		'http_port_options:string' \
		'ssldb:string' \
		'ssldb_options:string' \
		'coredump_dir:string' \
		'visible_hostname:string:OpenWrt' \
		'pinger_enable:string:off' \
		'mime_table:string:/etc/squid/mime.conf'
}

@dannil
Copy link
Contributor Author

dannil commented Oct 10, 2024

This looks fine as-is. If you're feeling up to it, could you also add the extra variables found in the squid package please ( as at 23.05 ):

validate_squid_section() {
	uci_load_validate squid squid "$1" "$2" \
		'config_file:string' \
		'http_port:port:3128' \
		'http_port_options:string' \
		'ssldb:string' \
		'ssldb_options:string' \
		'coredump_dir:string' \
		'visible_hostname:string:OpenWrt' \
		'pinger_enable:string:off' \
		'mime_table:string:/etc/squid/mime.conf'
}

Sure thing, should be fairly straightforward.

@dannil dannil marked this pull request as draft October 11, 2024 07:28
@dannil
Copy link
Contributor Author

dannil commented Oct 11, 2024

I've basically got everything working with the new options, but during this I discovered that the pinger_enable option requires Squid to be started with the --enable-icmp parameter, which the principal package doesn't do. This can also be seen in the logs:

Fri Oct 11 20:01:30 2024 daemon.notice squid[4620]: ERROR: 'pinger_enable' requires --enable-icmp

Should we still expose this option even though it won't do anything?

@hnyman
Copy link
Contributor

hnyman commented Oct 11, 2024

LuCI should match the principal package.
It makes no sense to offer options that the package does not actually support.

@systemcrash
Copy link
Contributor

systemcrash commented Oct 11, 2024 via email

@dannil
Copy link
Contributor Author

dannil commented Oct 11, 2024

Is it not what the start script makes possible?

A prerequisite of being able to use pinger_enable (even if you set it on or off doesn't matter, the warning will show up irregardless otherwise) is that Squid has been compiled with the --enable-icmp option, which isn't enabled in the config at https://github.com/openwrt/packages/blob/552f561c51abac603cc40229f3cfa89e32ef3127/net/squid/Config.in#L13-L15 which gets passed through at https://github.com/openwrt/packages/blob/552f561c51abac603cc40229f3cfa89e32ef3127/net/squid/Makefile#L100. So for everyone which doesn't set this in menuconfig (which is everyone not compiling from source) this option won't do anything, and I'm pretty sure we can't check compile options in LuCI...

Also, another interesting thing is that the default compile option then becomes --disable-icmp, which as of Squid 6.11 isn't even a valid parameter, so I guess it gets silently ignored.

@systemcrash
Copy link
Contributor

Ah. Okay. Previously you wrote started. I started to suspect it was a CTO. Technically it's possible to parse the help output of squid to scrape whether it's compiled so, but that's another problem for another day. Skip ping 👌

@dannil
Copy link
Contributor Author

dannil commented Oct 11, 2024

Ah. Okay. Previously you wrote started. I started to suspect it was a CTO. Technically it's possible to parse the help output of squid to scrape whether it's compiled so, but that's another problem for another day. Skip ping 👌

Sounds good. Yeah I see the misunderstanding, I had actually missed it was a compile-time option instead of a parameter, my bad.

@hnyman
Copy link
Contributor

hnyman commented Oct 11, 2024

If it is a compile-time option, one alternative might be to add a note to the option explanation in LuCI, that it a compile option is required for the functionality to work.

@systemcrash
Copy link
Contributor

You can take a look at how we did it in (luci-app-)lldpd.

@dannil
Copy link
Contributor Author

dannil commented Oct 13, 2024

FYI: I'm gonna remove the custom handleSaveApply implementation as I noticed that squid sets up a procd reload trigger for its UCI section, so migrating the on_after_commit function in the Lua implementation isn't even necessary as it'll restart itself as needed. The more you know!

@systemcrash
Copy link
Contributor

How's it coming with handleSaveApply? Do you prefer to add GUI restart helpers and let uci handle the reload?

@dannil
Copy link
Contributor Author

dannil commented Oct 17, 2024

How's it coming with handleSaveApply? Do you prefer to add GUI restart helpers and let uci handle the reload?

I basically have the entire PR sorted out on my end, just haven't had the time to finalize it. Since the principal package sets up a procd trigger on the uci squid section, there's no easy way for us anyway to handle the reload manually on the LuCI app with restart helpers, so I'm just gonna leave it the way it was before (as in the default Save and Apply reloading squid), which works as it should.

@dannil
Copy link
Contributor Author

dannil commented Oct 17, 2024

PR should be good to go now. Changes since putting in draft:

@dannil dannil marked this pull request as ready for review October 17, 2024 16:18
@systemcrash
Copy link
Contributor

Once those are done, just squash all the commits together too, please.

The conversion adds the missing parameters in the UI which is
configurable in the principal package.

Assumption has been made that the config file is stored in /etc/squid
since the principal package limits the sysconfdir to this directory. If
that assumption is changed in the future we need to adjust the ACL.

Signed-off-by: Daniel Nilsson <[email protected]>
@systemcrash systemcrash merged commit 5c6b08c into openwrt:master Oct 17, 2024
5 checks passed
@systemcrash
Copy link
Contributor

Great. Thanks @dannil

@dannil dannil deleted the squid-js branch October 17, 2024 17:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants