Subversion Repositories DevTools

Rev

Rev 1293 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

[% hash_ex_line %] 

[% scary_warning %]

###############################################################################
# Codestriker: Copyright (c) 2001, 2002 David Sitsky.  All rights reserved.
# sits@users.sourceforge.net
#
# This program is free software; you can redistribute it and modify it under
# the terms of the GPL.

# This is the top level package which receives all HTTP requests, and
# delegates it to the appropriate Action module.

require 5.8.0;

# Set this to the location of the Codestriker libraries on your system.
# Ideally, this should be done in the apache configs, but trying to do this
# in an easy way for Apache1/Apache2 with/without mod_perl with/without taint
# checking turned out to be a major headache.  For mod_perl, setting this
# ensures the first time Codestiker is loaded, it can be compiled properly,
# even if @INC is blatted later.  Also note all the use declarations below
# effectively "pre-load" all of the Codestriker modules in the system, as the
# modules below load all of their supporting modules.  That is why the
# template plugins are "pre-loaded" here.
[% codestriker_lib %]

use strict;

use CGI qw/:standard :html3/;
use CGI::Carp 'fatalsToBrowser';

use Codestriker;
use Codestriker::Http::Input;
use Codestriker::Http::Response;
use Codestriker::Action::CreateTopic;
use Codestriker::Action::EditComment;
use Codestriker::Action::Search;
use Codestriker::Action::ListTopics;
use Codestriker::Action::DownloadTopic;
use Codestriker::Action::ListProjects;
use Codestriker::Action::EditProject;
use Codestriker::Action::CreateProject;
use Codestriker::Action::MetricsReport;
use Codestriker::Action::SubmitEditTopicProperties;
use Codestriker::Action::SubmitEditTopicMetrics;
use Codestriker::Action::SubmitEditTopicsState;
use Codestriker::Action::SubmitEditCommentsState;
use Codestriker::Action::SubmitEditProject;
use Codestriker::Action::SubmitNewProject;
use Codestriker::Action::SubmitNewTopic;
use Codestriker::Action::SubmitNewComment;
use Codestriker::Action::SubmitSearch;
use Codestriker::Action::ViewTopicFile;
use Codestriker::Action::ViewTopicInfo;
use Codestriker::Action::ViewTopic;
use Codestriker::Action::ViewTopicProperties;
use Codestriker::Action::ViewTopicComments;
[% IF has_rss %]use Codestriker::Action::ListTopicsRSS; [% END %]

use Codestriker::Template::Plugin::AutomagicLinks;
use Codestriker::Template::Plugin::JavascriptEscape;
use Codestriker::Template::Plugin::StringObfuscator;
use Codestriker::Template::Plugin::FormatWhitespace;

# Set the temp file location, if one has been specified.
if (defined $Codestriker::tmpdir && $Codestriker::tmpdir ne '') {
    $CGITempFile::TMPDIRECTORY = $Codestriker::tmpdir;
}

# Set the PATH to something sane if we aren't running under windows.
# For a lot of annoying reasons, we can't run Codestriker in
# tainted mode under Win32.
if (Codestriker::is_windows()) {
    $ENV{'PATH'} = '';
} else {
    $ENV{'PATH'} = '/bin:/usr/bin';
}

# Prototypes of subroutines used in this module.
sub main();

main;

