FILEUP



LOG | FILES | OVERVIEW


F diff --git a/css/style.css b/css/style.css --- a/css/style.css +++ b/css/style.css
to { opacity: 1; }
}
- input:not([type=file]) {
+ .content > input {
min-width: 300px;
+ }
+
+ input:not([type=file]) {
border: 1px solid #bbb;
- padding: 0.5rem;
+ padding: 0.8rem 2rem 0.5rem 2rem;
font-size: inherit;
font-family: inherit;
border-radius: 0.3rem;
- background: #fdfdfd;
- transition: background 0.15s, border-color 0.35s;
+ background: #f6f6f6;
}
- input[type=submit] {
+ input[type=button], button, input[type=submit] {
cursor: pointer;
+ }
+ input[type=button]:hover, button:hover, input[type=submit]:hover {
+ background: white;
+ }
+
+ input[type=submit] {
margin-top: 2rem;
width: 100%;
display: block;
z-index: -200;
}
- #signupform {
+ #loginform {
display: none;
}
F diff --git a/loggedin.js b/loggedin.js new file mode 100644 --- /dev/null +++ b/loggedin.js
+ const upload_form = document.getElementById("upload_form");
+ const the_file = document.getElementById("the_file");
+ const filename_input = document.getElementById("filename");
+ const upload_btn = document.getElementById("upload_btn");
+
+ the_file.onchange = on_file_added;
+
+ function on_file_added(e) {
+ if (the_file.files.length >= 1) {
+ filename_input.value = the_file.files[0].name;
+
+ // Send the form asynchronously through the fetch api
+ fetch(upload_form.action, {
+ method: upload_form.method,
+ body: new FormData(upload_form)
+ })
+
+ alert("Sent the upload request");
+ }
+ else {
+ alert("No files selected");
+ }
+
+ }
+
+ function begin_upload() {
+ the_file.click();
+ }
F diff --git a/loggedin.php b/loggedin.php --- a/loggedin.php +++ b/loggedin.php
+
<div>
<div class="filesystem">
-
- <h2>
+ <h2 style="display: flex; gap: 1rem;">
<div class="path">
<a class="pathentry" href="#"> <?php echo $_SESSION['username'] ?>'s files/</a><a class="pathentry" href="#">foo/</a><a class="pathentry" href="#">bar</a></div>
- <input type="button" value="New Folder">
+ <input id="upload_btn" type="button" value="Upload" onclick="begin_upload()">
</h2>
<div class="files">
<img src="/mimeicons/application-pdf.png">
<div class="filename">asdf</div>
</div>
- <div class="file">
- <img src="/mimeicons/application-pdf.png">
- <div class="filename">asdf</div>
- </div>
- <div class="file">
- <img src="/mimeicons/application-pdf.png">
- <div class="filename">asdf</div>
- </div>
- <div class="file">
- <img src="/mimeicons/application-pdf.png">
- <div class="filename">asdf</div>
- </div>
- <div class="file">
- <img src="/mimeicons/application-pdf.png">
- <div class="filename">asdf</div>
- </div>
- <div class="file">
- <img src="/mimeicons/application-pdf.png">
- <div class="filename">asdf</div>
- </div>
- <div class="file">
- <img src="/mimeicons/application-pdf.png">
- <div class="filename">asdf</div>
- </div>
- <div class="file">
- <img src="/mimeicons/application-pdf.png">
- <div class="filename">asdf</div>
- </div>
- <div class="file">
- <img src="/mimeicons/application-pdf.png">
- <div class="filename">asdf</div>
- </div>
- <div class="file">
- <img src="/mimeicons/application-pdf.png">
- <div class="filename">asdf</div>
- </div>
- <div class="file">
- <img src="/mimeicons/application-pdf.png">
- <div class="filename">asdf</div>
- </div>
- <div class="file">
- <img src="/mimeicons/application-pdf.png">
- <div class="filename">asdf</div>
- </div>
- <div class="file">
- <img src="/mimeicons/application-pdf.png">
- <div class="filename">asdf</div>
- </div>
- <div class="file">
- <img src="/mimeicons/application-pdf.png">
- <div class="filename">asdf</div>
- </div>
- <div class="file">
- <img src="/mimeicons/application-pdf.png">
- <div class="filename">asdf</div>
- </div>
- <div class="file">
- <img src="/mimeicons/application-pdf.png">
- <div class="filename">asdf</div>
- </div>
- <div class="file">
- <img src="/mimeicons/application-pdf.png">
- <div class="filename">asdf</div>
- </div>
- <div class="file">
- <img src="/mimeicons/application-pdf.png">
- <div class="filename">asdf</div>
- </div>
- <div class="file">
- <img src="/mimeicons/application-pdf.png">
- <div class="filename">asdf</div>
- </div>
- <div class="file">
- <img src="/mimeicons/application-pdf.png">
- <div class="filename">asdf</div>
- </div>
- <div class="file">
- <img src="/mimeicons/application-pdf.png">
- <div class="filename">asdf</div>
- </div>
</div>
</div>
-
</div>
+ <form id="upload_form" style="display:none;" action="php/upload.php" method="post">
+ <input id="filename" name="filename">
+ <input type="file" name="the_file" id="the_file">
+ </form>
-
+ <script src="loggedin.js"></script>
F diff --git a/loginregister.js b/loginregister.js --- a/loginregister.js +++ b/loginregister.js
+
function clear_hero_errors()
{
let errors = document.getElementsByClassName("hero_form_error");
F diff --git a/php/.database.php.swp b/php/.database.php.swp deleted file mode 100644
B Binary files a/php/.database.php.swp and /dev/null differ
F diff --git a/php/.node.php.swp b/php/.node.php.swp deleted file mode 100644
B Binary files a/php/.node.php.swp and /dev/null differ
F diff --git a/php/.upload.php.swp b/php/.upload.php.swp deleted file mode 100644
B Binary files a/php/.upload.php.swp and /dev/null differ
F diff --git a/php/configuration.php b/php/configuration.php --- a/php/configuration.php +++ b/php/configuration.php
$storage_root = "/home/alex/fileup_storage";
}
else {
+ $database_name="adam";
+ $database_username="adam";
+ $database_password="asdfd";
+ $database_location="127.0.0.1";
- $database_name="fileup_testing";
- $database_username="outsider";
- $database_password="parola123";
- $database_location="localhost";
-
- $storage_root = "/tmp/fileup_storage";
+ $storage_root = "/home/adam/fileup_storage";
}
F diff --git a/php/database.php b/php/database.php --- a/php/database.php +++ b/php/database.php
require_once "configuration.php";
require_once "user.php";
require_once "misc.php";
- require_once "node.php";
/*handles database stuff*/
class Database
$ret->user_id=$hold["user_id"];
$ret->username=$hold["username"];
$ret->email_address=$hold["email"];
- $ret->current_directory=$hold["home_directory"];
return $ret;
}else
{
return false;
}
}
- function get_home_id($user_id)
- {
- $statement=$this->pdo->prepare("select home_directory
- from users
- where user_id=:id
- ");
- $statement->bindParam(':id',$user_id);
-
- $ret=$statement->execute(PDO::FETCH_ASSOC);
- return $ret["home_directory"];
- }
- function get_node_id($name,$directory_id)
- {
- $hold=NULL;
- $statement=NULL;
- $ret=[];
- if($name != NULL)
- {
- if($directory_id!=NULL)
- {
- $statement=$this->pdo->prepare(
- "select nl.node_id as id from node_links nl
- inner join nodes n on n.node_id=nl.node_id
- where name=:name and directory_id=:directory_id)");
- $statement->bindParam(':name',$name);
- $statement->bindParam(':directory_id',$directory_id);
- }else
- {
- /*get all node_ids with the name name*/
- $statement=$this->pdo->prepare("select node_id as id from nodes where name=:name");
- $statement->bindParam(':name',$name);
- }
- if($statement==NULL)
- {
- error_log("statement is null");
- exit(1);
- }
- }else {
- $statement=$this->pdo->prepare("select node_id as id from node_links where directory_id=:dir_id");
- $statement->bindParam(':dir_id',$directory_id);
- }
- if($statement->execute()==false)
- {
- error_log("there is an error in the sql statement in get_node_id");
- exit(1);
- }
-
- while($hold=$statement->fetch(PDO::FETCH_ASSOC))
- {
- print_r($hold);
- array_push($ret,$hold["id"]);
- }
- return $ret;
-
- }
- function get_random_node_name(string $prefix)
- {
- do{
- $proposal=uniqid($prefix,true);
- }while($this->get_node_id($proposal,NULL)!=NULL);
- return $proposal;
- }
- /*returns NULL if node doesn't exist*/
- /*if name is NULL return all node ids in the directory*/
- /*if directory is NULL return all node ids with the name name*/
- /*if both are null return NULL*/
- /*returns node id*/
- function create_dangling_directory(): int
- {
- $dir_name=$this->get_random_node_name("");
- global $storage_root;
-
- $prep=$this->pdo->prepare("insert into nodes(is_directory,relative_path,name) values(true,:root,:name)");
- $prep->bindParam(':name',$dir_name);
- $prep->bindParam(':root',$storage_root);
- if($prep->execute()==false)
- {
- error_log("tried to create a dangling directory but sql statement failed. Fatal error!");
- exit(1);
- }
-
- $id=$this->get_node_id($dir_name,NULL);
- if(count($id)!=1)
- {
- error_log("created a dangling directory but couldn't find it afterward. Fatal error!");
- exit(1);
- }
-
- //print count($id);
- return $id[0];
- }
- /*returns the file name as it must be in the filesystem*/
- function create_file_node(string $filename): string
- {
- global $storage_root;
- $code=get_random_node_name("");
- if($filename==NULL)return false;
- $prep=$this->pdo->prepare("insert into nodes(is_directory,relative_path,name,code)
- values(false,:root,:name,:code)
- ");
- $prep->bindParam(':name',$filename);
- $prep->bindParam(':root',$storage_root);
-
- $prep->bindParam(':code',$code);
- if($prep->execute()==false)
- {
- error_log("could not upload file");
- /*not so quiet error*/
- return "error";
- }
- return code;
- }
- function are_linked(int $directory_id,int $node_id): bool
- {
- $prepare=$this->pdo->prepare("select node_id
- from node_links
- where node_id=:node_id and directory_id=:dir_id
- ");
- $prepare->bindParam(':node_id',$node_id);
- $prepare->bindParam(':dir_id',$directory_id);
- if($prepare->execute()==false)
- {
- error_log("there is an sql error in are_linked");
- /*quiet error*/
- return false;
- }
- if(count($prepare->fetch(PDO::FETCH_ASSOC))==1)
- {
- return true;
- }else
- {
- return false;
- }
- }
-
/*returns false if username is taken, email is not checked here*/
function register_user(string $user,string $password,string $email) : bool
{
}else
{
$hashed_pass=password_hash($password,$password_hash_algo);
- $home_dir=$this->create_dangling_directory();
- $prep=$this->pdo->prepare("insert into users(username,password,email,home_directory) values(:username,:password,:email,:dir)");
+ $prep=$this->pdo->prepare("insert into users(username,password,email) values(:username,:password,:email)");
$prep->bindParam(':username',$user);
$prep->bindParam(':password',$hashed_pass);
$prep->bindParam(':email',$email);
- $prep->bindParam(':dir',$home_dir);
- if($prep->execute()==false)
- {
- error_log("can't create user because there was an error in the sql statement");
- /*todo make an error page*/
- exit(1);
- }
+ $prep->execute();
}
return true;
}
}
}
- $database=new Database();
+
?>
F diff --git a/php/node.php b/php/node.php deleted file mode 100644 --- a/php/node.php +++ /dev/null
- <?php
- require_once "database.php";
-
- class Current_Directory
- {
- public $node_id;
- /*an array of the dir_ids taken to reach here*/
- public $path;
-
- function __construct($user_id)
- {
- $this->dir_id=get_home_id($user_id);
- $this->path=[$dir_id];
- }
- function change_directory($directory_id):bool
- {
- global $database;
- if(!$database->is_directory($directory_id))
- {
- return false;
- }
-
- }
- }
-
- ?>
F diff --git a/php/upload.php b/php/upload.php --- a/php/upload.php +++ b/php/upload.php
<?php
- require_once "database.php"
- require_once "configuration.php"
- if (!isset( $_POST["filename") || !isset($_POST["the_file"])
- {
+ if (!array_key_exists('uf', $_FILES)) {
http_response_code(400);
- error_log("someone tried to upload something impropperly");
- exit(1);
+ exit();
}
- $file = $_POST["the_file"];
- $filename= $_POST["filename"];
+ $file = $_FILES['uf'];
- $codename=create_file_node($filename);
+ if (file['error'] != 0) {
+ http_response_code(400);
+ exit();
+ }
+
+ $m = md5_file($file['tmp_name']);
+
+ copy($file['tmp_name'], "screen/$m.png");
- copy($file['tmp_name'], "$storage_root/$codename");
+ echo "http://india.fmi.fail/screen/$m.png";
- echo $codename;
?>
F diff --git a/php/user.php b/php/user.php --- a/php/user.php +++ b/php/user.php
<?php
class User
{
+ /*I don't think we need to abstract these away*/
public $user_id;
public $username;
public $email_address;
- public $current_directory;
}
?>
F diff --git a/sql/.fileshare.sql.swp b/sql/.fileshare.sql.swp deleted file mode 100644
B Binary files a/sql/.fileshare.sql.swp and /dev/null differ
F diff --git a/sql/fileshare.sql b/sql/fileshare.sql --- a/sql/fileshare.sql +++ b/sql/fileshare.sql
- create table nodes (
- node_id int not null auto_increment,
- is_directory boolean default false,
- relative_path varchar(500) not null,
- type varchar(20) not null default 'data',
- name varchar(100) not null default 'no name',
- note varchar(200) not null default "",
- code varchar(100) not null default "error",
- primary key (node_id)
- );
-
/*base user information*/
create table users (
- user_id int not null auto_increment,
- username varchar(50) not null unique,
- password varchar(255) not null,
- email varchar(50),
- home_directory int not null,
- primary key (user_id),
- foreign key (home_directory) references nodes(node_id)
+ user_id int not null auto_increment,
+ username varchar(50) not null unique,
+ password varchar(255) not null,
+ email varchar(50),
+ primary key (user_id)
);
- create table node_access (
- node_id int not null,
- user_id int not null,
-
- can_view boolean not null default true,
- can_edit boolean not null default false,
- check (can_view=true or can_edit=true) ,
- foreign key (node_id) references nodes(node_id),
- foreign key (user_id) references users(user_id)
+ /*table has only one owner and is identifyed by a number*/
+ create table files (
+ file_id int not null auto_increment,
+ owner_id int default null,
+ relative_path varchar(500) not null,
+ type varchar(20) not null default 'data',
+ primary key (file_id),
+ foreign key (owner_id) references users(user_id)
);
- create table node_links (
- directory_id int not null,
- node_id int not null,
- check (directory_id != node_id),
- foreign key (directory_id) references nodes(node_id),
- foreign key (node_id) references nodes(node_id)
+ /*the user with userid is given some kind of access to the file with fileid*/
+ /*there is no edit bit because it will be too dificult to implement prehaps a change bit is in order (but not an edit bit)*/
+ /*might be beneficial to even go full minimalist and remove the remove bit and only have the view bit*/
+ create table access (
+ file_id int not null,
+ user_id int not null,
+ can_view boolean not null default true,
+ can_remove boolean not null default false,
+ check (can_view=true or can_remove=true) ,
+ foreign key (file_id) references files(file_id),
+ foreign key (user_id) references users(user_id)
);
-
-