This is a how-to geared especially toward our add-on developers, but it'll be useful to anyone who wants to create a cycling concrete5 demo that automatically resets. In this how-to I'll explain how to prepare a database for the demo, setup special demo-specific permissions overrides, create a demo administrative user, install one or more add-ons along with the demo, and provide a script that can be run at any time to reset the demo.
Note: This how-to requires concrete5 184.108.40.206 and earlier. If you're running a newer version of concrete5, check out this how-to and code.
This how-to references a reset script and permissions overrides. You can download these files here:
Reset Script and Permissions Overrides
It's important that you setup your demo install with its own database, database user, and database access. That way, if anything is ever disclosed or compromised, there is at least that sandbox in place. My demo will use the "concretedemo" user account, with the password "concretedemo," in the "concretedemo" database.
First I create the database:
CREATE DATABASE concretedemo;
Then I grant permissions to the user on the database:
GRANT ALL ON concretedemo.* TO concretedemo@localhost IDENTIFIED BY 'concretedemo';
Download the latest version of concrete5, unzip it to the web directory that will house your demo, and install it.
We want our demo user to be added to the Administrators group, so they can access the dashboard, but we don't want to give out full and complete access. We don't want sitewide settings to be looked at, or file access permissions to change, for example. Fortunately there's a little-used feature that allows us to lock down single page permissions at the time of their creation: access.xml files. These files live in the specific controllers/ directory for the given single page.
A sample access.xml file looks like this:
<guests canRead="0" ></guests>
<registered canRead="0" ></registered>
<administrators canRead="0" canWrite="0" canAdmin="0" ></administrators>
This locks the admnistrators group out of accessing the /dashboard/files/access page.
In the .zip file above, you'll see a controllers/ directory. Copy the contents of this controllers/ directory into your root controllers/ directory. The next time your demo site is reset, these access restrictions will be in place.
Install "Reset" Script
Also contained within the .zip file above is a reset script. When run, this script does the following:
- Removes config/site.php
- Removes all files in the files/ directory
- Removes all tables in the demo database
- Reinstalls concrete5 with the values specified in the reset script, and the database information that you originally installed concrete5 with. Permission overrides described in "Lockdown Dashboard" are applied
- Creates a second administrative user in the Administrators group
- Locks down file permissions
- Disables site emails
- Installs specified add-ons into the site.
Before you install
Please, rename the reset script! Anyone who hits the URL of the reset script will be able to reset your demo.
There are a number of values at the beginning of the script that deserve explanation.
- DEMO_SETUP_SITE: This constant will determine the name of your site.
- DEMO_DB_SERVER: Your demo's MySQL server. Typically "localhost".
- DEMO_DB_USER: The username for your demo's MySQL user. e.g. "concretedemo".
- DEMO_DB_PASSWORD: The password for your demo's MySQL user. e.g. "concretedemo".
- DEMO_DB_DATABASE: Your demo's MySQL database. e.g. "concretedemo".
- DEMO_ADMIN_EMAIL: An email address for the admin account that will be created when your site is reset.
- DEMO_ADMIN_PASSWORD: The password for your "admin" user account.
- DEMO_USER_USERNAME: The username for your "demo" account. This is the account you will give out to users who wish to demo your software.
- DEMO_USER_PASSWORD: The password for the "demo" user.
- PASSWORD_SALT, MANUAL_PASSWORD_SALT: A long string that needs to be in place in this script.
- PACKAGES_TO_INSTALL: A comma-separated list of package handles of all add-ons in the local packages/ directory you wish to install every time the demo site is reset.
Scheduling this Script
It is easy to cron this script so that it will clean out data every hour. Something like this can be entered into a crontab on a Linux server. For example, if your reset script is
You can can make it run every hour on the hour with
0 * * * * /usr/bin/wget -T 0 -q http://www.yoursite.com/reset_128273282.php
in your crontab file.
That's it! Now you should have a fully functional concrete5 demo with a full admin account, a limited admin account, and any add-ons preinstalled that you wish to demonstrate.