<commit_before>#!/bin/bash

#The mazi-domain.sh script enables the modification of the MAZI Portal's domain and the change of the splash page.

###### Initialization ######
hosts="/etc/hosts"
portal_conf="/etc/apache2/sites-available/portal.conf"
index_apache="/var/www/html/index.html"

usage() { echo "This script changes the domain of mazi toolkit"
          echo ""
          echo "Usage: mazi-domain.sh [options]"
          echo "[options]"
          echo "-d,--domain <new domain>             Set a new network  domain of the portal"
          echo "-s,--splash <application>/<portal>   Set a new spalsh page"  1>&2; exit 1; }

while [ $# -gt 0 ]
do
key="$1"
case $key in
    -d|--domain)
    domain="$2"
    shift # past argument=value
    ;;
    -s|--splash)
    app="$2"
    shift
    ;;
    *)
    # unknown option
    usage
    ;;
esac
shift     #past argument or value
done


if [ $domain ];then
  c_domain=$(grep -o -P '(?<=url=http://).*(?=">)' $index_apache)
  sed -i "s/$c_domain/$domain/g" $hosts
  sed -i '/<meta HTTP-EQUIV="REFRESH"/c\          <meta HTTP-EQUIV="REFRESH" content="0; url=http://'$domain'">' $index_apache
  sed -i "s/$c_domain/$domain/g" $portal_conf 
  sudo systemctl daemon-reload
  sudo service apache2 restart
  sudo service dnsmasq restart
fi

if [ $app ];then
   domain=$(grep -o -P '(?<=url=http://).*(?=">)' $index_apache)
   case $app in
    guestbook | etherpad)
    
    [ "$app" = "guestbook" ] && port="8081" || port="9001"
    cat << EOF >  $portal_conf
<VirtualHost *:80>
        Redirect /admin http://local.mazizone.eu/admin
        ServerName $domain
        ProxyPreserveHost On
        ProxyRequests Off
        ProxyPass  /admin !
        ProxyPass / http://localhost:$port/
        ProxyPassReverse / http://localhost:$port/

</VirtualHost>

<VirtualHost *:80><commit_msg>restart nodogspalsh when domain change<commit_after>#!/bin/bash

#The mazi-domain.sh script enables the modification of the MAZI Portal's domain and the change of the splash page.

###### Initialization ######
hosts="/etc/hosts"
portal_conf="/etc/apache2/sites-available/portal.conf"
index_apache="/var/www/html/index.html"

usage() { echo "This script changes the domain of mazi toolkit"
          echo ""
          echo "Usage: mazi-domain.sh [options]"
          echo "[options]"
          echo "-d,--domain <new domain>             Set a new network  domain of the portal"
          echo "-s,--splash <application>/<portal>   Set a new spalsh page"  1>&2; exit 1; }

while [ $# -gt 0 ]
do
key="$1"
case $key in
    -d|--domain)
    domain="$2"
    shift # past argument=value
    ;;
    -s|--splash)
    app="$2"
    shift
    ;;
    *)
    # unknown option
    usage
    ;;
esac
shift     #past argument or value
done


if [ $domain ];then
  c_domain=$(grep -o -P '(?<=url=http://).*(?=">)' $index_apache)
  sed -i "s/$c_domain/$domain/g" $hosts
  sed -i '/<meta HTTP-EQUIV="REFRESH"/c\          <meta HTTP-EQUIV="REFRESH" content="0; url=http://'$domain'">' $index_apache
  sed -i "s/$c_domain/$domain/g" $portal_conf 
  sudo systemctl daemon-reload
  sudo service apache2 restart
  sudo service dnsmasq restart
  /etc/init.d/nodogsplash stop
  /etc/init.d/nodogsplash start
fi

if [ $app ];then
   domain=$(grep -o -P '(?<=url=http://).*(?=">)' $index_apache)
   case $app in
    guestbook | etherpad)
    
    [ "$app" = "guestbook" ] && port="8081" || port="9001"
    cat << EOF >  $portal_conf
<VirtualHost *:80>
        Redirect /admin http://local.mazizone.eu/admin
        ServerName $domain
        ProxyPreserveHost On
        ProxyRequests Off
        ProxyPass  /admin !
        ProxyPass / http://localhost:$port/
        ProxyPassReverse / http://localhost:$port/

</VirtualHost>

<VirtualHost *:80>
{'fraction_non_alphanumeric': 0.16008537886872998, 'fraction_numerical': 0.011739594450373533, 'mean_word_length': 2.664711632453568, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5953856', 'n_tokens_mistral': 1351, 'n_tokens_neox': 1276, 'n_words': 339}