Ejemplo n.º 1
0
 /**
  * 登陆回调页面
  */
 function callback()
 {
     $mod = $this->_get('mod', 'trim');
     !$mod && $this->_404();
     $callback_type = cookie('callback_type');
     $oauth = new oauth($mod);
     $rk = $oauth->NeedRequest();
     $request_args = array();
     foreach ($rk as $v) {
         $request_args[$v] = $this->_get($v);
     }
     switch ($callback_type) {
         case 'login':
             $url = $oauth->callbackLogin($request_args);
             break;
         case 'bind':
             $url = $oauth->callbackbind($request_args);
             break;
         default:
             $url = U('index/index');
             break;
     }
     cookie('callback_type', null);
     redirect($url);
 }
Ejemplo n.º 2
0
 /**
 * Prepare FTP connection
 * Connect to remote server and check if credentials are correct, if so, store the connection id in $ftp_conn
 *
 * @return bool
 * @author Dmitry (dio) Levashov
 * @author Cem (DiscoFever)
 **/
 protected function init()
 {
     $this->netmountPrepare($this->options);
     if (!$this->options['consumerKey'] || !$this->options['consumerSecret'] || !$this->options['accessToken'] || !$this->options['accessTokenSecret']) {
         return $this->setError('Required options undefined.');
     }
     // make net mount key
     $this->netMountKey = md5(join('-', array('dropbox', $this->options['path'])));
     if (!$this->oauth) {
         if (class_exists('OAuth')) {
             $this->oauth = new Dropbox_OAuth_PHP($this->options['consumerKey'], $this->options['consumerSecret']);
         } else {
             if (!class_exists('HTTP_OAuth_Consumer')) {
                 // We're going to try to load in manually
                 include 'HTTP/OAuth/Consumer.php';
             }
             if (class_exists('HTTP_OAuth_Consumer')) {
                 $this->oauth = new Dropbox_OAuth_PEAR($this->options['consumerKey'], $this->options['consumerSecret']);
             }
         }
     }
     if (!$this->oauth) {
         return $this->setError('OAuth extension not loaded.');
     }
     // normalize root path
     $this->root = $this->options['path'] = $this->_normpath($this->options['path']);
     if (empty($this->options['alias'])) {
         $this->options['alias'] = $this->options['path'] === '/' ? 'Dropbox.com' : 'Dropbox' . $this->options['path'];
     }
     $this->rootName = $this->options['alias'];
     $this->options['separator'] = '/';
     try {
         $this->oauth->setToken($this->options['accessToken'], $this->options['accessTokenSecret']);
         $this->dropbox = new Dropbox_API($this->oauth, $this->options['root']);
     } catch (Dropbox_Exception $e) {
         unset($_SESSION['elFinderDropboxTokens']);
         return $this->setError('Dropbox error: ' . $e->getMessage());
     }
     // user
     if (empty($this->options['dropboxUid'])) {
         try {
             $res = $this->dropbox->getAccountInfo();
             $this->options['dropboxUid'] = $res['uid'];
         } catch (Dropbox_Exception $e) {
             unset($_SESSION['elFinderDropboxTokens']);
             return $this->setError('Dropbox error: ' . $e->getMessage());
         }
     }
     $this->dropboxUid = $this->options['dropboxUid'];
     if (!empty($this->options['tmpPath'])) {
         if ((is_dir($this->options['tmpPath']) || @mkdir($this->options['tmpPath'])) && is_writable($this->options['tmpPath'])) {
             $this->tmp = $this->options['tmpPath'];
         }
     }
     if (!$this->tmp && is_writable($this->options['tmbPath'])) {
         $this->tmp = $this->options['tmbPath'];
     }
     if (!empty($this->options['metaCachePath'])) {
         if ((is_dir($this->options['metaCachePath']) || @mkdir($this->options['metaCachePath'])) && is_writable($this->options['metaCachePath'])) {
             $this->metaCache = $this->options['metaCachePath'];
         }
     }
     if (!$this->metaCache && $this->tmp) {
         $this->metaCache = $this->tmp;
     }
     if (!$this->tmp) {
         $this->disabled[] = 'archive';
         $this->disabled[] = 'extract';
     }
     if (!$this->metaCache) {
         return $this->setError('Cache dirctory (metaCachePath or tmp) is require.');
     }
     $this->metaCacheFile = $this->metaCache . DIRECTORY_SEPARATOR . '.elFinder_dropbox_metaCache_' . md5($this->dropboxUid . $this->options['consumerSecret']);
     $this->metaCacheGet(!empty($_REQUEST['init']));
     return true;
 }
