Home

Josie Stauffer
<style type="text/css"> h2 { font-size: 1.3em; font-weight: bold; text-align: center; } h3 { font-size: 1em; font-weight: bold; } li{ padding: 5px; } </style> This software is designed for camera club members to upload images for competitions.

Members log in and fill out a form with information about each image. When the form
is submitted, the images are uploaded and stored on the webhosting server.

Once all images have been submitted, the administrator logs in and downloads all the
images, together with a spreadsheet containing the information entered by the members.

There is considerable flexibility in the information that members may be required to
enter, and in the columns that appear in the downloaded spreadsheet.

Several different competition formats may be set up to run concurrently.

For updating from a previous version, see UPDATING

Requirements:

A Linux or Unix webhosting service, offering
  • Perl CGI
  • ImageMagick (without this the images will upload, but no dimension checks or thumbnails will be available)
  • Enough storage space for all the images you plan to upload
Most of your members should have high-speed internet, since uploading images via dialup
is slow and more likely to have problems with interruptions.

Desirable but not essential:

An easy way to install additional Perl modules. This application requires:
  • Apache::Htpasswd
  • Config::General
  • either File::MMagic::XS or File::Type
  • Spreadsheet::WriteExcel
  • Template
  • Template::Stash
  • Test::Simple
in addition to the modules that are part of the standard Perl distribution.

It is also easier to install if CGI scripts run as your own user name. This is the case with some, but not all, hosting providers.

