Browse Source

Upload files to 'QuickSend'

Yeung Alan 5 years ago
parent
commit
b763b48d2a
7 changed files with 537 additions and 0 deletions
  1. 104 0
      QuickSend/access.php
  2. 1 0
      QuickSend/data.json
  3. 59 0
      QuickSend/download.php
  4. 60 0
      QuickSend/i18n.js
  5. 43 0
      QuickSend/include.php
  6. 241 0
      QuickSend/index.php
  7. 29 0
      QuickSend/opr.php

+ 104 - 0
QuickSend/access.php

@@ -0,0 +1,104 @@
+<?php
+$data = json_decode(file_get_contents("data.json"),true)[$_GET["sharingid"]];
+function formatSizeUnits($bytes){
+        if ($bytes >= 1073741824){
+            $bytes = number_format($bytes / 1073741824, 2) . ' GB';
+        }elseif ($bytes >= 1048576){
+            $bytes = number_format($bytes / 1048576, 2) . ' MB';
+        }elseif ($bytes >= 1024){
+            $bytes = number_format($bytes / 1024, 2) . ' KB';
+        }elseif ($bytes > 1){
+            $bytes = $bytes . ' bytes';
+        }elseif ($bytes == 1){
+            $bytes = $bytes . ' byte';
+        }else{
+            $bytes = '0 bytes';
+        }
+        return $bytes;
+}
+?>
+<!DOCTYPE html>
+<meta name="apple-mobile-web-app-capable" content="yes" />
+<meta name="viewport" content="user-scalable=no, width=device-width, initial-scale=1, maximum-scale=1"/>
+<html>
+<head>
+<script type='text/javascript' charset='utf-8'>
+    // Hides mobile browser's address bar when page is done loading.
+      window.addEventListener('load', function(e) {
+        setTimeout(function() { window.scrollTo(0, 1); }, 1);
+      }, false);
+</script>
+<meta charset="UTF-8">
+<title>Quick Send</title>
+<link rel="stylesheet" href="../script/tocas/tocas.css">
+<style>
+.outer-div
+{
+     display: table;
+     position: absolute;
+     height: 100%;
+     width: 100%;
+}
+.mid-div
+{
+     display: table-cell;
+     vertical-align: middle;
+}
+.center-div
+{
+     margin: 0 auto;
+     width: 300px;
+     height: 100px;
+}
+</style>
+</head>
+<body>
+<br>
+<div class="outer-div"><div class="mid-div"><div class="center-div">
+
+<div class="ts container" style="margin: auto;margin: auto;margin-top: 30vh;text-align: center">
+	<div class="ts segment">
+		<h3 class="ts center aligned icon header">
+			<i id="icn" class="file outline icon"></i><?php echo pathinfo($data["path"],PATHINFO_BASENAME); ?>
+			<div class="sub header"><?php echo formatSizeUnits(filesize($data["path"])); ?></div>
+		</h3>
+		<?php if(isset($data["password"])){ ?>
+		<br>
+		<div class="ts fluid input">
+			<input id="pwd" type="password" placeholder="Verification Code">
+		</div>
+		<br>
+		<?php } ?>
+		<br>
+		<button onclick="download()" class="ts fluid button">Download</button>
+	<div>
+</div>
+
+</div></div></div>
+<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js"></script>
+<script src="../script/tocas/tocas.js"></script>
+<script src="../script/ao_module.js"></script>
+<script>
+var sharingid = "<?php echo $_GET["sharingid"]; ?>";
+var ext = ao_module_utils.getIconFromExt("<?php echo pathinfo($data["path"],PATHINFO_EXTENSION) ?>");
+$("#icn").attr("class",ext + " icon");
+
+function download(){
+	if($("#pwd").length){
+		$.get( "download.php?sharingid=" + sharingid + "&chkpassword=" + $("#pwd").val(), function( data ) {
+			if(data){
+				window.location = "download.php?sharingid=" + sharingid + "&password=" + $("#pwd").val();
+			}else{
+				console.log("Incorrect");
+			}
+		});
+	}else{
+		window.location = "download.php?sharingid=" + sharingid;
+	}
+}
+
+var lan = JSON.parse('{"zh-TW":{"%n KB":"%n千位元組","%n MB":"%n百萬位元組","%n GB":"%n吉位元組","%n TB":"%n兆位元組","%n PB":"%n拍位元組","%n EB":"%n艾位元組","%n ZB":"%n皆位元組","%n YB":"%n佑位元組","Verification Code":"驗證碼","Download":"下載"},"en-US":{"%nKB":"%nKiloByte","%nMB":"%nMegaByte","%nGB":"%nGigaByte","%nTB":"%nTeraByte","%nPB":"%nPetaByte","%nEB":"%nExaByte","%nZB":"%nZettaByte","%nYB":"%nYottaByte","Verification Code":"Verification Code","Download":"Download"}}');
+</script>
+<script src="i18n.js"></script>
+</body>
+</html>

