What "dsurvey" is in a Nutshell

Contents

Description

When starting up my company, I needed to do some market research. I wanted to do an online kind of survey, and instead of hard coding, I wanted something which was configurable.

This is the first release of dsurvey, version 0.01. It is a set of perl CGI and config scripts which work with apache 1.3 and MySQL 3.25.

This series of perl scripts is designed to interface with a backend MySQL server.

Setting up the User

In order to set the database up, you need to add the user "survey" to your database. Using the "mysql" command prompt, add the following permissions to the survey user:

where "****" is the account's password.

Create the directory "/etc/survey/passwords". Put the "survey" password in the file "/etc/survey/passwords/survey" as follows:

where "****" is the account's password, as above.

You only need the "root" password in the "/etc/survey/passwords/root" file in order to initialize the database. Then you can safely remove the file.

top

Setting up the Database

In order to set up all of the required tables, run the "create_survey_db.pl" script. This will create the following tables in the database "mithril_survey": Next, you need to populate the survey questions. Download the file questions.conf to see a sample, customize the file, the make sure it's in your distribution directory. Run the "add_questions.pl" script to populate the database with questions.

Once the database is created and the tables populated, you are ready to run the survey. Just make sure you unpack the distribution into the "cgi-bin/survey" directory.

top

A Word on Security

You should remove the "/etc/survey/passwords/root" file after initializing the database for the first time. Also, set the permissions for group read only, and other users to nil, and make sure group ownership of the file is the same as the running group of your web server. For example, on Debian Sarge:

top

Source Code

cgiform.pm

This file contains code which wraps the creation and manipluation of a CGI perl object. I made this to keep from having to cut and paste the same code over and over again.

top

common.pm

The common module contains common definitions (like $SECTION_MARKER, for example), plus many functions which wrap the Perl CGI object code. These functions made life easier for me because more than one CGI file accesses the CGI object code.

top

passwords.pm

The passwords module contains a single function, read_passwords(), which is used to read a password from the passwords files. The passwords are stored in seperate files under the /etc/survey/passwords directory. There are two files: root and survey containing, respectively, the required password.

top

create_survey_db.pl

The first step is the creation of the actual survey tables using the create_survey_db.pl script.

top

add_questions.pl

This script initializes the question table with a list of questions from a configuration file, questions.conf. The questions table is then populated.

top

CGI Scripts

survey.cgi (page 1)

Once the database has been created, it is important that a user, survey, be created with access rights for SELECT, INSERT, and DELETE.

The survey page starts by calling the survey.cgi script. This script uses the Perl CGI object to create and or modify a cookie and to create a form. Once the user fills out the form and clicks the SUBMIT button, the next page is invoked.

The CGI form is driven by the contents of the questions table. The sections table delimites the questions into groups, and the choices table contains a record for each choice a particular question might have (i.e. "Please choose your gender:", and there would be three rows in the choices file: male, female or no_answer).

If no cookie has yet been created on the user's machine, a unique id is extracted from a table in the survey database. This is done by using the DBD::MySql perl libraries. If, on the other hand, a cookie does indeed exist on the user's machine, the unique id number is extracted from the cookie itself. The form is then prepopulated with the respondent's previous entries (the responses table drives the pre-population).

top

finish.cgi (page 2)

This script commits the user's answers (from the previous form) to the database. The user's responses for the entire survey are then read back from the database and displayed.

top

Source Code Tarball

top

License

This software has been released under the GNU General Public License.

top

TODO

top


Back to the survey page.