Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Y
yii2
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
PSDI Army
yii2
Commits
066989f0
Commit
066989f0
authored
Aug 01, 2014
by
Qiang Xue
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixes #4425: generate cookie validation keys in local config files.
parent
2a8ca600
Show whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
85 additions
and
32 deletions
+85
-32
main.php
apps/advanced/backend/config/main.php
+0
-4
composer.json
apps/advanced/composer.json
+1
-6
main-local.php
apps/advanced/environments/dev/backend/config/main-local.php
+8
-1
main-local.php
.../advanced/environments/dev/frontend/config/main-local.php
+8
-1
index.php
apps/advanced/environments/index.php
+19
-5
main-local.php
.../advanced/environments/prod/backend/config/main-local.php
+6
-0
main-local.php
...advanced/environments/prod/frontend/config/main-local.php
+6
-0
main.php
apps/advanced/frontend/config/main.php
+0
-4
init
apps/advanced/init
+37
-11
No files found.
apps/advanced/backend/config/main.php
View file @
066989f0
...
...
@@ -13,10 +13,6 @@ return [
'bootstrap'
=>
[
'log'
],
'modules'
=>
[],
'components'
=>
[
'request'
=>
[
// !!! insert a secret key in the following (if it is empty) - this is required by cookie validation
'cookieValidationKey'
=>
''
,
],
'user'
=>
[
'identityClass'
=>
'common\models\User'
,
'enableAutoLogin'
=>
true
,
...
...
apps/advanced/composer.json
View file @
066989f0
...
...
@@ -32,8 +32,7 @@
},
"scripts"
:
{
"post-create-project-cmd"
:
[
"yii
\\
composer
\\
Installer::setPermission"
,
"yii
\\
composer
\\
Installer::generateCookieValidationKey"
"yii
\\
composer
\\
Installer::setPermission"
]
},
"config"
:
{
...
...
@@ -46,10 +45,6 @@
"frontend/runtime"
,
"frontend/web/assets"
],
"config"
:
[
"frontend/config/main.php"
,
"backend/config/main.php"
]
}
}
apps/advanced/environments/dev/backend/config/main-local.php
View file @
066989f0
<?php
$config
=
[];
$config
=
[
'components'
=>
[
'request'
=>
[
// !!! insert a secret key in the following (if it is empty) - this is required by cookie validation
'cookieValidationKey'
=>
''
,
],
],
];
if
(
!
YII_ENV_TEST
)
{
// configuration adjustments for 'dev' environment
...
...
apps/advanced/environments/dev/frontend/config/main-local.php
View file @
066989f0
<?php
$config
=
[];
$config
=
[
'components'
=>
[
'request'
=>
[
// !!! insert a secret key in the following (if it is empty) - this is required by cookie validation
'cookieValidationKey'
=>
''
,
],
],
];
if
(
!
YII_ENV_TEST
)
{
// configuration adjustments for 'dev' environment
...
...
apps/advanced/environments/index.php
View file @
066989f0
...
...
@@ -9,9 +9,15 @@
* return [
* 'environment name' => [
* 'path' => 'directory storing the local files',
* '
w
ritable' => [
* '
setW
ritable' => [
* // list of directories that should be set writable
* ],
* 'setExecutable' => [
* // list of directories that should be set executable
* ],
* 'setCookieValidationKey' => [
* // list of config files that need to be inserted with automatically generated cookie validation keys
* ],
* ],
* ];
* ```
...
...
@@ -19,26 +25,34 @@
return
[
'Development'
=>
[
'path'
=>
'dev'
,
'
w
ritable'
=>
[
'
setW
ritable'
=>
[
'backend/runtime'
,
'backend/web/assets'
,
'frontend/runtime'
,
'frontend/web/assets'
,
],
'
e
xecutable'
=>
[
'
setE
xecutable'
=>
[
'yii'
,
],
'setCookieValidationKey'
=>
[
'backend/config/main-local.php'
,
'frontend/config/main-local.php'
,
],
],
'Production'
=>
[
'path'
=>
'prod'
,
'
w
ritable'
=>
[
'
setW
ritable'
=>
[
'backend/runtime'
,
'backend/web/assets'
,
'frontend/runtime'
,
'frontend/web/assets'
,
],
'
e
xecutable'
=>
[
'
setE
xecutable'
=>
[
'yii'
,
],
'setCookieValidationKey'
=>
[
'backend/config/main-local.php'
,
'frontend/config/main-local.php'
,
],
],
];
apps/advanced/environments/prod/backend/config/main-local.php
View file @
066989f0
<?php
return
[
'components'
=>
[
'request'
=>
[
// !!! insert a secret key in the following (if it is empty) - this is required by cookie validation
'cookieValidationKey'
=>
''
,
],
],
];
apps/advanced/environments/prod/frontend/config/main-local.php
View file @
066989f0
<?php
return
[
'components'
=>
[
'request'
=>
[
// !!! insert a secret key in the following (if it is empty) - this is required by cookie validation
'cookieValidationKey'
=>
''
,
],
],
];
apps/advanced/frontend/config/main.php
View file @
066989f0
...
...
@@ -12,10 +12,6 @@ return [
'bootstrap'
=>
[
'log'
],
'controllerNamespace'
=>
'frontend\controllers'
,
'components'
=>
[
'request'
=>
[
// !!! insert a secret key in the following (if it is empty) - this is required by cookie validation
'cookieValidationKey'
=>
''
,
],
'user'
=>
[
'identityClass'
=>
'common\models\User'
,
'enableAutoLogin'
=>
true
,
...
...
apps/advanced/init
View file @
066989f0
...
...
@@ -14,6 +14,10 @@
* @license http://www.yiiframework.com/license/
*/
if
(
!
extension_loaded
(
'mcrypt'
))
{
die
(
'The mcrypt PHP extension is required by Yii2.'
);
}
$params
=
getParams
();
$root
=
str_replace
(
'\\'
,
'/'
,
__DIR__
);
$envs
=
require
(
"
$root
/environments/index.php"
);
...
...
@@ -68,17 +72,10 @@ foreach ($files as $file) {
}
}
if
(
isset
(
$env
[
'writable'
]))
{
foreach
(
$env
[
'writable'
]
as
$writable
)
{
echo
" chmod 0777
$writable
\n
"
;
@
chmod
(
"
$root
/
$writable
"
,
0777
);
}
}
if
(
isset
(
$env
[
'executable'
]))
{
foreach
(
$env
[
'executable'
]
as
$executable
)
{
echo
" chmod 0755
$executable
\n
"
;
@
chmod
(
"
$root
/
$executable
"
,
0755
);
$callbacks
=
[
'setCookieValidationKey'
,
'setWritable'
,
'setExecutable'
];
foreach
(
$callbacks
as
$callback
)
{
if
(
!
empty
(
$env
[
$callback
]))
{
$callback
(
$root
,
$env
[
$callback
]);
}
}
...
...
@@ -167,3 +164,32 @@ function getParams()
}
return
$params
;
}
function
setWritable
(
$root
,
$paths
)
{
foreach
(
$paths
as
$writable
)
{
echo
" chmod 0777
$writable
\n
"
;
@
chmod
(
"
$root
/
$writable
"
,
0777
);
}
}
function
setExecutable
(
$root
,
$paths
)
{
foreach
(
$paths
as
$executable
)
{
echo
" chmod 0755
$executable
\n
"
;
@
chmod
(
"
$root
/
$executable
"
,
0755
);
}
}
function
setCookieValidationKey
(
$root
,
$paths
)
{
foreach
(
$paths
as
$file
)
{
echo
" generating cookie validation key
$file
\n
"
;
$file
=
$root
.
'/'
.
$file
;
$length
=
32
;
$bytes
=
mcrypt_create_iv
(
$length
,
MCRYPT_DEV_URANDOM
);
$key
=
strtr
(
substr
(
base64_encode
(
$bytes
),
0
,
$length
),
'+/='
,
'_-.'
);
$content
=
preg_replace
(
'/(("|\')cookieValidationKey("|\')\s*=>\s*)(""|\'\')/'
,
"
\\
1'
$key
'"
,
file_get_contents
(
$file
));
file_put_contents
(
$file
,
$content
);
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment