From: Sebastien D. <sde...@us...> - 2005-01-26 17:49:30
|
Update of /cvsroot/tslogparser/tslogparser/admin In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv32037/admin Modified Files: index.php Log Message: New method for testsuite uploading Index: index.php =================================================================== RCS file: /cvsroot/tslogparser/tslogparser/admin/index.php,v retrieving revision 1.7 retrieving revision 1.8 diff -u -d -r1.7 -r1.8 --- index.php 7 Jan 2005 14:28:34 -0000 1.7 +++ index.php 26 Jan 2005 17:48:52 -0000 1.8 @@ -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"]); } |