Example #1
0
 /**
  * Deletes a particular model.
  * If deletion is successful, the browser will be redirected to the 'admin' page.
  * @param integer $id the ID of the model to be deleted
  */
 public function actionDelete($id)
 {
     $model = $this->loadModel($id);
     SourceBans::log('Game deleted', 'Game "' . $model . '" was deleted', SBLog::TYPE_WARNING);
     $model->delete();
     // if AJAX request (triggered by deletion via admin grid view), we should not redirect the browser
     if (!isset($_GET['ajax'])) {
         $this->redirect(isset($_POST['returnUrl']) ? $_POST['returnUrl'] : array('admin'));
     }
 }
Example #2
0
 public function actionUninstall($id)
 {
     $plugin = $this->loadModel($id);
     try {
         $plugin->runUninstall();
         $plugin->status = 0;
         $plugin->save();
         SourceBans::log('Plugin uninstalled', 'Plugin "' . $plugin . '" was uninstalled', SBLog::TYPE_WARNING);
     } catch (Exception $e) {
         Yii::app()->end(CJSON::encode(array('error' => array('code' => $e->getCode(), 'message' => $e->getMessage()))));
     }
     Yii::app()->end(CJSON::encode(true));
 }
Example #3
0
 public function actionImport()
 {
     $file = $_FILES['file'];
     switch ($file['name']) {
         // SourceMod
         case 'admins.cfg':
         case 'admins_simple.ini':
             $server_groups = CHtml::listData(SBServerGroup::model()->findAll(), 'name', 'id');
             // Detailed
             if ($file['name'] == 'admins.cfg') {
                 $kv = new KeyValues('Admins');
                 $kv->load($file['tmp_name']);
                 foreach ($kv as $name => $data) {
                     $admin = new SBAdmin();
                     $admin->name = $name;
                     $admin->auth = $data['auth'];
                     $admin->identity = $data['identity'];
                     if (isset($data['password'])) {
                         $admin->new_password = $data['password'];
                         $admin->server_password = $data['password'];
                     }
                     if (isset($data['group'])) {
                         $admin->server_groups = array();
                         foreach ((array) $data['group'] as $group) {
                             $admin->server_groups = array_merge($admin->server_groups, array($server_groups[$group]));
                         }
                     }
                     $admin->save();
                 }
             } else {
                 preg_match_all('/"(.+?)"[ \\t]*"(.+?)"([ \\t]*"(.+?)")?/', file_get_contents($file['tmp_name']), $admins);
                 for ($i = 0; $i < count($admins[0]); $i++) {
                     list($identity, $flags, $password) = array($admins[1][$i], $admins[2][$i], $admins[4][$i]);
                     // Parse authentication type depending on identity
                     if (preg_match(SourceBans::PATTERN_STEAM, $identity)) {
                         $auth = SBAdmin::AUTH_STEAM;
                     } else {
                         if ($identity[0] == '!' && preg_match(SourceBans::PATTERN_IP, $identity)) {
                             $auth = SBAdmin::AUTH_IP;
                         } else {
                             $auth = SBAdmin::AUTH_NAME;
                         }
                     }
                     // Parse flags
                     if ($flags[0] == '@') {
                         $group = substr($flags, 1);
                     } else {
                         if (strpos($flags, ':') !== false) {
                             list($immunity, $flags) = explode(':', $flags);
                         }
                     }
                     $admin = new SBAdmin();
                     $admin->name = $identity;
                     $admin->auth = $auth;
                     $admin->identity = $identity;
                     if (!empty($password)) {
                         $admin->new_password = $password;
                         $admin->server_password = $password;
                     }
                     if (isset($group)) {
                         $admin->server_groups = array($server_groups[$group]);
                     }
                     $admin->save();
                 }
             }
             break;
             // Mani Admin Plugin
         // Mani Admin Plugin
         case 'clients.txt':
             $kv = new KeyValues();
             $kv->load($file['tmp_name']);
             foreach ($kv['players'] as $name => $player) {
                 $admin = new SBAdmin();
                 $admin->auth = SBAdmin::AUTH_STEAM;
                 $admin->name = $name;
                 $admin->identity = $player['steam'];
                 $admin->save();
             }
             break;
         default:
             throw new CHttpException(500, Yii::t('sourcebans', 'controllers.admins.import.error'));
     }
     SourceBans::log('Admins imported', 'Admins imported from ' . $file['name']);
     Yii::app()->user->setFlash('success', Yii::t('sourcebans', 'Imported successfully'));
     $this->redirect(array('admin/admins'));
 }
