Cerb5

by jstanden
15 deployments · 3 still active · last rev. 4 years ago

Cerb5 is a fast and flexible toolkit built for web-based collaboration and workflow automation. Remember anything about anyone, collaborate from anywhere, deftly reply to an email flood, automate, stay informed, capture feedback, track time, flag opportunities, remember tasks, share expert knowledge, and otherwise execute efficiently.
http://www.cerberusweb.com/

This script installs Cerb5 on a Debian/Ubuntu instance. It installs and configures the LAMP stack (Apache2, MySQL5, PHP5), Git, and the Cerb5 requirements (e.g. PHP/Mailparse). MySQL's root password is automatically generated and placed in a shadow file at `~root/.db.shadow`. A cronjob is installed on the 'cerb5' user.

For improved performance, Memcached and XCache are automatically installed and configured.

Compatible with: No distros currently supported
						#!/bin/bash
# Cerb5 Stackscript
# By Jeff Standen <jeff@webgroupmedia.com> of WebGroup Media
#
# Cerb5 is a fast and flexible toolkit built for web-based collaboration 
# and workflow automation. Remember anything about anyone, collaborate 
# from anywhere, deftly reply to an email flood, automate, stay informed, 
# capture feedback, track time, flag opportunities, remember tasks, share 
# expert knowledge, and otherwise execute efficiently.
# http://www.cerberusweb.com/
#
# This script installs Cerb5 on a Debian/Ubuntu instance.  It installs and 
# configures the LAMP stack (Apache2, MySQL5, PHP5), Git, and the Cerb5 
# requirements (e.g. PHP/Mailparse).  MySQL's root password is automatically 
# generated and placed in a shadow file at `~root/.db.shadow`.  A cronjob is 
# installed on the 'cerb5' user. For improved performance, Memcached and 
# XCache are automatically installed and configured.
#
# <UDF name="vhost" Label="Domain" default="" example="e.g. helpdesk.example.com" />
# <UDF name="email" Label="Email" default="superuser@example.com" example="Your email address" />
# <UDF name="cerb5_pass" Label="Cerb5 Password" default="" example="Your password for logging in to Cerb5" />
# <UDF name="cerb5_replyto" Label="Cerb5 Reply-To" default="support@example.com" example="The email address to send mail as" />

exec &> /root/stackscript.log

source <ssinclude StackScriptID="1">

# MySQL root password
echo "$(randomString 16)" > ~root/.db.shadow
chmod 400 ~root/.db.shadow

system_update
postfix_install_loopback_only
mysql_install "`cat ~/.db.shadow`" && mysql_tune 40
php_install_with_apache && php_tune
apache_install && apache_tune 40 && a2enmod rewrite
goodstuff
restartServices

###########################################################
# Security
###########################################################

# SSH
#[TODO]

###########################################################
# Git
###########################################################
aptitude -y install git-core

###########################################################
# Cerb5
###########################################################

# Prerequisites
aptitude -y install php-pear make wget
aptitude -y install php5-gd php5-imap php5-curl php5-xcache
aptitude -y install memcached php5-memcache

## Mailparse
pecl install mailparse
echo "extension=mailparse.so" > /etc/php5/conf.d/mailparse.ini

#pecl install oauth
#echo "extension=oauth.so" > /etc/php5/conf.d/oauth.ini

# Vhost
apache_virtualhost "$VHOST"
VPATH=/srv/www/$VHOST/public_html/
cd $VPATH

# Reload Apache
touch /tmp/restart-apache2

# Create Database
CERB5_DB_NAME="cerb5"
CERB5_DB_USER="cerb5"
CERB5_DB_PASS="$(randomString 16)"

echo "CREATE DATABASE $CERB5_DB_NAME character set utf8;" | mysql -u root -p"`cat ~/.db.shadow`"
mysql_create_user "`cat ~/.db.shadow`" "$CERB5_DB_USER" "$CERB5_DB_PASS"
mysql_grant_user "`cat ~/.db.shadow`" "$CERB5_DB_USER" "$CERB5_DB_NAME"

