Example #1
0
 /**
  * @NoAdminRequired
  */
 public function getTasks()
 {
     $calendars = \OC_Calendar_Calendar::allCalendars($this->userId, true);
     $user_timezone = \OC_Calendar_App::getTimezone();
     $tasks = array();
     foreach ($calendars as $calendar) {
         $calendar_tasks = \OC_Calendar_Object::all($calendar['id']);
         foreach ($calendar_tasks as $task) {
             if ($task['objecttype'] != 'VTODO') {
                 continue;
             }
             if (is_null($task['summary'])) {
                 continue;
             }
             $vtodo = Helper::parseVTODO($task['calendardata']);
             try {
                 $task_data = Helper::arrayForJSON($task['id'], $vtodo, $user_timezone);
                 $task_data['calendarid'] = $calendar['id'];
                 $task_data['calendarcolor'] = $calendar['calendarcolor'];
                 $tasks[] = $task_data;
             } catch (\Exception $e) {
                 \OCP\Util::writeLog('tasks', $e->getMessage(), \OCP\Util::ERROR);
             }
         }
     }
     $result = array('data' => array('tasks' => $tasks));
     $response = new JSONResponse();
     $response->setData($result);
     return $response;
 }
Example #2
0
 public static function getCalenderSources($parameters)
 {
     $base_url = \OCP\Util::linkTo('calendar', 'ajax/events.php') . '?calendar_id=';
     foreach (Addressbook::all(\OCP\USER::getUser()) as $addressbook) {
         $parameters['sources'][] = array('url' => $base_url . 'birthday_' . $addressbook['id'], 'backgroundColor' => '#cccccc', 'borderColor' => '#888', 'textColor' => 'black', 'cache' => true, 'editable' => false);
     }
 }
Example #3
0
 public function setup()
 {
     Util::connectHook('OC_User', 'post_createUser', $this, 'postCreateUser');
     Util::connectHook('OC_User', 'pre_deleteUser', $this, 'preDeleteUser');
     Util::connectHook('OC_User', 'post_deleteUser', $this, 'postDeleteUser');
     Util::connectHook('OC_User', 'changeUser', $this, 'changeUser');
 }
Example #4
0
 public function __construct(IL10N $l, ISession $session, ICrypto $crypto)
 {
     $this->session = $session;
     $this->crypto = $crypto;
     $this->setIdentifier('password::sessioncredentials')->setScheme(self::SCHEME_PASSWORD)->setText($l->t('Session credentials'))->addParameters([]);
     \OCP\Util::connectHook('OC_User', 'post_login', $this, 'authenticate');
 }
Example #5
0
 public static function setUpBeforeClass()
 {
     // reset backend
     \OC_User::clearBackends();
     \OC_User::useBackend('database');
     // enable resharing
     \OC_Appconfig::setValue('core', 'shareapi_allow_resharing', 'yes');
     // clear share hooks
     \OC_Hook::clear('OCP\\Share');
     \OC::registerShareHooks();
     \OCP\Util::connectHook('OC_Filesystem', 'setup', '\\OC\\Files\\Storage\\Shared', 'setup');
     // Sharing related hooks
     \OCA\Encryption\Helper::registerShareHooks();
     // Filesystem related hooks
     \OCA\Encryption\Helper::registerFilesystemHooks();
     // clear and register hooks
     \OC_FileProxy::clearProxies();
     \OC_FileProxy::register(new OCA\Encryption\Proxy());
     // create users
     \Test_Encryption_Util::loginHelper(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1, true);
     \Test_Encryption_Util::loginHelper(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2, true);
     \Test_Encryption_Util::loginHelper(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER3, true);
     \Test_Encryption_Util::loginHelper(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER4, true);
     // create group and assign users
     \OC_Group::createGroup(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_GROUP1);
     \OC_Group::addToGroup(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER3, \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_GROUP1);
     \OC_Group::addToGroup(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER4, \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_GROUP1);
 }
Example #6
0
 public static function get_realm()
 {
     $appConfig = \OC::$server->getAppConfig();
     $result = $appConfig->getValue('privacyIDEA', 'realm', '');
     \OCP\Util::writeLog('user_privacyidea', "Getting result for realm: {$result}", \OCP\Util::DEBUG);
     return $result;
 }
