WebEditor/SystemExplorer.pm

filter: Statementstmt 11.9% 32 / 268 Branchbran 0.0% 0 / 124 Conditioncond 0.0% 0 / 32 MC/DCmcdc 0.0% 0 / 20 Subroutinesub 37.0% 10 / 27 Podpod 0.0% 0 / 15 totaltotal 8.6% 42 / 486 CC 75 SCAR 43.9
CC
75
Cov
8%
new_file
210.0
dispatch
156.0
do_upload
132.0
CRAP 80.4
« WE/DB/FS.pm ↑ Summary WE_Frontend/Plugin/Linear.pm »
1 # -*- perl -*-
2  
3 #
4 # $Id: SystemExplorer.pm,v 1.6 2004/10/08 15:20:50 eserte Exp $
5 # Author: Slaven Rezic
6 #
7 # Copyright (C) 2003,2004 Slaven Rezic. All rights reserved.
8 # This package is free software; you can redistribute it and/or
9 # modify it under the same terms as Perl itself.
10 #
11 # Mail: slaven@rezic.de
12 # WWW: http://www.rezic.de/eserte/
13 #
14  
15 package WebEditor::SystemExplorer;
16  
17 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 1 ▶no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
19 1 ▶use vars qw($VERSION);
Subroutine BEGIN: called CC=1 SCAR=0.0
20 1 $VERSION = sprintf("%d.%02d", q$Revision: 1.6 $ =~ /(\d+)\.(\d+)/);
21  
22 1 ▶use File::Spec;
Subroutine BEGIN: called CC=1 SCAR=0.0
23 1 ▶use File::Basename qw(dirname basename);
Subroutine BEGIN: called CC=1 SCAR=0.0
24 1 ▶use File::Path qw(mkpath);
Subroutine BEGIN: called CC=1 SCAR=0.0
25 1 ▶use File::Copy qw(cp);
Subroutine BEGIN: called CC=1 SCAR=0.0
26  
27 1 ▶use Template;
Subroutine BEGIN: called CC=1 SCAR=0.0
28  
29 1 ▶use constant UPLOADDIR => "/tmp/templateeditorupload";
Subroutine BEGIN: called CC=1 SCAR=0.0
30  
31 1 ▶use constant DEBUG => 0;
Subroutine BEGIN: called CC=1 SCAR=0.0
32  
33 0 ▶sub OK {
Subroutine OK: not called CC=2 SCAR=17.9
Pod undocumented
34 0 ▶ if (defined &Apache::Constants::OK) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined &Apache::Constants::OK) { } 0 0 0
35 0 Apache::Constants::OK();
36 } else {
37 0 1;
38 }
39 }
40  
41 0 ▶sub http_header {
Subroutine http_header: not called CC=4 SCAR=30.0
Pod undocumented
42 0 my($self, $type) = @_;
43 0 my $r = $self->{R};
44 0 ▶ if ($r) {
Branch: 2 branches
BranchTrueFalseTotal
if ($r) { } 0 0 0
elsif (not $self->{'Controller'}{'HeaderPrinted'}) { } 0 0 0
45 0 $r->send_http_header($type);
46 } elsif (!$self->{Controller}{HeaderPrinted}) {
47 0 my $cgi = $self->{CGI};
48 0 ▶ $type = "text/html" if !defined $type;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $type 0 0 0
49 0 print $cgi->header($type);
50 0 $self->{Controller}{HeaderPrinted}++;
51 }
52 }
53  
54 0 ▶sub new {
Subroutine new: not called CC=3 SCAR=24.8
Pod undocumented
55 0 my($class, $oc) = @_;
56 0 my $self = { Controller => $oc,
57 R => $oc->R,
58 C => { WEsiteinfo => $oc->C },
59 };
60 0 my $cgi;
61 0 ▶ if ($ENV{MOD_PERL} && eval q{ require Apache::Request; 1 }) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ENV{'MOD_PERL'} and eval ' require Apache::Request; 1 ') { } 0 0 0
Condition0%0/3
$ENV{"MOD_PERL"} and eval " require Apache::Request; 1 "
!ll&&!rl&&r
000
MC/DC0%0/2
$ENV{"MOD_PERL"} and eval " require Apache::Request; 1 "
$ENV{"MOD_PERL"} eval " require Apache::Request; 1 "
Truth table0%0/3
A and B
A= $ENV{"MOD_PERL"}B= eval " require Apache::Request; 1 "
ABresult
0X0
100
111
62 0 $cgi = Apache::Request->new($self->{R});
63 } else {
64 0 require CGI;
65 0 $cgi = CGI->new;
66 }
67 0 $self->{CGI} = $cgi;
68  
69 0 bless $self, $class;
70 }
71  
72 0 ▶sub dispatch {
Subroutine dispatch: not called CC=12 SCAR=50.5
Pod undocumented
73 0 my $self = shift;
74  
75 0 my($cgi, $c) = @{$self}{qw(CGI C)};
76 0 my $wesiteinfo = $c->{WEsiteinfo};
77  
78 0 my $t = Template->new
79 (#DEBUG => $debug, # XXX make templates debug-clean
80 INCLUDE_PATH => [$wesiteinfo->paths->site_we_templatebase,
81 $wesiteinfo->paths->we_templatebase],
82 PLUGIN_BASE => ["WE_" . $wesiteinfo->project->name . "::Plugin",
83 "WE_Frontend::Plugin"],
84 );
85  
86 0 $self->{TT} = $t;
87  
88 0 ▶ my $action = $cgi->param("action") || "";
Condition0%0/2
$cgi->param('action') || ''
l!l
00
MC/DC0%0/1
$cgi->param('action') || ''
$cgi->param('action')
Truth table0%0/2
A
A= $cgi->param('action')
Aresult
11
00
89 0 ▶ my $path = $cgi->param("path") || "";
Condition0%0/2
$cgi->param('path') || ''
l!l
00
MC/DC0%0/1
$cgi->param('path') || ''
$cgi->param('path')
Truth table0%0/2
A
A= $cgi->param('path')
Aresult
11
00
90 0 ▶ if ($action eq 'newfileform') {
Branch: 9 branches
BranchTrueFalseTotal
if ($action eq 'newfileform') { } 0 0 0
elsif ($action eq 'newfile') { } 0 0 0
elsif ($action eq 'delfile') { } 0 0 0
elsif ($action eq 'newdirform') { } 0 0 0
elsif ($action eq 'newdir') { } 0 0 0
elsif ($action eq 'download') { } 0 0 0
elsif ($action eq 'upload') { } 0 0 0
elsif ($action eq 'doupload') { } 0 0 0
elsif ($action eq 'version') { } 0 0 0
91 0 return $self->new_file_form($path);
92 } elsif ($action eq 'newfile') {
93 0 return $self->new_file($path);
94 } elsif ($action eq 'delfile') {
95 0 return $self->do_del_file($path);
96 } elsif ($action eq 'newdirform') {
97 0 return $self->new_dir_form($path);
98 } elsif ($action eq 'newdir') {
99 0 return $self->new_dir($path);
100 } elsif ($action eq 'download') {
101 0 return $self->do_download($path);
102 } elsif ($action eq 'upload') {
103 0 return $self->upload_intermediate_page($path);
104 } elsif ($action eq 'doupload') {
105 0 return $self->do_upload($path);
106 } elsif ($action eq 'version') {
107 0 return $self->version_page($path);
108 } else {
109 # just show it
110 0 return $self->directory_or_file($path);
111 }
112 }
113  
114 0 ▶sub directory_or_file {
Subroutine directory_or_file: not called CC=5 SCAR=34.0
Pod undocumented
115 0 my($self, $path, %args) = @_;
116 0 my($r, $cgi, $t, $c) = @{$self}{qw(R CGI TT C)};
117 0 my $wesiteinfo = $c->{WEsiteinfo};
118 0 ▶ $path = "/" if !defined $path || $path eq '';
Branch: 1 branch
BranchTrueFalseTotal
if not defined $path or $path eq "" 0 0 0
Condition0%0/3
not defined $path or $path eq ""
l!l&&r!l&&!r
000
MC/DC0%0/2
not defined $path or $path eq ""
not defined $path $path eq ""
Truth table0%0/3
not(A) or B
A= not defined $pathB= $path eq ""
ABresult
1X1
011
000
119 ## ja?
120 # my $msg;
121 # if (!$self->check_permissions($path, \$msg)) {
122 # die $msg;
123 # }
124 0 my $rootdir = $wesiteinfo->paths->rootdir;
125 0 my $abspath = File::Spec->catfile($rootdir, $path);
126 0 ▶ if (-d $abspath) {
Branch: 2 branches
BranchTrueFalseTotal
if (-d $abspath) { } 0 0 0
elsif (-f $abspath) { } 0 0 0
127 0 $self->directory_listing($path, %args);
128 } elsif (-f $abspath) {
129 0 $self->file_page($path, %args);
130 } else {
131 0 die "Invalid file type: $abspath";
132 }
133 }
134  
135 0 ▶sub directory_listing {
Subroutine directory_listing: not called CC=8 SCAR=42.8
Pod undocumented
136 0 my($self, $path, %args) = @_;
137 0 my($r, $cgi, $t, $c) = @{$self}{qw(R CGI TT C)}; my $wesiteinfo = $c->{WEsiteinfo};
138 0 my $message = $args{-message};
139 0 my $htmlmessage = $args{-htmlmessage};
140  
141 0 my $rootdir = $wesiteinfo->paths->rootdir;
142 0 my $abspath = File::Spec->catfile($rootdir, $path);
143 0 my @file;
144 0 ▶ if (opendir(D, $abspath)) {
Branch: 1 branch
BranchTrueFalseTotal
if (opendir D, $abspath) 0 0 0
145 0 my $f;
146 0 ▶ while(defined($f = readdir(D))) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($f = readdir D)) 0 0 0
147 0 ▶ next if $f =~ /(^(RCS$|CVS$|\.)|~$ )/x;
Branch: 1 branch
BranchTrueFalseTotal
if $f =~ /(^(RCS$|CVS$|\.)|~$ )/x 0 0 0
148 0 my $desc = "";
149 0 ▶ if (open(DESC, File::Spec->catfile($abspath, ".desc.$f"))) {
Branch: 1 branch
BranchTrueFalseTotal
if (open DESC, "File::Spec"->catfile($abspath, ".desc.$f")) 0 0 0
150 0 local $/ = undef;
151 0 $desc = <DESC>;
152 0 close DESC;
153 }
154 0 my $absfile = File::Spec->catfile($abspath,$f);
155 0 my @s = stat $absfile;
156 0 ▶ push @file, {path => File::Spec->catfile($path,$f),
Branch: 1 branch
BranchTrueFalseTotal
-l $absfile ? : 0 0 0
157 directory => -d $absfile,
158 symlink => -l $absfile,
159 symlink_target => (-l $absfile ? readlink($absfile) : undef),
160 name => $f,
161 stat => \@s,
162 modtime => $s[9],
163 size => $s[7],
164 desc => $desc,
165 (DEBUG ? (fs_path => File::Spec->catfile($abspath,$f)) : ()),
166 };
167 }
168 0 closedir D;
169 }
170 0 @file = sort { $a->{name} cmp $b->{name} } @file;
171  
172 0 ▶ if ($path ne '/') {
Branch: 1 branch
BranchTrueFalseTotal
if ($path ne "/") 0 0 0
173 0 unshift @file, {path => dirname($path),
174 directory => 1,
175 name => "Parent directory",
176 desc => "Zur nächsthöheren Ebene (" . dirname($path) . ") wechseln",
177 s => [],
178 size => "",
179 modtime => "",
180 (DEBUG ? (fs_path => dirname($abspath)) : ()),
181 };
182 }
183  
184 0 $self->http_header("text/html");
185  
186 0 ▶ $t->process("tmpleditor_dirlisting.tpl.html",
Branch: 1 branch
BranchTrueFalseTotal
$t->process("tmpleditor_dirlisting.tpl.html", {"message", $message, "htmlmessage", $htmlmessage, "paths", $wesiteinfo->paths, "files", \@file, "r", $r, "currentdir", $path, "currentdirfs", $abspath, "dirwritable", -w $abspath, "debug", 0}) or die $t->error 0 0 0
187 { message => $message,
188 htmlmessage => $htmlmessage,
189 paths => $wesiteinfo->paths,
190 files => \@file,
191 r => $r,
192 currentdir => $path,
193 currentdirfs => $abspath,
194 dirwritable => -w $abspath,
195 debug => DEBUG,
196 }) or die $t->error;
197  
198 0 OK;
199 }
200  
201 0 ▶sub file_page {
Subroutine file_page: not called CC=8 SCAR=42.8
Pod undocumented
202 0 my($self, $path, %args) = @_;
203 0 my($r, $cgi, $t, $c) = @{$self}{qw(R CGI TT C)}; my $wesiteinfo = $c->{WEsiteinfo};
204 0 my $message = $args{-message};
205 0 my $htmlmessage = $args{-htmlmessage};
206  
207 0 my $rootdir = $wesiteinfo->paths->rootdir;
208 0 my $abspath = File::Spec->catfile($rootdir, $path);
209  
210 0 my $imgurl;
211 my $text;
212 0 my $text_fragment;
213 0 ▶ if ($path =~ /\.(gif|jpe?g|png|tiff?)$/) {
Branch: 2 branches
BranchTrueFalseTotal
if ($path =~ /\.(gif|jpe?g|png|tiff?)$/) { } 0 0 0
elsif (-T $abspath and open my $f, $abspath) { } 0 0 0
214 0 $imgurl = File::Spec->catfile($wesiteinfo->paths->rooturl, $path);
215 ▶ } elsif (-T $abspath && open(my $f, $abspath)) {
Condition0%0/3
-T $abspath and open my $f, $abspath
!ll&&!rl&&r
000
MC/DC0%0/2
-T $abspath and open my $f, $abspath
-T $abspath open my $f, $abspath
Truth table0%0/3
A and B
A= -T $abspathB= open my $f, $abspath
ABresult
0X0
100
111
216 0 local $/ = undef;
217 0 $text = <$f>;
218 0 ▶ if (length($text) > 1024) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $text > 1024) 0 0 0
219 0 $text_fragment = substr($text, 0, 512) . "\n\n ... (Teile der Datei weggelassen, bitte Download für Ansicht der kompletten Datei benutzen) ...\n\n" . substr($text, -512);
220 }
221 }
222  
223 # my @versions;
224 # my $vcs_url = "vcs://localhost/VCS::" . VCS_IMPL . $abspath;
225 # eval {
226 # my $vcs = VCS::File->new($vcs_url);
227 # @versions = $vcs->versions;
228 # };
229 # if ($@) {
230 # warn $@;
231 # }
232  
233 0 $self->http_header("text/html");
234  
235 0 ▶ $t->process("tmpleditor_filepage.tpl.html",
Branch: 3 branches
BranchTrueFalseTotal
$t->process("tmpleditor_filepage.tpl.html", {"message", $message, "htmlmessage", $htmlmessage, "paths", $wesiteinfo->paths, "r", $r, "currentfile", $path, "currentbasename", basename($path), "parentdir", dirname($path), "imgurl", defined $imgurl ? $imgurl : undef, "text", $text, "textfragment", $text_fragment, "filewritable", -w $abspath, "selfuri", $r ? $r->uri : $cgi->url("-relative", 1)}) or die $t->error 0 0 0
defined $imgurl ? : 0 0 0
$r ? : 0 0 0
236 { message => $message,
237 htmlmessage => $htmlmessage,
238 paths => $wesiteinfo->paths,
239 r => $r,
240 currentfile => $path,
241 currentbasename => basename($path),
242 parentdir => dirname($path),
243 imgurl => (defined $imgurl ? $imgurl : undef),
244 text => $text,
245 textfragment => $text_fragment,
246 # versions => \@versions,
247 filewritable => -w $abspath,
248 selfuri => $r ? $r->uri : $cgi->url(-relative => 1),
249 }) or die $t->error;
250  
251 0 OK;
252 }
253  
254 # sub version_page {
255 # my($self, $path, %args) = @_;
256 # my($r, $cgi, $t, $c) = @{$self}{qw(R CGI TT C)}; my $wesiteinfo = $c->{WEsiteinfo};
257 # my $message = $args{-message};
258 # my $htmlmessage = $args{-htmlmessage};
259  
260 # my $rootdir = $wesiteinfo->paths->rootdir;
261 # my $abspath = File::Spec->catfile($rootdir, $path);
262  
263 # my $version_nr = $cgi->param("version");
264  
265 # my $vcs_url = "vcs://localhost/VCS::" . VCS_IMPL . $abspath . "/$version_nr";
266 # my $vcs = VCS::File->new($vcs_url);
267  
268 # my $imgurl;# XXX not implemented
269 # my $text;
270 # my $text_fragment;
271 # if (-T $abspath && open(my $f, $abspath)) {
272 # local $/ = undef;
273 # $text = <$f>;
274 # if (length($text) > 2048) {
275 # $text_fragment = substr($text, 0, 1024) . "\n\n ... (Teile der Datei weggelassen, bitte Download für komplette Datei benutzen) ...\n\n" . substr($text, -1024);
276 # }
277 # }
278  
279 # $t->process("tmpleditor_versionpage.tpl.html",
280 # { message => $message,
281 # htmlmessage => $htmlmessage,
282 # paths => $wesiteinfo->paths,
283 # r => $r,
284 # currentfile => $path,
285 # version => $version_nr,
286 # imgurl => $imgurl,
287 # text => $text,
288 # textfragment => $text_fragment,
289 # versions => \@versions,
290 # }) or die $t->error;
291  
292 # return Apache::Constants::OK();
293 # }
294  
295 #sub upload_intermediate_page {
296 0 ▶sub do_upload {
Subroutine do_upload: not called CC=11 SCAR=48.8
Pod undocumented
297 0 my($self, $path, %args) = @_;
298 0 my($r, $cgi, $t, $c) = @{$self}{qw(R CGI TT C)}; my $wesiteinfo = $c->{WEsiteinfo};
299 0 my $message = $args{-message};
300 0 my $htmlmessage = $args{-htmlmessage};
301 0 my $rootdir = $wesiteinfo->paths->rootdir;
302 0 my $abspath = File::Spec->catfile($rootdir, $path);
303  
304 0 ▶ if ($cgi->param("uploadfile") eq '') {
Branch: 1 branch
BranchTrueFalseTotal
if ($cgi->param("uploadfile") eq "") 0 0 0
305 0 return $self->file_page($path, -message => "Bitte Uploaddatei angeben.");
306 }
307  
308 0 mkpath([UPLOADDIR],0,0775);
309  
310 # tie my %sess, 'Apache::Session::DB_File', undef,
311 # { FileName => UPLOADDIR . "/sessions.db", # XXX make configurable
312 # LockDirectory => '/tmp',
313 # }
314 # or die "Can't tie Apache::Session: $!";
315 # my $sessionid = $sess{_session_id};
316 # my $dest_file = File::Spec->catfile(UPLOADDIR, "upload-$sessionid");
317 0 my $dest_file = UPLOADDIR . "/$$";
318  
319 0 my $upload = $cgi->upload("uploadfile");
320 0 ▶ if (!$upload) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($upload) 0 0 0
321 0 return $self->file_page($path, -message => "Kein Upload?");
322 }
323  
324 0 ▶ open(my $out_fh, "> $dest_file") or die "Can't write to $dest_file: $!";
Branch: 1 branch
BranchTrueFalseTotal
open my $out_fh, "> $dest_file" or die "Can't write to ${dest_file}: $!" 0 0 0
325 0 ▶ my $in_fh = ref $upload && $upload->can("fh") ? $upload->fh : $upload;
Branch: 1 branch
BranchTrueFalseTotal
ref $upload && $upload->can('fh') ? : 0 0 0
Condition0%0/3
ref $upload and $upload->can("fh")
!ll&&!rl&&r
000
MC/DC0%0/2
ref $upload and $upload->can("fh")
ref $upload $upload->can("fh")
Truth table0%0/3
A and B
A= ref $uploadB= $upload->can("fh")
ABresult
0X0
100
111
326 0 ▶ while(<$in_fh>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline $in_fh)) 0 0 0
327 0 print $out_fh $_;
328 }
329 0 close $in_fh;
330 0 ▶ close $out_fh or do {
Branch: 1 branch
BranchTrueFalseTotal
close $out_fh or do { return $self->file_page($path, "-message", "Schreiben der Datei <$dest_file> fehlgeschlagen: $!") } 0 0 0
331 0 return $self->file_page($path, -message => "Schreiben der Datei <$dest_file> fehlgeschlagen: $!");
332 };
333  
334 0 ▶ if (!cp($dest_file, $abspath)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (cp($dest_file, $abspath)) 0 0 0
335 0 unlink $dest_file;
336 0 return $self->file_page($path, -message => "Kopieren von <$dest_file> nach <$abspath> fehlgeschlagen: $!");
337 }
338 0 unlink $dest_file;
339  
340 0 my $msg = "";
341 0 eval {
342 0 upload_hook($path, $abspath, \$msg);
343 };
344 0 ▶ if ($@ && $@ !~ /Undefined subroutine &WebEditor::SystemExplorer::upload_hook called/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@ and not $@ =~ /Undefined subroutine &WebEditor::SystemExplorer::upload_hook called/) 0 0 0
Condition0%0/3
$@ and not $@ =~ /Undefined subroutine &WebEditor::SystemExplorer::upload_hook called/
!ll&&!rl&&r
000
MC/DC0%0/2
$@ and not $@ =~ /Undefined subroutine &WebEditor::SystemExplorer::upload_hook called/
$@ not $@ =~ /Undefined subroutine &WebEditor::SystemExplorer::upload_hook called/
Truth table0%0/3
A and not(B)
A= $@B= not $@ =~ /Undefined subroutine &WebEditor::SystemExplorer::upload_hook called/
ABresult
0X0
100
111
345 0 return $self->file_page($path, -message => "Der Upload-Hook für $path hat die folgende Fehlermeldung erzeugt: $@");
346 }
347  
348 0 $self->file_page($path, -message => "Der Upload war erfolgreich. $msg");
349 }
350  
351 # sub do_upload {
352 # my($self, $path, %args) = @_;
353 # my($r, $cgi, $t, $c) = @{$self}{qw(R CGI TT C)}; my $wesiteinfo = $c->{WEsiteinfo};
354 # my $message = $args{-message};
355 # my $htmlmessage = $args{-htmlmessage};
356 # my $rootdir = $wesiteinfo->paths->rootdir;
357 # my $abspath = File::Spec->catfile($rootdir, $path);
358  
359 # tie my %sess, 'Apache::Session::DB_File', $cgi->param("sessionid"),
360 # { FileName => UPLOADDIR . "/sessions.db", # XXX make configurable
361 # LockDirectory => '/tmp',
362 # }
363 # or die "Can't tie Apache::Session with id " . $cgi->param("sessionid") . ": $!";
364  
365 # my $uploadfile = $sess{file};
366 # if (!-e $uploadfile) {
367 # return $self->file_page($path, -message => "Upload fehlgeschlagen. Datei auf dem Server <$uploadfile> existiert nicht mehr.");
368 # }
369  
370 # my $logentry = $cgi->param("logentry")||"";
371  
372 # my $vcs_url = "vcs://localhost/VCS::" . VCS_IMPL . $abspath;
373 # my $vcs;
374 # eval {
375 # $vcs = VCS::File->new($vcs_url);
376 # };
377 # if (!$vcs) {
378 # my $rcsdir = File::Spec->catfile(dirname($abspath), "RCS");
379 # if (!-d $rcsdir) {
380 # mkdir $rcsdir;
381 # }
382 # if (!-d $rcsdir) {
383 # return $self->file_page($path, -message => "Das RCS-Verzeichnis <$rcsdir> konnte nicht angelegt werden.");
384 # }
385 # eval {
386 # $vcs = VCS::File->new($vcs_url);
387 # };
388 # if (!$vcs) {
389 # # erst einmal alte Version erzeugen
390 # system("ci", "-l", $abspath);
391 # }
392 # }
393  
394 # if (!cp($uploadfile, $abspath)) {
395 # return $self->file_page($path, -message => "<$uploadfile> konnte nicht nach <$abspath> kopiert werden.");
396 # }
397  
398 # system("ci", "-m$logentry", "-l", $abspath);
399  
400 # $vcs = VCS::File->new($vcs_url);
401  
402 # my $version_nr = ($vcs->versions)[-1]->version;
403  
404 # tied(%sess)->delete;
405  
406 # $self->file_page($path, -message => "Version $version_nr erfolgreich angelegt.");
407  
408 # }
409  
410 0 ▶sub do_download {
Subroutine do_download: not called CC=3 SCAR=24.8
Pod undocumented
411 0 my($self, $path) = @_;
412 0 my($r, $cgi, $t, $c) = @{$self}{qw(R CGI TT C)}; my $wesiteinfo = $c->{WEsiteinfo};
413 0 my $rootdir = $wesiteinfo->paths->rootdir;
414 0 my $abspath = File::Spec->catfile($rootdir, $path);
415  
416 0 my $contenttype = "application/octet-stream";
417 0 $self->http_header($contenttype);
418 0 ▶ open(my $fh, $abspath) or die "Can't open $abspath: $!";
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, $abspath or die "Can't open ${abspath}: $!" 0 0 0
419 0 ▶ while(<$fh>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline $fh)) 0 0 0
420 0 print $_;
421 }
422 0 OK;
423 }
424  
425 0 ▶sub do_del_file {
Subroutine do_del_file: not called CC=2 SCAR=17.9
Pod undocumented
426 0 my($self, $path) = @_;
427 0 my($r, $cgi, $t, $c) = @{$self}{qw(R CGI TT C)};
428 0 my $wesiteinfo = $c->{WEsiteinfo};
429 0 my $rootdir = $wesiteinfo->paths->rootdir;
430 0 my $abspath = File::Spec->catfile($rootdir, $path);
431 0 unlink $abspath;
432 0 ▶ if (-e $abspath) {
Branch: 1 branch
BranchTrueFalseTotal
if (-e $abspath) 0 0 0
433 0 return $self->file_page($path, -message => "Die Datei <$path> konnte nicht gelöscht werden. Grund: $!");
434 }
435 0 $self->directory_listing(dirname($path), -message => "Die Datei <$path> wurde erfolgreich gelöscht.");
436 }
437  
438 0 ▶sub new_file_form {
Subroutine new_file_form: not called CC=2 SCAR=17.9
Pod undocumented
439 0 my($self, $path, %args) = @_;
440 0 my($r, $cgi, $t, $c) = @{$self}{qw(R CGI TT C)}; my $wesiteinfo = $c->{WEsiteinfo};
441 0 my $message = $args{-message};
442 0 my $htmlmessage = $args{-htmlmessage};
443  
444 0 $self->http_header("text/html");
445  
446 0 ▶ $t->process("tmpleditor_newfile.tpl.html",
Branch: 1 branch
BranchTrueFalseTotal
$t->process("tmpleditor_newfile.tpl.html", {"message", $message, "htmlmessage", $htmlmessage, "paths", $wesiteinfo->paths, "r", $r, "currentdir", $path}) or die $t->error 0 0 0
447 { message => $message,
448 htmlmessage => $htmlmessage,
449 paths => $wesiteinfo->paths,
450 r => $r,
451 currentdir => $path,
452 }) or die $t->error;
453  
454 0 OK;
455 }
456  
457 0 ▶sub new_file {
Subroutine new_file: not called CC=14 SCAR=53.5
Pod undocumented
458 0 my($self, $path, %args) = @_;
459  
460 0 my($r, $cgi, $t, $c) = @{$self}{qw(R CGI TT C)}; my $wesiteinfo = $c->{WEsiteinfo};
461 0 my $message = $args{-message};
462 0 my $htmlmessage = $args{-htmlmessage};
463  
464 0 ▶ if ($cgi->param("uploadfile") eq '') {
Branch: 1 branch
BranchTrueFalseTotal
if ($cgi->param("uploadfile") eq "") 0 0 0
465 0 return $self->new_file_form($path, -message => "Bitte Uploaddatei angeben.");
466 }
467  
468 0 ▶ my $basename = $cgi->param("filename") || "";
Condition0%0/2
$cgi->param('filename') || ''
l!l
00
MC/DC0%0/1
$cgi->param('filename') || ''
$cgi->param('filename')
Truth table0%0/2
A
A= $cgi->param('filename')
Aresult
11
00
469 0 ▶ if ($basename ne "" && _invalid_file_name($basename)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($basename ne "" and _invalid_file_name($basename)) 0 0 0
Condition0%0/3
$basename ne "" and _invalid_file_name($basename)
!ll&&!rl&&r
000
MC/DC0%0/2
$basename ne "" and _invalid_file_name($basename)
$basename ne "" _invalid_file_name($basename)
Truth table0%0/3
A and B
A= $basename ne ""B= _invalid_file_name($basename)
ABresult
0X0
100
111
470 0 return $self->new_file_form($path, -message => "Dateiname ist ungültig");
471 }
472  
473 0 my $upload = $cgi->upload("uploadfile");
474 0 ▶ if (!$upload) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($upload) 0 0 0
475 0 return $self->new_file_form($path, -message => "Kein Upload?");
476 }
477  
478 0 ▶ if ($basename eq '') {
Branch: 1 branch
BranchTrueFalseTotal
if ($basename eq "") 0 0 0
479 0 $basename = basename($upload->filename);
480 0 $basename =~ s|.*\\||; # strip DOS file names
481 0 ▶ if (_invalid_file_name($basename)) {
Branch: 1 branch
BranchTrueFalseTotal
if (_invalid_file_name($basename)) 0 0 0
482 0 return $self->new_file_form($path, -message => "Automatisch ermittelter Dateiname <$basename> ist ungültig, bitte einen anderen Dateinamen angeben.");
483 }
484 }
485  
486 0 my $rootdir = $wesiteinfo->paths->rootdir;
487 0 my $abspath = File::Spec->catfile($rootdir, $path);
488  
489 0 my $out_name = File::Spec->catfile($abspath, $basename);
490  
491 0 ▶ open(my $out_fh, "> $out_name") or die "Can't write to $out_name: $!";
Branch: 1 branch
BranchTrueFalseTotal
open my $out_fh, "> $out_name" or die "Can't write to ${out_name}: $!" 0 0 0
492 0 ▶ my $in_fh = ref $upload && $upload->can("fh") ? $upload->fh : $upload;
Branch: 1 branch
BranchTrueFalseTotal
ref $upload && $upload->can('fh') ? : 0 0 0
Condition0%0/3
ref $upload and $upload->can("fh")
!ll&&!rl&&r
000
MC/DC0%0/2
ref $upload and $upload->can("fh")
ref $upload $upload->can("fh")
Truth table0%0/3
A and B
A= ref $uploadB= $upload->can("fh")
ABresult
0X0
100
111
493 0 ▶ while(<$in_fh>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline $in_fh)) 0 0 0
494 0 print $out_fh $_;
495 }
496 0 close $in_fh;
497 0 close $out_fh;
498  
499 0 my $msg = "";
500 0 eval {
501 0 newfile_hook($path, $abspath, \$msg);
502 };
503 0 ▶ if ($@ && $@ !~ /Undefined subroutine &WebEditor::SystemExplorer::newfile_hook called/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@ and not $@ =~ /Undefined subroutine &WebEditor::SystemExplorer::newfile_hook called/) 0 0 0
Condition0%0/3
$@ and not $@ =~ /Undefined subroutine &WebEditor::SystemExplorer::newfile_hook called/
!ll&&!rl&&r
000
MC/DC0%0/2
$@ and not $@ =~ /Undefined subroutine &WebEditor::SystemExplorer::newfile_hook called/
$@ not $@ =~ /Undefined subroutine &WebEditor::SystemExplorer::newfile_hook called/
Truth table0%0/3
A and not(B)
A= $@B= not $@ =~ /Undefined subroutine &WebEditor::SystemExplorer::newfile_hook called/
ABresult
0X0
100
111
504 0 return $self->file_page($path, -message => "Der Hook für $path hat die folgende Fehlermeldung erzeugt: $@");
505 }
506  
507 0 return $self->directory_listing($path, -message => "Die Datei <$basename> wurde erfolgreich gespeichert. $msg");
508 }
509  
510 0 ▶sub new_dir_form {
Subroutine new_dir_form: not called CC=2 SCAR=17.9
Pod undocumented
511 0 my($self, $path, %args) = @_;
512 0 my($r, $cgi, $t, $c) = @{$self}{qw(R CGI TT C)}; my $wesiteinfo = $c->{WEsiteinfo};
513 0 my $message = $args{-message};
514 0 my $htmlmessage = $args{-htmlmessage};
515  
516 0 $self->http_header("text/html");
517  
518 0 ▶ $t->process("tmpleditor_newdir.tpl.html",
Branch: 1 branch
BranchTrueFalseTotal
$t->process("tmpleditor_newdir.tpl.html", {"message", $message, "htmlmessage", $htmlmessage, "paths", $wesiteinfo->paths, "r", $r, "currentdir", $path}) or die $t->error 0 0 0
519 { message => $message,
520 htmlmessage => $htmlmessage,
521 paths => $wesiteinfo->paths,
522 r => $r,
523 currentdir => $path,
524 }) or die $t->error;
525  
526 0 OK;
527 }
528  
529 0 ▶sub new_dir {
Subroutine new_dir: not called CC=5 SCAR=34.0
Pod undocumented
530 0 my($self, $path, %args) = @_;
531  
532 0 my($r, $cgi, $t, $c) = @{$self}{qw(R CGI TT C)}; my $wesiteinfo = $c->{WEsiteinfo};
533 0 my $message = $args{-message};
534 0 my $htmlmessage = $args{-htmlmessage};
535  
536 0 ▶ my $basename = $cgi->param("dirname") || "";
Condition0%0/2
$cgi->param('dirname') || ''
l!l
00
MC/DC0%0/1
$cgi->param('dirname') || ''
$cgi->param('dirname')
Truth table0%0/2
A
A= $cgi->param('dirname')
Aresult
11
00
537 0 ▶ if ($basename eq "") {
Branch: 1 branch
BranchTrueFalseTotal
if ($basename eq "") 0 0 0
538 0 return $self->new_dir_form($path, -message => "Es wurde kein Verzeichnisname angegeben.");
539 }
540 0 ▶ if (_invalid_file_name($basename)) {
Branch: 1 branch
BranchTrueFalseTotal
if (_invalid_file_name($basename)) 0 0 0
541 0 return $self->new_dir_form($path, -message => "Verzeichnisname ist ungültig");
542 }
543  
544 0 my $rootdir = $wesiteinfo->paths->rootdir;
545 0 my $abspath = File::Spec->catfile($rootdir, $path);
546  
547 0 my $out_name = File::Spec->catfile($abspath, $basename);
548  
549 0 mkdir $out_name, 0777;
550 0 ▶ if (!-d $out_name) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-d $out_name) 0 0 0
551 0 return $self->new_dir_form($path, -message => "Das Verzeichnis $out_name konnte nicht erzeugt werden: $!");
552 }
553  
554 0 return $self->directory_listing($path, -message => "Das Verzeichnis <$basename> wurde erfolgreich erzeugt.");
555 }
556  
557 0 ▶sub check_permissions {
Subroutine check_permissions: not called CC=5 SCAR=34.0
Pod undocumented
558 0 my($self, $relpath, $msgref) = @_;
559 0 ▶ if (_invalid_path_name($relpath)) {
Branch: 1 branch
BranchTrueFalseTotal
if (_invalid_path_name($relpath)) 0 0 0
560 0 ▶ $$msgref = "Invalid file name (contains ..): $relpath"
Branch: 1 branch
BranchTrueFalseTotal
if ref $msgref 0 0 0
561 if ref $msgref;
562 0 return 0;
563 }
564 0 ▶ if ($relpath !~ m#^(|images|styles|we/(styles|script|images|we_templates|oszportal_(templates|prototypes|we_prototypes)))/#) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($relpath =~ m[^(|images|styles|we/(styles|script|images|we_templates|oszportal_(templates|prototypes|we_prototypes)))/]) 0 0 0
565 0 ▶ $$msgref = "Invalid file name: $relpath"
Branch: 1 branch
BranchTrueFalseTotal
if ref $msgref 0 0 0
566 if ref $msgref;
567 0 return 0;
568 }
569 0 return 1;
570 }
571  
572 0 ▶sub _invalid_path_name {
Subroutine _invalid_path_name: not called CC=2 SCAR=17.9
573 0 my $file = shift;
574 0 ▶ return 1 if $file =~ /(^|\/)\.\.($|\/)/;
Branch: 1 branch
BranchTrueFalseTotal
if $file =~ m[(^|/)\.\.($|/)] 0 0 0
575 }
576  
577 0 ▶sub _invalid_file_name {
Subroutine _invalid_file_name: not called CC=3 SCAR=24.8
578 0 my $file = shift;
579 0 ▶ return 1 if $file =~ m|/|;
Branch: 1 branch
BranchTrueFalseTotal
if $file =~ m[/] 0 0 0
580 0 ▶ return 1 if $file =~ m|^\.|; # no hidden files, please
Branch: 1 branch
BranchTrueFalseTotal
if $file =~ /^\./ 0 0 0
581 0 return _invalid_path_name($file);
582 }
583  
584 1 1;
585  
586 __END__
« WE/DB/FS.pm ↑ Summary WE_Frontend/Plugin/Linear.pm »