#!/usr/bin/perl -wI. # # Copyright (C) 2004 Peter Thoeny, peter@thoeny.com # # Quick and dirty utility to execute commands as the Apache user, use at your own risk! # Useful if you do not have root access on a hosted server. # # To install: # - copy qdexec to your twiki/bin directory # - add qdexec to .htaccess to require authentication (like the edit script) # - set $allowedUserName in the CONFIGURATION section below to the WikiName of the person # who is allowed to execute commands # # To use: # - uncomment a ready made command temporarily (or create your own) # - point your browser to http://your.server/cgi-bin/qdexec to execute the command # - comment out the command immediately after use # # WARNING: For security, uncomment ready made commands only temporarily! # BEGIN { # Set library paths in @INC at compile time unshift @INC, '.'; require 'setlib.cfg'; } # CONFIGURATION: my $allowedUserName = "FooBar"; use CGI::Carp qw(fatalsToBrowser); use CGI; use TWiki; open(STDERR,'>&STDOUT'); # redirect error to browser $| = 1; # no buffering print "Content-type: text/html\n\n"; print "

Quick and dirty exec utility

\n"; my $query= new CGI; my $thePathInfo = $query->path_info(); my $theRemoteUser = $query->remote_user(); my $theTopic = $query->param( 'topic' ); my $theUrl = $query->url; my( $topic, $webName, $scriptUrlPath, $userName ) = &TWiki::initialize( $thePathInfo, $theRemoteUser, $theTopic, $theUrl, $query ); my $dataDir = TWiki::Func::getDataDir(); my $pubDir = TWiki::Func::getPubDir(); print "User: $userName
\n"; print "Data dir: $dataDir
\n"; print "Pub dir: $pubDir
\n"; if( $userName eq $allowedUserName ) { print "
======( start execute )================================================
\n"; print "
\n";

    # uncomment and customize one of the following lines temporarily:

    #print `ls $dataDir`;
    #print `chmod 777 $dataDir/Trash`;
    #print `chmod 777 $pubDir/Trash`;
    #print `chmod 777 $pubDir/Trash/*`;
    #print `kill -9 12345`;

    print "
\n"; print "
======( end execute )================================================
\n"; } else { print "Error: No permission for $userName
\n"; } print "End qdexec
\n";