forked from Alanaktion/MCHostPanel
-
Notifications
You must be signed in to change notification settings - Fork 0
/
files.php
286 lines (245 loc) · 9.3 KB
/
files.php
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
<?php
require_once 'inc/lib.php';
session_start();
if (empty($_SESSION['user']) || !$user = user_info($_SESSION['user'])) {
// Not logged in, redirect to login page
header('Location: .');
exit('Not Authorized');
}
?><!doctype html>
<html>
<head>
<title>File Manager | MCHostPanel</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="css/bootstrap.min.css">
<link rel="stylesheet" href="css/bootstrap-responsive.min.css">
<link rel="stylesheet" href="css/smooth.css" id="smooth-css">
<link rel="stylesheet" href="css/style.css">
<meta name="author" content="Alan Hardman <[email protected]>">
<script src="js/jquery-1.7.2.min.js"></script>
<script src="js/bootstrap.min.js"></script>
<script type="text/javascript">
$(document).ready(function () {
// Directory tree item click
$('#dirtree').on('click', 'a', function () {
// Adjust styles
$('#dirtree a').parents('li').removeClass('active');
$('#dirtree a i').addClass('icon-folder-close').removeClass('icon-folder-open');
$(this).parents('li').addClass('active');
$(this).children('i').removeClass('icon-folder-close').addClass('icon-folder-open');
// Load directory
loaddir($(this).attr('href'));
// Prevent navigation
return false;
});
// File list item click
$('#filelist').on('click', 'a', function (e) {
// If not holding Ctrl or Shift, clear selection
if (!e.ctrlKey && !e.shiftKey)
$('#filelist a').parents('li').removeClass('active');
// Add or remove from selection
$(this).parents('li').toggleClass('active');
// Enable/disable Edti and Delete buttons
if ($('#filelist li.active').length == 1) {
$('#btn-delete,#btn-edit,#btn-rename,#btn-dl,#btn-view').prop('disabled', false);
} else if ($('#filelist li.active').length > 1) {
$('#btn-delete').prop('disabled', false);
$('#btn-edit,#btn-rename,#btn-dl,#btn-view').prop('disabled', true);
} else {
$('#btn-delete,#btn-edit,#btn-rename,#btn-dl,#btn-view').prop('disabled', true);
}
// Prevent navigation
return false;
});
// File list item double click
$('#filelist').on('dblclick', 'a', function () {
// Load directory
if ($(this).data('type') == 'dir')
loaddir($(this).attr('href'));
// Open file
if ($(this).data('type') == 'file')
window.location = 'edit.php?file=' + encodeURIComponent($(this).attr('href'));
});
// Clear selection on Esc
$(document).on('keyup', function (e) {
if (e.which == 27 || e.keyCode == 27 || e.charCode == 27) {
$('#filelist li.active').removeClass('active');
$('#btn-delete,#btn-edit,#btn-rename,#btn-dl,#btn-view').prop('disabled', true);
}
});
// Add delete button handler
$('#btn-delete').click(function () {
// Get files
window.selectedfiles = [];
$('#filelist li.active').each(function () {
window.selectedfiles.push($(this).children('a').attr('href'));
});
// Delete if confirmed
if (confirm('Are you sure you want to delete the selected files?')) {
$.post('ajax.php', {
req: 'delete',
files: window.selectedfiles
},function (data) {
loaddir(window.lastdir);
}).error(function () {
alert('There was an error deleting your files.');
});
}
});
// Add edit button handler
$('#btn-edit').click(function () {
window.location = 'edit.php?file=' + encodeURIComponent($('#filelist li.active a').attr('href'));
});
// Add rename button handler
$('#btn-rename').click(function () {
newname = prompt('Enter a new name for the file:', basename($('#filelist li.active a').attr('href')));
if (newname) {
$.post('ajax.php', {
req: 'rename',
path: $('#filelist li.active a').attr('href'),
newname: newname
},function (data) {
loaddir(window.lastdir);
}).error(function () {
alert('There was an error deleting your files.');
});
}
});
// Add view button handler
$('#btn-view').click(function () {
window.open('download.php?dl=0&file=' + encodeURIComponent($('#filelist li.active a').attr('href')));
});
// Add download button handler
$('#btn-dl').click(function () {
window.open('download.php?dl=1&file=' + encodeURIComponent($('#filelist li.active a').attr('href')));
});
// Add upload button handler
$('#btn-upload').click(function () {
$('#modal-upload').modal('show');
});
// Generate button tooltips
$('button.ht').tooltip();
// Load requested directory
loaddir('<?php echo $_GET["dir"] ? $_GET["dir"] : '/'; ?>');
});
function loaddir(dir) {
window.lastdir = dir;
// Clear the file list
$('#filelist').empty().addClass('loading');
$('#btn-delete,#btn-edit,#btn-rename,#btn-dl,#btn-view').prop('disabled', true);
$('#dirtree li:gt(2)').remove();
// Load the directory contents
$.post('ajax.php', {
req: 'dir',
dir: dir
},function (data) {
// Calculate path components
var lvl_array = window.lastdir.replace(/\/$/, '').split('/');
// Add the header breadcrumbs
$('#path').empty();
var lvl_current = '/';
for (var i = 0; i < lvl_array.length; i++) {
if (i) {
lvl_current += lvl_array[i] + '/';
$('#path').append('<button type="button" class="btn" onclick="loaddir(\'' + lvl_current + '\')">' + lvl_array[i] + '</button>');
} else
$('#path').append('<button type="button" class="btn" onclick="loaddir(\'/\')"><i class="icon-home"></i></button>');
}
// Add directory tree nodes
var dirtree = '';
//for(var i; i < lvl_count - 1; i++)
//dirtree+= '<li><a href="'+window.lastdir.replace(/\/$/,'')+'/'+lvl_array[i]+'"><i class="icon-folder-close"></i> '+lvl_array[i]+'</a></li>';
// Add items to the directory tree and file list
var filelist = '';
for (var d in data.dirs) {
dirtree += '<li><a href="' + window.lastdir.replace(/\/$/, '') + '/' + data.dirs[d] + '"><i class="icon-folder-close"></i> ' + data.dirs[d] + '</a></li>';
//filelist+='<li><a href="'+window.lastdir.replace(/\/$/,'')+'/'+data.dirs[d]+'" data-type="dir"><i class="icon-folder-close"></i> '+data.dirs[d]+'</a></li>';
}
for (var f in data.files) {
filelist += '<li><a href="' + window.lastdir.replace(/\/$/, '') + '/' + data.files[f] + '" data-type="file"><i class="icon-file"></i> ' + data.files[f] + ' <small class="pull-right">' + size_format(data.sizes[f]) + '</small><div class="clearfix"></div></a></li>';
}
// Add directory contents to document
$('#dirtree').append(dirtree);
$('#filelist').removeClass('loading').html(filelist);
// Select current directory
$('#dirtree li.active').removeClass('active');
//$('#dirtree [href="'+window.lastdir+'"]').addClass('active');
if (window.lastdir == '/')
$('#home').addClass('active');
// Change upload directory
$('#iframe-upload').attr('src', 'uploader.php?dir=' + encodeURIComponent(window.lastdir));
}, 'json').error(function () {
try {
console.log('Error loading directory "' + window.lastdir + '"');
} catch (ex) {}
});
}
function size_format(s) {
if (s >= 1073741824)
s = Math.round(s / 1073741824 * 100) / 100 + ' GB';
else if (s >= 1048576)
s = Math.round(s / 1048576 * 100) / 100 + ' MB';
else if (s >= 1024)
s = Math.round(s / 1024 * 100) / 100 + ' KB';
else
s = s + ' bytes';
return s;
}
function basename(path, suffix) {
var b = path.replace(/^.*[\/\\]/g, '');
if (typeof(suffix) == 'string' && b.substr(b.length - suffix.length) == suffix)
b = b.substr(0, b.length - suffix.length);
return b;
}
</script>
</head>
<body>
<?php require 'inc/top.php'; ?>
<div class="tab-content">
<div class="tab-pane active">
<div class="container-fluid">
<div class="row-fluid">
<div class="span3">
<div class="well sidebar-nav">
<ul class="nav nav-list" id="dirtree">
<li class="nav-header">Directories</li>
<li class="active" id="home"><a href="/"><span class="icon-home"></span> Home</a></li>
<li class="divider"></li>
</ul>
</div>
</div>
<div class="span9">
<div class="well">
<div class="row-fluid">
<p class="span6 btn-group" id="path"></p>
<div class="span6 btn-toolbar" style="margin-top:0;text-align:right;">
<div class="btn-group">
<button id="btn-delete" type="button" class="btn ht" title="Delete" disabled><i class="icon-trash"></i></button>
<button id="btn-edit" type="button" class="btn ht" title="Edit" disabled><i class="icon-edit"></i></button>
<button id="btn-rename" type="button" class="btn ht" title="Rename" disabled><i class="icon-repeat"></i></button>
</div>
<div class="btn-group">
<button id="btn-view" type="button" class="btn ht" title="View" disabled><i class="icon-picture"></i></button>
<button id="btn-dl" type="button" class="btn ht" title="Download" disabled><i class="icon-download"></i></button>
</div>
<button id="btn-upload" type="button" class="btn btn-primary"><i class="icon-upload icon-white"></i> Upload</button>
</div>
</div>
<ul class="nav nav-list" id="filelist"></ul>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="modal fade hide" id="modal-upload" tabindex="-1" role="dialog" aria-labelledby="lbl-upload" aria-hidden="true">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h3 id="lbl-upload">Upload Files</h3>
</div>
<div class="modal-body">
<iframe src="uploader.php" id="iframe-upload" border="0" frameborder="0" style="width:100%;height:125px;" allowtransparency="true"></iframe>
</div>
</div>
</body>
</html>