9
9
$ act = $ pData ->act ?? '' ;
10
10
if ($ act == 'del ' ) {
11
11
$ path = $ pData ->path ?? '' ;
12
- if (!empty ($ path ) and file_exists (DIR_ROOT . $ path )) {
13
- ajaxDone (removeDirFile (DIR_ROOT . $ path ));
12
+ if (!empty ($ path ) and file_exists (PATH_ROOT . $ path )) {
13
+ ajaxDone (removeDirFile (PATH_ROOT . $ path ));
14
14
} else {
15
15
ajaxDone (false );
16
16
}
17
17
} else if ($ act == 'zip ' ) {
18
18
$ path = $ pData ->path ?? '' ;
19
- if (!empty ($ path ) and file_exists (DIR_ROOT . $ path )) {
20
- ajaxDone (zipDir (DIR_ROOT . $ path ));
19
+ if (!empty ($ path ) and file_exists (PATH_ROOT . $ path )) {
20
+ ajaxDone (zipDir (PATH_ROOT . $ path ));
21
21
} else {
22
22
ajaxDone (false );
23
23
}
24
+ } else if ($ act == 'addFile ' ) {
25
+ $ directory = $ pData ->dir ?? '' ;
26
+ $ name = $ pData ->name ?? '' ;
27
+ if (empty ($ name )) {
28
+ ajaxDone (false , "File name is empty! " );
29
+ } if (file_exists (PATH_ROOT . $ directory .$ name )) {
30
+ ajaxDone (false , "Duplicated file name! " );
31
+ } else {
32
+ ajaxDone (fopen (PATH_ROOT . $ directory .$ name , "w " )!==false );
33
+ }
34
+ } else if ($ act == 'addFolder ' ) {
35
+ $ directory = $ pData ->dir ?? '' ;
36
+ $ name = $ pData ->name ?? '' ;
37
+ if (empty ($ name )) {
38
+ ajaxDone (false , "Folder name is empty! " );
39
+ } if (file_exists (PATH_ROOT . $ directory .$ name )) {
40
+ ajaxDone (false , "Duplicated folder name! " );
41
+ } else {
42
+ ajaxDone (mkdir (PATH_ROOT . $ directory .$ name , 0777 , true ), "w " );
43
+ }
24
44
}
25
45
26
46
ajaxInvalid ();
47
+ } else if (isset ($ _POST ['upload ' ])) {
48
+ $ path = $ _POST ['path ' ];
49
+ foreach ($ _FILES as $ file ) {
50
+ @move_uploaded_file ($ file ["tmp_name " ], PATH_ROOT . $ path . $ file ["name " ]);
51
+ }
52
+ ajaxDone (true );
27
53
}
28
54
29
55
36
62
if (@$ _GET ['act ' ] == 'download ' ) {
37
63
if ($ _GET ['targetf ' ] ?? false ) {
38
64
$ targetFile = $ _GET ['targetf ' ];
39
- if (file_exists (DIR_ROOT . $ directory . $ targetFile )) {
65
+ if (file_exists (PATH_ROOT . $ directory . $ targetFile )) {
40
66
header ("Content-Type:application/octet-stream " );
41
67
header ("Accept-Ranges: bytes " );
42
- header ("Content-Length: " . filesize (DIR_ROOT . $ directory . $ targetFile ));
68
+ header ("Content-Length: " . filesize (PATH_ROOT . $ directory . $ targetFile ));
43
69
header ("Content-Disposition: attachment; filename= " . $ targetFile );
44
- readfile (DIR_ROOT . $ directory . $ targetFile );
70
+ readfile (PATH_ROOT . $ directory . $ targetFile );
45
71
exit ;
46
72
}
47
73
} else if ($ _GET ['targetd ' ] ?? false ) {
50
76
$ download = $ targetDir . '.zip ' ;
51
77
$ zip ->open ($ download , ZipArchive::CREATE );
52
78
53
- addDirToZip ($ zip , $ targetDir , DIR_ROOT . $ directory . $ targetDir );
79
+ addDirToZip ($ zip , $ targetDir , PATH_ROOT . $ directory . $ targetDir );
54
80
55
81
$ zip ->close ();
56
82
header ('Content-Type: application/zip ' );
62
88
exit ("<script>window.close()</script> " );
63
89
}
64
90
65
-
91
+ $ isInProjectPath = strpos (PATH_PROJECT , PATH_ROOT . $ directory ) !== false && strlen ($ directory ) > 0 ;
92
+ $ isInRootDir = PATH_ROOT . $ directory == PATH_ROOT ? true : false ;
66
93
67
94
$ dirs_list = "" ;
68
95
$ files_list = "" ;
69
- if ($ files = array_diff (scandir (DIR_ROOT . $ directory ), ['. ' , '.. ' ])) {
96
+ if ($ files = array_diff (scandir (PATH_ROOT . $ directory ), ['. ' , '.. ' ])) {
70
97
$ index = 0 ;
71
98
foreach ($ files as $ entry ) {
72
99
if ($ entry != ". " && $ entry != ".. " ) {
73
- $ path = DIR_ROOT . $ directory . $ entry ;
100
+ $ path = PATH_ROOT . $ directory . $ entry ;
74
101
// print decoct(fileperms($file) & 0777);
75
102
$ stat = stat ($ path );
76
103
if (is_dir ($ path )) {
85
112
<td> ' . getPermDescription ($ path ) . '</td>
86
113
<td> '
87
114
. (true ? '<button type="button" class="btn btn-default btn-sm btn-dirtozip" ng-click="zipDir($event, ' . $ index . ')">Create Zip File</button> ' : ' ' )
88
- . ( is_writable ( $ path) ? ' <input type="button" class="btn btn-danger btn-sm" ng-click="deleteFileDir($event, ' . $ index . ' )" value="Delete" title="Delete without confirmation!"> ' : ' ' ) .
115
+ . makeDeleteButtonForDir ( $ path, $ entry , $ index ) .
89
116
'</td>
90
117
</tr> ' ;
91
118
} else {
100
127
<td> ' . getPermDescription ($ path ) . '</td>
101
128
<td> '
102
129
. (true ? '<input type="button" class="btn btn-default btn-sm" ng-click="downloadFile($event, ' . $ index . ')" value="Download"> ' : ' ' )
103
- . ( is_writable ( $ path) ? ' <input type="button" class="btn btn-danger btn-sm" ng-click="deleteFileDir($event, ' . $ index . ' )" value="Delete"> ' : ' ' ) .
130
+ . makeDeleteButtonForFile ( $ path, $ entry , $ index ) .
104
131
'</td>
105
132
</tr> ' ;
106
133
}
@@ -121,20 +148,54 @@ function getPermDescription($path)
121
148
return implode ('+ ' , $ desc );
122
149
}
123
150
151
+ function makeDeleteButtonForDir ($ path , $ entry , $ index )
152
+ {
153
+ global $ isInProjectPath , $ isInRootDir ;
154
+ if (!is_writable ($ path )) {
155
+ return '<input type="button" class="btn btn-danger btn-sm" value="Delete" title="Permission Denied!" disabled="disabled"> ' ;
156
+ } else if ($ isInProjectPath || ($ isInRootDir && $ entry == DIR_PROJECT )) {
157
+ return '<input type="button" class="btn btn-danger btn-sm" value="Delete" title="Not Allowed!" disabled="disabled"> ' ;
158
+ }
159
+ return '<input type="button" class="btn btn-danger btn-sm" ng-click="deleteFileDir($event, ' . $ index . ')" value="Delete" title="Delete without confirmation!"> ' ;
160
+ }
161
+
162
+ function makeDeleteButtonForFile ($ path , $ entry , $ index )
163
+ {
164
+ global $ project_root_files , $ isInProjectPath , $ isInRootDir ;
165
+ if (!is_writable ($ path )) {
166
+ return '<input type="button" class="btn btn-danger btn-sm" value="Delete" title="Permission Denied!" disabled="disabled"> ' ;
167
+ } else if ($ isInProjectPath || ($ isInRootDir && in_array ($ entry , $ project_root_files ))) {
168
+ return '<input type="button" class="btn btn-danger btn-sm" value="Delete" title="Not Allowed!" disabled="disabled"> ' ;
169
+ }
170
+ return '<input type="button" class="btn btn-danger btn-sm" ng-click="deleteFileDir($event, ' . $ index . ')" value="Delete" title="Delete without confirmation!"> ' ;
171
+ }
172
+
124
173
125
174
126
175
getHeader ();
127
176
?>
128
-
129
177
<!-- Page Content -->
130
178
<div class="container">
131
- <div class="row">
179
+ <div class="row" ng-app="theApp" >
132
180
<div class="col-lg-12">
133
181
<h1 class="page-header">Your Host <br><span class="details"><?php print getWebServerDetails (); ?>
134
182
</h1>
135
183
<?php
136
184
showBreadCrumb ($ directory );
137
185
?>
186
+ <div class="file-upload">
187
+ <ul ng-controller="addNewCtl">
188
+ <li ng-click="showUploadBox($event)"><span class="glyphicon glyphicon-upload"></span> Upload</li>
189
+ <li ng-click="addNewFile($event)"><span class="glyphicon glyphicon-plus"></span> <span class="m-hidden-xs">New </span>File</li>
190
+ <li ng-click="addNewFolder($event)"><span class="glyphicon glyphicon-plus"></span> <span class="m-hidden-xs">New </span>Folder</li>
191
+ <li>
192
+ <input style="display:none" type="text" ng-model="newfileName" id="newfileName" name="newfileName" placeholder="File/Folder Name">
193
+ <input style="display:none" type="button" ng-click="addNewFileFolderHide($event)" class="btn btn-default btn-xs m-hidden-xs" value=" Cancel ">
194
+ <input style="display:none" type="button" ng-click="addNewFileFolder($event)" class="btn btn-primary btn-xs" value=" Add ">
195
+ </li>
196
+ </ul>
197
+ <upload id="filedrop" to="index.php"></upload>
198
+ </div>
138
199
<div class="table-responsive" style="border: 1px solid #efefef;">
139
200
<table class="table filestable">
140
201
<thead>
@@ -143,10 +204,10 @@ function getPermDescription($path)
143
204
<th>Size</th>
144
205
<th>Modified</th>
145
206
<th>Permissions</th>
146
- <th>Actions</th>
207
+ <th style="min-width: 180px;" >Actions</th>
147
208
</tr>
148
209
</thead>
149
- <tbody ng-app="filesApp" ng- controller="filesCtl">
210
+ <tbody ng-controller="filesCtl">
150
211
<?php
151
212
if (empty ($ dirs_list ) and empty ($ files_list )) {
152
213
print '<tr>
@@ -267,91 +328,9 @@ function getMenuPosition(mouse, direction, scrollDir) {
267
328
</script>
268
329
<script>
269
330
var rootUrl = "<?php print URL_ROOT ; ?> ";
270
- angular.module('filesApp', [])
271
- .controller('filesCtl', function($scope, $http, $element, $timeout, $window) {
272
- $scope.downloadFile = function(event, id) {
273
- var trItem = $element.find('#tr-' + id);
274
- var path = trItem.attr("data-href");
275
- var file = trItem.attr("data-file");
276
- var url = window.location.href;
277
- url += (url.search('/?') > 0 ? '&' : '?');
278
-
279
- $window.open(url + "act=download&targetf=" + file, '_blank');
280
- $window.focus();
281
- }
282
- $scope.zipDir = function(event, id) {
283
- var zipBtn = angular.element(event.target);
284
- zipBtn.html('<span class="spinner-grow spinner-grow-sm" style="margin:0 5px 0 -2px;" role="status" aria-hidden="true"></span> Zipping ...');
285
- angular.element(".btn-dirtozip").attr("disabled", true);
286
-
287
-
288
- var trItem = $element.find('#tr-' + id);
289
- var path = trItem.attr("data-href");
290
-
291
- $http({
292
- method: 'POST',
293
- url: "index.php",
294
- headers: {
295
- 'Content-Type': 'application/x-www-form-urlencoded'
296
- },
297
- data: {
298
- act: 'zip',
299
- path: path
300
- }
301
- }).then(function successCallback(response) {
302
- console.log(response.data);
303
- if (response.data.status === true) {
304
- zipBtn.html('Create Zip File');
305
- angular.element(".btn-dirtozip").attr("disabled", false);
306
-
307
- $timeout(function() {
308
- $window.location.reload();
309
- }, 250);
310
- } else {
311
- trItem.addClass("dangerHighlight");
312
- $timeout(function() {
313
- trItem.addClass("highlightOut");
314
- }, 1000);
315
- }
316
-
317
- }, function errorCallback(response) {
318
-
319
- });
320
- }
321
- $scope.deleteFileDir = function(event, id) {
322
- var trItem = $element.find('#tr-' + id);
323
- var path = trItem.attr("data-href");
324
- trItem.removeClass();
325
- $http({
326
- method: 'DELETE',
327
- url: "index.php",
328
- headers: {
329
- 'Content-Type': 'application/x-www-form-urlencoded'
330
- },
331
- data: {
332
- act: 'del',
333
- path: path
334
- }
335
- }).then(function successCallback(response) {
336
- if (response.data.status === true) {
337
- trItem.hide(250);
338
- $timeout(function() {
339
- trItem.remove();
340
- }, 250);
341
- } else {
342
- trItem.addClass("dangerHighlight");
343
- $timeout(function() {
344
- trItem.addClass("highlightOut");
345
- }, 1000);
346
- }
347
-
348
- }, function errorCallback(response) {
349
-
350
- });
351
- }
352
-
353
- });
331
+ var directory = "<?php print $ directory ; ?> ";
354
332
</script>
333
+ <script src="theme/assets/js/app.js"></script>
355
334
<?php
356
335
getFooter ();
357
336
?>
0 commit comments