Sharedwww / cgi-bin / openwebmail / openwebmail-webdisk.plOpen in CoCalc
Author: William A. Stein
1
#!/usr/bin/perl
2
#
3
# openwebmail-webdisk.pl - web disk program
4
#
5
# 2002/12/30 tung.AT.turtle.ee.ncku.edu.tw
6
#
7
# To prevent shell escape, all external commands are executed through exec
8
# with parameters in an array, this makes perl call execvp directly instead
9
# of invoking the /bin/sh
10
#
11
# Path names from CGI are treated as virtual paths under $webdiskrootdir
12
# ($homedir/$config{webdisk_rootpath}), and all pathnames will be prefixed
13
# with $webdiskrootdir before passing to external command for security
14
#
15
# To disable the use of symbolic link, please refer to openwebmail.conf.help
16
# for options webdisk_lssymlink and webdisk_allow_symlinkout
17
#
18
19
use vars qw($SCRIPT_DIR);
20
if ( $0 =~ m!^(\S*)/[\w\d\-\.]+\.pl! ) { $SCRIPT_DIR=$1 }
21
if ($SCRIPT_DIR eq '' && open(F, '/etc/openwebmail/openwebmail_path.conf')) {
22
$_=<F>; close(F); if ( $_=~/^(\S*)/) { $SCRIPT_DIR=$1 }
23
}
24
if ($SCRIPT_DIR eq '') { print "Content-type: text/html\n\nSCRIPT_DIR not set in /etc/openwebmail/openwebmail_path.conf !\n"; exit 0; }
25
push (@INC, $SCRIPT_DIR);
26
27
foreach (qw(ENV BASH_ENV CDPATH IFS TERM)) {delete $ENV{$_}}; $ENV{PATH}='/bin:/usr/bin'; # secure ENV
28
umask(0002); # make sure the openwebmail group can write
29
30
use strict;
31
use Fcntl qw(:DEFAULT :flock);
32
use CGI qw(-private_tempfiles :standard);
33
use CGI::Carp qw(fatalsToBrowser carpout);
34
35
require "modules/dbm.pl";
36
require "modules/suid.pl";
37
require "modules/filelock.pl";
38
require "modules/tool.pl";
39
require "modules/execute.pl";
40
require "modules/datetime.pl";
41
require "modules/lang.pl";
42
require "modules/htmltext.pl";
43
require "auth/auth.pl";
44
require "quota/quota.pl";
45
require "shares/ow-shared.pl";
46
require "shares/iconv.pl";
47
require "shares/cut.pl";
48
49
# common globals
50
use vars qw(%config %config_raw);
51
use vars qw($thissession);
52
use vars qw($domain $user $userrealname $uuid $ugid $homedir);
53
use vars qw(%prefs %style %icontext);
54
use vars qw($quotausage $quotalimit);
55
56
# extern vars
57
use vars qw(%lang_folders %lang_sizes %lang_wdbutton %lang_text %lang_err); # defined in lang/xy
58
59
# local globals
60
use vars qw($folder $messageid);
61
use vars qw($escapedmessageid $escapedfolder);
62
use vars qw($webdiskrootdir);
63
64
########## MAIN ##################################################
65
openwebmail_requestbegin();
66
$SIG{PIPE}=\&openwebmail_exit; # for user stop
67
$SIG{TERM}=\&openwebmail_exit; # for user stop
68
69
userenv_init();
70
71
if (!$config{'enable_webdisk'}) {
72
openwebmailerror(__FILE__, __LINE__, "$lang_text{'webdisk'} $lang_err{'access_denied'}");
73
}
74
75
# userenv_init() will set umask to 0077 to protect mail folder data.
76
# set umask back to 0022 here dir & files are created as world readable
77
umask(0022);
78
79
$folder = param('folder') || 'INBOX';
80
$messageid = param('message_id')||'';
81
82
$escapedfolder = ow::tool::escapeURL($folder);
83
$escapedmessageid = ow::tool::escapeURL($messageid);
84
85
$webdiskrootdir=$homedir.absolute_vpath("/", $config{'webdisk_rootpath'});
86
($webdiskrootdir =~ m!^(.+)/?$!) && ($webdiskrootdir = $1); # untaint & remove tail /
87
if (! -d $webdiskrootdir) {
88
mkdir($webdiskrootdir, 0755) or
89
openwebmailerror(__FILE__, __LINE__, "lang_text{'cant_create_dir'} $webdiskrootdir ($!)");
90
}
91
92
my $action = param('action')||'';
93
my $currentdir;
94
if (defined(param('currentdir')) && param('currentdir') ne "") {
95
$currentdir = param('currentdir');
96
} else {
97
$currentdir = cookie("$user-currentdir"),
98
}
99
my $gotodir = param('gotodir')||'';
100
my @selitems = (param('selitems'));
101
my $destname = param('destname')||'';
102
my $filesort = param('filesort')|| 'name';
103
my $page = param('page') || 1;
104
105
# all path in param are treated as virtual path under $webdiskrootdir.
106
$currentdir = absolute_vpath("/", $currentdir);
107
$gotodir = absolute_vpath($currentdir, $gotodir);
108
109
my $msg=verify_vpath($webdiskrootdir, $currentdir);
110
openwebmailerror(__FILE__, __LINE__, $msg) if ($msg ne '');
111
$currentdir=ow::tool::untaint($currentdir);
112
113
if ($action eq "mkdir" || defined(param('mkdirbutton')) ) {
114
if ($config{'webdisk_readonly'}) {
115
$msg=$lang_err{'webdisk_readonly'};
116
} elsif (is_quota_available(0)) {
117
$msg=createdir($currentdir, $destname) if ($destname);
118
} else {
119
$msg="$lang_err{'quotahit_alert'}\n";
120
}
121
showdir($currentdir, $gotodir, $filesort, $page, $msg);
122
123
} elsif ($action eq "newfile" || defined(param('newfilebutton'))) {
124
if ($config{'webdisk_readonly'}) {
125
$msg="$lang_err{'webdisk_readonly'}\n";
126
} elsif (is_quota_available(0)) {
127
$msg=createfile($currentdir, $destname) if ($destname);
128
} else {
129
$msg="$lang_err{'quotahit_alert'}\n";
130
}
131
showdir($currentdir, $gotodir, $filesort, $page, $msg);
132
133
} elsif ($action eq "copy" || defined(param('copybutton'))) {
134
if ($config{'webdisk_readonly'}) {
135
$msg="$lang_err{'webdisk_readonly'}\n";
136
} elsif (is_quota_available(0)) {
137
$msg=copymovesymlink_dirfiles("copy", $currentdir, $destname, @selitems) if ($#selitems>=0);
138
} else {
139
$msg="$lang_err{'quotahit_alert'}\n";
140
}
141
showdir($currentdir, $gotodir, $filesort, $page, $msg);
142
143
} elsif ($action eq "move" || defined(param('movebutton'))) {
144
if ($config{'webdisk_readonly'}) {
145
$msg="$lang_err{'webdisk_readonly'}\n";
146
} elsif (is_quota_available(0)) {
147
$msg=copymovesymlink_dirfiles("move", $currentdir, $destname, @selitems) if ($#selitems>=0);
148
} else {
149
$msg="$lang_err{'quotahit_alert'}\n";
150
}
151
showdir($currentdir, $gotodir, $filesort, $page, $msg);
152
153
} elsif ( $config{'webdisk_allow_symlinkcreate'} &&
154
($action eq "symlink" || defined(param('symlinkbutton'))) ){
155
if ($config{'webdisk_readonly'}) {
156
$msg="$lang_err{'webdisk_readonly'}\n";
157
} elsif (is_quota_available(0)) {
158
$msg=copymovesymlink_dirfiles("symlink", $currentdir, $destname, @selitems) if ($#selitems>=0);
159
} else {
160
$msg="$lang_err{'quotahit_alert'}\n";
161
}
162
showdir($currentdir, $gotodir, $filesort, $page, $msg);
163
164
} elsif ($action eq "delete" || defined(param('deletebutton'))) {
165
if ($config{'webdisk_readonly'}) {
166
$msg="$lang_err{'webdisk_readonly'}\n";
167
} else {
168
$msg=deletedirfiles($currentdir, @selitems) if ($#selitems>=0);
169
}
170
showdir($currentdir, $gotodir, $filesort, $page, $msg);
171
172
} elsif ($action eq "editfile" || defined(param('editbutton'))) {
173
if ($config{'webdisk_readonly'}) {
174
autoclosewindow($lang_wdbutton{'edit'}, $lang_err{'webdisk_readonly'});
175
} elsif (is_quota_available(0)) {
176
if ($#selitems==0) {
177
editfile($currentdir, $selitems[0]);
178
} else {
179
autoclosewindow($lang_wdbutton{'edit'}, $lang_err{'onefileonly'});
180
}
181
} else {
182
autoclosewindow($lang_text{'quotahit'}, $lang_err{'quotahit_alert'});
183
}
184
185
} elsif ($action eq "savefile" || defined(param('savebutton'))) {
186
if ($config{'webdisk_readonly'}) {
187
autoclosewindow($lang_wdbutton{'edit'}, $lang_err{'webdisk_readonly'});
188
} elsif (is_quota_available(0)) {
189
savefile($currentdir, $destname, param('filecontent')) if ($destname ne '');
190
} else {
191
autoclosewindow($lang_text{'quotahit'}, $lang_err{'quotahit_alert'});
192
}
193
194
} elsif ($action eq "gzip" || defined(param('gzipbutton'))) {
195
if ($config{'webdisk_readonly'}) {
196
$msg="$lang_err{'webdisk_readonly'}\n";
197
} elsif (is_quota_available(0)) {
198
$msg=compressfiles("gzip", $currentdir, '', @selitems) if ($#selitems>=0);
199
} else {
200
$msg="$lang_err{'quotahit_alert'}\n";
201
}
202
showdir($currentdir, $gotodir, $filesort, $page, $msg);
203
204
} elsif ($action eq "mkzip" || defined(param('mkzipbutton'))) {
205
if ($config{'webdisk_readonly'}) {
206
$msg="$lang_err{'webdisk_readonly'}\n";
207
} elsif (is_quota_available(0)) {
208
$msg=compressfiles("mkzip", $currentdir, $destname, @selitems) if ($#selitems>=0);
209
} else {
210
$msg="$lang_err{'quotahit_alert'}\n";
211
}
212
showdir($currentdir, $gotodir, $filesort, $page, $msg);
213
214
} elsif ($action eq "mktgz" || defined(param('mktgzbutton'))) {
215
if ($config{'webdisk_readonly'}) {
216
$msg="$lang_err{'webdisk_readonly'}\n";
217
} elsif (is_quota_available(0)) {
218
$msg=compressfiles("mktgz", $currentdir, $destname, @selitems) if ($#selitems>=0);
219
} else {
220
$msg="$lang_err{'quotahit_alert'}\n";
221
}
222
showdir($currentdir, $gotodir, $filesort, $page, $msg);
223
224
} elsif ($action eq "decompress" || defined(param('decompressbutton'))) {
225
if ($config{'webdisk_readonly'}) {
226
$msg="$lang_err{'webdisk_readonly'}\n";
227
} elsif (is_quota_available(0)) {
228
if ($#selitems==0) {
229
$msg=decompressfile($currentdir, $selitems[0]);
230
} else {
231
$msg="$lang_wdbutton{'decompress'} - $lang_err{'onefileonly'}";
232
}
233
} else {
234
$msg="$lang_err{'quotahit_alert'}\n";
235
}
236
showdir($currentdir, $gotodir, $filesort, $page, $msg);
237
238
} elsif ($action eq "listarchive" || defined(param('listarchivebutton'))) {
239
if ($#selitems==0) {
240
$msg=listarchive($currentdir, $selitems[0]);
241
} else {
242
$msg="$lang_wdbutton{'listarchive'} - $lang_err{'onefileonly'}";
243
}
244
245
} elsif ($action eq "wordpreview" || defined(param('wordpreviewbutton'))) {
246
if ($#selitems==0) {
247
$msg=wordpreview($currentdir, $selitems[0]);
248
} else {
249
$msg="MS Word $lang_wdbutton{'preview'} - $lang_err{'onefileonly'}";
250
}
251
252
} elsif ($action eq "mkpdf" || defined(param('mkpdfbutton')) ) {
253
if ($config{'webdisk_readonly'}) {
254
$msg="$lang_err{'webdisk_readonly'}\n";
255
} elsif (is_quota_available(0)) {
256
if ($#selitems==0) {
257
$msg=makepdfps('mkpdf', $currentdir, $selitems[0]);
258
} else {
259
$msg="$lang_wdbutton{'mkpdf'} - $lang_err{'onefileonly'}";
260
}
261
} else {
262
$msg="$lang_err{'quotahit_alert'}\n";
263
}
264
showdir($currentdir, $gotodir, $filesort, $page, $msg);
265
266
} elsif ($action eq "mkps" || defined(param('mkpsbutton')) ) {
267
if ($config{'webdisk_readonly'}) {
268
$msg="$lang_err{'webdisk_readonly'}\n";
269
} elsif (is_quota_available(0)) {
270
if ($#selitems==0) {
271
$msg=makepdfps('mkps', $currentdir, $selitems[0]);
272
} else {
273
$msg="$lang_wdbutton{'mkps'} - $lang_err{'onefileonly'}";
274
}
275
} else {
276
$msg="$lang_err{'quotahit_alert'}\n";
277
}
278
showdir($currentdir, $gotodir, $filesort, $page, $msg);
279
280
} elsif ($action eq "mkthumbnail" || defined(param('mkthumbnailbutton'))) {
281
if ($config{'webdisk_readonly'}) {
282
$msg="$lang_err{'webdisk_readonly'}\n";
283
} elsif (is_quota_available(0)) {
284
$msg=makethumbnail($currentdir, @selitems) if ($#selitems>=0);
285
} else {
286
$msg="$lang_err{'quotahit_alert'}\n";
287
}
288
showdir($currentdir, $gotodir, $filesort, $page, $msg);
289
290
} elsif ($action eq "preview") {
291
my $vpath=absolute_vpath($currentdir, $selitems[0]);
292
my $filecontent=param('filecontent')||'';
293
if ($#selitems==0) {
294
if ( $filecontent) {
295
$msg=previewfile($currentdir, $selitems[0], $filecontent);
296
} elsif ( -d "$webdiskrootdir/$vpath" ) {
297
showdir($currentdir, $vpath, $filesort, $page, $msg); $msg='';
298
} else {
299
$msg=previewfile($currentdir, $selitems[0], '');
300
}
301
} else {
302
$msg=$lang_err{'no_file_todownload'};
303
}
304
openwebmailerror(__FILE__, __LINE__, $msg) if ($msg ne '');
305
306
} elsif ($action eq "download" || defined(param('downloadbutton'))) {
307
if ($#selitems>0) {
308
$msg=downloadfiles($currentdir, @selitems);
309
} elsif ($#selitems==0) {
310
my $vpath=absolute_vpath($currentdir, $selitems[0]);
311
if ( -d "$webdiskrootdir/$vpath" ) {
312
$msg=downloadfiles($currentdir, @selitems);
313
} else {
314
$msg=downloadfile($currentdir, $selitems[0]);
315
}
316
} else {
317
$msg="$lang_err{'no_file_todownload'}\n";
318
}
319
showdir($currentdir, $gotodir, $filesort, $page, $msg) if ($msg ne '');
320
321
} elsif ($action eq "upload" || defined(param('uploadbutton'))) {
322
if ($config{'webdisk_readonly'}) {
323
$msg="$lang_err{'webdisk_readonly'}\n";
324
} elsif (is_quota_available(0)) {
325
my $upload=param('upload'); # name and handle of the upload file
326
$msg=uploadfile($currentdir, $upload) if ($upload);
327
} else {
328
$msg="$lang_err{'quotahit_alert'}\n";
329
}
330
showdir($currentdir, $gotodir, $filesort, $page, $msg);
331
332
} elsif ($action eq "sel_addattachment") { # used in composemsg to add attachment
333
dirfilesel($action, $currentdir, $gotodir, $filesort, $page);
334
335
} elsif ($action eq "sel_saveattfile" || # used in composemsg to save attfile
336
$action eq "sel_saveattachment") { # used in readmsg to save attachment
337
if ($config{'webdisk_readonly'}) {
338
autoclosewindow($lang_wdbutton{'edit'}, $lang_err{'webdisk_readonly'});
339
} elsif (is_quota_available(0)) {
340
dirfilesel($action, $currentdir, $gotodir, $filesort, $page);
341
} else {
342
autoclosewindow($lang_text{'quotahit'}, $lang_err{'quotahit_alert'});
343
}
344
345
} elsif ($action eq "userrefresh") {
346
if ($config{'quota_module'} ne 'none') {
347
$quotausage=(ow::quota::get_usage_limit(\%config, $user, $homedir, 1))[2];
348
}
349
showdir($currentdir, $gotodir, $filesort, $page, $msg);
350
351
} elsif ($action eq "showdir" || $action eq "" || defined(param('chdirbutton'))) {
352
# put chdir in last or user will be matched by ($action eq "") when clicking button
353
if ($destname ne '') { # chdir
354
$destname = absolute_vpath($currentdir, $destname);
355
showdir($currentdir, $destname, $filesort, $page, $msg);
356
} else { # showdir, refresh
357
showdir($currentdir, $gotodir, $filesort, $page, $msg);
358
}
359
360
} else {
361
openwebmailerror(__FILE__, __LINE__, "Action $lang_err{'has_illegal_chars'}");
362
}
363
364
openwebmail_requestend();
365
########## END MAIN ##############################################
366
367
########## CREATEDIR #############################################
368
sub createdir {
369
my ($currentdir, $destname)=@_;
370
371
my $vpath=ow::tool::untaint(absolute_vpath($currentdir, $destname));
372
my $err=verify_vpath($webdiskrootdir, $vpath);
373
return ("$err\n") if ($err ne '');
374
375
if ( -e "$webdiskrootdir/$vpath") {
376
return("$lang_text{'dir'} $vpath $lang_err{'already_exists'}\n") if (-d _);
377
return("$lang_text{'file'} $vpath $lang_err{'already_exists'}\n");
378
} else {
379
if (mkdir("$webdiskrootdir/$vpath", 0755)) {
380
writelog("webdisk mkdir - $vpath");
381
writehistory("webdisk mkdir - $vpath");
382
return("$lang_wdbutton{'mkdir'} $vpath\n");
383
} else {
384
return("$lang_err{'couldnt_open'} $vpath ($!)\n");
385
}
386
}
387
}
388
########## END CREATEDIR #########################################
389
390
########## NEWFILE ###############################################
391
sub createfile {
392
my ($currentdir, $destname)=@_;
393
394
my $vpath=ow::tool::untaint(absolute_vpath($currentdir, $destname));
395
my $err=verify_vpath($webdiskrootdir, $vpath);
396
return ("$err\n") if ($err ne '');
397
398
if ( -e "$webdiskrootdir/$vpath") {
399
return("$lang_text{'dir'} $vpath $lang_err{'already_exists'}\n") if (-d _);
400
return("$lang_text{'file'} $vpath $lang_err{'already_exists'}\n");
401
} else {
402
if (open(F, ">$webdiskrootdir/$vpath")) {
403
print F "";
404
close(F);
405
writelog("webdisk createfile - $vpath");
406
writehistory("webdisk createfile - $vpath");
407
return("$lang_wdbutton{'newfile'} $vpath\n");
408
} else {
409
return("$lang_err{'couldnt_open'} $vpath ($!)\n");
410
}
411
}
412
}
413
########## END NEWFILE ###########################################
414
415
########## DELETEDIRFILES ########################################
416
sub deletedirfiles {
417
my ($currentdir, @selitems)=@_;
418
my ($msg, $err);
419
420
my @filelist;
421
foreach (@selitems) {
422
my $vpath=ow::tool::untaint(absolute_vpath($currentdir, $_));
423
$err=verify_vpath($webdiskrootdir, $vpath);
424
if ($err ne '') {
425
$msg.="$err\n"; next;
426
}
427
if (!-l "$webdiskrootdir/$vpath" && !-e "$webdiskrootdir/$vpath") {
428
$msg.="$vpath $lang_err{'doesnt_exist'}\n"; next;
429
}
430
if (-f _ && $vpath=~/\.(?:jpe?g|gif|png|bmp|tif)$/i) {
431
my $thumbnail=path2thumbnail("$webdiskrootdir/$vpath");
432
push(@filelist, $thumbnail) if (-f $thumbnail);
433
}
434
push(@filelist, "$webdiskrootdir/$vpath");
435
}
436
return($msg) if ($#filelist<0);
437
438
my @cmd;
439
my $rmbin=ow::tool::findbin('rm');
440
return("$lang_text{'program'} rm $lang_err{'doesnt_exist'}\n") if ($rmbin eq '');
441
@cmd=($rmbin, '-Rfv');
442
443
chdir("$webdiskrootdir/$currentdir") or
444
return("$lang_err{'couldnt_chdirto'} $currentdir\n");
445
446
my $msg2=webdisk_execute($lang_wdbutton{'delete'}, @cmd, @filelist);
447
if ($msg2=~/rm:/) {
448
$cmd[1]=~s/v//;
449
$msg2=webdisk_execute($lang_wdbutton{'delete'}, @cmd, @filelist);
450
}
451
$msg.=$msg2;
452
if ($quotalimit>0 && $quotausage>$quotalimit) { # get uptodate quotausage
453
$quotausage=(ow::quota::get_usage_limit(\%config, $user, $homedir, 1))[2];
454
}
455
return($msg);
456
}
457
########## END DELETEDIRFILES ####################################
458
459
########## COPYDIRFILES ##########################################
460
sub copymovesymlink_dirfiles {
461
my ($op, $currentdir, $destname, @selitems)=@_;
462
my ($msg, $err);
463
464
my $vpath2=ow::tool::untaint(absolute_vpath($currentdir, $destname));
465
$err=verify_vpath($webdiskrootdir, $vpath2);
466
return ("$err\n") if ($err ne '');
467
468
if ($#selitems>0) {
469
if (!-e "$webdiskrootdir/$vpath2") {
470
return("$vpath2 $lang_err{'doesnt_exist'}\n");
471
} elsif (!-d _) {
472
return("$vpath2 $lang_err{'isnt_a_dir'}\n");
473
}
474
}
475
476
my @filelist;
477
foreach (@selitems) {
478
my $vpath1=ow::tool::untaint(absolute_vpath($currentdir, $_));
479
$err=verify_vpath($webdiskrootdir, $vpath1);
480
if ($err ne '') {
481
$msg.="$err\n"; next;
482
}
483
if (! -e "$webdiskrootdir/$vpath1") {
484
$msg.="$vpath1 $lang_err{'doesnt_exist'}\n"; next;
485
}
486
next if ($vpath1 eq $vpath2);
487
488
my $p="$webdiskrootdir/$vpath1"; $p=~s!/+!/!g; # eliminate duplicated /
489
push(@filelist, $p);
490
}
491
return($msg) if ($#filelist<0);
492
493
my @cmd;
494
if ($op eq "copy") {
495
my $cpbin=ow::tool::findbin('cp');
496
return("$lang_text{'program'} cp $lang_err{'doesnt_exist'}\n") if ($cpbin eq '');
497
@cmd=($cpbin, '-pRfv');
498
} elsif ($op eq "move") {
499
my $mvbin=ow::tool::findbin('mv');
500
return("$lang_text{'program'} mv $lang_err{'doesnt_exist'}\n") if ($mvbin eq '');
501
@cmd=($mvbin, '-fv');
502
} elsif ($op eq "symlink") {
503
my $lnbin=ow::tool::findbin('ln');
504
return("$lang_text{'program'} ln $lang_err{'doesnt_exist'}\n") if ($lnbin eq '');
505
@cmd=($lnbin, '-sv');
506
} else {
507
return($msg);
508
}
509
510
chdir("$webdiskrootdir/$currentdir") or
511
return("$lang_err{'couldnt_chdirto'} $currentdir\n");
512
513
my $msg2=webdisk_execute($lang_wdbutton{$op}, @cmd, @filelist, "$webdiskrootdir/$vpath2");
514
if ($msg2=~/cp:/ || $msg2=~/mv:/ || $msg2=~/ln:/) { # -vcmds not supported on solaris
515
$cmd[1]=~s/v//;
516
$msg2=webdisk_execute($lang_wdbutton{$op}, @cmd, @filelist, "$webdiskrootdir/$vpath2");
517
}
518
$msg.=$msg2;
519
return($msg);
520
}
521
########## END COPYDIRFILES ######################################
522
523
########## EDITFILE ##############################################
524
sub editfile {
525
my ($currentdir, $selitem)=@_;
526
my $vpath=absolute_vpath($currentdir, $selitem);
527
my $content;
528
529
my ($html, $temphtml);
530
$html = applystyle(readtemplate("editfile.template"));
531
532
if ( -d "$webdiskrootdir/$vpath") {
533
autoclosewindow($lang_wdbutton{'edit'}, $lang_err{'edit_notfordir'});
534
} elsif ( -f "$webdiskrootdir/$vpath" ) {
535
my $err=verify_vpath($webdiskrootdir, $vpath);
536
autoclosewindow($lang_wdbutton{'edit'}, $err) if ($err ne '');
537
538
if (!open(F, "$webdiskrootdir/$vpath")) {
539
autoclosewindow($lang_wdbutton{'edit'}, "$lang_err{'couldnt_open'} $vpath");
540
}
541
ow::filelock::lock("$webdiskrootdir/$vpath", LOCK_SH|LOCK_NB) or
542
autoclosewindow($lang_text{'edit'}, "$lang_err{'couldnt_locksh'} $webdiskrootdir/$vpath!");
543
while (<F>) { $content .= $_; }
544
close(F);
545
ow::filelock::lock("$webdiskrootdir/$vpath", LOCK_UN);
546
547
$content =~ s|<\s*/\s*textarea\s*>|</ESCAPE_TEXTAREA>|gi;
548
549
writelog("webdisk editfile - $vpath");
550
writehistory("webdisk editfile - $vpath");
551
}
552
553
$temphtml .= start_form(-action=>"$config{'ow_cgiurl'}/openwebmail-webdisk.pl",
554
-name=>'editfile') .
555
ow::tool::hiddens(sessionid=>$thissession,
556
action=>'savefile',
557
currentdir=>$currentdir);
558
$html =~ s/\@\@\@STARTEDITFORM\@\@\@/$temphtml/;
559
560
$temphtml = textfield(-name=>'destname',
561
-default=>$vpath,
562
-size=>'66',
563
-override=>'1');
564
$html =~ s/\@\@\@FILENAME\@\@\@/$temphtml/;
565
566
if ($vpath=~/\.html?$/) {
567
$temphtml = submit(-name=>'previewbutton',
568
-value=>$lang_wdbutton{'preview'},
569
-OnClick=>qq|preview(); return false;|,
570
-override=>'1');
571
$html =~ s/\@\@\@PREVIEWBUTTON\@\@\@/$temphtml/;
572
} else {
573
$html =~ s/\@\@\@PREVIEWBUTTON\@\@\@//;
574
}
575
576
$temphtml = submit("$lang_text{'save'}");
577
$html =~ s/\@\@\@SAVEBUTTON\@\@\@/$temphtml/;
578
579
$temphtml = button(-name=>'cancelbutton',
580
-value=>$lang_text{'cancel'},
581
-onclick=>'window.close();',
582
-override=>'1');
583
$html =~ s/\@\@\@CANCELBUTTON\@\@\@/$temphtml/;
584
585
$temphtml= start_form(-action=>"$config{'ow_cgiurl'}/openwebmail-webdisk.pl",
586
-name=>'previewform',
587
-target=>'_preview').
588
ow::tool::hiddens(sessionid=>$thissession,
589
action=>'preview',
590
currentdir=>$currentdir,
591
selitems=>'',
592
filecontent=>'');
593
$html =~ s/\@\@\@STARTPREVIEWFORM\@\@\@/$temphtml/;
594
595
$temphtml = end_form();
596
$html =~ s/\@\@\@ENDFORM\@\@\@/$temphtml/g;
597
598
# put this at last to avoid @@@[email protected]@@ replacement happens on $content
599
$temphtml = textarea(-name=>'filecontent',
600
-default=>$content,
601
-rows=>$prefs{'webdisk_fileeditrows'},
602
-columns=>$prefs{'webdisk_fileeditcolumns'},
603
-wrap=>'soft',
604
-override=>'1');
605
$html =~ s/\@\@\@FILECONTENT\@\@\@/$temphtml/;
606
607
httpprint([], [htmlheader(), $html, htmlfooter(2)]);
608
}
609
########## END EDITFILE ##########################################
610
611
########## SAVEFILE ##############################################
612
sub savefile {
613
my ($currentdir, $destname, $content)=@_;
614
my $vpath=ow::tool::untaint(absolute_vpath($currentdir, $destname));
615
my $err=verify_vpath($webdiskrootdir, $vpath);
616
autoclosewindow($lang_text{'savefile'}, $err, 60) if ($err ne '');
617
618
$content =~ s|</ESCAPE_TEXTAREA>|</textarea>|gi;
619
$content =~ s/\r\n/\n/g;
620
$content =~ s/\r/\n/g;
621
622
if (!open(F, ">$webdiskrootdir/$vpath") ) {
623
autoclosewindow($lang_text{'savefile'}, "$lang_text{'savefile'} $lang_text{'failed'} ($vpath: $!)", 60);
624
}
625
ow::filelock::lock("$webdiskrootdir/$vpath", LOCK_EX) or
626
autoclosewindow($lang_text{'savefile'}, "$lang_err{'couldnt_lock'} $webdiskrootdir/$vpath!", 60);
627
print F "$content";
628
close(F);
629
ow::filelock::lock("$webdiskrootdir/$vpath", LOCK_UN);
630
631
writelog("webdisk savefile - $vpath");
632
writehistory("webdisk savefile - $vpath");
633
634
my $jscode=qq|window.opener.document.dirform.submit();|;
635
autoclosewindow($lang_text{'savefile'}, "$lang_text{'savefile'} $lang_text{'succeeded'} ($vpath)", 5, $jscode);
636
}
637
########## END SAVEFILE ##########################################
638
639
########## COMPRESSFILES #########################################
640
sub compressfiles { # pack files with zip or tgz (tar -zcvf)
641
my ($ztype, $currentdir, $destname, @selitems)=@_;
642
my ($vpath2, $msg, $err);
643
644
if ($ztype eq "mkzip" || $ztype eq "mktgz" ) {
645
$vpath2=ow::tool::untaint(absolute_vpath($currentdir, $destname));
646
$err=verify_vpath($webdiskrootdir, $vpath2);
647
return ("$err\n") if ($err ne '');
648
if ( -e "$webdiskrootdir/$vpath2") {
649
return("$lang_text{'dir'} $vpath2 $lang_err{'already_exists'}\n") if (-d _);
650
return("$lang_text{'file'} $vpath2 $lang_err{'already_exists'}\n");
651
}
652
}
653
654
my %selitem;
655
foreach (@selitems) {
656
my $vpath=absolute_vpath($currentdir, $_);
657
$err=verify_vpath($webdiskrootdir, $vpath);
658
if ($err ne '') {
659
$msg.="$err\n"; next;
660
}
661
662
# use relative path to currentdir since we will chdir to webdiskrootdir/currentdir before compress
663
my $p=fullpath2vpath("$webdiskrootdir/$vpath", "$webdiskrootdir/$currentdir");
664
# use absolute path if relative to webdiskrootdir/currentdir is not possible
665
$p="$webdiskrootdir/$vpath" if ($p eq "");
666
$p=ow::tool::untaint($p);
667
668
if ( -d "$webdiskrootdir/$vpath" ) {
669
$selitem{".$p/"}=1;
670
} elsif ( -e _ ) {
671
$selitem{".$p"}=1;
672
}
673
}
674
my @filelist=keys(%selitem);
675
return($msg) if ($#filelist<0);
676
677
my @cmd;
678
if ($ztype eq "gzip") {
679
my $gzipbin=ow::tool::findbin('gzip');
680
return("$lang_text{'program'} gzip $lang_err{'doesnt_exist'}\n") if ($gzipbin eq '');
681
@cmd=($gzipbin, '-rq');
682
} elsif ($ztype eq "mkzip") {
683
my $zipbin=ow::tool::findbin('zip');
684
return("$lang_text{'program'} zip $lang_err{'doesnt_exist'}\n") if ($zipbin eq '');
685
@cmd=($zipbin, '-ryq', "$webdiskrootdir/$vpath2");
686
} elsif ($ztype eq "mktgz") {
687
my $gzipbin=ow::tool::findbin('gzip');
688
my $tarbin=ow::tool::findbin('tar');
689
if ($gzipbin ne '') {
690
$ENV{'PATH'}=$gzipbin; $ENV{'PATH'}=~s|/gzip||; # for tar
691
@cmd=($tarbin, '-zcpf', "$webdiskrootdir/$vpath2");
692
} else {
693
@cmd=($tarbin, '-cpf', "$webdiskrootdir/$vpath2");
694
}
695
} else {
696
return("unknow ztype($ztype)?");
697
}
698
699
chdir("$webdiskrootdir/$currentdir") or
700
return("$lang_err{'couldnt_chdirto'} $currentdir\n");
701
702
my $opstr;
703
if ($ztype eq "mkzip") {
704
$opstr=$lang_wdbutton{'mkzip'};
705
} elsif ($ztype eq "mktgz") {
706
$opstr=$lang_wdbutton{'mktgz'};
707
} else {
708
$opstr=$lang_wdbutton{'gzip'};
709
}
710
return(webdisk_execute($opstr, @cmd, @filelist));
711
}
712
########## END COMPRESSFILES #####################################
713
714
########## DECOMPRESSFILE ########################################
715
sub decompressfile { # unpack tar.gz, tgz, tar.bz2, tbz, gz, zip, rar, arj, lzh, tnef/tnf
716
my ($currentdir, $selitem)=@_;
717
my $vpath=absolute_vpath($currentdir, $selitem);
718
719
if ( !-f "$webdiskrootdir/$vpath" || !-r _) {
720
return("$lang_err{'couldnt_open'} $vpath");
721
}
722
my $err=verify_vpath($webdiskrootdir, $vpath);
723
return($err) if ($err ne '');
724
725
my @cmd;
726
if ($vpath=~/\.(tar\.g?z||tgz)$/i && $config{'webdisk_allow_untar'}) {
727
my $gzipbin=ow::tool::findbin('gzip');
728
return("$lang_text{'program'} gzip $lang_err{'doesnt_exist'}\n") if ($gzipbin eq '');
729
my $tarbin=ow::tool::findbin('tar');
730
$ENV{'PATH'}=$gzipbin; $ENV{'PATH'}=~s|/gzip||; # for tar
731
@cmd=($tarbin, '-zxpf');
732
733
} elsif ($vpath=~/\.(tar\.bz2?||tbz)$/i && $config{'webdisk_allow_untar'}) {
734
my $bzip2bin=ow::tool::findbin('bzip2');
735
return("$lang_text{'program'} bzip2 $lang_err{'doesnt_exist'}\n") if ($bzip2bin eq '');
736
my $tarbin=ow::tool::findbin('tar');
737
$ENV{'PATH'}=$bzip2bin; $ENV{'PATH'}=~s|/bzip2||; # for tar
738
@cmd=($tarbin, '-yxpf');
739
740
} elsif ($vpath=~/\.g?z$/i) {
741
my $gzipbin=ow::tool::findbin('gzip');
742
return("$lang_text{'program'} gzip $lang_err{'doesnt_exist'}\n") if ($gzipbin eq '');
743
@cmd=($gzipbin, '-dq');
744
745
} elsif ($vpath=~/\.bz2?$/i) {
746
my $bzip2bin=ow::tool::findbin('bzip2');
747
return("$lang_text{'program'} bzip2 $lang_err{'doesnt_exist'}\n") if ($bzip2bin eq '');
748
@cmd=($bzip2bin, '-dq');
749
750
} elsif ($vpath=~/\.zip$/i && $config{'webdisk_allow_unzip'}) {
751
my $unzipbin=ow::tool::findbin('unzip');
752
return("$lang_text{'program'} unzip $lang_err{'doesnt_exist'}\n") if ($unzipbin eq '');
753
@cmd=($unzipbin, '-oq');
754
755
} elsif ($vpath=~/\.rar$/i && $config{'webdisk_allow_unrar'}) {
756
my $unrarbin=ow::tool::findbin('unrar');
757
return("$lang_text{'program'} unrar $lang_err{'doesnt_exist'}\n") if ($unrarbin eq '');
758
@cmd=($unrarbin, 'x', '-r', '-y', '-o+');
759
760
} elsif ($vpath=~/\.arj$/i && $config{'webdisk_allow_unarj'}) {
761
my $unarjbin=ow::tool::findbin('unarj');
762
return("$lang_text{'program'} unarj $lang_err{'doesnt_exist'}\n") if ($unarjbin eq '');
763
@cmd=($unarjbin, 'x');
764
765
} elsif ($vpath=~/\.lzh$/i && $config{'webdisk_allow_unlzh'}) {
766
my $lhabin=ow::tool::findbin('lha');
767
return("$lang_text{'program'} lha $lang_err{'doesnt_exist'}\n") if ($lhabin eq '');
768
@cmd=($lhabin, '-xfq');
769
770
} elsif ($vpath=~/\.tne?f$/i) {
771
my $tnefbin=ow::tool::findbin('tnef');
772
return("$lang_text{'program'} tnef $lang_err{'doesnt_exist'}\n") if ($tnefbin eq '');
773
@cmd=($tnefbin, '--overwrite', '-v', '-f');
774
775
} else {
776
return("$lang_err{'decomp_notsupported'} ($vpath)\n");
777
}
778
779
chdir("$webdiskrootdir/$currentdir") or
780
return("$lang_err{'couldnt_chdirto'} $currentdir\n");
781
782
my $opstr;
783
if ($vpath=~/\.(?:zip|rar|arj|lhz|t[bg]z|tar\.g?z|tar\.bz2?|tne?f)$/i) {
784
$opstr=$lang_wdbutton{'extract'};
785
} else {
786
$opstr=$lang_wdbutton{'decompress'};
787
}
788
return(webdisk_execute($opstr, @cmd, "$webdiskrootdir/$vpath"));
789
}
790
########## END DECOMPRESSFILE ####################################
791
792
########## LISTARCHIVE ###########################################
793
sub listarchive {
794
my ($currentdir, $selitem)=@_;
795
my $vpath=absolute_vpath($currentdir, $selitem);
796
797
my ($html, $temphtml);
798
$html = applystyle(readtemplate("listarchive.template"));
799
800
if (! -f "$webdiskrootdir/$vpath") {
801
autoclosewindow($lang_wdbutton{'listarchive'}, "$lang_text{'file'} $vpath $lang_err{'doesnt_exist'}");
802
return;
803
}
804
my $err=verify_vpath($webdiskrootdir, $vpath);
805
if ($err ne '') {
806
autoclosewindow($lang_wdbutton{'listarchive'}, $err);
807
return;
808
}
809
810
my @cmd;
811
if ($vpath=~/\.(tar\.g?z|tgz)$/i) {
812
my $gzipbin=ow::tool::findbin('gzip');
813
autoclosewindow($lang_wdbutton{'listarchive'}, "$lang_text{'program'} gzip $lang_err{'doesnt_exist'}\n") if ($gzipbin eq '');
814
my $tarbin=ow::tool::findbin('tar');
815
$ENV{'PATH'}=$gzipbin; $ENV{'PATH'}=~s|/gzip||; # for tar
816
@cmd=($tarbin, '-ztvf');
817
818
} elsif ($vpath=~/\.(tar\.bz2?|tbz)$/i) {
819
my $bzip2bin=ow::tool::findbin('bzip2');
820
autoclosewindow($lang_wdbutton{'listarchive'}, "$lang_text{'program'} bzip2 $lang_err{'doesnt_exist'}\n") if ($bzip2bin eq '');
821
my $tarbin=ow::tool::findbin('tar');
822
$ENV{'PATH'}=$bzip2bin; $ENV{'PATH'}=~s|/bzip2||; # for tar
823
@cmd=($tarbin, '-ytvf');
824
825
} elsif ($vpath=~/\.zip$/i) {
826
my $unzipbin=ow::tool::findbin('unzip');
827
autoclosewindow($lang_wdbutton{'listarchive'}, "$lang_text{'program'} unzip $lang_err{'doesnt_exist'}\n") if ($unzipbin eq '');
828
@cmd=($unzipbin, '-lq');
829
830
} elsif ($vpath=~/\.rar$/i) {
831
my $unrarbin=ow::tool::findbin('unrar');
832
autoclosewindow($lang_wdbutton{'listarchive'}, "$lang_text{'program'} unrar $lang_err{'doesnt_exist'}\n") if ($unrarbin eq '');
833
@cmd=($unrarbin, 'l');
834
835
} elsif ($vpath=~/\.arj$/i) {
836
my $unarjbin=ow::tool::findbin('unarj');
837
autoclosewindow($lang_wdbutton{'listarchive'}, "$lang_text{'program'} unarj $lang_err{'doesnt_exist'}\n") if ($unarjbin eq '');
838
@cmd=($unarjbin, 'l');
839
840
} elsif ($vpath=~/\.lzh$/i) {
841
my $lhabin=ow::tool::findbin('lha');
842
autoclosewindow($lang_wdbutton{'listarchive'}, "$lang_text{'program'} lha $lang_err{'doesnt_exist'}\n") if ($lhabin eq '');
843
@cmd=($lhabin, '-l');
844
845
} elsif ($vpath=~/\.tne?f$/i) {
846
my $tnefbin=ow::tool::findbin('tnef');
847
autoclosewindow($lang_wdbutton{'listarchive'}, "$lang_text{'program'} tnef $lang_err{'doesnt_exist'}\n") if ($tnefbin eq '');
848
@cmd=($tnefbin, '-t');
849
850
} else {
851
autoclosewindow($lang_wdbutton{'listarchive'}, "$lang_err{'decomp_notsupported'} ($vpath)\n");
852
}
853
854
my ($stdout, $stderr, $exit, $sig)=ow::execute::execute(@cmd, "$webdiskrootdir/$vpath");
855
# try to conv realpath in stdout/stderr back to vpath
856
$stdout=~s!(?:$webdiskrootdir//|\s$webdiskrootdir/)! /!g; $stdout=~s!/+!/!g;
857
$stderr=~s!(?:$webdiskrootdir//|\s$webdiskrootdir/)! /!g; $stderr=~s!/+!/!g;
858
859
if ($exit||$sig) {
860
my $err="$lang_text{'program'} $cmd[0] $lang_text{'failed'} (exit status $exit";
861
$err.=", terminated by signal $sig" if ($sig);
862
$err.=")\n$stdout$stderr";
863
autoclosewindow($lang_wdbutton{'listarchive'}, $err);
864
} else {
865
writelog("webdisk listarchive - $vpath");
866
writehistory("webdisk listarchive - $vpath");
867
}
868
869
$temphtml .= start_form('listarchive') .
870
$html =~ s/\@\@\@STARTEDITFORM\@\@\@/$temphtml/;
871
872
$temphtml = textfield(-name=>'selectitems',
873
-default=>$vpath,
874
-size=>'66',
875
-disabled=>'1',
876
-override=>'1');
877
$html =~ s/\@\@\@FILENAME\@\@\@/$temphtml/;
878
879
$temphtml = qq|<table width="95%" border=0 cellpadding=0 cellspacing=1 bgcolor=#999999><tr><td nowrap bgcolor=#ffffff>\n|.
880
qq|<table width=100%><tr><td><pre>$stdout</pre></td></tr></table>\n|.
881
qq|</td</tr></table>\n|;
882
$html =~ s/\@\@\@FILECONTENT\@\@\@/$temphtml/;
883
884
$temphtml = button(-name=>'closebutton',
885
-value=>$lang_text{'close'},
886
-onclick=>'window.close();',
887
-override=>'1');
888
$html =~ s/\@\@\@CLOSEBUTTON\@\@\@/$temphtml/;
889
890
$temphtml = end_form();
891
$html =~ s/\@\@\@ENDFORM\@\@\@/$temphtml/;
892
893
httpprint([], [htmlheader(), $html, htmlfooter(2)]);
894
}
895
########## END LISTARCHIVE #######################################
896
897
########## WORDPREVIEW ###########################################
898
sub wordpreview { # msword text preview
899
my ($currentdir, $selitem)=@_;
900
my $vpath=absolute_vpath($currentdir, $selitem);
901
902
my ($html, $temphtml);
903
$html = applystyle(readtemplate("wordpreview.template"));
904
905
if (! -f "$webdiskrootdir/$vpath") {
906
autoclosewindow("MS Word $lang_wdbutton{'preview'}", "$lang_text{'file'} $vpath $lang_err{'doesnt_exist'}");
907
return;
908
}
909
my $err=verify_vpath($webdiskrootdir, $vpath);
910
if ($err ne '') {
911
autoclosewindow("MS Word $lang_wdbutton{'preview'}", $err);
912
return;
913
}
914
915
my @cmd;
916
if ($vpath=~/\.(?:doc|dot)$/i) {
917
my $antiwordbin=ow::tool::findbin('antiword');
918
autoclosewindow("MS Word $lang_wdbutton{'preview'}", "$lang_text{'program'} antiword $lang_err{'doesnt_exist'}\n") if ($antiwordbin eq '');
919
@cmd=($antiwordbin, '-m', 'UTF-8.txt');
920
} else {
921
autoclosewindow("MS Word $lang_wdbutton{'preview'}", "$lang_err{'filefmt_notsupported'} ($vpath)\n");
922
}
923
924
chdir("$webdiskrootdir/$currentdir") or
925
return("$lang_err{'couldnt_chdirto'} $currentdir\n");
926
927
my ($stdout, $stderr, $exit, $sig)=ow::execute::execute(@cmd, "$webdiskrootdir/$vpath");
928
929
if ($exit||$sig) {
930
# try to conv realpath in stdout/stderr back to vpath
931
$stderr=~s!(?:$webdiskrootdir//|\s$webdiskrootdir/)! /!g; $stderr=~s!/+!/!g;
932
$stderr=~s!^\s+.*$!!mg; # remove the antiword syntax description
933
934
my $err="$lang_text{'program'} antiword $lang_text{'failed'} (exit status $exit";
935
$err.=", terminated by signal $sig" if ($sig);
936
$err.=")\n$stderr";
937
autoclosewindow("MS Word $lang_wdbutton{'preview'}", $err);
938
} else {
939
if (is_convertable('utf-8', $prefs{'charset'}) ) {
940
($stdout)=iconv('utf-8', $prefs{'charset'}, $stdout);
941
}
942
writelog("webdisk wordpreview - $vpath");
943
writehistory("webdisk wordpreview - $vpath");
944
}
945
946
$temphtml .= start_form('wordpreview') .
947
$html =~ s/\@\@\@STARTEDITFORM\@\@\@/$temphtml/;
948
949
$temphtml = textfield(-name=>'selectitems',
950
-default=>$vpath,
951
-size=>'66',
952
-disabled=>'1',
953
-override=>'1');
954
$html =~ s/\@\@\@FILENAME\@\@\@/$temphtml/;
955
956
$temphtml = qq|<table width="95%" border=0 cellpadding=0 cellspacing=1 bgcolor=#999999><tr><td nowrap bgcolor=#ffffff>\n|.
957
qq|<table width=100%><tr><td><pre>$stdout</pre></td></tr></table>\n|.
958
qq|</td</tr></table>\n|;
959
$html =~ s/\@\@\@FILECONTENT\@\@\@/$temphtml/;
960
961
$temphtml = button(-name=>'closebutton',
962
-value=>$lang_text{'close'},
963
-onclick=>'window.close();',
964
-override=>'1');
965
$html =~ s/\@\@\@CLOSEBUTTON\@\@\@/$temphtml/;
966
967
$temphtml = end_form();
968
$html =~ s/\@\@\@ENDFORM\@\@\@/$temphtml/;
969
970
httpprint([], [htmlheader(), $html, htmlfooter(2)]);
971
}
972
########## END WORDPREVIEW #######################################
973
974
########## MAKEPDFPS #############################################
975
sub makepdfps { # ps2pdf or pdf2ps
976
my ($mktype, $currentdir, $selitem)=@_;
977
my $vpath=absolute_vpath($currentdir, $selitem);
978
979
if ( !-f "$webdiskrootdir/$vpath" || !-r _) {
980
return("$lang_err{'couldnt_open'} $vpath");
981
}
982
my $err=verify_vpath($webdiskrootdir, $vpath);
983
return($err) if ($err ne '');
984
985
my $gsbin=ow::tool::findbin('gs');
986
return("$lang_text{'program'} gs $lang_err{'doesnt_exist'}\n") if ($gsbin eq '');
987
988
my @cmd;
989
my $outputfile="$webdiskrootdir/$vpath";
990
991
if ($mktype eq 'mkpdf' && $outputfile=~s/^(.*)\.ps$/$1\.pdf/i) {
992
@cmd=($gsbin, '-q', '-dNOPAUSE', '-dBATCH', '-dSAFER',
993
'-dCompatibilityLevel=1.3', '-dPDFSETTINGS=/printer',
994
'-sDEVICE=pdfwrite', "-sOutputFile=$outputfile",
995
'-c', '.setpdfwrite', '-f'); # -c must immediately before -f
996
997
} elsif ($mktype eq 'mkps' && $outputfile=~s/^(.*)\.pdf$/$1\.ps/i) {
998
@cmd=($gsbin, '-q', '-dNOPAUSE', '-dBATCH', '-dSAFER',
999
'-sDEVICE=pswrite', "-sOutputFile=$outputfile",
1000
'-c', 'save', 'pop', '-f'); # -c must immediately before -f
1001
1002
} else {
1003
return("$lang_err{'filefmt_notsupported'} ($vpath)\n");
1004
}
1005
1006
chdir("$webdiskrootdir/$currentdir") or
1007
return("$lang_err{'couldnt_chdirto'} $currentdir\n");
1008
1009
return(webdisk_execute($lang_wdbutton{$mktype}, @cmd, "$webdiskrootdir/$vpath"));
1010
}
1011
########## END MAKEPDFPS #########################################
1012
1013
########## MAKETHUMB #############################################
1014
sub makethumbnail {
1015
my ($currentdir, @selitems)=@_;
1016
my $msg;
1017
1018
my $convertbin=ow::tool::findbin('convert');
1019
return("$lang_text{'program'} convert $lang_err{'doesnt_exist'}\n") if ($convertbin eq '');
1020
my @cmd=($convertbin, '+profile', '*', '-interlace', 'NONE', '-geometry', '64x64');
1021
1022
foreach (@selitems) {
1023
my $vpath=absolute_vpath($currentdir, $_);
1024
my $err=verify_vpath($webdiskrootdir, $vpath);
1025
if ($err ne '') {
1026
$msg.="$err\n"; next;
1027
}
1028
next if ( $vpath!~/\.(jpe?g|gif|png|bmp|tif)$/i || !-f "$webdiskrootdir/$vpath");
1029
1030
my $thumbnail=ow::tool::untaint(path2thumbnail($vpath));
1031
my @p=split(/\//, $thumbnail); pop(@p);
1032
my $thumbnaildir=join('/', @p);
1033
if (!-d "$webdiskrootdir/$thumbnaildir") {
1034
if (!mkdir (ow::tool::untaint("$webdiskrootdir/$thumbnaildir"), 0755)) {
1035
$msg.="$!\n"; next;
1036
}
1037
}
1038
1039
my ($img_atime,$img_mtime)= (stat("$webdiskrootdir/$vpath"))[8,9];
1040
if (-f "$webdiskrootdir/$thumbnail") {
1041
my ($thumbnail_atime,$thumbnail_mtime)= (stat("$webdiskrootdir/$thumbnail"))[8,9];
1042
next if ($thumbnail_mtime==$img_mtime);
1043
}
1044
$msg.=webdisk_execute("$lang_wdbutton{'mkthumbnail'} $thumbnail", @cmd, "$webdiskrootdir/$vpath", "$webdiskrootdir/$thumbnail");
1045
if (-f "$webdiskrootdir/$thumbnail.0") {
1046
my @f;
1047
foreach (1..20) {
1048
push(@f, "$webdiskrootdir/$thumbnail.$_");
1049
}
1050
unlink @f;
1051
rename("$webdiskrootdir/$thumbnail.0", "$webdiskrootdir/$thumbnail");
1052
}
1053
if (-f "$webdiskrootdir/$thumbnail") {
1054
utime(ow::tool::untaint($img_atime), ow::tool::untaint($img_mtime), "$webdiskrootdir/$thumbnail");
1055
}
1056
}
1057
return($msg);
1058
}
1059
1060
sub path2thumbnail {
1061
my @p=split(/\//, $_[0]);
1062
my $tfile=pop(@p); $tfile=~s/\.[^\.]*$/\.jpg/i;
1063
push(@p, '.thumbnail');
1064
return(join('/',@p)."/$tfile");
1065
}
1066
########## END MAKETHUMB #########################################
1067
1068
########## DOWNLOADFILES #########################################
1069
sub downloadfiles { # through zip or tgz
1070
my ($currentdir, @selitems)=@_;
1071
my $msg;
1072
1073
my %selitem;
1074
foreach (@selitems) {
1075
my $vpath=absolute_vpath($currentdir, $_);
1076
my $err=verify_vpath($webdiskrootdir, $vpath);
1077
if ($err ne '') {
1078
$msg.="$err\n"; next;
1079
}
1080
# use relative path to currentdir since we will chdir to webdiskrootdir/currentdir before DL
1081
my $p=fullpath2vpath("$webdiskrootdir/$vpath", "$webdiskrootdir/$currentdir");
1082
# use absolute path if relative to webdiskrootdir/currentdir is not possible
1083
$p="$webdiskrootdir/$vpath" if ($p eq "");
1084
$p=ow::tool::untaint($p);
1085
1086
if ( -d "$webdiskrootdir/$vpath" ) {
1087
$selitem{".$p/"}=1;
1088
} elsif ( -e _ ) {
1089
$selitem{".$p"}=1;
1090
}
1091
}
1092
my @filelist=keys(%selitem);
1093
return($msg) if ($#filelist<0);
1094
1095
my $dlname;
1096
if ($#filelist==0) {
1097
$dlname=safedlname($filelist[0]);
1098
} else {
1099
my $localtime=ow::datetime::time_gm2local(time(), $prefs{'timeoffset'}, $prefs{'daylightsaving'});
1100
my @t=ow::datetime::seconds2array($localtime);
1101
$dlname=sprintf("%4d%02d%02d-%02d%02d", $t[5]+1900,$t[4]+1,$t[3], $t[2],$t[1]);
1102
}
1103
1104
my @cmd;
1105
my $zipbin=ow::tool::findbin('zip');
1106
if ($zipbin ne '') {
1107
@cmd=($zipbin, '-ryq', '-');
1108
$dlname.=".zip";
1109
} else {
1110
my $gzipbin=ow::tool::findbin('gzip');
1111
my $tarbin=ow::tool::findbin('tar');
1112
if ($gzipbin ne '') {
1113
$ENV{'PATH'}=$gzipbin; $ENV{'PATH'}=~s|/gzip||; # for tar
1114
@cmd=($tarbin, '-zcpf', '-');
1115
$dlname.=".tgz";
1116
} else {
1117
@cmd=($tarbin, '-cpf', '-');
1118
$dlname.=".tar";
1119
}
1120
}
1121
1122
chdir("$webdiskrootdir/$currentdir") or
1123
return("$lang_err{'couldnt_chdirto'} $currentdir\n");
1124
1125
my $contenttype=ow::tool::ext2contenttype($dlname);
1126
1127
local $|=1;
1128
print qq|Connection: close\n|,
1129
qq|Content-Type: $contenttype; name="$dlname"\n|;
1130
if ( $ENV{'HTTP_USER_AGENT'}=~/MSIE 5.5/ ) { # ie5.5 is broken with content-disposition: attachment
1131
print qq|Content-Disposition: filename="$dlname"\n|;
1132
} else {
1133
print qq|Content-Disposition: attachment; filename="$dlname"\n|;
1134
}
1135
print qq|\n|;
1136
1137
writelog("webdisk download - ".join(' ', @filelist));
1138
writehistory("webdisk download - ".join(' ', @filelist));
1139
1140
# set enviro's for cmd
1141
$ENV{'USER'}=$ENV{'LOGNAME'}=$user;
1142
$ENV{'HOME'}=$homedir;
1143
$<=$>; # drop ruid by setting ruid = euid
1144
exec(@cmd, @filelist) or print qq|Error in executing |.join(' ', @cmd, @filelist);
1145
}
1146
########## END DOWNLOADFILES #####################################
1147
1148
########## DOWNLOADFILE ##########################################
1149
sub downloadfile {
1150
my ($currentdir, $selitem)=@_;
1151
1152
my $vpath=absolute_vpath($currentdir, $selitem);
1153
my $err=verify_vpath($webdiskrootdir, $vpath);
1154
return($err) if ($err ne '');
1155
1156
open(F, "$webdiskrootdir/$vpath") or
1157
return("$lang_err{'couldnt_open'} $vpath\n");
1158
1159
my $dlname=safedlname($vpath);
1160
my $contenttype=ow::tool::ext2contenttype($vpath);
1161
my $length = ( -s "$webdiskrootdir/$vpath");
1162
1163
# disposition:inline default to open
1164
print qq|Connection: close\n|,
1165
qq|Content-Type: $contenttype; name="$dlname"\n|;
1166
if ($contenttype=~/^text/ || $dlname=~/\.(jpe?g|gif|png|bmp)$/i) {
1167
print qq|Content-Disposition: inline; filename="$dlname"\n|;
1168
} else {
1169
if ( $ENV{'HTTP_USER_AGENT'}=~/MSIE 5.5/ ) { # ie5.5 is broken with content-disposition: attachment
1170
print qq|Content-Disposition: filename="$dlname"\n|;
1171
} else {
1172
print qq|Content-Disposition: attachment; filename="$dlname"\n|;
1173
}
1174
}
1175
1176
if ($contenttype=~/^text/ && $length>512 &&
1177
is_http_compression_enabled()) {
1178
my $content;
1179
local $/; undef $/; $content=<F>; # no seperator, read whole file at once
1180
close (F);
1181
$content=Compress::Zlib::memGzip($content);
1182
$length=length($content);
1183
print qq|Content-Encoding: gzip\n|,
1184
qq|Vary: Accept-Encoding\n|,
1185
qq|Content-Length: $length\n\n|, $content;
1186
} else {
1187
print qq|Content-Length: $length\n\n|;
1188
my $buff;
1189
while (read(F, $buff, 32768)) {
1190
print $buff;
1191
}
1192
close(F);
1193
}
1194
1195
# we only log download other than thumbnail imgs
1196
my @p=split(/\//, $vpath);
1197
if (!defined($p[$#p-1]) || $p[$#p-1] ne '.thumbnail') {
1198
writelog("webdisk download - $vpath");
1199
writehistory("webdisk download - $vpath ");
1200
}
1201
return;
1202
}
1203
########## END DOWNLOADFILE ######################################
1204
1205
########## PREVIEWFILE ###########################################
1206
# relative links in html content will be converted so they can be
1207
# redirect back to openwebmail-webdisk.pl with correct parmteters
1208
sub previewfile {
1209
my ($currentdir, $selitem, $filecontent)=@_;
1210
my $vpath=absolute_vpath($currentdir, $selitem);
1211
my $err=verify_vpath($webdiskrootdir, $vpath);
1212
return($err) if ($err ne '');
1213
1214
if ($filecontent eq "") {
1215
open(F, "$webdiskrootdir/$vpath") or return("$lang_err{'couldnt_open'} $vpath\n");
1216
local $/; undef $/; $filecontent=<F>; # no seperator, read whole file at once
1217
close(F);
1218
}
1219
1220
# remove path from filename
1221
my $dlname=safedlname($vpath);
1222
my $contenttype=ow::tool::ext2contenttype($vpath);
1223
if ($vpath=~/\.(?:html?|js)$/i) {
1224
# use the dir where this html is as new currentdir
1225
my @p=path2array($vpath); pop @p;
1226
my $newdir='/'.join('/', @p);
1227
my $escapednewdir=ow::tool::escapeURL($newdir);
1228
my $preview_url=qq|$config{'ow_cgiurl'}/openwebmail-webdisk.pl?sessionid=$thissession|.
1229
qq|&amp;folder=$escapedfolder&amp;message_id=$escapedmessageid|.
1230
qq|&amp;currentdir=$escapednewdir&amp;action=preview&amp;selitems=|;
1231
$filecontent=~s/\r\n/\n/g;
1232
$filecontent=linkconv($filecontent, $preview_url);
1233
}
1234
1235
print qq|Connection: close\n|,
1236
qq|Content-Type: $contenttype; name="$dlname"\n|,
1237
qq|Content-Disposition: inline; filename="$dlname"\n|;
1238
1239
my $length = length($filecontent); # calc length since linkconv may change data length
1240
if ($contenttype=~/^text/ && $length>512 &&
1241
is_http_compression_enabled()) {
1242
$filecontent=Compress::Zlib::memGzip($filecontent);
1243
$length=length($filecontent);
1244
print qq|Content-Encoding: gzip\n|,
1245
qq|Vary: Accept-Encoding\n|,
1246
qq|Content-Length: $length\n\n|;
1247
} else {
1248
print qq|Content-Length: $length\n\n|;
1249
}
1250
print $filecontent;
1251
return;
1252
}
1253
1254
sub linkconv {
1255
my ($html, $preview_url)=@_;
1256
$html=~s/( url| href| src| stylesrc| background)(="?)([^\<\>\s]+?)("?[>\s+])/_linkconv($1.$2, $3, $4, $preview_url)/igems;
1257
$html=~s/(window.open\()([^\<\>\s]+?)(\))/_linkconv2($1, $2, $3, $preview_url)/igems;
1258
return($html);
1259
}
1260
1261
sub _linkconv {
1262
my ($prefix, $link, $postfix, $preview_url)=@_;
1263
if ($link=~m!^(?:mailto:|javascript:|#)!i) {
1264
return($prefix.$link.$postfix);
1265
}
1266
if ($link !~ m!^http://!i && $link!~m!^/!) {
1267
$link=$preview_url.$link;
1268
}
1269
return($prefix.$link.$postfix);
1270
}
1271
sub _linkconv2 {
1272
my ($prefix, $link, $postfix, $preview_url)=@_;
1273
if ($link=~m!^'?(?:http://|/)!i) {
1274
return($prefix.$link.$postfix);
1275
}
1276
$link=qq|'$preview_url'.$link|;
1277
return($prefix.$link.$postfix);
1278
}
1279
########## END PREVIEWFILE #######################################
1280
1281
########## UPLOADFILE ############################################
1282
sub uploadfile {
1283
no strict 'refs'; # for $upload, which is fname and fhandle of the upload
1284
my ($currentdir, $upload)=@_;
1285
my $size=(-s $upload);
1286
1287
if (!is_quota_available($size/1024)) {
1288
return("$lang_err{'quotahit_alert'}\n");
1289
}
1290
if ($config{'webdisk_uploadlimit'} &&
1291
$size/1024>$config{'webdisk_uploadlimit'} ) {
1292
return ("$lang_err{'upload_overlimit'} $config{'webdisk_uploadlimit'} $lang_sizes{'kb'}\n");
1293
}
1294
if ($size ==0) {
1295
return("$lang_wdbutton{'upload'} $lang_text{'failed'} (filesize is zero)\n");
1296
}
1297
1298
my $fname = $upload;
1299
# Convert :: back to the ' like it should be.
1300
$fname =~ s/::/'/g;
1301
# Trim the path info from the filename
1302
1303
if ($prefs{'charset'} eq 'big5' || $prefs{'charset'} eq 'gb2312') {
1304
$fname=ow::tool::zh_dospath2fname($fname); # dos path
1305
} else {
1306
$fname =~ s|^.*\\||; # dos path
1307
}
1308
$fname =~ s|^.*/||; # unix path
1309
$fname =~ s|^.*:||; # mac path and dos drive
1310
1311
my $vpath=ow::tool::untaint(absolute_vpath($currentdir, $fname));
1312
my $err=verify_vpath($webdiskrootdir, $vpath);
1313
return($err) if ($err ne '');
1314
1315
renameoldfile("$webdiskrootdir/$vpath") if ( -f "$webdiskrootdir/$vpath");
1316
1317
if (open(UPLOAD, ">$webdiskrootdir/$vpath")) {
1318
my $buff;
1319
while (read($upload, $buff, 32768)) {
1320
print UPLOAD $buff;
1321
}
1322
close(UPLOAD);
1323
writelog("webdisk upload - $vpath");
1324
writehistory("webdisk upload - $vpath");
1325
return("$lang_wdbutton{'upload'} $vpath $lang_text{'succeeded'}\n");
1326
1327
} else {
1328
return("$lang_wdbutton{'upload'} $vpath $lang_text{'failed'} ($!)\n");
1329
}
1330
}
1331
1332
# rename fname.ext to fname.0.ext
1333
# fname.0.ext to fname.1.ext
1334
# .....
1335
# fname.8.ext to fname.9.ext
1336
# so fname.ext won't be overwritten by uploaded file if duplicated name
1337
sub renameoldfile {
1338
my ($base, $ext)=($_[0], ''); ($base,$ext)=($1,$2) if ($_[0]=~/(.*)(\..*)/);
1339
my (%from, %to); $to{0}=1;
1340
for my $i (0..9) {
1341
$from{$i}=1 if (-f "$base.$i$ext");
1342
$to{$i+1}=1 if ($to{$i} && $from{$i});
1343
}
1344
for (my $i=9; $i>=0; $i--) {
1345
if ($from{$i} && $to{$i+1}) {
1346
rename(ow::tool::untaint("$base.$i$ext"), ow::tool::untaint("$base.".($i+1).$ext));
1347
}
1348
}
1349
rename(ow::tool::untaint("$base$ext"), ow::tool::untaint("$base.0$ext"));
1350
}
1351
1352
########## END UPLOADFILE ########################################
1353
1354
########## FILESELECT ############################################
1355
sub dirfilesel {
1356
my ($action, $olddir, $newdir, $filesort, $page)=@_;
1357
my $showhidden=param('showhidden')||0;
1358
my $singlepage=param('singlepage')||0;
1359
1360
# for sel_saveattfile, used in composemessage to save attfile
1361
my $attfile=param('attfile')||'';
1362
my $attachment_nodeid=param('attachment_nodeid');
1363
my $convfrom=param('convfrom')||'';
1364
my $attname=param('attname')||'';
1365
1366
if ( $action eq "sel_saveattfile" && $attfile eq "") {
1367
autoclosewindow($lang_text{'savefile'}, $lang_err{'param_fmterr'});
1368
} elsif ( $action eq "sel_saveattachment" && $attachment_nodeid eq "") {
1369
autoclosewindow($lang_text{'savefile'}, $lang_err{'param_fmterr'});
1370
}
1371
1372
my ($currentdir, $escapedcurrentdir, $msg);
1373
foreach my $dir ($newdir, $olddir, "/") {
1374
my $err=verify_vpath($webdiskrootdir, $dir);
1375
if ($err ne '') {
1376
$msg .= "$err<br>\n"; next;
1377
}
1378
if (!opendir(D, "$webdiskrootdir/$dir")) {
1379
$msg .= "$lang_err{'couldnt_open'} $dir ($!)<br>\n"; next;
1380
}
1381
$currentdir=$dir; last;
1382
}
1383
openwebmailerror(__FILE__, __LINE__, $msg) if ($currentdir eq '');
1384
$escapedcurrentdir=ow::tool::escapeURL($currentdir);
1385
1386
my (%fsize, %fdate, %ftype, %flink);
1387
while( my $fname=readdir(D) ) {
1388
next if ( $fname eq "." || $fname eq ".." );
1389
next if ( (!$config{'webdisk_lshidden'} || !$showhidden) && $fname =~ /^\./ );
1390
if ( !$config{'webdisk_lsmailfolder'} ) {
1391
next if ( is_under_dotdir_or_folderdir("$webdiskrootdir/$currentdir/$fname") );
1392
}
1393
if ( -l "$webdiskrootdir/$currentdir/$fname" ) { # symbolic link, aka:shortcut
1394
next if (!$config{'webdisk_lssymlink'});
1395
my $realpath=readlink("$webdiskrootdir/$currentdir/$fname");
1396
$realpath="$webdiskrootdir/$currentdir/$realpath" if ($realpath!~m!^/!);
1397
my $vpath=fullpath2vpath($realpath, $webdiskrootdir);
1398
if ($vpath ne '') {
1399
$flink{$fname}=" -> $vpath";
1400
} else {
1401
next if (!$config{'webdisk_allow_symlinkout'});
1402
if ($config{'webdisk_symlinkout_display'} eq 'path') {
1403
$flink{$fname}=" -> sys::$realpath";
1404
} elsif ($config{'webdisk_symlinkout_display'} eq '@') {
1405
$flink{$fname}='@';
1406
} else {
1407
$flink{$fname}='';
1408
}
1409
}
1410
}
1411
1412
my ($st_dev,$st_ino,$st_mode,$st_nlink,$st_uid,$st_gid,$st_rdev,$st_size,
1413
$st_atime,$st_mtime,$st_ctime,$st_blksize,$st_blocks)= stat("$webdiskrootdir/$currentdir/$fname");
1414
if ( ($st_mode&0170000)==0040000 ) {
1415
$ftype{$fname}="d";
1416
} elsif ( ($st_mode&0170000)==0100000 ) {
1417
$ftype{$fname}="f";
1418
} else { # unix specific filetype: fifo, socket, block dev, char dev..
1419
next; # skip because dirfilesel is used for upload/download
1420
}
1421
$fsize{$fname}=$st_size;
1422
$fdate{$fname}=$st_mtime;
1423
}
1424
closedir(D);
1425
1426
my @sortedlist;
1427
if ($filesort eq "name_rev") {
1428
@sortedlist= sort { $ftype{$a} cmp $ftype{$b} || $b cmp $a } keys(%ftype)
1429
} elsif ($filesort eq "size") {
1430
@sortedlist= sort { $ftype{$a} cmp $ftype{$b} || $fsize{$a}<=>$fsize{$b} } keys(%ftype)
1431
} elsif ($filesort eq "size_rev") {
1432
@sortedlist= sort { $ftype{$a} cmp $ftype{$b} || $fsize{$b}<=>$fsize{$a} } keys(%ftype)
1433
} elsif ($filesort eq "time") {
1434
@sortedlist= sort { $ftype{$a} cmp $ftype{$b} || $fdate{$a}<=>$fdate{$b} } keys(%ftype)
1435
} elsif ($filesort eq "time_rev") {
1436
@sortedlist= sort { $ftype{$a} cmp $ftype{$b} || $fdate{$b}<=>$fdate{$a} } keys(%ftype)
1437
} else { # filesort = name
1438
@sortedlist= sort { $ftype{$a} cmp $ftype{$b} || $ftype{$a} cmp $ftype{$b} || $a cmp $b } keys(%ftype)
1439
}
1440
1441
my $totalpage= int(($#sortedlist+1)/10+0.999999); # use 10 instead of $prefs{'webdisk_dirnumitems'} for shorter page
1442
$totalpage=1 if ($totalpage==0);
1443
if ($currentdir ne $olddir) {
1444
$page=1; # reset page number if change to new dir
1445
} else {
1446
$page=1 if ($page<1);
1447
$page=$totalpage if ($page>$totalpage);
1448
}
1449
1450
my ($html, $temphtml);
1451
$html = applystyle(readtemplate("dirfilesel.template"));
1452
1453
my $wd_url=qq|$config{ow_cgiurl}/openwebmail-webdisk.pl?sessionid=$thissession&amp;folder=$escapedfolder&amp;message_id=$escapedmessageid&amp;currentdir=$escapedcurrentdir|;
1454
if ($action eq "sel_saveattfile") {
1455
$html =~ s/\@\@\@SELTITLE\@\@\@/$lang_text{'savefile_towd'}/g;
1456
$wd_url.=qq|&amp;attfile=$attfile&attname=|.ow::tool::escapeURL($attname);
1457
} elsif ($action eq "sel_saveattachment") {
1458
$html =~ s/\@\@\@SELTITLE\@\@\@/$lang_text{'saveatt_towd'}/g;
1459
$wd_url.=qq|&amp;attachment_nodeid=$attachment_nodeid&amp;convfrom=$convfrom&amp;attname=|.ow::tool::escapeURL($attname);
1460
} elsif ($action eq "sel_addattachment") {
1461
$html =~ s/\@\@\@SELTITLE\@\@\@/$lang_text{'addatt_fromwd'}/g;
1462
} else {
1463
autoclosewindow("Unknow action: $action!");
1464
}
1465
my $wd_url_sort_page=qq|$wd_url&amp;showhidden=$showhidden&amp;singlepage=$singlepage&amp;filesort=$filesort&amp;page=$page|;
1466
1467
if ($action eq "sel_addattachment") {
1468
$temphtml=start_form(-name=>'selform',
1469
-action=>"javascript:addattachment_and_close();");
1470
} elsif ($action eq "sel_saveattfile") {
1471
$temphtml=start_form(-name=>'selform',
1472
-action=>"javascript:saveattfile_and_close('$attfile');");
1473
} elsif ($action eq "sel_saveattachment") {
1474
$temphtml=start_form(-name=>'selform',
1475
-action=>"javascript:saveattachment_and_close('$escapedfolder', '$escapedmessageid', '$attachment_nodeid');");
1476
}
1477
$html =~ s/\@\@\@STARTDIRFORM\@\@\@/$temphtml/g;
1478
1479
my $p='/';
1480
$temphtml=qq|<a href="$wd_url_sort_page&amp;action=$action&amp;gotodir=|.ow::tool::escapeURL($p).qq|">/</a>\n|;
1481
foreach ( split(/\//, $currentdir) ) {
1482
next if ($_ eq "");
1483
$p.="$_/";
1484
$temphtml.=qq|<a href="$wd_url_sort_page&amp;action=$action&amp;gotodir=|.ow::tool::escapeURL($p).qq|">|.
1485
ow::htmltext::str2html("$_/").qq|</a>\n|;
1486
}
1487
$html =~ s/\@\@\@CURRENTDIR\@\@\@/$temphtml/g;
1488
1489
my $newval=!$showhidden;
1490
if ($config{'webdisk_lshidden'}) {
1491
$html =~ s/\@\@\@SHOWHIDDENLABEL\@\@\@/$lang_text{'showhidden'}/g;
1492
$temphtml=checkbox(-name=>'showhidden',
1493
-value=>'1',
1494
-checked=>$showhidden,
1495
-OnClick=>qq|window.location.href='$wd_url&amp;action=$action&amp;filesort=$filesort&amp;page=$page&amp;singlepage=$singlepage&amp;showhidden=$newval'; return false;|,
1496
-override=>'1',
1497
-label=>'');
1498
$html =~ s/\@\@\@SHOWHIDDENCHECKBOX\@\@\@/$temphtml/g;
1499
} else {
1500
$html =~ s/\@\@\@SHOWHIDDENLABEL\@\@\@//g;
1501
$html =~ s/\@\@\@SHOWHIDDENCHECKBOX\@\@\@//g;
1502
}
1503
$newval=!$singlepage;
1504
$temphtml=checkbox(-name=>'singlepage',
1505
-value=>'1',
1506
-checked=>$singlepage,
1507
-OnClick=>qq|window.location.href='$wd_url&amp;action=$action&amp;filesort=$filesort&amp;page=$page&amp;showhidden=$showhidden&amp;singlepage=$newval'; return false;|,
1508
-override=>'1',
1509
-label=>'');
1510
$html =~ s/\@\@\@SINGLEPAGECHECKBOX\@\@\@/$temphtml/g;
1511
1512
if ($currentdir eq "/") {
1513
$temphtml=qq|<IMG SRC="$config{'ow_htmlurl'}/images/file/disk.gif" align="absmiddle" border="0">|;
1514
} else {
1515
my $parentdir = absolute_vpath($currentdir, "..");
1516
$temphtml=qq|<a href="$wd_url_sort_page&amp;action=$action&amp;gotodir=|.ow::tool::escapeURL($parentdir).qq|">|.
1517
qq|<IMG SRC="$config{'ow_htmlurl'}/images/file/dirup.gif" align="absmiddle" border="0">|.
1518
qq|</a>|;
1519
}
1520
$html =~ s/\@\@\@DIRUPLINK\@\@\@/$temphtml/g;
1521
1522
my $wd_url_sort=qq|$wd_url&amp;action=$action&amp;gotodir=$escapedcurrentdir&amp;showhidden=$showhidden&amp;singlepage=$singlepage&amp;page=$page&amp;filesort|;
1523
1524
if ($filesort eq "name") {
1525
$temphtml = qq|<a href="$wd_url_sort=name_rev">$lang_text{'filename'}</a> |.iconlink("up.gif", "^", "");
1526
} elsif ($filesort eq "name_rev") {
1527
$temphtml = qq|<a href="$wd_url_sort=name">$lang_text{'filename'}</a> |.iconlink("down.gif", "v", "");
1528
} else {
1529
$temphtml = qq|<a href="$wd_url_sort=name">$lang_text{'filename'}</a>|;
1530
}
1531
$html =~ s/\@\@\@FILENAME\@\@\@/$temphtml/g;
1532
1533
if ($filesort eq "size") {
1534
$temphtml = qq|<a href="$wd_url_sort=size_rev">$lang_text{'size'}</a> |.iconlink("up.gif", "^", "");
1535
} elsif ($filesort eq "size_rev") {
1536
$temphtml = qq|<a href="$wd_url_sort=size">$lang_text{'size'}</a> |.iconlink("down.gif", "v", "");
1537
} else {
1538
$temphtml = qq|<a href="$wd_url_sort=size_rev">$lang_text{'size'}</a>|;
1539
}
1540
$html =~ s/\@\@\@FILESIZE\@\@\@/$temphtml/g;
1541
1542
if ($filesort eq "time") {
1543
$temphtml = qq|<a href="$wd_url_sort=time_rev">$lang_text{'lastmodified'}</a> |.iconlink("up.gif", "^", "");
1544
} elsif ($filesort eq "time_rev") {
1545
$temphtml = qq|<a href="$wd_url_sort=time">$lang_text{'lastmodified'}</a> |.iconlink("down.gif", "v", "");
1546
} else {
1547
$temphtml = qq|<a href="$wd_url_sort=time_rev">$lang_text{'lastmodified'}</a>|;
1548
}
1549
$html =~ s/\@\@\@FILEDATE\@\@\@/$temphtml/g;
1550
1551
my $filelisthtml='';
1552
if ($#sortedlist>=0) {
1553
my $os=$^O||'generic';
1554
my ($i_first, $i_last)=(0, $#sortedlist);
1555
if (!$singlepage) {
1556
$i_first=($page-1)*10; # use 10 instead of $prefs{'webdisk_dirnumitems'} for shorter page
1557
$i_last=$i_first+10-1;
1558
$i_last=$#sortedlist if ($i_last>$#sortedlist);
1559
}
1560
foreach my $i ($i_first..$i_last) {
1561
my $fname=$sortedlist[$i];
1562
my $vpath=absolute_vpath($currentdir, $fname);
1563
my $accesskeystr=$i%10+1;
1564
if ($accesskeystr == 10) {
1565
$accesskeystr=qq|accesskey="0"|;
1566
} elsif ($accesskeystr < 10) {
1567
$accesskeystr=qq|accesskey="$accesskeystr"|;
1568
}
1569
1570
my ($imgstr, $namestr, $opstr, $onclickstr);
1571
$namestr=ow::htmltext::str2html($fname);
1572
$namestr.=ow::htmltext::str2html($flink{$fname}) if (defined($flink{$fname}));
1573
if ($ftype{$fname} eq "d") {
1574
if ($prefs{'iconset'}!~/^Text\./) {
1575
$imgstr=qq|<IMG SRC="$config{'ow_htmlurl'}/images/file/|.
1576
findicon($fname, $ftype{$fname}, 0, $os).
1577
qq|" align="absmiddle" border="0">|;
1578
}
1579
$namestr=qq|<a href="$wd_url_sort_page&amp;action=$action&amp;gotodir=|.
1580
ow::tool::escapeURL("$fname").qq|" $accesskeystr>$imgstr <b>$namestr</b></a>|;
1581
$opstr=qq|<a href="$wd_url_sort_page&amp;action=$action&amp;gotodir=|.
1582
ow::tool::escapeURL("$fname").qq|"><b>&lt;$lang_text{'dir'}&gt;</b></a>|;
1583
$onclickstr=qq|onClick="window.location.href='$wd_url_sort_page&amp;action=$action&amp;gotodir=|.
1584
ow::tool::escapeURL("$fname").
1585
qq|';"|;
1586
1587
} else {
1588
my $is_txt= (-T "$webdiskrootdir/$currentdir/$fname");
1589
if ($prefs{'iconset'}!~/^Text\./) {
1590
$imgstr=qq|<IMG SRC="$config{'ow_htmlurl'}/images/file/|.
1591
findicon($fname, $ftype{$fname}, $is_txt, $os).
1592
qq|" align="absmiddle" border="0">|;
1593
}
1594
$namestr=qq|<a href=#here onClick="filldestname('$vpath');" $accesskeystr>$imgstr $namestr</a>|;
1595
$onclickstr=qq|onClick="filldestname('$vpath')"|;
1596
}
1597
1598
my $right='right'; $right='left' if ($ow::lang::RTL{$prefs{'language'}});
1599
$namestr=qq|<table width="100%" border=0 cellspacing=0 cellpadding=0><tr>|.
1600
qq|<td>$namestr</td>\n<td align="$right" nowrap>$opstr</td></tr></table>|;
1601
1602
my $sizestr=qq|<a title="|.lenstr($fsize{$fname},1).qq|">$fsize{$fname}</a>|;
1603
1604
my $datestr;
1605
if (defined($fdate{$fname})) {
1606
$datestr=ow::datetime::dateserial2str(ow::datetime::gmtime2dateserial($fdate{$fname}),
1607
$prefs{'timeoffset'}, $prefs{'daylightsaving'},
1608
$prefs{'dateformat'}, $prefs{'hourformat'});
1609
}
1610
1611
my ($tr_bgcolorstr, $td_bgcolorstr);
1612
if ($prefs{'uselightbar'}) {
1613
$tr_bgcolorstr=qq|bgcolor=$style{tablerow_light} |.
1614
qq|onMouseOver='this.style.backgroundColor=$style{tablerow_hicolor};' |.
1615
qq|onMouseOut='this.style.backgroundColor=$style{tablerow_light};' |.
1616
qq|$onclickstr |;
1617
$td_bgcolorstr='';
1618
} else {
1619
$tr_bgcolorstr='';
1620
$td_bgcolorstr=qq|bgcolor=|.($style{"tablerow_dark"},$style{"tablerow_light"})[$i%2];
1621
}
1622
$filelisthtml.=qq|<tr $tr_bgcolorstr>\n|.
1623
qq|<td $td_bgcolorstr>$namestr</td>\n|.
1624
qq|<td $td_bgcolorstr align="right">$sizestr</td>\n|.
1625
qq|<td $td_bgcolorstr align="center">$datestr</td>\n|.
1626
qq|</tr>\n\n|;
1627
}
1628
} else {
1629
my $td_bgcolorstr = qq|bgcolor=|.$style{"tablerow_light"};
1630
$filelisthtml.=qq|<tr>\n|.
1631
qq|<td $td_bgcolorstr align=center>|.
1632
qq|<table><tr><td><font color=#aaaaaa>$lang_text{'noitemfound'}</font></td</tr></table>|.
1633
qq|</td>\n|.
1634
qq|<td $td_bgcolorstr>&nbsp;</td>\n|.
1635
qq|<td $td_bgcolorstr>&nbsp;</td>\n|.
1636
qq|</tr>\n\n|;
1637
}
1638
undef(%fsize); undef(%fdate); undef(%ftype); undef(%flink); # relase mem if possible
1639
1640
if (!$singlepage) {
1641
my $wd_url_page=qq|$wd_url&amp;action=$action&amp;gotodir=$escapedcurrentdir&amp;showhidden=$showhidden&amp;singlepage=$singlepage&amp;filesort=$filesort&amp;page|;
1642
1643
if ($page>1) {
1644
my $gif="left.gif"; $gif="right.gif" if ($ow::lang::RTL{$prefs{'language'}});
1645
$temphtml = iconlink($gif, "&lt;", qq|accesskey="U" href="$wd_url_page=|.($page-1).qq|"|).qq|\n|;
1646
} else {
1647
my $gif="left-grey.gif"; $gif="right-grey.gif" if ($ow::lang::RTL{$prefs{'language'}});
1648
$temphtml = iconlink($gif, "-", "").qq|\n|;
1649
}
1650
$html =~ s/\@\@\@LEFTPAGECONTROL\@\@\@/$temphtml/g;
1651
1652
if ($page<$totalpage) {
1653
my $gif="right.gif"; $gif="left.gif" if ($ow::lang::RTL{$prefs{'language'}});
1654
$temphtml = iconlink($gif, "&gt;", qq|accesskey="D" href="$wd_url_page=|.($page+1).qq|"|).qq|\n|;
1655
} else {
1656
my $gif="right-grey.gif"; $gif="left-grey.gif" if ($ow::lang::RTL{$prefs{'language'}});
1657
$temphtml = iconlink($gif, "-", "").qq|\n|;
1658
}
1659
$html =~ s/\@\@\@RIGHTPAGECONTROL\@\@\@/$temphtml/g;
1660
1661
my $p_first=$page-4; $p_first=1 if ($p_first<1);
1662
my $p_last=$p_first+9;
1663
if ($p_last>$totalpage) {
1664
$p_last=$totalpage;
1665
while ($p_last-$p_first<9 && $p_first>1) {
1666
$p_first--;
1667
}
1668
}
1669
1670
$temphtml='';
1671
for my $p ($p_first..$p_last) {
1672
if ($p == $page) {
1673
$temphtml .= qq|<b>$p</b>&nbsp;\n|;
1674
} else {
1675
$temphtml .= qq|<a href="$wd_url_page=$p">$p</a>&nbsp;\n|;
1676
}
1677
}
1678
$html =~ s/\@\@\@PAGELINKS\@\@\@/$temphtml/g;
1679
} else {
1680
$html =~ s/\@\@\@LEFTPAGECONTROL\@\@\@//g;
1681
$html =~ s/\@\@\@RIGHTPAGECONTROL\@\@\@//g;
1682
$html =~ s/\@\@\@PAGELINKS\@\@\@//g;
1683
}
1684
1685
if ($action eq "sel_saveattfile" || $action eq "sel_saveattachment") {
1686
$temphtml = textfield(-name=>'destname',
1687
-default=>"",
1688
-size=>'35',
1689
-accesskey=>'N',
1690
-value=>absolute_vpath($currentdir, $attname),
1691
-override=>'1');
1692
} else {
1693
$temphtml = textfield(-name=>'destname',
1694
-default=>"",
1695
-size=>'35',
1696
-accesskey=>'N',
1697
-value=>'',
1698
-disabled=>'1',
1699
-override=>'1');
1700
}
1701
$html =~ s/\@\@\@DESTNAMEFIELD\@\@\@/$temphtml/g;
1702
1703
$temphtml='';
1704
# we return false for the okbutton click event because we do all things in javascript
1705
# and we dn't want the current page to be reloaded
1706
if ($action eq "sel_addattachment") {
1707
$temphtml.=submit(-name=>'okbutton',
1708
-onClick=>"addattachment_and_close(); return false;",
1709
-value=>$lang_text{'ok'});
1710
} elsif ($action eq "sel_saveattfile") {
1711
$temphtml.=submit(-name=>'okbutton',
1712
-onClick=>"saveattfile_and_close('$attfile'); return false;",
1713
-value=>$lang_text{'ok'});
1714
} elsif ($action eq "sel_saveattachment") {
1715
$temphtml.=submit(-name=>'okbutton',
1716
-onClick=>"saveattachment_and_close('$folder', '$messageid', '$attachment_nodeid'); return false;",
1717
-value=>$lang_text{'ok'});
1718
}
1719
$temphtml.=submit(-name=>'cencelbutton',
1720
-onClick=>'window.close();',
1721
-value=>$lang_text{'cancel'});
1722
$html =~ s/\@\@\@BUTTONS\@\@\@/$temphtml/g;
1723
1724
$temphtml=end_form();
1725
$html =~ s/\@\@\@ENDFORM\@\@\@/$temphtml/g;
1726
1727
$temphtml = start_form(-action=>"$config{'ow_cgiurl'}/openwebmail-viewatt.pl",
1728
-name=>'saveattfileform').
1729
ow::tool::hiddens(action=>'saveattfile',
1730
sessionid=>$thissession,
1731
attfile=>'',
1732
webdisksel=>'').
1733
end_form();
1734
$html =~ s/\@\@\@SAVEATTFILEFORM\@\@\@/$temphtml/;
1735
1736
$temphtml = start_form(-action=>"$config{'ow_cgiurl'}/openwebmail-viewatt.pl",
1737
-name=>'saveattachmentform').
1738
ow::tool::hiddens(action=>'saveattachment',
1739
sessionid=>$thissession,
1740
folder=>'',
1741
message_id=>'',
1742
attachment_nodeid=>'saveattfile',
1743
webdisksel=>'').
1744
end_form();
1745
$html =~ s/\@\@\@SAVEATTACHMENTFORM\@\@\@/$temphtml/;
1746
1747
# since $filelisthtml may be large, we put it into $html as late as possible
1748
$html =~ s/\@\@\@FILELIST\@\@\@/$filelisthtml/; undef($filelisthtml);
1749
1750
my $cookie = cookie( -name => "$user-currentdir",
1751
-value => $currentdir,
1752
-path => '/');
1753
httpprint([-cookie=>[$cookie]], [htmlheader(), $html, htmlfooter(2)]);
1754
}
1755
########## END FILESELECT ########################################
1756
1757
########## SHOWDIR ###############################################
1758
sub showdir {
1759
my ($olddir, $newdir, $filesort, $page, $msg)=@_;
1760
my $showthumbnail=param('showthumbnail')||0;
1761
my $showhidden=param('showhidden')||0;
1762
my $singlepage=param('singlepage')||0;
1763
my $searchtype=param('searchtype')||'';
1764
my $keyword=param('keyword')||''; $keyword=~s/[`;\|]//g;
1765
my $escapedkeyword=ow::tool::escapeURL($keyword);
1766
1767
my $quotahit_deltype='';
1768
if ($quotalimit>0 && $quotausage>$quotalimit &&
1769
($config{'delmail_ifquotahit'}||$config{'delfile_ifquotahit'}) ) {
1770
$quotausage=(ow::quota::get_usage_limit(\%config, $user, $homedir, 1))[2]; # get uptodate usage
1771
if ($quotausage>$quotalimit) {
1772
1773
my (@validfolders, $inboxusage, $folderusage);
1774
getfolders(\@validfolders, \$inboxusage, \$folderusage);
1775
1776
if ($config{'delfile_ifquotahit'} && $folderusage < $quotausage*0.5) {
1777
$quotahit_deltype='quotahit_delfile';
1778
my $webdiskrootdir=$homedir.absolute_vpath("/", $config{'webdisk_rootpath'});
1779
cutdirfiles(($quotausage-$quotalimit*0.9)*1024, $webdiskrootdir);
1780
1781
$quotausage=(ow::quota::get_usage_limit(\%config, $user, $homedir, 1))[2]; # get uptodate usage
1782
}
1783
}
1784
}
1785
1786
my ($currentdir, $escapedcurrentdir, @list);
1787
if ($keyword ne '') { # olddir = newdir if keyword is supplied for searching
1788
my $err=filelist_of_search($searchtype, $keyword, $olddir, dotpath('webdisk.cache'), \@list);
1789
if ($err ne '') {
1790
$keyword=""; $msg.=$err;
1791
} else {
1792
$currentdir=$olddir;
1793
}
1794
}
1795
if ($keyword eq '') {
1796
foreach my $dir ($newdir, $olddir, "/") {
1797
my $err=verify_vpath($webdiskrootdir, $dir);
1798
if ($err ne '') {
1799
$msg .= "$err\n"; next;
1800
}
1801
if (!opendir(D, "$webdiskrootdir/$dir")) {
1802
$msg .= "$lang_err{'couldnt_open'} $dir ($!)\n"; next;
1803
}
1804
@list=readdir(D);
1805
closedir(D);
1806
$currentdir=$dir;
1807
last;
1808
}
1809
openwebmailerror(__FILE__, __LINE__, $msg) if ($currentdir eq '');
1810
}
1811
$escapedcurrentdir=ow::tool::escapeURL($currentdir);
1812
1813
my (%fsize, %fdate, %fperm, %ftype, %flink);
1814
my ($dcount, $fcount, $sizecount)=(0,0,0);
1815
foreach my $p (@list) {
1816
next if ( $p eq "." || $p eq "..");
1817
my $vpath=absolute_vpath($currentdir, $p);
1818
if ( !$config{'webdisk_lsmailfolder'} ) {
1819
next if ( is_under_dotdir_or_folderdir("$webdiskrootdir/$vpath") );
1820
}
1821
my $fname=$vpath; $fname=~s|.*/||;
1822
next if ( (!$config{'webdisk_lshidden'}||!$showhidden) && $fname =~ /^\./ );
1823
if ( -l "$webdiskrootdir/$vpath" ) { # symbolic link, aka:shortcut
1824
next if (!$config{'webdisk_lssymlink'});
1825
my $realpath=readlink("$webdiskrootdir/$vpath");
1826
$realpath="$webdiskrootdir/$vpath/../$realpath" if ($realpath!~m!^/!);
1827
my $vpath2=fullpath2vpath($realpath, $webdiskrootdir);
1828
if ($vpath2 ne '') {
1829
$flink{$p}=" -> $vpath2";
1830
} else {
1831
next if (!$config{'webdisk_allow_symlinkout'});
1832
if ($config{'webdisk_symlinkout_display'} eq 'path') {
1833
$flink{$p}=" -> sys::$realpath";
1834
} elsif ($config{'webdisk_symlinkout_display'} eq '@') {
1835
$flink{$p}='@';
1836
} else {
1837
$flink{$p}='';
1838
}
1839
}
1840
}
1841
1842
my ($st_dev,$st_ino,$st_mode,$st_nlink,$st_uid,$st_gid,$st_rdev,$st_size,
1843
$st_atime,$st_mtime,$st_ctime,$st_blksize,$st_blocks)= stat("$webdiskrootdir/$vpath");
1844
if ( ($st_mode&0170000)==0040000 ) {
1845
$ftype{$p}="d"; $dcount++;
1846
} elsif ( ($st_mode&0170000)==0100000 ) {
1847
$ftype{$p}="f"; $fcount++; $sizecount+=$st_size;
1848
} else { # unix specific filetype: fifo, socket, block dev, char dev..
1849
next if (!$config{'webdisk_lsunixspec'});
1850
$ftype{$fname}="u";
1851
}
1852
my $r=(-r _)?'R':'-';
1853
my $w=(-w _)?'W':'-';
1854
my $x=(-x _)?'X':'-';
1855
$fperm{$p}="$r$w$x";
1856
$fsize{$p}=$st_size;
1857
$fdate{$p}=$st_mtime;
1858
}
1859
close(D);
1860
1861
my @sortedlist;
1862
if ($filesort eq "name_rev") {
1863
@sortedlist= sort { $ftype{$a} cmp $ftype{$b} || $b cmp $a } keys(%ftype)
1864
} elsif ($filesort eq "size") {
1865
@sortedlist= sort { $ftype{$a} cmp $ftype{$b} || $fsize{$a}<=>$fsize{$b} } keys(%ftype)
1866
} elsif ($filesort eq "size_rev") {
1867
@sortedlist= sort { $ftype{$a} cmp $ftype{$b} || $fsize{$b}<=>$fsize{$a} } keys(%ftype)
1868
} elsif ($filesort eq "time") {
1869
@sortedlist= sort { $ftype{$a} cmp $ftype{$b} || $fdate{$a}<=>$fdate{$b} } keys(%ftype)
1870
} elsif ($filesort eq "time_rev") {
1871
@sortedlist= sort { $ftype{$a} cmp $ftype{$b} || $fdate{$b}<=>$fdate{$a} } keys(%ftype)
1872
} elsif ($filesort eq "perm") {
1873
@sortedlist= sort { $ftype{$a} cmp $ftype{$b} || $fperm{$a} cmp $fperm{$b} } keys(%ftype)
1874
} elsif ($filesort eq "perm_rev") {
1875
@sortedlist= sort { $ftype{$a} cmp $ftype{$b} || $fperm{$b} cmp $fperm{$a} } keys(%ftype)
1876
} else { # filesort = name
1877
@sortedlist= sort { $ftype{$a} cmp $ftype{$b} || $ftype{$a} cmp $ftype{$b} || $a cmp $b } keys(%ftype)
1878
}
1879
1880
my $totalpage= int(($#sortedlist+1)/($prefs{'webdisk_dirnumitems'}||10)+0.999999);
1881
$totalpage=1 if ($totalpage==0);
1882
if ($currentdir ne $olddir) {
1883
$page=1; # reset page number if change to new dir
1884
} else {
1885
$page=1 if ($page<1);
1886
$page=$totalpage if ($page>$totalpage);
1887
}
1888
1889
my ($html, $temphtml);
1890
$html = applystyle(readtemplate("dir.template"));
1891
1892
my $wd_url=qq|$config{'ow_cgiurl'}/openwebmail-webdisk.pl?sessionid=$thissession&amp;folder=$escapedfolder&amp;message_id=$escapedmessageid&amp;currentdir=$escapedcurrentdir&amp;showthumbnail=$showthumbnail&amp;showhidden=$showhidden&amp;singlepage=$singlepage|;
1893
my $wd_url_sort_page=qq|$wd_url&amp;filesort=$filesort&amp;page=$page|;
1894
1895
$temphtml .= iconlink("home.gif" ,"$lang_text{'backto'} $lang_text{'homedir'}", qq|accesskey="G" href="$wd_url_sort_page&amp;action=showdir&amp;gotodir=|.ow::tool::escapeURL('/').qq|"|);
1896
$temphtml .= iconlink("refresh.gif" ,"$lang_wdbutton{'refresh'} ", qq|accesskey="R" href="$wd_url_sort_page&amp;action=userrefresh&amp;gotodir=$escapedcurrentdir"|);
1897
1898
$temphtml .= "&nbsp;\n";
1899
1900
if ($config{'enable_webmail'}) {
1901
if ($messageid eq "") {
1902
$temphtml .= iconlink("owm.gif", "$lang_text{'backto'} ".($lang_folders{$folder}||$folder),
1903
qq|accesskey="M" href="$config{'ow_cgiurl'}/openwebmail-main.pl?action=listmessages&amp;sessionid=$thissession&amp;folder=$escapedfolder"|);
1904
} else {
1905
$temphtml .= iconlink("owm.gif", "$lang_text{'backto'} ".($lang_folders{$folder}||$folder),
1906
qq|accesskey="M" href="$config{'ow_cgiurl'}/openwebmail-read.pl?action=readmessage&amp;sessionid=$thissession&amp;folder=$escapedfolder&amp;message_id=$escapedmessageid"|);
1907
}
1908
}
1909
if ($config{'enable_calendar'}) {
1910
$temphtml .= iconlink("calendar.gif", $lang_text{'calendar'}, qq|accesskey="K" href="$config{'ow_cgiurl'}/openwebmail-cal.pl?action=$prefs{'calendar_defaultview'}&amp;sessionid=$thissession&amp;folder=$escapedfolder&amp;message_id=$escapedmessageid"|);
1911
}
1912
if ( $config{'enable_sshterm'}) {
1913
if ( -r "$config{'ow_htmldir'}/applet/mindterm2/mindterm.jar" ) {
1914
$temphtml .= iconlink("sshterm.gif" ,"$lang_text{'sshterm'} ", qq|accesskey="T" href="#" onClick="window.open('$config{ow_htmlurl}/applet/mindterm2/ssh2.html', '_applet', 'width=400,height=100,top=2000,left=2000,resizable=no,menubar=no,scrollbars=no');"|);
1915
} elsif ( -r "$config{'ow_htmldir'}/applet/mindterm/mindtermfull.jar" ) {
1916
$temphtml .= iconlink("sshterm.gif" ,"$lang_text{'sshterm'} ", qq|accesskey="T" href="#" onClick="window.open('$config{ow_htmlurl}/applet/mindterm/ssh.html', '_applet', 'width=400,height=100,top=2000,left=2000,resizable=no,menubar=no,scrollbars=no');"|);
1917
}
1918
}
1919
if ( $config{'enable_preference'}) {
1920
$temphtml .= iconlink("prefs.gif", $lang_text{'userprefs'}, qq|accesskey="O" href="$config{'ow_cgiurl'}/openwebmail-prefs.pl?action=editprefs&amp;sessionid=$thissession&amp;folder=$escapedfolder&amp;message_id=$escapedmessageid&amp;prefs_caller=webdisk"|);
1921
}
1922
$temphtml .= iconlink("logout.gif", "$lang_text{'logout'} $prefs{'email'}", qq|accesskey="X" href="$config{'ow_cgiurl'}/openwebmail-main.pl?sessionid=$thissession&amp;action=logout"|);
1923
1924
$html =~ s/\@\@\@MENUBARLINKS\@\@\@/$temphtml/g;
1925
1926
if ($config{'quota_module'} ne "none") {
1927
$temphtml='';
1928
my $overthreshold=($quotalimit>0 && $quotausage/$quotalimit>$config{'quota_threshold'}/100);
1929
if ($config{'quota_threshold'}==0 || $overthreshold) {
1930
$temphtml = "$lang_text{'quotausage'}: ".lenstr($quotausage*1024,1);
1931
}
1932
if ($overthreshold) {
1933
$temphtml.=" (".(int($quotausage*1000/$quotalimit)/10)."%) ";
1934
}
1935
} else {
1936
$temphtml="&nbsp;";
1937
}
1938
$html =~ s/\@\@\@QUOTAUSAGE\@\@\@/$temphtml/;
1939
1940
$temphtml = start_multipart_form(-name=>'dirform',
1941
-action=>"$config{'ow_cgiurl'}/openwebmail-webdisk.pl") .
1942
ow::tool::hiddens(sessionid=>$thissession,
1943
folder=>$folder,
1944
message_id=>$messageid,
1945
currentdir=>$currentdir,
1946
gotodir=>$currentdir,
1947
filesort=>$filesort,
1948
page=>$page);
1949
$html =~ s/\@\@\@STARTDIRFORM\@\@\@/$temphtml/g;
1950
1951
if ($keyword ne '') {
1952
$temphtml=qq|$lang_text{'search'} &nbsp;|;
1953
} else {
1954
$temphtml=qq|$lang_text{'dir'} &nbsp;|;
1955
}
1956
1957
my $p='/';
1958
$temphtml.=qq|<a href="$wd_url_sort_page&amp;action=showdir&amp;gotodir=|.ow::tool::escapeURL($p).qq|">/</a>\n|;
1959
foreach ( split(/\//, $currentdir) ) {
1960
next if ($_ eq "");
1961
$p.="$_/";
1962
$temphtml.=qq|<a href="$wd_url_sort_page&amp;action=showdir&amp;gotodir=|.ow::tool::escapeURL($p).qq|">|.
1963
ow::htmltext::str2html("$_/").qq|</a>\n|;
1964
}
1965
$html =~ s/\@\@\@CURRENTDIR\@\@\@/$temphtml/g;
1966
1967
if ($config{'webdisk_allow_thumbnail'}) {
1968
$html =~ s/\@\@\@SHOWTHUMBLABEL\@\@\@/$lang_text{'showthumbnail'}/g;
1969
$temphtml=checkbox(-name=>'showthumbnail',
1970
-value=>'1',
1971
-checked=>$showthumbnail,
1972
-OnClick=>'document.dirform.submit();',
1973
-override=>'1',
1974
-label=>'');
1975
$html =~ s/\@\@\@SHOWTHUMBCHECKBOX\@\@\@/$temphtml/g;
1976
} else {
1977
$html =~ s/\@\@\@SHOWTHUMBLABEL\@\@\@//g;
1978
$html =~ s/\@\@\@SHOWTHUMBCHECKBOX\@\@\@//g;
1979
}
1980
1981
if ($config{'webdisk_lshidden'}) {
1982
$html =~ s/\@\@\@SHOWHIDDENLABEL\@\@\@/$lang_text{'showhidden'}/g;
1983
$temphtml=checkbox(-name=>'showhidden',
1984
-value=>'1',
1985
-checked=>$showhidden,
1986
-OnClick=>'document.dirform.submit();',
1987
-override=>'1',
1988
-label=>'');
1989
$html =~ s/\@\@\@SHOWHIDDENCHECKBOX\@\@\@/$temphtml/g;
1990
} else {
1991
$html =~ s/\@\@\@SHOWHIDDENLABEL\@\@\@//g;
1992
$html =~ s/\@\@\@SHOWHIDDENCHECKBOX\@\@\@//g;
1993
}
1994
1995
$temphtml=checkbox(-name=>'singlepage',
1996
-value=>'1',
1997
-checked=>$singlepage,
1998
-OnClick=>'document.dirform.submit();',
1999
-override=>'1',
2000
-label=>'');
2001
$html =~ s/\@\@\@SINGLEPAGECHECKBOX\@\@\@/$temphtml/g;
2002
2003
if ($prefs{'iconset'}!~/^Text\./) {
2004
if ($currentdir eq "/") {
2005
$temphtml=qq|<IMG SRC="$config{'ow_htmlurl'}/images/file/disk.gif" align="absmiddle" border="0">|;
2006
} else {
2007
my $parentdir = absolute_vpath($currentdir, "..");
2008
$temphtml=qq|<a href="$wd_url_sort_page&amp;action=showdir&amp;gotodir=|.ow::tool::escapeURL($parentdir).qq|">|.
2009
qq|<IMG SRC="$config{'ow_htmlurl'}/images/file/dirup.gif" align="absmiddle" border="0">|.
2010
qq|</a>|;
2011
}
2012
} else {
2013
$temphtml='';
2014
}
2015
$html =~ s/\@\@\@DIRUPLINK\@\@\@/$temphtml/g;
2016
2017
my $wd_url_sort=qq|$wd_url&amp;action=showdir&amp;gotodir=$escapedcurrentdir&amp;page=$page&amp;searchtype=$searchtype&amp;keyword=$escapedkeyword&amp;filesort|;
2018
2019
if ($filesort eq "name") {
2020
$temphtml = qq|<a href="$wd_url_sort=name_rev">$lang_text{'filename'}</a> |.iconlink("up.gif", "^", "");
2021
} elsif ($filesort eq "name_rev") {
2022
$temphtml = qq|<a href="$wd_url_sort=name">$lang_text{'filename'}</a> |.iconlink("down.gif", "v", "");
2023
} else {
2024
$temphtml = qq|<a href="$wd_url_sort=name">$lang_text{'filename'}</a>|;
2025
}
2026
$html =~ s/\@\@\@FILENAME\@\@\@/$temphtml/g;
2027
2028
if ($filesort eq "size") {
2029
$temphtml = qq|<a href="$wd_url_sort=size_rev">$lang_text{'size'}</a> |.iconlink("up.gif", "^", "");
2030
} elsif ($filesort eq "size_rev") {
2031
$temphtml = qq|<a href="$wd_url_sort=size">$lang_text{'size'}</a> |.iconlink("down.gif", "v", "");
2032
} else {
2033
$temphtml = qq|<a href="$wd_url_sort=size_rev">$lang_text{'size'}</a>|;
2034
}
2035
$html =~ s/\@\@\@FILESIZE\@\@\@/$temphtml/g;
2036
2037
if ($filesort eq "time") {
2038
$temphtml = qq|<a href="$wd_url_sort=time_rev">$lang_text{'lastmodified'}</a> |.iconlink("up.gif", "^", "");
2039
} elsif ($filesort eq "time_rev") {
2040
$temphtml = qq|<a href="$wd_url_sort=time">$lang_text{'lastmodified'}</a> |.iconlink("down.gif", "v", "");
2041
} else {
2042
$temphtml = qq|<a href="$wd_url_sort=time_rev">$lang_text{'lastmodified'}</a>|;
2043
}
2044
$html =~ s/\@\@\@FILEDATE\@\@\@/$temphtml/g;
2045
2046
if ($filesort eq "perm") {
2047
$temphtml = qq|<a href="$wd_url_sort=perm_rev" title="$lang_text{'permission'}">$lang_text{'perm'}</a> |.iconlink("up.gif", "^", "");
2048
} elsif ($filesort eq "perm_rev") {
2049
$temphtml = qq|<a href="$wd_url_sort=perm" title="$lang_text{'permission'}">$lang_text{'perm'}</a> |.iconlink("down.gif", "v", "");
2050
} else {
2051
$temphtml = qq|<a href="$wd_url_sort=perm_rev" title="$lang_text{'permission'}">$lang_text{'perm'}</a>|;
2052
}
2053
$html =~ s/\@\@\@FILEPERM\@\@\@/$temphtml/g;
2054
2055
$temphtml = checkbox(-name=>'allbox',
2056
-value=>'1',
2057
-onClick=>"CheckAll($prefs{'uselightbar'});",
2058
-label=>'',
2059
-override=>'1');
2060
$html =~ s/\@\@\@ALLBOXCHECKBOX\@\@\@/$temphtml/;
2061
2062
my $filelisthtml;
2063
if ($#sortedlist>=0) {
2064
my $os=$^O||'generic';
2065
my ($i_first, $i_last)=(0, $#sortedlist);
2066
if (!$singlepage) {
2067
$i_first=($page-1)*$prefs{'webdisk_dirnumitems'};
2068
$i_last=$i_first+$prefs{'webdisk_dirnumitems'}-1;
2069
$i_last=$#sortedlist if ($i_last>$#sortedlist);
2070
}
2071
foreach my $i ($i_first..$i_last) {
2072
my $p=$sortedlist[$i];
2073
my $accesskeystr=$i%10+1;
2074
if ($accesskeystr == 10) {
2075
$accesskeystr=qq|accesskey="0"|;
2076
} elsif ($accesskeystr < 10) {
2077
$accesskeystr=qq|accesskey="$accesskeystr"|;
2078
}
2079
2080
my ($imgstr, $namestr, $opstr);
2081
if ($ftype{$p} eq "d") {
2082
if ($prefs{'iconset'}!~/^Text\./) {
2083
$imgstr=qq|<IMG SRC="$config{'ow_htmlurl'}/images/file/|.
2084
findicon($p, $ftype{$p}, 0, $os).
2085
qq|" align="absmiddle" border="0">|;
2086
}
2087
$namestr=qq|<a href="$wd_url_sort_page&amp;action=showdir&amp;gotodir=|.
2088
ow::tool::escapeURL($p).qq|" $accesskeystr>$imgstr <b>|.ow::htmltext::str2html($p);
2089
$namestr.=ow::htmltext::str2html($flink{$p}) if (defined($flink{$p}));
2090
$namestr.=qq|</b></a>|;
2091
$opstr=qq|<a href="$wd_url_sort_page&amp;action=showdir&amp;gotodir=|.
2092
ow::tool::escapeURL($p).qq|"><b>&lt;$lang_text{'dir'}&gt;</b></a>|;
2093
2094
} else {
2095
my $is_txt= (-T "$webdiskrootdir/$currentdir/$p" || $p=~/\.(txt|html?)$/i);
2096
if ($prefs{'iconset'}!~/^Text\./) {
2097
$imgstr=qq|<IMG SRC="$config{'ow_htmlurl'}/images/file/|.
2098
findicon($p, $ftype{$p}, $is_txt, $os).
2099
qq|" align="absmiddle" border="0">|;
2100
}
2101
my $blank=""; $blank="target=_blank" if ($is_txt || $p=~/\.(jpe?g|gif|png|bmp)$/i);
2102
2103
my ($dname, $fname);
2104
if ($p=~m|^(.*/)([^/]*)$|) {
2105
($dname, $fname)=($1, $2);
2106
} else {
2107
($dname, $fname)=('', $p);
2108
}
2109
2110
my $a=qq|<a href="$config{'ow_cgiurl'}/openwebmail-webdisk.pl/|.ow::tool::escapeURL($fname).
2111
qq|?sessionid=$thissession&amp;currentdir=$escapedcurrentdir&amp;|.
2112
qq|action=download&amp;selitems=|.ow::tool::escapeURL($p).
2113
qq|" $accesskeystr $blank>|;
2114
2115
$namestr="$a$imgstr</a> ";
2116
if ($dname ne '') {
2117
$namestr.=qq|<a href="$wd_url_sort_page&amp;action=showdir&amp;gotodir=|.
2118
ow::tool::escapeURL($dname).qq|" $accesskeystr><b>|.ow::htmltext::str2html($dname).qq|</b> </a>|;
2119
}
2120
$namestr.=$a.ow::htmltext::str2html($fname);
2121
$namestr.=ow::htmltext::str2html($flink{$p}) if (defined($flink{$p}));
2122
$namestr.=qq|</a>|;
2123
2124
if ($p=~/\.(?:pdf|ps)$/i ) {
2125
if (!$config{'webdisk_readonly'} &&
2126
(!$quotalimit||$quotausage<$quotalimit) ) {
2127
my $mk='mkpdf'; $mk='mkps' if ($p=~/\.pdf$/i);
2128
my $onclickstr;
2129
if ($prefs{'webdisk_confirmcompress'}) {
2130
my $pstr=$p; $pstr=~s/'/\\'/g; # escape for javascript
2131
$onclickstr=qq|onclick="return confirm('$lang_wdbutton{$mk}? ($pstr)');"|;
2132
}
2133
$opstr.=qq|<a href="$wd_url_sort_page&amp;action=$mk&amp;selitems=|.
2134
ow::tool::escapeURL($p).qq|" $onclickstr>[$lang_wdbutton{$mk}]</a>|;
2135
}
2136
} elsif ($is_txt) {
2137
if ($p=~/\.html?$/i) {
2138
$opstr=qq|<a href=#here onClick="window.open('|.
2139
qq|$wd_url&amp;action=preview&amp;selitems=|.ow::tool::escapeURL($p).
2140
qq|','_previewfile','width=720,height=550,scrollbars=yes,resizable=yes,location=no');|.
2141
qq|">[$lang_wdbutton{'preview'}]</a>|;
2142
}
2143
if (!$config{'webdisk_readonly'} &&
2144
(!$quotalimit||$quotausage<$quotalimit) ) {
2145
$opstr.=qq|<a href=#here onClick="window.open('|.
2146
qq|$wd_url&amp;action=editfile&amp;selitems=|.ow::tool::escapeURL($p).
2147
qq|','_editfile','width=720,height=550,scrollbars=yes,resizable=yes,location=no');|.
2148
qq|">[$lang_wdbutton{'edit'}]</a>|;
2149
}
2150
} elsif ($p=~/\.(?:zip|rar|arj|lzh|t[bg]z|tar\.g?z|tar\.bz2?|tne?f)$/i ) {
2151
$opstr=qq|<a href=#here onClick="window.open('|.
2152
qq|$wd_url&amp;action=listarchive&amp;selitems=|.ow::tool::escapeURL($p).
2153
qq|','_editfile','width=780,height=550,scrollbars=yes,resizable=yes,location=no');|.
2154
qq|">[$lang_wdbutton{'listarchive'}]</a>|;
2155
if (!$config{'webdisk_readonly'} &&
2156
(!$quotalimit||$quotausage<$quotalimit) ) {
2157
my $onclickstr;
2158
if ($prefs{'webdisk_confirmcompress'}) {
2159
my $pstr=$p; $pstr=~s/'/\\'/g; # escape for javascript
2160
$onclickstr=qq|onclick="return confirm('$lang_wdbutton{extract}? ($pstr)');"|;
2161
}
2162
my $allow_extract=1;
2163
if ($p=~/\.(?:t[bg]z|tar\.g?z|tar\.bz2?)$/i && !$config{'webdisk_allow_untar'} ||
2164
$p=~/\.zip$/i && !$config{'webdisk_allow_unzip'} ||
2165
$p=~/\.rar$/i && !$config{'webdisk_allow_unrar'} ||
2166
$p=~/\.arj$/i && !$config{'webdisk_allow_unarj'} ||
2167
$p=~/\.lzh$/i && !$config{'webdisk_allow_unlzh'} ) {
2168
$allow_extract=0;
2169
}
2170
if ($allow_extract) {
2171
$opstr.=qq| <a href="$wd_url_sort_page&amp;action=decompress&amp;selitems=|.
2172
ow::tool::escapeURL($p).qq|" $onclickstr>[$lang_wdbutton{'extract'}]</a>|;
2173
}
2174
}
2175
} elsif ($p=~/\.(?:g?z|bz2?)$/i ) {
2176
if (!$config{'webdisk_readonly'} &&
2177
(!$quotalimit||$quotausage<$quotalimit) ) {
2178
my $onclickstr;
2179
if ($prefs{'webdisk_confirmcompress'}) {
2180
my $pstr=$p; $pstr=~s/'/\\'/g; # escape for javascript
2181
$onclickstr=qq|onclick="return confirm('$lang_wdbutton{decompress}? ($pstr)');"|;
2182
}
2183
$opstr=qq|<a href="$wd_url_sort_page&amp;action=decompress&amp;selitems=|.
2184
ow::tool::escapeURL($p).qq|" $onclickstr>[$lang_wdbutton{'decompress'}]</a>|;
2185
}
2186
} elsif ($p=~/\.(?:doc|dot)$/i ) {
2187
$opstr=qq|<a href=#here onClick="window.open('|.
2188
qq|$wd_url&amp;action=wordpreview&amp;selitems=|.ow::tool::escapeURL($p).
2189
qq|','_wordpreview','width=780,height=550,scrollbars=yes,resizable=yes,location=no');|.
2190
qq|">[$lang_wdbutton{'preview'}]</a>|;
2191
2192
} elsif ($p=~/\.(?:jpe?g|gif|png|bmp|tif)$/i ) {
2193
if ($showthumbnail) {
2194
my $thumbnail=path2thumbnail($p);
2195
if ( -f "$webdiskrootdir/$currentdir/$thumbnail") {
2196
my $fname=$p; $fname=~s|.*/||g;
2197
$opstr=qq|<a href="$config{'ow_cgiurl'}/openwebmail-webdisk.pl/|.ow::tool::escapeURL($fname).
2198
qq|?sessionid=$thissession&amp;currentdir=$escapedcurrentdir&amp;|.
2199
qq|action=download&amp;selitems=|.ow::tool::escapeURL($p).qq|" $blank>|.
2200
qq|<IMG SRC="$wd_url_sort_page&amp;action=download&amp;selitems=|.
2201
ow::tool::escapeURL($thumbnail).qq|" align="absmiddle" border="0"></a>|;
2202
}
2203
}
2204
}
2205
}
2206
2207
my $right='right'; $right='left' if ($ow::lang::RTL{$prefs{'language'}});
2208
$namestr=qq|<table width="100%" border=0 cellspacing=0 cellpadding=0><tr>|.
2209
qq|<td>$namestr</td>\n<td align="$right" nowrap>$opstr</td></tr></table>|;
2210
2211
my $sizestr=qq|<a title="|.lenstr($fsize{$p},1).qq|">$fsize{$p}</a>|;
2212
2213
my $datestr;
2214
if (defined($fdate{$p})) {
2215
$datestr=ow::datetime::dateserial2str(ow::datetime::gmtime2dateserial($fdate{$p}),
2216
$prefs{'timeoffset'}, $prefs{'daylightsaving'},
2217
$prefs{'dateformat'}, $prefs{'hourformat'});
2218
}
2219
2220
$fperm{$p}=~/^(.)(.)(.)$/;
2221
my $permstr=qq|<table cellspacing="0" cellpadding="0" border="0"><tr>|.
2222
qq|<td align=center width=12>$1</td>|.
2223
qq|<td align=center width=12>$2</td>|.
2224
qq|<td align=center width=12>$3</td>|.
2225
qq|</tr></table>|;
2226
2227
my ($tr_bgcolorstr, $td_bgcolorstr, $checkbox_onclickstr);
2228
if ($prefs{'uselightbar'}) {
2229
$tr_bgcolorstr=qq|bgcolor=$style{tablerow_light} |.
2230
qq|onMouseOver='this.style.backgroundColor=$style{tablerow_hicolor};' |.
2231
qq|onMouseOut='this.style.backgroundColor = document.getElementById("$i").checked? $style{tablerow_dark}:$style{tablerow_light};' |.
2232
qq|onClick='if (!document.layers) {var cb=document.getElementById("$i"); cb.checked=!cb.checked}' |.
2233
qq|id='tr_$i' |;
2234
$td_bgcolorstr='';
2235
$checkbox_onclickstr='if (!document.layers) {this.checked=!this.checked}'; # disable checkbox change since it is already done once by tr onclick event
2236
} else {
2237
$tr_bgcolorstr='';
2238
$td_bgcolorstr=qq|bgcolor=|.($style{"tablerow_dark"},$style{"tablerow_light"})[$i%2];
2239
$checkbox_onclickstr='';
2240
}
2241
$filelisthtml.=qq|<tr $tr_bgcolorstr>\n|.
2242
qq|<td $td_bgcolorstr>$namestr</td>\n|.
2243
qq|<td $td_bgcolorstr align="right">$sizestr</td>\n|.
2244
qq|<td $td_bgcolorstr align="center">$datestr</td>\n|.
2245
qq|<td $td_bgcolorstr align="center">$permstr</td>\n|.
2246
qq|<td $td_bgcolorstr align="center">|.
2247
checkbox(-name=>'selitems',
2248
-value=>$p,
2249
-override=>'1',
2250
-label=>'',
2251
-onclick=> $checkbox_onclickstr,
2252
-id=>$i).
2253
qq|</td>\n</tr>\n\n|;
2254
}
2255
} else {
2256
my $td_bgcolorstr = qq|bgcolor=|.$style{"tablerow_light"};
2257
$filelisthtml.=qq|<tr>\n|.
2258
qq|<td $td_bgcolorstr align=center>|.
2259
qq|<table><tr><td><font color=#aaaaaa>$lang_text{'noitemfound'}</font></td</tr></table>|.
2260
qq|</td>\n|.
2261
qq|<td $td_bgcolorstr>&nbsp;</td>\n|.
2262
qq|<td $td_bgcolorstr>&nbsp;</td>\n|.
2263
qq|<td $td_bgcolorstr>&nbsp;</td>\n|.
2264
qq|<td $td_bgcolorstr>&nbsp;</td>\n|.
2265
qq|</tr>\n\n|;
2266
}
2267
undef(%fsize); undef(%fdate); undef(%fperm); undef(%ftype); undef(%flink); # release mem if possible
2268
2269
if (!$singlepage) {
2270
my $wd_url_page=qq|$wd_url&amp;action=showdir&amp;gotodir=$escapedcurrentdir&amp;filesort=$filesort&amp;searchtype=$searchtype&amp;keyword=$escapedkeyword&amp;page|;
2271
if ($page>1) {
2272
my $gif="left.gif"; $gif="right.gif" if ($ow::lang::RTL{$prefs{'language'}});
2273
$temphtml = iconlink($gif, "&lt;", qq|accesskey="U" href="$wd_url_page=|.($page-1).qq|"|).qq|\n|;
2274
} else {
2275
my $gif="left-grey.gif"; $gif="right-grey.gif" if ($ow::lang::RTL{$prefs{'language'}});
2276
$temphtml = iconlink($gif, "-", "").qq|\n|;
2277
}
2278
$html =~ s/\@\@\@LEFTPAGECONTROL\@\@\@/$temphtml/g;
2279
2280
if ($page<$totalpage) {
2281
my $gif="right.gif"; $gif="left.gif" if ($ow::lang::RTL{$prefs{'language'}});
2282
$temphtml = iconlink($gif, "&gt;", qq|accesskey="D" href="$wd_url_page=|.($page+1).qq|"|).qq|\n|;
2283
} else {
2284
my $gif="right-grey.gif"; $gif="left-grey.gif" if ($ow::lang::RTL{$prefs{'language'}});
2285
$temphtml = iconlink($gif, "-", "").qq|\n|;
2286
}
2287
$html =~ s/\@\@\@RIGHTPAGECONTROL\@\@\@/$temphtml/g;
2288
2289
my $p_first=$page-4; $p_first=1 if ($p_first<1);
2290
my $p_last=$p_first+9;
2291
if ($p_last>$totalpage) {
2292
$p_last=$totalpage;
2293
while ($p_last-$p_first<9 && $p_first>1) {
2294
$p_first--;
2295
}
2296
}
2297
2298
$temphtml='';
2299
for my $p ($p_first..$p_last) {
2300
if ($p == $page) {
2301
$temphtml .= qq|<b>$p</b>&nbsp;\n|;
2302
} else {
2303
$temphtml .= qq|<a href="$wd_url_page=$p">$p</a>&nbsp;\n|;
2304
}
2305
}
2306
$html =~ s/\@\@\@PAGELINKS\@\@\@/$temphtml/g;
2307
} else {
2308
$html =~ s/\@\@\@LEFTPAGECONTROL\@\@\@//g;
2309
$html =~ s/\@\@\@RIGHTPAGECONTROL\@\@\@//g;
2310
$html =~ s/\@\@\@PAGELINKS\@\@\@//g;
2311
}
2312
2313
$temphtml = sprintf("%d %s, %d %s",
2314
$dcount, ($dcount>1)?$lang_text{'dirs'}:$lang_text{'dir'},
2315
$fcount, ($fcount>1)?$lang_text{'files'}:$lang_text{'file'});
2316
$temphtml.= ", $totalpage $lang_text{'page'}" if ($totalpage>9);
2317
$html =~ s/\@\@\@INFOCOUNT\@\@\@/$temphtml/g;
2318
2319
$temphtml = lenstr($sizecount,1);
2320
$html =~ s/\@\@\@INFOSIZE\@\@\@/$temphtml/g;
2321
2322
2323
$temphtml = textfield(-name=>'destname',
2324
-default=>"",
2325
-size=>'35',
2326
-accesskey=>'N',
2327
-override=>'1').qq|\n|;
2328
$html =~ s/\@\@\@DESTNAMEFIELD\@\@\@/$temphtml/g;
2329
2330
$temphtml=submit(-name=>'chdirbutton',
2331
-accesskey=>'J',
2332
-onClick=>"if (document.dirform.keyword.value != '') {return true;}; return destnamefilled('$lang_text{dest_of_chdir}');",
2333
-value=>$lang_wdbutton{'chdir'});
2334
if (!$config{'webdisk_readonly'} &&
2335
(!$quotalimit||$quotausage<$quotalimit) ) {
2336
$temphtml.=submit(-name=>'mkdirbutton',
2337
-accesskey=>'M',
2338
-onClick=>"return destnamefilled('$lang_text{name_of_newdir}');",
2339
-value=>$lang_wdbutton{'mkdir'});
2340
$temphtml.=submit(-name=>'newfilebutton',
2341
-accesskey=>'F',
2342
-onClick=>"return destnamefilled('$lang_text{name_of_newfile}');",
2343
-value=>$lang_wdbutton{'newfile'});
2344
$temphtml.=qq|\n|;
2345
2346
}
2347
$html =~ s/\@\@\@BUTTONS\@\@\@/$temphtml/g;
2348
2349
$temphtml='';
2350
if (!$config{'webdisk_readonly'}) {
2351
if (!$quotalimit||$quotausage<$quotalimit) {
2352
$temphtml.=submit(-name=>'copybutton',
2353
-accesskey=>'C',
2354
-onClick=>"return(anyfileselected() && destnamefilled('$lang_text{dest_of_thecopy}') && opconfirm('$lang_wdbutton{copy}', $prefs{webdisk_confirmmovecopy}));",
2355
-value=>$lang_wdbutton{'copy'});
2356
$temphtml.=submit(-name=>'movebutton',
2357
-accesskey=>'V',
2358
-onClick=>"return(anyfileselected() && destnamefilled('$lang_text{dest_of_themove}') && opconfirm('$lang_wdbutton{move}', $prefs{webdisk_confirmmovecopy}));",
2359
-value=>$lang_wdbutton{'move'});
2360
if ($config{'webdisk_allow_symlinkcreate'} &&
2361
$config{'webdisk_lssymlink'}) {
2362
$temphtml.=submit(-name=>'symlinkbutton',
2363
-accesskey=>'N',
2364
-onClick=>"return(anyfileselected() && destnamefilled('$lang_text{dest_of_themove}') && opconfirm('$lang_wdbutton{symlink}', $prefs{webdisk_confirmmovecopy}));",
2365
-value=>$lang_wdbutton{'symlink'});
2366
}
2367
}
2368
$temphtml.=submit(-name=>'deletebutton',
2369
-accesskey=>'Y',
2370
-onClick=>"return (anyfileselected() && opconfirm('$lang_wdbutton{delete}', $prefs{webdisk_confirmdel}));",
2371
-value=>$lang_wdbutton{'delete'});
2372
$temphtml.=qq|&nbsp;\n|;
2373
}
2374
2375
if (!$config{'webdisk_readonly'} &&
2376
(!$quotalimit||$quotausage<$quotalimit) ) {
2377
$temphtml.=submit(-name=>'gzipbutton',
2378
-accesskey=>'Z',
2379
-onClick=>"return(anyfileselected() && opconfirm('$lang_wdbutton{gzip}', $prefs{webdisk_confirmcompress}));",
2380
-value=>$lang_wdbutton{'gzip'});
2381
$temphtml.=submit(-name=>'mkzipbutton',
2382
-accesskey=>'Z',
2383
-onClick=>"return(anyfileselected() && destnamefilled('$lang_text{dest_of_thezip}') && opconfirm('$lang_wdbutton{mkzip}', $prefs{webdisk_confirmcompress}));",
2384
-value=>$lang_wdbutton{'mkzip'});
2385
$temphtml.=submit(-name=>'mktgzbutton',
2386
-accesskey=>'Z',
2387
-onClick=>"return(anyfileselected() && destnamefilled('$lang_text{dest_of_thetgz}') && opconfirm('$lang_wdbutton{mktgz}', $prefs{webdisk_confirmcompress}));",
2388
-value=>$lang_wdbutton{'mktgz'});
2389
if ($config{'webdisk_allow_thumbnail'}) {
2390
$temphtml.=submit(-name=>'mkthumbnailbutton',
2391
-accesskey=>'Z',
2392
-onClick=>"return(anyfileselected() && opconfirm('$lang_wdbutton{mkthumbnail}', $prefs{webdisk_confirmcompress}));",
2393
-value=>$lang_wdbutton{'mkthumbnail'});
2394
}
2395
$temphtml.=qq|&nbsp;\n|;
2396
}
2397
2398
$temphtml.=submit(-name=>'downloadbutton',
2399
-accesskey=>'L',
2400
-onClick=>'return anyfileselected();',
2401
-value=>$lang_wdbutton{'download'});
2402
$html =~ s/\@\@\@BUTTONS2\@\@\@/$temphtml/g;
2403
2404
my %searchtypelabels = ('filename'=>$lang_text{'filename'},
2405
'textcontent'=>$lang_text{'textcontent'});
2406
$temphtml = popup_menu(-name=>'searchtype',
2407
-default=>'filename',
2408
-values=>['filename', 'textcontent'],
2409
-labels=>\%searchtypelabels);
2410
$temphtml .= textfield(-name=>'keyword',
2411
-default=>$keyword,
2412
-size=>'25',
2413
-accesskey=>'S',
2414
-onChange=>'document.dirform.searchbutton.focus();',
2415
-override=>'1');
2416
$temphtml .= submit(-name=>'searchbutton',
2417
-value=>$lang_text{'search'});
2418
$html =~ s/\@\@\@SEARCHFILEFIELD\@\@\@/$temphtml/g;
2419
2420
if (!$config{'webdisk_readonly'} &&
2421
(!$quotalimit||$quotausage<$quotalimit) ) {
2422
templateblock_enable($html, 'UPLOAD');
2423
$temphtml = filefield(-name=>'upload',
2424
-default=>"",
2425
-size=>'20',
2426
-accesskey=>'W',
2427
-override=>'1');
2428
$temphtml .= submit(-name=>'uploadbutton',
2429
-onClick=>'return uploadfilled();',
2430
-value=>$lang_wdbutton{'upload'});
2431
$html =~ s/\@\@\@UPLOADFILEFIELD\@\@\@/$temphtml/g;
2432
} else {
2433
templateblock_disable($html, 'UPLOAD');
2434
}
2435
2436
if ($quotalimit>0 && $quotausage>=$quotalimit) {
2437
$msg.="$lang_err{'quotahit_alert'}\n";
2438
}
2439
$temphtml = textarea(-name=>'msg',
2440
-default=>$msg,
2441
-rows=>'3',
2442
-columns=>'78',
2443
-wrap=>'hard',
2444
-override=>'1');
2445
$html =~ s/\@\@\@MSGTEXTAREA\@\@\@/$temphtml/g;
2446
2447
$temphtml=end_form();
2448
$html =~ s/\@\@\@ENDFORM\@\@\@/$temphtml/g;
2449
2450
# show quotahit del warning
2451
if ($quotahit_deltype ne '') {
2452
my $msg=qq|<font size="-1" color="#cc0000">$lang_err{$quotahit_deltype}</font>|;
2453
$msg=~s/\@\@\@QUOTALIMIT\@\@\@/$config{'quota_limit'}$lang_sizes{'kb'}/;
2454
$html.=readtemplate('showmsg.js').
2455
qq|<script language="JavaScript">\n<!--\n|.
2456
qq|showmsg('$prefs{"charset"}', '$lang_text{"quotahit"}', '$msg', '$lang_text{"close"}', '_quotahit_del', 400, 100, 60);\n|.
2457
qq|//-->\n</script>\n|;
2458
}
2459
2460
# since $filelisthtml may be large, we put it into $html as late as possible
2461
$html =~ s/\@\@\@FILELIST\@\@\@/$filelisthtml/g; undef($filelisthtml);
2462
2463
# since some browser always treat refresh directive as realtive url.
2464
# we use relative path for refresh
2465
my $refreshinterval=$prefs{'refreshinterval'}*60;
2466
my $relative_url="$config{'ow_cgiurl'}/openwebmail-webdisk.pl";
2467
$relative_url=~s!/.*/!!g;
2468
my $cookie = cookie( -name => "$user-currentdir",
2469
-value => $currentdir,
2470
-path => '/');
2471
httpprint([-cookie=>[$cookie],
2472
-Refresh=>"$refreshinterval;URL=$relative_url?sessionid=$thissession&folder=$escapedfolder&message_id=$escapedmessageid&action=showdir&currentdir=$escapedcurrentdir&gotodir=$escapedcurrentdir&showthumbnail=$showthumbnail&showhidden=$showhidden&singlepage=$singlepage&filesort=$filesort&page=$page&searchtype=$searchtype&keyword=$escapedkeyword&session_noupdate=1"],
2473
[htmlheader(), htmlplugin($config{'header_pluginfile'}),
2474
$html,
2475
htmlplugin($config{'footer_pluginfile'}), htmlfooter(2)] );
2476
}
2477
2478
sub filelist_of_search {
2479
my ($searchtype, $keyword, $vpath, $cachefile, $r_list)[email protected]_;
2480
my $metainfo=join("@@@", $searchtype, $keyword, $vpath);
2481
my $cache_metainfo;
2482
2483
$cachefile=ow::tool::untaint($cachefile);
2484
ow::filelock::lock($cachefile, LOCK_EX) or
2485
return("$lang_err{'couldnt_lock'} $cachefile\n");
2486
2487
if ( -e $cachefile ) {
2488
open(CACHE, "$cachefile") or return("$lang_err{'couldnt_open'} $cachefile!");
2489
$cache_metainfo=<CACHE>;
2490
chomp($cache_metainfo);
2491
close(CACHE);
2492
}
2493
if ( $cache_metainfo ne $metainfo ) {
2494
my (@cmd, $stdout, $stderr, $exit, $sig);
2495
2496
chdir("$webdiskrootdir/$vpath") or
2497
return("$lang_err{'couldnt_chdirto'} $vpath\n");
2498
2499
if ($searchtype eq "filename") { # find . -name "*keyword"
2500
my $findbin=ow::tool::findbin('find');
2501
return("$lang_text{'program'} find $lang_err{'doesnt_exist'}\n") if ($findbin eq '');
2502
@cmd=($findbin, ".", '-iname', "*$keyword*", '-print');
2503
($stdout, $stderr, $exit, $sig)=ow::execute::execute(@cmd);
2504
2505
if ($stderr ne '') { # old find doesn't support -iname, use -name instead
2506
@cmd=($findbin, ".", '-name', "*$keyword*", '-print');
2507
($stdout, $stderr, $exit, $sig)=ow::execute::execute(@cmd);
2508
}
2509
} else { # grep -ilsr -- keyword .
2510
my $grepbin=ow::tool::findbin('grep');
2511
return("$lang_text{'program'} grep $lang_err{'doesnt_exist'}\n") if ($grepbin eq '');
2512
@cmd=($grepbin, "-ilsr", '--', $keyword, '.');
2513
($stdout, $stderr, $exit, $sig)=ow::execute::execute(@cmd);
2514
2515
if ($stderr ne '') { # old grep doesn't support -r, do no-recursive search instead
2516
if (!opendir(D, "$webdiskrootdir/$vpath")) {
2517
return("$lang_err{'couldnt_open'} $vpath ($!)\n");
2518
}
2519
my @f=readdir(D);
2520
closedir(D);
2521
@cmd=($grepbin, "-ils", '--', $keyword, @f);
2522
($stdout, $stderr, $exit, $sig)=ow::execute::execute(@cmd);
2523
}
2524
}
2525
2526
if (($exit!=0 && $stderr) || $sig) {
2527
if ($sig) {
2528
return "$lang_text{'search'} $lang_text{'failed'} (exit status $exit, terminated by signal $sig)\n$stdout$stderr";
2529
} else {
2530
return "$lang_text{'search'} $lang_text{'failed'} (exit status $exit)\n$stdout$stderr";
2531
}
2532
}
2533
2534
$stdout=~s|^\./||igm;
2535
open(CACHE, ">$cachefile");
2536
print CACHE $metainfo, "\n", $stdout;
2537
close(CACHE);
2538
@{$r_list}=split(/\n/, $stdout);
2539
2540
} else {
2541
my @result;
2542
open(CACHE, $cachefile);
2543
$_=<CACHE>;
2544
while (<CACHE>) {
2545
chomp;
2546
push (@{$r_list}, $_);
2547
}
2548
close(CACHE);
2549
}
2550
2551
ow::filelock::lock($cachefile, LOCK_UN);
2552
2553
return;
2554
}
2555
########## END SHOWDIR ###########################################
2556
2557
########## WD_EXECUTE ############################################
2558
# a wrapper for execute() to handle the dirty work
2559
sub webdisk_execute {
2560
my ($opstr, @cmd)=@_;
2561
my ($stdout, $stderr, $exit, $sig)=ow::execute::execute(@cmd);
2562
2563
# try to conv realpath in stdout/stderr back to vpath
2564
foreach ($stdout, $stderr) {
2565
s!(?:$webdiskrootdir/+|^$webdiskrootdir/*|\s$webdiskrootdir/*)! /!g;
2566
s!^\s*!!; s!/+!/!g;
2567
}
2568
2569
my $opresult;
2570
if ($exit||$sig) {
2571
$opresult=$lang_text{'failed'};
2572
} else {
2573
$opresult=$lang_text{'succeeded'};
2574
writelog("webdisk execute - ".join(' ', @cmd));
2575
writehistory("webdisk execute - ".join(' ', @cmd));
2576
}
2577
if ($sig) {
2578
return "$opstr $opresult (exit status $exit, terminated by signal $sig)\n$stdout$stderr";
2579
} else {
2580
return "$opstr $opresult (exit status $exit)\n$stdout$stderr";
2581
}
2582
}
2583
########## END WD_EXECUTE ########################################
2584
2585
########## FINDICON ##############################################
2586
sub findicon {
2587
my ($fname, $ftype, $is_txt, $os)=@_;
2588
2589
return ("dir.gif") if ($ftype eq "d");
2590
return ("sys.gif") if ($ftype eq "u");
2591
2592
$_=lc($fname);
2593
2594
return("cert.gif") if ( /\.(ce?rt|cer|ssl)$/ );
2595
return("help.gif") if ( /\.(hlp|man|cat|info)$/ );
2596
return("pdf.gif") if ( /\.(fdf|pdf)$/ );
2597
return("html.gif") if ( /\.(shtml|html?|xml|sgml|wmls?)$/ );
2598
return("txt.gif") if ( /\.te?xt$/ );
2599
2600
if ($is_txt) {
2601
return("css.gif") if ( /\.(css|jsp?|aspx?|php[34]?|xslt?|vb[se]|ws[cf]|wrl|vrml)$/ );
2602
return("ini.gif") if ( /\.(ini|inf|conf|cf|config)$/ || /^\..*rc$/ );
2603
return("mail.gif") if ( /\.(msg|elm)$/ );
2604
return("ps.gif") if ( /\.(ps|eps)$/ );
2605
return("txt.gif");
2606
} else {
2607
return("audio.gif") if (/\.(mid[is]?|mod|au|cda|aif[fc]?|voc|wav|snd)$/ );
2608
return("chm.gif") if ( /\.chm$/ );
2609
return("doc.gif") if ( /\.(do[ct]|rtf|wri)$/ );
2610
return("exe.gif") if ( /\.(exe|com|dll)$/ );
2611
return("font.gif") if ( /\.fon$/ );
2612
return("graph.gif") if ( /\.(jpe?g|gif|png|bmp|p[nbgp]m|pc[xt]|pi[cx]|psp|dcx|kdc|tiff?|ico|x[bp]m|img)$/);
2613
return("mdb.gif") if ( /\.(md[bentz]|ma[fmq])$/ );
2614
return("mp3.gif") if ( /\.(m3u|mp[32]|mpga)$/ );
2615
return("ppt.gif") if ( /\.(pp[at]|pot)$/ );
2616
return("rm.gif") if ( /\.(r[fampv]|ram)$/ );
2617
return("stream.gif") if ( /\.(wmv|wvx|as[fx])$/ );
2618
return("ttf.gif") if ( /\.tt[cf]$/ );
2619
return("video.gif") if ( /\.(avi|mov|dat|mpe?g)$/ );
2620
return("xls.gif") if ( /\.xl[abcdmst]$/ );
2621
return("zip.gif") if ( /\.(zip|tar|t?g?z|tbz|bz2?|rar|lzh|arj|bhx|hqx|jar|tne?f)$/ );
2622
2623
return("file".lc($1).".gif") if ( $os =~ /(bsd|linux|solaris)/i );
2624
return("file.gif");
2625
}
2626
}
2627
########## END FINDICON ##########################################
2628
2629
########## IS_QUOTA_AVAILABLE ####################################
2630
sub is_quota_available {
2631
my $writesize=$_[0];
2632
if ($quotalimit>0 && $quotausage+$writesize>$quotalimit) {
2633
$quotausage=(ow::quota::get_usage_limit(\%config, $user, $homedir, 1))[2];
2634
return 0 if ($quotausage+$writesize>$quotalimit);
2635
}
2636
return 1;
2637
}
2638
########## END IS_QUOTA_AVAILABLE ################################
2639