This commit is contained in:
Mateusz Gruszczyński committed 2026-09-29 15:57:07 +02:00
1 parent 1a2a5f0faf
commit c0068d624e
13 files changed
+230 -17

No files matched your search

+11 -1
View File
@@ -8,6 +8,16 @@ if ! /usr/sbin/pw usershow rustproxy >/dev/null 2>&1; then
/usr/sbin/pw useradd rustproxy -g rustproxy -c "RustProxy daemon" -d /var/db/rustproxy -s /usr/sbin/nologin
fi
/usr/bin/install -d -o rustproxy -g rustproxy -m 0750 /var/db/rustproxy
/usr/bin/install -d -o rustproxy -g rustproxy -m 0700 /var/db/rustproxy
/usr/sbin/chown rustproxy:rustproxy /var/db/rustproxy
/bin/chmod 0700 /var/db/rustproxy
/usr/bin/install -d -o rustproxy -g rustproxy -m 0750 /var/log/rustproxy
/usr/bin/install -d -o root -g wheel -m 0755 /usr/local/etc/rustproxy
# configd discovers actions only on startup/reload. A direct `pkg add` must
# therefore refresh configd before the MVC service controller can call them.
/usr/sbin/service configd restart >/dev/null 2>&1 || true
/usr/local/sbin/pluginctl -cq cache_flush >/dev/null 2>&1 || true
/usr/local/sbin/configctl template reload OPNsense/RustProxy >/dev/null 2>&1 || true
exit 0
+3 -3
View File
@@ -1,4 +1,4 @@
RustProxy packaged as an OPNsense plugin.
RustProxy packaged as an OPNsense service plugin.
The initial OPNsense UI intentionally exposes only one setting: Enabled.
Runtime proxy configuration remains managed by RustProxy itself.
The OPNsense UI exposes service enable/disable, HTTP and HTTPS/TLS listener
addresses, the administration listener and the remote-admin opt-in.
@@ -19,18 +19,46 @@ load_rc_config "$name"
: ${rustproxy_log_file:="${rustproxy_log_dir}/rustproxy.log"}
: ${rustproxy_command:="/usr/local/sbin/rust-proxy"}
: ${rustproxy_restart_delay:="5"}
: ${rustproxy_proxy_listen:="0.0.0.0:8080"}
: ${rustproxy_tls_enabled:="1"}
: ${rustproxy_tls_listen:="0.0.0.0:8181"}
: ${rustproxy_admin_listen:="127.0.0.1:9090"}
: ${rustproxy_allow_remote_admin:="0"}
enabled="0"
config_file="/usr/local/etc/rustproxy/opnsense.conf"
if [ -r "$config_file" ]; then
. "$config_file"
fi
if [ "$enabled" = "1" ]; then
rustproxy_enable="YES"
else
rustproxy_enable="NO"
fi
rustproxy_runtime_args="--data-dir ${rustproxy_data_dir} --admin-listen ${rustproxy_admin_listen} --update-check-interval-secs 0 serve --proxy-listen ${rustproxy_proxy_listen}"
if [ "$rustproxy_tls_enabled" = "1" ]; then
rustproxy_runtime_args="${rustproxy_runtime_args} --tls-listen ${rustproxy_tls_listen}"
fi
if [ "$rustproxy_allow_remote_admin" = "1" ]; then
rustproxy_runtime_args="${rustproxy_runtime_args} --allow-remote-admin"
fi
pidfile="/var/run/rustproxy-daemon.pid"
child_pidfile="/var/run/rustproxy.pid"
command="/usr/sbin/daemon"
command_args="-r -R ${rustproxy_restart_delay} -P ${pidfile} -p ${child_pidfile} -u ${rustproxy_user} -o ${rustproxy_log_file} ${rustproxy_command} --data-dir ${rustproxy_data_dir} --update-check-interval-secs 0 serve"
command_args="-r -R ${rustproxy_restart_delay} -P ${pidfile} -p ${child_pidfile} -u ${rustproxy_user} -o ${rustproxy_log_file} ${rustproxy_command} ${rustproxy_runtime_args}"
required_files="${rustproxy_command}"
start_precmd="rustproxy_prestart"
stop_postcmd="rustproxy_poststop"
rustproxy_prestart()
{
/usr/bin/install -d -o "${rustproxy_user}" -g "${rustproxy_group}" -m 0750 "${rustproxy_data_dir}"
/usr/bin/install -d -o "${rustproxy_user}" -g "${rustproxy_group}" -m 0700 "${rustproxy_data_dir}"
/usr/sbin/chown "${rustproxy_user}:${rustproxy_group}" "${rustproxy_data_dir}"
/bin/chmod 0700 "${rustproxy_data_dir}"
/usr/bin/install -d -o "${rustproxy_user}" -g "${rustproxy_group}" -m 0750 "${rustproxy_log_dir}"
/usr/bin/touch "${rustproxy_log_file}"
/usr/sbin/chown "${rustproxy_user}:${rustproxy_group}" "${rustproxy_log_file}"
@@ -1,8 +1,53 @@
<form>
<field>
<label>General</label>
<type>header</type>
<static>true</static>
</field>
<field>
<id>rustproxy.general.enabled</id>
<label>Enabled</label>
<type>checkbox</type>
<help>Start RustProxy and keep it enabled after OPNsense restarts.</help>
</field>
<field>
<label>Proxy listeners</label>
<type>header</type>
<static>true</static>
</field>
<field>
<id>rustproxy.general.proxyListen</id>
<label>HTTP listen</label>
<type>text</type>
<help>HTTP listener passed as --proxy-listen. Default: 0.0.0.0:8080.</help>
</field>
<field>
<id>rustproxy.general.tlsEnabled</id>
<label>Enable HTTPS/TLS listener</label>
<type>checkbox</type>
<help>When enabled, pass --tls-listen to RustProxy.</help>
</field>
<field>
<id>rustproxy.general.tlsListen</id>
<label>HTTPS/TLS listen</label>
<type>text</type>
<help>HTTPS/TLS listener passed as --tls-listen. Default: 0.0.0.0:8181.</help>
</field>
<field>
<label>Administration</label>
<type>header</type>
<static>true</static>
</field>
<field>
<id>rustproxy.general.adminListen</id>
<label>Admin listen</label>
<type>text</type>
<help>RustProxy administration listener passed as --admin-listen. Default: 127.0.0.1:9090.</help>
</field>
<field>
<id>rustproxy.general.allowRemoteAdmin</id>
<label>Allow remote admin</label>
<type>checkbox</type>
<help>Required when Admin listen is not a loopback address, for example 0.0.0.0:9090. This passes --allow-remote-admin.</help>
</field>
</form>
@@ -1,13 +1,36 @@
<model>
<mount>//OPNsense/rustproxy</mount>
<version>1.0.0</version>
<version>1.1.0</version>
<description>RustProxy service settings</description>
<items>
<general>
<enabled type="BooleanField">
<default>0</default>
<Default>0</Default>
<Required>Y</Required>
</enabled>
<proxyListen type="IPPortField">
<Default>0.0.0.0:8080</Default>
<Required>Y</Required>
<ValidationMessage>Enter a valid HTTP listen address and port, for example 0.0.0.0:8080.</ValidationMessage>
</proxyListen>
<tlsEnabled type="BooleanField">
<Default>1</Default>
<Required>Y</Required>
</tlsEnabled>
<tlsListen type="IPPortField">
<Default>0.0.0.0:8181</Default>
<Required>Y</Required>
<ValidationMessage>Enter a valid HTTPS/TLS listen address and port, for example 0.0.0.0:8181.</ValidationMessage>
</tlsListen>
<adminListen type="IPPortField">
<Default>127.0.0.1:9090</Default>
<Required>Y</Required>
<ValidationMessage>Enter a valid administration listen address and port, for example 127.0.0.1:9090.</ValidationMessage>
</adminListen>
<allowRemoteAdmin type="BooleanField">
<Default>0</Default>
<Required>Y</Required>
</allowRemoteAdmin>
</general>
</items>
</model>
@@ -3,33 +3,40 @@ command:/usr/local/opnsense/scripts/rustproxy/service.sh start
parameters:
type:script
message:starting RustProxy
allowed_groups:wheel,wwwonly
[stop]
command:/usr/local/opnsense/scripts/rustproxy/service.sh stop
parameters:
type:script
message:stopping RustProxy
allowed_groups:wheel,wwwonly
[restart]
command:/usr/local/opnsense/scripts/rustproxy/service.sh restart
parameters:
type:script
message:restarting RustProxy
allowed_groups:wheel,wwwonly
[reload]
command:/usr/local/opnsense/scripts/rustproxy/service.sh restart
parameters:
type:script
message:reloading RustProxy
allowed_groups:wheel,wwwonly
[status]
command:/usr/local/opnsense/scripts/rustproxy/service.sh status
parameters:
type:script_output
errors:no
message:RustProxy status
allowed_groups:wheel,wwwonly
[boot]
command:/usr/local/opnsense/scripts/rustproxy/service.sh boot
parameters:
type:script
message:starting RustProxy at boot
allowed_groups:wheel,wwwonly
@@ -1 +1,6 @@
enabled="{% if not helpers.empty('OPNsense.rustproxy.general.enabled') %}1{% else %}0{% endif %}"
rustproxy_proxy_listen="{% if not helpers.empty('OPNsense.rustproxy.general.proxyListen') %}{{ OPNsense.rustproxy.general.proxyListen }}{% else %}0.0.0.0:8080{% endif %}"
rustproxy_tls_enabled="{% if not helpers.empty('OPNsense.rustproxy.general.tlsEnabled') %}1{% else %}0{% endif %}"
rustproxy_tls_listen="{% if not helpers.empty('OPNsense.rustproxy.general.tlsListen') %}{{ OPNsense.rustproxy.general.tlsListen }}{% else %}0.0.0.0:8181{% endif %}"
rustproxy_admin_listen="{% if not helpers.empty('OPNsense.rustproxy.general.adminListen') %}{{ OPNsense.rustproxy.general.adminListen }}{% else %}127.0.0.1:9090{% endif %}"
rustproxy_allow_remote_admin="{% if not helpers.empty('OPNsense.rustproxy.general.allowRemoteAdmin') %}1{% else %}0{% endif %}"