Ejemplo n.º 3
0
 /**
  * OAuth callback.
  * 
  * @param  string    $provider
  * @param  string    $referer
  * @access public
  * @return void
  */
 public function oauthCallback($provider)
 {
     /* First check the state and provider fields. */
     if ($this->get->state != $this->session->oauthState) {
         die('state wrong!');
     }
     if ($provider != $this->session->oauthProvider) {
         die('provider wrong.');
     }
     $referer = $this->session->referer;
     /* Init the OAuth client. */
     $this->app->loadClass('oauth', $static = true);
     $this->config->oauth->{$provider} = json_decode($this->config->oauth->{$provider});
     $client = oauth::factory($provider, $this->config->oauth->{$provider}, $this->user->createOAuthCallbackURL($provider));
     /* Begin OAuth authing. */
     $token = $client->getToken($this->get->code);
     // Step1: get token by the code.
     $openID = $client->getOpenID($token);
     // Step2: get open id by the token.
     $openUser = $client->getUserInfo($token, $openID);
     // Get open user info.
     $this->session->set('openUser', $openUser);
     $this->session->set('openID', $openID);
     // Save the openID to session.
     /* Step3: Try to get user by the open id, if got, login him. */
     $user = $this->user->getUserByOpenID($provider, $openID);
     $this->session->set('random', md5(time() . mt_rand()));
     if ($user) {
         if ($this->user->login($user->account, md5($user->password . $this->session->random))) {
             if ($referer) {
                 $this->locate(helper::safe64Decode($referer));
             }
             /* No referer, go to the user control panel. */
             $default = $this->config->user->default;
             $this->locate($this->createLink($default->module, $default->method));
         }
         exit;
     }
     /* Step4.1: if bind, display the register or bind page. */
     if ($this->get->referer != false) {
         $this->setReferer($referer);
     }
     // Set the referer.
     $this->config->oauth->{$provider} = json_encode($this->config->oauth->{$provider});
     $this->view->title = $this->lang->user->login->common;
     $this->view->referer = $referer;
     $this->view->mobileURL = helper::createLink('user', 'oauthCallback', "provider={$provider}", '', 'mhtml');
     $this->view->desktopURL = helper::createLink('user', 'oauthCallback', "provider={$provider}", '', 'html');
     die($this->display());
 }
 /**
  * Prepare FTP connection
  * Connect to remote server and check if credentials are correct, if so, store the connection id in $ftp_conn
  *
  * @return bool
  * @author Dmitry (dio) Levashov
  * @author Cem (DiscoFever)
  **/
 protected function init()
 {
     if (!class_exists('PDO', false)) {
         return $this->setError('PHP PDO class is require.');
     }
     if (!$this->options['consumerKey'] || !$this->options['consumerSecret'] || !$this->options['accessToken'] || !$this->options['accessTokenSecret']) {
         return $this->setError('Required options undefined.');
     }
     if (empty($this->options['metaCachePath']) && defined('ELFINDER_DROPBOX_META_CACHE_PATH')) {
         $this->options['metaCachePath'] = ELFINDER_DROPBOX_META_CACHE_PATH;
     }
     // make net mount key
     $this->netMountKey = md5(join('-', array('dropbox', $this->options['path'])));
     if (!$this->oauth) {
         if (defined('ELFINDER_DROPBOX_USE_CURL_PUT')) {
             $this->oauth = new Dropbox_OAuth_Curl($this->options['consumerKey'], $this->options['consumerSecret']);
         } else {
             if (class_exists('OAuth', false)) {
                 $this->oauth = new Dropbox_OAuth_PHP($this->options['consumerKey'], $this->options['consumerSecret']);
             } else {
                 if (!class_exists('HTTP_OAuth_Consumer')) {
                     // We're going to try to load in manually
                     include 'HTTP/OAuth/Consumer.php';
                 }
                 if (class_exists('HTTP_OAuth_Consumer', false)) {
                     $this->oauth = new Dropbox_OAuth_PEAR($this->options['consumerKey'], $this->options['consumerSecret']);
                 }
             }
         }
     }
     if (!$this->oauth) {
         return $this->setError('OAuth extension not loaded.');
     }
     // normalize root path
     $this->root = $this->options['path'] = $this->_normpath($this->options['path']);
     if (empty($this->options['alias'])) {
         $this->options['alias'] = $this->options['path'] === '/' ? 'Dropbox.com' : 'Dropbox' . $this->options['path'];
     }
     $this->rootName = $this->options['alias'];
     try {
         $this->oauth->setToken($this->options['accessToken'], $this->options['accessTokenSecret']);
         $this->dropbox = new Dropbox_API($this->oauth, $this->options['root']);
     } catch (Dropbox_Exception $e) {
         $this->session->remove('DropboxTokens');
         return $this->setError('Dropbox error: ' . $e->getMessage());
     }
     // user
     if (empty($this->options['dropboxUid'])) {
         try {
             $res = $this->dropbox->getAccountInfo();
             $this->options['dropboxUid'] = $res['uid'];
         } catch (Dropbox_Exception $e) {
             $this->session->remove('DropboxTokens');
             return $this->setError('Dropbox error: ' . $e->getMessage());
         }
     }
     $this->dropboxUid = $this->options['dropboxUid'];
     $this->tmbPrefix = 'dropbox' . base_convert($this->dropboxUid, 10, 32);
     if (!empty($this->options['tmpPath'])) {
         if ((is_dir($this->options['tmpPath']) || mkdir($this->options['tmpPath'])) && is_writable($this->options['tmpPath'])) {
             $this->tmp = $this->options['tmpPath'];
         }
     }
     if (!$this->tmp && is_writable($this->options['tmbPath'])) {
         $this->tmp = $this->options['tmbPath'];
     }
     if (!$this->tmp && ($tmp = elFinder::getStaticVar('commonTempPath'))) {
         $this->tmp = $tmp;
     }
     if (!empty($this->options['metaCachePath'])) {
         if ((is_dir($this->options['metaCachePath']) || mkdir($this->options['metaCachePath'])) && is_writable($this->options['metaCachePath'])) {
             $this->metaCache = $this->options['metaCachePath'];
         }
     }
     if (!$this->metaCache && $this->tmp) {
         $this->metaCache = $this->tmp;
     }
     if (!$this->metaCache) {
         return $this->setError('Cache dirctory (metaCachePath or tmp) is require.');
     }
     // setup PDO
     if (!$this->options['PDO_DSN']) {
         $this->options['PDO_DSN'] = 'sqlite:' . $this->metaCache . DIRECTORY_SEPARATOR . '.elFinder_dropbox_db_' . md5($this->dropboxUid . $this->options['consumerSecret']);
     }
     // DataBase table name
     $this->DB_TableName = $this->options['PDO_DBName'];
     // DataBase check or make table
     try {
         $this->DB = new PDO($this->options['PDO_DSN'], $this->options['PDO_User'], $this->options['PDO_Pass'], $this->options['PDO_Options']);
         if (!$this->checkDB()) {
             return $this->setError('Can not make DB table');
         }
     } catch (PDOException $e) {
         return $this->setError('PDO connection failed: ' . $e->getMessage());
     }
     $res = $this->deltaCheck($this->isMyReload());
     if ($res !== true) {
         if (is_string($res)) {
             return $this->setError($res);
         } else {
             return $this->setError('Could not check API "delta"');
         }
     }
     if (is_null($this->options['syncChkAsTs'])) {
         $this->options['syncChkAsTs'] = true;
     }
     if ($this->options['syncChkAsTs']) {
         // 'tsPlSleep' minmum 5 sec
         $this->options['tsPlSleep'] = max(5, $this->options['tsPlSleep']);
     } else {
         // 'lsPlSleep' minmum 10 sec
         $this->options['lsPlSleep'] = max(10, $this->options['lsPlSleep']);
     }
     return true;
 }
