Browse Source

Add files via upload

yeungalan 6 years ago
parent
commit
2ca422f1a9
3 changed files with 638 additions and 0 deletions
  1. 337 0
      MainUI.php
  2. 268 0
      ProgressUI.php
  3. 33 0
      deltmp.php

+ 337 - 0
MainUI.php

@@ -0,0 +1,337 @@
+<?php
+include '../auth.php';
+?>
+<!DOCTYPE html>
+<html>
+<head>
+    <meta charset="UTF-8">
+	<meta name="viewport" content="width=device-width, initial-scale=0.86, maximum-scale=0.86, minimum-scale=0.86, user-scalable=no">
+
+	<script src="../script/jquery.min.js"></script>
+    <link rel="stylesheet" href="../script/tocas/tocas.css">
+	<script type='text/javascript' src="../script/tocas/tocas.js"></script>
+	<script type='text/javascript' src="../script/ao_module.js"></script>
+	<title>7z File Manager</title>
+	<style>
+	body{
+		background-color:white;
+		-webkit-user-select: none; /* Safari */        
+		-moz-user-select: none; /* Firefox */
+		-ms-user-select: none; /* IE10+/Edge */
+		user-select: none; /* Standard */
+	}
+	tr{
+	    cursor:pointer;
+	}
+	tr:hover { 
+		background-color: #fafafa;
+	}
+	@media (max-width: 767px){
+		.ts.bottom.right.snackbar.active{
+			width: 100% !important;
+			bottom: 0px !important;
+			right: 0px !important;
+		}
+		.ts.snackbar:not(.inline) .content {
+		    margin-bottom: 7px;
+		}
+	}
+	</style>
+</head>
+<body>
+<div class="ts labeled icon menu" style="box-shadow: 0px 0px 0px 0 #000000 !important;">
+    <a class="item" onclick="functionbar_extract();">
+        <i class="minus icon"></i> Extract
+    </a>
+	<a class="item"  onclick="functionbar_clean();">
+        <i class="remove icon"></i> Clear Cache
+    </a>
+	<a class="item" onclick="functionbar_info();">
+        <i class="notice icon"></i> Info
+    </a>
+</div>
+<div class="ts breadcrumb" style="left: 20px;padding-bottom:10px;" id="breadcrumb">
+	<button class="ts icon mini basic button" path="" attr="Dir" id="returnBtn" onclick="load(this)">
+		<i class="reply icon"></i>
+	</button>
+		<p href="#!" class="section"><?php echo $_GET["file"] ?></p>
+</div>
+<div class="ts fitted divider"></div>
+<table class="ts borderless table">
+    <thead>
+        <tr id="thead">
+        </tr>
+    </thead>
+    <tbody id="tbody">
+    </tbody>
+</table>
+
+<!-- use for displaying dialog , for VDI user , use VDI module instead -->
+<div class="ts modals dimmer">
+    <dialog id="modal" class="ts closable basic modal" style="background-color: white;color: black!important" open>
+        <div class="content" id="modaldata">
+        </div>
+    </dialog>
+</div>
+<div class="ts bottom right snackbar">
+    <div class="content"></div>
+</div>
+<div class="ts contextmenu">
+    <div class="item" onclick="contextmenu_extract()">
+        Open
+		<span class="description">Enter</span>
+    </div>
+    <div class="item" onclick="functionbar_extract()">
+        Extract
+    </div>
+    <div class="item"  onclick="functionbar_info()">
+        Properties
+    </div>
+</div>
+
+</body>
+<script>
+/*
+Reminder: the x and y for new windows no longer has any function;
+please change it on another page directly.
+*/
+//Global variable
+var random = Math.floor((Math.random() * 10000) + 1000);
+var file = "<?php echo $_GET["file"] ?>";
+
+//Init floatWindow events
+ao_module_setWindowIcon("file archive outline");
+ao_module_setGlassEffectMode();
+ao_module_setWindowTitle(ao_module_codec.decodeUmFilename(basename(file)) + " 7-Zip File Manager");
+
+if(!["7Z","LZMA","CAB","ZIP","GZIP","BZIP2","Z","TAR"].includes(basename(file).split(".")[1].toUpperCase())){
+	msgbox('Warning: Unsupport file type','yellow','black');
+}
+
+if (ao_module_virtualDesktop){
+    //Push up the body section a bit to compensate for the floatWindow offsets
+    $("body").css("padding-bottom","20px");
+}
+ao_module_setWindowSize(950,530);
+
+function basename(path){
+    path = path.split("\\").join("/");
+    return path.split("/").pop();
+}
+
+load($("#returnBtn"));
+$.get("deltmp.php?forced=false", function(data) {
+});
+
+
+ts('.borderless.table').contextmenu({
+    menu: '.ts.contextmenu'
+});
+
+$('body').on('click', function(e) {
+  if (e.target !== this)
+    return;
+  $("tr").removeAttr("style");
+});
+
+document.onkeydown = function(e) {
+    if($("[style='background-color: #e9e9e9;']").length > 0){
+        var htmlelement = $("[style='background-color: #e9e9e9;']");
+    }else{
+        var htmlelement = $("#tbody tr:first");
+    }
+    switch (e.keyCode) {
+        case 9:
+            if(htmlelement.prev().length > 0){
+                var next = htmlelement.prev();
+    	    	$("tr").removeAttr("style");
+    		    $(next).attr("style","background-color: #e9e9e9;");
+            }
+        case 13:
+            var htmlelement = $("[style='background-color: #e9e9e9;']");
+            load(htmlelement);
+            break;
+        case 38:
+            if(htmlelement.prev().length > 0){
+                var next = htmlelement.prev();
+    	    	$("tr").removeAttr("style");
+    		    $(next).attr("style","background-color: #e9e9e9;");
+            }else{
+            	$("tr").removeAttr("style");
+                $(htmlelement).attr("style","background-color: #e9e9e9;");
+            }
+            break;
+        case 40:
+            if(htmlelement.next().length > 0){
+    	    	var next = htmlelement.next();
+    	    	$("tr").removeAttr("style");
+    		    $(next).attr("style","background-color: #e9e9e9;");
+            }else{
+            	$("tr").removeAttr("style");
+                $(htmlelement).attr("style","background-color: #e9e9e9;");
+            }
+            break;
+    }
+};
+
+
+//for load data into table
+//load($(returnBtn));
+
+function onsingleclick(htmlelement){
+	$("tr").removeAttr("style");
+	$(htmlelement).attr("style","background-color: #e9e9e9;");
+}
+
+function load(htmlelement){
+	if($(htmlelement).attr("attr") == "Dir"){
+		$("#breadcrumb").html('<button class="ts icon mini basic button" disabled><i class="level up icon"></i></button> <p class="section"><i class="loading circle notched icon"></i>Fetching..</p>');
+		//for load data into table
+		$.get("opr.php?method=l&rand=" + random + "&file=" + file + "&dir=" + $(htmlelement).attr("path"), function( raw ) {
+			//clear table for pepare load data into table
+			$("#thead").html("");
+			$("#tbody").html("");
+			var data = JSON.parse(raw); //parse it
+			var header = data["Header"]; 
+			//create thead
+			$(data["Header"]).each(function( key, value ) {
+			  $("#thead").append("<th>" + value + "</th>");//create header (thead) first
+			});
+			//create tbody
+			$(data["Information"]).each(function( a, value ) {
+				//to check if attr not exists. if not exists, assume it is an file.
+				if(typeof value["Attributes"] === 'undefined'){
+					var attr = "File";
+				}else{
+					if(value["Attributes"].includes("D")){
+						var attr = "Dir";
+					}else{
+						var attr = "File";
+					}
+				}
+				//create HTML structure
+				var tmp = "";
+				tmp = tmp + '<tr path="' + value["Path"] + '" attr="' + attr + '" ondblclick="load(this)" onclick="onsingleclick(this)" oncontextmenu="onsingleclick(this)">'
+				$.each(data["Header"], function( a, key ) {
+					if(typeof value[key] !== 'undefined'){
+					    if(key == "Path"){
+					        //create fanastic icon to user
+					        if(attr == "Dir"){
+					            var tdicon = '<i class="folder outline icon"></i>';
+					        }else{
+					            var filepath = value["Path"].trim();
+					            if (filepath != ""){
+					                var ext = filepath.split(".").pop();
+					                var icon = ao_module_utils.getIconFromExt(ext);
+					                var tdicon = '<i class="' + icon + ' icon"></i>';
+					            }else{
+					                var tdicon = '<i class="file outline icon"></i>';
+					            }
+					            
+					        }
+					        var tdpath = value[key].replace(new RegExp($(htmlelement).attr("path") + "/"),"");
+							if(tdpath.includes("?")){
+					            var tdicon = '<i class="exclamation triangle icon"></i>';
+					        }
+							tmp = tmp + "<td>" + tdicon + ao_module_codec.decodeUmFilename(tdpath) + "</td>";					        
+					    }else{
+					        tmp = tmp + "<td>" + value[key] + "</td>";
+					    }
+					}else{
+						tmp = tmp + "<td></td>";
+					}
+				});
+				$("#tbody").append(tmp + "</tr>");
+				$('tr').on('touchstart', function(e){
+					load(this);
+				});
+			});
+			
+			/*
+			//Little patch for HEX file name (PATCH)
+			$( "tr td:first-child" ).each( function( index, element ){
+				var tpath = $(this);
+				if(/^inith[0-9a-fA-F]*\..*$|^[0-9a-fA-F]*$/.test($(tpath).text())){
+					
+					$.get( '../SystemAOB/functions/file_system/um_filename_decoder.php?filename=' + $(tpath).text(), function( decodedfilename ) {
+						$(tpath).text(decodedfilename);
+					});
+					
+				}
+			});
+			*/
+			
+			//process for Prev button 
+			var path = $(htmlelement).attr("path").split("/");
+			var previousPath = $(htmlelement).attr("path").replace(/([^\/]+)$/, '').slice(0, -1);
+			if(previousPath == $(htmlelement).attr("path")){
+				previousPath = "";
+			}
+			//console.log(previousPath);
+			$("#breadcrumb").html('<button class="ts icon mini basic button" currPath="' + $(htmlelement).attr("path") + '" path="' + previousPath + '" attr="Dir" id="returnBtn" onclick="load(this)"><i class="level up icon"></i></button> <p href="#!" class="section">' + ao_module_codec.decodeUmFilename(file.replace(/^.*[\\\/]/, '')) +'</p><div class="divider">/</div>');
+			if($(htmlelement).attr("path").length > 1){
+				$.each(path, function( a, key ) {
+					$("#breadcrumb").append('<p href="#!" class="section"><i class="folder icon"></i>' + key + '</p><div class="divider">/</div>');
+				});
+			}
+		});
+	}else{
+		//if it was file, show it.
+		showDialog("ProgressUI.php?method=e&rand=" + random + "&file=" + file + "&dir=" + $(htmlelement).attr("path"),720,250);
+		random = Math.floor((Math.random() * 10000) + 1000);
+	}
+}
+
+function contextmenu_extract(){
+	showDialog("ProgressUI.php?method=e&rand=" + random + "&file=" + file + "&dir=" + $("[style='background-color: #e9e9e9;']").attr("path"),720,250);
+	random = Math.floor((Math.random() * 10000) + 1000);
+}
+
+function functionbar_extract(){
+	//extract files or dir , if file then pass method=e , if dir then pass method=x
+	if($("[style='background-color: #e9e9e9;']").attr("attr") == "Dir"){
+		showDialog("CopyNMoveUI.php?method=x&rand=" + random + "&file=" + file + "&dir=" + $($("[style='background-color: #e9e9e9;']")).attr("path"),720,280);
+	}else if($("[style='background-color: #e9e9e9;']").attr("attr") == "File"){
+		showDialog("CopyNMoveUI.php?method=e&rand=" + random + "&file=" + file + "&dir=" + $("[style='background-color: #e9e9e9;']").attr("path"),720,280);
+	}else{
+		showDialog("CopyNMoveUI.php?method=x&rand=" + random + "&file=" + file + "&dir=" + $("#returnBtn").attr("currPath"),720,250);
+	}
+	//generate new number for next extraction
+	random = Math.floor((Math.random() * 10000) + 1000);
+}
+
+function functionbar_info(){
+	//showDialog("infoUI.php?file=" + file,365,475);
+	var displayname = ao_module_codec.decodeUmFilename(basename(file));
+	var icon = ao_module_utils.getIconFromExt(displayname.split(".").pop().trim());
+	showDialog("infoUI.php?file=" + file,displayname + ' - Properties',icon,365,475);
+}
+
+function showDialog(href,x,y){
+	if(ao_module_virtualDesktop){
+		ao_module_newfw('7-Zip File Manager/' + href,'Extract Files - 7zip File Manager','external','7-ZipProgressUI' + Math.floor(Math.random()*100),x,y,undefined,undefined,true,true);
+	}else{
+		$.get( href, function( data ) {
+			$( "#modaldata" ).html( data );
+			ts('#modal').modal("show");
+		});
+	}
+}
+
+function functionbar_clean(){
+	$.get( 'deltmp.php?forced=true', function(data) {
+		msgbox(data,'','');
+	});
+	
+}
+function msgbox(content,bgcolor,fontcolor){
+	$(".snackbar").attr("style",'background-color: ' + bgcolor + ';color:' + fontcolor);
+	ts('.snackbar').snackbar({
+		content: content,
+		onAction: () => {
+			$(".snackbar").removeAttr("style");
+		}
+	});
+}
+</script>
+</html>

