Пример #1
0
 public static function sendEmail($args)
 {
     $isEncrypted = OC_App::isEnabled('files_encryption');
     if (!$isEncrypted || isset($_POST['continue'])) {
         $continue = true;
     } else {
         $continue = false;
     }
     if (OC_User::userExists($_POST['user']) && $continue) {
         $token = hash('sha256', OC_Util::generate_random_bytes(30) . OC_Config::getValue('passwordsalt', ''));
         OC_Preferences::setValue($_POST['user'], 'owncloud', 'lostpassword', hash('sha256', $token));
         // Hash the token again to prevent timing attacks
         $email = OC_Preferences::getValue($_POST['user'], 'settings', 'email', '');
         if (!empty($email)) {
             $link = OC_Helper::linkToRoute('core_lostpassword_reset', array('user' => $_POST['user'], 'token' => $token));
             $link = OC_Helper::makeURLAbsolute($link);
             $tmpl = new OC_Template('core/lostpassword', 'email');
             $tmpl->assign('link', $link, false);
             $msg = $tmpl->fetchPage();
             $l = OC_L10N::get('core');
             $from = OCP\Util::getDefaultEmailAddress('lostpassword-noreply');
             try {
                 OC_Mail::send($email, $_POST['user'], $l->t('ownCloud password reset'), $msg, $from, 'ownCloud');
             } catch (Exception $e) {
                 OC_Template::printErrorPage('A problem occurs during sending the e-mail please contact your administrator.');
             }
             self::displayLostPasswordPage(false, true);
         } else {
             self::displayLostPasswordPage(true, false);
         }
     } else {
         self::displayLostPasswordPage(true, false);
     }
 }
 /**
  * @brief Constructor.
  * @param $app The application identifier e.g. 'contacts' or 'calendar'.
  * @param $user The user whos data the object will operate on. This
  *   parameter should normally be omitted but to make an app able to
  *   update categories for all users it is made possible to provide it.
  * @param $defcategories An array of default categories to be used if none is stored.
  */
 public function __construct($app, $user = null, $defcategories = array())
 {
     $this->app = $app;
     $this->user = is_null($user) ? OC_User::getUser() : $user;
     $categories = trim(OC_Preferences::getValue($this->user, $app, self::PREF_CATEGORIES_LABEL, ''));
     $this->categories = $categories != '' ? unserialize($categories) : $defcategories;
 }
Пример #3
0
 public static function sendEmail($args)
 {
     if (OC_User::userExists($_POST['user'])) {
         $token = hash('sha256', OC_Util::generate_random_bytes(30) . OC_Config::getValue('passwordsalt', ''));
         OC_Preferences::setValue($_POST['user'], 'owncloud', 'lostpassword', hash('sha256', $token));
         // Hash the token again to prevent timing attacks
         $email = OC_Preferences::getValue($_POST['user'], 'settings', 'email', '');
         if (!empty($email)) {
             $link = OC_Helper::linkToRoute('core_lostpassword_reset', array('user' => $_POST['user'], 'token' => $token));
             $link = OC_Helper::makeURLAbsolute($link);
             $tmpl = new OC_Template('core/lostpassword', 'email');
             $tmpl->assign('link', $link, false);
             $msg = $tmpl->fetchPage();
             $l = OC_L10N::get('core');
             $from = 'lostpassword-noreply@' . OCP\Util::getServerHost();
             OC_Mail::send($email, $_POST['user'], $l->t('ownCloud password reset'), $msg, $from, 'ownCloud');
             echo 'Mailsent';
             self::displayLostPasswordPage(false, true);
         } else {
             self::displayLostPasswordPage(true, false);
         }
     } else {
         self::displayLostPasswordPage(true, false);
     }
 }
 private function getFreeSpace()
 {
     $usedSpace = OC_Filesystem::filesize('');
     $totalSpace = OC_Preferences::getValue(OC_User::getUser(), 'files', 'quota', 0);
     if ($totalSpace == 0) {
         return 0;
     }
     return $totalSpace - $usedSpace;
 }
