[go: up one dir, main page]

Menu

[r32]: / trunk / index.php  Maximize  Restore  History

Download this file

448 lines (365 with data), 13.3 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
<?php
/**
* $Id$
*/
ini_set('error_reporting',E_ALL);
ini_set('display_errors','1');
if (! file_exists('config.php')) {
header('Location:check.php');
exit;
}
define('WSVER','$Id$');
require_once('config-core.php');
require_once('session.php');
require_once('functions-inc.php');
require_once('vfs-'.$conf['vfstype'].'.php');
if ($conf['enable_logging'] && ($conf['logfile']=='syslog')) {
openlog('oliver',LOG_PID|LOG_PERROR, $conf['syslog_facility']);
}
$s = new OliverSession($conf);
$conf = $s->getConf();
/*
* Pseudo NLS stuff - messy - very messy
* Load the default language, in case a translation doesn't exist in
* the language file.
*/
require_once('lang/'.$conf['default_lang'].'.php');
if (file_exists('lang/'.$conf['lang'].'.php')) {
require_once('lang/'.$conf['lang'].'.php');
}
$_SESSION['language'] = $conf['lang'];
// Create vfs object - also connects
$wvfs = eval('return new oliver_vfs_'.$conf['vfstype'].'($conf);');
if (! $s->sessionValid($wvfs)) {
require_once('header-inc.php');
$errmsg = $s->getParam('error_message');
require_once('loginform-inc.php');
require_once('footer-inc.php');
die();
}
// At this point we're logged in and everything's groovy.
$_SESSION['atime'] = time();
// Set up some useful variables
$ip = $s->getParam('ip');
$pwd = $s->getParam('pwd');
$act = $s->getParam('act');
$mode = $s->getParam('mode');
$perms = $s->getParam('perms');
$file = urldecode($s->getParam('file'));
$fileactions = $s->getParam('fileactions');
$sessionID = $s->getParam('sessionID');
/*
* First we make sure this isn't a "utility" request
* if it is then display the utility
*/
if ((! empty($_REQUEST['utilchmod'])) && ($file || count($fileactions))) {
require_once('chmod.php');
exit;
} elseif ((! empty($_REQUEST['utilchmod']))) {
$error_message = $conf['nls']['select_files_first'];
}
// Next, make sure we're in the right place
if (empty($pwd)) {
$pwd = $wvfs->get_pwd();
} else {
$pwd = urldecode($pwd);
$wvfs->chdir($pwd);
}
// Let's see what action we're being asked to do
switch ($act) {
case 'chdir':
if (! preg_match('/^\//',$file)) {
$file = urldecode($pwd).'/'.$file;
}
if (! ($wvfs->chdir($file))) {
$error_message = "Can't Open Folder";
}
break;
case 'cdup':
$wvfs->cdup();
break;
case 'getfile':
$mimetype = $s->getParam('mimetype');
if ($s->getParam('download')) {
$mimetype = 'application/octet-stream';
}
$mimetype = $mimetype ? $mimetype : 'application/octet-stream';
$local_file = "ftp_cache/$sessionID.$ip.get";
$wvfs->showFile($file, $mimetype, $local_file);
break;
case 'logout':
session_destroy();
session_regenerate_id(true);
header('Location:./');
die;
break;
}
$pwd = $wvfs->get_pwd();
if (!empty($_POST['actup'])) {
$tmpFilename = $s->getParam('tmpFilename');
$origFilename = $s->getParam('origFilename');
if (is_uploaded_file($tmpFilename)) {
$wvfs->put($origFilename,$tmpFilename, FTP_BINARY);
uploadStatus('Completed',$origFilename);
} else {
$error_message .= $conf['nls']['error'].$conf['nls']['upload'];
uploadStatus('Error',$origFilename);
}
exit;
}
require_once('header-inc.php');
if (isset($_POST['actdel'])) {
$deleted=0;
foreach($fileactions as $key => $value) {
$tobedeleted = urldecode($pwd)."/".urldecode($key);
if ($wvfs->delete($tobedeleted)) {
$deleted++;
} else {
if ($wvfs->rmdir($tobedeleted)) {
$deleted++;
} else {
$error_message.="$key: ".
$conf['nls']['delete_failed']."\\n";
}
}
}
$error_message .= "\\n$deleted ".$conf['nls']['files_deleted']."\\n";
} elseif (($conf['enable_chmod']) &&
(!empty($_POST['actchmod'])) && $perms && $fileactions) {
foreach($fileactions as $key => $value) {
$key=urldecode($key);
if (! ($wvfs->chmod($key,decoct($perms)))) {
$error_message.=$conf['nls']['cant_change_perms'].
" $key\\n";
} else {
$error_message.=$conf['nls']['perms_changed'].
" $key\\n";
}
}
} elseif (!empty($_POST['actmkdir'])) {
if (! $wvfs->mkdir($s->getParam('newdir'))) {
$error_message.=$conf['nls']['dir_create_failed'].
' '.$s->getParam('newdir');
} else {
$error_message.=$conf['nls']['dir_created'].
' '.$s->getParam('newdir');
}
}
if (($sessionID) && ($s->getParam('showlisting'))) {
echo '<p><em>'.$conf['nls']['path']."</em> $pwd</p>";
}
// Display button bar
echo '<div class="buttonbar">';
echo '<a class="button" style="background-image:url(graphics/parent.gif)" href="',$_SERVER['PHP_SELF'],'?act=cdup&amp;file=';
echo rawurlencode(rawurlencode($file)),"&amp;pwd=$pwd",'">';
echo $conf['nls']['up'],'</a>';
echo '<a class="button" style="background-image:url(graphics/home.gif)" href="',$_SERVER['PHP_SELF'],'?sessionID=',$sessionID,'">';
echo $conf['nls']['home'],'</a>';
if (sizeof($conf['roots'])>0) {
foreach($conf['roots'] as $key => $value) {
echo '<a class="button" style="background-image:url(graphics/gollem.gif)" href="',$_SERVER['PHP_SELF'],"?pwd=$value",'">';
echo $key,'</a>';
}
}
echo '<a class="button" style="background-image:url(graphics/logout.gif)" href="',$_SERVER['PHP_SELF'],"?act=logout",'">';
echo $conf['nls']['logout'],'</a>';
echo '<br />&nbsp;</div>';
// Get a list of files
$list = array();
$list = $wvfs->ls($pwd);
if ($conf['rawlistdebug'] && function_exists('base64_encode')) {
echo '<h2>Copy this block of text and send it to the developers:</h2><pre>';
echo preg_replace('/(.{80})/',"$1\n",base64_encode(serialize($list)));
echo '</pre>';
exit;
}
if (! is_array($list)) {
$list=array();
}
// Remove the files in the veto list
$pa=array();
foreach($list as $key => $dirline) {
//print (":$dirline:<br>\n");
// Workaround for OS-X and its inventive "total" line
if (preg_match("/^total\s+\d+$/",$dirline)) {continue;}
$fn = $wvfs->getFilename($dirline,0);
if(empty($conf['veto_filenames'][$fn]) && ($fn!=".")) {
array_push($pa,$dirline);
}
}
$i=0;
$n = count($pa) - 1;
/* Error message if it exists */
if ($error==1) {
$error_message = $conf['nls']['cant_create']." \"".urldecode($file)."\"".$conf['nls']['already_exists'];
}
if ($error_message) {
print '<script language="JavaScript">';
print "<!--\n";
print "alert('$error_message');\n";
print "//-->\n";
print "</script>\n";
print "<noscript>\n";
print '<p><b>Status:'.preg_replace('/[^\w\s]n/','<br>',$error_message);
print "</b></p>\n";
print "</noscript>\n";
}
// Create unique ID for progress bar (even if we're not using it)
$uploadid = md5(microtime() . rand());
// Uncomment the next line to debug progress bar
//$uploadid = 1;
echo '<form name="indexform" method="post" enctype="multipart/form-data" action="',$_SERVER['PHP_SELF'],'?pwd=',$pwd,'">';
echo '<input type="hidden" name="UPLOAD_IDENTIFIER" value="',$uploadid,'" />';
echo '<input type="hidden" name="sessionID" value="',$sessionID,'">',"\n";
echo '<table class="filelist">';
$newdirname=$conf['nls']['new_directory'];
$newdirid='';
if ($n >= 0) {
echo "<tr class=\"tablecell\">\n<td><!-- <input type=checkbox name=tog >\"javascript:toggle();\"> -->&nbsp;</td>\n";
echo "<td colspan=\"2\">".$conf['nls']['file_name']."</td>\n";
echo "<td>".$conf['nls']['owner']."</td>\n";
echo "<td>".$conf['nls']['permissions']."</td>\n";
echo "<td>".$conf['nls']['last_mod']."</td>\n";
echo "<td>".$conf['nls']['size']."</td>\n";
echo "<td>&nbsp;</td>\n";
echo "</tr>\n";
// display each file on a line of its own
for ($i = 0; $i <= $n; $i++) {
$pa[$i] = trim($pa[$i]);
$cor=($i%2) ? "even" : "odd";
echo "<tr class=\"$cor\">\n";
// tick box
echo '<td class="tool">';
echo '<input type="checkbox" name="cb['.
urlencode($wvfs->getFilename($pa[$i],0)).']">';
echo "</td>\n";
// icon
echo '<td class="tool">';
$filetype = $wvfs->getFileType($pa[$i]);
if ( $filetype == 'd' || $filetype == 'l') {
echo $wvfs->getFileTypeIcon($pa[$i]);
} else {
$fname = $wvfs->getFilename($pa[$i],0);
echo '<a target="blank" href="',$_SERVER['PHP_SELF'],'?sessionID=',$sessionID,'&amp;act=getfile&amp;pwd=',rawurlencode($pwd);
echo '&amp;mimetype=',rawurlencode($wvfs->getMIMEType($pa[$i])),'&amp;file=',rawurlencode($fname),'&amp;d=1">';
echo $wvfs->getFileTypeIcon($pa[$i]),'</a>';
}
echo '</td>';
// filename
echo '<td>';
$filetype = $wvfs->getFileType($pa[$i]);
if ( $filetype == 'd' || $filetype == 'l') {
$fname = urlencode($wvfs->getFilename($pa[$i],2));
if ($fname == urlencode($newdirname.$newdirid)) {
$newdirid++;
}
echo '<a href="',$_SERVER['PHP_SELF'],'?sessionID=',$sessionID,'&amp;act=chdir&amp;pwd=',urlencode($pwd),'&amp;file=',rawurlencode($fname);
} else {
$fname = urlencode($wvfs->getFilename($pa[$i],0));
echo '<a target="new" href="',$_SERVER['PHP_SELF'],'?sessionID=',$sessionID,'&amp;act=getfile&amp;pwd=';
echo urlencode($pwd),'&amp;mimetype=',urlencode($wvfs->getMIMEType($pa[$i])),'&amp;file=',rawurlencode($fname);
}
echo '">'.$wvfs->getFilename($pa[$i],1).'</a>';
echo "</td>\n";
// owner
echo "<td>";
echo $wvfs->getOwner($pa[$i]);
echo "</td>\n";
// mode
$mode = $wvfs->getFileMode($pa[$i]);
$umode = urlencode($mode);
echo '<td><span class="tt">';
if ($conf['enable_chmod'] ) {
echo '<a href="', $_SERVER['PHP_SELF'], '?pwd=', $pwd ,'&amp;file=',rawurlencode($fname), '&amp;mode=', $umode, '&amp;utilchmod=1">';
echo $mode,'</a>';
} else {
echo $mode;
}
echo '</span></td>';
// lastmod
echo '<td>';
echo $wvfs->getFileDate($pa[$i]);
echo "&nbsp;</td>\n";
// size
echo '<td>';
$tam = $wvfs->size($wvfs->getFilename($pa[$i],0));
echo $wvfs->FileTam($tam);
echo "&nbsp;</td>\n";
// direct link
echo '<td class="tool">';
if ($conf['enable_dlink'] && $filetype != 'd') {
echo '<a href="dl.php?f=',urlencode("$pwd/$fname"),'">';
echo '<img src="graphics/link.png" width="12" height="12" alt="Direct Link"></a>';
} else {
echo '&nbsp;';
}
echo "</td></tr>\n";
}
} else {
echo '<tr class="even">';
echo '<td colspan="3"><center><em>',$conf['nls']['empty_directory'];
echo '</b></center></td>', "</tr>\n";
}
// get the decor right
$cor = ($i%2) ? "even" : "odd";
// suggestion for the name of a new directory
$newdirname .= $newdirid;
// invite the user to create a directory
echo '<tr class="',$cor,'"><td>&nbsp;</td>';
echo '<td class="tool">';
echo '<img src="',$conf['imgdir'],'/dir.gif" alt=""></td>';
echo '<td class="tool" colspan="',($conf['listcols']-2),'"><input type="text" size="20" name="newdir" ';
echo 'value="',$newdirname, '">&nbsp;';
echo '<input type="submit" name="actmkdir" ';
echo ' value="',$conf['nls']['create_new_directory'],'" class="bopt">';
echo '</td></tr>';
if ($conf['uploadprogress']) {
?>
<script type="text/javascript">
var loop = false;
function uploadComplete() {
loop = false;
$('#uploadprogress').hide();
alert('Upload complete');
}
function updateUpload() {
if (!loop) {
return true;
}
$.ajax({ url: "progress.php?i=<?php echo $uploadid ?>",
success: function(data){
$('#uploadprogress').html(data);
}});
setTimeout("updateUpload()",1500);
return true;
}
function startUpload() {
$('#upcontainer').hide();
$('#uploadprogress').html('Upload started. Please wait...');
loop=true;
setTimeout("updateUpload()",100);
if ('<?php echo $uploadid ?>' == 1) {
return false;
} else {
return true;
}
}
</script>
<?php
} else {
echo '<script type="text/javascript">function startUpload {return true;}"';
}
// Buttons!
echo '<tr><td class="topt" colspan="',$conf['listcols'],'">';
if ($conf['enable_chmod']) {
echo '<input class="bopt" type="submit" name="utilchmod" value="',$conf['nls']['change_perms'],'"> | ';
}
echo '<input class="bopt" type="submit" name="actdel" value="',$conf['nls']['delete'],'">';
echo '<br />&nbsp;<br /></form>';
echo '<iframe src="uploader.php?id=',$uploadid,'" scrolling="no" id="upcontainer"></iframe>';
echo '<div id="uploadprogress"></div>';
echo '</tr></table>';
// close our connection
$wvfs->quit();
require_once('footer-inc.php');
?>