#!/bin/sh

# ClonePanel - Manages duplicate accounts on two or more webservers,
# including snapshot backups, monitoring and failover dns.
# Copyright (C)2006 Chris Cheers, Internet Lynx.
# Contact chris[at]clonepanel[dot]com.
# Internet Lynx, PO Box 7117, Mannering Park, NSW 2259, Australia

# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.

# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.

# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

# config - important system and user filenames, general configuration values
VERSION=0.33

COPYLEFT="\n
ClonePanel version $VERSION, Copyright (C)2006 Chris Cheers\n
ClonePanel comes with ABSOLUTELY NO WARRANTY.\n
This is free software, and you are welcome to redistribute\n
it under certain conditions; read LICENSE.txt for details.\n
"

# Leave the values here blank - will be defined in system/config on install
MY_NAME=''
REMOTEHOST_SYNC_DIRNAME=''
# Directory to be used on the remote server for all system files
# (defaults to cp$version)
DATABASE_STORENAME=''
# Name of subdirectory (under $REMOTEHOST_HOME) on remote server where sql
# dumps will be stored (defaults to clonepanel_db)
DB_HOST_OVERRIDE=''
# Allows a different host name to be used for mysql connections on certain servers.
ERROR_REPORT_EMAIL=''
STATUS_CHANGE_EMAIL=''
# Email address for error reports and status changes
# DON'T CHANGE THESE HERE! Edit system/config

# End of blanks to be defined in system/config on install

# Start main file config section - files / locations / setup can be
# modified by changing values below (at user's own risk!)

SSH_PORT=22
# default 22 - normally leave it unchanged here but override for hosts that
# use a non-standard port (hosts/HOSTNAME/config)
ACCOUNTS_DIRNAME=accounts
TEMP_DIRNAME=temp
TEMP_MONITOR_FILENAME=monitor.out
TEMP_SYNC_RES_FILENAME=sync.out
SYSAUTH_DIRNAME=auth
REMOTE_SKELNAME=skel

AUTH_DIRNAME=auth
# Name of subdir in userdir that stores authorization info

HOSTS_CONFIG_FILENAME=config
HOSTS_DIRNAME=hosts
STATUS_FILENAME=status
UPDATES_FILENAME=updates
# ACCOUNTS_FILENAME=accounts

MONITOR_DIRNAME=monitor
REMOTE_SETUP_DIRNAME=remote
REMOTE_PROGRAM_DIRNAME=scripts

# Note naming convention here:
# LOCAL and REMOTE prefixes refer to directories on backup machine
# containing info and templates
# REMOTEHOST prefix refers to setting on the remote host machine

REMOTEHOST_HOME_TP=/home/_USERNAME_
# Default template for constructing home directory on remote host
# (override in host config)
REMOTEHOST_MAIL_DIRNAME=mail
REMOTEHOST_CLONE_MAIL_DIRNAME=mailclone
REMOTE_CGI_DIRNAME=cgi

UPLOAD_PERL_MAIL_MODULES=''
# Use 'all' to upload perl mail handling modules Mail::Box - for use
# on shared systems where these cannot be installed system-wide
# (override by using host name in host config)
PERL_MODULES_DIR=perl_modules
# Where to find necessary modules in REMOTE_SETUP_DIR

SYNC_R=sync_r
SYNC_R_TEMPLATE=sync_r.template
# Names of working file and template for script to be run by key-authorized shell access

SYNC_R_SUBS='REMOTEHOST_PATH_RSYNC REMOTEHOST_PROGRAM_DIR REMOTEHOST_SYNC_DIR'
# Names of variables to be substituted into sync_r program

SYNC_CGI_SUBS='REMOTEHOST_SYNC_DIR'
# Names of variables to be substituted into cgi scripts

REMOTEHOST_PATH_RSYNC=/usr/bin
# Default path to rsync binary on remote server
# (can be overridden by host-specific setup)

REMOTE_CONFIG_FILES='colours error_codes rconfig'
# Config files to include complete

REMOTE_COMMAND_VARS='CAT ECHO GREP CUT LS MKDIR MYSQLDUMP MYSQL RM EXPR TAIL DATE'
# Commands to be made available to remote scripts

REMOTE_CONFIG_VARS='REMOTEHOST_ROLES_FILE REMOTEHOST_DATABASE_DIR REMOTEHOST_DATABASE_STORE MAIL_MOVE_SCRIPT REMOTEHOST_MAIL_DIR REMOTEHOST_CLONE_MAIL_DIR DB_HOST_OVERRIDE REMOTE_ERROR_LOG'
# Variables to be made available to remote scripts

