Subversion Repositories ALCASAR

Rev

Blame | Last modification | View Log

#!/bin/bash

# alcasar-defaultcert.sh
# by Raphaël, Hugo, Clément, Bettyna

# This script is distributed under Gnu General Public License (GPL)

# Script permettant
# - de revenir au certificat par default

# Script allows
# - go back to the default certificate

SED="/bin/sed -ri"

DIR_CERT="/etc/pki/tls"

usage="Usage: alcasar-defaultcert.sh. Ce script permet de revenir au certificat par default"

nb_args=$#
args=$1

function defaultNdd()
{
        $SED 's/^DOMAIN=.*/DOMAIN=localdomain/g' /usr/local/etc/alcasar.conf
        $SED 's/\.([a-zA-Z][a-zA-Z0-9-]+(\.[a-z]{2,4})?)/.localdomain/g' /etc/hosts
        $SED 's/alcasar\.([a-zA-Z0-9-]+(\.[a-z]{2,4})?)/alcasar.localdomain/g' /etc/chilli.conf
        $SED 's/^domain.*/domain\t\tlocaldomain/g' /etc/chilli.conf
        $SED 's/^ServerName.*/ServerName alcasar.localdomain/g' /etc/httpd/conf/httpd.conf
}

function defaultCert()
{
        cd $DIR_CERT
        rm private/alcasar.key
        rm certs/alcasar.crt
        mv certs/alcasar.crt.old certs/alcasar.crt
        mv private/alcasar.key.old private/alcasar.key
        if [ -f certs/server-chain.crt.old ]
        then
                rm certs/server-chain.crt
                mv certs/server-chain.crt.old certs/server-chain.crt
        fi
}

if [ $nb_args != 0 ]
then
        nb_args=1
        args="-h"
fi

case $args in
        -\? | -h* | --h*)
                echo "$usage"
                exit 0
                ;;
esac
if [ -f "/etc/pki/tls/certs/alcasar.crt.old" -a -f "/etc/pki/tls/private/alcasar.key.old" ]
then
        echo "Back to the original certificate"
        defaultCert
        defaultNdd
        systemctl restart chilli.service
        systemctl restart httpd.service
fi