/**
  * @NoAdminRequired
  * @NoCSRFRequired
  */
 public function export()
 {
     $data = $this->data->export();
     $fileName = User::getUser() . ".csv";
     $Download = new DataDownloadResponse($data, $fileName, 'text/csv');
     return $Download;
 }
示例#2
0
 /**
  * Get the template for a specific activity-event in the activities
  *
  * @param array $activity An array with all the activity data in it
  * @return string
  */
 public static function show($activity)
 {
     $tmpl = new Template('activity', 'activity.box');
     $tmpl->assign('formattedDate', Util::formatDate($activity['timestamp']));
     $tmpl->assign('formattedTimestamp', \OCP\relative_modified_date($activity['timestamp']));
     $tmpl->assign('user', $activity['user']);
     $tmpl->assign('displayName', User::getDisplayName($activity['user']));
     if (strpos($activity['subjectformatted']['markup']['trimmed'], '<a ') !== false) {
         // We do not link the subject as we create links for the parameters instead
         $activity['link'] = '';
     }
     $tmpl->assign('event', $activity);
     if ($activity['file']) {
         $rootView = new View('/' . $activity['affecteduser'] . '/files');
         $exist = $rootView->file_exists($activity['file']);
         $is_dir = $rootView->is_dir($activity['file']);
         unset($rootView);
         // show a preview image if the file still exists
         $mimetype = \OC_Helper::getFileNameMimeType($activity['file']);
         if (!$is_dir && \OC::$server->getPreviewManager()->isMimeSupported($mimetype) && $exist) {
             $tmpl->assign('previewLink', Util::linkTo('files', 'index.php', array('dir' => dirname($activity['file']))));
             $tmpl->assign('previewImageLink', Util::linkToRoute('core_ajax_preview', array('file' => $activity['file'], 'x' => 150, 'y' => 150)));
         } else {
             $tmpl->assign('previewLink', Util::linkTo('files', 'index.php', array('dir' => $activity['file'])));
             $tmpl->assign('previewImageLink', \OC_Helper::mimetypeIcon($is_dir ? 'dir' : $mimetype));
             $tmpl->assign('previewLinkIsDir', true);
         }
     }
     return $tmpl->fetchPage();
 }
示例#3
0
 public function __construct(array $urlParams = array())
 {
     parent::__construct('weather', $urlParams);
     $container = $this->getContainer();
     /**
      * Core
      */
     $container->registerService('UserId', function (IContainer $c) {
         return \OCP\User::getUser();
     });
     /**
      * Database Layer
      */
     $container->registerService('CityMapper', function (IContainer $c) {
         return new CityMapper($c->query('ServerContainer')->getDb());
     });
     $container->registerService('SettingsMapper', function (IContainer $c) {
         return new SettingsMapper($c->query('ServerContainer')->getDb());
     });
     /**
      * Controllers
      */
     $container->registerService('CityController', function (IContainer $c) {
         return new CityController($c->query('AppName'), $c->query('Request'), $c->query('UserId'), $c->query('CityMapper'), $c->query('SettingsMapper'));
     });
     $container->registerService('SettingsController', function (IContainer $c) {
         return new SettingsController($c->query('AppName'), $c->query('Request'), $c->query('UserId'), $c->query('SettingsMapper'), $c->query('CityMapper'));
     });
     $container->registerService('WeatherController', function (IContainer $c) {
         return new WeatherController($c->query('AppName'), $c->query('Request'), $c->query('UserId'), $c->query('CityMapper'), $c->query('SettingsMapper'));
     });
 }
 public function register()
 {
     $loginRecord = function ($user) {
         \OCP\Util::writeLog('core', "user:"******" action:login success", \OCP\Util::INFO);
     };
     $logoutRecord = function () {
         \OCP\Util::writeLog('core', "user:"******" action:logout success", \OCP\Util::INFO);
     };
     $createRecord = function ($node) {
         \OCP\Util::writeLog('activity', "user:"******" action:cretes " . $node->getName() . " sucess", \OCP\Util::INFO);
     };
     $deleteRecord = function ($node) {
         \OCP\Util::writeLog('activity', "user:"******" action:deletes " . $node->getName() . " sucess", \OCP\Util::INFO);
     };
     $renameRecord = function ($node) {
         \OCP\Util::writeLog('activity', "user:"******" action:renames " . $node->getName() . " sucess", \OCP\Util::INFO);
     };
     $touchRecord = function ($node) {
         \OCP\Util::writeLog('activity', "user:"******" action:touches " . $node->getName() . " sucess", \OCP\Util::INFO);
     };
     $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);
 }
示例#5
0
	public function __construct (array $urlParams=array()) {
		parent::__construct('ownnote', $urlParams);

		$container = $this->getContainer();

		/**
		 * Controllers
		 */
		$container->registerService('PageController', function(IContainer $c) {
			return new PageController(
				$c->query('AppName'), 
				$c->query('Request'),
				$c->query('UserId')
			);
		});

                $container->registerService('OwnnoteApiController', function($c){
                        return new OwnnoteApiController(
                                $c->query('AppName'),
                                $c->query('Request')
                        );
                });


		/**
		 * Core
		 */
		$container->registerService('UserId', function(IContainer $c) {
			return \OCP\User::getUser();
		});		
		
	}
示例#6
0
 /**
  * Returns a list of ACE's for this node.
  *
  * Each ACE has the following properties:
  *   * 'privilege', a string such as {DAV:}read or {DAV:}write. These are
  *     currently the only supported privileges
  *   * 'principal', a url to the principal who owns the node
  *   * 'protected' (optional), indicating that this ACE is not allowed to
  *      be updated.
  *
  * @return array
  */
 public function getACL()
 {
     $readprincipal = $this->getOwner();
     $writeprincipal = $this->getOwner();
     $createprincipal = $this->getOwner();
     $deleteprincipal = $this->getOwner();
     $uid = AddrBook::extractUserID($this->getOwner());
     //\OCP\Config::setUserValue($uid, 'contactsplus', 'syncaddrbook', $this->addressBookInfo['uri']);
     $readWriteACL = array(array('privilege' => '{DAV:}read', 'principal' => 'principals/' . \OCP\User::getUser(), 'protected' => true), array('privilege' => '{DAV:}write', 'principal' => 'principals/' . \OCP\User::getUser(), 'protected' => true));
     if ($uid !== \OCP\USER::getUser()) {
         $sharedAddressbook = \OCP\Share::getItemSharedWithBySource(ContactsApp::SHAREADDRESSBOOK, ContactsApp::SHAREADDRESSBOOKPREFIX . $this->addressBookInfo['id']);
         if ($sharedAddressbook) {
             if ($sharedAddressbook['permissions'] & \OCP\PERMISSION_CREATE && $sharedAddressbook['permissions'] & \OCP\PERMISSION_UPDATE && $sharedAddressbook['permissions'] & \OCP\PERMISSION_DELETE) {
                 return $readWriteACL;
             }
             if ($sharedAddressbook['permissions'] & \OCP\PERMISSION_CREATE) {
                 $createprincipal = 'principals/' . \OCP\USER::getUser();
             }
             if ($sharedAddressbook['permissions'] & \OCP\PERMISSION_READ) {
                 $readprincipal = 'principals/' . \OCP\USER::getUser();
             }
             if ($sharedAddressbook['permissions'] & \OCP\PERMISSION_UPDATE) {
                 $writeprincipal = 'principals/' . \OCP\USER::getUser();
             }
             if ($sharedAddressbook['permissions'] & \OCP\PERMISSION_DELETE) {
                 $deleteprincipal = 'principals/' . \OCP\USER::getUser();
             }
         }
     } else {
         return parent::getACL();
     }
     return array(array('privilege' => '{DAV:}read', 'principal' => $readprincipal, 'protected' => true), array('privilege' => '{DAV:}write-content', 'principal' => $writeprincipal, 'protected' => true), array('privilege' => '{DAV:}bind', 'principal' => $createprincipal, 'protected' => true), array('privilege' => '{DAV:}unbind', 'principal' => $deleteprincipal, 'protected' => true));
 }
示例#7
0
 public function __construct(array $urlParams = array())
 {
     parent::__construct('tasks', $urlParams);
     $container = $this->getContainer();
     /**
      * Controllers
      */
     $container->registerService('PageController', function ($c) {
         return new PageController($c->query('AppName'), $c->query('Request'), $c->query('UserId'));
     });
     $container->registerService('CollectionsController', function ($c) {
         return new CollectionsController($c->query('AppName'), $c->query('Request'), $c->query('UserId'), $c->query('L10N'), $c->query('Settings'));
     });
     $container->registerService('ListsController', function ($c) {
         return new ListsController($c->query('AppName'), $c->query('Request'), $c->query('UserId'));
     });
     $container->registerService('SettingsController', function ($c) {
         return new SettingsController($c->query('AppName'), $c->query('Request'), $c->query('UserId'), $c->query('Settings'));
     });
     $container->registerService('TasksController', function ($c) {
         return new TasksController($c->query('AppName'), $c->query('Request'), $c->query('UserId'));
     });
     /**
      * Core
      */
     $container->registerService('UserId', function ($c) {
         return \OCP\User::getUser();
     });
     $container->registerService('L10N', function ($c) {
         return $c->query('ServerContainer')->getL10N($c->query('AppName'));
     });
     $container->registerService('Settings', function ($c) {
         return $c->query('ServerContainer')->getConfig();
     });
 }
