mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-11-29 08:25:10 +00:00
Created a custom command in Plinth to disable ssl for the diaspora pod on the freedombox.
102 lines
3.4 KiB
Python
Executable File
102 lines
3.4 KiB
Python
Executable File
#!/usr/bin/python3
|
|
# -*- mode: python -*-
|
|
#
|
|
# 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 diaspora* pod.
|
|
"""
|
|
|
|
import argparse
|
|
import socket
|
|
import subprocess
|
|
|
|
from plinth import action_utils
|
|
|
|
|
|
def parse_arguments():
|
|
"""Return parsed command line arguments as dictionary."""
|
|
parser = argparse.ArgumentParser()
|
|
subparsers = parser.add_subparsers(dest='subcommand', help='Sub command')
|
|
pre_install = subparsers.add_parser(
|
|
'pre-install',
|
|
help='Preseed debconf values before packages are installed.')
|
|
|
|
subparsers.add_parser('enable', help='Enable diaspora*')
|
|
subparsers.add_parser('disable', help='Disable diaspora*')
|
|
subparsers.add_parser('disable-ssl', help="Disable SSL on the diaspora* application server")
|
|
|
|
return parser.parse_args()
|
|
|
|
|
|
def subcommand_disable_ssl(_):
|
|
"""
|
|
Disable ssl in the diaspora configuration
|
|
as the apache server takes care of ssl
|
|
"""
|
|
subprocess.call(["sed", "-i",
|
|
"s/#require_ssl: true/require_ssl: false/g",
|
|
"/etc/diaspora/diaspora.yml"])
|
|
|
|
|
|
def subcommand_pre_install(arguments):
|
|
"""Pre installation configuration for diaspora"""
|
|
presets= [
|
|
b'diaspora-common diaspora-common/url string http://localhost/diaspora',
|
|
b'diaspora-common diaspora-common/dbpass note ',
|
|
b'diaspora-common diaspora-common/enablessl boolean false',
|
|
b'diaspora-common diaspora-common/useletsencrypt string false',
|
|
b'diaspora-common diaspora-common/services multiselect ',
|
|
b'diaspora-common diaspora-common/ssl boolean false',
|
|
b'diaspora-common diaspora-common/pgsql/authmethod-admin string ident',
|
|
b'diaspora-common diaspora-common/letsencrypt boolean false',
|
|
b'diaspora-common diaspora-common/remote/host string localhost',
|
|
b'diaspora-common diaspora-common/database-type string pgsql',
|
|
b'diaspora-common diaspora-common/dbconfig-install boolean true'
|
|
]
|
|
|
|
for preset in presets:
|
|
subprocess.check_output(['debconf-set-selections'], input=preset)
|
|
|
|
# hostname = arguments.hostname or socket.gethostname()
|
|
# subprocess.check_output(
|
|
# ['debconf-set-selections'],
|
|
# input=b'diaspora diaspora/url string ' + hostname.encode())
|
|
|
|
def subcommand_enable(_):
|
|
"""Enable web configuration and reload."""
|
|
action_utils.webserver_enable('diaspora-plinth')
|
|
|
|
|
|
def subcommand_disable(_):
|
|
"""Disable web configuration and reload."""
|
|
action_utils.webserver_disable('diaspora-plinth')
|
|
|
|
|
|
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()
|
|
|