[Fusionforge-commits] r9583 - in trunk/gforge: . common/include cronjobs deb-specific etc/local.d www/frs/admin www/frs/include

Roland Mas lolando at libremir.placard.fr.eu.org
Fri Apr 23 10:57:02 CEST 2010


Author: lolando
Date: 2010-04-23 10:57:02 +0200 (Fri, 23 Apr 2010)
New Revision: 9583

Modified:
   trunk/gforge/common/include/utils.php
   trunk/gforge/cronjobs/homedirs.php
   trunk/gforge/deb-specific/group_dump_update.pl
   trunk/gforge/etc/local.d/25features
   trunk/gforge/setup
   trunk/gforge/www/frs/admin/editrelease.php
   trunk/gforge/www/frs/admin/qrs.php
   trunk/gforge/www/frs/include/frs_utils.php
Log:
Implemented 'manual uploads' (by SCP or SFTP) for the FRS

Modified: trunk/gforge/common/include/utils.php
===================================================================
--- trunk/gforge/common/include/utils.php	2010-04-23 08:56:54 UTC (rev 9582)
+++ trunk/gforge/common/include/utils.php	2010-04-23 08:57:02 UTC (rev 9583)
@@ -918,6 +918,10 @@
  *	@return	array	array of file names.
  */
 function &ls($dir,$filter=false) {
+	if (!is_dir ($dir)) {
+		$out = array () ;
+		return $out ;
+	}
 	exec('ls -c1 '.$dir,$out);
 	if ($filter) {
 		for ($i=0; $i<count($out); $i++) {

Modified: trunk/gforge/cronjobs/homedirs.php
===================================================================
--- trunk/gforge/cronjobs/homedirs.php	2010-04-23 08:56:54 UTC (rev 9582)
+++ trunk/gforge/cronjobs/homedirs.php	2010-04-23 08:57:02 UTC (rev 9583)
@@ -171,7 +171,17 @@
 		fwrite($fw,$contents);
 		fclose($fw);
 	}
+
+	if ($sys_use_manual_uploads) { 
+		$incoming = $groupdir_prefix/$group."/incoming" ;
+		if (!is_dir($incoming))
+		{
+			@mkdir($incoming); 
+		}
+	}
+
 	system("chown -R ".forge_get_config('apache_user').":".forge_get_config('apache_group')." $groupdir_prefix/$group");
+
 }
 
 

Modified: trunk/gforge/deb-specific/group_dump_update.pl
===================================================================
--- trunk/gforge/deb-specific/group_dump_update.pl	2010-04-23 08:56:54 UTC (rev 9582)
+++ trunk/gforge/deb-specific/group_dump_update.pl	2010-04-23 08:57:02 UTC (rev 9583)
@@ -96,6 +96,7 @@
 	$log_dir = $group_dir."/log";
 	$cgi_dir = $group_dir."/cgi-bin";
 	$ht_dir = $group_dir."/htdocs";
+	$inc_dir = $group_dir."/incoming";
 
         if ($is_public) {
             $default_perms = 2775 ;
@@ -113,12 +114,14 @@
 	mkdir $log_dir, $default_perms ;
 	mkdir $cgi_dir, $default_perms ;
 	mkdir $ht_dir, $default_perms ;
+	mkdir $inc_dir, $default_perms ;
 	system("cp $default_page $ht_dir/index.php");
 	# perl is sometime fucked to create with right permission
 	system("chmod $default_perms $group_dir");
 	system("chmod $default_perms $log_dir");
 	system("chmod $default_perms $cgi_dir");
 	system("chmod $default_perms $ht_dir");
+	system("chmod $default_perms $inc_dir");
 	system("chmod $file_default_perms $ht_dir/index.php");
 	chown $dummy_uid, $gid, ($group_dir, $log_dir, $cgi_dir, $ht_dir);
 	chown $dummy_uid, $gid, ("$ht_dir/index.php");
@@ -137,6 +140,7 @@
 	$log_dir = $group_dir."/log";
 	$cgi_dir = $group_dir."/cgi-bin";
 	$ht_dir = $group_dir."/htdocs";
+	$inc_dir = $group_dir."/incoming";
 
 	if ($is_public) {
 	    $default_perms = 2775 ;
@@ -150,6 +154,7 @@
 	system("chmod $default_perms $log_dir");
 	system("chmod $default_perms $cgi_dir");
 	system("chmod $default_perms $ht_dir");
+	system("chmod $default_perms $inc_dir");
 	chown $dummy_uid, $gid, ($group_dir, $log_dir, $cgi_dir, $ht_dir);
 	
 	my $realuid=get_file_owner_uid($group_dir);

Modified: trunk/gforge/etc/local.d/25features
===================================================================
--- trunk/gforge/etc/local.d/25features	2010-04-23 08:56:54 UTC (rev 9582)
+++ trunk/gforge/etc/local.d/25features	2010-04-23 08:57:02 UTC (rev 9583)
@@ -31,6 +31,8 @@
 $sys_use_ratings={sys_use_ratings};
 // Enable/Disable the ability to upload files using FTP in FRS
 $sys_use_ftpuploads={sys_use_ftpuploads};
+// Enable/Disable the ability to upload files using SCP/SFTP in FRS
+$sys_use_manual_uploads={sys_use_manual_uploads};
 // Enable/Disable the use of mail gateways for trackers and forums
 $sys_use_gateways={sys_use_gateways};
 

Modified: trunk/gforge/setup
===================================================================
--- trunk/gforge/setup	2010-04-23 08:56:54 UTC (rev 9582)
+++ trunk/gforge/setup	2010-04-23 08:57:02 UTC (rev 9583)
@@ -106,6 +106,7 @@
 	DEFAULTsys_use_ratings=true
 	DEFAULTsys_use_ssl=false
 	DEFAULTsys_use_people=true
+	DEFAULTsys_use_manual_uploads=false
 	DEFAULTsys_use_ftpuploads=false
 	DEFAULTsys_use_diary=true
 	DEFAULTsys_use_bookmarks=true

Modified: trunk/gforge/www/frs/admin/editrelease.php
===================================================================
--- trunk/gforge/www/frs/admin/editrelease.php	2010-04-23 08:56:54 UTC (rev 9582)
+++ trunk/gforge/www/frs/admin/editrelease.php	2010-04-23 08:57:02 UTC (rev 9583)
@@ -147,38 +147,21 @@
 	$userfile_name = $userfile['name'];
 	$type_id = getIntFromRequest('type_id');
 	$release_date = getStringFromRequest('release_date');
+	// Build a Unix time value from the supplied Y-m-d value
 	$release_date = strtotime($release_date);
 	$processor_id = getStringFromRequest('processor_id');
-	// Build a Unix time value from the supplied Y-m-d value
 	$group_unix_name=group_getunixname($group_id);
 	$ftp_filename = getStringFromRequest('ftp_filename');
+	$manual_filename = getStringFromRequest('manual_filename');
 
-	if (($userfile && is_uploaded_file($userfile['tmp_name'])) || (forge_get_config('use_ftpuploads') && $ftp_filename)){
-		if (forge_get_config('use_ftpuploads') && $ftp_filename && util_is_valid_filename($ftp_filename) && is_file($upload_dir.'/'.$ftp_filename)) {
-			//file was uploaded already via ftp
-			//use setuid prog to chown it
-			//$cmd = escapeshellcmd("$sys_ftp_upload_chowner $ftp_filename");
-			//exec($cmd,$output);
-			$userfile_name=$ftp_filename;
-			$userfile=$upload_dir.'/'.$ftp_filename;
-			//echo $cmd.'***'.$output.'***'.$userfile;
-		}
-		//
-		//  Now create the new FRSFile in the db
-		//
-		$frsf = new FRSFile($frsr);
-		if (!$frsf || !is_object($frsf)) {
-			exit_error('Error','Could Not Get FRSFile');
-		} elseif ($frsf->isError()) {
-			exit_error('Error',$frsf->getErrorMessage());
-		} else {
-			if (!$frsf->create($userfile_name,$userfile['tmp_name'],$type_id,$processor_id,$release_date)) {
-				db_rollback();
-				exit_error('Error',$frsf->getErrorMessage());
-			}
-			$feedback=_('File Released');
-		}
+	$ret = frs_add_file_from_form ($frsr, $type_id, $processor_id, $release_date,
+				       $userfile, $ftp_filename, $manual_filename) ;
+	if ($ret == true) {
+		$feedback = _('File Released') ;
+	} else {
+		$feedback .= $ret ;
 	}
+
 }
 
 // Edit/Delete files in a release
@@ -308,22 +291,27 @@
 <?php echo _("Upload a new file") ?>: <input type="file" name="userfile"  size="30" />
 <?php if (forge_get_config('use_ftpuploads')) {
 	echo '<p>';
-	printf(_('Alternatively, you can use FTP to upload a new file at %1$s'), forge_get_config('ftp_upload_host')).'<br />';
-	echo _('Choose an FTP file instead of uploading:').'<br />';
-	$arr[]='';
-	$ftp_files_arr=array_merge($arr,ls($upload_dir,true));
-	echo html_build_select_box_from_arrays($ftp_files_arr,$ftp_files_arr,'ftp_filename','',false); ?>
+	  printf(_('Alternatively, you can use FTP to upload a new file at %1$s.'), forge_get_config('ftp_upload_host'));
+	echo '<br />';
+	echo _('Choose an already uploaded file:').'<br />';
+	$ftp_files_arr=ls($upload_dir,true);
+	echo html_build_select_box_from_arrays($ftp_files_arr,$ftp_files_arr,'ftp_filename',''); ?>
 	</p>
 <?php } ?>
-<p>
-<span class="important">
-<?php echo _('NOTE: In some browsers you must select the file in the file-upload dialog and click "OK".  Double-clicking doesn\'t register the file.').' ('._('Maximum upload file size:').' '. ini_get('upload_max_filesize')?>)
-</span>
-</p>
-<p>
-<?php echo _('Specify a new URL') ?>: <input type="text" name="userlink"  size="50" />
-</p>
-</fieldset>
+
+<?php if ($sys_use_manual_uploads) {
+	$incoming = $groupdir_prefix."/".$g->getUnixName()."/incoming" ;
+
+	echo '<p>';
+	printf(_('Alternatively, you can use a file you already uploaded (by SFTP or SCP) to the project\'s incoming directory (%1$s).'),
+	       $incoming);
+	echo '<br />';
+	echo _('Choose an already uploaded file:').'<br />';
+	$manual_files_arr=ls($incoming,true);
+	echo html_build_select_box_from_arrays($manual_files_arr,$manual_files_arr,'manual_filename',''); ?>
+	</p>
+<?php } ?>
+
 <table width="60%">
 <tr>
 <td>

Modified: trunk/gforge/www/frs/admin/qrs.php
===================================================================
--- trunk/gforge/www/frs/admin/qrs.php	2010-04-23 08:56:54 UTC (rev 9582)
+++ trunk/gforge/www/frs/admin/qrs.php	2010-04-23 08:57:02 UTC (rev 9583)
@@ -60,41 +60,20 @@
 	$type_id = getIntFromRequest('type_id');
 	$processor_id = getIntFromRequest('processor_id');
 	$release_date = getStringFromRequest('release_date');
+	// Build a Unix time value from the supplied Y-m-d value
+	$release_date = strtotime($release_date);
 	$release_notes = getStringFromRequest('release_notes');
 	$release_changes = getStringFromRequest('release_changes');
 	$preformatted = getStringFromRequest('preformatted');
 	$ftp_filename = getStringFromRequest('ftp_filename');
+	$manual_filename = getStringFromRequest('manual_filename');
+	$group_unix_name=group_getunixname($group_id);
+
 	$feedback = '' ;
-	if (forge_get_config('use_ftpuploads') && $ftp_filename && util_is_valid_filename($ftp_filename) && is_file($upload_dir.'/'.$ftp_filename)) {
-		//file was uploaded already via ftp
-		//use setuid prog to chown it
-		//$cmd = escapeshellcmd("$sys_ftp_upload_chowner $ftp_filename");
-		//exec($cmd,$output);
-		$userfile_name=$ftp_filename;
-		$userfile=$upload_dir.'/'.$ftp_filename;
-		//echo $cmd.'***'.$output.'***'.$userfile;
-	}
 	if (!$release_name) {
 		$feedback .= _('Must define a release name.');
 	} else 	if (!$package_id) {
 		$feedback .= _('Must select a package.');
-	} else 	if (!$userfile['tmp_name'] && !$ftp_filename) {
-		// Check errors
-		switch($userfile['error']) {
-			case UPLOAD_ERR_INI_SIZE:
-			case UPLOAD_ERR_FORM_SIZE:
-				$feedback .= _('The uploaded file exceeds the maximum file size. Contact to the site admin to upload this big file.');
-			break;
-			case UPLOAD_ERR_PARTIAL:
-				$feedback .= _('The uploaded file was only partially uploaded.');
-			break;
-			case UPLOAD_ERR_NO_FILE:
-				$feedback .= _('Must select a file.');
-			break;
-			default:
-				$feedback .= _('Unknown file upload error.');
-			break;
-		}
 	} else 	if (!$type_id || $type_id == "100") {
 		$feedback .= _('Must select a file type.');
 	} else 	if (!$processor_id || $processor_id == "100")  {
@@ -110,68 +89,43 @@
 		} elseif ($frsp->isError()) {
 			exit_error('Error',$frsp->getErrorMessage());
 		} else {
-			if ($userfile && (is_uploaded_file($userfile['tmp_name']) || (forge_get_config('use_ftpuploads') && $ftp_filename))) {
-				//
-				//	Create a new FRSRelease in the db
-				//
-				$frsr = new FRSRelease($frsp);
-				if (!$frsr || !is_object($frsr)) {
-					exit_error('Error','Could Not Get FRSRelease');
-				} elseif ($frsr->isError()) {
+			//
+			//	Create a new FRSRelease in the db
+			//
+			$frsr = new FRSRelease($frsp);
+			if (!$frsr || !is_object($frsr)) {
+				exit_error('Error','Could Not Get FRSRelease');
+			} elseif ($frsr->isError()) {
+				exit_error('Error',$frsr->getErrorMessage());
+			} else {
+				db_begin();
+				if (!$frsr->create($release_name,$release_notes,$release_changes,
+						   $preformatted,$release_date)) {
+					db_rollback();
 					exit_error('Error',$frsr->getErrorMessage());
-				} else {
-//					$date_list = split('[- :]',$release_date,5);
-//					$release_date = mktime($date_list[3],$date_list[4],0,$date_list[1],$date_list[2],$date_list[0]);
-					$release_date = strtotime($release_date);
-					db_begin();
-					if (!$frsr->create($release_name,$release_notes,$release_changes,
-						$preformatted,$release_date)) {
-						db_rollback();
-						exit_error('Error',$frsr->getErrorMessage());
-					}
-
-					//
-					//	Now create the new FRSFile in the db
-					//
-					$frsf = new FRSFile($frsr);
-					if (!$frsf || !is_object($frsf)) {
-						exit_error('Error','Could Not Get FRSFile');
-					} elseif ($frsf->isError()) {
-						exit_error('Error',$frsf->getErrorMessage());
-					} else {
-						if (!$frsf->create($userfile_name,$userfile['tmp_name'],$type_id,$processor_id,$release_date)) {
-							db_rollback();
-							exit_error('Error',$frsf->getErrorMessage());
-						}
-						$frsr->sendNotice();
-						$feedback .= _('File Released: You May Choose To Edit the Release Now');
-
-						frs_admin_header(array('title'=>_('Quick Release System'),'group'=>$group_id));
-						?>
-						<p>
-							 <?php 
-							 printf (_('You can now <a href="%1$s"><strong>add files to this release</strong></a> if you wish, or edit the release. Please note that file(s) may not appear immediately on the <a href="%2$s">download page</a>. Allow several hours for propagation.'),
-								 util_make_url ('/frs/admin/editrelease.php?release_id='.$frsr->getID().'&amp;group_id='.$group_id.'&amp;package_id='.$package_id),
-								 util_make_url ('/frs/?group_id='.$group_id)
-								 )
-							 ?>
-						<?php
-						db_commit();
-						frs_admin_footer(array());
-						exit(); //quite dirty but less that a buggy output like before
-						
-					}
-
 				}
 
-			} else {
-				exit_error('Error','Could Not Upload User File: '.$userfile['name']);
+				$ret = frs_add_file_from_form ($frsr, $type_id, $processor_id, $release_date,
+							       $userfile, $ftp_filename, $manual_filename) ;
+				if ($ret != true) {
+					db_rollback() ;
+					exit_error ($ret) ;
+				}
+				$frsr->sendNotice();
+				
+				frs_admin_header(array('title'=>_('Quick Release System'),'group'=>$group_id));
+				echo '<p>' ;
+				printf (_('You can now <a href="%1$s"><strong>add files to this release</strong></a> if you wish, or edit the release. Please note that file(s) may not appear immediately on the <a href="%2$s">download page</a>. Allow several hours for propagation.'),
+					util_make_url ('/frs/admin/editrelease.php?release_id='.$frsr->getID().'&amp;group_id='.$group_id.'&amp;package_id='.$package_id),
+					util_make_url ('/frs/?group_id='.$group_id)
+					) ;
+				echo '</p>' ;
+				db_commit();
+				frs_admin_footer(array());
+				exit () ;
 			}
-
 		}
-
 	}
-
 } else {
 	$release_name = '';
 	$userfile = '';
@@ -183,6 +137,7 @@
 	$release_changes = '';
 	$preformatted = '';
 	$ftp_filename = '';
+	$manual_filename = '';
 }
 
 frs_admin_header(array('title'=>_('Quick Release System'),'group'=>$group_id));
@@ -245,14 +200,27 @@
 		<?php if (forge_get_config('use_ftpuploads')) {
 
 			echo '<p>';
-			printf(_('Alternatively, you can use FTP to upload a new file at %1$s'), forge_get_config('ftp_upload_host')).'<br />';
+			printf(_('Alternatively, you can use FTP to upload a new file at %1$s.'), forge_get_config('ftp_upload_host'));
+			echo '<br />';
 			echo _('Choose an FTP file instead of uploading:').'<br />';
-			$arr[]='';
-			$ftp_files_arr=array_merge($arr,ls($upload_dir,true));
+			$ftp_files_arr=ls($upload_dir,true);
 			echo html_build_select_box_from_arrays($ftp_files_arr,$ftp_files_arr,'ftp_filename',''); ?>
 		
 		</p>
 		<?php } ?>
+<?php if ($sys_use_manual_uploads) {
+	$incoming = $groupdir_prefix."/".$g->getUnixName()."/incoming" ;
+
+	echo '<p>';
+	printf(_('Alternatively, you can use a file you already uploaded (by SFTP or SCP) to the project\'s incoming directory (%1$s).'),
+	       $incoming) ;
+	echo '<br />';
+	echo _('Choose an already uploaded file:').'<br />';
+	$manual_files_arr=ls($incoming,true);
+	echo html_build_select_box_from_arrays($manual_files_arr,$manual_files_arr,'manual_filename',''); ?>
+	</p>
+<?php } ?>
+
 		</td>
 	</tr>
 	<tr>

Modified: trunk/gforge/www/frs/include/frs_utils.php
===================================================================
--- trunk/gforge/www/frs/include/frs_utils.php	2010-04-23 08:56:54 UTC (rev 9582)
+++ trunk/gforge/www/frs/include/frs_utils.php	2010-04-23 08:57:02 UTC (rev 9583)
@@ -220,6 +220,71 @@
 	}
 }
 
