\n";
}
function HiddenFields($step,$asking=0) {
global $carpsetup;
HiddenField('step',$step);
if ($asking!=1) {
if (isset($carpsetup['incdir'])) HiddenField('incdir');
if (isset($carpsetup['chrincdir'])) HiddenField('chrincdir');
}
if ($asking!=2) {
if (isset($carpsetup['proxyserver'])) HiddenField('proxyserver');
if (isset($carpsetup['proxyport'])) HiddenField('proxyport');
if (isset($carpsetup['proxyuser'])) HiddenField('proxyuser');
if (isset($carpsetup['proxypass'])) HiddenField('proxypass');
}
}
function AddToFailed($failedname) {
global $failed,$havefailed;
$failed.=($havefailed?', ':'').$failedname;
$havefailed=1;
}
function CarpSetup0() {
global $failed,$havefailed;
echo 'Checking your server\'s PHP version...';
$vers=explode('.',PHP_VERSION);
$needvers=array(4,0);
$j=count($vers);
$k=count($needvers);
if ($k<$j) $j=$k;
for ($i=0;$i<$j;$i++) {
if (($vers[$i]+0)>$needvers[$i]) break;
if (($vers[$i]+0)<$needvers[$i]) {
echo 'Failed. Your server is running PHP version '.PHP_VERSION.
'. CaRP requires PHP version ';
for ($i=0,$j=count($needvers);$i<$j;$i++) echo ($i?'.':'').$needvers[$i];
echo ' or higher.';
return;
}
}
echo 'Pass
Checking your server\'s PHP function support...';
$failed='';
$havefailed=0;
if (trim(' a ')!='a') AddToFailed('trim');
if (str_replace('ab','x','1ab2ab3')!='1x2x3') AddToFailed('str_replace');
if (!file_exists(__file__)) AddToFailed('file_exists');
if (count(explode('.','1.2.3.4'))!=4) AddToFailed('explode');
if (strlen('12345')!=5) AddToFailed('strlen');
if (strpos('12345','4')!=3) AddToFailed('strpos');
if (strtolower('CaRP')!='carp') AddToFailed('strtolower');
if (strcmp('carp','carp')||!strcmp('carp','grouper')) AddToFailed('strcmp');
if (preg_replace('/a/','b','asdf')!='bsdf') AddToFailed('preg_replace');
if (!preg_match('/a/','ace')) AddToFailed('preg_match');
if (strlen($_SERVER['SERVER_ADDR'])) $ip=$_SERVER['SERVER_ADDR'];
else if (strlen($_SERVER['SERVER_NAME'])||strlen($_SERVER['HOST_NAME'])) {
$server=$_SERVER[strlen($_SERVER['SERVER_NAME'])?'SERVER_NAME':'HOST_NAME'];
if (preg_match('/[^0-9.]/',$server)) {
$ip=gethostbyname($server);
if ($ip==$server) $ip='127.0.0.1';
} else $ip=$server;
} else $ip='127.0.0.1';
if ($fp=fsockopen($ip,$_SERVER['SERVER_PORT'])) fclose($fp);
else AddToFailed('fsockopen');
if ($fp=fopen(__file__,'r')) fclose($fp);
else AddToFailed('fopen');
if ($p=xml_parser_create()) xml_parser_free($p);
else AddToFailed('xml_parser_create');
/*
next most important to check:
unlink, fstat, flock (just be sure function exists--okay for it to fail)
not checked:
preg_match_all, call_user_func, error_reporting, array_splices, strcasecmp, strtotime, parse_url,
fputs, feof, fgets, clearstatcache, fclose, ftruncate, fflush, xml_parser_set_option,
xml_set_element_handler, xml_set_character_data_handler, fread, xml_error_string,
xml_get_current_line_number, xml_parser_free
*/
if (strlen($failed)) {
include_once dirname(__file__).'/carp.php';
?>
Failed The following functions are either disabled on your server,
or are not working correctly.
CaRP will not work on this server unless this situation is resolved:
\n";
if (CarpSetupCreateDirectories(1)&&CarpSetupAccessDirectories(1)) {
echo 'Checking for cache directories...Found
';
CarpSetup7();
} else CarpSetup1();
}
function CarpSetup1() {
global $carpsetup;
?>
Create cache folders:
The easiest method is to enter your FTP or Telnet login name and password, and let me try to do it automatically.
If the automatic method fails for any reason, you will need to use the manual method.
Please choose your preferred method:
DoCommand('site chmod 777 '.$carpsetup['chrincdir'],$rn,$rt);
else $telnet->DoCommand('chmod 777 '.$carpsetup['chrincdir'],$result);
if (CarpSetupCheckAccess(0777,0777)) CarpSetup4();
else {
echo 'Unable to set access permissions automatically ';
echo 'Please set the access permissions manually.';
CarpSetup1();
}
}
function CarpSetup2() {
global $carpsetup,$telnet,$ftp;
$carpsetup['protocol']='ftp';
include_once dirname(__file__).'/PHPFTP.php';
$ftp=new PHPFTP;
$dotelnet=1;
if (!$ftp->Connect('',$carpsetup['u'],$carpsetup['p'])) {
$dotelnet=0;
$ftp->DoCommand('site chmod 777 '.$carpsetup['incdir'],$rn,$rt);
if (CarpSetupCheckAccess(0777,0777)) CarpSetup4();
else {
$ftp->DoCommand('pwd',$rn,$path);
if ($rn{0}==2) {
$path=($path{0}=='"')?substr($path,1,strpos(substr($path,1),'"',1)):trim($path);
if (($start=strpos($carpsetup['incdir'],$path))!==false) {
$carpsetup['chrincdir']=substr($carpsetup['incdir'],$start);
CarpSetup2LastTry();
} else if (($start=strpos($carpsetup['incdir'],'public_html'))!==false) {
$carpsetup['chrincdir']='/www'.substr($carpsetup['incdir'],$start+strlen('public_html'));
CarpSetup2LastTry();
}
} else $dotelnet=1;
}
}
if ($dotelnet) {
$carpsetup['protocol']='telnet';
include_once dirname(__file__).'/PHPTelnet.php';
$telnet=new PHPTelnet;
if (!($r=$telnet->Connect('',$carpsetup['u'],$carpsetup['p']))) {
$telnet->DoCommand('chmod 777 '.$carpsetup['incdir'],$junk);
if (CarpSetupCheckAccess(0777,0777)) CarpSetup4();
else {
$telnet->DoCommand('pwd',$path);
if (($start=strpos($carpsetup['incdir'],$path))!==false) {
$carpsetup['chrincdir']=substr($carpsetup['incdir'],$start);
CarpSetup2LastTry();
} else if (($start=strpos($carpsetup['incdir'],'public_html'))!==false) {
$carpsetup['chrincdir']='/www'.substr($carpsetup['incdir'],$start+strlen('public_html'));
CarpSetup2LastTry();
}
}
} else {
echo 'Unable to set access permissions ';
switch($r) {
case 1:
echo 'Unable to create network connection. Please set access permissions manually.
';
break;
case 3:
echo 'Login failed. Please be sure to enter your login name and password accurately, or set access permissions manually.
';
break;
case 4:
echo 'The version of PHP running on your server does not support functions needed to set access permissions automatically. Please do that manually instead.
';
break;
}
CarpSetup1();
}
}
}
function CarpSetupCreateDirectories($silent=0) {
global $carpsetup;
if ($silent) $ser=error_reporting(0);
else echo 'Attempting to create cache directories...';
$rv=(file_exists($carpsetup['incdir']."/manualcache")||mkdir($carpsetup['incdir']."/manualcache",0700))
&&(file_exists($carpsetup['incdir']."/autocache")||mkdir($carpsetup['incdir']."/autocache",0700))
&&(file_exists($carpsetup['incdir']."/aggregatecache")||mkdir($carpsetup['incdir']."/aggregatecache",0700));
if (!$silent) {
if ($rv) echo "Success \n";
else {
echo 'Unexpected error ';
echo 'Although the access permissions on your carp directory are correct, I am unable to create subdirectories inside it. '.
'Unable to proceed with installation.';
}
}
if ($silent) error_reporting($ser);
return $rv;
}
function CarpSetupAccessDirectories($silent=0) {
global $carpsetup;
$rv=1;
if ($silent) $ser=error_reporting(0);
else echo 'Attempting to create files in cache directories...';
if ($f=fopen($carpsetup['incdir']."/manualcache/test",'w')) {
fclose($f);
unlink($carpsetup['incdir']."/manualcache/test");
if ($f=fopen($carpsetup['incdir']."/autocache/test",'w')) {
fclose($f);
unlink($carpsetup['incdir']."/autocache/test");
if ($f=fopen($carpsetup['incdir']."/aggregatecache/test",'w')) {
fclose($f);
unlink($carpsetup['incdir']."/aggregatecache/test");
} else $rv=0;
} else $rv=0;
} else $rv=0;
if (!$silent) {
if ($rv) echo "Success \n";
else echo 'Failed. Unable to create files inside your cache directories. '.
'If you created these directories manually (for example, with the command "mkdir manualcache", etc.), please delete them and run the installation script again. '.
'If the installation script created them, then some unexected error is causing the problem.';
}
if ($silent) error_reporting($ser);
return $rv;
}
function CarpSetup3() {
if (CarpSetupCheckAccess(0777,0777)) {
if (CarpSetupCreateDirectories()&&CarpSetupAccessDirectories()) CarpSetup6();
} else {
echo 'Access permissions incorrect ';
CarpSetup1();
}
}
function CarpSetup4() {
if (CarpSetupCreateDirectories()&&CarpSetupAccessDirectories()) CarpSetup5();
}
function CarpSetup5() {
global $carpsetup,$telnet,$ftp;
if ($carpsetup['protocol']=='ftp') $ftp->DoCommand('site chmod 711 '.$carpsetup['chrincdir'],$rn,$rt);
else $telnet->DoCommand('chmod 711 '.$carpsetup['chrincdir'],$junk);
if (CarpSetupCheckAccess(0711,0777)) CarpSetup7();
else {
echo 'I was unable to reset the access permissions on the carp directory. ';
CarpSetup6();
}
}
function CarpSetup6() {
global $carpsetup;
?>
DNS lookup of $server failed. CaRP may be installed properly, but I am unable to confirm at this time.";
} else {
if ($tfp=fsockopen($ip,$port)) {
fputs($tfp,"GET $rq HTTP/1.0\r\nHost: $server\r\nUser-Agent: CaRPInstaller/1.0\r\n");
if (strlen($carpsetup['proxyuser']))
fputs($tfp,'Proxy-Authorization: Basic '.base64_encode($carpsetup['proxyuser'].':'.md5($carpsetup['proxypass']))."\r\n");
fputs($tfp,"\r\n");
do { $l=fgets($tfp); } while (strlen(preg_replace("/[\r\n]/",'',$l))&&!feof($tfp));
if (feof($tfp)) CarpSetupAskProxy();
else {
$l=fgets($tfp);
if (preg_match('/Installation Success/',$l)) CarpSetup8();
else CarpSetupAskProxy();
}
} else CarpSetupAskProxy();
}
}
function CarpSetup8() {
global $carpsetup,$carpconf,$carpversion;
include_once $carpsetup['incdir'].'/carp.php';
if (isset($carpconf)) {
echo "I will now attempt to display a newsfeed. ";
echo '
';
CarpConf('maxitems',3);
CarpConf('phperrors',E_ALL);
CarpConf('carperrors',1);
if (isset($carpsetup['proxyserver'])) {
$proxy=preg_replace("#/$#",'',$carpsetup['proxyserver']).(isset($carpsetup['proxyport'])&&($carpsetup['proxyport']!=80))?(':'.$carpsetup['proxyport']):'';
} else $proxy=$carpsetup['proxyuser']=$carpsetup['proxypass']='';
if (strlen($proxy)) CarpConf('proxyserver',$proxy);
if (isset($carpsetup['proxyuser'])&&strlen($carpsetup['proxyuser'])) CarpConf('proxyauth',$carpsetup['proxyuser'].':'.md5($carpsetup['proxypass']));
CarpShow('http://www.geckotribe.com/press/rss/pr.rss');
?>
If a newsfeed was successfully displayed above, then installation is complete.
If error messages were displayed, you will need to resolve them.
To display newsfeeds in your web pages
copy the following code and paste it into a PHP page (a page whose filename ends with ".php").
To display newsfeeds in pages whose filenames end in ".html" or any other non-PHP extension,
paste the following code into a new document whose name ends with ".php",
and refer to the example code for converting RSS to JavaScript.
Change the URL on the line where "CarpCacheShow" is called to the URL of the feed you wish to display,
and add any desired configuration settings where shown.
For more information, please refer to the CaRP documentation.
<?php
require_once '/carp.php';
// Add any desired configuration settings below this line using "CarpConf" and other functions
\n";
if (isset($proxy)&&strlen($proxy)) echo "CarpConf('proxyserver',$proxy); \n";
echo "CarpCacheShow('http://www.geckotribe.com/press/rss/pr.rss'); \n";
echo "?>\n";
echo '
';
if ((isset($proxy)&&strlen($proxy))||(isset($carpsetup['proxyuser'])&&strlen($carpsetup['proxyuser']))||(isset($carpsetup['proxypass'])&&strlen($carpsetup['proxypass']))) {
echo " You may wish to specify the proxyserver and proxyauth settings in carpconf.php rather than in every PHP file where you use CaRP.\n";
}
} else echo "An unexpected error occurred while attempting to load carp.php. Please resolve this issue and then load the CaRP setup assistant again.";
}
?>