+ 268 - 0
ProgressUI.php

@@ -0,0 +1,268 @@
+<?php
+include '../auth.php';
+?>
+<!DOCTYPE html>
+<html>
+<head>
+    <meta charset="UTF-8">
+	<script src="../script/jquery.min.js"></script>
+    <link rel="stylesheet" href="../script/tocas/tocas.css">
+	<script type='text/javascript' src="../script/tocas/tocas.js"></script>
+	<script type='text/javascript' src="../script/ao_module.js"></script>
+	<title>7z File Manager</title>
+	<style>
+	body{
+		background-color:white
+	}
+	.ts.form .inline.field label {
+		min-width: 50%;
+	}
+	.ts.basic.dropdown, .ts.form select {
+		max-width: 50%;
+	}
+	</style>
+</head>
+<body>
+<br>
+	<div class="ts container">
+		<div class="ts grid">
+			
+			<div class="eight wide column">
+				<span style="text-align:left">Elasped time:</span>
+				<span style="text-align:right" id="time">00:00:00</span>
+			</div>
+			<div class="eight wide column">
+				<span style="text-align:left">Total size:</span>
+				<span style="text-align:right" id="totalsize">0 b</span>
+			</div>
+			
+			<div class="eight wide column">
+				<span style="text-align:left">Remaining time:</span>
+				<span style="text-align:right" id="remaining">00:00:00</span>
+			</div>
+			<div class="eight wide column">
+				<span style="text-align:left">Speed:</span>
+				<span style="text-align:right" id="speed">0 b/s</span>
+			</div>
+			
+			<div class="sixteen wide column">
+				<span style="text-align:left">Loading...</span>
+				<div class="ts progress">
+					<div class="bar" id="bar" style="width: 0%"></div>
+				</div>
+			</div>	
+			
+			<div class="eight wide column"></div>
+			<div class="eight wide column">
+				<button class="ts basic button" style="width:100%" onclick="f_close();f_cancel = true;">Cancel</button>
+			</div>
+		</div>
+	</div>
+	<div class="ts bottom right snackbar">
+		<div class="content"></div>
+	</div>
+</body>
+<script>
+var f_method = "<?php echo $_GET["method"] ?>";
+var f_rand = "<?php echo $_GET["rand"] ?>";
+var f_file = "<?php echo $_GET["file"] ?>";
+var f_dir = "<?php echo $_GET["dir"] ?>";
+var f_size = "<?php echo filesize($_GET["file"]); ?>";
+var f_DontCreateNewFolder = <?php echo isset($_GET["DontCreateNewFolder"]) ? $_GET["DontCreateNewFolder"] : "false"; ?>;
+var f_destdir = "<?php echo isset($_GET["destdir"]) ? $_GET["destdir"] : ""; ?>";
+var f_time = 1;
+var f_totaltime = 1;
+var f_cancel = false;
+var f_iOS = !!navigator.platform && /iPad|iPhone|iPod/.test(navigator.platform);
+
+//Initiate floatWindow events
+ao_module_setWindowTitle("Inflating from compressed file...");
+ao_module_setWindowIcon("loading spinner");
+
+var f_load = setInterval(function(){ 
+
+	$.ajax({
+		//url: "getMessage.php?id=" + f_rand + "messages",
+		url: "./tmp/" + f_rand + "messages",
+		contentType: "text/plain"
+	}).done(function(data) { 
+		var progress = data.match(/ ([0-9]{0,2}%)/gim);
+		console.log(progress[progress.length - 1]);
+		f_totaltime = Math.floor(f_time / (parseInt(progress[progress.length - 1])/100));
+		$("#bar").attr("style","width: " + progress[progress.length - 1]);
+		$("#time").text(f_convert(f_time));
+		$("#remaining").text(f_convert(f_totaltime - f_time));
+		$("#speed").text(f_filesize(Math.floor(f_size / f_totaltime)) + "/s");
+		$("#totalsize").text(f_filesize(f_size));
+		f_time += 1;
+	});
+	
+	/*
+	$.get("./tmp/" + f_rand + "messages", function( data ) {
+		var progress = data.match(/ ([0-9]{0,2}%)/gim);
+		console.log(progress[progress.length - 1]);
+		f_totaltime = Math.floor(f_time / (parseInt(progress[progress.length - 1])/100));
+		$("#bar").attr("style","width: " + progress[progress.length - 1]);
+		$("#time").text(f_convert(f_time));
+		$("#remaining").text(f_convert(f_totaltime - f_time));
+		$("#speed").text(f_filesize(Math.floor(f_size / f_totaltime)) + "/s");
+		$("#totalsize").text(f_filesize(f_size));
+		f_time += 1;
+	});
+	*/
+}, 1000);
+
+f_load;
+
+$.get("opr.php?method=" + f_method + "&rand=" + f_rand + "&file=" + f_file + "&dir=" + f_dir , function( raw ) {
+		clearInterval(f_load);
+		if(!f_cancel){
+			if(f_destdir.length >0){
+				//console.log('../SystemAOB/functions/file_system/move.php?from=../../../7-Zip%20File%20Manager/tmp/' + f_rand +'&to=../../' + f_destdir + f_filenameToFoldername(f_file));
+				//$.get( '../SystemAOB/functions/file_system/move.php?from=../../../7-Zip%20File%20Manager/tmp/' + f_rand +'&to=../../' + f_destdir + f_filenameToFoldername(f_file), function(data) {
+					
+				$.get( 'move.php?from=../7-Zip%20File%20Manager/tmp/' + f_rand +'&to=' + f_destdir + f_filenameToFoldername(f_file) + '&DontCreateNewFolder=' + f_DontCreateNewFolder , function(data) {
+					if(data !== "DONE"){
+						if(ao_module_virtualDesktop){
+							parent.msgbox(data,'<i class="caution sign icon"></i> 7-Zip File Manager',"");
+							ao_module_close();
+						}else{
+							msgbox(data,"","");
+							setTimeout(function(){ts('#modal').modal('hide')},1500);
+						}
+					}else{
+						f_openFile(true);
+					}
+				});
+			}else{
+				f_openFile(false);
+			}
+		}
+});
+
+function f_filenameToFoldername(path){
+	if(!f_DontCreateNewFolder){
+		var filename = path.split("\\").join("/").split("/").pop();
+		var filename = filename.split(".");
+		if (filename.length > 1){
+			filename.pop();
+		}
+		filename = filename.join(".");
+		if (filename.substring(0,5) == "inith"){
+			filename = filename.replace("inith","");
+		}
+		return filename;
+	}else{
+		return "";
+	}
+}
+
+function f_openFile(bool){
+	var Folder = "";
+	// bool = true then it have destdir
+	// bool = false then it dont have destdir
+	if(bool == true){
+		//f_method = e then it is only single file
+		//f_method = x then it is a folder
+		if(f_method == "e"){
+			Folder = f_destdir.replace("../","") + f_filenameToFoldername(f_file) + "/" + f_dir.replace(/^.*[\\\/]/, '');
+		}else if(f_method == "x"){
+			Folder = f_destdir.replace("../","") + f_filenameToFoldername(f_file);
+		}
+	}else{
+		//f_method = e then it is only single file
+		//f_method = x then it is a folder
+		if(f_method == "e"){
+			Folder = "7-Zip File Manager/tmp/" + f_rand + "/" + f_dir.replace(/^.*[\\\/]/, '');
+		}else if(f_method == "x"){
+			Folder = "7-Zip File Manager/tmp/" + f_rand + "/";
+		}
+	}
+	//console.log(f_rand + Folder);
+	if(ao_module_virtualDesktop){
+		if(f_method == "e"){
+			ao_module_openFile(Folder,"7-Zip Preview");
+		}else if(f_method == "x"){
+			ao_module_openPath(Folder);
+		}
+		ao_module_close();
+	}else{
+		if(f_method == "e"){
+			if(f_iOS){
+				window.location.replace("../" + Folder)
+			}else{
+				window.open("../" + Folder);
+			}
+		}else if(f_method == "x"){
+			if(f_iOS){
+				window.location.replace("../SystemAOB/functions/file_system/index.php?controlLv=2#../../../" + Folder)
+			}else{
+				window.open("../SystemAOB/functions/file_system/index.php?controlLv=2#../../../" + Folder);
+			}
+		}
+		setTimeout(function(){ts('#modal').modal('hide')},1500);
+	}
+}
+
+function f_convert(time){
+	var hours   = Math.floor(time / 3600);
+	var minutes = Math.floor((time - (hours * 3600)) / 60);
+	var seconds = time - (hours * 3600) - (minutes * 60);
+	
+	if(hours < 10){
+		var dhour  = "0" + hours;
+	}else{
+		var dhour  = hours;
+	}
+	
+	if(minutes < 10){
+		var dminutes  = "0" + minutes;
+	}else{
+		var dminutes  = minutes;
+	}
+
+	if(seconds < 10){
+		var dseconds  = "0" + seconds;
+	}else{
+		var dseconds  = seconds;
+	}
+	
+	if(!isNaN(hours) && !isNaN(minutes) && !isNaN(seconds)){
+		var formatted = dhour + ":" + dminutes + ":" + dseconds;
+	}else{
+		var formatted = "00:00:00";
+	}
+	return formatted;
+}
+
+function f_filesize(size){
+	if(size >= 1073741824){
+		return Math.floor(size/1073741824*100)/100 + "GB";
+	}else if(size >= 1048576){
+		return Math.floor(size/1048576*100)/100 + "MB";
+	}else if(size >= 1024){
+		return Math.floor(size/1024*100)/100 + "KB";
+	}else{
+		return size + "Bytes";
+	}
+}
+
+function msgbox(content,bgcolor,fontcolor){
+	$(".snackbar").attr("style",'background-color: ' + bgcolor + ';color:' + fontcolor);
+	ts('.snackbar').snackbar({
+		content: content,
+		onAction: () => {
+			$(".snackbar").removeAttr("style");
+		}
+	});
+}
+
+function f_close(){
+	if(ao_module_virtualDesktop){
+		ao_module_close();
+	}else{
+		setTimeout(function(){ts('#modal').modal('hide')},1500);
+	}
+}
+</script>
+</html>

+ 33 - 0
deltmp.php

@@ -0,0 +1,33 @@
+<?php
+include '../auth.php';
+?>
+<?php
+    $dirs = scandir("./tmp/");
+    foreach ($dirs as $dir){
+       $time = filectime("./tmp/".$dir) ;
+        if(($time + 3600*3 <= time() && $dir !== ".." && $dir !== ".") || $_GET["forced"] == "true"){
+            //echo "$dir Deleted.\r\n";
+            if(is_dir("./tmp/".$dir)){
+                rrmdir("./tmp/".$dir);
+            }else{
+                unlink("./tmp/".$dir);
+            }
+        }
+    }
+    echo "Completed.";
+
+//https://stackoverflow.com/questions/3338123/how-do-i-recursively-delete-a-directory-and-its-entire-contents-files-sub-dir
+ function rrmdir($dir) { 
+   if (is_dir($dir)) { 
+     $objects = scandir($dir); 
+     foreach ($objects as $object) { 
+       if ($object != "." && $object != "..") { 
+         if (is_dir($dir."/".$object))
+           rrmdir($dir."/".$object);
+         else
+           unlink($dir."/".$object); 
+       } 
+     }
+     rmdir($dir); 
+   } 
+ }