Пример #5
0
 /**
  * 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;
 }
Пример #6
0
 public function testGetValue()
 {
     $this->assertNull(\OC_Preferences::getValue('nonexistant', 'nonexistant', 'nonexistant'));
     $this->assertEquals('default', \OC_Preferences::getValue('nonexistant', 'nonexistant', 'nonexistant', 'default'));
     $query = \OC_DB::prepare('SELECT `configvalue` FROM `*PREFIX*preferences` WHERE `userid` = ? AND `appid` = ? AND `configkey` = ?');
     $result = $query->execute(array('Someuser', 'getvalueapp', 'key'));
     $row = $result->fetchRow();
     $expected = $row['configvalue'];
     $this->assertEquals($expected, \OC_Preferences::getValue('Someuser', 'getvalueapp', 'key'));
 }
	/**
	 * inform users if a file was shared with them
	 *
	 * @param array $recipientList list of recipients
	 * @param string $itemSource shared item source
	 * @param string $itemType shared item type
	 * @return array list of user to whom the mail send operation failed
	 */
	public function sendInternalShareMail($recipientList, $itemSource, $itemType) {

		$noMail = array();

		foreach ($recipientList as $recipient) {
			$recipientDisplayName = \OCP\User::getDisplayName($recipient);
			$to = \OC_Preferences::getValue($recipient, 'settings', 'email', '');

			if ($to === '') {
				$noMail[] = $recipientDisplayName;
				continue;
			}

			$items = \OCP\Share::getItemSharedWithUser($itemType, $itemSource, $recipient);
			$filename = trim($items[0]['file_target'], '/');
			$subject = (string) $this->l->t('%s shared »%s« with you', array($this->senderDisplayName, $filename));
			$expiration = null;
			if (isset($items[0]['expiration'])) {
				try {
					$date = new DateTime($items[0]['expiration']);
					$expiration = $date->getTimestamp();
				} catch (\Exception $e) {
					\OCP\Util::writeLog('sharing', "Couldn't read date: " . $e->getMessage(), \OCP\Util::ERROR);
				}
			}

			// Link to folder, or root folder if a file

			if ($itemType === 'folder') {
				$args = array(
					'dir' => $filename,
				);
			} else {
				$args = array(
					'dir' => '/',
					'scrollto' => $filename,
				);
			}

			$link = \OCP\Util::linkToAbsolute('files', 'index.php', $args);

			list($htmlMail, $alttextMail) = $this->createMailBody($filename, $link, $expiration);

			// send it out now
			try {
				\OCP\Util::sendMail($to, $recipientDisplayName, $subject, $htmlMail, $this->from, $this->senderDisplayName, 1, $alttextMail);
			} catch (\Exception $e) {
				\OCP\Util::writeLog('sharing', "Can't send mail to inform the user about an internal share: " . $e->getMessage() , \OCP\Util::ERROR);
				$noMail[] = $recipientDisplayName;
			}
		}

		return $noMail;

	}
