public function checkActionAccess($model)
 {
     if (!Yii::app()->user->isSuperuser() && ($model->hidden || !Yii::app()->user->can($model->server_id, 'manage commands', true))) {
         Yii::app()->user->deny();
     }
     $cfg = ServerConfig::model()->findByPk($model->server_id);
     if (!Yii::app()->user->isSuperuser() && (!$cfg || !$cfg->user_schedule)) {
         Yii::app()->user->deny();
     }
 }
 public function actionIndex($id)
 {
     $sv = Server::model()->findByPk((int) $id);
     if (!$sv) {
         throw new Exception('Server not found');
     }
     $cfg = ServerConfig::model()->findByPk((int) $id);
     $pl = $sv->getOnlinePlayers();
     $st = $pl >= 0 ? 'online' : 'offline';
     $image = $this->getImg(Theme::themeFilePath('images/status/' . $this->banner));
     $statusIcon = $this->getImg(Theme::themeFilePath('images/status/' . $this->statusIcons[$st == 'online' ? 0 : 1]));
     $font = Theme::themeFilePath('images/status/' . $this->font);
     $color = imagecolorallocate($image, $this->color[0], $this->color[1], $this->color[2]);
     //Status icon
     imagecopy($image, $statusIcon, $this->textX, $this->iconY, 0, 0, imagesx($statusIcon), imagesy($statusIcon));
     imagedestroy($statusIcon);
     //Server name
     imagettftext($image, $this->titleSize, 0, $this->textX, $this->titleY, $color, $font, $sv->name);
     //Server IP
     $ipStr = trim($cfg && $cfg->display_ip ? $cfg->display_ip : $sv->ip);
     if (!strlen($ipStr) || $ipStr == '0.0.0.0') {
         if ($dmn = Daemon::model()->findByPk($sv->daemon_id)) {
             $ipStr = $dmn->ip;
         }
     }
     $ipStr = 'IP: ' . $ipStr . ':' . $sv->port;
     $sz = imagettfbbox($this->ipSize, 0, $font, $ipStr);
     imagettftext($image, $this->ipSize, 0, imagesx($image) - ($sz[2] - $sz[0]) - $this->ipOffset, $this->statusY, $color, $font, $ipStr);
     //Server status
     if ($st == 'online') {
         imagettftext($image, $this->statusSize, 0, $this->textX + $this->statusOffset, $this->statusY, $color, $font, $pl . ' / ' . $sv->players . ' ' . Yii::t('mc', 'Players'));
     } else {
         imagettftext($image, $this->statusSize, 0, $this->textX + $this->statusOffset, $this->statusY, $color, $font, Yii::t('mc', 'Offline'));
     }
     imagecolordeallocate($image, $color);
     header('Content-type: image/png');
     imagepng($image);
     imagedestroy($image);
 }
 public function actionMysqlDb($id, $cmd = '')
 {
     Yii::app()->user->can($id, 'edit configs', true);
     $model = $this->loadModel($id);
     $settings = ServerConfig::model()->findByPk((int) $id);
     if (!strlen($model->mysqlHost) || !(Yii::app()->params['user_mysql'] && $settings->user_mysql || Yii::app()->user->isSuperuser())) {
         Yii::app()->user->deny();
     }
     if ($cmd == 'create') {
         if (!$model->createDatabase()) {
             Yii::app()->user->setFlash('server_error', Yii::t('mc', 'Failed to create MySQL database "{db}"!', array('{db}' => CHtml::encode($model->mysqlPrefix . $model->id))));
         }
         $this->redirect(array('mysqlDb', 'id' => $id));
     } else {
         if ($cmd == 'passwd') {
             if (!$model->changeDatabasePw()) {
                 Yii::app()->user->setFlash('server_error', Yii::t('mc', 'Failed to change MySQL password for "{db}"!', array('{db}' => CHtml::encode($model->mysqlPrefix . $model->id))));
             }
             $this->redirect(array('mysqlDb', 'id' => $id));
         } else {
             if ($cmd == 'delete') {
                 if (!$model->deleteDatabase()) {
                     Yii::app()->user->setFlash('server_error', Yii::t('mc', 'Failed to delete MySQL database "{db}"!', array('{db}' => CHtml::encode($model->mysqlPrefix . $model->id))));
                 }
                 $this->redirect(array('mysqlDb', 'id' => $id));
             }
         }
     }
     $this->render('mysqlDb', array('model' => $model, 'info' => $model->dbInfo));
 }
 /**
  * Check if the current user has the permissions for $action. If $self is
  * true this means that the action is to be performed on the player
  * corresponding to the current user (checks 'self $action')
  */
 private function _can($role, $action, $server, $self)
 {
     if ($self) {
         $sc = ServerConfig::model()->findByPk((int) $server);
         if ($sc && isset($sc->{$action . '_role'})) {
             $svIdx = array_search($sc->{$action . '_role'}, User::$roles);
             $plIdx = array_search($role, User::$roles);
             return $plIdx >= $svIdx;
         }
         $action = 'self ' . $action;
     }
     $res = false;
     switch ($role) {
         case 'owner':
         case 'admin':
             $res |= in_array($action, array('control', 'stop', 'restart', 'manage players', 'edit', 'manage commands', 'start backup', 'command', 'edit configs', 'clear chat', 'clear log'));
         case 'mod':
             $res |= in_array($action, array('start', 'asay', 'get log', 'player details', 'summon', 'give', 'tp', 'kick', 'get backup'));
         case 'user':
             $res |= in_array($action, array('self give', 'self tp', 'get chat', 'chat', 'view player', 'view command'));
         case 'guest':
             $res |= in_array($action, array('get status', 'get players', 'view', 'self view player'));
         default:
     }
     return $res;
 }
Beispiel #5
0
 public function getIpAuthRole()
 {
     $sc = ServerConfig::model()->findByPk($this->id);
     return $sc->ip_auth_role;
 }