Example #7
0
 function __construct()
 {
     $this->l = \OC::$server->getL10N('lib');
     $version = \OCP\Util::getVersion();
     $this->defaultEntity = 'ownCloud';
     /* e.g. company name, used for footers and copyright notices */
     $this->defaultName = 'ownCloud';
     /* short name, used when referring to the software */
     $this->defaultTitle = 'ownCloud';
     /* can be a longer name, for titles */
     $this->defaultBaseUrl = 'https://owncloud.org';
     $this->defaultSyncClientUrl = 'https://owncloud.org/sync-clients/';
     $this->defaultiOSClientUrl = 'https://itunes.apple.com/us/app/owncloud/id543672169?mt=8';
     $this->defaultiTunesAppId = '543672169';
     $this->defaultAndroidClientUrl = 'https://play.google.com/store/apps/details?id=com.owncloud.android';
     $this->defaultDocBaseUrl = 'https://doc.owncloud.org';
     $this->defaultDocVersion = $version[0] . '.' . $version[1];
     // used to generate doc links
     $this->defaultSlogan = $this->l->t('web services under your control');
     $this->defaultLogoClaim = '';
     $this->defaultMailHeaderColor = '#1d2d44';
     /* header color of mail notifications */
     $themePath = OC::$SERVERROOT . '/themes/' . OC_Util::getTheme() . '/defaults.php';
     if (file_exists($themePath)) {
         // prevent defaults.php from printing output
         ob_start();
         require_once $themePath;
         ob_end_clean();
         if (class_exists('OC_Theme')) {
             $this->theme = new OC_Theme();
         }
     }
 }
Example #8
0
 /**
  * @param array $urlParams
  */
 public function __construct(array $urlParams = array())
 {
     parent::__construct('settings', $urlParams);
     $container = $this->getContainer();
     /**
      * Controllers
      */
     $container->registerService('MailSettingsController', function (SimpleContainer $c) {
         return new MailSettingsController($c->query('AppName'), $c->query('Request'), $c->query('L10N'), $c->query('Config'), $c->query('UserSession'), $c->query('Defaults'), $c->query('Mail'), $c->query('DefaultMailAddress'));
     });
     /**
      * Core class wrappers
      */
     $container->registerService('Config', function (SimpleContainer $c) {
         return $c->query('ServerContainer')->getConfig();
     });
     $container->registerService('L10N', function (SimpleContainer $c) {
         return $c->query('ServerContainer')->getL10N('settings');
     });
     $container->registerService('UserSession', function (SimpleContainer $c) {
         return $c->query('ServerContainer')->getUserSession();
     });
     $container->registerService('Mail', function (SimpleContainer $c) {
         return new \OC_Mail();
     });
     $container->registerService('Defaults', function (SimpleContainer $c) {
         return new \OC_Defaults();
     });
     $container->registerService('DefaultMailAddress', function (SimpleContainer $c) {
         return Util::getDefaultEmailAddress('no-reply');
     });
 }
 public static function sendMail($path)
 {
     if (!\OCP\User::isLoggedIn()) {
         return;
     }
     $config = \OC::$server->getConfig();
     $user = \OC::$server->getUserSession()->getUser();
     $email = $user->getEMailAddress();
     $displayName = $user->getDisplayName();
     if (strval($displayName) === '') {
         $displayName = $user->getUID();
     }
     \OCP\Util::writeLog('files_antivirus', 'Email: ' . $email, \OCP\Util::DEBUG);
     if (!empty($email)) {
         try {
             $tmpl = new \OCP\Template('files_antivirus', 'notification');
             $tmpl->assign('file', $path);
             $tmpl->assign('host', \OC::$server->getRequest()->getServerHost());
             $tmpl->assign('user', $displayName);
             $msg = $tmpl->fetchPage();
             $from = \OCP\Util::getDefaultEmailAddress('security-noreply');
             $mailer = \OC::$server->getMailer();
             $message = $mailer->createMessage();
             $message->setSubject(\OCP\Util::getL10N('files_antivirus')->t('Malware detected'));
             $message->setFrom([$from => 'ownCloud Notifier']);
             $message->setTo([$email => $displayName]);
             $message->setPlainBody($msg);
             $message->setHtmlBody($msg);
             $mailer->send($message);
         } catch (\Exception $e) {
             \OC::$server->getLogger()->error(__METHOD__ . ', exception: ' . $e->getMessage(), ['app' => 'files_antivirus']);
         }
     }
 }
