diff options
| author | moehm | 2014-03-19 17:39:48 +0100 |
|---|---|---|
| committer | moehm | 2014-03-19 17:39:48 +0100 |
| commit | c526938c960524e8e79124890875cd7afeae1d7f (patch) | |
| tree | fd47ad71e1f96cdd3866bc5495226bc0f4d6e79f | |
| parent | 716707414f1ef931ba33abb4f508bf53a5b3564c (diff) | |
| download | files.iamfabulous.de-c526938c960524e8e79124890875cd7afeae1d7f.tar.gz | |
Added func_download and func_delete.
| -rw-r--r-- | www/constants.php | 9 | ||||
| -rw-r--r-- | www/functions/func_delete.php | 83 | ||||
| -rw-r--r-- | www/functions/func_download.php | 67 | ||||
| -rwxr-xr-x | www/functions/func_select.php | 4 | ||||
| -rwxr-xr-x | www/include.php | 2 |
5 files changed, 163 insertions, 2 deletions
diff --git a/www/constants.php b/www/constants.php index 9595cc3..2984c3a 100644 --- a/www/constants.php +++ b/www/constants.php @@ -47,3 +47,12 @@ define("UPLOAD_MOVING", 36); define("UPLOAD_DUPLICATE", 37); define("MKDIR_SLASH_IN_FOLDER_NAME", 38); //check TODO + +define("DELETE_FILE_SUCCESS", 39); +define("DELETE_FILE_DATABASE", 40); +define("DELETE_FILE_UNLINK", 41); +define("DELETE_FILE_NO_FILE", 42); + +define("DELETE_USER_SUCCESS", 43); +define("DELETE_USER_FILE_DELETE", 44); +define("DELETE_USER_DATABASE", 45); diff --git a/www/functions/func_delete.php b/www/functions/func_delete.php new file mode 100644 index 0000000..2dab9e2 --- /dev/null +++ b/www/functions/func_delete.php @@ -0,0 +1,83 @@ +<?php + +function delete_file($user, $path){ + $db = $GLOBALS["db"]; + $uploaddir = "../files/"; + + $file_id = select_file_id($db, $user, $path); + + $check_if_file_db = $db->query("SELECT folder, hash FROM files WHERE id=".$file_id.";"); + $check_if_file_ar = $check_if_file_db->fetchArray(SQLITE3_NUM); + + if($check_if_file_ar[0] != "FILE"){ + return DELETE_FILE_NO_FILE; + } + + $file_hash = $check_if_file_ar[1]; + + if(!unlink($uploaddir.$file_hash.".gz")){ + return DELETE_FILE_UNLINK; + } + + if($db->exec(" + BEGIN TRANSACTION; + DELETE FROM files WHERE id=".$file_id."; + COMMIT; + ")){ + return DELETE_FILE_SUCCESS; + } else { + return DELETE_FILE_DATABASE; + } +} + +function delete_user($user){ + $db = $GLOBALS["db"]; + $uploaddir = "../files/"; + + $owner = user_id($db, $user); + + $hash_array_db = $db->query("SELECT hash FROM files WHERE folder='FILE' AND owner=".$owner.";"); + + $count = 0; + while($row1 = $hash_array_db->fetchArray(SQLITE3_NUM)){ + $hash_ar[$count] = $row1[0]; + $count++; + } + + $count = 0; + + for($i=0; $i<count($hash_ar); $i++){ + $file_id_owner_db = $db->query("SELECT id, owner FROM files WHERE folder='FILE' AND hash=".$hash_ar[$i].";"); + while($row2 = $file_id_owner->fetchArray(SQLITE3_NUM)){ + if($row2[1] != $_SESSION["userid"]){ + $saved_files[$count] = $hash_ar[$i]; + } + $count++; + } + } + + for($i=0; $i<count($saved_files); $i++){ + $cur = $saved_files[$i]: + for($j=0;$j<count($hash_ar); $j++){ + if($cur == $hash_ar[$j]){ + $hash_ar[$j] = ""; + } + } + } + + for($i=0; $<count($hash_ar); $i++){ + if(!unlink($uploaddir.$hash_ar[$i].".gz")){ + return DELETE_USER_FILE_DELETE; + } + } + + if($db->exec(" + BEGIN TRANSACTION; + DELETE FROM user WHERE id=".$owner."; + COMMIT; + ")){ + return DELETE_USER_SUCCESS; + } else { + return DELETE_USER_DATABASE; + } +} diff --git a/www/functions/func_download.php b/www/functions/func_download.php new file mode 100644 index 0000000..91c8085 --- /dev/null +++ b/www/functions/func_download.php @@ -0,0 +1,67 @@ +<?php + +function start_file_download($user, $path){ + + $db = $GLOBALS["db"]; + + $owner = user_id($db, $user); + + $file_id = select_file_id($db, $owner, $path) + +/* $file_id_db = $db->query("SELECT id, owner, share FROM files WHERE parent=" . $folder_id . "); + $file_id_ar = $file_id_db->fetchArray(SQLITE3_NUM); + $file_id = $file_id_ar[0]; + + $check_verification_db = $ + $check_verification_ar[1]; + $share = $check_verification_ar[2]; + + + if($_SESSION["login"] && ($_SESSION["userid"] == $file_owner)){ + $var = download_file($db, $file_id); + } else { + if($share != "PUBLIC"){ + return false; + } + + $var = download_file($db, $file_id); + } +*/ + + $var = download_file($db, $file_id); + + return $var; +} + +function check_file_hash($db, $file_id, $download_hash){ + $check_hash_db = $db->query("SELECT share FROM files WHERE id=" . SQLite3::escapeString($file_id).";"); + $check_hash_ar = $check_hash_db->fetchArray(SQLITE3_NUM); + + if(($check_hash_ar[0] != "PUBLIC") || ($check_hash_ar[0] != $download_hash)){ + return false; + } + + $var = download_file($db, $file_id); + return $var; + +} + +function download_file($db, $file_id){ + + $file_db = $db->query("SELECT name, mime, hash FROM files WHERE id=". SQLite3::escapeString($file_id).";"); + $file_ar = $file_db->fetchArray(SQLITE3_NUM); + $file_name = $file_ar[0]; + $file_mime = $file_ar[1]; + $file_hash = $file_ar[2]; + + $uploaddir = "../files/"; + $gzip_file = $uploaddir . $file_hash . ".gz"; + $fp = gzopen($gzip_file, '') // TODO: DECOMPRESS CONSTANT + + //TODO GZIP DECOMPRESSION + + //TODO set HTTP HEADER + + return true; + +} diff --git a/www/functions/func_select.php b/www/functions/func_select.php index 2acfb93..a720feb 100755 --- a/www/functions/func_select.php +++ b/www/functions/func_select.php @@ -24,12 +24,12 @@ function select_file_id($db, $owner, $folder_path){ for($i=0; $i<$length; $i++){ - $parentdir_db = $db->query("SELECT id, parent FROM files WHERE owner=" . $owner . " AND folder='DIRECTORY' " . $share . " AND parent=" . $parentdir . " AND name='" . SQLite3::escapeString($folder_array_unsafe[$i]) . "';"); + $parentdir_db = $db->query("SELECT id, parent FROM files WHERE owner=" . $owner . " AND " . $share . " AND parent=" . $parentdir . " AND name='" . SQLite3::escapeString($folder_array_unsafe[$i]) . "';"); $prim_id = $parentdir_db->fetchArray(SQLITE3_NUM); if(empty($prim_id[0])){ - return $parentdir; + return $parentdir; //TODO; Return false because file not found } if($parentdir != $prim_id[1]){ diff --git a/www/include.php b/www/include.php index dc8ca72..98c6b8e 100755 --- a/www/include.php +++ b/www/include.php @@ -15,6 +15,8 @@ require_once($func_dir . "func_user.php"); // gets the userid and account speci require_once($func_dir . "func_content.php"); // get the vfs content require_once($func_dir . "func_password.php"); // changes the user password require_once($func_dir . "func_folder.php"); // creates a new folder +require_once($func_dir . "func_delete.php"); // deletes files, folder and user +require_once($func_dir . "func_download.php"); // handles the file download require_once("login.php"); // prints the login page require_once("register.php"); // prints the register page |
