-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
117 lines (84 loc) · 2.33 KB
/
index.php
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
<?php
require __DIR__ . '/vendor/autoload.php';
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
require 'jsondb/jsondb.php';
$app = new Silex\Application();
function get_rand($request)
{
$somaip = explode('.', $request->getClientIp() .'.'.date('d.m.Y'));
return array_sum($somaip);
}
function template_parser($file, $data){
$template = file_get_contents($file);
foreach ($data as $key => $value) {
$template = preg_replace('/\{'.$key.'\}/', $value, $template);
}
return $template;
};
function get_token(){
if(isset($_COOKIE['__eaut'])){
return $_COOKIE['__eaut'];
}else{
$id = md5(uniqid(rand(), true));
setcookie('__eaut', $id);
return $id;
}
};
function get_score($score, $request){
$a = array('a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z');
$score = explode('%dx%', $score);
$s = array();
for($i=0;$i<count($score);$i++)
{
$ss = array();
for($j=0;$j<strlen($score[$i]);$j++)
{
$cc = str_split($score[$i]);
for ($k = 0; $k < count($a); $k++)
{
if($cc[$j] == $a[$k])
{
array_push($ss, $k);
}
}
}
$ss = join('', $ss);
$ss = $ss == '' ? '0' : floor(get_rand($request) / $ss);
array_push($s, $ss);
}
return join('', $s);
}
$jsondb = new JsonDB(array('dbname'=>'database', 'path'=>realpath('database')));
$app->get('/', function (Request $request) use ($app, $jsondb) {
$data = array(
'CSRF_TOKEN' => get_token(),
'RAND' => get_rand($request)
);
$template = template_parser('views/home.php', $data);
return $template;
});
$app->post('/ranking', function (Request $request) use ($app, $jsondb){
$score = get_score($request->get('kng'), $request);
$token = get_token();
$user = $jsondb->users->find(array('userid'=>$user))->data;
if(count($user)){
$user->score = $score;
$jsondb->users->update(array('userid'=>$user), $user);
}else{
$jsondb->users->insert(array(
'userid' => $user,
'score' => $score
));
}
return $app->json(array(
'status' => true
), 200);
});
$app->get('/ranking', function () use ($app, $jsondb) {
return $app->json(array(
'users' => $jsondb->users->find(array('score'=>'*'), array('score'=>true))->data,
'status' => true
), 200);
});
$app->run();