-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Former-commit-id: a4e86c4
- Loading branch information
Showing
10 changed files
with
339 additions
and
281 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
<?php | ||
|
||
namespace app\commands; | ||
|
||
use yii\console\Controller; | ||
|
||
class InstallController extends Controller | ||
{ | ||
public function actionIndex() | ||
{ | ||
echo "================================================\n"; | ||
echo " Jiangnan Online Judge Initialization Tool v1.0\n"; | ||
echo "================================================\n\n"; | ||
$root = str_replace('\\', '/', __DIR__ . '/..'); | ||
$env = [ | ||
'setWritable' => [ | ||
'runtime', | ||
'web/assets', | ||
'web/uploads', | ||
'polygon/data', | ||
'judge/data' | ||
], | ||
'setCookieValidationKey' => [ | ||
'config/web.php', | ||
] | ||
]; | ||
$callbacks = ['setCookieValidationKey', 'setWritable', 'setExecutable']; | ||
foreach ($callbacks as $callback) { | ||
if (!empty($env[$callback])) { | ||
$this->$callback($root, $env[$callback]); | ||
} | ||
} | ||
|
||
echo "\n================================================"; | ||
echo "\nRun: ./yii migrate"; | ||
echo "\n================================================\n"; | ||
passthru("./yii migrate"); | ||
|
||
echo "\n================================================"; | ||
echo "\nRun: php socket.php start -d"; | ||
echo "\n================================================\n"; | ||
passthru("php socket.php start -d"); | ||
echo "\nInitialization completed.\n\n"; | ||
} | ||
|
||
private function setWritable($root, $paths) | ||
{ | ||
foreach ($paths as $writable) { | ||
echo " chmod 0777 $writable\n"; | ||
@chmod("$root/$writable", 0777); | ||
} | ||
} | ||
|
||
private function setExecutable($root, $paths) | ||
{ | ||
foreach ($paths as $executable) { | ||
echo " chmod 0755 $executable\n"; | ||
@chmod("$root/$executable", 0755); | ||
} | ||
} | ||
|
||
private function setCookieValidationKey($root, $paths) | ||
{ | ||
foreach ($paths as $file) { | ||
echo " generate cookie validation key in $file\n"; | ||
$file = $root . '/' . $file; | ||
$length = 32; | ||
$bytes = openssl_random_pseudo_bytes($length); | ||
$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); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.