Update besar apk finance
This commit is contained in:
@@ -15,12 +15,29 @@ class AttendanceWebhook extends CI_Controller {
|
||||
// =========================
|
||||
// AMBIL SN MESIN
|
||||
// =========================
|
||||
$sn = $this->input->get('SN');
|
||||
$sn = trim((string) $this->input->get('SN', true));
|
||||
if ($sn === '' || !preg_match('/^[A-Za-z0-9._-]{1,100}$/', $sn)) {
|
||||
show_error('Serial number perangkat tidak valid.', 400);
|
||||
}
|
||||
|
||||
$allowedSerials = array_filter(array_map('trim', explode(',', (string) getenv('ATTENDANCE_ALLOWED_SERIALS'))));
|
||||
if (!empty($allowedSerials) && !in_array($sn, $allowedSerials, true)) {
|
||||
log_message('error', 'Attendance webhook ditolak untuk SN: ' . $sn);
|
||||
show_error('Perangkat tidak terdaftar.', 403);
|
||||
}
|
||||
|
||||
if (ENVIRONMENT === 'production' && empty($allowedSerials)) {
|
||||
log_message('error', 'ATTENDANCE_ALLOWED_SERIALS belum dikonfigurasi di production.');
|
||||
show_error('Konfigurasi perangkat belum tersedia.', 503);
|
||||
}
|
||||
|
||||
// =========================
|
||||
// RAW BODY DARI MESIN
|
||||
// =========================
|
||||
$body = file_get_contents('php://input');
|
||||
$body = file_get_contents('php://input', false, null, 0, 1048576);
|
||||
if ($body === false) {
|
||||
show_error('Payload tidak dapat dibaca.', 400);
|
||||
}
|
||||
|
||||
// =========================
|
||||
// LOG DIRECTORY
|
||||
@@ -28,7 +45,7 @@ class AttendanceWebhook extends CI_Controller {
|
||||
$logDir = APPPATH . 'logs/fingerprint/';
|
||||
|
||||
if (!is_dir($logDir)) {
|
||||
mkdir($logDir, 0777, true);
|
||||
mkdir($logDir, 0750, true);
|
||||
}
|
||||
|
||||
// =========================
|
||||
@@ -58,7 +75,7 @@ class AttendanceWebhook extends CI_Controller {
|
||||
continue;
|
||||
}
|
||||
|
||||
$logText .= $line . "\n";
|
||||
$logText .= str_replace(array("\r", "\0"), '', $line) . "\n";
|
||||
|
||||
// contoh parsing
|
||||
$data = explode("\t", $line);
|
||||
@@ -75,11 +92,11 @@ class AttendanceWebhook extends CI_Controller {
|
||||
// =========================
|
||||
// SIMPAN LOG
|
||||
// =========================
|
||||
file_put_contents($logFile, $logText, FILE_APPEND);
|
||||
file_put_contents($logFile, $logText, FILE_APPEND | LOCK_EX);
|
||||
|
||||
// =========================
|
||||
// RESPONSE KE MESIN
|
||||
// =========================
|
||||
echo "OK";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user