コード例 #1
0
ファイル: controller.php プロジェクト: Combustible/core
 /**
  * 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)));
     }
 }
コード例 #2
0
ファイル: settings.php プロジェクト: olucao/owncloud-core
* @copyright 2012 Michael Gapczynski mtgap@owncloud.com
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
* License as published by the Free Software Foundation; either
* version 3 of the License, or any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
*
* You should have received a copy of the GNU Affero General Public
* License along with this library.  If not, see <http://www.gnu.org/licenses/>.
*/
OC_Util::checkAdminUser();
OCP\Util::addScript('files_external', 'settings');
OCP\Util::addscript('3rdparty', 'chosen/chosen.jquery.min');
OCP\Util::addStyle('files_external', 'settings');
OCP\Util::addStyle('3rdparty', 'chosen/chosen');
$backends = OC_Mount_Config::getBackends();
$personal_backends = array();
$enabled_backends = explode(',', OCP\Config::getAppValue('files_external', 'user_mounting_backends', ''));
foreach ($backends as $class => $backend) {
    if ($class != '\\OC\\Files\\Storage\\Local') {
        $personal_backends[$class] = array('backend' => $backend['backend'], 'enabled' => in_array($class, $enabled_backends));
    }
}
$tmpl = new OCP\Template('files_external', 'settings');
$tmpl->assign('isAdminPage', true);
$tmpl->assign('mounts', OC_Mount_Config::getSystemMountPoints());
コード例 #3
0
ファイル: user.php プロジェクト: olucao/owncloud-core
 /**
  * Check if the user is a admin, redirects to home if not
  */
 public static function checkAdminUser()
 {
     \OC_Util::checkAdminUser();
 }
コード例 #4
0
 /**
  * @Ajax
  */
 public function manageGroup()
 {
     \OC_Util::checkAdminUser();
     $params = $this->request->post;
     $id = isset($params['group']) ? $params['group'] : null;
     $name = isset($params['name']) ? $params['name'] : null;
     $action = isset($params['action']) ? $params['action'] : null;
     $groupType = isset($params['gt']) ? $params['gt'] : null;
     if (is_null($action) || is_null($groupType)) {
         return new JSONResponse(array("msg" => "Not specified action or group type"), Http::STATUS_BAD_REQUEST);
     }
     if (!GK::checkGroupType($groupType)) {
         return new JSONResponse(array("msg" => "Group type {$groupType} is not valid"), Http::STATUS_BAD_REQUEST);
     }
     switch ($action) {
         case 'rm':
             if (is_null($id)) {
                 return new JSONResponse(array("msg" => "Not specified id"), Http::STATUS_BAD_REQUEST);
             }
             $ao = AccessObject::fromParams(array('id' => $id));
             $this->accessObjectMapper->delete($ao);
             break;
         case 'add':
             if (is_null($name)) {
                 return new JSONResponse(array("msg" => "Not specified name"), Http::STATUS_BAD_REQUEST);
             }
             if ($this->accessObjectMapper->isGroupInMode($name, $groupType)) {
                 return new JSONResponse(array("msg" => "Group {$name} already exists in this list"), Http::STATUS_BAD_REQUEST);
             } else {
                 $ao = AccessObject::fromParams(array('name' => $name, 'mode' => $groupType));
                 $this->accessObjectMapper->insert($ao);
                 $id = $ao->getId();
             }
             break;
         default:
             # code...
             break;
     }
     return new JSONResponse(array('id' => $id));
 }