+ 1 - 0
QuickSend/data.json

@@ -0,0 +1 @@
+{"xPJpWgckr":{"path":"..\/Desktop\/files\/admin\/paint_20190627140209.png","secure_sharing":true,"sharewith":["admin"],"startd":"2009-10-21","startt":"10:00","stopd":"2019-10-11","stopt":"11:00","remain":"25"},"AQbycWqrM":{"path":"..\/Desktop\/files\/admin\/123.png","secure_sharing":false},"3ZrRCYkQp":{"path":"..\/Desktop\/files\/admin\/paint_20190627140209.png","secure_sharing":true,"password":"1234"}}

+ 59 - 0
QuickSend/download.php

@@ -0,0 +1,59 @@
+<?php
+  define("CHUNK_SIZE", 1024*1024); // Size (in bytes) of tiles chunk
+
+  // Read a file and display its content chunk by chunk
+  function readfile_chunked($filename, $retbytes = TRUE) {
+    $buffer = "";
+    $cnt =0;
+    // $handle = fopen($filename, "rb");
+    $handle = fopen($filename, "rb");
+    if ($handle === false) {
+      return false;
+    }
+    while (!feof($handle)) {
+      $buffer = fread($handle, CHUNK_SIZE);
+      echo $buffer;
+      ob_flush();
+      flush();
+      if ($retbytes) {
+        $cnt += strlen($buffer);
+      }
+    }
+    $status = fclose($handle);
+    if ($retbytes && $status) {
+      return $cnt; // return num. bytes delivered like readfile() does.
+    }
+    return $status;
+  }
+
+  // Here goes your code for checking that the user is logged in
+  // ...
+  // ...
+  
+  $data = json_decode(file_get_contents("data.json"),true)[$_GET["sharingid"]];
+  
+  if(isset($_GET["chkpassword"])){
+	 if($_GET["chkpassword"] == $data["password"]){
+		echo true;
+	 }else{
+		echo false;
+	 }
+  }else{
+	  $logged_in = false;
+	  if($_GET["password"] == $data["password"]){
+		$logged_in = true;
+	  }
+	  
+	  if ($logged_in) {
+		$filename = $data["path"];
+		//$mimetype = "mime/type";
+		$mimetype = mime_content_type($filename);
+		header("Content-length:".filesize($filename));
+		header("Content-Type: ".$mimetype );
+		readfile_chunked($filename);
+	  }
+	  else {
+		echo "Tabatha says you haven\"t paid.";
+	  }
+  }
+?>

+ 60 - 0
QuickSend/i18n.js

