Yii framework config/main.php doesnt contain gii to work with

536 views Asked by At

I have been using vagrant with yii framework, I have already created a virtual server and I have put my YII framework there. it is connected to my database and its works fine, however when I go to index.php?r=gii i get the following

error:Error 403
You are not allowed to access this page.

well I looked online and also from this website I found few solutions, such as going to config/main.php and from there change the allowedIPs however, when I go to my main.php this is what I see:

<?php

/**
 * This is the main Web application configuration.
 *
 * Any writable CWebApplication properties can be configured here.
 * It is constructed the following way:
 *    main.php = return the main settings
 *                  unless overwritten by the local main settings if available
 *                  unless overwritten by the test settings if available
 *                  unless overwritten by the local test settings if available
 * (mergeArray: latter will overwrite the former, see http://www.yiiframework.com/doc/api/1.1/CMap#mergeArray-detail)
 *
 * @author Yii, adapted by Robbert <[email protected]>
 * @since release 1.0 (sprint 1)
 */
// Set up path variables to reflect the directory structure
// $WEBHOME/                     -- doePath
// $WEBHOME/public/              -- webrootPath
// $WEBHOME/private/protected/   -- protectedPath
// $WEBHOME/private/runtime/     -- runtimePath

$pathToDoeDirectory  = realpath(dirname(__FILE__) . '/../../..');
$privatePath         = $pathToDoeDirectory . '/private/';
$protectedPath       = $pathToDoeDirectory . '/private/protected/';
$runtimePath         = $pathToDoeDirectory . '/private/runtime/';
$publicPath          = $pathToDoeDirectory . '/public/';
$webrootPath         = $publicPath;

/**
 * Namespace MTE
 */
Yii::setPathOfAlias('MTE', $protectedPath);

// used by the themeUrl of widgetFactory settings, in case the DOE is in a subdirectory
$baseUrl = (isset($_SERVER['DOCUMENT_ROOT'])) ? str_replace($_SERVER['DOCUMENT_ROOT'], '', realpath('.')) : '';

//define('EOL','<br/>');
//echo '$pathToCcsDirectory = ' . $pathToCcsDirectory . PHP_EOL;
//echo '$privatePath = ' . $privatePath . PHP_EOL;
//echo '$protectedPath = ' . $protectedPath . PHP_EOL;
//echo '$runtimePath = ' . $runtimePath . PHP_EOL;
//echo '$publicPath = ' . $publicPath . PHP_EOL;
//echo '$webrootPath = ' . $webrootPath . PHP_EOL;
/** the following defines path aliases using:   Yii::setPathOfAlias('local','path/to/local-folder');
 * usage e.g.  ... Yii::getPathOfAlias('runtimePath') ...
 */
Yii::setPathOfAlias('doePath', $pathToDoeDirectory);
Yii::setPathOfAlias('privatePath', $privatePath);
Yii::setPathOfAlias('publicPath', $publicPath);
Yii::setPathOfAlias('protectedPath', $protectedPath);
Yii::setPathOfAlias('runtimePath', $runtimePath);
Yii::setPathOfAlias('webrootPath', $webrootPath);
$config_database = require(dirname(__FILE__) . '/database.php');