Пример #8
0
 public static function setupFS($user = '')
 {
     // configure the initial filesystem based on the configuration
     if (self::$fsSetup) {
         //setting up the filesystem twice can only lead to trouble
         return false;
     }
     // If we are not forced to load a specific user we load the one that is logged in
     if ($user == "" && OC_User::isLoggedIn()) {
         $user = OC_User::getUser();
     }
     // the filesystem will finish when $user is not empty,
     // mark fs setup here to avoid doing the setup from loading
     // OC_Filesystem
     if ($user != '') {
         self::$fsSetup = true;
     }
     $CONFIG_DATADIRECTORY = OC_Config::getValue("datadirectory", OC::$SERVERROOT . "/data");
     //first set up the local "root" storage
     if (!self::$rootMounted) {
         OC_Filesystem::mount('OC_Filestorage_Local', array('datadir' => $CONFIG_DATADIRECTORY), '/');
         self::$rootMounted = true;
     }
     if ($user != "") {
         //if we aren't logged in, there is no use to set up the filesystem
         $user_dir = '/' . $user . '/files';
         $user_root = OC_User::getHome($user);
         $userdirectory = $user_root . '/files';
         if (!is_dir($userdirectory)) {
             mkdir($userdirectory, 0755, true);
         }
         //jail the user into his "home" directory
         OC_Filesystem::mount('OC_Filestorage_Local', array('datadir' => $user_root), $user);
         OC_Filesystem::init($user_dir);
         $quotaProxy = new OC_FileProxy_Quota();
         OC_FileProxy::register($quotaProxy);
         // Load personal mount config
         if (is_file($user_root . '/mount.php')) {
             $mountConfig = (include $user_root . '/mount.php');
             if (isset($mountConfig['user'][$user])) {
                 foreach ($mountConfig['user'][$user] as $mountPoint => $options) {
                     OC_Filesystem::mount($options['class'], $options['options'], $mountPoint);
                 }
             }
             $mtime = filemtime($user_root . '/mount.php');
             $previousMTime = OC_Preferences::getValue($user, 'files', 'mountconfigmtime', 0);
             if ($mtime > $previousMTime) {
                 //mount config has changed, filecache needs to be updated
                 OC_FileCache::triggerUpdate($user);
                 OC_Preferences::setValue($user, 'files', 'mountconfigmtime', $mtime);
             }
         }
         OC_Hook::emit('OC_Filesystem', 'setup', array('user' => $user, 'user_dir' => $user_dir));
     }
 }
Пример #9
0
 public static function getUserQuota($user)
 {
     $userQuota = OC_Preferences::getValue($user, 'files', 'quota', 'default');
     if ($userQuota === 'default') {
         $userQuota = OC_AppConfig::getValue('files', 'default_quota', 'none');
     }
     if ($userQuota === 'none') {
         return \OC\Files\SPACE_UNLIMITED;
     } else {
         return OC_Helper::computerFileSize($userQuota);
     }
 }
Пример #10
0
 /**
  * @param string $uid
  * @param \OC_User_Backend $backend
  * @param Emitter $emitter
  */
 public function __construct($uid, $backend, $emitter = null)
 {
     $this->uid = $uid;
     if ($backend and $backend->implementsActions(OC_USER_BACKEND_GET_DISPLAYNAME)) {
         $this->displayName = $backend->getDisplayName($uid);
     } else {
         $this->displayName = $uid;
     }
     $this->backend = $backend;
     $this->emitter = $emitter;
     $enabled = \OC_Preferences::getValue($uid, 'core', 'enabled', 'true');
     //TODO: DI for OC_Preferences
     $this->enabled = $enabled === 'true';
 }
Пример #11
0
 /**
  * @param string $uid
  * @param \OC_User_Interface $backend
  * @param \OC\Hooks\Emitter $emitter
  * @param \OC\AllConfig $config
  */
 public function __construct($uid, $backend, $emitter = null, $config = null)
 {
     $this->uid = $uid;
     $this->backend = $backend;
     $this->emitter = $emitter;
     $this->config = $config;
     if ($this->config) {
         $enabled = $this->config->getUserValue($uid, 'core', 'enabled', 'true');
         $this->enabled = $enabled === 'true';
     } else {
         $this->enabled = true;
     }
     $this->lastLogin = \OC_Preferences::getValue($uid, 'login', 'lastLogin', 0);
 }
Пример #12
0
 /**
  * get the quota for the user
  * @param user
  * @return int
  */
 private function getQuota($user)
 {
     if (in_array($user, $this->userQuota)) {
         return $this->userQuota[$user];
     }
     $userQuota = OC_Preferences::getValue($user, 'files', 'quota', 'default');
     if ($userQuota == 'default') {
         $userQuota = OC_AppConfig::getValue('files', 'default_quota', 'none');
     }
     if ($userQuota == 'none') {
         $this->userQuota[$user] = -1;
     } else {
         $this->userQuota[$user] = OC_Helper::computerFileSize($userQuota);
     }
     return $this->userQuota[$user];
 }