sub main() {
    # Initialise Codestriker, load up the configuration file.
    Codestriker->initialise([% codestriker_conf %]);

[% IF has_rss %]
    # only generated if checksetup.pl found a good version of XML::RSS.
    $Codestriker::rss_enabled = 1;
[% ELSE %]
    # valid XML::RSS not found
    $Codestriker::rss_enabled = 0;
[% END %]

    # If allow_delete is defined, but topic state 'Delete' is not, add it
    # in.  This accounts for older configuration files.
    if (defined $Codestriker::allow_delete && $Codestriker::allow_delete &&
        (! grep /^Deleted$/, @Codestriker::topic_states)) {
        push @Codestriker::topic_states, 'Deleted';
    }

    # Check if the old $allow_comment_email configuration option has been
    # specified in the config file, rather than the new $email_send_options
    # setting.
    if (defined $Codestriker::allow_comment_email &&
        ! defined $Codestriker::email_send_options) {
        $Codestriker::email_send_options = 
        {
          comments_sent_to_topic_author => $Codestriker::allow_comment_email,
          comments_sent_to_commenter => $Codestriker::allow_comment_email,
          topic_state_change_sent_to_reviewers => 0
        };
    }

    # Limit the size of the posts that can be done.
    $CGI::POST_MAX=$Codestriker::DIFF_SIZE_LIMIT;

    # Load the CGI object, and prepare the HTTP response.
    my $query = new CGI;
    my $http_response = Codestriker::Http::Response->new($query);

    # Process the HTTP input to ensure it is consistent.
    my $http_input = Codestriker::Http::Input->new($query, $http_response);
    $http_input->process();

    # Delegate the request to the appropriate Action module.
    my $action = $http_input->get("action");
    if ($action eq "create") {
        Codestriker::Action::CreateTopic->process($http_input, $http_response);
    } elsif ($action eq "submit_new_topic") {
        Codestriker::Action::SubmitNewTopic->process($http_input,
                                                     $http_response);
    } elsif ($action eq "view") {
        Codestriker::Action::ViewTopic->process($http_input, $http_response);
    } elsif ($action eq "view_topic_properties") {
        Codestriker::Action::ViewTopicProperties->process($http_input,
                                                          $http_response);
    } elsif ($action eq "viewinfo") {
        Codestriker::Action::ViewTopicInfo->process($http_input,
                                                    $http_response);
    } elsif ($action eq "edit") {
        Codestriker::Action::EditComment->process($http_input, $http_response);
    } elsif ($action eq "submit_comment") {
        Codestriker::Action::SubmitNewComment->process($http_input,
                                                       $http_response);
    } elsif ($action eq "view_file") {
        Codestriker::Action::ViewTopicFile->process($http_input,
                                                    $http_response);
    } elsif ($action eq "search") {
        Codestriker::Action::Search->process($http_input, $http_response);
    } elsif ($action eq "submit_search") {
        Codestriker::Action::SubmitSearch->process($http_input,
                                                   $http_response);
    } elsif ($action eq "list_topics") {
        Codestriker::Action::ListTopics->process($http_input, $http_response);
    } elsif ($action eq "download") {
        Codestriker::Action::DownloadTopic->process($http_input,
                                                    $http_response);
    } elsif ($action eq "edit_topic_properties") {
        Codestriker::Action::SubmitEditTopicProperties->process($http_input,
                                                                $http_response);
    } elsif ($action eq "edit_topic_metrics") {
        Codestriker::Action::SubmitEditTopicMetrics->process($http_input,
                                                             $http_response);
    } elsif ($action eq "change_topics_state") {
        Codestriker::Action::SubmitEditTopicsState->process($http_input,
                                                            $http_response);
    } elsif ($action eq "list_comments") {
        Codestriker::Action::ViewTopicComments->process($http_input,
                                                   $http_response);
    } elsif ($action eq "change_comments_state") {
        Codestriker::Action::SubmitEditCommentsState->process($http_input,
                                                     $http_response);
    } elsif ($action eq "list_projects") {
        Codestriker::Action::ListProjects->process($http_input,
                                                   $http_response);
    } elsif ($action eq "edit_project") {
        Codestriker::Action::EditProject->process($http_input,
                                                  $http_response);
    } elsif ($action eq "create_project") {
        Codestriker::Action::CreateProject->process($http_input,
                                                    $http_response);
    } elsif ($action eq "submit_project") {
        Codestriker::Action::SubmitNewProject->process($http_input,
                                                    $http_response);
    } elsif ($action eq "submit_editproject") {
        Codestriker::Action::SubmitEditProject->process($http_input,
                                                        $http_response);
    } elsif ($action eq "metrics_report") {
        Codestriker::Action::MetricsReport->process($http_input,
                                                    $http_response);
    } elsif ($action eq "metrics_download") {
        Codestriker::Action::MetricsReport->process_download($http_input,
                                                             $http_response);
[% IF has_rss %]
    # only generated if checksetup.pl found a good version of XML::RSS.
    } elsif ($action eq "list_topics_rss") {
        Codestriker::Action::ListTopicsRSS->process($http_input,
                                                    $http_response);
[% END %]

    } else {
        # Default action is to list topics that are in state open if the
        # list functionality is enabled, otherwise go to the create topic
        # screen.
        if ($Codestriker::allow_searchlist) {
            Codestriker::Action::ListTopics->process($http_input,
                                                     $http_response);
        } else {
            Codestriker::Action::CreateTopic->process($http_input,
                                                      $http_response);
        }
    }
}