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
138
139
140
141
142
143
|
# 9、owncloud/core/ajax/share.php 78行左右加了一个判断
#
if (isset($_POST['action']) && isset($_POST['itemType']) && isset($_POST['itemSource'])) {
switch ($_POST['action']) {
case 'share':
if (isset($_POST['shareType']) && isset($_POST['shareWith']) && isset($_POST['permissions'])) {
try {
$shareType = (int) $_POST['shareType'];
$shareWith = $_POST['shareWith'];
$itemSourceName = isset($_POST['itemSourceName']) ? $_POST['itemSourceName'] : null;
if ($shareType === OCP\Share::SHARE_TYPE_LINK && $shareWith == '') {
$shareWith = null;
}
$itemSourceName = (isset($_POST['itemSourceName'])) ? $_POST['itemSourceName'] : '';
$token = OCP\Share::shareItem(
$_POST['itemType'],
$_POST['itemSource'],
$shareType,
$shareWith,
$_POST['permissions'],
$itemSourceName,
(!empty($_POST['expirationDate']) ? new \DateTime($_POST['expirationDate']) : null
)
); /*
$checkExists = \OC\Share\Share::getItems( $_POST['itemType'],$_POST['itemSource'],$shareType,$shareWith );
$token = $checkExists['token'];
$token = $token;
//$token = \OCA\Files_Sharing\Controllers\ExternalSharesController::create($_POST['itemSource']);
*/
if (is_string($token)) {
OC_JSON::success(array('data' => array('token' => $token)));
} else {
OC_JSON::success();
}
} catch (Exception $exception) {
OC_JSON::error(array('data' => array('message' => $exception->getMessage())));
}
}
break;
case 'unshare':
if (isset($_POST['shareType']) && isset($_POST['shareWith'])) {
if ((int) $_POST['shareType'] === OCP\Share::SHARE_TYPE_LINK && $_POST['shareWith'] == '') {
$shareWith = null;
} else {
$shareWith = $_POST['shareWith'];
}
$return = OCP\Share::unshare($_POST['itemType'], $_POST['itemSource'], $_POST['shareType'], $shareWith);
($return) ? OC_JSON::success() : OC_JSON::error();
}
break;
case 'setPermissions':
if (isset($_POST['shareType']) && isset($_POST['shareWith']) && isset($_POST['permissions'])) {
$return = OCP\Share::setPermissions(
$_POST['itemType'],
$_POST['itemSource'],
(int) $_POST['shareType'],
$_POST['shareWith'],
(int) $_POST['permissions']
);
($return) ? OC_JSON::success() : OC_JSON::error();
}
break;
case 'setExpirationDate':
if (isset($_POST['date'])) {
try {
$return = OCP\Share::setExpirationDate($_POST['itemType'], $_POST['itemSource'], $_POST['date']);
($return) ? OC_JSON::success() : OC_JSON::error();
} catch (\Exception $e) {
OC_JSON::error(array('data' => array('message' => $e->getMessage())));
}
}
break;
case 'informRecipients':
$l = \OC::$server->getL10N('core');
$shareType = (int) $_POST['shareType'];
$itemType = $_POST['itemType'];
$itemSource = $_POST['itemSource'];
$recipient = $_POST['recipient'];
if ($shareType === \OCP\Share::SHARE_TYPE_USER) {
$recipientList[] = $recipient;
} elseif ($shareType === \OCP\Share::SHARE_TYPE_GROUP) {
$recipientList = \OC_Group::usersInGroup($recipient);
}
$recipientList = array_diff($recipientList, array(\OCP\User::getUser()));
$mailNotification = new OC\Share\MailNotifications(\OCP\User::getUser());
$result = $mailNotification->sendInternalShareMail($recipientList, $itemSource, $itemType);
\OCP\Share::setSendMailStatus($itemType, $itemSource, $shareType, $recipient, true);
if (empty($result)) {
OCP\JSON::success();
} else {
OCP\JSON::error(
array(
'data' => array(
'message' => $l->t(
"Couldn't send mail to following users: %s ",
implode(', ', $result)
)
)
)
);
}
break;
case 'informRecipientsDisabled':
$itemSource = $_POST['itemSource'];
$shareType = $_POST['shareType'];
$itemType = $_POST['itemType'];
$recipient = $_POST['recipient'];
\OCP\Share::setSendMailStatus($itemType, $itemSource, $shareType, $recipient, false);
OCP\JSON::success();
break;
case 'email':
$link = $_POST['link'];
$file = $_POST['file'];
$to_address = $_POST['toaddress'];
$mailNotification = new \OC\Share\MailNotifications(\OCP\User::getUser());
$expiration = null;
if (isset($_POST['expiration']) && $_POST['expiration'] !== '') {
try {
$date = new DateTime($_POST['expiration']);
$expiration = $date->getTimestamp();
} catch (Exception $e) {
\OCP\Util::writeLog('sharing', "Couldn't read date: " . $e->getMessage(), \OCP\Util::ERROR);
}
}
$result = $mailNotification->sendLinkShareMail($to_address, $file, $link, $expiration);
if (empty($result)) {
\OCP\JSON::success();
} else {
$l = \OC::$server->getL10N('core');
OCP\JSON::error(
array(
'data' => array(
'message' => $l->t(
"Couldn't send mail to following users: %s ",
implode(', ', $result)
)
)
)
);
}
break;
}
}
|