mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-08-26 12:46:08 +00:00
ikiwiki: Create admin account for new wiki/blog.
This commit is contained in:
parent
18234850ff
commit
35dcde00de
@ -30,7 +30,8 @@ CONFIG_ENABLE = '/etc/apache2/conf-enabled/ikiwiki.conf'
|
|||||||
CONFIG_FILE = '/etc/apache2/conf-available/ikiwiki.conf'
|
CONFIG_FILE = '/etc/apache2/conf-available/ikiwiki.conf'
|
||||||
SETUP_WIKI = '/etc/ikiwiki/plinth-wiki.setup'
|
SETUP_WIKI = '/etc/ikiwiki/plinth-wiki.setup'
|
||||||
SETUP_BLOG = '/etc/ikiwiki/plinth-blog.setup'
|
SETUP_BLOG = '/etc/ikiwiki/plinth-blog.setup'
|
||||||
WIKI_PATH = '/var/www/ikiwiki'
|
SITE_PATH = '/var/www/ikiwiki'
|
||||||
|
WIKI_PATH = '/var/ikiwiki'
|
||||||
|
|
||||||
|
|
||||||
def parse_arguments():
|
def parse_arguments():
|
||||||
@ -53,11 +54,17 @@ def parse_arguments():
|
|||||||
|
|
||||||
# Create a wiki
|
# Create a wiki
|
||||||
create_wiki = subparsers.add_parser('create-wiki', help='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_wiki.add_argument('--wiki_name', help='Name of new wiki')
|
||||||
|
create_wiki.add_argument('--admin_name', help='Administrator account name')
|
||||||
|
create_wiki.add_argument('--admin_password',
|
||||||
|
help='Administrator account password')
|
||||||
|
|
||||||
# Create a blog
|
# Create a blog
|
||||||
create_blog = subparsers.add_parser('create-blog', help='Create a blog')
|
create_blog = subparsers.add_parser('create-blog', help='Create a blog')
|
||||||
create_blog.add_argument('--name', help='Name of new blog')
|
create_blog.add_argument('--blog_name', help='Name of new blog')
|
||||||
|
create_blog.add_argument('--admin_name', help='Administrator account name')
|
||||||
|
create_blog.add_argument('--admin_password',
|
||||||
|
help='Administrator account password')
|
||||||
|
|
||||||
# Delete a wiki or blog
|
# Delete a wiki or blog
|
||||||
delete = subparsers.add_parser('delete', help='Delete a wiki or blog.')
|
delete = subparsers.add_parser('delete', help='Delete a wiki or blog.')
|
||||||
@ -78,40 +85,59 @@ def subcommand_enable(_):
|
|||||||
"""Enable ikiwiki site."""
|
"""Enable ikiwiki site."""
|
||||||
if not os.path.isfile(CONFIG_FILE):
|
if not os.path.isfile(CONFIG_FILE):
|
||||||
setup()
|
setup()
|
||||||
subprocess.check_output(['a2enconf', 'ikiwiki'])
|
subprocess.check_call(['a2enconf', 'ikiwiki'])
|
||||||
subprocess.check_output(['service', 'apache2', 'restart'])
|
subprocess.check_call(['service', 'apache2', 'restart'])
|
||||||
else:
|
else:
|
||||||
subprocess.check_output(['a2enconf', 'ikiwiki'])
|
subprocess.check_call(['a2enconf', 'ikiwiki'])
|
||||||
subprocess.check_output(['service', 'apache2', 'reload'])
|
subprocess.check_call(['service', 'apache2', 'reload'])
|
||||||
|
|
||||||
|
|
||||||
def subcommand_disable(_):
|
def subcommand_disable(_):
|
||||||
"""Disable ikiwiki site."""
|
"""Disable ikiwiki site."""
|
||||||
subprocess.check_output(['a2disconf', 'ikiwiki'])
|
subprocess.check_call(['a2disconf', 'ikiwiki'])
|
||||||
subprocess.check_output(['service', 'apache2', 'reload'])
|
subprocess.check_call(['service', 'apache2', 'reload'])
|
||||||
|
|
||||||
|
|
||||||
def subcommand_get_sites(_):
|
def subcommand_get_sites(_):
|
||||||
"""Get wikis and blogs."""
|
"""Get wikis and blogs."""
|
||||||
sites = os.listdir(WIKI_PATH)
|
sites = os.listdir(SITE_PATH)
|
||||||
print('\n'.join(sites))
|
print('\n'.join(sites))
|
||||||
|
|
||||||
|
|
||||||
def subcommand_create_wiki(arguments):
|
def subcommand_create_wiki(arguments):
|
||||||
"""Create a wiki."""
|
"""Create a wiki."""
|
||||||
subprocess.check_output(['ikiwiki', '-setup', SETUP_WIKI, arguments.name])
|
pw_bytes = arguments.admin_password.encode()
|
||||||
|
proc = subprocess.Popen(
|
||||||
|
['ikiwiki', '-setup', SETUP_WIKI,
|
||||||
|
arguments.wiki_name, arguments.admin_name],
|
||||||
|
stdout=subprocess.PIPE, stdin=subprocess.PIPE, stderr=subprocess.PIPE)
|
||||||
|
outs, errs = proc.communicate(input=pw_bytes + b'\n' + pw_bytes)
|
||||||
|
print(outs)
|
||||||
|
print(errs)
|
||||||
|
|
||||||
|
|
||||||
def subcommand_create_blog(arguments):
|
def subcommand_create_blog(arguments):
|
||||||
"""Create a blog."""
|
"""Create a blog."""
|
||||||
subprocess.check_output(['ikiwiki', '-setup', SETUP_BLOG, arguments.name])
|
pw_bytes = arguments.admin_password.encode()
|
||||||
|
proc = subprocess.Popen(
|
||||||
|
['ikiwiki', '-setup', SETUP_BLOG,
|
||||||
|
arguments.blog_name, arguments.admin_name],
|
||||||
|
stdout=subprocess.PIPE, stdin=subprocess.PIPE, stderr=subprocess.PIPE)
|
||||||
|
outs, errs = proc.communicate(input=pw_bytes + b'\n' + pw_bytes)
|
||||||
|
print(outs)
|
||||||
|
print(errs)
|
||||||
|
|
||||||
|
|
||||||
def subcommand_delete(arguments):
|
def subcommand_delete(arguments):
|
||||||
"""Delete a wiki or blog."""
|
"""Delete a wiki or blog."""
|
||||||
|
html_folder = os.path.join(SITE_PATH, arguments.name)
|
||||||
wiki_folder = os.path.join(WIKI_PATH, arguments.name)
|
wiki_folder = os.path.join(WIKI_PATH, arguments.name)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
shutil.rmtree(html_folder)
|
||||||
shutil.rmtree(wiki_folder)
|
shutil.rmtree(wiki_folder)
|
||||||
|
shutil.rmtree(wiki_folder + '.git')
|
||||||
|
os.remove(wiki_folder + '.setup')
|
||||||
print('Deleted %s' % arguments.name)
|
print('Deleted %s' % arguments.name)
|
||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
print('Error: %s not found.' % arguments.name)
|
print('Error: %s not found.' % arguments.name)
|
||||||
@ -120,10 +146,10 @@ def subcommand_delete(arguments):
|
|||||||
|
|
||||||
def setup():
|
def setup():
|
||||||
"""Initial setup"""
|
"""Initial setup"""
|
||||||
if not os.path.exists(WIKI_PATH):
|
if not os.path.exists(SITE_PATH):
|
||||||
os.makedirs(WIKI_PATH)
|
os.makedirs(SITE_PATH)
|
||||||
|
|
||||||
subprocess.check_output(['a2enmod', 'cgi'])
|
subprocess.check_call(['a2enmod', 'cgi'])
|
||||||
|
|
||||||
with open(CONFIG_FILE, 'w') as conffile:
|
with open(CONFIG_FILE, 'w') as conffile:
|
||||||
conffile.writelines([
|
conffile.writelines([
|
||||||
@ -143,15 +169,19 @@ def setup():
|
|||||||
'require IkiWiki::Setup::Automator;\n',
|
'require IkiWiki::Setup::Automator;\n',
|
||||||
'\n',
|
'\n',
|
||||||
'our $wikiname=$ARGV[0];\n',
|
'our $wikiname=$ARGV[0];\n',
|
||||||
'if ($wikiname eq "") {\n',
|
'our $admin=$ARGV[1];\n',
|
||||||
' print "Usage: ikiwiki -setup /etc/ikiwiki/plinth-wiki.setup wiki_name";\n',
|
'if (($wikiname eq "") || ($admin eq "")) {\n',
|
||||||
|
' print "Usage: ikiwiki -setup /etc/ikiwiki/plinth-wiki.setup ',
|
||||||
|
'wiki_name admin_name";\n',
|
||||||
' exit;\n',
|
' exit;\n',
|
||||||
'}\n',
|
'}\n',
|
||||||
'\n',
|
'\n',
|
||||||
'our $wikiname_short=IkiWiki::Setup::Automator::sanitize_wikiname($wikiname);\n',
|
'our $wikiname_short=IkiWiki::Setup::Automator::sanitize_wikiname',
|
||||||
|
'($wikiname);\n',
|
||||||
'\n',
|
'\n',
|
||||||
'IkiWiki::Setup::Automator->import(\n',
|
'IkiWiki::Setup::Automator->import(\n',
|
||||||
' wikiname => $wikiname,\n',
|
' wikiname => $wikiname,\n',
|
||||||
|
' adminuser => [$admin],\n',
|
||||||
' rcs => "git",\n',
|
' rcs => "git",\n',
|
||||||
' srcdir => "/var/ikiwiki/$wikiname_short",\n',
|
' srcdir => "/var/ikiwiki/$wikiname_short",\n',
|
||||||
' destdir => "/var/www/ikiwiki/$wikiname_short",\n',
|
' destdir => "/var/www/ikiwiki/$wikiname_short",\n',
|
||||||
@ -159,7 +189,8 @@ def setup():
|
|||||||
' dumpsetup => "/var/ikiwiki/$wikiname_short.setup",\n',
|
' dumpsetup => "/var/ikiwiki/$wikiname_short.setup",\n',
|
||||||
' url => "/ikiwiki/$wikiname_short",\n',
|
' url => "/ikiwiki/$wikiname_short",\n',
|
||||||
' cgiurl => "/ikiwiki/$wikiname_short/ikiwiki.cgi",\n',
|
' cgiurl => "/ikiwiki/$wikiname_short/ikiwiki.cgi",\n',
|
||||||
' cgi_wrapper => "/var/www/ikiwiki/$wikiname_short/ikiwiki.cgi",\n',
|
' cgi_wrapper => "/var/www/ikiwiki/$wikiname_short/ikiwiki.cgi",'
|
||||||
|
'\n',
|
||||||
' add_plugins => [qw{goodstuff websetup httpauth}],\n',
|
' add_plugins => [qw{goodstuff websetup httpauth}],\n',
|
||||||
' rss => 1,\n',
|
' rss => 1,\n',
|
||||||
' atom => 1,\n',
|
' atom => 1,\n',
|
||||||
@ -175,15 +206,19 @@ def setup():
|
|||||||
'require IkiWiki::Setup::Automator;\n',
|
'require IkiWiki::Setup::Automator;\n',
|
||||||
'\n',
|
'\n',
|
||||||
'our $wikiname=$ARGV[0];\n',
|
'our $wikiname=$ARGV[0];\n',
|
||||||
'if ($wikiname eq "") {\n',
|
'our $admin=$ARGV[1];\n',
|
||||||
' print "Usage: ikiwiki -setup /etc/ikiwiki/plinth-blog.setup blog_name";\n',
|
'if (($wikiname eq "") || ($admin eq "")) {\n',
|
||||||
|
' print "Usage: ikiwiki -setup /etc/ikiwiki/plinth-blog.setup ',
|
||||||
|
'blog_name admin_name";\n',
|
||||||
' exit;\n',
|
' exit;\n',
|
||||||
'}\n',
|
'}\n',
|
||||||
'\n',
|
'\n',
|
||||||
'our $wikiname_short=IkiWiki::Setup::Automator::sanitize_wikiname($wikiname);\n',
|
'our $wikiname_short=IkiWiki::Setup::Automator::sanitize_wikiname',
|
||||||
|
'($wikiname);\n',
|
||||||
'\n',
|
'\n',
|
||||||
'IkiWiki::Setup::Automator->import(\n',
|
'IkiWiki::Setup::Automator->import(\n',
|
||||||
' wikiname => $wikiname,\n',
|
' wikiname => $wikiname,\n',
|
||||||
|
' adminuser => [$admin],\n',
|
||||||
' rcs => "git",\n',
|
' rcs => "git",\n',
|
||||||
' srcdir => "/var/ikiwiki/$wikiname_short",\n',
|
' srcdir => "/var/ikiwiki/$wikiname_short",\n',
|
||||||
' destdir => "/var/www/ikiwiki/$wikiname_short",\n',
|
' destdir => "/var/www/ikiwiki/$wikiname_short",\n',
|
||||||
@ -191,8 +226,10 @@ def setup():
|
|||||||
' dumpsetup => "/var/ikiwiki/$wikiname_short.setup",\n',
|
' dumpsetup => "/var/ikiwiki/$wikiname_short.setup",\n',
|
||||||
' url => "/ikiwiki/$wikiname_short",\n',
|
' url => "/ikiwiki/$wikiname_short",\n',
|
||||||
' cgiurl => "/ikiwiki/$wikiname_short/ikiwiki.cgi",\n',
|
' cgiurl => "/ikiwiki/$wikiname_short/ikiwiki.cgi",\n',
|
||||||
' cgi_wrapper => "/var/www/ikiwiki/$wikiname_short/ikiwiki.cgi",\n',
|
' cgi_wrapper => "/var/www/ikiwiki/$wikiname_short/ikiwiki.cgi",'
|
||||||
' add_plugins => [qw{goodstuff websetup comments calendar sidebar trail httpauth}],\n',
|
'\n',
|
||||||
|
' add_plugins => [qw{goodstuff websetup comments calendar '
|
||||||
|
'sidebar trail httpauth}],\n',
|
||||||
' rss => 1,\n',
|
' rss => 1,\n',
|
||||||
' atom => 1,\n',
|
' atom => 1,\n',
|
||||||
' syslog => 1,\n',
|
' syslog => 1,\n',
|
||||||
|
|||||||
@ -36,3 +36,7 @@ class IkiwikiCreateForm(forms.Form):
|
|||||||
label=_('Type'),
|
label=_('Type'),
|
||||||
choices=[('wiki', 'Wiki'), ('blog', 'Blog')])
|
choices=[('wiki', 'Wiki'), ('blog', 'Blog')])
|
||||||
name = forms.CharField(label=_('Name'))
|
name = forms.CharField(label=_('Name'))
|
||||||
|
admin_name = forms.CharField(label=_('Admin Account Name'))
|
||||||
|
admin_password = forms.CharField(
|
||||||
|
label=_('Admin Account Password'),
|
||||||
|
widget=forms.PasswordInput())
|
||||||
|
|||||||
@ -25,6 +25,7 @@ from django.core.urlresolvers import reverse_lazy
|
|||||||
from django.shortcuts import redirect
|
from django.shortcuts import redirect
|
||||||
from django.template.response import TemplateResponse
|
from django.template.response import TemplateResponse
|
||||||
from gettext import gettext as _
|
from gettext import gettext as _
|
||||||
|
import logging
|
||||||
|
|
||||||
from .forms import IkiwikiForm, IkiwikiCreateForm
|
from .forms import IkiwikiForm, IkiwikiCreateForm
|
||||||
from plinth import actions
|
from plinth import actions
|
||||||
@ -32,6 +33,8 @@ from plinth import package
|
|||||||
from plinth.modules import ikiwiki
|
from plinth.modules import ikiwiki
|
||||||
|
|
||||||
|
|
||||||
|
LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
subsubmenu = [{'url': reverse_lazy('ikiwiki:index'),
|
subsubmenu = [{'url': reverse_lazy('ikiwiki:index'),
|
||||||
'text': _('Configure')},
|
'text': _('Configure')},
|
||||||
{'url': reverse_lazy('ikiwiki:manage'),
|
{'url': reverse_lazy('ikiwiki:manage'),
|
||||||
@ -107,9 +110,13 @@ def create(request):
|
|||||||
form = IkiwikiCreateForm(request.POST, prefix='ikiwiki')
|
form = IkiwikiCreateForm(request.POST, prefix='ikiwiki')
|
||||||
if form.is_valid():
|
if form.is_valid():
|
||||||
if form.cleaned_data['type'] == 'wiki':
|
if form.cleaned_data['type'] == 'wiki':
|
||||||
_create_wiki(request, form.cleaned_data['name'])
|
_create_wiki(request, form.cleaned_data['name'],
|
||||||
|
form.cleaned_data['admin_name'],
|
||||||
|
form.cleaned_data['admin_password'])
|
||||||
elif form.cleaned_data['type'] == 'blog':
|
elif form.cleaned_data['type'] == 'blog':
|
||||||
_create_blog(request, form.cleaned_data['name'])
|
_create_blog(request, form.cleaned_data['name'],
|
||||||
|
form.cleaned_data['admin_name'],
|
||||||
|
form.cleaned_data['admin_password'])
|
||||||
|
|
||||||
return redirect(reverse_lazy('ikiwiki:manage'))
|
return redirect(reverse_lazy('ikiwiki:manage'))
|
||||||
else:
|
else:
|
||||||
@ -121,19 +128,27 @@ def create(request):
|
|||||||
'subsubmenu': subsubmenu})
|
'subsubmenu': subsubmenu})
|
||||||
|
|
||||||
|
|
||||||
def _create_wiki(request, name):
|
def _create_wiki(request, name, admin_name, admin_password):
|
||||||
"""Create wiki."""
|
"""Create wiki."""
|
||||||
try:
|
try:
|
||||||
actions.superuser_run('ikiwiki', ['create-wiki', '--name', name])
|
output = actions.superuser_run(
|
||||||
|
'ikiwiki',
|
||||||
|
['create-wiki', '--wiki_name', name,
|
||||||
|
'--admin_name', admin_name, '--admin_password', admin_password])
|
||||||
|
#LOGGER.info('create wiki: %s' % output)
|
||||||
messages.success(request, _('Created wiki %s.') % name)
|
messages.success(request, _('Created wiki %s.') % name)
|
||||||
except actions.ActionError as err:
|
except actions.ActionError as err:
|
||||||
messages.error(request, _('Could not create wiki: %s') % err)
|
messages.error(request, _('Could not create wiki: %s') % err)
|
||||||
|
|
||||||
|
|
||||||
def _create_blog(request, name):
|
def _create_blog(request, name, admin_name, admin_password):
|
||||||
"""Create blog."""
|
"""Create blog."""
|
||||||
try:
|
try:
|
||||||
actions.superuser_run('ikiwiki', ['create-blog', '--name', name])
|
output = actions.superuser_run(
|
||||||
|
'ikiwiki',
|
||||||
|
['create-blog', '--blog_name', name,
|
||||||
|
'--admin_name', admin_name, '--admin_password', admin_password])
|
||||||
|
#LOGGER.info('create blog: %s' % output)
|
||||||
messages.success(request, _('Created blog %s.') % name)
|
messages.success(request, _('Created blog %s.') % name)
|
||||||
except actions.ActionError as err:
|
except actions.ActionError as err:
|
||||||
messages.error(request, _('Could not create blog: %s') % err)
|
messages.error(request, _('Could not create blog: %s') % err)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user