summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHorus32014-04-21 18:35:43 +0200
committerHorus32014-04-21 18:35:43 +0200
commitdef084a19a19e1d5c77600c0c0967e5a8fed5b93 (patch)
tree6b8eb4b3af0decc1d0a48dc9304789f2794fd98a
parent2a1a332c4e7625a40008d5c4565fca1bbf062d91 (diff)
downloadfiles.iamfabulous.de-def084a19a19e1d5c77600c0c0967e5a8fed5b93.tar.gz
Now you can get a full list of FILES or DIRECTORY from class files. Also changed database layout to log every up- and download.
-rwxr-xr-xblob/database_schema6
-rw-r--r--www/class.files.php (renamed from www/functions/class_files.php)42
-rw-r--r--www/functions/func_download.php5
-rw-r--r--www/functions/func_folder.php6
-rwxr-xr-xwww/functions/func_login.php2
-rwxr-xr-xwww/functions/func_register.php4
-rwxr-xr-xwww/functions/func_upload.php4
-rwxr-xr-xwww/include.php2
-rwxr-xr-xwww/index.php2
-rwxr-xr-xwww/setup.php12
10 files changed, 65 insertions, 20 deletions
diff --git a/blob/database_schema b/blob/database_schema
index d2bf0cf..eae081c 100755
--- a/blob/database_schema
+++ b/blob/database_schema
@@ -1,10 +1,10 @@
#Database schema for SQLite3 database, stored in "../database/sqlite.db", based on the "www" directory
-CREATE TABLE IF NOT EXISTS user (id INTEGER PRIMARY KEY, name TEXT UNIQUE, password TEXT, email TEXT UNIQUE, invites INTEGER, senpai INTEGER, key TEXT, status INTEGER, register TEXT, color_folder TEXT, color_file TEXT);
+CREATE TABLE IF NOT EXISTS user (id INTEGER PRIMARY KEY, name TEXT UNIQUE, password TEXT, email TEXT UNIQUE, invites INTEGER, senpai INTEGER, key TEXT, status INTEGER, register INT, color_folder TEXT, color_file TEXT);
-CREATE TABLE IF NOT EXISTS files (id INTEGER PRIMARY KEY, parent INTEGER, owner INTEGER, name TEXT, folder TEXT, mime TEXT, size INTEGER, share TEXT, hash TEXT, download_link TEXT, FOREIGN KEY(owner) REFERENCES user(id));
+CREATE TABLE IF NOT EXISTS files (id INTEGER PRIMARY KEY, parent INTEGER, owner INTEGER, name TEXT, folder TEXT, mime TEXT, size INTEGER, share TEXT, hash TEXT, download_link TEXT, upload INT, lastseen INT, FOREIGN KEY(owner) REFERENCES user(id));
-CREATE TABLE IF NOT EXISTS log (id INTEGER PRIMARY KEY, user INTEGER, login TEXT, FOREIGN KEY(user) REFERENCES user(id));
+CREATE TABLE IF NOT EXISTS log (id INTEGER PRIMARY KEY, user INTEGER, login INT, FOREIGN KEY(user) REFERENCES user(id));
CREATE TABLE IF NOT EXISTS banned_user (id INTEGER PRIMARY KEY, login_attempts, ip TEXT, session_id TEXT, time INTEGER, user INTEGER);
diff --git a/www/functions/class_files.php b/www/class.files.php
index 10182a9..7ce7d64 100644
--- a/www/functions/class_files.php
+++ b/www/class.files.php
@@ -3,6 +3,8 @@
class file {
public $file;
+ public $DirList;
+ public $FileList;
function __construct($val = null){
if($val == null){
@@ -10,6 +12,26 @@ class file {
} else {
$this->file = $val;
}
+
+ $f = $this->file;
+
+ $DirRes = false;
+ $FileRes = false;
+ $DirCnt = 0;
+ $FileCnt = 0;
+
+ for($i=0; $i<count($f); $i++){
+ if($f[$i][4] == "DIRECTORY"){
+ $DirRes[$DirCnt] = $f[$i];
+ $DirCnt++;
+ } else {
+ $FileRes[$FileCnt] = $f[$i];
+ $FileCnt++;
+ }
+ }
+
+ $this->DirList = $DirRes;
+ $this->FileList = $FileRes;
}
function NotFound(){
if($this->file == FILE_NOT_FOUND){
@@ -171,4 +193,24 @@ class file {
function getAll(){
return $this->file;
}
+ function getDirList(){
+ return $this->DirList;
+ }
+ function getFileList(){
+ return $this->FileList;
+ }
+ function getDirNum(){
+ if(!$this->DirList){
+ return false;
+ } else {
+ return count($this->DirList);
+ }
+ }
+ function getFileNum(){
+ if(!$this->FileList){
+ return false;
+ } else {
+ return count($this->FileList);
+ }
+ }
}
diff --git a/www/functions/func_download.php b/www/functions/func_download.php
index 26b25b1..576320c 100644
--- a/www/functions/func_download.php
+++ b/www/functions/func_download.php
@@ -103,17 +103,20 @@ function download_file($db, $file_id){
//TODO: buffer output, print if reading == true
header("Content-Type: ".$file_mime);
-
+/*
if(!preg_match("/^image\/.+/", $file_mime)){
header("Content-Disposition: attachment; filename=\"".$file_name."\"");
} else {
header("filename=".$file_name."");
}
+*/
+ header("filename=".$file_name."");
header("Content-Length: ".$file_size);
set_time_limit(0);
$uncompressed_file = readgzfile($gzip_file);
if($uncompressed_file){
+ $db->exec("UPDATE files SET lastseen=(SELECT strftime('%s', 'now')) WHERE id=".SQLite3::escapeString($file_id).";");
return true;
} else {
return false;
diff --git a/www/functions/func_folder.php b/www/functions/func_folder.php
index 044fd8e..f389227 100644
--- a/www/functions/func_folder.php
+++ b/www/functions/func_folder.php
@@ -3,7 +3,7 @@
function database_mkdir($db, $file_id, $new_folder_name, $share){
if($db->exec("
BEGIN TRANSACTION;
- INSERT INTO files (id, parent, owner, name, folder, size, share, hash) VALUES (Null, " . $file_id . ", " . $_SESSION['userid'] . ", '" . SQLite3::escapeString($new_folder_name) . "', 'DIRECTORY', 0, '" . SQLite3::escapeString($share) . "', '');
+ INSERT INTO files (id, parent, owner, name, folder, size, share, hash, upload, lastseen) VALUES (Null, " . $file_id . ", " . $_SESSION['userid'] . ", '" . SQLite3::escapeString($new_folder_name) . "', 'DIRECTORY', 0, '" . SQLite3::escapeString($share) . "', '', (SELECT strftime('%s', 'now')), (SELECT strftime('%s', 'now')));
COMMIT;
")){
return true;
@@ -78,7 +78,7 @@ function move_folder($old_path, $new_path){
if($db->exec("
BEGIN TRANSACTION;
- UPDATE files SET parent=".$new_file_id." WHERE id=".$old_file_id.";
+ UPDATE files SET parent=".$new_file_id.", lastseen=(SELECT strftime('%s', 'now')) WHERE id=".$old_file_id.";
COMMIT;
")){
return MV_FOLDER_SUCCESS;
@@ -116,7 +116,7 @@ function rename_folder($path, $new_name){
if($db->exec("
BEGIN TRANSACTION;
- UPDATE files SET name='".SQLite3::escapeString($new_name)."' WHERE id=".$file_id.";
+ UPDATE files SET name='".SQLite3::escapeString($new_name)."', lastseen=(SELECT strftime('%s', 'now')) WHERE id=".$file_id.";
COMMIT;
")){
return true;
diff --git a/www/functions/func_login.php b/www/functions/func_login.php
index 943e20e..6a38c3a 100755
--- a/www/functions/func_login.php
+++ b/www/functions/func_login.php
@@ -25,7 +25,7 @@ function login($db){
if($db->exec("
BEGIN TRANSACTION;
- INSERT INTO log (id, user, login) VALUES (NULL, (SELECT id FROM user WHERE name='" . $username . "'), (SELECT datetime()) );
+ INSERT INTO log (id, user, login) VALUES (NULL, (SELECT id FROM user WHERE name='" . $username . "'), (SELECT strftime('%s', 'now')) );
COMMIT;
")){
diff --git a/www/functions/func_register.php b/www/functions/func_register.php
index 90cbd7d..b848866 100755
--- a/www/functions/func_register.php
+++ b/www/functions/func_register.php
@@ -59,9 +59,9 @@ function register($db){
if($db->exec("
BEGIN TRANSACTION;
- UPDATE user SET name='" . $safe_name . "', password='" . $hash_password . "', invites=5, status=1, register=(SELECT datetime()), color_folder='DEFAULT', color_file='DEFAULT' WHERE id=" . $id . ";
+ UPDATE user SET name='" . $safe_name . "', password='" . $hash_password . "', invites=5, status=1, register=(SELECT strftime('%s', 'now')), color_folder='DEFAULT', color_file='DEFAULT' WHERE id=" . $id . ";
INSERT INTO files (id, parent, owner, name, folder, mime, size, share, size, hash) VALUES (NULL, 0, $id, '/', 'DIRECTORY', NULL, NULL, 'PUBLIC', 0, '');
- INSERT INTO log (id, user, login) VALUES (NULL, (SELECT id FROM user WHERE name='" . $safe_name. "'), (SELECT datetime()));
+ INSERT INTO log (id, user, login) VALUES (NULL, (SELECT id FROM user WHERE name='" . $safe_name. "'), (SELECT strftime('%s', 'now'));
COMMIT;")
){
diff --git a/www/functions/func_upload.php b/www/functions/func_upload.php
index 31fe304..f4f9b82 100755
--- a/www/functions/func_upload.php
+++ b/www/functions/func_upload.php
@@ -3,7 +3,7 @@
function database_upload($db, $parentdir, $owner, $filename, $folder, $mime, $size, $share, $filehash){
if($db->exec("
BEGIN TRANSACTION;
- INSERT INTO files (id, parent, owner, name, folder, mime, size, share, hash) VALUES (NULL, " . $parentdir . ", " . $owner . ", '" . $filename . "', '" . $folder . "', '" . $mime . "', '" . $size . "', '" . $share ."', '" . $filehash . "');
+ INSERT INTO files (id, parent, owner, name, folder, mime, size, share, hash, upload, lastseen) VALUES (NULL, " . $parentdir . ", " . $owner . ", '" . $filename . "', '" . $folder . "', '" . $mime . "', '" . $size . "', '" . $share ."', '" . $filehash . "', (SELECT strftime('%s', 'now')), (SELECT strftime('%s', 'now')));
COMMIT;
")){
return true;
@@ -15,7 +15,7 @@ function database_upload($db, $parentdir, $owner, $filename, $folder, $mime, $si
function database_upload_update($db, $id, $name, $mime, $size, $share, $filehash){
if($db->exec("
BEGIN TRANSACTION;
- UPDATE files SET name='".$name."', mime='".$mime."', size='".$size."', share='".$share."', hash='".$filehash."' WHERE id=".$id.";
+ UPDATE files SET name='".$name."', mime='".$mime."', size='".$size."', share='".$share."', hash='".$filehash."', lastseen=(SELECT strftime('%s', 'now')) WHERE id=".$id.";
COMMIT;
")){
return true;
diff --git a/www/include.php b/www/include.php
index 11d5451..39926f6 100755
--- a/www/include.php
+++ b/www/include.php
@@ -14,7 +14,7 @@ require_once("constants.php");
$func_dir = "functions/";
-require_once($func_dir . "class_files.php");
+require_once("class.files.php");
require_once($func_dir . "func_failure.php"); // 404 and other errors
require_once($func_dir . "func_interface.php"); // presents the vfs content
diff --git a/www/index.php b/www/index.php
index 333d02e..713e1f8 100755
--- a/www/index.php
+++ b/www/index.php
@@ -149,7 +149,7 @@ if(empty($_GET)){
if($f->isFile()){
start_file_download($_GET["name"], $_GET["folder"]);
} else {
- if($f->notFound()){
+ if($f->NotFound()){
$content = get_path_to_wrong_folder($db, $_GET["name"], $_GET["folder"]);
print_wrong_folder($content);
} elseif ($f->isEmpty()){
diff --git a/www/setup.php b/www/setup.php
index 8d56f6e..d26cdda 100755
--- a/www/setup.php
+++ b/www/setup.php
@@ -52,11 +52,11 @@ if($bool){
if($db->exec("
BEGIN TRANSACTION;
- CREATE TABLE IF NOT EXISTS user (id INTEGER PRIMARY KEY, name TEXT UNIQUE, password TEXT, email TEXT UNIQUE, invites INTEGER, senpai INTEGER, key TEXT, status INTEGER, register TEXT, color_folder TEXT, color_file TEXT);
- INSERT INTO user (id, name, senpai, key, status, invites, password, email, register, color_folder, color_file) VALUES (NULL, 'admin', 0, '11111', 1, 5, '" . $hash_password . "', '" . $email . "', (SELECT datetime()), 'DEFAULT', 'DEFAULT' );
- CREATE TABLE IF NOT EXISTS files (id INTEGER PRIMARY KEY, parent INTEGER, owner INTEGER, name TEXT, folder TEXT, mime TEXT, size INTEGER, share TEXT, hash TEXT, download_link TEXT, FOREIGN KEY(owner) REFERENCES user(id));
- INSERT INTO files (id, parent, owner, name, folder, size, share, hash, download_link) VALUES (NULL, 0, 1, '/', 'DIRECTORY', 0, 'HIDDEN', '', '');
- CREATE TABLE IF NOT EXISTS log (id INTEGER PRIMARY KEY, user INTEGER, login TEXT, FOREIGN KEY(user) REFERENCES user(id));
+ CREATE TABLE IF NOT EXISTS user (id INTEGER PRIMARY KEY, name TEXT UNIQUE, password TEXT, email TEXT UNIQUE, invites INTEGER, senpai INTEGER, key TEXT, status INTEGER, register INT, color_folder TEXT, color_file TEXT);
+ INSERT INTO user (id, name, senpai, key, status, invites, password, email, register, color_folder, color_file) VALUES (NULL, 'admin', 0, '11111', 1, 5, '" . $hash_password . "', '" . $email . "', (SELECT strftime('%s', 'now')), 'DEFAULT', 'DEFAULT' );
+ CREATE TABLE IF NOT EXISTS files (id INTEGER PRIMARY KEY, parent INTEGER, owner INTEGER, name TEXT, folder TEXT, mime TEXT, size INTEGER, share TEXT, hash TEXT, download_link TEXT, upload INT, lastseen INT, FOREIGN KEY(owner) REFERENCES user(id));
+ INSERT INTO files (id, parent, owner, name, folder, size, share, hash, download_link, upload, lastseen) VALUES (NULL, 0, 1, '/', 'DIRECTORY', 0, 'HIDDEN', '', '', (SELECT strftime('%s', 'now')), (SELECT strftime('%s', 'now')));
+ CREATE TABLE IF NOT EXISTS log (id INTEGER PRIMARY KEY, user INTEGER, login INT, FOREIGN KEY(user) REFERENCES user(id));
CREATE TABLE IF NOT EXISTS banned_user (id INTEGER PRIMARY KEY, login_attempts INTEGER, ip TEXT, session_id TEXT, time INTEGER, user INTEGER);
CREATE TRIGGER IF NOT EXISTS delete_files AFTER DELETE ON user FOR EACH ROW BEGIN DELETE FROM files WHERE owner=OLD.id; END;
COMMIT;")
@@ -65,9 +65,9 @@ if($bool){
$_SESSION["username"] = "admin";
$_SESSION["userid"] = 1;
+ include("include.php");
header("Refresh: 2; ".$scheme.$_SERVER["HTTP_HOST"]."/admin");
echo "Success! You will redirected any moment.";
- include("include.php");
} else {
echo "Failure! :( <br>";
echo "Your password: ".$hash_password;