Esempio n. 1
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'));
 }
Esempio n. 2
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'));
 }