示例#8
0
 /**
  * create a new share
  *
  * @param array $params
  * @return \OC_OCS_Result
  */
 public function createShare($params)
 {
     if (!$this->isS2SEnabled(true)) {
         return new \OC_OCS_Result(null, 503, 'Server does not support federated cloud sharing');
     }
     $remote = isset($_POST['remote']) ? $_POST['remote'] : null;
     $token = isset($_POST['token']) ? $_POST['token'] : null;
     $name = isset($_POST['name']) ? $_POST['name'] : null;
     $owner = isset($_POST['owner']) ? $_POST['owner'] : null;
     $shareWith = isset($_POST['shareWith']) ? $_POST['shareWith'] : null;
     $remoteId = isset($_POST['remoteId']) ? (int) $_POST['remoteId'] : null;
     if ($remote && $token && $name && $owner && $remoteId && $shareWith) {
         if (!\OCP\Util::isValidFileName($name)) {
             return new \OC_OCS_Result(null, 400, 'The mountpoint name contains invalid characters.');
         }
         if (!\OCP\User::userExists($shareWith)) {
             return new \OC_OCS_Result(null, 400, 'User does not exists');
         }
         \OC_Util::setupFS($shareWith);
         $externalManager = new \OCA\Files_Sharing\External\Manager(\OC::$server->getDatabaseConnection(), \OC\Files\Filesystem::getMountManager(), \OC\Files\Filesystem::getLoader(), \OC::$server->getHTTPHelper(), $shareWith);
         try {
             $externalManager->addShare($remote, $token, '', $name, $owner, false, $shareWith, $remoteId);
             $user = $owner . '@' . $this->cleanupRemote($remote);
             \OC::$server->getActivityManager()->publishActivity('files_sharing', \OCA\Files_Sharing\Activity::SUBJECT_REMOTE_SHARE_RECEIVED, array($user), '', array(), '', '', $shareWith, \OCA\Files_Sharing\Activity::TYPE_REMOTE_SHARE, \OCA\Files_Sharing\Activity::PRIORITY_LOW);
             return new \OC_OCS_Result();
         } catch (\Exception $e) {
             \OCP\Util::writeLog('files_sharing', 'server can not add remote share, ' . $e->getMessage(), \OCP\Util::ERROR);
             return new \OC_OCS_Result(null, 500, 'internal server error, was not able to add share from ' . $remote);
         }
     }
     return new \OC_OCS_Result(null, 400, 'server can not add remote share, missing parameter');
 }
示例#9
0
 /**
  * Checks if the user has all required attributes
  * and, if successfull, returns user's owncloud uid.
  *
  * @return false|string false if requirements not met, OC uid otherwise
  */
 public function checkAttributes()
 {
     // Shibboleth/SAML uid is always required
     $shibUid = $this->getShibUid();
     if (!$shibUid) {
         return false;
     }
     // TODO: Move email to $backendConfig['required_attrs']
     // TODO: Require email for all users (not only newly created)
     // when all IdP's will provide it for us. Then move getOcUid
     // call to the end of this method.
     $ocUid = $this->getOcUid();
     if (!$this->getEmail() && !\OCP\User::userExists($ocUid)) {
         return false;
     }
     // Check for additional required attributes
     $missingAttrs = '';
     foreach ($this->backendConfig['required_attrs'] as &$attr) {
         if (!$this->getAttribute($attr)) {
             $missingAttrs .= $attr . ' ';
         }
     }
     if ($missingAttrs !== '') {
         $this->logger->warning(sprintf('User: %s is' . ' missing required attributes: %s', $shibUid, $missingAttrs), $this->logCtx);
         return false;
     }
     return $ocUid;
 }
示例#10
0
 public function __construct(array $urlParams = array())
 {
     parent::__construct('documents', $urlParams);
     $container = $this->getContainer();
     /**
      * Controllers
      */
     $container->registerService('UserController', function ($c) {
         return new UserController($c->query('AppName'), $c->query('Request'));
     });
     $container->registerService('SessionController', function ($c) {
         return new SessionController($c->query('AppName'), $c->query('Request'), $c->query('Logger'), $c->query('UserId'));
     });
     $container->registerService('DocumentController', function ($c) {
         return new DocumentController($c->query('AppName'), $c->query('Request'), $c->query('CoreConfig'), $c->query('L10N'), $c->query('UserId'));
     });
     $container->registerService('SettingsController', function ($c) {
         return new SettingsController($c->query('AppName'), $c->query('Request'), $c->query('CoreConfig'), $c->query('Logger'), $c->query('L10N'), $c->query('UserId'));
     });
     /**
      * Core
      */
     $container->registerService('Logger', function ($c) {
         return $c->query('ServerContainer')->getLogger();
     });
     $container->registerService('CoreConfig', function ($c) {
         return $c->query('ServerContainer')->getConfig();
     });
     $container->registerService('L10N', function ($c) {
         return $c->query('ServerContainer')->getL10N($c->query('AppName'));
     });
     $container->registerService('UserId', function () {
         return \OCP\User::getUser();
     });
 }