Example #10
0
	/**
	 * @NoAdminRequired
	 * @NoCSRFRequired
	 */
	public function index() {
		\OC::$server->getNavigationManager()->setActiveEntry($this->appName);

		$importManager = new ImportManager();
		$imppTypes = Properties::getTypesForProperty('IMPP');
		$adrTypes = Properties::getTypesForProperty('ADR');
		$phoneTypes = Properties::getTypesForProperty('TEL');
		$emailTypes = Properties::getTypesForProperty('EMAIL');
		$ims = Properties::getIMOptions();
		$imProtocols = array();
		foreach($ims as $name => $values) {
			$imProtocols[$name] = $values['displayname'];
		}

		$maxUploadFilesize = \OCP\Util::maxUploadFilesize('/');

		$response = new TemplateResponse($this->appName, 'contacts');
		$response->setParams(array(
			'uploadMaxFilesize' => $maxUploadFilesize,
			'uploadMaxHumanFilesize' => \OCP\Util::humanFileSize($maxUploadFilesize),
			'phoneTypes' => $phoneTypes,
			'emailTypes' => $emailTypes,
			'adrTypes' => $adrTypes,
			'imppTypes' => $imppTypes,
			'imProtocols' => $imProtocols,
			'importManager' => $importManager,
		));

		return $response;
	}
