Software: Apache/2.4.41 (Ubuntu). PHP/8.0.30 uname -a: Linux apirnd 5.4.0-204-generic #224-Ubuntu SMP Thu Dec 5 13:38:28 UTC 2024 x86_64 uid=33(www-data) gid=33(www-data) groups=33(www-data) Safe-mode: OFF (not secure) /var/www/html/beximco/mrp/mrp/checking/ drwxrwxrwx | |
| Viewing file: Select action/file-type: const ZKLib = require("zklib-js");
var { client } = require("./redisClient");
const axios = require("axios").default;
const token =
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6NCwiaWF0IjoxNjYyNTQ1NjY3LCJleHAiOjE5NzgxMjE2Njd9.5lVlCpiqLqBmdASH-06JubosdJ4jmHwqkepXIkaGr3E";
const test = async () => {
let zkInstance = new ZKLib("192.168.31.132", 4370, 5200, 5000);
try {
// Create socket to machine
let zk = await zkInstance.createSocket();
// Get general info like logCapacity, user counts, logs count
// It's really useful to check the status of device
console.log(await zkInstance.getInfo());
} catch (e) {
console.log(e);
if (e.code === "EADDRINUSE") {
}
}
// const z = await zkInstance.getTime();
// console.log(z.toString());
await zkInstance.getRealTimeLogs((data) => {
// do something when some checkin
console.log(data);
client.exists(data.userId, async function (err, reply) {
if (reply === 1) {
client.hgetall(data.userId, async function (err, object) {
if (object.att_time) {
var current_date = new Date();
if (
Date.parse(current_date) > Date.parse(object.double_punch_time)
) {
console.log(current_date);
console.log(object.double_punch_time);
console.log("Exists!");
const databody = {
card_no: object.card_no,
image: object.image,
user_id: data.userId,
visitor_name: object.visitor_name,
time: data.attTime,
status: "OUT",
};
await axios
.delete(
`http://127.0.0.1:1337/visitors/user_id=${data.userId}`,
{
headers: {
Authorization: `Bearer ${token}`,
},
}
)
.then(async function (response) {
// handle success
await axios.post(
`http://127.0.0.1:1337/registered-logs`,
databody,
{
headers: {
Authorization: `Bearer ${token}`,
},
}
);
console.log(response.data);
await zkInstance.deleteUser(parseInt(object.uid));
})
.catch(function (error) {
// handle error
console.log(error.message);
});
} else {
console.log(current_date);
console.log(object.double_punch_time);
console.log("DOUBLE PUNCH");
}
} else {
console.log("ENTRY");
let e_dt = new Date();
e_dt.setSeconds(e_dt.getSeconds() + 15);
var end_date = e_dt.toISOString(); //interval end time
client.hmset(data.userId, {
att_time: data.attTime,
double_punch_time: end_date,
});
const databody = {
card_no: object.card_no,
image: object.image,
user_id: data.userId,
visitor_name: object.visitor_name,
time: data.attTime,
status: "IN",
};
const logsBody = {
card_no: object.card_no,
user_id: data.userId,
visitor_name: object.visitor_name,
entry_time: data.attTime,
phone: object.phone,
department: object.department,
employee: object.employee,
};
await axios.post(
`http://127.0.0.1:1337/registered-logs`,
databody,
{
headers: {
Authorization: `Bearer ${token}`,
},
}
);
await axios.post(`http://127.0.0.1:1337/logs`, logsBody, {
headers: {
Authorization: `Bearer ${token}`,
},
});
}
});
} else {
console.log("no data in redis");
}
});
});
// Get Attendance size
// const s = await zkInstance.getAttendanceSize();
// console.log(s);
// async function setuser() {
// await zkInstance.setUser(14, "12", "testing", "111", 0, 123);
// }
// setuser();
// setuser();
// Get users in machine
// const users = await zkInstance.getUsers();
// console.log(users);
// // Get the current Time in the machine
// Create new user: setUser(uid, userid, name, password, role = 0, cardno = 0)
// var result = await zkInstance.setUser(
// 1655391976,
// "16553919",
// "sazzad",
// "sss",
// 0,
// 3895782
// );
// console.log(result);
// await zkInstance.deleteUser(13);
// // Get all logs in the machine
// // Currently, there is no filter to take data, it just takes all !!
// const logs = await zkInstance.getAttendances(function () {
// if (err) throw err;
// console.log("Very cool!");
// });
// console.log(await zkInstance.getAttendances());
// // You can also read realtime log by getRealTimelogs function
// Delete the data in machine
// Note: You should do this when there are too many data in the machine,
// this issue can slow down machine.
// zkInstance.clearAttendanceLog();
// // Disconnect the machine ( don't do this when you need realtime update :)))
// await zkInstance.disconnect();
};
test();
// in the end we execute the function
|
:: Command execute :: | |
--[ c99shell v. 2.5 [PHP 8 Update] [24.05.2025] | Generation time: 0.0059 ]-- |