@@ -10,10 +10,10 @@ discard block |
||
| 10 | 10 | |
| 11 | 11 | <div id="app-navigation"> |
| 12 | 12 | <ul class="with-icon"> |
| 13 | - <?php foreach($_['forms'] as $form) { |
|
| 13 | + <?php foreach ($_['forms'] as $form) { |
|
| 14 | 14 | if (isset($form['anchor'])) { |
| 15 | - $anchor = '#' . $form['anchor']; |
|
| 16 | - $class = 'nav-icon-' . $form['anchor']; |
|
| 15 | + $anchor = '#'.$form['anchor']; |
|
| 16 | + $class = 'nav-icon-'.$form['anchor']; |
|
| 17 | 17 | $sectionName = $form['section-name']; |
| 18 | 18 | print_unescaped(sprintf("<li><a href='%s' class='%s'>%s</a></li>", \OCP\Util::sanitizeHTML($anchor), |
| 19 | 19 | \OCP\Util::sanitizeHTML($class), \OCP\Util::sanitizeHTML($sectionName))); |
@@ -25,15 +25,15 @@ discard block |
||
| 25 | 25 | <div id="app-content"> |
| 26 | 26 | |
| 27 | 27 | <div id="quota" class="section"> |
| 28 | - <div style="width:<?php p($_['usage_relative']);?>%" |
|
| 29 | - <?php if($_['usage_relative'] > 80): ?> class="quota-warning" <?php endif; ?>> |
|
| 28 | + <div style="width:<?php p($_['usage_relative']); ?>%" |
|
| 29 | + <?php if ($_['usage_relative'] > 80): ?> class="quota-warning" <?php endif; ?>> |
|
| 30 | 30 | <p id="quotatext"> |
| 31 | 31 | <?php if ($_['quota'] === \OCP\Files\FileInfo::SPACE_UNLIMITED): ?> |
| 32 | 32 | <?php print_unescaped($l->t('You are using <strong>%s</strong> of <strong>%s</strong>', |
| 33 | - [$_['usage'], $_['total_space']]));?> |
|
| 33 | + [$_['usage'], $_['total_space']])); ?> |
|
| 34 | 34 | <?php else: ?> |
| 35 | 35 | <?php print_unescaped($l->t('You are using <strong>%s</strong> of <strong>%s</strong> (<strong>%s %%</strong>)', |
| 36 | - [$_['usage'], $_['total_space'], $_['usage_relative']]));?> |
|
| 36 | + [$_['usage'], $_['total_space'], $_['usage_relative']])); ?> |
|
| 37 | 37 | <?php endif ?> |
| 38 | 38 | </p> |
| 39 | 39 | </div> |
@@ -67,7 +67,7 @@ discard block |
||
| 67 | 67 | </div> |
| 68 | 68 | </div> |
| 69 | 69 | <span class="icon-checkmark hidden"/> |
| 70 | - <?php if($_['lookupServerUploadEnabled']) { ?> |
|
| 70 | + <?php if ($_['lookupServerUploadEnabled']) { ?> |
|
| 71 | 71 | <input type="hidden" id="avatarscope" value="<?php p($_['avatarScope']) ?>"> |
| 72 | 72 | <?php } ?> |
| 73 | 73 | </form> |
@@ -81,14 +81,14 @@ discard block |
||
| 81 | 81 | <span class="icon-password"/> |
| 82 | 82 | </h2> |
| 83 | 83 | <input type="text" id="displayname" name="displayname" |
| 84 | - <?php if(!$_['displayNameChangeSupported']) { print_unescaped('class="hidden"'); } ?> |
|
| 84 | + <?php if (!$_['displayNameChangeSupported']) { print_unescaped('class="hidden"'); } ?> |
|
| 85 | 85 | value="<?php p($_['displayName']) ?>" |
| 86 | 86 | autocomplete="on" autocapitalize="none" autocorrect="off" /> |
| 87 | - <?php if(!$_['displayNameChangeSupported']) { ?> |
|
| 88 | - <span><?php if(isset($_['displayName']) && !empty($_['displayName'])) { p($_['displayName']); } else { p($l->t('No display name set')); } ?></span> |
|
| 87 | + <?php if (!$_['displayNameChangeSupported']) { ?> |
|
| 88 | + <span><?php if (isset($_['displayName']) && !empty($_['displayName'])) { p($_['displayName']); } else { p($l->t('No display name set')); } ?></span> |
|
| 89 | 89 | <?php } ?> |
| 90 | 90 | <span class="icon-checkmark hidden"/> |
| 91 | - <?php if($_['lookupServerUploadEnabled']) { ?> |
|
| 91 | + <?php if ($_['lookupServerUploadEnabled']) { ?> |
|
| 92 | 92 | <input type="hidden" id="displaynamescope" value="<?php p($_['displayNameScope']) ?>"> |
| 93 | 93 | <?php } ?> |
| 94 | 94 | </form> |
@@ -100,23 +100,23 @@ discard block |
||
| 100 | 100 | <span class="icon-password"/> |
| 101 | 101 | </h2> |
| 102 | 102 | <input type="email" name="email" id="email" value="<?php p($_['email']); ?>" |
| 103 | - <?php if(!$_['displayNameChangeSupported']) { print_unescaped('class="hidden"'); } ?> |
|
| 103 | + <?php if (!$_['displayNameChangeSupported']) { print_unescaped('class="hidden"'); } ?> |
|
| 104 | 104 | placeholder="<?php p($l->t('Your email address')); ?>" |
| 105 | 105 | autocomplete="on" autocapitalize="none" autocorrect="off" /> |
| 106 | - <?php if(!$_['displayNameChangeSupported']) { ?> |
|
| 107 | - <span><?php if(isset($_['email']) && !empty($_['email'])) { p($_['email']); } else { p($l->t('No email address set')); }?></span> |
|
| 106 | + <?php if (!$_['displayNameChangeSupported']) { ?> |
|
| 107 | + <span><?php if (isset($_['email']) && !empty($_['email'])) { p($_['email']); } else { p($l->t('No email address set')); }?></span> |
|
| 108 | 108 | <?php } ?> |
| 109 | - <?php if($_['displayNameChangeSupported']) { ?> |
|
| 109 | + <?php if ($_['displayNameChangeSupported']) { ?> |
|
| 110 | 110 | <br /> |
| 111 | 111 | <em><?php p($l->t('For password reset and notifications')); ?></em> |
| 112 | 112 | <?php } ?> |
| 113 | 113 | <span class="icon-checkmark hidden"/> |
| 114 | - <?php if($_['lookupServerUploadEnabled']) { ?> |
|
| 114 | + <?php if ($_['lookupServerUploadEnabled']) { ?> |
|
| 115 | 115 | <input type="hidden" id="emailscope" value="<?php p($_['emailScope']) ?>"> |
| 116 | 116 | <?php } ?> |
| 117 | 117 | </form> |
| 118 | 118 | </div> |
| 119 | - <?php if($_['lookupServerUploadEnabled']) { ?> |
|
| 119 | + <?php if ($_['lookupServerUploadEnabled']) { ?> |
|
| 120 | 120 | <div class="personal-settings-setting-box"> |
| 121 | 121 | <form id="phoneform" class="section"> |
| 122 | 122 | <h2> |
@@ -185,19 +185,19 @@ discard block |
||
| 185 | 185 | </div> |
| 186 | 186 | |
| 187 | 187 | <?php |
| 188 | -if($_['passwordChangeSupported']) { |
|
| 188 | +if ($_['passwordChangeSupported']) { |
|
| 189 | 189 | script('jquery-showpassword'); |
| 190 | 190 | ?> |
| 191 | 191 | <form id="passwordform" class="section"> |
| 192 | - <h2 class="inlineblock"><?php p($l->t('Password'));?></h2> |
|
| 192 | + <h2 class="inlineblock"><?php p($l->t('Password')); ?></h2> |
|
| 193 | 193 | <div id="password-error-msg" class="msg success inlineblock" style="display: none;">Saved</div> |
| 194 | 194 | <br> |
| 195 | 195 | <label for="pass1" class="hidden-visually"><?php p($l->t('Current password')); ?>: </label> |
| 196 | 196 | <input type="password" id="pass1" name="oldpassword" |
| 197 | - placeholder="<?php p($l->t('Current password'));?>" |
|
| 197 | + placeholder="<?php p($l->t('Current password')); ?>" |
|
| 198 | 198 | autocomplete="off" autocapitalize="none" autocorrect="off" /> |
| 199 | 199 | <div class="personal-show-container"> |
| 200 | - <label for="pass2" class="hidden-visually"><?php p($l->t('New password'));?>: </label> |
|
| 200 | + <label for="pass2" class="hidden-visually"><?php p($l->t('New password')); ?>: </label> |
|
| 201 | 201 | <input type="password" id="pass2" name="newpassword" |
| 202 | 202 | placeholder="<?php p($l->t('New password')); ?>" |
| 203 | 203 | data-typetoggle="#personal-show" |
@@ -213,44 +213,44 @@ discard block |
||
| 213 | 213 | |
| 214 | 214 | <form id="language" class="section"> |
| 215 | 215 | <h2> |
| 216 | - <label for="languageinput"><?php p($l->t('Language'));?></label> |
|
| 216 | + <label for="languageinput"><?php p($l->t('Language')); ?></label> |
|
| 217 | 217 | </h2> |
| 218 | - <select id="languageinput" name="lang" data-placeholder="<?php p($l->t('Language'));?>"> |
|
| 219 | - <option value="<?php p($_['activelanguage']['code']);?>"> |
|
| 220 | - <?php p($_['activelanguage']['name']);?> |
|
| 218 | + <select id="languageinput" name="lang" data-placeholder="<?php p($l->t('Language')); ?>"> |
|
| 219 | + <option value="<?php p($_['activelanguage']['code']); ?>"> |
|
| 220 | + <?php p($_['activelanguage']['name']); ?> |
|
| 221 | 221 | </option> |
| 222 | - <?php foreach($_['commonlanguages'] as $language):?> |
|
| 223 | - <option value="<?php p($language['code']);?>"> |
|
| 224 | - <?php p($language['name']);?> |
|
| 222 | + <?php foreach ($_['commonlanguages'] as $language):?> |
|
| 223 | + <option value="<?php p($language['code']); ?>"> |
|
| 224 | + <?php p($language['name']); ?> |
|
| 225 | 225 | </option> |
| 226 | - <?php endforeach;?> |
|
| 226 | + <?php endforeach; ?> |
|
| 227 | 227 | <optgroup label="––––––––––"></optgroup> |
| 228 | - <?php foreach($_['languages'] as $language):?> |
|
| 229 | - <option value="<?php p($language['code']);?>"> |
|
| 230 | - <?php p($language['name']);?> |
|
| 228 | + <?php foreach ($_['languages'] as $language):?> |
|
| 229 | + <option value="<?php p($language['code']); ?>"> |
|
| 230 | + <?php p($language['name']); ?> |
|
| 231 | 231 | </option> |
| 232 | - <?php endforeach;?> |
|
| 232 | + <?php endforeach; ?> |
|
| 233 | 233 | </select> |
| 234 | 234 | <a href="https://www.transifex.com/nextcloud/nextcloud/" |
| 235 | 235 | target="_blank" rel="noreferrer"> |
| 236 | - <em><?php p($l->t('Help translate'));?></em> |
|
| 236 | + <em><?php p($l->t('Help translate')); ?></em> |
|
| 237 | 237 | </a> |
| 238 | 238 | </form> |
| 239 | 239 | |
| 240 | 240 | |
| 241 | 241 | <div id="clientsbox" class="section clientsbox"> |
| 242 | - <h2><?php p($l->t('Get the apps to sync your files'));?></h2> |
|
| 242 | + <h2><?php p($l->t('Get the apps to sync your files')); ?></h2> |
|
| 243 | 243 | <a href="<?php p($_['clients']['desktop']); ?>" rel="noreferrer" target="_blank"> |
| 244 | 244 | <img src="<?php print_unescaped(image_path('core', 'desktopapp.svg')); ?>" |
| 245 | - alt="<?php p($l->t('Desktop client'));?>" /> |
|
| 245 | + alt="<?php p($l->t('Desktop client')); ?>" /> |
|
| 246 | 246 | </a> |
| 247 | 247 | <a href="<?php p($_['clients']['android']); ?>" rel="noreferrer" target="_blank"> |
| 248 | 248 | <img src="<?php print_unescaped(image_path('core', 'googleplay.png')); ?>" |
| 249 | - alt="<?php p($l->t('Android app'));?>" /> |
|
| 249 | + alt="<?php p($l->t('Android app')); ?>" /> |
|
| 250 | 250 | </a> |
| 251 | 251 | <a href="<?php p($_['clients']['ios']); ?>" rel="noreferrer" target="_blank"> |
| 252 | 252 | <img src="<?php print_unescaped(image_path('core', 'appstore.svg')); ?>" |
| 253 | - alt="<?php p($l->t('iOS app'));?>" /> |
|
| 253 | + alt="<?php p($l->t('iOS app')); ?>" /> |
|
| 254 | 254 | </a> |
| 255 | 255 | |
| 256 | 256 | <p> |
@@ -266,19 +266,19 @@ discard block |
||
| 266 | 266 | $l->t('If you want to support the project {contributeopen}join development{linkclose} or {contributeopen}spread the word{linkclose}!'))); ?> |
| 267 | 267 | </p> |
| 268 | 268 | |
| 269 | - <?php if(OC_APP::isEnabled('firstrunwizard')) {?> |
|
| 270 | - <p><a class="button" href="#" id="showWizard"><?php p($l->t('Show First Run Wizard again'));?></a></p> |
|
| 269 | + <?php if (OC_APP::isEnabled('firstrunwizard')) {?> |
|
| 270 | + <p><a class="button" href="#" id="showWizard"><?php p($l->t('Show First Run Wizard again')); ?></a></p> |
|
| 271 | 271 | <?php }?> |
| 272 | 272 | </div> |
| 273 | 273 | |
| 274 | 274 | <div id="sessions" class="section"> |
| 275 | - <h2><?php p($l->t('Sessions'));?></h2> |
|
| 276 | - <span class="hidden-when-empty"><?php p($l->t('Web, desktop and mobile clients currently logged in to your account.'));?></span> |
|
| 275 | + <h2><?php p($l->t('Sessions')); ?></h2> |
|
| 276 | + <span class="hidden-when-empty"><?php p($l->t('Web, desktop and mobile clients currently logged in to your account.')); ?></span> |
|
| 277 | 277 | <table class="icon-loading"> |
| 278 | 278 | <thead class="token-list-header"> |
| 279 | 279 | <tr> |
| 280 | - <th><?php p($l->t('Device'));?></th> |
|
| 281 | - <th><?php p($l->t('Last activity'));?></th> |
|
| 280 | + <th><?php p($l->t('Device')); ?></th> |
|
| 281 | + <th><?php p($l->t('Last activity')); ?></th> |
|
| 282 | 282 | <th></th> |
| 283 | 283 | </tr> |
| 284 | 284 | </thead> |
@@ -288,13 +288,13 @@ discard block |
||
| 288 | 288 | </div> |
| 289 | 289 | |
| 290 | 290 | <div id="apppasswords" class="section"> |
| 291 | - <h2><?php p($l->t('App passwords'));?></h2> |
|
| 292 | - <p><?php p($l->t('Passcodes that give an app or device permissions to access your account.'));?></p> |
|
| 291 | + <h2><?php p($l->t('App passwords')); ?></h2> |
|
| 292 | + <p><?php p($l->t('Passcodes that give an app or device permissions to access your account.')); ?></p> |
|
| 293 | 293 | <table class="icon-loading"> |
| 294 | 294 | <thead class="hidden-when-empty"> |
| 295 | 295 | <tr> |
| 296 | - <th><?php p($l->t('Name'));?></th> |
|
| 297 | - <th><?php p($l->t('Last activity'));?></th> |
|
| 296 | + <th><?php p($l->t('Name')); ?></th> |
|
| 297 | + <th><?php p($l->t('Last activity')); ?></th> |
|
| 298 | 298 | <th></th> |
| 299 | 299 | </tr> |
| 300 | 300 | </thead> |
@@ -323,14 +323,14 @@ discard block |
||
| 323 | 323 | </div> |
| 324 | 324 | </div> |
| 325 | 325 | |
| 326 | -<?php foreach($_['forms'] as $form) { |
|
| 326 | +<?php foreach ($_['forms'] as $form) { |
|
| 327 | 327 | if (isset($form['form'])) {?> |
| 328 | - <div id="<?php isset($form['anchor']) ? p($form['anchor']) : p('');?>"><?php print_unescaped($form['form']);?></div> |
|
| 328 | + <div id="<?php isset($form['anchor']) ? p($form['anchor']) : p(''); ?>"><?php print_unescaped($form['form']); ?></div> |
|
| 329 | 329 | <?php } |
| 330 | 330 | };?> |
| 331 | 331 | |
| 332 | 332 | <div class="section"> |
| 333 | - <h2><?php p($l->t('Version'));?></h2> |
|
| 333 | + <h2><?php p($l->t('Version')); ?></h2> |
|
| 334 | 334 | <p><a href="<?php print_unescaped($theme->getBaseUrl()); ?>" target="_blank"><?php p($theme->getTitle()); ?></a> <?php p(OC_Util::getHumanVersion()) ?></p> |
| 335 | 335 | <p><?php include('settings.development.notice.php'); ?></p> |
| 336 | 336 | </div> |
@@ -29,43 +29,43 @@ |
||
| 29 | 29 | |
| 30 | 30 | class Admin implements ISettings { |
| 31 | 31 | |
| 32 | - /** @var FederatedShareProvider */ |
|
| 33 | - private $fedShareProvider; |
|
| 32 | + /** @var FederatedShareProvider */ |
|
| 33 | + private $fedShareProvider; |
|
| 34 | 34 | |
| 35 | - public function __construct(FederatedShareProvider $fedShareProvider) { |
|
| 36 | - $this->fedShareProvider = $fedShareProvider; |
|
| 37 | - } |
|
| 35 | + public function __construct(FederatedShareProvider $fedShareProvider) { |
|
| 36 | + $this->fedShareProvider = $fedShareProvider; |
|
| 37 | + } |
|
| 38 | 38 | |
| 39 | - /** |
|
| 40 | - * @return TemplateResponse |
|
| 41 | - */ |
|
| 42 | - public function getForm() { |
|
| 43 | - $parameters = [ |
|
| 44 | - 'outgoingServer2serverShareEnabled' => $this->fedShareProvider->isOutgoingServer2serverShareEnabled(), |
|
| 45 | - 'incomingServer2serverShareEnabled' => $this->fedShareProvider->isIncomingServer2serverShareEnabled(), |
|
| 46 | - 'lookupServerEnabled' => $this->fedShareProvider->isLookupServerQueriesEnabled(), |
|
| 47 | - 'lookupServerUploadEnabled' => $this->fedShareProvider->isLookupServerUploadEnabled(), |
|
| 48 | - ]; |
|
| 39 | + /** |
|
| 40 | + * @return TemplateResponse |
|
| 41 | + */ |
|
| 42 | + public function getForm() { |
|
| 43 | + $parameters = [ |
|
| 44 | + 'outgoingServer2serverShareEnabled' => $this->fedShareProvider->isOutgoingServer2serverShareEnabled(), |
|
| 45 | + 'incomingServer2serverShareEnabled' => $this->fedShareProvider->isIncomingServer2serverShareEnabled(), |
|
| 46 | + 'lookupServerEnabled' => $this->fedShareProvider->isLookupServerQueriesEnabled(), |
|
| 47 | + 'lookupServerUploadEnabled' => $this->fedShareProvider->isLookupServerUploadEnabled(), |
|
| 48 | + ]; |
|
| 49 | 49 | |
| 50 | - return new TemplateResponse('federatedfilesharing', 'settings-admin', $parameters, ''); |
|
| 51 | - } |
|
| 50 | + return new TemplateResponse('federatedfilesharing', 'settings-admin', $parameters, ''); |
|
| 51 | + } |
|
| 52 | 52 | |
| 53 | - /** |
|
| 54 | - * @return string the section ID, e.g. 'sharing' |
|
| 55 | - */ |
|
| 56 | - public function getSection() { |
|
| 57 | - return 'sharing'; |
|
| 58 | - } |
|
| 53 | + /** |
|
| 54 | + * @return string the section ID, e.g. 'sharing' |
|
| 55 | + */ |
|
| 56 | + public function getSection() { |
|
| 57 | + return 'sharing'; |
|
| 58 | + } |
|
| 59 | 59 | |
| 60 | - /** |
|
| 61 | - * @return int whether the form should be rather on the top or bottom of |
|
| 62 | - * the admin section. The forms are arranged in ascending order of the |
|
| 63 | - * priority values. It is required to return a value between 0 and 100. |
|
| 64 | - * |
|
| 65 | - * E.g.: 70 |
|
| 66 | - */ |
|
| 67 | - public function getPriority() { |
|
| 68 | - return 20; |
|
| 69 | - } |
|
| 60 | + /** |
|
| 61 | + * @return int whether the form should be rather on the top or bottom of |
|
| 62 | + * the admin section. The forms are arranged in ascending order of the |
|
| 63 | + * priority values. It is required to return a value between 0 and 100. |
|
| 64 | + * |
|
| 65 | + * E.g.: 70 |
|
| 66 | + */ |
|
| 67 | + public function getPriority() { |
|
| 68 | + return 20; |
|
| 69 | + } |
|
| 70 | 70 | |
| 71 | 71 | } |
@@ -5,16 +5,16 @@ discard block |
||
| 5 | 5 | ?> |
| 6 | 6 | |
| 7 | 7 | <div id="fileSharingSettings" class="followupsection"> |
| 8 | - <h3><?php p($l->t('Federated Cloud Sharing'));?></h3> |
|
| 8 | + <h3><?php p($l->t('Federated Cloud Sharing')); ?></h3> |
|
| 9 | 9 | <a target="_blank" rel="noreferrer" class="icon-info svg" |
| 10 | - title="<?php p($l->t('Open documentation'));?>" |
|
| 10 | + title="<?php p($l->t('Open documentation')); ?>" |
|
| 11 | 11 | href="<?php p(link_to_docs('admin-sharing-federated')); ?>"></a> |
| 12 | 12 | |
| 13 | 13 | <p> |
| 14 | 14 | <input type="checkbox" name="outgoing_server2server_share_enabled" id="outgoingServer2serverShareEnabled" class="checkbox" |
| 15 | 15 | value="1" <?php if ($_['outgoingServer2serverShareEnabled']) print_unescaped('checked="checked"'); ?> /> |
| 16 | 16 | <label for="outgoingServer2serverShareEnabled"> |
| 17 | - <?php p($l->t('Allow users on this server to send shares to other servers'));?> |
|
| 17 | + <?php p($l->t('Allow users on this server to send shares to other servers')); ?> |
|
| 18 | 18 | </label> |
| 19 | 19 | </p> |
| 20 | 20 | |
@@ -22,21 +22,21 @@ discard block |
||
| 22 | 22 | <input type="checkbox" name="incoming_server2server_share_enabled" id="incomingServer2serverShareEnabled" class="checkbox" |
| 23 | 23 | value="1" <?php if ($_['incomingServer2serverShareEnabled']) print_unescaped('checked="checked"'); ?> /> |
| 24 | 24 | <label for="incomingServer2serverShareEnabled"> |
| 25 | - <?php p($l->t('Allow users on this server to receive shares from other servers'));?> |
|
| 25 | + <?php p($l->t('Allow users on this server to receive shares from other servers')); ?> |
|
| 26 | 26 | </label><br/> |
| 27 | 27 | </p> |
| 28 | 28 | <p> |
| 29 | 29 | <input type="checkbox" name="lookupServerEnabled" id="lookupServerEnabled" class="checkbox" |
| 30 | 30 | value="1" <?php if ($_['lookupServerEnabled']) print_unescaped('checked="checked"'); ?> /> |
| 31 | 31 | <label for="lookupServerEnabled"> |
| 32 | - <?php p($l->t('Search global and public address book for users and let local users publish their data'));?> |
|
| 32 | + <?php p($l->t('Search global and public address book for users and let local users publish their data')); ?> |
|
| 33 | 33 | </label><br/> |
| 34 | 34 | </p> |
| 35 | 35 | <p> |
| 36 | 36 | <input type="checkbox" name="lookupServerUploadEnabled" id="lookupServerUploadEnabled" class="checkbox" |
| 37 | 37 | value="1" <?php if ($_['lookupServerUploadEnabled']) print_unescaped('checked="checked"'); ?> /> |
| 38 | 38 | <label for="lookupServerUploadEnabled"> |
| 39 | - <?php p($l->t('Allow users to publish their data to a global and public address book'));?> |
|
| 39 | + <?php p($l->t('Allow users to publish their data to a global and public address book')); ?> |
|
| 40 | 40 | </label><br/> |
| 41 | 41 | </p> |
| 42 | 42 | |
@@ -12,7 +12,10 @@ discard block |
||
| 12 | 12 | |
| 13 | 13 | <p> |
| 14 | 14 | <input type="checkbox" name="outgoing_server2server_share_enabled" id="outgoingServer2serverShareEnabled" class="checkbox" |
| 15 | - value="1" <?php if ($_['outgoingServer2serverShareEnabled']) print_unescaped('checked="checked"'); ?> /> |
|
| 15 | + value="1" <?php if ($_['outgoingServer2serverShareEnabled']) { |
|
| 16 | + print_unescaped('checked="checked"'); |
|
| 17 | +} |
|
| 18 | +?> /> |
|
| 16 | 19 | <label for="outgoingServer2serverShareEnabled"> |
| 17 | 20 | <?php p($l->t('Allow users on this server to send shares to other servers'));?> |
| 18 | 21 | </label> |
@@ -20,21 +23,30 @@ discard block |
||
| 20 | 23 | |
| 21 | 24 | <p> |
| 22 | 25 | <input type="checkbox" name="incoming_server2server_share_enabled" id="incomingServer2serverShareEnabled" class="checkbox" |
| 23 | - value="1" <?php if ($_['incomingServer2serverShareEnabled']) print_unescaped('checked="checked"'); ?> /> |
|
| 26 | + value="1" <?php if ($_['incomingServer2serverShareEnabled']) { |
|
| 27 | + print_unescaped('checked="checked"'); |
|
| 28 | +} |
|
| 29 | +?> /> |
|
| 24 | 30 | <label for="incomingServer2serverShareEnabled"> |
| 25 | 31 | <?php p($l->t('Allow users on this server to receive shares from other servers'));?> |
| 26 | 32 | </label><br/> |
| 27 | 33 | </p> |
| 28 | 34 | <p> |
| 29 | 35 | <input type="checkbox" name="lookupServerEnabled" id="lookupServerEnabled" class="checkbox" |
| 30 | - value="1" <?php if ($_['lookupServerEnabled']) print_unescaped('checked="checked"'); ?> /> |
|
| 36 | + value="1" <?php if ($_['lookupServerEnabled']) { |
|
| 37 | + print_unescaped('checked="checked"'); |
|
| 38 | +} |
|
| 39 | +?> /> |
|
| 31 | 40 | <label for="lookupServerEnabled"> |
| 32 | 41 | <?php p($l->t('Search global and public address book for users and let local users publish their data'));?> |
| 33 | 42 | </label><br/> |
| 34 | 43 | </p> |
| 35 | 44 | <p> |
| 36 | 45 | <input type="checkbox" name="lookupServerUploadEnabled" id="lookupServerUploadEnabled" class="checkbox" |
| 37 | - value="1" <?php if ($_['lookupServerUploadEnabled']) print_unescaped('checked="checked"'); ?> /> |
|
| 46 | + value="1" <?php if ($_['lookupServerUploadEnabled']) { |
|
| 47 | + print_unescaped('checked="checked"'); |
|
| 48 | +} |
|
| 49 | +?> /> |
|
| 38 | 50 | <label for="lookupServerUploadEnabled"> |
| 39 | 51 | <?php p($l->t('Allow users to publish their data to a global and public address book'));?> |
| 40 | 52 | </label><br/> |
@@ -49,929 +49,929 @@ |
||
| 49 | 49 | */ |
| 50 | 50 | class FederatedShareProvider implements IShareProvider { |
| 51 | 51 | |
| 52 | - const SHARE_TYPE_REMOTE = 6; |
|
| 53 | - |
|
| 54 | - /** @var IDBConnection */ |
|
| 55 | - private $dbConnection; |
|
| 56 | - |
|
| 57 | - /** @var AddressHandler */ |
|
| 58 | - private $addressHandler; |
|
| 59 | - |
|
| 60 | - /** @var Notifications */ |
|
| 61 | - private $notifications; |
|
| 62 | - |
|
| 63 | - /** @var TokenHandler */ |
|
| 64 | - private $tokenHandler; |
|
| 65 | - |
|
| 66 | - /** @var IL10N */ |
|
| 67 | - private $l; |
|
| 68 | - |
|
| 69 | - /** @var ILogger */ |
|
| 70 | - private $logger; |
|
| 71 | - |
|
| 72 | - /** @var IRootFolder */ |
|
| 73 | - private $rootFolder; |
|
| 74 | - |
|
| 75 | - /** @var IConfig */ |
|
| 76 | - private $config; |
|
| 77 | - |
|
| 78 | - /** @var string */ |
|
| 79 | - private $externalShareTable = 'share_external'; |
|
| 80 | - |
|
| 81 | - /** @var IUserManager */ |
|
| 82 | - private $userManager; |
|
| 83 | - |
|
| 84 | - /** @var ICloudIdManager */ |
|
| 85 | - private $cloudIdManager; |
|
| 86 | - |
|
| 87 | - /** |
|
| 88 | - * DefaultShareProvider constructor. |
|
| 89 | - * |
|
| 90 | - * @param IDBConnection $connection |
|
| 91 | - * @param AddressHandler $addressHandler |
|
| 92 | - * @param Notifications $notifications |
|
| 93 | - * @param TokenHandler $tokenHandler |
|
| 94 | - * @param IL10N $l10n |
|
| 95 | - * @param ILogger $logger |
|
| 96 | - * @param IRootFolder $rootFolder |
|
| 97 | - * @param IConfig $config |
|
| 98 | - * @param IUserManager $userManager |
|
| 99 | - * @param ICloudIdManager $cloudIdManager |
|
| 100 | - */ |
|
| 101 | - public function __construct( |
|
| 102 | - IDBConnection $connection, |
|
| 103 | - AddressHandler $addressHandler, |
|
| 104 | - Notifications $notifications, |
|
| 105 | - TokenHandler $tokenHandler, |
|
| 106 | - IL10N $l10n, |
|
| 107 | - ILogger $logger, |
|
| 108 | - IRootFolder $rootFolder, |
|
| 109 | - IConfig $config, |
|
| 110 | - IUserManager $userManager, |
|
| 111 | - ICloudIdManager $cloudIdManager |
|
| 112 | - ) { |
|
| 113 | - $this->dbConnection = $connection; |
|
| 114 | - $this->addressHandler = $addressHandler; |
|
| 115 | - $this->notifications = $notifications; |
|
| 116 | - $this->tokenHandler = $tokenHandler; |
|
| 117 | - $this->l = $l10n; |
|
| 118 | - $this->logger = $logger; |
|
| 119 | - $this->rootFolder = $rootFolder; |
|
| 120 | - $this->config = $config; |
|
| 121 | - $this->userManager = $userManager; |
|
| 122 | - $this->cloudIdManager = $cloudIdManager; |
|
| 123 | - } |
|
| 124 | - |
|
| 125 | - /** |
|
| 126 | - * Return the identifier of this provider. |
|
| 127 | - * |
|
| 128 | - * @return string Containing only [a-zA-Z0-9] |
|
| 129 | - */ |
|
| 130 | - public function identifier() { |
|
| 131 | - return 'ocFederatedSharing'; |
|
| 132 | - } |
|
| 133 | - |
|
| 134 | - /** |
|
| 135 | - * Share a path |
|
| 136 | - * |
|
| 137 | - * @param IShare $share |
|
| 138 | - * @return IShare The share object |
|
| 139 | - * @throws ShareNotFound |
|
| 140 | - * @throws \Exception |
|
| 141 | - */ |
|
| 142 | - public function create(IShare $share) { |
|
| 143 | - |
|
| 144 | - $shareWith = $share->getSharedWith(); |
|
| 145 | - $itemSource = $share->getNodeId(); |
|
| 146 | - $itemType = $share->getNodeType(); |
|
| 147 | - $permissions = $share->getPermissions(); |
|
| 148 | - $sharedBy = $share->getSharedBy(); |
|
| 149 | - |
|
| 150 | - /* |
|
| 52 | + const SHARE_TYPE_REMOTE = 6; |
|
| 53 | + |
|
| 54 | + /** @var IDBConnection */ |
|
| 55 | + private $dbConnection; |
|
| 56 | + |
|
| 57 | + /** @var AddressHandler */ |
|
| 58 | + private $addressHandler; |
|
| 59 | + |
|
| 60 | + /** @var Notifications */ |
|
| 61 | + private $notifications; |
|
| 62 | + |
|
| 63 | + /** @var TokenHandler */ |
|
| 64 | + private $tokenHandler; |
|
| 65 | + |
|
| 66 | + /** @var IL10N */ |
|
| 67 | + private $l; |
|
| 68 | + |
|
| 69 | + /** @var ILogger */ |
|
| 70 | + private $logger; |
|
| 71 | + |
|
| 72 | + /** @var IRootFolder */ |
|
| 73 | + private $rootFolder; |
|
| 74 | + |
|
| 75 | + /** @var IConfig */ |
|
| 76 | + private $config; |
|
| 77 | + |
|
| 78 | + /** @var string */ |
|
| 79 | + private $externalShareTable = 'share_external'; |
|
| 80 | + |
|
| 81 | + /** @var IUserManager */ |
|
| 82 | + private $userManager; |
|
| 83 | + |
|
| 84 | + /** @var ICloudIdManager */ |
|
| 85 | + private $cloudIdManager; |
|
| 86 | + |
|
| 87 | + /** |
|
| 88 | + * DefaultShareProvider constructor. |
|
| 89 | + * |
|
| 90 | + * @param IDBConnection $connection |
|
| 91 | + * @param AddressHandler $addressHandler |
|
| 92 | + * @param Notifications $notifications |
|
| 93 | + * @param TokenHandler $tokenHandler |
|
| 94 | + * @param IL10N $l10n |
|
| 95 | + * @param ILogger $logger |
|
| 96 | + * @param IRootFolder $rootFolder |
|
| 97 | + * @param IConfig $config |
|
| 98 | + * @param IUserManager $userManager |
|
| 99 | + * @param ICloudIdManager $cloudIdManager |
|
| 100 | + */ |
|
| 101 | + public function __construct( |
|
| 102 | + IDBConnection $connection, |
|
| 103 | + AddressHandler $addressHandler, |
|
| 104 | + Notifications $notifications, |
|
| 105 | + TokenHandler $tokenHandler, |
|
| 106 | + IL10N $l10n, |
|
| 107 | + ILogger $logger, |
|
| 108 | + IRootFolder $rootFolder, |
|
| 109 | + IConfig $config, |
|
| 110 | + IUserManager $userManager, |
|
| 111 | + ICloudIdManager $cloudIdManager |
|
| 112 | + ) { |
|
| 113 | + $this->dbConnection = $connection; |
|
| 114 | + $this->addressHandler = $addressHandler; |
|
| 115 | + $this->notifications = $notifications; |
|
| 116 | + $this->tokenHandler = $tokenHandler; |
|
| 117 | + $this->l = $l10n; |
|
| 118 | + $this->logger = $logger; |
|
| 119 | + $this->rootFolder = $rootFolder; |
|
| 120 | + $this->config = $config; |
|
| 121 | + $this->userManager = $userManager; |
|
| 122 | + $this->cloudIdManager = $cloudIdManager; |
|
| 123 | + } |
|
| 124 | + |
|
| 125 | + /** |
|
| 126 | + * Return the identifier of this provider. |
|
| 127 | + * |
|
| 128 | + * @return string Containing only [a-zA-Z0-9] |
|
| 129 | + */ |
|
| 130 | + public function identifier() { |
|
| 131 | + return 'ocFederatedSharing'; |
|
| 132 | + } |
|
| 133 | + |
|
| 134 | + /** |
|
| 135 | + * Share a path |
|
| 136 | + * |
|
| 137 | + * @param IShare $share |
|
| 138 | + * @return IShare The share object |
|
| 139 | + * @throws ShareNotFound |
|
| 140 | + * @throws \Exception |
|
| 141 | + */ |
|
| 142 | + public function create(IShare $share) { |
|
| 143 | + |
|
| 144 | + $shareWith = $share->getSharedWith(); |
|
| 145 | + $itemSource = $share->getNodeId(); |
|
| 146 | + $itemType = $share->getNodeType(); |
|
| 147 | + $permissions = $share->getPermissions(); |
|
| 148 | + $sharedBy = $share->getSharedBy(); |
|
| 149 | + |
|
| 150 | + /* |
|
| 151 | 151 | * Check if file is not already shared with the remote user |
| 152 | 152 | */ |
| 153 | - $alreadyShared = $this->getSharedWith($shareWith, self::SHARE_TYPE_REMOTE, $share->getNode(), 1, 0); |
|
| 154 | - if (!empty($alreadyShared)) { |
|
| 155 | - $message = 'Sharing %s failed, because this item is already shared with %s'; |
|
| 156 | - $message_t = $this->l->t('Sharing %s failed, because this item is already shared with %s', array($share->getNode()->getName(), $shareWith)); |
|
| 157 | - $this->logger->debug(sprintf($message, $share->getNode()->getName(), $shareWith), ['app' => 'Federated File Sharing']); |
|
| 158 | - throw new \Exception($message_t); |
|
| 159 | - } |
|
| 160 | - |
|
| 161 | - |
|
| 162 | - // don't allow federated shares if source and target server are the same |
|
| 163 | - $cloudId = $this->cloudIdManager->resolveCloudId($shareWith); |
|
| 164 | - $currentServer = $this->addressHandler->generateRemoteURL(); |
|
| 165 | - $currentUser = $sharedBy; |
|
| 166 | - if ($this->addressHandler->compareAddresses($cloudId->getUser(), $cloudId->getRemote(), $currentUser, $currentServer)) { |
|
| 167 | - $message = 'Not allowed to create a federated share with the same user.'; |
|
| 168 | - $message_t = $this->l->t('Not allowed to create a federated share with the same user'); |
|
| 169 | - $this->logger->debug($message, ['app' => 'Federated File Sharing']); |
|
| 170 | - throw new \Exception($message_t); |
|
| 171 | - } |
|
| 172 | - |
|
| 173 | - |
|
| 174 | - $share->setSharedWith($cloudId->getId()); |
|
| 175 | - |
|
| 176 | - try { |
|
| 177 | - $remoteShare = $this->getShareFromExternalShareTable($share); |
|
| 178 | - } catch (ShareNotFound $e) { |
|
| 179 | - $remoteShare = null; |
|
| 180 | - } |
|
| 181 | - |
|
| 182 | - if ($remoteShare) { |
|
| 183 | - try { |
|
| 184 | - $ownerCloudId = $this->cloudIdManager->getCloudId($remoteShare['owner'], $remoteShare['remote']); |
|
| 185 | - $shareId = $this->addShareToDB($itemSource, $itemType, $shareWith, $sharedBy, $ownerCloudId->getId(), $permissions, 'tmp_token_' . time()); |
|
| 186 | - $share->setId($shareId); |
|
| 187 | - list($token, $remoteId) = $this->askOwnerToReShare($shareWith, $share, $shareId); |
|
| 188 | - // remote share was create successfully if we get a valid token as return |
|
| 189 | - $send = is_string($token) && $token !== ''; |
|
| 190 | - } catch (\Exception $e) { |
|
| 191 | - // fall back to old re-share behavior if the remote server |
|
| 192 | - // doesn't support flat re-shares (was introduced with Nextcloud 9.1) |
|
| 193 | - $this->removeShareFromTable($share); |
|
| 194 | - $shareId = $this->createFederatedShare($share); |
|
| 195 | - } |
|
| 196 | - if ($send) { |
|
| 197 | - $this->updateSuccessfulReshare($shareId, $token); |
|
| 198 | - $this->storeRemoteId($shareId, $remoteId); |
|
| 199 | - } else { |
|
| 200 | - $this->removeShareFromTable($share); |
|
| 201 | - $message_t = $this->l->t('File is already shared with %s', [$shareWith]); |
|
| 202 | - throw new \Exception($message_t); |
|
| 203 | - } |
|
| 204 | - |
|
| 205 | - } else { |
|
| 206 | - $shareId = $this->createFederatedShare($share); |
|
| 207 | - } |
|
| 208 | - |
|
| 209 | - $data = $this->getRawShare($shareId); |
|
| 210 | - return $this->createShareObject($data); |
|
| 211 | - } |
|
| 212 | - |
|
| 213 | - /** |
|
| 214 | - * create federated share and inform the recipient |
|
| 215 | - * |
|
| 216 | - * @param IShare $share |
|
| 217 | - * @return int |
|
| 218 | - * @throws ShareNotFound |
|
| 219 | - * @throws \Exception |
|
| 220 | - */ |
|
| 221 | - protected function createFederatedShare(IShare $share) { |
|
| 222 | - $token = $this->tokenHandler->generateToken(); |
|
| 223 | - $shareId = $this->addShareToDB( |
|
| 224 | - $share->getNodeId(), |
|
| 225 | - $share->getNodeType(), |
|
| 226 | - $share->getSharedWith(), |
|
| 227 | - $share->getSharedBy(), |
|
| 228 | - $share->getShareOwner(), |
|
| 229 | - $share->getPermissions(), |
|
| 230 | - $token |
|
| 231 | - ); |
|
| 232 | - |
|
| 233 | - $failure = false; |
|
| 234 | - |
|
| 235 | - try { |
|
| 236 | - $sharedByFederatedId = $share->getSharedBy(); |
|
| 237 | - if ($this->userManager->userExists($sharedByFederatedId)) { |
|
| 238 | - $cloudId = $this->cloudIdManager->getCloudId($sharedByFederatedId, $this->addressHandler->generateRemoteURL()); |
|
| 239 | - $sharedByFederatedId = $cloudId->getId(); |
|
| 240 | - } |
|
| 241 | - $ownerCloudId = $this->cloudIdManager->getCloudId($share->getShareOwner(), $this->addressHandler->generateRemoteURL()); |
|
| 242 | - $send = $this->notifications->sendRemoteShare( |
|
| 243 | - $token, |
|
| 244 | - $share->getSharedWith(), |
|
| 245 | - $share->getNode()->getName(), |
|
| 246 | - $shareId, |
|
| 247 | - $share->getShareOwner(), |
|
| 248 | - $ownerCloudId->getId(), |
|
| 249 | - $share->getSharedBy(), |
|
| 250 | - $sharedByFederatedId |
|
| 251 | - ); |
|
| 252 | - |
|
| 253 | - if ($send === false) { |
|
| 254 | - $failure = true; |
|
| 255 | - } |
|
| 256 | - } catch (\Exception $e) { |
|
| 257 | - $this->logger->error('Failed to notify remote server of federated share, removing share (' . $e->getMessage() . ')'); |
|
| 258 | - $failure = true; |
|
| 259 | - } |
|
| 260 | - |
|
| 261 | - if($failure) { |
|
| 262 | - $this->removeShareFromTableById($shareId); |
|
| 263 | - $message_t = $this->l->t('Sharing %s failed, could not find %s, maybe the server is currently unreachable or uses a self-signed certificate.', |
|
| 264 | - [$share->getNode()->getName(), $share->getSharedWith()]); |
|
| 265 | - throw new \Exception($message_t); |
|
| 266 | - } |
|
| 267 | - |
|
| 268 | - return $shareId; |
|
| 269 | - |
|
| 270 | - } |
|
| 271 | - |
|
| 272 | - /** |
|
| 273 | - * @param string $shareWith |
|
| 274 | - * @param IShare $share |
|
| 275 | - * @param string $shareId internal share Id |
|
| 276 | - * @return array |
|
| 277 | - * @throws \Exception |
|
| 278 | - */ |
|
| 279 | - protected function askOwnerToReShare($shareWith, IShare $share, $shareId) { |
|
| 280 | - |
|
| 281 | - $remoteShare = $this->getShareFromExternalShareTable($share); |
|
| 282 | - $token = $remoteShare['share_token']; |
|
| 283 | - $remoteId = $remoteShare['remote_id']; |
|
| 284 | - $remote = $remoteShare['remote']; |
|
| 285 | - |
|
| 286 | - list($token, $remoteId) = $this->notifications->requestReShare( |
|
| 287 | - $token, |
|
| 288 | - $remoteId, |
|
| 289 | - $shareId, |
|
| 290 | - $remote, |
|
| 291 | - $shareWith, |
|
| 292 | - $share->getPermissions() |
|
| 293 | - ); |
|
| 294 | - |
|
| 295 | - return [$token, $remoteId]; |
|
| 296 | - } |
|
| 297 | - |
|
| 298 | - /** |
|
| 299 | - * get federated share from the share_external table but exclude mounted link shares |
|
| 300 | - * |
|
| 301 | - * @param IShare $share |
|
| 302 | - * @return array |
|
| 303 | - * @throws ShareNotFound |
|
| 304 | - */ |
|
| 305 | - protected function getShareFromExternalShareTable(IShare $share) { |
|
| 306 | - $query = $this->dbConnection->getQueryBuilder(); |
|
| 307 | - $query->select('*')->from($this->externalShareTable) |
|
| 308 | - ->where($query->expr()->eq('user', $query->createNamedParameter($share->getShareOwner()))) |
|
| 309 | - ->andWhere($query->expr()->eq('mountpoint', $query->createNamedParameter($share->getTarget()))); |
|
| 310 | - $result = $query->execute()->fetchAll(); |
|
| 311 | - |
|
| 312 | - if (isset($result[0]) && (int)$result[0]['remote_id'] > 0) { |
|
| 313 | - return $result[0]; |
|
| 314 | - } |
|
| 315 | - |
|
| 316 | - throw new ShareNotFound('share not found in share_external table'); |
|
| 317 | - } |
|
| 318 | - |
|
| 319 | - /** |
|
| 320 | - * add share to the database and return the ID |
|
| 321 | - * |
|
| 322 | - * @param int $itemSource |
|
| 323 | - * @param string $itemType |
|
| 324 | - * @param string $shareWith |
|
| 325 | - * @param string $sharedBy |
|
| 326 | - * @param string $uidOwner |
|
| 327 | - * @param int $permissions |
|
| 328 | - * @param string $token |
|
| 329 | - * @return int |
|
| 330 | - */ |
|
| 331 | - private function addShareToDB($itemSource, $itemType, $shareWith, $sharedBy, $uidOwner, $permissions, $token) { |
|
| 332 | - $qb = $this->dbConnection->getQueryBuilder(); |
|
| 333 | - $qb->insert('share') |
|
| 334 | - ->setValue('share_type', $qb->createNamedParameter(self::SHARE_TYPE_REMOTE)) |
|
| 335 | - ->setValue('item_type', $qb->createNamedParameter($itemType)) |
|
| 336 | - ->setValue('item_source', $qb->createNamedParameter($itemSource)) |
|
| 337 | - ->setValue('file_source', $qb->createNamedParameter($itemSource)) |
|
| 338 | - ->setValue('share_with', $qb->createNamedParameter($shareWith)) |
|
| 339 | - ->setValue('uid_owner', $qb->createNamedParameter($uidOwner)) |
|
| 340 | - ->setValue('uid_initiator', $qb->createNamedParameter($sharedBy)) |
|
| 341 | - ->setValue('permissions', $qb->createNamedParameter($permissions)) |
|
| 342 | - ->setValue('token', $qb->createNamedParameter($token)) |
|
| 343 | - ->setValue('stime', $qb->createNamedParameter(time())); |
|
| 344 | - |
|
| 345 | - /* |
|
| 153 | + $alreadyShared = $this->getSharedWith($shareWith, self::SHARE_TYPE_REMOTE, $share->getNode(), 1, 0); |
|
| 154 | + if (!empty($alreadyShared)) { |
|
| 155 | + $message = 'Sharing %s failed, because this item is already shared with %s'; |
|
| 156 | + $message_t = $this->l->t('Sharing %s failed, because this item is already shared with %s', array($share->getNode()->getName(), $shareWith)); |
|
| 157 | + $this->logger->debug(sprintf($message, $share->getNode()->getName(), $shareWith), ['app' => 'Federated File Sharing']); |
|
| 158 | + throw new \Exception($message_t); |
|
| 159 | + } |
|
| 160 | + |
|
| 161 | + |
|
| 162 | + // don't allow federated shares if source and target server are the same |
|
| 163 | + $cloudId = $this->cloudIdManager->resolveCloudId($shareWith); |
|
| 164 | + $currentServer = $this->addressHandler->generateRemoteURL(); |
|
| 165 | + $currentUser = $sharedBy; |
|
| 166 | + if ($this->addressHandler->compareAddresses($cloudId->getUser(), $cloudId->getRemote(), $currentUser, $currentServer)) { |
|
| 167 | + $message = 'Not allowed to create a federated share with the same user.'; |
|
| 168 | + $message_t = $this->l->t('Not allowed to create a federated share with the same user'); |
|
| 169 | + $this->logger->debug($message, ['app' => 'Federated File Sharing']); |
|
| 170 | + throw new \Exception($message_t); |
|
| 171 | + } |
|
| 172 | + |
|
| 173 | + |
|
| 174 | + $share->setSharedWith($cloudId->getId()); |
|
| 175 | + |
|
| 176 | + try { |
|
| 177 | + $remoteShare = $this->getShareFromExternalShareTable($share); |
|
| 178 | + } catch (ShareNotFound $e) { |
|
| 179 | + $remoteShare = null; |
|
| 180 | + } |
|
| 181 | + |
|
| 182 | + if ($remoteShare) { |
|
| 183 | + try { |
|
| 184 | + $ownerCloudId = $this->cloudIdManager->getCloudId($remoteShare['owner'], $remoteShare['remote']); |
|
| 185 | + $shareId = $this->addShareToDB($itemSource, $itemType, $shareWith, $sharedBy, $ownerCloudId->getId(), $permissions, 'tmp_token_' . time()); |
|
| 186 | + $share->setId($shareId); |
|
| 187 | + list($token, $remoteId) = $this->askOwnerToReShare($shareWith, $share, $shareId); |
|
| 188 | + // remote share was create successfully if we get a valid token as return |
|
| 189 | + $send = is_string($token) && $token !== ''; |
|
| 190 | + } catch (\Exception $e) { |
|
| 191 | + // fall back to old re-share behavior if the remote server |
|
| 192 | + // doesn't support flat re-shares (was introduced with Nextcloud 9.1) |
|
| 193 | + $this->removeShareFromTable($share); |
|
| 194 | + $shareId = $this->createFederatedShare($share); |
|
| 195 | + } |
|
| 196 | + if ($send) { |
|
| 197 | + $this->updateSuccessfulReshare($shareId, $token); |
|
| 198 | + $this->storeRemoteId($shareId, $remoteId); |
|
| 199 | + } else { |
|
| 200 | + $this->removeShareFromTable($share); |
|
| 201 | + $message_t = $this->l->t('File is already shared with %s', [$shareWith]); |
|
| 202 | + throw new \Exception($message_t); |
|
| 203 | + } |
|
| 204 | + |
|
| 205 | + } else { |
|
| 206 | + $shareId = $this->createFederatedShare($share); |
|
| 207 | + } |
|
| 208 | + |
|
| 209 | + $data = $this->getRawShare($shareId); |
|
| 210 | + return $this->createShareObject($data); |
|
| 211 | + } |
|
| 212 | + |
|
| 213 | + /** |
|
| 214 | + * create federated share and inform the recipient |
|
| 215 | + * |
|
| 216 | + * @param IShare $share |
|
| 217 | + * @return int |
|
| 218 | + * @throws ShareNotFound |
|
| 219 | + * @throws \Exception |
|
| 220 | + */ |
|
| 221 | + protected function createFederatedShare(IShare $share) { |
|
| 222 | + $token = $this->tokenHandler->generateToken(); |
|
| 223 | + $shareId = $this->addShareToDB( |
|
| 224 | + $share->getNodeId(), |
|
| 225 | + $share->getNodeType(), |
|
| 226 | + $share->getSharedWith(), |
|
| 227 | + $share->getSharedBy(), |
|
| 228 | + $share->getShareOwner(), |
|
| 229 | + $share->getPermissions(), |
|
| 230 | + $token |
|
| 231 | + ); |
|
| 232 | + |
|
| 233 | + $failure = false; |
|
| 234 | + |
|
| 235 | + try { |
|
| 236 | + $sharedByFederatedId = $share->getSharedBy(); |
|
| 237 | + if ($this->userManager->userExists($sharedByFederatedId)) { |
|
| 238 | + $cloudId = $this->cloudIdManager->getCloudId($sharedByFederatedId, $this->addressHandler->generateRemoteURL()); |
|
| 239 | + $sharedByFederatedId = $cloudId->getId(); |
|
| 240 | + } |
|
| 241 | + $ownerCloudId = $this->cloudIdManager->getCloudId($share->getShareOwner(), $this->addressHandler->generateRemoteURL()); |
|
| 242 | + $send = $this->notifications->sendRemoteShare( |
|
| 243 | + $token, |
|
| 244 | + $share->getSharedWith(), |
|
| 245 | + $share->getNode()->getName(), |
|
| 246 | + $shareId, |
|
| 247 | + $share->getShareOwner(), |
|
| 248 | + $ownerCloudId->getId(), |
|
| 249 | + $share->getSharedBy(), |
|
| 250 | + $sharedByFederatedId |
|
| 251 | + ); |
|
| 252 | + |
|
| 253 | + if ($send === false) { |
|
| 254 | + $failure = true; |
|
| 255 | + } |
|
| 256 | + } catch (\Exception $e) { |
|
| 257 | + $this->logger->error('Failed to notify remote server of federated share, removing share (' . $e->getMessage() . ')'); |
|
| 258 | + $failure = true; |
|
| 259 | + } |
|
| 260 | + |
|
| 261 | + if($failure) { |
|
| 262 | + $this->removeShareFromTableById($shareId); |
|
| 263 | + $message_t = $this->l->t('Sharing %s failed, could not find %s, maybe the server is currently unreachable or uses a self-signed certificate.', |
|
| 264 | + [$share->getNode()->getName(), $share->getSharedWith()]); |
|
| 265 | + throw new \Exception($message_t); |
|
| 266 | + } |
|
| 267 | + |
|
| 268 | + return $shareId; |
|
| 269 | + |
|
| 270 | + } |
|
| 271 | + |
|
| 272 | + /** |
|
| 273 | + * @param string $shareWith |
|
| 274 | + * @param IShare $share |
|
| 275 | + * @param string $shareId internal share Id |
|
| 276 | + * @return array |
|
| 277 | + * @throws \Exception |
|
| 278 | + */ |
|
| 279 | + protected function askOwnerToReShare($shareWith, IShare $share, $shareId) { |
|
| 280 | + |
|
| 281 | + $remoteShare = $this->getShareFromExternalShareTable($share); |
|
| 282 | + $token = $remoteShare['share_token']; |
|
| 283 | + $remoteId = $remoteShare['remote_id']; |
|
| 284 | + $remote = $remoteShare['remote']; |
|
| 285 | + |
|
| 286 | + list($token, $remoteId) = $this->notifications->requestReShare( |
|
| 287 | + $token, |
|
| 288 | + $remoteId, |
|
| 289 | + $shareId, |
|
| 290 | + $remote, |
|
| 291 | + $shareWith, |
|
| 292 | + $share->getPermissions() |
|
| 293 | + ); |
|
| 294 | + |
|
| 295 | + return [$token, $remoteId]; |
|
| 296 | + } |
|
| 297 | + |
|
| 298 | + /** |
|
| 299 | + * get federated share from the share_external table but exclude mounted link shares |
|
| 300 | + * |
|
| 301 | + * @param IShare $share |
|
| 302 | + * @return array |
|
| 303 | + * @throws ShareNotFound |
|
| 304 | + */ |
|
| 305 | + protected function getShareFromExternalShareTable(IShare $share) { |
|
| 306 | + $query = $this->dbConnection->getQueryBuilder(); |
|
| 307 | + $query->select('*')->from($this->externalShareTable) |
|
| 308 | + ->where($query->expr()->eq('user', $query->createNamedParameter($share->getShareOwner()))) |
|
| 309 | + ->andWhere($query->expr()->eq('mountpoint', $query->createNamedParameter($share->getTarget()))); |
|
| 310 | + $result = $query->execute()->fetchAll(); |
|
| 311 | + |
|
| 312 | + if (isset($result[0]) && (int)$result[0]['remote_id'] > 0) { |
|
| 313 | + return $result[0]; |
|
| 314 | + } |
|
| 315 | + |
|
| 316 | + throw new ShareNotFound('share not found in share_external table'); |
|
| 317 | + } |
|
| 318 | + |
|
| 319 | + /** |
|
| 320 | + * add share to the database and return the ID |
|
| 321 | + * |
|
| 322 | + * @param int $itemSource |
|
| 323 | + * @param string $itemType |
|
| 324 | + * @param string $shareWith |
|
| 325 | + * @param string $sharedBy |
|
| 326 | + * @param string $uidOwner |
|
| 327 | + * @param int $permissions |
|
| 328 | + * @param string $token |
|
| 329 | + * @return int |
|
| 330 | + */ |
|
| 331 | + private function addShareToDB($itemSource, $itemType, $shareWith, $sharedBy, $uidOwner, $permissions, $token) { |
|
| 332 | + $qb = $this->dbConnection->getQueryBuilder(); |
|
| 333 | + $qb->insert('share') |
|
| 334 | + ->setValue('share_type', $qb->createNamedParameter(self::SHARE_TYPE_REMOTE)) |
|
| 335 | + ->setValue('item_type', $qb->createNamedParameter($itemType)) |
|
| 336 | + ->setValue('item_source', $qb->createNamedParameter($itemSource)) |
|
| 337 | + ->setValue('file_source', $qb->createNamedParameter($itemSource)) |
|
| 338 | + ->setValue('share_with', $qb->createNamedParameter($shareWith)) |
|
| 339 | + ->setValue('uid_owner', $qb->createNamedParameter($uidOwner)) |
|
| 340 | + ->setValue('uid_initiator', $qb->createNamedParameter($sharedBy)) |
|
| 341 | + ->setValue('permissions', $qb->createNamedParameter($permissions)) |
|
| 342 | + ->setValue('token', $qb->createNamedParameter($token)) |
|
| 343 | + ->setValue('stime', $qb->createNamedParameter(time())); |
|
| 344 | + |
|
| 345 | + /* |
|
| 346 | 346 | * Added to fix https://github.com/owncloud/core/issues/22215 |
| 347 | 347 | * Can be removed once we get rid of ajax/share.php |
| 348 | 348 | */ |
| 349 | - $qb->setValue('file_target', $qb->createNamedParameter('')); |
|
| 350 | - |
|
| 351 | - $qb->execute(); |
|
| 352 | - $id = $qb->getLastInsertId(); |
|
| 353 | - |
|
| 354 | - return (int)$id; |
|
| 355 | - } |
|
| 356 | - |
|
| 357 | - /** |
|
| 358 | - * Update a share |
|
| 359 | - * |
|
| 360 | - * @param IShare $share |
|
| 361 | - * @return IShare The share object |
|
| 362 | - */ |
|
| 363 | - public function update(IShare $share) { |
|
| 364 | - /* |
|
| 349 | + $qb->setValue('file_target', $qb->createNamedParameter('')); |
|
| 350 | + |
|
| 351 | + $qb->execute(); |
|
| 352 | + $id = $qb->getLastInsertId(); |
|
| 353 | + |
|
| 354 | + return (int)$id; |
|
| 355 | + } |
|
| 356 | + |
|
| 357 | + /** |
|
| 358 | + * Update a share |
|
| 359 | + * |
|
| 360 | + * @param IShare $share |
|
| 361 | + * @return IShare The share object |
|
| 362 | + */ |
|
| 363 | + public function update(IShare $share) { |
|
| 364 | + /* |
|
| 365 | 365 | * We allow updating the permissions of federated shares |
| 366 | 366 | */ |
| 367 | - $qb = $this->dbConnection->getQueryBuilder(); |
|
| 368 | - $qb->update('share') |
|
| 369 | - ->where($qb->expr()->eq('id', $qb->createNamedParameter($share->getId()))) |
|
| 370 | - ->set('permissions', $qb->createNamedParameter($share->getPermissions())) |
|
| 371 | - ->set('uid_owner', $qb->createNamedParameter($share->getShareOwner())) |
|
| 372 | - ->set('uid_initiator', $qb->createNamedParameter($share->getSharedBy())) |
|
| 373 | - ->execute(); |
|
| 374 | - |
|
| 375 | - // send the updated permission to the owner/initiator, if they are not the same |
|
| 376 | - if ($share->getShareOwner() !== $share->getSharedBy()) { |
|
| 377 | - $this->sendPermissionUpdate($share); |
|
| 378 | - } |
|
| 379 | - |
|
| 380 | - return $share; |
|
| 381 | - } |
|
| 382 | - |
|
| 383 | - /** |
|
| 384 | - * send the updated permission to the owner/initiator, if they are not the same |
|
| 385 | - * |
|
| 386 | - * @param IShare $share |
|
| 387 | - * @throws ShareNotFound |
|
| 388 | - * @throws \OC\HintException |
|
| 389 | - */ |
|
| 390 | - protected function sendPermissionUpdate(IShare $share) { |
|
| 391 | - $remoteId = $this->getRemoteId($share); |
|
| 392 | - // if the local user is the owner we send the permission change to the initiator |
|
| 393 | - if ($this->userManager->userExists($share->getShareOwner())) { |
|
| 394 | - list(, $remote) = $this->addressHandler->splitUserRemote($share->getSharedBy()); |
|
| 395 | - } else { // ... if not we send the permission change to the owner |
|
| 396 | - list(, $remote) = $this->addressHandler->splitUserRemote($share->getShareOwner()); |
|
| 397 | - } |
|
| 398 | - $this->notifications->sendPermissionChange($remote, $remoteId, $share->getToken(), $share->getPermissions()); |
|
| 399 | - } |
|
| 400 | - |
|
| 401 | - |
|
| 402 | - /** |
|
| 403 | - * update successful reShare with the correct token |
|
| 404 | - * |
|
| 405 | - * @param int $shareId |
|
| 406 | - * @param string $token |
|
| 407 | - */ |
|
| 408 | - protected function updateSuccessfulReShare($shareId, $token) { |
|
| 409 | - $query = $this->dbConnection->getQueryBuilder(); |
|
| 410 | - $query->update('share') |
|
| 411 | - ->where($query->expr()->eq('id', $query->createNamedParameter($shareId))) |
|
| 412 | - ->set('token', $query->createNamedParameter($token)) |
|
| 413 | - ->execute(); |
|
| 414 | - } |
|
| 415 | - |
|
| 416 | - /** |
|
| 417 | - * store remote ID in federated reShare table |
|
| 418 | - * |
|
| 419 | - * @param $shareId |
|
| 420 | - * @param $remoteId |
|
| 421 | - */ |
|
| 422 | - public function storeRemoteId($shareId, $remoteId) { |
|
| 423 | - $query = $this->dbConnection->getQueryBuilder(); |
|
| 424 | - $query->insert('federated_reshares') |
|
| 425 | - ->values( |
|
| 426 | - [ |
|
| 427 | - 'share_id' => $query->createNamedParameter($shareId), |
|
| 428 | - 'remote_id' => $query->createNamedParameter($remoteId), |
|
| 429 | - ] |
|
| 430 | - ); |
|
| 431 | - $query->execute(); |
|
| 432 | - } |
|
| 433 | - |
|
| 434 | - /** |
|
| 435 | - * get share ID on remote server for federated re-shares |
|
| 436 | - * |
|
| 437 | - * @param IShare $share |
|
| 438 | - * @return int |
|
| 439 | - * @throws ShareNotFound |
|
| 440 | - */ |
|
| 441 | - public function getRemoteId(IShare $share) { |
|
| 442 | - $query = $this->dbConnection->getQueryBuilder(); |
|
| 443 | - $query->select('remote_id')->from('federated_reshares') |
|
| 444 | - ->where($query->expr()->eq('share_id', $query->createNamedParameter((int)$share->getId()))); |
|
| 445 | - $data = $query->execute()->fetch(); |
|
| 446 | - |
|
| 447 | - if (!is_array($data) || !isset($data['remote_id'])) { |
|
| 448 | - throw new ShareNotFound(); |
|
| 449 | - } |
|
| 450 | - |
|
| 451 | - return (int)$data['remote_id']; |
|
| 452 | - } |
|
| 453 | - |
|
| 454 | - /** |
|
| 455 | - * @inheritdoc |
|
| 456 | - */ |
|
| 457 | - public function move(IShare $share, $recipient) { |
|
| 458 | - /* |
|
| 367 | + $qb = $this->dbConnection->getQueryBuilder(); |
|
| 368 | + $qb->update('share') |
|
| 369 | + ->where($qb->expr()->eq('id', $qb->createNamedParameter($share->getId()))) |
|
| 370 | + ->set('permissions', $qb->createNamedParameter($share->getPermissions())) |
|
| 371 | + ->set('uid_owner', $qb->createNamedParameter($share->getShareOwner())) |
|
| 372 | + ->set('uid_initiator', $qb->createNamedParameter($share->getSharedBy())) |
|
| 373 | + ->execute(); |
|
| 374 | + |
|
| 375 | + // send the updated permission to the owner/initiator, if they are not the same |
|
| 376 | + if ($share->getShareOwner() !== $share->getSharedBy()) { |
|
| 377 | + $this->sendPermissionUpdate($share); |
|
| 378 | + } |
|
| 379 | + |
|
| 380 | + return $share; |
|
| 381 | + } |
|
| 382 | + |
|
| 383 | + /** |
|
| 384 | + * send the updated permission to the owner/initiator, if they are not the same |
|
| 385 | + * |
|
| 386 | + * @param IShare $share |
|
| 387 | + * @throws ShareNotFound |
|
| 388 | + * @throws \OC\HintException |
|
| 389 | + */ |
|
| 390 | + protected function sendPermissionUpdate(IShare $share) { |
|
| 391 | + $remoteId = $this->getRemoteId($share); |
|
| 392 | + // if the local user is the owner we send the permission change to the initiator |
|
| 393 | + if ($this->userManager->userExists($share->getShareOwner())) { |
|
| 394 | + list(, $remote) = $this->addressHandler->splitUserRemote($share->getSharedBy()); |
|
| 395 | + } else { // ... if not we send the permission change to the owner |
|
| 396 | + list(, $remote) = $this->addressHandler->splitUserRemote($share->getShareOwner()); |
|
| 397 | + } |
|
| 398 | + $this->notifications->sendPermissionChange($remote, $remoteId, $share->getToken(), $share->getPermissions()); |
|
| 399 | + } |
|
| 400 | + |
|
| 401 | + |
|
| 402 | + /** |
|
| 403 | + * update successful reShare with the correct token |
|
| 404 | + * |
|
| 405 | + * @param int $shareId |
|
| 406 | + * @param string $token |
|
| 407 | + */ |
|
| 408 | + protected function updateSuccessfulReShare($shareId, $token) { |
|
| 409 | + $query = $this->dbConnection->getQueryBuilder(); |
|
| 410 | + $query->update('share') |
|
| 411 | + ->where($query->expr()->eq('id', $query->createNamedParameter($shareId))) |
|
| 412 | + ->set('token', $query->createNamedParameter($token)) |
|
| 413 | + ->execute(); |
|
| 414 | + } |
|
| 415 | + |
|
| 416 | + /** |
|
| 417 | + * store remote ID in federated reShare table |
|
| 418 | + * |
|
| 419 | + * @param $shareId |
|
| 420 | + * @param $remoteId |
|
| 421 | + */ |
|
| 422 | + public function storeRemoteId($shareId, $remoteId) { |
|
| 423 | + $query = $this->dbConnection->getQueryBuilder(); |
|
| 424 | + $query->insert('federated_reshares') |
|
| 425 | + ->values( |
|
| 426 | + [ |
|
| 427 | + 'share_id' => $query->createNamedParameter($shareId), |
|
| 428 | + 'remote_id' => $query->createNamedParameter($remoteId), |
|
| 429 | + ] |
|
| 430 | + ); |
|
| 431 | + $query->execute(); |
|
| 432 | + } |
|
| 433 | + |
|
| 434 | + /** |
|
| 435 | + * get share ID on remote server for federated re-shares |
|
| 436 | + * |
|
| 437 | + * @param IShare $share |
|
| 438 | + * @return int |
|
| 439 | + * @throws ShareNotFound |
|
| 440 | + */ |
|
| 441 | + public function getRemoteId(IShare $share) { |
|
| 442 | + $query = $this->dbConnection->getQueryBuilder(); |
|
| 443 | + $query->select('remote_id')->from('federated_reshares') |
|
| 444 | + ->where($query->expr()->eq('share_id', $query->createNamedParameter((int)$share->getId()))); |
|
| 445 | + $data = $query->execute()->fetch(); |
|
| 446 | + |
|
| 447 | + if (!is_array($data) || !isset($data['remote_id'])) { |
|
| 448 | + throw new ShareNotFound(); |
|
| 449 | + } |
|
| 450 | + |
|
| 451 | + return (int)$data['remote_id']; |
|
| 452 | + } |
|
| 453 | + |
|
| 454 | + /** |
|
| 455 | + * @inheritdoc |
|
| 456 | + */ |
|
| 457 | + public function move(IShare $share, $recipient) { |
|
| 458 | + /* |
|
| 459 | 459 | * This function does nothing yet as it is just for outgoing |
| 460 | 460 | * federated shares. |
| 461 | 461 | */ |
| 462 | - return $share; |
|
| 463 | - } |
|
| 464 | - |
|
| 465 | - /** |
|
| 466 | - * Get all children of this share |
|
| 467 | - * |
|
| 468 | - * @param IShare $parent |
|
| 469 | - * @return IShare[] |
|
| 470 | - */ |
|
| 471 | - public function getChildren(IShare $parent) { |
|
| 472 | - $children = []; |
|
| 473 | - |
|
| 474 | - $qb = $this->dbConnection->getQueryBuilder(); |
|
| 475 | - $qb->select('*') |
|
| 476 | - ->from('share') |
|
| 477 | - ->where($qb->expr()->eq('parent', $qb->createNamedParameter($parent->getId()))) |
|
| 478 | - ->andWhere($qb->expr()->eq('share_type', $qb->createNamedParameter(self::SHARE_TYPE_REMOTE))) |
|
| 479 | - ->orderBy('id'); |
|
| 480 | - |
|
| 481 | - $cursor = $qb->execute(); |
|
| 482 | - while($data = $cursor->fetch()) { |
|
| 483 | - $children[] = $this->createShareObject($data); |
|
| 484 | - } |
|
| 485 | - $cursor->closeCursor(); |
|
| 486 | - |
|
| 487 | - return $children; |
|
| 488 | - } |
|
| 489 | - |
|
| 490 | - /** |
|
| 491 | - * Delete a share (owner unShares the file) |
|
| 492 | - * |
|
| 493 | - * @param IShare $share |
|
| 494 | - */ |
|
| 495 | - public function delete(IShare $share) { |
|
| 496 | - |
|
| 497 | - list(, $remote) = $this->addressHandler->splitUserRemote($share->getSharedWith()); |
|
| 498 | - |
|
| 499 | - $isOwner = false; |
|
| 500 | - |
|
| 501 | - $this->removeShareFromTable($share); |
|
| 502 | - |
|
| 503 | - // if the local user is the owner we can send the unShare request directly... |
|
| 504 | - if ($this->userManager->userExists($share->getShareOwner())) { |
|
| 505 | - $this->notifications->sendRemoteUnShare($remote, $share->getId(), $share->getToken()); |
|
| 506 | - $this->revokeShare($share, true); |
|
| 507 | - $isOwner = true; |
|
| 508 | - } else { // ... if not we need to correct ID for the unShare request |
|
| 509 | - $remoteId = $this->getRemoteId($share); |
|
| 510 | - $this->notifications->sendRemoteUnShare($remote, $remoteId, $share->getToken()); |
|
| 511 | - $this->revokeShare($share, false); |
|
| 512 | - } |
|
| 513 | - |
|
| 514 | - // send revoke notification to the other user, if initiator and owner are not the same user |
|
| 515 | - if ($share->getShareOwner() !== $share->getSharedBy()) { |
|
| 516 | - $remoteId = $this->getRemoteId($share); |
|
| 517 | - if ($isOwner) { |
|
| 518 | - list(, $remote) = $this->addressHandler->splitUserRemote($share->getSharedBy()); |
|
| 519 | - } else { |
|
| 520 | - list(, $remote) = $this->addressHandler->splitUserRemote($share->getShareOwner()); |
|
| 521 | - } |
|
| 522 | - $this->notifications->sendRevokeShare($remote, $remoteId, $share->getToken()); |
|
| 523 | - } |
|
| 524 | - } |
|
| 525 | - |
|
| 526 | - /** |
|
| 527 | - * in case of a re-share we need to send the other use (initiator or owner) |
|
| 528 | - * a message that the file was unshared |
|
| 529 | - * |
|
| 530 | - * @param IShare $share |
|
| 531 | - * @param bool $isOwner the user can either be the owner or the user who re-sahred it |
|
| 532 | - * @throws ShareNotFound |
|
| 533 | - * @throws \OC\HintException |
|
| 534 | - */ |
|
| 535 | - protected function revokeShare($share, $isOwner) { |
|
| 536 | - // also send a unShare request to the initiator, if this is a different user than the owner |
|
| 537 | - if ($share->getShareOwner() !== $share->getSharedBy()) { |
|
| 538 | - if ($isOwner) { |
|
| 539 | - list(, $remote) = $this->addressHandler->splitUserRemote($share->getSharedBy()); |
|
| 540 | - } else { |
|
| 541 | - list(, $remote) = $this->addressHandler->splitUserRemote($share->getShareOwner()); |
|
| 542 | - } |
|
| 543 | - $remoteId = $this->getRemoteId($share); |
|
| 544 | - $this->notifications->sendRevokeShare($remote, $remoteId, $share->getToken()); |
|
| 545 | - } |
|
| 546 | - } |
|
| 547 | - |
|
| 548 | - /** |
|
| 549 | - * remove share from table |
|
| 550 | - * |
|
| 551 | - * @param IShare $share |
|
| 552 | - */ |
|
| 553 | - public function removeShareFromTable(IShare $share) { |
|
| 554 | - $this->removeShareFromTableById($share->getId()); |
|
| 555 | - } |
|
| 556 | - |
|
| 557 | - /** |
|
| 558 | - * remove share from table |
|
| 559 | - * |
|
| 560 | - * @param string $shareId |
|
| 561 | - */ |
|
| 562 | - private function removeShareFromTableById($shareId) { |
|
| 563 | - $qb = $this->dbConnection->getQueryBuilder(); |
|
| 564 | - $qb->delete('share') |
|
| 565 | - ->where($qb->expr()->eq('id', $qb->createNamedParameter($shareId))); |
|
| 566 | - $qb->execute(); |
|
| 567 | - |
|
| 568 | - $qb->delete('federated_reshares') |
|
| 569 | - ->where($qb->expr()->eq('share_id', $qb->createNamedParameter($shareId))); |
|
| 570 | - $qb->execute(); |
|
| 571 | - } |
|
| 572 | - |
|
| 573 | - /** |
|
| 574 | - * @inheritdoc |
|
| 575 | - */ |
|
| 576 | - public function deleteFromSelf(IShare $share, $recipient) { |
|
| 577 | - // nothing to do here. Technically deleteFromSelf in the context of federated |
|
| 578 | - // shares is a umount of a external storage. This is handled here |
|
| 579 | - // apps/files_sharing/lib/external/manager.php |
|
| 580 | - // TODO move this code over to this app |
|
| 581 | - return; |
|
| 582 | - } |
|
| 583 | - |
|
| 584 | - |
|
| 585 | - public function getSharesInFolder($userId, Folder $node, $reshares) { |
|
| 586 | - $qb = $this->dbConnection->getQueryBuilder(); |
|
| 587 | - $qb->select('*') |
|
| 588 | - ->from('share', 's') |
|
| 589 | - ->andWhere($qb->expr()->orX( |
|
| 590 | - $qb->expr()->eq('item_type', $qb->createNamedParameter('file')), |
|
| 591 | - $qb->expr()->eq('item_type', $qb->createNamedParameter('folder')) |
|
| 592 | - )) |
|
| 593 | - ->andWhere( |
|
| 594 | - $qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_REMOTE)) |
|
| 595 | - ); |
|
| 596 | - |
|
| 597 | - /** |
|
| 598 | - * Reshares for this user are shares where they are the owner. |
|
| 599 | - */ |
|
| 600 | - if ($reshares === false) { |
|
| 601 | - $qb->andWhere($qb->expr()->eq('uid_initiator', $qb->createNamedParameter($userId))); |
|
| 602 | - } else { |
|
| 603 | - $qb->andWhere( |
|
| 604 | - $qb->expr()->orX( |
|
| 605 | - $qb->expr()->eq('uid_owner', $qb->createNamedParameter($userId)), |
|
| 606 | - $qb->expr()->eq('uid_initiator', $qb->createNamedParameter($userId)) |
|
| 607 | - ) |
|
| 608 | - ); |
|
| 609 | - } |
|
| 610 | - |
|
| 611 | - $qb->innerJoin('s', 'filecache' ,'f', 's.file_source = f.fileid'); |
|
| 612 | - $qb->andWhere($qb->expr()->eq('f.parent', $qb->createNamedParameter($node->getId()))); |
|
| 613 | - |
|
| 614 | - $qb->orderBy('id'); |
|
| 615 | - |
|
| 616 | - $cursor = $qb->execute(); |
|
| 617 | - $shares = []; |
|
| 618 | - while ($data = $cursor->fetch()) { |
|
| 619 | - $shares[$data['fileid']][] = $this->createShareObject($data); |
|
| 620 | - } |
|
| 621 | - $cursor->closeCursor(); |
|
| 622 | - |
|
| 623 | - return $shares; |
|
| 624 | - } |
|
| 625 | - |
|
| 626 | - /** |
|
| 627 | - * @inheritdoc |
|
| 628 | - */ |
|
| 629 | - public function getSharesBy($userId, $shareType, $node, $reshares, $limit, $offset) { |
|
| 630 | - $qb = $this->dbConnection->getQueryBuilder(); |
|
| 631 | - $qb->select('*') |
|
| 632 | - ->from('share'); |
|
| 633 | - |
|
| 634 | - $qb->andWhere($qb->expr()->eq('share_type', $qb->createNamedParameter(self::SHARE_TYPE_REMOTE))); |
|
| 635 | - |
|
| 636 | - /** |
|
| 637 | - * Reshares for this user are shares where they are the owner. |
|
| 638 | - */ |
|
| 639 | - if ($reshares === false) { |
|
| 640 | - //Special case for old shares created via the web UI |
|
| 641 | - $or1 = $qb->expr()->andX( |
|
| 642 | - $qb->expr()->eq('uid_owner', $qb->createNamedParameter($userId)), |
|
| 643 | - $qb->expr()->isNull('uid_initiator') |
|
| 644 | - ); |
|
| 645 | - |
|
| 646 | - $qb->andWhere( |
|
| 647 | - $qb->expr()->orX( |
|
| 648 | - $qb->expr()->eq('uid_initiator', $qb->createNamedParameter($userId)), |
|
| 649 | - $or1 |
|
| 650 | - ) |
|
| 651 | - ); |
|
| 652 | - } else { |
|
| 653 | - $qb->andWhere( |
|
| 654 | - $qb->expr()->orX( |
|
| 655 | - $qb->expr()->eq('uid_owner', $qb->createNamedParameter($userId)), |
|
| 656 | - $qb->expr()->eq('uid_initiator', $qb->createNamedParameter($userId)) |
|
| 657 | - ) |
|
| 658 | - ); |
|
| 659 | - } |
|
| 660 | - |
|
| 661 | - if ($node !== null) { |
|
| 662 | - $qb->andWhere($qb->expr()->eq('file_source', $qb->createNamedParameter($node->getId()))); |
|
| 663 | - } |
|
| 664 | - |
|
| 665 | - if ($limit !== -1) { |
|
| 666 | - $qb->setMaxResults($limit); |
|
| 667 | - } |
|
| 668 | - |
|
| 669 | - $qb->setFirstResult($offset); |
|
| 670 | - $qb->orderBy('id'); |
|
| 671 | - |
|
| 672 | - $cursor = $qb->execute(); |
|
| 673 | - $shares = []; |
|
| 674 | - while($data = $cursor->fetch()) { |
|
| 675 | - $shares[] = $this->createShareObject($data); |
|
| 676 | - } |
|
| 677 | - $cursor->closeCursor(); |
|
| 678 | - |
|
| 679 | - return $shares; |
|
| 680 | - } |
|
| 681 | - |
|
| 682 | - /** |
|
| 683 | - * @inheritdoc |
|
| 684 | - */ |
|
| 685 | - public function getShareById($id, $recipientId = null) { |
|
| 686 | - $qb = $this->dbConnection->getQueryBuilder(); |
|
| 687 | - |
|
| 688 | - $qb->select('*') |
|
| 689 | - ->from('share') |
|
| 690 | - ->where($qb->expr()->eq('id', $qb->createNamedParameter($id))) |
|
| 691 | - ->andWhere($qb->expr()->eq('share_type', $qb->createNamedParameter(self::SHARE_TYPE_REMOTE))); |
|
| 692 | - |
|
| 693 | - $cursor = $qb->execute(); |
|
| 694 | - $data = $cursor->fetch(); |
|
| 695 | - $cursor->closeCursor(); |
|
| 696 | - |
|
| 697 | - if ($data === false) { |
|
| 698 | - throw new ShareNotFound(); |
|
| 699 | - } |
|
| 700 | - |
|
| 701 | - try { |
|
| 702 | - $share = $this->createShareObject($data); |
|
| 703 | - } catch (InvalidShare $e) { |
|
| 704 | - throw new ShareNotFound(); |
|
| 705 | - } |
|
| 706 | - |
|
| 707 | - return $share; |
|
| 708 | - } |
|
| 709 | - |
|
| 710 | - /** |
|
| 711 | - * Get shares for a given path |
|
| 712 | - * |
|
| 713 | - * @param \OCP\Files\Node $path |
|
| 714 | - * @return IShare[] |
|
| 715 | - */ |
|
| 716 | - public function getSharesByPath(Node $path) { |
|
| 717 | - $qb = $this->dbConnection->getQueryBuilder(); |
|
| 718 | - |
|
| 719 | - $cursor = $qb->select('*') |
|
| 720 | - ->from('share') |
|
| 721 | - ->andWhere($qb->expr()->eq('file_source', $qb->createNamedParameter($path->getId()))) |
|
| 722 | - ->andWhere($qb->expr()->eq('share_type', $qb->createNamedParameter(self::SHARE_TYPE_REMOTE))) |
|
| 723 | - ->execute(); |
|
| 724 | - |
|
| 725 | - $shares = []; |
|
| 726 | - while($data = $cursor->fetch()) { |
|
| 727 | - $shares[] = $this->createShareObject($data); |
|
| 728 | - } |
|
| 729 | - $cursor->closeCursor(); |
|
| 730 | - |
|
| 731 | - return $shares; |
|
| 732 | - } |
|
| 733 | - |
|
| 734 | - /** |
|
| 735 | - * @inheritdoc |
|
| 736 | - */ |
|
| 737 | - public function getSharedWith($userId, $shareType, $node, $limit, $offset) { |
|
| 738 | - /** @var IShare[] $shares */ |
|
| 739 | - $shares = []; |
|
| 740 | - |
|
| 741 | - //Get shares directly with this user |
|
| 742 | - $qb = $this->dbConnection->getQueryBuilder(); |
|
| 743 | - $qb->select('*') |
|
| 744 | - ->from('share'); |
|
| 745 | - |
|
| 746 | - // Order by id |
|
| 747 | - $qb->orderBy('id'); |
|
| 748 | - |
|
| 749 | - // Set limit and offset |
|
| 750 | - if ($limit !== -1) { |
|
| 751 | - $qb->setMaxResults($limit); |
|
| 752 | - } |
|
| 753 | - $qb->setFirstResult($offset); |
|
| 754 | - |
|
| 755 | - $qb->where($qb->expr()->eq('share_type', $qb->createNamedParameter(self::SHARE_TYPE_REMOTE))); |
|
| 756 | - $qb->andWhere($qb->expr()->eq('share_with', $qb->createNamedParameter($userId))); |
|
| 757 | - |
|
| 758 | - // Filter by node if provided |
|
| 759 | - if ($node !== null) { |
|
| 760 | - $qb->andWhere($qb->expr()->eq('file_source', $qb->createNamedParameter($node->getId()))); |
|
| 761 | - } |
|
| 762 | - |
|
| 763 | - $cursor = $qb->execute(); |
|
| 764 | - |
|
| 765 | - while($data = $cursor->fetch()) { |
|
| 766 | - $shares[] = $this->createShareObject($data); |
|
| 767 | - } |
|
| 768 | - $cursor->closeCursor(); |
|
| 769 | - |
|
| 770 | - |
|
| 771 | - return $shares; |
|
| 772 | - } |
|
| 773 | - |
|
| 774 | - /** |
|
| 775 | - * Get a share by token |
|
| 776 | - * |
|
| 777 | - * @param string $token |
|
| 778 | - * @return IShare |
|
| 779 | - * @throws ShareNotFound |
|
| 780 | - */ |
|
| 781 | - public function getShareByToken($token) { |
|
| 782 | - $qb = $this->dbConnection->getQueryBuilder(); |
|
| 783 | - |
|
| 784 | - $cursor = $qb->select('*') |
|
| 785 | - ->from('share') |
|
| 786 | - ->where($qb->expr()->eq('share_type', $qb->createNamedParameter(self::SHARE_TYPE_REMOTE))) |
|
| 787 | - ->andWhere($qb->expr()->eq('token', $qb->createNamedParameter($token))) |
|
| 788 | - ->execute(); |
|
| 789 | - |
|
| 790 | - $data = $cursor->fetch(); |
|
| 791 | - |
|
| 792 | - if ($data === false) { |
|
| 793 | - throw new ShareNotFound('Share not found', $this->l->t('Could not find share')); |
|
| 794 | - } |
|
| 795 | - |
|
| 796 | - try { |
|
| 797 | - $share = $this->createShareObject($data); |
|
| 798 | - } catch (InvalidShare $e) { |
|
| 799 | - throw new ShareNotFound('Share not found', $this->l->t('Could not find share')); |
|
| 800 | - } |
|
| 801 | - |
|
| 802 | - return $share; |
|
| 803 | - } |
|
| 804 | - |
|
| 805 | - /** |
|
| 806 | - * get database row of a give share |
|
| 807 | - * |
|
| 808 | - * @param $id |
|
| 809 | - * @return array |
|
| 810 | - * @throws ShareNotFound |
|
| 811 | - */ |
|
| 812 | - private function getRawShare($id) { |
|
| 813 | - |
|
| 814 | - // Now fetch the inserted share and create a complete share object |
|
| 815 | - $qb = $this->dbConnection->getQueryBuilder(); |
|
| 816 | - $qb->select('*') |
|
| 817 | - ->from('share') |
|
| 818 | - ->where($qb->expr()->eq('id', $qb->createNamedParameter($id))); |
|
| 819 | - |
|
| 820 | - $cursor = $qb->execute(); |
|
| 821 | - $data = $cursor->fetch(); |
|
| 822 | - $cursor->closeCursor(); |
|
| 823 | - |
|
| 824 | - if ($data === false) { |
|
| 825 | - throw new ShareNotFound; |
|
| 826 | - } |
|
| 827 | - |
|
| 828 | - return $data; |
|
| 829 | - } |
|
| 830 | - |
|
| 831 | - /** |
|
| 832 | - * Create a share object from an database row |
|
| 833 | - * |
|
| 834 | - * @param array $data |
|
| 835 | - * @return IShare |
|
| 836 | - * @throws InvalidShare |
|
| 837 | - * @throws ShareNotFound |
|
| 838 | - */ |
|
| 839 | - private function createShareObject($data) { |
|
| 840 | - |
|
| 841 | - $share = new Share($this->rootFolder, $this->userManager); |
|
| 842 | - $share->setId((int)$data['id']) |
|
| 843 | - ->setShareType((int)$data['share_type']) |
|
| 844 | - ->setPermissions((int)$data['permissions']) |
|
| 845 | - ->setTarget($data['file_target']) |
|
| 846 | - ->setMailSend((bool)$data['mail_send']) |
|
| 847 | - ->setToken($data['token']); |
|
| 848 | - |
|
| 849 | - $shareTime = new \DateTime(); |
|
| 850 | - $shareTime->setTimestamp((int)$data['stime']); |
|
| 851 | - $share->setShareTime($shareTime); |
|
| 852 | - $share->setSharedWith($data['share_with']); |
|
| 853 | - |
|
| 854 | - if ($data['uid_initiator'] !== null) { |
|
| 855 | - $share->setShareOwner($data['uid_owner']); |
|
| 856 | - $share->setSharedBy($data['uid_initiator']); |
|
| 857 | - } else { |
|
| 858 | - //OLD SHARE |
|
| 859 | - $share->setSharedBy($data['uid_owner']); |
|
| 860 | - $path = $this->getNode($share->getSharedBy(), (int)$data['file_source']); |
|
| 861 | - |
|
| 862 | - $owner = $path->getOwner(); |
|
| 863 | - $share->setShareOwner($owner->getUID()); |
|
| 864 | - } |
|
| 865 | - |
|
| 866 | - $share->setNodeId((int)$data['file_source']); |
|
| 867 | - $share->setNodeType($data['item_type']); |
|
| 868 | - |
|
| 869 | - $share->setProviderId($this->identifier()); |
|
| 870 | - |
|
| 871 | - return $share; |
|
| 872 | - } |
|
| 873 | - |
|
| 874 | - /** |
|
| 875 | - * Get the node with file $id for $user |
|
| 876 | - * |
|
| 877 | - * @param string $userId |
|
| 878 | - * @param int $id |
|
| 879 | - * @return \OCP\Files\File|\OCP\Files\Folder |
|
| 880 | - * @throws InvalidShare |
|
| 881 | - */ |
|
| 882 | - private function getNode($userId, $id) { |
|
| 883 | - try { |
|
| 884 | - $userFolder = $this->rootFolder->getUserFolder($userId); |
|
| 885 | - } catch (NotFoundException $e) { |
|
| 886 | - throw new InvalidShare(); |
|
| 887 | - } |
|
| 888 | - |
|
| 889 | - $nodes = $userFolder->getById($id); |
|
| 890 | - |
|
| 891 | - if (empty($nodes)) { |
|
| 892 | - throw new InvalidShare(); |
|
| 893 | - } |
|
| 894 | - |
|
| 895 | - return $nodes[0]; |
|
| 896 | - } |
|
| 897 | - |
|
| 898 | - /** |
|
| 899 | - * A user is deleted from the system |
|
| 900 | - * So clean up the relevant shares. |
|
| 901 | - * |
|
| 902 | - * @param string $uid |
|
| 903 | - * @param int $shareType |
|
| 904 | - */ |
|
| 905 | - public function userDeleted($uid, $shareType) { |
|
| 906 | - //TODO: probabaly a good idea to send unshare info to remote servers |
|
| 907 | - |
|
| 908 | - $qb = $this->dbConnection->getQueryBuilder(); |
|
| 909 | - |
|
| 910 | - $qb->delete('share') |
|
| 911 | - ->where($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_REMOTE))) |
|
| 912 | - ->andWhere($qb->expr()->eq('uid_owner', $qb->createNamedParameter($uid))) |
|
| 913 | - ->execute(); |
|
| 914 | - } |
|
| 915 | - |
|
| 916 | - /** |
|
| 917 | - * This provider does not handle groups |
|
| 918 | - * |
|
| 919 | - * @param string $gid |
|
| 920 | - */ |
|
| 921 | - public function groupDeleted($gid) { |
|
| 922 | - // We don't handle groups here |
|
| 923 | - return; |
|
| 924 | - } |
|
| 925 | - |
|
| 926 | - /** |
|
| 927 | - * This provider does not handle groups |
|
| 928 | - * |
|
| 929 | - * @param string $uid |
|
| 930 | - * @param string $gid |
|
| 931 | - */ |
|
| 932 | - public function userDeletedFromGroup($uid, $gid) { |
|
| 933 | - // We don't handle groups here |
|
| 934 | - return; |
|
| 935 | - } |
|
| 936 | - |
|
| 937 | - /** |
|
| 938 | - * check if users from other Nextcloud instances are allowed to mount public links share by this instance |
|
| 939 | - * |
|
| 940 | - * @return bool |
|
| 941 | - */ |
|
| 942 | - public function isOutgoingServer2serverShareEnabled() { |
|
| 943 | - $result = $this->config->getAppValue('files_sharing', 'outgoing_server2server_share_enabled', 'yes'); |
|
| 944 | - return ($result === 'yes'); |
|
| 945 | - } |
|
| 946 | - |
|
| 947 | - /** |
|
| 948 | - * check if users are allowed to mount public links from other ownClouds |
|
| 949 | - * |
|
| 950 | - * @return bool |
|
| 951 | - */ |
|
| 952 | - public function isIncomingServer2serverShareEnabled() { |
|
| 953 | - $result = $this->config->getAppValue('files_sharing', 'incoming_server2server_share_enabled', 'yes'); |
|
| 954 | - return ($result === 'yes'); |
|
| 955 | - } |
|
| 956 | - |
|
| 957 | - /** |
|
| 958 | - * Check if querying sharees on the lookup server is enabled |
|
| 959 | - * |
|
| 960 | - * @return bool |
|
| 961 | - */ |
|
| 962 | - public function isLookupServerQueriesEnabled() { |
|
| 963 | - $result = $this->config->getAppValue('files_sharing', 'lookupServerEnabled', 'no'); |
|
| 964 | - return ($result === 'yes'); |
|
| 965 | - } |
|
| 966 | - |
|
| 967 | - |
|
| 968 | - /** |
|
| 969 | - * Check if it is allowed to publish user specific data to the lookup server |
|
| 970 | - * |
|
| 971 | - * @return bool |
|
| 972 | - */ |
|
| 973 | - public function isLookupServerUploadEnabled() { |
|
| 974 | - $result = $this->config->getAppValue('files_sharing', 'lookupServerUploadEnabled', 'yes'); |
|
| 975 | - return ($result === 'yes'); |
|
| 976 | - } |
|
| 462 | + return $share; |
|
| 463 | + } |
|
| 464 | + |
|
| 465 | + /** |
|
| 466 | + * Get all children of this share |
|
| 467 | + * |
|
| 468 | + * @param IShare $parent |
|
| 469 | + * @return IShare[] |
|
| 470 | + */ |
|
| 471 | + public function getChildren(IShare $parent) { |
|
| 472 | + $children = []; |
|
| 473 | + |
|
| 474 | + $qb = $this->dbConnection->getQueryBuilder(); |
|
| 475 | + $qb->select('*') |
|
| 476 | + ->from('share') |
|
| 477 | + ->where($qb->expr()->eq('parent', $qb->createNamedParameter($parent->getId()))) |
|
| 478 | + ->andWhere($qb->expr()->eq('share_type', $qb->createNamedParameter(self::SHARE_TYPE_REMOTE))) |
|
| 479 | + ->orderBy('id'); |
|
| 480 | + |
|
| 481 | + $cursor = $qb->execute(); |
|
| 482 | + while($data = $cursor->fetch()) { |
|
| 483 | + $children[] = $this->createShareObject($data); |
|
| 484 | + } |
|
| 485 | + $cursor->closeCursor(); |
|
| 486 | + |
|
| 487 | + return $children; |
|
| 488 | + } |
|
| 489 | + |
|
| 490 | + /** |
|
| 491 | + * Delete a share (owner unShares the file) |
|
| 492 | + * |
|
| 493 | + * @param IShare $share |
|
| 494 | + */ |
|
| 495 | + public function delete(IShare $share) { |
|
| 496 | + |
|
| 497 | + list(, $remote) = $this->addressHandler->splitUserRemote($share->getSharedWith()); |
|
| 498 | + |
|
| 499 | + $isOwner = false; |
|
| 500 | + |
|
| 501 | + $this->removeShareFromTable($share); |
|
| 502 | + |
|
| 503 | + // if the local user is the owner we can send the unShare request directly... |
|
| 504 | + if ($this->userManager->userExists($share->getShareOwner())) { |
|
| 505 | + $this->notifications->sendRemoteUnShare($remote, $share->getId(), $share->getToken()); |
|
| 506 | + $this->revokeShare($share, true); |
|
| 507 | + $isOwner = true; |
|
| 508 | + } else { // ... if not we need to correct ID for the unShare request |
|
| 509 | + $remoteId = $this->getRemoteId($share); |
|
| 510 | + $this->notifications->sendRemoteUnShare($remote, $remoteId, $share->getToken()); |
|
| 511 | + $this->revokeShare($share, false); |
|
| 512 | + } |
|
| 513 | + |
|
| 514 | + // send revoke notification to the other user, if initiator and owner are not the same user |
|
| 515 | + if ($share->getShareOwner() !== $share->getSharedBy()) { |
|
| 516 | + $remoteId = $this->getRemoteId($share); |
|
| 517 | + if ($isOwner) { |
|
| 518 | + list(, $remote) = $this->addressHandler->splitUserRemote($share->getSharedBy()); |
|
| 519 | + } else { |
|
| 520 | + list(, $remote) = $this->addressHandler->splitUserRemote($share->getShareOwner()); |
|
| 521 | + } |
|
| 522 | + $this->notifications->sendRevokeShare($remote, $remoteId, $share->getToken()); |
|
| 523 | + } |
|
| 524 | + } |
|
| 525 | + |
|
| 526 | + /** |
|
| 527 | + * in case of a re-share we need to send the other use (initiator or owner) |
|
| 528 | + * a message that the file was unshared |
|
| 529 | + * |
|
| 530 | + * @param IShare $share |
|
| 531 | + * @param bool $isOwner the user can either be the owner or the user who re-sahred it |
|
| 532 | + * @throws ShareNotFound |
|
| 533 | + * @throws \OC\HintException |
|
| 534 | + */ |
|
| 535 | + protected function revokeShare($share, $isOwner) { |
|
| 536 | + // also send a unShare request to the initiator, if this is a different user than the owner |
|
| 537 | + if ($share->getShareOwner() !== $share->getSharedBy()) { |
|
| 538 | + if ($isOwner) { |
|
| 539 | + list(, $remote) = $this->addressHandler->splitUserRemote($share->getSharedBy()); |
|
| 540 | + } else { |
|
| 541 | + list(, $remote) = $this->addressHandler->splitUserRemote($share->getShareOwner()); |
|
| 542 | + } |
|
| 543 | + $remoteId = $this->getRemoteId($share); |
|
| 544 | + $this->notifications->sendRevokeShare($remote, $remoteId, $share->getToken()); |
|
| 545 | + } |
|
| 546 | + } |
|
| 547 | + |
|
| 548 | + /** |
|
| 549 | + * remove share from table |
|
| 550 | + * |
|
| 551 | + * @param IShare $share |
|
| 552 | + */ |
|
| 553 | + public function removeShareFromTable(IShare $share) { |
|
| 554 | + $this->removeShareFromTableById($share->getId()); |
|
| 555 | + } |
|
| 556 | + |
|
| 557 | + /** |
|
| 558 | + * remove share from table |
|
| 559 | + * |
|
| 560 | + * @param string $shareId |
|
| 561 | + */ |
|
| 562 | + private function removeShareFromTableById($shareId) { |
|
| 563 | + $qb = $this->dbConnection->getQueryBuilder(); |
|
| 564 | + $qb->delete('share') |
|
| 565 | + ->where($qb->expr()->eq('id', $qb->createNamedParameter($shareId))); |
|
| 566 | + $qb->execute(); |
|
| 567 | + |
|
| 568 | + $qb->delete('federated_reshares') |
|
| 569 | + ->where($qb->expr()->eq('share_id', $qb->createNamedParameter($shareId))); |
|
| 570 | + $qb->execute(); |
|
| 571 | + } |
|
| 572 | + |
|
| 573 | + /** |
|
| 574 | + * @inheritdoc |
|
| 575 | + */ |
|
| 576 | + public function deleteFromSelf(IShare $share, $recipient) { |
|
| 577 | + // nothing to do here. Technically deleteFromSelf in the context of federated |
|
| 578 | + // shares is a umount of a external storage. This is handled here |
|
| 579 | + // apps/files_sharing/lib/external/manager.php |
|
| 580 | + // TODO move this code over to this app |
|
| 581 | + return; |
|
| 582 | + } |
|
| 583 | + |
|
| 584 | + |
|
| 585 | + public function getSharesInFolder($userId, Folder $node, $reshares) { |
|
| 586 | + $qb = $this->dbConnection->getQueryBuilder(); |
|
| 587 | + $qb->select('*') |
|
| 588 | + ->from('share', 's') |
|
| 589 | + ->andWhere($qb->expr()->orX( |
|
| 590 | + $qb->expr()->eq('item_type', $qb->createNamedParameter('file')), |
|
| 591 | + $qb->expr()->eq('item_type', $qb->createNamedParameter('folder')) |
|
| 592 | + )) |
|
| 593 | + ->andWhere( |
|
| 594 | + $qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_REMOTE)) |
|
| 595 | + ); |
|
| 596 | + |
|
| 597 | + /** |
|
| 598 | + * Reshares for this user are shares where they are the owner. |
|
| 599 | + */ |
|
| 600 | + if ($reshares === false) { |
|
| 601 | + $qb->andWhere($qb->expr()->eq('uid_initiator', $qb->createNamedParameter($userId))); |
|
| 602 | + } else { |
|
| 603 | + $qb->andWhere( |
|
| 604 | + $qb->expr()->orX( |
|
| 605 | + $qb->expr()->eq('uid_owner', $qb->createNamedParameter($userId)), |
|
| 606 | + $qb->expr()->eq('uid_initiator', $qb->createNamedParameter($userId)) |
|
| 607 | + ) |
|
| 608 | + ); |
|
| 609 | + } |
|
| 610 | + |
|
| 611 | + $qb->innerJoin('s', 'filecache' ,'f', 's.file_source = f.fileid'); |
|
| 612 | + $qb->andWhere($qb->expr()->eq('f.parent', $qb->createNamedParameter($node->getId()))); |
|
| 613 | + |
|
| 614 | + $qb->orderBy('id'); |
|
| 615 | + |
|
| 616 | + $cursor = $qb->execute(); |
|
| 617 | + $shares = []; |
|
| 618 | + while ($data = $cursor->fetch()) { |
|
| 619 | + $shares[$data['fileid']][] = $this->createShareObject($data); |
|
| 620 | + } |
|
| 621 | + $cursor->closeCursor(); |
|
| 622 | + |
|
| 623 | + return $shares; |
|
| 624 | + } |
|
| 625 | + |
|
| 626 | + /** |
|
| 627 | + * @inheritdoc |
|
| 628 | + */ |
|
| 629 | + public function getSharesBy($userId, $shareType, $node, $reshares, $limit, $offset) { |
|
| 630 | + $qb = $this->dbConnection->getQueryBuilder(); |
|
| 631 | + $qb->select('*') |
|
| 632 | + ->from('share'); |
|
| 633 | + |
|
| 634 | + $qb->andWhere($qb->expr()->eq('share_type', $qb->createNamedParameter(self::SHARE_TYPE_REMOTE))); |
|
| 635 | + |
|
| 636 | + /** |
|
| 637 | + * Reshares for this user are shares where they are the owner. |
|
| 638 | + */ |
|
| 639 | + if ($reshares === false) { |
|
| 640 | + //Special case for old shares created via the web UI |
|
| 641 | + $or1 = $qb->expr()->andX( |
|
| 642 | + $qb->expr()->eq('uid_owner', $qb->createNamedParameter($userId)), |
|
| 643 | + $qb->expr()->isNull('uid_initiator') |
|
| 644 | + ); |
|
| 645 | + |
|
| 646 | + $qb->andWhere( |
|
| 647 | + $qb->expr()->orX( |
|
| 648 | + $qb->expr()->eq('uid_initiator', $qb->createNamedParameter($userId)), |
|
| 649 | + $or1 |
|
| 650 | + ) |
|
| 651 | + ); |
|
| 652 | + } else { |
|
| 653 | + $qb->andWhere( |
|
| 654 | + $qb->expr()->orX( |
|
| 655 | + $qb->expr()->eq('uid_owner', $qb->createNamedParameter($userId)), |
|
| 656 | + $qb->expr()->eq('uid_initiator', $qb->createNamedParameter($userId)) |
|
| 657 | + ) |
|
| 658 | + ); |
|
| 659 | + } |
|
| 660 | + |
|
| 661 | + if ($node !== null) { |
|
| 662 | + $qb->andWhere($qb->expr()->eq('file_source', $qb->createNamedParameter($node->getId()))); |
|
| 663 | + } |
|
| 664 | + |
|
| 665 | + if ($limit !== -1) { |
|
| 666 | + $qb->setMaxResults($limit); |
|
| 667 | + } |
|
| 668 | + |
|
| 669 | + $qb->setFirstResult($offset); |
|
| 670 | + $qb->orderBy('id'); |
|
| 671 | + |
|
| 672 | + $cursor = $qb->execute(); |
|
| 673 | + $shares = []; |
|
| 674 | + while($data = $cursor->fetch()) { |
|
| 675 | + $shares[] = $this->createShareObject($data); |
|
| 676 | + } |
|
| 677 | + $cursor->closeCursor(); |
|
| 678 | + |
|
| 679 | + return $shares; |
|
| 680 | + } |
|
| 681 | + |
|
| 682 | + /** |
|
| 683 | + * @inheritdoc |
|
| 684 | + */ |
|
| 685 | + public function getShareById($id, $recipientId = null) { |
|
| 686 | + $qb = $this->dbConnection->getQueryBuilder(); |
|
| 687 | + |
|
| 688 | + $qb->select('*') |
|
| 689 | + ->from('share') |
|
| 690 | + ->where($qb->expr()->eq('id', $qb->createNamedParameter($id))) |
|
| 691 | + ->andWhere($qb->expr()->eq('share_type', $qb->createNamedParameter(self::SHARE_TYPE_REMOTE))); |
|
| 692 | + |
|
| 693 | + $cursor = $qb->execute(); |
|
| 694 | + $data = $cursor->fetch(); |
|
| 695 | + $cursor->closeCursor(); |
|
| 696 | + |
|
| 697 | + if ($data === false) { |
|
| 698 | + throw new ShareNotFound(); |
|
| 699 | + } |
|
| 700 | + |
|
| 701 | + try { |
|
| 702 | + $share = $this->createShareObject($data); |
|
| 703 | + } catch (InvalidShare $e) { |
|
| 704 | + throw new ShareNotFound(); |
|
| 705 | + } |
|
| 706 | + |
|
| 707 | + return $share; |
|
| 708 | + } |
|
| 709 | + |
|
| 710 | + /** |
|
| 711 | + * Get shares for a given path |
|
| 712 | + * |
|
| 713 | + * @param \OCP\Files\Node $path |
|
| 714 | + * @return IShare[] |
|
| 715 | + */ |
|
| 716 | + public function getSharesByPath(Node $path) { |
|
| 717 | + $qb = $this->dbConnection->getQueryBuilder(); |
|
| 718 | + |
|
| 719 | + $cursor = $qb->select('*') |
|
| 720 | + ->from('share') |
|
| 721 | + ->andWhere($qb->expr()->eq('file_source', $qb->createNamedParameter($path->getId()))) |
|
| 722 | + ->andWhere($qb->expr()->eq('share_type', $qb->createNamedParameter(self::SHARE_TYPE_REMOTE))) |
|
| 723 | + ->execute(); |
|
| 724 | + |
|
| 725 | + $shares = []; |
|
| 726 | + while($data = $cursor->fetch()) { |
|
| 727 | + $shares[] = $this->createShareObject($data); |
|
| 728 | + } |
|
| 729 | + $cursor->closeCursor(); |
|
| 730 | + |
|
| 731 | + return $shares; |
|
| 732 | + } |
|
| 733 | + |
|
| 734 | + /** |
|
| 735 | + * @inheritdoc |
|
| 736 | + */ |
|
| 737 | + public function getSharedWith($userId, $shareType, $node, $limit, $offset) { |
|
| 738 | + /** @var IShare[] $shares */ |
|
| 739 | + $shares = []; |
|
| 740 | + |
|
| 741 | + //Get shares directly with this user |
|
| 742 | + $qb = $this->dbConnection->getQueryBuilder(); |
|
| 743 | + $qb->select('*') |
|
| 744 | + ->from('share'); |
|
| 745 | + |
|
| 746 | + // Order by id |
|
| 747 | + $qb->orderBy('id'); |
|
| 748 | + |
|
| 749 | + // Set limit and offset |
|
| 750 | + if ($limit !== -1) { |
|
| 751 | + $qb->setMaxResults($limit); |
|
| 752 | + } |
|
| 753 | + $qb->setFirstResult($offset); |
|
| 754 | + |
|
| 755 | + $qb->where($qb->expr()->eq('share_type', $qb->createNamedParameter(self::SHARE_TYPE_REMOTE))); |
|
| 756 | + $qb->andWhere($qb->expr()->eq('share_with', $qb->createNamedParameter($userId))); |
|
| 757 | + |
|
| 758 | + // Filter by node if provided |
|
| 759 | + if ($node !== null) { |
|
| 760 | + $qb->andWhere($qb->expr()->eq('file_source', $qb->createNamedParameter($node->getId()))); |
|
| 761 | + } |
|
| 762 | + |
|
| 763 | + $cursor = $qb->execute(); |
|
| 764 | + |
|
| 765 | + while($data = $cursor->fetch()) { |
|
| 766 | + $shares[] = $this->createShareObject($data); |
|
| 767 | + } |
|
| 768 | + $cursor->closeCursor(); |
|
| 769 | + |
|
| 770 | + |
|
| 771 | + return $shares; |
|
| 772 | + } |
|
| 773 | + |
|
| 774 | + /** |
|
| 775 | + * Get a share by token |
|
| 776 | + * |
|
| 777 | + * @param string $token |
|
| 778 | + * @return IShare |
|
| 779 | + * @throws ShareNotFound |
|
| 780 | + */ |
|
| 781 | + public function getShareByToken($token) { |
|
| 782 | + $qb = $this->dbConnection->getQueryBuilder(); |
|
| 783 | + |
|
| 784 | + $cursor = $qb->select('*') |
|
| 785 | + ->from('share') |
|
| 786 | + ->where($qb->expr()->eq('share_type', $qb->createNamedParameter(self::SHARE_TYPE_REMOTE))) |
|
| 787 | + ->andWhere($qb->expr()->eq('token', $qb->createNamedParameter($token))) |
|
| 788 | + ->execute(); |
|
| 789 | + |
|
| 790 | + $data = $cursor->fetch(); |
|
| 791 | + |
|
| 792 | + if ($data === false) { |
|
| 793 | + throw new ShareNotFound('Share not found', $this->l->t('Could not find share')); |
|
| 794 | + } |
|
| 795 | + |
|
| 796 | + try { |
|
| 797 | + $share = $this->createShareObject($data); |
|
| 798 | + } catch (InvalidShare $e) { |
|
| 799 | + throw new ShareNotFound('Share not found', $this->l->t('Could not find share')); |
|
| 800 | + } |
|
| 801 | + |
|
| 802 | + return $share; |
|
| 803 | + } |
|
| 804 | + |
|
| 805 | + /** |
|
| 806 | + * get database row of a give share |
|
| 807 | + * |
|
| 808 | + * @param $id |
|
| 809 | + * @return array |
|
| 810 | + * @throws ShareNotFound |
|
| 811 | + */ |
|
| 812 | + private function getRawShare($id) { |
|
| 813 | + |
|
| 814 | + // Now fetch the inserted share and create a complete share object |
|
| 815 | + $qb = $this->dbConnection->getQueryBuilder(); |
|
| 816 | + $qb->select('*') |
|
| 817 | + ->from('share') |
|
| 818 | + ->where($qb->expr()->eq('id', $qb->createNamedParameter($id))); |
|
| 819 | + |
|
| 820 | + $cursor = $qb->execute(); |
|
| 821 | + $data = $cursor->fetch(); |
|
| 822 | + $cursor->closeCursor(); |
|
| 823 | + |
|
| 824 | + if ($data === false) { |
|
| 825 | + throw new ShareNotFound; |
|
| 826 | + } |
|
| 827 | + |
|
| 828 | + return $data; |
|
| 829 | + } |
|
| 830 | + |
|
| 831 | + /** |
|
| 832 | + * Create a share object from an database row |
|
| 833 | + * |
|
| 834 | + * @param array $data |
|
| 835 | + * @return IShare |
|
| 836 | + * @throws InvalidShare |
|
| 837 | + * @throws ShareNotFound |
|
| 838 | + */ |
|
| 839 | + private function createShareObject($data) { |
|
| 840 | + |
|
| 841 | + $share = new Share($this->rootFolder, $this->userManager); |
|
| 842 | + $share->setId((int)$data['id']) |
|
| 843 | + ->setShareType((int)$data['share_type']) |
|
| 844 | + ->setPermissions((int)$data['permissions']) |
|
| 845 | + ->setTarget($data['file_target']) |
|
| 846 | + ->setMailSend((bool)$data['mail_send']) |
|
| 847 | + ->setToken($data['token']); |
|
| 848 | + |
|
| 849 | + $shareTime = new \DateTime(); |
|
| 850 | + $shareTime->setTimestamp((int)$data['stime']); |
|
| 851 | + $share->setShareTime($shareTime); |
|
| 852 | + $share->setSharedWith($data['share_with']); |
|
| 853 | + |
|
| 854 | + if ($data['uid_initiator'] !== null) { |
|
| 855 | + $share->setShareOwner($data['uid_owner']); |
|
| 856 | + $share->setSharedBy($data['uid_initiator']); |
|
| 857 | + } else { |
|
| 858 | + //OLD SHARE |
|
| 859 | + $share->setSharedBy($data['uid_owner']); |
|
| 860 | + $path = $this->getNode($share->getSharedBy(), (int)$data['file_source']); |
|
| 861 | + |
|
| 862 | + $owner = $path->getOwner(); |
|
| 863 | + $share->setShareOwner($owner->getUID()); |
|
| 864 | + } |
|
| 865 | + |
|
| 866 | + $share->setNodeId((int)$data['file_source']); |
|
| 867 | + $share->setNodeType($data['item_type']); |
|
| 868 | + |
|
| 869 | + $share->setProviderId($this->identifier()); |
|
| 870 | + |
|
| 871 | + return $share; |
|
| 872 | + } |
|
| 873 | + |
|
| 874 | + /** |
|
| 875 | + * Get the node with file $id for $user |
|
| 876 | + * |
|
| 877 | + * @param string $userId |
|
| 878 | + * @param int $id |
|
| 879 | + * @return \OCP\Files\File|\OCP\Files\Folder |
|
| 880 | + * @throws InvalidShare |
|
| 881 | + */ |
|
| 882 | + private function getNode($userId, $id) { |
|
| 883 | + try { |
|
| 884 | + $userFolder = $this->rootFolder->getUserFolder($userId); |
|
| 885 | + } catch (NotFoundException $e) { |
|
| 886 | + throw new InvalidShare(); |
|
| 887 | + } |
|
| 888 | + |
|
| 889 | + $nodes = $userFolder->getById($id); |
|
| 890 | + |
|
| 891 | + if (empty($nodes)) { |
|
| 892 | + throw new InvalidShare(); |
|
| 893 | + } |
|
| 894 | + |
|
| 895 | + return $nodes[0]; |
|
| 896 | + } |
|
| 897 | + |
|
| 898 | + /** |
|
| 899 | + * A user is deleted from the system |
|
| 900 | + * So clean up the relevant shares. |
|
| 901 | + * |
|
| 902 | + * @param string $uid |
|
| 903 | + * @param int $shareType |
|
| 904 | + */ |
|
| 905 | + public function userDeleted($uid, $shareType) { |
|
| 906 | + //TODO: probabaly a good idea to send unshare info to remote servers |
|
| 907 | + |
|
| 908 | + $qb = $this->dbConnection->getQueryBuilder(); |
|
| 909 | + |
|
| 910 | + $qb->delete('share') |
|
| 911 | + ->where($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_REMOTE))) |
|
| 912 | + ->andWhere($qb->expr()->eq('uid_owner', $qb->createNamedParameter($uid))) |
|
| 913 | + ->execute(); |
|
| 914 | + } |
|
| 915 | + |
|
| 916 | + /** |
|
| 917 | + * This provider does not handle groups |
|
| 918 | + * |
|
| 919 | + * @param string $gid |
|
| 920 | + */ |
|
| 921 | + public function groupDeleted($gid) { |
|
| 922 | + // We don't handle groups here |
|
| 923 | + return; |
|
| 924 | + } |
|
| 925 | + |
|
| 926 | + /** |
|
| 927 | + * This provider does not handle groups |
|
| 928 | + * |
|
| 929 | + * @param string $uid |
|
| 930 | + * @param string $gid |
|
| 931 | + */ |
|
| 932 | + public function userDeletedFromGroup($uid, $gid) { |
|
| 933 | + // We don't handle groups here |
|
| 934 | + return; |
|
| 935 | + } |
|
| 936 | + |
|
| 937 | + /** |
|
| 938 | + * check if users from other Nextcloud instances are allowed to mount public links share by this instance |
|
| 939 | + * |
|
| 940 | + * @return bool |
|
| 941 | + */ |
|
| 942 | + public function isOutgoingServer2serverShareEnabled() { |
|
| 943 | + $result = $this->config->getAppValue('files_sharing', 'outgoing_server2server_share_enabled', 'yes'); |
|
| 944 | + return ($result === 'yes'); |
|
| 945 | + } |
|
| 946 | + |
|
| 947 | + /** |
|
| 948 | + * check if users are allowed to mount public links from other ownClouds |
|
| 949 | + * |
|
| 950 | + * @return bool |
|
| 951 | + */ |
|
| 952 | + public function isIncomingServer2serverShareEnabled() { |
|
| 953 | + $result = $this->config->getAppValue('files_sharing', 'incoming_server2server_share_enabled', 'yes'); |
|
| 954 | + return ($result === 'yes'); |
|
| 955 | + } |
|
| 956 | + |
|
| 957 | + /** |
|
| 958 | + * Check if querying sharees on the lookup server is enabled |
|
| 959 | + * |
|
| 960 | + * @return bool |
|
| 961 | + */ |
|
| 962 | + public function isLookupServerQueriesEnabled() { |
|
| 963 | + $result = $this->config->getAppValue('files_sharing', 'lookupServerEnabled', 'no'); |
|
| 964 | + return ($result === 'yes'); |
|
| 965 | + } |
|
| 966 | + |
|
| 967 | + |
|
| 968 | + /** |
|
| 969 | + * Check if it is allowed to publish user specific data to the lookup server |
|
| 970 | + * |
|
| 971 | + * @return bool |
|
| 972 | + */ |
|
| 973 | + public function isLookupServerUploadEnabled() { |
|
| 974 | + $result = $this->config->getAppValue('files_sharing', 'lookupServerUploadEnabled', 'yes'); |
|
| 975 | + return ($result === 'yes'); |
|
| 976 | + } |
|
| 977 | 977 | } |
@@ -61,1388 +61,1388 @@ |
||
| 61 | 61 | use OCP\IUser; |
| 62 | 62 | |
| 63 | 63 | class OC_Util { |
| 64 | - public static $scripts = array(); |
|
| 65 | - public static $styles = array(); |
|
| 66 | - public static $headers = array(); |
|
| 67 | - private static $rootMounted = false; |
|
| 68 | - private static $fsSetup = false; |
|
| 69 | - |
|
| 70 | - /** @var array Local cache of version.php */ |
|
| 71 | - private static $versionCache = null; |
|
| 72 | - |
|
| 73 | - protected static function getAppManager() { |
|
| 74 | - return \OC::$server->getAppManager(); |
|
| 75 | - } |
|
| 76 | - |
|
| 77 | - private static function initLocalStorageRootFS() { |
|
| 78 | - // mount local file backend as root |
|
| 79 | - $configDataDirectory = \OC::$server->getSystemConfig()->getValue("datadirectory", OC::$SERVERROOT . "/data"); |
|
| 80 | - //first set up the local "root" storage |
|
| 81 | - \OC\Files\Filesystem::initMountManager(); |
|
| 82 | - if (!self::$rootMounted) { |
|
| 83 | - \OC\Files\Filesystem::mount('\OC\Files\Storage\Local', array('datadir' => $configDataDirectory), '/'); |
|
| 84 | - self::$rootMounted = true; |
|
| 85 | - } |
|
| 86 | - } |
|
| 87 | - |
|
| 88 | - /** |
|
| 89 | - * mounting an object storage as the root fs will in essence remove the |
|
| 90 | - * necessity of a data folder being present. |
|
| 91 | - * TODO make home storage aware of this and use the object storage instead of local disk access |
|
| 92 | - * |
|
| 93 | - * @param array $config containing 'class' and optional 'arguments' |
|
| 94 | - */ |
|
| 95 | - private static function initObjectStoreRootFS($config) { |
|
| 96 | - // check misconfiguration |
|
| 97 | - if (empty($config['class'])) { |
|
| 98 | - \OCP\Util::writeLog('files', 'No class given for objectstore', \OCP\Util::ERROR); |
|
| 99 | - } |
|
| 100 | - if (!isset($config['arguments'])) { |
|
| 101 | - $config['arguments'] = array(); |
|
| 102 | - } |
|
| 103 | - |
|
| 104 | - // instantiate object store implementation |
|
| 105 | - $name = $config['class']; |
|
| 106 | - if (strpos($name, 'OCA\\') === 0 && substr_count($name, '\\') >= 2) { |
|
| 107 | - $segments = explode('\\', $name); |
|
| 108 | - OC_App::loadApp(strtolower($segments[1])); |
|
| 109 | - } |
|
| 110 | - $config['arguments']['objectstore'] = new $config['class']($config['arguments']); |
|
| 111 | - // mount with plain / root object store implementation |
|
| 112 | - $config['class'] = '\OC\Files\ObjectStore\ObjectStoreStorage'; |
|
| 113 | - |
|
| 114 | - // mount object storage as root |
|
| 115 | - \OC\Files\Filesystem::initMountManager(); |
|
| 116 | - if (!self::$rootMounted) { |
|
| 117 | - \OC\Files\Filesystem::mount($config['class'], $config['arguments'], '/'); |
|
| 118 | - self::$rootMounted = true; |
|
| 119 | - } |
|
| 120 | - } |
|
| 121 | - |
|
| 122 | - /** |
|
| 123 | - * Can be set up |
|
| 124 | - * |
|
| 125 | - * @param string $user |
|
| 126 | - * @return boolean |
|
| 127 | - * @description configure the initial filesystem based on the configuration |
|
| 128 | - */ |
|
| 129 | - public static function setupFS($user = '') { |
|
| 130 | - //setting up the filesystem twice can only lead to trouble |
|
| 131 | - if (self::$fsSetup) { |
|
| 132 | - return false; |
|
| 133 | - } |
|
| 134 | - |
|
| 135 | - \OC::$server->getEventLogger()->start('setup_fs', 'Setup filesystem'); |
|
| 136 | - |
|
| 137 | - // If we are not forced to load a specific user we load the one that is logged in |
|
| 138 | - if ($user === null) { |
|
| 139 | - $user = ''; |
|
| 140 | - } else if ($user == "" && \OC::$server->getUserSession()->isLoggedIn()) { |
|
| 141 | - $user = OC_User::getUser(); |
|
| 142 | - } |
|
| 143 | - |
|
| 144 | - // load all filesystem apps before, so no setup-hook gets lost |
|
| 145 | - OC_App::loadApps(array('filesystem')); |
|
| 146 | - |
|
| 147 | - // the filesystem will finish when $user is not empty, |
|
| 148 | - // mark fs setup here to avoid doing the setup from loading |
|
| 149 | - // OC_Filesystem |
|
| 150 | - if ($user != '') { |
|
| 151 | - self::$fsSetup = true; |
|
| 152 | - } |
|
| 153 | - |
|
| 154 | - \OC\Files\Filesystem::initMountManager(); |
|
| 155 | - |
|
| 156 | - \OC\Files\Filesystem::logWarningWhenAddingStorageWrapper(false); |
|
| 157 | - \OC\Files\Filesystem::addStorageWrapper('mount_options', function ($mountPoint, \OCP\Files\Storage $storage, \OCP\Files\Mount\IMountPoint $mount) { |
|
| 158 | - if ($storage->instanceOfStorage('\OC\Files\Storage\Common')) { |
|
| 159 | - /** @var \OC\Files\Storage\Common $storage */ |
|
| 160 | - $storage->setMountOptions($mount->getOptions()); |
|
| 161 | - } |
|
| 162 | - return $storage; |
|
| 163 | - }); |
|
| 164 | - |
|
| 165 | - \OC\Files\Filesystem::addStorageWrapper('enable_sharing', function ($mountPoint, \OCP\Files\Storage $storage, \OCP\Files\Mount\IMountPoint $mount) { |
|
| 166 | - if (!$mount->getOption('enable_sharing', true)) { |
|
| 167 | - return new \OC\Files\Storage\Wrapper\PermissionsMask([ |
|
| 168 | - 'storage' => $storage, |
|
| 169 | - 'mask' => \OCP\Constants::PERMISSION_ALL - \OCP\Constants::PERMISSION_SHARE |
|
| 170 | - ]); |
|
| 171 | - } |
|
| 172 | - return $storage; |
|
| 173 | - }); |
|
| 174 | - |
|
| 175 | - // install storage availability wrapper, before most other wrappers |
|
| 176 | - \OC\Files\Filesystem::addStorageWrapper('oc_availability', function ($mountPoint, $storage) { |
|
| 177 | - if (!$storage->instanceOfStorage('\OCA\Files_Sharing\SharedStorage') && !$storage->isLocal()) { |
|
| 178 | - return new \OC\Files\Storage\Wrapper\Availability(['storage' => $storage]); |
|
| 179 | - } |
|
| 180 | - return $storage; |
|
| 181 | - }); |
|
| 182 | - |
|
| 183 | - \OC\Files\Filesystem::addStorageWrapper('oc_encoding', function ($mountPoint, \OCP\Files\Storage $storage, \OCP\Files\Mount\IMountPoint $mount) { |
|
| 184 | - if ($mount->getOption('encoding_compatibility', false) && !$storage->instanceOfStorage('\OCA\Files_Sharing\SharedStorage') && !$storage->isLocal()) { |
|
| 185 | - return new \OC\Files\Storage\Wrapper\Encoding(['storage' => $storage]); |
|
| 186 | - } |
|
| 187 | - return $storage; |
|
| 188 | - }); |
|
| 189 | - |
|
| 190 | - \OC\Files\Filesystem::addStorageWrapper('oc_quota', function ($mountPoint, $storage) { |
|
| 191 | - // set up quota for home storages, even for other users |
|
| 192 | - // which can happen when using sharing |
|
| 193 | - |
|
| 194 | - /** |
|
| 195 | - * @var \OC\Files\Storage\Storage $storage |
|
| 196 | - */ |
|
| 197 | - if ($storage->instanceOfStorage('\OC\Files\Storage\Home') |
|
| 198 | - || $storage->instanceOfStorage('\OC\Files\ObjectStore\HomeObjectStoreStorage') |
|
| 199 | - ) { |
|
| 200 | - /** @var \OC\Files\Storage\Home $storage */ |
|
| 201 | - if (is_object($storage->getUser())) { |
|
| 202 | - $user = $storage->getUser()->getUID(); |
|
| 203 | - $quota = OC_Util::getUserQuota($user); |
|
| 204 | - if ($quota !== \OCP\Files\FileInfo::SPACE_UNLIMITED) { |
|
| 205 | - return new \OC\Files\Storage\Wrapper\Quota(array('storage' => $storage, 'quota' => $quota, 'root' => 'files')); |
|
| 206 | - } |
|
| 207 | - } |
|
| 208 | - } |
|
| 209 | - |
|
| 210 | - return $storage; |
|
| 211 | - }); |
|
| 212 | - |
|
| 213 | - OC_Hook::emit('OC_Filesystem', 'preSetup', array('user' => $user)); |
|
| 214 | - \OC\Files\Filesystem::logWarningWhenAddingStorageWrapper(true); |
|
| 215 | - |
|
| 216 | - //check if we are using an object storage |
|
| 217 | - $objectStore = \OC::$server->getSystemConfig()->getValue('objectstore', null); |
|
| 218 | - if (isset($objectStore)) { |
|
| 219 | - self::initObjectStoreRootFS($objectStore); |
|
| 220 | - } else { |
|
| 221 | - self::initLocalStorageRootFS(); |
|
| 222 | - } |
|
| 223 | - |
|
| 224 | - if ($user != '' && !OCP\User::userExists($user)) { |
|
| 225 | - \OC::$server->getEventLogger()->end('setup_fs'); |
|
| 226 | - return false; |
|
| 227 | - } |
|
| 228 | - |
|
| 229 | - //if we aren't logged in, there is no use to set up the filesystem |
|
| 230 | - if ($user != "") { |
|
| 231 | - |
|
| 232 | - $userDir = '/' . $user . '/files'; |
|
| 233 | - |
|
| 234 | - //jail the user into his "home" directory |
|
| 235 | - \OC\Files\Filesystem::init($user, $userDir); |
|
| 236 | - |
|
| 237 | - OC_Hook::emit('OC_Filesystem', 'setup', array('user' => $user, 'user_dir' => $userDir)); |
|
| 238 | - } |
|
| 239 | - \OC::$server->getEventLogger()->end('setup_fs'); |
|
| 240 | - return true; |
|
| 241 | - } |
|
| 242 | - |
|
| 243 | - /** |
|
| 244 | - * check if a password is required for each public link |
|
| 245 | - * |
|
| 246 | - * @return boolean |
|
| 247 | - */ |
|
| 248 | - public static function isPublicLinkPasswordRequired() { |
|
| 249 | - $appConfig = \OC::$server->getAppConfig(); |
|
| 250 | - $enforcePassword = $appConfig->getValue('core', 'shareapi_enforce_links_password', 'no'); |
|
| 251 | - return ($enforcePassword === 'yes') ? true : false; |
|
| 252 | - } |
|
| 253 | - |
|
| 254 | - /** |
|
| 255 | - * check if sharing is disabled for the current user |
|
| 256 | - * @param IConfig $config |
|
| 257 | - * @param IGroupManager $groupManager |
|
| 258 | - * @param IUser|null $user |
|
| 259 | - * @return bool |
|
| 260 | - */ |
|
| 261 | - public static function isSharingDisabledForUser(IConfig $config, IGroupManager $groupManager, $user) { |
|
| 262 | - if ($config->getAppValue('core', 'shareapi_exclude_groups', 'no') === 'yes') { |
|
| 263 | - $groupsList = $config->getAppValue('core', 'shareapi_exclude_groups_list', ''); |
|
| 264 | - $excludedGroups = json_decode($groupsList); |
|
| 265 | - if (is_null($excludedGroups)) { |
|
| 266 | - $excludedGroups = explode(',', $groupsList); |
|
| 267 | - $newValue = json_encode($excludedGroups); |
|
| 268 | - $config->setAppValue('core', 'shareapi_exclude_groups_list', $newValue); |
|
| 269 | - } |
|
| 270 | - $usersGroups = $groupManager->getUserGroupIds($user); |
|
| 271 | - if (!empty($usersGroups)) { |
|
| 272 | - $remainingGroups = array_diff($usersGroups, $excludedGroups); |
|
| 273 | - // if the user is only in groups which are disabled for sharing then |
|
| 274 | - // sharing is also disabled for the user |
|
| 275 | - if (empty($remainingGroups)) { |
|
| 276 | - return true; |
|
| 277 | - } |
|
| 278 | - } |
|
| 279 | - } |
|
| 280 | - return false; |
|
| 281 | - } |
|
| 282 | - |
|
| 283 | - /** |
|
| 284 | - * check if share API enforces a default expire date |
|
| 285 | - * |
|
| 286 | - * @return boolean |
|
| 287 | - */ |
|
| 288 | - public static function isDefaultExpireDateEnforced() { |
|
| 289 | - $isDefaultExpireDateEnabled = \OCP\Config::getAppValue('core', 'shareapi_default_expire_date', 'no'); |
|
| 290 | - $enforceDefaultExpireDate = false; |
|
| 291 | - if ($isDefaultExpireDateEnabled === 'yes') { |
|
| 292 | - $value = \OCP\Config::getAppValue('core', 'shareapi_enforce_expire_date', 'no'); |
|
| 293 | - $enforceDefaultExpireDate = ($value === 'yes') ? true : false; |
|
| 294 | - } |
|
| 295 | - |
|
| 296 | - return $enforceDefaultExpireDate; |
|
| 297 | - } |
|
| 298 | - |
|
| 299 | - /** |
|
| 300 | - * Get the quota of a user |
|
| 301 | - * |
|
| 302 | - * @param string $userId |
|
| 303 | - * @return int Quota bytes |
|
| 304 | - */ |
|
| 305 | - public static function getUserQuota($userId) { |
|
| 306 | - $user = \OC::$server->getUserManager()->get($userId); |
|
| 307 | - if (is_null($user)) { |
|
| 308 | - return \OCP\Files\FileInfo::SPACE_UNLIMITED; |
|
| 309 | - } |
|
| 310 | - $userQuota = $user->getQuota(); |
|
| 311 | - if($userQuota === 'none') { |
|
| 312 | - return \OCP\Files\FileInfo::SPACE_UNLIMITED; |
|
| 313 | - } |
|
| 314 | - return OC_Helper::computerFileSize($userQuota); |
|
| 315 | - } |
|
| 316 | - |
|
| 317 | - /** |
|
| 318 | - * copies the skeleton to the users /files |
|
| 319 | - * |
|
| 320 | - * @param String $userId |
|
| 321 | - * @param \OCP\Files\Folder $userDirectory |
|
| 322 | - * @throws \RuntimeException |
|
| 323 | - */ |
|
| 324 | - public static function copySkeleton($userId, \OCP\Files\Folder $userDirectory) { |
|
| 325 | - |
|
| 326 | - $skeletonDirectory = \OC::$server->getConfig()->getSystemValue('skeletondirectory', \OC::$SERVERROOT . '/core/skeleton'); |
|
| 327 | - $instanceId = \OC::$server->getConfig()->getSystemValue('instanceid', ''); |
|
| 328 | - |
|
| 329 | - if ($instanceId === null) { |
|
| 330 | - throw new \RuntimeException('no instance id!'); |
|
| 331 | - } |
|
| 332 | - $appdata = 'appdata_' . $instanceId; |
|
| 333 | - if ($userId === $appdata) { |
|
| 334 | - throw new \RuntimeException('username is reserved name: ' . $appdata); |
|
| 335 | - } |
|
| 336 | - |
|
| 337 | - if (!empty($skeletonDirectory)) { |
|
| 338 | - \OCP\Util::writeLog( |
|
| 339 | - 'files_skeleton', |
|
| 340 | - 'copying skeleton for '.$userId.' from '.$skeletonDirectory.' to '.$userDirectory->getFullPath('/'), |
|
| 341 | - \OCP\Util::DEBUG |
|
| 342 | - ); |
|
| 343 | - self::copyr($skeletonDirectory, $userDirectory); |
|
| 344 | - // update the file cache |
|
| 345 | - $userDirectory->getStorage()->getScanner()->scan('', \OC\Files\Cache\Scanner::SCAN_RECURSIVE); |
|
| 346 | - } |
|
| 347 | - } |
|
| 348 | - |
|
| 349 | - /** |
|
| 350 | - * copies a directory recursively by using streams |
|
| 351 | - * |
|
| 352 | - * @param string $source |
|
| 353 | - * @param \OCP\Files\Folder $target |
|
| 354 | - * @return void |
|
| 355 | - */ |
|
| 356 | - public static function copyr($source, \OCP\Files\Folder $target) { |
|
| 357 | - $logger = \OC::$server->getLogger(); |
|
| 358 | - |
|
| 359 | - // Verify if folder exists |
|
| 360 | - $dir = opendir($source); |
|
| 361 | - if($dir === false) { |
|
| 362 | - $logger->error(sprintf('Could not opendir "%s"', $source), ['app' => 'core']); |
|
| 363 | - return; |
|
| 364 | - } |
|
| 365 | - |
|
| 366 | - // Copy the files |
|
| 367 | - while (false !== ($file = readdir($dir))) { |
|
| 368 | - if (!\OC\Files\Filesystem::isIgnoredDir($file)) { |
|
| 369 | - if (is_dir($source . '/' . $file)) { |
|
| 370 | - $child = $target->newFolder($file); |
|
| 371 | - self::copyr($source . '/' . $file, $child); |
|
| 372 | - } else { |
|
| 373 | - $child = $target->newFile($file); |
|
| 374 | - $sourceStream = fopen($source . '/' . $file, 'r'); |
|
| 375 | - if($sourceStream === false) { |
|
| 376 | - $logger->error(sprintf('Could not fopen "%s"', $source . '/' . $file), ['app' => 'core']); |
|
| 377 | - closedir($dir); |
|
| 378 | - return; |
|
| 379 | - } |
|
| 380 | - stream_copy_to_stream($sourceStream, $child->fopen('w')); |
|
| 381 | - } |
|
| 382 | - } |
|
| 383 | - } |
|
| 384 | - closedir($dir); |
|
| 385 | - } |
|
| 386 | - |
|
| 387 | - /** |
|
| 388 | - * @return void |
|
| 389 | - */ |
|
| 390 | - public static function tearDownFS() { |
|
| 391 | - \OC\Files\Filesystem::tearDown(); |
|
| 392 | - \OC::$server->getRootFolder()->clearCache(); |
|
| 393 | - self::$fsSetup = false; |
|
| 394 | - self::$rootMounted = false; |
|
| 395 | - } |
|
| 396 | - |
|
| 397 | - /** |
|
| 398 | - * get the current installed version of ownCloud |
|
| 399 | - * |
|
| 400 | - * @return array |
|
| 401 | - */ |
|
| 402 | - public static function getVersion() { |
|
| 403 | - OC_Util::loadVersion(); |
|
| 404 | - return self::$versionCache['OC_Version']; |
|
| 405 | - } |
|
| 406 | - |
|
| 407 | - /** |
|
| 408 | - * get the current installed version string of ownCloud |
|
| 409 | - * |
|
| 410 | - * @return string |
|
| 411 | - */ |
|
| 412 | - public static function getVersionString() { |
|
| 413 | - OC_Util::loadVersion(); |
|
| 414 | - return self::$versionCache['OC_VersionString']; |
|
| 415 | - } |
|
| 416 | - |
|
| 417 | - /** |
|
| 418 | - * @deprecated the value is of no use anymore |
|
| 419 | - * @return string |
|
| 420 | - */ |
|
| 421 | - public static function getEditionString() { |
|
| 422 | - return ''; |
|
| 423 | - } |
|
| 424 | - |
|
| 425 | - /** |
|
| 426 | - * @description get the update channel of the current installed of ownCloud. |
|
| 427 | - * @return string |
|
| 428 | - */ |
|
| 429 | - public static function getChannel() { |
|
| 430 | - OC_Util::loadVersion(); |
|
| 431 | - return \OC::$server->getConfig()->getSystemValue('updater.release.channel', self::$versionCache['OC_Channel']); |
|
| 432 | - } |
|
| 433 | - |
|
| 434 | - /** |
|
| 435 | - * @description get the build number of the current installed of ownCloud. |
|
| 436 | - * @return string |
|
| 437 | - */ |
|
| 438 | - public static function getBuild() { |
|
| 439 | - OC_Util::loadVersion(); |
|
| 440 | - return self::$versionCache['OC_Build']; |
|
| 441 | - } |
|
| 442 | - |
|
| 443 | - /** |
|
| 444 | - * @description load the version.php into the session as cache |
|
| 445 | - */ |
|
| 446 | - private static function loadVersion() { |
|
| 447 | - if (self::$versionCache !== null) { |
|
| 448 | - return; |
|
| 449 | - } |
|
| 450 | - |
|
| 451 | - $timestamp = filemtime(OC::$SERVERROOT . '/version.php'); |
|
| 452 | - require OC::$SERVERROOT . '/version.php'; |
|
| 453 | - /** @var $timestamp int */ |
|
| 454 | - self::$versionCache['OC_Version_Timestamp'] = $timestamp; |
|
| 455 | - /** @var $OC_Version string */ |
|
| 456 | - self::$versionCache['OC_Version'] = $OC_Version; |
|
| 457 | - /** @var $OC_VersionString string */ |
|
| 458 | - self::$versionCache['OC_VersionString'] = $OC_VersionString; |
|
| 459 | - /** @var $OC_Build string */ |
|
| 460 | - self::$versionCache['OC_Build'] = $OC_Build; |
|
| 461 | - |
|
| 462 | - /** @var $OC_Channel string */ |
|
| 463 | - self::$versionCache['OC_Channel'] = $OC_Channel; |
|
| 464 | - } |
|
| 465 | - |
|
| 466 | - /** |
|
| 467 | - * generates a path for JS/CSS files. If no application is provided it will create the path for core. |
|
| 468 | - * |
|
| 469 | - * @param string $application application to get the files from |
|
| 470 | - * @param string $directory directory within this application (css, js, vendor, etc) |
|
| 471 | - * @param string $file the file inside of the above folder |
|
| 472 | - * @return string the path |
|
| 473 | - */ |
|
| 474 | - private static function generatePath($application, $directory, $file) { |
|
| 475 | - if (is_null($file)) { |
|
| 476 | - $file = $application; |
|
| 477 | - $application = ""; |
|
| 478 | - } |
|
| 479 | - if (!empty($application)) { |
|
| 480 | - return "$application/$directory/$file"; |
|
| 481 | - } else { |
|
| 482 | - return "$directory/$file"; |
|
| 483 | - } |
|
| 484 | - } |
|
| 485 | - |
|
| 486 | - /** |
|
| 487 | - * add a javascript file |
|
| 488 | - * |
|
| 489 | - * @param string $application application id |
|
| 490 | - * @param string|null $file filename |
|
| 491 | - * @param bool $prepend prepend the Script to the beginning of the list |
|
| 492 | - * @return void |
|
| 493 | - */ |
|
| 494 | - public static function addScript($application, $file = null, $prepend = false) { |
|
| 495 | - $path = OC_Util::generatePath($application, 'js', $file); |
|
| 496 | - |
|
| 497 | - // core js files need separate handling |
|
| 498 | - if ($application !== 'core' && $file !== null) { |
|
| 499 | - self::addTranslations ( $application ); |
|
| 500 | - } |
|
| 501 | - self::addExternalResource($application, $prepend, $path, "script"); |
|
| 502 | - } |
|
| 503 | - |
|
| 504 | - /** |
|
| 505 | - * add a javascript file from the vendor sub folder |
|
| 506 | - * |
|
| 507 | - * @param string $application application id |
|
| 508 | - * @param string|null $file filename |
|
| 509 | - * @param bool $prepend prepend the Script to the beginning of the list |
|
| 510 | - * @return void |
|
| 511 | - */ |
|
| 512 | - public static function addVendorScript($application, $file = null, $prepend = false) { |
|
| 513 | - $path = OC_Util::generatePath($application, 'vendor', $file); |
|
| 514 | - self::addExternalResource($application, $prepend, $path, "script"); |
|
| 515 | - } |
|
| 516 | - |
|
| 517 | - /** |
|
| 518 | - * add a translation JS file |
|
| 519 | - * |
|
| 520 | - * @param string $application application id |
|
| 521 | - * @param string $languageCode language code, defaults to the current language |
|
| 522 | - * @param bool $prepend prepend the Script to the beginning of the list |
|
| 523 | - */ |
|
| 524 | - public static function addTranslations($application, $languageCode = null, $prepend = false) { |
|
| 525 | - if (is_null($languageCode)) { |
|
| 526 | - $languageCode = \OC::$server->getL10NFactory()->findLanguage($application); |
|
| 527 | - } |
|
| 528 | - if (!empty($application)) { |
|
| 529 | - $path = "$application/l10n/$languageCode"; |
|
| 530 | - } else { |
|
| 531 | - $path = "l10n/$languageCode"; |
|
| 532 | - } |
|
| 533 | - self::addExternalResource($application, $prepend, $path, "script"); |
|
| 534 | - } |
|
| 535 | - |
|
| 536 | - /** |
|
| 537 | - * add a css file |
|
| 538 | - * |
|
| 539 | - * @param string $application application id |
|
| 540 | - * @param string|null $file filename |
|
| 541 | - * @param bool $prepend prepend the Style to the beginning of the list |
|
| 542 | - * @return void |
|
| 543 | - */ |
|
| 544 | - public static function addStyle($application, $file = null, $prepend = false) { |
|
| 545 | - $path = OC_Util::generatePath($application, 'css', $file); |
|
| 546 | - self::addExternalResource($application, $prepend, $path, "style"); |
|
| 547 | - } |
|
| 548 | - |
|
| 549 | - /** |
|
| 550 | - * add a css file from the vendor sub folder |
|
| 551 | - * |
|
| 552 | - * @param string $application application id |
|
| 553 | - * @param string|null $file filename |
|
| 554 | - * @param bool $prepend prepend the Style to the beginning of the list |
|
| 555 | - * @return void |
|
| 556 | - */ |
|
| 557 | - public static function addVendorStyle($application, $file = null, $prepend = false) { |
|
| 558 | - $path = OC_Util::generatePath($application, 'vendor', $file); |
|
| 559 | - self::addExternalResource($application, $prepend, $path, "style"); |
|
| 560 | - } |
|
| 561 | - |
|
| 562 | - /** |
|
| 563 | - * add an external resource css/js file |
|
| 564 | - * |
|
| 565 | - * @param string $application application id |
|
| 566 | - * @param bool $prepend prepend the file to the beginning of the list |
|
| 567 | - * @param string $path |
|
| 568 | - * @param string $type (script or style) |
|
| 569 | - * @return void |
|
| 570 | - */ |
|
| 571 | - private static function addExternalResource($application, $prepend, $path, $type = "script") { |
|
| 572 | - |
|
| 573 | - if ($type === "style") { |
|
| 574 | - if (!in_array($path, self::$styles)) { |
|
| 575 | - if ($prepend === true) { |
|
| 576 | - array_unshift ( self::$styles, $path ); |
|
| 577 | - } else { |
|
| 578 | - self::$styles[] = $path; |
|
| 579 | - } |
|
| 580 | - } |
|
| 581 | - } elseif ($type === "script") { |
|
| 582 | - if (!in_array($path, self::$scripts)) { |
|
| 583 | - if ($prepend === true) { |
|
| 584 | - array_unshift ( self::$scripts, $path ); |
|
| 585 | - } else { |
|
| 586 | - self::$scripts [] = $path; |
|
| 587 | - } |
|
| 588 | - } |
|
| 589 | - } |
|
| 590 | - } |
|
| 591 | - |
|
| 592 | - /** |
|
| 593 | - * Add a custom element to the header |
|
| 594 | - * If $text is null then the element will be written as empty element. |
|
| 595 | - * So use "" to get a closing tag. |
|
| 596 | - * @param string $tag tag name of the element |
|
| 597 | - * @param array $attributes array of attributes for the element |
|
| 598 | - * @param string $text the text content for the element |
|
| 599 | - */ |
|
| 600 | - public static function addHeader($tag, $attributes, $text=null) { |
|
| 601 | - self::$headers[] = array( |
|
| 602 | - 'tag' => $tag, |
|
| 603 | - 'attributes' => $attributes, |
|
| 604 | - 'text' => $text |
|
| 605 | - ); |
|
| 606 | - } |
|
| 607 | - |
|
| 608 | - /** |
|
| 609 | - * formats a timestamp in the "right" way |
|
| 610 | - * |
|
| 611 | - * @param int $timestamp |
|
| 612 | - * @param bool $dateOnly option to omit time from the result |
|
| 613 | - * @param DateTimeZone|string $timeZone where the given timestamp shall be converted to |
|
| 614 | - * @return string timestamp |
|
| 615 | - * |
|
| 616 | - * @deprecated Use \OC::$server->query('DateTimeFormatter') instead |
|
| 617 | - */ |
|
| 618 | - public static function formatDate($timestamp, $dateOnly = false, $timeZone = null) { |
|
| 619 | - if ($timeZone !== null && !$timeZone instanceof \DateTimeZone) { |
|
| 620 | - $timeZone = new \DateTimeZone($timeZone); |
|
| 621 | - } |
|
| 622 | - |
|
| 623 | - /** @var \OC\DateTimeFormatter $formatter */ |
|
| 624 | - $formatter = \OC::$server->query('DateTimeFormatter'); |
|
| 625 | - if ($dateOnly) { |
|
| 626 | - return $formatter->formatDate($timestamp, 'long', $timeZone); |
|
| 627 | - } |
|
| 628 | - return $formatter->formatDateTime($timestamp, 'long', 'long', $timeZone); |
|
| 629 | - } |
|
| 630 | - |
|
| 631 | - /** |
|
| 632 | - * check if the current server configuration is suitable for ownCloud |
|
| 633 | - * |
|
| 634 | - * @param \OC\SystemConfig $config |
|
| 635 | - * @return array arrays with error messages and hints |
|
| 636 | - */ |
|
| 637 | - public static function checkServer(\OC\SystemConfig $config) { |
|
| 638 | - $l = \OC::$server->getL10N('lib'); |
|
| 639 | - $errors = array(); |
|
| 640 | - $CONFIG_DATADIRECTORY = $config->getValue('datadirectory', OC::$SERVERROOT . '/data'); |
|
| 641 | - |
|
| 642 | - if (!self::needUpgrade($config) && $config->getValue('installed', false)) { |
|
| 643 | - // this check needs to be done every time |
|
| 644 | - $errors = self::checkDataDirectoryValidity($CONFIG_DATADIRECTORY); |
|
| 645 | - } |
|
| 646 | - |
|
| 647 | - // Assume that if checkServer() succeeded before in this session, then all is fine. |
|
| 648 | - if (\OC::$server->getSession()->exists('checkServer_succeeded') && \OC::$server->getSession()->get('checkServer_succeeded')) { |
|
| 649 | - return $errors; |
|
| 650 | - } |
|
| 651 | - |
|
| 652 | - $webServerRestart = false; |
|
| 653 | - $setup = new \OC\Setup($config, \OC::$server->getIniWrapper(), \OC::$server->getL10N('lib'), |
|
| 654 | - \OC::$server->getThemingDefaults(), \OC::$server->getLogger(), \OC::$server->getSecureRandom()); |
|
| 655 | - |
|
| 656 | - $urlGenerator = \OC::$server->getURLGenerator(); |
|
| 657 | - |
|
| 658 | - $availableDatabases = $setup->getSupportedDatabases(); |
|
| 659 | - if (empty($availableDatabases)) { |
|
| 660 | - $errors[] = array( |
|
| 661 | - 'error' => $l->t('No database drivers (sqlite, mysql, or postgresql) installed.'), |
|
| 662 | - 'hint' => '' //TODO: sane hint |
|
| 663 | - ); |
|
| 664 | - $webServerRestart = true; |
|
| 665 | - } |
|
| 666 | - |
|
| 667 | - // Check if config folder is writable. |
|
| 668 | - if(!OC_Helper::isReadOnlyConfigEnabled()) { |
|
| 669 | - if (!is_writable(OC::$configDir) or !is_readable(OC::$configDir)) { |
|
| 670 | - $errors[] = array( |
|
| 671 | - 'error' => $l->t('Cannot write into "config" directory'), |
|
| 672 | - 'hint' => $l->t('This can usually be fixed by ' |
|
| 673 | - . '%sgiving the webserver write access to the config directory%s.', |
|
| 674 | - array('<a href="' . $urlGenerator->linkToDocs('admin-dir_permissions') . '" target="_blank" rel="noreferrer">', '</a>')) |
|
| 675 | - ); |
|
| 676 | - } |
|
| 677 | - } |
|
| 678 | - |
|
| 679 | - // Check if there is a writable install folder. |
|
| 680 | - if ($config->getValue('appstoreenabled', true)) { |
|
| 681 | - if (OC_App::getInstallPath() === null |
|
| 682 | - || !is_writable(OC_App::getInstallPath()) |
|
| 683 | - || !is_readable(OC_App::getInstallPath()) |
|
| 684 | - ) { |
|
| 685 | - $errors[] = array( |
|
| 686 | - 'error' => $l->t('Cannot write into "apps" directory'), |
|
| 687 | - 'hint' => $l->t('This can usually be fixed by ' |
|
| 688 | - . '%sgiving the webserver write access to the apps directory%s' |
|
| 689 | - . ' or disabling the appstore in the config file.', |
|
| 690 | - array('<a href="' . $urlGenerator->linkToDocs('admin-dir_permissions') . '" target="_blank" rel="noreferrer">', '</a>')) |
|
| 691 | - ); |
|
| 692 | - } |
|
| 693 | - } |
|
| 694 | - // Create root dir. |
|
| 695 | - if ($config->getValue('installed', false)) { |
|
| 696 | - if (!is_dir($CONFIG_DATADIRECTORY)) { |
|
| 697 | - $success = @mkdir($CONFIG_DATADIRECTORY); |
|
| 698 | - if ($success) { |
|
| 699 | - $errors = array_merge($errors, self::checkDataDirectoryPermissions($CONFIG_DATADIRECTORY)); |
|
| 700 | - } else { |
|
| 701 | - $errors[] = [ |
|
| 702 | - 'error' => $l->t('Cannot create "data" directory'), |
|
| 703 | - 'hint' => $l->t('This can usually be fixed by ' |
|
| 704 | - . '<a href="%s" target="_blank" rel="noreferrer">giving the webserver write access to the root directory</a>.', |
|
| 705 | - [$urlGenerator->linkToDocs('admin-dir_permissions')]) |
|
| 706 | - ]; |
|
| 707 | - } |
|
| 708 | - } else if (!is_writable($CONFIG_DATADIRECTORY) or !is_readable($CONFIG_DATADIRECTORY)) { |
|
| 709 | - //common hint for all file permissions error messages |
|
| 710 | - $permissionsHint = $l->t('Permissions can usually be fixed by ' |
|
| 711 | - . '%sgiving the webserver write access to the root directory%s.', |
|
| 712 | - ['<a href="' . $urlGenerator->linkToDocs('admin-dir_permissions') . '" target="_blank" rel="noreferrer">', '</a>']); |
|
| 713 | - $errors[] = [ |
|
| 714 | - 'error' => 'Your data directory is not writable', |
|
| 715 | - 'hint' => $permissionsHint |
|
| 716 | - ]; |
|
| 717 | - } else { |
|
| 718 | - $errors = array_merge($errors, self::checkDataDirectoryPermissions($CONFIG_DATADIRECTORY)); |
|
| 719 | - } |
|
| 720 | - } |
|
| 721 | - |
|
| 722 | - if (!OC_Util::isSetLocaleWorking()) { |
|
| 723 | - $errors[] = array( |
|
| 724 | - 'error' => $l->t('Setting locale to %s failed', |
|
| 725 | - array('en_US.UTF-8/fr_FR.UTF-8/es_ES.UTF-8/de_DE.UTF-8/ru_RU.UTF-8/' |
|
| 726 | - . 'pt_BR.UTF-8/it_IT.UTF-8/ja_JP.UTF-8/zh_CN.UTF-8')), |
|
| 727 | - 'hint' => $l->t('Please install one of these locales on your system and restart your webserver.') |
|
| 728 | - ); |
|
| 729 | - } |
|
| 730 | - |
|
| 731 | - // Contains the dependencies that should be checked against |
|
| 732 | - // classes = class_exists |
|
| 733 | - // functions = function_exists |
|
| 734 | - // defined = defined |
|
| 735 | - // ini = ini_get |
|
| 736 | - // If the dependency is not found the missing module name is shown to the EndUser |
|
| 737 | - // When adding new checks always verify that they pass on Travis as well |
|
| 738 | - // for ini settings, see https://github.com/owncloud/administration/blob/master/travis-ci/custom.ini |
|
| 739 | - $dependencies = array( |
|
| 740 | - 'classes' => array( |
|
| 741 | - 'ZipArchive' => 'zip', |
|
| 742 | - 'DOMDocument' => 'dom', |
|
| 743 | - 'XMLWriter' => 'XMLWriter', |
|
| 744 | - 'XMLReader' => 'XMLReader', |
|
| 745 | - ), |
|
| 746 | - 'functions' => [ |
|
| 747 | - 'xml_parser_create' => 'libxml', |
|
| 748 | - 'mb_strcut' => 'mb multibyte', |
|
| 749 | - 'ctype_digit' => 'ctype', |
|
| 750 | - 'json_encode' => 'JSON', |
|
| 751 | - 'gd_info' => 'GD', |
|
| 752 | - 'gzencode' => 'zlib', |
|
| 753 | - 'iconv' => 'iconv', |
|
| 754 | - 'simplexml_load_string' => 'SimpleXML', |
|
| 755 | - 'hash' => 'HASH Message Digest Framework', |
|
| 756 | - 'curl_init' => 'cURL', |
|
| 757 | - 'openssl_verify' => 'OpenSSL', |
|
| 758 | - ], |
|
| 759 | - 'defined' => array( |
|
| 760 | - 'PDO::ATTR_DRIVER_NAME' => 'PDO' |
|
| 761 | - ), |
|
| 762 | - 'ini' => [ |
|
| 763 | - 'default_charset' => 'UTF-8', |
|
| 764 | - ], |
|
| 765 | - ); |
|
| 766 | - $missingDependencies = array(); |
|
| 767 | - $invalidIniSettings = []; |
|
| 768 | - $moduleHint = $l->t('Please ask your server administrator to install the module.'); |
|
| 769 | - |
|
| 770 | - /** |
|
| 771 | - * FIXME: The dependency check does not work properly on HHVM on the moment |
|
| 772 | - * and prevents installation. Once HHVM is more compatible with our |
|
| 773 | - * approach to check for these values we should re-enable those |
|
| 774 | - * checks. |
|
| 775 | - */ |
|
| 776 | - $iniWrapper = \OC::$server->getIniWrapper(); |
|
| 777 | - if (!self::runningOnHhvm()) { |
|
| 778 | - foreach ($dependencies['classes'] as $class => $module) { |
|
| 779 | - if (!class_exists($class)) { |
|
| 780 | - $missingDependencies[] = $module; |
|
| 781 | - } |
|
| 782 | - } |
|
| 783 | - foreach ($dependencies['functions'] as $function => $module) { |
|
| 784 | - if (!function_exists($function)) { |
|
| 785 | - $missingDependencies[] = $module; |
|
| 786 | - } |
|
| 787 | - } |
|
| 788 | - foreach ($dependencies['defined'] as $defined => $module) { |
|
| 789 | - if (!defined($defined)) { |
|
| 790 | - $missingDependencies[] = $module; |
|
| 791 | - } |
|
| 792 | - } |
|
| 793 | - foreach ($dependencies['ini'] as $setting => $expected) { |
|
| 794 | - if (is_bool($expected)) { |
|
| 795 | - if ($iniWrapper->getBool($setting) !== $expected) { |
|
| 796 | - $invalidIniSettings[] = [$setting, $expected]; |
|
| 797 | - } |
|
| 798 | - } |
|
| 799 | - if (is_int($expected)) { |
|
| 800 | - if ($iniWrapper->getNumeric($setting) !== $expected) { |
|
| 801 | - $invalidIniSettings[] = [$setting, $expected]; |
|
| 802 | - } |
|
| 803 | - } |
|
| 804 | - if (is_string($expected)) { |
|
| 805 | - if (strtolower($iniWrapper->getString($setting)) !== strtolower($expected)) { |
|
| 806 | - $invalidIniSettings[] = [$setting, $expected]; |
|
| 807 | - } |
|
| 808 | - } |
|
| 809 | - } |
|
| 810 | - } |
|
| 811 | - |
|
| 812 | - foreach($missingDependencies as $missingDependency) { |
|
| 813 | - $errors[] = array( |
|
| 814 | - 'error' => $l->t('PHP module %s not installed.', array($missingDependency)), |
|
| 815 | - 'hint' => $moduleHint |
|
| 816 | - ); |
|
| 817 | - $webServerRestart = true; |
|
| 818 | - } |
|
| 819 | - foreach($invalidIniSettings as $setting) { |
|
| 820 | - if(is_bool($setting[1])) { |
|
| 821 | - $setting[1] = ($setting[1]) ? 'on' : 'off'; |
|
| 822 | - } |
|
| 823 | - $errors[] = [ |
|
| 824 | - 'error' => $l->t('PHP setting "%s" is not set to "%s".', [$setting[0], var_export($setting[1], true)]), |
|
| 825 | - 'hint' => $l->t('Adjusting this setting in php.ini will make Nextcloud run again') |
|
| 826 | - ]; |
|
| 827 | - $webServerRestart = true; |
|
| 828 | - } |
|
| 829 | - |
|
| 830 | - /** |
|
| 831 | - * The mbstring.func_overload check can only be performed if the mbstring |
|
| 832 | - * module is installed as it will return null if the checking setting is |
|
| 833 | - * not available and thus a check on the boolean value fails. |
|
| 834 | - * |
|
| 835 | - * TODO: Should probably be implemented in the above generic dependency |
|
| 836 | - * check somehow in the long-term. |
|
| 837 | - */ |
|
| 838 | - if($iniWrapper->getBool('mbstring.func_overload') !== null && |
|
| 839 | - $iniWrapper->getBool('mbstring.func_overload') === true) { |
|
| 840 | - $errors[] = array( |
|
| 841 | - 'error' => $l->t('mbstring.func_overload is set to "%s" instead of the expected value "0"', [$iniWrapper->getString('mbstring.func_overload')]), |
|
| 842 | - 'hint' => $l->t('To fix this issue set <code>mbstring.func_overload</code> to <code>0</code> in your php.ini') |
|
| 843 | - ); |
|
| 844 | - } |
|
| 845 | - |
|
| 846 | - if(function_exists('xml_parser_create') && |
|
| 847 | - LIBXML_LOADED_VERSION < 20700 ) { |
|
| 848 | - $version = LIBXML_LOADED_VERSION; |
|
| 849 | - $major = floor($version/10000); |
|
| 850 | - $version -= ($major * 10000); |
|
| 851 | - $minor = floor($version/100); |
|
| 852 | - $version -= ($minor * 100); |
|
| 853 | - $patch = $version; |
|
| 854 | - $errors[] = array( |
|
| 855 | - 'error' => $l->t('libxml2 2.7.0 is at least required. Currently %s is installed.', [$major . '.' . $minor . '.' . $patch]), |
|
| 856 | - 'hint' => $l->t('To fix this issue update your libxml2 version and restart your web server.') |
|
| 857 | - ); |
|
| 858 | - } |
|
| 859 | - |
|
| 860 | - if (!self::isAnnotationsWorking()) { |
|
| 861 | - $errors[] = array( |
|
| 862 | - 'error' => $l->t('PHP is apparently set up to strip inline doc blocks. This will make several core apps inaccessible.'), |
|
| 863 | - 'hint' => $l->t('This is probably caused by a cache/accelerator such as Zend OPcache or eAccelerator.') |
|
| 864 | - ); |
|
| 865 | - } |
|
| 866 | - |
|
| 867 | - if (!\OC::$CLI && $webServerRestart) { |
|
| 868 | - $errors[] = array( |
|
| 869 | - 'error' => $l->t('PHP modules have been installed, but they are still listed as missing?'), |
|
| 870 | - 'hint' => $l->t('Please ask your server administrator to restart the web server.') |
|
| 871 | - ); |
|
| 872 | - } |
|
| 873 | - |
|
| 874 | - $errors = array_merge($errors, self::checkDatabaseVersion()); |
|
| 875 | - |
|
| 876 | - // Cache the result of this function |
|
| 877 | - \OC::$server->getSession()->set('checkServer_succeeded', count($errors) == 0); |
|
| 878 | - |
|
| 879 | - return $errors; |
|
| 880 | - } |
|
| 881 | - |
|
| 882 | - /** |
|
| 883 | - * Check the database version |
|
| 884 | - * |
|
| 885 | - * @return array errors array |
|
| 886 | - */ |
|
| 887 | - public static function checkDatabaseVersion() { |
|
| 888 | - $l = \OC::$server->getL10N('lib'); |
|
| 889 | - $errors = array(); |
|
| 890 | - $dbType = \OC::$server->getSystemConfig()->getValue('dbtype', 'sqlite'); |
|
| 891 | - if ($dbType === 'pgsql') { |
|
| 892 | - // check PostgreSQL version |
|
| 893 | - try { |
|
| 894 | - $result = \OC_DB::executeAudited('SHOW SERVER_VERSION'); |
|
| 895 | - $data = $result->fetchRow(); |
|
| 896 | - if (isset($data['server_version'])) { |
|
| 897 | - $version = $data['server_version']; |
|
| 898 | - if (version_compare($version, '9.0.0', '<')) { |
|
| 899 | - $errors[] = array( |
|
| 900 | - 'error' => $l->t('PostgreSQL >= 9 required'), |
|
| 901 | - 'hint' => $l->t('Please upgrade your database version') |
|
| 902 | - ); |
|
| 903 | - } |
|
| 904 | - } |
|
| 905 | - } catch (\Doctrine\DBAL\DBALException $e) { |
|
| 906 | - $logger = \OC::$server->getLogger(); |
|
| 907 | - $logger->warning('Error occurred while checking PostgreSQL version, assuming >= 9'); |
|
| 908 | - $logger->logException($e); |
|
| 909 | - } |
|
| 910 | - } |
|
| 911 | - return $errors; |
|
| 912 | - } |
|
| 913 | - |
|
| 914 | - /** |
|
| 915 | - * Check for correct file permissions of data directory |
|
| 916 | - * |
|
| 917 | - * @param string $dataDirectory |
|
| 918 | - * @return array arrays with error messages and hints |
|
| 919 | - */ |
|
| 920 | - public static function checkDataDirectoryPermissions($dataDirectory) { |
|
| 921 | - $l = \OC::$server->getL10N('lib'); |
|
| 922 | - $errors = array(); |
|
| 923 | - $permissionsModHint = $l->t('Please change the permissions to 0770 so that the directory' |
|
| 924 | - . ' cannot be listed by other users.'); |
|
| 925 | - $perms = substr(decoct(@fileperms($dataDirectory)), -3); |
|
| 926 | - if (substr($perms, -1) !== '0') { |
|
| 927 | - chmod($dataDirectory, 0770); |
|
| 928 | - clearstatcache(); |
|
| 929 | - $perms = substr(decoct(@fileperms($dataDirectory)), -3); |
|
| 930 | - if ($perms[2] !== '0') { |
|
| 931 | - $errors[] = [ |
|
| 932 | - 'error' => $l->t('Your data directory is readable by other users'), |
|
| 933 | - 'hint' => $permissionsModHint |
|
| 934 | - ]; |
|
| 935 | - } |
|
| 936 | - } |
|
| 937 | - return $errors; |
|
| 938 | - } |
|
| 939 | - |
|
| 940 | - /** |
|
| 941 | - * Check that the data directory exists and is valid by |
|
| 942 | - * checking the existence of the ".ocdata" file. |
|
| 943 | - * |
|
| 944 | - * @param string $dataDirectory data directory path |
|
| 945 | - * @return array errors found |
|
| 946 | - */ |
|
| 947 | - public static function checkDataDirectoryValidity($dataDirectory) { |
|
| 948 | - $l = \OC::$server->getL10N('lib'); |
|
| 949 | - $errors = []; |
|
| 950 | - if ($dataDirectory[0] !== '/') { |
|
| 951 | - $errors[] = [ |
|
| 952 | - 'error' => $l->t('Your data directory must be an absolute path'), |
|
| 953 | - 'hint' => $l->t('Check the value of "datadirectory" in your configuration') |
|
| 954 | - ]; |
|
| 955 | - } |
|
| 956 | - if (!file_exists($dataDirectory . '/.ocdata')) { |
|
| 957 | - $errors[] = [ |
|
| 958 | - 'error' => $l->t('Your data directory is invalid'), |
|
| 959 | - 'hint' => $l->t('Please check that the data directory contains a file' . |
|
| 960 | - ' ".ocdata" in its root.') |
|
| 961 | - ]; |
|
| 962 | - } |
|
| 963 | - return $errors; |
|
| 964 | - } |
|
| 965 | - |
|
| 966 | - /** |
|
| 967 | - * Check if the user is logged in, redirects to home if not. With |
|
| 968 | - * redirect URL parameter to the request URI. |
|
| 969 | - * |
|
| 970 | - * @return void |
|
| 971 | - */ |
|
| 972 | - public static function checkLoggedIn() { |
|
| 973 | - // Check if we are a user |
|
| 974 | - if (!\OC::$server->getUserSession()->isLoggedIn()) { |
|
| 975 | - header('Location: ' . \OC::$server->getURLGenerator()->linkToRoute( |
|
| 976 | - 'core.login.showLoginForm', |
|
| 977 | - [ |
|
| 978 | - 'redirect_url' => \OC::$server->getRequest()->getRequestUri(), |
|
| 979 | - ] |
|
| 980 | - ) |
|
| 981 | - ); |
|
| 982 | - exit(); |
|
| 983 | - } |
|
| 984 | - // Redirect to 2FA challenge selection if 2FA challenge was not solved yet |
|
| 985 | - if (\OC::$server->getTwoFactorAuthManager()->needsSecondFactor(\OC::$server->getUserSession()->getUser())) { |
|
| 986 | - header('Location: ' . \OC::$server->getURLGenerator()->linkToRoute('core.TwoFactorChallenge.selectChallenge')); |
|
| 987 | - exit(); |
|
| 988 | - } |
|
| 989 | - } |
|
| 990 | - |
|
| 991 | - /** |
|
| 992 | - * Check if the user is a admin, redirects to home if not |
|
| 993 | - * |
|
| 994 | - * @return void |
|
| 995 | - */ |
|
| 996 | - public static function checkAdminUser() { |
|
| 997 | - OC_Util::checkLoggedIn(); |
|
| 998 | - if (!OC_User::isAdminUser(OC_User::getUser())) { |
|
| 999 | - header('Location: ' . \OCP\Util::linkToAbsolute('', 'index.php')); |
|
| 1000 | - exit(); |
|
| 1001 | - } |
|
| 1002 | - } |
|
| 1003 | - |
|
| 1004 | - /** |
|
| 1005 | - * Check if the user is a subadmin, redirects to home if not |
|
| 1006 | - * |
|
| 1007 | - * @return null|boolean $groups where the current user is subadmin |
|
| 1008 | - */ |
|
| 1009 | - public static function checkSubAdminUser() { |
|
| 1010 | - OC_Util::checkLoggedIn(); |
|
| 1011 | - $userObject = \OC::$server->getUserSession()->getUser(); |
|
| 1012 | - $isSubAdmin = false; |
|
| 1013 | - if($userObject !== null) { |
|
| 1014 | - $isSubAdmin = \OC::$server->getGroupManager()->getSubAdmin()->isSubAdmin($userObject); |
|
| 1015 | - } |
|
| 1016 | - |
|
| 1017 | - if (!$isSubAdmin) { |
|
| 1018 | - header('Location: ' . \OCP\Util::linkToAbsolute('', 'index.php')); |
|
| 1019 | - exit(); |
|
| 1020 | - } |
|
| 1021 | - return true; |
|
| 1022 | - } |
|
| 1023 | - |
|
| 1024 | - /** |
|
| 1025 | - * Returns the URL of the default page |
|
| 1026 | - * based on the system configuration and |
|
| 1027 | - * the apps visible for the current user |
|
| 1028 | - * |
|
| 1029 | - * @return string URL |
|
| 1030 | - */ |
|
| 1031 | - public static function getDefaultPageUrl() { |
|
| 1032 | - $urlGenerator = \OC::$server->getURLGenerator(); |
|
| 1033 | - // Deny the redirect if the URL contains a @ |
|
| 1034 | - // This prevents unvalidated redirects like ?redirect_url=:[email protected] |
|
| 1035 | - if (isset($_REQUEST['redirect_url']) && strpos($_REQUEST['redirect_url'], '@') === false) { |
|
| 1036 | - $location = $urlGenerator->getAbsoluteURL(urldecode($_REQUEST['redirect_url'])); |
|
| 1037 | - } else { |
|
| 1038 | - $defaultPage = \OC::$server->getAppConfig()->getValue('core', 'defaultpage'); |
|
| 1039 | - if ($defaultPage) { |
|
| 1040 | - $location = $urlGenerator->getAbsoluteURL($defaultPage); |
|
| 1041 | - } else { |
|
| 1042 | - $appId = 'files'; |
|
| 1043 | - $defaultApps = explode(',', \OCP\Config::getSystemValue('defaultapp', 'files')); |
|
| 1044 | - // find the first app that is enabled for the current user |
|
| 1045 | - foreach ($defaultApps as $defaultApp) { |
|
| 1046 | - $defaultApp = OC_App::cleanAppId(strip_tags($defaultApp)); |
|
| 1047 | - if (static::getAppManager()->isEnabledForUser($defaultApp)) { |
|
| 1048 | - $appId = $defaultApp; |
|
| 1049 | - break; |
|
| 1050 | - } |
|
| 1051 | - } |
|
| 1052 | - |
|
| 1053 | - if(\OC::$server->getConfig()->getSystemValue('htaccess.IgnoreFrontController', false) === true || getenv('front_controller_active') === 'true') { |
|
| 1054 | - $location = $urlGenerator->getAbsoluteURL('/apps/' . $appId . '/'); |
|
| 1055 | - } else { |
|
| 1056 | - $location = $urlGenerator->getAbsoluteURL('/index.php/apps/' . $appId . '/'); |
|
| 1057 | - } |
|
| 1058 | - } |
|
| 1059 | - } |
|
| 1060 | - return $location; |
|
| 1061 | - } |
|
| 1062 | - |
|
| 1063 | - /** |
|
| 1064 | - * Redirect to the user default page |
|
| 1065 | - * |
|
| 1066 | - * @return void |
|
| 1067 | - */ |
|
| 1068 | - public static function redirectToDefaultPage() { |
|
| 1069 | - $location = self::getDefaultPageUrl(); |
|
| 1070 | - header('Location: ' . $location); |
|
| 1071 | - exit(); |
|
| 1072 | - } |
|
| 1073 | - |
|
| 1074 | - /** |
|
| 1075 | - * get an id unique for this instance |
|
| 1076 | - * |
|
| 1077 | - * @return string |
|
| 1078 | - */ |
|
| 1079 | - public static function getInstanceId() { |
|
| 1080 | - $id = \OC::$server->getSystemConfig()->getValue('instanceid', null); |
|
| 1081 | - if (is_null($id)) { |
|
| 1082 | - // We need to guarantee at least one letter in instanceid so it can be used as the session_name |
|
| 1083 | - $id = 'oc' . \OC::$server->getSecureRandom()->generate(10, \OCP\Security\ISecureRandom::CHAR_LOWER.\OCP\Security\ISecureRandom::CHAR_DIGITS); |
|
| 1084 | - \OC::$server->getSystemConfig()->setValue('instanceid', $id); |
|
| 1085 | - } |
|
| 1086 | - return $id; |
|
| 1087 | - } |
|
| 1088 | - |
|
| 1089 | - /** |
|
| 1090 | - * Public function to sanitize HTML |
|
| 1091 | - * |
|
| 1092 | - * This function is used to sanitize HTML and should be applied on any |
|
| 1093 | - * string or array of strings before displaying it on a web page. |
|
| 1094 | - * |
|
| 1095 | - * @param string|array $value |
|
| 1096 | - * @return string|array an array of sanitized strings or a single sanitized string, depends on the input parameter. |
|
| 1097 | - */ |
|
| 1098 | - public static function sanitizeHTML($value) { |
|
| 1099 | - if (is_array($value)) { |
|
| 1100 | - $value = array_map(function($value) { |
|
| 1101 | - return self::sanitizeHTML($value); |
|
| 1102 | - }, $value); |
|
| 1103 | - } else { |
|
| 1104 | - // Specify encoding for PHP<5.4 |
|
| 1105 | - $value = htmlspecialchars((string)$value, ENT_QUOTES, 'UTF-8'); |
|
| 1106 | - } |
|
| 1107 | - return $value; |
|
| 1108 | - } |
|
| 1109 | - |
|
| 1110 | - /** |
|
| 1111 | - * Public function to encode url parameters |
|
| 1112 | - * |
|
| 1113 | - * This function is used to encode path to file before output. |
|
| 1114 | - * Encoding is done according to RFC 3986 with one exception: |
|
| 1115 | - * Character '/' is preserved as is. |
|
| 1116 | - * |
|
| 1117 | - * @param string $component part of URI to encode |
|
| 1118 | - * @return string |
|
| 1119 | - */ |
|
| 1120 | - public static function encodePath($component) { |
|
| 1121 | - $encoded = rawurlencode($component); |
|
| 1122 | - $encoded = str_replace('%2F', '/', $encoded); |
|
| 1123 | - return $encoded; |
|
| 1124 | - } |
|
| 1125 | - |
|
| 1126 | - |
|
| 1127 | - public function createHtaccessTestFile(\OCP\IConfig $config) { |
|
| 1128 | - // php dev server does not support htaccess |
|
| 1129 | - if (php_sapi_name() === 'cli-server') { |
|
| 1130 | - return false; |
|
| 1131 | - } |
|
| 1132 | - |
|
| 1133 | - // testdata |
|
| 1134 | - $fileName = '/htaccesstest.txt'; |
|
| 1135 | - $testContent = 'This is used for testing whether htaccess is properly enabled to disallow access from the outside. This file can be safely removed.'; |
|
| 1136 | - |
|
| 1137 | - // creating a test file |
|
| 1138 | - $testFile = $config->getSystemValue('datadirectory', OC::$SERVERROOT . '/data') . '/' . $fileName; |
|
| 1139 | - |
|
| 1140 | - if (file_exists($testFile)) {// already running this test, possible recursive call |
|
| 1141 | - return false; |
|
| 1142 | - } |
|
| 1143 | - |
|
| 1144 | - $fp = @fopen($testFile, 'w'); |
|
| 1145 | - if (!$fp) { |
|
| 1146 | - throw new OC\HintException('Can\'t create test file to check for working .htaccess file.', |
|
| 1147 | - 'Make sure it is possible for the webserver to write to ' . $testFile); |
|
| 1148 | - } |
|
| 1149 | - fwrite($fp, $testContent); |
|
| 1150 | - fclose($fp); |
|
| 1151 | - |
|
| 1152 | - return $testContent; |
|
| 1153 | - } |
|
| 1154 | - |
|
| 1155 | - /** |
|
| 1156 | - * Check if the .htaccess file is working |
|
| 1157 | - * @param \OCP\IConfig $config |
|
| 1158 | - * @return bool |
|
| 1159 | - * @throws Exception |
|
| 1160 | - * @throws \OC\HintException If the test file can't get written. |
|
| 1161 | - */ |
|
| 1162 | - public function isHtaccessWorking(\OCP\IConfig $config) { |
|
| 1163 | - |
|
| 1164 | - if (\OC::$CLI || !$config->getSystemValue('check_for_working_htaccess', true)) { |
|
| 1165 | - return true; |
|
| 1166 | - } |
|
| 1167 | - |
|
| 1168 | - $testContent = $this->createHtaccessTestFile($config); |
|
| 1169 | - if ($testContent === false) { |
|
| 1170 | - return false; |
|
| 1171 | - } |
|
| 1172 | - |
|
| 1173 | - $fileName = '/htaccesstest.txt'; |
|
| 1174 | - $testFile = $config->getSystemValue('datadirectory', OC::$SERVERROOT . '/data') . '/' . $fileName; |
|
| 1175 | - |
|
| 1176 | - // accessing the file via http |
|
| 1177 | - $url = \OC::$server->getURLGenerator()->getAbsoluteURL(OC::$WEBROOT . '/data' . $fileName); |
|
| 1178 | - try { |
|
| 1179 | - $content = \OC::$server->getHTTPClientService()->newClient()->get($url)->getBody(); |
|
| 1180 | - } catch (\Exception $e) { |
|
| 1181 | - $content = false; |
|
| 1182 | - } |
|
| 1183 | - |
|
| 1184 | - // cleanup |
|
| 1185 | - @unlink($testFile); |
|
| 1186 | - |
|
| 1187 | - /* |
|
| 64 | + public static $scripts = array(); |
|
| 65 | + public static $styles = array(); |
|
| 66 | + public static $headers = array(); |
|
| 67 | + private static $rootMounted = false; |
|
| 68 | + private static $fsSetup = false; |
|
| 69 | + |
|
| 70 | + /** @var array Local cache of version.php */ |
|
| 71 | + private static $versionCache = null; |
|
| 72 | + |
|
| 73 | + protected static function getAppManager() { |
|
| 74 | + return \OC::$server->getAppManager(); |
|
| 75 | + } |
|
| 76 | + |
|
| 77 | + private static function initLocalStorageRootFS() { |
|
| 78 | + // mount local file backend as root |
|
| 79 | + $configDataDirectory = \OC::$server->getSystemConfig()->getValue("datadirectory", OC::$SERVERROOT . "/data"); |
|
| 80 | + //first set up the local "root" storage |
|
| 81 | + \OC\Files\Filesystem::initMountManager(); |
|
| 82 | + if (!self::$rootMounted) { |
|
| 83 | + \OC\Files\Filesystem::mount('\OC\Files\Storage\Local', array('datadir' => $configDataDirectory), '/'); |
|
| 84 | + self::$rootMounted = true; |
|
| 85 | + } |
|
| 86 | + } |
|
| 87 | + |
|
| 88 | + /** |
|
| 89 | + * mounting an object storage as the root fs will in essence remove the |
|
| 90 | + * necessity of a data folder being present. |
|
| 91 | + * TODO make home storage aware of this and use the object storage instead of local disk access |
|
| 92 | + * |
|
| 93 | + * @param array $config containing 'class' and optional 'arguments' |
|
| 94 | + */ |
|
| 95 | + private static function initObjectStoreRootFS($config) { |
|
| 96 | + // check misconfiguration |
|
| 97 | + if (empty($config['class'])) { |
|
| 98 | + \OCP\Util::writeLog('files', 'No class given for objectstore', \OCP\Util::ERROR); |
|
| 99 | + } |
|
| 100 | + if (!isset($config['arguments'])) { |
|
| 101 | + $config['arguments'] = array(); |
|
| 102 | + } |
|
| 103 | + |
|
| 104 | + // instantiate object store implementation |
|
| 105 | + $name = $config['class']; |
|
| 106 | + if (strpos($name, 'OCA\\') === 0 && substr_count($name, '\\') >= 2) { |
|
| 107 | + $segments = explode('\\', $name); |
|
| 108 | + OC_App::loadApp(strtolower($segments[1])); |
|
| 109 | + } |
|
| 110 | + $config['arguments']['objectstore'] = new $config['class']($config['arguments']); |
|
| 111 | + // mount with plain / root object store implementation |
|
| 112 | + $config['class'] = '\OC\Files\ObjectStore\ObjectStoreStorage'; |
|
| 113 | + |
|
| 114 | + // mount object storage as root |
|
| 115 | + \OC\Files\Filesystem::initMountManager(); |
|
| 116 | + if (!self::$rootMounted) { |
|
| 117 | + \OC\Files\Filesystem::mount($config['class'], $config['arguments'], '/'); |
|
| 118 | + self::$rootMounted = true; |
|
| 119 | + } |
|
| 120 | + } |
|
| 121 | + |
|
| 122 | + /** |
|
| 123 | + * Can be set up |
|
| 124 | + * |
|
| 125 | + * @param string $user |
|
| 126 | + * @return boolean |
|
| 127 | + * @description configure the initial filesystem based on the configuration |
|
| 128 | + */ |
|
| 129 | + public static function setupFS($user = '') { |
|
| 130 | + //setting up the filesystem twice can only lead to trouble |
|
| 131 | + if (self::$fsSetup) { |
|
| 132 | + return false; |
|
| 133 | + } |
|
| 134 | + |
|
| 135 | + \OC::$server->getEventLogger()->start('setup_fs', 'Setup filesystem'); |
|
| 136 | + |
|
| 137 | + // If we are not forced to load a specific user we load the one that is logged in |
|
| 138 | + if ($user === null) { |
|
| 139 | + $user = ''; |
|
| 140 | + } else if ($user == "" && \OC::$server->getUserSession()->isLoggedIn()) { |
|
| 141 | + $user = OC_User::getUser(); |
|
| 142 | + } |
|
| 143 | + |
|
| 144 | + // load all filesystem apps before, so no setup-hook gets lost |
|
| 145 | + OC_App::loadApps(array('filesystem')); |
|
| 146 | + |
|
| 147 | + // the filesystem will finish when $user is not empty, |
|
| 148 | + // mark fs setup here to avoid doing the setup from loading |
|
| 149 | + // OC_Filesystem |
|
| 150 | + if ($user != '') { |
|
| 151 | + self::$fsSetup = true; |
|
| 152 | + } |
|
| 153 | + |
|
| 154 | + \OC\Files\Filesystem::initMountManager(); |
|
| 155 | + |
|
| 156 | + \OC\Files\Filesystem::logWarningWhenAddingStorageWrapper(false); |
|
| 157 | + \OC\Files\Filesystem::addStorageWrapper('mount_options', function ($mountPoint, \OCP\Files\Storage $storage, \OCP\Files\Mount\IMountPoint $mount) { |
|
| 158 | + if ($storage->instanceOfStorage('\OC\Files\Storage\Common')) { |
|
| 159 | + /** @var \OC\Files\Storage\Common $storage */ |
|
| 160 | + $storage->setMountOptions($mount->getOptions()); |
|
| 161 | + } |
|
| 162 | + return $storage; |
|
| 163 | + }); |
|
| 164 | + |
|
| 165 | + \OC\Files\Filesystem::addStorageWrapper('enable_sharing', function ($mountPoint, \OCP\Files\Storage $storage, \OCP\Files\Mount\IMountPoint $mount) { |
|
| 166 | + if (!$mount->getOption('enable_sharing', true)) { |
|
| 167 | + return new \OC\Files\Storage\Wrapper\PermissionsMask([ |
|
| 168 | + 'storage' => $storage, |
|
| 169 | + 'mask' => \OCP\Constants::PERMISSION_ALL - \OCP\Constants::PERMISSION_SHARE |
|
| 170 | + ]); |
|
| 171 | + } |
|
| 172 | + return $storage; |
|
| 173 | + }); |
|
| 174 | + |
|
| 175 | + // install storage availability wrapper, before most other wrappers |
|
| 176 | + \OC\Files\Filesystem::addStorageWrapper('oc_availability', function ($mountPoint, $storage) { |
|
| 177 | + if (!$storage->instanceOfStorage('\OCA\Files_Sharing\SharedStorage') && !$storage->isLocal()) { |
|
| 178 | + return new \OC\Files\Storage\Wrapper\Availability(['storage' => $storage]); |
|
| 179 | + } |
|
| 180 | + return $storage; |
|
| 181 | + }); |
|
| 182 | + |
|
| 183 | + \OC\Files\Filesystem::addStorageWrapper('oc_encoding', function ($mountPoint, \OCP\Files\Storage $storage, \OCP\Files\Mount\IMountPoint $mount) { |
|
| 184 | + if ($mount->getOption('encoding_compatibility', false) && !$storage->instanceOfStorage('\OCA\Files_Sharing\SharedStorage') && !$storage->isLocal()) { |
|
| 185 | + return new \OC\Files\Storage\Wrapper\Encoding(['storage' => $storage]); |
|
| 186 | + } |
|
| 187 | + return $storage; |
|
| 188 | + }); |
|
| 189 | + |
|
| 190 | + \OC\Files\Filesystem::addStorageWrapper('oc_quota', function ($mountPoint, $storage) { |
|
| 191 | + // set up quota for home storages, even for other users |
|
| 192 | + // which can happen when using sharing |
|
| 193 | + |
|
| 194 | + /** |
|
| 195 | + * @var \OC\Files\Storage\Storage $storage |
|
| 196 | + */ |
|
| 197 | + if ($storage->instanceOfStorage('\OC\Files\Storage\Home') |
|
| 198 | + || $storage->instanceOfStorage('\OC\Files\ObjectStore\HomeObjectStoreStorage') |
|
| 199 | + ) { |
|
| 200 | + /** @var \OC\Files\Storage\Home $storage */ |
|
| 201 | + if (is_object($storage->getUser())) { |
|
| 202 | + $user = $storage->getUser()->getUID(); |
|
| 203 | + $quota = OC_Util::getUserQuota($user); |
|
| 204 | + if ($quota !== \OCP\Files\FileInfo::SPACE_UNLIMITED) { |
|
| 205 | + return new \OC\Files\Storage\Wrapper\Quota(array('storage' => $storage, 'quota' => $quota, 'root' => 'files')); |
|
| 206 | + } |
|
| 207 | + } |
|
| 208 | + } |
|
| 209 | + |
|
| 210 | + return $storage; |
|
| 211 | + }); |
|
| 212 | + |
|
| 213 | + OC_Hook::emit('OC_Filesystem', 'preSetup', array('user' => $user)); |
|
| 214 | + \OC\Files\Filesystem::logWarningWhenAddingStorageWrapper(true); |
|
| 215 | + |
|
| 216 | + //check if we are using an object storage |
|
| 217 | + $objectStore = \OC::$server->getSystemConfig()->getValue('objectstore', null); |
|
| 218 | + if (isset($objectStore)) { |
|
| 219 | + self::initObjectStoreRootFS($objectStore); |
|
| 220 | + } else { |
|
| 221 | + self::initLocalStorageRootFS(); |
|
| 222 | + } |
|
| 223 | + |
|
| 224 | + if ($user != '' && !OCP\User::userExists($user)) { |
|
| 225 | + \OC::$server->getEventLogger()->end('setup_fs'); |
|
| 226 | + return false; |
|
| 227 | + } |
|
| 228 | + |
|
| 229 | + //if we aren't logged in, there is no use to set up the filesystem |
|
| 230 | + if ($user != "") { |
|
| 231 | + |
|
| 232 | + $userDir = '/' . $user . '/files'; |
|
| 233 | + |
|
| 234 | + //jail the user into his "home" directory |
|
| 235 | + \OC\Files\Filesystem::init($user, $userDir); |
|
| 236 | + |
|
| 237 | + OC_Hook::emit('OC_Filesystem', 'setup', array('user' => $user, 'user_dir' => $userDir)); |
|
| 238 | + } |
|
| 239 | + \OC::$server->getEventLogger()->end('setup_fs'); |
|
| 240 | + return true; |
|
| 241 | + } |
|
| 242 | + |
|
| 243 | + /** |
|
| 244 | + * check if a password is required for each public link |
|
| 245 | + * |
|
| 246 | + * @return boolean |
|
| 247 | + */ |
|
| 248 | + public static function isPublicLinkPasswordRequired() { |
|
| 249 | + $appConfig = \OC::$server->getAppConfig(); |
|
| 250 | + $enforcePassword = $appConfig->getValue('core', 'shareapi_enforce_links_password', 'no'); |
|
| 251 | + return ($enforcePassword === 'yes') ? true : false; |
|
| 252 | + } |
|
| 253 | + |
|
| 254 | + /** |
|
| 255 | + * check if sharing is disabled for the current user |
|
| 256 | + * @param IConfig $config |
|
| 257 | + * @param IGroupManager $groupManager |
|
| 258 | + * @param IUser|null $user |
|
| 259 | + * @return bool |
|
| 260 | + */ |
|
| 261 | + public static function isSharingDisabledForUser(IConfig $config, IGroupManager $groupManager, $user) { |
|
| 262 | + if ($config->getAppValue('core', 'shareapi_exclude_groups', 'no') === 'yes') { |
|
| 263 | + $groupsList = $config->getAppValue('core', 'shareapi_exclude_groups_list', ''); |
|
| 264 | + $excludedGroups = json_decode($groupsList); |
|
| 265 | + if (is_null($excludedGroups)) { |
|
| 266 | + $excludedGroups = explode(',', $groupsList); |
|
| 267 | + $newValue = json_encode($excludedGroups); |
|
| 268 | + $config->setAppValue('core', 'shareapi_exclude_groups_list', $newValue); |
|
| 269 | + } |
|
| 270 | + $usersGroups = $groupManager->getUserGroupIds($user); |
|
| 271 | + if (!empty($usersGroups)) { |
|
| 272 | + $remainingGroups = array_diff($usersGroups, $excludedGroups); |
|
| 273 | + // if the user is only in groups which are disabled for sharing then |
|
| 274 | + // sharing is also disabled for the user |
|
| 275 | + if (empty($remainingGroups)) { |
|
| 276 | + return true; |
|
| 277 | + } |
|
| 278 | + } |
|
| 279 | + } |
|
| 280 | + return false; |
|
| 281 | + } |
|
| 282 | + |
|
| 283 | + /** |
|
| 284 | + * check if share API enforces a default expire date |
|
| 285 | + * |
|
| 286 | + * @return boolean |
|
| 287 | + */ |
|
| 288 | + public static function isDefaultExpireDateEnforced() { |
|
| 289 | + $isDefaultExpireDateEnabled = \OCP\Config::getAppValue('core', 'shareapi_default_expire_date', 'no'); |
|
| 290 | + $enforceDefaultExpireDate = false; |
|
| 291 | + if ($isDefaultExpireDateEnabled === 'yes') { |
|
| 292 | + $value = \OCP\Config::getAppValue('core', 'shareapi_enforce_expire_date', 'no'); |
|
| 293 | + $enforceDefaultExpireDate = ($value === 'yes') ? true : false; |
|
| 294 | + } |
|
| 295 | + |
|
| 296 | + return $enforceDefaultExpireDate; |
|
| 297 | + } |
|
| 298 | + |
|
| 299 | + /** |
|
| 300 | + * Get the quota of a user |
|
| 301 | + * |
|
| 302 | + * @param string $userId |
|
| 303 | + * @return int Quota bytes |
|
| 304 | + */ |
|
| 305 | + public static function getUserQuota($userId) { |
|
| 306 | + $user = \OC::$server->getUserManager()->get($userId); |
|
| 307 | + if (is_null($user)) { |
|
| 308 | + return \OCP\Files\FileInfo::SPACE_UNLIMITED; |
|
| 309 | + } |
|
| 310 | + $userQuota = $user->getQuota(); |
|
| 311 | + if($userQuota === 'none') { |
|
| 312 | + return \OCP\Files\FileInfo::SPACE_UNLIMITED; |
|
| 313 | + } |
|
| 314 | + return OC_Helper::computerFileSize($userQuota); |
|
| 315 | + } |
|
| 316 | + |
|
| 317 | + /** |
|
| 318 | + * copies the skeleton to the users /files |
|
| 319 | + * |
|
| 320 | + * @param String $userId |
|
| 321 | + * @param \OCP\Files\Folder $userDirectory |
|
| 322 | + * @throws \RuntimeException |
|
| 323 | + */ |
|
| 324 | + public static function copySkeleton($userId, \OCP\Files\Folder $userDirectory) { |
|
| 325 | + |
|
| 326 | + $skeletonDirectory = \OC::$server->getConfig()->getSystemValue('skeletondirectory', \OC::$SERVERROOT . '/core/skeleton'); |
|
| 327 | + $instanceId = \OC::$server->getConfig()->getSystemValue('instanceid', ''); |
|
| 328 | + |
|
| 329 | + if ($instanceId === null) { |
|
| 330 | + throw new \RuntimeException('no instance id!'); |
|
| 331 | + } |
|
| 332 | + $appdata = 'appdata_' . $instanceId; |
|
| 333 | + if ($userId === $appdata) { |
|
| 334 | + throw new \RuntimeException('username is reserved name: ' . $appdata); |
|
| 335 | + } |
|
| 336 | + |
|
| 337 | + if (!empty($skeletonDirectory)) { |
|
| 338 | + \OCP\Util::writeLog( |
|
| 339 | + 'files_skeleton', |
|
| 340 | + 'copying skeleton for '.$userId.' from '.$skeletonDirectory.' to '.$userDirectory->getFullPath('/'), |
|
| 341 | + \OCP\Util::DEBUG |
|
| 342 | + ); |
|
| 343 | + self::copyr($skeletonDirectory, $userDirectory); |
|
| 344 | + // update the file cache |
|
| 345 | + $userDirectory->getStorage()->getScanner()->scan('', \OC\Files\Cache\Scanner::SCAN_RECURSIVE); |
|
| 346 | + } |
|
| 347 | + } |
|
| 348 | + |
|
| 349 | + /** |
|
| 350 | + * copies a directory recursively by using streams |
|
| 351 | + * |
|
| 352 | + * @param string $source |
|
| 353 | + * @param \OCP\Files\Folder $target |
|
| 354 | + * @return void |
|
| 355 | + */ |
|
| 356 | + public static function copyr($source, \OCP\Files\Folder $target) { |
|
| 357 | + $logger = \OC::$server->getLogger(); |
|
| 358 | + |
|
| 359 | + // Verify if folder exists |
|
| 360 | + $dir = opendir($source); |
|
| 361 | + if($dir === false) { |
|
| 362 | + $logger->error(sprintf('Could not opendir "%s"', $source), ['app' => 'core']); |
|
| 363 | + return; |
|
| 364 | + } |
|
| 365 | + |
|
| 366 | + // Copy the files |
|
| 367 | + while (false !== ($file = readdir($dir))) { |
|
| 368 | + if (!\OC\Files\Filesystem::isIgnoredDir($file)) { |
|
| 369 | + if (is_dir($source . '/' . $file)) { |
|
| 370 | + $child = $target->newFolder($file); |
|
| 371 | + self::copyr($source . '/' . $file, $child); |
|
| 372 | + } else { |
|
| 373 | + $child = $target->newFile($file); |
|
| 374 | + $sourceStream = fopen($source . '/' . $file, 'r'); |
|
| 375 | + if($sourceStream === false) { |
|
| 376 | + $logger->error(sprintf('Could not fopen "%s"', $source . '/' . $file), ['app' => 'core']); |
|
| 377 | + closedir($dir); |
|
| 378 | + return; |
|
| 379 | + } |
|
| 380 | + stream_copy_to_stream($sourceStream, $child->fopen('w')); |
|
| 381 | + } |
|
| 382 | + } |
|
| 383 | + } |
|
| 384 | + closedir($dir); |
|
| 385 | + } |
|
| 386 | + |
|
| 387 | + /** |
|
| 388 | + * @return void |
|
| 389 | + */ |
|
| 390 | + public static function tearDownFS() { |
|
| 391 | + \OC\Files\Filesystem::tearDown(); |
|
| 392 | + \OC::$server->getRootFolder()->clearCache(); |
|
| 393 | + self::$fsSetup = false; |
|
| 394 | + self::$rootMounted = false; |
|
| 395 | + } |
|
| 396 | + |
|
| 397 | + /** |
|
| 398 | + * get the current installed version of ownCloud |
|
| 399 | + * |
|
| 400 | + * @return array |
|
| 401 | + */ |
|
| 402 | + public static function getVersion() { |
|
| 403 | + OC_Util::loadVersion(); |
|
| 404 | + return self::$versionCache['OC_Version']; |
|
| 405 | + } |
|
| 406 | + |
|
| 407 | + /** |
|
| 408 | + * get the current installed version string of ownCloud |
|
| 409 | + * |
|
| 410 | + * @return string |
|
| 411 | + */ |
|
| 412 | + public static function getVersionString() { |
|
| 413 | + OC_Util::loadVersion(); |
|
| 414 | + return self::$versionCache['OC_VersionString']; |
|
| 415 | + } |
|
| 416 | + |
|
| 417 | + /** |
|
| 418 | + * @deprecated the value is of no use anymore |
|
| 419 | + * @return string |
|
| 420 | + */ |
|
| 421 | + public static function getEditionString() { |
|
| 422 | + return ''; |
|
| 423 | + } |
|
| 424 | + |
|
| 425 | + /** |
|
| 426 | + * @description get the update channel of the current installed of ownCloud. |
|
| 427 | + * @return string |
|
| 428 | + */ |
|
| 429 | + public static function getChannel() { |
|
| 430 | + OC_Util::loadVersion(); |
|
| 431 | + return \OC::$server->getConfig()->getSystemValue('updater.release.channel', self::$versionCache['OC_Channel']); |
|
| 432 | + } |
|
| 433 | + |
|
| 434 | + /** |
|
| 435 | + * @description get the build number of the current installed of ownCloud. |
|
| 436 | + * @return string |
|
| 437 | + */ |
|
| 438 | + public static function getBuild() { |
|
| 439 | + OC_Util::loadVersion(); |
|
| 440 | + return self::$versionCache['OC_Build']; |
|
| 441 | + } |
|
| 442 | + |
|
| 443 | + /** |
|
| 444 | + * @description load the version.php into the session as cache |
|
| 445 | + */ |
|
| 446 | + private static function loadVersion() { |
|
| 447 | + if (self::$versionCache !== null) { |
|
| 448 | + return; |
|
| 449 | + } |
|
| 450 | + |
|
| 451 | + $timestamp = filemtime(OC::$SERVERROOT . '/version.php'); |
|
| 452 | + require OC::$SERVERROOT . '/version.php'; |
|
| 453 | + /** @var $timestamp int */ |
|
| 454 | + self::$versionCache['OC_Version_Timestamp'] = $timestamp; |
|
| 455 | + /** @var $OC_Version string */ |
|
| 456 | + self::$versionCache['OC_Version'] = $OC_Version; |
|
| 457 | + /** @var $OC_VersionString string */ |
|
| 458 | + self::$versionCache['OC_VersionString'] = $OC_VersionString; |
|
| 459 | + /** @var $OC_Build string */ |
|
| 460 | + self::$versionCache['OC_Build'] = $OC_Build; |
|
| 461 | + |
|
| 462 | + /** @var $OC_Channel string */ |
|
| 463 | + self::$versionCache['OC_Channel'] = $OC_Channel; |
|
| 464 | + } |
|
| 465 | + |
|
| 466 | + /** |
|
| 467 | + * generates a path for JS/CSS files. If no application is provided it will create the path for core. |
|
| 468 | + * |
|
| 469 | + * @param string $application application to get the files from |
|
| 470 | + * @param string $directory directory within this application (css, js, vendor, etc) |
|
| 471 | + * @param string $file the file inside of the above folder |
|
| 472 | + * @return string the path |
|
| 473 | + */ |
|
| 474 | + private static function generatePath($application, $directory, $file) { |
|
| 475 | + if (is_null($file)) { |
|
| 476 | + $file = $application; |
|
| 477 | + $application = ""; |
|
| 478 | + } |
|
| 479 | + if (!empty($application)) { |
|
| 480 | + return "$application/$directory/$file"; |
|
| 481 | + } else { |
|
| 482 | + return "$directory/$file"; |
|
| 483 | + } |
|
| 484 | + } |
|
| 485 | + |
|
| 486 | + /** |
|
| 487 | + * add a javascript file |
|
| 488 | + * |
|
| 489 | + * @param string $application application id |
|
| 490 | + * @param string|null $file filename |
|
| 491 | + * @param bool $prepend prepend the Script to the beginning of the list |
|
| 492 | + * @return void |
|
| 493 | + */ |
|
| 494 | + public static function addScript($application, $file = null, $prepend = false) { |
|
| 495 | + $path = OC_Util::generatePath($application, 'js', $file); |
|
| 496 | + |
|
| 497 | + // core js files need separate handling |
|
| 498 | + if ($application !== 'core' && $file !== null) { |
|
| 499 | + self::addTranslations ( $application ); |
|
| 500 | + } |
|
| 501 | + self::addExternalResource($application, $prepend, $path, "script"); |
|
| 502 | + } |
|
| 503 | + |
|
| 504 | + /** |
|
| 505 | + * add a javascript file from the vendor sub folder |
|
| 506 | + * |
|
| 507 | + * @param string $application application id |
|
| 508 | + * @param string|null $file filename |
|
| 509 | + * @param bool $prepend prepend the Script to the beginning of the list |
|
| 510 | + * @return void |
|
| 511 | + */ |
|
| 512 | + public static function addVendorScript($application, $file = null, $prepend = false) { |
|
| 513 | + $path = OC_Util::generatePath($application, 'vendor', $file); |
|
| 514 | + self::addExternalResource($application, $prepend, $path, "script"); |
|
| 515 | + } |
|
| 516 | + |
|
| 517 | + /** |
|
| 518 | + * add a translation JS file |
|
| 519 | + * |
|
| 520 | + * @param string $application application id |
|
| 521 | + * @param string $languageCode language code, defaults to the current language |
|
| 522 | + * @param bool $prepend prepend the Script to the beginning of the list |
|
| 523 | + */ |
|
| 524 | + public static function addTranslations($application, $languageCode = null, $prepend = false) { |
|
| 525 | + if (is_null($languageCode)) { |
|
| 526 | + $languageCode = \OC::$server->getL10NFactory()->findLanguage($application); |
|
| 527 | + } |
|
| 528 | + if (!empty($application)) { |
|
| 529 | + $path = "$application/l10n/$languageCode"; |
|
| 530 | + } else { |
|
| 531 | + $path = "l10n/$languageCode"; |
|
| 532 | + } |
|
| 533 | + self::addExternalResource($application, $prepend, $path, "script"); |
|
| 534 | + } |
|
| 535 | + |
|
| 536 | + /** |
|
| 537 | + * add a css file |
|
| 538 | + * |
|
| 539 | + * @param string $application application id |
|
| 540 | + * @param string|null $file filename |
|
| 541 | + * @param bool $prepend prepend the Style to the beginning of the list |
|
| 542 | + * @return void |
|
| 543 | + */ |
|
| 544 | + public static function addStyle($application, $file = null, $prepend = false) { |
|
| 545 | + $path = OC_Util::generatePath($application, 'css', $file); |
|
| 546 | + self::addExternalResource($application, $prepend, $path, "style"); |
|
| 547 | + } |
|
| 548 | + |
|
| 549 | + /** |
|
| 550 | + * add a css file from the vendor sub folder |
|
| 551 | + * |
|
| 552 | + * @param string $application application id |
|
| 553 | + * @param string|null $file filename |
|
| 554 | + * @param bool $prepend prepend the Style to the beginning of the list |
|
| 555 | + * @return void |
|
| 556 | + */ |
|
| 557 | + public static function addVendorStyle($application, $file = null, $prepend = false) { |
|
| 558 | + $path = OC_Util::generatePath($application, 'vendor', $file); |
|
| 559 | + self::addExternalResource($application, $prepend, $path, "style"); |
|
| 560 | + } |
|
| 561 | + |
|
| 562 | + /** |
|
| 563 | + * add an external resource css/js file |
|
| 564 | + * |
|
| 565 | + * @param string $application application id |
|
| 566 | + * @param bool $prepend prepend the file to the beginning of the list |
|
| 567 | + * @param string $path |
|
| 568 | + * @param string $type (script or style) |
|
| 569 | + * @return void |
|
| 570 | + */ |
|
| 571 | + private static function addExternalResource($application, $prepend, $path, $type = "script") { |
|
| 572 | + |
|
| 573 | + if ($type === "style") { |
|
| 574 | + if (!in_array($path, self::$styles)) { |
|
| 575 | + if ($prepend === true) { |
|
| 576 | + array_unshift ( self::$styles, $path ); |
|
| 577 | + } else { |
|
| 578 | + self::$styles[] = $path; |
|
| 579 | + } |
|
| 580 | + } |
|
| 581 | + } elseif ($type === "script") { |
|
| 582 | + if (!in_array($path, self::$scripts)) { |
|
| 583 | + if ($prepend === true) { |
|
| 584 | + array_unshift ( self::$scripts, $path ); |
|
| 585 | + } else { |
|
| 586 | + self::$scripts [] = $path; |
|
| 587 | + } |
|
| 588 | + } |
|
| 589 | + } |
|
| 590 | + } |
|
| 591 | + |
|
| 592 | + /** |
|
| 593 | + * Add a custom element to the header |
|
| 594 | + * If $text is null then the element will be written as empty element. |
|
| 595 | + * So use "" to get a closing tag. |
|
| 596 | + * @param string $tag tag name of the element |
|
| 597 | + * @param array $attributes array of attributes for the element |
|
| 598 | + * @param string $text the text content for the element |
|
| 599 | + */ |
|
| 600 | + public static function addHeader($tag, $attributes, $text=null) { |
|
| 601 | + self::$headers[] = array( |
|
| 602 | + 'tag' => $tag, |
|
| 603 | + 'attributes' => $attributes, |
|
| 604 | + 'text' => $text |
|
| 605 | + ); |
|
| 606 | + } |
|
| 607 | + |
|
| 608 | + /** |
|
| 609 | + * formats a timestamp in the "right" way |
|
| 610 | + * |
|
| 611 | + * @param int $timestamp |
|
| 612 | + * @param bool $dateOnly option to omit time from the result |
|
| 613 | + * @param DateTimeZone|string $timeZone where the given timestamp shall be converted to |
|
| 614 | + * @return string timestamp |
|
| 615 | + * |
|
| 616 | + * @deprecated Use \OC::$server->query('DateTimeFormatter') instead |
|
| 617 | + */ |
|
| 618 | + public static function formatDate($timestamp, $dateOnly = false, $timeZone = null) { |
|
| 619 | + if ($timeZone !== null && !$timeZone instanceof \DateTimeZone) { |
|
| 620 | + $timeZone = new \DateTimeZone($timeZone); |
|
| 621 | + } |
|
| 622 | + |
|
| 623 | + /** @var \OC\DateTimeFormatter $formatter */ |
|
| 624 | + $formatter = \OC::$server->query('DateTimeFormatter'); |
|
| 625 | + if ($dateOnly) { |
|
| 626 | + return $formatter->formatDate($timestamp, 'long', $timeZone); |
|
| 627 | + } |
|
| 628 | + return $formatter->formatDateTime($timestamp, 'long', 'long', $timeZone); |
|
| 629 | + } |
|
| 630 | + |
|
| 631 | + /** |
|
| 632 | + * check if the current server configuration is suitable for ownCloud |
|
| 633 | + * |
|
| 634 | + * @param \OC\SystemConfig $config |
|
| 635 | + * @return array arrays with error messages and hints |
|
| 636 | + */ |
|
| 637 | + public static function checkServer(\OC\SystemConfig $config) { |
|
| 638 | + $l = \OC::$server->getL10N('lib'); |
|
| 639 | + $errors = array(); |
|
| 640 | + $CONFIG_DATADIRECTORY = $config->getValue('datadirectory', OC::$SERVERROOT . '/data'); |
|
| 641 | + |
|
| 642 | + if (!self::needUpgrade($config) && $config->getValue('installed', false)) { |
|
| 643 | + // this check needs to be done every time |
|
| 644 | + $errors = self::checkDataDirectoryValidity($CONFIG_DATADIRECTORY); |
|
| 645 | + } |
|
| 646 | + |
|
| 647 | + // Assume that if checkServer() succeeded before in this session, then all is fine. |
|
| 648 | + if (\OC::$server->getSession()->exists('checkServer_succeeded') && \OC::$server->getSession()->get('checkServer_succeeded')) { |
|
| 649 | + return $errors; |
|
| 650 | + } |
|
| 651 | + |
|
| 652 | + $webServerRestart = false; |
|
| 653 | + $setup = new \OC\Setup($config, \OC::$server->getIniWrapper(), \OC::$server->getL10N('lib'), |
|
| 654 | + \OC::$server->getThemingDefaults(), \OC::$server->getLogger(), \OC::$server->getSecureRandom()); |
|
| 655 | + |
|
| 656 | + $urlGenerator = \OC::$server->getURLGenerator(); |
|
| 657 | + |
|
| 658 | + $availableDatabases = $setup->getSupportedDatabases(); |
|
| 659 | + if (empty($availableDatabases)) { |
|
| 660 | + $errors[] = array( |
|
| 661 | + 'error' => $l->t('No database drivers (sqlite, mysql, or postgresql) installed.'), |
|
| 662 | + 'hint' => '' //TODO: sane hint |
|
| 663 | + ); |
|
| 664 | + $webServerRestart = true; |
|
| 665 | + } |
|
| 666 | + |
|
| 667 | + // Check if config folder is writable. |
|
| 668 | + if(!OC_Helper::isReadOnlyConfigEnabled()) { |
|
| 669 | + if (!is_writable(OC::$configDir) or !is_readable(OC::$configDir)) { |
|
| 670 | + $errors[] = array( |
|
| 671 | + 'error' => $l->t('Cannot write into "config" directory'), |
|
| 672 | + 'hint' => $l->t('This can usually be fixed by ' |
|
| 673 | + . '%sgiving the webserver write access to the config directory%s.', |
|
| 674 | + array('<a href="' . $urlGenerator->linkToDocs('admin-dir_permissions') . '" target="_blank" rel="noreferrer">', '</a>')) |
|
| 675 | + ); |
|
| 676 | + } |
|
| 677 | + } |
|
| 678 | + |
|
| 679 | + // Check if there is a writable install folder. |
|
| 680 | + if ($config->getValue('appstoreenabled', true)) { |
|
| 681 | + if (OC_App::getInstallPath() === null |
|
| 682 | + || !is_writable(OC_App::getInstallPath()) |
|
| 683 | + || !is_readable(OC_App::getInstallPath()) |
|
| 684 | + ) { |
|
| 685 | + $errors[] = array( |
|
| 686 | + 'error' => $l->t('Cannot write into "apps" directory'), |
|
| 687 | + 'hint' => $l->t('This can usually be fixed by ' |
|
| 688 | + . '%sgiving the webserver write access to the apps directory%s' |
|
| 689 | + . ' or disabling the appstore in the config file.', |
|
| 690 | + array('<a href="' . $urlGenerator->linkToDocs('admin-dir_permissions') . '" target="_blank" rel="noreferrer">', '</a>')) |
|
| 691 | + ); |
|
| 692 | + } |
|
| 693 | + } |
|
| 694 | + // Create root dir. |
|
| 695 | + if ($config->getValue('installed', false)) { |
|
| 696 | + if (!is_dir($CONFIG_DATADIRECTORY)) { |
|
| 697 | + $success = @mkdir($CONFIG_DATADIRECTORY); |
|
| 698 | + if ($success) { |
|
| 699 | + $errors = array_merge($errors, self::checkDataDirectoryPermissions($CONFIG_DATADIRECTORY)); |
|
| 700 | + } else { |
|
| 701 | + $errors[] = [ |
|
| 702 | + 'error' => $l->t('Cannot create "data" directory'), |
|
| 703 | + 'hint' => $l->t('This can usually be fixed by ' |
|
| 704 | + . '<a href="%s" target="_blank" rel="noreferrer">giving the webserver write access to the root directory</a>.', |
|
| 705 | + [$urlGenerator->linkToDocs('admin-dir_permissions')]) |
|
| 706 | + ]; |
|
| 707 | + } |
|
| 708 | + } else if (!is_writable($CONFIG_DATADIRECTORY) or !is_readable($CONFIG_DATADIRECTORY)) { |
|
| 709 | + //common hint for all file permissions error messages |
|
| 710 | + $permissionsHint = $l->t('Permissions can usually be fixed by ' |
|
| 711 | + . '%sgiving the webserver write access to the root directory%s.', |
|
| 712 | + ['<a href="' . $urlGenerator->linkToDocs('admin-dir_permissions') . '" target="_blank" rel="noreferrer">', '</a>']); |
|
| 713 | + $errors[] = [ |
|
| 714 | + 'error' => 'Your data directory is not writable', |
|
| 715 | + 'hint' => $permissionsHint |
|
| 716 | + ]; |
|
| 717 | + } else { |
|
| 718 | + $errors = array_merge($errors, self::checkDataDirectoryPermissions($CONFIG_DATADIRECTORY)); |
|
| 719 | + } |
|
| 720 | + } |
|
| 721 | + |
|
| 722 | + if (!OC_Util::isSetLocaleWorking()) { |
|
| 723 | + $errors[] = array( |
|
| 724 | + 'error' => $l->t('Setting locale to %s failed', |
|
| 725 | + array('en_US.UTF-8/fr_FR.UTF-8/es_ES.UTF-8/de_DE.UTF-8/ru_RU.UTF-8/' |
|
| 726 | + . 'pt_BR.UTF-8/it_IT.UTF-8/ja_JP.UTF-8/zh_CN.UTF-8')), |
|
| 727 | + 'hint' => $l->t('Please install one of these locales on your system and restart your webserver.') |
|
| 728 | + ); |
|
| 729 | + } |
|
| 730 | + |
|
| 731 | + // Contains the dependencies that should be checked against |
|
| 732 | + // classes = class_exists |
|
| 733 | + // functions = function_exists |
|
| 734 | + // defined = defined |
|
| 735 | + // ini = ini_get |
|
| 736 | + // If the dependency is not found the missing module name is shown to the EndUser |
|
| 737 | + // When adding new checks always verify that they pass on Travis as well |
|
| 738 | + // for ini settings, see https://github.com/owncloud/administration/blob/master/travis-ci/custom.ini |
|
| 739 | + $dependencies = array( |
|
| 740 | + 'classes' => array( |
|
| 741 | + 'ZipArchive' => 'zip', |
|
| 742 | + 'DOMDocument' => 'dom', |
|
| 743 | + 'XMLWriter' => 'XMLWriter', |
|
| 744 | + 'XMLReader' => 'XMLReader', |
|
| 745 | + ), |
|
| 746 | + 'functions' => [ |
|
| 747 | + 'xml_parser_create' => 'libxml', |
|
| 748 | + 'mb_strcut' => 'mb multibyte', |
|
| 749 | + 'ctype_digit' => 'ctype', |
|
| 750 | + 'json_encode' => 'JSON', |
|
| 751 | + 'gd_info' => 'GD', |
|
| 752 | + 'gzencode' => 'zlib', |
|
| 753 | + 'iconv' => 'iconv', |
|
| 754 | + 'simplexml_load_string' => 'SimpleXML', |
|
| 755 | + 'hash' => 'HASH Message Digest Framework', |
|
| 756 | + 'curl_init' => 'cURL', |
|
| 757 | + 'openssl_verify' => 'OpenSSL', |
|
| 758 | + ], |
|
| 759 | + 'defined' => array( |
|
| 760 | + 'PDO::ATTR_DRIVER_NAME' => 'PDO' |
|
| 761 | + ), |
|
| 762 | + 'ini' => [ |
|
| 763 | + 'default_charset' => 'UTF-8', |
|
| 764 | + ], |
|
| 765 | + ); |
|
| 766 | + $missingDependencies = array(); |
|
| 767 | + $invalidIniSettings = []; |
|
| 768 | + $moduleHint = $l->t('Please ask your server administrator to install the module.'); |
|
| 769 | + |
|
| 770 | + /** |
|
| 771 | + * FIXME: The dependency check does not work properly on HHVM on the moment |
|
| 772 | + * and prevents installation. Once HHVM is more compatible with our |
|
| 773 | + * approach to check for these values we should re-enable those |
|
| 774 | + * checks. |
|
| 775 | + */ |
|
| 776 | + $iniWrapper = \OC::$server->getIniWrapper(); |
|
| 777 | + if (!self::runningOnHhvm()) { |
|
| 778 | + foreach ($dependencies['classes'] as $class => $module) { |
|
| 779 | + if (!class_exists($class)) { |
|
| 780 | + $missingDependencies[] = $module; |
|
| 781 | + } |
|
| 782 | + } |
|
| 783 | + foreach ($dependencies['functions'] as $function => $module) { |
|
| 784 | + if (!function_exists($function)) { |
|
| 785 | + $missingDependencies[] = $module; |
|
| 786 | + } |
|
| 787 | + } |
|
| 788 | + foreach ($dependencies['defined'] as $defined => $module) { |
|
| 789 | + if (!defined($defined)) { |
|
| 790 | + $missingDependencies[] = $module; |
|
| 791 | + } |
|
| 792 | + } |
|
| 793 | + foreach ($dependencies['ini'] as $setting => $expected) { |
|
| 794 | + if (is_bool($expected)) { |
|
| 795 | + if ($iniWrapper->getBool($setting) !== $expected) { |
|
| 796 | + $invalidIniSettings[] = [$setting, $expected]; |
|
| 797 | + } |
|
| 798 | + } |
|
| 799 | + if (is_int($expected)) { |
|
| 800 | + if ($iniWrapper->getNumeric($setting) !== $expected) { |
|
| 801 | + $invalidIniSettings[] = [$setting, $expected]; |
|
| 802 | + } |
|
| 803 | + } |
|
| 804 | + if (is_string($expected)) { |
|
| 805 | + if (strtolower($iniWrapper->getString($setting)) !== strtolower($expected)) { |
|
| 806 | + $invalidIniSettings[] = [$setting, $expected]; |
|
| 807 | + } |
|
| 808 | + } |
|
| 809 | + } |
|
| 810 | + } |
|
| 811 | + |
|
| 812 | + foreach($missingDependencies as $missingDependency) { |
|
| 813 | + $errors[] = array( |
|
| 814 | + 'error' => $l->t('PHP module %s not installed.', array($missingDependency)), |
|
| 815 | + 'hint' => $moduleHint |
|
| 816 | + ); |
|
| 817 | + $webServerRestart = true; |
|
| 818 | + } |
|
| 819 | + foreach($invalidIniSettings as $setting) { |
|
| 820 | + if(is_bool($setting[1])) { |
|
| 821 | + $setting[1] = ($setting[1]) ? 'on' : 'off'; |
|
| 822 | + } |
|
| 823 | + $errors[] = [ |
|
| 824 | + 'error' => $l->t('PHP setting "%s" is not set to "%s".', [$setting[0], var_export($setting[1], true)]), |
|
| 825 | + 'hint' => $l->t('Adjusting this setting in php.ini will make Nextcloud run again') |
|
| 826 | + ]; |
|
| 827 | + $webServerRestart = true; |
|
| 828 | + } |
|
| 829 | + |
|
| 830 | + /** |
|
| 831 | + * The mbstring.func_overload check can only be performed if the mbstring |
|
| 832 | + * module is installed as it will return null if the checking setting is |
|
| 833 | + * not available and thus a check on the boolean value fails. |
|
| 834 | + * |
|
| 835 | + * TODO: Should probably be implemented in the above generic dependency |
|
| 836 | + * check somehow in the long-term. |
|
| 837 | + */ |
|
| 838 | + if($iniWrapper->getBool('mbstring.func_overload') !== null && |
|
| 839 | + $iniWrapper->getBool('mbstring.func_overload') === true) { |
|
| 840 | + $errors[] = array( |
|
| 841 | + 'error' => $l->t('mbstring.func_overload is set to "%s" instead of the expected value "0"', [$iniWrapper->getString('mbstring.func_overload')]), |
|
| 842 | + 'hint' => $l->t('To fix this issue set <code>mbstring.func_overload</code> to <code>0</code> in your php.ini') |
|
| 843 | + ); |
|
| 844 | + } |
|
| 845 | + |
|
| 846 | + if(function_exists('xml_parser_create') && |
|
| 847 | + LIBXML_LOADED_VERSION < 20700 ) { |
|
| 848 | + $version = LIBXML_LOADED_VERSION; |
|
| 849 | + $major = floor($version/10000); |
|
| 850 | + $version -= ($major * 10000); |
|
| 851 | + $minor = floor($version/100); |
|
| 852 | + $version -= ($minor * 100); |
|
| 853 | + $patch = $version; |
|
| 854 | + $errors[] = array( |
|
| 855 | + 'error' => $l->t('libxml2 2.7.0 is at least required. Currently %s is installed.', [$major . '.' . $minor . '.' . $patch]), |
|
| 856 | + 'hint' => $l->t('To fix this issue update your libxml2 version and restart your web server.') |
|
| 857 | + ); |
|
| 858 | + } |
|
| 859 | + |
|
| 860 | + if (!self::isAnnotationsWorking()) { |
|
| 861 | + $errors[] = array( |
|
| 862 | + 'error' => $l->t('PHP is apparently set up to strip inline doc blocks. This will make several core apps inaccessible.'), |
|
| 863 | + 'hint' => $l->t('This is probably caused by a cache/accelerator such as Zend OPcache or eAccelerator.') |
|
| 864 | + ); |
|
| 865 | + } |
|
| 866 | + |
|
| 867 | + if (!\OC::$CLI && $webServerRestart) { |
|
| 868 | + $errors[] = array( |
|
| 869 | + 'error' => $l->t('PHP modules have been installed, but they are still listed as missing?'), |
|
| 870 | + 'hint' => $l->t('Please ask your server administrator to restart the web server.') |
|
| 871 | + ); |
|
| 872 | + } |
|
| 873 | + |
|
| 874 | + $errors = array_merge($errors, self::checkDatabaseVersion()); |
|
| 875 | + |
|
| 876 | + // Cache the result of this function |
|
| 877 | + \OC::$server->getSession()->set('checkServer_succeeded', count($errors) == 0); |
|
| 878 | + |
|
| 879 | + return $errors; |
|
| 880 | + } |
|
| 881 | + |
|
| 882 | + /** |
|
| 883 | + * Check the database version |
|
| 884 | + * |
|
| 885 | + * @return array errors array |
|
| 886 | + */ |
|
| 887 | + public static function checkDatabaseVersion() { |
|
| 888 | + $l = \OC::$server->getL10N('lib'); |
|
| 889 | + $errors = array(); |
|
| 890 | + $dbType = \OC::$server->getSystemConfig()->getValue('dbtype', 'sqlite'); |
|
| 891 | + if ($dbType === 'pgsql') { |
|
| 892 | + // check PostgreSQL version |
|
| 893 | + try { |
|
| 894 | + $result = \OC_DB::executeAudited('SHOW SERVER_VERSION'); |
|
| 895 | + $data = $result->fetchRow(); |
|
| 896 | + if (isset($data['server_version'])) { |
|
| 897 | + $version = $data['server_version']; |
|
| 898 | + if (version_compare($version, '9.0.0', '<')) { |
|
| 899 | + $errors[] = array( |
|
| 900 | + 'error' => $l->t('PostgreSQL >= 9 required'), |
|
| 901 | + 'hint' => $l->t('Please upgrade your database version') |
|
| 902 | + ); |
|
| 903 | + } |
|
| 904 | + } |
|
| 905 | + } catch (\Doctrine\DBAL\DBALException $e) { |
|
| 906 | + $logger = \OC::$server->getLogger(); |
|
| 907 | + $logger->warning('Error occurred while checking PostgreSQL version, assuming >= 9'); |
|
| 908 | + $logger->logException($e); |
|
| 909 | + } |
|
| 910 | + } |
|
| 911 | + return $errors; |
|
| 912 | + } |
|
| 913 | + |
|
| 914 | + /** |
|
| 915 | + * Check for correct file permissions of data directory |
|
| 916 | + * |
|
| 917 | + * @param string $dataDirectory |
|
| 918 | + * @return array arrays with error messages and hints |
|
| 919 | + */ |
|
| 920 | + public static function checkDataDirectoryPermissions($dataDirectory) { |
|
| 921 | + $l = \OC::$server->getL10N('lib'); |
|
| 922 | + $errors = array(); |
|
| 923 | + $permissionsModHint = $l->t('Please change the permissions to 0770 so that the directory' |
|
| 924 | + . ' cannot be listed by other users.'); |
|
| 925 | + $perms = substr(decoct(@fileperms($dataDirectory)), -3); |
|
| 926 | + if (substr($perms, -1) !== '0') { |
|
| 927 | + chmod($dataDirectory, 0770); |
|
| 928 | + clearstatcache(); |
|
| 929 | + $perms = substr(decoct(@fileperms($dataDirectory)), -3); |
|
| 930 | + if ($perms[2] !== '0') { |
|
| 931 | + $errors[] = [ |
|
| 932 | + 'error' => $l->t('Your data directory is readable by other users'), |
|
| 933 | + 'hint' => $permissionsModHint |
|
| 934 | + ]; |
|
| 935 | + } |
|
| 936 | + } |
|
| 937 | + return $errors; |
|
| 938 | + } |
|
| 939 | + |
|
| 940 | + /** |
|
| 941 | + * Check that the data directory exists and is valid by |
|
| 942 | + * checking the existence of the ".ocdata" file. |
|
| 943 | + * |
|
| 944 | + * @param string $dataDirectory data directory path |
|
| 945 | + * @return array errors found |
|
| 946 | + */ |
|
| 947 | + public static function checkDataDirectoryValidity($dataDirectory) { |
|
| 948 | + $l = \OC::$server->getL10N('lib'); |
|
| 949 | + $errors = []; |
|
| 950 | + if ($dataDirectory[0] !== '/') { |
|
| 951 | + $errors[] = [ |
|
| 952 | + 'error' => $l->t('Your data directory must be an absolute path'), |
|
| 953 | + 'hint' => $l->t('Check the value of "datadirectory" in your configuration') |
|
| 954 | + ]; |
|
| 955 | + } |
|
| 956 | + if (!file_exists($dataDirectory . '/.ocdata')) { |
|
| 957 | + $errors[] = [ |
|
| 958 | + 'error' => $l->t('Your data directory is invalid'), |
|
| 959 | + 'hint' => $l->t('Please check that the data directory contains a file' . |
|
| 960 | + ' ".ocdata" in its root.') |
|
| 961 | + ]; |
|
| 962 | + } |
|
| 963 | + return $errors; |
|
| 964 | + } |
|
| 965 | + |
|
| 966 | + /** |
|
| 967 | + * Check if the user is logged in, redirects to home if not. With |
|
| 968 | + * redirect URL parameter to the request URI. |
|
| 969 | + * |
|
| 970 | + * @return void |
|
| 971 | + */ |
|
| 972 | + public static function checkLoggedIn() { |
|
| 973 | + // Check if we are a user |
|
| 974 | + if (!\OC::$server->getUserSession()->isLoggedIn()) { |
|
| 975 | + header('Location: ' . \OC::$server->getURLGenerator()->linkToRoute( |
|
| 976 | + 'core.login.showLoginForm', |
|
| 977 | + [ |
|
| 978 | + 'redirect_url' => \OC::$server->getRequest()->getRequestUri(), |
|
| 979 | + ] |
|
| 980 | + ) |
|
| 981 | + ); |
|
| 982 | + exit(); |
|
| 983 | + } |
|
| 984 | + // Redirect to 2FA challenge selection if 2FA challenge was not solved yet |
|
| 985 | + if (\OC::$server->getTwoFactorAuthManager()->needsSecondFactor(\OC::$server->getUserSession()->getUser())) { |
|
| 986 | + header('Location: ' . \OC::$server->getURLGenerator()->linkToRoute('core.TwoFactorChallenge.selectChallenge')); |
|
| 987 | + exit(); |
|
| 988 | + } |
|
| 989 | + } |
|
| 990 | + |
|
| 991 | + /** |
|
| 992 | + * Check if the user is a admin, redirects to home if not |
|
| 993 | + * |
|
| 994 | + * @return void |
|
| 995 | + */ |
|
| 996 | + public static function checkAdminUser() { |
|
| 997 | + OC_Util::checkLoggedIn(); |
|
| 998 | + if (!OC_User::isAdminUser(OC_User::getUser())) { |
|
| 999 | + header('Location: ' . \OCP\Util::linkToAbsolute('', 'index.php')); |
|
| 1000 | + exit(); |
|
| 1001 | + } |
|
| 1002 | + } |
|
| 1003 | + |
|
| 1004 | + /** |
|
| 1005 | + * Check if the user is a subadmin, redirects to home if not |
|
| 1006 | + * |
|
| 1007 | + * @return null|boolean $groups where the current user is subadmin |
|
| 1008 | + */ |
|
| 1009 | + public static function checkSubAdminUser() { |
|
| 1010 | + OC_Util::checkLoggedIn(); |
|
| 1011 | + $userObject = \OC::$server->getUserSession()->getUser(); |
|
| 1012 | + $isSubAdmin = false; |
|
| 1013 | + if($userObject !== null) { |
|
| 1014 | + $isSubAdmin = \OC::$server->getGroupManager()->getSubAdmin()->isSubAdmin($userObject); |
|
| 1015 | + } |
|
| 1016 | + |
|
| 1017 | + if (!$isSubAdmin) { |
|
| 1018 | + header('Location: ' . \OCP\Util::linkToAbsolute('', 'index.php')); |
|
| 1019 | + exit(); |
|
| 1020 | + } |
|
| 1021 | + return true; |
|
| 1022 | + } |
|
| 1023 | + |
|
| 1024 | + /** |
|
| 1025 | + * Returns the URL of the default page |
|
| 1026 | + * based on the system configuration and |
|
| 1027 | + * the apps visible for the current user |
|
| 1028 | + * |
|
| 1029 | + * @return string URL |
|
| 1030 | + */ |
|
| 1031 | + public static function getDefaultPageUrl() { |
|
| 1032 | + $urlGenerator = \OC::$server->getURLGenerator(); |
|
| 1033 | + // Deny the redirect if the URL contains a @ |
|
| 1034 | + // This prevents unvalidated redirects like ?redirect_url=:[email protected] |
|
| 1035 | + if (isset($_REQUEST['redirect_url']) && strpos($_REQUEST['redirect_url'], '@') === false) { |
|
| 1036 | + $location = $urlGenerator->getAbsoluteURL(urldecode($_REQUEST['redirect_url'])); |
|
| 1037 | + } else { |
|
| 1038 | + $defaultPage = \OC::$server->getAppConfig()->getValue('core', 'defaultpage'); |
|
| 1039 | + if ($defaultPage) { |
|
| 1040 | + $location = $urlGenerator->getAbsoluteURL($defaultPage); |
|
| 1041 | + } else { |
|
| 1042 | + $appId = 'files'; |
|
| 1043 | + $defaultApps = explode(',', \OCP\Config::getSystemValue('defaultapp', 'files')); |
|
| 1044 | + // find the first app that is enabled for the current user |
|
| 1045 | + foreach ($defaultApps as $defaultApp) { |
|
| 1046 | + $defaultApp = OC_App::cleanAppId(strip_tags($defaultApp)); |
|
| 1047 | + if (static::getAppManager()->isEnabledForUser($defaultApp)) { |
|
| 1048 | + $appId = $defaultApp; |
|
| 1049 | + break; |
|
| 1050 | + } |
|
| 1051 | + } |
|
| 1052 | + |
|
| 1053 | + if(\OC::$server->getConfig()->getSystemValue('htaccess.IgnoreFrontController', false) === true || getenv('front_controller_active') === 'true') { |
|
| 1054 | + $location = $urlGenerator->getAbsoluteURL('/apps/' . $appId . '/'); |
|
| 1055 | + } else { |
|
| 1056 | + $location = $urlGenerator->getAbsoluteURL('/index.php/apps/' . $appId . '/'); |
|
| 1057 | + } |
|
| 1058 | + } |
|
| 1059 | + } |
|
| 1060 | + return $location; |
|
| 1061 | + } |
|
| 1062 | + |
|
| 1063 | + /** |
|
| 1064 | + * Redirect to the user default page |
|
| 1065 | + * |
|
| 1066 | + * @return void |
|
| 1067 | + */ |
|
| 1068 | + public static function redirectToDefaultPage() { |
|
| 1069 | + $location = self::getDefaultPageUrl(); |
|
| 1070 | + header('Location: ' . $location); |
|
| 1071 | + exit(); |
|
| 1072 | + } |
|
| 1073 | + |
|
| 1074 | + /** |
|
| 1075 | + * get an id unique for this instance |
|
| 1076 | + * |
|
| 1077 | + * @return string |
|
| 1078 | + */ |
|
| 1079 | + public static function getInstanceId() { |
|
| 1080 | + $id = \OC::$server->getSystemConfig()->getValue('instanceid', null); |
|
| 1081 | + if (is_null($id)) { |
|
| 1082 | + // We need to guarantee at least one letter in instanceid so it can be used as the session_name |
|
| 1083 | + $id = 'oc' . \OC::$server->getSecureRandom()->generate(10, \OCP\Security\ISecureRandom::CHAR_LOWER.\OCP\Security\ISecureRandom::CHAR_DIGITS); |
|
| 1084 | + \OC::$server->getSystemConfig()->setValue('instanceid', $id); |
|
| 1085 | + } |
|
| 1086 | + return $id; |
|
| 1087 | + } |
|
| 1088 | + |
|
| 1089 | + /** |
|
| 1090 | + * Public function to sanitize HTML |
|
| 1091 | + * |
|
| 1092 | + * This function is used to sanitize HTML and should be applied on any |
|
| 1093 | + * string or array of strings before displaying it on a web page. |
|
| 1094 | + * |
|
| 1095 | + * @param string|array $value |
|
| 1096 | + * @return string|array an array of sanitized strings or a single sanitized string, depends on the input parameter. |
|
| 1097 | + */ |
|
| 1098 | + public static function sanitizeHTML($value) { |
|
| 1099 | + if (is_array($value)) { |
|
| 1100 | + $value = array_map(function($value) { |
|
| 1101 | + return self::sanitizeHTML($value); |
|
| 1102 | + }, $value); |
|
| 1103 | + } else { |
|
| 1104 | + // Specify encoding for PHP<5.4 |
|
| 1105 | + $value = htmlspecialchars((string)$value, ENT_QUOTES, 'UTF-8'); |
|
| 1106 | + } |
|
| 1107 | + return $value; |
|
| 1108 | + } |
|
| 1109 | + |
|
| 1110 | + /** |
|
| 1111 | + * Public function to encode url parameters |
|
| 1112 | + * |
|
| 1113 | + * This function is used to encode path to file before output. |
|
| 1114 | + * Encoding is done according to RFC 3986 with one exception: |
|
| 1115 | + * Character '/' is preserved as is. |
|
| 1116 | + * |
|
| 1117 | + * @param string $component part of URI to encode |
|
| 1118 | + * @return string |
|
| 1119 | + */ |
|
| 1120 | + public static function encodePath($component) { |
|
| 1121 | + $encoded = rawurlencode($component); |
|
| 1122 | + $encoded = str_replace('%2F', '/', $encoded); |
|
| 1123 | + return $encoded; |
|
| 1124 | + } |
|
| 1125 | + |
|
| 1126 | + |
|
| 1127 | + public function createHtaccessTestFile(\OCP\IConfig $config) { |
|
| 1128 | + // php dev server does not support htaccess |
|
| 1129 | + if (php_sapi_name() === 'cli-server') { |
|
| 1130 | + return false; |
|
| 1131 | + } |
|
| 1132 | + |
|
| 1133 | + // testdata |
|
| 1134 | + $fileName = '/htaccesstest.txt'; |
|
| 1135 | + $testContent = 'This is used for testing whether htaccess is properly enabled to disallow access from the outside. This file can be safely removed.'; |
|
| 1136 | + |
|
| 1137 | + // creating a test file |
|
| 1138 | + $testFile = $config->getSystemValue('datadirectory', OC::$SERVERROOT . '/data') . '/' . $fileName; |
|
| 1139 | + |
|
| 1140 | + if (file_exists($testFile)) {// already running this test, possible recursive call |
|
| 1141 | + return false; |
|
| 1142 | + } |
|
| 1143 | + |
|
| 1144 | + $fp = @fopen($testFile, 'w'); |
|
| 1145 | + if (!$fp) { |
|
| 1146 | + throw new OC\HintException('Can\'t create test file to check for working .htaccess file.', |
|
| 1147 | + 'Make sure it is possible for the webserver to write to ' . $testFile); |
|
| 1148 | + } |
|
| 1149 | + fwrite($fp, $testContent); |
|
| 1150 | + fclose($fp); |
|
| 1151 | + |
|
| 1152 | + return $testContent; |
|
| 1153 | + } |
|
| 1154 | + |
|
| 1155 | + /** |
|
| 1156 | + * Check if the .htaccess file is working |
|
| 1157 | + * @param \OCP\IConfig $config |
|
| 1158 | + * @return bool |
|
| 1159 | + * @throws Exception |
|
| 1160 | + * @throws \OC\HintException If the test file can't get written. |
|
| 1161 | + */ |
|
| 1162 | + public function isHtaccessWorking(\OCP\IConfig $config) { |
|
| 1163 | + |
|
| 1164 | + if (\OC::$CLI || !$config->getSystemValue('check_for_working_htaccess', true)) { |
|
| 1165 | + return true; |
|
| 1166 | + } |
|
| 1167 | + |
|
| 1168 | + $testContent = $this->createHtaccessTestFile($config); |
|
| 1169 | + if ($testContent === false) { |
|
| 1170 | + return false; |
|
| 1171 | + } |
|
| 1172 | + |
|
| 1173 | + $fileName = '/htaccesstest.txt'; |
|
| 1174 | + $testFile = $config->getSystemValue('datadirectory', OC::$SERVERROOT . '/data') . '/' . $fileName; |
|
| 1175 | + |
|
| 1176 | + // accessing the file via http |
|
| 1177 | + $url = \OC::$server->getURLGenerator()->getAbsoluteURL(OC::$WEBROOT . '/data' . $fileName); |
|
| 1178 | + try { |
|
| 1179 | + $content = \OC::$server->getHTTPClientService()->newClient()->get($url)->getBody(); |
|
| 1180 | + } catch (\Exception $e) { |
|
| 1181 | + $content = false; |
|
| 1182 | + } |
|
| 1183 | + |
|
| 1184 | + // cleanup |
|
| 1185 | + @unlink($testFile); |
|
| 1186 | + |
|
| 1187 | + /* |
|
| 1188 | 1188 | * If the content is not equal to test content our .htaccess |
| 1189 | 1189 | * is working as required |
| 1190 | 1190 | */ |
| 1191 | - return $content !== $testContent; |
|
| 1192 | - } |
|
| 1193 | - |
|
| 1194 | - /** |
|
| 1195 | - * Check if the setlocal call does not work. This can happen if the right |
|
| 1196 | - * local packages are not available on the server. |
|
| 1197 | - * |
|
| 1198 | - * @return bool |
|
| 1199 | - */ |
|
| 1200 | - public static function isSetLocaleWorking() { |
|
| 1201 | - \Patchwork\Utf8\Bootup::initLocale(); |
|
| 1202 | - if ('' === basename('§')) { |
|
| 1203 | - return false; |
|
| 1204 | - } |
|
| 1205 | - return true; |
|
| 1206 | - } |
|
| 1207 | - |
|
| 1208 | - /** |
|
| 1209 | - * Check if it's possible to get the inline annotations |
|
| 1210 | - * |
|
| 1211 | - * @return bool |
|
| 1212 | - */ |
|
| 1213 | - public static function isAnnotationsWorking() { |
|
| 1214 | - $reflection = new \ReflectionMethod(__METHOD__); |
|
| 1215 | - $docs = $reflection->getDocComment(); |
|
| 1216 | - |
|
| 1217 | - return (is_string($docs) && strlen($docs) > 50); |
|
| 1218 | - } |
|
| 1219 | - |
|
| 1220 | - /** |
|
| 1221 | - * Check if the PHP module fileinfo is loaded. |
|
| 1222 | - * |
|
| 1223 | - * @return bool |
|
| 1224 | - */ |
|
| 1225 | - public static function fileInfoLoaded() { |
|
| 1226 | - return function_exists('finfo_open'); |
|
| 1227 | - } |
|
| 1228 | - |
|
| 1229 | - /** |
|
| 1230 | - * clear all levels of output buffering |
|
| 1231 | - * |
|
| 1232 | - * @return void |
|
| 1233 | - */ |
|
| 1234 | - public static function obEnd() { |
|
| 1235 | - while (ob_get_level()) { |
|
| 1236 | - ob_end_clean(); |
|
| 1237 | - } |
|
| 1238 | - } |
|
| 1239 | - |
|
| 1240 | - /** |
|
| 1241 | - * Checks whether the server is running on Mac OS X |
|
| 1242 | - * |
|
| 1243 | - * @return bool true if running on Mac OS X, false otherwise |
|
| 1244 | - */ |
|
| 1245 | - public static function runningOnMac() { |
|
| 1246 | - return (strtoupper(substr(PHP_OS, 0, 6)) === 'DARWIN'); |
|
| 1247 | - } |
|
| 1248 | - |
|
| 1249 | - /** |
|
| 1250 | - * Checks whether server is running on HHVM |
|
| 1251 | - * |
|
| 1252 | - * @return bool True if running on HHVM, false otherwise |
|
| 1253 | - */ |
|
| 1254 | - public static function runningOnHhvm() { |
|
| 1255 | - return defined('HHVM_VERSION'); |
|
| 1256 | - } |
|
| 1257 | - |
|
| 1258 | - /** |
|
| 1259 | - * Handles the case that there may not be a theme, then check if a "default" |
|
| 1260 | - * theme exists and take that one |
|
| 1261 | - * |
|
| 1262 | - * @return string the theme |
|
| 1263 | - */ |
|
| 1264 | - public static function getTheme() { |
|
| 1265 | - $theme = \OC::$server->getSystemConfig()->getValue("theme", ''); |
|
| 1266 | - |
|
| 1267 | - if ($theme === '') { |
|
| 1268 | - if (is_dir(OC::$SERVERROOT . '/themes/default')) { |
|
| 1269 | - $theme = 'default'; |
|
| 1270 | - } |
|
| 1271 | - } |
|
| 1272 | - |
|
| 1273 | - return $theme; |
|
| 1274 | - } |
|
| 1275 | - |
|
| 1276 | - /** |
|
| 1277 | - * Clear a single file from the opcode cache |
|
| 1278 | - * This is useful for writing to the config file |
|
| 1279 | - * in case the opcode cache does not re-validate files |
|
| 1280 | - * Returns true if successful, false if unsuccessful: |
|
| 1281 | - * caller should fall back on clearing the entire cache |
|
| 1282 | - * with clearOpcodeCache() if unsuccessful |
|
| 1283 | - * |
|
| 1284 | - * @param string $path the path of the file to clear from the cache |
|
| 1285 | - * @return bool true if underlying function returns true, otherwise false |
|
| 1286 | - */ |
|
| 1287 | - public static function deleteFromOpcodeCache($path) { |
|
| 1288 | - $ret = false; |
|
| 1289 | - if ($path) { |
|
| 1290 | - // APC >= 3.1.1 |
|
| 1291 | - if (function_exists('apc_delete_file')) { |
|
| 1292 | - $ret = @apc_delete_file($path); |
|
| 1293 | - } |
|
| 1294 | - // Zend OpCache >= 7.0.0, PHP >= 5.5.0 |
|
| 1295 | - if (function_exists('opcache_invalidate')) { |
|
| 1296 | - $ret = opcache_invalidate($path); |
|
| 1297 | - } |
|
| 1298 | - } |
|
| 1299 | - return $ret; |
|
| 1300 | - } |
|
| 1301 | - |
|
| 1302 | - /** |
|
| 1303 | - * Clear the opcode cache if one exists |
|
| 1304 | - * This is necessary for writing to the config file |
|
| 1305 | - * in case the opcode cache does not re-validate files |
|
| 1306 | - * |
|
| 1307 | - * @return void |
|
| 1308 | - */ |
|
| 1309 | - public static function clearOpcodeCache() { |
|
| 1310 | - // APC |
|
| 1311 | - if (function_exists('apc_clear_cache')) { |
|
| 1312 | - apc_clear_cache(); |
|
| 1313 | - } |
|
| 1314 | - // Zend Opcache |
|
| 1315 | - if (function_exists('accelerator_reset')) { |
|
| 1316 | - accelerator_reset(); |
|
| 1317 | - } |
|
| 1318 | - // XCache |
|
| 1319 | - if (function_exists('xcache_clear_cache')) { |
|
| 1320 | - if (\OC::$server->getIniWrapper()->getBool('xcache.admin.enable_auth')) { |
|
| 1321 | - \OCP\Util::writeLog('core', 'XCache opcode cache will not be cleared because "xcache.admin.enable_auth" is enabled.', \OCP\Util::WARN); |
|
| 1322 | - } else { |
|
| 1323 | - @xcache_clear_cache(XC_TYPE_PHP, 0); |
|
| 1324 | - } |
|
| 1325 | - } |
|
| 1326 | - // Opcache (PHP >= 5.5) |
|
| 1327 | - if (function_exists('opcache_reset')) { |
|
| 1328 | - opcache_reset(); |
|
| 1329 | - } |
|
| 1330 | - } |
|
| 1331 | - |
|
| 1332 | - /** |
|
| 1333 | - * Normalize a unicode string |
|
| 1334 | - * |
|
| 1335 | - * @param string $value a not normalized string |
|
| 1336 | - * @return bool|string |
|
| 1337 | - */ |
|
| 1338 | - public static function normalizeUnicode($value) { |
|
| 1339 | - if(Normalizer::isNormalized($value)) { |
|
| 1340 | - return $value; |
|
| 1341 | - } |
|
| 1342 | - |
|
| 1343 | - $normalizedValue = Normalizer::normalize($value); |
|
| 1344 | - if ($normalizedValue === null || $normalizedValue === false) { |
|
| 1345 | - \OC::$server->getLogger()->warning('normalizing failed for "' . $value . '"', ['app' => 'core']); |
|
| 1346 | - return $value; |
|
| 1347 | - } |
|
| 1348 | - |
|
| 1349 | - return $normalizedValue; |
|
| 1350 | - } |
|
| 1351 | - |
|
| 1352 | - /** |
|
| 1353 | - * @param boolean|string $file |
|
| 1354 | - * @return string |
|
| 1355 | - */ |
|
| 1356 | - public static function basename($file) { |
|
| 1357 | - $file = rtrim($file, '/'); |
|
| 1358 | - $t = explode('/', $file); |
|
| 1359 | - return array_pop($t); |
|
| 1360 | - } |
|
| 1361 | - |
|
| 1362 | - /** |
|
| 1363 | - * A human readable string is generated based on version and build number |
|
| 1364 | - * |
|
| 1365 | - * @return string |
|
| 1366 | - */ |
|
| 1367 | - public static function getHumanVersion() { |
|
| 1368 | - $version = OC_Util::getVersionString(); |
|
| 1369 | - $build = OC_Util::getBuild(); |
|
| 1370 | - if (!empty($build) and OC_Util::getChannel() === 'daily') { |
|
| 1371 | - $version .= ' Build:' . $build; |
|
| 1372 | - } |
|
| 1373 | - return $version; |
|
| 1374 | - } |
|
| 1375 | - |
|
| 1376 | - /** |
|
| 1377 | - * Returns whether the given file name is valid |
|
| 1378 | - * |
|
| 1379 | - * @param string $file file name to check |
|
| 1380 | - * @return bool true if the file name is valid, false otherwise |
|
| 1381 | - * @deprecated use \OC\Files\View::verifyPath() |
|
| 1382 | - */ |
|
| 1383 | - public static function isValidFileName($file) { |
|
| 1384 | - $trimmed = trim($file); |
|
| 1385 | - if ($trimmed === '') { |
|
| 1386 | - return false; |
|
| 1387 | - } |
|
| 1388 | - if (\OC\Files\Filesystem::isIgnoredDir($trimmed)) { |
|
| 1389 | - return false; |
|
| 1390 | - } |
|
| 1391 | - foreach (str_split($trimmed) as $char) { |
|
| 1392 | - if (strpos(\OCP\Constants::FILENAME_INVALID_CHARS, $char) !== false) { |
|
| 1393 | - return false; |
|
| 1394 | - } |
|
| 1395 | - } |
|
| 1396 | - return true; |
|
| 1397 | - } |
|
| 1398 | - |
|
| 1399 | - /** |
|
| 1400 | - * Check whether the instance needs to perform an upgrade, |
|
| 1401 | - * either when the core version is higher or any app requires |
|
| 1402 | - * an upgrade. |
|
| 1403 | - * |
|
| 1404 | - * @param \OC\SystemConfig $config |
|
| 1405 | - * @return bool whether the core or any app needs an upgrade |
|
| 1406 | - * @throws \OC\HintException When the upgrade from the given version is not allowed |
|
| 1407 | - */ |
|
| 1408 | - public static function needUpgrade(\OC\SystemConfig $config) { |
|
| 1409 | - if ($config->getValue('installed', false)) { |
|
| 1410 | - $installedVersion = $config->getValue('version', '0.0.0'); |
|
| 1411 | - $currentVersion = implode('.', \OCP\Util::getVersion()); |
|
| 1412 | - $versionDiff = version_compare($currentVersion, $installedVersion); |
|
| 1413 | - if ($versionDiff > 0) { |
|
| 1414 | - return true; |
|
| 1415 | - } else if ($config->getValue('debug', false) && $versionDiff < 0) { |
|
| 1416 | - // downgrade with debug |
|
| 1417 | - $installedMajor = explode('.', $installedVersion); |
|
| 1418 | - $installedMajor = $installedMajor[0] . '.' . $installedMajor[1]; |
|
| 1419 | - $currentMajor = explode('.', $currentVersion); |
|
| 1420 | - $currentMajor = $currentMajor[0] . '.' . $currentMajor[1]; |
|
| 1421 | - if ($installedMajor === $currentMajor) { |
|
| 1422 | - // Same major, allow downgrade for developers |
|
| 1423 | - return true; |
|
| 1424 | - } else { |
|
| 1425 | - // downgrade attempt, throw exception |
|
| 1426 | - throw new \OC\HintException('Downgrading is not supported and is likely to cause unpredictable issues (from ' . $installedVersion . ' to ' . $currentVersion . ')'); |
|
| 1427 | - } |
|
| 1428 | - } else if ($versionDiff < 0) { |
|
| 1429 | - // downgrade attempt, throw exception |
|
| 1430 | - throw new \OC\HintException('Downgrading is not supported and is likely to cause unpredictable issues (from ' . $installedVersion . ' to ' . $currentVersion . ')'); |
|
| 1431 | - } |
|
| 1432 | - |
|
| 1433 | - // also check for upgrades for apps (independently from the user) |
|
| 1434 | - $apps = \OC_App::getEnabledApps(false, true); |
|
| 1435 | - $shouldUpgrade = false; |
|
| 1436 | - foreach ($apps as $app) { |
|
| 1437 | - if (\OC_App::shouldUpgrade($app)) { |
|
| 1438 | - $shouldUpgrade = true; |
|
| 1439 | - break; |
|
| 1440 | - } |
|
| 1441 | - } |
|
| 1442 | - return $shouldUpgrade; |
|
| 1443 | - } else { |
|
| 1444 | - return false; |
|
| 1445 | - } |
|
| 1446 | - } |
|
| 1191 | + return $content !== $testContent; |
|
| 1192 | + } |
|
| 1193 | + |
|
| 1194 | + /** |
|
| 1195 | + * Check if the setlocal call does not work. This can happen if the right |
|
| 1196 | + * local packages are not available on the server. |
|
| 1197 | + * |
|
| 1198 | + * @return bool |
|
| 1199 | + */ |
|
| 1200 | + public static function isSetLocaleWorking() { |
|
| 1201 | + \Patchwork\Utf8\Bootup::initLocale(); |
|
| 1202 | + if ('' === basename('§')) { |
|
| 1203 | + return false; |
|
| 1204 | + } |
|
| 1205 | + return true; |
|
| 1206 | + } |
|
| 1207 | + |
|
| 1208 | + /** |
|
| 1209 | + * Check if it's possible to get the inline annotations |
|
| 1210 | + * |
|
| 1211 | + * @return bool |
|
| 1212 | + */ |
|
| 1213 | + public static function isAnnotationsWorking() { |
|
| 1214 | + $reflection = new \ReflectionMethod(__METHOD__); |
|
| 1215 | + $docs = $reflection->getDocComment(); |
|
| 1216 | + |
|
| 1217 | + return (is_string($docs) && strlen($docs) > 50); |
|
| 1218 | + } |
|
| 1219 | + |
|
| 1220 | + /** |
|
| 1221 | + * Check if the PHP module fileinfo is loaded. |
|
| 1222 | + * |
|
| 1223 | + * @return bool |
|
| 1224 | + */ |
|
| 1225 | + public static function fileInfoLoaded() { |
|
| 1226 | + return function_exists('finfo_open'); |
|
| 1227 | + } |
|
| 1228 | + |
|
| 1229 | + /** |
|
| 1230 | + * clear all levels of output buffering |
|
| 1231 | + * |
|
| 1232 | + * @return void |
|
| 1233 | + */ |
|
| 1234 | + public static function obEnd() { |
|
| 1235 | + while (ob_get_level()) { |
|
| 1236 | + ob_end_clean(); |
|
| 1237 | + } |
|
| 1238 | + } |
|
| 1239 | + |
|
| 1240 | + /** |
|
| 1241 | + * Checks whether the server is running on Mac OS X |
|
| 1242 | + * |
|
| 1243 | + * @return bool true if running on Mac OS X, false otherwise |
|
| 1244 | + */ |
|
| 1245 | + public static function runningOnMac() { |
|
| 1246 | + return (strtoupper(substr(PHP_OS, 0, 6)) === 'DARWIN'); |
|
| 1247 | + } |
|
| 1248 | + |
|
| 1249 | + /** |
|
| 1250 | + * Checks whether server is running on HHVM |
|
| 1251 | + * |
|
| 1252 | + * @return bool True if running on HHVM, false otherwise |
|
| 1253 | + */ |
|
| 1254 | + public static function runningOnHhvm() { |
|
| 1255 | + return defined('HHVM_VERSION'); |
|
| 1256 | + } |
|
| 1257 | + |
|
| 1258 | + /** |
|
| 1259 | + * Handles the case that there may not be a theme, then check if a "default" |
|
| 1260 | + * theme exists and take that one |
|
| 1261 | + * |
|
| 1262 | + * @return string the theme |
|
| 1263 | + */ |
|
| 1264 | + public static function getTheme() { |
|
| 1265 | + $theme = \OC::$server->getSystemConfig()->getValue("theme", ''); |
|
| 1266 | + |
|
| 1267 | + if ($theme === '') { |
|
| 1268 | + if (is_dir(OC::$SERVERROOT . '/themes/default')) { |
|
| 1269 | + $theme = 'default'; |
|
| 1270 | + } |
|
| 1271 | + } |
|
| 1272 | + |
|
| 1273 | + return $theme; |
|
| 1274 | + } |
|
| 1275 | + |
|
| 1276 | + /** |
|
| 1277 | + * Clear a single file from the opcode cache |
|
| 1278 | + * This is useful for writing to the config file |
|
| 1279 | + * in case the opcode cache does not re-validate files |
|
| 1280 | + * Returns true if successful, false if unsuccessful: |
|
| 1281 | + * caller should fall back on clearing the entire cache |
|
| 1282 | + * with clearOpcodeCache() if unsuccessful |
|
| 1283 | + * |
|
| 1284 | + * @param string $path the path of the file to clear from the cache |
|
| 1285 | + * @return bool true if underlying function returns true, otherwise false |
|
| 1286 | + */ |
|
| 1287 | + public static function deleteFromOpcodeCache($path) { |
|
| 1288 | + $ret = false; |
|
| 1289 | + if ($path) { |
|
| 1290 | + // APC >= 3.1.1 |
|
| 1291 | + if (function_exists('apc_delete_file')) { |
|
| 1292 | + $ret = @apc_delete_file($path); |
|
| 1293 | + } |
|
| 1294 | + // Zend OpCache >= 7.0.0, PHP >= 5.5.0 |
|
| 1295 | + if (function_exists('opcache_invalidate')) { |
|
| 1296 | + $ret = opcache_invalidate($path); |
|
| 1297 | + } |
|
| 1298 | + } |
|
| 1299 | + return $ret; |
|
| 1300 | + } |
|
| 1301 | + |
|
| 1302 | + /** |
|
| 1303 | + * Clear the opcode cache if one exists |
|
| 1304 | + * This is necessary for writing to the config file |
|
| 1305 | + * in case the opcode cache does not re-validate files |
|
| 1306 | + * |
|
| 1307 | + * @return void |
|
| 1308 | + */ |
|
| 1309 | + public static function clearOpcodeCache() { |
|
| 1310 | + // APC |
|
| 1311 | + if (function_exists('apc_clear_cache')) { |
|
| 1312 | + apc_clear_cache(); |
|
| 1313 | + } |
|
| 1314 | + // Zend Opcache |
|
| 1315 | + if (function_exists('accelerator_reset')) { |
|
| 1316 | + accelerator_reset(); |
|
| 1317 | + } |
|
| 1318 | + // XCache |
|
| 1319 | + if (function_exists('xcache_clear_cache')) { |
|
| 1320 | + if (\OC::$server->getIniWrapper()->getBool('xcache.admin.enable_auth')) { |
|
| 1321 | + \OCP\Util::writeLog('core', 'XCache opcode cache will not be cleared because "xcache.admin.enable_auth" is enabled.', \OCP\Util::WARN); |
|
| 1322 | + } else { |
|
| 1323 | + @xcache_clear_cache(XC_TYPE_PHP, 0); |
|
| 1324 | + } |
|
| 1325 | + } |
|
| 1326 | + // Opcache (PHP >= 5.5) |
|
| 1327 | + if (function_exists('opcache_reset')) { |
|
| 1328 | + opcache_reset(); |
|
| 1329 | + } |
|
| 1330 | + } |
|
| 1331 | + |
|
| 1332 | + /** |
|
| 1333 | + * Normalize a unicode string |
|
| 1334 | + * |
|
| 1335 | + * @param string $value a not normalized string |
|
| 1336 | + * @return bool|string |
|
| 1337 | + */ |
|
| 1338 | + public static function normalizeUnicode($value) { |
|
| 1339 | + if(Normalizer::isNormalized($value)) { |
|
| 1340 | + return $value; |
|
| 1341 | + } |
|
| 1342 | + |
|
| 1343 | + $normalizedValue = Normalizer::normalize($value); |
|
| 1344 | + if ($normalizedValue === null || $normalizedValue === false) { |
|
| 1345 | + \OC::$server->getLogger()->warning('normalizing failed for "' . $value . '"', ['app' => 'core']); |
|
| 1346 | + return $value; |
|
| 1347 | + } |
|
| 1348 | + |
|
| 1349 | + return $normalizedValue; |
|
| 1350 | + } |
|
| 1351 | + |
|
| 1352 | + /** |
|
| 1353 | + * @param boolean|string $file |
|
| 1354 | + * @return string |
|
| 1355 | + */ |
|
| 1356 | + public static function basename($file) { |
|
| 1357 | + $file = rtrim($file, '/'); |
|
| 1358 | + $t = explode('/', $file); |
|
| 1359 | + return array_pop($t); |
|
| 1360 | + } |
|
| 1361 | + |
|
| 1362 | + /** |
|
| 1363 | + * A human readable string is generated based on version and build number |
|
| 1364 | + * |
|
| 1365 | + * @return string |
|
| 1366 | + */ |
|
| 1367 | + public static function getHumanVersion() { |
|
| 1368 | + $version = OC_Util::getVersionString(); |
|
| 1369 | + $build = OC_Util::getBuild(); |
|
| 1370 | + if (!empty($build) and OC_Util::getChannel() === 'daily') { |
|
| 1371 | + $version .= ' Build:' . $build; |
|
| 1372 | + } |
|
| 1373 | + return $version; |
|
| 1374 | + } |
|
| 1375 | + |
|
| 1376 | + /** |
|
| 1377 | + * Returns whether the given file name is valid |
|
| 1378 | + * |
|
| 1379 | + * @param string $file file name to check |
|
| 1380 | + * @return bool true if the file name is valid, false otherwise |
|
| 1381 | + * @deprecated use \OC\Files\View::verifyPath() |
|
| 1382 | + */ |
|
| 1383 | + public static function isValidFileName($file) { |
|
| 1384 | + $trimmed = trim($file); |
|
| 1385 | + if ($trimmed === '') { |
|
| 1386 | + return false; |
|
| 1387 | + } |
|
| 1388 | + if (\OC\Files\Filesystem::isIgnoredDir($trimmed)) { |
|
| 1389 | + return false; |
|
| 1390 | + } |
|
| 1391 | + foreach (str_split($trimmed) as $char) { |
|
| 1392 | + if (strpos(\OCP\Constants::FILENAME_INVALID_CHARS, $char) !== false) { |
|
| 1393 | + return false; |
|
| 1394 | + } |
|
| 1395 | + } |
|
| 1396 | + return true; |
|
| 1397 | + } |
|
| 1398 | + |
|
| 1399 | + /** |
|
| 1400 | + * Check whether the instance needs to perform an upgrade, |
|
| 1401 | + * either when the core version is higher or any app requires |
|
| 1402 | + * an upgrade. |
|
| 1403 | + * |
|
| 1404 | + * @param \OC\SystemConfig $config |
|
| 1405 | + * @return bool whether the core or any app needs an upgrade |
|
| 1406 | + * @throws \OC\HintException When the upgrade from the given version is not allowed |
|
| 1407 | + */ |
|
| 1408 | + public static function needUpgrade(\OC\SystemConfig $config) { |
|
| 1409 | + if ($config->getValue('installed', false)) { |
|
| 1410 | + $installedVersion = $config->getValue('version', '0.0.0'); |
|
| 1411 | + $currentVersion = implode('.', \OCP\Util::getVersion()); |
|
| 1412 | + $versionDiff = version_compare($currentVersion, $installedVersion); |
|
| 1413 | + if ($versionDiff > 0) { |
|
| 1414 | + return true; |
|
| 1415 | + } else if ($config->getValue('debug', false) && $versionDiff < 0) { |
|
| 1416 | + // downgrade with debug |
|
| 1417 | + $installedMajor = explode('.', $installedVersion); |
|
| 1418 | + $installedMajor = $installedMajor[0] . '.' . $installedMajor[1]; |
|
| 1419 | + $currentMajor = explode('.', $currentVersion); |
|
| 1420 | + $currentMajor = $currentMajor[0] . '.' . $currentMajor[1]; |
|
| 1421 | + if ($installedMajor === $currentMajor) { |
|
| 1422 | + // Same major, allow downgrade for developers |
|
| 1423 | + return true; |
|
| 1424 | + } else { |
|
| 1425 | + // downgrade attempt, throw exception |
|
| 1426 | + throw new \OC\HintException('Downgrading is not supported and is likely to cause unpredictable issues (from ' . $installedVersion . ' to ' . $currentVersion . ')'); |
|
| 1427 | + } |
|
| 1428 | + } else if ($versionDiff < 0) { |
|
| 1429 | + // downgrade attempt, throw exception |
|
| 1430 | + throw new \OC\HintException('Downgrading is not supported and is likely to cause unpredictable issues (from ' . $installedVersion . ' to ' . $currentVersion . ')'); |
|
| 1431 | + } |
|
| 1432 | + |
|
| 1433 | + // also check for upgrades for apps (independently from the user) |
|
| 1434 | + $apps = \OC_App::getEnabledApps(false, true); |
|
| 1435 | + $shouldUpgrade = false; |
|
| 1436 | + foreach ($apps as $app) { |
|
| 1437 | + if (\OC_App::shouldUpgrade($app)) { |
|
| 1438 | + $shouldUpgrade = true; |
|
| 1439 | + break; |
|
| 1440 | + } |
|
| 1441 | + } |
|
| 1442 | + return $shouldUpgrade; |
|
| 1443 | + } else { |
|
| 1444 | + return false; |
|
| 1445 | + } |
|
| 1446 | + } |
|
| 1447 | 1447 | |
| 1448 | 1448 | } |
@@ -76,7 +76,7 @@ discard block |
||
| 76 | 76 | |
| 77 | 77 | private static function initLocalStorageRootFS() { |
| 78 | 78 | // mount local file backend as root |
| 79 | - $configDataDirectory = \OC::$server->getSystemConfig()->getValue("datadirectory", OC::$SERVERROOT . "/data"); |
|
| 79 | + $configDataDirectory = \OC::$server->getSystemConfig()->getValue("datadirectory", OC::$SERVERROOT."/data"); |
|
| 80 | 80 | //first set up the local "root" storage |
| 81 | 81 | \OC\Files\Filesystem::initMountManager(); |
| 82 | 82 | if (!self::$rootMounted) { |
@@ -154,7 +154,7 @@ discard block |
||
| 154 | 154 | \OC\Files\Filesystem::initMountManager(); |
| 155 | 155 | |
| 156 | 156 | \OC\Files\Filesystem::logWarningWhenAddingStorageWrapper(false); |
| 157 | - \OC\Files\Filesystem::addStorageWrapper('mount_options', function ($mountPoint, \OCP\Files\Storage $storage, \OCP\Files\Mount\IMountPoint $mount) { |
|
| 157 | + \OC\Files\Filesystem::addStorageWrapper('mount_options', function($mountPoint, \OCP\Files\Storage $storage, \OCP\Files\Mount\IMountPoint $mount) { |
|
| 158 | 158 | if ($storage->instanceOfStorage('\OC\Files\Storage\Common')) { |
| 159 | 159 | /** @var \OC\Files\Storage\Common $storage */ |
| 160 | 160 | $storage->setMountOptions($mount->getOptions()); |
@@ -162,7 +162,7 @@ discard block |
||
| 162 | 162 | return $storage; |
| 163 | 163 | }); |
| 164 | 164 | |
| 165 | - \OC\Files\Filesystem::addStorageWrapper('enable_sharing', function ($mountPoint, \OCP\Files\Storage $storage, \OCP\Files\Mount\IMountPoint $mount) { |
|
| 165 | + \OC\Files\Filesystem::addStorageWrapper('enable_sharing', function($mountPoint, \OCP\Files\Storage $storage, \OCP\Files\Mount\IMountPoint $mount) { |
|
| 166 | 166 | if (!$mount->getOption('enable_sharing', true)) { |
| 167 | 167 | return new \OC\Files\Storage\Wrapper\PermissionsMask([ |
| 168 | 168 | 'storage' => $storage, |
@@ -173,21 +173,21 @@ discard block |
||
| 173 | 173 | }); |
| 174 | 174 | |
| 175 | 175 | // install storage availability wrapper, before most other wrappers |
| 176 | - \OC\Files\Filesystem::addStorageWrapper('oc_availability', function ($mountPoint, $storage) { |
|
| 176 | + \OC\Files\Filesystem::addStorageWrapper('oc_availability', function($mountPoint, $storage) { |
|
| 177 | 177 | if (!$storage->instanceOfStorage('\OCA\Files_Sharing\SharedStorage') && !$storage->isLocal()) { |
| 178 | 178 | return new \OC\Files\Storage\Wrapper\Availability(['storage' => $storage]); |
| 179 | 179 | } |
| 180 | 180 | return $storage; |
| 181 | 181 | }); |
| 182 | 182 | |
| 183 | - \OC\Files\Filesystem::addStorageWrapper('oc_encoding', function ($mountPoint, \OCP\Files\Storage $storage, \OCP\Files\Mount\IMountPoint $mount) { |
|
| 183 | + \OC\Files\Filesystem::addStorageWrapper('oc_encoding', function($mountPoint, \OCP\Files\Storage $storage, \OCP\Files\Mount\IMountPoint $mount) { |
|
| 184 | 184 | if ($mount->getOption('encoding_compatibility', false) && !$storage->instanceOfStorage('\OCA\Files_Sharing\SharedStorage') && !$storage->isLocal()) { |
| 185 | 185 | return new \OC\Files\Storage\Wrapper\Encoding(['storage' => $storage]); |
| 186 | 186 | } |
| 187 | 187 | return $storage; |
| 188 | 188 | }); |
| 189 | 189 | |
| 190 | - \OC\Files\Filesystem::addStorageWrapper('oc_quota', function ($mountPoint, $storage) { |
|
| 190 | + \OC\Files\Filesystem::addStorageWrapper('oc_quota', function($mountPoint, $storage) { |
|
| 191 | 191 | // set up quota for home storages, even for other users |
| 192 | 192 | // which can happen when using sharing |
| 193 | 193 | |
@@ -229,7 +229,7 @@ discard block |
||
| 229 | 229 | //if we aren't logged in, there is no use to set up the filesystem |
| 230 | 230 | if ($user != "") { |
| 231 | 231 | |
| 232 | - $userDir = '/' . $user . '/files'; |
|
| 232 | + $userDir = '/'.$user.'/files'; |
|
| 233 | 233 | |
| 234 | 234 | //jail the user into his "home" directory |
| 235 | 235 | \OC\Files\Filesystem::init($user, $userDir); |
@@ -308,7 +308,7 @@ discard block |
||
| 308 | 308 | return \OCP\Files\FileInfo::SPACE_UNLIMITED; |
| 309 | 309 | } |
| 310 | 310 | $userQuota = $user->getQuota(); |
| 311 | - if($userQuota === 'none') { |
|
| 311 | + if ($userQuota === 'none') { |
|
| 312 | 312 | return \OCP\Files\FileInfo::SPACE_UNLIMITED; |
| 313 | 313 | } |
| 314 | 314 | return OC_Helper::computerFileSize($userQuota); |
@@ -323,15 +323,15 @@ discard block |
||
| 323 | 323 | */ |
| 324 | 324 | public static function copySkeleton($userId, \OCP\Files\Folder $userDirectory) { |
| 325 | 325 | |
| 326 | - $skeletonDirectory = \OC::$server->getConfig()->getSystemValue('skeletondirectory', \OC::$SERVERROOT . '/core/skeleton'); |
|
| 326 | + $skeletonDirectory = \OC::$server->getConfig()->getSystemValue('skeletondirectory', \OC::$SERVERROOT.'/core/skeleton'); |
|
| 327 | 327 | $instanceId = \OC::$server->getConfig()->getSystemValue('instanceid', ''); |
| 328 | 328 | |
| 329 | 329 | if ($instanceId === null) { |
| 330 | 330 | throw new \RuntimeException('no instance id!'); |
| 331 | 331 | } |
| 332 | - $appdata = 'appdata_' . $instanceId; |
|
| 332 | + $appdata = 'appdata_'.$instanceId; |
|
| 333 | 333 | if ($userId === $appdata) { |
| 334 | - throw new \RuntimeException('username is reserved name: ' . $appdata); |
|
| 334 | + throw new \RuntimeException('username is reserved name: '.$appdata); |
|
| 335 | 335 | } |
| 336 | 336 | |
| 337 | 337 | if (!empty($skeletonDirectory)) { |
@@ -358,7 +358,7 @@ discard block |
||
| 358 | 358 | |
| 359 | 359 | // Verify if folder exists |
| 360 | 360 | $dir = opendir($source); |
| 361 | - if($dir === false) { |
|
| 361 | + if ($dir === false) { |
|
| 362 | 362 | $logger->error(sprintf('Could not opendir "%s"', $source), ['app' => 'core']); |
| 363 | 363 | return; |
| 364 | 364 | } |
@@ -366,14 +366,14 @@ discard block |
||
| 366 | 366 | // Copy the files |
| 367 | 367 | while (false !== ($file = readdir($dir))) { |
| 368 | 368 | if (!\OC\Files\Filesystem::isIgnoredDir($file)) { |
| 369 | - if (is_dir($source . '/' . $file)) { |
|
| 369 | + if (is_dir($source.'/'.$file)) { |
|
| 370 | 370 | $child = $target->newFolder($file); |
| 371 | - self::copyr($source . '/' . $file, $child); |
|
| 371 | + self::copyr($source.'/'.$file, $child); |
|
| 372 | 372 | } else { |
| 373 | 373 | $child = $target->newFile($file); |
| 374 | - $sourceStream = fopen($source . '/' . $file, 'r'); |
|
| 375 | - if($sourceStream === false) { |
|
| 376 | - $logger->error(sprintf('Could not fopen "%s"', $source . '/' . $file), ['app' => 'core']); |
|
| 374 | + $sourceStream = fopen($source.'/'.$file, 'r'); |
|
| 375 | + if ($sourceStream === false) { |
|
| 376 | + $logger->error(sprintf('Could not fopen "%s"', $source.'/'.$file), ['app' => 'core']); |
|
| 377 | 377 | closedir($dir); |
| 378 | 378 | return; |
| 379 | 379 | } |
@@ -448,8 +448,8 @@ discard block |
||
| 448 | 448 | return; |
| 449 | 449 | } |
| 450 | 450 | |
| 451 | - $timestamp = filemtime(OC::$SERVERROOT . '/version.php'); |
|
| 452 | - require OC::$SERVERROOT . '/version.php'; |
|
| 451 | + $timestamp = filemtime(OC::$SERVERROOT.'/version.php'); |
|
| 452 | + require OC::$SERVERROOT.'/version.php'; |
|
| 453 | 453 | /** @var $timestamp int */ |
| 454 | 454 | self::$versionCache['OC_Version_Timestamp'] = $timestamp; |
| 455 | 455 | /** @var $OC_Version string */ |
@@ -496,7 +496,7 @@ discard block |
||
| 496 | 496 | |
| 497 | 497 | // core js files need separate handling |
| 498 | 498 | if ($application !== 'core' && $file !== null) { |
| 499 | - self::addTranslations ( $application ); |
|
| 499 | + self::addTranslations($application); |
|
| 500 | 500 | } |
| 501 | 501 | self::addExternalResource($application, $prepend, $path, "script"); |
| 502 | 502 | } |
@@ -573,7 +573,7 @@ discard block |
||
| 573 | 573 | if ($type === "style") { |
| 574 | 574 | if (!in_array($path, self::$styles)) { |
| 575 | 575 | if ($prepend === true) { |
| 576 | - array_unshift ( self::$styles, $path ); |
|
| 576 | + array_unshift(self::$styles, $path); |
|
| 577 | 577 | } else { |
| 578 | 578 | self::$styles[] = $path; |
| 579 | 579 | } |
@@ -581,7 +581,7 @@ discard block |
||
| 581 | 581 | } elseif ($type === "script") { |
| 582 | 582 | if (!in_array($path, self::$scripts)) { |
| 583 | 583 | if ($prepend === true) { |
| 584 | - array_unshift ( self::$scripts, $path ); |
|
| 584 | + array_unshift(self::$scripts, $path); |
|
| 585 | 585 | } else { |
| 586 | 586 | self::$scripts [] = $path; |
| 587 | 587 | } |
@@ -597,7 +597,7 @@ discard block |
||
| 597 | 597 | * @param array $attributes array of attributes for the element |
| 598 | 598 | * @param string $text the text content for the element |
| 599 | 599 | */ |
| 600 | - public static function addHeader($tag, $attributes, $text=null) { |
|
| 600 | + public static function addHeader($tag, $attributes, $text = null) { |
|
| 601 | 601 | self::$headers[] = array( |
| 602 | 602 | 'tag' => $tag, |
| 603 | 603 | 'attributes' => $attributes, |
@@ -637,7 +637,7 @@ discard block |
||
| 637 | 637 | public static function checkServer(\OC\SystemConfig $config) { |
| 638 | 638 | $l = \OC::$server->getL10N('lib'); |
| 639 | 639 | $errors = array(); |
| 640 | - $CONFIG_DATADIRECTORY = $config->getValue('datadirectory', OC::$SERVERROOT . '/data'); |
|
| 640 | + $CONFIG_DATADIRECTORY = $config->getValue('datadirectory', OC::$SERVERROOT.'/data'); |
|
| 641 | 641 | |
| 642 | 642 | if (!self::needUpgrade($config) && $config->getValue('installed', false)) { |
| 643 | 643 | // this check needs to be done every time |
@@ -665,13 +665,13 @@ discard block |
||
| 665 | 665 | } |
| 666 | 666 | |
| 667 | 667 | // Check if config folder is writable. |
| 668 | - if(!OC_Helper::isReadOnlyConfigEnabled()) { |
|
| 668 | + if (!OC_Helper::isReadOnlyConfigEnabled()) { |
|
| 669 | 669 | if (!is_writable(OC::$configDir) or !is_readable(OC::$configDir)) { |
| 670 | 670 | $errors[] = array( |
| 671 | 671 | 'error' => $l->t('Cannot write into "config" directory'), |
| 672 | 672 | 'hint' => $l->t('This can usually be fixed by ' |
| 673 | 673 | . '%sgiving the webserver write access to the config directory%s.', |
| 674 | - array('<a href="' . $urlGenerator->linkToDocs('admin-dir_permissions') . '" target="_blank" rel="noreferrer">', '</a>')) |
|
| 674 | + array('<a href="'.$urlGenerator->linkToDocs('admin-dir_permissions').'" target="_blank" rel="noreferrer">', '</a>')) |
|
| 675 | 675 | ); |
| 676 | 676 | } |
| 677 | 677 | } |
@@ -687,7 +687,7 @@ discard block |
||
| 687 | 687 | 'hint' => $l->t('This can usually be fixed by ' |
| 688 | 688 | . '%sgiving the webserver write access to the apps directory%s' |
| 689 | 689 | . ' or disabling the appstore in the config file.', |
| 690 | - array('<a href="' . $urlGenerator->linkToDocs('admin-dir_permissions') . '" target="_blank" rel="noreferrer">', '</a>')) |
|
| 690 | + array('<a href="'.$urlGenerator->linkToDocs('admin-dir_permissions').'" target="_blank" rel="noreferrer">', '</a>')) |
|
| 691 | 691 | ); |
| 692 | 692 | } |
| 693 | 693 | } |
@@ -709,7 +709,7 @@ discard block |
||
| 709 | 709 | //common hint for all file permissions error messages |
| 710 | 710 | $permissionsHint = $l->t('Permissions can usually be fixed by ' |
| 711 | 711 | . '%sgiving the webserver write access to the root directory%s.', |
| 712 | - ['<a href="' . $urlGenerator->linkToDocs('admin-dir_permissions') . '" target="_blank" rel="noreferrer">', '</a>']); |
|
| 712 | + ['<a href="'.$urlGenerator->linkToDocs('admin-dir_permissions').'" target="_blank" rel="noreferrer">', '</a>']); |
|
| 713 | 713 | $errors[] = [ |
| 714 | 714 | 'error' => 'Your data directory is not writable', |
| 715 | 715 | 'hint' => $permissionsHint |
@@ -809,15 +809,15 @@ discard block |
||
| 809 | 809 | } |
| 810 | 810 | } |
| 811 | 811 | |
| 812 | - foreach($missingDependencies as $missingDependency) { |
|
| 812 | + foreach ($missingDependencies as $missingDependency) { |
|
| 813 | 813 | $errors[] = array( |
| 814 | 814 | 'error' => $l->t('PHP module %s not installed.', array($missingDependency)), |
| 815 | 815 | 'hint' => $moduleHint |
| 816 | 816 | ); |
| 817 | 817 | $webServerRestart = true; |
| 818 | 818 | } |
| 819 | - foreach($invalidIniSettings as $setting) { |
|
| 820 | - if(is_bool($setting[1])) { |
|
| 819 | + foreach ($invalidIniSettings as $setting) { |
|
| 820 | + if (is_bool($setting[1])) { |
|
| 821 | 821 | $setting[1] = ($setting[1]) ? 'on' : 'off'; |
| 822 | 822 | } |
| 823 | 823 | $errors[] = [ |
@@ -835,7 +835,7 @@ discard block |
||
| 835 | 835 | * TODO: Should probably be implemented in the above generic dependency |
| 836 | 836 | * check somehow in the long-term. |
| 837 | 837 | */ |
| 838 | - if($iniWrapper->getBool('mbstring.func_overload') !== null && |
|
| 838 | + if ($iniWrapper->getBool('mbstring.func_overload') !== null && |
|
| 839 | 839 | $iniWrapper->getBool('mbstring.func_overload') === true) { |
| 840 | 840 | $errors[] = array( |
| 841 | 841 | 'error' => $l->t('mbstring.func_overload is set to "%s" instead of the expected value "0"', [$iniWrapper->getString('mbstring.func_overload')]), |
@@ -843,16 +843,16 @@ discard block |
||
| 843 | 843 | ); |
| 844 | 844 | } |
| 845 | 845 | |
| 846 | - if(function_exists('xml_parser_create') && |
|
| 847 | - LIBXML_LOADED_VERSION < 20700 ) { |
|
| 846 | + if (function_exists('xml_parser_create') && |
|
| 847 | + LIBXML_LOADED_VERSION < 20700) { |
|
| 848 | 848 | $version = LIBXML_LOADED_VERSION; |
| 849 | - $major = floor($version/10000); |
|
| 849 | + $major = floor($version / 10000); |
|
| 850 | 850 | $version -= ($major * 10000); |
| 851 | - $minor = floor($version/100); |
|
| 851 | + $minor = floor($version / 100); |
|
| 852 | 852 | $version -= ($minor * 100); |
| 853 | 853 | $patch = $version; |
| 854 | 854 | $errors[] = array( |
| 855 | - 'error' => $l->t('libxml2 2.7.0 is at least required. Currently %s is installed.', [$major . '.' . $minor . '.' . $patch]), |
|
| 855 | + 'error' => $l->t('libxml2 2.7.0 is at least required. Currently %s is installed.', [$major.'.'.$minor.'.'.$patch]), |
|
| 856 | 856 | 'hint' => $l->t('To fix this issue update your libxml2 version and restart your web server.') |
| 857 | 857 | ); |
| 858 | 858 | } |
@@ -953,10 +953,10 @@ discard block |
||
| 953 | 953 | 'hint' => $l->t('Check the value of "datadirectory" in your configuration') |
| 954 | 954 | ]; |
| 955 | 955 | } |
| 956 | - if (!file_exists($dataDirectory . '/.ocdata')) { |
|
| 956 | + if (!file_exists($dataDirectory.'/.ocdata')) { |
|
| 957 | 957 | $errors[] = [ |
| 958 | 958 | 'error' => $l->t('Your data directory is invalid'), |
| 959 | - 'hint' => $l->t('Please check that the data directory contains a file' . |
|
| 959 | + 'hint' => $l->t('Please check that the data directory contains a file'. |
|
| 960 | 960 | ' ".ocdata" in its root.') |
| 961 | 961 | ]; |
| 962 | 962 | } |
@@ -972,7 +972,7 @@ discard block |
||
| 972 | 972 | public static function checkLoggedIn() { |
| 973 | 973 | // Check if we are a user |
| 974 | 974 | if (!\OC::$server->getUserSession()->isLoggedIn()) { |
| 975 | - header('Location: ' . \OC::$server->getURLGenerator()->linkToRoute( |
|
| 975 | + header('Location: '.\OC::$server->getURLGenerator()->linkToRoute( |
|
| 976 | 976 | 'core.login.showLoginForm', |
| 977 | 977 | [ |
| 978 | 978 | 'redirect_url' => \OC::$server->getRequest()->getRequestUri(), |
@@ -983,7 +983,7 @@ discard block |
||
| 983 | 983 | } |
| 984 | 984 | // Redirect to 2FA challenge selection if 2FA challenge was not solved yet |
| 985 | 985 | if (\OC::$server->getTwoFactorAuthManager()->needsSecondFactor(\OC::$server->getUserSession()->getUser())) { |
| 986 | - header('Location: ' . \OC::$server->getURLGenerator()->linkToRoute('core.TwoFactorChallenge.selectChallenge')); |
|
| 986 | + header('Location: '.\OC::$server->getURLGenerator()->linkToRoute('core.TwoFactorChallenge.selectChallenge')); |
|
| 987 | 987 | exit(); |
| 988 | 988 | } |
| 989 | 989 | } |
@@ -996,7 +996,7 @@ discard block |
||
| 996 | 996 | public static function checkAdminUser() { |
| 997 | 997 | OC_Util::checkLoggedIn(); |
| 998 | 998 | if (!OC_User::isAdminUser(OC_User::getUser())) { |
| 999 | - header('Location: ' . \OCP\Util::linkToAbsolute('', 'index.php')); |
|
| 999 | + header('Location: '.\OCP\Util::linkToAbsolute('', 'index.php')); |
|
| 1000 | 1000 | exit(); |
| 1001 | 1001 | } |
| 1002 | 1002 | } |
@@ -1010,12 +1010,12 @@ discard block |
||
| 1010 | 1010 | OC_Util::checkLoggedIn(); |
| 1011 | 1011 | $userObject = \OC::$server->getUserSession()->getUser(); |
| 1012 | 1012 | $isSubAdmin = false; |
| 1013 | - if($userObject !== null) { |
|
| 1013 | + if ($userObject !== null) { |
|
| 1014 | 1014 | $isSubAdmin = \OC::$server->getGroupManager()->getSubAdmin()->isSubAdmin($userObject); |
| 1015 | 1015 | } |
| 1016 | 1016 | |
| 1017 | 1017 | if (!$isSubAdmin) { |
| 1018 | - header('Location: ' . \OCP\Util::linkToAbsolute('', 'index.php')); |
|
| 1018 | + header('Location: '.\OCP\Util::linkToAbsolute('', 'index.php')); |
|
| 1019 | 1019 | exit(); |
| 1020 | 1020 | } |
| 1021 | 1021 | return true; |
@@ -1050,10 +1050,10 @@ discard block |
||
| 1050 | 1050 | } |
| 1051 | 1051 | } |
| 1052 | 1052 | |
| 1053 | - if(\OC::$server->getConfig()->getSystemValue('htaccess.IgnoreFrontController', false) === true || getenv('front_controller_active') === 'true') { |
|
| 1054 | - $location = $urlGenerator->getAbsoluteURL('/apps/' . $appId . '/'); |
|
| 1053 | + if (\OC::$server->getConfig()->getSystemValue('htaccess.IgnoreFrontController', false) === true || getenv('front_controller_active') === 'true') { |
|
| 1054 | + $location = $urlGenerator->getAbsoluteURL('/apps/'.$appId.'/'); |
|
| 1055 | 1055 | } else { |
| 1056 | - $location = $urlGenerator->getAbsoluteURL('/index.php/apps/' . $appId . '/'); |
|
| 1056 | + $location = $urlGenerator->getAbsoluteURL('/index.php/apps/'.$appId.'/'); |
|
| 1057 | 1057 | } |
| 1058 | 1058 | } |
| 1059 | 1059 | } |
@@ -1067,7 +1067,7 @@ discard block |
||
| 1067 | 1067 | */ |
| 1068 | 1068 | public static function redirectToDefaultPage() { |
| 1069 | 1069 | $location = self::getDefaultPageUrl(); |
| 1070 | - header('Location: ' . $location); |
|
| 1070 | + header('Location: '.$location); |
|
| 1071 | 1071 | exit(); |
| 1072 | 1072 | } |
| 1073 | 1073 | |
@@ -1080,7 +1080,7 @@ discard block |
||
| 1080 | 1080 | $id = \OC::$server->getSystemConfig()->getValue('instanceid', null); |
| 1081 | 1081 | if (is_null($id)) { |
| 1082 | 1082 | // We need to guarantee at least one letter in instanceid so it can be used as the session_name |
| 1083 | - $id = 'oc' . \OC::$server->getSecureRandom()->generate(10, \OCP\Security\ISecureRandom::CHAR_LOWER.\OCP\Security\ISecureRandom::CHAR_DIGITS); |
|
| 1083 | + $id = 'oc'.\OC::$server->getSecureRandom()->generate(10, \OCP\Security\ISecureRandom::CHAR_LOWER.\OCP\Security\ISecureRandom::CHAR_DIGITS); |
|
| 1084 | 1084 | \OC::$server->getSystemConfig()->setValue('instanceid', $id); |
| 1085 | 1085 | } |
| 1086 | 1086 | return $id; |
@@ -1102,7 +1102,7 @@ discard block |
||
| 1102 | 1102 | }, $value); |
| 1103 | 1103 | } else { |
| 1104 | 1104 | // Specify encoding for PHP<5.4 |
| 1105 | - $value = htmlspecialchars((string)$value, ENT_QUOTES, 'UTF-8'); |
|
| 1105 | + $value = htmlspecialchars((string) $value, ENT_QUOTES, 'UTF-8'); |
|
| 1106 | 1106 | } |
| 1107 | 1107 | return $value; |
| 1108 | 1108 | } |
@@ -1135,7 +1135,7 @@ discard block |
||
| 1135 | 1135 | $testContent = 'This is used for testing whether htaccess is properly enabled to disallow access from the outside. This file can be safely removed.'; |
| 1136 | 1136 | |
| 1137 | 1137 | // creating a test file |
| 1138 | - $testFile = $config->getSystemValue('datadirectory', OC::$SERVERROOT . '/data') . '/' . $fileName; |
|
| 1138 | + $testFile = $config->getSystemValue('datadirectory', OC::$SERVERROOT.'/data').'/'.$fileName; |
|
| 1139 | 1139 | |
| 1140 | 1140 | if (file_exists($testFile)) {// already running this test, possible recursive call |
| 1141 | 1141 | return false; |
@@ -1144,7 +1144,7 @@ discard block |
||
| 1144 | 1144 | $fp = @fopen($testFile, 'w'); |
| 1145 | 1145 | if (!$fp) { |
| 1146 | 1146 | throw new OC\HintException('Can\'t create test file to check for working .htaccess file.', |
| 1147 | - 'Make sure it is possible for the webserver to write to ' . $testFile); |
|
| 1147 | + 'Make sure it is possible for the webserver to write to '.$testFile); |
|
| 1148 | 1148 | } |
| 1149 | 1149 | fwrite($fp, $testContent); |
| 1150 | 1150 | fclose($fp); |
@@ -1171,10 +1171,10 @@ discard block |
||
| 1171 | 1171 | } |
| 1172 | 1172 | |
| 1173 | 1173 | $fileName = '/htaccesstest.txt'; |
| 1174 | - $testFile = $config->getSystemValue('datadirectory', OC::$SERVERROOT . '/data') . '/' . $fileName; |
|
| 1174 | + $testFile = $config->getSystemValue('datadirectory', OC::$SERVERROOT.'/data').'/'.$fileName; |
|
| 1175 | 1175 | |
| 1176 | 1176 | // accessing the file via http |
| 1177 | - $url = \OC::$server->getURLGenerator()->getAbsoluteURL(OC::$WEBROOT . '/data' . $fileName); |
|
| 1177 | + $url = \OC::$server->getURLGenerator()->getAbsoluteURL(OC::$WEBROOT.'/data'.$fileName); |
|
| 1178 | 1178 | try { |
| 1179 | 1179 | $content = \OC::$server->getHTTPClientService()->newClient()->get($url)->getBody(); |
| 1180 | 1180 | } catch (\Exception $e) { |
@@ -1265,7 +1265,7 @@ discard block |
||
| 1265 | 1265 | $theme = \OC::$server->getSystemConfig()->getValue("theme", ''); |
| 1266 | 1266 | |
| 1267 | 1267 | if ($theme === '') { |
| 1268 | - if (is_dir(OC::$SERVERROOT . '/themes/default')) { |
|
| 1268 | + if (is_dir(OC::$SERVERROOT.'/themes/default')) { |
|
| 1269 | 1269 | $theme = 'default'; |
| 1270 | 1270 | } |
| 1271 | 1271 | } |
@@ -1336,13 +1336,13 @@ discard block |
||
| 1336 | 1336 | * @return bool|string |
| 1337 | 1337 | */ |
| 1338 | 1338 | public static function normalizeUnicode($value) { |
| 1339 | - if(Normalizer::isNormalized($value)) { |
|
| 1339 | + if (Normalizer::isNormalized($value)) { |
|
| 1340 | 1340 | return $value; |
| 1341 | 1341 | } |
| 1342 | 1342 | |
| 1343 | 1343 | $normalizedValue = Normalizer::normalize($value); |
| 1344 | 1344 | if ($normalizedValue === null || $normalizedValue === false) { |
| 1345 | - \OC::$server->getLogger()->warning('normalizing failed for "' . $value . '"', ['app' => 'core']); |
|
| 1345 | + \OC::$server->getLogger()->warning('normalizing failed for "'.$value.'"', ['app' => 'core']); |
|
| 1346 | 1346 | return $value; |
| 1347 | 1347 | } |
| 1348 | 1348 | |
@@ -1368,7 +1368,7 @@ discard block |
||
| 1368 | 1368 | $version = OC_Util::getVersionString(); |
| 1369 | 1369 | $build = OC_Util::getBuild(); |
| 1370 | 1370 | if (!empty($build) and OC_Util::getChannel() === 'daily') { |
| 1371 | - $version .= ' Build:' . $build; |
|
| 1371 | + $version .= ' Build:'.$build; |
|
| 1372 | 1372 | } |
| 1373 | 1373 | return $version; |
| 1374 | 1374 | } |
@@ -1415,19 +1415,19 @@ discard block |
||
| 1415 | 1415 | } else if ($config->getValue('debug', false) && $versionDiff < 0) { |
| 1416 | 1416 | // downgrade with debug |
| 1417 | 1417 | $installedMajor = explode('.', $installedVersion); |
| 1418 | - $installedMajor = $installedMajor[0] . '.' . $installedMajor[1]; |
|
| 1418 | + $installedMajor = $installedMajor[0].'.'.$installedMajor[1]; |
|
| 1419 | 1419 | $currentMajor = explode('.', $currentVersion); |
| 1420 | - $currentMajor = $currentMajor[0] . '.' . $currentMajor[1]; |
|
| 1420 | + $currentMajor = $currentMajor[0].'.'.$currentMajor[1]; |
|
| 1421 | 1421 | if ($installedMajor === $currentMajor) { |
| 1422 | 1422 | // Same major, allow downgrade for developers |
| 1423 | 1423 | return true; |
| 1424 | 1424 | } else { |
| 1425 | 1425 | // downgrade attempt, throw exception |
| 1426 | - throw new \OC\HintException('Downgrading is not supported and is likely to cause unpredictable issues (from ' . $installedVersion . ' to ' . $currentVersion . ')'); |
|
| 1426 | + throw new \OC\HintException('Downgrading is not supported and is likely to cause unpredictable issues (from '.$installedVersion.' to '.$currentVersion.')'); |
|
| 1427 | 1427 | } |
| 1428 | 1428 | } else if ($versionDiff < 0) { |
| 1429 | 1429 | // downgrade attempt, throw exception |
| 1430 | - throw new \OC\HintException('Downgrading is not supported and is likely to cause unpredictable issues (from ' . $installedVersion . ' to ' . $currentVersion . ')'); |
|
| 1430 | + throw new \OC\HintException('Downgrading is not supported and is likely to cause unpredictable issues (from '.$installedVersion.' to '.$currentVersion.')'); |
|
| 1431 | 1431 | } |
| 1432 | 1432 | |
| 1433 | 1433 | // also check for upgrades for apps (independently from the user) |