Example #11
0
 /**
  * Log exception
  *
  * @internal param Exception $e exception
  */
 public function logException($e)
 {
     $exceptionClass = get_class($e);
     if ($exceptionClass !== 'Sabre_DAV_Exception_NotAuthenticated') {
         \OCP\Util::logException($this->appName, $e);
     }
 }
 /**
  * @dataProvider getTypeIconData
  */
 public function testGetTypeIcon($type, $expected)
 {
     $manager = $this->getMock('\\OCP\\Activity\\IManager');
     $manager->expects($this->any())->method('getTypeIcon')->willReturn('');
     $dataHelper = new DataHelper($manager, new ParameterHelper($manager, new View(''), $this->getMockBuilder('OCP\\IConfig')->disableOriginalConstructor()->getMock(), Util::getL10N('activity')), Util::getL10N('activity'));
     $this->assertEquals($expected, $dataHelper->getTypeIcon($type));
 }
 public function register()
 {
     $loginRecord = function ($user) {
         $UserRole = \OC::$server->getConfig()->getUserValue(\OC_User::getUser(), "settings", "role", "undefined");
         Util::writeLog('core', "user:"******" role:" . $UserRole . " action:login success", Util::INFO);
     };
     $logoutRecord = function () {
         $UserRole = \OC::$server->getConfig()->getUserValue(\OC_User::getUser(), "settings", "role", "undefined");
         Util::writeLog('core', "user:"******" role:" . $this->UserRole . " action:logout success", Util::INFO);
     };
     $createRecord = function ($node) {
         $UserRole = \OC::$server->getConfig()->getUserValue(\OC_User::getUser(), "settings", "role", "undefined");
         Util::writeLog('activity', "user:"******" role:" . $UserRole . " action:creates " . $node->getName() . " success", Util::INFO);
     };
     $deleteRecord = function ($node) {
         $UserRole = \OC::$server->getConfig()->getUserValue(\OC_User::getUser(), "settings", "role", "undefined");
         Util::writeLog('activity', "user:"******" role:" . $UserRole . " action:deletes " . $node->getName() . " success", Util::INFO);
     };
     $renameRecord = function ($node) {
         $UserRole = \OC::$server->getConfig()->getUserValue(\OC_User::getUser(), "settings", "role", "undefined");
         Util::writeLog('activity', "user:"******" role:" . $UserRole . " action:renames " . $node->getName() . " success", Util::INFO);
     };
     $touchRecord = function ($node) {
         $UserRole = \OC::$server->getConfig()->getUserValue(\OC_User::getUser(), "settings", "role", "undefined");
         Util::writeLog('activity', "user:"******" role:" . $UserRole . " action:touches " . $node->getName() . " success", Util::INFO);
     };
     Util::connectHook('OCP\\Share', 'post_shared', 'OCA\\Activity_Logging\\UserHooks', 'share');
     $this->userManager->listen('\\OC\\User', 'postLogin', $loginRecord);
     $this->userManager->listen('\\OC\\User', 'logout', $logoutRecord);
     $this->UserFolder->listen('\\OC\\Files', 'postCreate', $createRecord);
     $this->UserFolder->listen('\\OC\\Files', 'postDelete', $deleteRecord);
     $this->UserFolder->listen('\\OC\\Files', 'postRename', $renameRecord);
 }
 /**
  * @param IEvent $event
  * @param string $parameter The parameter to be formatted
  * @return string The formatted parameter
  */
 public function format(IEvent $event, $parameter)
 {
     $param = $this->fixLegacyFilename($parameter);
     // If the activity is about the very same file, we use the current path
     // for the link generation instead of the one that was saved.
     $fileId = '';
     if (is_array($param)) {
         $fileId = key($param);
         $param = $param[$fileId];
         $info = $this->infoCache->getInfoById($this->user, $fileId, $param);
     } elseif ($event->getObjectType() === 'files' && $event->getObjectName() === $param) {
         $fileId = $event->getObjectId();
         $info = $this->infoCache->getInfoById($this->user, $fileId, $param);
     } else {
         $info = $this->infoCache->getInfoByPath($this->user, $param);
     }
     if ($info['is_dir']) {
         $linkData = ['dir' => $info['path']];
     } else {
         $parentDir = substr_count($info['path'], '/') === 1 ? '/' : dirname($info['path']);
         $fileName = basename($info['path']);
         $linkData = ['dir' => $parentDir, 'scrollto' => $fileName];
     }
     if ($info['view'] !== '') {
         $linkData['view'] = $info['view'];
     }
     $param = trim($param, '/');
     $fileLink = $this->urlGenerator->linkToRouteAbsolute('files.view.index', $linkData);
     return '<file link="' . $fileLink . '" id="' . Util::sanitizeHTML($fileId) . '">' . Util::sanitizeHTML($param) . '</file>';
 }
 /**
  * @dataProvider translationData
  */
 public function testTranslation($text, $params, $stripPath, $highlightParams, $expected)
 {
     $config = $this->getMockBuilder('OCP\\IConfig')->disableOriginalConstructor()->getMock();
     $config->expects($this->any())->method('getSystemValue')->with('enable_avatars', true)->willReturn(true);
     $dataHelper = new \OCA\Activity\DataHelper($this->getMock('\\OCP\\Activity\\IManager'), new \OCA\Activity\ParameterHelper(new \OC\Files\View(''), $config, \OCP\Util::getL10N('activity')), \OCP\Util::getL10N('activity'));
     $this->assertEquals($expected, (string) $dataHelper->translation('files', $text, $params, $stripPath, $highlightParams));
 }
 /**
  * @dataProvider getTemplateData
  */
 public function testHooksDeleteUser($constructorActive, $forceActive)
 {
     $l = \OCP\Util::getL10N('activity');
     $navigation = new Navigation($l, \OC::$server->getActivityManager(), \OC::$server->getURLGenerator(), $constructorActive);
     $output = $navigation->getTemplate($forceActive)->fetchPage();
     // Get only the template part with the navigation links
     $navigationLinks = substr($output, strpos($output, '<li>') + 4);
     $navigationLinks = substr($navigationLinks, 0, strrpos($navigationLinks, '</li>'));
     // Remove tabs and new lines
     $navigationLinks = str_replace(array("\t", "\n"), '', $navigationLinks);
     // Turn the list of links into an array
     $navigationEntries = explode('</li><li>', $navigationLinks);
     $links = $navigation->getLinkList();
     // Check whether all top links are available
     foreach ($links['top'] as $link) {
         $found = false;
         foreach ($navigationEntries as $navigationEntry) {
             if (strpos($navigationEntry, 'data-navigation="' . $link['id'] . '"') !== false) {
                 $found = true;
                 $this->assertContains('href="' . $link['url'] . '">' . $link['name'] . '</a>', $navigationEntry);
                 if ($forceActive == $link['id']) {
                     $this->assertContains('class="active"', $navigationEntry);
                 } else {
                     if ($forceActive == null && $constructorActive == $link['id']) {
                         $this->assertContains('class="active"', $navigationEntry);
                     }
                 }
             }
         }
         $this->assertTrue($found, 'Could not find navigation entry "' . $link['name'] . '"');
     }
     // Check size of app links
     $this->assertSame(1, sizeof($links['apps']));
     $this->assertNotContains('data-navigation="files"', $navigationLinks, 'Files app should not be included when there are no other apps.');
 }
