From: Sebastien D. <sde...@us...> - 2005-01-27 10:38:09
|
Update of /cvsroot/tslogparser/web/admin In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv955/admin Modified Files: index.php Added Files: tar.inc.php Log Message: Update demo to v05 source --- NEW FILE: tar.inc.php --- <?php /* This file is copied from the PEAR package, so PEAR installation is not required on server. We try at first to include the real PEAR file, and if this fails we then define our version. */ $ok= @include("Archive/Tar.php"); if (!$ok) { /* We did not find the file, so we define the class here */ /* The rest of this file is copied from the PEAR package */ /* PEAR.php file content */ // // +----------------------------------------------------------------------+ [...2556 lines suppressed...] { if (OS_WINDOWS) { // ----- Look for potential disk letter if (($p_remove_disk_letter) && (($v_position = strpos($p_path, ':')) != false)) { $p_path = substr($p_path, $v_position+1); } // ----- Change potential windows directory separator if ((strpos($p_path, '\\') > 0) || (substr($p_path, 0,1) == '\\')) { $p_path = strtr($p_path, '\\', '/'); } } return $p_path; } // }}} } /* Done */ } ?> Index: index.php =================================================================== RCS file: /cvsroot/tslogparser/web/admin/index.php,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- index.php 12 Jan 2005 15:49:03 -0000 1.1 +++ index.php 27 Jan 2005 10:37:52 -0000 1.2 @@ -53,6 +53,7 @@ /* We'll need functions defined in other files */ require($root."database.inc.php"); require($root."functions.inc.php"); +require($root."admin/tar.inc.php"); /* Handle tar files */ /* We'll need the database connexion */ db_init(); @@ -66,6 +67,7 @@ $modules=$tslp->list_modules(); +/* We copy some variables from the POST array to the GET array */ if (isset($_POST["action"])) { $_GET["action"]=$_POST["action"]; @@ -79,6 +81,13 @@ $_GET["run_name"] = $_POST["run_name"]; if (isset($_POST["run_descr"])) $_GET["run_descr"] = $_POST["run_descr"]; + + if (isset($_POST["add_ts"])) + $_GET["add_ts"] = $_POST["add_ts"]; + if (isset($_POST["ts_name"])) + $_GET["ts_name"] = $_POST["ts_name"]; + if (isset($_POST["ts_descr"])) + $_GET["ts_descr"] = $_POST["ts_descr"]; } /* Parse the GET parameters if any */ @@ -143,18 +152,17 @@ *****************************/ if (isset($_GET["add_ts"])) { - /* Check Step 3 parameters and eventually fall back to step 2 */ if (!isset($_GET["ts_name"])) $_GET["ts_name"]=""; if (!isset($_GET["ts_descr"])) $_GET["ts_descr"]=""; - if (!isset($_GET["ts_root"])) - $_GET["ts_root"]=""; +// if (!isset($_GET["ts_root"])) +// $_GET["ts_root"]=""; if (($_GET["action"] == 2) - && ( !trim($_GET["ts_name"]) - || !trim($_GET["ts_root"]))) + && ( !trim($_GET["ts_name"]) + || !isset($_FILES['tsarchive']))) { echo "<p>Please fill all <b>(*) fields.</b></p>\n"; $_GET["action"] = 1; @@ -162,22 +170,76 @@ if ($_GET["action"] == 2) { + /* Check the uploaded file type */ + if (!isset($_FILES['tsarchive'])) + { + echo "<b>Invalid parameters</b>\n"; + db_fini(); + require($root."footer.inc.php"); + die(); + } + if (( $_FILES['tsarchive']['type'] != "application/x-gzip-compressed") + && ($_FILES['tsarchive']['type'] != "application/x-gzip")) + { + echo "<b>You have to supply the testsuite in a tar gzip'd format.</b>\n"; + db_fini(); + require($root."footer.inc.php"); + die(); + } + + /* Try expanding the archive */ + $tar = new Archive_Tar($_FILES['tsarchive']['tmp_name']); + $tar->setErrorHandling(PEAR_ERROR_PRINT); + + $tmpdir = $root."ts/".time(); + + if (!$tar->extractModify($tmpdir, "ts")) + { + echo "<b>Archive extraction failed.</b>\n"; + + db_fini(); + require($root."footer.inc.php"); + die(); + } + /* Here we're in step 2 in process: ready to proceed */ echo "<pre>\n"; - $tmp = $tslp->TS_parse($_GET["ts_name"], $_GET["ts_descr"], $_GET["ts_root"]); + $tmp = $tslp->TS_parse($_GET["ts_name"], $_GET["ts_descr"], $tmpdir); echo "</pre>\n"; if (!$tmp) { $_GET["action"] = 1; echo "<p><b>Error:</b> <i>".$tslp->last_error."</i>.</p>\n"; } + + /* In any case, remove the extracted archive now. */ + function deldir($dir) { + $dh=opendir($dir); + while ($file=readdir($dh)) { + if($file!="." && $file!="..") { + $fullpath=$dir."/".$file; + if(!is_dir($fullpath)) { + unlink($fullpath); + } else { + deldir($fullpath); + } + } + } + + closedir($dh); + + rmdir($dir); + } + + deldir($tmpdir); } if ($_GET["action"] < 2) { /* Output the new testsuite form */ - echo "<form method=\"GET\">\n"; + echo "<form enctype=\"multipart/form-data\" method=\"POST\">\n"; + echo " <input type=\"hidden\" name=\"MAX_FILE_SIZE\" value=\"2097152\">"; echo " <input type=\"hidden\" name=\"action\" value=\"2\">\n"; echo " <input type=\"hidden\" name=\"add_ts\" value=\"add\">\n"; echo " <input type=\"hidden\" name=\"module\" value=\"".$_GET["module"]."\">\n"; @@ -201,8 +263,8 @@ <td><textarea name="ts_descr" rows="3" cols="79"><?php echo $_GET["ts_descr"]; ?></textarea></td> </tr> <tr> - <td>Path to new release(*):</td> - <td><input type="text" name="ts_root" size="80" value=<?php echo "\"".$_GET["ts_root"]."\""; ?>></td> + <td>New release archive (tar.gz expanding in 'ts' directory):</td> + <td><input name="tsarchive" type="file"></td> </tr> <tr> <td colspan=2 align=center><input type="submit" name="send" value="Send"></td> @@ -216,11 +278,6 @@ die(); } - /* Here we're in step 2 in process: ready to proceed */ - - $tslp->select_module($_GET["module"]) or die("Invalid plugin"); - - $tmp = $tslp->TS_parse($_GET["ts_name"], $_GET["ts_descr"], $_GET["ts_root"]); } |