forked from vidar-team/hctf_backend
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7ddf41e
commit ff5f8f9
Showing
10 changed files
with
135 additions
and
59 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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,6 @@ | |
|
||
use APIReturn; | ||
use Carbon\Carbon; | ||
use Config; | ||
use Illuminate\Http\Request; | ||
|
||
class SystemController extends Controller | ||
|
@@ -17,14 +16,21 @@ class SystemController extends Controller | |
*/ | ||
public function getMetaInfo(Request $request) | ||
{ | ||
return \APIReturn::success([ | ||
"startTime" => Carbon::parse(Config::get("ctf.startTime"))->toIso8601String(), | ||
"endTime" => Carbon::parse(Config::get("ctf.endTime"))->toIso8601String(), | ||
"flagPrefix" => Config::get("ctf.flagPrefix"), | ||
"flagSuffix" => Config::get("ctf.flagSuffix") | ||
$config = collect(\DB::table("config")->get())->pluck('value', 'key'); | ||
return APIReturn::success([ | ||
'startTime' => Carbon::parse($config['start_time'], 'UTC')->toIso8601String(), | ||
'endTime' => Carbon::parse($config['end_time'], 'UTC')->toIso8601String(), | ||
'flagPrefix' => $config['flag_prefix'], | ||
'flagSuffix' => $config['flag_suffix'] | ||
]); | ||
} | ||
|
||
/** | ||
* 编辑系统设置 | ||
* @param Request $request | ||
* @return \Illuminate\Http\JsonResponse | ||
* @author Eridanus Sora <[email protected]> | ||
*/ | ||
public function editMetaInfo(Request $request){ | ||
$validator = \Validator::make($request->only(['startTime', 'endTime', 'flagPrefix', 'flagSuffix']), [ | ||
'startTime' => 'required|date', | ||
|
@@ -37,7 +43,24 @@ public function editMetaInfo(Request $request){ | |
return APIReturn::error('invalid_parameters', $validator->errors()->all(), 400); | ||
} | ||
|
||
Config::set('ctf.startTime', $request->input('startTime')); | ||
Config::set('ctf.endTime', $request->input('endTime')); | ||
try{ | ||
\DB::table("config")->where('key', '=', 'start_time')->update([ | ||
'value' => Carbon::parse($request->input('startTime'))->setTimezone('UTC')->toDateTimeString() | ||
]); | ||
\DB::table("config")->where('key', '=', 'end_time')->update([ | ||
'value' => Carbon::parse($request->input('endTime'))->setTimezone('UTC')->toDateTimeString() | ||
]); | ||
\DB::table("config")->where('key', '=', 'flag_prefix')->update([ | ||
'value' => $request->input('flagPrefix') | ||
]); | ||
\DB::table("config")->where('key', '=', 'flag_suffix')->update([ | ||
'value' => $request->input('flagSuffix') | ||
]); | ||
} | ||
catch (\Exception $e){ | ||
return \APIReturn::error("database_error", "数据库读写错误", 500); | ||
} | ||
|
||
return APIReturn::success(); | ||
} | ||
} |
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.
31 changes: 31 additions & 0 deletions
31
database/migrations/2017_10_26_154016_add_config_table.php
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,31 @@ | ||
<?php | ||
|
||
use Illuminate\Support\Facades\Schema; | ||
use Illuminate\Database\Schema\Blueprint; | ||
use Illuminate\Database\Migrations\Migration; | ||
|
||
class AddConfigTable extends Migration | ||
{ | ||
/** | ||
* Run the migrations. | ||
* | ||
* @return void | ||
*/ | ||
public function up() | ||
{ | ||
Schema::create("config", function(Blueprint $table){ | ||
$table->string('key')->unique(); | ||
$table->string('value'); | ||
}); | ||
} | ||
|
||
/** | ||
* Reverse the migrations. | ||
* | ||
* @return void | ||
*/ | ||
public function down() | ||
{ | ||
// | ||
} | ||
} |
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,37 @@ | ||
<?php | ||
|
||
use Illuminate\Database\Seeder; | ||
|
||
class ConfigTableSeeder extends Seeder | ||
{ | ||
/** | ||
* Run the database seeds. | ||
* | ||
* @return void | ||
*/ | ||
public function run() | ||
{ | ||
DB::table('config')->delete(); | ||
|
||
$config = [ | ||
[ | ||
'key' => 'start_time', | ||
'value' => '2017-11-11T08:00:00+08:00' | ||
], | ||
[ | ||
'key' => 'end_time', | ||
'value' => '2017-11-13T08:00:00+08:00' | ||
], | ||
[ | ||
'key' => 'flag_prefix', | ||
'value' => 'hctf{' | ||
], | ||
[ | ||
'key' => 'flag_suffix', | ||
'value' => '}' | ||
] | ||
]; | ||
|
||
DB::table('config')->insert($config); | ||
} | ||
} |
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