i2p: Include default favorites after installation

The default favorites might change and we might have to update the list but for
now they were extracted from a clean router.config saved by the i2p daemon.

1528 - augeas for router.config

Reviewed-by: Sunil Mohan Adapa <sunil@medhas.org>
This commit is contained in:
LoveIsGrief 2019-04-13 19:39:57 +02:00 committed by Sunil Mohan Adapa
parent 1c9ad9f953
commit f7d9c9eff5
No known key found for this signature in database
GPG Key ID: 43EA1CFF0AA7C5F2
4 changed files with 165 additions and 21 deletions

View File

@ -43,6 +43,8 @@ def parse_arguments():
'add-favorite', help='Add an eepsite to the list of favorites')
subparser.add_argument('--name', help='Name of the entry', required=True)
subparser.add_argument('--url', help='URL of the entry', required=True)
subparser.add_argument('--description', help='short description', required=False)
subparser.add_argument('--icon', help='URL to icon', required=False)
subparser = subparsers.add_parser('set-tunnel-property',
help='Modify configuration of a tunnel')
@ -92,7 +94,9 @@ def subcommand_add_favorite(arguments):
editor = RouterEditor()
editor.read_conf().add_favorite(
arguments.name,
url
url,
arguments.description,
arguments.icon
).write_conf()
print('Added {} to favorites'.format(url))

View File

@ -23,8 +23,8 @@ from django.utils.translation import ugettext_lazy as _
from plinth import action_utils, actions, frontpage
from plinth import service as service_module
from plinth.menu import main_menu
from plinth.modules.i2p.resources import FAVORITES
from plinth.modules.users import register_group
from .manifest import backup, clients
version = 1
@ -59,17 +59,6 @@ proxies_service = None
manual_page = 'I2P'
# TODO: Add all default favorites
# the router.config favorites is empty until a change is made
# in the front-end, but we currently do not have a method of
# doing that, so we need to add the favorites ourselves
additional_favorites = [
('Searx instance', 'http://ransack.i2p'),
('Torrent tracker', 'http://tracker2.postman.i2p'),
('YaCy Legwork', 'http://legwork.i2p'),
('YaCy Seeker', 'http://seeker.i2p'),
]
tunnels_to_manage = {
'I2P HTTP Proxy': 'i2p-http-proxy-freedombox',
'I2P HTTPS Proxy': 'i2p-https-proxy-freedombox',
@ -105,14 +94,20 @@ def setup(helper, old_version=None):
helper.call('post', disable)
# Add favorites to the configuration
for fav_name, fav_url in additional_favorites:
helper.call('post', actions.superuser_run, 'i2p', [
for fav in FAVORITES:
args = [
'add-favorite',
'--name',
fav_name,
'--url',
fav_url,
])
'--name', fav.get('name'),
'--url', fav.get('url'),
]
if 'icon' in fav:
args.extend(['--icon', fav.get('icon')])
if 'description' in fav:
args.extend(['--description', fav.get('description')])
helper.call('post', actions.superuser_run, 'i2p', args)
# Tunnels to all interfaces
for tunnel in tunnels_to_manage:

View File

@ -166,7 +166,7 @@ class RouterEditor(object):
def favorite_property(self):
return '/files{filename}/{prop}'.format(filename=self.conf_filename, prop=self.FAVORITE_PROP)
def add_favorite(self, name, url, description='', icon='/themes/console/images/eepsite.png'):
def add_favorite(self, name, url, description=None, icon=None):
"""
Adds a favorite to the router.config
@ -182,6 +182,11 @@ class RouterEditor(object):
:type description: basestring
:type icon: basestring
"""
if not description:
description = ''
if not icon:
icon = '/themes/console/images/eepsite.png'
if ',' in url:
raise ValueError('URL cannot contain commas')
if ',' in icon:

View File

@ -0,0 +1,140 @@
# This file is part of FreedomBox.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
DEFAULT_FAVORITES = [
{
'name': 'anoncoin.i2p',
'description': 'The Anoncoin project',
'icon': '/themes/console/images/anoncoin_32.png',
'url': 'http://anoncoin.i2p/'
},
{
'name': 'Dev Builds',
'description': 'Development builds of I2P',
'icon': '/themes/console/images/script_gear.png',
'url': 'http://bobthebuilder.i2p/'
},
{
'name': 'Dev Forum',
'description': 'Development forum',
'icon': '/themes/console/images/group_gear.png',
'url': 'http://zzz.i2p/'
},
{
'name': 'echelon.i2p',
'description': 'I2P Applications',
'icon': '/themes/console/images/box_open.png',
'url': 'http://echelon.i2p/'
},
{
'name': 'exchanged.i2p',
'description': 'Anonymous cryptocurrency exchange',
'icon': '/themes/console/images/exchanged.png',
'url': 'http://exchanged.i2p/'
},
{
'name': 'I2P Bug Reports',
'description': 'Bug tracker',
'icon': '/themes/console/images/bug.png',
'url': 'http://trac.i2p2.i2p/report/1'
},
{
'name': 'I2P FAQ',
'description': 'Frequently Asked Questions',
'icon': '/themes/console/images/question.png',
'url': 'http://i2p-projekt.i2p/faq'
},
{
'name': 'I2P Forum',
'description': 'Community forum',
'icon': '/themes/console/images/group.png',
'url': 'http://i2pforum.i2p/'
},
{
'name': 'I2P Plugins',
'description': 'Add-on directory',
'icon': '/themes/console/images/info/plugin_link.png',
'url': 'http://i2pwiki.i2p/index.php?title=Plugins'
},
{
'name': 'I2P Technical Docs',
'description': 'Technical documentation',
'icon': '/themes/console/images/education.png',
'url': 'http://i2p-projekt.i2p/how'
},
{
'name': 'I2P Wiki',
'description': 'Anonymous wiki - share the knowledge',
'icon': '/themes/console/images/i2pwiki_logo.png',
'url': 'http://i2pwiki.i2p/'
},
{
'name': 'Planet I2P',
'description': 'I2P News',
'icon': '/themes/console/images/world.png',
'url': 'http://planet.i2p/'
},
{
'name': 'PrivateBin',
'description': 'Encrypted I2P Pastebin',
'icon': '/themes/console/images/paste_plain.png',
'url': 'http://paste.crypthost.i2p/'
},
{
'name': 'Project Website',
'description': 'I2P home page',
'icon': '/themes/console/images/info_rhombus.png',
'url': 'http://i2p-projekt.i2p/'
},
{
'name': 'stats.i2p',
'description': 'I2P Network Statistics',
'icon': '/themes/console/images/chart_line.png',
'url': 'http://stats.i2p/cgi-bin/dashboard.cgi'
},
{
'name': 'The Tin Hat',
'description': 'Privacy guides and tutorials',
'icon': '/themes/console/images/thetinhat.png',
'url': 'http://secure.thetinhat.i2p/'
},
{
'name': 'Trac Wiki',
'description': '',
'icon': '/themes/console/images/billiard_marker.png',
'url': 'http://trac.i2p2.i2p/'
}
]
ADDITIONAL_FAVORITES = [
{
'name': 'Searx instance',
'url': 'http://ransack.i2p'
},
{
'name': 'Torrent tracker',
'url': 'http://tracker2.postman.i2p'
},
{
'name': 'YaCy Legwork',
'url': 'http://legwork.i2p'
},
{
'name': 'YaCy Seeker',
'url': 'http://seeker.i2p'
},
]
FAVORITES = DEFAULT_FAVORITES + ADDITIONAL_FAVORITES