$config_main = array(
    'sourceLanguage' => 'en',
    'timeZone'       => 'Europe/Amsterdam',
    'basePath'       => $protectedPath,
    // override the default of Yii
    'runtimePath'    => $runtimePath,
    'name'           => Yii::t('system', 'DOE Web Application'),
    // preloading 'log' component
    'preload'        => array(
        'log',
        'translate',
    ),
    // autoloading model and component classes, Note that importing a directory does not import any of its subdirectories!
    'import' => array(
        'application.components.*',
        'application.models.*',
        'application.modules.rights.*',
        'application.modules.rights.components.*',
        'application.modules.translate.TranslateModule',
    ),
    'modules' => array(
        'translate',
        'rights' => array(
            'install'        => false, // Whether to install rights.
            'userNameColumn' => 'login', // Name of the user name column in the database.
            'userClass'      => 'RightsModuleUser', // extended User model
            'cssFile'        => '/MTE/modules/rights/default.css', // custom css for rights module
        /* more options */
//          'appLayout'          => 'application.views.layouts.main', // Application layout.
//          'authenticatedName'  => 'Authenticated',                // Name of the authenticated user role.
//          'baseUrl'            => '/rights',                      // Base URL for Rights. Change if module is nested.
//          'debug'              => false,                          // Whether to enable debug mode.
//          'displayDescription' => true,                           // Whether to use item description instead of name.
//          'enableBizRule'      => true,                           // Whether to enable authorization item business rules.
//          'enableBizRuleData'  => false,                          // Whether to enable data for business rules.
//          'flashErrorKey'      => 'RightsError',                  // Key to use for setting error flash messages.
//          'flashSuccessKey'    => 'RightsSuccess',                // Key to use for setting success flash messages.
//          'layout'             => 'rights.views.layouts.main',    // Layout to use for displaying Rights.
//          'superuserName'      => 'Admin',                        // Name of the role with super user privileges.
//          'userIdColumn'       => 'id',                           // Name of the user id column in the database.
        ),
        // Whether to enable installer.
        // application components
        'components'     => array(
            'user' => array(
                'class'          => 'WebUser',
                /* enable cookie-based authentication */
                'allowAutoLogin' => true,
                /* @see http://www.yiiframework.com/doc/guide/1.1/en/topics.auth */
                'loginUrl'       => array('/site/login'),
            ),
            'authManager' => array(
                'class'          => 'RDbAuthManager',
                'connectionID'   => 'db',
                'defaultRoles'   => array('authenticated', 'user'),
            ),
            'messages' => array(
                'class'                  => 'CDbMessageSource',
                'onMissingTranslation'   => array('TranslateModule',
                    'missingTranslation',
                ),
                'translate' => array(
                    'class'              => 'translate.components.MPTranslate',
                    'acceptedLanguages'  => array(
                        'en'         => 'English',
                        'nl'         => 'Nederlands',
                    ),
                ),
            ),
            //use component to store the cookies
            'Cookies'    => array(
                'class'      => 'application.components.CookiesHelper'
            ),
            // uncomment the following to enable URLs in path-format
            'urlManager' => array(
                'urlFormat'      => 'path',
                'showScriptName' => false,
                'rules'          => array(
                    '<controller:\w+>/<id:\d+>'              => '<controller>/view',
                    '<controller:\w+>/<action:\w+>/<id:\d+>' => '<controller>/<action>',
                    '<controller:\w+>/<action:\w+>'          => '<controller>/<action>',
                ),
            ),
            'errorHandler'                           => array(
                // use 'site/error' action to display errors
                'errorAction'    => 'site/error',
            ),
            'log'            => array(
                'class'  => 'CLogRouter',
                'routes' => array(
                    array(
                        'class'  => 'CFileLogRoute',
                        'levels' => 'info, warning, error',
                    ),
                ),
            ),
        ),
    ),
    /** application-level parameters that can be accessed
     *  using Yii::app()->params['paramName']
     */
    'params' => array(
        // this is used in contact page
        'adminEmail'         => '[email protected]',
        'cookie_duration'    => 3600 * 24 * 30,
        'composer.callbacks' => array(
            // args for Yii command runner
            'yiisoft/yii-install' => array('yiic', 'webapp', dirname(__FILE__) . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..'),
            'post-update' => array('yiic', 'migrate'),
            'post-install' => array('yiic', 'migrate'),
        ),
    ),
);
$mainDbIncluded = CMap::mergeArray($config_database, $config_main);

// include and merge local main config if it exists
if (file_exists(dirname(__FILE__) . '/main-local.php'))
{
    return CMap::mergeArray($mainDbIncluded, include(dirname(__FILE__) . '/main-local.php'));
}
// otherwise just load the main config file
return $mainDbIncluded;

and this is my main-local.php:

<?php

/**
 * This is the main Web application configuration.
 *
 * This file is local to the developers machine.
 */
Yii::setPathOfAlias('MTe', '/var/www/private/protected/');
// the following lines may not run when in production mode, so they should be in a ..-local.php
defined('YII_DEBUG') or define('YII_DEBUG', true);
// specify how many levels of call stack should be shown in each log message
defined('YII_TRACE_LEVEL') or define('YII_TRACE_LEVEL', 5);

return array(
    'modules' => array(
        // uncomment the following to enable the Gii tool
        'gii' => array(
            'class'      => 'system.gii.GiiModule',
            'password'   => 'password',
            // If removed, Gii defaults to localhost only. Edit carefully to taste.
            'ipFilters'  => array('127.0.0.1', '::1'),
        ),
    ),
    'components' => array(
//      'urlManager' => array(
//          'urlFormat'      => 'path',
//          'showScriptName' => false,
//      ),
//      'cache'  => array(
//          'class'                  => 'CDbCache',
//          'connectionID'           => 'db',
//          'autoCreateCacheTable'   => true,
//      ),
//      'db'     => array(

//          'schemaCachingDuration' => 3600,
//      ),
        'log' => array(
            'class'  => 'CLogRouter',
            'routes' => array(
                array(
                    'class'  => 'CFileLogRoute',
                    'levels' => 'trace, info, warning, error',
                //       'categories' => 'system.*',
                ),
                array(
                    'class'  => 'CWebLogRoute',
                    'levels' => 'error, warning, info, trace',
                ),
                /*
                  array(
                  'class' => 'CEmailLogRoute',
                  'levels' => 'error, warning',
                  'emails' => '[email protected]',
                  ),
                 */
                array(
                    'class'              => 'CProfileLogRoute',
                ),
            ),
        ),
    ),
    'params'             => array(
        'adminEmail' => '[email protected]', // this is used in contact page
    ),
);

How can I fix the gii problem here??

1

There are 1 answers

2
Sergey Rusakov On

You are wrong! You allowed access to GII to everyone. Anybody can rewrite your classes...

Write an address of your computer or address mask of your network to ipFilter parameter.

Another way is to comment out GII module after you finish work with it.