summaryrefslogtreecommitdiffstats
path: root/web/html/pkgsubmit.php
blob: 21b0f9422a32ae3a4dff0fb277c878da70981aaf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
<?
include("aur.inc");         # access AUR common functions
include("submit_po.inc");   # use some form of this for i18n support
set_lang();                 # this sets up the visitor's language
check_sid();                # see if they're still logged in
html_header();              # print out the HTML header

print "<center>\n";

# this is the directory that new packages will be uploaded to
#
$UPLOAD_DIR = "/tmp/aur/temp/";
$INCOMING_DIR = "/tmp/aur/incoming/";

if ($_COOKIE["AURSID"]) {
	# track upload errors
	#
	$error = "";

	if ($_REQUEST["pkgsubmit"]) {

		# first, see if this package already exists, and if it can be overwritten
	 	#	
		$pkg_exists = package_exists($_FILES["pfile"]["name"]);
		if ($pkg_exists) {
			# ok, it exists - should it be overwritten, and does the user have
			# the permissions to do so?
			#
			if (can_overwrite_pkg($_FILES["pfile"]["name"], $_COOKIE["AURSID"])) {
				if (!$_REQUEST["overwrite"]) {
					$error = __("You did not tag the 'overwrite' checkbox.");
				}
			} else {
				$error = __("You are not allowed to overwrite the %h%s%h package.",
						array("<b>", $_FILES["pfile"]["name"], "</b>"));
			}
		}

		if (!$error) {
			# no errors checking upload permissions, go ahead and try to process
			# the uploaded package file.
			#

			$upload_file = $UPLOAD_DIR . $_FILES["pfile"]["name"];
			if (move_uploaded_file($_FILES["pfile"]["tmp_name"], $upload_file)) {
				# ok, we can proceed
				#
				if (file_exists($INCOMING_DIR . $_FILES["pfile"]["name"])) {
					# blow away the existing file/dir and contents
					#
					rm_rf($INCOMING_DIR . $_FILES["pfile"]["name"]);
				}

			} else {
				# errors uploading file...
				#
				$error = __("Error trying to upload file - please try again.");
			}
		}

		# at this point, we can safely create the directories, and update
		# the database with the new package
		#
		# TODO extract the package contents and parse the included files
		#


		# update the backend database
		#
		$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);


		} else {
			# this is a brand new package
			#
		}


	}


	if (!$_REQUEST["pkgsubmit"] || $error) {
		# give the visitor the default upload form
		#
		if (ini_get("file_uploads")) {
			if (!$error) {
				print "<span class='error'>".$error."</span><br />\n";
				print "<br />&nbsp;<br />\n";
			}
			print "<form action='/pkgsubmit.php' method='post'";
			print "	enctype='multipart/form-data'>\n";
			print "<input type='hidden' name='pkgsubmit' value='1' />\n";
			print "<input type='hidden' name='MAX_FILE_SIZE' value='";
			print initeger(ini_get("upload_max_filesize"))."' />\n";
			print "<table border='0' cellspacing='5'>\n";
			print "<tr>\n";
			print "  <td span='f4' align='right'>";
			print __("Upload package").":</td>\n";
			print "  <td span='f4' align='left'>";
			print "<input type='file' name='pfile' size='30' />\n";
			print "  </td>\n";
			print "</tr>\n";
			print "<tr>\n";
			print "  <td span='f4' align='right'>";
			print __("Overwrite existing package?");
			print "  </td>\n";
			print "  <td span='f4' align='left'>";
			print "<input type='checkbox' name='overwrite' value='1'> ".__("Yes");
			print "&nbsp;&nbsp;&nbsp;";
			print "<input type='checkbox' name='overwrite' value='0' checked> ";
			print __("No");
			print "  </td>\n";
			print "</tr>\n";

			print "<tr>\n";
			print "  <td>&nbsp;</td>\n";
			print "  <td align='left'>";
			print "<input class='button' type='submit' value='".__("Upload")."' />\n";
			print "</td>\n";
			print "</tr>\n";
			print "</table>\n";

			print "</form>\n";
		} else {
			print __("Sorry, uploads are not permitted by this server.");
			print "<br />\n";
		}
	}

} else {
	# visitor is not logged in
	#
	print __("You must create an account before you can upload packages.");
	print "<br />\n";
}

print "</center>\n";
html_footer("\$Id$");
?>