3 set_include_path(get_include_path() . PATH_SEPARATOR
. '../lib' . PATH_SEPARATOR
. '../lang');
5 include("aur.inc"); # access AUR common functions
6 include("submit_po.inc"); # use some form of this for i18n support
7 include("pkgfuncs.inc"); # package functions
8 include("config.inc"); # configuration file with dir locations
9 set_lang(); # this sets up the visitor's language
10 check_sid(); # see if they're still logged in
11 html_header(); # print out the HTML header
17 if ($_COOKIE["AURSID"]) {
22 print "</center><pre>\n";
26 print "</pre><center>\n";
29 if ($_REQUEST["pkgsubmit"]) {
30 # If this var is set, then the visitor is uploading a file...
32 if (!$_REQUEST["pkgname"]) {
33 $error = __("You did not specify a package name.");
35 $pkg_name = str_replace("'", "", $_REQUEST["pkgname"]);
36 $pkg_name = escapeshellarg($pkg_name);
37 $pkg_name = str_replace("'", "", $pkg_name); # get rid of single quotes
39 # Solves the problem when you try to submit PKGBUILD
40 # that have the name with a period like (gstreamer0.10)
41 # Added support for packages with + characters like (mysql++).
42 $presult = preg_match("/^[a-z0-9][a-z0-9\.+_-]*$/", $pkg_name);
44 if ($presult == FALSE ||
$presult <= 0) {
45 # FALSE => error processing regex, 0 => invalid characters
47 $error = __("Invalid name: only lowercase letters are allowed.");
51 if (!$error && (!$_REQUEST["comments"] ||
$_REQUEST["comments"] == '')) {
52 $error = __("You must supply a comment for this upload/change.");
56 # first, see if this package already exists, and if it can be overwritten
58 $pkg_exists = package_exists($pkg_name);
60 # ok, it exists - should it be overwritten, and does the user have
61 # the permissions to do so?
63 if (can_overwrite_pkg($pkg_name, $_COOKIE["AURSID"])) {
64 if (!$_REQUEST["overwrite"]) {
65 $error = __("You did not tag the 'overwrite' checkbox.");
68 $error = __("You are not allowed to overwrite the %h%s%h package.",
69 array("<b>", $pkg_name, "</b>"));
74 # TODO check to see if the user has the ability to 'change' package
75 # attributes such as location and/or category. Examples: TUs can
76 # only add/change packages in Unsupported and the AUR, normal users
77 # can only add/change packages in Unsupported.
80 #Before processing, make sure we even have a file
82 if ($_FILES['pfile']['size'] == 0){
83 $error = __("Error - No file uploaded");
87 # no errors checking upload permissions, go ahead and try to process
88 # the uploaded package file.
91 $upload_file = $UPLOAD_DIR . $_FILES["pfile"]["name"];
93 if (move_uploaded_file($_FILES["pfile"]["tmp_name"], $upload_file)) {
96 if (file_exists($INCOMING_DIR . $pkg_name)) {
97 # blow away the existing file/dir and contents
99 rm_rf($INCOMING_DIR . $pkg_name);
103 # errors uploading file...
105 $error = __("Error trying to upload file - please try again.");
109 # at this point, we can safely unpack the uploaded file and parse
114 if (!@mkdir
($INCOMING_DIR.$pkg_name)) {
115 $error = __("Could not create incoming directory: %s.",
116 array($INCOMING_DIR.$pkg_name));
118 if (!@chdir
($INCOMING_DIR.$pkg_name)) {
119 $error = __("Could not change directory to %s.",
120 array($INCOMING_DIR.$pkg_name));
124 exec("/bin/sh -c 'tar xzf ".$upload_file."'", $trash, $retval);
126 # now try .bz2 format
128 exec("/bin/sh -c 'tar xjf ".$upload_file."'", $trash, $retval);
131 $error = __("Unknown file format for uploaded file.");
137 # At this point, if no error exists, the package has been extracted
138 # There should be a $INCOMING_DIR.$pkg_name."/".$pkg_name directory
139 # if the user packaged it correctly. However, if the file was
140 # packaged without the $pkg_name subdirectory, try and create it
141 # and move the package contents into the new sub-directory.
144 if (is_dir($INCOMING_DIR.$pkg_name."/".$pkg_name) &&
145 is_file($INCOMING_DIR.$pkg_name."/".$pkg_name."/PKGBUILD")) {
146 # the files were packaged correctly
148 if (!@chdir
($INCOMING_DIR.$pkg_name."/".$pkg_name)) {
149 $error = __("Could not change to directory %s.",
150 array($INCOMING_DIR.$pkg_name."/".$pkg_name));
152 $pkg_dir = $INCOMING_DIR.$pkg_name."/".$pkg_name;
153 } elseif (is_file($INCOMING_DIR.$pkg_name."/PKGBUILD")) {
154 # not packaged correctly, but recovery may be possible.
155 # try and create $INCOMING_DIR.$pkg_name."/".$pkg_name and
156 # move package contents into the new dir
158 if (!@mkdir
($INCOMING_DIR.$pkg_name."/".$pkg_name)) {
159 $error = __("Could not create directory %s.",
160 array($INCOMING_DIR.$pkg_name."/".$pkg_name));
162 exec("/bin/sh -c 'mv * ".$pkg_name."'");
163 if (!file_exists($INCOMING_DIR.$pkg_name."/".$pkg_name."/PKGBUILD")) {
164 $error = __("Error exec'ing the mv command.");
167 if (!@chdir
($INCOMING_DIR.$pkg_name."/".$pkg_name)) {
168 $error = __("Could not change to directory %s.",
169 array($INCOMING_DIR.$pkg_name."/".$pkg_name));
171 $pkg_dir = $INCOMING_DIR.$pkg_name."/".$pkg_name;
173 # some wierd packaging/extraction error - baal
175 $error = __("Error trying to unpack upload - PKGBUILD does not exist.");
179 $shcmd = "/bin/mv ".$upload_file." ";
180 $shcmd.= escapeshellarg($INCOMING_DIR.$pkg_name."/".$_FILES["pfile"]["name"]);
183 # if no error, get list of directory contents and process PKGBUILD
189 $pkg_contents = array();
190 while ($f = $d->read()) {
191 if ($f != "." && $f != "..") {
192 $pkg_contents[$f] = filesize($f);
193 if (preg_match("/^(.*\.pkg\.tar\.gz|filelist)$/", $f)) {
194 $error = __("Binary packages and filelists are not allowed for upload.");
200 # process PKGBIULD - remove line concatenation
203 $fp = fopen($pkg_dir."/PKGBUILD", "r");
206 $continuation_line = 0;
209 $line = trim(fgets($fp));
210 $char_counts = count_chars($line, 0);
211 if (substr($line, strlen($line)-1) == "\\") {
212 # continue appending onto existing line_no
214 $current_line .= substr($line, 0, strlen($line)-1);
215 $continuation_line = 1;
216 } elseif ($char_counts[ord('(')] > $char_counts[ord(')')]) {
217 # assumed continuation
218 # continue appending onto existing line_no
220 $current_line .= $line . " ";
221 $continuation_line = 1;
223 # maybe the last line in a continuation, or a standalone line?
225 if ($continuation_line) {
226 # append onto existing line_no
228 $current_line .= $line;
229 $lines[$line_no] = $current_line;
234 $lines[$line_no] = $line;
236 $continuation_line = 0;
242 # Now process the lines and put any var=val lines into the
243 # 'pkgbuild' array. Also check to make sure it has the build()
246 $seen_build_function = 0;
247 while (list($k, $line) = each($lines)) {
248 $lparts = explode("=", $line, 2);
249 if (count($lparts) == 2) {
250 # this is a variable/value pair, strip out
251 # array parens and any quoting, except in pkgdesc
252 # for pkgdesc, only remove start/end pairs of " or '
253 if ($lparts[0]=="pkgdesc") {
254 if ($lparts[1]{0} == '"' &&
255 $lparts[1]{strlen($lparts[1])-1} == '"') {
256 $pkgbuild[$lparts[0]] = substr($lparts[1], 1, -1);
259 ($lparts[1]{0} == "'" &&
260 $lparts[1]{strlen($lparts[1])-1} == "'") {
261 $pkgbuild[$lparts[0]] = substr($lparts[1], 1, -1);
263 $pkgbuild[$lparts[0]] = $lparts[1];
266 $pkgbuild[$lparts[0]] = str_replace(array("(",")","\"","'"), "",
270 # either a comment, blank line, continued line, or build function
272 if (substr($lparts[0], 0, 5) == "build") {
273 $seen_build_function = 1;
276 # XXX: closes bug #2280? Might as well let the loop complete rather
277 # than break after the build() function.
279 #if ($seen_build_function) {break;}
282 # some error checking on PKGBUILD contents - just make sure each
283 # variable has a value. This does not do any validity checking
284 # on the values, or attempts to fix line continuation/wrapping.
286 if (!$seen_build_function) {
287 $error = __("Missing build function in PKGBUILD.");
289 if (!array_key_exists("md5sums", $pkgbuild)) {
290 $error = __("Missing md5sums variable in PKGBUILD.");
292 if (!array_key_exists("source", $pkgbuild)) {
293 $error = __("Missing source variable in PKGBUILD.");
295 if (!array_key_exists("url", $pkgbuild)) {
296 $error = __("Missing url variable in PKGBUILD.");
298 if (!array_key_exists("pkgdesc", $pkgbuild)) {
299 $error = __("Missing pkgdesc variable in PKGBUILD.");
301 if (!array_key_exists("license", $pkgbuild)) {
302 $error = __("Missing license variable in PKGBUILD.");
304 if (!array_key_exists("pkgrel", $pkgbuild)) {
305 $error = __("Missing pkgrel variable in PKGBUILD.");
307 if (!array_key_exists("pkgver", $pkgbuild)) {
308 $error = __("Missing pkgver variable in PKGBUILD.");
310 if (!array_key_exists("arch", $pkgbuild)) {
311 $error = __("Missing arch variable in PKGBUILD.");
313 if (!array_key_exists("pkgname", $pkgbuild)) {
314 $error = __("Missing pkgname variable in PKGBUILD.");
316 if ($pkgbuild["pkgname"] != $pkg_name) {
317 $error = __("Package names do not match.");
322 # TODO This is where other additional error checking can be
323 # performed. Examples: #md5sums == #sources?, md5sums of any
324 # included files match?, install scriptlet file exists?
327 # Check for http:// or other protocol in url
330 $parsed_url = parse_url($pkgbuild['url']);
331 if (!$parsed_url['scheme']) {
332 $error = __("Package URL is missing a protocol (ie. http:// ,ftp://)");
336 # Now, run through the pkgbuild array and do any $pkgname/$pkgver
339 #TODO: run through and do ALL substitutions, to cover custom vars
341 $pkgname_var = $pkgbuild["pkgname"];
342 $pkgver_var = $pkgbuild["pkgver"];
343 $new_pkgbuild = array();
344 while (list($k, $v) = each($pkgbuild)) {
345 $v = str_replace("\$pkgname", $pkgname_var, $v);
346 $v = str_replace("\${pkgname}", $pkgname_var, $v);
347 $v = str_replace("\$pkgver", $pkgver_var, $v);
348 $v = str_replace("\${pkgver}", $pkgver_var, $v);
349 $new_pkgbuild[$k] = $v;
353 # Re-tar the package for consistency's sake
356 if (!@chdir
($INCOMING_DIR.$pkg_name)) {
357 $error = __("Could not change directory to %s.",
358 array($INCOMING_DIR.$pkg_name));
362 @exec
("/bin/sh -c 'tar czf ".$pkg_name.".tar.gz ".$pkg_name."'", $trash, $retval);
364 $error = __("Could not re-tar");
367 # update the backend database
371 # this is an overwrite of an existing package, the database ID
372 # needs to be preserved so that any votes are retained. However,
373 # PackageDepends, PackageSources, and PackageContents can be
376 $q = "SELECT * FROM Packages ";
377 $q.= "WHERE Name = '".mysql_real_escape_string($new_pkgbuild['pkgname'])."'";
378 $result = db_query($q, $dbh);
379 $pdata = mysql_fetch_assoc($result);
383 # flush out old data that will be replaced with new data
385 $q = "DELETE FROM PackageContents WHERE PackageID = ".$pdata["ID"];
387 $q = "DELETE FROM PackageDepends WHERE PackageID = ".$pdata["ID"];
389 $q = "DELETE FROM PackageSources WHERE PackageID = ".$pdata["ID"];
392 # update package data
394 $q = "UPDATE Packages SET ";
395 # if the package was a dummy, undummy it and change submitter
396 # also give it a maintainer so we dont go making an orphan
397 if ($pdata['DummyPkg'] == 1) {
398 $q.= "DummyPkg = 0, ";
399 $q.= "SubmitterUID = ".uid_from_sid($_COOKIE["AURSID"]).", ";
400 $q.= "MaintainerUID = ".uid_from_sid($_COOKIE["AURSID"]).", ";
401 $q.= "SubmittedTS = UNIX_TIMESTAMP(), ";
403 $q.="ModifiedTS = UNIX_TIMESTAMP(), ";
405 $q.="Name='".mysql_real_escape_string($new_pkgbuild['pkgname'])."', ";
406 $q.="Version='".mysql_real_escape_string($new_pkgbuild['pkgver'])."-".
407 mysql_real_escape_string($new_pkgbuild['pkgrel'])."',";
408 $q.="CategoryID=".mysql_real_escape_string($_REQUEST['category']).", ";
409 $q.="License='".mysql_real_escape_string($new_pkgbuild['license'])."', ";
410 $q.="Description='".mysql_real_escape_string($new_pkgbuild['pkgdesc'])."', ";
411 $q.="URL='".mysql_real_escape_string($new_pkgbuild['url'])."', ";
412 $q.="LocationID=2, ";
413 if (account_from_sid($_COOKIE["AURSID"]) == "Trusted User" ||
account_from_sid($_COOKIE["AURSID"]) == "Developer") {
414 $q.="Safe=1, VerifiedBy=".uid_from_sid($_COOKIE["AURSID"]).", ";
418 $fspath=$INCOMING_DIR.$pkg_name."/".$_FILES["pfile"]["name"];
419 $q.="FSPath='".mysql_real_escape_string($fspath)."', ";
420 $urlpath=$URL_DIR.$pkg_name."/".$_FILES["pfile"]["name"];
421 $q.="URLPath='".mysql_real_escape_string($urlpath)."' ";
422 $q.="WHERE ID = " . $pdata["ID"];
423 $result = db_query($q, $dbh);
425 # update package contents
427 while (list($k, $v) = each($pkg_contents)) {
428 $q = "INSERT INTO PackageContents ";
429 $q.= "(PackageID, FSPath, URLPath, FileSize) VALUES (";
430 $q.= $pdata['ID'].", ";
431 $q.= "'".$INCOMING_DIR.$pkg_name."/".$pkg_name."/".$k."', ";
432 $q.= "'".$URL_DIR.$pkg_name."/".$pkg_name."/".$k."', ";
437 # update package depends
439 $depends = explode(" ", $new_pkgbuild['depends']);
441 while (list($k, $v) = each($depends)) {
442 $q = "INSERT INTO PackageDepends (PackageID, DepPkgID, DepCondition) VALUES (";
443 $deppkgname = preg_replace("/[<>]?=.*/", "", $v);
444 $depcondition = str_replace($deppkgname, "", $v);
446 # Solve the problem with comments and deps
447 # added by: dsa <dsandrade@gmail.com>
448 if ($deppkgname == "#")
451 $deppkgid = create_dummy($deppkgname, $_COOKIE['AURSID']);
453 if(!empty($depcondition))
454 $q .= $pdata["ID"].", ".$deppkgid.", '".$depcondition."')";
456 $q .= $pdata["ID"].", ".$deppkgid.", '')";
461 $sources = explode(" ", $new_pkgbuild['source']);
462 while (list($k, $v) = each($sources)) {
463 $q = "INSERT INTO PackageSources (PackageID, Source) VALUES (";
464 $q .= $pdata["ID"].", '".mysql_real_escape_string($v)."')";
470 $q = "INSERT INTO PackageComments ";
471 $q.= "(PackageID, UsersID, Comments, CommentTS) VALUES (";
472 $q.= $pdata["ID"] . ", " . uid_from_sid($_COOKIE['AURSID']);
473 $q.= ", '" . mysql_real_escape_string($_REQUEST["comments"]);
474 $q.= "', UNIX_TIMESTAMP())";
478 # this is a brand new package
480 $q = "INSERT INTO Packages ";
481 $q.= " (Name, License, Version, CategoryID, Description, URL, LocationID, ";
482 if (account_from_sid($_COOKIE["AURSID"]) == "Trusted User" ||
account_from_sid($_COOKIE["AURSID"]) == "Developer") {
483 $q.= "Safe, VerifiedBy,";
485 $q.= " SubmittedTS, SubmitterUID, MaintainerUID, FSPath, URLPath) ";
487 $q.= mysql_real_escape_string($new_pkgbuild['pkgname'])."', '";
488 $q.= mysql_real_escape_string($new_pkgbuild['license'])."', '";
489 $q.= mysql_real_escape_string($new_pkgbuild['pkgver'])."-".
490 mysql_real_escape_string($new_pkgbuild['pkgrel'])."', ";
491 $q.= mysql_real_escape_string($_REQUEST['category']).", '";
492 $q.= mysql_real_escape_string($new_pkgbuild['pkgdesc'])."', '";
493 $q.= mysql_real_escape_string($new_pkgbuild['url']);
495 if (account_from_sid($_COOKIE["AURSID"]) == "Trusted User" ||
account_from_sid($_COOKIE["AURSID"]) == "Developer") {
496 $q.= "1, ".uid_from_sid($_COOKIE["AURSID"]).", ";
498 $q.= "UNIX_TIMESTAMP(), ";
499 $q.= uid_from_sid($_COOKIE["AURSID"]).", ";
500 $q.= uid_from_sid($_COOKIE["AURSID"]).", '";
501 $fspath=$INCOMING_DIR.$pkg_name."/".$_FILES["pfile"]["name"];
502 $q.= mysql_real_escape_string($fspath)."', '";
503 $urlpath=$URL_DIR.$pkg_name."/".$_FILES["pfile"]["name"];
504 $q.= mysql_real_escape_string($urlpath)."')";
505 $result = db_query($q, $dbh);
506 # print $result . "<br>";
508 $packageID = mysql_insert_id($dbh);
510 # update package contents
512 while (list($k, $v) = each($pkg_contents)) {
513 $q = "INSERT INTO PackageContents ";
514 $q.= "(PackageID, FSPath, URLPath, FileSize) VALUES (";
515 $q.= $packageID.", ";
516 $q.= "'".$INCOMING_DIR.$pkg_name."/".$pkg_name."/".$k."', ";
517 $q.= "'".$URL_DIR.$pkg_name."/".$pkg_name."/".$k."', ";
522 # update package depends
524 $depends = explode(" ", $new_pkgbuild['depends']);
525 while (list($k, $v) = each($depends)) {
526 $q = "INSERT INTO PackageDepends (PackageID, DepPkgID) VALUES (";
527 $deppkgname = preg_replace("/[<>]?=.*/", "", $v);
529 # Solve the problem with comments and deps
530 # added by: dsa <dsandrade@gmail.com>
531 if ($deppkgname == "#")
534 $deppkgid = create_dummy($deppkgname, $_COOKIE['AURSID']);
535 $q .= $packageID.", ".$deppkgid.")";
539 $sources = explode(" ", $new_pkgbuild['source']);
540 while (list($k, $v) = each($sources)) {
541 $q = "INSERT INTO PackageSources (PackageID, Source) VALUES (";
542 $q .= $packageID.", '".mysql_real_escape_string($v)."')";
548 $q = "INSERT INTO PackageComments ";
549 $q.= "(PackageID, UsersID, Comments, CommentTS) VALUES (";
550 $q.= $packageID . ", " . uid_from_sid($_COOKIE["AURSID"]) . ", '";
551 $q.= mysql_real_escape_string($_REQUEST["comments"]);
552 $q.= "', UNIX_TIMESTAMP())";
559 if (!$_REQUEST["pkgsubmit"] ||
$error) {
560 # User is not uploading, or there were errors uploading - then
561 # give the visitor the default upload form
563 if (ini_get("file_uploads")) {
565 print "<span class='error'>".$error."</span><br />\n";
566 print "<br /> <br />\n";
570 print "<br><span class='error'>".$warning."</span><br />\n";
571 print "<br /> <br />\n";
574 $pkg_categories = pkgCategories();
575 $pkg_locations = pkgLocations();
577 print "<form action='/pkgsubmit.php' method='post'";
578 print " enctype='multipart/form-data'>\n";
579 print "<input type='hidden' name='pkgsubmit' value='1' />\n";
580 print "<input type='hidden' name='MAX_FILE_SIZE' value='";
581 print initeger(ini_get("upload_max_filesize"))."' />\n";
582 print "<table border='0' cellspacing='5'>\n";
584 print " <td span='f4' align='right'>";
585 print __("Package name").":</td>\n";
586 print " <td span='f4' align='left'>";
587 print "<input type='text' name='pkgname' size='30' maxlength='32' />\n";
591 print " <td span='f4' align='right'>";
592 print __("Package Category").":</td>\n";
593 print " <td span='f4' align='left'>";
594 print "<select name='category'>";
595 print "<option value='1'> " . __("Select Category") . "</option>";
596 while (list($k, $v) = each($pkg_categories)) {
597 print "<option value='".$k."'> " . $v . "</option>";
599 print "</select></td>\n";
602 # print " <td span='f4' align='right'>";
603 # print __("Package Location").":</td>\n";
604 # print " <td span='f4' align='left'>";
605 # print "<select name='location'>";
606 # print "<option value='0'> " . __("Select Location") . "</option>";
607 # while (list($k, $v) = each($pkg_locations)) {
608 # print "<option value='".$k."'> " . $v . "</option>";
610 # print "</select></td>\n";
613 print " <td span='f4' align='right'>";
614 print __("Upload package file").":</td>\n";
615 print " <td span='f4' align='left'>";
616 print "<input type='file' name='pfile' size='30' />\n";
620 print " <td span='f4' align='right'>";
621 print __("Overwrite existing package?");
623 print " <td span='f4' align='left'>";
624 print "<input type='radio' name='overwrite' value='1'> ".__("Yes");
625 print " ";
626 print "<input type='radio' name='overwrite' value='0' checked> ";
631 print " <td valign='top' span='f4' align='right'>";
632 print __("Comment").":</td>\n";
633 print " <td span='f4' align='left'>";
634 print "<textarea rows='10' cols='50' name='comments'></textarea>";
639 print " <td> </td>\n";
640 print " <td align='left'>";
641 print "<input class='button' type='submit' value='".__("Upload")."' />\n";
642 print " ";
643 print "<input class='button' type='reset' value='".__("Reset")."' />\n";
650 print __("Sorry, uploads are not permitted by this server.");
654 print __("Package upload successful.");
657 print "<span class='warning'>".$warning."</span><br />\n";
658 print "<br /> <br />\n";
663 # visitor is not logged in
665 print __("You must create an account before you can upload packages.");
670 html_footer("\$Id: pkgsubmit.php 347 2007-03-05 05:40:08Z dsa $");
671 # vim: ts=2 sw=2 noet ft=php