Skip to content

Commit

Permalink
luci-app-tor: Manage Onion services (tor-hs)
Browse files Browse the repository at this point in the history
The tor-hs packages provides Tor Onion (Hidden) Services.
This is a good option to bypass NAT and have stable access to a router.

Later once the main Tor package gains a support of a Proxy/Bridge configuration.
We can add this to the same luci app as a different view.

Signed-off-by: Sergey Ponomarev <[email protected]>
  • Loading branch information
stokito committed Aug 2, 2023
1 parent 6c259f7 commit 44dc14c
Show file tree
Hide file tree
Showing 4 changed files with 142 additions and 0 deletions.
11 changes: 11 additions & 0 deletions applications/luci-app-tor/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# See /LICENSE for more information.
# This is free software, licensed under the GNU General Public License v2.

include $(TOPDIR)/rules.mk

LUCI_TITLE:=LuCI app to configure Tor
LUCI_DEPENDS:=+luci-base

include ../../luci.mk

# call BuildPackage - OpenWrt buildroot signature
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
'use strict';
'require view';
'require form';
'require rpc';
'require uci';

var callTorHsList = rpc.declare({
object: 'tor_rpcd.sh',
method: 'list-hs',
});


return view.extend({
load: function () {
return Promise.all([
L.resolveDefault(callTorHsList(), {}),
]);
},

render: function (data) {
var hsList = data[0]['hs-list']
var hsMap = new Map()
hsList.forEach(function (hs) {
hsMap.set(hs.name, hs.hostname);
});

var m, s, o;

m = new form.Map('tor-hs', _('Tor Onion Services'),
_('<a href="https://openwrt.org/docs/guide-user/services/tor/hs" target="_blank">Tor Onion (Hidden) Services</a> are proxy tunnels to your local website, SSH and other services'));

s = m.section(form.GridSection, 'hidden-service', _('Tor Onion Services'));
s.addremove = true;
s.nodescriptions = true;

o = s.option(form.Flag, 'Enabled', _('Enabled'), '');
o.default = '1';
o.rmempty = false;

o = s.option(form.Value, 'Name', _('Name'), '');
o.datatype = 'uciname';
o.rmempty = false;
o.cfgvalue = function(section_id) {
var name = uci.get('tor-hs', section_id, 'Name');
if (!name)
return section_id;
return name;
};

o = s.option(form.DummyValue, '_Domain', _('Onion domain'), '');
o.modalonly = false;
o.rawhtml = true;
o.textvalue = function (section_id) {
var name = uci.get('tor-hs', section_id, 'Name');
if (!name)
return '';
var hostname = hsMap.get(name);
if (!hostname)
return '';
return '<a href="http://' + hostname + '" target="_blank" rel="noreferrer">' + _('Link') + '</a>';
};

o = s.option(form.Value, 'Description', _('Description'), '');
o.modalonly = true;

o = s.option(form.Value, 'IPv4', _('Destination IP Address'),
_('Traffic will be forwarded to the IP address')
);
o.datatype = 'ip';
o.default = '127.0.0.1';

o = s.option(form.DynamicList, 'PublicLocalPort', _('Public to Local Ports'),
_('PublicPort;Local Port or PublicPort;LocalUnixSocket'));
o.default = ['80', '443'];
o.datatype = 'list(string)';
o.rmempty = false;

o = s.option(form.Value, 'HookScript', _('Hook Script'),
_('Path to script which is executed after starting Tor. ' +
'The Onion domain is passes into the script with parameters `--update-onion HOSTNAME`'));
o.modalonly = true;

return m.render();
},
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"admin/services/tor": {
"title": "Tor Onion Services",
"order": 60,
"action": {
"type": "view",
"path": "tor/tor-hs"
},
"depends": {
"acl": [
"luci-app-tor"
]
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"luci-app-tor": {
"description": "Grant UCI access to LuCI app Tor",
"read": {
"ubus": {
"uci": [
"get"
],
"tor_rpcd.sh": [
"list-hs"
]
},
"uci": [
"tor",
"tor-hs"
]
},
"write": {
"ubus": {
"uci": [
"set",
"commit"
]
},
"uci": [
"tor",
"tor-hs"
]
}
}
}

0 comments on commit 44dc14c

Please sign in to comment.