-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
185 lines (168 loc) · 4.61 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
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
<?php
$config = parse_ini_file('config.ini', true);
require('osu-framework/include.php');
$osu = new OsuTournament\Check();
$rows = array();
$db_host = $config['db']['host'];
$db_user = $config['db']['user'];
$db_pass = $config['db']['pass'];
$db_name = $config['db']['name'];
$db_table = $config['db']['table'];
$conn = new mysqli($db_host, $db_user, $db_pass, $db_name);
if ($conn->connect_error) {
die('Connection failed: ' . $conn->connect_error);
}
if($_POST['number']) {
$sql = 'SELECT * FROM `'.$db_table.'` WHERE `number` = '.$_POST['number'];
$first = $conn->query($sql)->fetch_array(MYSQLI_ASSOC);
if(!$first) {
echo $conn->error;
die();
}
$first['passed'] ?
$sql = 'UPDATE `'.$db_table.'` SET `passed` = \'0\' WHERE `'.$db_table.'`.`number` = '.$_POST['number']:
$sql = 'UPDATE `'.$db_table.'` SET `passed` = \'1\' WHERE `'.$db_table.'`.`number` = '.$_POST['number'];
$after = $conn->query($sql);
if(!$after) {
echo $conn->error;
die();
}
$passed_status = (int) !$first['passed'];
$passed_status ? $passed_status = 'true' : $passed_status = 'false';
echo('{ "data" : "'.$passed_status.'" }');
die();
}
function changeFalse($data, $value) {
return $data ? $data : $value;
}
function osuModeFancy($modeInt) {
switch($modeInt) {
case(0):
return 'osu!';
break;
case(1):
return 'Taiko';
break;
case(2):
return 'CatchTheBeat';
break;
case(3):
return 'osu!mania';
break;
default:
return 'Not Defined Mode';
break;
}
}
function getData($username, $mode) {
global $osu;
$osu->CheckUser($username, $mode);
isset($_SERVER['HTTP_CF_CONNECTING_IP']) ? $cf = $_SERVER['HTTP_CF_CONNECTING_IP'] : $cf = false;
return(array(
'pc' => $osu->Playcount,
'pp' => $osu->Performance,
'rank' => $osu->Rank,
'need_set' => $osu->Occupation_Set,
'now_set' => $osu->Occupation,
'username' => $osu->RealID,
'id' => $osu->OsuID,
'mode' => osuModeFancy($mode),
'mode_code' => $mode,
'ip' => $_SERVER['REMOTE_ADDR'],
'cf' => $cf,
)
);
}
function notitypeFancy($noti_type) {
switch($noti_type) {
case 'twitter':
return 'Twitter';
break;
default:
return 'Undefined Notification Type : '.$noti_type;
break;
}
}
function obfuscate_email($email) {
$em = explode('@',$email);
$name = implode(array_slice($em, 0, count($em)-1), '@');
//$len = floor(strlen($name)/2);
$len = 3;
return substr($name, 0, -3).str_repeat('*', $len).'@'.end($em);
}
function table($data, $osu_data) { ?>
<tr>
<td><?php echo $data['number']; ?></td>
<td><?php echo notitypeFancy($data['noti_type']); ?></td>
<td><?php echo $osu_data['username']; ?></td>
<td><?php echo osuModeFancy($data['osu_mode']); ?></td>
<td><?php echo $data['twitter_id']; ?></td>
<td><?php echo obfuscate_email($data['twitter_email']); ?></td>
<td><?php echo changeFalse($data['web_ip'], 'No IP Data'); ?></td>
<td><?php echo changeFalse($data['cf_ip'], 'Not Connected with CloudFlare'); ?></td>
<td id="data-num<?php echo $data['number']; ?>"><?php echo $data['passed'] ? 'true' : 'false'; ?></td>
<td><a href="javascript:ajaxPost(<?php echo $data['number']; ?>)"<button type="button" class="btn btn-default">revert</button></td>
</tr>
<?php }
$sql = 'SELECT * FROM `'.$db_table.'`;';
$result = $conn->query($sql);
if(!$result) {
echo $conn->error;
die();
}
?>
<style>
table {
overflow: scroll;
}
</style>
<script>
function updatePassed(number, json) {
//$.get(window.location.href, function(data) {
$("#data-num"+number).html(json.data.toString());
//});
}
function ajaxPost(number){
$.ajax({
type: 'post',
url: '/',
data: { 'number' : number },
dataType: 'json',
error: function(xhr, status, error){
alert(error);
},
success: function(json){
updatePassed(number, json);
},
});
}
</script>
<table class="table table-hover">
<thead>
<tr>
<th>Count</th>
<th>Notification Type</th>
<th>osu!username</th>
<th>osu!mode</th>
<th>Twitter ID</th>
<th>Twitter Email</th>
<th>Web IP</th>
<th>CloudFlare IP</th>
<th>Passed</th>
<th>Passed Change</th>
</tr>
</thead>
<tbody>
<?php
while($row = $result->fetch_array(MYSQLI_ASSOC))
$rows[] = $row;
foreach($rows as $row) {
echo '<meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1"><link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.0/jquery.min.js"></script><script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>';
$osu_data = getData($row['osu_id'], $row['osu_mode']);
table($row, $osu_data);
echo '<br>';
}
?>
</tbody>
</table>