You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Server.php 69KB

7 jaren geleden
7 jaren geleden
7 jaren geleden
7 jaren geleden
7 jaren geleden
8 jaren geleden
7 jaren geleden
8 jaren geleden
Add code integrity check This PR implements the base foundation of the code signing and integrity check. In this PR implemented is the signing and verification logic, as well as commands to sign single apps or the core repository. Furthermore, there is a basic implementation to display problems with the code integrity on the update screen. Code signing basically happens the following way: - There is a ownCloud Root Certificate authority stored `resources/codesigning/root.crt` (in this PR I also ship the private key which we obviously need to change before a release :wink:). This certificate is not intended to be used for signing directly and only is used to sign new certificates. - Using the `integrity:sign-core` and `integrity:sign-app` commands developers can sign either the core release or a single app. The core release needs to be signed with a certificate that has a CN of `core`, apps need to be signed with a certificate that either has a CN of `core` (shipped apps!) or the AppID. - The command generates a signature.json file of the following format: ```json { "hashes": { "/filename.php": "2401fed2eea6f2c1027c482a633e8e25cd46701f811e2d2c10dc213fd95fa60e350bccbbebdccc73a042b1a2799f673fbabadc783284cc288e4f1a1eacb74e3d", "/lib/base.php": "55548cc16b457cd74241990cc9d3b72b6335f2e5f45eee95171da024087d114fcbc2effc3d5818a6d5d55f2ae960ab39fd0414d0c542b72a3b9e08eb21206dd9" }, "certificate": "-----BEGIN CERTIFICATE-----MIIBvTCCASagAwIBAgIUPvawyqJwCwYazcv7iz16TWxfeUMwDQYJKoZIhvcNAQEF\nBQAwIzEhMB8GA1UECgwYb3duQ2xvdWQgQ29kZSBTaWduaW5nIENBMB4XDTE1MTAx\nNDEzMTcxMFoXDTE2MTAxNDEzMTcxMFowEzERMA8GA1UEAwwIY29udGFjdHMwgZ8w\nDQYJKoZIhvcNAQEBBQADgY0AMIGJAoGBANoQesGdCW0L2L+a2xITYipixkScrIpB\nkX5Snu3fs45MscDb61xByjBSlFgR4QI6McoCipPw4SUr28EaExVvgPSvqUjYLGps\nfiv0Cvgquzbx/X3mUcdk9LcFo1uWGtrTfkuXSKX41PnJGTr6RQWGIBd1V52q1qbC\nJKkfzyeMeuQfAgMBAAEwDQYJKoZIhvcNAQEFBQADgYEAvF/KIhRMQ3tYTmgHWsiM\nwDMgIDb7iaHF0fS+/Nvo4PzoTO/trev6tMyjLbJ7hgdCpz/1sNzE11Cibf6V6dsz\njCE9invP368Xv0bTRObRqeSNsGogGl5ceAvR0c9BG+NRIKHcly3At3gLkS2791bC\niG+UxI/MNcWV0uJg9S63LF8=\n-----END CERTIFICATE-----", "signature": "U29tZVNpZ25lZERhdGFFeGFtcGxl" } ``` `hashes` is an array of all files in the folder with their corresponding SHA512 hashes (this is actually quite cheap to calculate), the `certificate` is the certificate used for signing. It has to be issued by the ownCloud Root Authority and it's CN needs to be permitted to perform the required action. The `signature` is then a signature of the `hashes` which can be verified using the `certificate`. Steps to do in other PRs, this is already a quite huge one: - Add nag screen in case the code check fails to ensure that administrators are aware of this. - Add code verification also to OCC upgrade and unify display code more. - Add enforced code verification to apps shipped from the appstore with a level of "official" - Add enfocrced code verification to apps shipped from the appstore that were already signed in a previous release - Add some developer documentation on how devs can request their own certificate - Check when installing ownCloud - Add support for CRLs to allow revoking certificates **Note:** The upgrade checks are only run when the instance has a defined release channel of `stable` (defined in `version.php`). If you want to test this, you need to change the channel thus and then generate the core signature: ``` ➜ master git:(add-integrity-checker) ✗ ./occ integrity:sign-core --privateKey=resources/codesigning/core.key --certificate=resources/codesigning/core.crt Successfully signed "core" ``` Then increase the version and you should see something like the following: ![2015-11-04_12-02-57](https://cloud.githubusercontent.com/assets/878997/10936336/6adb1d14-82ec-11e5-8f06-9a74801c9abf.png) As you can see a failed code check will not prevent the further update. It will instead just be a notice to the admin. In a next step we will add some nag screen. For packaging stable releases this requires the following additional steps as a last action before zipping: 1. Run `./occ integrity:sign-core` once 2. Run `./occ integrity:sign-app` _for each_ app. However, this can be simply automated using a simple foreach on the apps folder.
8 jaren geleden
8 jaren geleden
9 jaren geleden
Add public API to give developers the possibility to adjust the global CSP defaults Allows to inject something into the default content policy. This is for example useful when you're injecting Javascript code into a view belonging to another controller and cannot modify its Content-Security-Policy itself. Note that the adjustment is only applied to applications that use AppFramework controllers. To use this from your `app.php` use `\OC::$server->getContentSecurityPolicyManager()->addDefaultPolicy($policy)`, $policy has to be of type `\OCP\AppFramework\Http\ContentSecurityPolicy`. To test this add something like the following into an `app.php` of any enabled app: ``` $manager = \OC::$server->getContentSecurityPolicyManager(); $policy = new \OCP\AppFramework\Http\ContentSecurityPolicy(false); $policy->addAllowedFrameDomain('asdf'); $policy->addAllowedScriptDomain('yolo.com'); $policy->allowInlineScript(false); $manager->addDefaultPolicy($policy); $policy = new \OCP\AppFramework\Http\ContentSecurityPolicy(false); $policy->addAllowedFontDomain('yolo.com'); $manager->addDefaultPolicy($policy); $policy = new \OCP\AppFramework\Http\ContentSecurityPolicy(false); $policy->addAllowedFrameDomain('banana.com'); $manager->addDefaultPolicy($policy); ``` If you now open the files app the policy should be: ``` Content-Security-Policy:default-src 'none';script-src yolo.com 'self' 'unsafe-eval';style-src 'self' 'unsafe-inline';img-src 'self' data: blob:;font-src yolo.com 'self';connect-src 'self';media-src 'self';frame-src asdf banana.com 'self' ```
8 jaren geleden
8 jaren geleden
8 jaren geleden
8 jaren geleden
Add code integrity check This PR implements the base foundation of the code signing and integrity check. In this PR implemented is the signing and verification logic, as well as commands to sign single apps or the core repository. Furthermore, there is a basic implementation to display problems with the code integrity on the update screen. Code signing basically happens the following way: - There is a ownCloud Root Certificate authority stored `resources/codesigning/root.crt` (in this PR I also ship the private key which we obviously need to change before a release :wink:). This certificate is not intended to be used for signing directly and only is used to sign new certificates. - Using the `integrity:sign-core` and `integrity:sign-app` commands developers can sign either the core release or a single app. The core release needs to be signed with a certificate that has a CN of `core`, apps need to be signed with a certificate that either has a CN of `core` (shipped apps!) or the AppID. - The command generates a signature.json file of the following format: ```json { "hashes": { "/filename.php": "2401fed2eea6f2c1027c482a633e8e25cd46701f811e2d2c10dc213fd95fa60e350bccbbebdccc73a042b1a2799f673fbabadc783284cc288e4f1a1eacb74e3d", "/lib/base.php": "55548cc16b457cd74241990cc9d3b72b6335f2e5f45eee95171da024087d114fcbc2effc3d5818a6d5d55f2ae960ab39fd0414d0c542b72a3b9e08eb21206dd9" }, "certificate": "-----BEGIN CERTIFICATE-----MIIBvTCCASagAwIBAgIUPvawyqJwCwYazcv7iz16TWxfeUMwDQYJKoZIhvcNAQEF\nBQAwIzEhMB8GA1UECgwYb3duQ2xvdWQgQ29kZSBTaWduaW5nIENBMB4XDTE1MTAx\nNDEzMTcxMFoXDTE2MTAxNDEzMTcxMFowEzERMA8GA1UEAwwIY29udGFjdHMwgZ8w\nDQYJKoZIhvcNAQEBBQADgY0AMIGJAoGBANoQesGdCW0L2L+a2xITYipixkScrIpB\nkX5Snu3fs45MscDb61xByjBSlFgR4QI6McoCipPw4SUr28EaExVvgPSvqUjYLGps\nfiv0Cvgquzbx/X3mUcdk9LcFo1uWGtrTfkuXSKX41PnJGTr6RQWGIBd1V52q1qbC\nJKkfzyeMeuQfAgMBAAEwDQYJKoZIhvcNAQEFBQADgYEAvF/KIhRMQ3tYTmgHWsiM\nwDMgIDb7iaHF0fS+/Nvo4PzoTO/trev6tMyjLbJ7hgdCpz/1sNzE11Cibf6V6dsz\njCE9invP368Xv0bTRObRqeSNsGogGl5ceAvR0c9BG+NRIKHcly3At3gLkS2791bC\niG+UxI/MNcWV0uJg9S63LF8=\n-----END CERTIFICATE-----", "signature": "U29tZVNpZ25lZERhdGFFeGFtcGxl" } ``` `hashes` is an array of all files in the folder with their corresponding SHA512 hashes (this is actually quite cheap to calculate), the `certificate` is the certificate used for signing. It has to be issued by the ownCloud Root Authority and it's CN needs to be permitted to perform the required action. The `signature` is then a signature of the `hashes` which can be verified using the `certificate`. Steps to do in other PRs, this is already a quite huge one: - Add nag screen in case the code check fails to ensure that administrators are aware of this. - Add code verification also to OCC upgrade and unify display code more. - Add enforced code verification to apps shipped from the appstore with a level of "official" - Add enfocrced code verification to apps shipped from the appstore that were already signed in a previous release - Add some developer documentation on how devs can request their own certificate - Check when installing ownCloud - Add support for CRLs to allow revoking certificates **Note:** The upgrade checks are only run when the instance has a defined release channel of `stable` (defined in `version.php`). If you want to test this, you need to change the channel thus and then generate the core signature: ``` ➜ master git:(add-integrity-checker) ✗ ./occ integrity:sign-core --privateKey=resources/codesigning/core.key --certificate=resources/codesigning/core.crt Successfully signed "core" ``` Then increase the version and you should see something like the following: ![2015-11-04_12-02-57](https://cloud.githubusercontent.com/assets/878997/10936336/6adb1d14-82ec-11e5-8f06-9a74801c9abf.png) As you can see a failed code check will not prevent the further update. It will instead just be a notice to the admin. In a next step we will add some nag screen. For packaging stable releases this requires the following additional steps as a last action before zipping: 1. Run `./occ integrity:sign-core` once 2. Run `./occ integrity:sign-app` _for each_ app. However, this can be simply automated using a simple foreach on the apps folder.
8 jaren geleden
Add code integrity check This PR implements the base foundation of the code signing and integrity check. In this PR implemented is the signing and verification logic, as well as commands to sign single apps or the core repository. Furthermore, there is a basic implementation to display problems with the code integrity on the update screen. Code signing basically happens the following way: - There is a ownCloud Root Certificate authority stored `resources/codesigning/root.crt` (in this PR I also ship the private key which we obviously need to change before a release :wink:). This certificate is not intended to be used for signing directly and only is used to sign new certificates. - Using the `integrity:sign-core` and `integrity:sign-app` commands developers can sign either the core release or a single app. The core release needs to be signed with a certificate that has a CN of `core`, apps need to be signed with a certificate that either has a CN of `core` (shipped apps!) or the AppID. - The command generates a signature.json file of the following format: ```json { "hashes": { "/filename.php": "2401fed2eea6f2c1027c482a633e8e25cd46701f811e2d2c10dc213fd95fa60e350bccbbebdccc73a042b1a2799f673fbabadc783284cc288e4f1a1eacb74e3d", "/lib/base.php": "55548cc16b457cd74241990cc9d3b72b6335f2e5f45eee95171da024087d114fcbc2effc3d5818a6d5d55f2ae960ab39fd0414d0c542b72a3b9e08eb21206dd9" }, "certificate": "-----BEGIN CERTIFICATE-----MIIBvTCCASagAwIBAgIUPvawyqJwCwYazcv7iz16TWxfeUMwDQYJKoZIhvcNAQEF\nBQAwIzEhMB8GA1UECgwYb3duQ2xvdWQgQ29kZSBTaWduaW5nIENBMB4XDTE1MTAx\nNDEzMTcxMFoXDTE2MTAxNDEzMTcxMFowEzERMA8GA1UEAwwIY29udGFjdHMwgZ8w\nDQYJKoZIhvcNAQEBBQADgY0AMIGJAoGBANoQesGdCW0L2L+a2xITYipixkScrIpB\nkX5Snu3fs45MscDb61xByjBSlFgR4QI6McoCipPw4SUr28EaExVvgPSvqUjYLGps\nfiv0Cvgquzbx/X3mUcdk9LcFo1uWGtrTfkuXSKX41PnJGTr6RQWGIBd1V52q1qbC\nJKkfzyeMeuQfAgMBAAEwDQYJKoZIhvcNAQEFBQADgYEAvF/KIhRMQ3tYTmgHWsiM\nwDMgIDb7iaHF0fS+/Nvo4PzoTO/trev6tMyjLbJ7hgdCpz/1sNzE11Cibf6V6dsz\njCE9invP368Xv0bTRObRqeSNsGogGl5ceAvR0c9BG+NRIKHcly3At3gLkS2791bC\niG+UxI/MNcWV0uJg9S63LF8=\n-----END CERTIFICATE-----", "signature": "U29tZVNpZ25lZERhdGFFeGFtcGxl" } ``` `hashes` is an array of all files in the folder with their corresponding SHA512 hashes (this is actually quite cheap to calculate), the `certificate` is the certificate used for signing. It has to be issued by the ownCloud Root Authority and it's CN needs to be permitted to perform the required action. The `signature` is then a signature of the `hashes` which can be verified using the `certificate`. Steps to do in other PRs, this is already a quite huge one: - Add nag screen in case the code check fails to ensure that administrators are aware of this. - Add code verification also to OCC upgrade and unify display code more. - Add enforced code verification to apps shipped from the appstore with a level of "official" - Add enfocrced code verification to apps shipped from the appstore that were already signed in a previous release - Add some developer documentation on how devs can request their own certificate - Check when installing ownCloud - Add support for CRLs to allow revoking certificates **Note:** The upgrade checks are only run when the instance has a defined release channel of `stable` (defined in `version.php`). If you want to test this, you need to change the channel thus and then generate the core signature: ``` ➜ master git:(add-integrity-checker) ✗ ./occ integrity:sign-core --privateKey=resources/codesigning/core.key --certificate=resources/codesigning/core.crt Successfully signed "core" ``` Then increase the version and you should see something like the following: ![2015-11-04_12-02-57](https://cloud.githubusercontent.com/assets/878997/10936336/6adb1d14-82ec-11e5-8f06-9a74801c9abf.png) As you can see a failed code check will not prevent the further update. It will instead just be a notice to the admin. In a next step we will add some nag screen. For packaging stable releases this requires the following additional steps as a last action before zipping: 1. Run `./occ integrity:sign-core` once 2. Run `./occ integrity:sign-app` _for each_ app. However, this can be simply automated using a simple foreach on the apps folder.
8 jaren geleden
Add code integrity check This PR implements the base foundation of the code signing and integrity check. In this PR implemented is the signing and verification logic, as well as commands to sign single apps or the core repository. Furthermore, there is a basic implementation to display problems with the code integrity on the update screen. Code signing basically happens the following way: - There is a ownCloud Root Certificate authority stored `resources/codesigning/root.crt` (in this PR I also ship the private key which we obviously need to change before a release :wink:). This certificate is not intended to be used for signing directly and only is used to sign new certificates. - Using the `integrity:sign-core` and `integrity:sign-app` commands developers can sign either the core release or a single app. The core release needs to be signed with a certificate that has a CN of `core`, apps need to be signed with a certificate that either has a CN of `core` (shipped apps!) or the AppID. - The command generates a signature.json file of the following format: ```json { "hashes": { "/filename.php": "2401fed2eea6f2c1027c482a633e8e25cd46701f811e2d2c10dc213fd95fa60e350bccbbebdccc73a042b1a2799f673fbabadc783284cc288e4f1a1eacb74e3d", "/lib/base.php": "55548cc16b457cd74241990cc9d3b72b6335f2e5f45eee95171da024087d114fcbc2effc3d5818a6d5d55f2ae960ab39fd0414d0c542b72a3b9e08eb21206dd9" }, "certificate": "-----BEGIN CERTIFICATE-----MIIBvTCCASagAwIBAgIUPvawyqJwCwYazcv7iz16TWxfeUMwDQYJKoZIhvcNAQEF\nBQAwIzEhMB8GA1UECgwYb3duQ2xvdWQgQ29kZSBTaWduaW5nIENBMB4XDTE1MTAx\nNDEzMTcxMFoXDTE2MTAxNDEzMTcxMFowEzERMA8GA1UEAwwIY29udGFjdHMwgZ8w\nDQYJKoZIhvcNAQEBBQADgY0AMIGJAoGBANoQesGdCW0L2L+a2xITYipixkScrIpB\nkX5Snu3fs45MscDb61xByjBSlFgR4QI6McoCipPw4SUr28EaExVvgPSvqUjYLGps\nfiv0Cvgquzbx/X3mUcdk9LcFo1uWGtrTfkuXSKX41PnJGTr6RQWGIBd1V52q1qbC\nJKkfzyeMeuQfAgMBAAEwDQYJKoZIhvcNAQEFBQADgYEAvF/KIhRMQ3tYTmgHWsiM\nwDMgIDb7iaHF0fS+/Nvo4PzoTO/trev6tMyjLbJ7hgdCpz/1sNzE11Cibf6V6dsz\njCE9invP368Xv0bTRObRqeSNsGogGl5ceAvR0c9BG+NRIKHcly3At3gLkS2791bC\niG+UxI/MNcWV0uJg9S63LF8=\n-----END CERTIFICATE-----", "signature": "U29tZVNpZ25lZERhdGFFeGFtcGxl" } ``` `hashes` is an array of all files in the folder with their corresponding SHA512 hashes (this is actually quite cheap to calculate), the `certificate` is the certificate used for signing. It has to be issued by the ownCloud Root Authority and it's CN needs to be permitted to perform the required action. The `signature` is then a signature of the `hashes` which can be verified using the `certificate`. Steps to do in other PRs, this is already a quite huge one: - Add nag screen in case the code check fails to ensure that administrators are aware of this. - Add code verification also to OCC upgrade and unify display code more. - Add enforced code verification to apps shipped from the appstore with a level of "official" - Add enfocrced code verification to apps shipped from the appstore that were already signed in a previous release - Add some developer documentation on how devs can request their own certificate - Check when installing ownCloud - Add support for CRLs to allow revoking certificates **Note:** The upgrade checks are only run when the instance has a defined release channel of `stable` (defined in `version.php`). If you want to test this, you need to change the channel thus and then generate the core signature: ``` ➜ master git:(add-integrity-checker) ✗ ./occ integrity:sign-core --privateKey=resources/codesigning/core.key --certificate=resources/codesigning/core.crt Successfully signed "core" ``` Then increase the version and you should see something like the following: ![2015-11-04_12-02-57](https://cloud.githubusercontent.com/assets/878997/10936336/6adb1d14-82ec-11e5-8f06-9a74801c9abf.png) As you can see a failed code check will not prevent the further update. It will instead just be a notice to the admin. In a next step we will add some nag screen. For packaging stable releases this requires the following additional steps as a last action before zipping: 1. Run `./occ integrity:sign-core` once 2. Run `./occ integrity:sign-app` _for each_ app. However, this can be simply automated using a simple foreach on the apps folder.
8 jaren geleden
8 jaren geleden
8 jaren geleden
8 jaren geleden
8 jaren geleden
10 jaren geleden
10 jaren geleden
10 jaren geleden
10 jaren geleden
10 jaren geleden
9 jaren geleden
9 jaren geleden
9 jaren geleden
9 jaren geleden
8 jaren geleden
8 jaren geleden
8 jaren geleden
8 jaren geleden
8 jaren geleden
Add code integrity check This PR implements the base foundation of the code signing and integrity check. In this PR implemented is the signing and verification logic, as well as commands to sign single apps or the core repository. Furthermore, there is a basic implementation to display problems with the code integrity on the update screen. Code signing basically happens the following way: - There is a ownCloud Root Certificate authority stored `resources/codesigning/root.crt` (in this PR I also ship the private key which we obviously need to change before a release :wink:). This certificate is not intended to be used for signing directly and only is used to sign new certificates. - Using the `integrity:sign-core` and `integrity:sign-app` commands developers can sign either the core release or a single app. The core release needs to be signed with a certificate that has a CN of `core`, apps need to be signed with a certificate that either has a CN of `core` (shipped apps!) or the AppID. - The command generates a signature.json file of the following format: ```json { "hashes": { "/filename.php": "2401fed2eea6f2c1027c482a633e8e25cd46701f811e2d2c10dc213fd95fa60e350bccbbebdccc73a042b1a2799f673fbabadc783284cc288e4f1a1eacb74e3d", "/lib/base.php": "55548cc16b457cd74241990cc9d3b72b6335f2e5f45eee95171da024087d114fcbc2effc3d5818a6d5d55f2ae960ab39fd0414d0c542b72a3b9e08eb21206dd9" }, "certificate": "-----BEGIN CERTIFICATE-----MIIBvTCCASagAwIBAgIUPvawyqJwCwYazcv7iz16TWxfeUMwDQYJKoZIhvcNAQEF\nBQAwIzEhMB8GA1UECgwYb3duQ2xvdWQgQ29kZSBTaWduaW5nIENBMB4XDTE1MTAx\nNDEzMTcxMFoXDTE2MTAxNDEzMTcxMFowEzERMA8GA1UEAwwIY29udGFjdHMwgZ8w\nDQYJKoZIhvcNAQEBBQADgY0AMIGJAoGBANoQesGdCW0L2L+a2xITYipixkScrIpB\nkX5Snu3fs45MscDb61xByjBSlFgR4QI6McoCipPw4SUr28EaExVvgPSvqUjYLGps\nfiv0Cvgquzbx/X3mUcdk9LcFo1uWGtrTfkuXSKX41PnJGTr6RQWGIBd1V52q1qbC\nJKkfzyeMeuQfAgMBAAEwDQYJKoZIhvcNAQEFBQADgYEAvF/KIhRMQ3tYTmgHWsiM\nwDMgIDb7iaHF0fS+/Nvo4PzoTO/trev6tMyjLbJ7hgdCpz/1sNzE11Cibf6V6dsz\njCE9invP368Xv0bTRObRqeSNsGogGl5ceAvR0c9BG+NRIKHcly3At3gLkS2791bC\niG+UxI/MNcWV0uJg9S63LF8=\n-----END CERTIFICATE-----", "signature": "U29tZVNpZ25lZERhdGFFeGFtcGxl" } ``` `hashes` is an array of all files in the folder with their corresponding SHA512 hashes (this is actually quite cheap to calculate), the `certificate` is the certificate used for signing. It has to be issued by the ownCloud Root Authority and it's CN needs to be permitted to perform the required action. The `signature` is then a signature of the `hashes` which can be verified using the `certificate`. Steps to do in other PRs, this is already a quite huge one: - Add nag screen in case the code check fails to ensure that administrators are aware of this. - Add code verification also to OCC upgrade and unify display code more. - Add enforced code verification to apps shipped from the appstore with a level of "official" - Add enfocrced code verification to apps shipped from the appstore that were already signed in a previous release - Add some developer documentation on how devs can request their own certificate - Check when installing ownCloud - Add support for CRLs to allow revoking certificates **Note:** The upgrade checks are only run when the instance has a defined release channel of `stable` (defined in `version.php`). If you want to test this, you need to change the channel thus and then generate the core signature: ``` ➜ master git:(add-integrity-checker) ✗ ./occ integrity:sign-core --privateKey=resources/codesigning/core.key --certificate=resources/codesigning/core.crt Successfully signed "core" ``` Then increase the version and you should see something like the following: ![2015-11-04_12-02-57](https://cloud.githubusercontent.com/assets/878997/10936336/6adb1d14-82ec-11e5-8f06-9a74801c9abf.png) As you can see a failed code check will not prevent the further update. It will instead just be a notice to the admin. In a next step we will add some nag screen. For packaging stable releases this requires the following additional steps as a last action before zipping: 1. Run `./occ integrity:sign-core` once 2. Run `./occ integrity:sign-app` _for each_ app. However, this can be simply automated using a simple foreach on the apps folder.
8 jaren geleden
Add code integrity check This PR implements the base foundation of the code signing and integrity check. In this PR implemented is the signing and verification logic, as well as commands to sign single apps or the core repository. Furthermore, there is a basic implementation to display problems with the code integrity on the update screen. Code signing basically happens the following way: - There is a ownCloud Root Certificate authority stored `resources/codesigning/root.crt` (in this PR I also ship the private key which we obviously need to change before a release :wink:). This certificate is not intended to be used for signing directly and only is used to sign new certificates. - Using the `integrity:sign-core` and `integrity:sign-app` commands developers can sign either the core release or a single app. The core release needs to be signed with a certificate that has a CN of `core`, apps need to be signed with a certificate that either has a CN of `core` (shipped apps!) or the AppID. - The command generates a signature.json file of the following format: ```json { "hashes": { "/filename.php": "2401fed2eea6f2c1027c482a633e8e25cd46701f811e2d2c10dc213fd95fa60e350bccbbebdccc73a042b1a2799f673fbabadc783284cc288e4f1a1eacb74e3d", "/lib/base.php": "55548cc16b457cd74241990cc9d3b72b6335f2e5f45eee95171da024087d114fcbc2effc3d5818a6d5d55f2ae960ab39fd0414d0c542b72a3b9e08eb21206dd9" }, "certificate": "-----BEGIN CERTIFICATE-----MIIBvTCCASagAwIBAgIUPvawyqJwCwYazcv7iz16TWxfeUMwDQYJKoZIhvcNAQEF\nBQAwIzEhMB8GA1UECgwYb3duQ2xvdWQgQ29kZSBTaWduaW5nIENBMB4XDTE1MTAx\nNDEzMTcxMFoXDTE2MTAxNDEzMTcxMFowEzERMA8GA1UEAwwIY29udGFjdHMwgZ8w\nDQYJKoZIhvcNAQEBBQADgY0AMIGJAoGBANoQesGdCW0L2L+a2xITYipixkScrIpB\nkX5Snu3fs45MscDb61xByjBSlFgR4QI6McoCipPw4SUr28EaExVvgPSvqUjYLGps\nfiv0Cvgquzbx/X3mUcdk9LcFo1uWGtrTfkuXSKX41PnJGTr6RQWGIBd1V52q1qbC\nJKkfzyeMeuQfAgMBAAEwDQYJKoZIhvcNAQEFBQADgYEAvF/KIhRMQ3tYTmgHWsiM\nwDMgIDb7iaHF0fS+/Nvo4PzoTO/trev6tMyjLbJ7hgdCpz/1sNzE11Cibf6V6dsz\njCE9invP368Xv0bTRObRqeSNsGogGl5ceAvR0c9BG+NRIKHcly3At3gLkS2791bC\niG+UxI/MNcWV0uJg9S63LF8=\n-----END CERTIFICATE-----", "signature": "U29tZVNpZ25lZERhdGFFeGFtcGxl" } ``` `hashes` is an array of all files in the folder with their corresponding SHA512 hashes (this is actually quite cheap to calculate), the `certificate` is the certificate used for signing. It has to be issued by the ownCloud Root Authority and it's CN needs to be permitted to perform the required action. The `signature` is then a signature of the `hashes` which can be verified using the `certificate`. Steps to do in other PRs, this is already a quite huge one: - Add nag screen in case the code check fails to ensure that administrators are aware of this. - Add code verification also to OCC upgrade and unify display code more. - Add enforced code verification to apps shipped from the appstore with a level of "official" - Add enfocrced code verification to apps shipped from the appstore that were already signed in a previous release - Add some developer documentation on how devs can request their own certificate - Check when installing ownCloud - Add support for CRLs to allow revoking certificates **Note:** The upgrade checks are only run when the instance has a defined release channel of `stable` (defined in `version.php`). If you want to test this, you need to change the channel thus and then generate the core signature: ``` ➜ master git:(add-integrity-checker) ✗ ./occ integrity:sign-core --privateKey=resources/codesigning/core.key --certificate=resources/codesigning/core.crt Successfully signed "core" ``` Then increase the version and you should see something like the following: ![2015-11-04_12-02-57](https://cloud.githubusercontent.com/assets/878997/10936336/6adb1d14-82ec-11e5-8f06-9a74801c9abf.png) As you can see a failed code check will not prevent the further update. It will instead just be a notice to the admin. In a next step we will add some nag screen. For packaging stable releases this requires the following additional steps as a last action before zipping: 1. Run `./occ integrity:sign-core` once 2. Run `./occ integrity:sign-app` _for each_ app. However, this can be simply automated using a simple foreach on the apps folder.
8 jaren geleden
Add public API to give developers the possibility to adjust the global CSP defaults Allows to inject something into the default content policy. This is for example useful when you're injecting Javascript code into a view belonging to another controller and cannot modify its Content-Security-Policy itself. Note that the adjustment is only applied to applications that use AppFramework controllers. To use this from your `app.php` use `\OC::$server->getContentSecurityPolicyManager()->addDefaultPolicy($policy)`, $policy has to be of type `\OCP\AppFramework\Http\ContentSecurityPolicy`. To test this add something like the following into an `app.php` of any enabled app: ``` $manager = \OC::$server->getContentSecurityPolicyManager(); $policy = new \OCP\AppFramework\Http\ContentSecurityPolicy(false); $policy->addAllowedFrameDomain('asdf'); $policy->addAllowedScriptDomain('yolo.com'); $policy->allowInlineScript(false); $manager->addDefaultPolicy($policy); $policy = new \OCP\AppFramework\Http\ContentSecurityPolicy(false); $policy->addAllowedFontDomain('yolo.com'); $manager->addDefaultPolicy($policy); $policy = new \OCP\AppFramework\Http\ContentSecurityPolicy(false); $policy->addAllowedFrameDomain('banana.com'); $manager->addDefaultPolicy($policy); ``` If you now open the files app the policy should be: ``` Content-Security-Policy:default-src 'none';script-src yolo.com 'self' 'unsafe-eval';style-src 'self' 'unsafe-inline';img-src 'self' data: blob:;font-src yolo.com 'self';connect-src 'self';media-src 'self';frame-src asdf banana.com 'self' ```
8 jaren geleden
Add public API to give developers the possibility to adjust the global CSP defaults Allows to inject something into the default content policy. This is for example useful when you're injecting Javascript code into a view belonging to another controller and cannot modify its Content-Security-Policy itself. Note that the adjustment is only applied to applications that use AppFramework controllers. To use this from your `app.php` use `\OC::$server->getContentSecurityPolicyManager()->addDefaultPolicy($policy)`, $policy has to be of type `\OCP\AppFramework\Http\ContentSecurityPolicy`. To test this add something like the following into an `app.php` of any enabled app: ``` $manager = \OC::$server->getContentSecurityPolicyManager(); $policy = new \OCP\AppFramework\Http\ContentSecurityPolicy(false); $policy->addAllowedFrameDomain('asdf'); $policy->addAllowedScriptDomain('yolo.com'); $policy->allowInlineScript(false); $manager->addDefaultPolicy($policy); $policy = new \OCP\AppFramework\Http\ContentSecurityPolicy(false); $policy->addAllowedFontDomain('yolo.com'); $manager->addDefaultPolicy($policy); $policy = new \OCP\AppFramework\Http\ContentSecurityPolicy(false); $policy->addAllowedFrameDomain('banana.com'); $manager->addDefaultPolicy($policy); ``` If you now open the files app the policy should be: ``` Content-Security-Policy:default-src 'none';script-src yolo.com 'self' 'unsafe-eval';style-src 'self' 'unsafe-inline';img-src 'self' data: blob:;font-src yolo.com 'self';connect-src 'self';media-src 'self';frame-src asdf banana.com 'self' ```
8 jaren geleden
Add public API to give developers the possibility to adjust the global CSP defaults Allows to inject something into the default content policy. This is for example useful when you're injecting Javascript code into a view belonging to another controller and cannot modify its Content-Security-Policy itself. Note that the adjustment is only applied to applications that use AppFramework controllers. To use this from your `app.php` use `\OC::$server->getContentSecurityPolicyManager()->addDefaultPolicy($policy)`, $policy has to be of type `\OCP\AppFramework\Http\ContentSecurityPolicy`. To test this add something like the following into an `app.php` of any enabled app: ``` $manager = \OC::$server->getContentSecurityPolicyManager(); $policy = new \OCP\AppFramework\Http\ContentSecurityPolicy(false); $policy->addAllowedFrameDomain('asdf'); $policy->addAllowedScriptDomain('yolo.com'); $policy->allowInlineScript(false); $manager->addDefaultPolicy($policy); $policy = new \OCP\AppFramework\Http\ContentSecurityPolicy(false); $policy->addAllowedFontDomain('yolo.com'); $manager->addDefaultPolicy($policy); $policy = new \OCP\AppFramework\Http\ContentSecurityPolicy(false); $policy->addAllowedFrameDomain('banana.com'); $manager->addDefaultPolicy($policy); ``` If you now open the files app the policy should be: ``` Content-Security-Policy:default-src 'none';script-src yolo.com 'self' 'unsafe-eval';style-src 'self' 'unsafe-inline';img-src 'self' data: blob:;font-src yolo.com 'self';connect-src 'self';media-src 'self';frame-src asdf banana.com 'self' ```
8 jaren geleden
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. * @copyright Copyright (c) 2016, Lukas Reschke <lukas@statuscode.ch>
  5. *
  6. * @author Arne Hamann <kontakt+github@arne.email>
  7. * @author Arthur Schiwon <blizzz@arthur-schiwon.de>
  8. * @author Bart Visscher <bartv@thisnet.nl>
  9. * @author Bernhard Posselt <dev@bernhard-posselt.com>
  10. * @author Bernhard Reiter <ockham@raz.or.at>
  11. * @author Bjoern Schiessle <bjoern@schiessle.org>
  12. * @author Björn Schießle <bjoern@schiessle.org>
  13. * @author Christopher Schäpers <kondou@ts.unde.re>
  14. * @author Christoph Wurst <christoph@winzerhof-wurst.at>
  15. * @author Damjan Georgievski <gdamjan@gmail.com>
  16. * @author Daniel Kesselberg <mail@danielkesselberg.de>
  17. * @author Georg Ehrke <oc.list@georgehrke.com>
  18. * @author Joas Schilling <coding@schilljs.com>
  19. * @author John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
  20. * @author Jörn Friedrich Dreyer <jfd@butonic.de>
  21. * @author Julius Haertl <jus@bitgrid.net>
  22. * @author Julius Härtl <jus@bitgrid.net>
  23. * @author Lionel Elie Mamane <lionel@mamane.lu>
  24. * @author Lukas Reschke <lukas@statuscode.ch>
  25. * @author Maxence Lange <maxence@artificial-owl.com>
  26. * @author Michael Weimann <mail@michael-weimann.eu>
  27. * @author Morris Jobke <hey@morrisjobke.de>
  28. * @author Piotr Mrówczyński <mrow4a@yahoo.com>
  29. * @author Robin Appelman <robin@icewind.nl>
  30. * @author Robin McCorkell <robin@mccorkell.me.uk>
  31. * @author Roeland Jago Douma <roeland@famdouma.nl>
  32. * @author root <root@localhost.localdomain>
  33. * @author Thomas Müller <thomas.mueller@tmit.eu>
  34. * @author Thomas Tanghus <thomas@tanghus.net>
  35. * @author Tobia De Koninck <tobia@ledfan.be>
  36. * @author Vincent Petry <pvince81@owncloud.com>
  37. * @author Xheni Myrtaj <myrtajxheni@gmail.com>
  38. *
  39. * @license AGPL-3.0
  40. *
  41. * This code is free software: you can redistribute it and/or modify
  42. * it under the terms of the GNU Affero General Public License, version 3,
  43. * as published by the Free Software Foundation.
  44. *
  45. * This program is distributed in the hope that it will be useful,
  46. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  47. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  48. * GNU Affero General Public License for more details.
  49. *
  50. * You should have received a copy of the GNU Affero General Public License, version 3,
  51. * along with this program. If not, see <http://www.gnu.org/licenses/>
  52. *
  53. */
  54. namespace OC;
  55. use bantu\IniGetWrapper\IniGetWrapper;
  56. use OC\Accounts\AccountManager;
  57. use OC\App\AppManager;
  58. use OC\App\AppStore\Bundles\BundleFetcher;
  59. use OC\App\AppStore\Fetcher\AppFetcher;
  60. use OC\App\AppStore\Fetcher\CategoryFetcher;
  61. use OC\AppFramework\Http\Request;
  62. use OC\AppFramework\Utility\SimpleContainer;
  63. use OC\AppFramework\Utility\TimeFactory;
  64. use OC\Authentication\Events\LoginFailed;
  65. use OC\Authentication\Listeners\LoginFailedListener;
  66. use OC\Authentication\Listeners\UserLoggedInListener;
  67. use OC\Authentication\LoginCredentials\Store;
  68. use OC\Authentication\Token\IProvider;
  69. use OC\Avatar\AvatarManager;
  70. use OC\Collaboration\Collaborators\GroupPlugin;
  71. use OC\Collaboration\Collaborators\MailPlugin;
  72. use OC\Collaboration\Collaborators\RemoteGroupPlugin;
  73. use OC\Collaboration\Collaborators\RemotePlugin;
  74. use OC\Collaboration\Collaborators\UserPlugin;
  75. use OC\Command\CronBus;
  76. use OC\Comments\ManagerFactory as CommentsManagerFactory;
  77. use OC\Contacts\ContactsMenu\ActionFactory;
  78. use OC\Contacts\ContactsMenu\ContactsStore;
  79. use OC\Dashboard\DashboardManager;
  80. use OC\Diagnostics\EventLogger;
  81. use OC\Diagnostics\QueryLogger;
  82. use OC\Federation\CloudFederationFactory;
  83. use OC\Federation\CloudFederationProviderManager;
  84. use OC\Federation\CloudIdManager;
  85. use OC\Files\Config\UserMountCache;
  86. use OC\Files\Config\UserMountCacheListener;
  87. use OC\Files\Mount\CacheMountProvider;
  88. use OC\Files\Mount\LocalHomeMountProvider;
  89. use OC\Files\Mount\ObjectHomeMountProvider;
  90. use OC\Files\Mount\ObjectStorePreviewCacheMountProvider;
  91. use OC\Files\Node\HookConnector;
  92. use OC\Files\Node\LazyRoot;
  93. use OC\Files\Node\Root;
  94. use OC\Files\Storage\StorageFactory;
  95. use OC\Files\Type\Loader;
  96. use OC\Files\View;
  97. use OC\FullTextSearch\FullTextSearchManager;
  98. use OC\Http\Client\ClientService;
  99. use OC\IntegrityCheck\Checker;
  100. use OC\IntegrityCheck\Helpers\AppLocator;
  101. use OC\IntegrityCheck\Helpers\EnvironmentHelper;
  102. use OC\IntegrityCheck\Helpers\FileAccessHelper;
  103. use OC\Lock\DBLockingProvider;
  104. use OC\Lock\MemcacheLockingProvider;
  105. use OC\Lock\NoopLockingProvider;
  106. use OC\Lockdown\LockdownManager;
  107. use OC\Log\LogFactory;
  108. use OC\Log\PsrLoggerAdapter;
  109. use OC\Mail\Mailer;
  110. use OC\Memcache\ArrayCache;
  111. use OC\Memcache\Factory;
  112. use OC\Notification\Manager;
  113. use OC\OCS\DiscoveryService;
  114. use OC\Preview\GeneratorHelper;
  115. use OC\Remote\Api\ApiFactory;
  116. use OC\Remote\InstanceFactory;
  117. use OC\RichObjectStrings\Validator;
  118. use OC\Security\Bruteforce\Throttler;
  119. use OC\Security\CertificateManager;
  120. use OC\Security\CredentialsManager;
  121. use OC\Security\Crypto;
  122. use OC\Security\CSP\ContentSecurityPolicyManager;
  123. use OC\Security\CSP\ContentSecurityPolicyNonceManager;
  124. use OC\Security\CSRF\CsrfTokenManager;
  125. use OC\Security\CSRF\TokenStorage\SessionStorage;
  126. use OC\Security\Hasher;
  127. use OC\Security\SecureRandom;
  128. use OC\Security\TrustedDomainHelper;
  129. use OC\Session\CryptoWrapper;
  130. use OC\Share20\ProviderFactory;
  131. use OC\Share20\ShareHelper;
  132. use OC\SystemTag\ManagerFactory as SystemTagManagerFactory;
  133. use OC\Tagging\TagMapper;
  134. use OC\Template\JSCombiner;
  135. use OCA\Theming\ImageManager;
  136. use OCA\Theming\ThemingDefaults;
  137. use OCA\Theming\Util;
  138. use OCP\Accounts\IAccountManager;
  139. use OCP\App\IAppManager;
  140. use OCP\Authentication\LoginCredentials\IStore;
  141. use OCP\BackgroundJob\IJobList;
  142. use OCP\Collaboration\AutoComplete\IManager;
  143. use OCP\Command\IBus;
  144. use OCP\Comments\ICommentsManager;
  145. use OCP\Contacts\ContactsMenu\IActionFactory;
  146. use OCP\Contacts\ContactsMenu\IContactsStore;
  147. use OCP\Dashboard\IDashboardManager;
  148. use OCP\Defaults;
  149. use OCP\Diagnostics\IEventLogger;
  150. use OCP\Diagnostics\IQueryLogger;
  151. use OCP\EventDispatcher\IEventDispatcher;
  152. use OCP\Federation\ICloudFederationFactory;
  153. use OCP\Federation\ICloudFederationProviderManager;
  154. use OCP\Federation\ICloudIdManager;
  155. use OCP\Files\Config\IMountProviderCollection;
  156. use OCP\Files\Config\IUserMountCache;
  157. use OCP\Files\IMimeTypeDetector;
  158. use OCP\Files\IMimeTypeLoader;
  159. use OCP\Files\IRootFolder;
  160. use OCP\Files\Mount\IMountManager;
  161. use OCP\Files\NotFoundException;
  162. use OCP\Files\Storage\IStorageFactory;
  163. use OCP\FullTextSearch\IFullTextSearchManager;
  164. use OCP\GlobalScale\IConfig;
  165. use OCP\Group\Events\BeforeGroupCreatedEvent;
  166. use OCP\Group\Events\BeforeGroupDeletedEvent;
  167. use OCP\Group\Events\BeforeUserAddedEvent;
  168. use OCP\Group\Events\BeforeUserRemovedEvent;
  169. use OCP\Group\Events\GroupCreatedEvent;
  170. use OCP\Group\Events\GroupDeletedEvent;
  171. use OCP\Group\Events\UserAddedEvent;
  172. use OCP\Group\Events\UserRemovedEvent;
  173. use OCP\Group\ISubAdmin;
  174. use OCP\Http\Client\IClientService;
  175. use OCP\IAppConfig;
  176. use OCP\IAvatarManager;
  177. use OCP\ICache;
  178. use OCP\ICacheFactory;
  179. use OCP\IDateTimeFormatter;
  180. use OCP\IDateTimeZone;
  181. use OCP\IDBConnection;
  182. use OCP\IGroupManager;
  183. use OCP\IInitialStateService;
  184. use OCP\IL10N;
  185. use OCP\ILogger;
  186. use OCP\INavigationManager;
  187. use OCP\IPreview;
  188. use OCP\IRequest;
  189. use OCP\ISearch;
  190. use OCP\IServerContainer;
  191. use OCP\ITagManager;
  192. use OCP\ITempManager;
  193. use OCP\IURLGenerator;
  194. use OCP\IUser;
  195. use OCP\IUserManager;
  196. use OCP\IUserSession;
  197. use OCP\L10N\IFactory;
  198. use OCP\Lock\ILockingProvider;
  199. use OCP\Log\ILogFactory;
  200. use OCP\Mail\IMailer;
  201. use OCP\Remote\Api\IApiFactory;
  202. use OCP\Remote\IInstanceFactory;
  203. use OCP\RichObjectStrings\IValidator;
  204. use OCP\Route\IRouter;
  205. use OCP\Security\IContentSecurityPolicyManager;
  206. use OCP\Security\ICredentialsManager;
  207. use OCP\Security\ICrypto;
  208. use OCP\Security\IHasher;
  209. use OCP\Security\ISecureRandom;
  210. use OCP\Share\IShareHelper;
  211. use OCP\SystemTag\ISystemTagManager;
  212. use OCP\SystemTag\ISystemTagObjectMapper;
  213. use OCP\User\Events\BeforePasswordUpdatedEvent;
  214. use OCP\User\Events\BeforeUserCreatedEvent;
  215. use OCP\User\Events\BeforeUserDeletedEvent;
  216. use OCP\User\Events\BeforeUserLoggedInEvent;
  217. use OCP\User\Events\BeforeUserLoggedInWithCookieEvent;
  218. use OCP\User\Events\BeforeUserLoggedOutEvent;
  219. use OCP\User\Events\PasswordUpdatedEvent;
  220. use OCP\User\Events\PostLoginEvent;
  221. use OCP\User\Events\UserChangedEvent;
  222. use OCP\User\Events\UserCreatedEvent;
  223. use OCP\User\Events\UserDeletedEvent;
  224. use OCP\User\Events\UserLoggedInEvent;
  225. use OCP\User\Events\UserLoggedInWithCookieEvent;
  226. use OCP\User\Events\UserLoggedOutEvent;
  227. use Psr\Container\ContainerExceptionInterface;
  228. use Psr\Container\ContainerInterface;
  229. use Psr\Log\LoggerInterface;
  230. use Symfony\Component\EventDispatcher\EventDispatcherInterface;
  231. use Symfony\Component\EventDispatcher\GenericEvent;
  232. use OCA\Files_External\Service\UserStoragesService;
  233. use OCA\Files_External\Service\UserGlobalStoragesService;
  234. use OCA\Files_External\Service\GlobalStoragesService;
  235. use OCA\Files_External\Service\BackendService;
  236. /**
  237. * Class Server
  238. *
  239. * @package OC
  240. *
  241. * TODO: hookup all manager classes
  242. */
  243. class Server extends ServerContainer implements IServerContainer {
  244. /** @var string */
  245. private $webRoot;
  246. /**
  247. * @param string $webRoot
  248. * @param \OC\Config $config
  249. */
  250. public function __construct($webRoot, \OC\Config $config) {
  251. parent::__construct();
  252. $this->webRoot = $webRoot;
  253. // To find out if we are running from CLI or not
  254. $this->registerParameter('isCLI', \OC::$CLI);
  255. $this->registerParameter('serverRoot', \OC::$SERVERROOT);
  256. $this->registerService(ContainerInterface::class, function (ContainerInterface $c) {
  257. return $c;
  258. });
  259. $this->registerService(\OCP\IServerContainer::class, function (ContainerInterface $c) {
  260. return $c;
  261. });
  262. $this->registerAlias(\OCP\Calendar\IManager::class, \OC\Calendar\Manager::class);
  263. /** @deprecated 19.0.0 */
  264. $this->registerDeprecatedAlias('CalendarManager', \OC\Calendar\Manager::class);
  265. $this->registerAlias(\OCP\Calendar\Resource\IManager::class, \OC\Calendar\Resource\Manager::class);
  266. /** @deprecated 19.0.0 */
  267. $this->registerDeprecatedAlias('CalendarResourceBackendManager', \OC\Calendar\Resource\Manager::class);
  268. $this->registerAlias(\OCP\Calendar\Room\IManager::class, \OC\Calendar\Room\Manager::class);
  269. /** @deprecated 19.0.0 */
  270. $this->registerDeprecatedAlias('CalendarRoomBackendManager', \OC\Calendar\Room\Manager::class);
  271. $this->registerAlias(\OCP\Contacts\IManager::class, \OC\ContactsManager::class);
  272. /** @deprecated 19.0.0 */
  273. $this->registerDeprecatedAlias('ContactsManager', \OCP\Contacts\IManager::class);
  274. $this->registerAlias(\OCP\DirectEditing\IManager::class, \OC\DirectEditing\Manager::class);
  275. $this->registerAlias(IActionFactory::class, ActionFactory::class);
  276. $this->registerService(IPreview::class, function (Server $c) {
  277. return new PreviewManager(
  278. $c->getConfig(),
  279. $c->getRootFolder(),
  280. new \OC\Preview\Storage\Root($c->getRootFolder(), $c->getSystemConfig()),
  281. $c->getEventDispatcher(),
  282. $c->getGeneratorHelper(),
  283. $c->getSession()->get('user_id')
  284. );
  285. });
  286. /** @deprecated 19.0.0 */
  287. $this->registerDeprecatedAlias('PreviewManager', IPreview::class);
  288. $this->registerService(\OC\Preview\Watcher::class, function (Server $c) {
  289. return new \OC\Preview\Watcher(
  290. new \OC\Preview\Storage\Root($c->getRootFolder(), $c->getSystemConfig())
  291. );
  292. });
  293. $this->registerService(\OCP\Encryption\IManager::class, function (Server $c) {
  294. $view = new View();
  295. $util = new Encryption\Util(
  296. $view,
  297. $c->getUserManager(),
  298. $c->getGroupManager(),
  299. $c->getConfig()
  300. );
  301. return new Encryption\Manager(
  302. $c->getConfig(),
  303. $c->getLogger(),
  304. $c->getL10N('core'),
  305. new View(),
  306. $util,
  307. new ArrayCache()
  308. );
  309. });
  310. /** @deprecated 19.0.0 */
  311. $this->registerDeprecatedAlias('EncryptionManager', \OCP\Encryption\IManager::class);
  312. $this->registerService('EncryptionFileHelper', function (Server $c) {
  313. $util = new Encryption\Util(
  314. new View(),
  315. $c->getUserManager(),
  316. $c->getGroupManager(),
  317. $c->getConfig()
  318. );
  319. return new Encryption\File(
  320. $util,
  321. $c->getRootFolder(),
  322. $c->getShareManager()
  323. );
  324. });
  325. $this->registerService('EncryptionKeyStorage', function (Server $c) {
  326. $view = new View();
  327. $util = new Encryption\Util(
  328. $view,
  329. $c->getUserManager(),
  330. $c->getGroupManager(),
  331. $c->getConfig()
  332. );
  333. return new Encryption\Keys\Storage($view, $util, $c->getCrypto(), $c->getConfig());
  334. });
  335. /** @deprecated 20.0.0 */
  336. $this->registerDeprecatedAlias('TagMapper', TagMapper::class);
  337. $this->registerAlias(\OCP\ITagManager::class, TagManager::class);
  338. /** @deprecated 19.0.0 */
  339. $this->registerDeprecatedAlias('TagManager', \OCP\ITagManager::class);
  340. $this->registerService('SystemTagManagerFactory', function (Server $c) {
  341. $config = $c->getConfig();
  342. $factoryClass = $config->getSystemValue('systemtags.managerFactory', SystemTagManagerFactory::class);
  343. return new $factoryClass($this);
  344. });
  345. $this->registerService(ISystemTagManager::class, function (Server $c) {
  346. return $c->query('SystemTagManagerFactory')->getManager();
  347. });
  348. /** @deprecated 19.0.0 */
  349. $this->registerDeprecatedAlias('SystemTagManager', ISystemTagManager::class);
  350. $this->registerService(ISystemTagObjectMapper::class, function (Server $c) {
  351. return $c->query('SystemTagManagerFactory')->getObjectMapper();
  352. });
  353. $this->registerService('RootFolder', function (Server $c) {
  354. $manager = \OC\Files\Filesystem::getMountManager(null);
  355. $view = new View();
  356. $root = new Root(
  357. $manager,
  358. $view,
  359. null,
  360. $c->getUserMountCache(),
  361. $this->getLogger(),
  362. $this->getUserManager()
  363. );
  364. $previewConnector = new \OC\Preview\WatcherConnector($root, $c->getSystemConfig());
  365. $previewConnector->connectWatcher();
  366. return $root;
  367. });
  368. $this->registerService(HookConnector::class, function (Server $c) {
  369. return new HookConnector(
  370. $c->query(IRootFolder::class),
  371. new View(),
  372. $c->query(\OC\EventDispatcher\SymfonyAdapter::class),
  373. $c->query(IEventDispatcher::class)
  374. );
  375. });
  376. /** @deprecated 19.0.0 */
  377. $this->registerDeprecatedAlias('SystemTagObjectMapper', ISystemTagObjectMapper::class);
  378. $this->registerService(IRootFolder::class, function (Server $c) {
  379. return new LazyRoot(function () use ($c) {
  380. return $c->query('RootFolder');
  381. });
  382. });
  383. /** @deprecated 19.0.0 */
  384. $this->registerDeprecatedAlias('LazyRootFolder', IRootFolder::class);
  385. /** @deprecated 19.0.0 */
  386. $this->registerDeprecatedAlias('UserManager', \OC\User\Manager::class);
  387. $this->registerAlias(\OCP\IUserManager::class, \OC\User\Manager::class);
  388. $this->registerService(\OCP\IGroupManager::class, function (Server $c) {
  389. $groupManager = new \OC\Group\Manager($this->getUserManager(), $c->getEventDispatcher(), $this->getLogger());
  390. $groupManager->listen('\OC\Group', 'preCreate', function ($gid) {
  391. \OC_Hook::emit('OC_Group', 'pre_createGroup', ['run' => true, 'gid' => $gid]);
  392. /** @var IEventDispatcher $dispatcher */
  393. $dispatcher = $this->query(IEventDispatcher::class);
  394. $dispatcher->dispatchTyped(new BeforeGroupCreatedEvent($gid));
  395. });
  396. $groupManager->listen('\OC\Group', 'postCreate', function (\OC\Group\Group $group) {
  397. \OC_Hook::emit('OC_User', 'post_createGroup', ['gid' => $group->getGID()]);
  398. /** @var IEventDispatcher $dispatcher */
  399. $dispatcher = $this->query(IEventDispatcher::class);
  400. $dispatcher->dispatchTyped(new GroupCreatedEvent($group));
  401. });
  402. $groupManager->listen('\OC\Group', 'preDelete', function (\OC\Group\Group $group) {
  403. \OC_Hook::emit('OC_Group', 'pre_deleteGroup', ['run' => true, 'gid' => $group->getGID()]);
  404. /** @var IEventDispatcher $dispatcher */
  405. $dispatcher = $this->query(IEventDispatcher::class);
  406. $dispatcher->dispatchTyped(new BeforeGroupDeletedEvent($group));
  407. });
  408. $groupManager->listen('\OC\Group', 'postDelete', function (\OC\Group\Group $group) {
  409. \OC_Hook::emit('OC_User', 'post_deleteGroup', ['gid' => $group->getGID()]);
  410. /** @var IEventDispatcher $dispatcher */
  411. $dispatcher = $this->query(IEventDispatcher::class);
  412. $dispatcher->dispatchTyped(new GroupDeletedEvent($group));
  413. });
  414. $groupManager->listen('\OC\Group', 'preAddUser', function (\OC\Group\Group $group, \OC\User\User $user) {
  415. \OC_Hook::emit('OC_Group', 'pre_addToGroup', ['run' => true, 'uid' => $user->getUID(), 'gid' => $group->getGID()]);
  416. /** @var IEventDispatcher $dispatcher */
  417. $dispatcher = $this->query(IEventDispatcher::class);
  418. $dispatcher->dispatchTyped(new BeforeUserAddedEvent($group, $user));
  419. });
  420. $groupManager->listen('\OC\Group', 'postAddUser', function (\OC\Group\Group $group, \OC\User\User $user) {
  421. \OC_Hook::emit('OC_Group', 'post_addToGroup', ['uid' => $user->getUID(), 'gid' => $group->getGID()]);
  422. //Minimal fix to keep it backward compatible TODO: clean up all the GroupManager hooks
  423. \OC_Hook::emit('OC_User', 'post_addToGroup', ['uid' => $user->getUID(), 'gid' => $group->getGID()]);
  424. /** @var IEventDispatcher $dispatcher */
  425. $dispatcher = $this->query(IEventDispatcher::class);
  426. $dispatcher->dispatchTyped(new UserAddedEvent($group, $user));
  427. });
  428. $groupManager->listen('\OC\Group', 'preRemoveUser', function (\OC\Group\Group $group, \OC\User\User $user) {
  429. /** @var IEventDispatcher $dispatcher */
  430. $dispatcher = $this->query(IEventDispatcher::class);
  431. $dispatcher->dispatchTyped(new BeforeUserRemovedEvent($group, $user));
  432. });
  433. $groupManager->listen('\OC\Group', 'postRemoveUser', function (\OC\Group\Group $group, \OC\User\User $user) {
  434. /** @var IEventDispatcher $dispatcher */
  435. $dispatcher = $this->query(IEventDispatcher::class);
  436. $dispatcher->dispatchTyped(new UserRemovedEvent($group, $user));
  437. });
  438. return $groupManager;
  439. });
  440. /** @deprecated 19.0.0 */
  441. $this->registerDeprecatedAlias('GroupManager', \OCP\IGroupManager::class);
  442. $this->registerService(Store::class, function (Server $c) {
  443. $session = $c->getSession();
  444. if (\OC::$server->getSystemConfig()->getValue('installed', false)) {
  445. $tokenProvider = $c->query(IProvider::class);
  446. } else {
  447. $tokenProvider = null;
  448. }
  449. $logger = $c->getLogger();
  450. return new Store($session, $logger, $tokenProvider);
  451. });
  452. $this->registerAlias(IStore::class, Store::class);
  453. $this->registerAlias(IProvider::class, Authentication\Token\Manager::class);
  454. $this->registerService(\OC\User\Session::class, function (Server $c) {
  455. $manager = $c->getUserManager();
  456. $session = new \OC\Session\Memory('');
  457. $timeFactory = new TimeFactory();
  458. // Token providers might require a working database. This code
  459. // might however be called when ownCloud is not yet setup.
  460. if (\OC::$server->getSystemConfig()->getValue('installed', false)) {
  461. $defaultTokenProvider = $c->query(IProvider::class);
  462. } else {
  463. $defaultTokenProvider = null;
  464. }
  465. $legacyDispatcher = $c->getEventDispatcher();
  466. $userSession = new \OC\User\Session(
  467. $manager,
  468. $session,
  469. $timeFactory,
  470. $defaultTokenProvider,
  471. $c->getConfig(),
  472. $c->getSecureRandom(),
  473. $c->getLockdownManager(),
  474. $c->getLogger(),
  475. $c->query(IEventDispatcher::class)
  476. );
  477. $userSession->listen('\OC\User', 'preCreateUser', function ($uid, $password) {
  478. \OC_Hook::emit('OC_User', 'pre_createUser', ['run' => true, 'uid' => $uid, 'password' => $password]);
  479. /** @var IEventDispatcher $dispatcher */
  480. $dispatcher = $this->query(IEventDispatcher::class);
  481. $dispatcher->dispatchTyped(new BeforeUserCreatedEvent($uid, $password));
  482. });
  483. $userSession->listen('\OC\User', 'postCreateUser', function ($user, $password) {
  484. /** @var \OC\User\User $user */
  485. \OC_Hook::emit('OC_User', 'post_createUser', ['uid' => $user->getUID(), 'password' => $password]);
  486. /** @var IEventDispatcher $dispatcher */
  487. $dispatcher = $this->query(IEventDispatcher::class);
  488. $dispatcher->dispatchTyped(new UserCreatedEvent($user, $password));
  489. });
  490. $userSession->listen('\OC\User', 'preDelete', function ($user) use ($legacyDispatcher) {
  491. /** @var \OC\User\User $user */
  492. \OC_Hook::emit('OC_User', 'pre_deleteUser', ['run' => true, 'uid' => $user->getUID()]);
  493. $legacyDispatcher->dispatch('OCP\IUser::preDelete', new GenericEvent($user));
  494. /** @var IEventDispatcher $dispatcher */
  495. $dispatcher = $this->query(IEventDispatcher::class);
  496. $dispatcher->dispatchTyped(new BeforeUserDeletedEvent($user));
  497. });
  498. $userSession->listen('\OC\User', 'postDelete', function ($user) {
  499. /** @var \OC\User\User $user */
  500. \OC_Hook::emit('OC_User', 'post_deleteUser', ['uid' => $user->getUID()]);
  501. /** @var IEventDispatcher $dispatcher */
  502. $dispatcher = $this->query(IEventDispatcher::class);
  503. $dispatcher->dispatchTyped(new UserDeletedEvent($user));
  504. });
  505. $userSession->listen('\OC\User', 'preSetPassword', function ($user, $password, $recoveryPassword) {
  506. /** @var \OC\User\User $user */
  507. \OC_Hook::emit('OC_User', 'pre_setPassword', ['run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword]);
  508. /** @var IEventDispatcher $dispatcher */
  509. $dispatcher = $this->query(IEventDispatcher::class);
  510. $dispatcher->dispatchTyped(new BeforePasswordUpdatedEvent($user, $password, $recoveryPassword));
  511. });
  512. $userSession->listen('\OC\User', 'postSetPassword', function ($user, $password, $recoveryPassword) {
  513. /** @var \OC\User\User $user */
  514. \OC_Hook::emit('OC_User', 'post_setPassword', ['run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword]);
  515. /** @var IEventDispatcher $dispatcher */
  516. $dispatcher = $this->query(IEventDispatcher::class);
  517. $dispatcher->dispatchTyped(new PasswordUpdatedEvent($user, $password, $recoveryPassword));
  518. });
  519. $userSession->listen('\OC\User', 'preLogin', function ($uid, $password) {
  520. \OC_Hook::emit('OC_User', 'pre_login', ['run' => true, 'uid' => $uid, 'password' => $password]);
  521. /** @var IEventDispatcher $dispatcher */
  522. $dispatcher = $this->query(IEventDispatcher::class);
  523. $dispatcher->dispatchTyped(new BeforeUserLoggedInEvent($uid, $password));
  524. });
  525. $userSession->listen('\OC\User', 'postLogin', function ($user, $loginName, $password, $isTokenLogin) {
  526. /** @var \OC\User\User $user */
  527. \OC_Hook::emit('OC_User', 'post_login', ['run' => true, 'uid' => $user->getUID(), 'loginName' => $loginName, 'password' => $password, 'isTokenLogin' => $isTokenLogin]);
  528. /** @var IEventDispatcher $dispatcher */
  529. $dispatcher = $this->query(IEventDispatcher::class);
  530. $dispatcher->dispatchTyped(new UserLoggedInEvent($user, $password, $isTokenLogin));
  531. });
  532. $userSession->listen('\OC\User', 'preRememberedLogin', function ($uid) {
  533. /** @var IEventDispatcher $dispatcher */
  534. $dispatcher = $this->query(IEventDispatcher::class);
  535. $dispatcher->dispatchTyped(new BeforeUserLoggedInWithCookieEvent($uid));
  536. });
  537. $userSession->listen('\OC\User', 'postRememberedLogin', function ($user, $password) {
  538. /** @var \OC\User\User $user */
  539. \OC_Hook::emit('OC_User', 'post_login', ['run' => true, 'uid' => $user->getUID(), 'password' => $password]);
  540. /** @var IEventDispatcher $dispatcher */
  541. $dispatcher = $this->query(IEventDispatcher::class);
  542. $dispatcher->dispatchTyped(new UserLoggedInWithCookieEvent($user, $password));
  543. });
  544. $userSession->listen('\OC\User', 'logout', function ($user) {
  545. \OC_Hook::emit('OC_User', 'logout', []);
  546. /** @var IEventDispatcher $dispatcher */
  547. $dispatcher = $this->query(IEventDispatcher::class);
  548. $dispatcher->dispatchTyped(new BeforeUserLoggedOutEvent($user));
  549. });
  550. $userSession->listen('\OC\User', 'postLogout', function ($user) {
  551. /** @var IEventDispatcher $dispatcher */
  552. $dispatcher = $this->query(IEventDispatcher::class);
  553. $dispatcher->dispatchTyped(new UserLoggedOutEvent($user));
  554. });
  555. $userSession->listen('\OC\User', 'changeUser', function ($user, $feature, $value, $oldValue) {
  556. /** @var \OC\User\User $user */
  557. \OC_Hook::emit('OC_User', 'changeUser', ['run' => true, 'user' => $user, 'feature' => $feature, 'value' => $value, 'old_value' => $oldValue]);
  558. /** @var IEventDispatcher $dispatcher */
  559. $dispatcher = $this->query(IEventDispatcher::class);
  560. $dispatcher->dispatchTyped(new UserChangedEvent($user, $feature, $value, $oldValue));
  561. });
  562. return $userSession;
  563. });
  564. $this->registerAlias(\OCP\IUserSession::class, \OC\User\Session::class);
  565. /** @deprecated 19.0.0 */
  566. $this->registerDeprecatedAlias('UserSession', \OC\User\Session::class);
  567. $this->registerAlias(\OCP\Authentication\TwoFactorAuth\IRegistry::class, \OC\Authentication\TwoFactorAuth\Registry::class);
  568. $this->registerAlias(INavigationManager::class, \OC\NavigationManager::class);
  569. /** @deprecated 19.0.0 */
  570. $this->registerDeprecatedAlias('NavigationManager', INavigationManager::class);
  571. /** @deprecated 19.0.0 */
  572. $this->registerDeprecatedAlias('AllConfig', \OC\AllConfig::class);
  573. $this->registerAlias(\OCP\IConfig::class, \OC\AllConfig::class);
  574. $this->registerService(\OC\SystemConfig::class, function ($c) use ($config) {
  575. return new \OC\SystemConfig($config);
  576. });
  577. /** @deprecated 19.0.0 */
  578. $this->registerDeprecatedAlias('SystemConfig', \OC\SystemConfig::class);
  579. /** @deprecated 19.0.0 */
  580. $this->registerDeprecatedAlias('AppConfig', \OC\AppConfig::class);
  581. $this->registerAlias(IAppConfig::class, \OC\AppConfig::class);
  582. $this->registerService(IFactory::class, function (Server $c) {
  583. return new \OC\L10N\Factory(
  584. $c->getConfig(),
  585. $c->getRequest(),
  586. $c->getUserSession(),
  587. \OC::$SERVERROOT
  588. );
  589. });
  590. /** @deprecated 19.0.0 */
  591. $this->registerDeprecatedAlias('L10NFactory', IFactory::class);
  592. $this->registerAlias(IURLGenerator::class, URLGenerator::class);
  593. /** @deprecated 19.0.0 */
  594. $this->registerDeprecatedAlias('URLGenerator', IURLGenerator::class);
  595. /** @deprecated 19.0.0 */
  596. $this->registerDeprecatedAlias('AppFetcher', AppFetcher::class);
  597. /** @deprecated 19.0.0 */
  598. $this->registerDeprecatedAlias('CategoryFetcher', CategoryFetcher::class);
  599. $this->registerService(ICache::class, function ($c) {
  600. return new Cache\File();
  601. });
  602. /** @deprecated 19.0.0 */
  603. $this->registerDeprecatedAlias('UserCache', ICache::class);
  604. $this->registerService(Factory::class, function (Server $c) {
  605. $arrayCacheFactory = new \OC\Memcache\Factory('', $c->getLogger(),
  606. ArrayCache::class,
  607. ArrayCache::class,
  608. ArrayCache::class
  609. );
  610. $config = $c->getConfig();
  611. if ($config->getSystemValue('installed', false) && !(defined('PHPUNIT_RUN') && PHPUNIT_RUN)) {
  612. $v = \OC_App::getAppVersions();
  613. $v['core'] = implode(',', \OC_Util::getVersion());
  614. $version = implode(',', $v);
  615. $instanceId = \OC_Util::getInstanceId();
  616. $path = \OC::$SERVERROOT;
  617. $prefix = md5($instanceId . '-' . $version . '-' . $path);
  618. return new \OC\Memcache\Factory($prefix, $c->getLogger(),
  619. $config->getSystemValue('memcache.local', null),
  620. $config->getSystemValue('memcache.distributed', null),
  621. $config->getSystemValue('memcache.locking', null)
  622. );
  623. }
  624. return $arrayCacheFactory;
  625. });
  626. /** @deprecated 19.0.0 */
  627. $this->registerDeprecatedAlias('MemCacheFactory', Factory::class);
  628. $this->registerAlias(ICacheFactory::class, Factory::class);
  629. $this->registerService('RedisFactory', function (Server $c) {
  630. $systemConfig = $c->getSystemConfig();
  631. return new RedisFactory($systemConfig);
  632. });
  633. $this->registerService(\OCP\Activity\IManager::class, function (Server $c) {
  634. $l10n = $this->get(IFactory::class)->get('activity');
  635. return new \OC\Activity\Manager(
  636. $c->getRequest(),
  637. $c->getUserSession(),
  638. $c->getConfig(),
  639. $c->query(IValidator::class),
  640. $l10n
  641. );
  642. });
  643. /** @deprecated 19.0.0 */
  644. $this->registerDeprecatedAlias('ActivityManager', \OCP\Activity\IManager::class);
  645. $this->registerService(\OCP\Activity\IEventMerger::class, function (Server $c) {
  646. return new \OC\Activity\EventMerger(
  647. $c->getL10N('lib')
  648. );
  649. });
  650. $this->registerAlias(IValidator::class, Validator::class);
  651. $this->registerService(AvatarManager::class, function (Server $c) {
  652. return new AvatarManager(
  653. $c->query(\OC\User\Manager::class),
  654. $c->getAppDataDir('avatar'),
  655. $c->getL10N('lib'),
  656. $c->getLogger(),
  657. $c->getConfig()
  658. );
  659. });
  660. $this->registerAlias(IAvatarManager::class, AvatarManager::class);
  661. /** @deprecated 19.0.0 */
  662. $this->registerDeprecatedAlias('AvatarManager', AvatarManager::class);
  663. $this->registerAlias(\OCP\Support\CrashReport\IRegistry::class, \OC\Support\CrashReport\Registry::class);
  664. $this->registerAlias(\OCP\Support\Subscription\IRegistry::class, \OC\Support\Subscription\Registry::class);
  665. $this->registerService(\OC\Log::class, function (Server $c) {
  666. $logType = $c->query(AllConfig::class)->getSystemValue('log_type', 'file');
  667. $factory = new LogFactory($c, $this->getSystemConfig());
  668. $logger = $factory->get($logType);
  669. $registry = $c->query(\OCP\Support\CrashReport\IRegistry::class);
  670. return new Log($logger, $this->getSystemConfig(), null, $registry);
  671. });
  672. $this->registerAlias(ILogger::class, \OC\Log::class);
  673. /** @deprecated 19.0.0 */
  674. $this->registerDeprecatedAlias('Logger', \OC\Log::class);
  675. // PSR-3 logger
  676. $this->registerAlias(LoggerInterface::class, PsrLoggerAdapter::class);
  677. $this->registerService(ILogFactory::class, function (Server $c) {
  678. return new LogFactory($c, $this->getSystemConfig());
  679. });
  680. $this->registerAlias(IJobList::class, \OC\BackgroundJob\JobList::class);
  681. /** @deprecated 19.0.0 */
  682. $this->registerDeprecatedAlias('JobList', IJobList::class);
  683. $this->registerService(IRouter::class, function (Server $c) {
  684. $cacheFactory = $c->getMemCacheFactory();
  685. $logger = $c->getLogger();
  686. if ($cacheFactory->isLocalCacheAvailable()) {
  687. $router = new \OC\Route\CachingRouter($cacheFactory->createLocal('route'), $logger);
  688. } else {
  689. $router = new \OC\Route\Router($logger);
  690. }
  691. return $router;
  692. });
  693. /** @deprecated 19.0.0 */
  694. $this->registerDeprecatedAlias('Router', IRouter::class);
  695. $this->registerAlias(ISearch::class, Search::class);
  696. /** @deprecated 19.0.0 */
  697. $this->registerDeprecatedAlias('Search', ISearch::class);
  698. $this->registerService(\OC\Security\RateLimiting\Backend\IBackend::class, function ($c) {
  699. return new \OC\Security\RateLimiting\Backend\MemoryCache(
  700. $this->getMemCacheFactory(),
  701. new \OC\AppFramework\Utility\TimeFactory()
  702. );
  703. });
  704. $this->registerAlias(\OCP\Security\ISecureRandom::class, SecureRandom::class);
  705. /** @deprecated 19.0.0 */
  706. $this->registerDeprecatedAlias('SecureRandom', \OCP\Security\ISecureRandom::class);
  707. $this->registerAlias(ICrypto::class, Crypto::class);
  708. /** @deprecated 19.0.0 */
  709. $this->registerDeprecatedAlias('Crypto', ICrypto::class);
  710. $this->registerAlias(IHasher::class, Hasher::class);
  711. /** @deprecated 19.0.0 */
  712. $this->registerDeprecatedAlias('Hasher', IHasher::class);
  713. $this->registerAlias(ICredentialsManager::class, CredentialsManager::class);
  714. /** @deprecated 19.0.0 */
  715. $this->registerDeprecatedAlias('CredentialsManager', ICredentialsManager::class);
  716. $this->registerService(IDBConnection::class, function (Server $c) {
  717. $systemConfig = $c->getSystemConfig();
  718. $factory = new \OC\DB\ConnectionFactory($systemConfig);
  719. $type = $systemConfig->getValue('dbtype', 'sqlite');
  720. if (!$factory->isValidType($type)) {
  721. throw new \OC\DatabaseException('Invalid database type');
  722. }
  723. $connectionParams = $factory->createConnectionParams();
  724. $connection = $factory->getConnection($type, $connectionParams);
  725. $connection->getConfiguration()->setSQLLogger($c->getQueryLogger());
  726. return $connection;
  727. });
  728. /** @deprecated 19.0.0 */
  729. $this->registerDeprecatedAlias('DatabaseConnection', IDBConnection::class);
  730. $this->registerService(IClientService::class, function (Server $c) {
  731. $user = \OC_User::getUser();
  732. $uid = $user ? $user : null;
  733. return new ClientService(
  734. $c->getConfig(),
  735. $c->getLogger(),
  736. new \OC\Security\CertificateManager(
  737. $uid,
  738. new View(),
  739. $c->getConfig(),
  740. $c->getLogger(),
  741. $c->getSecureRandom()
  742. )
  743. );
  744. });
  745. /** @deprecated 19.0.0 */
  746. $this->registerDeprecatedAlias('HttpClientService', IClientService::class);
  747. $this->registerService(IEventLogger::class, function (Server $c) {
  748. $eventLogger = new EventLogger();
  749. if ($c->getSystemConfig()->getValue('debug', false)) {
  750. // In debug mode, module is being activated by default
  751. $eventLogger->activate();
  752. }
  753. return $eventLogger;
  754. });
  755. /** @deprecated 19.0.0 */
  756. $this->registerDeprecatedAlias('EventLogger', IEventLogger::class);
  757. $this->registerService(IQueryLogger::class, function (Server $c) {
  758. $queryLogger = new QueryLogger();
  759. if ($c->getSystemConfig()->getValue('debug', false)) {
  760. // In debug mode, module is being activated by default
  761. $queryLogger->activate();
  762. }
  763. return $queryLogger;
  764. });
  765. /** @deprecated 19.0.0 */
  766. $this->registerDeprecatedAlias('QueryLogger', IQueryLogger::class);
  767. /** @deprecated 19.0.0 */
  768. $this->registerDeprecatedAlias('TempManager', TempManager::class);
  769. $this->registerAlias(ITempManager::class, TempManager::class);
  770. $this->registerService(AppManager::class, function (Server $c) {
  771. return new \OC\App\AppManager(
  772. $c->getUserSession(),
  773. $c->getConfig(),
  774. $c->query(\OC\AppConfig::class),
  775. $c->getGroupManager(),
  776. $c->getMemCacheFactory(),
  777. $c->getEventDispatcher(),
  778. $c->getLogger()
  779. );
  780. });
  781. /** @deprecated 19.0.0 */
  782. $this->registerDeprecatedAlias('AppManager', AppManager::class);
  783. $this->registerAlias(IAppManager::class, AppManager::class);
  784. $this->registerAlias(IDateTimeZone::class, DateTimeZone::class);
  785. /** @deprecated 19.0.0 */
  786. $this->registerDeprecatedAlias('DateTimeZone', IDateTimeZone::class);
  787. $this->registerService(IDateTimeFormatter::class, function (Server $c) {
  788. $language = $c->getConfig()->getUserValue($c->getSession()->get('user_id'), 'core', 'lang', null);
  789. return new DateTimeFormatter(
  790. $c->getDateTimeZone()->getTimeZone(),
  791. $c->getL10N('lib', $language)
  792. );
  793. });
  794. /** @deprecated 19.0.0 */
  795. $this->registerDeprecatedAlias('DateTimeFormatter', IDateTimeFormatter::class);
  796. $this->registerService(IUserMountCache::class, function (Server $c) {
  797. $mountCache = new UserMountCache($c->getDatabaseConnection(), $c->getUserManager(), $c->getLogger());
  798. $listener = new UserMountCacheListener($mountCache);
  799. $listener->listen($c->getUserManager());
  800. return $mountCache;
  801. });
  802. /** @deprecated 19.0.0 */
  803. $this->registerDeprecatedAlias('UserMountCache', IUserMountCache::class);
  804. $this->registerService(IMountProviderCollection::class, function (Server $c) {
  805. $loader = \OC\Files\Filesystem::getLoader();
  806. $mountCache = $c->query(IUserMountCache::class);
  807. $manager = new \OC\Files\Config\MountProviderCollection($loader, $mountCache);
  808. // builtin providers
  809. $config = $c->getConfig();
  810. $logger = $c->getLogger();
  811. $manager->registerProvider(new CacheMountProvider($config));
  812. $manager->registerHomeProvider(new LocalHomeMountProvider());
  813. $manager->registerHomeProvider(new ObjectHomeMountProvider($config));
  814. $manager->registerRootProvider(new ObjectStorePreviewCacheMountProvider($logger, $config));
  815. return $manager;
  816. });
  817. /** @deprecated 19.0.0 */
  818. $this->registerDeprecatedAlias('MountConfigManager', IMountProviderCollection::class);
  819. /** @deprecated 20.0.0 */
  820. $this->registerDeprecatedAlias('IniWrapper', IniGetWrapper::class);
  821. $this->registerService('AsyncCommandBus', function (Server $c) {
  822. $busClass = $c->getConfig()->getSystemValue('commandbus');
  823. if ($busClass) {
  824. [$app, $class] = explode('::', $busClass, 2);
  825. if ($c->getAppManager()->isInstalled($app)) {
  826. \OC_App::loadApp($app);
  827. return $c->query($class);
  828. } else {
  829. throw new ServiceUnavailableException("The app providing the command bus ($app) is not enabled");
  830. }
  831. } else {
  832. $jobList = $c->getJobList();
  833. return new CronBus($jobList);
  834. }
  835. });
  836. $this->registerAlias(IBus::class, 'AsyncCommandBus');
  837. /** @deprecated 20.0.0 */
  838. $this->registerDeprecatedAlias('TrustedDomainHelper', TrustedDomainHelper::class);
  839. /** @deprecated 19.0.0 */
  840. $this->registerDeprecatedAlias('Throttler', Throttler::class);
  841. $this->registerService('IntegrityCodeChecker', function (Server $c) {
  842. // IConfig and IAppManager requires a working database. This code
  843. // might however be called when ownCloud is not yet setup.
  844. if (\OC::$server->getSystemConfig()->getValue('installed', false)) {
  845. $config = $c->getConfig();
  846. $appManager = $c->getAppManager();
  847. } else {
  848. $config = null;
  849. $appManager = null;
  850. }
  851. return new Checker(
  852. new EnvironmentHelper(),
  853. new FileAccessHelper(),
  854. new AppLocator(),
  855. $config,
  856. $c->getMemCacheFactory(),
  857. $appManager,
  858. $c->getTempManager(),
  859. $c->getMimeTypeDetector()
  860. );
  861. });
  862. $this->registerService(\OCP\IRequest::class, function ($c) {
  863. if (isset($this['urlParams'])) {
  864. $urlParams = $this['urlParams'];
  865. } else {
  866. $urlParams = [];
  867. }
  868. if (defined('PHPUNIT_RUN') && PHPUNIT_RUN
  869. && in_array('fakeinput', stream_get_wrappers())
  870. ) {
  871. $stream = 'fakeinput://data';
  872. } else {
  873. $stream = 'php://input';
  874. }
  875. return new Request(
  876. [
  877. 'get' => $_GET,
  878. 'post' => $_POST,
  879. 'files' => $_FILES,
  880. 'server' => $_SERVER,
  881. 'env' => $_ENV,
  882. 'cookies' => $_COOKIE,
  883. 'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD']))
  884. ? $_SERVER['REQUEST_METHOD']
  885. : '',
  886. 'urlParams' => $urlParams,
  887. ],
  888. $this->getSecureRandom(),
  889. $this->getConfig(),
  890. $this->getCsrfTokenManager(),
  891. $stream
  892. );
  893. });
  894. /** @deprecated 19.0.0 */
  895. $this->registerDeprecatedAlias('Request', \OCP\IRequest::class);
  896. $this->registerService(IMailer::class, function (Server $c) {
  897. return new Mailer(
  898. $c->getConfig(),
  899. $c->getLogger(),
  900. $c->query(Defaults::class),
  901. $c->getURLGenerator(),
  902. $c->getL10N('lib'),
  903. $c->query(IEventDispatcher::class),
  904. $c->getL10NFactory()
  905. );
  906. });
  907. /** @deprecated 19.0.0 */
  908. $this->registerDeprecatedAlias('Mailer', IMailer::class);
  909. $this->registerService('LDAPProvider', function (Server $c) {
  910. $config = $c->getConfig();
  911. $factoryClass = $config->getSystemValue('ldapProviderFactory', null);
  912. if (is_null($factoryClass)) {
  913. throw new \Exception('ldapProviderFactory not set');
  914. }
  915. /** @var \OCP\LDAP\ILDAPProviderFactory $factory */
  916. $factory = new $factoryClass($this);
  917. return $factory->getLDAPProvider();
  918. });
  919. $this->registerService(ILockingProvider::class, function (Server $c) {
  920. $ini = $c->get(IniGetWrapper::class);
  921. $config = $c->getConfig();
  922. $ttl = $config->getSystemValue('filelocking.ttl', max(3600, $ini->getNumeric('max_execution_time')));
  923. if ($config->getSystemValue('filelocking.enabled', true) or (defined('PHPUNIT_RUN') && PHPUNIT_RUN)) {
  924. /** @var \OC\Memcache\Factory $memcacheFactory */
  925. $memcacheFactory = $c->getMemCacheFactory();
  926. $memcache = $memcacheFactory->createLocking('lock');
  927. if (!($memcache instanceof \OC\Memcache\NullCache)) {
  928. return new MemcacheLockingProvider($memcache, $ttl);
  929. }
  930. return new DBLockingProvider(
  931. $c->getDatabaseConnection(),
  932. $c->getLogger(),
  933. new TimeFactory(),
  934. $ttl,
  935. !\OC::$CLI
  936. );
  937. }
  938. return new NoopLockingProvider();
  939. });
  940. /** @deprecated 19.0.0 */
  941. $this->registerDeprecatedAlias('LockingProvider', ILockingProvider::class);
  942. $this->registerAlias(IMountManager::class, \OC\Files\Mount\Manager::class);
  943. /** @deprecated 19.0.0 */
  944. $this->registerDeprecatedAlias('MountManager', IMountManager::class);
  945. $this->registerService(IMimeTypeDetector::class, function (Server $c) {
  946. return new \OC\Files\Type\Detection(
  947. $c->getURLGenerator(),
  948. $c->getLogger(),
  949. \OC::$configDir,
  950. \OC::$SERVERROOT . '/resources/config/'
  951. );
  952. });
  953. /** @deprecated 19.0.0 */
  954. $this->registerDeprecatedAlias('MimeTypeDetector', IMimeTypeDetector::class);
  955. $this->registerAlias(IMimeTypeLoader::class, Loader::class);
  956. /** @deprecated 19.0.0 */
  957. $this->registerDeprecatedAlias('MimeTypeLoader', IMimeTypeLoader::class);
  958. $this->registerService(BundleFetcher::class, function () {
  959. return new BundleFetcher($this->getL10N('lib'));
  960. });
  961. $this->registerAlias(\OCP\Notification\IManager::class, Manager::class);
  962. /** @deprecated 19.0.0 */
  963. $this->registerDeprecatedAlias('NotificationManager', \OCP\Notification\IManager::class);
  964. $this->registerService(CapabilitiesManager::class, function (Server $c) {
  965. $manager = new CapabilitiesManager($c->getLogger());
  966. $manager->registerCapability(function () use ($c) {
  967. return new \OC\OCS\CoreCapabilities($c->getConfig());
  968. });
  969. $manager->registerCapability(function () use ($c) {
  970. return $c->query(\OC\Security\Bruteforce\Capabilities::class);
  971. });
  972. return $manager;
  973. });
  974. /** @deprecated 19.0.0 */
  975. $this->registerDeprecatedAlias('CapabilitiesManager', CapabilitiesManager::class);
  976. $this->registerService(ICommentsManager::class, function (Server $c) {
  977. $config = $c->getConfig();
  978. $factoryClass = $config->getSystemValue('comments.managerFactory', CommentsManagerFactory::class);
  979. /** @var \OCP\Comments\ICommentsManagerFactory $factory */
  980. $factory = new $factoryClass($this);
  981. $manager = $factory->getManager();
  982. $manager->registerDisplayNameResolver('user', function ($id) use ($c) {
  983. $manager = $c->getUserManager();
  984. $user = $manager->get($id);
  985. if (is_null($user)) {
  986. $l = $c->getL10N('core');
  987. $displayName = $l->t('Unknown user');
  988. } else {
  989. $displayName = $user->getDisplayName();
  990. }
  991. return $displayName;
  992. });
  993. return $manager;
  994. });
  995. /** @deprecated 19.0.0 */
  996. $this->registerDeprecatedAlias('CommentsManager', ICommentsManager::class);
  997. $this->registerAlias(\OC_Defaults::class, 'ThemingDefaults');
  998. $this->registerService('ThemingDefaults', function (Server $c) {
  999. /*
  1000. * Dark magic for autoloader.
  1001. * If we do a class_exists it will try to load the class which will
  1002. * make composer cache the result. Resulting in errors when enabling
  1003. * the theming app.
  1004. */
  1005. $prefixes = \OC::$composerAutoloader->getPrefixesPsr4();
  1006. if (isset($prefixes['OCA\\Theming\\'])) {
  1007. $classExists = true;
  1008. } else {
  1009. $classExists = false;
  1010. }
  1011. if ($classExists && $c->getConfig()->getSystemValue('installed', false) && $c->getAppManager()->isInstalled('theming') && $c->getTrustedDomainHelper()->isTrustedDomain($c->getRequest()->getInsecureServerHost())) {
  1012. return new ThemingDefaults(
  1013. $c->getConfig(),
  1014. $c->getL10N('theming'),
  1015. $c->getURLGenerator(),
  1016. $c->getMemCacheFactory(),
  1017. new Util($c->getConfig(), $this->getAppManager(), $c->getAppDataDir('theming')),
  1018. new ImageManager($c->getConfig(), $c->getAppDataDir('theming'), $c->getURLGenerator(), $this->getMemCacheFactory(), $this->getLogger()),
  1019. $c->getAppManager(),
  1020. $c->getNavigationManager()
  1021. );
  1022. }
  1023. return new \OC_Defaults();
  1024. });
  1025. $this->registerService(JSCombiner::class, function (Server $c) {
  1026. return new JSCombiner(
  1027. $c->getAppDataDir('js'),
  1028. $c->getURLGenerator(),
  1029. $this->getMemCacheFactory(),
  1030. $c->getSystemConfig(),
  1031. $c->getLogger()
  1032. );
  1033. });
  1034. $this->registerAlias(\OCP\EventDispatcher\IEventDispatcher::class, \OC\EventDispatcher\EventDispatcher::class);
  1035. /** @deprecated 19.0.0 */
  1036. $this->registerDeprecatedAlias('EventDispatcher', \OC\EventDispatcher\SymfonyAdapter::class);
  1037. $this->registerAlias(EventDispatcherInterface::class, \OC\EventDispatcher\SymfonyAdapter::class);
  1038. $this->registerService('CryptoWrapper', function (Server $c) {
  1039. // FIXME: Instantiiated here due to cyclic dependency
  1040. $request = new Request(
  1041. [
  1042. 'get' => $_GET,
  1043. 'post' => $_POST,
  1044. 'files' => $_FILES,
  1045. 'server' => $_SERVER,
  1046. 'env' => $_ENV,
  1047. 'cookies' => $_COOKIE,
  1048. 'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD']))
  1049. ? $_SERVER['REQUEST_METHOD']
  1050. : null,
  1051. ],
  1052. $c->getSecureRandom(),
  1053. $c->getConfig()
  1054. );
  1055. return new CryptoWrapper(
  1056. $c->getConfig(),
  1057. $c->getCrypto(),
  1058. $c->getSecureRandom(),
  1059. $request
  1060. );
  1061. });
  1062. /** @deprecated 19.0.0 */
  1063. $this->registerDeprecatedAlias('CsrfTokenManager', CsrfTokenManager::class);
  1064. $this->registerService(SessionStorage::class, function (Server $c) {
  1065. return new SessionStorage($c->getSession());
  1066. });
  1067. $this->registerAlias(\OCP\Security\IContentSecurityPolicyManager::class, ContentSecurityPolicyManager::class);
  1068. /** @deprecated 19.0.0 */
  1069. $this->registerDeprecatedAlias('ContentSecurityPolicyManager', ContentSecurityPolicyManager::class);
  1070. $this->registerService(\OCP\Share\IManager::class, function (Server $c) {
  1071. $config = $c->getConfig();
  1072. $factoryClass = $config->getSystemValue('sharing.managerFactory', ProviderFactory::class);
  1073. /** @var \OCP\Share\IProviderFactory $factory */
  1074. $factory = new $factoryClass($this);
  1075. $manager = new \OC\Share20\Manager(
  1076. $c->getLogger(),
  1077. $c->getConfig(),
  1078. $c->getSecureRandom(),
  1079. $c->getHasher(),
  1080. $c->getMountManager(),
  1081. $c->getGroupManager(),
  1082. $c->getL10N('lib'),
  1083. $c->getL10NFactory(),
  1084. $factory,
  1085. $c->getUserManager(),
  1086. $c->getLazyRootFolder(),
  1087. $c->getEventDispatcher(),
  1088. $c->getMailer(),
  1089. $c->getURLGenerator(),
  1090. $c->getThemingDefaults(),
  1091. $c->query(IEventDispatcher::class)
  1092. );
  1093. return $manager;
  1094. });
  1095. /** @deprecated 19.0.0 */
  1096. $this->registerDeprecatedAlias('ShareManager', \OCP\Share\IManager::class);
  1097. $this->registerService(\OCP\Collaboration\Collaborators\ISearch::class, function (Server $c) {
  1098. $instance = new Collaboration\Collaborators\Search($c);
  1099. // register default plugins
  1100. $instance->registerPlugin(['shareType' => 'SHARE_TYPE_USER', 'class' => UserPlugin::class]);
  1101. $instance->registerPlugin(['shareType' => 'SHARE_TYPE_GROUP', 'class' => GroupPlugin::class]);
  1102. $instance->registerPlugin(['shareType' => 'SHARE_TYPE_EMAIL', 'class' => MailPlugin::class]);
  1103. $instance->registerPlugin(['shareType' => 'SHARE_TYPE_REMOTE', 'class' => RemotePlugin::class]);
  1104. $instance->registerPlugin(['shareType' => 'SHARE_TYPE_REMOTE_GROUP', 'class' => RemoteGroupPlugin::class]);
  1105. return $instance;
  1106. });
  1107. /** @deprecated 19.0.0 */
  1108. $this->registerDeprecatedAlias('CollaboratorSearch', \OCP\Collaboration\Collaborators\ISearch::class);
  1109. $this->registerAlias(\OCP\Collaboration\Collaborators\ISearchResult::class, \OC\Collaboration\Collaborators\SearchResult::class);
  1110. $this->registerAlias(\OCP\Collaboration\AutoComplete\IManager::class, \OC\Collaboration\AutoComplete\Manager::class);
  1111. $this->registerAlias(\OCP\Collaboration\Resources\IProviderManager::class, \OC\Collaboration\Resources\ProviderManager::class);
  1112. $this->registerAlias(\OCP\Collaboration\Resources\IManager::class, \OC\Collaboration\Resources\Manager::class);
  1113. $this->registerDeprecatedAlias('SettingsManager', \OC\Settings\Manager::class);
  1114. $this->registerAlias(\OCP\Settings\IManager::class, \OC\Settings\Manager::class);
  1115. $this->registerService(\OC\Files\AppData\Factory::class, function (Server $c) {
  1116. return new \OC\Files\AppData\Factory(
  1117. $c->getRootFolder(),
  1118. $c->getSystemConfig()
  1119. );
  1120. });
  1121. $this->registerService('LockdownManager', function (Server $c) {
  1122. return new LockdownManager(function () use ($c) {
  1123. return $c->getSession();
  1124. });
  1125. });
  1126. $this->registerService(\OCP\OCS\IDiscoveryService::class, function (Server $c) {
  1127. return new DiscoveryService($c->getMemCacheFactory(), $c->getHTTPClientService());
  1128. });
  1129. $this->registerService(ICloudIdManager::class, function (Server $c) {
  1130. return new CloudIdManager();
  1131. });
  1132. $this->registerAlias(\OCP\GlobalScale\IConfig::class, \OC\GlobalScale\Config::class);
  1133. $this->registerService(ICloudFederationProviderManager::class, function (Server $c) {
  1134. return new CloudFederationProviderManager($c->getAppManager(), $c->getHTTPClientService(), $c->getCloudIdManager(), $c->getLogger());
  1135. });
  1136. $this->registerService(ICloudFederationFactory::class, function (Server $c) {
  1137. return new CloudFederationFactory();
  1138. });
  1139. $this->registerAlias(\OCP\AppFramework\Utility\IControllerMethodReflector::class, \OC\AppFramework\Utility\ControllerMethodReflector::class);
  1140. /** @deprecated 19.0.0 */
  1141. $this->registerDeprecatedAlias('ControllerMethodReflector', \OCP\AppFramework\Utility\IControllerMethodReflector::class);
  1142. $this->registerAlias(\OCP\AppFramework\Utility\ITimeFactory::class, \OC\AppFramework\Utility\TimeFactory::class);
  1143. /** @deprecated 19.0.0 */
  1144. $this->registerDeprecatedAlias('TimeFactory', \OCP\AppFramework\Utility\ITimeFactory::class);
  1145. $this->registerService(Defaults::class, function (Server $c) {
  1146. return new Defaults(
  1147. $c->getThemingDefaults()
  1148. );
  1149. });
  1150. /** @deprecated 19.0.0 */
  1151. $this->registerDeprecatedAlias('Defaults', \OCP\Defaults::class);
  1152. $this->registerService(\OCP\ISession::class, function (SimpleContainer $c) {
  1153. return $c->query(\OCP\IUserSession::class)->getSession();
  1154. });
  1155. $this->registerService(IShareHelper::class, function (Server $c) {
  1156. return new ShareHelper(
  1157. $c->query(\OCP\Share\IManager::class)
  1158. );
  1159. });
  1160. $this->registerService(Installer::class, function (Server $c) {
  1161. return new Installer(
  1162. $c->getAppFetcher(),
  1163. $c->getHTTPClientService(),
  1164. $c->getTempManager(),
  1165. $c->getLogger(),
  1166. $c->getConfig(),
  1167. \OC::$CLI
  1168. );
  1169. });
  1170. $this->registerService(IApiFactory::class, function (Server $c) {
  1171. return new ApiFactory($c->getHTTPClientService());
  1172. });
  1173. $this->registerService(IInstanceFactory::class, function (Server $c) {
  1174. $memcacheFactory = $c->getMemCacheFactory();
  1175. return new InstanceFactory($memcacheFactory->createLocal('remoteinstance.'), $c->getHTTPClientService());
  1176. });
  1177. $this->registerAlias(IContactsStore::class, ContactsStore::class);
  1178. $this->registerAlias(IAccountManager::class, AccountManager::class);
  1179. $this->registerAlias(IStorageFactory::class, StorageFactory::class);
  1180. $this->registerAlias(IDashboardManager::class, DashboardManager::class);
  1181. $this->registerAlias(\OCP\Dashboard\IManager::class, \OC\Dashboard\Manager::class);
  1182. $this->registerAlias(IFullTextSearchManager::class, FullTextSearchManager::class);
  1183. $this->registerAlias(ISubAdmin::class, SubAdmin::class);
  1184. $this->registerAlias(IInitialStateService::class, InitialStateService::class);
  1185. $this->registerAlias(\OCP\UserStatus\IManager::class, \OC\UserStatus\Manager::class);
  1186. $this->connectDispatcher();
  1187. }
  1188. public function boot() {
  1189. /** @var HookConnector $hookConnector */
  1190. $hookConnector = $this->query(HookConnector::class);
  1191. $hookConnector->viewToNode();
  1192. }
  1193. /**
  1194. * @return \OCP\Calendar\IManager
  1195. * @deprecated
  1196. */
  1197. public function getCalendarManager() {
  1198. return $this->query(\OC\Calendar\Manager::class);
  1199. }
  1200. /**
  1201. * @return \OCP\Calendar\Resource\IManager
  1202. * @deprecated
  1203. */
  1204. public function getCalendarResourceBackendManager() {
  1205. return $this->query(\OC\Calendar\Resource\Manager::class);
  1206. }
  1207. /**
  1208. * @return \OCP\Calendar\Room\IManager
  1209. * @deprecated
  1210. */
  1211. public function getCalendarRoomBackendManager() {
  1212. return $this->query(\OC\Calendar\Room\Manager::class);
  1213. }
  1214. private function connectDispatcher() {
  1215. $dispatcher = $this->getEventDispatcher();
  1216. // Delete avatar on user deletion
  1217. $dispatcher->addListener('OCP\IUser::preDelete', function (GenericEvent $e) {
  1218. $logger = $this->getLogger();
  1219. $manager = $this->getAvatarManager();
  1220. /** @var IUser $user */
  1221. $user = $e->getSubject();
  1222. try {
  1223. $avatar = $manager->getAvatar($user->getUID());
  1224. $avatar->remove();
  1225. } catch (NotFoundException $e) {
  1226. // no avatar to remove
  1227. } catch (\Exception $e) {
  1228. // Ignore exceptions
  1229. $logger->info('Could not cleanup avatar of ' . $user->getUID());
  1230. }
  1231. });
  1232. $dispatcher->addListener('OCP\IUser::changeUser', function (GenericEvent $e) {
  1233. $manager = $this->getAvatarManager();
  1234. /** @var IUser $user */
  1235. $user = $e->getSubject();
  1236. $feature = $e->getArgument('feature');
  1237. $oldValue = $e->getArgument('oldValue');
  1238. $value = $e->getArgument('value');
  1239. // We only change the avatar on display name changes
  1240. if ($feature !== 'displayName') {
  1241. return;
  1242. }
  1243. try {
  1244. $avatar = $manager->getAvatar($user->getUID());
  1245. $avatar->userChanged($feature, $oldValue, $value);
  1246. } catch (NotFoundException $e) {
  1247. // no avatar to remove
  1248. }
  1249. });
  1250. /** @var IEventDispatcher $eventDispatched */
  1251. $eventDispatched = $this->query(IEventDispatcher::class);
  1252. $eventDispatched->addServiceListener(LoginFailed::class, LoginFailedListener::class);
  1253. $eventDispatched->addServiceListener(PostLoginEvent::class, UserLoggedInListener::class);
  1254. }
  1255. /**
  1256. * @return \OCP\Contacts\IManager
  1257. * @deprecated
  1258. */
  1259. public function getContactsManager() {
  1260. return $this->query(\OCP\Contacts\IManager::class);
  1261. }
  1262. /**
  1263. * @return \OC\Encryption\Manager
  1264. * @deprecated
  1265. */
  1266. public function getEncryptionManager() {
  1267. return $this->query(\OCP\Encryption\IManager::class);
  1268. }
  1269. /**
  1270. * @return \OC\Encryption\File
  1271. * @deprecated
  1272. */
  1273. public function getEncryptionFilesHelper() {
  1274. return $this->query('EncryptionFileHelper');
  1275. }
  1276. /**
  1277. * @return \OCP\Encryption\Keys\IStorage
  1278. * @deprecated
  1279. */
  1280. public function getEncryptionKeyStorage() {
  1281. return $this->query('EncryptionKeyStorage');
  1282. }
  1283. /**
  1284. * The current request object holding all information about the request
  1285. * currently being processed is returned from this method.
  1286. * In case the current execution was not initiated by a web request null is returned
  1287. *
  1288. * @return \OCP\IRequest
  1289. * @deprecated
  1290. */
  1291. public function getRequest() {
  1292. return $this->query(IRequest::class);
  1293. }
  1294. /**
  1295. * Returns the preview manager which can create preview images for a given file
  1296. *
  1297. * @return IPreview
  1298. * @deprecated
  1299. */
  1300. public function getPreviewManager() {
  1301. return $this->query(IPreview::class);
  1302. }
  1303. /**
  1304. * Returns the tag manager which can get and set tags for different object types
  1305. *
  1306. * @see \OCP\ITagManager::load()
  1307. * @return ITagManager
  1308. * @deprecated
  1309. */
  1310. public function getTagManager() {
  1311. return $this->query(ITagManager::class);
  1312. }
  1313. /**
  1314. * Returns the system-tag manager
  1315. *
  1316. * @return ISystemTagManager
  1317. *
  1318. * @since 9.0.0
  1319. * @deprecated
  1320. */
  1321. public function getSystemTagManager() {
  1322. return $this->query(ISystemTagManager::class);
  1323. }
  1324. /**
  1325. * Returns the system-tag object mapper
  1326. *
  1327. * @return ISystemTagObjectMapper
  1328. *
  1329. * @since 9.0.0
  1330. * @deprecated
  1331. */
  1332. public function getSystemTagObjectMapper() {
  1333. return $this->query(ISystemTagObjectMapper::class);
  1334. }
  1335. /**
  1336. * Returns the avatar manager, used for avatar functionality
  1337. *
  1338. * @return IAvatarManager
  1339. * @deprecated
  1340. */
  1341. public function getAvatarManager() {
  1342. return $this->query(IAvatarManager::class);
  1343. }
  1344. /**
  1345. * Returns the root folder of ownCloud's data directory
  1346. *
  1347. * @return IRootFolder
  1348. * @deprecated
  1349. */
  1350. public function getRootFolder() {
  1351. return $this->query(IRootFolder::class);
  1352. }
  1353. /**
  1354. * Returns the root folder of ownCloud's data directory
  1355. * This is the lazy variant so this gets only initialized once it
  1356. * is actually used.
  1357. *
  1358. * @return IRootFolder
  1359. */
  1360. public function getLazyRootFolder() {
  1361. return $this->query(IRootFolder::class);
  1362. }
  1363. /**
  1364. * Returns a view to ownCloud's files folder
  1365. *
  1366. * @param string $userId user ID
  1367. * @return \OCP\Files\Folder|null
  1368. * @deprecated
  1369. */
  1370. public function getUserFolder($userId = null) {
  1371. if ($userId === null) {
  1372. $user = $this->getUserSession()->getUser();
  1373. if (!$user) {
  1374. return null;
  1375. }
  1376. $userId = $user->getUID();
  1377. }
  1378. $root = $this->getRootFolder();
  1379. return $root->getUserFolder($userId);
  1380. }
  1381. /**
  1382. * @return \OC\User\Manager
  1383. * @deprecated
  1384. */
  1385. public function getUserManager() {
  1386. return $this->query(IUserManager::class);
  1387. }
  1388. /**
  1389. * @return \OC\Group\Manager
  1390. * @deprecated
  1391. */
  1392. public function getGroupManager() {
  1393. return $this->query(IGroupManager::class);
  1394. }
  1395. /**
  1396. * @return \OC\User\Session
  1397. * @deprecated
  1398. */
  1399. public function getUserSession() {
  1400. return $this->query(IUserSession::class);
  1401. }
  1402. /**
  1403. * @return \OCP\ISession
  1404. * @deprecated
  1405. */
  1406. public function getSession() {
  1407. return $this->getUserSession()->getSession();
  1408. }
  1409. /**
  1410. * @param \OCP\ISession $session
  1411. */
  1412. public function setSession(\OCP\ISession $session) {
  1413. $this->query(SessionStorage::class)->setSession($session);
  1414. $this->getUserSession()->setSession($session);
  1415. $this->query(Store::class)->setSession($session);
  1416. }
  1417. /**
  1418. * @return \OC\Authentication\TwoFactorAuth\Manager
  1419. * @deprecated
  1420. */
  1421. public function getTwoFactorAuthManager() {
  1422. return $this->query(\OC\Authentication\TwoFactorAuth\Manager::class);
  1423. }
  1424. /**
  1425. * @return \OC\NavigationManager
  1426. * @deprecated
  1427. */
  1428. public function getNavigationManager() {
  1429. return $this->query(INavigationManager::class);
  1430. }
  1431. /**
  1432. * @return \OCP\IConfig
  1433. * @deprecated
  1434. */
  1435. public function getConfig() {
  1436. return $this->query(AllConfig::class);
  1437. }
  1438. /**
  1439. * @return \OC\SystemConfig
  1440. * @deprecated
  1441. */
  1442. public function getSystemConfig() {
  1443. return $this->query(SystemConfig::class);
  1444. }
  1445. /**
  1446. * Returns the app config manager
  1447. *
  1448. * @return IAppConfig
  1449. * @deprecated
  1450. */
  1451. public function getAppConfig() {
  1452. return $this->query(IAppConfig::class);
  1453. }
  1454. /**
  1455. * @return IFactory
  1456. * @deprecated
  1457. */
  1458. public function getL10NFactory() {
  1459. return $this->query(IFactory::class);
  1460. }
  1461. /**
  1462. * get an L10N instance
  1463. *
  1464. * @param string $app appid
  1465. * @param string $lang
  1466. * @return IL10N
  1467. * @deprecated
  1468. */
  1469. public function getL10N($app, $lang = null) {
  1470. return $this->getL10NFactory()->get($app, $lang);
  1471. }
  1472. /**
  1473. * @return IURLGenerator
  1474. * @deprecated
  1475. */
  1476. public function getURLGenerator() {
  1477. return $this->query(IURLGenerator::class);
  1478. }
  1479. /**
  1480. * @return AppFetcher
  1481. * @deprecated
  1482. */
  1483. public function getAppFetcher() {
  1484. return $this->query(AppFetcher::class);
  1485. }
  1486. /**
  1487. * Returns an ICache instance. Since 8.1.0 it returns a fake cache. Use
  1488. * getMemCacheFactory() instead.
  1489. *
  1490. * @return ICache
  1491. * @deprecated 8.1.0 use getMemCacheFactory to obtain a proper cache
  1492. */
  1493. public function getCache() {
  1494. return $this->query(ICache::class);
  1495. }
  1496. /**
  1497. * Returns an \OCP\CacheFactory instance
  1498. *
  1499. * @return \OCP\ICacheFactory
  1500. * @deprecated
  1501. */
  1502. public function getMemCacheFactory() {
  1503. return $this->query(Factory::class);
  1504. }
  1505. /**
  1506. * Returns an \OC\RedisFactory instance
  1507. *
  1508. * @return \OC\RedisFactory
  1509. * @deprecated
  1510. */
  1511. public function getGetRedisFactory() {
  1512. return $this->query('RedisFactory');
  1513. }
  1514. /**
  1515. * Returns the current session
  1516. *
  1517. * @return \OCP\IDBConnection
  1518. * @deprecated
  1519. */
  1520. public function getDatabaseConnection() {
  1521. return $this->query(IDBConnection::class);
  1522. }
  1523. /**
  1524. * Returns the activity manager
  1525. *
  1526. * @return \OCP\Activity\IManager
  1527. * @deprecated
  1528. */
  1529. public function getActivityManager() {
  1530. return $this->query(\OCP\Activity\IManager::class);
  1531. }
  1532. /**
  1533. * Returns an job list for controlling background jobs
  1534. *
  1535. * @return IJobList
  1536. * @deprecated
  1537. */
  1538. public function getJobList() {
  1539. return $this->query(IJobList::class);
  1540. }
  1541. /**
  1542. * Returns a logger instance
  1543. *
  1544. * @return ILogger
  1545. * @deprecated
  1546. */
  1547. public function getLogger() {
  1548. return $this->query(ILogger::class);
  1549. }
  1550. /**
  1551. * @return ILogFactory
  1552. * @throws \OCP\AppFramework\QueryException
  1553. * @deprecated
  1554. */
  1555. public function getLogFactory() {
  1556. return $this->query(ILogFactory::class);
  1557. }
  1558. /**
  1559. * Returns a router for generating and matching urls
  1560. *
  1561. * @return IRouter
  1562. * @deprecated
  1563. */
  1564. public function getRouter() {
  1565. return $this->query(IRouter::class);
  1566. }
  1567. /**
  1568. * Returns a search instance
  1569. *
  1570. * @return ISearch
  1571. * @deprecated
  1572. */
  1573. public function getSearch() {
  1574. return $this->query(ISearch::class);
  1575. }
  1576. /**
  1577. * Returns a SecureRandom instance
  1578. *
  1579. * @return \OCP\Security\ISecureRandom
  1580. * @deprecated
  1581. */
  1582. public function getSecureRandom() {
  1583. return $this->query(ISecureRandom::class);
  1584. }
  1585. /**
  1586. * Returns a Crypto instance
  1587. *
  1588. * @return ICrypto
  1589. * @deprecated
  1590. */
  1591. public function getCrypto() {
  1592. return $this->query(ICrypto::class);
  1593. }
  1594. /**
  1595. * Returns a Hasher instance
  1596. *
  1597. * @return IHasher
  1598. * @deprecated
  1599. */
  1600. public function getHasher() {
  1601. return $this->query(IHasher::class);
  1602. }
  1603. /**
  1604. * Returns a CredentialsManager instance
  1605. *
  1606. * @return ICredentialsManager
  1607. * @deprecated
  1608. */
  1609. public function getCredentialsManager() {
  1610. return $this->query(ICredentialsManager::class);
  1611. }
  1612. /**
  1613. * Get the certificate manager for the user
  1614. *
  1615. * @param string $userId (optional) if not specified the current loggedin user is used, use null to get the system certificate manager
  1616. * @return \OCP\ICertificateManager | null if $uid is null and no user is logged in
  1617. * @deprecated
  1618. */
  1619. public function getCertificateManager($userId = '') {
  1620. if ($userId === '') {
  1621. $userSession = $this->getUserSession();
  1622. $user = $userSession->getUser();
  1623. if (is_null($user)) {
  1624. return null;
  1625. }
  1626. $userId = $user->getUID();
  1627. }
  1628. return new CertificateManager(
  1629. $userId,
  1630. new View(),
  1631. $this->getConfig(),
  1632. $this->getLogger(),
  1633. $this->getSecureRandom()
  1634. );
  1635. }
  1636. /**
  1637. * Returns an instance of the HTTP client service
  1638. *
  1639. * @return IClientService
  1640. * @deprecated
  1641. */
  1642. public function getHTTPClientService() {
  1643. return $this->query(IClientService::class);
  1644. }
  1645. /**
  1646. * Create a new event source
  1647. *
  1648. * @return \OCP\IEventSource
  1649. * @deprecated
  1650. */
  1651. public function createEventSource() {
  1652. return new \OC_EventSource();
  1653. }
  1654. /**
  1655. * Get the active event logger
  1656. *
  1657. * The returned logger only logs data when debug mode is enabled
  1658. *
  1659. * @return IEventLogger
  1660. * @deprecated
  1661. */
  1662. public function getEventLogger() {
  1663. return $this->query(IEventLogger::class);
  1664. }
  1665. /**
  1666. * Get the active query logger
  1667. *
  1668. * The returned logger only logs data when debug mode is enabled
  1669. *
  1670. * @return IQueryLogger
  1671. * @deprecated
  1672. */
  1673. public function getQueryLogger() {
  1674. return $this->query(IQueryLogger::class);
  1675. }
  1676. /**
  1677. * Get the manager for temporary files and folders
  1678. *
  1679. * @return \OCP\ITempManager
  1680. * @deprecated
  1681. */
  1682. public function getTempManager() {
  1683. return $this->query(ITempManager::class);
  1684. }
  1685. /**
  1686. * Get the app manager
  1687. *
  1688. * @return \OCP\App\IAppManager
  1689. * @deprecated
  1690. */
  1691. public function getAppManager() {
  1692. return $this->query(IAppManager::class);
  1693. }
  1694. /**
  1695. * Creates a new mailer
  1696. *
  1697. * @return IMailer
  1698. * @deprecated
  1699. */
  1700. public function getMailer() {
  1701. return $this->query(IMailer::class);
  1702. }
  1703. /**
  1704. * Get the webroot
  1705. *
  1706. * @return string
  1707. * @deprecated
  1708. */
  1709. public function getWebRoot() {
  1710. return $this->webRoot;
  1711. }
  1712. /**
  1713. * @return \OC\OCSClient
  1714. * @deprecated
  1715. */
  1716. public function getOcsClient() {
  1717. return $this->query('OcsClient');
  1718. }
  1719. /**
  1720. * @return IDateTimeZone
  1721. * @deprecated
  1722. */
  1723. public function getDateTimeZone() {
  1724. return $this->query(IDateTimeZone::class);
  1725. }
  1726. /**
  1727. * @return IDateTimeFormatter
  1728. * @deprecated
  1729. */
  1730. public function getDateTimeFormatter() {
  1731. return $this->query(IDateTimeFormatter::class);
  1732. }
  1733. /**
  1734. * @return IMountProviderCollection
  1735. * @deprecated
  1736. */
  1737. public function getMountProviderCollection() {
  1738. return $this->query(IMountProviderCollection::class);
  1739. }
  1740. /**
  1741. * Get the IniWrapper
  1742. *
  1743. * @return IniGetWrapper
  1744. * @deprecated
  1745. */
  1746. public function getIniWrapper() {
  1747. return $this->query(IniGetWrapper::class);
  1748. }
  1749. /**
  1750. * @return \OCP\Command\IBus
  1751. * @deprecated
  1752. */
  1753. public function getCommandBus() {
  1754. return $this->query('AsyncCommandBus');
  1755. }
  1756. /**
  1757. * Get the trusted domain helper
  1758. *
  1759. * @return TrustedDomainHelper
  1760. * @deprecated
  1761. */
  1762. public function getTrustedDomainHelper() {
  1763. return $this->query('TrustedDomainHelper');
  1764. }
  1765. /**
  1766. * Get the locking provider
  1767. *
  1768. * @return ILockingProvider
  1769. * @since 8.1.0
  1770. * @deprecated
  1771. */
  1772. public function getLockingProvider() {
  1773. return $this->query(ILockingProvider::class);
  1774. }
  1775. /**
  1776. * @return IMountManager
  1777. * @deprecated
  1778. **/
  1779. public function getMountManager() {
  1780. return $this->query(IMountManager::class);
  1781. }
  1782. /**
  1783. * @return IUserMountCache
  1784. * @deprecated
  1785. */
  1786. public function getUserMountCache() {
  1787. return $this->query(IUserMountCache::class);
  1788. }
  1789. /**
  1790. * Get the MimeTypeDetector
  1791. *
  1792. * @return IMimeTypeDetector
  1793. * @deprecated
  1794. */
  1795. public function getMimeTypeDetector() {
  1796. return $this->query(IMimeTypeDetector::class);
  1797. }
  1798. /**
  1799. * Get the MimeTypeLoader
  1800. *
  1801. * @return IMimeTypeLoader
  1802. * @deprecated
  1803. */
  1804. public function getMimeTypeLoader() {
  1805. return $this->query(IMimeTypeLoader::class);
  1806. }
  1807. /**
  1808. * Get the manager of all the capabilities
  1809. *
  1810. * @return CapabilitiesManager
  1811. * @deprecated
  1812. */
  1813. public function getCapabilitiesManager() {
  1814. return $this->query(CapabilitiesManager::class);
  1815. }
  1816. /**
  1817. * Get the EventDispatcher
  1818. *
  1819. * @return EventDispatcherInterface
  1820. * @since 8.2.0
  1821. * @deprecated 18.0.0 use \OCP\EventDispatcher\IEventDispatcher
  1822. */
  1823. public function getEventDispatcher() {
  1824. return $this->query(\OC\EventDispatcher\SymfonyAdapter::class);
  1825. }
  1826. /**
  1827. * Get the Notification Manager
  1828. *
  1829. * @return \OCP\Notification\IManager
  1830. * @since 8.2.0
  1831. * @deprecated
  1832. */
  1833. public function getNotificationManager() {
  1834. return $this->query(\OCP\Notification\IManager::class);
  1835. }
  1836. /**
  1837. * @return ICommentsManager
  1838. * @deprecated
  1839. */
  1840. public function getCommentsManager() {
  1841. return $this->query(ICommentsManager::class);
  1842. }
  1843. /**
  1844. * @return \OCA\Theming\ThemingDefaults
  1845. * @deprecated
  1846. */
  1847. public function getThemingDefaults() {
  1848. return $this->query('ThemingDefaults');
  1849. }
  1850. /**
  1851. * @return \OC\IntegrityCheck\Checker
  1852. * @deprecated
  1853. */
  1854. public function getIntegrityCodeChecker() {
  1855. return $this->query('IntegrityCodeChecker');
  1856. }
  1857. /**
  1858. * @return \OC\Session\CryptoWrapper
  1859. * @deprecated
  1860. */
  1861. public function getSessionCryptoWrapper() {
  1862. return $this->query('CryptoWrapper');
  1863. }
  1864. /**
  1865. * @return CsrfTokenManager
  1866. * @deprecated
  1867. */
  1868. public function getCsrfTokenManager() {
  1869. return $this->query(CsrfTokenManager::class);
  1870. }
  1871. /**
  1872. * @return Throttler
  1873. * @deprecated
  1874. */
  1875. public function getBruteForceThrottler() {
  1876. return $this->query(Throttler::class);
  1877. }
  1878. /**
  1879. * @return IContentSecurityPolicyManager
  1880. * @deprecated
  1881. */
  1882. public function getContentSecurityPolicyManager() {
  1883. return $this->query(ContentSecurityPolicyManager::class);
  1884. }
  1885. /**
  1886. * @return ContentSecurityPolicyNonceManager
  1887. * @deprecated
  1888. */
  1889. public function getContentSecurityPolicyNonceManager() {
  1890. return $this->query(ContentSecurityPolicyNonceManager::class);
  1891. }
  1892. /**
  1893. * Not a public API as of 8.2, wait for 9.0
  1894. *
  1895. * @return \OCA\Files_External\Service\BackendService
  1896. * @deprecated
  1897. */
  1898. public function getStoragesBackendService() {
  1899. return $this->query(BackendService::class);
  1900. }
  1901. /**
  1902. * Not a public API as of 8.2, wait for 9.0
  1903. *
  1904. * @return \OCA\Files_External\Service\GlobalStoragesService
  1905. * @deprecated
  1906. */
  1907. public function getGlobalStoragesService() {
  1908. return $this->query(GlobalStoragesService::class);
  1909. }
  1910. /**
  1911. * Not a public API as of 8.2, wait for 9.0
  1912. *
  1913. * @return \OCA\Files_External\Service\UserGlobalStoragesService
  1914. * @deprecated
  1915. */
  1916. public function getUserGlobalStoragesService() {
  1917. return $this->query(UserGlobalStoragesService::class);
  1918. }
  1919. /**
  1920. * Not a public API as of 8.2, wait for 9.0
  1921. *
  1922. * @return \OCA\Files_External\Service\UserStoragesService
  1923. * @deprecated
  1924. */
  1925. public function getUserStoragesService() {
  1926. return $this->query(UserStoragesService::class);
  1927. }
  1928. /**
  1929. * @return \OCP\Share\IManager
  1930. * @deprecated
  1931. */
  1932. public function getShareManager() {
  1933. return $this->query(\OCP\Share\IManager::class);
  1934. }
  1935. /**
  1936. * @return \OCP\Collaboration\Collaborators\ISearch
  1937. * @deprecated
  1938. */
  1939. public function getCollaboratorSearch() {
  1940. return $this->query(\OCP\Collaboration\Collaborators\ISearch::class);
  1941. }
  1942. /**
  1943. * @return \OCP\Collaboration\AutoComplete\IManager
  1944. * @deprecated
  1945. */
  1946. public function getAutoCompleteManager() {
  1947. return $this->query(IManager::class);
  1948. }
  1949. /**
  1950. * Returns the LDAP Provider
  1951. *
  1952. * @return \OCP\LDAP\ILDAPProvider
  1953. * @deprecated
  1954. */
  1955. public function getLDAPProvider() {
  1956. return $this->query('LDAPProvider');
  1957. }
  1958. /**
  1959. * @return \OCP\Settings\IManager
  1960. * @deprecated
  1961. */
  1962. public function getSettingsManager() {
  1963. return $this->query(\OC\Settings\Manager::class);
  1964. }
  1965. /**
  1966. * @return \OCP\Files\IAppData
  1967. * @deprecated
  1968. */
  1969. public function getAppDataDir($app) {
  1970. /** @var \OC\Files\AppData\Factory $factory */
  1971. $factory = $this->query(\OC\Files\AppData\Factory::class);
  1972. return $factory->get($app);
  1973. }
  1974. /**
  1975. * @return \OCP\Lockdown\ILockdownManager
  1976. * @deprecated
  1977. */
  1978. public function getLockdownManager() {
  1979. return $this->query('LockdownManager');
  1980. }
  1981. /**
  1982. * @return \OCP\Federation\ICloudIdManager
  1983. * @deprecated
  1984. */
  1985. public function getCloudIdManager() {
  1986. return $this->query(ICloudIdManager::class);
  1987. }
  1988. /**
  1989. * @return \OCP\GlobalScale\IConfig
  1990. * @deprecated
  1991. */
  1992. public function getGlobalScaleConfig() {
  1993. return $this->query(IConfig::class);
  1994. }
  1995. /**
  1996. * @return \OCP\Federation\ICloudFederationProviderManager
  1997. * @deprecated
  1998. */
  1999. public function getCloudFederationProviderManager() {
  2000. return $this->query(ICloudFederationProviderManager::class);
  2001. }
  2002. /**
  2003. * @return \OCP\Remote\Api\IApiFactory
  2004. * @deprecated
  2005. */
  2006. public function getRemoteApiFactory() {
  2007. return $this->query(IApiFactory::class);
  2008. }
  2009. /**
  2010. * @return \OCP\Federation\ICloudFederationFactory
  2011. * @deprecated
  2012. */
  2013. public function getCloudFederationFactory() {
  2014. return $this->query(ICloudFederationFactory::class);
  2015. }
  2016. /**
  2017. * @return \OCP\Remote\IInstanceFactory
  2018. * @deprecated
  2019. */
  2020. public function getRemoteInstanceFactory() {
  2021. return $this->query(IInstanceFactory::class);
  2022. }
  2023. /**
  2024. * @return IStorageFactory
  2025. * @deprecated
  2026. */
  2027. public function getStorageFactory() {
  2028. return $this->query(IStorageFactory::class);
  2029. }
  2030. /**
  2031. * Get the Preview GeneratorHelper
  2032. *
  2033. * @return GeneratorHelper
  2034. * @since 17.0.0
  2035. * @deprecated
  2036. */
  2037. public function getGeneratorHelper() {
  2038. return $this->query(\OC\Preview\GeneratorHelper::class);
  2039. }
  2040. private function registerDeprecatedAlias(string $alias, string $target) {
  2041. $this->registerService($alias, function (ContainerInterface $container) use ($target, $alias) {
  2042. try {
  2043. /** @var ILogger $logger */
  2044. $logger = $container->get(ILogger::class);
  2045. $logger->debug('The requested alias "' . $alias . '" is depreacted. Please request "' . $target . '" directly. This alias will be removed in a future Nextcloud version.', ['app' => 'serverDI']);
  2046. } catch (ContainerExceptionInterface $e) {
  2047. // Could not get logger. Continue
  2048. }
  2049. return $container->get($target);
  2050. }, false);
  2051. }
  2052. }