Example #17
0
 /**
  * @NoAdminRequired
  * @NoCSRFRequired
  */
 public function index()
 {
     if (defined('DEBUG') && DEBUG) {
         \OCP\Util::addScript('tasks', 'vendor/angularjs/angular');
         \OCP\Util::addScript('tasks', 'vendor/angularjs/angular-route');
         \OCP\Util::addScript('tasks', 'vendor/angularjs/angular-animate');
         \OCP\Util::addScript('tasks', 'vendor/momentjs/moment');
         \OCP\Util::addScript('tasks', 'vendor/bootstrap/ui-bootstrap-custom-tpls-0.10.0');
     } else {
         \OCP\Util::addScript('tasks', 'vendor/angularjs/angular.min');
         \OCP\Util::addScript('tasks', 'vendor/angularjs/angular-route.min');
         \OCP\Util::addScript('tasks', 'vendor/angularjs/angular-animate.min');
         \OCP\Util::addScript('tasks', 'vendor/momentjs/moment.min');
         \OCP\Util::addScript('tasks', 'vendor/bootstrap/ui-bootstrap-custom-tpls-0.10.0.min');
     }
     \OCP\Util::addScript('tasks', 'public/app');
     \OCP\Util::addScript('tasks', 'vendor/appframework/app');
     \OCP\Util::addScript('tasks', 'vendor/timepicker/jquery.ui.timepicker');
     \OCP\Util::addStyle('tasks', 'style');
     \OCP\Util::addStyle('tasks', 'vendor/bootstrap/bootstrap');
     $date = new \DateTimeZone(\OC_Calendar_App::getTimezone());
     $day = new \DateTime('today', $date);
     $day = $day->format('d');
     // TODO: Make a HTMLTemplateResponse class
     $response = new TemplateResponse('tasks', 'main');
     $response->setParams(array('DOM' => $day));
     return $response;
 }
Example #18
0
File: html.php Project: Gomez/mail
 public function sanitizeHtmlMailBody($mailBody, array $messageParameters, Closure $mapCidToAttachmentId)
 {
     $config = HTMLPurifier_Config::createDefault();
     // Append target="_blank" to all link (a) elements
     $config->set('HTML.TargetBlank', true);
     // allow cid, http and ftp
     $config->set('URI.AllowedSchemes', ['cid' => true, 'http' => true, 'https' => true, 'ftp' => true, 'mailto' => true]);
     $config->set('URI.Host', Util::getServerHostName());
     // Disable the cache since ownCloud has no really appcache
     // TODO: Fix this - requires https://github.com/owncloud/core/issues/10767 to be fixed
     $config->set('Cache.DefinitionImpl', null);
     // Rewrite URL for redirection and proxying of content
     $html = $config->getDefinition('HTML');
     $html->info_attr_transform_post['imagesrc'] = new TransformImageSrc($this->urlGenerator);
     $html->info_attr_transform_post['cssbackground'] = new TransformCSSBackground($this->urlGenerator);
     $html->info_attr_transform_post['htmllinks'] = new TransformHTMLLinks();
     $uri = $config->getDefinition('URI');
     $uri->addFilter(new TransformURLScheme($messageParameters, $mapCidToAttachmentId, $this->urlGenerator), $config);
     HTMLPurifier_URISchemeRegistry::instance()->register('cid', new CidURIScheme());
     $purifier = new HTMLPurifier($config);
     $result = $purifier->purify($mailBody);
     // eat xml parse errors within HTMLPurifier
     libxml_clear_errors();
     return $result;
 }