REMOTE_MONITOR_VARS='FIND SED REMOTEHOST_HOSTS_DIR HOSTS_CONFIG_FILENAME MONITOR_TIMEOUT MONITOR_USER_AGENT'
# Extra variables / commands for monitoring accounts

RSYNC_BWLIMIT=180
# Option to rsync --bwlimit (limit bandwidth to x KBPS).
# Default 180 kbytes/second is approx 1.5Mbit DSL

LOCAL_DIRNAME=local
# Name of directory of files destined for user's local account
LOCAL_SKELNAME=user
# Name of skeleton directory of files to be used in user's local account
ZONE_TEMPLATE_DIRNAME=zone
# Directory containing skeleton zone files

ROLES_FILENAME=roles
# File assigning role to each server for a user / zone
# ZONES_FILENAME=zones
# File containing list of domains / zones hosted ($USER_DIR)
ZONES_DIRNAME=zones
# Directory name containing list of domains / zones hosted ($USER_DIR)
ZONE_FILENAME=zone.db
# Filename of zone file (goes in directory $USER_DIR/$ZONES_DIRNAME/domain/)
OVERRIDE_FILENAME=override.db
# (obselete) Filename of list of dns overrides (directory $USER_DIR/domain/)

CRONTAB_TEMP_FILENAME=cron.tmp
# Temporary file to hold crontab data
CRONTAB_DEFAULT_NOTIFY=all
# Notification default on cron jobs (all error or none)
CRONJOB_DIRNAME=cron_jobs
# Name of directory in userdir where cron-job info held

STATUS_TMP_FILENAME=status.tmp
DNS_UPDATE_PROGRAM=set_dns
# program to run directly or via cron to do the updates (and keep trying until it works!
DNS_UPDATE_FREQUENCY=5
# frequency (minutes) at which to run it
DNS_MODIFY_PROGRAM=mod_dns.pl
# program to modify zone files (failover / back)

PENDING_TASKS_DIRNAME=pending_tasks
# Directory holding pending tasks (typically zone updates on down servers)

MONITOR_FREQUENCY=5
# Run frequency (minutes) for monitor program
MONITOR_MINUTE_OFFSET=2
# For cron jobs, offset by x minutes to avoid running everything at 0,5,10 etc.
MONITOR_TIMEOUT=30
# Seconds before timeout on wget
MONITOR_TIMEOUT_BY_PROXY=45
# Allow a little longer when monitoring via a proxy
MONITOR_RETRY_DELAY=30
# Seconds before retry on wget
MONITOR_USER_AGENT="Mozilla/5.0 ClonePanel"
# Some servers get snotty about the LWP user agent id - if necessary use
# the exact user-agent string from the browser of your choice

SNAPSHOT_DIRNAME=snapshot
NO_SNAPSHOTS=3
# number of hourly / short-term snapshots to keep
DAILY_SNAPSHOTS=7
WEEKLY_SNAPSHOTS=4
MONTHLY_SNAPSHOTS=6
# Although 7 days / week, 4 weeks / month is convenient these can be
# changed as required to suit circumstances / storage available
ROLLMONTHDAY='01';
# trigger monthly roll on 1st of each month (NB - string!)
ROLLWEEKDAY=Sat
# trigger weekly roll every Saturday
# No value for daily roll - happens every time rollover runs

DATABASE_DIRNAME=databases
# Name of subdirectory within accounts/username to use for database info

MAIL_DIRNAME=mail
# Where on remote server (under $REMOTE_HOME) to find mailboxes for backup
MAIL_CLONE_DIRNAME=mail_clone
# Where to sync the mail brought in from other server(s)...
MAIL_MOVE_SCRIPT=moveallmail.pl
# and perl script to move mailboxes from one directory tree to another

# Which directories (within user's home dir) will be mirrored
# Note - depends on transfer type (WEB or MAIL, others tba)
# May also be overridden in special config file for non-CPanel
# hosts that may use different paths to web root
# SS refers to subdir in snapshot - this will not be overridden

MIRROR_DIR_WEB=public_html
MIRROR_SS_WEB=public_html
EXCLUDESFILE_WEB=web_exclude
NOBACKUPFILE_WEB=web_nobackup

MIRROR_DIR_MAIL=$MAIL_CLONE_DIRNAME
MIRROR_SS_MAIL=$MAIL_CLONE_DIRNAME
EXCLUDESFILE_MAIL=mail_exclude
NOBACKUPFILE_MAIL=mail_nobackup