示例#11
0
function getShortcode($url) {
	$shortcode = '';
	$query = OCP\DB::prepare('SELECT shortcode FROM *PREFIX*shorten WHERE url=?');
	$results = $query->execute(Array($url))->fetchAll();
	if ($results) {
		foreach($results as $result) {
			$shortcode = $result['shortcode'];	
		}
	}
	if ($shortcode == "") {
		$shortcode = rand_chars(6);
		$found = true;
		while ($found) {
			$query = OCP\DB::prepare('SELECT id FROM *PREFIX*shorten WHERE shortcode=?');
			$results = $query->execute(Array($shortcode))->fetchAll();
			if (!$results) {
				$found = false;
				$uid = \OCP\User::getUser();
				$query = OCP\DB::prepare('INSERT INTO *PREFIX*shorten (uid, shortcode, url) VALUES (?,?,?)');
				$query->execute(Array($uid,$shortcode,$url));
				$id = OCP\DB::insertid('*PREFIX*shorten');
			} else
				$shortcode = rand_chars(6);
		}
	}
	return $shortcode;
}
 /**
  * Define your dependencies in here
  */
 public function __construct(array $urlParams = array())
 {
     parent::__construct('user_files_restore', $urlParams);
     $container = $this->getContainer();
     /**
      * Controllers
      */
     $container->registerService('PageController', function ($c) {
         return new PageController($c->query('AppName'), $c->query('Request'), $c->query('L10N'), $c->query('RequestService'), $c->query('UserId'));
     });
     $container->registerService('RequestController', function ($c) {
         return new RequestController($c->query('AppName'), $c->query('Request'), $c->query('L10N'), $c->query('RequestMapper'), $c->query('UserId'));
     });
     /**
      * Services
      */
     $container->registerService('RequestService', function ($c) {
         return new RequestService($c->query('RequestMapper'), $c->query('UserId'), $c->query('L10N'));
     });
     /**
      * Database Layer
      */
     $container->registerService('RequestMapper', function ($c) {
         return new RequestMapper($c->query('ServerContainer')->getDb(), $c->query('L10N'));
     });
     /**
      * Core
      */
     $container->registerService('UserId', function ($c) {
         return \OCP\User::getUser();
     });
     $container->registerService('L10N', function ($c) {
         return $c->query('ServerContainer')->getL10N($c->query('AppName'));
     });
 }
示例#13
0
文件: display.php 项目: samj1912/repo
 /**
  * Get the template for a specific activity-event in the activities
  *
  * @param array $activity An array with all the activity data in it
  * @return string
  */
 public function show($activity)
 {
     $tmpl = new Template('activity', 'stream.item');
     $tmpl->assign('formattedDate', $this->dateTimeFormatter->formatDateTime($activity['timestamp']));
     $tmpl->assign('formattedTimestamp', Template::relative_modified_date($activity['timestamp']));
     $tmpl->assign('user', $activity['user']);
     $tmpl->assign('displayName', User::getDisplayName($activity['user']));
     if (strpos($activity['subjectformatted']['markup']['trimmed'], '<a ') !== false) {
         // We do not link the subject as we create links for the parameters instead
         $activity['link'] = '';
     }
     $tmpl->assign('event', $activity);
     if ($activity['file']) {
         $this->view->chroot('/' . $activity['affecteduser'] . '/files');
         $exist = $this->view->file_exists($activity['file']);
         $is_dir = $this->view->is_dir($activity['file']);
         $tmpl->assign('previewLink', $this->getPreviewLink($activity['file'], $is_dir));
         // show a preview image if the file still exists
         $mimeType = \OC_Helper::getFileNameMimeType($activity['file']);
         if ($mimeType && !$is_dir && $this->preview->isMimeSupported($mimeType) && $exist) {
             $tmpl->assign('previewImageLink', $this->urlGenerator->linkToRoute('core_ajax_preview', array('file' => $activity['file'], 'x' => 150, 'y' => 150)));
         } else {
             $mimeTypeIcon = Template::mimetype_icon($is_dir ? 'dir' : $mimeType);
             $mimeTypeIcon = substr($mimeTypeIcon, -4) === '.png' ? substr($mimeTypeIcon, 0, -4) . '.svg' : $mimeTypeIcon;
             $tmpl->assign('previewImageLink', $mimeTypeIcon);
             $tmpl->assign('previewLinkIsDir', true);
         }
     }
     return $tmpl->fetchPage();
 }
