1
# See bottom of file for license and copyright information
5
---+!! package Foswiki::Engine::CLI
7
Class that implements CGI scripts functionality when called from
8
command line or cron job
10
Refer to Foswiki::Engine documentation for explanation about methos below.
14
package Foswiki::Engine::CLI;
15
use base 'Foswiki::Engine';
21
use Foswiki::Request::Upload;
22
use Foswiki::Response;
26
my @args = @ARGV; # Copy, so original @ARGV doesn't get modified
27
while ( scalar @args ) {
29
my $arg = shift @args;
30
if ( $arg =~ /^-([a-z0-9_]+)/) {
31
($name, $arg) = (TAINT($1), shift( @args ));
32
} elsif ( $arg =~ /([a-z0-9_]+)=(.*)$/i ) {
33
($name, $arg) = (TAINT($1), TAINT($2));
35
if ($name && $name eq 'user' ) {
39
push @{ $this->{plist} }, $name
40
unless exists $this->{params}->{$name};
41
push @{ $this->{params}->{$name} }, $arg;
44
$this->{path_info} = $arg; # keep it tainted
47
my $req = $this->prepare;
48
if ( UNIVERSAL::isa( $req, 'Foswiki::Request' ) ) {
49
my $res = Foswiki::UI::handleRequest($req);
50
$this->finalize( $res, $req );
54
sub prepareConnection {
55
my ( $this, $req ) = @_;
56
$req->remoteAddress('127.0.0.1');
59
sub prepareQueryParameters {
60
my ( $this, $req ) = @_;
61
foreach my $name ( @{ $this->{plist} } ) {
62
$req->param( -name => $name, -value => $this->{params}->{$name} );
64
delete $this->{plist};
65
delete $this->{params};
69
my ( $this, $req ) = @_;
70
if ( defined $this->{user} ) {
71
$req->remoteUser( $this->{user} );
75
$req->remoteUser( $Foswiki::cfg{SuperAdminGroup} );
80
my ( $this, $req ) = @_;
81
if ( $ENV{FOSWIKI_ACTION} ) {
82
$req->action( $ENV{FOSWIKI_ACTION} );
86
$req->action( ( File::Spec->splitpath($0) )[2] );
88
if ( exists $this->{path_info} ) {
89
$req->pathInfo( $this->{path_info} );
90
delete $this->{path_info};
94
sub prepareCookies { }
96
sub finalizeHeaders { }
99
my ( $this, $buffer ) = @_;
105
# Module of Foswiki - The Free and Open Source Wiki, http://foswiki.org/
107
# Copyright (C) 2008-2009 Foswiki Contributors. Foswiki Contributors
108
# are listed in the AUTHORS file in the root of this distribution.
109
# NOTE: Please extend that file, not this notice.
111
# Additional copyrights apply to some or all of the code in this
114
# Copyright (C) 1999-2007 Peter Thoeny, peter@thoeny.org
115
# and TWiki Contributors. All Rights Reserved. TWiki Contributors
116
# are listed in the AUTHORS file in the root of this distribution.
118
# This module is based/inspired on Catalyst framework. Refer to
120
# http://search.cpan.org/~mramberg/Catalyst-Runtime-5.7010/lib/Catalyst.pm
122
# for credits and liscence details.
124
# This program is free software; you can redistribute it and/or
125
# modify it under the terms of the GNU General Public License
126
# as published by the Free Software Foundation; either version 2
127
# of the License, or (at your option) any later version. For
128
# more details read LICENSE in the root of this distribution.
130
# This program is distributed in the hope that it will be useful,
131
# but WITHOUT ANY WARRANTY; without even the implied warranty of
132
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
134
# As per the GPL, removal of this notice is prohibited.