示例#1
0
 public function authorize()
 {
     global $_G, $_GET, $clouds;
     if (empty($_G['uid'])) {
         dsetcookie('_refer', rawurlencode(BASESCRIPT . '?mod=connect&op=oauth&bz=ftp'));
         showmessage('to_login', '', array(), array('showmsg' => true, 'login' => 1));
     }
     if (submitcheck('ftpsubmit')) {
         $config = $_GET['config'];
         $config['password'] = authcode($config['password'], 'ENCODE', md5(getglobal('config/security/authkey')));
         $config['bz'] = 'ftp';
         $uid = defined('IN_ADMIN') ? 0 : $_G['uid'];
         $config['on'] = 1;
         $ftp = new dzz_ftp($config);
         if ($ftp->error()) {
             showmessage('FTP 参数设置错误,请检查', dreferer());
         }
         if ($ftp->connect()) {
             $config['uid'] = $uid;
             if ($id = DB::result_first("select id from %t where uid=%d and host=%s and port=%d and username=%s", array(self::T, $uid, $config['host'], $config['port'], $config['username']))) {
                 DB::update(self::T, $config, "id ='{$id}'");
             } else {
                 $config['dateline'] = TIMESTAMP;
                 $id = DB::insert(self::T, $config, 1);
             }
             if (defined('IN_ADMIN')) {
                 $setarr = array('name' => $config['cloudname'], 'bz' => 'ftp', 'isdefault' => 0, 'dname' => self::T, 'did' => $id, 'dateline' => TIMESTAMP);
                 if (!DB::result_first("select COUNT(*) from %t where did=%d and dname=%s ", array('local_storage', $id, self::T))) {
                     C::t('local_storage')->insert($setarr);
                 }
                 showmessage('do_success', BASESCRIPT . '?mod=cloud&op=space');
             } else {
                 showmessage('do_success', BASESCRIPT . '?mod=connect');
             }
         } else {
             showmessage('尝试连接ftp未成功,请检查参数后重试', dreferer());
         }
     } else {
         include template('oauth_ftp');
     }
 }