".$site->GetInterfaceTemplate("gallery", "setup-manual")."");
return;
}
if ( !isset($_REQUEST["command"]) )
{
InitialiseScriptaculous();
eval("?>".$site->GetInterfaceTemplate("gallery", "setup")."");
return;
}
header("Content-Type: application/xml");
header("Cache-Control: no-cache");
$site->DisableHeaders();
switch ( $_REQUEST["command"] )
{
case "download":
$url = ( isset($_REQUEST["url"]) ? $_REQUEST["url"] : GALLERY_DEFAULT_URL );
$fd = @fopen($url, "r");
if ( !$fd )
{
$url = GALLERY_DEFAULT_URL;
$fd = @fopen($url, "r");
}
if ( !$fd )
{
echo "1".
htmlspecialchars("The download process failed. Please install manually.").
"";
return;
}
$ofd = @fopen("/tmp/gallery.tar.gz", "w");
if ( !$ofd )
{
echo "2".
htmlspecialchars("Could not write to /tmp/gallery.tar.gz. Please check permissions, or install manually.").
"";
return;
}
try
{
while ( !@feof($fd) )
{
if ( @file_exists("/tmp/gallery-cancel-download") )
{
$cancelled = true;
@unlink("/tmp/gallery-cancel-download");
break;
}
@fwrite($ofd, @fgets($fd));
}
@fclose($fd);
@fclose($ofd);
}
catch ( Exception $e )
{
echo "3".
htmlspecialchars("The download process failed. Please install manually."). "";
@unlink("/tmp/gallery.tar.gz");
return;
}
if ( $cancelled )
{
echo "4".
htmlspecialchars("The download was cancelled. Please install manually.").
@unlink("/tmp/gallery.tar.gz");
return;
}
echo "0".
"Succeeded.";
break;
case "get_download_status":
if ( file_exists("/tmp/gallery.tar.gz") )
{
echo "0".
filesize("/tmp/gallery.tar.gz").
"";
}
else
{
echo "1".
"Not downloaded.";
}
break;
case "cancel-download":
if ( @touch("/tmp/gallery-cancel-download") )
{
echo "0".
"Cancelling...";
}
else
{
echo "1".
"Couldn't cancel.";
}
break;
case "extract":
@chdir($_SERVER["DOCUMENT_ROOT"]."/modules/gallery");
$err = trim(@shell_exec("tar zxf /tmp/gallery.tar.gz 2>&1"));
if ( file_exists("gallery2/index.php") )
{
echo "0".
"Succeeded.";
}
else
{
echo "1".
"Could not extract Gallery package.".
($err?" Extraction process said: ".htmlspecialchars($err):"").
htmlspecialchars("
Please install manually.").
"";
}
@unlink("/tmp/gallery.tar.gz");
break;
}
}
?>