# Checkout Cerb5 project files
git clone git://github.com/jstanden/cerb5.git
cd cerb5
chown -R www-data:www-data .
cp .htaccess-dist .htaccess

# Configure framework.config.php
cat << EOF > framework.config.php
<?php
define('APP_DB_DRIVER','mysqli');
define('APP_DB_ENGINE','MyISAM');
define('APP_DB_HOST','localhost');
define('APP_DB_DATABASE','$CERB5_DB_NAME');
define('APP_DB_USER','$CERB5_DB_USER');
define('APP_DB_PASS','$CERB5_DB_PASS');
define('APP_DB_PCONNECT',false);

define('LANG_CHARSET_CODE','utf-8'); // iso-8859-1, utf-8
define('DB_CHARSET_CODE','utf8'); // latin1, utf8

// Memcached (high-performance shared memory cache)
// optional, memcached 1.2.x + extension must be enabled
// list multiple servers comma-delimited: host1:port,host2:port
define('DEVBLOCKS_CACHE_PREFIX','$(randomString 6)'); // ONLY A-Z, a-z, 0-9 and underscore
define('DEVBLOCKS_MEMCACHED_SERVERS','127.0.0.1:11211');

//@ini_set('memory_limit', '64M');

/****************************************************************************
 * [JAS]: Don't change the following unless you know what you're doing!
 ***************************************************************************/
define('APP_DEFAULT_CONTROLLER','core.controller.page');
define('APP_DB_PREFIX','cerb');
define('APP_PATH',dirname(__FILE__));
define('APP_STORAGE_PATH',APP_PATH . '/storage');
define('APP_TEMP_PATH',APP_STORAGE_PATH . '/tmp');
define('DEVBLOCKS_PATH',APP_PATH . '/libs/devblocks/');
define('DEVBLOCKS_REWRITE', file_exists(dirname(__FILE__).'/.htaccess'));
define('DEVELOPMENT_MODE', false);
define('AUTHORIZED_IPS_DEFAULTS', '127.0.0.1,$(system_primary_ip)');
define('ONDEMAND_MODE', false);

require_once(DEVBLOCKS_PATH . 'framework.defaults.php');
EOF

# Initialize the database
cat install/extras/automation/c5_clean.schema.sql | mysql -u root -p`cat ~/.db.shadow` $CERB5_DB_NAME
cat install/extras/automation/c5_clean.data.sql | mysql -u root -p`cat ~/.db.shadow` $CERB5_DB_NAME