Example #19
0
 /**
  * @NoAdminRequired
  * @NoCSRFRequired
  * @PublicPage
  */
 public function validateEmail()
 {
     $email = $this->request->getParam('email');
     if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
         return new TemplateResponse('', 'error', array(array('error' => $this->l10n->t('Email address you entered is not valid'))), 'error');
         return new TemplateResponse('', 'error', array('errors' => array(array('error' => $this->l10n->t('Email address you entered is not valid'), 'hint' => ''))), 'error');
     }
     if ($this->pendingreg->find($email)) {
         return new TemplateResponse('', 'error', array('errors' => array(array('error' => $this->l10n->t('There is already a pending registration with this email'), 'hint' => ''))), 'error');
     }
     if ($this->config->getUsersForUserValue('settings', 'email', $email)) {
         return new TemplateResponse('', 'error', array('errors' => array(array('error' => $this->l10n->t('There is an existing user with this email'), 'hint' => ''))), 'error');
     }
     // FEATURE: allow only from specific email domain
     $token = $this->pendingreg->save($email);
     //TODO: check for error
     $link = $this->urlgenerator->linkToRoute('registration.register.verifyToken', array('token' => $token));
     $link = $this->urlgenerator->getAbsoluteURL($link);
     $from = Util::getDefaultEmailAddress('register');
     $res = new TemplateResponse('registration', 'email', array('link' => $link), 'blank');
     $msg = $res->render();
     try {
         $this->mail->sendMail($email, 'ownCloud User', $this->l10n->t('Verify your ownCloud registration request'), $msg, $from, 'ownCloud');
     } catch (\Exception $e) {
         \OC_Template::printErrorPage('A problem occurs during sending the e-mail please contact your administrator.');
         return;
     }
     return new TemplateResponse('registration', 'message', array('msg' => $this->l10n->t('Verification email successfully sent.')), 'guest');
 }
 /**
  * @param $requestToken
  * @return string
  */
 public function getUrl($requestToken)
 {
     if (!$requestToken) {
         throw new \RuntimeException('No request token given');
     }
     return \OCP\Util::linkToRoute('ocusagecharts.chart_api.load_chart', array('id' => $this->chart->getId(), 'requesttoken' => $requestToken));
 }
Example #21
0
 /**
  * Load the frontend files needed
  */
 public function loadFrontend()
 {
     \OCP\Util::addStyle('ocusagecharts', 'c3js/c3');
     \OCP\Util::addScript('ocusagecharts', 'c3js/d3.min');
     \OCP\Util::addScript('ocusagecharts', 'c3js/c3.min');
     \OCP\Util::addScript('ocusagecharts', 'c3js/initGraphs');
 }
Example #22
0
 /**
  * @param OutputInterface $output
  */
 public function loadCommands(OutputInterface $output)
 {
     // $application is required to be defined in the register_command scripts
     $application = $this->application;
     require_once \OC::$SERVERROOT . '/core/register_command.php';
     if ($this->config->getSystemValue('installed', false)) {
         if (!\OCP\Util::needUpgrade()) {
             OC_App::loadApps();
             foreach (OC_App::getAllApps() as $app) {
                 $file = OC_App::getAppPath($app) . '/appinfo/register_command.php';
                 if (file_exists($file)) {
                     require $file;
                 }
             }
         } else {
             $output->writeln("ownCloud or one of the apps require upgrade - only a limited number of commands are available");
         }
     } else {
         $output->writeln("ownCloud is not installed - only a limited number of commands are available");
     }
     $input = new ArgvInput();
     if ($input->getFirstArgument() !== 'check') {
         $errors = \OC_Util::checkServer(\OC::$server->getConfig());
         if (!empty($errors)) {
             foreach ($errors as $error) {
                 $output->writeln($error['error']);
                 $output->writeln($error['hint']);
                 $output->writeln('');
             }
             throw new \Exception("Environment not properly prepared.");
         }
     }
 }