示例#14
0
 /**
  *@PublicPage
  * @NoCSRFRequired
  * 
  */
 public function exportEvents()
 {
     $token = $this->params('t');
     $calid = null;
     $eventid = null;
     if (isset($token)) {
         $linkItem = \OCP\Share::getShareByToken($token, false);
         if (is_array($linkItem) && isset($linkItem['uid_owner'])) {
             $rootLinkItem = \OCP\Share::resolveReShare($linkItem);
             if (isset($rootLinkItem['uid_owner'])) {
                 \OCP\JSON::checkUserExists($rootLinkItem['uid_owner']);
                 if ($linkItem['item_type'] === CalendarApp::SHARECALENDAR) {
                     $sPrefix = CalendarApp::SHARECALENDARPREFIX;
                 }
                 if ($linkItem['item_type'] === CalendarApp::SHAREEVENT) {
                     $sPrefix = CalendarApp::SHAREEVENTPREFIX;
                 }
                 if ($linkItem['item_type'] === CalendarApp::SHARETODO) {
                     $sPrefix = CalendarApp::SHARETODOPREFIX;
                 }
                 $itemSource = CalendarApp::validateItemSource($linkItem['item_source'], $sPrefix);
                 if ($linkItem['item_type'] === CalendarApp::SHARECALENDAR) {
                     $calid = $itemSource;
                 }
                 if ($linkItem['item_type'] === CalendarApp::SHAREEVENT || $linkItem['item_type'] === CalendarApp::SHARETODO) {
                     $eventid = $itemSource;
                 }
             }
         }
     } else {
         if (\OCP\User::isLoggedIn()) {
             $calid = $this->params('calid');
             $eventid = $this->params('eventid');
         }
     }
     if (!is_null($calid)) {
         $calendar = CalendarApp::getCalendar($calid, true);
         if (!$calendar) {
             $params = ['status' => 'error'];
             $response = new JSONResponse($params);
             return $response;
         }
         $name = str_replace(' ', '_', $calendar['displayname']) . '.ics';
         $calendarEvents = Export::export($calid, Export::CALENDAR);
         $response = new DataDownloadResponse($calendarEvents, $name, 'text/calendar');
         return $response;
     }
     if (!is_null($eventid)) {
         $data = CalendarApp::getEventObject($eventid, false);
         if (!$data) {
             $params = ['status' => 'error'];
             $response = new JSONResponse($params);
             return $response;
         }
         $name = str_replace(' ', '_', $data['summary']) . '.ics';
         $singleEvent = Export::export($eventid, Export::EVENT);
         $response = new DataDownloadResponse($singleEvent, $name, 'text/calendar');
         return $response;
     }
 }
示例#15
0
 function search($query)
 {
     $collection = new Collection(\OCP\User::getUser());
     $l = \OC_L10N::get('media');
     $app_name = (string) $l->t('Music');
     $artists = $collection->getArtists($query);
     $albums = $collection->getAlbums(0, $query);
     $songs = $collection->getSongs(0, 0, $query);
     $results = array();
     foreach ($artists as $artist) {
         $results[] = new \OC_Search_Result($artist['artist_name'], '', \OCP\Util::linkTo('media', 'index.php') . '#artist=' . urlencode($artist['artist_name']), $app_name);
     }
     foreach ($albums as $album) {
         $artist = $collection->getArtistName($album['album_artist']);
         $results[] = new \OC_Search_Result($album['album_name'], 'by ' . $artist, \OCP\Util::linkTo('media', 'index.php') . '#artist=' . urlencode($artist) . '&album=' . urlencode($album['album_name']), $app_name);
     }
     foreach ($songs as $song) {
         $minutes = floor($song['song_length'] / 60);
         $seconds = $song['song_length'] % 60;
         $artist = $collection->getArtistName($song['song_artist']);
         $album = $collection->getalbumName($song['song_album']);
         $results[] = new \OC_Search_Result($song['song_name'], "by {$artist}, in {$album} {$minutes}:{$seconds}", \OCP\Util::linkTo('media', 'index.php') . '#artist=' . urlencode($artist) . '&album=' . urlencode($album) . '&song=' . urlencode($song['song_name']), $app_name);
     }
     return $results;
 }
