forked from team-granite/HNGi7-First-Task
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.php
More file actions
210 lines (182 loc) · 6.22 KB
/
index.php
File metadata and controls
210 lines (182 loc) · 6.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
<?php
$files = scandir("scripts");
function filter_files($var)
{
$arr = [];
for ($counter = 0; $counter < count($var); $counter++) {
$file = $var[$counter];
if (strlen($file) > 3) {
array_push($arr, $file);
}
}
return $arr;
}
$nfiles = filter_files($files);
$json = [];
$pass = 0;
$fail = 0;
$python = 0;
$javascript = 0;
$php = 0;
for ($counter = 0; $counter < count($nfiles); $counter++) {
$file = $nfiles[$counter];
$path_info = pathinfo($file);
if ($path_info["extension"] == "js") {
$ret = exec("node scripts/" . $file . " 2>&1 ", $output, $return_var);
$javascript++;
}
if ($path_info["extension"] == "py") {
$ret = exec("python scripts/" . $file . " 2>&1 ", $output, $return_var);
$python++;
}
if ($path_info["extension"] == "php") {
$ret = exec("php scripts/" . $file . " 2>&1 ", $output, $return_var);
$php++;
}
if (isset($output[0])) {
$userStrings = strip_tags($output[0]);
} else {
$userStrings = "nothing returned";
}
$detail = explode(" and ", $userStrings);
$userString = trim($detail[0]);
if (isset($detail[1])) {
$email = $detail[1];
} else {
$email = "";
}
preg_match("/ [a-zA-Z]+ [a-zA-Z]+ with/", $userString, $matches);
preg_match("/ HNG-[0-9]+ using/", $userString, $matches2);
preg_match("/ [a-zA-Z]+ for/", $userString, $matches3);
if (isset($matches2[0])) {
$id = substr($matches2[0], 1, -6);
} else {
$id = "";
}
if (isset($matches[0])) {
$name = substr($matches[0], 1, -5);
} else {
$name = "";
}
if (isset($matches3[0])) {
$language = substr($matches3[0], 0, -3);
} else {
$language = "";
}
if (preg_match("/^Hello World, this is [A-Za-z]+([\ A-Za-z]+)* with HNGi7 ID HNG-[0-9]+ using [a-zA-Z]+ for stage 2 task$/", $userString)){
$obj = [
"file" => $file,
"output" => $userString,
"email" => $email,
"fullname" => $name,
"HNGId" => $id,
"language" => $language,
"status" => "pass"
];
array_push($json, $obj);
$pass++;
$output = [];
}else {
$obj = [
"file" => $file,
"output" => $userString,
"email" => $email,
"fullname" => $name,
"HNGId" => $id,
"language" => $language,
"status" => "fail"
];
array_push($json, $obj);
$fail++;
$output = [];
}
}
$jsonlist = $json;
$json = json_encode($json);
if (isset($_GET['json'])) {
echo $json;
}else{
?>
<!doctype html>
<html lang='en'>
<head>
<title>HNGi7 Task 2 - Team Granite</title>
<meta charset='utf-8'>
<meta name='viewport' content='width=device-width, initial-scale=1, shrink-to-fit=no'>
<!-- Bootstrap CSS -->
<link rel='stylesheet' href='https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css' integrity='sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T' crossorigin='anonymous'>
</head>
<body>
<div class='container p-5 text-center'>
<h1>HNGi7 Team Granite </h1>
<a href='?json' class='btn btn-info btn-sm'>VIEW JSON</a>
</div>
<div class='card mt-5 p-4'>
<div class='row'>
<div class='col-1'></div>
<div class='col-2'>
<span class='btn btn-success btn-disabled btn-sm btn-block'><?php echo $pass ?> Passed</span>
</div>
<div class='col-2'>
<span class='btn btn-warning btn-disabled btn-sm btn-block'><?php echo $fail ?> Failed</span>
</div>
<div class='col-2'>
<span class='btn btn-primary btn-disabled btn-sm btn-block'><?php echo $php ?> PHP SCRIPT</span>
</div>
<div class='col-2'>
<span class='btn btn-secondary btn-disabled btn-sm btn-block'><?php echo $javascript ?> JavsScript</span>
</div>
<div class='col-2'>
<span class='btn btn-info btn-disabled btn-sm btn-block'><?php echo $python ?> Python SCRIPT</span>
</div>
</div>
</div>
</div>
<div class='container mt-5 p-0'>
<div class='row'>
<div class='col-12'>
<table class='table table-bordered table-hover table-striped'>
<thead class='thead-dark'>
<tr>
<th>Full Name</th>
<th>HNG-ID</th>
<th>Email</th>
<th>Response</th>
<th>Status</th>
</tr>
</thead>
<tbody>
<?php
foreach ($jsonlist as $out){
sleep(1);
flush();
ob_flush();
if ($out["status"] == "pass"){
$pf = "<td> <span class='btn btn-success btn-disabled btn-sm'>Pass</span></td>";
}else{
$pf = "<td> <span class='btn btn-danger btn-disabled btn-sm'>Fail</span></td>";
}
echo ("<tr>
<td scope='row'>".$out["fullname"]."</td>
<td >".$out["HNGId"]."</td>
<td >".$out["email"]."</td>
<td>".$out["output"]."</td>
.$pf.
</tr>");
}
?>
</tbody>
</table>
</div>
</div>
</div>
</body>
<!-- Optional JavaScript -->
<!-- jQuery first, then Popper.js, then Bootstrap JS -->
<script src='https://code.jquery.com/jquery-3.3.1.slim.min.js' integrity='sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo' crossorigin='anonymous'></script>
<script src='https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js' integrity='sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1' crossorigin='anonymous'></script>
<script src='https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js' integrity='sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM' crossorigin='anonymous'></script>
</html>
<?php
}
?>