Example #23
0
 public static function printAutoLoginPage($user)
 {
     $user = \OCP\Util::sanitizeHTML($user);
     $title = 'Forwarding to ownCloud login page';
     $body = '<form id="auto_login_form" action="' . \OC::$WEBROOT . '/index.php" method="post" enctype="application/x-www-form-urlencoded" target="_self" ><input type="hidden" id="user" name="user" value="' . $user . '"/><input type="hidden" id="password" name="password" value="irrelevant"/><noscript><input type="submit" name="login" value="Log in" /></noscript></form><script type="text/javascript" >document.getElementById("auto_login_form").submit();</script>';
     self::printPage($title, $body);
 }
Example #24
0
 protected function scan($fileView, $filepath)
 {
     $this->status = new Status();
     $fhandler = $this->getFileHandle($fileView, $filepath);
     \OCP\Util::writeLog('files_antivirus', 'Exec scan: ' . $filepath, \OCP\Util::DEBUG);
     // using 2>&1 to grab the full command-line output.
     $cmd = escapeshellcmd($this->avPath) . " - 2>&1";
     $descriptorSpec = array(0 => array("pipe", "r"), 1 => array("pipe", "w"));
     $pipes = array();
     $process = proc_open($cmd, $descriptorSpec, $pipes);
     if (!is_resource($process)) {
         fclose($fhandler);
         throw new \RuntimeException('Error starting process');
     }
     // write to stdin
     $shandler = $pipes[0];
     while (!feof($fhandler)) {
         $chunk = fread($fhandler, $this->chunkSize);
         fwrite($shandler, $chunk);
     }
     fclose($shandler);
     fclose($fhandler);
     $output = stream_get_contents($pipes[1]);
     fclose($pipes[1]);
     $result = proc_close($process);
     $this->status->parseResponse($output, $result);
     return $this->status->getNumericStatus();
 }
Example #25
0
 /**
  * {@inheritDoc}
  */
 public function getThumbnail($path, $maxX, $maxY, $scalingup, $fileview)
 {
     $this->initCmd();
     if (is_null($this->cmd)) {
         return false;
     }
     $absPath = $fileview->toTmpFile($path);
     $tmpDir = \OC::$server->getTempManager()->getTempBaseDir();
     $defaultParameters = ' -env:UserInstallation=file://' . escapeshellarg($tmpDir . '/owncloud-' . \OC_Util::getInstanceId() . '/') . ' --headless --nologo --nofirststartwizard --invisible --norestore --convert-to pdf --outdir ';
     $clParameters = \OCP\Config::getSystemValue('preview_office_cl_parameters', $defaultParameters);
     $exec = $this->cmd . $clParameters . escapeshellarg($tmpDir) . ' ' . escapeshellarg($absPath);
     shell_exec($exec);
     //create imagick object from pdf
     $pdfPreview = null;
     try {
         list($dirname, , , $filename) = array_values(pathinfo($absPath));
         $pdfPreview = $dirname . '/' . $filename . '.pdf';
         $pdf = new \imagick($pdfPreview . '[0]');
         $pdf->setImageFormat('jpg');
     } catch (\Exception $e) {
         unlink($absPath);
         unlink($pdfPreview);
         \OCP\Util::writeLog('core', $e->getmessage(), \OCP\Util::ERROR);
         return false;
     }
     $image = new \OC_Image();
     $image->loadFromData($pdf);
     unlink($absPath);
     unlink($pdfPreview);
     if ($image->valid()) {
         $image->scaleDownToFit($maxX, $maxY);
         return $image;
     }
     return false;
 }
