public function actionLogin($id = 0)
 {
     if (isset($_POST['password'])) {
         $pw = $_POST['password'];
         $id = (int) $_POST['server_id'];
         $server = Server::model()->findByPk((int) $id);
         if (!$server) {
             throw new CHttpException(404, Yii::t('mc', 'The requested page does not exist.'));
         }
         $this->net2FtpDefines();
         global $net2ftp_result, $net2ftp_settings, $net2ftp_globals;
         require_once dirname(__FILE__) . '/../extensions/net2ftp/main.inc.php';
         require_once dirname(__FILE__) . '/../extensions/net2ftp/includes/authorizations.inc.php';
         $ftpSv = $this->getFtpServer($server);
         if (strlen($pw)) {
             $_SESSION['net2ftp_password_encrypted'] = encryptPassword($pw);
             $sessKey = 'net2ftp_password_encrypted_' . $ftpSv['ip'] . $this->getUsername($server);
             unset($_SESSION[$sessKey]);
         }
         Yii::log('Logging in to FTP server for server ' . $id);
         $this->redirect(array('ftpClient/browse', 'id' => $id));
     }
     $ftpUser = FtpUser::model()->findByAttributes(array('name' => Yii::app()->user->name));
     $daemons = array();
     $serverList = array();
     $sel = Yii::t('mc', 'Please select a server');
     if ($ftpUser) {
         $c = new CDbCriteria();
         $c->join = 'join `ftp_user_server` on `t`.`id`=`server_id`';
         $c->condition = '`user_id`=? and `perms`!=\'\'';
         $c->params = array((int) $ftpUser->id);
         $svs = Server::model()->findAll($c);
         $serverList = array(0 => Yii::t('mc', 'Select'));
         foreach ($svs as $sv) {
             $dmn = Daemon::model()->findByPk($sv->daemon_id);
             $dmnInfo = array('ip' => '', 'port' => '');
             if (!$dmn) {
                 $dmnInfo['ip'] = Yii::t('mc', 'No daemon found for this server.');
             } else {
                 if (isset($dmn->ftp_ip) && isset($dmn->ftp_port)) {
                     $dmnInfo = array('ip' => $dmn->ftp_ip, 'port' => $dmn->ftp_port);
                 } else {
                     $dmnInfo['ip'] = Yii::t('mc', 'Daemon database not up to date, please run the Multicraft installer.');
                 }
             }
             $daemons[$sv->id] = $dmnInfo;
             $serverList[$sv->id] = $sv->name;
         }
     } else {
         $serverList = array(0 => Yii::t('mc', 'No FTP account found'));
         $sel = Yii::t('mc', 'See the "Users" menu of your server for a list of FTP accounts');
     }
     $this->render('login', array('id' => $id, 'havePw' => isset($_SESSION['net2ftp_password_encrypted']), 'serverList' => $serverList, 'daemons' => $daemons, 'sel' => $sel));
 }
示例#2
0
 public function afterDelete()
 {
     UserServer::model()->deleteAllByAttributes(array('user_id' => $this->id));
     $ftpUser = FtpUser::model()->findByAttributes(array('name' => $this->name));
     if ($ftpUser) {
         FtpUserServer::model()->deleteAllByAttributes(array('user_id' => $ftpUser->id));
         $ftpUser->delete();
     }
     return parent::afterDelete();
 }