Ejemplo n.º 5
0
 /**
  * OAuth callback.
  * 
  * @param  string    $provider
  * @param  string    $referer
  * @access public
  * @return void
  */
 public function oauthCallback($provider, $referer = '')
 {
     /* First check the state and provider fields. */
     if ($this->get->state != $this->session->oauthState) {
         die('state wrong!');
     }
     if ($provider != $this->session->oauthProvider) {
         die('provider wrong.');
     }
     /* Init the OAuth client. */
     $this->app->loadClass('oauth', $static = true);
     $this->config->oauth->{$provider} = json_decode($this->config->oauth->{$provider});
     $client = oauth::factory($provider, $this->config->oauth->{$provider}, $this->user->createOAuthCallbackURL($provider, $referer));
     /* Begin OAuth authing. */
     $token = $client->getToken($this->get->code);
     // Step1: get token by the code.
     $openID = $client->getOpenID($token);
     // Step2: get open id by the token.
     /* Step3: Try to get user by the open id, if got, login him. */
     $user = $this->user->getUserByOpenID($provider, $openID);
     $this->session->set('random', md5(time() . mt_rand()));
     if ($user) {
         if ($this->user->login($user->account, md5($user->password . $this->session->random))) {
             if ($referer) {
                 $this->locate(helper::safe64Decode($referer));
             }
             /* No referer, go to the user control panel. */
             $default = $this->config->user->default;
             $this->locate($this->createLink($default->module, $default->method));
         }
         exit;
     }
     /* Step4.1: if the provider is sina, display the register or bind page. */
     if ($provider == 'sina') {
         $this->session->set('oauthOpenID', $openID);
         // Save the openID to session.
         if ($this->get->referer != false) {
             $this->setReferer($referer);
         }
         // Set the referer.
         $this->view->title = $this->lang->user->login->common;
         $this->view->referer = $referer;
         die($this->display());
     }
     /* Step4.2: if the provider is qq, register a user with random user. Shit! */
     if ($provider == 'qq') {
         $openUser = $client->getUserInfo($token, $openID);
         // Get open user info.
         $this->post->set('account', uniqid('qq_'));
         // Create a uniq account.
         $this->post->set('realname', htmlspecialchars($openUser->nickname));
         // Set the realname.
         $this->user->registerOauthAccount($provider, $openID);
         $user = $this->user->getUserByOpenID($provider, $openID);
         $this->session->set('random', md5(time() . mt_rand()));
         if ($user and $this->user->login($user->account, md5($user->password . $this->session->random))) {
             if ($referer) {
                 $this->locate(helper::safe64Decode($referer));
             }
             /* No referer, go to the user control panel. */
             $default = $this->config->user->default;
             $this->locate($this->createLink($default->module, $default->method));
         } else {
             die('some error occers.');
         }
     }
 }
