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 59KB

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