]>
git.p6c8.net - devedit.git/blob - modules/Tool.pm
4 # Dev-Editor - Module Tool
6 # Some shared sub routines
8 # Author: Patrick Canterino <patshaping@gmx.net>
9 # Last modified: 2004-11-04
26 use base
qw(Exporter);
28 @EXPORT = qw(check_path
38 # Check, if a virtual path is above a virtual root directory
39 # (currently no check if the path exists - check otherwise!)
41 # Params: 1. Virtual root directory
42 # 2. Virtual path to check
44 # Return: Array with the physical and the cleaned virtual path;
45 # false, if the submitted path is above the root directory
49 my ($root,$path) = @_;
53 $root = abs_path
($root);
54 $root = File
::Spec
->canonpath($root);
57 $path = $root."/".$path;
59 # We extract the last part of the path and create the absolute path
61 my $first = upper_path
($path);
62 my $last = file_name
($path);
64 $first = abs_path
($first);
65 $path = $first."/".$last;
67 $path = File
::Spec
->canonpath($path);
69 # Check if the path is above the root directory
71 return if(index($path,$root) == -1);
73 # Create short path name
75 my $short_path = substr($path,length($root));
76 $short_path =~ tr!\\!\/!;
77 $short_path = "/".$short_path if($short_path !~ m
!^/!);
78 $short_path = $short_path."/" if($short_path !~ m
!/$! && -d
$path);
80 return ($path,$short_path);
85 # Clean up a path logically and replace backslashes with
90 # Return: Cleaned path
95 $path = File
::Spec
->canonpath($path);
103 # Create a HTTP redirection header to load Dev-Editor
104 # with some other parameters
106 # Params: Hash Reference (will be merged to a query string)
108 # Return: HTTP redirection header (Scalar Reference)
110 sub devedit_reload
($)
114 # Detect the protocol (simple HTTP or SSL encrypted HTTP)
115 # and check if the server listens on the default port
122 # SSL encrypted HTTP (HTTPS)
125 $port = ":".$ENV{'SERVER_PORT'} if($ENV{'SERVER_PORT'} != 443);
132 $port = ":".$ENV{'SERVER_PORT'} if($ENV{'SERVER_PORT'} != 80);
135 # The following code is grabbed from Template::_query of
136 # Andre Malo's selfforum (http://sourceforge.net/projects/selfforum/)
137 # and modified by Patrick Canterino
139 my $query = '?'.join ('&' =>
142 ?
map{escape
($_).'='.escape
($params -> {$_})} @
{$params -> {$_}}
143 : escape
($_).'='.escape
($params -> {$_})
147 # Create the redirection header
149 my $header = redirect
($protocol."://".virtual_host
.$port.$ENV{'SCRIPT_NAME'}.$query);
156 # Create URL equal to a file or directory
158 # Params: 1. HTTP root
161 # Return: Formatted link (String)
165 my ($root,$path) = @_;
170 $url = $root."/".$path;
177 # Return the last part of a path
181 # Return: Last part of the path
190 $path = substr($path,0,-1) if($path =~ m!/$!);
191 $path = substr($path,rindex($path,"/")+1);
199 # Convert a file mode number into a human readable string (rwxr-x-r-x)
200 # (also supports SetUID, SetGID and Sticky Bit)
202 # Params: File mode number
204 # Return: Human readable mode string
213 $string = ($mode & 00400) ?
"r" : "-";
214 $string .= ($mode & 00200) ?
"w" : "-";
215 $string .= ($mode & 00100) ?
(($mode & 04000) ?
"s" : "x") :
216 ($mode & 04000) ?
"S" : "-";
220 $string .= ($mode & 00040) ?
"r" : "-";
221 $string .= ($mode & 00020) ?
"w" : "-";
222 $string .= ($mode & 00010) ?
(($mode & 02000) ?
"s" : "x") :
223 ($mode & 02000) ?
"S" : "-";
227 $string .= ($mode & 00004) ?
"r" : "-";
228 $string .= ($mode & 00002) ?
"w" : "-";
229 $string .= ($mode & 00001) ?
(($mode & 01000) ?
"t" : "x") :
230 ($mode & 01000) ?
"T" : "-";
237 # Cut away the last part of a path
241 # Return: Truncated path
250 $path = substr($path,0,-1) if($path =~ m!/$!);
251 $path = substr($path,0,rindex($path,"/")+1);
257 # it's true, baby ;-)
patrick-canterino.de