first commit

This commit is contained in:
Mateusz Gruszczyński committed 2026-09-29 13:37:57 +02:00
commit 093e6a7c14
39 files changed
+1112

No files matched your search

@@ -0,0 +1,13 @@
#!/bin/sh
if ! /usr/sbin/pw groupshow rustproxy >/dev/null 2>&1; then
/usr/sbin/pw groupadd rustproxy
fi
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 0750 /var/log/rustproxy
/usr/bin/install -d -o root -g wheel -m 0755 /usr/local/etc/rustproxy
@@ -0,0 +1,4 @@
#!/bin/sh
/usr/local/sbin/configctl rustproxy stop >/dev/null 2>&1 || true
exit 0
+9
View File
@@ -0,0 +1,9 @@
PLUGIN_NAME= rustproxy
PLUGIN_VERSION?= 0.20.0
PLUGIN_REVISION?= 0
PLUGIN_COMMENT= RustProxy reverse proxy service
PLUGIN_MAINTAINER?= local@localhost
PLUGIN_WWW?= https://example.invalid/rustproxy
PLUGIN_LICENSE= UNKNOWN
.include "../../Mk/plugins.mk"
+4
View File
@@ -0,0 +1,4 @@
RustProxy packaged as an OPNsense plugin.
The initial OPNsense UI intentionally exposes only one setting: Enabled.
Runtime proxy configuration remains managed by RustProxy itself.
+45
View File
@@ -0,0 +1,45 @@
#!/bin/sh
# PROVIDE: rustproxy
# REQUIRE: LOGIN NETWORKING
# KEYWORD: shutdown
. /etc/rc.subr
name="rustproxy"
rcvar="${name}_enable"
load_rc_config "$name"
: ${rustproxy_enable:="NO"}
: ${rustproxy_user:="rustproxy"}
: ${rustproxy_group:="rustproxy"}
: ${rustproxy_data_dir:="/var/db/rustproxy"}
: ${rustproxy_log_dir:="/var/log/rustproxy"}
: ${rustproxy_log_file:="${rustproxy_log_dir}/rustproxy.log"}
: ${rustproxy_command:="/usr/local/sbin/rust-proxy"}
: ${rustproxy_restart_delay:="5"}
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"
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 0750 "${rustproxy_log_dir}"
/usr/bin/touch "${rustproxy_log_file}"
/usr/sbin/chown "${rustproxy_user}:${rustproxy_group}" "${rustproxy_log_file}"
/bin/chmod 0640 "${rustproxy_log_file}"
}
rustproxy_poststop()
{
/bin/rm -f "${child_pidfile}"
}
run_rc_command "$1"
@@ -0,0 +1,4 @@
#!/bin/sh
/usr/local/sbin/configctl template reload OPNsense/RustProxy >/dev/null 2>&1 || true
/usr/local/sbin/configctl rustproxy boot >/dev/null 2>&1 || true
@@ -0,0 +1,18 @@
<?php
namespace OPNsense\RustProxy\Api;
use OPNsense\Base\ApiMutableServiceControllerBase;
class ServiceController extends ApiMutableServiceControllerBase
{
protected static $internalServiceClass = '\\OPNsense\\RustProxy\\RustProxy';
protected static $internalServiceTemplate = 'OPNsense/RustProxy';
protected static $internalServiceEnabled = 'general.enabled';
protected static $internalServiceName = 'rustproxy';
protected function reconfigureForceRestart()
{
return 0;
}
}
@@ -0,0 +1,11 @@
<?php
namespace OPNsense\RustProxy\Api;
use OPNsense\Base\ApiMutableModelControllerBase;
class SettingsController extends ApiMutableModelControllerBase
{
protected static $internalModelClass = 'OPNsense\RustProxy\RustProxy';
protected static $internalModelName = 'rustproxy';
}
@@ -0,0 +1,12 @@
<?php
namespace OPNsense\RustProxy;
class IndexController extends \OPNsense\Base\IndexController
{
public function indexAction()
{
$this->view->generalForm = $this->getForm('general');
$this->view->pick('OPNsense/RustProxy/index');
}
}
@@ -0,0 +1,8 @@
<form>
<field>
<id>rustproxy.general.enabled</id>
<label>Enabled</label>
<type>checkbox</type>
<help>Start RustProxy and keep it enabled after OPNsense restarts.</help>
</field>
</form>
@@ -0,0 +1,10 @@
<acl>
<page-services-rustproxy>
<name>Services: RustProxy</name>
<description>Allow access to RustProxy settings and service controls</description>
<patterns>
<pattern>ui/rustproxy/*</pattern>
<pattern>api/rustproxy/*</pattern>
</patterns>
</page-services-rustproxy>
</acl>
@@ -0,0 +1,7 @@
<menu>
<Services>
<RustProxy cssClass="fa fa-exchange fa-fw">
<General VisibleName="General" order="10" url="/ui/rustproxy/"/>
</RustProxy>
</Services>
</menu>
@@ -0,0 +1,9 @@
<?php
namespace OPNsense\RustProxy;
use OPNsense\Base\BaseModel;
class RustProxy extends BaseModel
{
}
@@ -0,0 +1,13 @@
<model>
<mount>//OPNsense/rustproxy</mount>
<version>1.0.0</version>
<description>RustProxy service settings</description>
<items>
<general>
<enabled type="BooleanField">
<default>0</default>
<Required>Y</Required>
</enabled>
</general>
</items>
</model>
@@ -0,0 +1,43 @@
<script type="text/javascript">
$(document).ready(function() {
mapDataToFormUI({'frm_GeneralSettings': '/api/rustproxy/settings/get'}).done(function() {
updateServiceControlUI('rustproxy');
});
$('#reconfigureAct').SimpleActionButton({
onPreAction: function() {
const deferred = new $.Deferred();
saveFormToEndpoint(
'/api/rustproxy/settings/set',
'frm_GeneralSettings',
function() { deferred.resolve(); },
true,
function() { deferred.reject(); }
);
return deferred;
},
onAction: function() {
updateServiceControlUI('rustproxy');
}
});
});
</script>
<section class="page-content-main">
<div class="content-box">
{{ partial("layout_partials/base_form", ['fields': generalForm, 'id': 'frm_GeneralSettings']) }}
</div>
<br/>
<div class="content-box">
<div class="col-md-12">
<br/>
<button class="btn btn-primary"
id="reconfigureAct"
data-endpoint="/api/rustproxy/service/reconfigure"
data-label="{{ lang._('Apply') }}"
data-error-title="{{ lang._('Error reconfiguring RustProxy') }}"
type="button"></button>
<br/><br/>
</div>
</div>
</section>
@@ -0,0 +1,45 @@
#!/bin/sh
set -u
CONFIG_FILE="/usr/local/etc/rustproxy/opnsense.conf"
RC_SCRIPT="/usr/local/etc/rc.d/rustproxy"
enabled="0"
if [ -r "$CONFIG_FILE" ]; then
. "$CONFIG_FILE"
fi
start_service()
{
if [ "$enabled" != "1" ]; then
echo "RustProxy is disabled in OPNsense configuration"
return 0
fi
"$RC_SCRIPT" onestart
}
stop_service()
{
"$RC_SCRIPT" onestop >/dev/null 2>&1 || true
}
case "${1:-}" in
start|boot)
start_service
;;
stop)
stop_service
;;
restart|reload)
stop_service
start_service
;;
status)
"$RC_SCRIPT" status
;;
*)
echo "usage: $0 {start|stop|restart|reload|status|boot}" >&2
exit 64
;;
esac
@@ -0,0 +1,35 @@
[start]
command:/usr/local/opnsense/scripts/rustproxy/service.sh start
parameters:
type:script
message:starting RustProxy
[stop]
command:/usr/local/opnsense/scripts/rustproxy/service.sh stop
parameters:
type:script
message:stopping RustProxy
[restart]
command:/usr/local/opnsense/scripts/rustproxy/service.sh restart
parameters:
type:script
message:restarting RustProxy
[reload]
command:/usr/local/opnsense/scripts/rustproxy/service.sh restart
parameters:
type:script
message:reloading RustProxy
[status]
command:/usr/local/opnsense/scripts/rustproxy/service.sh status
parameters:
type:script_output
message:RustProxy status
[boot]
command:/usr/local/opnsense/scripts/rustproxy/service.sh boot
parameters:
type:script
message:starting RustProxy at boot
@@ -0,0 +1 @@
rustproxy.conf:/usr/local/etc/rustproxy/opnsense.conf
@@ -0,0 +1 @@
enabled="{% if not helpers.empty('OPNsense.rustproxy.general.enabled') %}1{% else %}0{% endif %}"