Пример #13
0
 /**
  * get the quota for the current user
  * @return int
  */
 private function getQuota()
 {
     if ($this->userQuota != -1) {
         return $this->userQuota;
     }
     $userQuota = OC_Preferences::getValue(OC_User::getUser(), 'files', 'quota', 'default');
     if ($userQuota == 'default') {
         $userQuota = OC_AppConfig::getValue('files', 'default_quota', 'none');
     }
     if ($userQuota == 'none') {
         $this->userQuota = 0;
     } else {
         $this->userQuota = OC_Helper::computerFileSize($userQuota);
     }
     return $this->userQuota;
 }
 /**
  * @brief Send an email while creating and assigning a task
  * @param Title of the task
  * @param Task description
  * @param Project ID to which the task belongs
  * @param To whom the task is assigned
  * @param Deadline for completing the task
  */
 public static function sendTaskCreationMail($title, $desc, $pid, $member, $deadline)
 {
     try {
         $subject = 'You are assigned a task \'' . $title . '\'';
         $message = 'Hello ' . $member . ',';
         $message .= '<br /><p style="text-indent: 50px;" >';
         $message .= 'You are assigned to the task \'' . $title . '\' under the project \'' . OC_Collaboration_Project::getProjectTitle($pid) . '\'.';
         $message .= '<br /><p style="text-align: justify;" ><span style="font-weight: bold;" >';
         $message .= 'Description: ';
         $message .= '</span>' . $desc . '<br /><br /><span style="font-weight: bold;" >';
         $message .= 'Deadline: ';
         $message .= '</span>' . $deadline . '</p><br /><br />';
         $message .= 'For further details, logon to your owncloud account.';
         $message .= '<br /><br />';
         \OC_Mail::send(OC_Preferences::getValue($member, 'settings', 'email'), $member, $subject, $message, OC_Config::getValue('mail_smtpname', ''), 'Owncloud Collaboration App', true);
     } catch (\Exception $e) {
         OC_Log::write('collaboration', __METHOD__ . ', Exception: ' . $e->getMessage(), OCP\Util::DEBUG);
         return false;
     }
 }
Пример #15
0
 /**
  * Send a mail to test the settings
  */
 public static function sendTestMail()
 {
     \OC_Util::checkAdminUser();
     \OCP\JSON::callCheck();
     $l = \OC::$server->getL10N('settings');
     $email = \OC_Preferences::getValue(\OC_User::getUser(), 'settings', 'email', '');
     if (!empty($email)) {
         $defaults = new \OC_Defaults();
         try {
             \OC_Mail::send($email, \OC_User::getDisplayName(), $l->t('test email settings'), $l->t('If you received this email, the settings seem to be correct.'), \OCP\Util::getDefaultEmailAddress('no-reply'), $defaults->getName());
         } catch (\Exception $e) {
             $message = $l->t('A problem occurred while sending the e-mail. Please revisit your settings.');
             \OC_JSON::error(array("data" => array("message" => $message)));
             exit;
         }
         \OC_JSON::success(array("data" => array("message" => $l->t("Email sent"))));
     } else {
         $message = $l->t('You need to set your user email before being able to send test emails.');
         \OC_JSON::error(array("data" => array("message" => $message)));
     }
 }