示例#16
0
 /**
  * Get the template for a specific activity-event in the activities
  *
  * @param array $activity An array with all the activity data in it
  * @param return string
  */
 public static function show($activity)
 {
     $tmpl = new \OCP\Template('activity', 'activity.box');
     $tmpl->assign('formattedDate', \OCP\Util::formatDate($activity['timestamp']));
     $tmpl->assign('formattedTimestamp', \OCP\relative_modified_date($activity['timestamp']));
     $tmpl->assign('user', $activity['user']);
     $tmpl->assign('displayName', \OCP\User::getDisplayName($activity['user']));
     if ($activity['app'] === 'files') {
         // We do not link the subject as we create links for the parameters instead
         $activity['link'] = '';
     }
     $tmpl->assign('event', $activity);
     if ($activity['file']) {
         $rootView = new \OC\Files\View('');
         $exist = $rootView->file_exists('/' . $activity['user'] . '/files' . $activity['file']);
         $is_dir = $rootView->is_dir('/' . $activity['user'] . '/files' . $activity['file']);
         unset($rootView);
         // show a preview image if the file still exists
         if (!$is_dir && $exist) {
             $tmpl->assign('previewLink', \OCP\Util::linkTo('files', 'index.php', array('dir' => dirname($activity['file']))));
             $tmpl->assign('previewImageLink', \OCP\Util::linkToRoute('core_ajax_preview', array('file' => $activity['file'], 'x' => 150, 'y' => 150)));
         } else {
             if ($exist) {
                 $tmpl->assign('previewLink', \OCP\Util::linkTo('files', 'index.php', array('dir' => $activity['file'])));
                 $tmpl->assign('previewImageLink', \OC_Helper::mimetypeIcon('dir'));
                 $tmpl->assign('previewLinkIsDir', true);
             }
         }
     }
     return $tmpl->fetchPage();
 }
 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);
 }
示例#18
0
 /**
  * create a new share
  *
  * @param array $params
  * @return \OC_OCS_Result
  */
 public function createShare($params)
 {
     if (!$this->isS2SEnabled(true)) {
         return new \OC_OCS_Result(null, 503, 'Server does not support federated cloud sharing');
     }
     $remote = isset($_POST['remote']) ? $_POST['remote'] : null;
     $token = isset($_POST['token']) ? $_POST['token'] : null;
     $name = isset($_POST['name']) ? $_POST['name'] : null;
     $owner = isset($_POST['owner']) ? $_POST['owner'] : null;
     $shareWith = isset($_POST['shareWith']) ? $_POST['shareWith'] : null;
     $remoteId = isset($_POST['remoteId']) ? (int) $_POST['remoteId'] : null;
     if ($remote && $token && $name && $owner && $remoteId && $shareWith) {
         if (!\OCP\Util::isValidFileName($name)) {
             return new \OC_OCS_Result(null, 400, 'The mountpoint name contains invalid characters.');
         }
         // FIXME this should be a method in the user management instead
         \OCP\Util::writeLog('files_sharing', 'shareWith before, ' . $shareWith, \OCP\Util::DEBUG);
         \OCP\Util::emitHook('\\OCA\\Files_Sharing\\API\\Server2Server', 'preLoginNameUsedAsUserName', array('uid' => &$shareWith));
         \OCP\Util::writeLog('files_sharing', 'shareWith after, ' . $shareWith, \OCP\Util::DEBUG);
         if (!\OCP\User::userExists($shareWith)) {
             return new \OC_OCS_Result(null, 400, 'User does not exists');
         }
         \OC_Util::setupFS($shareWith);
         $externalManager = new \OCA\Files_Sharing\External\Manager(\OC::$server->getDatabaseConnection(), \OC\Files\Filesystem::getMountManager(), \OC\Files\Filesystem::getLoader(), \OC::$server->getHTTPHelper(), \OC::$server->getNotificationManager(), $shareWith);
         try {
             $externalManager->addShare($remote, $token, '', $name, $owner, false, $shareWith, $remoteId);
             $user = $owner . '@' . $this->cleanupRemote($remote);
             \OC::$server->getActivityManager()->publishActivity(Activity::FILES_SHARING_APP, Activity::SUBJECT_REMOTE_SHARE_RECEIVED, array($user, trim($name, '/')), '', array(), '', '', $shareWith, Activity::TYPE_REMOTE_SHARE, Activity::PRIORITY_LOW);
             /**
             * FIXME
             				$urlGenerator = \OC::$server->getURLGenerator();
             
             				$notificationManager = \OC::$server->getNotificationManager();
             				$notification = $notificationManager->createNotification();
             				$notification->setApp('files_sharing')
             					->setUser($shareWith)
             					->setTimestamp(time())
             					->setObject('remote_share', $remoteId)
             					->setSubject('remote_share', [$user, trim($name, '/')]);
             
             				$declineAction = $notification->createAction();
             				$declineAction->setLabel('decline')
             					->setLink($urlGenerator->getAbsoluteURL('/ocs/v1.php/apps/files_sharing/api/v1/remote_shares/' . $remoteId), 'DELETE');
             				$notification->addAction($declineAction);
             
             				$acceptAction = $notification->createAction();
             				$acceptAction->setLabel('accept')
             					->setLink($urlGenerator->getAbsoluteURL('/ocs/v1.php/apps/files_sharing/api/v1/remote_shares/' . $remoteId), 'POST');
             				$notification->addAction($acceptAction);
             
             				$notificationManager->notify($notification);
             */
             return new \OC_OCS_Result();
         } catch (\Exception $e) {
             \OCP\Util::writeLog('files_sharing', 'server can not add remote share, ' . $e->getMessage(), \OCP\Util::ERROR);
             return new \OC_OCS_Result(null, 500, 'internal server error, was not able to add share from ' . $remote);
         }
     }
     return new \OC_OCS_Result(null, 400, 'server can not add remote share, missing parameter');
 }