Example #4
0
 public function actionImport()
 {
     $file = $_FILES['file'];
     switch ($file['name']) {
         // Source Dedicated Server
         case 'banned_ip.cfg':
         case 'banned_user.cfg':
             foreach (file($file['tmp_name']) as $line) {
                 list(, $length, $identity) = explode(' ', rtrim($line));
                 // If this is not a permanent ban, ignore
                 if ($length) {
                     continue;
                 }
                 // Steam ID
                 if (preg_match(SourceBans::PATTERN_STEAM, $identity)) {
                     $ban = new SBBan();
                     $ban->type = SBBan::TYPE_STEAM;
                     $ban->steam = $identity;
                     $ban->reason = 'Imported from banned_user.cfg';
                     $ban->length = 0;
                     $ban->save();
                 } else {
                     if (preg_match(SourceBans::PATTERN_IP, $identity)) {
                         $ban = new SBBan();
                         $ban->type = SBBan::TYPE_IP;
                         $ban->ip = $identity;
                         $ban->reason = 'Imported from banned_ip.cfg';
                         $ban->length = 0;
                         $ban->save();
                     }
                 }
             }
             break;
             // ESEA Ban List
         // ESEA Ban List
         case 'esea_ban_list.csv':
             $handle = fopen($file['tmp_name'], 'r');
             while (list($steam, $name) = fgetcsv($handle, 4096)) {
                 $steam = 'STEAM_' . trim($steam);
                 if (!preg_match(SourceBans::PATTERN_STEAM, $steam)) {
                     continue;
                 }
                 $ban = new SBBan();
                 $ban->type = SBBan::TYPE_STEAM;
                 $ban->steam = $steam;
                 $ban->name = $name;
                 $ban->reason = 'Imported from esea_ban_list.csv';
                 $ban->length = 0;
                 $ban->save();
             }
             fclose($handle);
             break;
         default:
             throw new CHttpException(500, Yii::t('sourcebans', 'controllers.bans.import.error'));
     }
     SourceBans::log('Bans imported', 'Bans imported from ' . $file['name']);
     Yii::app()->user->setFlash('success', Yii::t('sourcebans', 'Imported successfully'));
     $this->redirect(array('default/bans'));
 }
Example #5
0
 /**
  * Displays the appeal ban page
  */
 public function actionAppeal()
 {
     $this->pageTitle = Yii::t('sourcebans', 'controllers.default.appeal.title');
     $this->breadcrumbs = array(Yii::t('sourcebans', 'controllers.default.appeal.title'));
     $model = new SBAppeal();
     $model->ban_steam = 'STEAM_';
     $model->ban_ip = Yii::app()->request->userHostAddress;
     // if it is ajax validation request
     if (isset($_POST['ajax']) && $_POST['ajax'] === 'appeal-form') {
         echo CActiveForm::validate($model);
         Yii::app()->end();
     }
     if (isset($_POST['SBAppeal'])) {
         $model->attributes = $_POST['SBAppeal'];
         if ($model->save()) {
             SourceBans::log('Appeal added', 'Ban against "' . $model->user_email . '" was appealed');
             Yii::app()->user->setFlash('success', Yii::t('sourcebans', 'Saved successfully'));
             $this->refresh();
         }
     }
     $this->render('appeal', array('model' => $model));
 }
Example #6
0
 public function actionImport()
 {
     $file = $_FILES['file'];
     $kv = new KeyValues('Groups');
     $kv->load($file['tmp_name']);
     foreach ($kv as $name => $data) {
         $server_group = new SBServerGroup();
         $server_group->name = $name;
         $server_group->flags = isset($data['flags']) ? $data['flags'] : '';
         $server_group->immunity = isset($data['immunity']) ? $data['immunity'] : 0;
         $server_group->save();
         if (isset($data['Overrides'])) {
             foreach ($data['Overrides'] as $name => $access) {
                 // Parse name
                 if ($name[0] == ':') {
                     $type = 'group';
                     $name = substr($name, 1);
                 } else {
                     $type = 'command';
                 }
                 $override = new SBServerGroupOverride();
                 $override->group_id = $server_group->id;
                 $override->type = $type;
                 $override->name = $name;
                 $override->access = $access;
                 $override->save();
             }
         }
     }
     SourceBans::log('Groups imported', 'Groups imported from ' . $file['name']);
     Yii::app()->user->setFlash('success', Yii::t('sourcebans', 'Imported successfully'));
     $this->redirect(array('admin/groups'));
 }