@@ -0,0 +1,60 @@
+if(lan !== undefined){
+	var syslang = navigator.language;
+	var ContainsNonTagElement = [];
+	$.each($("*"), function( index, value ) {
+		//to check if the element was the script or style, if it is script or style then skip it
+		if($(value)[0].tagName.toUpperCase() !== "SCRIPT" && $(value)[0].tagName.toUpperCase() !== "STYLE"){
+			//if the element doesn't contains any children element
+			if(!$(value).children().length){
+				//check if it is textbox, if true then show placeholder
+				if($(value).attr("placeholder") !== undefined){
+					var t = $(value).attr("placeholder").trim();
+					if(t.length > 0){
+						$(value).attr("placeholder",intl_convert(syslang,t));
+					}
+				}
+				//if it is normal text, display the text
+				if($(value).html() !== undefined){
+					var t = $(value).text().trim();
+					if(t.length > 0){
+						$(value).html($(value).html().replace(t,intl_convert(syslang,t)));
+					}
+				}
+			}else{
+				//if it still contains some child element, then try to remove all element and check if there contains any text
+				//if we find any, then store it and process it later.
+				var t = $(value).clone().children().remove().end().text().trim();
+				if(t.length > 0){
+					ContainsNonTagElement.push($(value))
+				}
+			}
+		}
+	});
+	$.each(ContainsNonTagElement, function( index, value ) {
+		var t = $(value).clone().children().remove().end().text().trim();
+		if(t.length > 0){
+			$(value).html($(value).html().replace(t,intl_convert(syslang,t)));
+		}
+	});
+}else{
+	throw "No language file was find, include variable lan and try again.";
+}
+
+function intl_convert(lang,t){
+	if(lan == undefined){
+		throw "No language file was find, include variable lan and try again.";
+	}
+	var r = new RegExp("[0-9,.]+");
+	var num_part = t.match(r);
+	if(num_part == null){
+		num_part = "";
+	}
+	var text_part = t.replace(r,"");
+	if(lan[lang][t.replace(r,"%n")] !== undefined){
+		var convertedtext = lan[lang][t.replace(r,"%n")].replace("%n",num_part);
+	}else{
+		var convertedtext = t;
+	}
+	console.log("Number part: " + num_part + "\nText part: " + text_part + "\nInput text: " + t + "\nProcessed text: " + t.replace(r,"%n") + "\nConverted: " + convertedtext);
+	return convertedtext;
+}

+ 43 - 0
QuickSend/include.php

@@ -0,0 +1,43 @@
+<?php
+class QS{
+	function getUsernameList(){
+		$databasePath = "";
+		if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
+				$rootPath = "C:/AOB/";
+			}else{
+				$rootPath = "/etc/AOB/";
+		}
+		if (filesize("root.inf") > 0){
+			//Use the special path instead.
+			$rootPath = trim(file_get_contents("root.inf"));
+		}
+		$databasePath = $rootPath . "whitelist.config";
+		$authdata =  file_get_contents($databasePath);
+		$usernameList = [];
+		foreach(explode("\n",$authdata) as $value){
+			 array_push($usernameList,explode(",",$value)[0]);
+		}
+		array_pop($usernameList);
+		return $usernameList;
+	}
+	
+	function filepath($str){
+		return '"'.explode("<and>",explode("file_request=../../",$str)[1])[0].'"';
+	}
+	
+	function checkfileexist($str){
+		$path = $this->filepath($str);
+		$path = str_replace('"',"",$path);
+		return file_exists($path) ? "true" : "false";
+	}
+
+	function arr2jsarr($arr){
+		$str = "[";
+		foreach($arr as $value){
+			 $str = $str.'"'.$value.'",';
+		}
+		$str = substr($str, 0, -1);
+		$str = $str."]";
+		return $str;
+	}
+}

+ 241 - 0
QuickSend/index.php

