1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
|
<?php
require_once "configuration.php";
require_once "database.php";
require_once "user.php";
session_start();
if($_SERVER["REQUEST_METHOD"] == "POST")
{
if(!isset($_SESSION['user_object']) || !isset($_POST["folder"]) || !isset($_POST["filename"]) || !isset($_POST["users"]) || !isset($_POST["password"]) || !isset($_POST["permissions"]) )
{
error_log("things are not set quite right");
http_response_code(409);
exit(0);
}
$user=$_SESSION['user_object'];
$path=$_POST["folder"];
/*this could be a directory as well*/
$filename=$_POST["filename"];
$users=$_POST["users"];
$password=$_POST["password"];
$permissions=$_POST["permissions"];
if($permissions==1)
{
$can_read=true;
$can_write=false;
}else if($permissions==3)
{
$can_read=true;
$can_write=true;
}
else
{
http_response_code(409);
error_log("someone gave wrong premmissions =".$permissions."! This could be an attack");
exit(1);
}
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);
if($share_link==NULL)
{
http_response_code(409);
}
echo $share_link;
http_response_code(200);
exit(0);
}else if($_SERVER["REQUEST_METHOD"]== "GET")
{
if(!isset($_GET["file"]))
{
http_response_code(409);
exit(0);
}
$code=$_GET["file"];
if(isset($_GET["password"]))
{
$password=$_GET["password"];
}else
{
$password="";
}
$shared_node=$database->get_shared_node($code);
if($shared_node==NULL)
{
http_response_code(409);
exit(0);
}
if ($shared_node->password!=$password) {
if ($password == "")
{
require_once("../share_frontend.php");
exit(0);
}else
{
echo "Invalid password";
http_response_code(409);
exit(0);
}
}
if(isset($_SESSION["user_object"]))
{
$user=$_SESSION["user_object"];
$permissions=$database->get_permissions($shared_node->node_id,$user->user_id);
if($permissions["can_view"]==true)
{
$node=$database->get_node($shared_node->node_id);
if($node->is_directory)
{
/*spooky stuff here*/
http_response_code(409);
exit(1);
}else
{
header("Content-type: $node->type");
readfile("$storage_root/$node->code");
}
}
}else
{
if($shared_node->is_public==true)
{
$node=$database->get_node($shared_node->node_id);
if($node->is_directory)
{
/*spooky stuff here*/
http_response_code(409);
exit(1);
}else
{
header("Content-type: $node->type");
readfile("$storage_root/$node->code");
}
}else
{
http_response_code(409);
exit(1);
}
}
}else
{
http_response_code(409);
exit(0);
}
?>
|