Ejemplo n.º 6
0
 /**
  * 用户注册
  */
 public function register()
 {
     $this->visitor->is_login && $this->redirect('user/index');
     if (IS_POST) {
         //方式
         $type = $this->_post('type', 'trim', 'reg');
         if ($type == 'reg') {
             //验证
             $agreement = $this->_post('agreement');
             !$agreement && $this->error(L('agreement_failed'));
             $captcha = $this->_post('captcha', 'trim');
             if (session('captcha') != md5($captcha)) {
                 $this->error(L('captcha_failed'));
             }
         }
         $username = $this->_post('username', 'trim');
         $email = $this->_post('email', 'trim');
         $password = $this->_post('password', 'trim');
         $repassword = $this->_post('repassword', 'trim');
         if ($password != $repassword) {
             $this->error(L('inconsistent_password'));
             //确认密码
         }
         $gender = $this->_post('gender', 'intval', '0');
         //用户禁止
         $ipban_mod = D('ipban');
         $ipban_mod->clear();
         //清除过期数据
         $is_ban = $ipban_mod->where("(type='name' AND name='" . $username . "') OR (type='email' AND name='" . $email . "')")->count();
         $is_ban && $this->error(L('register_ban'));
         //连接用户中心
         $passport = $this->_user_server();
         //注册
         $uid = $passport->register($username, $password, $email, $gender);
         !$uid && $this->error($passport->get_error());
         //第三方帐号绑定
         if (cookie('user_bind_info')) {
             $user_bind_info = object_to_array(cookie('user_bind_info'));
             $oauth = new oauth($user_bind_info['type']);
             $bind_info = array('ftx_uid' => $uid, 'ftx_username' => $username, 'keyid' => $user_bind_info['keyid'], 'bind_info' => $user_bind_info['bind_info']);
             $oauth->bindByData($bind_info);
             $this->_save_avatar($uid, $user_bind_info['temp_avatar']);
             cookie('user_bind_info', NULL);
         }
         $tag_arg = array('uid' => $uid, 'uname' => $username, 'action' => 'register');
         tag('register_end', $tag_arg);
         //邀请注册奖励
         $union_date = array('uid' => $uid, 'username' => $username);
         D('user')->union_reg($union_date);
         //登陆
         $this->visitor->login($uid);
         //登陆完成
         $tag_arg = array('uid' => $uid, 'uname' => $username, 'action' => 'login');
         tag('login_end', $tag_arg);
         //同步登陆
         $synlogin = $passport->synlogin($uid);
         $this->success(L('register_successe') . $synlogin, U('user/index'));
     } else {
         //关闭注册
         if (!C('ftx_reg_status')) {
             $this->error(C('ftx_reg_closed_reason'));
         }
         $this->_config_seo(array('title' => ' 注册	-	' . C('ftx_site_name')));
         $this->display();
     }
 }
 /**
  * Prepare FTP connection
  * Connect to remote server and check if credentials are correct, if so, store the connection id in $ftp_conn
  *
  * @return bool
  * @author Dmitry (dio) Levashov
  * @author Cem (DiscoFever)
  **/
 protected function init()
 {
     if (!$this->options['consumerKey'] || !$this->options['consumerSecret'] || !$this->options['accessToken'] || !$this->options['accessTokenSecret']) {
         return $this->setError('Required options undefined.');
     }
     if (empty($this->options['metaCachePath']) && defined('ELFINDER_DROPBOX_META_CACHE_PATH')) {
         $this->options['metaCachePath'] = ELFINDER_DROPBOX_META_CACHE_PATH;
     }
     // make net mount key
     $this->netMountKey = md5(join('-', array('dropbox', $this->options['path'])));
     if (!$this->oauth) {
         if (class_exists('OAuth')) {
             $this->oauth = new Dropbox_OAuth_PHP($this->options['consumerKey'], $this->options['consumerSecret']);
         } else {
             if (!class_exists('HTTP_OAuth_Consumer')) {
                 // We're going to try to load in manually
                 include 'HTTP/OAuth/Consumer.php';
             }
             if (class_exists('HTTP_OAuth_Consumer')) {
                 $this->oauth = new Dropbox_OAuth_PEAR($this->options['consumerKey'], $this->options['consumerSecret']);
             }
         }
     }
     if (!$this->oauth) {
         return $this->setError('OAuth extension not loaded.');
     }
     // normalize root path
     $this->root = $this->options['path'] = $this->_normpath($this->options['path']);
     if (empty($this->options['alias'])) {
         $this->options['alias'] = $this->options['path'] === '/' ? 'Dropbox.com' : 'Dropbox' . $this->options['path'];
     }
     $this->rootName = $this->options['alias'];
     $this->options['separator'] = '/';
     try {
         $this->oauth->setToken($this->options['accessToken'], $this->options['accessTokenSecret']);
         $this->dropbox = new Dropbox_API($this->oauth, $this->options['root']);
     } catch (Dropbox_Exception $e) {
         unset($_SESSION['elFinderDropboxTokens']);
         return $this->setError('Dropbox error: ' . $e->getMessage());
     }
     // user
     if (empty($this->options['dropboxUid'])) {
         try {
             $res = $this->dropbox->getAccountInfo();
             $this->options['dropboxUid'] = $res['uid'];
         } catch (Dropbox_Exception $e) {
             unset($_SESSION['elFinderDropboxTokens']);
             return $this->setError('Dropbox error: ' . $e->getMessage());
         }
     }
     $this->dropboxUid = $this->options['dropboxUid'];
     $this->tmbPrefix = 'dropbox' . base_convert($this->dropboxUid, 10, 32);
     if (!empty($this->options['tmpPath'])) {
         if ((is_dir($this->options['tmpPath']) || @mkdir($this->options['tmpPath'])) && is_writable($this->options['tmpPath'])) {
             $this->tmp = $this->options['tmpPath'];
         }
     }
     if (!$this->tmp && is_writable($this->options['tmbPath'])) {
         $this->tmp = $this->options['tmbPath'];
     }
     if (!empty($this->options['metaCachePath'])) {
         if ((is_dir($this->options['metaCachePath']) || @mkdir($this->options['metaCachePath'])) && is_writable($this->options['metaCachePath'])) {
             $this->metaCache = $this->options['metaCachePath'];
         }
     }
     if (!$this->metaCache && $this->tmp) {
         $this->metaCache = $this->tmp;
     }
     if (!$this->tmp) {
         $this->disabled[] = 'archive';
         $this->disabled[] = 'extract';
     }
     if (!$this->metaCache) {
         return $this->setError('Cache dirctory (metaCachePath or tmp) is require.');
     }
     // setup PDO
     if (!$this->options['PDO_DSN']) {
         $this->options['PDO_DSN'] = 'sqlite:' . $this->metaCache . DIRECTORY_SEPARATOR . '.elFinder_dropbox_db_' . md5($this->dropboxUid . $this->options['consumerSecret']);
     }
     // DataBase table name
     $this->DB_TableName = $this->options['PDO_DBName'];
     // DataBase check or make table
     if ($this->DB = new PDO($this->options['PDO_DSN'], $this->options['PDO_User'], $this->options['PDO_Pass'], $this->options['PDO_Options'])) {
         if (!$this->checkDB()) {
             return $this->setError('Can not make DB table');
         }
     } else {
         return $this->setError('Could not use PDO');
     }
     $res = $this->deltaCheck(!empty($_REQUEST['init']));
     if ($res !== true) {
         if (is_string($res)) {
             return $this->setError($res);
         } else {
             return $this->setError('Could not check API "delta"');
         }
     }
     return true;
 }