85 lines
2.1 KiB
PHP
85 lines
2.1 KiB
PHP
<?php
|
|
defined('BASEPATH') OR exit('No direct script access allowed');
|
|
|
|
class AttendanceWebhook extends CI_Controller {
|
|
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
|
|
date_default_timezone_set('Asia/Jakarta');
|
|
}
|
|
|
|
public function cdata()
|
|
{
|
|
// =========================
|
|
// AMBIL SN MESIN
|
|
// =========================
|
|
$sn = $this->input->get('SN');
|
|
|
|
// =========================
|
|
// RAW BODY DARI MESIN
|
|
// =========================
|
|
$body = file_get_contents('php://input');
|
|
|
|
// =========================
|
|
// LOG DIRECTORY
|
|
// =========================
|
|
$logDir = APPPATH . 'logs/fingerprint/';
|
|
|
|
if (!is_dir($logDir)) {
|
|
mkdir($logDir, 0777, true);
|
|
}
|
|
|
|
// =========================
|
|
// FILE LOG
|
|
// =========================
|
|
$logFile = $logDir . date('Y-m-d') . '.log';
|
|
|
|
// =========================
|
|
// FORMAT LOG HEADER
|
|
// =========================
|
|
$logText = "\n==================================================\n";
|
|
$logText .= "TIME : " . date('Y-m-d H:i:s') . "\n";
|
|
$logText .= "SN : " . $sn . "\n";
|
|
$logText .= "IP : " . $this->input->ip_address() . "\n";
|
|
$logText .= "DATA : \n";
|
|
|
|
// =========================
|
|
// PARSE BARIS ABSENSI
|
|
// =========================
|
|
$lines = explode("\n", trim($body));
|
|
|
|
foreach ($lines as $line) {
|
|
|
|
$line = trim($line);
|
|
|
|
if (empty($line)) {
|
|
continue;
|
|
}
|
|
|
|
$logText .= $line . "\n";
|
|
|
|
// contoh parsing
|
|
$data = explode("\t", $line);
|
|
|
|
/*
|
|
hasil biasanya:
|
|
[0] => PIN/User ID
|
|
[1] => Datetime
|
|
[2] => Status
|
|
*/
|
|
|
|
}
|
|
|
|
// =========================
|
|
// SIMPAN LOG
|
|
// =========================
|
|
file_put_contents($logFile, $logText, FILE_APPEND);
|
|
|
|
// =========================
|
|
// RESPONSE KE MESIN
|
|
// =========================
|
|
echo "OK";
|
|
}
|
|
} |