Пример #16
0
 public static function loadUserMountPoints($user)
 {
     $user_dir = '/' . $user . '/files';
     $user_root = OC_User::getHome($user);
     $userdirectory = $user_root . '/files';
     if (is_file($user_root . '/mount.php')) {
         $mountConfig = (include $user_root . '/mount.php');
         if (isset($mountConfig['user'][$user])) {
             foreach ($mountConfig['user'][$user] as $mountPoint => $options) {
                 OC_Filesystem::mount($options['class'], $options['options'], $mountPoint);
             }
         }
         $mtime = filemtime($user_root . '/mount.php');
         $previousMTime = OC_Preferences::getValue($user, 'files', 'mountconfigmtime', 0);
         if ($mtime > $previousMTime) {
             //mount config has changed, filecache needs to be updated
             OC_FileCache::triggerUpdate($user);
             OC_Preferences::setValue($user, 'files', 'mountconfigmtime', $mtime);
         }
     }
 }
Пример #17
0
 public static function av_scan($path)
 {
     $path = $path[\OC\Files\Filesystem::signal_param_path];
     if ($path != '') {
         $files_view = \OCP\Files::getStorage("files");
         if ($files_view->file_exists($path)) {
             $root = OC_User::getHome(OC_User::getUser()) . '/files';
             $file = $root . $path;
             $result = self::clamav_scan($file);
             switch ($result) {
                 case CLAMAV_SCANRESULT_UNCHECKED:
                     //TODO: Show warning to the user: The file can not be checked
                     break;
                 case CLAMAV_SCANRESULT_INFECTED:
                     //remove file
                     $files_view->unlink($path);
                     OCP\JSON::error(array("data" => array("message" => "Virus detected! Can't upload the file.")));
                     $email = OC_Preferences::getValue(OC_User::getUser(), 'settings', 'email', '');
                     \OCP\Util::writeLog('files_antivirus', 'Email: ' . $email, \OCP\Util::DEBUG);
                     if (!empty($email)) {
                         $tmpl = new OC_Template('files_antivirus', 'notification');
                         $tmpl->assign('file', $path);
                         $tmpl->assign('host', OCP\Util::getServerHost());
                         $tmpl->assign('user', OC_User::getUser());
                         $msg = $tmpl->fetchPage();
                         $from = OCP\Util::getDefaultEmailAddress('security-noreply');
                         OCP\Util::sendMail($email, OC_User::getUser(), 'Malware detected', $msg, $from, 'ownCloud', 1);
                     }
                     exit;
                     break;
                 case CLAMAV_SCANRESULT_CLEAN:
                     //do nothing
                     break;
             }
         }
     }
 }