@@ -0,0 +1,241 @@
+<?php
+if(isset($_GET["sharingid"])){
+	header("Location: access.php?sharingid=".$_GET["sharingid"]);
+}
+?>
+<!DOCTYPE html>
+<meta name="apple-mobile-web-app-capable" content="yes" />
+<meta name="viewport" content="user-scalable=no, width=device-width, initial-scale=1, maximum-scale=1"/>
+<html>
+<head>
+<script type='text/javascript' charset='utf-8'>
+    // Hides mobile browser's address bar when page is done loading.
+      window.addEventListener('load', function(e) {
+        setTimeout(function() { window.scrollTo(0, 1); }, 1);
+      }, false);
+</script>
+<meta charset="UTF-8">
+<title>Quick Send</title>
+<link rel="stylesheet" href="../script/tocas/tocas.css">
+</head>
+<body>
+<br>
+<div class="ts container">
+<div class="ts menu">
+<a class="item">Functions</a>
+<a class="item" onclick="ts('#modal').modal('show')">Vaildity Period</a>
+<a class="item">QR-Code</a>
+</div>
+
+<div class="ts text segment">
+    <div class="ts segment">
+	<div class="ts horizontal form">
+    <div class="field">
+        <label>File path</label>
+       <input type="text" id="path">
+    </div>
+    <div class="field">
+        <label>Shared Link</label>
+        <input type="text" id="link">
+    </div>
+    <div class="field">
+        <div class="ts checkbox">
+            <input id="secure_sharing" type="checkbox" id="secure_sharing">
+            <label for="secure_sharing">Enable secure sharing</label>
+        </div>
+    </div>
+	 <div class="field">
+        <label>Share with</label>
+        <div class="ts checkboxes" style="width:100%">
+            <div class="ts disabled radio checkbox" id="cuser">
+                <input id="onlineuser" type="radio" name="method">
+                <label for="onlineuser">ArOZ Online Users</label>
+            </div>
+			<select id="userList" disabled>
+			</select>
+			<br><br>
+            <div class="ts disabled radio checkbox" id="cpwdm">
+                <input id="pwdm" type="radio" name="method">
+                <label for="pwdm">Password</label>
+            </div>
+			<input type="password" id="pwd" disabled>
+        </div>
+    </div>
+</div>
+<br>
+	<div class="ts container" align="right">
+	<button class="ts tiny basic button" onclick="senddata()">Save</button>
+	</div>
+	</div>
+</div>
+
+</div>
+</div>
+<div class="ts modals dimmer">
+<dialog id="modal" class="ts fullscreen modal">
+    <div class="header">
+        Customize Validity Period
+    </div>
+    <div class="content">
+	<form class="ts form">
+		<div class="field">
+			<div class="ts checkbox" id="cstart">
+				<input id="startt" type="checkbox">
+				<label for="startt">Setup start time</label>
+			</div>
+		</div>
+		<div class="inline field">
+			<div class="eight wide field">
+				<input id="startt1" type="text" placeholder="Start date (YYYY-mm-dd)" disabled>
+			</div>
+			<div class="eight wide field">
+				<input id="startt2" type="text" placeholder="Start time (HH:mm)" disabled>
+			</div>
+		</div>
+		<div class="field">
+			<div class="ts checkbox" id="cstop">
+				<input id="stopt" type="checkbox">
+				<label for="stopt">Setup stop time</label>
+			</div>
+		</div>
+		<div class="inline field">
+			<div class="eight wide field">
+				<input id="stoptt1" type="text" placeholder="Stop date (YYYY-mm-dd)" disabled>
+			</div>
+			<div class="eight wide field">
+				<input id="stoptt2" type="text" placeholder="Stop time (HH:mm)" disabled>
+			</div>
+		</div>
+		<div class="field">
+			<div class="ts checkbox" id="cnumall">
+				<input id="numalla" type="checkbox">
+				<label for="numalla">Number of allowed access</label>
+			</div>
+		</div>
+		<div class="field">
+			<label>Remaining access times:</label>
+			<input id="numallt" type="text" disabled>
+		</div>
+		</form>
+    </div>
+    <div class="actions">
+        <button class="ts positive button">
+            Save
+        </button>
+    </div>
+</dialog>
+</div>
+<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js"></script>
+<script src="../script/tocas/tocas.js"></script>
+<script src="../script/ao_module.js"></script>
+
+<?php
+include "include.php";
+$a = new QS();
+?>
+<script>
+if(ao_module_virtualDesktop){
+	ao_module_setWindowSize(810,540);
+}
+var usernameList = <?php echo $a->arr2jsarr($a->getUsernameList()); ?>;
+var filepath = <?php echo $a->filepath($_GET["share"]); ?>;
+var file_exist = <?php echo $a->checkfileexist($_GET["share"]); ?>;
+
+//https://stackoverflow.com/questions/38620152/pick-a-random-letter-from-string-in-javascript
+var randomID = "";
+var alphabet = "abcdefghjkmnpqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ123456789";
+while (randomID.length < 9) {
+  randomID += alphabet[Math.floor(Math.random() * alphabet.length)];
+}
+
+$("#path").val(filepath.replace("../","/AOR/"));
+$("#link").val(window.location["href"].replace(/\?share=.*/,"?sharingid=" + randomID));
+
+for(i=0;i<usernameList.length;i++){
+	$('#userList').append(new Option(usernameList, usernameList))
+}
+
+$("#onlineuser").attr("checked",true);
+
+var securetype = "nil";
+var vstart = "no";
+var vstop = "no";
+var vaccess = "no";
+
+$("#secure_sharing").change(function() {
+	if($("#secure_sharing").attr("checked")){
+		$(".ts.disabled.radio.checkbox").attr("class","ts radio checkbox");
+		if($("#pwdm").attr("checked")){
+			$("#pwd").removeAttr("disabled");
+			securetype = "pwd";
+		}else{
+			$("#userList").removeAttr("disabled");
+			securetype = "user";
+		}
+	}else{
+		$(".ts.radio.checkbox").attr("class","ts disabled radio checkbox");
+		$("#userList").attr("disabled","disabled");
+		$("#pwd").attr("disabled","disabled");
+		securetype = "nil"
+	}
+});
+
+$("#cuser").change(function() {
+	if($("#onlineuser").attr("checked")){
+		$("#userList").removeAttr("disabled");
+		$("#pwd").attr("disabled","disabled");
+		securetype = "user";
+	}
+});
+$("#cpwdm").change(function() {
+	if($("#pwdm").attr("checked")){
+		$("#userList").attr("disabled","disabled");
+		$("#pwd").removeAttr("disabled");
+		securetype = "pwd";
+	}
+});
+
+$("#cstart").change(function() {
+	if($("#startt").attr("checked")){
+		$("#startt1").removeAttr("disabled");
+		$("#startt2").removeAttr("disabled");
+		vstart = "yes";
+	}else{
+		$("#startt1").attr("disabled","disabled");
+		$("#startt2").attr("disabled","disabled");
+		vstart = "no";
+	}
+});
+$("#cstop").change(function() {
+	if($("#stopt").attr("checked")){
+		$("#stoptt1").removeAttr("disabled");
+		$("#stoptt2").removeAttr("disabled");
+		vstop = "yes";
+	}else{
+		$("#stoptt1").attr("disabled","disabled");
+		$("#stoptt2").attr("disabled","disabled");
+		vstop = "no";
+	}
+});
+$("#cnumall").change(function() {
+	if($("#numalla").attr("checked")){
+		$("#numallt").removeAttr("disabled");
+		vaccess = "yes";
+	}else{
+		$("#numallt").attr("disabled","disabled");
+		vaccess = "no";
+	}
+});
+
+function senddata(){
+	$.post( "opr.php", { path: ".." + $("#path").val().substring(4), id: randomID, secure_sharing: securetype, userList: $("#userList").val(), pwd: $("#pwd").val(), isstart: vstart, isstop: vstop, is_access: vaccess, startd: $("#startt1").val(), startt: $("#startt2").val(), stopd: $("#stoptt1").val(), stopt: $("#stoptt2").val(), numaccess: $("#numallt").val() }, function( data ) {
+		console.log("OKAY!");
+	}, "json");
+}
+
+
+var lan = JSON.parse('{"zh-TW":{"File path":"檔案路徑","Shared Link":"分享連結","Enable secure sharing":"啟動安全分享","ArOZ Online Users":"ArOZ Online使用者","Password":"密碼","Share with": "分享給其他人","QR-Code":"取得QR碼","Functions": "功能","Vaildity Period":"有效期間","Customize Validity Period":"自訂有效期間","Setup start time":"設定開始時間","Start date":"開始日期","Start time":"開始時間","Setup stop time":"設定結束時間","Stop date":"結束日期","Stop time":"結束時間","Number of allowed access":"可存取次數","Remaining access times":"剩餘存取次數"},"zh-HK":{},"en-US":{}}');
+</script>
+<script src="i18n.js"></script>
+</body>
+</html>

+ 29 - 0
QuickSend/opr.php

@@ -0,0 +1,29 @@
+<?php
+$data = json_decode(file_get_contents("data.json"),true);
+$id = $_POST["id"];
+$data[$id]["path"] = $_POST["path"];
+if($_POST["secure_sharing"] == "nil"){
+	$data[$id]["secure_sharing"] = false;
+}else{
+	$data[$id]["secure_sharing"] = true;
+	if($_POST["secure_sharing"] == "user"){
+		$data[$id]["sharewith"] = array($_POST["userList"]);
+	}else if($_POST["secure_sharing"] == "pwd"){
+		$data[$id]["password"] = $_POST["pwd"];
+	}
+}
+if($_POST["isstart"] == "yes"){
+	$data[$id]["startd"] = $_POST["startd"];
+	$data[$id]["startt"] = $_POST["startt"];
+}
+
+if($_POST["isstop"] == "yes"){
+	$data[$id]["stopd"] = $_POST["stopd"];
+	$data[$id]["stopt"]= $_POST["stopt"];
+}
+
+if($_POST["is_access"] == "yes"){
+	$data[$id]["remain"] = $_POST["numaccess"];
+}
+
+file_put_contents("data.json",json_encode($data));