]>
git.p6c8.net - devedit.git/blob - modules/Tool.pm
18d437c49499369770e5ecabe642afd958a9e7f4
4 # Dev-Editor - Module Tool
6 # Some shared sub routines
8 # Author: Patrick Canterino <patshaping@gmx.net>
9 # Last modified: 2004-07-30
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;
61 # The path points to a file
62 # We have to extract the directory name and create the absolute path
64 my $dir = upper_path
($path);
65 my $file = file_name
($path);
67 $dir = abs_path
($dir);
68 $path = $dir."/".$file;
72 $path = abs_path
($path);
75 $path = File
::Spec
->canonpath($path);
77 # Check if the path is above the root directory
79 return if(index($path,$root) == -1);
81 # Create short path name
83 my $short_path = substr($path,length($root));
84 $short_path =~ tr!\\!\/!;
85 $short_path = "/".$short_path if($short_path !~ m
!^/!);
86 $short_path = $short_path."/" if($short_path !~ m
!/$! && -d
$path);
88 return ($path,$short_path);
93 # Clean up a path logically and replace backslashes with
98 # Return: Cleaned path
103 $path = File
::Spec
->canonpath($path);
111 # Create a HTTP redirection header to load Dev-Editor
112 # with some other parameters
114 # Params: Hash Reference (will be merged to a query string)
116 # Return: HTTP redirection header (Scalar Reference)
118 sub devedit_reload
($)
122 # Detect the protocol (simple HTTP or SSL encrypted HTTP)
123 # and check if the server listens on the default port
130 # SSL encrypted HTTP (HTTPS)
133 $port = ":".$ENV{'SERVER_PORT'} if($ENV{'SERVER_PORT'} != 443);
140 $port = ":".$ENV{'SERVER_PORT'} if($ENV{'SERVER_PORT'} != 80);
143 # The following code is grabbed from Template::_query of
144 # Andre Malo's selfforum (http://sourceforge.net/projects/selfforum/)
145 # and modified by Patrick Canterino
147 my $query = '?'.join ('&' =>
150 ?
map{escape
($_).'='.escape
($params -> {$_})} @
{$params -> {$_}}
151 : escape
($_).'='.escape
($params -> {$_})
155 # Create the redirection header
157 my $header = redirect
($protocol."://".virtual_host
.$port.$ENV{'SCRIPT_NAME'}.$query);
164 # Create URL equal to a file or directory
166 # Params: 1. HTTP root
169 # Return: Formatted link (String)
173 my ($root,$path) = @_;
178 $url = $root."/".$path;
185 # Return the last part of a path
189 # Return: Last part of the path
198 $path = substr($path,0,-1) if($path =~ m!/$!);
199 $path = substr($path,rindex($path,"/")+1);
207 # Convert a file mode number into a human readable string (rwxr-x-r-x)
208 # (also supports SetUID, SetGID and Sticky Bit)
210 # Params: File mode number
212 # Return: Humand readable mode string
221 $string = ($mode & 00400) ?
"r" : "-";
222 $string .= ($mode & 00200) ?
"w" : "-";
223 $string .= ($mode & 00100) ?
(($mode & 04000) ?
"s" : "x") :
224 ($mode & 04000) ?
"S" : "-";
228 $string .= ($mode & 00040) ?
"r" : "-";
229 $string .= ($mode & 00020) ?
"w" : "-";
230 $string .= ($mode & 00010) ?
(($mode & 02000) ?
"s" : "x") :
231 ($mode & 02000) ?
"S" : "-";
235 $string .= ($mode & 00004) ?
"r" : "-";
236 $string .= ($mode & 00002) ?
"w" : "-";
237 $string .= ($mode & 00001) ?
(($mode & 01000) ?
"t" : "x") :
238 ($mode & 01000) ?
"T" : "-";
245 # Cut away the last part of a path
249 # Return: Truncated path
258 $path = substr($path,0,-1) if($path =~ m!/$!);
259 $path = substr($path,0,rindex($path,"/")+1);
265 # it's true, baby ;-)
patrick-canterino.de