Пример #18
0
 /**
  * @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;
 }
Пример #19
0
    if (sizeof($users) !== 1) {
        // User not found
        header('HTTP/1.0 404 Not Found');
        exit;
    }
    // Token found login as that user
    \OC_User::setUserId(array_shift($users));
    $forceUserLogout = true;
}
// check if the user has the right permissions.
\OCP\User::checkLoggedIn();
// rss is of content type text/xml
if (isset($_SERVER['HTTP_ACCEPT']) && stristr($_SERVER['HTTP_ACCEPT'], 'application/rss+xml')) {
    header('Content-Type: application/rss+xml');
} else {
    header('Content-Type: text/xml; charset=UTF-8');
}
// generate and show the rss feed
$l = \OCP\Util::getL10N('activity');
$data = new \OCA\Activity\Data(\OC::$server->getActivityManager());
$groupHelper = new \OCA\Activity\GroupHelper(\OC::$server->getActivityManager(), new \OCA\Activity\DataHelper(\OC::$server->getActivityManager(), new \OCA\Activity\ParameterHelper(new \OC\Files\View(''), $l), $l), false);
$tmpl = new \OCP\Template('activity', 'rss');
$tmpl->assign('rssLang', \OC_Preferences::getValue(\OCP\User::getUser(), 'core', 'lang'));
$tmpl->assign('rssLink', \OCP\Util::linkToAbsolute('activity', 'rss.php'));
$tmpl->assign('rssPubDate', date('r'));
$tmpl->assign('user', \OCP\User::getUser());
$tmpl->assign('activities', $data->read($groupHelper, 0, 30, 'all'));
$tmpl->printPage();
if ($forceUserLogout) {
    \OC_User::logout();
}
Пример #20
0
 private static function update_mail($uid, $email)
 {
     if ($email != OC_Preferences::getValue($uid, 'settings', 'email', '')) {
         OC_Preferences::setValue($uid, 'settings', 'email', $email);
         OC_Log::write('saml', 'Set email "' . $email . '" for the user: ' . $uid, OC_Log::DEBUG);
     }
 }
Пример #21
0
 public function testDuplicateDataMigration()
 {
     // create test table
     OC_DB::createDbFromStructure(__DIR__ . '/encryption_table.xml');
     // in case of duplicate entries we want to preserve 0 on migration status and 1 on recovery
     $data = array(array('user1', 'server-side', 1, 1), array('user1', 'server-side', 1, 0), array('user1', 'server-side', 0, 1), array('user1', 'server-side', 0, 0));
     foreach ($data as $d) {
         OC_DB::executeAudited('INSERT INTO `*PREFIX*encryption_test` values(?, ?, ?, ?)', $d);
     }
     // preform migration
     $migration = new Migration('encryption_test');
     $migration->dropTableEncryption();
     // assert
     $this->assertTableNotExist('encryption_test');
     $rec = \OC_Preferences::getValue('user1', 'files_encryption', 'recovery_enabled');
     $mig = \OC_Preferences::getValue('user1', 'files_encryption', 'migration_status');
     $this->assertEquals(1, $rec);
     $this->assertEquals(0, $mig);
 }
Пример #22
0
            OC::loadapp();
        } else {
            OC::loadfile();
        }
    }
    // For all others cases, we display the guest page :
} else {
    OC_App::loadApps();
    $error = false;
    // remember was checked after last login
    if (isset($_COOKIE["oc_remember_login"]) && isset($_COOKIE["oc_token"]) && isset($_COOKIE["oc_username"]) && $_COOKIE["oc_remember_login"]) {
        if (defined("DEBUG") && DEBUG) {
            OC_Log::write('core', 'Trying to login from cookie', OC_Log::DEBUG);
        }
        // confirm credentials in cookie
        if (isset($_COOKIE['oc_token']) && OC_User::userExists($_COOKIE['oc_username']) && OC_Preferences::getValue($_COOKIE['oc_username'], "login", "token") === $_COOKIE['oc_token']) {
            OC_User::setUserId($_COOKIE['oc_username']);
            OC_Util::redirectToDefaultPage();
        } else {
            OC_User::unsetMagicInCookie();
        }
        // Someone wants to log in :
    } elseif (isset($_POST["user"]) and isset($_POST['password']) and isset($_SESSION['sectoken']) and isset($_POST['sectoken']) and $_SESSION['sectoken'] == $_POST['sectoken']) {
        if (OC_User::login($_POST["user"], $_POST["password"])) {
            if (!empty($_POST["remember_login"])) {
                if (defined("DEBUG") && DEBUG) {
                    OC_Log::write('core', 'Setting remember login to cookie', OC_Log::DEBUG);
                }
                $token = md5($_POST["user"] . time() . $_POST['password']);
                OC_Preferences::setValue($_POST['user'], 'login', 'token', $token);
                OC_User::setMagicInCookie($_POST["user"], $token);
Пример #23
0
 /**
  * calculate remaining free space for trash bin
  *
  * @param integer $trashbinSize current size of the trash bin
  * @param string $user
  * @return int available free space for trash bin
  */
 private static function calculateFreeSpace($trashbinSize, $user)
 {
     $softQuota = true;
     $quota = \OC_Preferences::getValue($user, 'files', 'quota');
     $view = new \OC\Files\View('/' . $user);
     if ($quota === null || $quota === 'default') {
         $quota = \OC::$server->getAppConfig()->getValue('files', 'default_quota');
     }
     if ($quota === null || $quota === 'none') {
         $quota = \OC\Files\Filesystem::free_space('/');
         $softQuota = false;
     } else {
         $quota = \OCP\Util::computerFileSize($quota);
     }
     // calculate available space for trash bin
     // subtract size of files and current trash bin size from quota
     if ($softQuota) {
         $rootInfo = $view->getFileInfo('/files/', false);
         $free = $quota - $rootInfo['size'];
         // remaining free space for user
         if ($free > 0) {
             $availableSpace = $free * self::DEFAULTMAXSIZE / 100 - $trashbinSize;
             // how much space can be used for versions
         } else {
             $availableSpace = $free - $trashbinSize;
         }
     } else {
         $availableSpace = $quota;
     }
     return $availableSpace;
 }
