-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgestionlog.php
More file actions
129 lines (115 loc) · 4.22 KB
/
gestionlog.php
File metadata and controls
129 lines (115 loc) · 4.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
<?php
//include_once("JSON.php");
/************************************ GESTION DES LOGS ********************************************************/
function getIp(): string
{
if (isset($_SERVER['HTTP_CF_CONNECTING_IP'])) { // Support Cloudflare
$ip = $_SERVER['HTTP_CF_CONNECTING_IP'];
} elseif (isset($_SERVER['REMOTE_ADDR']) === true) {
$ip = $_SERVER['REMOTE_ADDR'];
if (preg_match('/^(?:127|10)\.0\.0\.[12]?\d{1,2}$/', $ip)) {
if (isset($_SERVER['HTTP_X_REAL_IP'])) {
$ip = $_SERVER['HTTP_X_REAL_IP'];
} elseif (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
$ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
}
}
} else {
$ip = '127.0.0.1';
}
if (in_array($ip, ['::1', '0.0.0.0', 'localhost'], true)) {
$ip = '127.0.0.1';
}
$filter = filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4);
if ($filter === false) {
$ip = '127.0.0.1';
}
return $ip;
}
/**
Affichage json
*/
function affichagelogrow ($json){
$ip = getIp();
echo '<div id="div_histo" style="height:250px; overflow-y:scroll; border:2px inset #ffffff; background-color:#ffffff; padding:5px">';
$assoc_array = json_decode($json, true);
$arrayOfObjsnew = $assoc_array["menuitem"];
$reversed = array_reverse(array($arrayOfObjsnew));
foreach ($reversed[0] as $key => $object) {
if ($ip == $object["ip"]){
echo nl2br('<span class="text-info"><b>Atom : </b>'.$object["result"].'</span><br>');
echo nl2br('<span class="text-primary"><b>Vous : </b>'.$object["log"].'</span><br>');
}
}
echo '</div>';
echo 'Vous savez, votre adresse IP est ' . $ip . '?<br>';
echo 'PHP version: ' . phpversion();
}
function affichagelogadminrow ($json){
$ip = getIp();
echo '<div id="div_histo" style="height:250px; overflow-y:scroll; border:2px inset #ffffff; background-color:#ffffff; padding:5px">';
$assoc_array = json_decode($json, true);
$arrayOfObjsnew = $assoc_array["menuitem"];
$reversed = array_reverse(array($arrayOfObjsnew));
foreach ($reversed[0] as $key => $object) {
echo nl2br('<span class="text-info"><b>Atom : '.$object["date"].' </b>'.$object["result"].'</span><br>');
echo nl2br('<span class="text-primary"><b>Vous : '.$object["ip"].' </b>'.$object["log"].'</span><br>');
}
//}
echo '</div>';
echo 'Vous savez, votre adresse IP est ' . $ip . '?<br>';
echo 'PHP version: ' . phpversion();
}
/**
retourne un tableau depuis le fichier jscon
*/
function loadlogjson () {
//$json = new Services_JSON();
$input = file_get_contents('logatom.json', 1000000);
//$json_a = $json->decode($input);
//json_encode($json);
$json_a = json_decode($input);
return $json_a;
}
/**
Enregistre tableau dans le fichier de log json
param stdClass $json_string
*/
function savelogjson ($json_string) {
//$json = new Services_JSON();
$fp = fopen('logatom.json', 'w');
//$output = $json->encode($arr);
//json_encode($json);
//$a = (array)$json_string_in_array[0];
$json_array = json_decode($json_string);
$json_string2 = json_encode($json_array);
fwrite($fp, $json_string2 ?? '');
fclose($fp);
}
function enregistrerlog ($json_log_a, $entrer, $resul,$admin){
$entrer = trim($entrer);
$resul = trim($resul);
//$ip = $_SERVER["REMOTE_ADDR"];
$ip = getIp();
$Datecourante = date('d-m-Y H:i:s');
echo "<! -- Enregistement log: ".$ip." date: ".$Datecourante." !>\n";
// On ajout un object
$obj = new stdClass;
$obj2 = new stdClass;
$obj2->log = $entrer;
$obj2->result = $resul;
$obj2->ip = $ip;
$obj2->date = $Datecourante;
$obj->menuitem = array($obj2);
$json_array = (object) array_merge_recursive ( (array) $json_log_a, (array) $obj );
//$json_array = json_decode($extended, true);
$json_string2 = json_encode($json_array);
if ($admin){
affichagelogadminrow ($json_string2);
}else{
affichagelogrow ($json_string2);
}
savelogjson ($json_string2);
}
/********************************************************************************************/
?>