/** * sets the background jobs execution type * @param string $type execution type * @return false|null * * This method sets the execution type of the background jobs. Possible types * are "none", "ajax", "webcron", "cron" */ public static function setExecutionType($type) { if (!in_array($type, array('none', 'ajax', 'webcron', 'cron'))) { return false; } return OC_Appconfig::setValue('core', 'backgroundjobs_mode', $type); }
/** * Check if a new version is available */ public static function check() { OC_Appconfig::setValue('core', 'lastupdatedat', microtime(true)); if (OC_Appconfig::getValue('core', 'installedat', '') == '') { OC_Appconfig::setValue('core', 'installedat', microtime(true)); } $updaterurl = 'http://apps.owncloud.com/updater.php'; $version = OC_Util::getVersion(); $version['installed'] = OC_Appconfig::getValue('core', 'installedat'); $version['updated'] = OC_Appconfig::getValue('core', 'lastupdatedat'); $version['updatechannel'] = 'stable'; $version['edition'] = OC_Util::getEditionString(); $versionstring = implode('x', $version); //fetch xml data from updater $url = $updaterurl . '?version=' . $versionstring; $xml = @file_get_contents($url); if ($xml == FALSE) { return array(); } $data = @simplexml_load_string($xml); $tmp = array(); $tmp['version'] = $data->version; $tmp['versionstring'] = $data->versionstring; $tmp['url'] = $data->url; $tmp['web'] = $data->web; return $tmp; }
/** * Check if a new version is available */ public static function check() { OC_Appconfig::setValue('core', 'lastupdatedat', microtime(true)); if (OC_Appconfig::getValue('core', 'installedat', '') == '') { OC_Appconfig::setValue('core', 'installedat', microtime(true)); } $updaterurl = 'http://apps.owncloud.com/updater.php'; $version = OC_Util::getVersion(); $version['installed'] = OC_Appconfig::getValue('core', 'installedat'); $version['updated'] = OC_Appconfig::getValue('core', 'lastupdatedat'); $version['updatechannel'] = 'stable'; $version['edition'] = OC_Util::getEditionString(); $versionstring = implode('x', $version); //fetch xml data from updater $url = $updaterurl . '?version=' . $versionstring; // set a sensible timeout of 10 sec to stay responsive even if the update server is down. $ctx = stream_context_create(array('http' => array('timeout' => 10))); $xml = @file_get_contents($url, 0, $ctx); if ($xml == false) { return array(); } $data = @simplexml_load_string($xml); $tmp = array(); $tmp['version'] = $data->version; $tmp['versionstring'] = $data->versionstring; $tmp['url'] = $data->url; $tmp['web'] = $data->web; return $tmp; }
/** * Check if a new version is available * @param string $updaterUrl the url to check, i.e. 'http://apps.owncloud.com/updater.php' * @return array | bool */ public function check($updaterUrl) { // Look up the cache - it is invalidated all 30 minutes if (\OC_Appconfig::getValue('core', 'lastupdatedat') + 1800 > time()) { return json_decode(\OC_Appconfig::getValue('core', 'lastupdateResult'), true); } \OC_Appconfig::setValue('core', 'lastupdatedat', time()); if (\OC_Appconfig::getValue('core', 'installedat', '') == '') { \OC_Appconfig::setValue('core', 'installedat', microtime(true)); } $version = \OC_Util::getVersion(); $version['installed'] = \OC_Appconfig::getValue('core', 'installedat'); $version['updated'] = \OC_Appconfig::getValue('core', 'lastupdatedat'); $version['updatechannel'] = \OC_Util::getChannel(); $version['edition'] = \OC_Util::getEditionString(); $version['build'] = \OC_Util::getBuild(); $versionString = implode('x', $version); //fetch xml data from updater $url = $updaterUrl . '?version=' . $versionString; // set a sensible timeout of 10 sec to stay responsive even if the update server is down. $ctx = stream_context_create(array('http' => array('timeout' => 10))); $xml = @file_get_contents($url, 0, $ctx); if ($xml == false) { return array(); } $data = @simplexml_load_string($xml); $tmp = array(); $tmp['version'] = $data->version; $tmp['versionstring'] = $data->versionstring; $tmp['url'] = $data->url; $tmp['web'] = $data->web; // Cache the result \OC_Appconfig::setValue('core', 'lastupdateResult', json_encode($data)); return $tmp; }
/** * gets user info */ public static function getUser($parameters) { $userid = $parameters['userid']; $return = array(); $return['email'] = OC_Preferences::getValue($userid, 'settings', 'email', ''); $default = OC_Appconfig::getValue('files', 'default_quota', 0); $return['quota'] = OC_Preferences::getValue($userid, 'files', 'quota', $default); return $return; }
function __construct() { $this->ldap_host = OC_Appconfig::getValue('user_ldap', 'ldap_host', ''); $this->ldap_port = OC_Appconfig::getValue('user_ldap', 'ldap_port', OC_USER_BACKEND_LDAP_DEFAULT_PORT); $this->ldap_dn = OC_Appconfig::getValue('user_ldap', 'ldap_dn', ''); $this->ldap_password = OC_Appconfig::getValue('user_ldap', 'ldap_password', ''); $this->ldap_base = OC_Appconfig::getValue('user_ldap', 'ldap_base', ''); $this->ldap_filter = OC_Appconfig::getValue('user_ldap', 'ldap_filter', ''); if (!empty($this->ldap_host) && !empty($this->ldap_port) && !empty($this->ldap_dn) && !empty($this->ldap_password) && !empty($this->ldap_base) && !empty($this->ldap_filter)) { $this->configured = true; } }
public static function checkNext() { // check both 1 file and 1 folder, this way new files are detected quicker because there are less folders than files usually $previousFile = \OC_Appconfig::getValue('files', 'backgroundwatcher_previous_file', 0); $previousFolder = \OC_Appconfig::getValue('files', 'backgroundwatcher_previous_folder', 0); $nextFile = self::getNextFileId($previousFile, false); $nextFolder = self::getNextFileId($previousFolder, true); \OC_Appconfig::setValue('files', 'backgroundwatcher_previous_file', $nextFile); \OC_Appconfig::setValue('files', 'backgroundwatcher_previous_folder', $nextFolder); if ($nextFile > 0) { self::checkUpdate($nextFile); } if ($nextFolder > 0) { self::checkUpdate($nextFolder); } }
function __construct() { $this->db_conn = false; $db_host = OC_Appconfig::getValue('user_django_auth', 'django_auth_db_host', ''); $db_name = OC_Appconfig::getValue('user_django_auth', 'django_auth_db_name', ''); $db_driver = OC_Appconfig::getValue('user_django_auth', 'django_auth_db_driver', 'mysql'); $db_user = OC_Appconfig::getValue('user_django_auth', 'django_auth_db_user', ''); $db_password = OC_Appconfig::getValue('user_django_auth', 'django_auth_db_password', ''); $dsn = "{$db_driver}:host={$db_host};dbname={$db_name}"; try { $this->db = new PDO($dsn, $db_user, $db_password); $this->db_conn = true; } catch (PDOException $e) { OC_Log::write('OC_User_Django_Auth', 'OC_User_Django_Auth, Failed to connect to django auth database: ' . $e->getMessage(), OC_Log::ERROR); } return false; }
public function __construct() { $this->pwauth_bin_path = OC_Appconfig::getValue('user_pwauth', 'pwauth_path', OC_USER_BACKEND_PWAUTH_PATH); $list = explode(";", OC_Appconfig::getValue('user_pwauth', 'uid_list', OC_USER_BACKEND_PWAUTH_UID_LIST)); $r = array(); foreach ($list as $entry) { if (strpos($entry, "-") === FALSE) { $r[] = $entry; } else { $range = explode("-", $entry); if ($range[0] < 0) { $range[0] = 0; } if ($range[1] < $range[0]) { $range[1] = $range[0]; } for ($i = $range[0]; $i <= $range[1]; $i++) { $r[] = $i; } } } $this->pwauth_uid_list = $r; }
/** * @brief if session is started, check if ownCloud key pair is set up, if not create it * @param \OC_FilesystemView $view * * @note The ownCloud key pair is used to allow public link sharing even if encryption is enabled */ public function __construct($view) { $this->view = $view; if (!$this->view->is_dir('owncloud_private_key')) { $this->view->mkdir('owncloud_private_key'); } $publicShareKeyId = \OC_Appconfig::getValue('files_encryption', 'publicShareKeyId'); if ($publicShareKeyId === null) { $publicShareKeyId = 'pubShare_' . substr(md5(time()), 0, 8); \OC_Appconfig::setValue('files_encryption', 'publicShareKeyId', $publicShareKeyId); } if (!$this->view->file_exists("/public-keys/" . $publicShareKeyId . ".public.key") || !$this->view->file_exists("/owncloud_private_key/" . $publicShareKeyId . ".private.key")) { $keypair = Crypt::createKeypair(); // Disable encryption proxy to prevent recursive calls $proxyStatus = \OC_FileProxy::$enabled; \OC_FileProxy::$enabled = false; // Save public key if (!$view->is_dir('/public-keys')) { $view->mkdir('/public-keys'); } $this->view->file_put_contents('/public-keys/' . $publicShareKeyId . '.public.key', $keypair['publicKey']); // Encrypt private key empty passphrase $encryptedPrivateKey = Crypt::symmetricEncryptFileContent($keypair['privateKey'], ''); // Save private key $this->view->file_put_contents('/owncloud_private_key/' . $publicShareKeyId . '.private.key', $encryptedPrivateKey); \OC_FileProxy::$enabled = $proxyStatus; } if (\OCA\Encryption\Helper::isPublicAccess()) { // Disable encryption proxy to prevent recursive calls $proxyStatus = \OC_FileProxy::$enabled; \OC_FileProxy::$enabled = false; $encryptedKey = $this->view->file_get_contents('/owncloud_private_key/' . $publicShareKeyId . '.private.key'); $privateKey = Crypt::decryptPrivateKey($encryptedKey, ''); $this->setPublicSharePrivateKey($privateKey); \OC_FileProxy::$enabled = $proxyStatus; } }
public function getParams() { $array = array(); foreach ($this->params as $key => $param) { $array[$param] = OC_Appconfig::getValue('user_wordpress', $param, ''); } if (empty($array['wordpress_db_host'])) { $array['wordpress_db_host'] = OC_Config::getValue("dbhost", ""); } if (empty($array['wordpress_db_name'])) { $array['wordpress_db_name'] = OC_Config::getValue("dbname", "owncloud"); } if (empty($array['wordpress_db_user'])) { $array['wordpress_db_user'] = OC_Config::getValue("dbuser", ""); } if (empty($array['wordpress_db_password'])) { $array['wordpress_db_password'] = OC_Config::getValue("dbpassword", ""); } if (empty($array['wordpress_have_to_be_logged'])) { $array['wordpress_have_to_be_logged'] = '0'; OC_Appconfig::setValue('user_wordpress', 'wordpress_have_to_be_logged', '0'); } return $array; }
if ($param === 'rcHost') { if ($_POST[$param] == '' || strlen($_POST[$param]) > 3) { OCP\Config::setAppValue('roundcube', $param, $_POST[$param]); } } else { if ($param === 'maildir') { $maildir = $_POST[$param]; if (substr($maildir, -1) != '/') { $maildir .= '/'; } OCP\Config::setAppValue('roundcube', $param, $maildir); } else { if ($param == 'rcRefreshInterval') { $refresh = trim($_POST[$param]); if ($refresh == '') { OC_Appconfig::deleteKey('roundcube', $param); } else { if (!is_numeric($refresh)) { OC_JSON::error(array("data" => array("message" => $l->t("Refresh interval '%s' is not a number.", array($refresh))))); return false; } else { OCP\Config::setAppValue('roundcube', $param, $refresh); } } } else { OCP\Config::setAppValue('roundcube', $param, $_POST[$param]); } } } } } else {
/** * check if user can only share with group members * @return bool */ public static function shareWithGroupMembersOnly() { $value = \OC_Appconfig::getValue('core', 'shareapi_only_share_with_group_members', 'no'); return $value === 'yes' ? true : false; }
<?php /** * ownCloud - Updater plugin * * @author Victor Dubiniuk * @copyright 2012-2013 Victor Dubiniuk victor.dubiniuk@gmail.com * * This file is licensed under the Affero General Public License version 3 or * later. */ namespace OCA\Updater; \OCP\User::checkAdminUser(); \OCP\Util::addScript(App::APP_ID, '3rdparty/angular'); \OCP\Util::addScript(App::APP_ID, 'app'); \OCP\Util::addScript(App::APP_ID, 'controllers'); \OCP\Util::addStyle(App::APP_ID, 'updater'); if (!@file_exists(App::getBackupBase())) { Helper::mkdir(App::getBackupBase()); } $data = App::getFeed(); $isNewVersionAvailable = isset($data['version']) && $data['version'] != '' && $data['version'] !== array(); $tmpl = new \OCP\Template(App::APP_ID, 'admin'); $lastCheck = \OC_Appconfig::getValue('core', 'lastupdatedat'); $tmpl->assign('checkedAt', \OCP\Util::formatDate($lastCheck)); $tmpl->assign('isNewVersionAvailable', $isNewVersionAvailable ? 'true' : 'false'); $tmpl->assign('channels', Channel::getChannels()); $tmpl->assign('currentChannel', Channel::getCurrentChannel()); $tmpl->assign('version', isset($data['versionstring']) ? $data['versionstring'] : ''); return $tmpl->fetchPage();
* 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 library. If not, see <http://www.gnu.org/licenses/>. * */ namespace OCA\Documents; \OCP\User::checkLoggedIn(); \OCP\JSON::checkAppEnabled('documents'); \OCP\App::setActiveNavigationEntry('documents_index'); \OCP\Util::addStyle('documents', 'style'); \OCP\Util::addStyle('documents', '3rdparty/webodf/dojo-app'); \OCP\Util::addScript('documents', 'documents'); \OCP\Util::addScript('files', 'file-upload'); \OCP\Util::addScript('files', 'jquery.iframe-transport'); \OCP\Util::addScript('files', 'jquery.fileupload'); $tmpl = new \OCP\Template('documents', 'documents', 'user'); $previewsEnabled = \OC::$server->getConfig()->getSystemValue('enable_previews', true); $unstable = \OCP\Config::getAppValue('documents', 'unstable', 'false'); $maxUploadFilesize = \OCP\Util::maxUploadFilesize("/"); $savePath = \OCP\Config::getUserValue(\OCP\User::getUser(), 'documents', 'save_path', '/'); $tmpl->assign('enable_previews', $previewsEnabled); $tmpl->assign('useUnstable', $unstable); $tmpl->assign('uploadMaxFilesize', $maxUploadFilesize); $tmpl->assign('uploadMaxHumanFilesize', \OCP\Util::humanFileSize($maxUploadFilesize)); $tmpl->assign('savePath', $savePath); $tmpl->assign("allowShareWithLink", \OC_Appconfig::getValue('core', 'shareapi_allow_links', 'yes')); $tmpl->printPage();
public function testDefaultExpireDate() { \Test_Files_Sharing_Api::loginHelper(\Test_Files_Sharing_Api::TEST_FILES_SHARING_API_USER1); \OC_Appconfig::setValue('core', 'shareapi_default_expire_date', 'yes'); \OC_Appconfig::setValue('core', 'shareapi_enforce_expire_date', 'yes'); \OC_Appconfig::setValue('core', 'shareapi_expire_after_n_days', '2'); // default expire date is set to 2 days // the time when the share was created is set to 3 days in the past // user defined expire date is set to +2 days from now on // -> link should be already expired by the default expire date but the user // share should still exists. $now = time(); $dateFormat = 'Y-m-d H:i:s'; $shareCreated = $now - 3 * 24 * 60 * 60; $expireDate = date($dateFormat, $now + 2 * 24 * 60 * 60); $info = OC\Files\Filesystem::getFileInfo($this->filename); $this->assertTrue($info instanceof \OC\Files\FileInfo); $result = \OCP\Share::shareItem('file', $info->getId(), \OCP\Share::SHARE_TYPE_LINK, null, \OCP\PERMISSION_READ); $this->assertTrue(is_string($result)); $result = \OCP\Share::shareItem('file', $info->getId(), \OCP\Share::SHARE_TYPE_USER, \Test_Files_Sharing_Api::TEST_FILES_SHARING_API_USER2, 31); $this->assertTrue($result); $result = \OCP\Share::setExpirationDate('file', $info->getId(), $expireDate); $this->assertTrue($result); //manipulate stime so that both shares are older then the default expire date $statement = "UPDATE `*PREFIX*share` SET `stime` = ? WHERE `share_type` = ?"; $query = \OCP\DB::prepare($statement); $result = $query->execute(array($shareCreated, \OCP\Share::SHARE_TYPE_LINK)); $this->assertSame(1, $result); $query = \OCP\DB::prepare($statement); $result = $query->execute(array($shareCreated, \OCP\Share::SHARE_TYPE_USER)); $this->assertSame(1, $result); // now the link share should expire because of enforced default expire date // the user share should still exist $result = \OCP\Share::getItemShared('file', $info->getId()); $this->assertTrue(is_array($result)); $this->assertSame(1, count($result)); $share = reset($result); $this->assertSame(\OCP\Share::SHARE_TYPE_USER, $share['share_type']); //cleanup $result = \OCP\Share::unshare('file', $info->getId(), \OCP\Share::SHARE_TYPE_USER, \Test_Files_Sharing_Api::TEST_FILES_SHARING_API_USER2); $this->assertTrue($result); \OC_Appconfig::setValue('core', 'shareapi_default_expire_date', 'no'); \OC_Appconfig::setValue('core', 'shareapi_enforce_expire_date', 'no'); }
<?php $currentVersion = OC_Appconfig::getValue('search_lucene', 'installed_version'); if (version_compare($currentVersion, '0.5.0', '<')) { //force reindexing of files $stmt = OCP\DB::prepare('DELETE FROM `*PREFIX*lucene_status` WHERE 1=1'); $stmt->execute(); //clear old background jobs $stmt = OCP\DB::prepare('DELETE FROM `*PREFIX*queuedtasks` WHERE `app`=?'); $stmt->execute(array('search_lucene')); }
$linkItem = $data['linkItem']; // Load the files $dir = $data['realPath']; $dir = \OC\Files\Filesystem::normalizePath($dir); if (!\OC\Files\Filesystem::is_dir($dir . '/')) { \OC_Response::setStatus(\OC_Response::STATUS_NOT_FOUND); \OCP\JSON::error(array('success' => false)); exit; } $data = array(); // make filelist $files = \OCA\Files\Helper::getFiles($dir, $sortAttribute, $sortDirection); $formattedFiles = array(); foreach ($files as $file) { $entry = \OCA\Files\Helper::formatFileInfo($file); unset($entry['directory']); // for now $entry['permissions'] = \OCP\PERMISSION_READ; $formattedFiles[] = $entry; } $data['directory'] = $relativePath; $data['files'] = $formattedFiles; $data['dirToken'] = $linkItem['token']; $permissions = $linkItem['permissions']; // if globally disabled if (OC_Appconfig::getValue('core', 'shareapi_allow_public_upload', 'yes') === 'no') { // only allow reading $permissions = \OCP\PERMISSION_READ; } $data['permissions'] = $permissions; OCP\JSON::success(array('data' => $data));
/** * @brief Erase a file's versions which exceed the set quota */ private static function expire($filename, $versionsSize = null, $offset = 0) { if (\OCP\Config::getSystemValue('files_versions', Storage::DEFAULTENABLED) == 'true') { list($uid, $filename) = self::getUidAndFilename($filename); $versionsFileview = new \OC\Files\View('/' . $uid . '/files_versions'); // get available disk space for user $softQuota = true; $quota = \OC_Preferences::getValue($uid, 'files', 'quota'); if ($quota === null || $quota === 'default') { $quota = \OC_Appconfig::getValue('files', 'default_quota'); } if ($quota === null || $quota === 'none') { $quota = \OC\Files\Filesystem::free_space('/'); $softQuota = false; } else { $quota = \OCP\Util::computerFileSize($quota); } // make sure that we have the current size of the version history if ($versionsSize === null) { $versionsSize = self::getVersionsSize($uid); if ($versionsSize === false || $versionsSize < 0) { $versionsSize = self::calculateSize($uid); } } // calculate available space for version history // subtract size of files and current versions size from quota if ($softQuota) { $files_view = new \OC\Files\View('/' . $uid . '/files'); $rootInfo = $files_view->getFileInfo('/'); $free = $quota - $rootInfo['size']; // remaining free space for user if ($free > 0) { $availableSpace = $free * self::DEFAULTMAXSIZE / 100 - ($versionsSize + $offset); // how much space can be used for versions } else { $availableSpace = $free - $versionsSize - $offset; } } else { $availableSpace = $quota - $offset; } // with the probability of 0.1% we reduce the number of all versions not only for the current file $random = rand(0, 1000); if ($random == 0) { $allFiles = true; } else { $allFiles = false; } $allVersions = Storage::getVersions($uid, $filename); $versionsByFile[$filename] = $allVersions; $sizeOfDeletedVersions = self::delOldVersions($versionsByFile, $allVersions, $versionsFileview); $availableSpace = $availableSpace + $sizeOfDeletedVersions; $versionsSize = $versionsSize - $sizeOfDeletedVersions; // if still not enough free space we rearrange the versions from all files if ($availableSpace <= 0 || $allFiles) { $result = Storage::getAllVersions($uid); $versionsByFile = $result['by_file']; $allVersions = $result['all']; $sizeOfDeletedVersions = self::delOldVersions($versionsByFile, $allVersions, $versionsFileview); $availableSpace = $availableSpace + $sizeOfDeletedVersions; $versionsSize = $versionsSize - $sizeOfDeletedVersions; } // Check if enough space is available after versions are rearranged. // If not we delete the oldest versions until we meet the size limit for versions, // but always keep the two latest versions $numOfVersions = count($allVersions) - 2; $i = 0; while ($availableSpace < 0 && $i < $numOfVersions) { $version = current($allVersions); $versionsFileview->unlink($version['path'] . '.v' . $version['version']); $versionsSize -= $version['size']; $availableSpace += $version['size']; next($allVersions); $i++; } return $versionsSize; // finally return the new size of the version history } return false; }
$upload_max_filesize = OCP\Util::computerFileSize(ini_get('upload_max_filesize')); $post_max_size = OCP\Util::computerFileSize(ini_get('post_max_size')); $maxUploadFilesize = OCP\Util::humanFileSize(min($upload_max_filesize, $post_max_size)); if ($_POST && OC_Util::isCallRegistered()) { if (isset($_POST['maxUploadSize'])) { if (($setMaxSize = OC_Files::setUploadLimit(OCP\Util::computerFileSize($_POST['maxUploadSize']))) !== false) { $maxUploadFilesize = OCP\Util::humanFileSize($setMaxSize); } } } OCP\App::setActiveNavigationEntry("files_administration"); $htaccessWritable = is_writable(OC::$SERVERROOT . '/.htaccess'); $tmpl = new OCP\Template('files', 'admin'); /* * extended version * + only users with permission can delete files(in the files app only) * + file type restriction */ $filetyprestriction = \OC_Appconfig::getValue('core', 'filetyperes_enabled', 'no'); $allowed_types = \OC_Appconfig::getValue('core', 'allowed_filetypes', ''); $deleteGroupsList = \OC_Appconfig::getValue('core', 'delete', ''); $deleteGroupsList = explode(',', $deleteGroupsList); $tmpl->assign('deleteGroupsList', implode('|', $deleteGroupsList)); $tmpl->assign('fileTypeRes', $filetyprestriction); $tmpl->assign('allowed_filetypes', $allowed_types); $tmpl->assign('uploadChangable', $htaccessWorking and $htaccessWritable); $tmpl->assign('uploadMaxFilesize', $maxUploadFilesize); // max possible makes only sense on a 32 bit system $tmpl->assign('displayMaxPossibleUploadSize', PHP_INT_SIZE === 4); $tmpl->assign('maxPossibleUploadSize', OCP\Util::humanFileSize(PHP_INT_MAX)); return $tmpl->fetchPage();
/** * Returns the URL of the default page * based on the system configuration and * the apps visible for the current user * * @return string URL */ public static function getDefaultPageUrl() { $urlGenerator = \OC::$server->getURLGenerator(); // Deny the redirect if the URL contains a @ // This prevents unvalidated redirects like ?redirect_url=:user@domain.com if (isset($_REQUEST['redirect_url']) && strpos($_REQUEST['redirect_url'], '@') === false) { $location = $urlGenerator->getAbsoluteURL(urldecode($_REQUEST['redirect_url'])); } else { $defaultPage = OC_Appconfig::getValue('core', 'defaultpage'); if ($defaultPage) { $location = $urlGenerator->getAbsoluteURL($defaultPage); } else { $appId = 'files'; $defaultApps = explode(',', \OCP\Config::getSystemValue('defaultapp', 'files')); // find the first app that is enabled for the current user foreach ($defaultApps as $defaultApp) { $defaultApp = OC_App::cleanAppId(strip_tags($defaultApp)); if (OC_App::isEnabled($defaultApp)) { $appId = $defaultApp; break; } } $location = $urlGenerator->getAbsoluteURL('/index.php/apps/' . $appId . '/'); } } return $location; }
/** * @brief disable recovery * * @param $recoveryPassword * @return bool */ public static function adminDisableRecovery($recoveryPassword) { $util = new Util(new \OC_FilesystemView('/'), \OCP\User::getUser()); $return = $util->checkRecoveryPassword($recoveryPassword); if ($return) { // Set recoveryAdmin as disabled \OC_Appconfig::setValue('files_encryption', 'recoveryAdminEnabled', 0); } return $return; }
/** * Returns the URL of the default page * based on the system configuration and * the apps visible for the current user * * @return string URL */ public static function getDefaultPageUrl() { $urlGenerator = \OC::$server->getURLGenerator(); if (isset($_REQUEST['redirect_url'])) { $location = urldecode($_REQUEST['redirect_url']); } else { $defaultPage = OC_Appconfig::getValue('core', 'defaultpage'); if ($defaultPage) { $location = $urlGenerator->getAbsoluteURL($defaultPage); } else { $appId = 'files'; $defaultApps = explode(',', \OCP\Config::getSystemValue('defaultapp', 'files')); // find the first app that is enabled for the current user foreach ($defaultApps as $defaultApp) { $defaultApp = OC_App::cleanAppId(strip_tags($defaultApp)); if (OC_App::isEnabled($defaultApp)) { $appId = $defaultApp; break; } } $location = $urlGenerator->getAbsoluteURL('/index.php/apps/' . $appId . '/'); } } return $location; }
<?php $currentVersion = OC_Appconfig::getValue('gallery', 'installed_version'); if (version_compare($currentVersion, '0.5.0', '<')) { $stmt = OCP\DB::prepare('DROP TABLE IF EXISTS `*PREFIX*gallery_photos`'); $stmt->execute(); $stmt = OCP\DB::prepare('DROP TABLE IF EXISTS `*PREFIX*gallery_albums`'); $stmt->execute(); \OC_DB::createDbFromStructure(OC_App::getAppPath($appid) . '/appinfo/database.xml'); }
* * 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/> * */ OC_JSON::checkSubAdminUser(); OCP\JSON::callCheck(); $username = isset($_POST["username"]) ? (string) $_POST["username"] : ''; if ($username === '' && !OC_User::isAdminUser(OC_User::getUser()) || !OC_User::isAdminUser(OC_User::getUser()) && !OC_SubAdmin::isUserAccessible(OC_User::getUser(), $username)) { $l = \OC::$server->getL10N('core'); OC_JSON::error(array('data' => array('message' => $l->t('Authentication error')))); exit; } //make sure the quota is in the expected format $quota = (string) $_POST["quota"]; if ($quota !== 'none' and $quota !== 'default') { $quota = OC_Helper::computerFileSize($quota); $quota = OC_Helper::humanFileSize($quota); } // Return Success story if ($username) { \OC::$server->getConfig()->setUserValue($username, 'files', 'quota', $quota); } else { //set the default quota when no username is specified if ($quota === 'default') { //'default' as default quota makes no sense $quota = 'none'; } OC_Appconfig::setValue('files', 'default_quota', $quota); } OC_JSON::success(array("data" => array("username" => $username, 'quota' => $quota)));
/** * Sets a value in the appconfig * @param string $app app * @param string $key key * @param string $value value * @return string true/false * * Sets a value. If the key did not exist before it will be created. */ public static function setAppValue($app, $key, $value) { try { \OC_Appconfig::setValue($app, $key, $value); } catch (Exception $e) { return false; } return true; }
/** * install an app already placed in the app folder * @param string $app id of the app to install * @return integer */ public static function installShippedApp($app) { //install the database if (is_file(OC_App::getAppPath($app) . "/appinfo/database.xml")) { OC_DB::createDbFromStructure(OC_App::getAppPath($app) . "/appinfo/database.xml"); } //run appinfo/install.php if (is_file(OC_App::getAppPath($app) . "/appinfo/install.php")) { include OC_App::getAppPath($app) . "/appinfo/install.php"; } $info = OC_App::getAppInfo($app); if (is_null($info)) { return false; } OC_Appconfig::setValue($app, 'installed_version', OC_App::getAppVersion($app)); if (array_key_exists('ocsid', $info)) { OC_Appconfig::setValue($app, 'ocsid', $info['ocsid']); } //set remote/public handelers foreach ($info['remote'] as $name => $path) { OCP\CONFIG::setAppValue('core', 'remote_' . $name, $app . '/' . $path); } foreach ($info['public'] as $name => $path) { OCP\CONFIG::setAppValue('core', 'public_' . $name, $app . '/' . $path); } OC_App::setAppTypes($info['id']); return $info['id']; }
/** * runs the update actions in maintenance mode, does not upgrade the source files * except the main .htaccess file * * @param string $currentVersion current version to upgrade to * @param string $installedVersion previous version from which to upgrade from * * @throws \Exception * @return bool true if the operation succeeded, false otherwise */ private function doUpgrade($currentVersion, $installedVersion) { // Stop update if the update is over several major versions if (!self::isUpgradePossible($installedVersion, $currentVersion)) { throw new \Exception('Updates between multiple major versions are unsupported.'); } // Update htaccess files for apache hosts if (isset($_SERVER['SERVER_SOFTWARE']) && strstr($_SERVER['SERVER_SOFTWARE'], 'Apache')) { \OC_Setup::updateHtaccess(); } // create empty file in data dir, so we can later find // out that this is indeed an ownCloud data directory // (in case it didn't exist before) file_put_contents(\OC_Config::getValue('datadirectory', \OC::$SERVERROOT . '/data') . '/.ocdata', ''); /* * START CONFIG CHANGES FOR OLDER VERSIONS */ if (!\OC::$CLI && version_compare($installedVersion, '6.90.1', '<')) { // Add the trusted_domains config if it is not existant // This is added to prevent host header poisoning \OC_Config::setValue('trusted_domains', \OC_Config::getValue('trusted_domains', array(\OC_Request::serverHost()))); } /* * STOP CONFIG CHANGES FOR OLDER VERSIONS */ // pre-upgrade repairs $repair = new \OC\Repair(\OC\Repair::getBeforeUpgradeRepairSteps()); $repair->run(); // simulate DB upgrade if ($this->simulateStepEnabled) { $this->checkCoreUpgrade(); // simulate apps DB upgrade $this->checkAppUpgrade($currentVersion); } // upgrade from OC6 to OC7 // TODO removed it again for OC8 $sharePolicy = \OC_Appconfig::getValue('core', 'shareapi_share_policy', 'global'); if ($sharePolicy === 'groups_only') { \OC_Appconfig::setValue('core', 'shareapi_only_share_with_group_members', 'yes'); } if ($this->updateStepEnabled) { $this->doCoreUpgrade(); $disabledApps = \OC_App::checkAppsRequirements(); if (!empty($disabledApps)) { $this->emit('\\OC\\Updater', 'disabledApps', array($disabledApps)); } $this->doAppUpgrade(); // post-upgrade repairs $repair = new \OC\Repair(\OC\Repair::getRepairSteps()); $repair->run(); //Invalidate update feed \OC_Appconfig::setValue('core', 'lastupdatedat', 0); // only set the final version if everything went well \OC_Config::setValue('version', implode('.', \OC_Util::getVersion())); } }
/** * update the database for the app and call the update script * * @param string $appId * @return bool */ public static function updateApp($appId) { if (file_exists(self::getAppPath($appId) . '/appinfo/database.xml')) { OC_DB::updateDbFromStructure(self::getAppPath($appId) . '/appinfo/database.xml'); } if (!self::isEnabled($appId)) { return false; } if (file_exists(self::getAppPath($appId) . '/appinfo/update.php')) { self::loadApp($appId, false); include self::getAppPath($appId) . '/appinfo/update.php'; } //set remote/public handlers $appData = self::getAppInfo($appId); if (array_key_exists('ocsid', $appData)) { OC_Appconfig::setValue($appId, 'ocsid', $appData['ocsid']); } foreach ($appData['remote'] as $name => $path) { OCP\CONFIG::setAppValue('core', 'remote_' . $name, $appId . '/' . $path); } foreach ($appData['public'] as $name => $path) { OCP\CONFIG::setAppValue('core', 'public_' . $name, $appId . '/' . $path); } self::setAppTypes($appId); $version = \OC_App::getAppVersion($appId); \OC_Appconfig::setValue($appId, 'installed_version', $version); return true; }
/** * @large */ function testRecoveryForUser() { // login as admin \Test_Encryption_Util::loginHelper(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1); $result = \OCA\Encryption\Helper::adminEnableRecovery(null, 'test123'); $this->assertTrue($result); $recoveryKeyId = OC_Appconfig::getValue('files_encryption', 'recoveryKeyId'); // login as user2 \Test_Encryption_Util::loginHelper(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2); $util = new \OCA\Encryption\Util(new \OC_FilesystemView('/'), \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2); // enable recovery for admin $this->assertTrue($util->setRecoveryForUser(1)); // add recovery keys for existing files (e.g. the auto-generated welcome.txt) $util->addRecoveryKeys(); // create folder structure $this->view->mkdir('/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2 . '/files' . $this->folder1); $this->view->mkdir('/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2 . '/files' . $this->folder1 . $this->subfolder); $this->view->mkdir('/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2 . '/files' . $this->folder1 . $this->subfolder . $this->subsubfolder); // save file with content $cryptedFile1 = file_put_contents('crypt:///' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2 . '/files/' . $this->filename, $this->dataShort); $cryptedFile2 = file_put_contents('crypt:///' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2 . '/files/' . $this->folder1 . $this->subfolder . $this->subsubfolder . '/' . $this->filename, $this->dataShort); // test that data was successfully written $this->assertTrue(is_int($cryptedFile1)); $this->assertTrue(is_int($cryptedFile2)); // check if share key for user and recovery exists $this->assertTrue($this->view->file_exists('/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2 . '/files_encryption/share-keys/' . $this->filename . '.' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2 . '.shareKey')); $this->assertTrue($this->view->file_exists('/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2 . '/files_encryption/share-keys/' . $this->filename . '.' . $recoveryKeyId . '.shareKey')); $this->assertTrue($this->view->file_exists('/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2 . '/files_encryption/share-keys/' . $this->folder1 . $this->subfolder . $this->subsubfolder . '/' . $this->filename . '.' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2 . '.shareKey')); $this->assertTrue($this->view->file_exists('/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2 . '/files_encryption/share-keys/' . $this->folder1 . $this->subfolder . $this->subsubfolder . '/' . $this->filename . '.' . $recoveryKeyId . '.shareKey')); // login as admin \Test_Encryption_Util::loginHelper(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1); // change password \OC_User::setPassword(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2, 'test', 'test123'); $params = array('uid' => \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2, 'password' => 'test', 'recoveryPassword' => 'test123'); \OCA\Encryption\Hooks::setPassphrase($params); // login as user2 \Test_Encryption_Util::loginHelper(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2, false, 'test'); // get file contents $retrievedCryptedFile1 = file_get_contents('crypt:///' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2 . '/files/' . $this->filename); $retrievedCryptedFile2 = file_get_contents('crypt:///' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2 . '/files' . $this->folder1 . $this->subfolder . $this->subsubfolder . '/' . $this->filename); // check if data is the same as we previously written $this->assertEquals($this->dataShort, $retrievedCryptedFile1); $this->assertEquals($this->dataShort, $retrievedCryptedFile2); // cleanup $this->view->chroot('/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2 . '/files/'); $this->view->unlink($this->folder1); $this->view->unlink($this->filename); $this->view->chroot('/'); // check if share key for user and recovery exists $this->assertFalse($this->view->file_exists('/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2 . '/files_encryption/share-keys/' . $this->filename . '.' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2 . '.shareKey')); $this->assertFalse($this->view->file_exists('/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2 . '/files_encryption/share-keys/' . $this->filename . '.' . $recoveryKeyId . '.shareKey')); $this->assertFalse($this->view->file_exists('/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2 . '/files_encryption/share-keys/' . $this->folder1 . $this->subfolder . $this->subsubfolder . '/' . $this->filename . '.' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2 . '.shareKey')); $this->assertFalse($this->view->file_exists('/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2 . '/files_encryption/share-keys/' . $this->folder1 . $this->subfolder . $this->subsubfolder . '/' . $this->filename . '.' . $recoveryKeyId . '.shareKey')); // disable recovery for admin $this->assertTrue($util->setRecoveryForUser(0)); \OCA\Encryption\Helper::adminDisableRecovery('test123'); $this->assertEquals(0, \OC_Appconfig::getValue('files_encryption', 'recoveryAdminEnabled')); //clean up, reset passwords \OC_User::setPassword(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2, \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2, 'test123'); $params = array('uid' => \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2, 'password' => \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2, 'recoveryPassword' => 'test123'); \OCA\Encryption\Hooks::setPassphrase($params); }