Пример #24
0
 /**
  * Gets the preference
  * @param string $user user
  * @param string $app app
  * @param string $key key
  * @param string $default = null, default value if the key does not exist
  * @return string the value or $default
  *
  * This function gets a value from the preferences table. If the key does
  * not exist the default value will be returned
  */
 public static function getUserValue($user, $app, $key, $default = null)
 {
     return \OC_Preferences::getValue($user, $app, $key, $default);
 }
<?php

/**
 * Copyright (c) 2011 Georg Ehrke <ownclouddev at georgswebsite dot de>
 * This file is licensed under the Affero General Public License version 3 or
 * later.
 * See the COPYING-README file.
 */
require_once '../../../lib/base.php';
OC_JSON::checkLoggedIn();
$firstdayofweek = OC_Preferences::getValue(OC_User::getUser(), 'calendar', 'firstdayofweek', "1");
OC_JSON::encodedPrint(array("firstdayofweek" => $firstdayofweek));
Пример #26
0
 /**
  * @brief find the best language
  * @param $app Array or string, details below
  * @returns language
  *
  * If $app is an array, ownCloud assumes that these are the available
  * languages. Otherwise ownCloud tries to find the files in the l10n
  * folder.
  *
  * If nothing works it returns 'en'
  */
 public static function findLanguage($app = null)
 {
     if (!is_array($app) && self::$language != '') {
         return self::$language;
     }
     if (OC_User::getUser() && OC_Preferences::getValue(OC_User::getUser(), 'core', 'lang')) {
         $lang = OC_Preferences::getValue(OC_User::getUser(), 'core', 'lang');
         self::$language = $lang;
         if (is_array($app)) {
             $available = $app;
             $lang_exists = array_search($lang, $available) !== false;
         } else {
             $lang_exists = self::languageExists($app, $lang);
         }
         if ($lang_exists) {
             return $lang;
         }
     }
     if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
         $accepted_languages = preg_split('/,\\s*/', strtolower($_SERVER['HTTP_ACCEPT_LANGUAGE']));
         if (is_array($app)) {
             $available = $app;
         } else {
             $available = self::findAvailableLanguages($app);
         }
         foreach ($accepted_languages as $i) {
             $temp = explode(';', $i);
             $temp[0] = str_replace('-', '_', $temp[0]);
             if (($key = array_search($temp[0], $available)) !== false) {
                 return $available[$key];
             }
             foreach ($available as $l) {
                 if ($temp[0] == substr($l, 0, 2)) {
                     return $l;
                 }
             }
         }
     }
     // Last try: English
     return 'en';
 }
 */