cat << EOF | mysql -u root -p`cat ~/.db.shadow` $CERB5_DB_NAME
	# Create the default reply-to address
	INSERT INTO address (id,email) VALUES (1,'$CERB5_REPLYTO');
	INSERT INTO address_outgoing (address_id,is_default,reply_personal) VALUES (1,1,'');

	# Set the helpdesk title
	#INSERT INTO devblocks_setting (plugin_id, setting, value) VALUES ('cerberusweb.core','helpdesk_title','');

	# Configure SMTP
	INSERT INTO devblocks_setting (plugin_id, setting, value) VALUES ('cerberusweb.core','smtp_host','localhost');
	INSERT INTO devblocks_setting (plugin_id, setting, value) VALUES ('cerberusweb.core','smtp_port','25');
	INSERT INTO devblocks_setting (plugin_id, setting, value) VALUES ('cerberusweb.core','smtp_enc','None'); #TLS/SSL/None
	## SMTP Authentication
	INSERT INTO devblocks_setting (plugin_id, setting, value) VALUES ('cerberusweb.core','smtp_auth_enabled','0'); #0/1
	#INSERT INTO devblocks_setting (plugin_id, setting, value) VALUES ('cerberusweb.core','smtp_auth_user','');
	#INSERT INTO devblocks_setting (plugin_id, setting, value) VALUES ('cerberusweb.core','smtp_auth_pass','');

	# Configure POP3/IMAP (pop3:110,pop3-ssl:995,imap:143,imap-ssl:993)
	#INSERT INTO pop3_account (id, enabled, nickname, protocol, host, username, password, port) VALUES (1, 1, 'Dropbox', 'pop3', 'mail.example.com', 'user', 'password', 110);

	# Default Role
	INSERT INTO worker_role (id, name, params_json) VALUES (1, 'Default', '{"who":"all","what":"all"}');

	# Default Groups
	INSERT INTO worker_group (id, name, is_default) VALUES (1, 'Dispatch', 1);
	INSERT INTO worker_group (id, name, is_default) VALUES (2, 'Support', 0);
	INSERT INTO worker_group (id, name, is_default) VALUES (3, 'Sales', 0);

	# Default Buckets
	INSERT INTO bucket (id, group_id, name, is_assignable) VALUES (1, 1, 'Spam', 1);
	INSERT INTO bucket (id, group_id, name, is_assignable) VALUES (2, 2, 'Spam', 1);
	INSERT INTO bucket (id, group_id, name, is_assignable) VALUES (3, 3, 'Spam', 1);

	# Add Superuser
	INSERT INTO worker (id, title, email, pass, is_superuser, first_name, last_name) VALUES (1, 'Administrator', '$EMAIL', MD5('$CERB5_PASS'), 1, 'Super', 'User');
	INSERT INTO address (id,email) VALUES(2,'$EMAIL');
	INSERT INTO address_to_worker (address, worker_id, is_confirmed) VALUES ('$EMAIL', 1, 1);
	## Preferences
	INSERT INTO worker_pref (worker_id, setting, value) VALUES (1, 'timezone', 'America/Los_Angeles');
	INSERT INTO worker_pref (worker_id, setting, value) VALUES (1, 'locale', 'en_US');
	## Memberships
	INSERT INTO worker_to_group (worker_id, group_id, is_manager) VALUES (1, 1, 1); # Dispatch manager
	INSERT INTO worker_to_group (worker_id, group_id, is_manager) VALUES (1, 2, 1); # Support manager
	INSERT INTO worker_to_group (worker_id, group_id, is_manager) VALUES (1, 3, 1); # Sales manager

	# Scheduler defaults
	
	REPLACE INTO cerb_property_store (extension_id, property, value) VALUES ('cron.pop3', 'enabled', '1');
	REPLACE INTO cerb_property_store (extension_id, property, value) VALUES ('cron.pop3', 'duration', '5');
	REPLACE INTO cerb_property_store (extension_id, property, value) VALUES ('cron.pop3', 'term', 'm');
	REPLACE INTO cerb_property_store (extension_id, property, value) VALUES ('cron.pop3', 'lastrun', '0');

	REPLACE INTO cerb_property_store (extension_id, property, value) VALUES ('cron.parser', 'enabled', '1');
	REPLACE INTO cerb_property_store (extension_id, property, value) VALUES ('cron.parser', 'duration', '1');
	REPLACE INTO cerb_property_store (extension_id, property, value) VALUES ('cron.parser', 'term', 'm');
	REPLACE INTO cerb_property_store (extension_id, property, value) VALUES ('cron.parser', 'lastrun', '0');

	REPLACE INTO cerb_property_store (extension_id, property, value) VALUES ('cron.maint', 'enabled', '1');
	REPLACE INTO cerb_property_store (extension_id, property, value) VALUES ('cron.maint', 'duration', '24');
	REPLACE INTO cerb_property_store (extension_id, property, value) VALUES ('cron.maint', 'term', 'h');
	REPLACE INTO cerb_property_store (extension_id, property, value) VALUES ('cron.maint', 'lastrun', '0');

	REPLACE INTO cerb_property_store (extension_id, property, value) VALUES ('cron.heartbeat', 'enabled', '1');
	REPLACE INTO cerb_property_store (extension_id, property, value) VALUES ('cron.heartbeat', 'duration', '5');
	REPLACE INTO cerb_property_store (extension_id, property, value) VALUES ('cron.heartbeat', 'term', 'm');
	REPLACE INTO cerb_property_store (extension_id, property, value) VALUES ('cron.heartbeat', 'lastrun', '0');

	REPLACE INTO cerb_property_store (extension_id, property, value) VALUES ('cron.search', 'enabled', '1');
	REPLACE INTO cerb_property_store (extension_id, property, value) VALUES ('cron.search', 'duration', '15');
	REPLACE INTO cerb_property_store (extension_id, property, value) VALUES ('cron.search', 'term', 'm');
	REPLACE INTO cerb_property_store (extension_id, property, value) VALUES ('cron.search', 'lastrun', '0');

	REPLACE INTO cerb_property_store (extension_id, property, value) VALUES ('cron.mail_queue', 'enabled', '1');
	REPLACE INTO cerb_property_store (extension_id, property, value) VALUES ('cron.mail_queue', 'duration', '1');
	REPLACE INTO cerb_property_store (extension_id, property, value) VALUES ('cron.mail_queue', 'term', 'm');
	REPLACE INTO cerb_property_store (extension_id, property, value) VALUES ('cron.mail_queue', 'lastrun', '0');

	REPLACE INTO cerb_property_store (extension_id, property, value) VALUES ('cron.virtual_attendant.scheduled_behavior', 'enabled', '1');
	REPLACE INTO cerb_property_store (extension_id, property, value) VALUES ('cron.virtual_attendant.scheduled_behavior', 'duration', '1');
	REPLACE INTO cerb_property_store (extension_id, property, value) VALUES ('cron.virtual_attendant.scheduled_behavior', 'term', 'm');
	REPLACE INTO cerb_property_store (extension_id, property, value) VALUES ('cron.virtual_attendant.scheduled_behavior', 'lastrun', '0');

	# Default Organization
	INSERT INTO contact_org (id, name, street, city, province, postal, country, phone, website, created) VALUES (1, 'WebGroup Media, LLC.', '451 W. Lambert Rd. #201', 'Brea', 'California', '92821', 'USA', '+1 714-224-2254', 'http://www.cerberusweb.com/', UNIX_TIMESTAMP());
