summaryrefslogtreecommitdiffstats
path: root/lib/private
diff options
context:
space:
mode:
Diffstat (limited to 'lib/private')
-rw-r--r--lib/private/App/AppStore/Fetcher/AppFetcher.php52
-rw-r--r--lib/private/App/AppStore/Fetcher/CategoryFetcher.php45
-rw-r--r--lib/private/App/AppStore/Fetcher/Fetcher.php92
-rw-r--r--lib/private/App/AppStore/Version/Version.php52
-rw-r--r--lib/private/App/AppStore/Version/VersionParser.php64
-rw-r--r--lib/private/Installer.php230
-rw-r--r--lib/private/OCSClient.php351
-rw-r--r--lib/private/Server.php7
-rw-r--r--lib/private/legacy/app.php242
9 files changed, 507 insertions, 628 deletions
diff --git a/lib/private/App/AppStore/Fetcher/AppFetcher.php b/lib/private/App/AppStore/Fetcher/AppFetcher.php
new file mode 100644
index 00000000000..2a39b047a5a
--- /dev/null
+++ b/lib/private/App/AppStore/Fetcher/AppFetcher.php
@@ -0,0 +1,52 @@
+<?php
+/**
+ * @copyright Copyright (c) 2016 Lukas Reschke <lukas@statuscode.ch>
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+namespace OC\App\AppStore\Fetcher;
+
+use OCP\AppFramework\Utility\ITimeFactory;
+use OCP\Files\IAppData;
+use OCP\Http\Client\IClientService;
+use OCP\IConfig;
+
+class AppFetcher extends Fetcher {
+ /**
+ * @param IAppData $appData
+ * @param IClientService $clientService
+ * @param ITimeFactory $timeFactory
+ * @param IConfig $config;
+ */
+ public function __construct(IAppData $appData,
+ IClientService $clientService,
+ ITimeFactory $timeFactory,
+ IConfig $config) {
+ parent::__construct(
+ $appData,
+ $clientService,
+ $timeFactory
+ );
+
+ $this->fileName = 'apps.json';
+ $this->endpointUrl = sprintf(
+ 'https://apps.nextcloud.com/api/v1/platform/%s/apps.json',
+ substr(implode(\OC_Util::getVersion(), '.'), 0, 5)
+ );
+ }
+}
diff --git a/lib/private/App/AppStore/Fetcher/CategoryFetcher.php b/lib/private/App/AppStore/Fetcher/CategoryFetcher.php
new file mode 100644
index 00000000000..74201ec3737
--- /dev/null
+++ b/lib/private/App/AppStore/Fetcher/CategoryFetcher.php
@@ -0,0 +1,45 @@
+<?php
+/**
+ * @copyright Copyright (c) 2016 Lukas Reschke <lukas@statuscode.ch>
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+namespace OC\App\AppStore\Fetcher;
+
+use OCP\AppFramework\Utility\ITimeFactory;
+use OCP\Files\IAppData;
+use OCP\Http\Client\IClientService;
+
+class CategoryFetcher extends Fetcher {
+ /**
+ * @param IAppData $appData
+ * @param IClientService $clientService
+ * @param ITimeFactory $timeFactory
+ */
+ public function __construct(IAppData $appData,
+ IClientService $clientService,
+ ITimeFactory $timeFactory) {
+ parent::__construct(
+ $appData,
+ $clientService,
+ $timeFactory
+ );
+ $this->fileName = 'categories.json';
+ $this->endpointUrl = 'https://apps.nextcloud.com/api/v1/categories.json';
+ }
+}
diff --git a/lib/private/App/AppStore/Fetcher/Fetcher.php b/lib/private/App/AppStore/Fetcher/Fetcher.php
new file mode 100644
index 00000000000..cffff9176e2
--- /dev/null
+++ b/lib/private/App/AppStore/Fetcher/Fetcher.php
@@ -0,0 +1,92 @@
+<?php
+/**
+ * @copyright Copyright (c) 2016 Lukas Reschke <lukas@statuscode.ch>
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+namespace OC\App\AppStore\Fetcher;
+
+use OCP\AppFramework\Utility\ITimeFactory;
+use OCP\Files\IAppData;
+use OCP\Files\NotFoundException;
+use OCP\Http\Client\IClientService;
+
+abstract class Fetcher {
+ const INVALIDATE_AFTER_SECONDS = 300;
+
+ /** @var IAppData */
+ private $appData;
+ /** @var IClientService */
+ private $clientService;
+ /** @var ITimeFactory */
+ private $timeFactory;
+ /** @var string */
+ protected $fileName;
+ /** @var string */
+ protected $endpointUrl;
+
+ /**
+ * @param IAppData $appData
+ * @param IClientService $clientService
+ * @param ITimeFactory $timeFactory
+ */
+ public function __construct(IAppData $appData,
+ IClientService $clientService,
+ ITimeFactory $timeFactory) {
+ $this->appData = $appData;
+ $this->clientService = $clientService;
+ $this->timeFactory = $timeFactory;
+ }
+
+ /**
+ * Returns the array with the categories on the appstore server
+ *
+ * @return array
+ */
+ public function get() {
+ $rootFolder = $this->appData->getFolder('/');
+
+ try {
+ // File does already exists
+ $file = $rootFolder->getFile($this->fileName);
+ $jsonBlob = json_decode($file->getContent(), true);
+ if(is_array($jsonBlob)) {
+ // If the timestamp is older than 300 seconds request the files new
+ if((int)$jsonBlob['timestamp'] > ($this->timeFactory->getTime() - self::INVALIDATE_AFTER_SECONDS)) {
+ return $jsonBlob['data'];
+ }
+ }
+ } catch (NotFoundException $e) {
+ // File does not already exists
+ $file = $rootFolder->newFile($this->fileName);
+ }
+
+ // Refresh the file content
+ $client = $this->clientService->newClient();
+ try {
+ $response = $client->get($this->endpointUrl);
+ $responseJson = [];
+ $responseJson['data'] = json_decode($response->getBody(), true);
+ $responseJson['timestamp'] = $this->timeFactory->getTime();
+ $file->putContent(json_encode($responseJson));
+ return json_decode($file->getContent(), true)['data'];
+ } catch (\Exception $e) {
+ return [];
+ }
+ }
+}
diff --git a/lib/private/App/AppStore/Version/Version.php b/lib/private/App/AppStore/Version/Version.php
new file mode 100644
index 00000000000..ca182ae078b
--- /dev/null
+++ b/lib/private/App/AppStore/Version/Version.php
@@ -0,0 +1,52 @@
+<?php
+/**
+ * @copyright Copyright (c) 2016 Lukas Reschke <lukas@statuscode.ch>
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+namespace OC\App\AppStore\Version;
+
+class Version {
+ /** @var string */
+ private $minVersion;
+ /** @var string */
+ private $maxVersion;
+
+ /**
+ * @param string $minVersion
+ * @param string $maxVersion
+ */
+ public function __construct($minVersion, $maxVersion) {
+ $this->minVersion = $minVersion;
+ $this->maxVersion = $maxVersion;
+ }
+
+ /**
+ * @return string
+ */
+ public function getMinimumVersion() {
+ return $this->minVersion;
+ }
+
+ /**
+ * @return string
+ */
+ public function getMaximumVersion() {
+ return $this->maxVersion;
+ }
+}
diff --git a/lib/private/App/AppStore/Version/VersionParser.php b/lib/private/App/AppStore/Version/VersionParser.php
new file mode 100644
index 00000000000..1058a8bc0fa
--- /dev/null
+++ b/lib/private/App/AppStore/Version/VersionParser.php
@@ -0,0 +1,64 @@
+<?php
+/**
+ * @copyright Copyright (c) 2016 Lukas Reschke <lukas@statuscode.ch>
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+namespace OC\App\AppStore\Version;
+
+/**
+ * Class VersionParser parses the versions as sent by the Nextcloud app store
+ *
+ * @package OC\App\AppStore
+ */
+class VersionParser {
+ /**
+ * Returns the version for a version string
+ *
+ * @param string $versionSpec
+ * @return Version
+ * @throws \Exception If the version cannot be parsed
+ */
+ public function getVersion($versionSpec) {
+ // * indicates that the version is compatible with all versions
+ if($versionSpec === '*') {
+ return new Version('', '');
+ }
+
+ // Count the amount of =, if it is one then it's either maximum or minimum
+ // version. If it is two then it is maximum and minimum.
+ if (preg_match_all('/(?:>|<)(?:=|)[0-9.]+/', $versionSpec, $matches)) {
+ switch(count($matches[0])) {
+ case 1:
+ if(substr($matches[0][0], 0, 1) === '>') {
+ return new Version(substr($matches[0][0], 2), '');
+ } else {
+ return new Version('', substr($matches[0][0], 2));
+ }
+ break;
+ case 2:
+ return new Version(substr($matches[0][0], 2), substr($matches[0][1], 2));
+ break;
+ default:
+ throw new \Exception('Version cannot be parsed');
+ }
+ }
+
+ throw new \Exception('Version cannot be parsed');
+ }
+}
diff --git a/lib/private/Installer.php b/lib/private/Installer.php
index 009df790585..02dbd670a0a 100644
--- a/lib/private/Installer.php
+++ b/lib/private/Installer.php
@@ -40,12 +40,18 @@
namespace OC;
+use OC\App\AppStore\Fetcher\AppFetcher;
use OC\App\CodeChecker\CodeChecker;
use OC\App\CodeChecker\EmptyCheck;
use OC\App\CodeChecker\PrivateCheck;
+use OC\Archive\Archive;
use OC_App;
use OC_DB;
use OC_Helper;
+use OCP\Http\Client\IClientService;
+use OCP\ILogger;
+use OCP\ITempManager;
+use phpseclib\File\X509;
/**
* This class provides the functionality needed to install, update and remove plugins/apps
@@ -81,49 +87,13 @@ class Installer {
* needed to get the app working.
*
* Installs an app
- * @param array $data with all information
+ * @param string $appId App to install
* @throws \Exception
* @return integer
*/
- public static function installApp( $data = array()) {
- $l = \OC::$server->getL10N('lib');
-
- list($extractDir, $path) = self::downloadApp($data);
-
- $info = self::checkAppsIntegrity($data, $extractDir, $path);
- $appId = OC_App::cleanAppId($info['id']);
+ public function installApp($appId) {
$basedir = OC_App::getInstallPath().'/'.$appId;
- //check if the destination directory already exists
- if(is_dir($basedir)) {
- OC_Helper::rmdirr($extractDir);
- if($data['source']=='http') {
- unlink($path);
- }
- throw new \Exception($l->t("App directory already exists"));
- }
-
- if(!empty($data['pretent'])) {
- return false;
- }
-
- //copy the app to the correct place
- if(@!mkdir($basedir)) {
- OC_Helper::rmdirr($extractDir);
- if($data['source']=='http') {
- unlink($path);
- }
- throw new \Exception($l->t("Can't create app folder. Please fix permissions. %s", array($basedir)));
- }
-
- $extractDir .= '/' . $info['id'];
- if(!file_exists($extractDir)) {
- OC_Helper::rmdirr($basedir);
- throw new \Exception($l->t("Archive does not contain a directory named %s", $info['id']));
- }
- OC_Helper::copyr($extractDir, $basedir);
-
- //remove temporary files
- OC_Helper::rmdirr($extractDir);
+ $info = OC_App::getAppInfo($basedir.'/appinfo/info.xml', true);
//install the database
if(is_file($basedir.'/appinfo/database.xml')) {
@@ -168,7 +138,7 @@ class Installer {
*
* Checks whether or not an app is installed, i.e. registered in apps table.
*/
- public static function isInstalled( $app ) {
+ public static function isInstalled( $app ) {
return (\OC::$server->getConfig()->getAppValue($app, "installed_version", null) !== null);
}
@@ -265,58 +235,148 @@ class Installer {
}
/**
- * @param array $data
- * @return array
+ * Downloads an app and puts it into the app directory
+ *
+ * @param string $appId
+ * @param AppFetcher $appFetcher
+ * @param IClientService $clientService
+ * @param ITempManager $tempManager
+ * @param ILogger $logger
+ *
+ * @return bool Whether the installation was successful or not
* @throws \Exception
*/
- public static function downloadApp($data = array()) {
- $l = \OC::$server->getL10N('lib');
-
- if(!isset($data['source'])) {
- throw new \Exception($l->t("No source specified when installing app"));
- }
+ public function downloadApp($appId,
+ AppFetcher $appFetcher,
+ IClientService $clientService,
+ ITempManager $tempManager,
+ ILogger $logger) {
+ $appId = strtolower($appId);
+
+ $apps = $appFetcher->get();
+ foreach($apps as $app) {
+ if($app['id'] === $appId) {
+ // Verify if the certificate has been issued by the Nextcloud Code Authority CA
+ $x509 = new X509();
+ $x509->loadCA(file_get_contents(__DIR__ . '/../../resources/codesigning/root.crt'));
+ $x509->loadX509($app['certificate']);
+ if($x509->validateSignature() !== true) {
+ $logger->error(
+ sprintf(
+ 'App with id %s has a certificate not issued by a trusted Code Signing Authority',
+ $appId
+ ),
+ [
+ 'app' => 'core',
+ ]
+ );
+ return false;
+ }
- //download the file if necessary
- if($data['source']=='http') {
- $pathInfo = pathinfo($data['href']);
- $extension = isset($pathInfo['extension']) ? '.' . $pathInfo['extension'] : '';
- $path = \OC::$server->getTempManager()->getTemporaryFile($extension);
- if(!isset($data['href'])) {
- throw new \Exception($l->t("No href specified when installing app from http"));
- }
- $client = \OC::$server->getHTTPClientService()->newClient();
- $client->get($data['href'], ['save_to' => $path]);
- } else {
- if(!isset($data['path'])) {
- throw new \Exception($l->t("No path specified when installing app from local file"));
- }
- $path=$data['path'];
- }
+ // Verify if the certificate is issued for the requested app id
+ $certInfo = openssl_x509_parse($app['certificate']);
+ if(!isset($certInfo['subject']['CN'])) {
+ $logger->error(
+ sprintf(
+ 'App with id %s has a cert with no CN',
+ $appId
+ ),
+ [
+ 'app' => 'core',
+ ]
+ );
+ return false;
+ }
+ if($certInfo['subject']['CN'] !== $appId) {
+ $logger->error(
+ sprintf(
+ 'App with id %s has a cert issued to %s',
+ $appId,
+ $certInfo['subject']['CN']
+ ),
+ [
+ 'app' => 'core',
+ ]
+ );
+ return false;
+ }
- //detect the archive type
- $mime = \OC::$server->getMimeTypeDetector()->detect($path);
- if ($mime !=='application/zip' && $mime !== 'application/x-gzip' && $mime !== 'application/x-bzip2') {
- throw new \Exception($l->t("Archives of type %s are not supported", array($mime)));
- }
+ // Download the release
+ $tempFile = $tempManager->getTemporaryFile('.tar.gz');
+ $client = $clientService->newClient();
+ // FIXME: Proper way to determine what the latest release is
+ $client->get($app['releases'][0]['download'], ['save_to' => $tempFile]);
+
+ // Check if the signature actually matches the downloaded content
+ $certificate = openssl_get_publickey($app['certificate']);
+ $verified = (bool)openssl_verify(file_get_contents($tempFile), base64_decode($app['releases'][0]['signature']), $certificate, OPENSSL_ALGO_SHA512);
+ openssl_free_key($certificate);
+
+ if($verified === true) {
+ // Seems to match, let's proceed
+ $extractDir = $tempManager->getTemporaryFolder();
+ $archive = Archive::open($tempFile);
+
+ if($archive) {
+ $archive->extract($extractDir);
+
+ // Check if appinfo/info.xml has the same app ID as well
+ $loadEntities = libxml_disable_entity_loader(false);
+ $xml = simplexml_load_file($extractDir . '/' . $appId . '/appinfo/info.xml');
+ libxml_disable_entity_loader($loadEntities);
+ if((string)$xml->id !== $appId) {
+ $logger->error(
+ sprintf(
+ 'App for id %s has a wrong app ID in info.xml: %s',
+ $appId,
+ (string)$xml->id
+ ),
+ [
+ 'app' => 'core',
+ ]
+ );
+ return false;
+ }
- //extract the archive in a temporary folder
- $extractDir = \OC::$server->getTempManager()->getTemporaryFolder();
- OC_Helper::rmdirr($extractDir);
- mkdir($extractDir);
- if($archive=\OC\Archive\Archive::open($path)) {
- $archive->extract($extractDir);
- } else {
- OC_Helper::rmdirr($extractDir);
- if($data['source']=='http') {
- unlink($path);
+ // Move to app folder
+ $baseDir = OC_App::getInstallPath().'/'.$appId;
+ //copy the app to the correct place
+ if(@mkdir($baseDir)) {
+ $extractDir .= '/' . $appId;
+ OC_Helper::copyr($extractDir, $baseDir);
+ }
+ OC_Helper::copyr($extractDir, $baseDir);
+ OC_Helper::rmdirr($extractDir);
+ return true;
+ } else {
+ $logger->error(
+ sprintf(
+ 'Could not extract app with ID %s to %s',
+ $appId,
+ $extractDir
+ ),
+ [
+ 'app' => 'core',
+ ]
+ );
+ return false;
+ }
+ } else {
+ // Signature does not match
+ $logger->error(
+ sprintf(
+ 'App with id %s has invalid signature',
+ $appId
+ ),
+ [
+ 'app' => 'core',
+ ]
+ );
+ }
}
- throw new \Exception($l->t("Failed to open archive when installing app"));
}
- return array(
- $extractDir,
- $path
- );
+ return false;
}
/**
@@ -466,7 +526,7 @@ class Installer {
*
* The function will check if the app is already downloaded in the apps repository
*/
- public static function isDownloaded( $name ) {
+ public function isDownloaded($name) {
foreach(\OC::$APPSROOTS as $dir) {
$dirToTest = $dir['path'];
$dirToTest .= '/';
diff --git a/lib/private/OCSClient.php b/lib/private/OCSClient.php
deleted file mode 100644
index 76c0b136c06..00000000000
--- a/lib/private/OCSClient.php
+++ /dev/null
@@ -1,351 +0,0 @@
-<?php
-/**
- * @copyright Copyright (c) 2016, ownCloud, Inc.
- *
- * @author Bart Visscher <bartv@thisnet.nl>
- * @author Brice Maron <brice@bmaron.net>
- * @author Felix Moeller <mail@felixmoeller.de>
- * @author Frank Karlitschek <frank@karlitschek.de>
- * @author Jarrett <JetUni@users.noreply.github.com>
- * @author Joas Schilling <coding@schilljs.com>
- * @author Jörn Friedrich Dreyer <jfd@butonic.de>
- * @author Kamil Domanski <kdomanski@kdemail.net>
- * @author Lukas Reschke <lukas@statuscode.ch>
- * @author Morris Jobke <hey@morrisjobke.de>
- * @author Robin McCorkell <robin@mccorkell.me.uk>
- * @author Sam Tuke <mail@samtuke.com>
- * @author Thomas Müller <thomas.mueller@tmit.eu>
- *
- * @license AGPL-3.0
- *
- * This code is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License, version 3,
- * as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License, version 3,
- * along with this program. If not, see <http://www.gnu.org/licenses/>
- *
- */
-
-namespace OC;
-
-use OCP\Http\Client\IClientService;
-use OCP\IConfig;
-use OCP\ILogger;
-
-/**
- * Class OCSClient is a class for communication with the ownCloud appstore
- *
- * @package OC
- */
-class OCSClient {
- /** @var IClientService */
- private $httpClientService;
- /** @var IConfig */
- private $config;
- /** @var ILogger */
- private $logger;
-
- /**
- * @param IClientService $httpClientService
- * @param IConfig $config
- * @param ILogger $logger
- */
- public function __construct(IClientService $httpClientService,
- IConfig $config,
- ILogger $logger) {
- $this->httpClientService = $httpClientService;
- $this->config = $config;
- $this->logger = $logger;
- }
-
- /**
- * Returns whether the AppStore is enabled (i.e. because the AppStore is disabled for EE)
- *
- * @return bool
- */
- public function isAppStoreEnabled() {
- return $this->config->getSystemValue('appstoreenabled', true) === true;
- }
-
- /**
- * Get the url of the OCS AppStore server.
- *
- * @return string of the AppStore server
- */
- private function getAppStoreUrl() {
- return $this->config->getSystemValue('appstoreurl', 'https://api.owncloud.com/v1');
- }
-
- /**
- * @param string $body
- * @param string $action
- * @return null|\SimpleXMLElement
- */
- private function loadData($body, $action) {
- $loadEntities = libxml_disable_entity_loader(true);
- $data = @simplexml_load_string($body);
- libxml_disable_entity_loader($loadEntities);
-
- if($data === false) {
- libxml_clear_errors();
- $this->logger->error(
- sprintf('Could not get %s, content was no valid XML', $action),
- [
- 'app' => 'core',
- ]
- );
- return null;
- }
-
- return $data;
- }
-
- /**
- * Get all the categories from the OCS server
- *
- * @param array $targetVersion The target ownCloud version
- * @return array|null an array of category ids or null
- * @note returns NULL if config value appstoreenabled is set to false
- * This function returns a list of all the application categories on the OCS server
- */
- public function getCategories(array $targetVersion) {
- if (!$this->isAppStoreEnabled()) {
- return null;
- }
-
- $client = $this->httpClientService->newClient();
- try {
- $response = $client->get(
- $this->getAppStoreUrl() . '/content/categories',
- [
- 'timeout' => 20,
- 'query' => [
- 'version' => implode('x', $targetVersion),
- ],
- ]
- );
- } catch(\Exception $e) {
- $this->logger->error(
- sprintf('Could not get categories: %s', $e->getMessage()),
- [
- 'app' => 'core',
- ]
- );
- return null;
- }
-
- $data = $this->loadData($response->getBody(), 'categories');
- if($data === null) {
- return null;
- }
-
- $tmp = $data->data;
- $cats = [];
-
- foreach ($tmp->category as $value) {
- $id = (int)$value->id;
- $name = (string)$value->name;
- $cats[$id] = $name;
- }
-
- return $cats;
- }
-
- /**
- * Get all the applications from the OCS server
- * @param array $categories
- * @param int $page
- * @param string $filter
- * @param array $targetVersion The target ownCloud version
- * @return array An array of application data
- */
- public function getApplications(array $categories, $page, $filter, array $targetVersion) {
- if (!$this->isAppStoreEnabled()) {
- return [];
- }
-
- $client = $this->httpClientService->newClient();
- try {
- $response = $client->get(
- $this->getAppStoreUrl() . '/content/data',
- [
- 'timeout' => 20,
- 'query' => [
- 'version' => implode('x', $targetVersion),
- 'filter' => $filter,
- 'categories' => implode('x', $categories),
- 'sortmode' => 'new',
- 'page' => $page,
- 'pagesize' => 100,
- 'approved' => $filter
- ],
- ]
- );
- } catch(\Exception $e) {
- $this->logger->error(
- sprintf('Could not get applications: %s', $e->getMessage()),
- [
- 'app' => 'core',
- ]
- );
- return [];
- }
-
- $data = $this->loadData($response->getBody(), 'applications');
- if($data === null) {
- return [];
- }
-
- $tmp = $data->data->content;
- $tmpCount = count($tmp);
-
- $apps = [];
- for ($i = 0; $i < $tmpCount; $i++) {
- $app = [];
- $app['id'] = (string)$tmp[$i]->id;
- $app['name'] = (string)$tmp[$i]->name;
- $app['label'] = (string)$tmp[$i]->label;
- $app['version'] = (string)$tmp[$i]->version;
- $app['type'] = (string)$tmp[$i]->typeid;
- $app['typename'] = (string)$tmp[$i]->typename;
- $app['personid'] = (string)$tmp[$i]->personid;
- $app['profilepage'] = (string)$tmp[$i]->profilepage;
- $app['license'] = (string)$tmp[$i]->license;
- $app['detailpage'] = (string)$tmp[$i]->detailpage;
- $app['preview'] = (string)$tmp[$i]->smallpreviewpic1;
- $app['preview-full'] = (string)$tmp[$i]->previewpic1;
- $app['changed'] = strtotime($tmp[$i]->changed);
- $app['description'] = (string)$tmp[$i]->description;
- $app['score'] = (string)$tmp[$i]->score;
- $app['downloads'] = (int)$tmp[$i]->downloads;
- $app['level'] = (int)$tmp[$i]->approved;
-
- $apps[] = $app;
- }
-
- return $apps;
- }
-
-
- /**
- * Get an the applications from the OCS server
- *
- * @param string $id
- * @param array $targetVersion The target ownCloud version
- * @return array|null an array of application data or null
- *
- * This function returns an applications from the OCS server
- */
- public function getApplication($id, array $targetVersion) {
- if (!$this->isAppStoreEnabled()) {
- return null;
- }
-
- $client = $this->httpClientService->newClient();
- try {
- $response = $client->get(
- $this->getAppStoreUrl() . '/content/data/' . urlencode($id),
- [
- 'timeout' => 20,
- 'query' => [
- 'version' => implode('x', $targetVersion),
- ],
- ]
- );
- } catch(\Exception $e) {
- $this->logger->error(
- sprintf('Could not get application: %s', $e->getMessage()),
- [
- 'app' => 'core',
- ]
- );
- return null;
- }
-
- $data = $this->loadData($response->getBody(), 'application');
- if($data === null) {
- return null;
- }
-
- $tmp = $data->data->content;
- if (is_null($tmp)) {
- \OCP\Util::writeLog('core', 'No update found at the ownCloud appstore for app ' . $id, \OCP\Util::DEBUG);
- return null;
- }
-
- $app = [];
- $app['id'] = (int)$id;
- $app['name'] = (string)$tmp->name;
- $app['version'] = (string)$tmp->version;
- $app['type'] = (string)$tmp->typeid;
- $app['label'] = (string)$tmp->label;
- $app['typename'] = (string)$tmp->typename;
- $app['personid'] = (string)$tmp->personid;
- $app['profilepage'] = (string)$tmp->profilepage;
- $app['detailpage'] = (string)$tmp->detailpage;
- $app['preview1'] = (string)$tmp->smallpreviewpic1;
- $app['preview2'] = (string)$tmp->smallpreviewpic2;
- $app['preview3'] = (string)$tmp->smallpreviewpic3;
- $app['changed'] = strtotime($tmp->changed);
- $app['description'] = (string)$tmp->description;
- $app['detailpage'] = (string)$tmp->detailpage;
- $app['score'] = (int)$tmp->score;
- $app['level'] = (int)$tmp->approved;
-
- return $app;
- }
-
- /**
- * Get the download url for an application from the OCS server
- * @param string $id
- * @param array $targetVersion The target ownCloud version
- * @return array|null an array of application data or null
- */
- public function getApplicationDownload($id, array $targetVersion) {
- if (!$this->isAppStoreEnabled()) {
- return null;
- }
- $url = $this->getAppStoreUrl() . '/content/download/' . urlencode($id) . '/1';
- $client = $this->httpClientService->newClient();
- try {
- $response = $client->get(
- $url,
- [
- 'timeout' => 20,
- 'query' => [
- 'version' => implode('x', $targetVersion),
- ],
- ]
- );
- } catch(\Exception $e) {
- $this->logger->error(
- sprintf('Could not get application download URL: %s', $e->getMessage()),
- [
- 'app' => 'core',
- ]
- );
- return null;
- }
-
- $data = $this->loadData($response->getBody(), 'application download URL');
- if($data === null) {
- return null;
- }
-
- $tmp = $data->data->content;
- $app = [];
- if (isset($tmp->downloadlink)) {
- $app['downloadlink'] = (string)$tmp->downloadlink;
- } else {
- $app['downloadlink'] = '';
- }
- return $app;
- }
-
-}
diff --git a/lib/private/Server.php b/lib/private/Server.php
index 21ec311401d..39905dcf7ce 100644
--- a/lib/private/Server.php
+++ b/lib/private/Server.php
@@ -580,13 +580,6 @@ class Server extends ServerContainer implements IServerContainer {
$c->getThemingDefaults()
);
});
- $this->registerService('OcsClient', function (Server $c) {
- return new OCSClient(
- $this->getHTTPClientService(),
- $this->getConfig(),
- $this->getLogger()
- );
- });
$this->registerService('LDAPProvider', function(Server $c) {
$config = $c->getConfig();
$factoryClass = $config->getSystemValue('ldapProviderFactory', null);
diff --git a/lib/private/legacy/app.php b/lib/private/legacy/app.php
index d25534aa822..1db1ce74cdc 100644
--- a/lib/private/legacy/app.php
+++ b/lib/private/legacy/app.php
@@ -1,6 +1,7 @@
<?php
/**
* @copyright Copyright (c) 2016, ownCloud, Inc.
+ * @copyright Copyright (c) 2016, Lukas Reschke <lukas@statuscode.ch>
*
* @author Arthur Schiwon <blizzz@arthur-schiwon.de>
* @author Bart Visscher <bartv@thisnet.nl>
@@ -326,24 +327,59 @@ class OC_App {
/**
* enables an app
*
- * @param mixed $app app
+ * @param string $appId
* @param array $groups (optional) when set, only these groups will have access to the app
* @throws \Exception
* @return void
*
* This function set an app as enabled in appconfig.
*/
- public static function enable($app, $groups = null) {
+ public function enable($appId,
+ $groups = null) {
self::$enabledAppsCache = []; // flush
- if (!Installer::isInstalled($app)) {
- $app = self::installApp($app);
+ $l = \OC::$server->getL10N('core');
+ $config = \OC::$server->getConfig();
+
+ // Check if app is already downloaded
+ $installer = new Installer();
+ $isDownloaded = $installer->isDownloaded($appId);
+
+ if(!$isDownloaded) {
+ $state = $installer->downloadApp(
+ $appId,
+ new \OC\App\AppStore\Fetcher\AppFetcher(
+ \OC::$server->getAppDataDir('appstore'),
+ \OC::$server->getHTTPClientService(),
+ new \OC\AppFramework\Utility\TimeFactory(),
+ $config
+ ),
+ \OC::$server->getHTTPClientService(),
+ \OC::$server->getTempManager(),
+ \OC::$server->getLogger()
+ );
+
+ if($state !== true) {
+ throw new \Exception(
+ sprintf(
+ 'Could not download app with id: %s',
+ $appId
+ )
+ );
+ }
+ }
+
+ if (!Installer::isInstalled($appId)) {
+ $appId = self::installApp(
+ $appId,
+ $config,
+ $l
+ );
+ $installer->installApp($appId);
} else {
// check for required dependencies
- $config = \OC::$server->getConfig();
- $l = \OC::$server->getL10N('core');
- $info = self::getAppInfo($app);
-
+ $info = self::getAppInfo($appId);
self::checkAppDependencies($config, $l, $info);
+ $installer->installApp($appId);
}
$appManager = \OC::$server->getAppManager();
@@ -356,42 +392,21 @@ class OC_App {
$groupsList[] = $groupManager->get($group);
}
}
- $appManager->enableAppForGroups($app, $groupsList);
+ $appManager->enableAppForGroups($appId, $groupsList);
} else {
- $appManager->enableApp($app);
+ $appManager->enableApp($appId);
}
- $info = self::getAppInfo($app);
+ $info = self::getAppInfo($appId);
if(isset($info['settings']) && is_array($info['settings'])) {
- $appPath = self::getAppPath($app);
- self::registerAutoloading($app, $appPath);
+ $appPath = self::getAppPath($appId);
+ self::registerAutoloading($appId, $appPath);
\OC::$server->getSettingsManager()->setupSettings($info['settings']);
}
}
/**
* @param string $app
- * @return int
- */
- private static function downloadApp($app) {
- $ocsClient = new OCSClient(
- \OC::$server->getHTTPClientService(),
- \OC::$server->getConfig(),
- \OC::$server->getLogger()
- );
- $appData = $ocsClient->getApplication($app, \OCP\Util::getVersion());
- $download = $ocsClient->getApplicationDownload($app, \OCP\Util::getVersion());
- if(isset($download['downloadlink']) and $download['downloadlink']!='') {
- // Replace spaces in download link without encoding entire URL
- $download['downloadlink'] = str_replace(' ', '%20', $download['downloadlink']);
- $info = array('source' => 'http', 'href' => $download['downloadlink'], 'appdata' => $appData);
- $app = Installer::installApp($info);
- }
- return $app;
- }
-
- /**
- * @param string $app
* @return bool
*/
public static function removeApp($app) {
@@ -409,11 +424,6 @@ class OC_App {
* @throws Exception
*/
public static function disable($app) {
- // Convert OCS ID to regular application identifier
- if(self::getInternalAppIdByOcs($app) !== false) {
- $app = self::getInternalAppIdByOcs($app);
- }
-
// flush
self::$enabledAppsCache = array();
@@ -613,18 +623,6 @@ class OC_App {
return false;
}
-
- /**
- * check if an app's directory is writable
- *
- * @param string $appId
- * @return bool
- */
- public static function isAppDirWritable($appId) {
- $path = self::getAppPath($appId);
- return ($path !== false) ? is_writable($path) : false;
- }
-
/**
* Get the path for the given app on the access
* If the app is defined in multiple directories, the first one is taken. (false if not found)
@@ -837,20 +835,11 @@ class OC_App {
/**
* List all apps, this is used in apps.php
*
- * @param bool $onlyLocal
- * @param bool $includeUpdateInfo Should we check whether there is an update
- * in the app store?
- * @param OCSClient $ocsClient
* @return array
*/
- public static function listAllApps($onlyLocal = false,
- $includeUpdateInfo = true,
- OCSClient $ocsClient) {
+ public function listAllApps() {
$installedApps = OC_App::getAllApps();
- //TODO which apps do we want to blacklist and how do we integrate
- // blacklisting with the multi apps folder feature?
-
//we don't want to show configuration for these
$blacklist = \OC::$server->getAppManager()->getAlwaysEnabledApps();
$appList = array();
@@ -893,8 +882,6 @@ class OC_App {
$info['removable'] = true;
}
- $info['update'] = ($includeUpdateInfo) ? Installer::isUpdateAvailable($app) : null;
-
$appPath = self::getAppPath($app);
if($appPath !== false) {
$appIcon = $appPath . '/img/' . $app . '.svg';
@@ -926,29 +913,8 @@ class OC_App {
$appList[] = $info;
}
}
- if ($onlyLocal) {
- $remoteApps = [];
- } else {
- $remoteApps = OC_App::getAppstoreApps('approved', null, $ocsClient);
- }
- if ($remoteApps) {
- // Remove duplicates
- foreach ($appList as $app) {
- foreach ($remoteApps AS $key => $remote) {
- if ($app['name'] === $remote['name'] ||
- (isset($app['ocsid']) &&
- $app['ocsid'] === $remote['id'])
- ) {
- unset($remoteApps[$key]);
- }
- }
- }
- $combinedApps = array_merge($appList, $remoteApps);
- } else {
- $combinedApps = $appList;
- }
- return $combinedApps;
+ return $appList;
}
/**
@@ -966,70 +932,6 @@ class OC_App {
return false;
}
- /**
- * Get a list of all apps on the appstore
- * @param string $filter
- * @param string|null $category
- * @param OCSClient $ocsClient
- * @return array|bool multi-dimensional array of apps.
- * Keys: id, name, type, typename, personid, license, detailpage, preview, changed, description
- */
- public static function getAppstoreApps($filter = 'approved',
- $category = null,
- OCSClient $ocsClient) {
- $categories = [$category];
-
- if (is_null($category)) {
- $categoryNames = $ocsClient->getCategories(\OCP\Util::getVersion());
- if (is_array($categoryNames)) {
- // Check that categories of apps were retrieved correctly
- if (!$categories = array_keys($categoryNames)) {
- return false;
- }
- } else {
- return false;
- }
- }
-
- $page = 0;
- $remoteApps = $ocsClient->getApplications($categories, $page, $filter, \OCP\Util::getVersion());
- $apps = [];
- $i = 0;
- $l = \OC::$server->getL10N('core');
- foreach ($remoteApps as $app) {
- $potentialCleanId = self::getInternalAppIdByOcs($app['id']);
- // enhance app info (for example the description)
- $apps[$i] = OC_App::parseAppInfo($app);
- $apps[$i]['author'] = $app['personid'];
- $apps[$i]['ocs_id'] = $app['id'];
- $apps[$i]['internal'] = 0;
- $apps[$i]['active'] = ($potentialCleanId !== false) ? self::isEnabled($potentialCleanId) : false;
- $apps[$i]['update'] = false;
- $apps[$i]['groups'] = false;
- $apps[$i]['score'] = $app['score'];
- $apps[$i]['removable'] = false;
- if ($app['label'] == 'recommended') {
- $apps[$i]['internallabel'] = (string)$l->t('Recommended');
- $apps[$i]['internalclass'] = 'recommendedapp';
- }
-
- // Apps from the appstore are always assumed to be compatible with the
- // the current release as the initial filtering is done on the appstore
- $apps[$i]['dependencies']['owncloud']['@attributes']['min-version'] = implode('.', \OCP\Util::getVersion());
- $apps[$i]['dependencies']['owncloud']['@attributes']['max-version'] = implode('.', \OCP\Util::getVersion());
-
- $i++;
- }
-
-
-
- if (empty($apps)) {
- return false;
- } else {
- return $apps;
- }
- }
-
public static function shouldUpgrade($app) {
$versions = self::getAppVersions();
$currentVersion = OC_App::getAppVersion($app);
@@ -1132,46 +1034,16 @@ class OC_App {
/**
* @param string $app
+ * @param \OCP\IConfig $config
+ * @param \OCP\IL10N $l
* @return bool
+ *
* @throws Exception if app is not compatible with this version of ownCloud
* @throws Exception if no app-name was specified
*/
- public static function installApp($app) {
- $appName = $app; // $app will be overwritten, preserve name for error logging
- $l = \OC::$server->getL10N('core');
- $config = \OC::$server->getConfig();
- $ocsClient = new OCSClient(
- \OC::$server->getHTTPClientService(),
- $config,
- \OC::$server->getLogger()
- );
- $appData = $ocsClient->getApplication($app, \OCP\Util::getVersion());
-
- // check if app is a shipped app or not. OCS apps have an integer as id, shipped apps use a string
- if (!is_numeric($app)) {
- $shippedVersion = self::getAppVersion($app);
- if ($appData && version_compare($shippedVersion, $appData['version'], '<')) {
- $app = self::downloadApp($app);
- } else {
- $app = Installer::installShippedApp($app);
- }
- } else {
- // Maybe the app is already installed - compare the version in this
- // case and use the local already installed one.
- // FIXME: This is a horrible hack. I feel sad. The god of code cleanness may forgive me.
- $internalAppId = self::getInternalAppIdByOcs($app);
- if($internalAppId !== false) {
- if($appData && version_compare(\OC_App::getAppVersion($internalAppId), $appData['version'], '<')) {
- $app = self::downloadApp($app);
- } else {
- self::enable($internalAppId);
- $app = $internalAppId;
- }
- } else {
- $app = self::downloadApp($app);
- }
- }
-
+ public function installApp($app,
+ \OCP\IConfig $config,
+ \OCP\IL10N $l) {
if ($app !== false) {
// check if the app is compatible with this version of ownCloud
$info = self::getAppInfo($app);