# Federated Computer functions

# Define all services
CORE_APPS=("pdnsmysql" "pdns" "pdnsadmin" "traefik" "postgresql" "ldap")
EXTRA_APPS=("mail" "collabora" "authelia" "nextcloud" "matrix" "element" "listmonk" "vaultwarden" "panel" "wireguard" "jitsi" "baserow" "gitea" "caddy" "autodiscover" "castopod" "wordpress" "coturn" "bookstack" "freescout" "msp" "espocrm" "nginx" "matrixslack" "matrixsignal" "matrixwhatsapp" "dashboard" "jitsiopenid" "roundcube" "redis" "discourse" "wordpressshop" "plane" "calcom")
SERVICES=("${CORE_APPS[@]}" "${EXTRA_APPS[@]}")

failts() {
  echo "$*" >&2;
  exit 1;
}
run_command() {
  $1 &> /dev/null
  if [[ $? -ne 0 ]]; then
    echo "* FAILED - Couldn't run \"$1\"" >&2
  else
    return 0
  fi
}
fail() {
  echo -ne "FAILED\n\n$1\n\n"
  kill -9 $SPINPID &> /dev/null
  #  [ -d "apps/dns" ] && rm -rf apps/dns
  #  docker network rm fstack &> /dev/null
  exit 2;
}
failcheck() {
  echo -ne "\n\nFAILED - $1\n\n"
  exit 2;
}
cleanup() {
   kill -9 $SPINPID &> /dev/null
   exit 2;
}
spin() {
  spinner="/|\\-/|\\-"
  while :
  do
    for i in `seq 0 7`
    do
      echo -n "${spinner:$i:1}"
      echo -en "\010"
      sleep 1
    done
  done
}
update_alpine() {
  apk update &> /dev/null
  [ $? -ne 0 ] && fail "Failed running apk update"

  apk upgrade &> /dev/null
  [ $? -ne 0 ] && fail "Failed running apk upgrade"
}
install_packages_alpine() {
  # Install docker packages
  apk add docker docker-cli-compose &> /dev/null
  [ $? -ne 0 ] && failcheck "Failed running apk add docker docker-cli-compose"

  # Start docker
  rc-update add docker default
  [ $? -ne 0 ] && failcheck "Failed running rc-update add docker default"
  service docker start
  [ $? -ne 0 ] && failcheck "Failed running service docker start"

  # Install extra packages
  apk add duplicity apache2-utils pipx curl htop bind-tools openssl &> /dev/null
  [ $? -ne 0 ] && failcheck "Failed running apk add duplicity apache2-utils pipx curl htop bind-tools openssl"

  # Install b2 through pipx
  pipx install b2 &> /dev/null
  [ $? -ne 0 ] && failcheck "Failed running pipx install b2"
  pipx ensurepath &> /dev/null
  [ $? -ne 0 ] && failcheck "Failed running pipx ensurepath"
  echo 'PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/root/.local/bin/' > /root/.bashrc

  # Install Traefik certs dumper
  curl -sfL https://raw.githubusercontent.com/ldez/traefik-certs-dumper/master/godownloader.sh | bash -s -- -b $(go env GOPATH 2>/dev/null)/bin v2.8.1 &> /dev/null
  [ $? -ne 0 ] && failcheck "Failed running curl to get traefik certs dumper"
}
send_alert_backups() {
  EXTERNALIP=`dig @resolver4.opendns.com myip.opendns.com +short 2> /dev/null`
  echo "Generated by /federated/bin/backuptool" > /federated/apps/mail/data/root/certs/mailfile
  docker exec mail bash -c "mail -r admin@$DOMAIN -a \"Content-type: text/html\" -s \"backuptool failed to run on $EXTERNALIP - low disk\" $ALERTS_EMAIL < /root/certs/mailfile"
}
send_alert_upgrade() {
  . /etc/federated
  EXTERNALIP=`dig @resolver4.opendns.com myip.opendns.com +short 2> /dev/null`
  echo "Generated by /federated/bin/upgrade" > /federated/apps/mail/data/root/certs/mailfile
  docker exec mail bash -c "mail -r admin@$DOMAIN -a \"Content-type: text/html\" -s \"upgrade failed to run on $EXTERNALIP - couldn't pull from git\" $ALERTS_EMAIL < /root/certs/mailfile"
}
add_cron() {
cat > /etc/logrotate.d/federated <<EOF
/federated/logs/*.log {
  rotate 12
  monthly
  compress
  missingok
  notifempty
}
EOF
  (crontab -l 2>/dev/null; echo "30 22 * * * date >> /federated/logs/backup.log && /federated/bin/backuptool -b all >> /federated/logs/backup.log 2>&1") | sort -u | crontab -
  (crontab -l 2>/dev/null; echo "0 2 * * * date >> /federated/logs/upgrade.log && /federated/bin/upgrade >> /federated/logs/upgrade.log 2>&1") | sort -u | crontab -
  (crontab -l 2>/dev/null; echo "0 3 * * * date >> /federated/logs/dumpcerts.log && /federated/bin/dumpcerts >> /federated/logs/dumpcerts.log 2>&1") | sort -u | crontab -
  if [[ "${PLUS}" != "true" ]]; then
    (crontab -l 2>/dev/null; echo "*/5 * * * * /usr/bin/docker exec -u 33 nextcloud php -f /var/www/html/cron.php") | sort -u | crontab -
  fi
}
install_federated() {
  # Check if Federated is already installed then install
  [ -d "/federated" ] && fail "Directory /federated already exists. Already installed?"
  API_TOKEN="6f3d11bee38b636e593aba295d661b9908b42134"
  git clone https://installcore:$API_TOKEN@code.federated.company/federatedcomputer/Core /federated
}
upgrade_federated() {
  echo -ne "\n* Updating federated install.."
  [ ! -d "/federated" ] && fail "Directory /federated doesn't exist."

  echo -ne "\n* Grabbing the latest version from Gitea.."

  API_TOKEN="6f3d11bee38b636e593aba295d661b9908b42134"
  cd /federated && git pull https://installcore:$API_TOKEN@code.federated.company/federatedcomputer/Core
  if [ $? -ne 0 ]; then
    send_alert_upgrade
    fail "Git pull not working on update of federated."
  fi

  echo -ne "\n* Checking installed app versions with latest-versions."

  [ ! -f "/federated/lib/latest-versions" ] && fail "File /federated/lib/latest-version doesn't exist."
  APP_DOTS='......................'
  for i in `cat /federated/lib/latest-versions`; do
    SERVICE=(${i//=/ });
    APP="${SERVICE[0]}"
    VERSION="${SERVICE[1]}"
    printf "\n%s %s" "$APP" "${APP_DOTS:${#APP}} "

    if [ -f "/federated/apps/$APP/.env" ]; then
      [[ $(grep IMAGE_VERSION_HOLD /federated/apps/$APP/.env) ]] && echo -ne "version hold found, skipping." && continue
      if [ "$APP" = "jitsi" ]; then
        if [ "$JITSI_SCALE" = "server" ]; then
          [[ "$(docker container inspect -f '{{.State.Status}}' jitsi-jvb-1 2>/dev/null)" != "running" ]] && APP_NOTRUNNING="true"
	else
          [[ "$(docker container inspect -f '{{.State.Status}}' jitsi-web-1 2>/dev/null)" != "running" ]] && APP_NOTRUNNING="true"
	fi
      else
        [[ "$(docker container inspect -f '{{.State.Status}}' $APP 2>/dev/null)" != "running" ]] && APP_NOTRUNNING="true"
      fi
      APP_VERSION_RAW=`grep IMAGE_VERSION /federated/apps/$APP/.env | awk -F= '{ print $2 }'`
      APP_VERSION="${APP_VERSION_RAW//\"}"

      if [ "$APP_VERSION" = "$VERSION" ]; then
        printf "%s" "is already at the latest version."
      else
        NC_COMMAND=`grep start_service /federated/lib/$APP.sh  | awk -F\" '{ print $4 }'`
        echo -ne "upgrading to $VERSION..\n"
        if [[ ! "$APP_NOTRUNNING" ]]; then
          echo -ne "\n   Shutting Down $APP.."
          cd /federated/apps/$APP && docker compose -f docker-compose.yml -p $APP down
        fi
        if [ "$APP" = "jitsi" ]; then
          sed -i "s/#JITSI_IMAGE_VERSION=.*/JITSI_IMAGE_VERSION=$VERSION/g" /federated/apps/$APP/.env
          sed -i "s/JITSI_IMAGE_VERSION=.*/JITSI_IMAGE_VERSION=$VERSION/g" /federated/apps/$APP/.env
        else
          sed -i "s#VERSION=.*#VERSION=$VERSION#g" /federated/apps/$APP/.env
        fi
        if [[ "$APP_NOTRUNNING" ]]; then
          echo -ne "$APP was already shut down so we won't be starting it.\n"
        else
          /federated/bin/start $APP
          echo -ne "Done upgrading $APP to $VERSION.\n"
        fi
      fi
      APP_NOTRUNNING=""
    else
      printf "%s" "not installed."
    fi
  done
  echo -ne "\n"

  echo -ne "\n* Getting upgrade script from Upgrades repo.."
  curl -s -f https://$API_TOKEN@code.federated.company/federatedcomputer/Upgrades/raw/branch/master/upgrade.sh > /tmp/upgrade.sh
  if [ $? -ne 0 ]; then
    echo "not found."
  else
    echo -ne "\n* Found. Running /tmp/upgrade.sh..\n\n" 
    chmod +x /tmp/upgrade.sh
    bash -c /tmp/upgrade.sh
    if [ $? -ne 0 ]; then
      rm /tmp/upgrade.sh
      fail "There was an error running /tmp/upgrade.sh"
    else
      rm /tmp/upgrade.sh
      echo -ne "\nDone.\n"
    fi
  fi
}
create_password() {
#	eval $1_var=$1
#	echo "$postgres_var"
  SECRET=`tr -cd '[:alnum:]' < /dev/urandom | fold -w32 | head -n1`
  echo "$SECRET";
}
get_externalip() {
  EXTERNALIP=`dig @resolver4.opendns.com myip.opendns.com +short 2> /dev/null`
  echo "$EXTERNALIP";
}
start_service_convert() {
  SERVICE="$1"
  COMMAND="$2"

  # Start /federated/apps/SERVICE with output to /dev/null
  echo -ne "\n* Starting /federated/apps/$SERVICE service.."

  docker compose -f /federated/apps/$SERVICE/docker-compose.yml -p $SERVICE up -d &> /dev/null

  # Keep trying service port to make sure it's up before
  # we proceed
  RETRY="40"
  while [ $RETRY -gt 0 ]; do
    bash -c "$COMMAND" &> /dev/null
    if [ $? -eq 0 ]; then
      break
    else
      if [ "$RETRY" == 1 ]; then
        docker compose -f /federated/apps/$SERVICE/docker-compose.yml -p $SERVICE down &> /dev/null
        fail "There was a problem starting service /federated/apps/$SERVICE\nCheck the output of 'docker logs $SERVICE' or turn on\ndebug with -d"
      fi
      ((RETRY--))
      sleep 7
    fi
  done
}
start_service_upgrade() {
  SERVICE="$1"
  COMMAND="$2"

  # Start /federated/apps/SERVICE with output to /dev/null
  echo -ne "\n* Starting /federated/apps/$SERVICE service.."

  if [ $DEBUG ]; then
    # Start /federated/apps/SERVICE with output to console for debug
    docker compose -f /federated/apps/$SERVICE/docker-compose.yml -p $SERVICE up
    [ $? -eq 0 ] && echo -ne "done.\n" || fail "There was a problem starting service /federated/apps/$SERVICE"
  else
    docker compose -f /federated/apps/$SERVICE/docker-compose.yml -p $SERVICE up -d &> /dev/null

    # Keep trying service port to make sure it's up before
    # we proceed
    RETRY="30"
    while [ $RETRY -gt 0 ]; do
      bash -c "$COMMAND" &> /dev/null
      if [ $? -eq 0 ]; then
        break
      else
        if [ "$RETRY" == 1 ]; then
          docker compose -f /federated/apps/$SERVICE/docker-compose.yml -p $SERVICE down &> /dev/null
          fail "There was a problem starting service /federated/apps/$SERVICE\nCheck the output of 'docker logs $SERVICE' or turn on\ndebug with -d"
        fi
        ((RETRY--))
        sleep 7
      fi
    done
  fi
}
start_service_withalert2() {
  SERVICE="$1"
  COMMAND="$2"
  RETRY="$3"
  ALERT="$4"

  # First start the service
  docker compose -f /federated/apps/$SERVICE/docker-compose.yml -p $SERVICE up -d &> /dev/null

  # Keep trying service COMMAND to make sure it's up before we proceed
  while [ "$RETRY" -gt "0" ]; do
    bash -c "eval $COMMAND" &> /dev/null
    if [ $? -eq 0 ]; then
      break
    else
      # When RETRY gets down to 1 then we have failed
      if [ "$RETRY" == 1 ]; then
#       disown $SPINPID &> /dev/null
#       kill -9 $SPINPID &> /dev/null
        FAILED="yes"

        if [ "$ALERT" = "yes" ]; then
          EXTERNALIP=`dig @resolver4.opendns.com myip.opendns.com +short 2> /dev/null`
          docker compose -f /federated/apps/$SERVICE/docker-compose.yml -p $SERVICE down &> /dev/null
          echo "Generated by /federated/bin/start" > /federated/apps/mail/data/root/certs/mailfile
          docker exec mail bash -c "mail -r admin@$DOMAIN -a \"Content-type: text/html\" -s \"$SERVICE failed to start on $EXTERNALIP\" $ALERTS_EMAIL < /root/certs/mailfile"
          echo -ne "\nThere was a problem starting service /federated/apps/$SERVICE\nCheck the output of 'docker logs $SERVICE' while starting or run\ndocker compose -f /federated/apps/$SERVICE/docker-compose.yml -p $SERVICE up\n"
        else
          docker compose -f /federated/apps/$SERVICE/docker-compose.yml -p $SERVICE down &> /dev/null
          echo -ne "\nThere was a problem starting service /federated/apps/$SERVICE\nCheck the output of 'docker logs $SERVICE' while starting or run\ndocker compose -f /federated/apps/$SERVICE/docker-compose.yml -p $SERVICE up\n"
        fi
        echo -ne "\n"
      fi
      ((RETRY--))
      sleep 7
    fi
  done
}
start_service_withalert() {
  SERVICE="$1"
  COMMAND="$2"
  RETRY="$3"
  ALERT="$4"

  echo -ne "* Starting $SERVICE.."

  docker compose -f /federated/apps/$SERVICE/docker-compose.yml -p $SERVICE up -d &> /dev/null

  # Keep trying service port to make sure it's up before
  # we proceed
  while [ $RETRY -gt 0 ]; do
    bash -c "eval $COMMAND" &> /dev/null
    if [ $? -eq 0 ]; then
      break
    else
      if [ "$RETRY" == 1 ]; then
	disown $SPINPID &> /dev/null
	kill -9 $SPINPID &> /dev/null
	FAILED="yes"

	if [ "$ALERT" = "yes" ]; then
          EXTERNALIP=`dig @resolver4.opendns.com myip.opendns.com +short 2> /dev/null`
          docker compose -f /federated/apps/$SERVICE/docker-compose.yml -p $SERVICE down &> /dev/null
	  echo "Generated by /federated/bin/start" > /federated/apps/mail/data/root/certs/mailfile
	  docker exec mail bash -c "mail -r admin@$DOMAIN -a \"Content-type: text/html\" -s \"$SERVICE failed to start on $EXTERNALIP\" $ALERTS_EMAIL < /root/certs/mailfile"
          echo -ne "\n\nThere was a problem starting service /federated/apps/$SERVICE\nCheck the output of 'docker logs $SERVICE' or turn on\ndebug with set -x\n\n"
	else
          docker compose -f /federated/apps/$SERVICE/docker-compose.yml -p $SERVICE down &> /dev/null
          echo -ne "\n\nThere was a problem starting service /federated/apps/$SERVICE\nCheck the output of 'docker logs $SERVICE' or turn on\ndebug with set -x\n\n"
	fi
      fi
      ((RETRY--))
      sleep 7
    fi
  done
}
start_service() {
  SERVICE="$1"
  COMMAND="$2"
  RETRY="$3"

  # Start /federated/apps/SERVICE with output to /dev/null
  echo -ne "* Starting $SERVICE.."

  if [ $DEBUG ]; then
    # Start /federated/apps/SERVICE with output to console for debug
    docker compose -f /federated/apps/$SERVICE/docker-compose.yml -p $SERVICE up
    [ $? -eq 0 ] && echo -ne "done.\n" || fail "There was a problem starting service /federated/apps/$SERVICE"
  else
    docker compose -f /federated/apps/$SERVICE/docker-compose.yml -p $SERVICE up -d &> /dev/null

    # Keep trying service port to make sure it's up before
    # we proceed
    while [ $RETRY -gt 0 ]; do
      bash -c "$COMMAND" &> /dev/null
      if [ $? -eq 0 ]; then
        break
      else
        if [ "$RETRY" == 1 ]; then
          docker compose -f /federated/apps/$SERVICE/docker-compose.yml -p $SERVICE down &> /dev/null
          kill -9 $SPINPID &> /dev/null
          fail "There was a problem starting service /federated/apps/$SERVICE\nCheck the output of 'docker logs $SERVICE' or turn on\ndebug with set -x"
        fi
        ((RETRY--))
        sleep 7
      fi
    done
  fi
}
print_details_migrated() {
cat > /federated/apps/mail/data/root/certs/mailfile <<EOF
<html>
<img src="https://www.federated.computer/images/logo.png" alt="" /><br>
<p>
<h4>You are now migrated to $DOMAIN</h4>
<p>
Credentials will be the same as the admin user and listmonk user in the original welcome e-mail.<br>
Here is your applications reference chart with $DOMAIN:
<p>
<h4>Applications</h4>
<style type="text/css">
.tg  {border-collapse:collapse;border-spacing:0;}
.tg td{border-color:black;border-style:solid;border-width:1px;font-family:Arial, sans-serif;font-size:14px;
  overflow:hidden;padding:10px 5px;word-break:normal;}
.tg th{border-color:black;border-style:solid;border-width:1px;font-family:Arial, sans-serif;font-size:14px;
  font-weight:normal;overflow:hidden;padding:10px 5px;word-break:normal;}
.tg .tg-cul6{border-color:inherit;color:#340096;text-align:left;text-decoration:underline;vertical-align:top}
.tg .tg-acii{background-color:#FFF;border-color:inherit;color:#333;text-align:left;vertical-align:top}
.tg .tg-0hty{background-color:#000000;border-color:inherit;color:#ffffff;font-weight:bold;text-align:left;vertical-align:top}
.tg .tg-kwiq{border-color:inherit;color:#000000;text-align:left;vertical-align:top}
.tg .tg-0pky{border-color:inherit;text-align:left;vertical-align:top}
</style>
<table class="tg" style="undefined;table-layout: fixed; width: 996px">
<colgroup>
<col style="width: 101.333333px">
<col style="width: 203.333333px">
<col style="width: 172.333333px">
<col style="width: 221.333333px">
<col style="width: 77.333333px">
<col style="width: 220.333333px">
</colgroup>
<thead>
  <tr>
    <th class="tg-0hty">Service</th>
    <th class="tg-0hty">Link</th>
    <th class="tg-0hty">User / Pass</th>
    <th class="tg-0hty">Access</th>
    <th class="tg-0hty">Docs</th>
    <th class="tg-0hty">Description</th>
  </tr>
</thead>
<tbody>
  <tr>
    <td class="tg-kwiq">Panel</td>
    <td class="tg-kwiq"><a href="https://panel.$DOMAIN/" target="_blank" rel="noopener noreferrer"><span style="color:#340096">panel.$DOMAIN</span></a></td>
    <td class="tg-kwiq">admin@$DOMAIN<br>admin password above</td>
    <td class="tg-kwiq">All users added in panel can access panel with their own user@$DOMAIN</td>
    <td class="tg-cul6"><a href="https://documentation.federated.computer/docs/core_applications/panel" target="_blank" rel="noopener noreferrer"><span style="color:#340096">Click here</span></a></td>
    <td class="tg-kwiq">Use panel to create user accounts for your team and change passwords</td>
  </tr>
  <tr>
    <td class="tg-kwiq">Email</td>
    <td class="tg-kwiq"><a href="https://nextcloud.$DOMAIN/" target="_blank" rel="noopener noreferrer"><span style="color:#340096">nextcloud.$DOMAIN</span></a><br>WebMail application</td>
    <td class="tg-kwiq">admin@$DOMAIN<br>admin password above</td>
    <td class="tg-kwiq">All users added in panel can access their own mail accounts through Nextcloud or mail client using user@$DOMAIN</td>
    <td class="tg-cul6"><a href="https://documentation.federated.computer/docs/getting_started/welcome" target="_blank" rel="noopener noreferrer"><span style="color:#340096">Click here</span></a></td>
    <td class="tg-kwiq">This is your own private e-mail service accessed through Nextcloud webmail or configure a mail client with SMTP mail.$DOMAIN (port 465), and IMAP mail.$DOMAIN (port 993)</td>
  </tr>
  <tr>
    <td class="tg-kwiq">Nextcloud</td>
    <td class="tg-kwiq"><a href="https://nextcloud.$DOMAIN/" target="_blank" rel="noopener noreferrer"><span style="color:#340096">nextcloud.$DOMAIN</span></a></td>
    <td class="tg-kwiq">admin@$DOMAIN<br>admin password above</td>
    <td class="tg-kwiq">All users added in panel can access Nextcloud / Email with their own user@$DOMAIN account</td>
    <td class="tg-cul6"><a href="https://documentation.federated.computer/docs/core_applications/nextcloud" target="_blank" rel="noopener noreferrer"><span style="color:#340096">Click here</span></a></td>
    <td class="tg-kwiq">The Nextcloud Suite replaces google workspace which provides mail, calendar, contacts, notes, tasks, files, word processing, spreadsheets, project management, slides, and pictures</td>
  </tr>
  <tr>
    <td class="tg-kwiq">Jitsi</td>
    <td class="tg-kwiq"><a href="https://jitsi.$DOMAIN/" target="_blank" rel="noopener noreferrer"><span style="color:#340096">jitsi.$DOMAIN</span></a></td>
    <td class="tg-kwiq">admin<br>admin password above</td>
    <td class="tg-kwiq">All users added in panel can access Jitsi with their own user account using 'username'</td>
    <td class="tg-cul6"><a href="https://documentation.federated.computer/docs/core_applications/jitsi" target="_blank" rel="noopener noreferrer"><span style="color:#340096">Click here</span></a></td>
    <td class="tg-kwiq">Jitsi is a zoom replacement video conferencing solution</td>
  </tr>
  <tr>
    <td class="tg-kwiq">Element</td>
    <td class="tg-kwiq"><a href="https://element.$DOMAIN/" target="_blank" rel="noopener noreferrer"><span style="color:#340096">element.$DOMAIN</span></a></td>
    <td class="tg-kwiq">admin@$DOMAIN<br>admin password above</td>
    <td class="tg-kwiq">All users added in panel can access element / matrix with their own user@$DOMAIN account</td>
    <td class="tg-cul6"><a href="https://documentation.federated.computer/docs/core_applications/element" target="_blank" rel="noopener noreferrer"><span style="color:#340096">Click here</span></a></td>
    <td class="tg-kwiq">Element (a Slack replacement) provides you the ability to chat with those on your team and outside of your team</td>
  </tr>
  <tr>
    <td class="tg-kwiq">Listmonk</td>
    <td class="tg-kwiq"><a href="https://listmonk.$DOMAIN/" target="_blank" rel="noopener noreferrer"><span style="color:#340096">listmonk.$DOMAIN</span></a></td>
    <td class="tg-kwiq">listmonk<br>listmonk password above</td>
    <td class="tg-kwiq">User access is separate from panel. There is only the listmonk user</td>
    <td class="tg-cul6"><a href="https://documentation.federated.computer/docs/core_applications/listmonk" target="_blank" rel="noopener noreferrer"><span style="color:#340096">Click here</span></a></td>
    <td class="tg-kwiq">Listmonk is (a replacement for Mailchimp) is used to create e-mail subscription lists</td>
  </tr>
  <tr>
    <td class="tg-kwiq">Baserow</td>
    <td class="tg-kwiq"><a href="https://baserow.$DOMAIN/" target="_blank" rel="noopener noreferrer"><span style="color:#340096">baserow.$DOMAIN</span></a></td>
    <td class="tg-kwiq">admin@$DOMAIN<br>admin password above</td>
    <td class="tg-kwiq">User access is separate from panel. Use the admin account to login and then invite other users</td>
    <td class="tg-cul6"><a href="https://documentation.federated.computer/docs/core_applications/baserow" target="_blank" rel="noopener noreferrer"><span style="color:#340096">Click here</span></a></td>
    <td class="tg-kwiq">Baserow (Air table replacement) allows you to create and customize databases without writing any code</td>
  </tr>
  <tr>
    <td class="tg-kwiq">Vaultwarden</td>
    <td class="tg-kwiq"><a href="https://vaultwarden.$DOMAIN/" target="_blank" rel="noopener noreferrer"><span style="color:#340096">vaultwarden.$DOMAIN</span></a></td>
    <td class="tg-kwiq">Create your own user</td>
    <td class="tg-kwiq">User access is separate from panel. Create your own initial user</td>
    <td class="tg-cul6"><a href="https://documentation.federated.computer/docs/core_applications/vaultwarden" target="_blank" rel="noopener noreferrer"><span style="color:#340096">Click here</span></a></td>
    <td class="tg-kwiq">Vaultwarden is a password manager</td>
  </tr>
  <tr>
    <td class="tg-kwiq">Gitea</td>
    <td class="tg-kwiq"><a href="https://gitea.$DOMAIN/" target="_blank" rel="noopener noreferrer"><span style="color:#340096">gitea.$DOMAIN</span></a></td>
    <td class="tg-kwiq">admin@$DOMAIN<br>admin password above</td>
    <td class="tg-kwiq">User access is separate from panel</td>
    <td class="tg-cul6"><a href="https://documentation.federated.computer/docs/core_applications/gitea" target="_blank" rel="noopener noreferrer"><span style="color:#340096">Click here</span></a></td>
    <td class="tg-kwiq">Gitea is a code repository system similar to GitHub</td>
  </tr>
  <tr>
    <td class="tg-kwiq">PowerDNS</td>
    <td class="tg-kwiq"><a href="https://powerdns.$DOMAIN/" target="_blank" rel="noopener noreferrer"><span style="color:#340096">powerdns.$DOMAIN</span></a></td>
    <td class="tg-kwiq">admin@$DOMAIN<br>admin password above</td>
    <td class="tg-kwiq">User access is separate from panel</td>
    <td class="tg-cul6"><a href="https://documentation.federated.computer/docs/core_applications/powerdns" target="_blank" rel="noopener noreferrer"><span style="color:#340096">Click here</span></a></td>
    <td class="tg-kwiq">PowerDNS is a powerful tool for managing DNS of your domain</td>
  </tr>
  <tr>
    <td class="tg-0pky">Castopod</td>
    <td class="tg-0pky"><a href="https://castopod.$DOMAIN/cp-auth/login" target="_blank" rel="noopener noreferrer"><span style="color:#340096">castopod.$DOMAIN/cp-auth/login</span></a></td>
    <td class="tg-0pky">admin@$DOMAIN<br>admin password above</td>
    <td class="tg-0pky">User access is separate from panel</td>
    <td class="tg-cul6"><a href="https://documentation.federated.computer/docs/getting_started/welcome" target="_blank" rel="noopener noreferrer"><span style="color:#340096">Click here</span></a></td>
    <td class="tg-0pky">Castopod is a full platform for hosting and delivering podcasts to your audience</td>
  </tr>
  <tr>
    <td class="tg-0pky">Wordpress</td>
    <td class="tg-0pky"><a href="https://www.$DOMAIN/login" target="_blank" rel="noopener noreferrer"><span style="color:#340096">www.$DOMAIN/login</span></a></td>
    <td class="tg-0pky">admin@$DOMAIN<br>admin password above</td>
    <td class="tg-0pky">User access is separate from panel</td>
    <td class="tg-cul6"><a href="https://documentation.federated.computer/docs/getting_started/welcome/" target="_blank" rel="noopener noreferrer"><span style="color:#340096">Click here</span></a></td>
    <td class="tg-0pky">Wordpress is a dynamic content management solution used by 10s of millions of websites around the globe</td>
  </tr>
  <tr>
    <td class="tg-0pky">Autodiscovery</td>
    <td class="tg-0pky"><a href="https://autodiscover.$DOMAIN/" target="_blank" rel="noopener noreferrer"><span style="color:#340096">autodiscover.$DOMAIN</span></a></td>
    <td class="tg-0pky">admin@$DOMAIN<br>admin password above</td>
    <td class="tg-0pky">User access is separate from panel</td>
    <td class="tg-cul6"><a href="https://documentation.federated.computer/docs/getting_started/welcome/" target="_blank" rel="noopener noreferrer"><span style="color:#340096">Click here</span></a></td>
    <td class="tg-0pky">Auto discovery is a service to provide automatic mail configurations for mail clients</td>
  </tr>
  <tr>
    <td class="tg-0pky">Bookstack</td>
    <td class="tg-0pky"><a href="https://bookstack.$DOMAIN/login" target="_blank" rel="noopener noreferrer"><span style="color:#340096">bookstack.$DOMAIN</span></a></td>
    <td class="tg-0pky">admin@$DOMAIN<br>admin password above</td>
    <td class="tg-0pky">User access is separate from panel</td>
    <td class="tg-cul6"><a href="https://documentation.federated.computer/docs/getting_started/welcome/" target="_blank" rel="noopener noreferrer"><span style="color:#340096">Click here</span></a></td>
    <td class="tg-0pky">Bookstack is a simple, open-source, self-hosted, easy-to-use platform (Wiki) for organising and storing information</td>
  </tr>
  <tr>
    <td class="tg-0pky">Freescout</td>
    <td class="tg-0pky"><a href="https://freescout.$DOMAIN/login" target="_blank" rel="noopener noreferrer"><span style="color:#340096">freescout.$DOMAIN</span></a></td>
    <td class="tg-0pky">admin@$DOMAIN<br>admin password above</td>
    <td class="tg-0pky">User access is separate from panel</td>
    <td class="tg-cul6"><a href="https://documentation.federated.computer/docs/getting_started/welcome/" target="_blank" rel="noopener noreferrer"><span style="color:#340096">Click here</span></a></td>
    <td class="tg-0pky">FreeScout is the super lightweight and powerful free open source help desk</td>
  </tr>
  <tr>
    <td class="tg-0pky">Music Side Project</td>
    <td class="tg-0pky"><a href="https://msp.$DOMAIN" target="_blank" rel="noopener noreferrer"><span style="color:#340096">msp.$DOMAIN</span></a></td>
    <td class="tg-0pky">admin@$DOMAIN<br>admin password above</td>
    <td class="tg-0pky">User access is separate from panel</td>
    <td class="tg-cul6"><a href="https://documentation.federated.computer/docs/getting_started/welcome/" target="_blank" rel="noopener noreferrer"><span style="color:#340096">Click here</span></a></td>
    <td class="tg-0pky">Music Side Project Studio enables you to harness the potential of RSS feeds and the Lightning Network, allowing you to self-host your music and receive direct payment from your fans</td>
  </tr>
  <tr>
    <td class="tg-0pky">EspoCRM</td>
    <td class="tg-0pky"><a href="https://espocrm.$DOMAIN" target="_blank" rel="noopener noreferrer"><span style="color:#340096">espocrm.$DOMAIN</span></a></td>
    <td class="tg-0pky">admin@$DOMAIN<br>admin password above</td>
    <td class="tg-0pky">All users in panel can access EspoCRM using user@domain.com</td>
    <td class="tg-cul6"><a href="https://documentation.federated.computer/docs/getting_started/welcome/" target="_blank" rel="noopener noreferrer"><span style="color:#340096">Click here</span></a></td>
    <td class="tg-0pky">EspoCRM is an Open Source CRM (Customer Relationship Management) software that allows you to see, enter and evaluate all your company relationships</td>
  </tr>
</tbody>
</table>
<h4>Thanks for your support!</h4>
<p>
Thank you for your support of Federated Computer. We really appreciate it and hope you have a very successful
time with Federated Core.
<p>
Again, if we can be of any assistance, please don't hesitate to get in touch.
<p>
Support: https://support.federated.computer<br>
Phone: (970) 722-8715<br>
Email: support@federated.computer<br>
<p>
It's <b>your</b> computer. Let's make it work for you!
</html>
EOF

# Send out e-mail from mail container with details
#docker exec mail bash -c "mail -r admin@$DOMAIN -a \"Content-type: text/html\" -s \"Migrated To $DOMAIN\" admin@$DOMAIN < /root/certs/mailfile"
#docker exec mail bash -c "mail -r admin@$DOMAIN -a \"Content-type: text/html\" -s \"Migrated To $DOMAIN\" $EMAIL < /root/certs/mailfile"
#cat /federated/apps/mail/data/root/certs/mailfile
#rm /federated/apps/mail/data/root/certs/mailfile
}
print_details_creator() {
cat > /federated/apps/mail/data/root/certs/mailfile <<EOF
<html>
<img src="https://www.federated.computer/images/logo.png" alt="" /><br>
Dear Federated Customer,
<p>
Please read this note in its entirety since it has some important information for you to get the best use
out of your Federated Core. If you ever get stuck for whatever reason, please reach out to us for support:
<p>
Website: https://support.federated.computer<br>
Phone: 970-722-8715<br>
Email: support@federated.computer<br>
<p>
We are here to help you, the Customer, get the most out of your Federated Core.
<p>
All documentation for your Federated Core can be found at https://documentation.federated.computer.
There you'll find tips for how to use your Core and the various open source applications bundled with
your Core.
<p>
<h4>Domain Information</h4>
This is your domain: <b>$DOMAIN</b>
<p>
If you just signed up for Federated Core, your domain is a temporary domain (example: starts with F...). Please do not change the admin password (see below) until you switch to your own domain name (example: mustache.com). We use the admin account and password for your temporary domain to re-configure all the software for your new/permanent domain. If you have a question about this, send us an email to support@federated.computer.
<p>
When you are ready to switch over to your own yourdomain.com send us an e-mail at support@federated.computer and let us know you are done migrating your data, have pointed DNS correctly, and ready for us to switch. We also need to know the yourdomain.com you will be using.
<p>
For setting DNS records you will need to set your glue records for your own yourdomain.com to be:
<p>
ns1.yourdomain.com - $EXTERNALIP<br>
ns2.yourdomain.com - $EXTERNALIP<br>
<p>
And your authoritative:
<p>
ns1.yourdomain.com<br>
ns2.yourdomain.com<br>
<p>
If you have questions about DNS records, please send us an email at support@federated.computer so that we can help you.
<p>
<h4>Admin User</h4>
<p>
There is an "admin" or administrative use that has access to everything on your Federated Core.
Here are the credentials for that user.
<p>
Username = "admin@$DOMAIN"<br>
Password = "$ADMINPASS"
<p>
<h4>Applications</h4>
<style type="text/css">
.tg  {border-collapse:collapse;border-spacing:0;}
.tg td{border-color:black;border-style:solid;border-width:1px;font-family:Arial, sans-serif;font-size:14px;
  overflow:hidden;padding:10px 5px;word-break:normal;}
.tg th{border-color:black;border-style:solid;border-width:1px;font-family:Arial, sans-serif;font-size:14px;
  font-weight:normal;overflow:hidden;padding:10px 5px;word-break:normal;}
.tg .tg-cul6{border-color:inherit;color:#340096;text-align:left;text-decoration:underline;vertical-align:top}
.tg .tg-acii{background-color:#FFF;border-color:inherit;color:#333;text-align:left;vertical-align:top}
.tg .tg-0hty{background-color:#000000;border-color:inherit;color:#ffffff;font-weight:bold;text-align:left;vertical-align:top}
.tg .tg-kwiq{border-color:inherit;color:#000000;text-align:left;vertical-align:top;word-wrap:break-word}
.tg .tg-0pky{border-color:inherit;text-align:left;vertical-align:top}
</style>
<table class="tg" style="undefined;table-layout: fixed; width: 996px">
<colgroup>
<col style="width: 101.333333px">
<col style="width: 203.333333px">
<col style="width: 200.333333px">
<col style="width: 200.333333px">
<col style="width: 77.333333px">
<col style="width: 220.333333px">
</colgroup>
<thead>
  <tr>
    <th class="tg-0hty">Service</th>
    <th class="tg-0hty">Link</th>
    <th class="tg-0hty">User / Pass</th>
    <th class="tg-0hty">Access</th>
    <th class="tg-0hty">Docs</th>
    <th class="tg-0hty">Description</th>
  </tr>
</thead>
<tbody>
  <tr>
    <td class="tg-kwiq">Panel</td>
    <td class="tg-kwiq"><a href="https://panel.$DOMAIN/" target="_blank" rel="noopener noreferrer"><span style="color:#340096">panel.$DOMAIN</span></a></td>
    <td class="tg-kwiq">admin@$DOMAIN<br>admin password above</td>
    <td class="tg-kwiq">All users in panel have access using user@$DOMAIN</td>
    <td class="tg-cul6"><a href="https://documentation.federated.computer/docs/core_applications/panel" target="_blank" rel="noopener noreferrer"><span style="color:#340096">Click here</span></a></td>
    <td class="tg-kwiq">Use panel to create user accounts for your team and change passwords</td>
  </tr>
  <tr>
    <td class="tg-kwiq">Email</td>
    <td class="tg-kwiq"><a href="https://nextcloud.$DOMAIN/" target="_blank" rel="noopener noreferrer"><span style="color:#340096">nextcloud.$DOMAIN</span></a><br>WebMail application</td>
    <td class="tg-kwiq">admin@$DOMAIN<br>admin password above</td>
    <td class="tg-kwiq">All users in panel can access their own mail accounts through Nextcloud or mail client using user@$DOMAIN</td>
    <td class="tg-cul6"><a href="https://documentation.federated.computer/docs/getting_started/welcome" target="_blank" rel="noopener noreferrer"><span style="color:#340096">Click here</span></a></td>
    <td class="tg-kwiq">This is your own private e-mail service accessed through Nextcloud webmail or configure a mail client with SMTP mail.$DOMAIN (port 465), and IMAP mail.$DOMAIN (port 993)</td>
  </tr>
  <tr>
    <td class="tg-kwiq">Nextcloud</td>
    <td class="tg-kwiq"><a href="https://nextcloud.$DOMAIN/" target="_blank" rel="noopener noreferrer"><span style="color:#340096">nextcloud.$DOMAIN</span></a></td>
    <td class="tg-kwiq">admin@$DOMAIN<br>admin password above</td>
    <td class="tg-kwiq">All users in panel have access using user@$DOMAIN</td>
    <td class="tg-cul6"><a href="https://documentation.federated.computer/docs/core_applications/nextcloud" target="_blank" rel="noopener noreferrer"><span style="color:#340096">Click here</span></a></td>
    <td class="tg-kwiq">The Nextcloud Suite replaces google workspace which provides mail, calendar, contacts, notes, tasks, files, word processing, spreadsheets, project management, slides, and pictures</td>
  </tr>
  <tr>
    <td class="tg-kwiq">Autodiscovery</td>
    <td class="tg-kwiq"><a href="https://autodiscover.$DOMAIN/" target="_blank" rel="noopener noreferrer"><span style="color:#340096">autodiscover.$DOMAIN</span></a></td>
    <td class="tg-kwiq">admin@$DOMAIN<br>admin password above</td>
    <td class="tg-kwiq">User access is separate from panel</td>
    <td class="tg-kwiq"><a href="https://documentation.federated.computer/docs/getting_started/welcome/" target="_blank" rel="noopener noreferrer"><span style="color:#340096">Click here</span></a></td>
    <td class="tg-kwiq">Auto discovery is a service to provide automatic mail configurations for mail clients</td>
  </tr>
  <tr>
    <td class="tg-kwiq">Vaultwarden</td>
    <td class="tg-kwiq"><a href="https://vaultwarden.$DOMAIN/" target="_blank" rel="noopener noreferrer"><span style="color:#340096">vaultwarden.$DOMAIN</span></a></td>
    <td class="tg-kwiq">Create your own user</td>
    <td class="tg-kwiq">User access is separate from panel. Create your own initial user</td>
    <td class="tg-cul6"><a href="https://documentation.federated.computer/docs/core_applications/vaultwarden" target="_blank" rel="noopener noreferrer"><span style="color:#340096">Click here</span></a></td>
    <td class="tg-kwiq">Vaultwarden is a password manager</td>
  </tr>
  <tr>
    <td class="tg-kwiq">PowerDNS</td>
    <td class="tg-kwiq"><a href="https://powerdns.$DOMAIN/" target="_blank" rel="noopener noreferrer"><span style="color:#340096">powerdns.$DOMAIN</span></a></td>
    <td class="tg-kwiq">admin@$DOMAIN<br>admin password above</td>
    <td class="tg-kwiq">User access is separate from panel</td>
    <td class="tg-kwiq"><a href="https://documentation.federated.computer/docs/core_applications/powerdns" target="_blank" rel="noopener noreferrer"><span style="color:#340096">Click here</span></a></td>
    <td class="tg-kwiq">PowerDNS is a powerful tool for managing DNS of your domain</td>
  </tr>
  <tr>
    <td class="tg-kwiq">Element</td>
    <td class="tg-kwiq"><a href="https://element.$DOMAIN/" target="_blank" rel="noopener noreferrer"><span style="color:#340096">element.$DOMAIN</span></a></td>
    <td class="tg-kwiq">admin@$DOMAIN<br>admin password above</td>
    <td class="tg-kwiq">All users added in panel can access element / matrix with their own user@$DOMAIN account</td>
    <td class="tg-cul6"><a href="https://documentation.federated.computer/docs/core_applications/element" target="_blank" rel="noopener noreferrer"><span style="color:#340096">Click here</span></a></td>
    <td class="tg-kwiq">Element (a Slack replacement) provides you the ability to chat with those on your team and outside of your team</td>
  </tr>
  <tr>
    <td class="tg-kwiq">Wordpress</td>
    <td class="tg-kwiq"><a href="https://www.$DOMAIN/login" target="_blank" rel="noopener noreferrer"><span style="color:#340096">www.$DOMAIN/login</span></a></td>
    <td class="tg-kwiq">admin@$DOMAIN<br>admin password above</td>
    <td class="tg-kwiq">User access is separate from panel</td>
    <td class="tg-cul6"><a href="https://documentation.federated.computer/docs/getting_started/welcome/" target="_blank" rel="noopener noreferrer"><span style="color:#340096">Click here</span></a></td>
    <td class="tg-kwiq">Wordpress is a dynamic content management solution used by 10s of millions of websites around the globe</td>
  </tr>
</tbody>
</table>
<br>
<h4>Thanks for your support!</h4>
<p>
Thank you for your support of Federated Computer. We really appreciate it and hope you have a very successful
time with Federated Core.
<p>
Again, if we can be of any assistance, please don't hesitate to get in touch.
<p>
Support: https://support.federated.computer<br>
Phone: (970) 722-8715<br>
Email: support@federated.computer<br>
<p>
It's <b>your</b> computer. Let's make it work for you!
</html>
EOF

# Send out e-mail from mail container with details
#docker exec mail bash -c "mail -r admin@$DOMAIN -a \"Content-type: text/html\" -s \"Welcome to Federated\" admin@$DOMAIN < /root/certs/mailfile"
#docker exec mail bash -c "mail -r admin@$DOMAIN -a \"Content-type: text/html\" -s \"Welcome to Federated\" $EMAIL < /root/certs/mailfile"
#cat /federated/apps/mail/data/root/certs/mailfile
#rm /federated/apps/mail/data/root/certs/mailfile
}
print_details_team() {
cat > /federated/apps/mail/data/root/certs/mailfile <<EOF
<html>
<img src="https://www.federated.computer/images/logo.png" alt="" /><br>
Dear Federated Customer,
<p>
Please read this note in its entirety since it has some important information for you to get the best use
out of your Federated Core. If you ever get stuck for whatever reason, please reach out to us for support:
<p>
Website: https://support.federated.computer<br>
Phone: 970-722-8715<br>
Email: support@federated.computer<br>
<p>
We are here to help you, the Customer, get the most out of your Federated Core.
<p>
All documentation for your Federated Core can be found at https://documentation.federated.computer.
There you'll find tips for how to use your Core and the various open source applications bundled with
your Core.
<p>
<h4>Domain Information</h4>
This is your domain: <b>$DOMAIN</b>
<p>
If you just signed up for Federated Core, your domain is a temporary domain (example: starts with F...). Please do not change the admin password (see below) until you switch to your own domain name (example: mustache.com). We use the admin account and password for your temporary domain to re-configure all the software for your new/permanent domain. If you have a question about this, send us an email to support@federated.computer.
<p>
When you are ready to switch over to your own yourdomain.com send us an e-mail at support@federated.computer and let us know you are done migrating your data, have pointed DNS correctly, and ready for us to switch. We also need to know the yourdomain.com you will be using.
<p>
For setting DNS records you will need to set your glue records for your own yourdomain.com to be:
<p>
ns1.yourdomain.com - $EXTERNALIP<br>
ns2.yourdomain.com - $EXTERNALIP<br>
<p>
And your authoritative:
<p>
ns1.yourdomain.com<br>
ns2.yourdomain.com<br>
<p>
If you have questions about DNS records, please send us an email at support@federated.computer so that we can help you.
<p>
<h4>Admin User</h4>
<p>
There is an "admin" or administrative use that has access to everything on your Federated Core.
Here are the credentials for that user.
<p>
Username = "admin@$DOMAIN"<br>
Password = "$ADMINPASS"
<p>
<h4>Applications</h4>
<style type="text/css">
.tg  {border-collapse:collapse;border-spacing:0;}
.tg td{border-color:black;border-style:solid;border-width:1px;font-family:Arial, sans-serif;font-size:14px;
  overflow:hidden;padding:10px 5px;word-break:normal;}
.tg th{border-color:black;border-style:solid;border-width:1px;font-family:Arial, sans-serif;font-size:14px;
  font-weight:normal;overflow:hidden;padding:10px 5px;word-break:normal;}
.tg .tg-cul6{border-color:inherit;color:#340096;text-align:left;text-decoration:underline;vertical-align:top}
.tg .tg-acii{background-color:#FFF;border-color:inherit;color:#333;text-align:left;vertical-align:top}
.tg .tg-0hty{background-color:#000000;border-color:inherit;color:#ffffff;font-weight:bold;text-align:left;vertical-align:top}
.tg .tg-kwiq{border-color:inherit;color:#000000;text-align:left;vertical-align:top;word-wrap:break-word}
.tg .tg-0pky{border-color:inherit;text-align:left;vertical-align:top}
</style>
<table class="tg" style="undefined;table-layout: fixed; width: 996px">
<colgroup>
<col style="width: 101.333333px">
<col style="width: 203.333333px">
<col style="width: 200.333333px">
<col style="width: 200.333333px">
<col style="width: 77.333333px">
<col style="width: 220.333333px">
</colgroup>
<thead>
  <tr>
    <th class="tg-0hty">Service</th>
    <th class="tg-0hty">Link</th>
    <th class="tg-0hty">User / Pass</th>
    <th class="tg-0hty">Access</th>
    <th class="tg-0hty">Docs</th>
    <th class="tg-0hty">Description</th>
  </tr>
</thead>
<tbody>
  <tr>
    <td class="tg-kwiq">Panel</td>
    <td class="tg-kwiq"><a href="https://panel.$DOMAIN/" target="_blank" rel="noopener noreferrer"><span style="color:#340096">panel.$DOMAIN</span></a></td>
    <td class="tg-kwiq">admin@$DOMAIN<br>admin password above</td>
    <td class="tg-kwiq">All users in panel have access using user@$DOMAIN</td>
    <td class="tg-cul6"><a href="https://documentation.federated.computer/docs/core_applications/panel" target="_blank" rel="noopener noreferrer"><span style="color:#340096">Click here</span></a></td>
    <td class="tg-kwiq">Use panel to create user accounts for your team and change passwords</td>
  </tr>
  <tr>
    <td class="tg-kwiq">Email</td>
    <td class="tg-kwiq"><a href="https://nextcloud.$DOMAIN/" target="_blank" rel="noopener noreferrer"><span style="color:#340096">nextcloud.$DOMAIN</span></a><br>WebMail application</td>
    <td class="tg-kwiq">admin@$DOMAIN<br>admin password above</td>
    <td class="tg-kwiq">All users in panel can access their own mail accounts through Nextcloud or mail client using user@$DOMAIN</td>
    <td class="tg-cul6"><a href="https://documentation.federated.computer/docs/getting_started/welcome" target="_blank" rel="noopener noreferrer"><span style="color:#340096">Click here</span></a></td>
    <td class="tg-kwiq">This is your own private e-mail service accessed through Nextcloud webmail or configure a mail client with SMTP mail.$DOMAIN (port 465), and IMAP mail.$DOMAIN (port 993)</td>
  </tr>
  <tr>
    <td class="tg-kwiq">Nextcloud</td>
    <td class="tg-kwiq"><a href="https://nextcloud.$DOMAIN/" target="_blank" rel="noopener noreferrer"><span style="color:#340096">nextcloud.$DOMAIN</span></a></td>
    <td class="tg-kwiq">admin@$DOMAIN<br>admin password above</td>
    <td class="tg-kwiq">All users in panel have access using user@$DOMAIN</td>
    <td class="tg-cul6"><a href="https://documentation.federated.computer/docs/core_applications/nextcloud" target="_blank" rel="noopener noreferrer"><span style="color:#340096">Click here</span></a></td>
    <td class="tg-kwiq">The Nextcloud Suite replaces google workspace which provides mail, calendar, contacts, notes, tasks, files, word processing, spreadsheets, project management, slides, and pictures</td>
  </tr>
  <tr>
    <td class="tg-kwiq">Autodiscovery</td>
    <td class="tg-kwiq"><a href="https://autodiscover.$DOMAIN/" target="_blank" rel="noopener noreferrer"><span style="color:#340096">autodiscover.$DOMAIN</span></a></td>
    <td class="tg-kwiq">admin@$DOMAIN<br>admin password above</td>
    <td class="tg-kwiq">User access is separate from panel</td>
    <td class="tg-kwiq"><a href="https://documentation.federated.computer/docs/getting_started/welcome/" target="_blank" rel="noopener noreferrer"><span style="color:#340096">Click here</span></a></td>
    <td class="tg-kwiq">Auto discovery is a service to provide automatic mail configurations for mail clients</td>
  </tr>
  <tr>
    <td class="tg-kwiq">Vaultwarden</td>
    <td class="tg-kwiq"><a href="https://vaultwarden.$DOMAIN/" target="_blank" rel="noopener noreferrer"><span style="color:#340096">vaultwarden.$DOMAIN</span></a></td>
    <td class="tg-kwiq">Create your own user</td>
    <td class="tg-kwiq">User access is separate from panel. Create your own initial user</td>
    <td class="tg-cul6"><a href="https://documentation.federated.computer/docs/core_applications/vaultwarden" target="_blank" rel="noopener noreferrer"><span style="color:#340096">Click here</span></a></td>
    <td class="tg-kwiq">Vaultwarden is a password manager</td>
  </tr>
  <tr>
    <td class="tg-kwiq">PowerDNS</td>
    <td class="tg-kwiq"><a href="https://powerdns.$DOMAIN/" target="_blank" rel="noopener noreferrer"><span style="color:#340096">powerdns.$DOMAIN</span></a></td>
    <td class="tg-kwiq">admin@$DOMAIN<br>admin password above</td>
    <td class="tg-kwiq">User access is separate from panel</td>
    <td class="tg-kwiq"><a href="https://documentation.federated.computer/docs/core_applications/powerdns" target="_blank" rel="noopener noreferrer"><span style="color:#340096">Click here</span></a></td>
    <td class="tg-kwiq">PowerDNS is a powerful tool for managing DNS of your domain</td>
  </tr>
  <tr>
    <td class="tg-kwiq">Element</td>
    <td class="tg-kwiq"><a href="https://element.$DOMAIN/" target="_blank" rel="noopener noreferrer"><span style="color:#340096">element.$DOMAIN</span></a></td>
    <td class="tg-kwiq">admin@$DOMAIN<br>admin password above</td>
    <td class="tg-kwiq">All users added in panel can access element / matrix with their own user@$DOMAIN account</td>
    <td class="tg-cul6"><a href="https://documentation.federated.computer/docs/core_applications/element" target="_blank" rel="noopener noreferrer"><span style="color:#340096">Click here</span></a></td>
    <td class="tg-kwiq">Element (a Slack replacement) provides you the ability to chat with those on your team and outside of your team</td>
  </tr>
  <tr>
    <td class="tg-kwiq">Wordpress</td>
    <td class="tg-kwiq"><a href="https://www.$DOMAIN/login" target="_blank" rel="noopener noreferrer"><span style="color:#340096">www.$DOMAIN/login</span></a></td>
    <td class="tg-kwiq">admin@$DOMAIN<br>admin password above</td>
    <td class="tg-kwiq">User access is separate from panel</td>
    <td class="tg-cul6"><a href="https://documentation.federated.computer/docs/getting_started/welcome/" target="_blank" rel="noopener noreferrer"><span style="color:#340096">Click here</span></a></td>
    <td class="tg-kwiq">Wordpress is a dynamic content management solution used by 10s of millions of websites around the globe</td>
  </tr>
  <tr>
    <td class="tg-kwiq">Freescout</td>
    <td class="tg-kwiq"><a href="https://freescout.$DOMAIN/login" target="_blank" rel="noopener noreferrer"><span style="color:#340096">freescout.$DOMAIN</span></a></td>
    <td class="tg-kwiq">admin@$DOMAIN<br>admin password above</td>
    <td class="tg-kwiq">User access is separate from panel</td>
    <td class="tg-kwiq"><a href="https://documentation.federated.computer/docs/getting_started/welcome/" target="_blank" rel="noopener noreferrer"><span style="color:#340096">Click here</span></a></td>
    <td class="tg-kwiq">FreeScout is the super lightweight and powerful free open source help desk</td>
  </tr>
  <tr>
    <td class="tg-kwiq">EspoCRM</td>
    <td class="tg-kwiq"><a href="https://espocrm.$DOMAIN" target="_blank" rel="noopener noreferrer"><span style="color:#340096">espocrm.$DOMAIN</span></a></td>
    <td class="tg-kwiq">admin@$DOMAIN<br>admin password above</td>
    <td class="tg-kwiq">All users in panel can access EspoCRM using user@$DOMAIN</td>
    <td class="tg-kwiq"><a href="https://documentation.federated.computer/docs/getting_started/welcome/" target="_blank" rel="noopener noreferrer"><span style="color:#340096">Click here</span></a></td>
    <td class="tg-kwiq">EspoCRM is an Open Source CRM (Customer Relationship Management) software that allows you to see, enter and evaluate all your company relationships</td>
  </tr>
</tbody>
</table>
<br>
<h4>Thanks for your support!</h4>
<p>
Thank you for your support of Federated Computer. We really appreciate it and hope you have a very successful
time with Federated Core.
<p>
Again, if we can be of any assistance, please don't hesitate to get in touch.
<p>
Support: https://support.federated.computer<br>
Phone: (970) 722-8715<br>
Email: support@federated.computer<br>
<p>
It's <b>your</b> computer. Let's make it work for you!
</html>
EOF

# Send out e-mail from mail container with details
#docker exec mail bash -c "mail -r admin@$DOMAIN -a \"Content-type: text/html\" -s \"Welcome to Federated\" admin@$DOMAIN < /root/certs/mailfile"
#docker exec mail bash -c "mail -r admin@$DOMAIN -a \"Content-type: text/html\" -s \"Welcome to Federated\" $EMAIL < /root/certs/mailfile"
#cat /federated/apps/mail/data/root/certs/mailfile
#rm /federated/apps/mail/data/root/certs/mailfile
}
print_details_starter() {
cat > /federated/apps/mail/data/root/certs/mailfile <<EOF
<html>
<img src="https://www.federated.computer/images/logo.png" alt="" /><br>
Dear Federated Customer,
<p>
Please read this note in its entirety since it has some important information for you to get the best use
out of your Federated Core. If you ever get stuck for whatever reason, please reach out to us for support:
<p>
Website: https://support.federated.computer<br>
Phone: 970-722-8715<br>
Email: support@federated.computer<br>
<p>
We are here to help you, the Customer, get the most out of your Federated Core.
<p>
All documentation for your Federated Core can be found at https://documentation.federated.computer.
There you'll find tips for how to use your Core and the various open source applications bundled with
your Core.
<p>
<h4>Domain Information</h4>
This is your domain: <b>$DOMAIN</b>
<p>
If you just signed up for Federated Core, your domain is a temporary domain (example: starts with F...). Please do not change the admin password (see below) until you switch to your own domain name (example: mustache.com). We use the admin account and password for your temporary domain to re-configure all the software for your new/permanent domain. If you have a question about this, send us an email to support@federated.computer.
<p>
When you are ready to switch over to your own yourdomain.com send us an e-mail at support@federated.computer and let us know you are done migrating your data, have pointed DNS correctly, and ready for us to switch. We also need to know the yourdomain.com you will be using.
<p>
For setting DNS records you will need to set your glue records for your own yourdomain.com to be:
<p>
ns1.yourdomain.com - $EXTERNALIP<br>
ns2.yourdomain.com - $EXTERNALIP<br>
<p>
And your authoritative:
<p>
ns1.yourdomain.com<br>
ns2.yourdomain.com<br>
<p>
If you have questions about DNS records, please send us an email at support@federated.computer so that we can help you.
<p>
<h4>Admin User</h4>
<p>
There is an "admin" or administrative use that has access to everything on your Federated Core.
Here are the credentials for that user.
<p>
Username = "admin@$DOMAIN"<br>
Password = "$ADMINPASS"
<p>
<h4>Applications</h4>
<style type="text/css">
.tg  {border-collapse:collapse;border-spacing:0;}
.tg td{border-color:black;border-style:solid;border-width:1px;font-family:Arial, sans-serif;font-size:14px;
  overflow:hidden;padding:10px 5px;word-break:normal;}
.tg th{border-color:black;border-style:solid;border-width:1px;font-family:Arial, sans-serif;font-size:14px;
  font-weight:normal;overflow:hidden;padding:10px 5px;word-break:normal;}
.tg .tg-cul6{border-color:inherit;color:#340096;text-align:left;text-decoration:underline;vertical-align:top}
.tg .tg-acii{background-color:#FFF;border-color:inherit;color:#333;text-align:left;vertical-align:top}
.tg .tg-0hty{background-color:#000000;border-color:inherit;color:#ffffff;font-weight:bold;text-align:left;vertical-align:top}
.tg .tg-kwiq{border-color:inherit;color:#000000;text-align:left;vertical-align:top;word-wrap:break-word}
.tg .tg-0pky{border-color:inherit;text-align:left;vertical-align:top}
</style>
<table class="tg" style="undefined;table-layout: fixed; width: 996px">
<colgroup>
<col style="width: 101.333333px">
<col style="width: 203.333333px">
<col style="width: 200.333333px">
<col style="width: 200.333333px">
<col style="width: 77.333333px">
<col style="width: 220.333333px">
</colgroup>
<thead>
  <tr>
    <th class="tg-0hty">Service</th>
    <th class="tg-0hty">Link</th>
    <th class="tg-0hty">User / Pass</th>
    <th class="tg-0hty">Access</th>
    <th class="tg-0hty">Docs</th>
    <th class="tg-0hty">Description</th>
  </tr>
</thead>
<tbody>
  <tr>
    <td class="tg-kwiq">Panel</td>
    <td class="tg-kwiq"><a href="https://panel.$DOMAIN/" target="_blank" rel="noopener noreferrer"><span style="color:#340096">panel.$DOMAIN</span></a></td>
    <td class="tg-kwiq">admin@$DOMAIN<br>admin password above</td>
    <td class="tg-kwiq">All users in panel have access using user@$DOMAIN</td>
    <td class="tg-cul6"><a href="https://documentation.federated.computer/docs/core_applications/panel" target="_blank" rel="noopener noreferrer"><span style="color:#340096">Click here</span></a></td>
    <td class="tg-kwiq">Use panel to create user accounts for your team and change passwords</td>
  </tr>
  <tr>
    <td class="tg-kwiq">Email</td>
    <td class="tg-kwiq"><a href="https://nextcloud.$DOMAIN/" target="_blank" rel="noopener noreferrer"><span style="color:#340096">nextcloud.$DOMAIN</span></a><br>WebMail application</td>
    <td class="tg-kwiq">admin@$DOMAIN<br>admin password above</td>
    <td class="tg-kwiq">All users in panel can access their own mail accounts through Nextcloud or mail client using user@$DOMAIN</td>
    <td class="tg-cul6"><a href="https://documentation.federated.computer/docs/getting_started/welcome" target="_blank" rel="noopener noreferrer"><span style="color:#340096">Click here</span></a></td>
    <td class="tg-kwiq">This is your own private e-mail service accessed through Nextcloud webmail or configure a mail client with SMTP mail.$DOMAIN (port 465), and IMAP mail.$DOMAIN (port 993)</td>
  </tr>
  <tr>
    <td class="tg-kwiq">Nextcloud</td>
    <td class="tg-kwiq"><a href="https://nextcloud.$DOMAIN/" target="_blank" rel="noopener noreferrer"><span style="color:#340096">nextcloud.$DOMAIN</span></a></td>
    <td class="tg-kwiq">admin@$DOMAIN<br>admin password above</td>
    <td class="tg-kwiq">All users in panel have access using user@$DOMAIN</td>
    <td class="tg-cul6"><a href="https://documentation.federated.computer/docs/core_applications/nextcloud" target="_blank" rel="noopener noreferrer"><span style="color:#340096">Click here</span></a></td>
    <td class="tg-kwiq">The Nextcloud Suite replaces google workspace which provides mail, calendar, contacts, notes, tasks, files, word processing, spreadsheets, project management, slides, and pictures</td>
  </tr>
  <tr>
    <td class="tg-kwiq">Autodiscovery</td>
    <td class="tg-kwiq"><a href="https://autodiscover.$DOMAIN/" target="_blank" rel="noopener noreferrer"><span style="color:#340096">autodiscover.$DOMAIN</span></a></td>
    <td class="tg-kwiq">admin@$DOMAIN<br>admin password above</td>
    <td class="tg-kwiq">User access is separate from panel</td>
    <td class="tg-kwiq"><a href="https://documentation.federated.computer/docs/getting_started/welcome/" target="_blank" rel="noopener noreferrer"><span style="color:#340096">Click here</span></a></td>
    <td class="tg-kwiq">Auto discovery is a service to provide automatic mail configurations for mail clients</td>
  </tr>
  <tr>
    <td class="tg-kwiq">Vaultwarden</td>
    <td class="tg-kwiq"><a href="https://vaultwarden.$DOMAIN/" target="_blank" rel="noopener noreferrer"><span style="color:#340096">vaultwarden.$DOMAIN</span></a></td>
    <td class="tg-kwiq">Create your own user</td>
    <td class="tg-kwiq">User access is separate from panel. Create your own initial user</td>
    <td class="tg-cul6"><a href="https://documentation.federated.computer/docs/core_applications/vaultwarden" target="_blank" rel="noopener noreferrer"><span style="color:#340096">Click here</span></a></td>
    <td class="tg-kwiq">Vaultwarden is a password manager</td>
  </tr>
  <tr>
    <td class="tg-kwiq">PowerDNS</td>
    <td class="tg-kwiq"><a href="https://powerdns.$DOMAIN/" target="_blank" rel="noopener noreferrer"><span style="color:#340096">powerdns.$DOMAIN</span></a></td>
    <td class="tg-kwiq">admin@$DOMAIN<br>admin password above</td>
    <td class="tg-kwiq">User access is separate from panel</td>
    <td class="tg-kwiq"><a href="https://documentation.federated.computer/docs/core_applications/powerdns" target="_blank" rel="noopener noreferrer"><span style="color:#340096">Click here</span></a></td>
    <td class="tg-kwiq">PowerDNS is a powerful tool for managing DNS of your domain</td>
  </tr>
</tbody>
</table>
<br>
<h4>Thanks for your support!</h4>
<p>
Thank you for your support of Federated Computer. We really appreciate it and hope you have a very successful
time with Federated Core.
<p>
Again, if we can be of any assistance, please don't hesitate to get in touch.
<p>
Support: https://support.federated.computer<br>
Phone: (970) 722-8715<br>
Email: support@federated.computer<br>
<p>
It's <b>your</b> computer. Let's make it work for you!
</html>
EOF

# Send out e-mail from mail container with details
#docker exec mail bash -c "mail -r admin@$DOMAIN -a \"Content-type: text/html\" -s \"Welcome to Federated\" admin@$DOMAIN < /root/certs/mailfile"
#docker exec mail bash -c "mail -r admin@$DOMAIN -a \"Content-type: text/html\" -s \"Welcome to Federated\" $EMAIL < /root/certs/mailfile"
#cat /federated/apps/mail/data/root/certs/mailfile
#rm /federated/apps/mail/data/root/certs/mailfile
}
print_details() {
cat > /federated/apps/mail/data/root/certs/mailfile <<EOF
<html>
<img src="https://www.federated.computer/images/logo.png" alt="" /><br>
Dear Federated Customer,
<p>
Please read this note in its entirety since it has some important information for you to get the best use
out of your Federated Core. If you ever get stuck for whatever reason, please reach out to us for support:
<p>
Website: https://support.federated.computer<br>
Phone: 970-722-8715<br>
Email: support@federated.computer<br>
<p>
We are here to help you, the Customer, get the most out of your Federated Core.
<p>
All documentation for your Federated Core can be found at https://documentation.federated.computer.
There you'll find tips for how to use your Core and the various open source applications bundled with
your Core.
<p>
<h4>Domain Information</h4>
This is your domain: <b>$DOMAIN</b>
<p>
If you just signed up for Federated Core, your domain is a temporary domain (example: starts with F...). Please do not change the admin password (see below) until you switch to your own domain name (example: mustache.com). We use the admin account and password for your temporary domain to re-configure all the software for your new/permanent domain. If you have a question about this, send us an email to support@federated.computer.
<p>
When you are ready to switch over to your own yourdomain.com send us an e-mail at support@federated.computer and let us know you are done migrating your data, have pointed DNS correctly, and ready for us to switch. We also need to know the yourdomain.com you will be using.
<p>
For setting DNS records you will need to set your glue records for your own yourdomain.com to be:
<p>
ns1.yourdomain.com - $EXTERNALIP<br>
ns2.yourdomain.com - $EXTERNALIP<br>
<p>
And your authoritative:
<p>
ns1.yourdomain.com<br>
ns2.yourdomain.com<br>
<p>
If you have questions about DNS records, please send us an email at support@federated.computer so that we can help you.
<p>
<h4>Admin User</h4>
<p>
There is an "admin" or administrative use that has access to everything on your Federated Core.
Here are the credentials for that user.
<p>
Username = "admin@$DOMAIN"<br>
Password = "$ADMINPASS"
<p>
<h4>Applications</h4>
<style type="text/css">
.tg  {border-collapse:collapse;border-spacing:0;}
.tg td{border-color:black;border-style:solid;border-width:1px;font-family:Arial, sans-serif;font-size:14px;
  overflow:hidden;padding:10px 5px;word-break:normal;}
.tg th{border-color:black;border-style:solid;border-width:1px;font-family:Arial, sans-serif;font-size:14px;
  font-weight:normal;overflow:hidden;padding:10px 5px;word-break:normal;}
.tg .tg-cul6{border-color:inherit;color:#340096;text-align:left;text-decoration:underline;vertical-align:top}
.tg .tg-acii{background-color:#FFF;border-color:inherit;color:#333;text-align:left;vertical-align:top}
.tg .tg-0hty{background-color:#000000;border-color:inherit;color:#ffffff;font-weight:bold;text-align:left;vertical-align:top}
.tg .tg-kwiq{border-color:inherit;color:#000000;text-align:left;vertical-align:top;word-wrap:break-word}
.tg .tg-0pky{border-color:inherit;text-align:left;vertical-align:top}
</style>
<table class="tg" style="undefined;table-layout: fixed; width: 996px">
<colgroup>
<col style="width: 101.333333px">
<col style="width: 203.333333px">
<col style="width: 200.333333px">
<col style="width: 200.333333px">
<col style="width: 77.333333px">
<col style="width: 220.333333px">
</colgroup>
<thead>
  <tr>
    <th class="tg-0hty">Service</th>
    <th class="tg-0hty">Link</th>
    <th class="tg-0hty">User / Pass</th>
    <th class="tg-0hty">Access</th>
    <th class="tg-0hty">Docs</th>
    <th class="tg-0hty">Description</th>
  </tr>
</thead>
<tbody>
  <tr>
    <td class="tg-kwiq">Panel</td>
    <td class="tg-kwiq"><a href="https://panel.$DOMAIN/" target="_blank" rel="noopener noreferrer"><span style="color:#340096">panel.$DOMAIN</span></a></td>
    <td class="tg-kwiq">admin@$DOMAIN<br>admin password above</td>
    <td class="tg-kwiq">All users in panel have access using user@$DOMAIN</td>
    <td class="tg-cul6"><a href="https://documentation.federated.computer/docs/core_applications/panel" target="_blank" rel="noopener noreferrer"><span style="color:#340096">Click here</span></a></td>
    <td class="tg-kwiq">Use panel to create user accounts for your team and change passwords</td>
  </tr>
  <tr>
    <td class="tg-kwiq">Email</td>
    <td class="tg-kwiq"><a href="https://nextcloud.$DOMAIN/" target="_blank" rel="noopener noreferrer"><span style="color:#340096">nextcloud.$DOMAIN</span></a><br>WebMail application</td>
    <td class="tg-kwiq">admin@$DOMAIN<br>admin password above</td>
    <td class="tg-kwiq">All users in panel can access their own mail accounts through Nextcloud or mail client using user@$DOMAIN</td>
    <td class="tg-cul6"><a href="https://documentation.federated.computer/docs/getting_started/welcome" target="_blank" rel="noopener noreferrer"><span style="color:#340096">Click here</span></a></td>
    <td class="tg-kwiq">This is your own private e-mail service accessed through Nextcloud webmail or configure a mail client with SMTP mail.$DOMAIN (port 465), and IMAP mail.$DOMAIN (port 993)</td>
  </tr>
  <tr>
    <td class="tg-kwiq">Nextcloud</td>
    <td class="tg-kwiq"><a href="https://nextcloud.$DOMAIN/" target="_blank" rel="noopener noreferrer"><span style="color:#340096">nextcloud.$DOMAIN</span></a></td>
    <td class="tg-kwiq">admin@$DOMAIN<br>admin password above</td>
    <td class="tg-kwiq">All users in panel have access using user@$DOMAIN</td>
    <td class="tg-cul6"><a href="https://documentation.federated.computer/docs/core_applications/nextcloud" target="_blank" rel="noopener noreferrer"><span style="color:#340096">Click here</span></a></td>
    <td class="tg-kwiq">The Nextcloud Suite replaces google workspace which provides mail, calendar, contacts, notes, tasks, files, word processing, spreadsheets, project management, slides, and pictures</td>
  </tr>
  <tr>
    <td class="tg-kwiq">Jitsi</td>
    <td class="tg-kwiq"><a href="https://jitsi.$DOMAIN/" target="_blank" rel="noopener noreferrer"><span style="color:#340096">jitsi.$DOMAIN</span></a></td>
    <td class="tg-kwiq">admin@$DOMAIN<br>admin password above</td>
    <td class="tg-kwiq">All users in panel have access using user@$DOMAIN</td>
    <td class="tg-cul6"><a href="https://documentation.federated.computer/docs/core_applications/jitsi" target="_blank" rel="noopener noreferrer"><span style="color:#340096">Click here</span></a></td>
    <td class="tg-kwiq">Jitsi is a zoom replacement video conferencing solution</td>
  </tr>
  <tr>
    <td class="tg-kwiq">Element</td>
    <td class="tg-kwiq"><a href="https://element.$DOMAIN/" target="_blank" rel="noopener noreferrer"><span style="color:#340096">element.$DOMAIN</span></a></td>
    <td class="tg-kwiq">admin@$DOMAIN<br>admin password above</td>
    <td class="tg-kwiq">All users in panel have access using user@$DOMAIN</td>
    <td class="tg-cul6"><a href="https://documentation.federated.computer/docs/core_applications/element" target="_blank" rel="noopener noreferrer"><span style="color:#340096">Click here</span></a></td>
    <td class="tg-kwiq">Element (a Slack replacement) provides you the ability to chat with those on your team and outside of your team</td>
  </tr>
  <tr>
    <td class="tg-kwiq">Listmonk</td>
    <td class="tg-kwiq"><a href="https://listmonk.$DOMAIN/" target="_blank" rel="noopener noreferrer"><span style="color:#340096">listmonk.$DOMAIN</span></a></td>
    <td class="tg-kwiq">admin@$DOMAIN<br>admin password above</td>
    <td class="tg-kwiq">User access is separate from panel.</td>
    <td class="tg-cul6"><a href="https://documentation.federated.computer/docs/core_applications/listmonk" target="_blank" rel="noopener noreferrer"><span style="color:#340096">Click here</span></a></td>
    <td class="tg-kwiq">Listmonk is (a replacement for Mailchimp) is used to create e-mail subscription lists</td>
  </tr>
  <tr>
    <td class="tg-kwiq">Baserow</td>
    <td class="tg-kwiq"><a href="https://baserow.$DOMAIN/" target="_blank" rel="noopener noreferrer"><span style="color:#340096">baserow.$DOMAIN</span></a></td>
    <td class="tg-kwiq">admin@$DOMAIN<br>admin password above</td>
    <td class="tg-kwiq">User access is separate from panel. Use the admin account to login and then invite other users</td>
    <td class="tg-cul6"><a href="https://documentation.federated.computer/docs/core_applications/baserow" target="_blank" rel="noopener noreferrer"><span style="color:#340096">Click here</span></a></td>
    <td class="tg-kwiq">Baserow (Air table replacement) allows you to create and customize databases without writing any code</td>
  </tr>
  <tr>
    <td class="tg-kwiq">Vaultwarden</td>
    <td class="tg-kwiq"><a href="https://vaultwarden.$DOMAIN/" target="_blank" rel="noopener noreferrer"><span style="color:#340096">vaultwarden.$DOMAIN</span></a></td>
    <td class="tg-kwiq">Create your own user</td>
    <td class="tg-kwiq">User access is separate from panel. Create your own initial user</td>
    <td class="tg-cul6"><a href="https://documentation.federated.computer/docs/core_applications/vaultwarden" target="_blank" rel="noopener noreferrer"><span style="color:#340096">Click here</span></a></td>
    <td class="tg-kwiq">Vaultwarden is a password manager</td>
  </tr>
  <tr>
    <td class="tg-kwiq">Gitea</td>
    <td class="tg-kwiq"><a href="https://gitea.$DOMAIN/" target="_blank" rel="noopener noreferrer"><span style="color:#340096">gitea.$DOMAIN</span></a></td>
    <td class="tg-kwiq">admin@$DOMAIN<br>admin password above</td>
    <td class="tg-kwiq">User access is separate from panel</td>
    <td class="tg-cul6"><a href="https://documentation.federated.computer/docs/core_applications/gitea" target="_blank" rel="noopener noreferrer"><span style="color:#340096">Click here</span></a></td>
    <td class="tg-kwiq">Gitea is a code repository system similar to GitHub</td>
  </tr>
  <tr>
    <td class="tg-kwiq">PowerDNS</td>
    <td class="tg-kwiq"><a href="https://powerdns.$DOMAIN/" target="_blank" rel="noopener noreferrer"><span style="color:#340096">powerdns.$DOMAIN</span></a></td>
    <td class="tg-kwiq">admin@$DOMAIN<br>admin password above</td>
    <td class="tg-kwiq">User access is separate from panel</td>
    <td class="tg-kwiq"><a href="https://documentation.federated.computer/docs/core_applications/powerdns" target="_blank" rel="noopener noreferrer"><span style="color:#340096">Click here</span></a></td>
    <td class="tg-kwiq">PowerDNS is a powerful tool for managing DNS of your domain</td>
  </tr>
  <tr>
    <td class="tg-kwiq">Castopod</td>
    <td class="tg-kwiq"><a href="https://castopod.$DOMAIN/cp-auth/login" target="_blank" rel="noopener noreferrer"><span style="color:#340096">castopod.$DOMAIN/cp-auth/login</span></a></td>
    <td class="tg-kwiq">admin@$DOMAIN<br>admin password above</td>
    <td class="tg-kwiq">User access is separate from panel</td>
    <td class="tg-kwiq"><a href="https://documentation.federated.computer/docs/getting_started/welcome" target="_blank" rel="noopener noreferrer"><span style="color:#340096">Click here</span></a></td>
    <td class="tg-kwiq">Castopod is a full platform for hosting and delivering podcasts to your audience</td>
  </tr>
  <tr>
    <td class="tg-kwiq">Wordpress</td>
    <td class="tg-kwiq"><a href="https://www.$DOMAIN/login" target="_blank" rel="noopener noreferrer"><span style="color:#340096">www.$DOMAIN/login</span></a></td>
    <td class="tg-kwiq">admin@$DOMAIN<br>admin password above</td>
    <td class="tg-kwiq">User access is separate from panel</td>
    <td class="tg-cul6"><a href="https://documentation.federated.computer/docs/getting_started/welcome/" target="_blank" rel="noopener noreferrer"><span style="color:#340096">Click here</span></a></td>
    <td class="tg-kwiq">Wordpress is a dynamic content management solution used by 10s of millions of websites around the globe</td>
  </tr>
  <tr>
    <td class="tg-kwiq">Autodiscovery</td>
    <td class="tg-kwiq"><a href="https://autodiscover.$DOMAIN/" target="_blank" rel="noopener noreferrer"><span style="color:#340096">autodiscover.$DOMAIN</span></a></td>
    <td class="tg-kwiq">admin@$DOMAIN<br>admin password above</td>
    <td class="tg-kwiq">User access is separate from panel</td>
    <td class="tg-kwiq"><a href="https://documentation.federated.computer/docs/getting_started/welcome/" target="_blank" rel="noopener noreferrer"><span style="color:#340096">Click here</span></a></td>
    <td class="tg-kwiq">Auto discovery is a service to provide automatic mail configurations for mail clients</td>
  </tr>
  <tr>
    <td class="tg-kwiq">Bookstack</td>
    <td class="tg-kwiq"><a href="https://bookstack.$DOMAIN/login" target="_blank" rel="noopener noreferrer"><span style="color:#340096">bookstack.$DOMAIN</span></a></td>
    <td class="tg-kwiq">admin@$DOMAIN<br>admin password above</td>
    <td class="tg-kwiq">User access is separate from panel</td>
    <td class="tg-kwiq"><a href="https://documentation.federated.computer/docs/getting_started/welcome/" target="_blank" rel="noopener noreferrer"><span style="color:#340096">Click here</span></a></td>
    <td class="tg-kwiq">Bookstack is a simple, open-source, self-hosted, easy-to-use platform (Wiki) for organising and storing information</td>
  </tr>
  <tr>
    <td class="tg-kwiq">Freescout</td>
    <td class="tg-kwiq"><a href="https://freescout.$DOMAIN/login" target="_blank" rel="noopener noreferrer"><span style="color:#340096">freescout.$DOMAIN</span></a></td>
    <td class="tg-kwiq">admin@$DOMAIN<br>admin password above</td>
    <td class="tg-kwiq">User access is separate from panel</td>
    <td class="tg-kwiq"><a href="https://documentation.federated.computer/docs/getting_started/welcome/" target="_blank" rel="noopener noreferrer"><span style="color:#340096">Click here</span></a></td>
    <td class="tg-kwiq">FreeScout is the super lightweight and powerful free open source help desk</td>
  </tr>
  <tr>
    <td class="tg-kwiq">Music Side Project</td>
    <td class="tg-kwiq"><a href="https://msp.$DOMAIN" target="_blank" rel="noopener noreferrer"><span style="color:#340096">msp.$DOMAIN</span></a></td>
    <td class="tg-kwiq">admin@$DOMAIN<br>admin password above</td>
    <td class="tg-kwiq">User access is separate from panel</td>
    <td class="tg-kwiq"><a href="https://documentation.federated.computer/docs/getting_started/welcome/" target="_blank" rel="noopener noreferrer"><span style="color:#340096">Click here</span></a></td>
    <td class="tg-kwiq">Music Side Project Studio enables you to harness the potential of RSS feeds and the Lightning Network, allowing you to self-host your music and receive direct payment from your fans</td>
  </tr>
  <tr>
    <td class="tg-kwiq">EspoCRM</td>
    <td class="tg-kwiq"><a href="https://espocrm.$DOMAIN" target="_blank" rel="noopener noreferrer"><span style="color:#340096">espocrm.$DOMAIN</span></a></td>
    <td class="tg-kwiq">admin@$DOMAIN<br>admin password above</td>
    <td class="tg-kwiq">All users in panel have access using user@$DOMAIN</td>
    <td class="tg-kwiq"><a href="https://documentation.federated.computer/docs/getting_started/welcome/" target="_blank" rel="noopener noreferrer"><span style="color:#340096">Click here</span></a></td>
    <td class="tg-kwiq">EspoCRM is an Open Source CRM (Customer Relationship Management) software that allows you to see, enter and evaluate all your company relationships</td>
  </tr>
</tbody>
</table>
<br>
<h4>VPN</h4>
<p>
Your core comes with a very powerful VPN solution built using Wireguard. The following information is
needed by your users so that they can use the VPN. Please treat this information as a very important
secret. There are two important parts of the VPN:
<p>
Here is your VPN configuration:<br>
<code>

EOF
sed "s/$/<br>/" /federated/apps/wireguard/data/config/peer1/peer1.conf >> /federated/apps/mail/data/root/certs/mailfile

cat >> /federated/apps/mail/data/root/certs/mailfile <<EOF

</code>
<h4>Thanks for your support!</h4>
<p>
Thank you for your support of Federated Computer. We really appreciate it and hope you have a very successful
time with Federated Core.
<p>
Again, if we can be of any assistance, please don't hesitate to get in touch.
<p>
Support: https://support.federated.computer<br>
Phone: (970) 722-8715<br>
Email: support@federated.computer<br>
<p>
It's <b>your</b> computer. Let's make it work for you!
</html>
EOF

# Send out e-mail from mail container with details
#docker exec mail bash -c "mail -r admin@$DOMAIN -a \"Content-type: text/html\" -s \"Welcome to Federated\" admin@$DOMAIN < /root/certs/mailfile"
#docker exec mail bash -c "mail -r admin@$DOMAIN -a \"Content-type: text/html\" -s \"Welcome to Federated\" $EMAIL < /root/certs/mailfile"
#cat /federated/apps/mail/data/root/certs/mailfile
#rm /federated/apps/mail/data/root/certs/mailfile
}
check_docker() {
  OSRELEASE=`cat /etc/os-release|grep ^ID= |cut -d= -f2 |sed -e 's,^",,;s,"$,,'`

  echo -ne "\n* Updating OS with the latest patches.."

  if [ "$OSRELEASE" = "ubuntu" ]; then
    # Update OS with latest patches
    sudo apt-get update -y &> /dev/null
    [ $? -ne 0 ] && failcheck "Couldn't run sudo apt-get update"

    NEEDRESTART_MODE=a apt-get upgrade -y &> /dev/null
    [ $? -ne 0 ] && failcheck "Couldn't run sudo apt-get upgrade"
  elif [ "$OSRELEASE" = "openmandriva" ]; then
    dnf -y --refresh distro-sync &>/dev/null
    [ $? -ne 0 ] && failcheck "Couldn't run dnf distro-sync"
  fi

  kill -9 $SPINPID &> /dev/null
  echo -ne "done."

  # Install docker if not found
  if ! command -v docker &> /dev/null; then
      echo -ne "\n* Couldn't find docker, installing.."
      spin &
      SPINPID=$!
    
      # Install Docker on Ubuntu  
      if [ $OSRELEASE == "ubuntu" ]; then
        # Update list of packages	
        sudo apt-get update -y &> /dev/null
        [ $? -ne 0 ] && failcheck "Couldn't run sudo apt-get update"

	# Install packages which let apt use packages over HTTPS
        sudo apt install apt-transport-https ca-certificates curl software-properties-common -y &> /dev/null
        [ $? -ne 0 ] && failcheck "Couldn't run sudo apt install for https packages"

        # Add GPG key for the official Docker repository to this system
        curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add - &> /dev/null
        [ $? -ne 0 ] && failcheck "Couldn't run curl to add Docker GPG key"

	# Add the docker repository to our APT sources list
        sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu jammy stable" -y &> /dev/null
        [ $? -ne 0 ] && failcheck "Couldn't run sudo add-apt-repository"

	# Install docker packages
	sudo apt-get install docker-ce docker-ce-cli containerd.io docker-compose-plugin docker-compose -y &> /dev/null
        [ $? -ne 0 ] && failcheck "Couldn't run sudo apt install docker packages"

	# Install extra packages
	sudo apt-get install duplicity python3-b2sdk uuid apache2-utils -y &> /dev/null
        [ $? -ne 0 ] && failcheck "Couldn't run sudo apt install extra packages"

        # Put in log rotation fix for docker container logs
        cat > /etc/docker/daemon.json <<EOF
{
    "log-driver": "json-file",
    "log-opts": {
        "max-size": "200m",
        "max-file": "3"
    }
}
EOF

        # Install Traefik certs dumper
        curl -sfL https://raw.githubusercontent.com/ldez/traefik-certs-dumper/master/godownloader.sh | bash -s -- -b $(go env GOPATH 2>/dev/null)/bin v2.8.1 &> /dev/null
        [ $? -ne 0 ] && failcheck "Couldn't install traefik certs dumper"

      elif [ "$OSRELEASE" = "openmandriva" ]; then
        dnf -y --refresh install docker curl docker-compose traefik-certs-dumper
	sed -i -e "s,^OPTIONS=.*,OPTIONS='--log-opt max-size=200m --log-opt max-file=3'," /etc/sysconfig/docker

	systemctl enable --now docker
      fi

      # Restart docker daemon
      systemctl restart docker

      kill -9 $SPINPID &> /dev/null
      echo -ne "done."
  fi

  if ! command -v docker-compose &> /dev/null; then
    echo -ne "\n* Couldn't find docker-compose, installing.."
    spin &
    SPINPID=$!

    # Install Docker compose on Ubuntu  
    if [ $OSRELEASE == "ubuntu" ]; then
      sudo apt-get install docker-compose -y &> /dev/null
    elif [ $OSRELEASE = "openmandriva" ]; then
      sudo dnf -y --refresh install docker-compose &>/dev/null
    fi

    kill -9 $SPINPID &> /dev/null
    echo -ne "done."
  fi
}
check_ports() {
  EXTERNALIP=`dig @resolver4.opendns.com myip.opendns.com +short 2> /dev/null`
  [ $? -ne 0 ] && failcheck "Couldn't run dig, dns is not working"

  # Check if ss command exists
  if command -v ss &> /dev/null; then
  # Check every port we need if it's in use (only if we have never run before)
  if [ $(ls /federated/apps | wc -l) -eq "0" ]; then
    for i in 25 53 80 143 389 587 993 8000; do
        SS=`ss -tulwn | grep LISTEN | awk '{ print $5 }' | awk -F: '{ print $NF }' | grep "^$i$" | head -1`
        # If port 53 (dns) in use by system-resolvd (Ubuntu) then auto fix
        if [ "$SS" == 53 ]; then
          echo -ne "\n* Port 53 in use by systemd-resolved, fixing.."
          spin &
          SPINPID=$!
          if [ $OSRELEASE == "ubuntu" ]; then
            if [ `pgrep -x systemd-resolve` ]; then
              # Install resolvconf to fix
              sudo apt install resolvconf -y &> /dev/null
              [ $? -eq 0 ] && echo -ne "." || failcheck "Failed running sudo apt install resolvconf" 


            else
	      echo -ne "\nFAILED - Port 53 (dns) is already in use\n\n" && exit 2
            fi
	  elif [ $OSRELEASE == "openmandriva" ]; then
            systemctl disable --now systemd-resolved
          fi
          # Shut down systemd-resolved
          systemctl stop systemd-resolved &> /dev/null
          [ $? -ne 0 ] && failcheck "Failed running systemctl stop systemd-resolved"
          systemctl disable systemd-resolved &> /dev/null
          [ $? -ne 0 ] && failcheck "Failed running systemctl disable systemd-resolved"
          # Put nameserver entries so will exist on reboot
	  rm /etc/resolv.conf
          echo "nameserver 1.1.1.1" >> /etc/resolv.conf
          echo "nameserver 1.0.0.1" >> /etc/resolv.conf

	  kill -9 $SPINPID &> /dev/null
          echo -ne "done."
        elif [ "$SS" == "$i" ]; then
  	  failcheck "FAILED - Port $i is already in use" 
        fi
      done
    fi
  fi
}
check_os() {
  OSRELEASE=`cat /etc/os-release|grep ^ID= |cut -d= -f2 |sed -e 's,^",,;s,"$,,'`
  VERSIONID=`grep "VERSION_ID=" /etc/os-release | awk -F\" '{ print $2 }'`
  if [ "$OSRELEASE" = "ubuntu" -a "$VERSIONID" != "22.04" ]; then
    echo -ne "\nFederated requires a minimum of 4G of RAM and 25G of storage\n \ 
              running Ubuntu 22.04 LTS. Your system is not supported. Please contact\n \
	      Federated @ support@federated.computer for assistance or choose our\n \
	      cloud offerings at https://cloud.federated.computer.\n\n"
    exit 2;
  fi
}
check_memory() {
  MEMTOTAL=`awk '/MemTotal/ { printf "%.3d \n", $2/1024 }' /proc/meminfo`
  if [ "$MEMTOTAL" -lt "3700" ]; then
    echo -ne "\nFederated requires a minimum of 4G of RAM and 25G of storage\n \ 
              running Ubuntu 22.04 LTS. Your system is not supported. Please contact\n \
	      Federated @ support@federated.computer for assistance or choose our\n \
	      cloud offerings at https://cloud.federated.computer.\n\n"
    exit 2;
  fi
}
get_installedapps() {
  SERVICES=( $(ls -d /federated/apps/* | awk -F/ '{ print $4 }') )
}
get_appvars() {
  BUNDLE=$(egrep "TIER|BUNDLE" /etc/federated | awk -F\" '{ print $2 }')
  [[ -d "/federated/apps/ldap" ]] && LDAP_SECRET=`cat /federated/apps/ldap/.ldap.secret`
  EXTERNALIP=$(get_externalip)
  MYSQL_ROOTPASSWORD=`cat /federated/apps/pdnsmysql/.env | grep MYSQL_ROOT_PASSWORD | awk -F= '{ print $2 }'`

  # If ADMINPASS doesn't exist in /etc/federated then use nextcloud to get it.  Otherwise get it from /etc/federated
  # [[ ! $(grep ADMINPASS /etc/federated | awk -F\" '{ print $2 }') ]] && ADMINPASS=$(cat /federated/apps/nextcloud/.nextcloud.secret) || ADMINPASS=$(grep ADMINPASS /etc/federated | awk -F\" '{ print $2 }')

  # If ADMINPASS doesn't exist in /etc/federated then use nextcloud to get it. If Nextcloud secret isn't there then use panel.
  # If ADMINPASS exists in /etc/federated then get it from /etc/federated
  if [[ ! $(grep ADMINPASS /etc/federated | awk -F\" '{ print $2 }') ]]; then
    if [[ -f "/federated/apps/nextcloud/.nextcloud.secret" ]]; then
      ADMINPASS=$(cat /federated/apps/nextcloud/.nextcloud.secret)
    else
      ADMINPASS=$(grep SMTP_PASSWORD /federated/apps/panel/.env | awk -F= '{ print $2 }')
    fi
  else
    ADMINPASS=$(grep ADMINPASS /etc/federated | awk -F\" '{ print $2 }')
  fi

  # If COTURN_MATRIX_SECRET exists in turnserver.conf then use it, otherwise create the password
  [[ $(grep static-auth-secret /federated/apps/coturn/data/etc/turnserver.conf 2>/dev/null | awk -F= '{ print $2 }') ]] && COTURN_MATRIX_SECRET=$(grep static-auth-secret /federated/apps/coturn/data/etc/turnserver.conf 2>/dev/null | awk -F= '{ print $2 }') || COTURN_MATRIX_SECRET=$(create_password);

  # If LISTMONKPASS doesn't exist in /etc/federated then create it.  Otherwise get it from /etc/federated
  [[ ! $(grep LISTMONKPASS /etc/federated | awk -F\" '{ print $2 }') ]] && LISTMONKPASS=$(create_password) || LISTMONKPASS=$(grep LISTMONKPASS /etc/federated | awk -F\" '{ print $2 }')

  # If gitea token file exists then set it as the variable.  Otherwise create it.  Used for caddy / gitea webhook
  [[ -f "/federated/apps/gitea/.gitea.token.1" ]] && GITEA_TOKEN_1=$(cat /federated/apps/gitea/.gitea.token.1) || GITEA_TOKEN_1=$(create_password)

  # If webhook file exists then set it as the variable.  Otherwise create it.  Used for caddy / gitea webhook
  if [[ -f "/federated/apps/gitea/.webhook.secret" ]]; then
    WEBHOOK_SECRET=$(cat /federated/apps/gitea/.webhook.secret)
  else
    WEBHOOK_SECRET=$(create_password)
    if [[ -d "/federated/apps/gitea" ]]; then
      echo "$WEBHOOK_SECRET" > /federated/apps/gitea/.webhook.secret
    fi
  fi

  # Get LDAP DOMAIN from ldap its self and setup variables for each part
  [[ -d "/federated/apps/ldap" ]] && LDAP_DOMAIN=$(docker exec ldap slapcat | grep "dn:" | head -1 | awk -F: '{ print $2 }')

  # Setup LDAP_DOMAIN variable for domain or subdomain
  LDAP_DOMAIN_ARRAY=(${LDAP_DOMAIN//,/ })
  if [ "${#LDAP_DOMAIN_ARRAY[@]}" -eq "2" ]; then
    LDAP_DOMAIN_FIRST=$(echo "${LDAP_DOMAIN_ARRAY[0]}" | awk -F= '{ print $2 }')
    LDAP_DOMAIN_LAST=$(echo "${LDAP_DOMAIN_ARRAY[1]}" | awk -F= '{ print $2 }')
  elif [ "${#LDAP_DOMAIN_ARRAY[@]}" -eq "3" ]; then
    LDAP_DOMAIN_FIRST=$(echo "${LDAP_DOMAIN_ARRAY[0]}" | awk -F= '{ print $2 }')
    LDAP_DOMAIN_MIDDLE=$(echo "${LDAP_DOMAIN_ARRAY[1]}" | awk -F= '{ print $2 }')
    LDAP_DOMAIN_LAST=$(echo "${LDAP_DOMAIN_ARRAY[2]}" | awk -F= '{ print $2 }')
  fi

  # Set SMTP user based on if fcore or admin exists
  if [[ -d "/federated/apps/ldap" ]]; then
    if [[ $(docker exec ldap slapcat | grep fcore) ]]; then
      SMTPUSER="fcore"
    elif [[ $(docker exec ldap slapcat | grep admin) ]]; then
      SMTPUSER="admin"
    else
      SMTPUSER="fcore"
    fi
  fi
}
get_appvars_old() {
  LDAP_SECRET=`cat /federated/apps/ldap/.ldap.secret`
  EXTERNALIP=$(get_externalip);
  MYSQL_ROOTPASSWORD=`cat /federated/apps/pdnsmysql/.env | grep MYSQL_ROOT_PASSWORD | awk -F= '{ print $2 }'`

  # If ADMINPASS doesn't exist in /etc/federated then use nextcloud to get it.  Otherwise get it from /etc/federated
  [[ ! $(grep ADMINPASS /etc/federated | awk -F\" '{ print $2 }') ]] && ADMINPASS=$(cat /federated/apps/nextcloud/.nextcloud.secret) || ADMINPASS=$(grep ADMINPASS /etc/federated | awk -F\" '{ print $2 }')

  # If COTURN_MATRIX_SECRET exists in turnserver.conf then use it, otherwise create the password
  [[ $(grep static-auth-secret /federated/apps/coturn/data/etc/turnserver.conf 2>/dev/null | awk -F= '{ print $2 }') ]] && COTURN_MATRIX_SECRET=$(grep static-auth-secret /federated/apps/coturn/data/etc/turnserver.conf 2>/dev/null | awk -F= '{ print $2 }') || COTURN_MATRIX_SECRET=$(create_password);

  # Set SMTP user based on if fcore exists
  [[ $(docker exec ldap slapcat | grep fcore) ]] && SMTPUSER="fcore" || SMTPUSER="admin"
}
get_ldapdomain() {
  # Get LDAP DOMAIN from ldap its self and setup variables for each part
  LDAP_DOMAIN=$(docker exec ldap slapcat | grep "dn:" | head -1 | awk -F: '{ print $2 }')

  # Setup LDAP_DOMAIN variable for domain or subdomain
  LDAP_DOMAIN_ARRAY=(${LDAP_DOMAIN//,/ })
  if [ "${#LDAP_DOMAIN_ARRAY[@]}" -eq "2" ]; then
    LDAP_DOMAIN_FIRST=$(echo "${LDAP_DOMAIN_ARRAY[0]}" | awk -F= '{ print $2 }')
    LDAP_DOMAIN_LAST=$(echo "${LDAP_DOMAIN_ARRAY[1]}" | awk -F= '{ print $2 }')
  elif [ "${#LDAP_DOMAIN_ARRAY[@]}" -eq "3" ]; then
    LDAP_DOMAIN_FIRST=$(echo "${LDAP_DOMAIN_ARRAY[0]}" | awk -F= '{ print $2 }')
    LDAP_DOMAIN_MIDDLE=$(echo "${LDAP_DOMAIN_ARRAY[1]}" | awk -F= '{ print $2 }')
    LDAP_DOMAIN_LAST=$(echo "${LDAP_DOMAIN_ARRAY[2]}" | awk -F= '{ print $2 }')
  fi
}
create_email_withoutvpn() {
cat > /federated/apps/mail/data/root/certs/mailfile <<EOF
<html>
<img src="https://www.federated.computer/images/logo.png" alt="" /><br>
Dear Federated Customer,
<p>
Please read this note in its entirety since it has some important information for you to get the best use
out of your Federated Core. If you ever get stuck for whatever reason, please reach out to us for support:
<p>
Website: https://support.federated.computer<br>
Phone: 970-722-8715<br>
Email: support@federated.computer<br>
<p>
We are here to help you, the Customer, get the most out of your Federated Core.
<p>
All documentation for your Federated Core can be found at https://documentation.federated.computer.
There you'll find tips for how to use your Core and the various open source applications bundled with
your Core.
<p>
<h4>Domain Information</h4>
This is your domain: <b>$DOMAIN</b>
<p>
If you just signed up for Federated Core, your domain is a temporary domain (example: starts with F...). Please do not change the admin password (see below) until you switch to your own domain name (example: mustache.com). We use the admin account and password for your temporary domain to re-configure all the software for your new/permanent domain. If you have a question about this, send us an email to support@federated.computer.
<p>
When you are ready to switch over to your own yourdomain.com send us an e-mail at support@federated.computer and let us know you are done migrating your data, have pointed DNS correctly, and ready for us to switch. We also need to know the yourdomain.com you will be using.
<p>
For setting DNS records you will need to set your glue records for your own yourdomain.com to be:
<p>
ns1.yourdomain.com - $EXTERNALIP<br>
ns2.yourdomain.com - $EXTERNALIP<br>
<p>
And your authoritative:
<p>
ns1.yourdomain.com<br>
ns2.yourdomain.com<br>
<p>
If you have questions about DNS records, please check <a href="https://www.federated.computer/support">https://www.federated.computer/support</a> for videos on pointing your DNS correctly.
For further help please send us an email at support@federated.computer so that we can assist you.
<p>
<h4>Admin User</h4>
<p>
There is an "admin" or administrative use that has access to everything on your Federated Core.
Here are the credentials for that user.
<p>
Username = "admin@$DOMAIN"<br>
Password = "$ADMINPASS"
<p>
<h4>Dashboard</h4>
Visit <a href="https://dashboard.$DOMAIN">https://dashboard.$DOMAIN</a> to access all of your applications using the admin user and password above.
You can use dashboard as a launching pad for your applications.
<br>
<h4>Thanks for your support!</h4>
<p>
Thank you for your support of Federated Computer. We really appreciate it and hope you have a very successful
time with Federated Core.
<p>
Again, if we can be of any assistance, please don't hesitate to get in touch.
<p>
Support: https://support.federated.computer<br>
Phone: (970) 722-8715<br>
Email: support@federated.computer<br>
<p>
It's <b>your</b> computer. Let's make it work for you!
</html>
EOF

# Send out e-mail from mail container with details
#docker exec mail bash -c "mail -r admin@$DOMAIN -a \"Content-type: text/html\" -s \"Welcome to Federated\" admin@$DOMAIN < /root/certs/mailfile"
#docker exec mail bash -c "mail -r admin@$DOMAIN -a \"Content-type: text/html\" -s \"Welcome to Federated\" $EMAIL < /root/certs/mailfile"
#cat /federated/apps/mail/data/root/certs/mailfile
#rm /federated/apps/mail/data/root/certs/mailfile
}
create_email_withvpn() {
cat > /federated/apps/mail/data/root/certs/mailfile <<EOF
<html>
<img src="https://www.federated.computer/images/logo.png" alt="" /><br>
Dear Federated Customer,
<p>
Please read this note in its entirety since it has some important information for you to get the best use
out of your Federated Core. If you ever get stuck for whatever reason, please reach out to us for support:
<p>
Website: https://support.federated.computer<br>
Phone: 970-722-8715<br>
Email: support@federated.computer<br>
<p>
We are here to help you, the Customer, get the most out of your Federated Core.
<p>
All documentation for your Federated Core can be found at https://documentation.federated.computer.
There you'll find tips for how to use your Core and the various open source applications bundled with
your Core.
<p>
<h4>Domain Information</h4>
This is your domain: <b>$DOMAIN</b>
<p>
If you just signed up for Federated Core, your domain is a temporary domain (example: starts with F...). Please do not change the admin password (see below) until you switch to your own domain name (example: mustache.com). We use the admin account and password for your temporary domain to re-configure all the software for your new/permanent domain. If you have a question about this, send us an email to support@federated.computer.
<p>
When you are ready to switch over to your own yourdomain.com send us an e-mail at support@federated.computer and let us know you are done migrating your data, have pointed DNS correctly, and ready for us to switch. We also need to know the yourdomain.com you will be using.
<p>
For setting DNS records you will need to set your glue records for your own yourdomain.com to be:
<p>
ns1.yourdomain.com - $EXTERNALIP<br>
ns2.yourdomain.com - $EXTERNALIP<br>
<p>
And your authoritative:
<p>
ns1.yourdomain.com<br>
ns2.yourdomain.com<br>
<p>
If you have questions about DNS records, please check <a href="https://www.federated.computer/support">https://www.federated.computer/support</a> for videos on pointing your DNS correctly.
For further help please send us an email at support@federated.computer so that we can assist you.
<p>
<h4>Admin User</h4>
<p>
There is an "admin" or administrative use that has access to everything on your Federated Core.
Here are the credentials for that user.
<p>
Username = "admin@$DOMAIN"<br>
Password = "$ADMINPASS"
<p>
IMPORTANT: When logging into Nextcloud using normal login (NOT Login with Authelia), you need to use the system username from panel, not user@domain.com. This includes the admin user.
<p>
<h4>Dashboard</h4>
Visit <a href="https://dashboard.$DOMAIN">https://dashboard.$DOMAIN</a> to access all of your applications using the admin user and password above.
You can use dashboard as a launching pad for your applications.
<br>
<h4>VPN</h4>
<p>
Your core comes with a very powerful VPN solution built using Wireguard. The following information is
needed by your users so that they can use the VPN. Please treat this information as a very important
secret. There are two important parts of the VPN:
<p>
Here is your VPN configuration:<br>
<code>

EOF
sed "s/$/<br>/" /federated/apps/wireguard/data/config/peer1/peer1.conf >> /federated/apps/mail/data/root/certs/mailfile

cat >> /federated/apps/mail/data/root/certs/mailfile <<EOF

</code>
<h4>Thanks for your support!</h4>
<p>
Thank you for your support of Federated Computer. We really appreciate it and hope you have a very successful
time with Federated Core.
<p>
Again, if we can be of any assistance, please don't hesitate to get in touch.
<p>
Support: https://support.federated.computer<br>
Phone: (970) 722-8715<br>
Email: support@federated.computer<br>
<p>
It's <b>your</b> computer. Let's make it work for you!
</html>
EOF

# Send out e-mail from mail container with details
#docker exec mail bash -c "mail -r admin@$DOMAIN -a \"Content-type: text/html\" -s \"Welcome to Federated\" admin@$DOMAIN < /root/certs/mailfile"
#docker exec mail bash -c "mail -r admin@$DOMAIN -a \"Content-type: text/html\" -s \"Welcome to Federated\" $EMAIL < /root/certs/mailfile"
#cat /federated/apps/mail/data/root/certs/mailfile
#rm /federated/apps/mail/data/root/certs/mailfile
}
create_email_migrated() {
cat > /federated/apps/mail/data/root/certs/mailfile <<EOF
<html>
<img src="https://www.federated.computer/images/logo.png" alt="" /><br>
<p>
<h4>You are now migrated to $DOMAIN</h4>
<p>
Credentials will be the same as the admin user in the original welcome e-mail.<br>
<p>
<h4>Dashboard</h4>
Visit <a href="https://dashboard.$DOMAIN">https://dashboard.$DOMAIN</a> to access all of your applications using the admin user and password.
You can use dashboard as a launching pad for your applications.
<br>
<p>
<h4>Thanks for your support!</h4>
<p>
Thank you for your support of Federated Computer. We really appreciate it and hope you have a very successful
time with Federated Core.
<p>
Again, if we can be of any assistance, please don't hesitate to get in touch.
<p>
Support: https://support.federated.computer<br>
Phone: (970) 722-8715<br>
Email: support@federated.computer<br>
<p>
It's <b>your</b> computer. Let's make it work for you!
</html>
EOF
}
config_network() {
  echo -ne "\n* Configuring core network.."
  spin &
  SPINPID=$!

  if [ ! `docker network ls -q --filter name=core` ]; then
    docker network create --subnet 192.168.0.0/16 core &> /dev/null
    [ $? -ne 0 ] && fail "Couldn't run docker network create"
  fi

  echo -ne "done."
  kill -9 $SPINPID &> /dev/null
}
run_finishtasks() {
  if [[ "${PLUS}" != "true" ]]; then
    docker exec -u 33 nextcloud php -f /var/www/html/cron.php
    docker exec -u 33 nextcloud truncate /var/www/html/data/nextcloud.log --size 0
    docker exec -u 33 nextcloud php -f /var/www/html/cron.php
    docker exec -u 33 nextcloud truncate /var/www/html/data/nextcloud.log --size 0
  fi
  docker system prune -a -f
}
add_authelia_config_to_dockercompose() {
  if [[ ! $(grep authelia /federated/apps/$1/docker-compose.yml) ]]; then
    if [[ $(grep extra_hosts /federated/apps/$1/docker-compose.yml) ]]; then
      sed -i "/extra_hosts/a  \      - \"authelia.$DOMAIN:$2\"" /federated/apps/$1/docker-compose.yml
    else
      sed -i "/restart: always/a  \    extra_hosts:\n\      - \"authelia.$DOMAIN:$2\"" /federated/apps/$1/docker-compose.yml
    fi
  fi
}