示例#19
0
 public function __construct(array $urlParams = array())
 {
     parent::__construct('bookmarks', $urlParams);
     $container = $this->getContainer();
     /**
      * Controllers
      * @param OC\AppFramework\Utility\SimpleContainer $c The Container instance
      *													 that handles the request
      */
     $container->registerService('WebViewController', function ($c) {
         return new WebViewController($c->query('AppName'), $c->query('Request'), $c->query('UserId'), $c->query('ServerContainer')->getURLGenerator(), $c->query('ServerContainer')->getDb());
     });
     $container->registerService('BookmarkController', function ($c) {
         return new BookmarkController($c->query('AppName'), $c->query('Request'), $c->query('UserId'), $c->query('ServerContainer')->getDb());
     });
     $container->registerService('TagsController', function ($c) {
         return new TagsController($c->query('AppName'), $c->query('Request'), $c->query('UserId'), $c->query('ServerContainer')->getDb());
     });
     $container->registerService('PublicController', function ($c) {
         return new PublicController($c->query('AppName'), $c->query('Request'), $c->query('ServerContainer')->getDb(), $c->query('ServerContainer')->getUserManager());
     });
     /**
      * Core
      */
     $container->registerService('UserId', function () {
         return \OCP\User::getUser();
     });
 }
示例#20
0
 public static function post_write_hook($params)
 {
     $user = \OCP\User::getUser();
     if (!empty($user)) {
         Trashbin::resizeTrash($user);
     }
 }
示例#21
0
 public function __construct()
 {
     $timeNow = time();
     //test
     $checkOffset = new \DateTime(date('d.m.Y', $timeNow), new \DateTimeZone(self::$tz));
     $calcSumWin = $checkOffset->getOffset();
     $this->nowTime = strtotime(date('d.m.Y H:i', $timeNow)) + $calcSumWin;
     if (\OC::$server->getSession()->get('public_link_token')) {
         $linkItem = \OCP\Share::getShareByToken(\OC::$server->getSession()->get('public_link_token', false));
         if (is_array($linkItem) && isset($linkItem['uid_owner'])) {
             if ($linkItem['item_type'] === App::SHARECALENDAR) {
                 $sPrefix = App::SHARECALENDARPREFIX;
             }
             if ($linkItem['item_type'] === App::SHAREEVENT) {
                 $sPrefix = App::SHAREEVENTPREFIX;
             }
             if ($linkItem['item_type'] === App::SHARETODO) {
                 $sPrefix = App::SHARETODOPREFIX;
             }
             $itemSource = App::validateItemSource($linkItem['item_source'], $sPrefix);
             $rootLinkItem = Calendar::find($itemSource);
             $this->aCalendars[] = $rootLinkItem;
         }
     } else {
         if (\OCP\User::isLoggedIn()) {
             $this->aCalendars = Calendar::allCalendars(\OCP\User::getUser());
             $this->checkAlarm();
         }
     }
 }
 /**
  * @dataProvider prepareParametersData
  */
 public function testPrepareParameters($params, $filePosition, $stripPath, $highlightParams, $expected, $createFolder = '')
 {
     if ($createFolder !== '') {
         $this->view->mkdir('/' . \OCP\User::getUser() . '/files/' . $createFolder);
     }
     $this->assertEquals($expected, $this->parameterHelper->prepareParameters($params, $filePosition, $stripPath, $highlightParams));
 }