EOF

# Clean up
rm -Rf install

# Welcome email
cat << EOF > storage/mail/new/welcome.msg
From: "WebGroup Media, LLC." <support@webgroupmedia.com>
To: $CERB5_REPLYTO
Date: `date -R`
Subject: Welcome to Cerb5!

Welcome to Cerberus Helpdesk 5.x (Cerb5)!

We automatically set up a few things for you during the installation process.

You'll notice you have three groups:
* Dispatch: All your mail will be delivered to this group by default.
* Support: This is a group for holding tickets related to customer service.
* Sales: This is a group for holding tickets relates to sales.

If these default groups don't meet your needs, feel free to change them by clicking 'Helpdesk Setup' in the top-right and selecting the 'Groups' tab.

We also set up a 'Spam' bucket inside each group to start quarantining junk mail.  Your helpdesk's spam training functionality is adaptive and will become increasingly accurate as you use your helpdesk.

If you have any questions about your new helpdesk, simply reply to this message.  Our response will show up on this page as a new message.

Subscribe to the Cerb5 blog for project news, sneak peeks of development progress, tips & tricks, and more:
http://www.cerb4.com/blog/

Thanks for your interest!
---
The Cerb5 Team
WebGroup Media, LLC.
http://www.cerberusweb.com/
EOF

restartServices

# Crons
useradd -r -s /bin/false cerb5

cat << EOF | crontab -u cerb5 -
*/1 * * * * wget -O - "http://${VHOST}/cerb5/cron" >/dev/null 2>&1
EOF

# Deliver the welcome letter
wget -O - "http://$VHOST/cerb5/cron/cron.parser?ignore_wait=1"

echo "All set!"