require_once "../../../lib/base.php";
if (!OC_USER::isLoggedIn()) {
    die("<script type=\"text/javascript\">document.location = oc_webroot;</script>");
}
OC_JSON::checkAppEnabled('calendar');
$calendars = OC_Calendar_Calendar::allCalendars(OC_User::getUser(), 1);
$events = array();
$return = array('calendars' => array());
foreach ($calendars as $calendar) {
    $tmp = OC_Calendar_Object::all($calendar['id']);
    $events = array_merge($events, $tmp);
    $return['calendars'][$calendar['id']] = array('displayname' => $calendar['displayname'], 'color' => '#' . $calendar['calendarcolor']);
}
$select_year = $_GET["year"];
$user_timezone = OC_Preferences::getValue(OC_USER::getUser(), "calendar", "timezone", "Europe/London");
foreach ($events as $event) {
    if ($select_year != substr($event['startdate'], 0, 4)) {
        continue;
    }
    $object = Sabre_VObject_Reader::read($event['calendardata']);
    $vevent = $object->VEVENT;
    $dtstart = $vevent->DTSTART;
    $dtend = OC_Calendar_Object::getDTEndFromVEvent($vevent);
    $start_dt = $dtstart->getDateTime();
    $start_dt->setTimezone(new DateTimeZone($user_timezone));
    $end_dt = $dtend->getDateTime();
    $end_dt->setTimezone(new DateTimeZone($user_timezone));
    $year = $start_dt->format('Y');
    $month = $start_dt->format('n') - 1;
    // return is 0 based
Пример #28
0
    $pattern = '';
}
$users = array();
$userManager = \OC_User::getManager();
if (OC_User::isAdminUser(OC_User::getUser())) {
    if ($gid !== false) {
        $batch = OC_Group::displayNamesInGroup($gid, $pattern, $limit, $offset);
    } else {
        $batch = OC_User::getDisplayNames($pattern, $limit, $offset);
    }
    foreach ($batch as $uid => $displayname) {
        $user = $userManager->get($uid);
        $users[] = array('name' => $uid, 'displayname' => $displayname, 'groups' => join(', ', OC_Group::getUserGroups($uid)), 'subadmin' => join(', ', OC_SubAdmin::getSubAdminsGroups($uid)), 'quota' => OC_Preferences::getValue($uid, 'files', 'quota', 'default'), 'storageLocation' => $user->getHome(), 'lastLogin' => $user->getLastLogin());
    }
} else {
    $groups = OC_SubAdmin::getSubAdminsGroups(OC_User::getUser());
    if ($gid !== false && in_array($gid, $groups)) {
        $groups = array($gid);
    } elseif ($gid !== false) {
        //don't you try to investigate loops you must not know about
        $groups = array();
    }
    $batch = OC_Group::usersInGroups($groups, $pattern, $limit, $offset);
    foreach ($batch as $uid) {
        $user = $userManager->get($uid);
        // Only add the groups, this user is a subadmin of
        $userGroups = array_intersect(OC_Group::getUserGroups($uid), OC_SubAdmin::getSubAdminsGroups(OC_User::getUser()));
        $users[] = array('name' => $uid, 'displayname' => $user->getDisplayName(), 'groups' => join(', ', $userGroups), 'quota' => OC_Preferences::getValue($uid, 'files', 'quota', 'default'), 'storageLocation' => $user->getHome(), 'lastLogin' => $user->getLastLogin());
    }
}
OC_JSON::success(array('data' => $users));
<?php

/**
 * Copyright (c) 2011 Georg Ehrke <ownclouddev at georgswebsite dot de>
 * This file is licensed under the Affero General Public License version 3 or
 * later.
 * See the COPYING-README file.
 */
require_once '../../../lib/base.php';
OC_JSON::checkLoggedIn();
$duration = OC_Preferences::getValue(OC_User::getUser(), 'calendar', 'duration', "60");
OC_JSON::encodedPrint(array("duration" => $duration));
?>
 
Пример #30
0
 protected static function cleanupLoginTokens($user)
 {
     $cutoff = time() - OC_Config::getValue('remember_login_cookie_lifetime', 60 * 60 * 24 * 15);
     $tokens = OC_Preferences::getKeys($user, 'login_token');
     foreach ($tokens as $token) {
         $time = OC_Preferences::getValue($user, 'login_token', $token);
         if ($time < $cutoff) {
             OC_Preferences::deleteKey($user, 'login_token', $token);
         }
     }
 }