SECTION 1. INSTALLATION

  1. Environment:
    On your webhosting site, locate the following and make a note of their full path names:
    • Your “cgi-bin” (or it may be called “cgiBin”) folder.
      Files in this folder are normally executable, and when executed they print HTML code.
      This is where the Ph_comp code will go.
    • The root of your website, where publicly-accessible files are stored.
      Create a folder there for thumbnail images.
    • A private folder, not accessible from a browser but writeable by your CGI scripts, where Ph_comp can store the uploaded images and information.
  2. Configuration:
    On your local machine, unzip Ph_compPackage.zip (you probably have already, if you are reading this!).
    You should find one file called ".htpasswd" (note the '.' at the start) and three sub-folders:
    • Ph_Start_Here, which contains documentation, including this file, and some other files that may be required
    • Ph_src, which is the "source code" for the application
    • Ph_data, which is a starter set of data that will later get changed by the application.

    Open Ph_src/ServerConfigs.txt in a text editor. Fill out the values for
    • Ph_website, Ph_base: the full path and url to the cgi-bin folder, followed by "/Ph_src"
    • Ph_upload: The full path to your private folder, followed by "/Ph_data"
    • Ph_passfile: The full path to a file where the application will store passwords.
      This should be readable and writeable by your CGI scripts and readable by the apache webserver, but should NOT be visible in a browser ( so not inside the htdocs, www, or public_html folder, and not in a private folder ).
      This file is usually called .htpasswd, so a default value would be something like "/home/ourcameraclub/.htpasswd"
    • Ph_thumbsdir, Ph_thumbsite: The full path to the folder you created for thumbnails
    • Ph_favicon: The (optional) location for your favicon image (the tiny icon that shows on the page tab in a browser)
    • Ph_ckeditor: If you wish to use the CKEditor text editor to edit the html, install it and set this to the full url of your ckeditor folder.

    (NB: file pathnames must be in Unix format, with the folders separated by '/'. Windows uses '\', so be careful. )

    Save the file in plain text format.

    In the rest of this documentation, "<Ph_website>" will refer to whatever you entered here for Ph_website, "<Ph_upload>" will refer to whatever you entered here for Ph_upload, etc.

  3. .htaccess:
    Still on your local machine, open the file "Ph_src/.htaccess".
    Change the value "Camera Club Competition Upload" to something that identifies your club.
    This phrase will appear on the password request when members attempt to log in.

    Insert in the "AuthUserFile" line the value of <Ph_passfile>

  4. Uploading:
    Upload the contents of Ph_compPackage to folders on your server as follows:
    • Ph_src folder to your cgi-bin folder.
    • Ph_data folder to your private folder.
    • .htpasswd file to <Ph_passfile> (rename it if you did not use the default ".htpasswd" name)

    Make sure that all the ".cgi" files in the bin folder are executable

  5. CKEditor:
    If you are using ckeditor, upload the files PhConfig.js and Ph_comp.css from the "Ph_Start_Here" folder to the ckeditor folder.
    These files may be edited if you wish to customize your editing interface. They have been slightly modified from the basic ckeditor versions to fit with the styling of Ph_comp. Keep copies of these files because they may be overwritten if CKEditor is updated.

  6. Testing your installation:
    Open a web browser and browse to <Ph_website>/bin/testit.cgi. You should be asked for a username ('phcomp1')
    and password ('changeme').

    If you get something like a "Server Error" message, see "Perl Path" below. Also check the permissions on your Ph_src and Ph_data folders.

    You should see the following output:
    Testing that all the modules we require are loaded:
        ok 1 - use Apache::Htpasswd;
        ok 2 - use Archive::Zip;
        ok 3 - use CGI::Carp;
        ok 4 - use CGI;
        ok 5 - use Config::General;
        
    ..... followed by a lot more similar lines starting 'ok', and some information about the running environment, finishing with
    "******** TESTS COMPLETED *********".

    If any (non-Ph_comp) module shows "not ok" you will need to install it yourself.
    Most webhosting companies provide a way to install perl modules. You may also do it by obtaining the required files yourself (do a web search for CPAN plus the module name) and putting them in the cgi-bin/Ph_src/lib folder.
  7. ImageMagick:
    Note that the Image::Magick module requires that the ImageMagick library ( a set of programs for handling images ) be available on the server, in addition to the Perl Image::Magick module itself.

    If the library is in place on the server, then running testit.cgi in your browser should have produced the line:
      Test for the ImageMagick installation:                  --- OK
    near the bottom of the output.

    If the ImageMagick library is not available on the server, there is no point in installing the Perl Image::Magick module. The application should still work, but no checking will be done for image dimensions, and there will be no display of thumbnails.


  8. Troubleshooting:
    Problems running testit.cgi are usually due to incorrect file permissions or locations. Try making problem files readable to everyone. Once you have the system working, you can try to restrict permissions more tightly.

    If testit.cgi does not produce any output, try "test1.cgi", which simply tests to see if Perl is installed and accessible. If Perl is not accessible, it may not be in the usual "/usr/bin/perl" folder. Check with your service provider for the actual location, and alter the "/usr/bin/perl" lines in all the ".cgi" files in Ph_src/bin/.

    If all else fails, temporarily rename the .htaccess file in Ph_src. This should make it possible to run testit.cgi in your browser, and the output, especially the file creation tests at the end, should give you some clue as to the problem.

NOTE: The security used for this application is htaccess. Your login session lasts until you close your browser, and there is no real way other than closing your browser to "log out".
As an administrator, you may well wish to log in as a different user for testing purposes, or view the application as it appears to a user who is not logged in. The easiest way to do this is to run two different browsers - e.g. Firefox and Chrome. Log in as an administrator on one, and as another user on the other.


SECTION 2. OPERATION AND CUSTOMIZATION


Options

The starter environment consists of a single user called "phcomp1", with password "changeme". The first thing to do is to browse to <Ph_website>/bin/upload.cgi, click on the "change my password" button, change this to something more secure, and make sure you can log in again.

The software has been set to require a minimum of 8 characters including at least one character that is not alphabetic.

Click Next and make sure that you are able to upload an image using the default competition format. Click Change and delete the uploaded image.

Troubleshooting: If anything went wrong in the above steps, a clue to the problem may be found in <Ph_upload>/errors.log or in your webhost's server error log.

Then browse to <Ph_website>/bin/admin.cgi to begin the customization (you will want to bookmark <Ph_website>/bin/admin.cgi, because this is where you will control all the competitions).

Click first on "Edit top level options" and set up your preferences for the use of levels and membership numbers.
Leave the administrators until you have created your members.

Then set up your Regular Competitions by clicking Manage followed by Options.

Remember, you may eventually set up more than one competition format by duplicating the options for this one and then editing them. The first format you set up cannot be deleted, but other formats can be. You may have one active competition of each format at any one time.


Normal Operation

Before users can enter images in a competition, the administrator has to "open" the competition for upload ( <Ph_website>/bin/admin.cgi, select the competition, and under "Competition Control" click "Open the current competition").

At this point, any user with the right password may browse to <Ph_website>/bin/upload.cgi and enter images.
When the administrator closes the competition ( <Ph_website>/bin/admin.cgi, select the competition, and under "Competition Control" click "Close the current competition"), users will see a "Competition Closed" message. You may customize the message - see below.

Occasionally, it may be desirable to allow a particular user to (re-) submit an image after the closing.
  • When the competition has been closed, an option appears on the administrative screen that allows the competition to be effectively opened for selected users only.
  • Making any change to this user list, or re-opening the competition, removes all previous users from the list.
  • The user-names of all the specially-privileged users is displayed next to the selection box.
  • When a user has this sort of special access, they will see "*** Competition Closed ***" at the top of each screen, but will still be able to upload.
At any time, the administrator may click "Download Excel Spreadsheet" or "Download Images".
"Download Excel Spreadsheet" should cause either a download or the automatic opening (depending on your browser settings) of a spreadsheet containing all the uploaded information. The format of this spreadsheet may be customized under "Edit Options".
"Download Images" allows you to download a zipped archive of all the uploaded images for the competition.

Editing the Text

Once your options are set up, you may wish to go back to <Ph_website>/bin/upload.cgi and look again at the screens.
A lot of the text on these screens may be changed by using the buttons under "Edit Page Text" on the competition management screen.
Note that the "Save" button simply saves one piece of text you have edited, in a temporary area. To make the text visible on your website, you need to click "Publish Page", which makes all changes on that page visible.
There are a number of generated items that you may include in the text if you wish:

Macro Generates
[% cfgs.maximages %] Maximum number of images allowed
[% cfgs.max_img_w %] Maximum image width in pixels
[% cfgs.max_img_h %] Maximum image height in pixels
[% cfgs.max_image_size %] Maximum image size in Megabytes
[% cfgs.min_area %] Minimum image area in square pixels
[% cfgs.fmt_name %] Name of this competition format
[% cfgs.home_url %] Home URL
[% cfgs.entryTitle %] Page header
[% memberdata.membernum %] Membership number
[% memberdata.surname %] Surname
[% memberdata.firstname %] First name
[% memberdata.level %] Level
[% memberdata.xtra %] The "Extra Data" field (do NOT display email address or anything confidential
- the security on this application is not of a very high level)
[% user %] Username
[% compname %] Name of the current competition
[% website %] The value you entered for Ph_website in ServerConfigs.txt
[% other_format_links %] A list of links to all your other currently open competitions


The text below the "Home", "Undo" and "Submit" buttons on the image upload page contains a number of these macros.
This makes sure that the information about limits on image size, etc, matches the constraints that are actually placed on the images by the application.
You may move this text to another place if you prefer, but be very careful when editing it. Changes in the wrong place may make it unintelligible.

Adding Members

To add members, you may either
1. use the "Add a new user" button on the main administration page to add users one at a time
or
2. put all the information about your members (Membership Number, Surname, Firstname, Username, Level, Password, other data) in a single comma-separated .csv file, one line per member, and upload it using the upload button.
(The "Level" in this file is the short "value" entered in the top level options, not the "label" that is shown to members.)

This file may be generated from a spreadsheet, but the data must consist only of Membership Number, Surname, Firstname, Username, Level, Password, other data separated by commas only, with no quotes. ( "other data" may be anything else for a member, like an email address, that you wish to have appear in the downloaded spreadsheet. Or it may be blank. ).

To keep your membership data in synch, you may upload the .csv file at any time, see how it differs from what is stored on the server, and modify the data on the server to match the .csv file. NOTE: when data for an existing member is modified using this method, the password will not be changed.

Once you have other members added, you may go back to the "Top Level Options" and set up other administrators.
An administrator is just a regular member who is given access to the "admin.cgi" application.

This software does not have sophisticated code to handle the possibility of more than one administrator making changes at the same time, so you should be clear about who is responsible for doing what.


Adding A New Format

In the main administration screen, click "Copy to a new type" for the format you wish to copy from. This will create a new format called "** New Format **", which you may then edit by clicking "manage". If this is your second format, the upload screen for it is reached via the url <Ph_website>/bin/upload.cgi?cformat=2. Each subsequent format gets a new number and corresponding url. If there is no "?cformat=N" in the url, the first format is assumed.
If you have several open competitions in different formats, you may optionally put links to the other competitions in the text you edit using Edit Page Text. Insert "[% other_format_links %]" where you wish to see the links.

Registration

Note there is also a second category of administrators for "registrations". The Registrations part of the application was developed to handle registering members for workshops and field trips. There are other, far more sophisticated, applications available for this task, and the only advantage of this one is that the same login will allow a member to access either the image upload or the registration.

There is no administrative page for registrations - someone must edit a text file to control the setup. A sample text file is included, and if you wish to use the application, it is suggested that you rename Ph_data/SampleRegConfigs.txt to Ph_data/RegConfigs.txt, and carefully study the relationship between Ph_data/SampleRegConfigs.txt and the web page found at <Ph_website>/bin/registration.cgi.
Warning: if the RegConfigs.txt file does not have the correct format, the image upload site will break. Keep a backup. Use Notepad++ to edit it, and set the language to XML.

The list of people registered should be visible at <Ph_website>/bin/registration.cgi?runmode=list

It is not currently planned to develop the registration part of this application further.


Logging Out

This application uses basic .htaccess for protection. This authorizes the user's browser, and does NOT provide a mechanism for logging out. The only effective way to "log out" is to close the browser.

Deleting Items:

A user should be able to delete any image from the normal upload window. But if the user is for some reason unable to do so, an administrator with ftp access to the server may remove it.
The uploaded images and their information are stored in <Ph_upload>. There is a subfolder for each competition, labelled compFormatN, and within that a subfolder for each member, labelled by the username. Inside the user folder are the uploaded image files for that user and that competition, and for each image file there is a matching data file.
To totally remove all record of an uploaded image, delete both the image file and the matching data file.

SECTION 3. UPDATING PH_COMP


To update the Ph_comp code to a newer version without affecting any of your existing settings or data, download the "Update" package and unzip. Usually, the contents will be an "UPDATE.txt" file and 3 folders: bin, Templates and Ph_comp.
Open UPDATE.txt and follow the instructions in it. Normally these will be:
  • Upload the contents of "bin" to your <Ph_base>/bin folder, overwriting the existing files.
  • Upload the contents of "Templates" to your <Ph_base>/Templates folder, overwriting the existing files.
  • Upload the contents of "Ph_comp" to your <Ph_base>/lib/Ph_comp folder, overwriting the existing files.


SECTION 4. EXAMPLE FOLDER STRUCTURE


This section attempts to describe what files are part of Ph_comp, and what their purpose is.
It is not, strictly speaking, necessary to understand this in order to run the software, but if anything goes wrong, it could be very helpful.


"/" is the "root" folder. Normally this is where you would be when you first connect to the server via FTP.

Paths use Unix notation, so for instance the full path to RegConfigs.txt is "/private/Ph_data/RegConfigs.txt". Note the different direction of the slash from Windows ("\").

"<>" angle-brackets refer to item names in ServerConfigs.txt.

                   '/' 
                    |
                    |
         ---------------------------------------------------------------------------------------
        |                            |                                                          |                    
     #private                        |                                                    #public_html         
        |                     ***.htpasswd                                        ( <Ph_website> - your site url )  
        |                                                              ( <Ph_base> - the full path to public_html ) 
     Ph_data(<Ph_upload>)                                                                       |
        |                                                                                       |
        |                                                                                       |
     ---------------------------------------------------------------------------------          |
    |          |      |                  |             |               |        |    |          |
    |          |      |                  |             |               |        |    |          |
members.dat  ~dbg  ~errors.log     Configs.txt    RegConfigs.txt       |        |    |          |
                                                                       |        |    |          | 
                                                                compFormat1  ~compFormat2,3,..  |
                                                                       |          |             |
                                                                       |          |             |
            ---------------------------------------------------------------------------         |
           |             |                |             |           |                 |         |
  CompConfigs.txt current_competition TemplateText ent_phcomp1  ~ent_member1  ~ent_member2 ...  |
                                          |                                                     |
                                          |                                                     |
                               -----------------                                                |
                              |                |                                                |
                            Test           .tt2 files                                           |
                              |                                                                 |
                         ~.tt2 files                                                            |
                                                                                                |
                                                                                                |
                     --------------------------------------------------------------------------------
                    |                   |                                                           |
                    |                   |                                                           |
                    |             our_thumbnails (<Ph_thumbsdir>/<Ph_thumbsite>)                    |
                #cgi-bin                |                                                           |
                    |                   |        
                    |            ~thumbnails of uploaded images                 #html files for existing website
                    |                         
                    |                
                  Ph_src
                    |   
                    |    
        ------------------------------------------------------------------------
       |                   |                |               |                  |
 ***ServerConfigs.txt      |                |               |                  |  
                           |              Templates         |           ***.htaccess   
                          bin               |              lib           
                           |                |               |
                           |             .tt2 files         |        
                           |                                |         
                       .cgi files                  -------------------------------------------
                                                  |              |                 |         |
                                                  |              |                 |         |       
                                                  |        ***(Public source .pm files as required)*** 
                                                Ph_comp                                       
                                           (perl modules)    
                                                 |            
                                                 |            
                                              .pm files


In addition, every folder should contain an empty index.html file.

# indicates files that should already exist on the server, or their equivalent does.

*** Triple starred files need to be manually changed/created for each installation

~ indicates files that are or may be created automatically by the code

cgi-bin folder:

The webserver assumes that, instead of being an html file, any file that a browser calls from under this folder is really an executable (application, program,...) that spits out html when it is run. Perl executables conventionally end in .cgi or .pl.

cgi-bin/Ph_src/bin:

Contains all the perl ".cgi" files that may be called directly from a browser:

setup.pm - common code required by all the other files admin.cgi - administration, limited to specified users
upload.cgi - enter data and upload digital images
registration.cgi - a separate application, still under development, used for registering members in workshops
test... - used to output some information about the server for help with installation

cgi-bin/Ph_src/Templates:

Contains the "skeletons" or "templates" for the html that is generated by the .cgi files.

cgi-bin/Ph_src/TemplateText:

More templates - these are plain text and very simple html for text sections of the web pages.
They may be changed by administrators as required, using admin.cgi and CKEditor if it is installed.

cgi-bin/Ph_src/lib:

"library" perl files ending in .pm (modules) required by the .cgi files. Ph_comp contains all the .pm files that are actually part of the Ph_comp application.

This is also where we add the perl modules we need that are not installed on the system. These modules are freely available on the internet, but which ones are actually installed on the system depends on the webhosting service. If the webhost does not have them installed, we have to put our own copies here.

You can find out what is installed (and other useful stuff) by running cgi-bin/bin/testit.cgi in a browser. Or you may find out they are not installed from the error messages you get when you try to run code that requires them.

<Ph_upload> folder (NOT in public area):

Where all the user data like images, image names, etc is stored.

This folder contains a subfolder compFormatN for each possible competition format, and each compFormatN contains a subfolder ent_XXXX, where XXXX is a username, for each member.

That is where the data is stored for all that member's uploads. ( The user's folders are automatically created when you add a user, or upload a comma-separated file of members, using the admin screen )

How to access in a browser:

The base url is what you entered for <Ph_website>

So to run "upload.cgi" type the value of <Ph_website> followed by "/upload.cgi" in a browser.
If you have other formats 2,3,..., they may be accessed as <Ph_website>/upload.cgi?cformat=2 ... etc.
Links to these can be created in a normal web page just like links to .htm files.

Permissions:

Unix file permissions can be set using ftp. The permissions needed vary from host to host. One thing you need to remember is that a folder has to be executable in order for its contents to be readable or writeable.

Anything ending .cgi should be executable.
All the contents of <Ph_upload> should be readable and writable by your cgi scripts, but, if possible, not readable by everyone.
All the contents of cgi-bin/Ph_src should be readable by everyone.

The simplest way to get things working if you have permissions problems is:
Start out by making
  • everything readable by owner, group and others.
  • .cgi files executable by owner, group and others.
  • user directories executable and writable by owner, group and others.
Get everything working.
Then reduce the permissions to the minimum needed to keep things working.

Security:

.htpasswd contains the usernames and encoded passwords - it must NOT be in a folder that can be accessed via a browser, like cgi-bin or public_html. It's location is stored in .htaccess.

.htaccess is in cgi-bin/Ph_src. It tells the system that only people listed in .htpasswd can access the files in cgi-bin/Ph_src, and that they must enter a password.


SECTION 5. POSSIBLE PROBLEMS AND ADVANCED CONFIGURATION

1. Perl path:

On most Linux servers, the Perl executable may be found at /usr/bin/perl. If this is not the case on your server, you will need to find out from your hosting company where the perl executable is located.
In Ph_src/bin are 4 files with extension ".cgi": admin.cgi, registration.cgi, testit.cgi and upload.cgi.

In each of these files, you will need to replace "#!/usr/bin/perl" in the first line with "#!" followed by your path to perl, and then re-upload the files. Remember to save the files as text only.

2. Perl modules:

If your hosting company tells you to place some specific code at the start of your script in order to load the required modules, the place to put this code is in Ph_src/bin/setup.pm. The code in this file is run before anything else.

3. Line Endings:

If running on a non-unix host, this code may work, but has not been properly tested. Look for the line starting "Line separator ASCII code" in the output of testit.cgi, and if the value is not 10, open Ph_data/members.dat on the system, edit and save the file so it aquires the system line ending.
OR
remove members.dat, temporarily comment out the line 'require valid-user' by putting a '#' at the start, create the admin account using the admin.cgi interface, and finally replace the 'require valid-user' line.


If your hosting company tells you to place some specific code at the start of your script in order to
load the required modules, the place to put this code is in Ph_src/bin/setup.pm. The code in this file
is run before anything else.


3. Line Endings:

If running on a non-unix host, this code may work, but has not been properly tested. Look for the line
starting "Line separator ASCII code" in the output of testit.cgi, and if the value is not 10, open
Ph_data/members.dat on the system, edit and save the file so it aquires the system line ending.

OR

remove members.dat, temporarily comment out the line 'require valid-user' by putting a '#' at the start,
create the admin account using the admin.cgi interface, and finally replace the 'require valid-user' line.





Project Admins: