· 8 years ago · Aug 07, 2018, 03:02 AM
1var jsonlock,cdir,mcname,mcpath,mcmove;
2
3function basename (path, suffix) {
4 var b = path.replace(/^.*[\/\\]/g, '');
5 if (typeof(suffix) == 'string' && b.substr(b.length-suffix.length) == suffix){
6 b = b.substr(0, b.length-suffix.length);
7 }
8 return b;
9}
10function dirname (path) {
11 return path.replace(/\\/g,'/').replace(/\/[^\/]*\/?$/, '');
12}
13
14function obIsEmpty(o) {
15 for(var i in o){ return false; }
16 return true;
17}
18
19String.prototype.escape = function() {
20 return this.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");
21}
22
23function toggle(umm) {
24 if(umm==0){
25 return 1;
26 }else{
27 return 0;
28 }
29}
30
31function updateFiles(dir){
32 var i, totalhref='', fdir, fname, fsize, fperms, nofiles=0, fbin, finbs, ldisabled, noperms='', lightbox, ffperms, firstpart=false;
33 $("#files_outer").slideUp('slow',function(){
34 $("#files").html('<tr class="loading"><td colspan="4"><img src="_tastydir/images/loading.gif"></td></tr>');
35
36 /* here we assign a random number to a variable called jsonlock... */
37 jsonlock=Math.floor(Math.random()*99999);
38 /* then do the json request */
39 $.getJSON(sn_d+"_tastydir/do.php?d="+dir+"&lock="+jsonlock+"&cb=?", function(data){
40 /* callback forjson request: jsonlock has the json lock from when we initially started the request - we send it to the dir function and it sends it back
41 if the jsonlock var isn't the same as the one above then another request has taken place and we need to stop updating everything
42 because if we do update it we'll get two sets of results on top of each other and that's not cool
43 */
44 cdir=data.cdir.escape();
45 if(jsonlock == data.jsonlock){
46 /* if the result is obsolete we just drop it, otherwise proceed */
47 if(loggedin){
48 ldisabled='class="enabled" ';
49 }else{
50 ldisabled='class="disabled" ';
51 }
52 $("tr.loading").remove();
53 for(i in data.cdirs){
54 totalhref+=data.cdirs[i].escape();
55 if(data.cdirs[i]!='/') totalhref=totalhref+'/';
56 if(firstpart){
57 $("#path").append('<div class="pathpart"><a href="#'+totalhref+'">'+data.cdirs[i].escape()+'<div class="breadcrumb"></div></a></div>');
58 }else{
59 $("#path").html('<div class="pathpart"><a href="#'+totalhref+'">'+data.cdirs[i].escape()+'<div class="breadcrumb"></div></a></div>');
60 }
61 firstpart=true;
62 }
63 if(!obIsEmpty(data.dirs)){
64 for(i in data.dirs){
65 if(data.dirs[i]){
66 fdir=data.dirs[i]['n'];
67 fsize=data.dirs[i]['s'];
68 fperms=data.dirs[i]['p'];
69 ffperms=data.dirs[i]['fp'];
70 if(fperms=='?---------'){
71 noperms=' noperms';
72 }else{
73 noperms='';
74 }
75 }else{
76 fdir='ERROR';
77 fsize='';
78 fperms='';
79 ffperms='';
80 }
81 $("#files")
82 .append( '<tr class="frow'+noperms+'">'+
83 '<td class="fcell folder"><a class="fname folder" href="#'+data.cdir+'/'+fdir+'"><img title="Folder" alt="Folder" src="_tastydir/images/folder.png"><span class="ftitle">'+basename(fdir).escape()+'</span></a></td>'+
84 '<td>'+fsize+'</td>'+
85 '<td><a class="fperms" href="javascript:;" onClick="chmod(\''+fdir+'\',\''+data.cdir+'/'+fdir+'\',\''+fperms+'\');">'+ffperms+'</a></td>'+
86 '<td class="actions">'+
87 '<img '+ldisabled+'onClick="editFolderDialog(\''+fdir+'\',\''+data.cdir+'/'+fdir+'\');" title="Edit" alt="Edit" src="_tastydir/images/page_white_edit.png">'+
88 '<img '+ldisabled+'onClick="deleteFolder(\''+fdir+'\',\''+data.cdir+'/'+fdir+'\');" title="Delete" alt="Delete" src="_tastydir/images/doc_shred.png">'+
89 '</td>'+
90 '</tr>');
91 }
92 }else{
93 nofiles+=1;
94 }
95 if(!obIsEmpty(data.files)){
96 for(i in data.files){
97 if(data.files[i]){
98 fname=data.files[i]['n'];
99 fsize=data.files[i]['s'];
100 fperms=data.files[i]['p'];
101 ffperms=data.files[i]['fp'];
102 ftype=data.files[i]['t'];
103 fbin=data.files[i]['b'];
104 if(fbin=='true' || !loggedin){
105 fbins='class="disabled" ';
106 }else{
107 fbins='class="enabled" ';
108 }
109 if(fperms=='?---------'){
110 noperms=' noperms';
111 }else{
112 noperms='';
113 }
114 if(ftype=='img'){
115 lightbox='href="javascript:;" onClick="lightboxImage(\''+data.cdir+'/'+fname+'\');"';
116 }else{
117 lightbox='href="_tastydir/do.php?download='+data.cdir+'/'+fname+'" target="_blank"';
118 }
119 }else{
120 fname='ERROR';
121 fsize='';
122 fperms='';
123 ffperms='';
124 ftype='';
125 fbin='';
126 fbins='';
127 }
128 $("#files")
129 .append( '<tr class="frow'+noperms+'">'+
130 '<td class="fcell file"><a class="fname file" '+lightbox+'><img title="File" alt="File" src="_tastydir/images/file_'+ftype+'.png"><span class="ftitle">'+basename(fname).escape()+'</span></a></td>'+
131 '<td>'+fsize+'</td>'+
132 '<td><a class="fperms" href="javascript:;" onClick="chmod(\''+fname+'\',\''+data.cdir+'/'+fname+'\',\''+fperms+'\');">'+ffperms+'</a></td>'+
133 '<td class="actions">'+
134 '<img '+fbins+'onClick="editFileDialog(\''+fname+'\',\''+data.cdir+'/'+fname+'\');" title="Edit" alt="Edit" src="_tastydir/images/page_white_edit.png">'+
135 '<img '+ldisabled+'onclick="deleteFile(\''+fname+'\',\''+data.cdir+'/'+fname+'\');" title="Delete" alt="Delete" src="_tastydir/images/doc_shred.png">'+
136 '<img '+ldisabled+'onclick="copyBar(\''+fname+'\',\''+data.cdir+'/'+fname+'\');" title="Copy/Move" alt="Copy/Move" src="_tastydir/images/page_copy.png">'+
137 '</td>'+
138 '</tr>')
139 }
140 }else{
141 nofiles+=1;
142 }
143 if(nofiles==2){
144 $("#files").append('<tr><td colspan="4" class="no" style="text-align:center;">Directory is either empty or could not be accessed!</td></tr>');
145 }
146 /* image fading */
147 $("tr.frow").hover(
148 function(){
149 $(this).find('td').stop(true,true).animate({backgroundColor:'#f6f6f6'},'whatev');
150 },
151 function(){
152 $(this).find('td').stop(true,true).animate({backgroundColor:'white'},'whatev');
153 }
154 );
155 $("td.actions").find("img.enabled").hover(
156 function(){
157 $(this).stop(true,true).fadeTo('fast',1);
158 },
159 function(){
160 $(this).stop(true,true).fadeTo('fast',0.6);
161 }
162 );
163 }
164 $("#files_outer").slideDown('slow');
165 });
166 });
167}
168
169function getInfo(name,path,callback){
170 /*
171 //
172 // Return object looks like this:
173 //
174 Array
175 (
176 [status] => 0
177 [0] => Array
178 (
179 [dev] => 3
180 [ino] => 0
181 [mode] => 33206
182 [nlink] => 1
183 [uid] => 0
184 [gid] => 0
185 [rdev] => 3
186 [size] => 108907
187 [atime] => 1280616258
188 [mtime] => 1280616258
189 [ctime] => 1280700400
190 [blksize] => -1
191 [blocks] => -1
192 )
193
194 [1] => Array
195 (
196 [name] => VLADH-DESK-WIN7$
197 [passwd] =>
198 [uid] => 0
199 [gid] => 0
200 [geocs] =>
201 [dir] =>
202 [shell] =>
203 )
204
205 [2] => Array
206 (
207 [name] => N/A
208 [passwd] =>
209 [members] => Array
210 (
211 )
212
213 [gid] => 0
214 )
215 )
216 //
217 */
218 if(!loggedin){
219 noPerms();
220 return 0;
221 }
222 $.getJSON(sn_d+"_tastydir/do.php?getinfo="+path+"&cb=?", function(data){
223 if(data.status>0){
224 $("#editfile_modal").dialog({
225 title: 'Info Error - '+name.escape(),
226 modal: true,
227 width: 500,
228 height: 200,
229 buttons: {
230 'Close': function() {
231 $(this).dialog('close');
232 }
233 },
234 close: function(event,ui){
235 $(this).empty();
236 }
237 });
238 if(data.status==1){
239 $("#editfile_modal").append('<h3 class="no">Error</h3> The file you\'re trying to get info for doesn\'t exist.');
240 }
241 }else{
242 callback(data);
243 return 0;
244 }
245 });
246}
247
248function getLetters(){
249 var letters='', i;
250 $.getJSON(sn_d+"_tastydir/do.php?lt&cb=?", function(data){
251 for(i in data){
252 letters+='<button onClick="document.location=\'#'+data[i]+':/\'">'+data[i]+':\\</button>';
253 }
254 $("#letters").html(letters);
255 });
256}
257
258function editFileDialog(name, path){
259 if(!loggedin){
260 noPerms();
261 return 0;
262 }
263 $("#loading_modal").dialog({
264 modal:true,
265 height:60,
266 width:60,
267 resizable:false,
268 draggable:false
269 });
270 $.getJSON(sn_d+"_tastydir/do.php?getf="+path+"&cb=?", function(data){
271 $("#loading_modal").dialog('close');
272 if(data.status>0){
273 $("#editfile_modal").dialog({
274 title: 'File Editing Error - '+name.escape(),
275 modal: true,
276 width: 500,
277 height: 200,
278 buttons: {
279 'Close': function() {
280 $(this).dialog('close');
281 }
282 },
283 close: function(event,ui){
284 $(this).empty();
285 }
286 });
287 if(data.status==1){
288 $("#editfile_modal").append('<h3 class="no">Error</h3> The file you\'re trying to edit doesn\'t exist.');
289 }
290 if(data.status==2){
291 $("#editfile_modal").append('<h3 class="no">Error</h3> The file you\'re trying to edit is a binary file, such as an image. Editing it will only cause corruption (and there\'s no point in viewing it).');
292 }
293 }else{
294 $("#editfile_modal").append('<div id="editfile_top">Name: <input type="text" value="'+name.escape()+'" id="editfile_fname"></div><textarea id="editfile_textarea" onkeydown="return onTextareaKey(this,event)">'+data.data.escape()+'</textarea>');
295 $("#editfile_modal").dialog({
296 title: 'Edit File - '+name.escape()+'',
297 modal: true,
298 width: 800,
299 height: 600,
300 buttons: {
301 'Edit File': function() {
302 if($("#editfile_fname").val() != name){
303 mcfile=name;
304 mcpath=path;
305 moveFile(dirname(path)+'/'+$("#editfile_fname").val(),true);
306 }
307 if($('#editfile_textarea').val() != data.data){
308 writeFile(name,path,$('#editfile_textarea').val());
309 }
310 $(this).dialog('close');
311 },
312 'Cancel': function() {
313 $(this).dialog('close');
314 }
315 },
316 open: function(event,ui){
317 $("#editfile_textarea").height($("#editfile_modal").height() - $("#editfile_top").height() - 27);
318 },
319 resize: function(event,ui){
320 $("#editfile_textarea").height($("#editfile_modal").height() - $("#editfile_top").height() - 27);
321 },
322 close: function(event,ui){
323 $(this).empty();
324 }
325 });
326 }
327 });
328}
329
330function createFileDialog(path){
331 if(!loggedin){
332 noPerms();
333 return 0;
334 }
335 $("#editfile_modal").append('<div id="editfile_top">Name: <input type="text" value="" id="editfile_fname"></div><textarea id="editfile_textarea" onkeydown="return onTextareaKey(this,event)"></textarea>');
336 $("#editfile_modal").dialog({
337 title: 'Create File',
338 modal: true,
339 width: 800,
340 height: 400,
341 buttons: {
342 'Save File': function() {
343 writeNewFile($('#editfile_fname').val(),path+'/'+$('#editfile_fname').val(),$('#editfile_textarea').val());
344 $(this).dialog('close');
345 },
346 'Cancel': function() {
347 $(this).dialog('close');
348 }
349 },
350 open: function(event,ui){
351 $("#editfile_textarea").height($("#editfile_modal").height() - $("#editfile_top").height() - 27);
352 },
353 resize: function(event,ui){
354 $("#editfile_textarea").height($("#editfile_modal").height() - $("#editfile_top").height() - 27);
355 },
356 close: function(event,ui){
357 $(this).empty();
358 }
359 });
360}
361
362function editFolderDialog(name, path){
363 if(!loggedin){
364 noPerms();
365 return 0;
366 }
367 $("#editfile_modal").append('Name: <input type="text" value="'+name.escape()+'" id="editfile_fname">');
368 $("#editfile_modal").dialog({
369 title: 'Edit Folder - '+name.escape()+'',
370 modal: true,
371 width: 500,
372 height: 200,
373 buttons: {
374 'Edit': function() {
375 if($("#editfile_fname").val() != name){
376 mcfile=name;
377 mcpath=path;
378 moveFile(dirname(path)+'/'+$("#editfile_fname").val(),true);
379 }
380 $(this).dialog('close');
381 },
382 'Cancel': function() {
383 $(this).dialog('close');
384 }
385 },
386 close: function(event,ui){
387 $(this).empty();
388 }
389 });
390}
391
392function createFolderDialog(path){
393 if(!loggedin){
394 noPerms();
395 return 0;
396 }
397 $("#editfile_modal").append('Name: <input type="text" value="'+name.escape()+'" id="editfile_fname">');
398 $("#editfile_modal").dialog({
399 title: 'Create Folder',
400 modal: true,
401 width: 500,
402 height: 150,
403 buttons: {
404 'Create': function() {
405 if($("#editfile_fname").val() != name){
406 createFolder($("#editfile_fname").val(),path+'/'+$("#editfile_fname").val());
407 }
408 $(this).dialog('close');
409 },
410 'Cancel': function() {
411 $(this).dialog('close');
412 }
413 },
414 close: function(event,ui){
415 $(this).empty();
416 }
417 });
418}
419
420function createFolder(name,path){
421 $.getJSON(sn_d+"_tastydir/do.php?fcheck="+path+"&cb=?", function(data){
422 if(data.exists){
423 $("#editfile_modal").html('<strong>'+name.escape()+'</strong> already exists. Would you like to overwrite it?');
424 $("#editfile_modal").dialog({
425 title: 'File creation - <strong>'+name.escape()+'</strong> already exists',
426 modal: true,
427 width: 500,
428 height: 200,
429 buttons: {
430 'No': function() {
431 $("#editfile_modal").html('Folder not created.');
432 $("#editfile_modal").dialog({
433 title: 'Overwrite confirmation',
434 modal: true,
435 width: 500,
436 height: 200,
437 buttons: {
438 'Close': function(){
439 $(this).dialog('close');
440 }
441 }
442 });
443 },
444 'Yes': function() {
445 mkdir(name,path);
446 }
447 },
448 close: function(event,ui){
449 $(this).empty();
450 }
451 });
452 }else{
453 mkdir(name,path);
454 updateFiles(document.location.hash.substr(1));
455 }
456 });
457}
458
459function writeNewFile(name,path,fdata){
460 $.getJSON(sn_d+"_tastydir/do.php?fcheck="+path+"&cb=?", function(data){
461 if(data.exists){
462 $("#editfile_modal").html('<strong>'+name.escape()+'</strong> already exists. Would you like to overwrite it?');
463 $("#editfile_modal").dialog({
464 title: 'File creation - <strong>'+name.escape()+'</strong> already exists',
465 modal: true,
466 width: 500,
467 height: 200,
468 buttons: {
469 'No': function() {
470 $("#editfile_modal").html('File not created.');
471 $("#editfile_modal").dialog({
472 title: 'Overwrite confirmation',
473 modal: true,
474 width: 500,
475 height: 200,
476 buttons: {
477 'Close': function(){
478 $(this).dialog('close');
479 }
480 }
481 });
482 },
483 'Yes': function() {
484 writeFile(name,path,fdata);
485 }
486 },
487 close: function(event,ui){
488 $(this).empty();
489 }
490 });
491 }else{
492 writeFile(name,path,fdata);
493 updateFiles(document.location.hash.substr(1));
494 }
495 });
496}
497
498function writeFile(name,path,fdata){
499 $.ajax({
500 url: sn_d+"_tastydir/do.php?editf="+path+"&cb=?",
501 dataType: 'json',
502 type: 'POST',
503 data: 'fdata='+fdata,
504 success: function(data){
505 if(data.status>0){
506 $("#editfile_modal").dialog({
507 title: 'File Editing Error - '+name.escape(),
508 modal: true,
509 width: 500,
510 height: 200,
511 buttons: {
512 'Close': function() {
513 $(this).dialog('close');
514 }
515 },
516 close: function(event,ui){
517 $(this).empty();
518 }
519 });
520 if(data.status==1){
521 $("#editfile_modal").append('<h3 class="no">Error</h3> The file you\'re trying to edit (or its parent folder) isn\'t writable. Please set permissions of at least 755 in order to be able to modify files.');
522 }
523 if(data.status==2){
524 $("#editfile_modal").append('<h3 class="no">Error</h3> Couldn\'t write to file. This is either a permission problem, or the filename is invalid. Sorry!');
525 }
526 }
527 }
528 });
529}
530
531function mkdir(name,path){
532 $.getJSON(sn_d+"_tastydir/do.php?mkdir="+path+"&cb=?", function(data){
533 if(data.status>0){
534 $("#editfile_modal").dialog({
535 title: 'Folder Creation Error - '+name.escape(),
536 modal: true,
537 width: 500,
538 height: 200,
539 buttons: {
540 'Close': function() {
541 $(this).dialog('close');
542 }
543 },
544 close: function(event,ui){
545 $(this).empty();
546 }
547 });
548 if(data.status==1){
549 $("#editfile_modal").append('<h3 class="no">Error</h3> The parent folder of the folder you\'re trying to create isn\'t writable. Please set permissions of at least 755 in order to be able to modify files.');
550 }
551 if(data.status==2){
552 $("#editfile_modal").append('<h3 class="no">Error</h3> Couldn\'t write to file. This is either a permission problem, or the filename is invalid. Sorry!');
553 }
554 }
555 });
556}
557
558function deleteFile(name,path){
559 if(!loggedin){
560 noPerms();
561 return 0;
562 }
563 $("#editfile_modal").append('Are you sure you want to delete <strong>'+name.escape()+'</strong>?');
564 $("#editfile_modal").dialog({
565 title: 'File Deletion Confirmation - '+name.escape(),
566 modal: true,
567 width: 500,
568 height: 200,
569 buttons: {
570 'Delete': function() {
571 $(this).dialog('close');
572 $.getJSON(sn_d+"_tastydir/do.php?delf="+path+"&cb=?", function(data){
573 if(data.status>0){
574 $("#editfile_modal").dialog({
575 title: 'File Deletion Error - '+name.escape(),
576 modal: true,
577 width: 500,
578 height: 200,
579 buttons: {
580 'Close': function() {
581 $(this).dialog('close');
582 }
583 },
584 close: function(event,ui){
585 $(this).empty();
586 }
587 });
588 if(data.status==1){
589 $("#editfile_modal").append('<h3 class="no">Error</h3> The file you\'re trying to delete doesn\'t exist.');
590 }
591 if(data.status==2){
592 $("#editfile_modal").append('<h3 class="no">Error</h3> The file you\'re trying to delete isn\'t writable. Please set permissions of at least 755 in order to be able to modify files.');
593 }
594 if(data.status==3){
595 $("#editfile_modal").append('<h3 class="no">Error</h3> For some reason, the file couldn\'t be deleted. This is most likely a permission issue. Sorry!');
596 }
597 }else{
598 updateFiles(document.location.hash.substr(1));
599 }
600 });
601 },
602 'Cancel': function() {
603 $(this).dialog('close');
604 }
605 },
606 close: function(event,ui){
607 $(this).empty();
608 }
609 });
610}
611
612function deleteFolder(name,path){
613 if(!loggedin){
614 noPerms();
615 return 0;
616 }
617 $("#editfile_modal").append('Are you REALLY sure you want to delete the folder <strong>'+name.escape()+'</strong> and everything in it?');
618 $("#editfile_modal").dialog({
619 title: 'Folder Deletion Confirmation - '+name.escape(),
620 modal: true,
621 width: 500,
622 height: 200,
623 buttons: {
624 'Do it': function() {
625 $(this).dialog('close');
626 $("#loading_modal").dialog({
627 modal:true,
628 height:60,
629 width:60,
630 resizable:false,
631 draggable:false
632 });
633 $.getJSON(sn_d+"_tastydir/do.php?delfld="+path+"&cb=?", function(data){
634 $("#loading_modal").dialog('close');
635 if(data.status>0){
636 $("#editfile_modal").dialog({
637 title: 'Folder Deletion Error - '+name.escape(),
638 modal: true,
639 width: 500,
640 height: 200,
641 buttons: {
642 'Close': function() {
643 $(this).dialog('close');
644 }
645 },
646 close: function(event,ui){
647 $(this).empty();
648 }
649 });
650 if(data.status==1){
651 $("#editfile_modal").append('<h3 class="no">Error</h3> The folder you\'re trying to delete doesn\'t exist.');
652 }
653 if(data.status==2){
654 $("#editfile_modal").append('<h3 class="no">Error</h3> The folder you\'re trying to delete isn\'t writable. Please set permissions of at least 755 in order to be able to modify files.');
655 }
656 if(data.status==3){
657 $("#editfile_modal").append('<h3 class="no">Error</h3> For some reason, the folder couldn\'t be deleted. This is most likely a permission issue. Sorry!');
658 }
659 }else{
660 updateFiles(document.location.hash.substr(1));
661 $("#editfile_modal").append('Folder succesfully deleted.');
662 $("#editfile_modal").dialog({
663 title: 'Folder Deletion Completed - '+name.escape(),
664 modal: true,
665 width: 500,
666 height: 200,
667 buttons: {
668 'Close': function() {
669 $(this).dialog('close');
670 }
671 },
672 close: function(event,ui){
673 $(this).empty();
674 }
675 });
676 }
677 });
678 },
679 'Cancel': function() {
680 $(this).dialog('close');
681 }
682 },
683 close: function(event,ui){
684 $(this).empty();
685 }
686 });
687}
688
689function copyBar(name,path){
690 if(!loggedin){
691 noPerms();
692 return 0;
693 }
694 mcfile=name;
695 mcpath=path;
696 $("#copyname").html(name);
697 $("#bottombar").show();
698}
699function copyFileAttempt(path,move){
700 mcmove=move;
701 if(mcfile!=undefined && mcpath!=undefined){
702 $.getJSON(sn_d+"_tastydir/do.php?fcheck="+path+'/'+mcfile+"&cb=?", function(data){
703 if(data.exists){
704 $("#editfile_modal").html('<strong>'+mcfile+'</strong> already exists. Would you like to overwrite it?');
705 $("#editfile_modal").dialog({
706 title: 'File '+(mcmove ? 'move' : 'copy')+' - <strong>'+mcfile+'</strong> already exists',
707 modal: true,
708 width: 500,
709 height: 200,
710 buttons: {
711 'Yes': function() {
712 if (mcmove){
713 moveFile(path);
714 }else{
715 copyFile(path);
716 }
717 closeCopyBar();
718 },
719 'No': function() {
720 closeCopyBar();
721 $("#editfile_modal").html('File not '+(mcmove ? 'moved' : 'copied')+'.');
722 $("#editfile_modal").dialog({
723 title: 'Overwrite confirmation',
724 modal: true,
725 width: 500,
726 height: 200,
727 buttons: {
728 'Close': function(){
729 $(this).dialog('close');
730 }
731 }
732 });
733 }
734 },
735 close: function(event,ui){
736 $(this).empty();
737 }
738 });
739 }else{
740 if(mcmove){
741 moveFile(path);
742 }else{
743 copyFile(path);
744 }
745 closeCopyBar();
746 updateFiles(document.location.hash.substr(1));
747 }
748 });
749 }
750}
751function copyFile(path){
752 $.getJSON(sn_d+"_tastydir/do.php?copy=copy&from="+mcpath+'&to='+path+'/'+mcfile+"&cb=?", function(data){
753 if(data.status>0){
754 $("#editfile_modal").dialog({
755 title: 'File Copy Error - '+mcfile,
756 modal: true,
757 width: 500,
758 height: 200,
759 buttons: {
760 'Close': function() {
761 $(this).dialog('close');
762 }
763 },
764 close: function(event,ui){
765 $(this).empty();
766 }
767 });
768 if(data.status==1){
769 $("#editfile_modal").append('<h3 class="no">Error</h3> The file you\'re trying to copy doesn\'t exist.');
770 }
771 if(data.status==2){
772 $("#editfile_modal").append('<h3 class="no">Error</h3> The destination path isn\'t writable. Please set permissions of at least 755.');
773 }
774 if(data.status==3){
775 $("#editfile_modal").append('<h3 class="no">Error</h3> For some reason, the file couldn\'t be copied. This is most likely a permission issue. Sorry!');
776 }
777 }else{
778 updateFiles(document.location.hash.substr(1));
779 }
780 });
781}
782function moveFile(path,newname){
783 if(!newname){
784 fpath=path+'/'+mcfile;
785 }else{
786 fpath=path;
787 }
788 $.getJSON(sn_d+"_tastydir/do.php?copy=move&from="+mcpath+'&to='+fpath+"&cb=?", function(data){
789 if(data.status>0){
790 $("#editfile_modal").dialog({
791 title: 'File Move Error - '+mcfile,
792 modal: true,
793 width: 500,
794 height: 200,
795 buttons: {
796 'Close': function() {
797 $(this).dialog('close');
798 }
799 },
800 close: function(event,ui){
801 $(this).empty();
802 }
803 });
804 if(data.status==1){
805 $("#editfile_modal").append('<h3 class="no">Error</h3> The file you\'re trying to move doesn\'t exist.');
806 }
807 if(data.status==2){
808 $("#editfile_modal").append('<h3 class="no">Error</h3> The file you\'re trying to move isn\'t writable. Please set permissions of at least 755.');
809 }
810 if(data.status==3){
811 $("#editfile_modal").append('<h3 class="no">Error</h3> The destination path isn\'t writable. Please set permissions of at least 755.');
812 }
813 if(data.status==4){
814 $("#editfile_modal").append('<h3 class="no">Error</h3> For some reason, the file couldn\'t be move. This is most likely a permission issue. Sorry!');
815 }
816 }else{
817 updateFiles(document.location.hash.substr(1));
818 }
819 });
820}
821function closeCopyBar(){
822 $("#bottombar").hide();
823}
824
825
826
827function chmod(name, path, fperms){
828 if(!loggedin){
829 noPerms();
830 return 0;
831 }
832 var ur,uw,ux,gr,gw,gx,wr,ww,wx,octal,changed=false,finfo;
833 getInfo(name,path,function(finfo){
834 // code in this function is pretty inefficient but I
835 // couldn't figure out a much better way in javascript
836 function chchange(initial){
837 octal=String((ur*4)+(uw*2)+(ux*1))+String((gr*4)+(gw*2)+(gx*1))+String((wr*4)+(ww*2)+(wx*1));
838 $("#octal").html(octal);
839 if(!initial){
840 changed=true;
841 }
842 }
843 ur=(fperms[1]=='r') ? 1 : 0;
844 if(ur){ urs=' checked="checked"'; }else{ urs=''; }
845 uw=(fperms[2]=='w') ? 1 : 0;
846 if(uw){ uws=' checked="checked"'; }else{ uws=''; }
847 ux=(fperms[3]=='x') ? 1 : 0;
848 if(ux){ uxs=' checked="checked"'; }else{ uxs=''; }
849
850 gr=(fperms[4]=='r') ? 1 : 0;
851 if(gr){ grs=' checked="checked"'; }else{ grs=''; }
852 gw=(fperms[5]=='w') ? 1 : 0;
853 if(gw){ gws=' checked="checked"'; }else{ gws=''; }
854 gx=(fperms[6]=='x') ? 1 : 0;
855 if(gx){ gxs=' checked="checked"'; }else{ gxs=''; }
856
857 wr=(fperms[7]=='r') ? 1 : 0;
858 if(wr){ wrs=' checked="checked"'; }else{ wrs=''; }
859 ww=(fperms[8]=='w') ? 1 : 0;
860 if(ww){ wws=' checked="checked"'; }else{ wws=''; }
861 wx=(fperms[9]=='x') ? 1 : 0;
862 if(wx){ wxs=' checked="checked"'; }else{ wxs=''; }
863 $("#editfile_modal").append(
864 '<table id="chmodstuff">'+
865 '<tr>'+
866 '<td> </td>'+
867 '<td>read</td>'+
868 '<td>write</td>'+
869 '<td>execute</td>'+
870 '</tr>'+
871 '<tr>'+
872 '<td>user</td>'+
873 '<td><input type="checkbox" id="ur"'+urs+'></td>'+
874 '<td><input type="checkbox" id="uw"'+uws+'></td>'+
875 '<td><input type="checkbox" id="ux"'+uxs+'></td>'+
876 '</tr>'+
877 '<tr>'+
878 '<td>group</td>'+
879 '<td><input type="checkbox" id="gr"'+grs+'></td>'+
880 '<td><input type="checkbox" id="gw"'+gws+'></td>'+
881 '<td><input type="checkbox" id="gx"'+gxs+'></td>'+
882 '</tr>'+
883 '<tr>'+
884 '<td>world</td>'+
885 '<td><input type="checkbox" id="wr"'+wrs+'></td>'+
886 '<td><input type="checkbox" id="ww"'+wws+'></td>'+
887 '<td><input type="checkbox" id="wx"'+wxs+'></td>'+
888 '</tr>'+
889 '<tr>'+
890 '<td>octal</td>'+
891 '<td colspan="3"><span id="octal"></span></td>'+
892 '</tr>'+
893 '<tr>'+
894 '<td>owner</td>'+
895 '<td colspan="3"><abbr title="id: '+finfo['f']['uid']+'">'+finfo['u']['name']+'</abbr></td>'+
896 '</tr>'+
897 '<tr>'+
898 '<td> </td>'+
899 '<td colspan="3"><abbr title="id: '+finfo['f']['gid']+'">'+finfo['g']['name']+'</abbr></td>'+
900 '</tr>'+
901 '</table>'
902 );
903 $("#ur").change(function(){ur=toggle(ur);chchange();});
904 $("#uw").change(function(){uw=toggle(uw);chchange();});
905 $("#ux").change(function(){ux=toggle(ux);chchange();});
906 $("#gr").change(function(){gr=toggle(gr);chchange();});
907 $("#gw").change(function(){gw=toggle(gw);chchange();});
908 $("#gx").change(function(){gx=toggle(gx);chchange();});
909 $("#wr").change(function(){wr=toggle(wr);chchange();});
910 $("#ww").change(function(){ww=toggle(ww);chchange();});
911 $("#wx").change(function(){wx=toggle(wx);chchange();});
912 chchange(true);
913 $("#editfile_modal").dialog({
914 title: 'chmod - '+name.escape(),
915 modal: true,
916 width: 500,
917 height: 300,
918 buttons: {
919 'chmod': function() {
920 $(this).dialog('close');
921 if(changed){
922 $.getJSON(sn_d+"_tastydir/do.php?chmod="+path+"&to="+octal+"&cb=?", function(data){
923 if(data.status>0){
924 $("#editfile_modal").dialog({
925 title: 'chmod Error - '+name.escape(),
926 modal: true,
927 width: 500,
928 height: 200,
929 buttons: {
930 'Close': function() {
931 $(this).dialog('close');
932 }
933 },
934 close: function(event,ui){
935 $(this).empty();
936 }
937 });
938 if(data.status==1){
939 $("#editfile_modal").append('<h3 class="no">Error</h3> The file you\'re trying to chmod doesn\'t exist.');
940 }
941 if(data.status==2){
942 $("#editfile_modal").append('<h3 class="no">Error</h3> For some reason, the file couldn\'t be chmodded. This is most likely a permission issue. Sorry!');
943 }
944 }else{
945 updateFiles(document.location.hash.substr(1));
946 }
947 });
948 }
949 },
950 'Cancel': function() {
951 $(this).dialog('close');
952 }
953 },
954 close: function(event,ui){
955 $(this).empty();
956 }
957 });
958 });
959}
960
961function showUploadForm(){
962 if(!loggedin){
963 noPerms();
964 return 0;
965 }
966 $("#uploadtext").hide();
967 $("#uploadform").show();
968 $("#uploadform_seriously").append('<input type="hidden" name="dir" value="'+cdir+'">');
969}
970function startUpload(){
971 $("#uploadform_progress").show();
972 return true;
973}
974function stopUpload(data){
975 $("#uploadform_progress").hide();
976 $("#uploadform").hide();
977 if(data.status==0){
978 $("#uploadtext_really").html('File succesfully uploaded');
979 $("#uploadtext_really").delay(1000).fadeOut('whatev',function(){
980 $(this).html('Upload file');
981 $(this).fadeIn('whatev');
982 });
983 }
984 if(data.status==1){
985 $("#editfile_modal").html('The file you\'re trying to upload already exists. Would you like to overwrite it?');
986 $("#uploadtext_really").html('Waiting for confirmation...');
987 $("#editfile_modal").dialog({
988 title: 'Upload - <strong>'+data.name+'</strong> already exists',
989 modal: true,
990 width: 500,
991 height: 200,
992 buttons: {
993 'No': function() {
994 $(this).dialog('close');
995 $("#uploadtext_really").html('<strong>'+data.name+'</strong> not uploaded.');
996 $("#uploadtext_really").delay(1000).fadeOut('whatev',function(){
997 $(this).html('Upload file');
998 $(this).fadeIn('whatev');
999 });
1000 },
1001 'Yes': function() {
1002 $("#uploadform_seriously").append('<input type="hidden" id="uploadform_force" name="force" value="force">');
1003 $("#uploadform_seriously").submit();
1004 $(this).dialog('close');
1005 }
1006 },
1007 close: function(event,ui){
1008 $(this).empty();
1009 }
1010 });
1011 }
1012 if(data.status==2){
1013 $("#uploadtext_really").html('<span class="no">There was an error while uploading your file. This is probably a permissions problem. Sorry!</span>');
1014 }
1015 $("#uploadtext").show();
1016 if($("#uploadform_force").length != 0){
1017 $("#uploadform_force").remove();
1018 }
1019 if(data.status!=1){
1020 updateFiles(document.location.hash.substr(1));
1021 }
1022 return true;
1023}
1024
1025function lightboxImage(file){
1026 var newheight, maxwidth=500;
1027 $.getJSON(sn_d+"_tastydir/do.php?getsize="+file+"&cb=?", function(data){
1028 if(data.status>0){
1029 $("#editfile_modal").dialog({
1030 title: 'Image Error - '+basename(file),
1031 modal: true,
1032 width: 500,
1033 height: 200,
1034 buttons: {
1035 'Close': function() {
1036 $(this).dialog('close');
1037 }
1038 },
1039 close: function(event,ui){
1040 $(this).empty();
1041 }
1042 });
1043 if(data.status==1){
1044 $("#editfile_modal").append('<h3 class="no">Error</h3> The image you\'re trying to view doesn\'t exist.');
1045 }
1046 if(data.status==2){
1047 $("#editfile_modal").append('<h3 class="no">Error</h3> The file you\'re trying to view isn\'t an image, or there was an error determining its size.');
1048 }
1049 }else{
1050 $("#editfile_modal").html('<img src="_tastydir/do.php?download='+file+'" width="500">');
1051 $("#editfile_modal").css('text-align','center');
1052 newheight=Math.ceil(data.height/(data.width/maxwidth));
1053 $("#editfile_modal").dialog({
1054 modal: true,
1055 width: maxwidth+30,
1056 height: newheight+120,
1057 buttons: {
1058 'Close': function() {
1059 $(this).dialog('close');
1060 },
1061 'Download': function() {
1062 document.location='_tastydir/do.php?download='+file+'&forcedl';
1063 }
1064 },
1065 open: function(event,ui){
1066 $('.ui-dialog-titlebar').hide();
1067 },
1068 close: function(event,ui){
1069 $('.ui-dialog-titlebar').show();
1070 $("#editfile_modal").css('text-align','left');
1071 $(this).empty();
1072 }
1073 });
1074 }
1075 });
1076}
1077
1078// if the user isn't logged in, we disallow him from editing and stuff
1079// YES, I ALSO CHECK FOR THIS SERVERSIDE
1080function noPerms(){
1081 $("#editfile_modal").dialog({
1082 title: 'Permission Error',
1083 modal: true,
1084 width: 500,
1085 height: 200,
1086 buttons: {
1087 'Close': function() {
1088 $(this).dialog('close');
1089 }
1090 },
1091 close: function(event,ui){
1092 $(this).empty();
1093 }
1094 });
1095 $("#editfile_modal").append('<h3 class="no">Error</h3> You need to log in to modify files.');
1096}
1097
1098function unFrontSlash(string){
1099 while(string[0]=='/' && string[1]=='/'){
1100 alert(string);
1101 string=string.substr(1);
1102 }
1103 alert(string);
1104 return string;
1105}
1106
1107// tab character stuff
1108
1109function setSelectionRange(input, selectionStart, selectionEnd) {
1110 if (input.setSelectionRange) {
1111 input.focus();
1112 input.setSelectionRange(selectionStart, selectionEnd);
1113 }
1114 else if (input.createTextRange) {
1115 var range = input.createTextRange();
1116 range.collapse(true);
1117 range.moveEnd('character', selectionEnd);
1118 range.moveStart('character', selectionStart);
1119 range.select();
1120 }
1121}
1122
1123function replaceSelection (input, replaceString) {
1124 if (input.setSelectionRange) {
1125 var selectionStart = input.selectionStart;
1126 var selectionEnd = input.selectionEnd;
1127 input.value = input.value.substring(0, selectionStart)+
1128replaceString + input.value.substring(selectionEnd);
1129
1130 if (selectionStart != selectionEnd){
1131 setSelectionRange(input, selectionStart, selectionStart +
1132 replaceString.length);
1133 }else{
1134 setSelectionRange(input, selectionStart +
1135replaceString.length, selectionStart + replaceString.length);
1136 }
1137
1138 }else if (document.selection) {
1139 var range = document.selection.createRange();
1140
1141 if (range.parentElement() == input) {
1142 var isCollapsed = range.text == '';
1143 range.text = replaceString;
1144
1145 if (!isCollapsed) {
1146 range.moveStart('character', -replaceString.length);
1147 range.select();
1148 }
1149 }
1150 }
1151}
1152
1153function onTextareaKey(item,e){
1154 if(navigator.userAgent.match("Gecko"))
1155 c=e.which;
1156 else
1157 c=e.keyCode;
1158 if(c==9){
1159 replaceSelection(item,String.fromCharCode(9));
1160 setTimeout("document.getElementById('"+item.id+"').focus();",0);
1161 return false;
1162 }
1163}
1164
1165function replaceLogin(){
1166 $("#login").html(
1167 '<form action="index.php" method="post">'+
1168 '<labeL>password</label> <input id="loginpw" type="password" name="pw" size="20">'+
1169 '<input type="hidden" name="action" value="login">'+
1170 '<input type="submit" value="Go" style="display:none;">'+
1171 '</form>'
1172 );
1173 $("#loginpw").focus();
1174}
1175
1176/* stuff we want to run initially */
1177$(document).ready(function(){
1178 getLetters();
1179
1180 /* hashchange stuff for history when you hit back */
1181 if(document.location.hash.length > 0){
1182 updateFiles(document.location.hash.substr(1));
1183 }else{
1184 updateFiles('');
1185 }
1186 $(window).bind("hashchange",function(e){
1187 updateFiles(document.location.hash.substr(1));
1188 });
1189});