示例#23
0
 public function __construct(array $urlParams = array())
 {
     parent::__construct('maps', $urlParams);
     $container = $this->getContainer();
     /**
      * Controllers
      */
     $container->registerService('PageController', function ($c) {
         return new PageController($c->query('AppName'), $c->query('Request'), $c->query('UserId'), $c->query('CacheManager'), $c->query('LocationManager'));
     });
     $container->registerService('LocationController', function ($c) {
         return new LocationController($c->query('AppName'), $c->query('Request'), $c->query('LocationManager'), $c->query('UserId'));
     });
     $container->registerService('CacheManager', function ($c) {
         return new CacheManager($c->query('ServerContainer')->getDb());
     });
     $container->registerService('LocationManager', function ($c) {
         return new LocationManager($c->query('ServerContainer')->getDb());
     });
     /**
      * Core
      */
     $container->registerService('UserId', function ($c) {
         return \OCP\User::getUser();
     });
     $container->registerService('Db', function () {
         return new Db();
     });
 }
示例#24
0
 public function __construct($imagePath, $user = null, $square = false)
 {
     if (!Filesystem::isValidPath($imagePath)) {
         return;
     }
     if (is_null($user)) {
         $this->view = Filesystem::getView();
         $this->user = \OCP\User::getUser();
     } else {
         $this->view = new View('/' . $user . '/files');
         $this->user = $user;
     }
     $this->useOriginal = (substr($imagePath, -4) === '.svg' or substr($imagePath, -5) === '.svgz');
     if ($this->useOriginal) {
         $this->path = $imagePath;
     } else {
         $galleryDir = \OC_User::getHome($this->user) . '/gallery/' . $this->user . '/';
         if (strrpos($imagePath, '.')) {
             $extension = substr($imagePath, strrpos($imagePath, '.') + 1);
             $image = substr($imagePath, 0, strrpos($imagePath, '.'));
         } else {
             $extension = '';
             $image = $imagePath;
         }
         if ($square) {
             $extension = 'square.' . $extension;
         }
         $this->path = $galleryDir . $image . '.' . $extension;
         if (!file_exists($this->path)) {
             $this->create($imagePath, $square);
         }
     }
 }
示例#25
0
 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']);
         }
     }
 }
示例#26
0
 public function __construct($user = null, $addressBooksTableName = '*PREFIX*addressbook', $backendsTableName = '*PREFIX*addressbooks_backend', $dbBackend = null)
 {
     $this->user = $user ? $user : \OCP\User::getUser();
     $this->addressBooksTableName = $addressBooksTableName;
     $this->backendsTableName = $backendsTableName;
     $this->dbBackend = $dbBackend ? $dbBackend : new Backend\Database($user);
 }
 /**
  * @dataProvider prepareParametersData
  */
 public function testPrepareParameters($params, $filePosition, $stripPath, $highlightParams, $expected, $createFolder = '', $enableAvatars = true)
 {
     if ($createFolder !== '') {
         $this->view->mkdir('/' . \OCP\User::getUser() . '/files/' . $createFolder);
     }
     $this->config->expects($this->any())->method('getSystemValue')->with('enable_avatars', true)->willReturn($enableAvatars);
     $this->assertEquals($expected, $this->parameterHelper->prepareParameters($params, $filePosition, $stripPath, $highlightParams));
 }
示例#28
0
 /**
  * Sets up the backend
  *
  * @param string $addressBooksTableName
  * @param string $cardsTableName
  */
 public function __construct($userid = null, $options = array('addressBooksTableName' => '*PREFIX*contacts_addressbooks', 'cardsTableName' => '*PREFIX*contacts_cards', 'indexTableName' => '*PREFIX*contacts_cards_properties'))
 {
     $this->userid = $userid ? $userid : \OCP\User::getUser();
     $this->addressBooksTableName = $options['addressBooksTableName'];
     $this->cardsTableName = $options['cardsTableName'];
     $this->indexTableName = $options['indexTableName'];
     $this->addressBooks = array();
 }
示例#29
0
 public static function readdir($path)
 {
     $result = parent::readdir($path);
     if ($result === false) {
         \OCP\Util::writeLog('activity', "user:"******" action:read fail", \OCP\Util::WARN);
     }
     return $result;
 }
示例#30
0
 /**
  * Do security precheck
  * @param bool callcheck - whether security token check is needed
  * @return string userId of the currently logged in user
  */
 public static function preDispatch($callcheck = true)
 {
     if ($callcheck) {
         \OCP\JSON::callCheck();
     }
     \OCP\JSON::checkAppEnabled('documents');
     \OCP\JSON::checkLoggedIn();
     return \OCP\User::getUser();
 }