mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-08-26 12:46:08 +00:00
Add ikiwiki module with initial setup and option to enable site.
This commit is contained in:
parent
e09018fe9a
commit
fbce204180
193
actions/ikiwiki
Executable file
193
actions/ikiwiki
Executable file
@ -0,0 +1,193 @@
|
|||||||
|
#!/usr/bin/python3
|
||||||
|
#
|
||||||
|
# This file is part of Plinth.
|
||||||
|
#
|
||||||
|
# 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/>.
|
||||||
|
#
|
||||||
|
|
||||||
|
"""
|
||||||
|
Configuration helper for ikiwiki
|
||||||
|
"""
|
||||||
|
|
||||||
|
import argparse
|
||||||
|
import os
|
||||||
|
import subprocess
|
||||||
|
|
||||||
|
|
||||||
|
CONFIG_ENABLE = '/etc/apache2/conf-enabled/ikiwiki.conf'
|
||||||
|
CONFIG_FILE = '/etc/apache2/conf-available/ikiwiki.conf'
|
||||||
|
SETUP_WIKI = '/etc/ikiwiki/plinth-wiki.setup'
|
||||||
|
SETUP_BLOG = '/etc/ikiwiki/plinth-blog.setup'
|
||||||
|
WIKI_PATH = '/var/www/ikiwiki'
|
||||||
|
|
||||||
|
|
||||||
|
def parse_arguments():
|
||||||
|
"""Return parsed command line arguments as dictionary."""
|
||||||
|
parser = argparse.ArgumentParser()
|
||||||
|
subparsers = parser.add_subparsers(dest='subcommand', help='Sub command')
|
||||||
|
|
||||||
|
# Get whether ikiwiki site is enabled
|
||||||
|
subparsers.add_parser('get-enabled',
|
||||||
|
help='Get whether ikiwiki site is enabled')
|
||||||
|
|
||||||
|
# Enable ikiwiki site
|
||||||
|
subparsers.add_parser('enable', help='Enable ikiwiki site')
|
||||||
|
|
||||||
|
# Disable ikiwiki site
|
||||||
|
subparsers.add_parser('disable', help='Disable ikiwiki site')
|
||||||
|
|
||||||
|
# Create a wiki
|
||||||
|
create_wiki = subparsers.add_parser('create-wiki', help='Create a wiki')
|
||||||
|
create_wiki.add_argument('--name', help='Name of new wiki')
|
||||||
|
|
||||||
|
# Create a blog
|
||||||
|
create_blog = subparsers.add_parser('create-blog', help='Create a blog')
|
||||||
|
create_blog.add_argument('--name', help='Name of new blog')
|
||||||
|
|
||||||
|
return parser.parse_args()
|
||||||
|
|
||||||
|
|
||||||
|
def subcommand_get_enabled(_):
|
||||||
|
"""Get whether ikiwiki site is enabled."""
|
||||||
|
if os.path.isfile(CONFIG_ENABLE):
|
||||||
|
print('yes')
|
||||||
|
else:
|
||||||
|
print('no')
|
||||||
|
|
||||||
|
|
||||||
|
def subcommand_enable(_):
|
||||||
|
"""Enable ikiwiki site."""
|
||||||
|
if not os.path.isfile(CONFIG_FILE):
|
||||||
|
setup()
|
||||||
|
|
||||||
|
subprocess.check_output(['a2enconf', 'ikiwiki'])
|
||||||
|
subprocess.check_output(['service', 'apache2', 'reload'])
|
||||||
|
|
||||||
|
|
||||||
|
def subcommand_disable(_):
|
||||||
|
"""Disable ikiwiki site."""
|
||||||
|
subprocess.check_output(['a2disconf', 'ikiwiki'])
|
||||||
|
subprocess.check_output(['service', 'apache2', 'reload'])
|
||||||
|
|
||||||
|
|
||||||
|
def subcommand_create_wiki(arguments):
|
||||||
|
"""Create a wiki"""
|
||||||
|
subprocess.check_output(['ikiwiki', '-setup', SETUP_WIKI, arguments.name])
|
||||||
|
|
||||||
|
|
||||||
|
def subcommand_create_blog(arguments):
|
||||||
|
"""Create a blog"""
|
||||||
|
subprocess.check_output(['ikiwiki', '-setup', SETUP_BLOG, arguments.name])
|
||||||
|
|
||||||
|
|
||||||
|
def setup():
|
||||||
|
"""Initial setup"""
|
||||||
|
if not os.path.exists(WIKI_PATH):
|
||||||
|
os.makedirs(WIKI_PATH)
|
||||||
|
|
||||||
|
with open(CONFIG_FILE, 'w') as conffile:
|
||||||
|
conffile.writelines([
|
||||||
|
'Alias /ikiwiki /var/www/ikiwiki\n',
|
||||||
|
'AddHandler cgi-script .cgi\n',
|
||||||
|
'\n',
|
||||||
|
'<Directory /var/www/ikiwiki>\n',
|
||||||
|
' Options +ExecCGI\n',
|
||||||
|
'</Directory>\n'
|
||||||
|
])
|
||||||
|
|
||||||
|
with open(SETUP_WIKI, 'w') as setupfile:
|
||||||
|
setupfile.writelines([
|
||||||
|
'#!/usr/bin/perl\n',
|
||||||
|
'# Ikiwiki setup automator for Plinth.\n',
|
||||||
|
'\n',
|
||||||
|
'require IkiWiki::Setup::Automator;\n',
|
||||||
|
'\n',
|
||||||
|
'our $wikiname=$ARGV[0];\n',
|
||||||
|
'if ($wikiname eq "") {\n',
|
||||||
|
' print "Usage: ikiwiki -setup /etc/ikiwiki/plinth-wiki.setup wiki_name";\n',
|
||||||
|
' exit;\n',
|
||||||
|
'}\n',
|
||||||
|
'\n',
|
||||||
|
'our $wikiname_short=IkiWiki::Setup::Automator::sanitize_wikiname($wikiname);\n',
|
||||||
|
'\n',
|
||||||
|
'IkiWiki::Setup::Automator->import(\n',
|
||||||
|
' wikiname => $wikiname,\n',
|
||||||
|
' rcs => "git",\n',
|
||||||
|
' srcdir => "/var/ikiwiki/$wikiname_short",\n',
|
||||||
|
' destdir => "/var/www/ikiwiki/$wikiname_short",\n',
|
||||||
|
' repository => "/var/ikiwiki/$wikiname_short.git",\n',
|
||||||
|
' dumpsetup => "/var/ikiwiki/$wikiname_short.setup",\n',
|
||||||
|
' url => "/ikiwiki/$wikiname_short",\n',
|
||||||
|
' cgiurl => "/ikiwiki/$wikiname_short/ikiwiki.cgi",\n',
|
||||||
|
' cgi_wrapper => "/var/www/ikiwiki/$wikiname_short/ikiwiki.cgi",\n',
|
||||||
|
' add_plugins => [qw{goodstuff websetup httpauth}],\n',
|
||||||
|
' rss => 1,\n',
|
||||||
|
' atom => 1,\n',
|
||||||
|
' syslog => 1,\n',
|
||||||
|
')\n',
|
||||||
|
])
|
||||||
|
|
||||||
|
with open(SETUP_BLOG, 'w') as setupfile:
|
||||||
|
setupfile.writelines([
|
||||||
|
'#!/usr/bin/perl\n',
|
||||||
|
'# Ikiwiki setup automator for Plinth (blog version).\n',
|
||||||
|
'\n',
|
||||||
|
'require IkiWiki::Setup::Automator;\n',
|
||||||
|
'\n',
|
||||||
|
'our $wikiname=$ARGV[0];\n',
|
||||||
|
'if ($wikiname eq "") {\n',
|
||||||
|
' print "Usage: ikiwiki -setup /etc/ikiwiki/plinth-blog.setup blog_name";\n',
|
||||||
|
' exit;\n',
|
||||||
|
'}\n',
|
||||||
|
'\n',
|
||||||
|
'our $wikiname_short=IkiWiki::Setup::Automator::sanitize_wikiname($wikiname);\n',
|
||||||
|
'\n',
|
||||||
|
'IkiWiki::Setup::Automator->import(\n',
|
||||||
|
' wikiname => $wikiname,\n',
|
||||||
|
' rcs => "git",\n',
|
||||||
|
' srcdir => "/var/ikiwiki/$wikiname_short",\n',
|
||||||
|
' destdir => "/var/www/ikiwiki/$wikiname_short",\n',
|
||||||
|
' repository => "/var/ikiwiki/$wikiname_short.git",\n',
|
||||||
|
' dumpsetup => "/var/ikiwiki/$wikiname_short.setup",\n',
|
||||||
|
' url => "/ikiwiki/$wikiname_short",\n',
|
||||||
|
' cgiurl => "/ikiwiki/$wikiname_short/ikiwiki.cgi",\n',
|
||||||
|
' cgi_wrapper => "/var/www/ikiwiki/$wikiname_short/ikiwiki.cgi",\n',
|
||||||
|
' add_plugins => [qw{goodstuff websetup comments blogspam calendar sidebar trail httpauth}],\n',
|
||||||
|
' rss => 1,\n',
|
||||||
|
' atom => 1,\n',
|
||||||
|
' syslog => 1,\n',
|
||||||
|
'\n',
|
||||||
|
' example => "blog",\n',
|
||||||
|
' comments_pagespec => "posts/* and !*/Discussion",\n',
|
||||||
|
' blogspam_pagespec => "postcomment(*)",\n',
|
||||||
|
' archive_pagespec => "page(posts/*) and !*/Discussion",\n',
|
||||||
|
' global_sidebars => 0,\n',
|
||||||
|
' discussion => 0,\n',
|
||||||
|
' locked_pages => "* and !postcomment(*)",\n',
|
||||||
|
' tagbase => "tags",\n',
|
||||||
|
')\n',
|
||||||
|
])
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
"""Parse arguments and perform all duties."""
|
||||||
|
arguments = parse_arguments()
|
||||||
|
|
||||||
|
subcommand = arguments.subcommand.replace('-', '_')
|
||||||
|
subcommand_method = globals()['subcommand_' + subcommand]
|
||||||
|
subcommand_method(arguments)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
||||||
1
data/etc/plinth/modules-enabled/ikiwiki
Normal file
1
data/etc/plinth/modules-enabled/ikiwiki
Normal file
@ -0,0 +1 @@
|
|||||||
|
plinth.modules.ikiwiki
|
||||||
33
plinth/modules/ikiwiki/__init__.py
Normal file
33
plinth/modules/ikiwiki/__init__.py
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
#
|
||||||
|
# This file is part of Plinth.
|
||||||
|
#
|
||||||
|
# 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/>.
|
||||||
|
#
|
||||||
|
|
||||||
|
"""
|
||||||
|
Plinth module to configure ikiwiki
|
||||||
|
"""
|
||||||
|
|
||||||
|
from gettext import gettext as _
|
||||||
|
|
||||||
|
from plinth import cfg
|
||||||
|
|
||||||
|
|
||||||
|
depends = ['plinth.modules.apps']
|
||||||
|
|
||||||
|
|
||||||
|
def init():
|
||||||
|
"""Initialize the ikiwiki module."""
|
||||||
|
menu = cfg.main_menu.get('apps:index')
|
||||||
|
menu.add_urlname(_('Wiki & Blog'), 'glyphicon-edit', 'ikiwiki:index', 38)
|
||||||
30
plinth/modules/ikiwiki/forms.py
Normal file
30
plinth/modules/ikiwiki/forms.py
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
#
|
||||||
|
# This file is part of Plinth.
|
||||||
|
#
|
||||||
|
# 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/>.
|
||||||
|
#
|
||||||
|
|
||||||
|
"""
|
||||||
|
Forms for configuring ikiwiki
|
||||||
|
"""
|
||||||
|
|
||||||
|
from django import forms
|
||||||
|
from gettext import gettext as _
|
||||||
|
|
||||||
|
|
||||||
|
class IkiwikiForm(forms.Form):
|
||||||
|
"""ikiwiki configuration form."""
|
||||||
|
enabled = forms.BooleanField(
|
||||||
|
label=_('Enable ikiwiki site'),
|
||||||
|
required=False)
|
||||||
38
plinth/modules/ikiwiki/templates/ikiwiki.html
Normal file
38
plinth/modules/ikiwiki/templates/ikiwiki.html
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
{% extends "base.html" %}
|
||||||
|
{% comment %}
|
||||||
|
#
|
||||||
|
# This file is part of Plinth.
|
||||||
|
#
|
||||||
|
# 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/>.
|
||||||
|
#
|
||||||
|
{% endcomment %}
|
||||||
|
|
||||||
|
{% load bootstrap %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
|
||||||
|
<h2>Wiki & Blog</h2>
|
||||||
|
|
||||||
|
<p>When enabled, the ikiwiki site will be available from <a href="/ikiwiki">
|
||||||
|
/ikiwiki</a> path on the web server.</p>
|
||||||
|
|
||||||
|
<form class="form" method="post">
|
||||||
|
{% csrf_token %}
|
||||||
|
|
||||||
|
{{ form|bootstrap }}
|
||||||
|
|
||||||
|
<input type="submit" class="btn btn-primary" value="Update setup"/>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
{% endblock %}
|
||||||
28
plinth/modules/ikiwiki/urls.py
Normal file
28
plinth/modules/ikiwiki/urls.py
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
#
|
||||||
|
# This file is part of Plinth.
|
||||||
|
#
|
||||||
|
# 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/>.
|
||||||
|
#
|
||||||
|
|
||||||
|
"""
|
||||||
|
URLs for the ikiwiki module
|
||||||
|
"""
|
||||||
|
|
||||||
|
from django.conf.urls import patterns, url
|
||||||
|
|
||||||
|
|
||||||
|
urlpatterns = patterns(
|
||||||
|
'plinth.modules.ikiwiki.views',
|
||||||
|
url(r'^apps/ikiwiki/$', 'index', name='index'),
|
||||||
|
)
|
||||||
75
plinth/modules/ikiwiki/views.py
Normal file
75
plinth/modules/ikiwiki/views.py
Normal file
@ -0,0 +1,75 @@
|
|||||||
|
#
|
||||||
|
# This file is part of Plinth.
|
||||||
|
#
|
||||||
|
# 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/>.
|
||||||
|
#
|
||||||
|
|
||||||
|
"""
|
||||||
|
Plinth module for configuring ikiwiki
|
||||||
|
"""
|
||||||
|
|
||||||
|
from django.contrib import messages
|
||||||
|
from django.contrib.auth.decorators import login_required
|
||||||
|
from django.template.response import TemplateResponse
|
||||||
|
from gettext import gettext as _
|
||||||
|
|
||||||
|
from .forms import IkiwikiForm
|
||||||
|
from plinth import actions
|
||||||
|
from plinth import package
|
||||||
|
from plinth.modules import ikiwiki
|
||||||
|
|
||||||
|
|
||||||
|
@login_required
|
||||||
|
@package.required(['ikiwiki'])
|
||||||
|
def index(request):
|
||||||
|
"""Serve configuration page."""
|
||||||
|
status = get_status()
|
||||||
|
|
||||||
|
form = None
|
||||||
|
|
||||||
|
if request.method == 'POST':
|
||||||
|
form = IkiwikiForm(request.POST, prefix='ikiwiki')
|
||||||
|
if form.is_valid():
|
||||||
|
_apply_changes(request, status, form.cleaned_data)
|
||||||
|
status = get_status()
|
||||||
|
form = IkiwikiForm(initial=status, prefix='ikiwiki')
|
||||||
|
else:
|
||||||
|
form = IkiwikiForm(initial=status, prefix='ikiwiki')
|
||||||
|
|
||||||
|
return TemplateResponse(request, 'ikiwiki.html',
|
||||||
|
{'title': _('Wiki'),
|
||||||
|
'status': status,
|
||||||
|
'form': form})
|
||||||
|
|
||||||
|
|
||||||
|
def get_status():
|
||||||
|
"""Get the current setting."""
|
||||||
|
output = actions.run('ikiwiki', ['get-enabled'])
|
||||||
|
enabled = (output.strip() == 'yes')
|
||||||
|
return {'enabled': enabled}
|
||||||
|
|
||||||
|
|
||||||
|
def _apply_changes(request, old_status, new_status):
|
||||||
|
"""Apply the changes."""
|
||||||
|
modified = False
|
||||||
|
|
||||||
|
if old_status['enabled'] != new_status['enabled']:
|
||||||
|
sub_command = 'enable' if new_status['enabled'] else 'disable'
|
||||||
|
actions.superuser_run('ikiwiki', [sub_command])
|
||||||
|
modified = True
|
||||||
|
|
||||||
|
if modified:
|
||||||
|
messages.success(request, _('Configuration updated'))
|
||||||
|
else:
|
||||||
|
messages.info(request, _('Setting unchanged'))
|
||||||
Loading…
x
Reference in New Issue
Block a user