forked from vodvud/php_zklib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sync.php
50 lines (43 loc) · 1.05 KB
/
sync.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<?php
include('zklib/ZKLib.php');
date_default_timezone_set('Asia/Manila'); //Default Timezone
$users = [];
//Main device
$zk = new ZKLib('192.168.5.166');
$ret = $zk->connect();
if ($ret) {
$zk->disableDevice();
//Get users
$users = $zk->getUser();
$zk->enableDevice();
}
$zk->disconnect();
if (count($users) > 0) {
//Sync devices list
$devices = [
'192.168.5.167',
'192.168.5.163'
];
foreach ($devices as $ip) {
$zk = new ZKLib($ip);
$ret = $zk->connect();
if ($ret) {
$zk->disableDevice();
//Remove old users
$zk->clearUsers();
foreach ($users as $user) {
//Add user
echo $zk->setUser(
$user['uid'],
$user['userid'],
$user['name'],
$user['password'],
$user['role']
);
}
$zk->enableDevice();
}
$zk->disconnect();
}
$zk->setTime(date('Y-m-d H:i:s'));
}