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

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