Flexile demo setup

Posted by: Liviu

Introduction

The best way to test online software is to use a demo site that has that software installed. Many content management systems like Joomla use the demo sites to present their product for public (see http://demo.joomla.org ). The main issue with the demo sites is that giving unrestricted access to everyone might cause severe damage to the site, and it doesn't have to be someone with bad intentions. For example the site could be compromised if someone is testing a change in the configuration. Having the demo site too restrictive is also not a good solution because by doing that you can't show all your product features to a potential customer.

This article describes how to create a demo site by giving enough access to public so one can fully test the product and also create a procedure that resets the demo to a working state at a specific time (a counter showing the remaining time until the demo will be restored to its original state is really helpful). A working state for the demo site means that we have the site code & database tested successfully and all the features of the site are working properly. 

We are going to setup 3 demo sites for Jentla Flexile template with Joomla 1.6 code at http://flexile.jentla.com/demo1 , http://flexile.jentla.com/demo2 and http://flexile.jentla.com/demo3. What's different from other demo sites is that the code is updated automatically in the demo site with the newest revisions from subversion repository once it passes our tests. For code updates we are using Jenkins ( http://jenkins-ci.org ) - an open-source continuous integration server , and the acceptance tests are done using Selenium (http://seleniumhq.org) – a software testing framework.

Preparation of code using Jenkins

The first job that needs to be configured in Jenkins is the one that gets the nightly build of Joomla and the latest code of Jentla Flexile admin template installed together in the same workspace.

In Jenkins main menu, click on New Job . Add a name for the project(“Flexile1”) and select “Build a free-style software project “:

 

 

In the configuration menu for the new project, it's better to discard old builds and keep only a few of the latest build records. Also we can setup a custom workspace in the “Advanced Project Options “ section so we don't have to work with the really long and complicated path that's provided by default for the project workspace. (We have selected /app/jenkins/flexile1)

The most important part in the job configuration is the 'Source Code Management”. Here we can select the 2 repository URLs, one for the Joomla 1.6 code and one for the Jentla Flexile 1.6 template. We have set the following configuration

 

In the Build Triggers section, we have set the project to be build periodically. The schedule syntax is very similar to the one used by cron in Unix ( http://en.wikipedia.org/wiki/Cron ). To have the project build every 1 hour we've added the following:

In the “Post-build Actions” section of the configuration we can setup various tests (like Selenium/JUnit tests) and also build other projects if the build was successful. We will not get into details for the testing actions right now.

In the second stage, we need to setup the project that copies and prepares the workspace code for the demo site. The new project will be called 'Flexile1_deployment' and it needs to be build after the main project “Flexile1” was built. You can set this up in Job configuration → Build triggers by selecting 'Build after other projects are built'.

To copy the code to a new folder , we have created a shell script (update_flexile1.sh) that needs to be added in the Build section of the job configuration, in the Execute shell paragraph.

 

The shell script just creates a new folder with the .svn subfolders removed.

#!/bin/bash


#Deleting prior temporary folder
rm -rf /app/demos/flexile1_

#copy workspace to a temporary folder
cp -rp /app/jenkins/flexile1 /app/demos/flexile1_


#delete .svn folders from temporary location
cd /app/demos/flexile1_
/bin/delsvn


#Rename temporary folder to working directory
cd /app/demos
rm -rf /app/demos/flexile1
mv flexile1_ flexile1

The final step is to add in the Flexile1 configuration in the “Post-build Actions” the following:

 

At this point, we should have both projects up and running:

 

 

Flexile1 job console output:

 

After finishing the Jenkins configuration, we should have a working code with the latest Joomla 1.6 code and latest Jentla Flexile admin template in /app/htdocs/flexile1. The next step is to configure the initial state of the demo site using that code and secure the Joomla site.

Securing the Joomla demo

The requirements are simple: allow users almost complete administrator access to the joomla site but prevent them from doing bad things. The solution is unfortunately a bit more complicated. True for the much improved user permissions of Joomla 1.6 makes all this a bit easier there still are many things to do. Let’s make a check list of things that need to be done:

  1. limit the user actions as little as possible

  2. prevent the users from gaining access to the files, database or denying access to other users

  3. limit the possible damage if a malicious users bypasses no. 2

How do you prevent users from doing bad things in the Joomla administrator interface? Easy: we deny them the possibility of installing or removing components, modules and plug-ins. First thing we did was to create a user group for the demo users and set special permissions for this group:

You can see in the above picture the settings of the Demo Administrator group for the Extensions Installer. Be sure to visit all Joomla functions that could allow a user to do damage and set appropriate permissions:

  • Installer must be denied completely

  • Modules, plugins can be browsed and configured (allow the users to publish, unpublish and move them around) but don’t allow them to erase them

  • Global configuration denied completely, you don’t want them seeing your DB configuration

  • User manager denied completely, you don’t want users changing passwords, creating new users, etc.

A few issues directly related to Joomla remain that cannot be fixed using the built-in security settings:

  • You don’t want the demo user changing it’s own password. Even if the user manager is denied one can still visit the My Profile page and change his password. There’s no way to deny this from Joomla it’self but a simple rewrite rule in your apache configuration will help you here:

RewriteCond %{REQUEST_URI} ^/demo/administrator/

RewriteCond %{QUERY_STRING} ^option=com_admin&view=profile&layout=edit

RewriteRule ^(.*)$ /demo/administrator/index.php? [L,R=301]

  • As a safety measure create a new superadministrator user in place of admin, name it something different and set a complicated random password. After this remove the original admin user.

Ok, we now have a fairly secure Joomla installation so we will move on to the server configuration.

We will not go into details, be sure to follow the usual rules of configuring a secure LAMP server. There are though a couple of particular issues:

  • Be sure that you use a mysql user that only has access to the demo site database and nothing more

  • Have the Joomla code and folders made read-only to the apache user (only leave write access to the cache and tmp folders) This will prevent the installation of extensions even if the user manages to bypass the build in security.

  • Disable potential dangerous features in php.ini:

allow_url_fopen = 0

allow_url_include = Off

disable_functions = show_source, system, shell_exec, passthru, exec, phpinfo, popen, proc_open

Reset demo site at regular intervals

The source folder from which we reset the code is not accessible from apache. Set it outside the document root. Also be sure not just to overwrite but also remove files not found in the source, otherwise one attacker could leave files on the demo server for later use.

After you reset the files reset the database as well. Set-up a cron job (belonging to another user, not apache) to do the above at regular intervals.

Be sure to keep the Joomla version up to date and check the logs from time to time, set-up other monitoring tools to be sure that you catch any unexpected security breach.

To reset the code and database, we use a simple system, comprised of different scripts:

demo-sync-code.sh that syncs the local copy of the code with the one jenkins builds for us.

# cat demo-sync-code.sh

#!/bin/bash

# syncs with the automated jenkins build

SOURCE='jenkins@ZAC1D07REL:/app/demos/flexile1/' # note the trailing slash!
DESTINATION='/app/demosource/code/'
EXCLUDE='/app/scripts/demo-sync-code-exclude.txt'

# r = recursive; a = archive and will attempt to set weird permissions
rsync -rz --delete --exclude-from=$EXCLUDE $SOURCE $DESTINATION --progress

# Ensure correct permissions will be propagated
find $DESTINATION -type f -exec chmod 644 {} ;
find $DESTINATION -type d -exec chmod 755 {} ;

# Apache only needs read access
chown -R root.apache $DESTINATION
# though it needs to be able to write here
chown -R apache $DESTINATION/tmp
chown -R apache $DESTINATION/logs

Let’s take a look at the exclude file:

# cat demo-sync-code-exclude.txt

configuration.php
installation/

Simple enough we don’t copy over the configuration.php configuration file and the installation folder. Next script used is demo-reset-code.sh that resets the code for one environment using the synced source above and a skel folder (that holds files particular to the environmnet, right now configuration.php)

# cat demo-reset-code.sh

#!/bin/bash

SOURCE='/app/demosource/code/'
SKEL='/app/demosource/skel/'

DESTINATION=( /app/htdocs/flexile.jentla.com/demo1 /app/htdocs/flexile.jentla.com/demo2 /app/htdocs/flexile.jentla.com/demo3 )

if [ $# -ne 1 ]; then
    echo "Please specify the env. number (1..n) or all"
    exit 1
fi
if [[ $1 != 'all' ]]; then
    if [[ $1 -gt ${#DESTINATION[*]} ]] || [[ $1 -lt 1 ]]; then
        echo "Environment number must be between 1 and ${#DESTINATION[*]}"
        exit 1
    fi
fi

case $1 in
    all)

for dst in ${DESTINATION[*]}
do
    echo -e "Overwritting $dst ..."
    rsync -az --delete $SOURCE $dst
    echo -e "Copying files from $SKEL`basename $dst` to $dst/"
    /bin/cp -fr $SKEL`basename $dst`/* $dst/
    echo -e " done!n"
done

        ;;
    *)

    echo -e "Overwritting ${DESTINATION[$1-1]} ..."
    rsync -az --delete $SOURCE ${DESTINATION[$1-1]}
    echo -e "Copying files from $SKEL`basename ${DESTINATION[$1-1]}` to ${DESTINATION[$1-1]}/"
    /bin/cp -fr $SKEL`basename ${DESTINATION[$1-1]}`/* ${DESTINATION[$1-1]}/
    echo -e " done!n"

        ;;
esac

We need a similar script that will reset the database of an environment:

# cat demo-reset-dbs.sh


#!/bin/bash

# Reloads DB's for the flexile demo sites

SOURCEDB='/app/demosource/db/flexdemo.sql'
DESTDB=( flexdemo01db flexdemo02db flexdemo03db )
# order the above array with the db's of demo1 .. demon

MYUSER='****'
MYPASS='******'

if [ $# -ne 1 ]; then
    echo "Please specify the env. number (1..n) or all"
    exit 1
fi
if [[ $1 != 'all' ]]; then
    if [[ $1 -gt ${#DESTDB[*]} ]] || [[ $1 -lt 1 ]]; then
        echo "Environment number must be between 1 and ${#DESTDB[*]}"
        exit 1
    fi
fi

case $1 in
    all)
        for db in ${DESTDB[*]}
        do
            echo -e "Importing $SOURCEDB to $db ..."
            mysql -u $MYUSER -p$MYPASS $db < $SOURCEDB
            echo -e " done!n"
        done
        ;;
    *)
        echo -e "Importing $SOURCEDB to ${DESTDB[$1-1]} ..."
        mysql -u $MYUSER -p$MYPASS ${DESTDB[$1-1]} < $SOURCEDB
        echo -e " done!n"
        ;;
esac


For ease of use we also have a master script running the two above (so we can reset an environment completely)

# cat demo-reset-env.sh


#!/bin/bash

LOGFILE='/var/log/demo-env.log'
UPDATECODE='/app/scripts/demo-sync-code.sh'
ENVPATH='/app/htdocs/flexile.jentla.com'
ENVNO=3

if [ $# -ne 1 ]; then
    echo "Please specify the env. number (1..n) or all"
    exit 1
fi
if [[ $1 != 'all' ]]; then
    if [[ $1 -gt $ENVNO ]] || [[ $1 -lt 1 ]]; then
        echo "Environment number must be between 1 and $ENVNO"
        exit 1
    fi
fi

# Check if the log file exists

if [ ! -f $LOGFILE ]; then
    echo "Creating logfile at $LOGFILE"
    touch $LOGFILE
fi

echo -e "Resetting $1 at `date`" >> $LOGFILE
echo -e "Updating the code from build server" >> $LOGFILE
eval $UPDATECODE

case $1 in
    all)
        /app/scripts/demo-reset-code.sh all >> $LOGFILE
        /app/scripts/demo-reset-dbs.sh all >> $LOGFILE
        ;;
    *)
        /app/scripts/demo-reset-code.sh $1 >> $LOGFILE
        /app/scripts/demo-reset-dbs.sh $1 >> $LOGFILE
        ;;
esac


Why use different scripts when simply one could do the job? Well because for once you might want to manually reset an environment (or only it’s code or database) and we wanted the sync from Jenkins separated so that resetting the environment will continue to work if for some reason the source cannot be synced with the Jenkins server. And last but not least because it’s easier to maintain and add features in the long run.

The demo-reset-env.sh script is called from crontab to reset environments every hour but at different times.

All done! We have now made sure that each environment gets cleaned up using sources inaccessible to outside users once per hour.

Conclusion

Using this tutorial you can quickly and easily make a website demo if you have a Joomla extension that you want to show online. There are minor changes to be completed by you, like changing the repository path of your extension or the paths to the bash scripts. Have fun!

Comments (30)Add Comment
0
...
written by winter hats, February 22, 2012 at 6:04 PM
I am afraid to lose, I fear this time, http://www.amandahats.com/buy/winter-hats/ and I love it but memories. I could not forget the sweat on the pitch with the sway of the brothers, http://www.amandahats.com/buy/warm-winter-hats/ forget accompany me cry close friend,
bertha
...
written by discount oakley sunglasses, February 22, 2012 at 11:07 AM
thank you for your share i think it's useful to the need one i like it
0
...
written by New Era Hats, February 21, 2012 at 7:33 PM
Two years ago, a certain day, I filled with the ruins of a sense. At that time, the uncle told me the story of a New Era Hats. It is said that a cold winter, a wall standing in front of Walker, blocking his way. Climb walls or without success, he chose the former, but has been climbing unsuccessful. Lost in the cold weather keeping warm Snapback Caps, the human ear is very easy to frostbite, and even life-threatening. The last monk decisively NFL Hats thrown on the other side of the wall, and then exhausted body strength jumped over not MLB Hats to retrieve the NHL Hats move. So far I still clearly remember the NBA Hats story. A lot of time is a drastic lack of courage!
0
...
written by saint jerseys, February 21, 2012 at 10:36 AM
Morten Andersen Jersey Patrick Robinson Jersey Pierre Thomas Jersey Reggie Bush Jersey Rickey Jackson Jersey Robert Meachem Jersey Roman Harper Jersey Saints Customized Jersey Scott Fujita Jersey Sedrick Ellis Jersey Tracy Porter Jersey
0
...
written by north face fleece clearanc, January 31, 2012 at 11:47 AM
hammer slightly baking? Christopher Association na they and no immediately pursuit, but have gathered to has the north face of side. just kuangxia although looks like Japanese than the north face were eat of losses large points, but had to said also is> dangerous of. If locations were no first attacks the north face but all at with rose past, withered bad also really can succeeded also maybe. Although rose in the North Face this team does not play a DPS role, but her batteries, the north face and more irresponsibly than?
0
...
written by new gucci 2011, January 18, 2012 at 2:37 AM
This is a good release, thank you for your post.Reproduction handbags are as good as originals and obtainable at lesser prices.Recommend a good website, click here, you can see the http://www.womenhandbags2u.com...-6_54.html and http://www.womenhandbags2u.com...6_22.html.
0
...
written by rolex swiss, January 14, 2012 at 2:36 PM
Pretty good article.I just came across your site and wanted to say that I have really enjoyed reading your blog posts. http://www.hello-rolex.com/swi...-c-67.html
0
...
written by Belstaff Outlet, January 10, 2012 at 6:14 PM
So nice article!
0
...
written by china wholesale, January 10, 2012 at 6:14 PM
Hi, the article is so wonderful, I am interested in it. I will pay attention to your articles.
0
...
written by Los Angeles Dodgers Hats, January 07, 2012 at 12:46 PM
Don’t neglect the factors you as quickly when you owned. Treasure the factors you cannot get. Don't quit the factors that belong for you and retain people lost factors in memory. gss3w43s%6
0
...
written by Snapbacks Hats, January 06, 2012 at 12:35 PM
This is really interesting, You are a very skilled blogger.i like to read http://www.nflsnapbacksale.org/ informative blogs and this blog is also so good and helpful.thanks for taking time to http://www.nflsnapbacksale.org/ discus this topic
0
...
written by Allure wedding dress, January 04, 2012 at 4:52 PM
Anyways, superb site!Prepare for http://www.bestbridalprice.co....-7939.html bridal gown to provide you with the most beneficial memories.Especially designer's http://www.bestbridalprice.co....-8195.html wedding dress, will most likely be a large shock for you, isn't it?
0
...
written by Allure wedding dress, January 04, 2012 at 4:50 PM
Thank you for so severe an great blog. in which else could a single obtain this a single sort of information and facts composed within extraordinarily a single incite entire way? while you will possess a party,If you desire for obtaining a exceptional one, a celebration celebration http://www.bestbridalprice.co.uk/ bridal gown with mini-skirts is perfect for you. This can be a fine idea, one of the most specific http://www.bestbridalprice.co.uk/ bridal gown for the fine time.
0
...
written by Allure wedding dress, January 04, 2012 at 4:48 PM
You completed certain fine points there. I did a search on the subject matter and found a good number of folks will have the same opinion with your blog.a tremendous amount of girls experienced been limited to placing on conventional http://www.manndybridal.com/la-sposa-c-101.html wedding dresses that showed tiny to no skin. However, instances have changed, and girls can now embrace their timeless attractiveness and elegance using a artist http://www.manndybridal.com/ that shows away their stylish skin.
0
...
written by Allure wedding dress, January 04, 2012 at 4:46 PM
The subsequent time I learn a weblog, I hope that it doesnt disappoint me as much as this one. I imply, I know it was my option to read, but I actually thought youd have something attention-grabbing to say. design your http://www.manndybridal.com/ma...359.html,I think this is the most special.When you use this way,First choose a very simple http://www.manndybridal.com/ma...-3472.html bridal gown
0
...
written by Vibrating Dildo , January 04, 2012 at 4:45 PM
The world of sex toys is full of vibrators They are made especially for women. There are also those that are made for a mans enjoyment. Couples are not left out of this mix because they can find a sex toy for their amusement. The many styles of Rabbits and dildos help people to increase their sexual satisfaction. It is all with the intent of bringing fun to peoples lives.
0
...
written by Replica Oakley Sunglasses, January 04, 2012 at 4:45 PM
In a customer's perspective, it's very important to know both the advantages and disadvantages of a product. There is no ideal product and there will always be a down side to it regardless how nice it is. Right now, I will be providing honest reviews concerning Oakley sunglasses. Discover its advantages and disadvantages according to its buyers.
0
...
written by wholesale jewelry, December 27, 2011 at 3:37 PM
The decision of one's http://www.jewelora.com/wholes...-2_36.html is seeing as desired seeing as the selection of your http://www.jewelora.com/wholes...3_27.html.
0
...
written by buy cheap watches online, December 20, 2011 at 5:38 PM
I like this website, and I can benefit a lot from it!
0
...
written by replica rolex gmt-master, December 12, 2011 at 9:17 PM
The very best good quality http://www.misswatches2u.com/r...-5_41.html are generally 100% hand mirror the main design and style in order to meet your muscle size market place, nevertheless in reasonably priced price ranges. In fact, common those with minimal financial constraints tend not to desire his or her hard-earned income can be invested in prime designer watches. Get a http://www.misswatches2u.com/, the idea helps you to save a lot of cash to get other locations.
0
...
written by Cheap Replica Handbags, December 12, 2011 at 6:38 PM
Legendary travel case in http://www.idolbagsshop.com/louis-vuitton-c-1.html an allusion to the hero who furthermore http://www.idolbagsshop.com/valentino-c-85.html of flight.
0
...
written by warrtiy, December 09, 2011 at 6:27 PM
This is a good blog message, I will keep the post in my mind. If you can add more video and pictures can be much better.http://www.iwcreplicas.net/graham-c-270.html
Because they help much clear nderstanding.http://www.iwcreplicas.net/guess-c-215.html
0
...
written by Best Replica Watches, November 30, 2011 at 1:53 PM
Replica watches, timepieces that are copied from well-known watchmakers, are perfect mixture of low-cost cost and high quality.http://www.store-replica.com
0
...
written by viagra online, November 12, 2011 at 12:38 AM
also betas help a lot. Even alpha funding is a great idea because you can get the most feedback than any other method.
0
...
written by Buy Viagra, November 09, 2011 at 1:29 AM
thanks for share the mini tutorial, i just start working with html but my knowledge about this language is very low, the guy who hire me, gave me 3 weeks to learn the basics, so i decide to study by myself and also I'm in touch with my supervisor if i have any doubt.
0
...
written by viagra online, November 03, 2011 at 4:13 AM
http://www.mutualpharmacy.com

Interesting post , I've been seeking for this kind of information through Internet, then I found this post and it was the happiest moment in my research. I will tell al my acquaintances about this useful website and you will get more visitors.
0
...
written by dakuro, October 27, 2011 at 7:03 AM
Great thanks a lot for share, i work in http://www.xlpharmacy-reviews.com and i have to test many software everyday because this company buys a lot of software dunno why, thanks for the advice.
0
...
written by Online pharmacy reviews, October 21, 2011 at 1:27 AM
The code seems to have an error in somewhere I'm still looking for it but i can't find it, but i start to think that the compilation software is the one with the problem.
0
...
written by dakuro, October 21, 2011 at 1:26 AM
thanks, i was reading a http://www.onlinepharmacywiki.com about this, is very helpful because not many people can do stuff like this, but i'm gonna be sure to make an html space in my blog later, thanks
0
...
written by dvds for sale, October 13, 2011 at 8:55 PM
It is a great pleasure to declare you that your article has fascinated me. You are doing a great job. Keep up the work.

Write comment
smaller | bigger

security code
Write the displayed characters


busy