From d118769d8ca25cd406ceb7412b84aa87f97c808f Mon Sep 17 00:00:00 2001 From: eric Date: Sun, 24 Oct 2004 20:55:30 +0000 Subject: just a little work on it - still have some code and plenty of debugging to do --- web/html/pkgsubmit.php | 268 +++++++++++++++++++++++++++---------------------- 1 file changed, 148 insertions(+), 120 deletions(-) (limited to 'web/html/pkgsubmit.php') diff --git a/web/html/pkgsubmit.php b/web/html/pkgsubmit.php index 4439911..1b986cc 100644 --- a/web/html/pkgsubmit.php +++ b/web/html/pkgsubmit.php @@ -1,6 +1,7 @@ " . $msg . "
\n"; - print "\n"; - html_footer("\$Id$"); - exit(); -} if ($_COOKIE["AURSID"]) { # track upload errors @@ -37,7 +32,9 @@ if ($_COOKIE["AURSID"]) { if (!$_REQUEST["pkgname"]) { $error = __("You did not specify a package name."); } else { - $pkg_name = escapeshellarg($_REQUEST["pkgname"]); + $pkg_name = str_replace("'", "", $_REQUEST["pkgname"]); + $pkg_name = escapeshellarg($pkg_name); + $pkg_name = str_replace("'", "", $pkg_name); # get rid of single quotes $presult = preg_match("/^[a-z][a-z0-9_-]*$/", $pkg_name); if ($presult == FALSE || $presult <= 0) { # FALSE => error processing regex, 0 => invalid characters @@ -47,9 +44,7 @@ if ($_COOKIE["AURSID"]) { } if (!$error && (!$_REQUEST["comments"] || $_REQUEST["comments"] == '')) { - $error = __("You must supply a comment."); - } else { - print exitError($error); + $error = __("You must supply a comment for this upload/change."); } if (!$error) { @@ -69,10 +64,15 @@ if ($_COOKIE["AURSID"]) { array("", $pkg_name, "")); } } - } else { - print exitError($error); } + # TODO check to see if the user has the ability to 'change' package + # attributes such as location and/or category. Examples: TUs can + # only add/change packages in Unsupported and the AUR, normal users + # can only add/change packages in Unsupported. + # + + if (!$error) { # no errors checking upload permissions, go ahead and try to process # the uploaded package file. @@ -93,36 +93,33 @@ if ($_COOKIE["AURSID"]) { # $error = __("Error trying to upload file - please try again."); } - } else { - print exitError($error); } # at this point, we can safely unpack the uploaded file and parse # its contents. # - if (!@mkdir($INCOMING_DIR.$pkg_name)) { - $error = __("Could not create incoming directory: %s.", - array($INCOMING_DIR.$pkg_name)); - } else { - if (!@chdir($INCOMING_DIR.$pkg_name)) { - $error = __("Could not change directory to %s.", - array($INCOMING_DIR.$pkg_name)); - } else { - # try .gz first - # - exec("/bin/sh -c 'tar xzf ".$upload_file."'", $retval); - if (!$retval) { - # now try .bz2 format - # - exec("/bin/sh -c 'tar xjf ".$upload_file."'", $retval); - } - if (!$retval) { - $error = __("Unknown file format for uploaded file."); - } - } - } - if ($error) { - print exitError($error); + if (!$error) { + if (!@mkdir($INCOMING_DIR.$pkg_name)) { + $error = __("Could not create incoming directory: %s.", + array($INCOMING_DIR.$pkg_name)); + } else { + if (!@chdir($INCOMING_DIR.$pkg_name)) { + $error = __("Could not change directory to %s.", + array($INCOMING_DIR.$pkg_name)); + } else { + # try .gz first + # + @exec("/bin/sh -c 'tar xzf ".$upload_file."'", $trash, $retval); + if (!$retval) { + # now try .bz2 format + # + @exec("/bin/sh -c 'tar xjf ".$upload_file."'", $trash, $retval); + } + if (!$retval) { + $error = __("Unknown file format for uploaded file."); + } + } + } } # At this point, if no error exists, the package has been extracted @@ -131,39 +128,41 @@ if ($_COOKIE["AURSID"]) { # packaged without the $pkg_name subdirectory, try and create it # and move the package contents into the new sub-directory. # - if (is_dir($INCOMING_DIR.$pkg_name."/".$pkg_name) && - is_file($INCOMING_DIR.$pkg_name."/".$pkg_name."/PKGBUILD")) { - # the files were packaged correctly - # - if (!chdir($INCOMING_DIR.$pkg_name."/".$pkg_name)) { - $error = __("Could not change to directory %s.", - array($INCOMING_DIR.$pkg_name."/".$pkg_name)); - } - $pkg_dir = $INCOMING_DIR.$pkg_name."/".$pkg_name; - } elseif (is_file($INCOMING_DIR.$pkg_name."/PKGBUILD")) { - # not packaged correctly, but recovery may be possible. - # try and create $INCOMING_DIR.$pkg_name."/".$pkg_name and - # move package contents into the new dir - # - if (!@mkdir($INCOMING_DIR.$pkg_name."/".$pkg_name)) { - $error = __("Could not create directory %s.", - array($INCOMING_DIR.$pkg_name."/".$pkg_name)); - } else { - exec("/bin/sh -c 'mv * ".$pkg_name."'"); - if (!file_exists($INCOMING_DIR.$pkg_name."/".$pkg_name."/PKGBUILD")) { - $error = __("Error exec'ing the mv command."); - } - } - if (!@chdir($INCOMING_DIR.$pkg_name."/".$pkg_name)) { - $error = __("Could not change to directory %s.", - array($INCOMING_DIR.$pkg_name."/".$pkg_name)); - } - $pkg_dir = $INCOMING_DIR.$pkg_name."/".$pkg_name; - } else { - # some wierd packaging/extraction error - baal - # - $error = __("Error trying to unpack upload - PKGBUILD does not exist."); - } + if (!$error) { + if (is_dir($INCOMING_DIR.$pkg_name."/".$pkg_name) && + is_file($INCOMING_DIR.$pkg_name."/".$pkg_name."/PKGBUILD")) { + # the files were packaged correctly + # + if (!@chdir($INCOMING_DIR.$pkg_name."/".$pkg_name)) { + $error = __("Could not change to directory %s.", + array($INCOMING_DIR.$pkg_name."/".$pkg_name)); + } + $pkg_dir = $INCOMING_DIR.$pkg_name."/".$pkg_name; + } elseif (is_file($INCOMING_DIR.$pkg_name."/PKGBUILD")) { + # not packaged correctly, but recovery may be possible. + # try and create $INCOMING_DIR.$pkg_name."/".$pkg_name and + # move package contents into the new dir + # + if (!@mkdir($INCOMING_DIR.$pkg_name."/".$pkg_name)) { + $error = __("Could not create directory %s.", + array($INCOMING_DIR.$pkg_name."/".$pkg_name)); + } else { + @exec("/bin/sh -c 'mv * ".$pkg_name."'"); + if (!file_exists($INCOMING_DIR.$pkg_name."/".$pkg_name."/PKGBUILD")) { + $error = __("Error exec'ing the mv command."); + } + } + if (!@chdir($INCOMING_DIR.$pkg_name."/".$pkg_name)) { + $error = __("Could not change to directory %s.", + array($INCOMING_DIR.$pkg_name."/".$pkg_name)); + } + $pkg_dir = $INCOMING_DIR.$pkg_name."/".$pkg_name; + } else { + # some wierd packaging/extraction error - baal + # + $error = __("Error trying to unpack upload - PKGBUILD does not exist."); + } + } # if no error, get list of directory contents and process PKGBUILD # @@ -271,60 +270,64 @@ if ($_COOKIE["AURSID"]) { } } } - if ($error) { - print exitError($error); - } - print "Groovy!!! - We're all set to populate the database!!
\n"; - print "\n"; - html_footer("\$Id$"); - exit(); + # TODO This is where other additional error checking can be + # performed. Examples: #md5sums == #sources?, md5sums of any + # included files match?, install scriptlet file exists? + # + + + # Now, run through the pkgbuild array and do any $pkgname/$pkgver + # substituions. + # + if (!$error) { + $pkgname_var = $pkgbuild["pkgname"]; + $pkgver_var = $pkgbuild["pkgver"]; + $new_pkgbuild = array(); + while (list($k, $v) = each($pkgbuild)) { + $v = str_replace("\$pkgname", $pkgname_var, $v); + $v = str_replace("\$pkgver", $pkgver_var, $v); + $new_pkgbuild[$k] = $v; + } + } - # update the backend database if there are no errors + # update the backend database # - if (!$error) { - $dbh = db_connect(); - if ($pkg_exists) { - - # this is an overwrite of an existing package, the database ID - # needs to be preserved so that any votes are retained. However, - # PackageDepends, PackageSources, and PackageContents can be - # purged. - # - $q = "SELECT * FROM Packages "; - $q.= "WHERE Name = '".mysql_escape_string($_FILES["pfile"]["name"])."'"; - $result = db_query($q, $dbh); - $pdata = mysql_fetch_assoc($result); - - # flush out old data that will be replaced with new data - # - $q = "DELETE FROM PackageContents WHERE PackageID = ".$pdata["ID"]; - db_query($q, $dbh); - $q = "DELETE FROM PackageDepends WHERE PackageID = ".$pdata["ID"]; - db_query($q, $dbh); - $q = "DELETE FROM PackageSources WHERE PackageID = ".$pdata["ID"]; - db_query($q, $dbh); - - # TODO - # $q = "UPDATE Packages ..." + if (!$error) { + $dbh = db_connect(); + if ($pkg_exists) { + + # this is an overwrite of an existing package, the database ID + # needs to be preserved so that any votes are retained. However, + # PackageDepends, PackageSources, and PackageContents can be + # purged. + # + $q = "SELECT * FROM Packages "; + $q.= "WHERE Name = '".mysql_escape_string($_FILES["pfile"]["name"])."'"; + $result = db_query($q, $dbh); + $pdata = mysql_fetch_assoc($result); + + # flush out old data that will be replaced with new data + # + $q = "DELETE FROM PackageContents WHERE PackageID = ".$pdata["ID"]; + db_query($q, $dbh); + $q = "DELETE FROM PackageDepends WHERE PackageID = ".$pdata["ID"]; + db_query($q, $dbh); + $q = "DELETE FROM PackageSources WHERE PackageID = ".$pdata["ID"]; + db_query($q, $dbh); + + # TODO + # $q = "UPDATE Packages ..." # $q = "INSERT INTO PackageUploadHistory ..." - } else { - # this is a brand new package - # - # TODO - # $q = "INSERT ..." - } - } - - # TODO clean up on error? How much cleaning to do? - # - if ($error) { - # TODO clean house (filesystem/database) - # - } - + } else { + # this is a brand new package + # + # TODO + # $q = "INSERT ..." + } + } } @@ -337,6 +340,9 @@ if ($_COOKIE["AURSID"]) { print "".$error."
\n"; print "
 
\n"; } + $pkg_categories = pkgCategories(); + $pkg_locations = pkgLocations(); + print "
\n"; print "\n"; @@ -350,6 +356,28 @@ if ($_COOKIE["AURSID"]) { print "\n"; print " \n"; print "\n"; + print "\n"; + print " "; + print __("Package Category").":\n"; + print " "; + print "\n"; + print "\n"; + print "\n"; + print " "; + print __("Package Location").":\n"; + print " "; + print "\n"; + print "\n"; print "\n"; print " "; print __("Upload package file").":\n"; @@ -362,9 +390,9 @@ if ($_COOKIE["AURSID"]) { print __("Overwrite existing package?"); print " \n"; print " "; - print " ".__("Yes"); + print " ".__("Yes"); print "   "; - print " "; + print " "; print __("No"); print " \n"; print "\n"; -- cgit v1.2.3-70-g09d2