mirror of
https://github.com/netbirdio/plugins.git
synced 2026-05-22 18:44:07 -07:00
hidden services: add auth for clients (#350)
This commit is contained in:
@@ -33,6 +33,7 @@ use \OPNsense\Base\ApiMutableModelControllerBase;
|
||||
use \OPNsense\Core\Backend;
|
||||
use \OPNsense\Core\Config;
|
||||
use \OPNsense\Tor\General;
|
||||
use \OPNsense\Base\UIModelGrid;
|
||||
|
||||
class GeneralController extends ApiMutableModelControllerBase
|
||||
{
|
||||
@@ -70,4 +71,137 @@ class GeneralController extends ApiMutableModelControllerBase
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* Hidden service authentication */
|
||||
|
||||
public function searchhidservauthAction()
|
||||
{
|
||||
$this->sessionClose();
|
||||
$mdl = $this->getModel();
|
||||
$grid = new UIModelGrid($mdl->client_authentications->client_auth);
|
||||
return $grid->fetchBindRequest(
|
||||
$this->request,
|
||||
array('enabled', 'onion_service', 'auth_cookie')
|
||||
);
|
||||
}
|
||||
public function gethidservauthAction($uuid = null)
|
||||
{
|
||||
$mdl = $this->getModel();
|
||||
if ($uuid != null) {
|
||||
$node = $mdl->getNodeByReference('client_authentications.client_auth.' . $uuid);
|
||||
if ($node != null) {
|
||||
// return node
|
||||
return array('client_auth' => $node->getNodes());
|
||||
}
|
||||
} else {
|
||||
$node = $mdl->client_authentications->client_auth->add();
|
||||
return array('client_auth' => $node->getNodes());
|
||||
}
|
||||
return array();
|
||||
}
|
||||
public function addhidservauthAction()
|
||||
{
|
||||
$result = array('result' => 'failed');
|
||||
if ($this->request->isPost() && $this->request->hasPost('client_auth')) {
|
||||
$result = array('result' => 'failed', 'validations' => array());
|
||||
$mdl = $this->getModel();
|
||||
$node = $mdl->client_authentications->client_auth->Add();
|
||||
$node->setNodes($this->request->getPost('client_auth'));
|
||||
$valMsgs = $mdl->performValidation();
|
||||
|
||||
foreach ($valMsgs as $field => $msg) {
|
||||
$fieldnm = str_replace($node->__reference, 'client_auth', $msg->getField());
|
||||
$result['validations'][$fieldnm] = $msg->getMessage();
|
||||
}
|
||||
|
||||
if (count($result['validations']) == 0) {
|
||||
// save config if validated correctly
|
||||
$mdl->serializeToConfig();
|
||||
Config::getInstance()->save();
|
||||
unset($result['validations']);
|
||||
$result['result'] = 'saved';
|
||||
}
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
public function delhidservauthAction($uuid)
|
||||
{
|
||||
|
||||
$result = array('result' => 'failed');
|
||||
|
||||
if ($this->request->isPost()) {
|
||||
$mdl = $this->getModel();
|
||||
if ($uuid != null) {
|
||||
if ($mdl->client_authentications->client_auth->del($uuid)) {
|
||||
$mdl->serializeToConfig();
|
||||
Config::getInstance()->save();
|
||||
$result['result'] = 'deleted';
|
||||
} else {
|
||||
$result['result'] = 'not found';
|
||||
}
|
||||
}
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
public function sethidservauthAction($uuid)
|
||||
{
|
||||
if ($this->request->isPost() && $this->request->hasPost('client_auth')) {
|
||||
$mdl = $this->getModel();
|
||||
if ($uuid != null) {
|
||||
$node = $mdl->getNodeByReference('client_authentications.client_auth.' . $uuid);
|
||||
if ($node != null) {
|
||||
$result = array('result' => 'failed', 'validations' => array());
|
||||
$info = $this->request->getPost('client_auth');
|
||||
|
||||
$node->setNodes($info);
|
||||
$valMsgs = $mdl->performValidation();
|
||||
foreach ($valMsgs as $field => $msg) {
|
||||
$fieldnm = str_replace($node->__reference, 'client_auth', $msg->getField());
|
||||
$result['validations'][$fieldnm] = $msg->getMessage();
|
||||
}
|
||||
|
||||
if (count($result['validations']) == 0) {
|
||||
// save config if validated correctly
|
||||
$mdl->serializeToConfig();
|
||||
unset($result['validations']);
|
||||
Config::getInstance()->save();
|
||||
$result = array('result' => 'saved');
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
}
|
||||
return array('result' => 'failed');
|
||||
}
|
||||
public function toggle_handler($uuid, $element)
|
||||
{
|
||||
|
||||
$result = array('result' => 'failed');
|
||||
|
||||
if ($this->request->isPost()) {
|
||||
$mdl = $this->getModel();
|
||||
if ($uuid != null) {
|
||||
$node = $mdl->getNodeByReference($element . '.' . $uuid);
|
||||
if ($node != null) {
|
||||
if ($node->enabled->__toString() == '1') {
|
||||
$result['result'] = 'Disabled';
|
||||
$node->enabled = '0';
|
||||
} else {
|
||||
$result['result'] = 'Enabled';
|
||||
$node->enabled = '1';
|
||||
}
|
||||
$mdl->serializeToConfig();
|
||||
Config::getInstance()->save();
|
||||
}
|
||||
}
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function togglehidservauthAction($uuid)
|
||||
{
|
||||
return $this->toggle_handler($uuid, 'client_authentications.client_auth');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,6 +45,7 @@ class IndexController extends \OPNsense\Base\IndexController
|
||||
$this->view->hidden_service = $this->getForm("hidden_service");
|
||||
$this->view->hidden_service_acl = $this->getForm("hidden_service_acl");
|
||||
$this->view->relay = $this->getForm("relay");
|
||||
$this->view->hidservauth = $this->getForm("hidservauth");
|
||||
$this->view->exitpolicy = $this->getForm("acl_exitpolicy");
|
||||
$this->view->pick('OPNsense/Tor/general');
|
||||
}
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
<form>
|
||||
<field>
|
||||
<id>client_auth.enabled</id>
|
||||
<label>Enable</label>
|
||||
<type>checkbox</type>
|
||||
</field>
|
||||
<field>
|
||||
<id>client_auth.onion_service</id>
|
||||
<label>Host Name</label>
|
||||
<type>text</type>
|
||||
</field>
|
||||
<field>
|
||||
<id>client_auth.auth_cookie</id>
|
||||
<label>Authentication Cookie</label>
|
||||
<type>text</type>
|
||||
</field>
|
||||
</form>
|
||||
@@ -99,5 +99,23 @@
|
||||
<default>0</default>
|
||||
<Required>Y</Required>
|
||||
</dns_map_hosts>
|
||||
<client_authentications>
|
||||
<client_auth type="ArrayField">
|
||||
<enabled type="BooleanField">
|
||||
<default>1</default>
|
||||
<Required>Y</Required>
|
||||
</enabled>
|
||||
<onion_service type="TextField">
|
||||
<Required>Y</Required>
|
||||
<default>exampleexample23.onion</default>
|
||||
<mask>/^[a-z2-7]{16}\.onion$/i</mask>
|
||||
</onion_service>
|
||||
<auth_cookie type="TextField">
|
||||
<Required>Y</Required>
|
||||
<default>0000000000000000000000</default>
|
||||
<mask>/^[a-z0-9\+\/]{22}$/i</mask>
|
||||
</auth_cookie>
|
||||
</client_auth>
|
||||
</client_authentications>
|
||||
</items>
|
||||
</model>
|
||||
|
||||
@@ -115,11 +115,22 @@ $( document ).ready(function() {
|
||||
'options':{selection:false, multiSelect:false}
|
||||
}
|
||||
);
|
||||
$("#grid-hidservauth").UIBootgrid(
|
||||
{ 'search':'/api/tor/general/searchhidservauth',
|
||||
'get':'/api/tor/general/gethidservauth/',
|
||||
'set':'/api/tor/general/sethidservauth/',
|
||||
'add':'/api/tor/general/addhidservauth/',
|
||||
'del':'/api/tor/general/delhidservauth/',
|
||||
'toggle':'/api/tor/general/togglehidservauth/',
|
||||
'options':{selection:false, multiSelect:false}
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
</script>
|
||||
<ul class="nav nav-tabs" data-tabs="tabs" id="maintabs">
|
||||
<li class="active"><a data-toggle="tab" href="#general">{{ lang._('General') }}</a></li>
|
||||
<li><a data-toggle="tab" href="#hidservauth">{{ lang._('Onion Service Authentication') }}</a></li>
|
||||
<li><a data-toggle="tab" href="#acl">{{ lang._('SOCKS Proxy ACL') }}</a></li>
|
||||
<li><a data-toggle="tab" href="#hidden">{{ lang._('Onion Services') }}</a></li>
|
||||
<li><a data-toggle="tab" href="#hiddenrouting">{{ lang._('Onion Service Routing') }}</a></li>
|
||||
@@ -185,6 +196,31 @@ $( document ).ready(function() {
|
||||
</tfoot>
|
||||
</table>
|
||||
</div>
|
||||
<div id="hidservauth" class="tab-pane fade in">
|
||||
<table id="grid-hidservauth" class="table table-responsive" data-editDialog="hidservauthdlg">
|
||||
<thead>
|
||||
<tr>
|
||||
<th data-column-id="enabled" data-type="string" data-formatter="rowtoggle">{{ lang._('Enabled') }}</th>
|
||||
<th data-column-id="onion_service" data-type="string" data-visible="true">{{ lang._('Onion Service') }}</th>
|
||||
<th data-column-id="auth_cookie" data-type="string" data-visible="true">{{ lang._('Authentication Cookie') }}</th>
|
||||
<th data-column-id="uuid" data-type="string" data-identifier="true" data-visible="false">{{ lang._('ID') }}</th>
|
||||
<th data-column-id="commands" data-formatter="commands" data-sortable="false">{{ lang._('Commands') }}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
</tbody>
|
||||
<tfoot>
|
||||
<tr>
|
||||
<td colspan="4"></td>
|
||||
<td>
|
||||
<button data-action="add" type="button" class="btn btn-xs btn-default"><span class="fa fa-plus"></span></button>
|
||||
<!-- <button data-action="deleteSelected" type="button" class="btn btn-xs btn-default"><span class="fa fa-trash-o"></span></button> -->
|
||||
<button type="button" class="btn btn-xs reload_btn btn-primary"><span class="fa fa-refresh reloadAct_progress"></span> {{ lang._('Reload Service') }}</button>
|
||||
</td>
|
||||
</tr>
|
||||
</tfoot>
|
||||
</table>
|
||||
</div>
|
||||
<div id="hiddenrouting" class="tab-pane fade in">
|
||||
<table id="grid-hiddenacl" class="table table-responsive" data-editDialog="hiddenserviceacl">
|
||||
<thead>
|
||||
@@ -257,3 +293,4 @@ $( document ).ready(function() {
|
||||
{{ partial("layout_partials/base_dialog",['fields': hidden_service,'id':'hiddenservicedlg', 'label':lang._('Edit Onion Service')]) }}
|
||||
{{ partial("layout_partials/base_dialog",['fields': hidden_service_acl,'id':'hiddenserviceacl', 'label':lang._('Edit Onion Service Route')]) }}
|
||||
{{ partial("layout_partials/base_dialog",['fields': exitpolicy,'id':'torexitacldlg', 'label':lang._('Edit Exit Node ACL')]) }}
|
||||
{{ partial("layout_partials/base_dialog",['fields': hidservauth,'id':'hidservauthdlg', 'label':lang._('Edit Hidden Service Credentials')]) }}
|
||||
|
||||
@@ -88,6 +88,15 @@ VirtualAddrNetwork {{ OPNsense.tor.general.transparent_ip_pool }}
|
||||
AutomapHostsOnResolve {{ OPNsense.tor.general.dns_map_hosts }}
|
||||
{% endif %}
|
||||
|
||||
## Client Authentication
|
||||
{% if helpers.exists('OPNsense.tor.general.client_authentications.client_auth') %}
|
||||
{% for service in helpers.toList('OPNsense.tor.general.client_authentications.client_auth') %}
|
||||
{% if service.enabled == '1' %}
|
||||
HidServAuth {{ service.onion_service }} {{ service.auth_cookie }}
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
|
||||
{% if helpers.exists('OPNsense.tor.hiddenservice') and helpers.exists('OPNsense.tor.hiddenserviceacl') and helpers.exists('OPNsense.tor.hiddenserviceacl.hiddenserviceacl') %}
|
||||
|
||||
############### This section is just for location-hidden services ###
|
||||
|
||||
Reference in New Issue
Block a user