<?php
/* (C) 2006 by legolas558
Veloce php script v0.1
Licensed under GPL
* This program is free software and open source software; you can redistribute
* it and/or modify it under the terms of the GNU General Public License
* version 2 as published by the Free Software Foundation
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA or visit
* http://www.gnu.org/licenses/gpl.html
*/
$root = str_replace('\\','/', dirname(__FILE__)).'/'; //! the current folder absolute path
if (@$_GET['kill']==1) {
if (@unlink($root.$_GET['chosen']))
{
unlink($root.'TarExtract.php');
unlink($root.basename($_SERVER['PHP_SELF']));
header('Location: '.default_redir($root));
} else
echo 'Could not delete files';
exit;
}
define('__TBK_DEFAULT_CHUNK', 10 * 1024 * 1024);
include 'TarExtract.php';
session_start();
if (@$_GET['auto'])
$auto = 1;
else $auto = 0;
?><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta name="author" content="legolas558">
<title>Veloce Extraction wizard</title>
</head>
<body<?php if ($auto) echo ' onLoad="do_auto()"';?>>
<div style="width:50%; height:20px; position: absolute; left: 10px; top:15px; background-color:black; text-align:right; color:white"><sub>by <a href="http://sf.net/users/legolas558">legolas558</a></sub> </div>
<div style="width:20px; height:50%; position: absolute; left: 20px; top:5px; background-color:gray"></div>
<div style="position: absolute; left:50px; top:45px; font-family: tahoma; background-color:#B1D3ED ">
<h2>Veloce extraction wizard</h2>
<form <?php if (isset($_GET['step'])) {?> onSubmit="return do_submit()"<?php } ?> name="veloce" method="get" action="<?php echo basename($_SERVER['PHP_SELF']);?>">
<?php
if (!isset($_GET['step'])) {
$found = archives_list($root);
$c = count($found);
if (!$c) {?>
<p><i>No archives found in current folder</i></p>
<?php } else {
?><p>Select archive to extract</p><?php
function one_option($filename, $ext) {
global $root;
?><label>
<input type="radio" name="chosen" value="<?php echo $filename ?>"<?php echo $ext; ?>>
<?php echo $filename.' ('.filesize($root.$filename).' bytes)'; ?></label>
<br>
<?php }
one_option($found[0], ' checked="1"');
for ($i=1;$i<$c;$i++)
one_option($found[$i], '');
?><br><input type="submit" id="btnSubmit" value="Start">
<label for="auto"><input id="auto" type="checkbox" name="auto">Continuous mode</label>
<input name="step" type="hidden" value="0"><?php
}
} else {
$step = ((int)$_GET['step']);
$tar = new TarExtract(&$_SESSION['tarextract']);
if ($step==0) {
$tar->BeginExtract($root, $root.$_GET['chosen']);
}
else
if (!isset($tar->progress))
trigger_error('Session lost, restart please', 256);
function extract_cb($again, $total, $done) {
global $message, $finished;
if (!$again) {
$message = 'Extraction 100% complete<br/><br/>Pressing "Exit & Delete" will cause the archive <i>'.$_GET['chosen'].'</i> and this script <i>'.basename($_SERVER['PHP_SELF']).'</i> to be deleted';
$finished = true;
} else {
$message = '<b>'.((int)($done*100/$total)).'%</b> complete<br/>';
$finished = false;
}
}
$tar->Extract('extract_cb');
?>
<input type="hidden" name="step" value="<?php echo ($step+1); ?>">
<input type="hidden" name="auto" value="<?php echo $auto; ?>">
<input type="hidden" name="chosen" value="<?php echo $_GET['chosen']; ?>">
<p><?php
echo $message;
?></p><?php if (!$finished) {?>
<script language="javascript" type="text/javascript">
function do_submit() {
document.getElementById('btnSubmit').disabled = true;
return true;
}
function do_auto() {
document.forms[0].submit();
}
</script>
<input type="submit" id="btnSubmit" value="Continue"><?php } else {?>
<script language="javascript" type="text/javascript">
function do_submit() { return true; }
function do_auto() { }
</script>
<input id="kill" type="hidden" name="kill" value="0">
<input type="button" value="Exit" onclick="document.location='<?php
echo default_redir($root);
?>'">
<input type="button" value="Exit & Delete" onclick="document.getElementById('kill').value = 1; document.forms[0].submit();">
<?php
}
} ?>
</form>
</div>
</body>
</html>
<?php
// misc functions
function file_ext($file)
{
$p = strrpos($file, '.');
if ($p===false)return '';
return strtolower(substr($file,$p+1));
}
function archives_list($parent)
{
$allowed_ext = array('tgz','tar', 'gz');
$dh=opendir($parent);
$found = array();
while (false !== ($filename = readdir($dh))) {
if( $filename[0]=='.' ) continue;
if (!is_dir( $parent.$filename ) && in_array(file_ext($filename), $allowed_ext))
$found[] = $filename;
}
return $found;
}
function default_redir($root) {
if (file_exists($root.'install/index.php'))
return 'install/index.php';
else
return 'index.php';
}
function mt_float()
{
list($usec, $sec) = explode(' ', microtime());
return ((float)$usec + (float)$sec);
}
?>