[interchange] Add better ability to set file umask from various upload locations

Greg Hanson interchange-cvs at icdevgroup.org
Wed Mar 30 19:44:01 UTC 2011


commit 93e95eb36037a1f1689f0144a26b4c252b1bf7e5
Author: Greg Hanson <greg at perusion.com>
Date:   Wed Mar 30 14:51:14 2011 -0400

    Add better ability to set file umask from various upload locations
    
    Basic changes added to admin file_upload page to allow passing of umask more easily. Users trying to upload files for web viewing needed better control
    
    Also modified slightly the uploadhelper widget to provide means to pass umask option, and subsequently altered process_filter where there were previously no means to pass umask through

 code/Widget/uploadhelper.widget          |    7 +++++--
 dist/lib/UI/pages/admin/upload_file.html |    5 ++++-
 dist/lib/UI/profiles/process_filter      |    6 +++++-
 3 files changed, 14 insertions(+), 4 deletions(-)
---
diff --git a/code/Widget/uploadhelper.widget b/code/Widget/uploadhelper.widget
index c5e18a0..69ece75 100644
--- a/code/Widget/uploadhelper.widget
+++ b/code/Widget/uploadhelper.widget
@@ -16,6 +16,7 @@ sub {
 
 	my $name = $opt->{name};
 	my $val  = $opt->{value};
+	my $umask = $opt->{umask} || '022';
 	my $path = $opt->{path} || $opt->{outboard};
 	my $size = $opt->{cols} || $opt->{width};
 	
@@ -37,11 +38,13 @@ sub {
 		}
 		$out .= qq{&nbsp;<INPUT TYPE=file NAME="$name" VALUE="$val">
 <INPUT TYPE=hidden NAME="ui_upload_file_path:$name" VALUE="$path">
-<INPUT TYPE=hidden NAME="$name" VALUE="$val">};      
+<INPUT TYPE=hidden NAME="$name" VALUE="$val">
+<INPUT TYPE=hidden NAME="ui_upload_umask:$name" VALUE="$umask">};      
     }
 	else {
         $out = qq{<INPUT TYPE=hidden NAME="ui_upload_file_path:$name" VALUE="$path">
-<INPUT TYPE=file NAME="$name"$size>};
+<INPUT TYPE=file NAME="$name"$size>
+<INPUT TYPE=hidden NAME="ui_upload_umask:$name" VALUE="$umask">};
     }
 	return $out;
 }
diff --git a/dist/lib/UI/pages/admin/upload_file.html b/dist/lib/UI/pages/admin/upload_file.html
index 5c9693c..9599ae6 100644
--- a/dist/lib/UI/pages/admin/upload_file.html
+++ b/dist/lib/UI/pages/admin/upload_file.html
@@ -89,6 +89,9 @@
 	<INPUT NAME=ui_upload_ascii TYPE=radio VALUE=0>&nbsp;[L]Binary[/L]
 [/else]
 [/if]
+	<BR>
+	[L]Umask default (022)[/L]&nbsp;<INPUT NAME=ui_upload_umask TYPE=text VALUE='022' size=10>
+	<BR>
 	</BLOCKQUOTE>
 <P>
 <B>[L]Backup mode[/L]</B>
@@ -124,7 +127,7 @@
 
 		$regex = q{@_UI_CONST_IMAGE_REGEX_@} || '\.(?:gif|jpe?g|png)$';
 		if( $CGI->{ui_upload_fn} =~ m{$regex}i) {
-			$CGI->{ui_upload_umask} = '022';
+			$CGI->{ui_upload_umask} ||= '022';
 		}
 		return;
 	[/calc]
diff --git a/dist/lib/UI/profiles/process_filter b/dist/lib/UI/profiles/process_filter
index c449d80..c8da7b0 100644
--- a/dist/lib/UI/profiles/process_filter
+++ b/dist/lib/UI/profiles/process_filter
@@ -98,9 +98,13 @@ __NAME__ process_filter
 		$fn =~ s,.*\\,,;
 		$fn = $Tag->filter('filesafe', $fn);
 #Debug("cgi->$key now='$CGI->{$key}'");
+
+		my $umaskkey = 'ui_upload_umask:' . $key;
+		my $umask = $CGI->{$umaskkey};
+
 		$CGI->{$key} = $fn;
 		my $out = "$path/$fn";
-		unless ($Tag->value_extended( { name => $key, outfile => $out , yes => 1} ) ) {
+		unless ($Tag->value_extended( { name => $key, outfile => $out , yes => 1, umask => $umask} ) ) {
 			$Scratch->{ui_failure} .= "\nFailed to write upload file $out";
 		}
 	}



More information about the interchange-cvs mailing list