public function testCreate() { $model = new SBAdmin(); $model->name = 'Local'; $model->auth = SBAdmin::AUTH_IP; $model->identity = '127.0.0.1'; $model->setPassword('localhost'); $this->assertTrue($model->save()); }
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')); }
$file = fopen($paths['config'] . '/sourcebans.php', 'w'); fwrite($file, $config); fclose($file); // Setup database require WEB_ROOT . 'api.php'; $queries = file_get_contents(dirname(__FILE__) . '/data/install.sql'); $queries = str_replace('{prefix}', $db['prefix'], $queries); foreach (explode(';', $queries) as $query) { if (($query = trim($query)) != '') { Yii::app()->db->createCommand($query)->execute(); } } // Setup web group $group = new SBGroup(); $group->name = 'Owner'; $group->permissions = array('OWNER'); if (!$group->save()) { throw new CException('Failed to save group "' . $group->name . '"'); } // Setup admin $admin = new SBAdmin(); $admin->attributes = $_POST['SBAdmin']; $admin->group_id = $group->id; $admin->new_password = $admin->password; if (!$admin->save()) { throw new CException('Failed to save admin "' . $admin->name . '"'); } } catch (Exception $e) { exit(json_encode(array('error' => $e->getMessage()))); } exit(json_encode(true));