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.

326 lines
10 KiB

9 years ago
9 years ago
10 years ago
9 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.
10 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.
10 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.
10 years ago
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Bart Visscher <bartv@thisnet.nl>
  6. * @author Christopher Schäpers <kondou@ts.unde.re>
  7. * @author Clark Tomlinson <fallen013@gmail.com>
  8. * @author Hendrik Leppelsack <hendrik@leppelsack.de>
  9. * @author Joas Schilling <coding@schilljs.com>
  10. * @author John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
  11. * @author Julius Haertl <jus@bitgrid.net>
  12. * @author Julius Härtl <jus@bitgrid.net>
  13. * @author Jörn Friedrich Dreyer <jfd@butonic.de>
  14. * @author Lukas Reschke <lukas@statuscode.ch>
  15. * @author Michael Gapczynski <GapczynskiM@gmail.com>
  16. * @author Morris Jobke <hey@morrisjobke.de>
  17. * @author Nils <git@to.nilsschnabel.de>
  18. * @author Remco Brenninkmeijer <requist1@starmail.nl>
  19. * @author Robin Appelman <robin@icewind.nl>
  20. * @author Robin McCorkell <robin@mccorkell.me.uk>
  21. * @author Roeland Jago Douma <roeland@famdouma.nl>
  22. * @author Thomas Müller <thomas.mueller@tmit.eu>
  23. *
  24. * @license AGPL-3.0
  25. *
  26. * This code is free software: you can redistribute it and/or modify
  27. * it under the terms of the GNU Affero General Public License, version 3,
  28. * as published by the Free Software Foundation.
  29. *
  30. * This program is distributed in the hope that it will be useful,
  31. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  32. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  33. * GNU Affero General Public License for more details.
  34. *
  35. * You should have received a copy of the GNU Affero General Public License, version 3,
  36. * along with this program. If not, see <http://www.gnu.org/licenses/>
  37. *
  38. */
  39. namespace OC;
  40. use OC\Template\JSCombiner;
  41. use OC\Template\JSConfigHelper;
  42. use OC\Template\SCSSCacher;
  43. use OCP\Defaults;
  44. class TemplateLayout extends \OC_Template {
  45. private static $versionHash = '';
  46. /**
  47. * @var \OCP\IConfig
  48. */
  49. private $config;
  50. /**
  51. * @param string $renderAs
  52. * @param string $appId application id
  53. */
  54. public function __construct( $renderAs, $appId = '' ) {
  55. // yes - should be injected ....
  56. $this->config = \OC::$server->getConfig();
  57. // Decide which page we show
  58. if($renderAs == 'user') {
  59. parent::__construct( 'core', 'layout.user' );
  60. if(in_array(\OC_App::getCurrentApp(), ['settings','admin', 'help']) !== false) {
  61. $this->assign('bodyid', 'body-settings');
  62. }else{
  63. $this->assign('bodyid', 'body-user');
  64. }
  65. // Code integrity notification
  66. $integrityChecker = \OC::$server->getIntegrityCodeChecker();
  67. if(\OC_User::isAdminUser(\OC_User::getUser()) && $integrityChecker->isCodeCheckEnforced() && !$integrityChecker->hasPassedCheck()) {
  68. \OCP\Util::addScript('core', 'integritycheck-failed-notification');
  69. }
  70. // Add navigation entry
  71. $this->assign( 'application', '');
  72. $this->assign( 'appid', $appId );
  73. $navigation = \OC_App::getNavigation();
  74. $this->assign( 'navigation', $navigation);
  75. $settingsNavigation = \OC_App::getSettingsNavigation();
  76. $this->assign( 'settingsnavigation', $settingsNavigation);
  77. foreach($navigation as $entry) {
  78. if ($entry['active']) {
  79. $this->assign( 'application', $entry['name'] );
  80. break;
  81. }
  82. }
  83. foreach($settingsNavigation as $entry) {
  84. if ($entry['active']) {
  85. $this->assign( 'application', $entry['name'] );
  86. break;
  87. }
  88. }
  89. $userDisplayName = \OC_User::getDisplayName();
  90. $this->assign('user_displayname', $userDisplayName);
  91. $this->assign('user_uid', \OC_User::getUser());
  92. if (\OC_User::getUser() === false) {
  93. $this->assign('userAvatarSet', false);
  94. } else {
  95. $this->assign('userAvatarSet', \OC::$server->getAvatarManager()->getAvatar(\OC_User::getUser())->exists());
  96. $this->assign('userAvatarVersion', $this->config->getUserValue(\OC_User::getUser(), 'avatar', 'version', 0));
  97. }
  98. // check if app menu icons should be inverted
  99. try {
  100. /** @var \OCA\Theming\Util $util */
  101. $util = \OC::$server->query(\OCA\Theming\Util::class);
  102. $this->assign('themingInvertMenu', $util->invertTextColor(\OC::$server->getThemingDefaults()->getColorPrimary()));
  103. } catch (\OCP\AppFramework\QueryException $e) {
  104. $this->assign('themingInvertMenu', false);
  105. }
  106. } else if ($renderAs == 'error') {
  107. parent::__construct('core', 'layout.guest', '', false);
  108. $this->assign('bodyid', 'body-login');
  109. } else if ($renderAs == 'guest') {
  110. parent::__construct('core', 'layout.guest');
  111. $this->assign('bodyid', 'body-login');
  112. } else {
  113. parent::__construct('core', 'layout.base');
  114. }
  115. // Send the language to our layouts
  116. $this->assign('language', \OC::$server->getL10NFactory()->findLanguage());
  117. if(\OC::$server->getSystemConfig()->getValue('installed', false)) {
  118. if (empty(self::$versionHash)) {
  119. $v = \OC_App::getAppVersions();
  120. $v['core'] = implode('.', \OCP\Util::getVersion());
  121. self::$versionHash = substr(md5(implode(',', $v)), 0, 8);
  122. }
  123. } else {
  124. self::$versionHash = md5('not installed');
  125. }
  126. // Add the js files
  127. $jsFiles = self::findJavascriptFiles(\OC_Util::$scripts);
  128. $this->assign('jsfiles', array());
  129. if ($this->config->getSystemValue('installed', false) && $renderAs != 'error') {
  130. if (\OC::$server->getContentSecurityPolicyNonceManager()->browserSupportsCspV3()) {
  131. $jsConfigHelper = new JSConfigHelper(
  132. \OC::$server->getL10N('core'),
  133. \OC::$server->query(Defaults::class),
  134. \OC::$server->getAppManager(),
  135. \OC::$server->getSession(),
  136. \OC::$server->getUserSession()->getUser(),
  137. $this->config,
  138. \OC::$server->getGroupManager(),
  139. \OC::$server->getIniWrapper(),
  140. \OC::$server->getURLGenerator()
  141. );
  142. $this->assign('inline_ocjs', $jsConfigHelper->getConfig());
  143. } else {
  144. $this->append('jsfiles', \OC::$server->getURLGenerator()->linkToRoute('core.OCJS.getConfig', ['v' => self::$versionHash]));
  145. }
  146. }
  147. foreach($jsFiles as $info) {
  148. $web = $info[1];
  149. $file = $info[2];
  150. $this->append( 'jsfiles', $web.'/'.$file . $this->getVersionHashSuffix() );
  151. }
  152. try {
  153. $pathInfo = \OC::$server->getRequest()->getPathInfo();
  154. } catch (\Exception $e) {
  155. $pathInfo = '';
  156. }
  157. // Do not initialise scss appdata until we have a fully installed instance
  158. // Do not load scss for update, errors, installation or login page
  159. if(\OC::$server->getSystemConfig()->getValue('installed', false)
  160. && !\OCP\Util::needUpgrade()
  161. && $pathInfo !== ''
  162. && !preg_match('/^\/login/', $pathInfo)) {
  163. $cssFiles = self::findStylesheetFiles(\OC_Util::$styles);
  164. } else {
  165. // If we ignore the scss compiler,
  166. // we need to load the guest css fallback
  167. \OC_Util::addStyle('guest');
  168. $cssFiles = self::findStylesheetFiles(\OC_Util::$styles, false);
  169. }
  170. $this->assign('cssfiles', array());
  171. $this->assign('printcssfiles', []);
  172. $this->assign('versionHash', self::$versionHash);
  173. foreach($cssFiles as $info) {
  174. $web = $info[1];
  175. $file = $info[2];
  176. if (substr($file, -strlen('print.css')) === 'print.css') {
  177. $this->append( 'printcssfiles', $web.'/'.$file . $this->getVersionHashSuffix() );
  178. } else {
  179. $this->append( 'cssfiles', $web.'/'.$file . $this->getVersionHashSuffix($web, $file) );
  180. }
  181. }
  182. }
  183. /**
  184. * @param string $path
  185. * @param string $file
  186. * @return string
  187. */
  188. protected function getVersionHashSuffix($path = false, $file = false) {
  189. if ($this->config->getSystemValue('debug', false)) {
  190. // allows chrome workspace mapping in debug mode
  191. return "";
  192. }
  193. $themingSuffix = '';
  194. $v = [];
  195. if ($this->config->getSystemValue('installed', false)) {
  196. if (\OC::$server->getAppManager()->isInstalled('theming')) {
  197. $themingSuffix = '-' . $this->config->getAppValue('theming', 'cachebuster', '0');
  198. }
  199. $v = \OC_App::getAppVersions();
  200. }
  201. // Try the webroot path for a match
  202. if ($path !== false && $path !== '') {
  203. $appName = $this->getAppNamefromPath($path);
  204. if(array_key_exists($appName, $v)) {
  205. $appVersion = $v[$appName];
  206. return '?v=' . substr(md5($appVersion), 0, 8) . $themingSuffix;
  207. }
  208. }
  209. // fallback to the file path instead
  210. if ($file !== false && $file !== '') {
  211. $appName = $this->getAppNamefromPath($file);
  212. if(array_key_exists($appName, $v)) {
  213. $appVersion = $v[$appName];
  214. return '?v=' . substr(md5($appVersion), 0, 8) . $themingSuffix;
  215. }
  216. }
  217. return '?v=' . self::$versionHash . $themingSuffix;
  218. }
  219. /**
  220. * @param array $styles
  221. * @return array
  222. */
  223. static public function findStylesheetFiles($styles, $compileScss = true) {
  224. // Read the selected theme from the config file
  225. $theme = \OC_Util::getTheme();
  226. if($compileScss) {
  227. $SCSSCacher = \OC::$server->query(SCSSCacher::class);
  228. } else {
  229. $SCSSCacher = null;
  230. }
  231. $locator = new \OC\Template\CSSResourceLocator(
  232. \OC::$server->getLogger(),
  233. $theme,
  234. array( \OC::$SERVERROOT => \OC::$WEBROOT ),
  235. array( \OC::$SERVERROOT => \OC::$WEBROOT ),
  236. $SCSSCacher
  237. );
  238. $locator->find($styles);
  239. return $locator->getResources();
  240. }
  241. /**
  242. * @param string $path
  243. * @return string|boolean
  244. */
  245. public function getAppNamefromPath($path) {
  246. if ($path !== '' && is_string($path)) {
  247. $pathParts = explode('/', $path);
  248. if ($pathParts[0] === 'css') {
  249. // This is a scss request
  250. return $pathParts[1];
  251. }
  252. return end($pathParts);
  253. }
  254. return false;
  255. }
  256. /**
  257. * @param array $scripts
  258. * @return array
  259. */
  260. static public function findJavascriptFiles($scripts) {
  261. // Read the selected theme from the config file
  262. $theme = \OC_Util::getTheme();
  263. $locator = new \OC\Template\JSResourceLocator(
  264. \OC::$server->getLogger(),
  265. $theme,
  266. array( \OC::$SERVERROOT => \OC::$WEBROOT ),
  267. array( \OC::$SERVERROOT => \OC::$WEBROOT ),
  268. new JSCombiner(
  269. \OC::$server->getAppDataDir('js'),
  270. \OC::$server->getURLGenerator(),
  271. \OC::$server->getMemCacheFactory()->createDistributed('JS'),
  272. \OC::$server->getSystemConfig(),
  273. \OC::$server->getLogger()
  274. )
  275. );
  276. $locator->find($scripts);
  277. return $locator->getResources();
  278. }
  279. /**
  280. * Converts the absolute file path to a relative path from \OC::$SERVERROOT
  281. * @param string $filePath Absolute path
  282. * @return string Relative path
  283. * @throws \Exception If $filePath is not under \OC::$SERVERROOT
  284. */
  285. public static function convertToRelativePath($filePath) {
  286. $relativePath = explode(\OC::$SERVERROOT, $filePath);
  287. if(count($relativePath) !== 2) {
  288. throw new \Exception('$filePath is not under the \OC::$SERVERROOT');
  289. }
  290. return $relativePath[1];
  291. }
  292. }