Files
MYSOPHAL/front/access.logs.php
2025-08-07 13:15:31 +01:00

488 lines
8.7 KiB
PHP

<?php
use Glpi\Event;
include ('../inc/includes.php');
Session::checkLoginUser();
if (Session::getCurrentInterface() == "helpdesk") {
Html::helpHeader("Journal authentification", '', $_SESSION["glpiname"]);
} else {
Html::header("Journal authentification", '', "", "");
}
if( $_SESSION['glpiactiveprofile']['name'] == "Super-Admin" ||
$_SESSION['glpiactiveprofile']['name'] == "DGA" || $_SESSION['glpiactiveprofile']['name'] == "DG"){
function fullname($id_user){
global $DB;
$query = "SELECT concat(realname , ' ' , firstname) as fullname FROM `glpi_users`
where registration_number = ? LIMIT 1";
$stmt = $DB->prepare($query);
$stmt->bind_param("i" , $id_user);
$stmt->execute();
$result = $stmt->get_result();
if ($result->num_rows > 0) {
$res = array();
$res = $result->fetch_assoc();
return $res['fullname'];
}
return null;
}
function WebService(){
$url = "https://erp.sophal.net/Webservices.php";
$accessKey = '@k4H9NQVhvg9KqWL$ZDvd9xm!'; //CSRF ATTACK
$data = array(
'accessKey' => $accessKey
);
$resource = curl_init();
curl_setopt($resource, CURLOPT_URL, $url);
curl_setopt($resource, CURLOPT_HTTPHEADER, array('Content-Type:multipart/form-data'));
curl_setopt($resource, CURLOPT_POST, 1);
curl_setopt($resource, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($resource, CURLOPT_POSTFIELDS, $data);
$response = curl_exec($resource);
if(curl_errno($resource))
{
echo 'Erreur Curl : ' . curl_error($resource);
}
curl_close($resource);
if ($response !== false) {
return $response;
}
return false;
}
$res = WebService();
//supprimer UTF-8-BOM
for ($i = 0; $i <= 31; ++$i) {
$res = str_replace(chr($i), "", $res );
}
$res = str_replace(chr(127), "", $res );
if (0 === strpos(bin2hex($res ), 'efbbbf')) {
$res = substr($res , 3);
}
//supprimer UTF-8-BOM
$res = json_decode($res ,true);
if($res != null){
$total = count($res['virdi'])+count($res['sis_smarti']);
echo "<p id='nbLigneResultat'>".$total." ligne(s) </p>";
echo "<div onclick=\"exportThisWithParameter('tabcenter', 'logs.xls')\" style=\"cursor: pointer; border: 1px solid #ccc; text-align: center;width:19%;\">Exporter Vers Excel</div>";
echo '<table id="tabcenter" class="tab_cadrehov">';
echo '<thead>
<tr>
<td>Date</td>
<td>Temps</td>
<td>Mtricule</td>
<td>Terminal ID</td>
<td>Unité</td>
</tr>
</thead>
<tbody >';
$dictionary = ["1"=>"Technical area" ,
"/192.168.11.2"=>"MALE CHANGE-1" ,
"/192.168.11.5"=>"VISITOR ENTRY" ,
"/192.168.11.6"=>"FEMALE CHANGE ROOM" ,
"/192.168.11.7"=>"PASSAGE-A" ,
"/192.168.11.19"=>"SPM IN & FG OUT" ,
"/192.168.11.20"=>"DAY STORE" ,
"/192.168.11.21"=>"CHANGE ROOM 1 (CPA)" ,
"/192.168.11.36"=>"AIRLOCK TO LINEN AREA" ,
"/192.168.11.39"=>"AIRLOCK (ENTRY TO STERILE AREA)" ,
"/192.168.11.40"=>"CHANGE ROOM-1 (APA)" ,
"/192.168.11.51"=>"RETURN CHANGE ROOM-3 (APA)" ,
"/192.168.11.52"=>"AIRLOCK TO SCRAP EXIST"
];
$users = ["0001"=>"BENYAMINA Mohammed",
"0100"=>"MOUSTAPHA (maintenance U1)",
"0101"=>"BOURASE (cordinateur maintenance)",
"0102"=>"CHAREF ( technicien 2 )",
"0103"=>"KADA HANI (supr maintenance OSD)",
"0104"=>"IMADE HMDAOUI (technicien 2)",
"0105"=>"Yogesh vishare",
"0106"=>"Houari zouigh",
"0107"=>"bilal (supr maint U4)",
"2626"=>"RACHID SEBTI ( technicien instru U1)",
"2560"=>"SALIME RAHMANI ( technicien instru U4)",
"2377"=>"HAFFAF CHAHINEZ ( microbiologie)",
"2085"=>"BRAHOU AZZEDINE ( microbiologie)",
"2000"=>"TARMOUL AMINE ( microbiologie)",
"2579"=>"GHAZOUI NARDGESS ( microbiologie)",
"2252"=>"DROUICHE WAFAA ( microbiologie)",
"2180"=>"BENKADA CHAREF ( microbiologie)",
"0016"=>"SAAD NOURDINE (QC)",
"0669"=>"MAZZIZ JAZIA (QC)",
"2421"=>"NESRINE QVM",
"2194"=>"WAFAA QVM",
"2434"=>"AHMED QVM",
"1699"=>"ALI (maintenance )",
"2236"=>"DJALLAL (Operateur)",
"2209"=>"OUSSAMA (Operateur)",
"0810"=>"TOUHAMI (maintenance)",
"0788"=>"MAHMOUD (maintenance )",
"9999"=>"BOUSBA YASMINE (QVM orien lab )",
"1072"=>"RIMA (MANAGER QA)",
"2020"=>"GHANEM MANAGER U5",
"2021"=>"ARKILICHE(QVM orien lab )",
"1948"=>"ABD EL HADI (MANAGER U4)",
"2635"=>"GHOMARI YOUNES ( microbiologie)",
"2631"=>"GRINE MOHAMMED AMINE (microbiologie)",
"2624"=>"KHELEF IMEN ( microbiologie)",
"2376"=>"MAZEDA ASSIA ( microbiologie)"];
if(is_array($res) && count($res) > 0 ){
foreach ($res['sis_smarti'] as $row['sis_smarti']) {
//$name = fullname($row['sis_smarti']['uid']);
//$name = $name==null ? $row['sis_smarti']['uid'] : $name ;
$name = array_key_exists($row['sis_smarti']['uid'],$users) ? $users[$row['sis_smarti']['uid']] : $row['sis_smarti']['uid'];
$host = array_key_exists($row['sis_smarti']['host'],$dictionary) ? $dictionary[$row['sis_smarti']['host']] : $row['sis_smarti']['host'];
echo '
<tr>
<td>'.$row['sis_smarti']['date'].'</td>
<td>'.$row['sis_smarti']['time'].'</td>
<td>'.$name.'</td>
<td>'.$host.'</td>
<td>Unité 01</td>
</tr> ';
}
foreach ($res['virdi'] as $row['virdi']) {
$y = substr($row['virdi']['C_Date'],0,-4);
$d = substr($row['virdi']['C_Date'],6);
$m = substr($row['virdi']['C_Date'],4,-2);
$hour = substr($row['virdi']['C_Time'],0,-4);
$minute = substr($row['virdi']['C_Time'],2,-2);
$second = substr($row['virdi']['C_Time'],4);
//$name = fullname($row['virdi']['L_UID']);
//$name = $name==null ? $row['virdi']['L_UID'] : $name ;
$mat = str_pad($row['virdi']['L_UID'],4,0,STR_PAD_LEFT);
$name = array_key_exists($mat,$users) ? $users[$mat] : $mat;
$host = array_key_exists($row['virdi']['L_TID'],$dictionary) ? $dictionary[$row['virdi']['L_TID']] : $row['virdi']['L_TID'];
echo '
<tr>
<td>'.$y.'-'.$m.'-'.$d.'</td>
<td>'.$hour.':'.$minute.':'.$second.'</td>
<td>'.$name.'</td>
<td>'.$host.'</td>
<td>Unité 01</td>
</tr> ';
}
}
echo '</tbody>
</table>';
}
}
if (Session::getCurrentInterface() == "helpdesk") {
Html::helpFooter();
} else {
Html::footer();
}
?>
<script>
var childerns = <?php echo json_encode($res); ?>;
console.log(childerns);
var exportThisWithParameter = (function () {
var uri = 'data:application/vnd.ms-excel;base64,',
template = '<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns="http://www.w3.org/TR/REC-html40"><meta http-equiv=Content-Type content="text/html; charset=utf-8"><head><!--[if gte mso 9]><xml><x:ExcelWorkbook><x:ExcelWorksheets> <x:ExcelWorksheet><x:Name>{worksheet}</x:Name> <x:WorksheetOptions><x:DisplayGridlines/></x:WorksheetOptions> </x:ExcelWorksheet></x:ExcelWorksheets></x:ExcelWorkbook> </xml><![endif]--></head><body> <table>{table}</table></body></html>',
base64 = function (s) {
return window.btoa(unescape(encodeURIComponent(s)))
},
format = function (s, c) {
return s.replace(/{(\w+)}/g, function (m, p) { return c[p]; })
}
return function (tableID, excelName) {
tableID = document.getElementById(tableID)
var ctx = { worksheet: excelName || 'Worksheet', table: tableID.innerHTML }
// window.location.href = uri + base64(format(template, ctx))
var link = document.createElement("a");
link.download = excelName;
//link.charset = 'utf-8';
link.href = uri + base64(format(template, ctx));
link.click();
}
})()
</script>