#!/usr/bin/perl ############################################################################### # cpanelphp PHP wrapper for Cpanel # A replacement of the original cpanelphp wrapper for # POST variables to be passed to both Cpanel and PHP. # Third public release: 04/AUG/2004 # By Juan R. Pozo - jrpozo@conclase.net - http://html.conclase.net/cp/scripts/ # Copyright of original wrapper: (c) CPanel, Inc. ############################################################################### ############################################################################### # Copyright (c) 2003-2004, Juan R. Pozo # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal # in the Software without restriction, including without limitation the rights # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell # copies of the Software, and to permit persons to whom the Software is # furnished to do so, subject to the following conditions: # - The above copyright notice and this permission notice shall be included in # all copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # SOFTWARE. ############################################################################### BEGIN { push @INC, "/usr/local/cpanel"; } unless (open(STDERR, ">&STDOUT")) { print "Can't dup STDERR: $!\n"; exit; } use Cpanel; Cpanel::initcp(); my ($pid, $cpanel, $php) = (undef, undef, undef); my $formdata = ; if (!defined($pid = open(IPC, "-|"))) { dead_error("Cannot fork: $!"); } elsif ($pid == 0) { if (!defined($cpanel = open(CPANEL, "|-"))) { dead_error("Cannot fork to cpanel: $!"); } elsif (!$cpanel) { exec("/usr/local/cpanel/cpanel", $ARGV[0], "2>&1") or dead_error("Cannot launch CPanel parser: $!"); } print CPANEL $formdata; close(CPANEL); } elsif ($pid) { my @output = strip_headers(); close(IPC); my $file = "/tmp/" . $Cpanel::user . "-" . time() . "-" . $pid; open(TMP, ">$file") or dead_error("Cannot open temp file: $!"); chmod 0600, $file; print TMP @output; close(TMP); $ENV{'SCRIPT_FILENAME'} = $file; $ENV{'PATH_TRANSLATED'} = $file; $ENV{'REDIRECT_STATUS'} = 1; if (!defined($php = open(SCRIPT, "|-"))) { dead_error("Cannot fork to PHP: $!"); } elsif (!$php) { exec("/usr/local/cpanel/3rdparty/bin/php", $file) or dead_error("Cannot launch PHP parser: $!"); } print SCRIPT $formdata; close(SCRIPT); unlink($file); exit; } sub dead_error { my ($msg) = @_; print "Content-Type: text/html\n\nError: $msg"; exit; } sub strip_headers { shift while $_[0] !~ /^\s*$/; splice @_, 1; }