-
Notifications
You must be signed in to change notification settings - Fork 1
/
root-me101.php
80 lines (73 loc) · 2.06 KB
/
root-me101.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
<?php
include('../php/simple_html_dom.php');
$date='01/03';
?>
<html>
<head>
<title>Root-Me101 : Tableau des Scores</title>
<link rel="stylesheet" href="./css/bootstrap.min.css">
<script src="./js/bootstrap.min.js"></script>
</head>
<body>
<h1 class="text-center">Tableau des scores</h1>
<br><br>
<table class="table table-striped table-hover">
<tr>
<th>Pseudo</th><th>nom IRL</th><th>SCORE</th><th>challenges complétés</th><th>points depuis le <?php echo($date); ?></th>
</tr>
<?php
function get_RootMe_score($pseudo){
$url="https://www.root-me.org/".$pseudo;
$html=file_get_html($url);
$score='not_found';
foreach($html->find('ul') as $element){
if ($element->class === 'spip') {
$line=$element->find('li',2);
$score=$line->first_child()->plaintext;
#echo('score = '.$score.'<br>');
}
}
return $score;
}
function get_RootMe_challs($pseudo){
$url="https://www.root-me.org/".$pseudo.'?inc=score';
$html=file_get_html($url);
$challs='not_found';
foreach($html->find('ul') as $element){
$line1=$element->find('li',0);
$line2=$line1->find('span',0);
if ($line2->class === 'color1 tl') {
$challs=$line2->first_child()->plaintext;
}
}
return $challs;
}
function load_profiles(){
$row = 1;
$profiles=array();
if (($handle = fopen("/home/rmichon/participants.csv", "r")) !== FALSE) {
while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
$num = count($data);
array_push($profiles,$data);
$row++;
}
fclose($handle);
}
return $profiles;
}
foreach(load_profiles() as $profile){
$score = get_RootMe_score($profile[0]);
echo('<tr><td>');
if($profile[2] !== 'anonyme'){
echo('<a href="https://www.root-me.org/'.$profile[0].'">'.$profile[2].'</a>');
}
echo('</td><td>'.$profile[1].'</td><td>'.$score.'</td><td>'.get_RootMe_challs($profile[0]).'</td><td>'.((int) $score - (int) $profile[3]).'</td></tr>');
}
?>
</table>
<br><br>
<footer class="page-footer font-small text-center">
<p class="text-center font-small">Romain du Marais - <a href="https://github.com/hackheera/root-me101">github</a></p>
</footer>
</body>
</html>