+function frs_add_file_from_form ($release, $type_id, $processor_id, $release_date,
+				 $userfile, $ftp_filename, $manual_filename) {
+	global $groupdir_prefix, $sys_use_manual_uploads ;
+
+	$group_unix_name = $release->getFRSPackage()->getGroup()->getUnixName() ;
+	$incoming = "$groupdir_prefix/$group_unix_name/incoming" ;
+
+	$filechecks = false ;
+
+	if ($userfile && is_uploaded_file($userfile['tmp_name']) && util_is_valid_filename($userfile['name'])) {
+		$infile = $userfile['tmp_name'] ;
+		$fname = $userfile['name'] ;
+		$move = true ;
+		$filechecks = true ;
+	} elseif ($userfile && $userfile['error'] != UPLOAD_ERR_OK && $userfile['error'] != UPLOAD_ERR_NO_FILE) {
+		switch ($userfile['error']) {
+			case UPLOAD_ERR_INI_SIZE:
+			case UPLOAD_ERR_FORM_SIZE:
+				return _('The uploaded file exceeds the maximum file size. Contact to the site admin to upload this big file, or use an alternate upload method (if available).') ;
+			break;
+			case UPLOAD_ERR_PARTIAL:
+				return _('The uploaded file was only partially uploaded.') ;
+			break;
+			default:
+				return _('Unknown file upload error.') ;
+			break;
+		}
+	} elseif (forge_get_config('use_ftp_uploads') && $ftp_filename && util_is_valid_filename($ftp_filename) && is_file($upload_dir.'/'.$ftp_filename)) {
+		$infile = $upload_dir.'/'.$ftp_filename;
+		$fname = $ftp_filename ;
+		$move = false ;
+		$filechecks = true ;
+	} elseif ($sys_use_manual_uploads && $manual_filename && util_is_valid_filename($manual_filename) && is_file($incoming.'/'.$manual_filename)) {
+		$infile = $incoming.'/'.$manual_filename ;
+		$fname = $manual_filename ;
+		$move = false ;
+		$filechecks = true ;
+	} elseif ($userfile && $userfile['error'] == UPLOAD_ERR_NO_FILE) {
+		return _('Must select a file.') ;
+	}
+
+	if ($filechecks) {
+		if (!$move) {
+			$tmp = tempnam ('', '') ;
+			copy ($infile, $tmp) ;
+			$infile = $tmp ;
+		}
+		$frsf = new FRSFile($release);
+		if (!$frsf || !is_object($frsf)) {
+			exit_error('Error','Could Not Get FRSFile');
+		} elseif ($frsf->isError()) {
+			exit_error('Error',$frsf->getErrorMessage());
+		} else {
+			if (!$frsf->create($fname,$infile,$type_id,$processor_id,$release_date)) {
+				db_rollback();
+				exit_error('Error',$frsf->getErrorMessage());
+			}
+			return true ;
+		}
+	} else {
+		return _('Unknown file upload error.') ;
+	}
+}
+
+
 // Local Variables:
 // mode: php
 // c-file-style: "bsd"




More information about the Fusionforge-commits mailing list