mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-11-29 08:25:10 +00:00
Merge remote-tracking branch 'upstream/master' into dynamicdns
This commit is contained in:
commit
6c214c915c
26 files changed
+546
-223
No files matched your search
@@ -9,19 +9,19 @@
|
||||
#
|
||||
# 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
|
||||
# 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/>.
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
|
||||
# Action to backup ejabberd database before changing hostname.
|
||||
domainname="$1"
|
||||
hostname=$(hostname)
|
||||
|
||||
BACKUP=/tmp/ejabberd.dump
|
||||
ejabberdctl dump $BACKUP
|
||||
ejabberdctl stop
|
||||
|
||||
# Make sure there aren't files in the Mnesia spool dir
|
||||
mkdir -p /var/lib/ejabberd/oldfiles
|
||||
mv /var/lib/ejabberd/*.* /var/lib/ejabberd/oldfiles/
|
||||
if grep -q 127.0.1.1 /etc/hosts ; then
|
||||
sed -i "s/127.0.1.1.*/127.0.1.1 $hostname.$domainname $hostname/" /etc/hosts
|
||||
else
|
||||
sed -i "/127.0.0.1.*/a \
|
||||
127.0.1.1 $hostname.$domainname $hostname" /etc/hosts
|
||||
fi
|
||||
@@ -30,10 +30,6 @@ def parse_arguments():
|
||||
parser = argparse.ArgumentParser()
|
||||
subparsers = parser.add_subparsers(dest='subcommand', help='Sub command')
|
||||
|
||||
# Get installed status
|
||||
subparsers.add_parser('get-installed',
|
||||
help='Get whether firewalld is installed')
|
||||
|
||||
# Get status
|
||||
subparsers.add_parser('get-status',
|
||||
help='Get whether firewalld is running')
|
||||
@@ -64,14 +60,6 @@ def parse_arguments():
|
||||
return parser.parse_args()
|
||||
|
||||
|
||||
def subcommand_get_installed(_):
|
||||
"""Print whether firewalld is installed"""
|
||||
with open('/dev/null', 'w') as file_handle:
|
||||
status = subprocess.call(['which', 'firewalld'], stdout=file_handle)
|
||||
|
||||
print('installed' if not status else 'not installed')
|
||||
|
||||
|
||||
def subcommand_get_status(_):
|
||||
"""Print status of the firewalld service"""
|
||||
subprocess.call(['firewall-cmd', '--state'])
|
||||
|
||||
@@ -18,11 +18,15 @@
|
||||
|
||||
hostname="$1"
|
||||
|
||||
echo "$hostname" > /etc/hostname
|
||||
if [ -x /etc/init.d/hostname.sh ] ; then
|
||||
service hostname.sh start
|
||||
if [ -d /run/systemd/system ] ; then
|
||||
hostnamectl set-hostname --transient --static "$hostname"
|
||||
else
|
||||
service hostname start
|
||||
echo "$hostname" > /etc/hostname
|
||||
if [ -x /etc/init.d/hostname.sh ] ; then
|
||||
invoke-rc.d hostname.sh start
|
||||
else
|
||||
service hostname start
|
||||
fi
|
||||
fi
|
||||
|
||||
service avahi-daemon restart
|
||||
@@ -58,14 +58,6 @@ done
|
||||
|
||||
if [ "$owncloud_enable" != "$owncloud_enable_cur" ] ; then
|
||||
if $owncloud_enable ; then
|
||||
# Select postgresql as the backend database for OwnCloud, and
|
||||
# make sure its php support is enabled when owncloud is
|
||||
# installed.
|
||||
DEBIAN_FRONTEND=noninteractive apt-get --no-install-recommends \
|
||||
install -y postgresql php5-pgsql 2>&1 | logger -t owncloud-setup
|
||||
DEBIAN_FRONTEND=noninteractive apt-get --no-install-recommends \
|
||||
install -y owncloud 2>&1 | logger -t owncloud-setup
|
||||
|
||||
# Keep existing configuration if it exist
|
||||
if [ ! -e /etc/owncloud/config.php ] ; then
|
||||
# Set up postgresql database and user
|
||||
|
||||
@@ -48,10 +48,6 @@ def parse_arguments():
|
||||
parser = argparse.ArgumentParser()
|
||||
subparsers = parser.add_subparsers(dest='subcommand', help='Sub command')
|
||||
|
||||
# Get installed status
|
||||
subparsers.add_parser('get-installed',
|
||||
help='Get whether PakeKite is installed')
|
||||
|
||||
# Start PageKite
|
||||
subparsers.add_parser('start', help='Start PageKite service')
|
||||
|
||||
@@ -91,14 +87,6 @@ def parse_arguments():
|
||||
return parser.parse_args()
|
||||
|
||||
|
||||
def subcommand_get_installed(_):
|
||||
"""Print whether PageKite is installed"""
|
||||
with open('/dev/null', 'w') as file_handle:
|
||||
status = subprocess.call(['which', 'pagekite'], stdout=file_handle)
|
||||
|
||||
print('installed' if not status else 'not installed')
|
||||
|
||||
|
||||
def subcommand_start(_):
|
||||
"""Start PageKite service"""
|
||||
status = subprocess.call(['service', 'pagekite', 'start'])
|
||||
|
||||
+2
-25
@@ -34,10 +34,6 @@ def parse_arguments():
|
||||
parser = argparse.ArgumentParser()
|
||||
subparsers = parser.add_subparsers(dest='subcommand', help='Sub command')
|
||||
|
||||
# Get whether Tor is installed
|
||||
subparsers.add_parser('get-installed',
|
||||
help='Get whether Tor is installed')
|
||||
|
||||
# Get whether Tor is running
|
||||
subparsers.add_parser('is-running', help='Get whether Tor is running')
|
||||
|
||||
@@ -59,11 +55,6 @@ def parse_arguments():
|
||||
return parser.parse_args()
|
||||
|
||||
|
||||
def subcommand_get_installed(_):
|
||||
"""Get whether Tor is installed"""
|
||||
print('installed' if get_installed() else 'not installed')
|
||||
|
||||
|
||||
def subcommand_is_running(_):
|
||||
"""Get whether Tor is running"""
|
||||
try:
|
||||
@@ -101,7 +92,7 @@ def subcommand_get_hs(_):
|
||||
|
||||
def subcommand_enable_hs(_):
|
||||
"""Enable Tor hidden service"""
|
||||
if not get_installed() or get_hidden_service():
|
||||
if get_hidden_service():
|
||||
return
|
||||
|
||||
with open(TOR_CONFIG, 'r') as conffile:
|
||||
@@ -121,7 +112,7 @@ def subcommand_enable_hs(_):
|
||||
|
||||
def subcommand_disable_hs(_):
|
||||
"""Disable Tor hidden service"""
|
||||
if not get_installed() or not get_hidden_service():
|
||||
if not get_hidden_service():
|
||||
return
|
||||
|
||||
with open(TOR_CONFIG, 'r') as conffile:
|
||||
@@ -154,19 +145,8 @@ def subcommand_disable_hs(_):
|
||||
subprocess.call(['service', 'tor', 'restart'])
|
||||
|
||||
|
||||
def get_installed():
|
||||
"""Get whether Tor is installed"""
|
||||
with open('/dev/null', 'w') as file_handle:
|
||||
status = subprocess.call(['which', 'tor'], stdout=file_handle)
|
||||
|
||||
return not status
|
||||
|
||||
|
||||
def set_tor_service(enable):
|
||||
"""Enable/disable Tor service; enable: boolean"""
|
||||
if not get_installed():
|
||||
return
|
||||
|
||||
newline = 'RUN_DAEMON="yes"\n' if enable else 'RUN_DAEMON="no"\n'
|
||||
|
||||
with open(SERVICE_CONFIG, 'r') as file:
|
||||
@@ -182,9 +162,6 @@ def set_tor_service(enable):
|
||||
|
||||
def get_hidden_service():
|
||||
"""Return a string with configured Tor hidden service information"""
|
||||
if not get_installed():
|
||||
return ''
|
||||
|
||||
hs_dir = None
|
||||
hs_ports = []
|
||||
|
||||
|
||||
+107
-20
@@ -23,6 +23,14 @@ Configuration helper for the ejabberd service
|
||||
|
||||
import argparse
|
||||
import subprocess
|
||||
import os
|
||||
import socket
|
||||
import re
|
||||
|
||||
JWCHAT_CONFIG = '/etc/jwchat/config.js'
|
||||
EJABBERD_CONFIG = '/etc/ejabberd/ejabberd.yml'
|
||||
EJABBERD_BACKUP = '/var/log/ejabberd/ejabberd.dump'
|
||||
EJABBERD_BACKUP_NEW = '/var/log/ejabberd/ejabberd_new.dump'
|
||||
|
||||
|
||||
def parse_arguments():
|
||||
@@ -30,9 +38,29 @@ def parse_arguments():
|
||||
parser = argparse.ArgumentParser()
|
||||
subparsers = parser.add_subparsers(dest='subcommand', help='Sub command')
|
||||
|
||||
# Get whether ejabberd is installed
|
||||
subparsers.add_parser('get-installed',
|
||||
help='Get whether ejabberd is installed')
|
||||
# Prepare ejabberd for hostname change
|
||||
pre_hostname_change = subparsers.add_parser(
|
||||
'pre-change-hostname',
|
||||
help='Prepare ejabberd for hostname change')
|
||||
pre_hostname_change.add_argument('--old-hostname',
|
||||
help='Previous hostname')
|
||||
pre_hostname_change.add_argument('--new-hostname',
|
||||
help='New hostname')
|
||||
|
||||
# Update ejabberd and jwchat with new hostname
|
||||
hostname_change = subparsers.add_parser(
|
||||
'change-hostname',
|
||||
help='Update ejabberd and jwchat with new hostname')
|
||||
hostname_change.add_argument('--old-hostname',
|
||||
help='Previous hostname')
|
||||
hostname_change.add_argument('--new-hostname',
|
||||
help='New hostname')
|
||||
|
||||
# Update ejabberd and jwchat with new domainname
|
||||
domainname_change = subparsers.add_parser(
|
||||
'change-domainname',
|
||||
help='Update ejabberd and jwchat with new domainname')
|
||||
domainname_change.add_argument('--domainname', help='New domainname')
|
||||
|
||||
# Register a new user account
|
||||
register = subparsers.add_parser('register',
|
||||
@@ -45,37 +73,96 @@ def parse_arguments():
|
||||
return parser.parse_args()
|
||||
|
||||
|
||||
def subcommand_get_installed(_):
|
||||
"""Get whether ejabberd is installed"""
|
||||
print('installed' if get_installed() else 'not installed')
|
||||
def subcommand_pre_change_hostname(arguments):
|
||||
"""Prepare ejabberd for hostname change"""
|
||||
old_hostname = arguments.old_hostname
|
||||
new_hostname = arguments.new_hostname
|
||||
|
||||
subprocess.call(['ejabberdctl', 'backup', EJABBERD_BACKUP])
|
||||
try:
|
||||
subprocess.check_output(['ejabberdctl', 'mnesia-change-nodename',
|
||||
'ejabberd@' + old_hostname,
|
||||
'ejabberd@' + new_hostname,
|
||||
EJABBERD_BACKUP, EJABBERD_BACKUP_NEW])
|
||||
os.remove(EJABBERD_BACKUP)
|
||||
except subprocess.CalledProcessError as err:
|
||||
print('Failed to change hostname in ejabberd backup database: %s', err)
|
||||
|
||||
|
||||
def subcommand_change_hostname(arguments):
|
||||
"""Update ejabberd and jwchat with new hostname"""
|
||||
subprocess.call(['service', 'ejabberd', 'stop'])
|
||||
subprocess.call(['pkill', '-u', 'ejabberd'])
|
||||
|
||||
# Make sure there aren't files in the Mnesia spool dir
|
||||
os.makedirs('/var/lib/ejabberd/oldfiles', exist_ok=True)
|
||||
subprocess.call('mv /var/lib/ejabberd/*.* /var/lib/ejabberd/oldfiles/',
|
||||
shell=True)
|
||||
|
||||
subprocess.call(['service', 'ejabberd', 'start'])
|
||||
|
||||
# restore backup database
|
||||
if os.path.exists(EJABBERD_BACKUP_NEW):
|
||||
try:
|
||||
subprocess.check_output(['ejabberdctl',
|
||||
'restore',
|
||||
EJABBERD_BACKUP_NEW])
|
||||
os.remove(EJABBERD_BACKUP_NEW)
|
||||
except subprocess.CalledProcessError as err:
|
||||
print('Failed to restore ejabberd backup database: %s', err)
|
||||
else:
|
||||
print('Could not load ejabberd backup database: %s not found'
|
||||
% EJABBERD_BACKUP_NEW)
|
||||
|
||||
|
||||
def subcommand_change_domainname(arguments):
|
||||
"""Update ejabberd and jwchat with new domainname"""
|
||||
domainname = arguments.domainname
|
||||
fqdn = socket.gethostname() + '.' + domainname
|
||||
|
||||
# update jwchat's sitename, if it's installed
|
||||
if os.path.exists(JWCHAT_CONFIG):
|
||||
with open(JWCHAT_CONFIG, 'r') as conffile:
|
||||
lines = conffile.readlines()
|
||||
with open(JWCHAT_CONFIG, 'w') as conffile:
|
||||
for line in lines:
|
||||
if re.match(r'\s*var\s+SITENAME', line):
|
||||
conffile.write('var SITENAME = "' + fqdn + '";\n')
|
||||
else:
|
||||
conffile.write(line)
|
||||
else:
|
||||
print('Skipping configuring jwchat sitename: %s not found',
|
||||
JWCHAT_CONFIG)
|
||||
|
||||
subprocess.call(['service', 'ejabberd', 'stop'])
|
||||
subprocess.call(['pkill', '-u', 'ejabberd'])
|
||||
|
||||
# add updated FQDN to top of ejabberd hosts list
|
||||
with open(EJABBERD_CONFIG, 'r') as conffile:
|
||||
lines = conffile.readlines()
|
||||
with open(EJABBERD_CONFIG, 'w') as conffile:
|
||||
for line in lines:
|
||||
conffile.write(line)
|
||||
if re.match(r'\s*hosts:', line):
|
||||
conffile.write(' - "' + fqdn + '"\n')
|
||||
|
||||
subprocess.call(['service', 'ejabberd', 'start'])
|
||||
|
||||
|
||||
def subcommand_register(arguments):
|
||||
"""Register a new user account"""
|
||||
if not get_installed():
|
||||
print('Failed to register XMPP account: ejabberd is not installed.')
|
||||
return
|
||||
|
||||
username = arguments.username
|
||||
password = arguments.password
|
||||
hostname = subprocess.check_output(['hostname'])
|
||||
fqdn = socket.getfqdn()
|
||||
|
||||
try:
|
||||
output = subprocess.check_output(['ejabberdctl', 'register',
|
||||
username, hostname, password])
|
||||
username, fqdn, password])
|
||||
print(output.decode())
|
||||
except subprocess.CalledProcessError as e:
|
||||
print('Failed to register XMPP account:', e.output.decode())
|
||||
|
||||
|
||||
def get_installed():
|
||||
"""Check if ejabberd is installed"""
|
||||
with open('/dev/null', 'w') as file_handle:
|
||||
status = subprocess.call(['which', 'ejabberdctl'], stdout=file_handle)
|
||||
|
||||
return not status
|
||||
|
||||
|
||||
def main():
|
||||
"""Parse arguments and perform all duties"""
|
||||
arguments = parse_arguments()
|
||||
|
||||
@@ -1,43 +0,0 @@
|
||||
#!/bin/bash
|
||||
#
|
||||
# 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/>.
|
||||
#
|
||||
|
||||
# Action to set up new hostname for ejabberd and jwchat.
|
||||
|
||||
hostname="$1"
|
||||
old_hostname=`debconf-show ejabberd | awk '/hostname/ { print $3 }'`
|
||||
|
||||
# Based on http://www.process-one.net/docs/ejabberd/guide_en.html#htoc77
|
||||
|
||||
BACKUP=/tmp/ejabberd.dump
|
||||
|
||||
# Note: dpkg-reconfigure will fail if there have been manual changes made to the
|
||||
# configuration file for a package. Since this is the case for ejabberd,
|
||||
# manually update the hostname in the configuration file.
|
||||
echo "ejabberd ejabberd/hostname string $hostname" | debconf-set-selections
|
||||
echo "jwchat jwchat/ApacheServerName string $hostname" | debconf-set-selections
|
||||
DEBIAN_FRONTEND=noninteractive dpkg-reconfigure jwchat
|
||||
|
||||
sed -i "s/$old_hostname/$hostname/g" /etc/ejabberd/ejabberd.yml
|
||||
sed -i "s/$old_hostname/$hostname/g" $BACKUP
|
||||
|
||||
service ejabberd restart
|
||||
|
||||
# Load backup database
|
||||
sleep 10
|
||||
ejabberdctl load $BACKUP
|
||||
rm $BACKUP
|
||||
Reference in new issue
Block a user