コード例 #5
0
 /**
  * @brief imports a user, or owncloud instance
  * @param $path string path to zip
  * @param optional $type type of import (user or instance)
  * @param optional $uid userid of new user
  */
 public static function import($path, $type = 'user', $uid = null)
 {
     OC_Util::checkAdminUser();
     $datadir = OC_Config::getValue('datadirectory');
     // Extract the zip
     if (!($extractpath = self::extractZip($path))) {
         return json_encode(array('success' => false));
     }
     // Get export_info.json
     $scan = scandir($extractpath);
     // Check for export_info.json
     if (!in_array('export_info.json', $scan)) {
         OC_Log::write('migration', 'Invalid import file, export_info.json note found', OC_Log::ERROR);
         return json_encode(array('success' => false));
     }
     $json = json_decode(file_get_contents($extractpath . 'export_info.json'));
     if ($json->exporttype != $type) {
         OC_Log::write('migration', 'Invalid import file', OC_Log::ERROR);
         return json_encode(array('success' => false));
     }
     self::$exporttype = $type;
     // Have we got a user if type is user
     if (self::$exporttype == 'user') {
         if (!$uid) {
             self::$uid = $json->exporteduser;
         } else {
             self::$uid = $uid;
         }
     }
     // Handle export types
     switch (self::$exporttype) {
         case 'user':
             // Check user availability
             if (OC_User::userExists(self::$uid)) {
                 OC_Log::write('migration', 'User already exists', OC_Log::ERROR);
                 return json_encode(array('success' => false));
             }
             $run = true;
             OC_Hook::emit("OC_User", "pre_createUser", array("run" => &$run, "uid" => self::$uid, "password" => $json->hash));
             if (!$run) {
                 // Something stopped the user creation
                 OC_Log::write('migration', 'User creation failed', OC_Log::ERROR);
                 return json_encode(array('success' => false));
             }
             // Create the user
             if (!self::createUser(self::$uid, $json->hash)) {
                 return json_encode(array('success' => false));
             }
             // Emit the post_createUser hook (password is already hashed, will cause problems
             OC_Hook::emit("OC_User", "post_createUser", array("uid" => self::$uid, "password" => $json->hash));
             // Make the new users data dir
             $path = $datadir . '/' . self::$uid;
             if (!mkdir($path, 0755, true)) {
                 OC_Log::write('migration', 'Failed to create users data dir: ' . $path, OC_Log::ERROR);
                 return json_encode(array('success' => false));
             }
             // Copy data
             if (!self::copy_r($extractpath . $json->exporteduser, $datadir . '/' . self::$uid)) {
                 return json_encode(array('success' => false));
             }
             // Import user app data
             if (!($appsimported = self::importAppData($extractpath . $json->exporteduser . '/migration.db', $json, self::$uid))) {
                 return json_encode(array('success' => false));
             }
             // All done!
             if (!self::unlink_r($extractpath)) {
                 OC_Log::write('migration', 'Failed to delete the extracted zip', OC_Log::ERROR);
             }
             return json_encode(array('success' => true, 'data' => $appsimported));
             break;
         case 'instance':
             /*
              * EXPERIMENTAL
             // Check for new data dir and dbexport before doing anything
             // TODO
             
             // Delete current data folder.
             OC_Log::write( 'migration', "Deleting current data dir", OC_Log::INFO );
             if( !self::unlink_r( $datadir, false ) ){
             	OC_Log::write( 'migration', 'Failed to delete the current data dir', OC_Log::ERROR );
             	return json_encode( array( 'success' => false ) );
             }
             
             // Copy over data
             if( !self::copy_r( $extractpath . 'userdata', $datadir ) ){
             	OC_Log::write( 'migration', 'Failed to copy over data directory', OC_Log::ERROR );
             	return json_encode( array( 'success' => false ) );
             }
             
             // Import the db
             if( !OC_DB::replaceDB( $extractpath . 'dbexport.xml' ) ){
             	return json_encode( array( 'success' => false ) );
             }
             // Done
             return json_encode( 'success' => true );
             */
             break;
     }
 }
コード例 #6
0
 /**
  * @Ajax
  */
 public function conf()
 {
     \OC_Util::checkAdminUser();
     $params = $this->request->post;
     $helper = new ConfigHelper();
     return new JSONResponse($helper->getJSon($params['file']));
 }