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/devices/ drwxrwxrwx | |
| Viewing file: Select action/file-type: const ZKLib = require("zklib-js");
var { client } = require("../redisClient");
const axios = require("axios").default;
const port = 4370;
const token =
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6NCwiaWF0IjoxNjYyNTQ1NjY3LCJleHAiOjE5NzgxMjE2Njd9.5lVlCpiqLqBmdASH-06JubosdJ4jmHwqkepXIkaGr3E";
const test = async () => {
let zkInstance = new ZKLib("192.168.0.91", 4370, 5200, 5000);
try {
// Create socket to machine
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") {
}
}
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: new Date(),
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
const visitors = await axios.get(
"http://127.0.0.1:1337/visitors?phone=" + object.phone,
{
headers: {
Authorization: "Bearer " + token,
},
}
);
console.log(visitors.data[0].id);
if (visitors.data[0].id) {
await axios.put(
"http://127.0.0.1:1337/visitors/" + visitors.data[0].id,
{
status: 3,
},
{
headers: {
Authorization: "Bearer " + token,
},
}
);
}
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));
var logs = await axios.get(
"http://127.0.0.1:1337/logs?card_no=" +
object.card_no +
"&user_id=" +
data.userId +
"&_sort=id:DESC&_limit=1&returned=0",
{
headers: {
Authorization: "Bearer " + token,
},
}
);
if (logs) {
await axios.put(
"http://127.0.0.1:1337/logs/" + logs.data[0].id,
{
out_time: new Date(),
},
{
headers: {
Authorization: "Bearer " + token,
},
}
);
}
// })
// .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: new Date(),
status: "IN",
};
const logsBody = {
card_no: object.card_no,
user_id: data.userId,
image: object.image,
visitor_name: object.visitor_name,
entry_time: new Date(),
phone: object.phone,
departments: object.department,
employee: object.employee,
};
const visitors = await axios.get(
"http://127.0.0.1:1337/visitors?phone=" + object.phone,
{
headers: {
Authorization: "Bearer " + token,
},
}
);
console.log(visitors.data[0].id);
if (visitors.data[0].id) {
await axios.put(
"http://127.0.0.1:1337/visitors/" + visitors.data[0].id,
{
status: 2,
},
{
headers: {
Authorization: "Bearer " + token,
},
}
);
}
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");
}
});
});
};
test();
|
:: Command execute :: | |
--[ c99shell v. 2.5 [PHP 8 Update] [24.05.2025] | Generation time: 0.0049 ]-- |