Skip to content

Commit

Permalink
luci-app-tor: Manage onion services
Browse files Browse the repository at this point in the history
Signed-off-by: Sergey Ponomarev <stokito@gmail.com>
  • Loading branch information
stokito committed Jul 22, 2023
1 parent 6c259f7 commit 7b7a647
Show file tree
Hide file tree
Showing 4 changed files with 130 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,76 @@
'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 Hidden Services'),
_('Tor Hidden Services are proxy tunnels to your local website, SSH and other services'));

s = m.section(form.GridSection, 'hidden-service', _('Tor Hidden Services'));
s.anonymous = true;
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 = s.option(form.DummyValue, '_Hostname', _('Hostname'), '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'),
_('Public;Local Port'));
o.placeholder = '2222;22';
o.datatype = "list(string)"; //TODO port
o.rmempty = false;

o = s.option(form.Value, 'HookScript', _('Hook Script'), _('Path to script which is executed after starting tor-hs. Script is executed with paramters `--update-onion hostname`. Hostname is replaced with Onion v3 address for given hidden service.'));
o.modalonly = true;

return m.render();
},
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"admin/services/tor/": {
"title": "Tor Hidden 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,30 @@
{
"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 7b7a647

Please sign in to comment.