# NB - excludes will be backed up but not restored to slave, eg. Use for
# config files that must be different on the 2 hosts. Excluded files on 
# slave will not be backed up by the regular sync process but may be backed
# up manually using the backup script.
# Files / directories listed in the *_nobackup files WILL NOT BE BACKED UP
# (duh!), eg. use for large temporary files

# Error actions:
REMOTE_ERROR_LOG=cp_error_log
REPORT_ERRORS_BY_EMAIL=y
ERROR_LOG_DIRNAME=errors
ERROR_MANAGER_SCRIPT=error_manager
# Name of script that will count logged errors and take further action
ERROR_MANAGER_UPDATE_FREQ=5
# Frequency (minutes) at which to run error manager script
ERROR_ACTION_SCRIPT=log_error
# Name of script that will log errors
ERROR_ACTION_THRESHOLD=400
# Based on log-scale score from 1 to 1000 - below threshold do nothing.
ERROR_EMAIL_THRESHOLD=400
WRITE_ON_ERROR=y
WRITE_ON_STATUS_CHANGE=y
# Terminal alerts to current user if online
WRITE_STOPS_EMAIL_ON_ERROR=y
WRITE_STOPS_EMAIL_ON_STATUS_CHANGE=y
# Suppress e-mail messages if online (leave blank for no)
ERROR_IGNORE_FILENAME=ignore_errors
ERROR_LOG_MINUTES=300
# Age (by modification time) of files to include in error count
# Status codes (blank code indicates no further levels)
STATUS_CODES="GREEN AMBER CYAN RED"
# All status codes
STATUS_CODES_ALIVE="GREEN CYAN"
# Status codes indicating server alive (ready for dns update)
STAT_DEFAULT=GREEN
STAT_GREEN_UP=AMBER
STAT_GREEN_DOWN=''
STAT_AMBER_UP=RED
STAT_AMBER_DOWN=GREEN
STAT_RED_UP=''
STAT_RED_DOWN=CYAN
STAT_CYAN_UP=RED
STAT_CYAN_DOWN=GREEN
# Error counts to trigger change of status - note overlap to minimise changes
STATCOUNT_GREEN_UP=7
STATCOUNT_AMBER_UP=11
STATCOUNT_CYAN_UP=11
STATCOUNT_RED_DOWN=7
STATCOUNT_AMBER_DOWN=3
STATCOUNT_CYAN_DOWN=0
# Times (minutes) to include in error count for specific status changes
# (use ERROR_LOG_MINUTES where appropriate, no value should be greater)
STATTIME_GREEN_UP=$ERROR_LOG_MINUTES
STATTIME_AMBER_UP=60
STATTIME_RED_DOWN=60
STATTIME_CYAN_UP=60
STATTIME_CYAN_DOWN=$ERROR_LOG_MINUTES
STATTIME_AMBER_DOWN=$ERROR_LOG_MINUTES

FAILOVER_AUTO='n'
# Global option - override with 'y' to enable automatic dns failover on any domain
FAILOVER_ENABLE='n'
# For each user / zone: override with 'y' to enable automatic dns failover

FAILOVER_ACTIONS="PREPARE FAILOVER RESTORE"
# Default actions for each status code

FAILOVER_ACTION_AMBER=PREPARE
# Default setting PREPARE shortens TTL but doesn't failover - better for 
# dynamic sites where failover means limited functionality
# For static sites you may want to override with FAILOVER_ACTION_AMBER=FAILOVER
# which moves sites to slave asap.

FAILOVER_ACTION_RED=FAILOVER
# No good reason for anything else here - if you don't want failover don't enable it

FAILOVER_ACTION_CYAN=PREPARE
# Default setting PREPARE changes dns back as soon as reasonably practical - good
# for dynamic sites that may be limited when running on slave server.
# For static sites you may want to override with FAILOVER_ACTION_CYAN=FAILOVER
# which keeps sites on slave until errors on master are long gone

FAILOVER_ACTION_GREEN=RESTORE
# No good reason for anything else here either

FAILOVER_TRUSTED_STATUS="GREEN_CYAN"
# Intended to disable failover if monitor is in trouble - change to GREEN
# to reduce risk of mistaken failover (but also increase risk that failover
# won't be available when you need it)

QUIET_MODE='n'
# Quiet mode does not show copyleft info at start of program runs
# (normally for non-interactive jobs)
