|
1
|
|
|
<?php |
|
2
|
|
|
namespace App\Http\Controllers\VirtualJudge\Vijos; |
|
3
|
|
|
|
|
4
|
|
|
use App\Http\Controllers\VirtualJudge\Curl; |
|
5
|
|
|
use App\Models\CompilerModel; |
|
6
|
|
|
use App\Models\JudgerModel; |
|
7
|
|
|
use Illuminate\Support\Facades\Validator; |
|
8
|
|
|
use Requests; |
|
9
|
|
|
|
|
10
|
|
|
class Vijos extends Curl |
|
11
|
|
|
{ |
|
12
|
|
|
protected $sub; |
|
13
|
|
|
public $post_data=[]; |
|
14
|
|
|
|
|
15
|
|
|
public function __construct(& $sub, $all_data) |
|
16
|
|
|
{ |
|
17
|
|
|
$this->sub=& $sub; |
|
18
|
|
|
$this->post_data=$all_data; |
|
19
|
|
|
} |
|
20
|
|
|
|
|
21
|
|
|
private function ojLogin() |
|
22
|
|
|
{ |
|
23
|
|
|
$response=$this->grab_page('https://vijos.org', 'vijos'); |
|
24
|
|
|
if (strpos($response, '登出') === false) { |
|
25
|
|
|
|
|
26
|
|
|
$judger=new JudgerModel(); |
|
27
|
|
|
$judger_list=$judger->list(5); |
|
28
|
|
|
$params = [ |
|
29
|
|
|
'uname' => $judger_list[0]["handle"], |
|
30
|
|
|
'password' => $judger_list[0]["password"], |
|
31
|
|
|
'rememberme' => 'on', |
|
32
|
|
|
]; |
|
33
|
|
|
$this->login('https://vijos.org/login', http_build_query($params), 'vijos'); |
|
34
|
|
|
} |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
private function submitSolution() |
|
38
|
|
|
{ |
|
39
|
|
|
$compilerModel = new CompilerModel(); |
|
40
|
|
|
$lang = $compilerModel->detail($this->post_data["coid"]); |
|
41
|
|
|
$pid = $this->post_data['iid']; |
|
42
|
|
|
$this->sub['language']=$lang['display_name']; |
|
43
|
|
|
$this->sub['solution']=$this->post_data["solution"]; |
|
44
|
|
|
$this->sub['pid']=$this->post_data["pid"]; |
|
45
|
|
|
$this->sub['coid']=$this->post_data["coid"]; |
|
46
|
|
|
if (isset($this->post_data["contest"])) { |
|
47
|
|
|
$this->sub['cid']=$this->post_data["contest"]; |
|
48
|
|
|
} else { |
|
49
|
|
|
$this->sub['cid']=null; |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
$response=$this->grab_page("https://vijos.org/p/{$pid}/submit", 'vijos'); |
|
53
|
|
|
preg_match('/"csrf_token":"([0-9a-f]{64})"/', $response, $match); |
|
54
|
|
|
|
|
55
|
|
|
$params = [ |
|
56
|
|
|
'lang' => $lang['lcode'], |
|
57
|
|
|
'code' => $this->post_data["solution"], |
|
58
|
|
|
'csrf_token' => $match[1], |
|
59
|
|
|
]; |
|
60
|
|
|
$response=$this->post_data("https://vijos.org/p/{$pid}/submit", http_build_query($params), "vijos", true, false); |
|
61
|
|
|
if (preg_match('/\nLocation: \/records\/(.+)/i', $response, $match)) { |
|
62
|
|
|
$this->sub['remote_id'] = $match[1]; |
|
63
|
|
|
} else { |
|
64
|
|
|
$this->sub['verdict'] = 'Submission Error'; |
|
65
|
|
|
} |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
public function submit() |
|
69
|
|
|
{ |
|
70
|
|
|
Validator::make($this->post_data, [ |
|
71
|
|
|
'pid' => 'required|integer', |
|
72
|
|
|
'coid' => 'required|integer', |
|
73
|
|
|
'iid' => 'required|integer', |
|
74
|
|
|
'solution' => 'required', |
|
75
|
|
|
])->validate(); |
|
76
|
|
|
|
|
77
|
|
|
$this->ojLogin(); |
|
78
|
|
|
$this->submitSolution(); |
|
79
|
|
|
} |
|
80
|
|
|
} |
|
81
|
|
|
|