diff options
author | Alex Vitkov <alexvitkov98@gmail.com> | 2021-02-14 11:58:31 +0200 |
---|---|---|
committer | Alex Vitkov <alexvitkov98@gmail.com> | 2021-02-14 11:58:31 +0200 |
commit | cd872e6ed818761fc52a828c3af67ae44cfc9fe1 (patch) | |
tree | b5d571ce5972267ba2edef68b22871fffcdbeebc /php | |
parent | 67a6b658b4ed300743292e99bb8d2a955ced24b3 (diff) | |
parent | 8c5e2a88177786da775deb551ea24cca26a686a2 (diff) | |
download | fileup-cd872e6ed818761fc52a828c3af67ae44cfc9fe1.tar.gz |
Merge branch 'master' of https://github.com/alexvitkov/india
Diffstat (limited to 'php')
-rw-r--r-- | php/database.php | 11 | ||||
-rw-r--r-- | php/node.php | 28 | ||||
-rw-r--r-- | php/share.php | 3 |
3 files changed, 32 insertions, 10 deletions
diff --git a/php/database.php b/php/database.php index 58ca251..61ff344 100644 --- a/php/database.php +++ b/php/database.php @@ -21,7 +21,7 @@ require_once "node.php"; $this->pdo=new PDO("mysql:dbname={$database_name};host={$database_location}",$database_username,$database_password); } - /*returns false if this isn't a user, otherwise returns the user*/ + /*returns NULL if this isn't a user, otherwise returns the user*/ function get_user(string $user) { $ret=new User; @@ -33,16 +33,16 @@ require_once "node.php"; $hold=$prep->fetch(PDO::FETCH_ASSOC); - if($hold) + if(isset($hold["user_id"])) { $ret->user_id=$hold["user_id"]; $ret->username=$hold["username"]; $ret->email_address=$hold["email"]; - $ret->current_directory=$hold["home_directory"]; + $ret->home_directory=$hold["home_directory"]; return $ret; }else { - return false; + return NULL; } } /*returns false if this isn't a user or the password is incorrect, otherwise returns the userid*/ @@ -444,6 +444,9 @@ require_once "node.php"; $ret=$this->create_dangling_directory(); $trash_folder_id=$this->create_dangling_directory(); $this->link_nodes($ret,$trash_folder_id,"trash","trash folder"); + + $share_folder_id=$this->create_dangling_directory(); + $this->link_nodes($ret,$share_folder_id,"share","shared things go in here"); return $ret; } diff --git a/php/node.php b/php/node.php index c86beae..0593211 100644 --- a/php/node.php +++ b/php/node.php @@ -76,7 +76,8 @@ require_once "user.php"; $parent_dir_id=get_directory($abstract_path,$user); $database->unlink_nodes($parent_dir_id,$filename); } - function create_share_link(string $abstract_path,string $filename,string $password,User $user,bool $can_read,bool $can_write) + function create_share_link(string $abstract_path,string $filename,string $password, + User $user,bool $can_read,bool $can_write,$users) { global $database; global $domain_name; @@ -98,10 +99,27 @@ require_once "user.php"; return NULL; } - if($can_read) - $database->give_view_access($node_id,$user->user_id); - if($can_write) - $database->give_edit_access($node_id,$user->user_id); + $usernames=explode(',',$users); + foreach($usernames as $username) + { + $usr=$database->get_user($username); + if($usr==NULL) + continue; + error_log("sharing with $usr->username"); + + if($can_read) + $database->give_view_access($node_id,$usr->user_id); + if($can_write) + $database->give_edit_access($node_id,$usr->user_id); + + error_log("home directory is $usr->home_directory"); + $share_id=$database->get_node_id("share",$usr->home_directory); + if($share_id==NULL) + { + error_log("could not find share directory for $username"); + } + $database->link_nodes($share_id,$node_id,$filename,"this was shared to you"); + } if($use_https) { return "https://".$domain_name."/php/share.php?file=".$shared_node->code; diff --git a/php/share.php b/php/share.php index aeffac4..8f2aeaf 100644 --- a/php/share.php +++ b/php/share.php @@ -33,7 +33,8 @@ if($_SERVER["REQUEST_METHOD"] == "POST") exit(1); } - $share_link=create_share_link($path,$filename,$password,$user,$can_read,$can_write); + error_log("someone is sharing ".$filename." with ".$users); + $share_link=create_share_link($path,$filename,$password,$user,$can_read,$can_write,$users); //$share_link=create_share_link($path,$filename,$password,$user,true,true); |