Example #26
0
 public function search($query)
 {
     $unescape = function ($value) {
         return strtr($value, array('\\,' => ',', '\\;' => ';'));
     };
     $searchresults = array();
     $results = \OCP\Contacts::search($query, array('N', 'FN', 'EMAIL', 'NICKNAME', 'ORG'));
     $l = new \OC_l10n('contacts');
     foreach ($results as $result) {
         $link = \OCP\Util::linkToRoute('contacts_index') . '#' . $result['id'];
         $props = array();
         $display = isset($result['FN']) && $result['FN'] ? $result['FN'] : null;
         foreach (array('EMAIL', 'NICKNAME', 'ORG') as $searchvar) {
             if (isset($result[$searchvar]) && $result[$searchvar]) {
                 if (is_array($result[$searchvar])) {
                     $result[$searchvar] = array_filter($result[$searchvar]);
                 }
                 $prop = is_array($result[$searchvar]) ? implode(',', $result[$searchvar]) : $result[$searchvar];
                 $props[] = $prop;
                 $display = $display ?: $result[$searchvar];
             }
         }
         $props = array_map($unescape, $props);
         $searchresults[] = new \OC_Search_Result($display, implode(', ', $props), $link, (string) $l->t('Contact'), null);
         //$name,$text,$link,$type
     }
     return $searchresults;
 }
Example #27
0
 /**
  * @dataProvider getData
  */
 public function testGet($user, $start, $count, $expected)
 {
     $_GET['start'] = $start;
     $_GET['count'] = $count;
     \OC_User::setUserId($user);
     $sessionUser = \OC::$server->getUserSession()->getUser();
     $this->assertInstanceOf('OCP\\IUser', $sessionUser);
     $this->assertEquals($user, $sessionUser->getUID());
     $activityManager = new ActivityManager($this->getMock('OCP\\IRequest'), $this->getMock('OCP\\IUserSession'), $this->getMock('OCP\\IConfig'));
     $activityManager->registerExtension(function () {
         return new Extension(\OCP\Util::getL10N('activity', 'en'), $this->getMock('\\OCP\\IURLGenerator'));
     });
     $this->overwriteService('ActivityManager', $activityManager);
     $result = \OCA\Activity\Api::get(array('_route' => 'get_cloud_activity'));
     $this->restoreService('ActivityManager');
     $this->assertEquals(100, $result->getStatusCode());
     $data = $result->getData();
     $this->assertEquals(sizeof($expected), sizeof($data));
     while (!empty($expected)) {
         $assertExpected = array_shift($expected);
         $assertData = array_shift($data);
         foreach ($assertExpected as $key => $value) {
             $this->assertArrayHasKey($key, $assertData);
             if ($value !== null) {
                 $this->assertEquals($value, $assertData[$key]);
             }
         }
     }
 }
Example #28
0
	/**
	 * {@inheritDoc}
	 */
	public function getThumbnail($path, $maxX, $maxY, $scalingup, $fileview) {
		try {
			$svg = new \Imagick();
			$svg->setBackgroundColor(new \ImagickPixel('transparent'));

			$content = stream_get_contents($fileview->fopen($path, 'r'));
			if (substr($content, 0, 5) !== '<?xml') {
				$content = '<?xml version="1.0" encoding="UTF-8" standalone="no"?>' . $content;
			}

			// Do not parse SVG files with references
			if (stripos($content, 'xlink:href') !== false) {
				return false;
			}

			$svg->readImageBlob($content);
			$svg->setImageFormat('png32');
		} catch (\Exception $e) {
			\OCP\Util::writeLog('core', $e->getmessage(), \OCP\Util::ERROR);
			return false;
		}

		//new image object
		$image = new \OC_Image();
		$image->loadFromData($svg);
		//check if image object is valid
		if ($image->valid()) {
			$image->scaleDownToFit($maxX, $maxY);

			return $image;
		}
		return false;
	}
Example #29
0
 public function __construct(IL10N $l, ISession $session, ICredentialsManager $credentialsManager)
 {
     $this->session = $session;
     $this->credentialsManager = $credentialsManager;
     $this->setIdentifier('password::logincredentials')->setScheme(self::SCHEME_PASSWORD)->setText($l->t('Log-in credentials, save in database'))->addParameters([]);
     \OCP\Util::connectHook('OC_User', 'post_login', $this, 'authenticate');
 }
Example #30
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::generateRandomBytes(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 {
                 $defaults = new \OC_Defaults();
                 \OC_Mail::send($email, $_POST['user'], $l->t('%s password reset', array($defaults->getName())), $msg, $from, $defaults->getName());
             } 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);
     }
 }