1212use Exception ;
1313use OC \Files \Storage \Wrapper \Wrapper ;
1414use OCA \Circles \Api \v1 \Circles ;
15+ use OCA \Deck \Sharing \ShareAPIHelper ;
16+ use OCA \Federation \TrustedServers ;
1517use OCA \Files \Helper ;
1618use OCA \Files_Sharing \Exceptions \SharingRightsException ;
1719use OCA \Files_Sharing \External \Storage ;
7274class ShareAPIController extends OCSController {
7375
7476 private ?Node $ lockedNode = null ;
77+ private array $ trustedServerCache = [];
7578
7679 /**
7780 * Share20OCS constructor.
@@ -94,6 +97,8 @@ public function __construct(
9497 private LoggerInterface $ logger ,
9598 private IProviderFactory $ factory ,
9699 private IMailer $ mailer ,
100+ private ITagManager $ tagManager ,
101+ private ?TrustedServers $ trustedServers ,
97102 private ?string $ userId = null ,
98103 ) {
99104 parent ::__construct ($ appName , $ request );
@@ -196,6 +201,32 @@ protected function formatShare(IShare $share, ?Node $recipientNode = null): arra
196201 $ result ['item_size ' ] = $ node ->getSize ();
197202 $ result ['item_mtime ' ] = $ node ->getMTime ();
198203
204+ if ($ this ->trustedServers !== null && in_array ($ share ->getShareType (), [IShare::TYPE_REMOTE , IShare::TYPE_REMOTE_GROUP ], true )) {
205+ $ result ['is_trusted_server ' ] = false ;
206+ $ sharedWith = $ share ->getSharedWith ();
207+ $ remoteIdentifier = is_string ($ sharedWith ) ? strrchr ($ sharedWith , '@ ' ) : false ;
208+ if ($ remoteIdentifier !== false ) {
209+ $ remote = substr ($ remoteIdentifier , 1 );
210+
211+ if (isset ($ this ->trustedServerCache [$ remote ])) {
212+ $ result ['is_trusted_server ' ] = $ this ->trustedServerCache [$ remote ];
213+ } else {
214+ try {
215+ $ isTrusted = $ this ->trustedServers ->isTrustedServer ($ remote );
216+ $ this ->trustedServerCache [$ remote ] = $ isTrusted ;
217+ $ result ['is_trusted_server ' ] = $ isTrusted ;
218+ } catch (\Exception $ e ) {
219+ // Server not found or other issue, we consider it not trusted
220+ $ this ->trustedServerCache [$ remote ] = false ;
221+ $ this ->logger ->error (
222+ 'Error checking if remote server is trusted (treating as untrusted): ' . $ e ->getMessage (),
223+ ['exception ' => $ e ]
224+ );
225+ }
226+ }
227+ }
228+ }
229+
199230 $ expiration = $ share ->getExpirationDate ();
200231 if ($ expiration !== null ) {
201232 $ expiration ->setTimezone ($ this ->dateTimeZone ->getTimeZone ());
0 commit comments