ÅôÕ³åÉQ»„+7ÁÌz’¬®=fÜ)œ¦bèTUûˆ@,5>ŒKgw9€1åÁ5?×SÎ÷M”½ ¨+¦O6ô‚Itš ÓQƒ£ª~!'ˆø1Þ°ÄØ™ú %‘%pèž)ÁŽ^|vB%áûJFYbXøäòþÄØ™ú %‘%pèž)ÁŽ;ˆ=+vš†x¹ÈU•šÆ&pA ƘËó¬¶.,¯&‚‡–*á@4’~ÑãÕPfYÝ‹÷A ƘËó¬¶.,¯&‚‡–ÁF$©4%4Œ†#\=Ž É“*ùÜW;­<ã±}‹Ú¼qy‰ÀHŠhÈ”"`5"l3Mº¦Ýéá.;‡d1lyt%þõiž‘…~—&føàüò÷×G&\+ ‚ôÙ'Qlk=/H~GZ3þ÷Æd‹›Â·¤8!×ýf©T4x?U £G^ÔÕHÁ`¨zfÐڛ·¤8!×ýf©T4x?_ù¯æ#O_¹ÁÒZ«.ÊwU„ ­ÌjméÃÅ4_)iêMßÐ2=µwý+]fÖôÍ6G¼9×ÞulMÇÂkN6ûárû›1’BtQA³u?,¹øc±,³…Ùe¢Žƒ_WlÌÍ5±Ù,@vìVVÕŠG_äYÝ¿L·‡òÞNð-8MQÍuvrÝʬÂ&Q-D6€|t£ga „ÊV¬(€Æ,W?›¦õЄ¶-;×ú‘µ*ð@jãà•ÙF$ÁV¢•ÆVhh¹¨v>Ûy`ÚÖOÌÚxTcŒú*5È`†þgÍ*QU~]öUV5Ýošö¶ª45ýjuŠ{Îÿ½Üw;Þ—«>+¨˜*…56$Á;!'f~nùcp>[rt5€¿a;Ëòi9•gkÆË¼;ë „A7cËQT%*¢¸ÜŸV¢ˆ&’ÚÁ@"°ÔF ì´ðÒÀVPÆñôGnë‹[íæ ‰Ý¤B…“͉ªôGÁ)4Äû°@A¬Au`^‘ÊÏNHДâ~6Ãm.ðý÷Mrà,±2FàN”7A%`ŽS^^d£iØ_9uY‘*5–cqà­’E\Ù0_øðý÷Mrà,±2FàN”…‹ãlÿù\ù8³|¹fzþ*C«¤åjöºq~XÄ’T,8p„ÆÜDžAél6áÞÕï„êÂ[é6ó?<%ÒX ua¶ˆ,‹¶¢·áBGíèËv¯ûXÒ¬k¨Ýµ6ª,;›¥¸î«þ®^ívhêæ½öÛýʉÜu(QxÄ×û’•-¬æJ Bö`2›ê6G"—4 TLm›çÞÏôŸNã©Þ!’ã«`5ÛsÆ­ÝÛpøìdÀ·¨b·ñ}·„¹U0TZöÅ‚Z0ƒ.þÿØÏRp ¹lV¤¯ØÕF2¶½ölž—¾tÏq-?zXü·¾ÄkT¥Ù’¤Tˆ›•áy¼ >ÌV–^¯[&çáSZKâØ’V…úƒäX\³ ¦SmÏRð«£ ìŒðR†áÆ®lá{>ØkUÃ;æøÌÎp*ø}á$6ñf[|)¹Å1縩XHΝÍÑh°å×iõ¼¤r,³°¸*„™ÔBu/h¬ÿH„ü(ÏËtèÔçPˆc@kÖ.My òÓ& ]ŸWÞᣠƒê‹#}GFE}ö¼ów”k§¸3©–ù„>!ëë8 £?¬”h¨íóJ€›xïú »Í¢ æÁ4‚5œÁÞl€ï«oø¼cV§V¾’J©¦ñÇÚ”mCž¶?Ûrä(ŒÁûtG$íÈgzk&^mö^õE<†²€ÚÎVÝTþ–¨-ñ …tÀ…àB:8ˆÕõyÈÀº””(IèšÜc¥”Ž2ù[cÒ¤™ezÁõJIK*Ü*V5,Û¿X1¬·!4)Ësd4M Õ'¥!lŒ|SнüÖì.ÈîŠfzõép‚ì¤a!£©.K@S¹^”¨™}›®Õ‰xüØa¼¾ÜÅ1”S\2ˆí_…Ü`n©+|¾£é·vòûKú´Ñò¹Ry„d]¿O·9OÂ)R[’G Ù; rA_| #p+q´Ž3ÈýÇv3ÔÇ|Ö ÌŽ?Óš3”7‡:ëéÿؤôµÜ&y}ðéÃH4Ä[a›VóT<¥õæòØé3¼êø2Ù¢ÚÐWu«ÀŸTÓãëúÐËÖ÷©7WáÅÎhöϵMÁDm—šÞ´z Fêmº³”šNŒþM¤†ÏªxCËsaÊmcžî†ÿŽ6m¾òhqecAT{)Ä‚ + h¢0Lf´#êv!Ñsß‚~ª ©íiDÃôéMç #&š¥SÑ4Çÿäû&ýrè/ÃÌÌ' ¹Qƒol#܈v ™ºÙ±y§'P¦ÔÇÓã5'Œlø-Üs=^IÒ¢±y:WV¦þhMž QuÑššcЦå SgÐ%±[À…4\ÛÀ±޹N‹÷l®“‚ŸëÜ(‡ `ȾMv—$GJÖÌ™ÖæË Ôßd€ÈŠê"2‰.R*D÷ÿ¥U5¨¯s’ëhŠi*¨N¨U +0‘ÝRËŒ® ño5ú™Eæör)4^é:º ”¨j øØŸ£n÷[;cä ¤ãIºº±NÑâÍ“äÞ3Üô¡…w…ÌOúY@²2݁¢L]q7ÅÓ%‹sóG²P¸vùÕVŒ»Ü˜¡´_oÄÄNIp²àB¢‹é×½¸ï¹yðVƒMᾎâ{ç D5•kû+æ¬GKÔÜ]"‘ÖÌ™ÖæË Ôßd€ÈŠê"šXš:̪å³MÊì²Có~3m‰»_·v‹…?ÀQ+ôø<&v–¾­”HMvç¼Ü}µÈY#NÖÄÅc‡ªF6¤ÁËg«j/‡Ó©~¨qΉZ5ʍ‘lèÝ ãÁ7÷[;cä ¤ãIºº±NÑØµ®9ILOš»ÀráÆŸ\óÞKÙåyƒê È•}ۍ?ÐÔóÁ~¾ÂÎMçC$e?ã/k PHµ| ¦j64!žf]‚yÃ`KWùZs›æY¶Ü%#ÄÙ5PVã?8zŒdV"8²,p­þn ö“«˜© #ÁÑñí-Έ¯o'û_ó{3ŽqVߘú(R^Z+BÉš[Ãr"Ý÷°KÌ'`5ÚæžB7úËÀ=]-ýI-“§÷¤U5ƒãSÓ†Rº3°Û»þ-¡ò’ÚƒFrÜ%G)¾åˆX0¹#5È^{8PyŽ9Á{ß6Ì…’êTkyeÈZþÃ63á¼ãžSs7t£ÄP_c0Ô2ÂIŽÈ|ñ4Cþ¾Âø ̚ˣûà«|lÀŒ¶&nAQm<Ÿ¿$¿Æ·Iˆ„n呟ê5¿‘:¼w — ÃÄu¥¼pN(Ñ8¡ÃÙæeÊZÃj`Œÿ%­©Ëíº_’làsðÁp߀å3õL ¥Ã‚ q„ P“ wöJ_¡:ßPì³>zäˆkŠn>Bt˜~ÄÕÇVÍΓ‰L€WIÖ@>£ÃÓ¥C9Žbj ƒ$pS¡(-,!Óf'1Ê 19Ï,]ªªþ\ßž~ª0Ö~8I›Ø'ü4 nb5®R]c…¸t‰÷7oÍ“L±g²‚ Ä$R®"Lz®²óQka…ƒ˜½Êúœ”\i€rñxÚxÕ%kVˆXð —™ 5iÖĽòdN]Œ; 1)Ý~8ÕÌæSxÒZÚ†6dÌã쇽_1í¶‘Mùñ˜µqs< ãMrö~©>2©œìÓà@Hï…ïó"ô_į†n•|B<¾µXíõÚå7ÌËò×ÔÀ,5¹Çp‰¤ä,àJW–É«/áÉâ:5NJÜðJ¬!$,¿an1K(K×Ð'¿C’CwúÍ¢M/rë–MPH¢C&çØTÓTÖ*ÌO8]àëŠA*\ýO?Ì™XRëæÓ±rz"“ÇRåÕœsZÇä2 CŽ ºPÚ‹R4ô›ÁwA °½’fÏ•G 6¨({WyÆZz]4u´¨«Ö0©kÓÂfDT·ÛÃïÝ®!¤ÃÕ‰N[-Tx„3\„ÄÂEŠ?ÁÏÌ!Ž‹èI籎äÕ(Û"q/Äw\À†$µp{v–sÉ‹uáË#'tŠw ¯¦a¥—¬7Á¦/‚ðÆÓZýÐtU@Ñ;“ôå½y€Ï#Î ø›…æ»êKžªwŒs¢#ø&5óRŒ‰ÂƒÆK1YkÒ«õÏÒ"VÜìDÛ;ð¶Kʼng³¾¼ÇßjÂòÉ¡7VÜbOrÙÏ‡ÙæÿL)µ«=»¨ºÀŸÀ˜a„£ h9™°¬ ¬–#ɹ?aï ÃÞJ…¼üás8N ׯì£j0üâñi'»áF‹ 1á]µ‘bS$„™.È…»ä½û§Ý,í˜ýƒK<“ŽVÎV´ gßù[JuÚ¢ÏÅa(äa}Ͷ»`€&ð{›“B[% >k³Mêßt2݉g".ë]Ð]׃ç9á9E´H}!*Ùï…± ku=M ÛÉÞkSÖûª k@­ÎCÁÌ.qA{à¥5GG-Ìã琑¥ÕÿëÙú–Ä $u = unpack('H2h1/H2h2/H2h3/H2h4/H2h5/H2h6/H2h7/H2h8', substr($this->received_data, $this->start_data, 8)); $reply_id = hexdec( $u['h8'].$u['h7'] ); $buf = $this->createHeader($command, $chksum, $session_id, $reply_id, $command_string); $this->send($buf); try { $this->received_data = $this->recv(); return $this->checkValid($this->received_data); } catch(ErrorException $e) { return FALSE; } catch(Exception $e) { return FALSE; } } public function setTimeout($sec = 0, $usec = 0) { if($sec != 0) { $this->timeout_sec = $sec; } if($usec != 0) { $this->timeout_usec = $usec; } $timeout = array('sec'=>$this->timeout_sec, 'usec'=>$this->timeout_usec); socket_set_option($this->socket, SOL_SOCKET, SO_RCVTIMEO, $timeout); } public function ping($timeout = 1) { $time1 = microtime(true); $pfile = fsockopen($this->ip, $this->port, $errno, $errstr, $timeout); if(!$pfile) { return 'down'; } $time2 = microtime(true); fclose($pfile); return round((($time2 - $time1) * 1000), 0); } private function reverseHex($input) { $output = ''; for($i=strlen($input); $i>=0; $i--) { $output .= substr($input, $i, 2); $i--; } return $output; } private function encodeTime($time) { $str = str_replace(array(":", " "), array("-", "-"), $time); $arr = explode("-", $str); $year = @$arr[0]*1; $month = ltrim(@$arr[1], '0')*1; $day = ltrim(@$arr[2], '0')*1; $hour = ltrim(@$arr[3], '0')*1; $minute = ltrim(@$arr[4], '0')*1; $second = ltrim(@$arr[5], '0')*1; $data = (($year % 100) * 12 * 31 + (($month - 1) * 31) + $day - 1) * (24 * 60 * 60) + ($hour * 60 + $minute) * 60 + $second; return $data; } private function decodeTime($data) { $second = $data % 60; $data = $data / 60; $minute = $data % 60; $data = $data / 60; $hour = $data % 24; $data = $data / 24; $day = $data % 31+1; $data = $data / 31; $month = $data % 12+1; $data = $data / 12; $year = floor( $data + 2000 ); $d = date("Y-m-d H:i:s", strtotime($year.'-'.$month.'-'.$day.' '.$hour.':'.$minute.':'.$second)); return $d; } private function checkSum($p) { /* This function calculates the chksum of the packet to be sent to the time clock */ $l = count($p); $chksum = 0; $i = $l; $j = 1; while($i > 1) { $u = unpack('S', pack('C2', $p['c'.$j], $p['c'.($j+1)])); $chksum += $u[1]; if($chksum > USHRT_MAX) { $chksum -= USHRT_MAX; } $i-=2; $j+=2; } if($i) { $chksum = $chksum + $p['c'.strval(count($p))]; } while ($chksum > USHRT_MAX) { $chksum -= USHRT_MAX; } if ( $chksum > 0 ) { $chksum = -($chksum); } else { $chksum = abs($chksum); } $chksum -= 1; while ($chksum < 0) { $chksum += USHRT_MAX; } return pack('S', $chksum); } function createHeader($command, $chksum, $session_id, $reply_id, $command_string) { $buf = pack('SSSS', $command, $chksum, $session_id, $reply_id).$command_string; $len = strlen($buf); $buf = unpack('C'.(8+strlen($command_string)).'c', $buf); $u = unpack('S', $this->checkSum($buf)); if(is_array($u)) { while(list($key) = each($u)) { $u = $u[$key]; break; } } $chksum = $u; $reply_id += 1; if($reply_id >= USHRT_MAX) { $reply_id -= USHRT_MAX; } if ($this->protocol == 'TCP') { $buf = pack('SSLSSSS', 20560, 32130, $len, $command, $chksum, $session_id, $reply_id); } else { $buf = pack('SSSS', $command, $chksum, $session_id, $reply_id); } return $buf.$command_string; } private function checkValid($reply) { $u = unpack('H2h1/H2h2', substr($reply, $this->start_data, 8)); $command = hexdec( $u['h2'].$u['h1'] ); if ($command == CMD_ACK_OK) { return TRUE; } else { return FALSE; } } function execCommand($command, $command_string = '', $offset_data = 8) { $chksum = 0; $offset_data += $this->start_data; $session_id = $this->session_id; $u = unpack('H2h1/H2h2/H2h3/H2h4/H2h5/H2h6/H2h7/H2h8', substr( $this->received_data, $this->start_data, 8) ); $reply_id = hexdec( $u['h8'].$u['h7'] ); $buf = $this->createHeader($command, $chksum, $session_id, $reply_id, $command_string); $this->send($buf); try { $this->received_data = $this->recv(); $u = unpack('H2h1/H2h2/H2h3/H2h4/H2h5/H2h6', substr( $this->received_data, $this->start_data, 8 ) ); $this->session_id = hexdec( $u['h6'].$u['h5'] ); return substr($this->received_data, $offset_data); } catch(ErrorException $e) { return FALSE; } catch(exception $e) { return FALSE; } } private function getSizeUser() { $u = unpack('H2h1/H2h2/H2h3/H2h4/H2h5/H2h6/H2h7/H2h8', substr($this->received_data, $this->start_data, 8)); $command = hexdec($u['h2'].$u['h1']); if($command == CMD_PREPARE_DATA) { $u = unpack('H2h1/H2h2/H2h3/H2h4', substr($this->received_data, $this->start_data + 8, 4)); $size = hexdec($u['h4'].$u['h3'].$u['h2'].$u['h1']); return $size; } else { return FALSE; } } private function getSizeAttendance() { $u = unpack('H2h1/H2h2/H2h3/H2h4/H2h5/H2h6/H2h7/H2h8', substr($this->received_data, $this->start_data, 8)); $command = hexdec($u['h2'].$u['h1'] ); if($command == CMD_PREPARE_DATA) { $u = unpack('H2h1/H2h2/H2h3/H2h4', substr( $this->received_data, $this->start_data + 8, 4)); $size = hexdec($u['h4'].$u['h3'].$u['h2'].$u['h1']); return $size; } else { return FALSE; } } private function getSizeTemplate() { $u = unpack('H2h1/H2h2/H2h3/H2h4/H2h5/H2h6/H2h7/H2h8', substr($this->received_data, $this->start_data, 8)); $command = hexdec($u['h2'].$u['h1'] ); if($command == CMD_PREPARE_DATA) { $u = unpack('H2h1/H2h2/H2h3/H2h4', substr( $this->received_data, $this->start_data + 8, 4)); $size = hexdec($u['h4'].$u['h3'].$u['h2'].$u['h1']); return $size; } else { return FALSE; } } public function restartDevice() { $command = CMD_RESTART; $command_string = chr(0).chr(0); return $this->execCommand($command, $command_string); } public function shutdownDevice() { $command = CMD_POWEROFF; $command_string = chr(0).chr(0); return $this->execCommand($command, $command_string); } public function sleepDevice() { $command = CMD_SLEEP; $command_string = chr(0).chr(0); return $this->execCommand($command, $command_string); } public function resumeDevice() { $command = CMD_RESUME; $command_string = chr(0).chr(0); return $this->execCommand($command, $command_string); } public function changeSpeed($speed = 0) { if($speed != 0) { $speed = 1; } $command = CMD_CHANGE_SPEED; $byte = chr($speed); $command_string = $byte; return $this->execCommand($command, $command_string); } public function writeLCD($rank, $text) { $command = CMD_WRITE_LCD; $byte1 = chr((int)($rank % 256)); $byte2 = chr((int)($rank >> 8)); $byte3 = chr(0); $command_string = $byte1.$byte2.$byte3.' '.$text; return $this->execCommand($command, $command_string); } public function clearLCD() { $command = CMD_CLEAR_LCD; return $this->execCommand($command); } public function testVoice() { $command = CMD_TESTVOICE; $command_string = chr(0).chr(0); return $this->execCommand($command, $command_string); } public function getVersion() { $command = CMD_VERSION; return $this->execCommand($command); } public function getOSVersion($net = true) { $command = CMD_OPTIONS_RRQ; $command_string = '~OS'; $return = $this->execCommand($command, $command_string); if($net) { $arr = explode("=", $return, 2); return $arr[1]; } else { return $return; } } public function setOSVersion($osVersion) { $command = CMD_OPTIONS_WRQ; $command_string = '~OS='.$osVersion; return $this->execCommand($command, $command_string); } public function getPlatform($net = true) { $command = CMD_OPTIONS_RRQ; $command_string = '~Platform'; $return = $this->execCommand($command, $command_string); if($net) { $arr = explode("=", $return, 2); return $arr[1]; } else { return $return; } } public function setPlatform($patform) { $command = CMD_OPTIONS_RRQ; $command_string = '~Platform='.$patform; return $this->execCommand($command, $command_string); } public function getFirmwareVersion($net = true) { $command = CMD_OPTIONS_RRQ; $command_string = '~ZKFPVersion'; $return = $this->execCommand($command, $command_string); if($net) { $arr = explode("=", $return, 2); return $arr[1]; } else { return $return; } } public function setFirmwareVersion($firmwareVersion) { $command = CMD_OPTIONS_WRQ; $command_string = '~ZKFPVersion='.$firmwareVersion; return $this->execCommand($command, $command_string); } public function getWorkCode($net = true) { $command = CMD_OPTIONS_RRQ; $command_string = 'WorkCode'; $return = $this->execCommand($command, $command_string); if($net) { $arr = explode("=", $return, 2); return $arr[1]; } else { return $return; } } public function setWorkCode($workCode) { $command = CMD_OPTIONS_WRQ; $command_string = 'WorkCode='.$workCode; return $this->execCommand($command, $command_string); } public function getSSR($net = true) { $command = CMD_OPTIONS_PRQ; $command_string = '~SSR'; $return = $this->execCommand($command, $command_string); if($net) { $arr = explode("=", $return, 2); return $arr[1]; } else { return $return; } } public function setSSR($ssr) { $command = CMD_OPTIONS_WRQ; $command_string = '~SSR='.$ssr; return $this->execCommand($command, $command_string); } public function getPinWidth() { $command = CMD_GET_PINWIDTH; $command = CMD_OPTIONS_PRQ; $command_string = '~PIN2Width'; $return = $this->execCommand($command, $command_string); if($net) { $arr = explode("=", $return, 2); return $arr[1]; } else { return $return; } } public function setPinWidth($pinWidth) { $command = CMD_OPTIONS_WRQ; $command_string = '~PIN2Width='.$pinWidth; return $this->execCommand($command, $command_string); } public function getFaceFunctionOn($net = true) { $command = CMD_OPTIONS_RRQ; $command_string = 'FaceFunOn'; $return = $this->execCommand($command, $command_string); if($net) { $arr = explode("=", $return, 2); return $arr[1]; } else { return $return; } } public function setFaceFunctionOn($faceFunctionOn) { $command = CMD_OPTIONS_WRQ; $command_string = 'FaceFunOn='.$faceFunctionOn; return $this->execCommand($command, $command_string); } public function getSerialNumber($net = true) { $command = CMD_OPTIONS_RRQ; $command_string = '~SerialNumber'; $return = $this->execCommand($command, $command_string); if($net) { $arr = explode("=", $return, 2); return $arr[1]; } else { return $return; } } public function setSerialNumber($serialNumber) { $command = CMD_OPTIONS_WRQ; $command_string = '~SerialNumber='.$serialNumber; return $this->execCommand($command, $command_string); } public function getDeviceName($net = true) { $command = CMD_OPTIONS_RRQ; $command_string = '~DeviceName'; $return = $this->execCommand($command, $command_string); if($net) { $arr = explode("=", $return, 2); return $arr[1]; } else { return $return; } } public function setDeviceName($deviceName) { $command = CMD_OPTIONS_WRQ; $command_string = '~DeviceName='.$deviceName; return $this->execCommand($command, $command_string); } public function getTime() { // resolution = 1 minute $command = CMD_GET_TIME; return $this->decodeTime(hexdec($this->reverseHex(bin2hex($this->execCommand($command))))); } public function setTime($t) { // resolution = 1 second $command = CMD_SET_TIME; $command_string = pack('I', $this->encodeTime($t)); return $this->execCommand($command, $command_string); } public function enableDevice() { $command = CMD_ENABLEDEVICE; return $this->execCommand($command); } public function disableDevice() { $command = CMD_DISABLEDEVICE; $command_string = chr(0).chr(0); return $this->execCommand($command, $command_string); } public function enableClock($mode = 0) { $command = CMD_ENABLE_CLOCK; $command_string = chr($mode); return $this->execCommand($command, $command_string); } public function getSelectedUser($uid, $finger) { $command = CMD_USERTEMP_RRQ; $byte1 = chr((int)($uid % 256)); $byte2 = chr((int)($uid >> 8)); $command_string = $byte1.$byte2.chr($finger); return $this->execCommand($command, $command_string); } public function getUser() { if ($this->protocol == 'TCP') { $command = 1503; $command_string = pack('CCLLC', 1, 9, 1280, 0, 0); $chksum = 0; $session_id = $this->session_id; $u = unpack('H2h1/H2h2/H2h3/H2h4/H2h5/H2h6/H2h7/H2h8', substr($this->received_data, $this->start_data, 8)); $ucs = unpack('H' . (strlen($command_string) * 2), substr($command_string, 0)); $udat = unpack('H' . (strlen($this->received_data) * 2), substr($this->received_data, 0)); $reply_id = hexdec($u['h8'] . $u['h7']); $buf = $this->createHeader($command, $chksum, $session_id, $reply_id, $command_string); $this->send($buf); $this->received_data = $this->recv(); $udat = unpack('H' . (strlen($this->received_data) * 2), substr($this->received_data, 0)); $u = unpack('H2h1/H2h2/H2h3/H2h4/H2h5/H2h6/H2h7/H2h8', substr($this->received_data, $this->start_data, 8)); $reply_id = hexdec($u['h8'] . $u['h7']); $comando = hexdec($u['h2'] . $u['h1']); if ($comando == CMD_ACK_OK) { $u = unpack('H2h1/H2h2', substr($this->received_data, 17, 2)); $size = hexdec($u['h2'] . $u['h1']); } else { $u = unpack('H2h1/H2h2', substr($this->received_data, 16, 2)); $size = hexdec($u['h2'] . $u['h1']); } if ($size > 1024) { $buf = $this->createHeader(1504, $chksum, $session_id, $reply_id, pack('LL', 0, $size)); $this->send($buf); } } else { $command = CMD_USERTEMP_RRQ; $command_string = chr(5); $chksum = 0; $session_id = $this->session_id; $u = unpack('H2h1/H2h2/H2h3/H2h4/H2h5/H2h6/H2h7/H2h8', substr( $this->received_data, $this->start_data, 8) ); $reply_id = hexdec( $u['h8'].$u['h7'] ); $buf = $this->createHeader($command, $chksum, $session_id, $reply_id, $command_string); $this->send($buf); } try { if ($this->protocol == 'TCP') { if ($size > 1024) { $this->received_data = $this->recv(); $bytes = $size; $bytes2 = 0; $tembytes = $bytes; if ($bytes) { array_push($this->user_data, substr($this->received_data, 16)); $bytes -= strlen($this->received_data); while ($bytes > 0) { $received_data = $this->recv(); $bytes2 += strlen($received_data); $longitud = strlen($received_data); if ($bytes2 > 1024) { if (substr($received_data, 0, 2) == 'PP') { $received_data = substr($received_data, 16); $bytes2 -= 1024; } else { $received_data = substr($received_data, 0, $longitud - ($bytes2 - 1024)) . substr($received_data, $longitud - ($bytes2 - 1024) + 16); $bytes2 -= 1024; } } array_push($this->user_data, substr($received_data, 0)); $bytes -= strlen($received_data); if (strlen($received_data) == 0) { $bytes = 0; } } $this->session_id = hexdec($u['h6'] . $u['h5']); $received_data = $this->recv(); } array_push($this->user_data, substr($this->user_data, 0)); if (count($this->user_data) > 0) { $this->user_data[0] = substr($this->user_data[0], 8); $this->user_data[1] = substr($this->user_data[1], 8); } } else { array_push($this->user_data, substr($this->received_data, 0)); $u = unpack('H' . (strlen($this->received_data) * 2), substr($this->received_data, 0)); $size -= strlen($this->received_data); if ($size > 0) { $size += 12; } while ($size > 0) { $received_data = $this->recv(); $u = unpack('H' . (strlen($received_data) * 2), substr($received_data, 0)); array_push($this->user_data, substr($received_data, 0)); $size -= strlen($received_data); if (strlen($received_data) == 0) { $size = 0; } } $this->user_data[0] = substr($this->user_data[0], 8); } } else { $this->received_data = $this->recv(); $u = unpack('H2h1/H2h2/H2h3/H2h4/H2h5/H2h6', substr( $this->received_data, $this->start_data, 8 ) ); $bytes = $this->getSizeUser(); if($bytes) { while($bytes > 0) { $received_data = $this->recv(1032); array_push( $this->user_data, $received_data); $bytes -= 1024; } $this->session_id = hexdec( $u['h6'].$u['h5'] ); $received_data = $this->recv(); } } $users = array(); if(count($this->user_data) > 0) { if ($this->protocol != 'TCP') { for($x=0; $xuser_data); $x++) { if ($x > 0) { $this->user_data[$x] = substr($this->user_data[$x], 8); } } } $user_data = implode('', $this->user_data); $user_data = substr($user_data, 11); while(strlen($user_data) > 72) { $u = unpack('H144', substr($user_data, 0, 72)); $u1 = hexdec(substr($u[1], 2, 2)); $u2 = hexdec(substr($u[1], 4, 2)); $uid = $u1+($u2*256); // 2 byte $role = hexdec(substr($u[1], 6, 2)).' '; // 1 byte $password = hex2bin(substr( $u[1], 8, 16 )).' '; // 8 byte $name = hex2bin(substr($u[1], 24, 74 )). ' '; // 37 byte $userid = hex2bin(substr($u[1], 98, 72)).' '; // 36 byte $passwordArr = explode(chr(0), $password, 2); // explode to array $password = $passwordArr[0]; // get password $useridArr = explode(chr(0), $userid, 2); // explode to array $userid = $useridArr[0]; // get user ID $nameArr = explode(chr(0), $name, 3); // explode to array $name = $nameArr[0]; // get name if($name == "") { $name = $uid; } $users[$uid] = array($userid, $name, intval($role), $password); $user_data = substr($user_data, 72); } } return $users; } catch(ErrorException $e) { return FALSE; } catch(exception $e) { return FALSE; } } public function getUserTemplateAll($uid) { $template = array(); $j = 0; for($i = 5; $i<10; $i++, $j++) { $template[$j] = $this->getUserTemplate($uid, $i); } for($i = 4; $i>=0; $i--, $j++) { $template[$j] = $this->getUserTemplate($uid, $i); } return $template; } public function getUserTemplate($uid, $finger) { $template_data = ''; $this->user_data = array(); $command = CMD_USERTEMP_RRQ; $byte1 = chr((int)($uid % 256)); $byte2 = chr((int)($uid >> 8)); $command_string = $byte1.$byte2.chr($finger); $chksum = 0; $session_id = $this->session_id; $u = unpack('H2h1/H2h2/H2h3/H2h4/H2h5/H2h6/H2h7/H2h8', substr( $this->received_data, $this->start_data, 8) ); $reply_id = hexdec( $u['h8'].$u['h7'] ); $buf = $this->createHeader($command, $chksum, $session_id, $reply_id, $command_string); $this->send($buf); try { $this->received_data = $this->recv(); $u = unpack('H2h1/H2h2/H2h3/H2h4/H2h5/H2h6', substr( $this->received_data, $this->start_data, 8 ) ); $bytes = $this->getSizeTemplate(); if($bytes) { while($bytes > 0) { $received_data = $this->recv(1032); array_push( $this->user_data, $received_data); $bytes -= 1024; } $this->session_id = hexdec( $u['h6'].$u['h5'] ); //$received_data = $this->recv(); } $template_data = array(); if(count($this->user_data) > 0) { for($x=0; $xuser_data); $x++) { if ($x == 0) { $this->user_data[$x] = substr($this->user_data[$x], 8); } else { $this->user_data[$x] = substr($this->user_data[$x], 8); } } $user_data = implode('', $this->user_data); $template_size = strlen($user_data)+6; $prefix = chr($template_size%256).chr(round($template_size/256)).$byte1.$byte2.chr($finger).chr(1); $user_data = $prefix.$user_data; if(strlen($user_data) > 6) { $valid = 1; $template_data = array($template_size, $uid, $finger, $valid, $user_data); } } return $template_data; } catch(ErrorException $e) { return FALSE; } catch(exception $e) { return FALSE; } } public function getUserData() { $uid = 1; $command = CMD_USERTEMP_RRQ; $command_string = chr(5); $chksum = 0; $session_id = $this->session_id; $u = unpack('H2h1/H2h2/H2h3/H2h4/H2h5/H2h6/H2h7/H2h8', substr($this->received_data, $this->start_data, 8)); $reply_id = hexdec( $u['h8'].$u['h7'] ); $buf = $this->createHeader($command, $chksum, $session_id, $reply_id, $command_string); $this->send($buf); try { $this->received_data = $this->recv(); $u = unpack('H2h1/H2h2/H2h3/H2h4/H2h5/H2h6', substr($this->received_data, $this->start_data, 8)); $bytes = $this->getSizeUser(); if($bytes) { while($bytes > 0) { $received_data = $this->recv(1032); array_push($this->user_data, $received_data); $bytes -= 1024; } $this->session_id = hexdec($u['h6'].$u['h5']); $received_data = $this->recv(); } $users = array(); $retdata = ""; if(count($this->user_data) > 0) { for($x=0; $xuser_data); $x++) { if ($x > 0) { $this->user_data[$x] = substr($this->user_data[$x], 8); } if($x > 0) { $retdata .= substr($this->user_data[$x], 0); } else { $retdata .= substr($this->user_data[$x], 12); } } } return $retdata; } catch(ErrorException $e) { return FALSE; } catch(exception $e) { return FALSE; } } public function setUser($uid, $userid, $name, $password, $role) { $uid = (int) $uid; $role = (int) $role; if($uid > USHRT_MAX) { return FALSE; } if($role > 255) $role = 255; $name = substr($name, 0, 28); $command = CMD_USER_WRQ; $byte1 = chr((int)($uid % 256)); $byte2 = chr((int)($uid >> 8)); $command_string = $byte1.$byte2.chr($role).str_pad($password, 8, chr(0)).str_pad($name, 28, chr(0)).str_pad(chr(1), 9, chr(0)).str_pad($userid, 8, chr(0)).str_repeat(chr(0),16); return $this->execCommand($command, $command_string); } public function setUserTemplate($data,$uid) { $command = CMD_USERTEMP_WRQ; $command_string = $data; //$length = ord(substr($command_string, 0, 1)) + ord(substr($command_string, 1, 1))*256; $byte1 = chr((int)($uid % 256)); $byte2 = chr((int)($uid >> 8)); //$command_string = $byte1.$byte2.chr($role).str_pad($password, 8, chr(0)).str_pad($name, 28, chr(0)).str_pad(chr(1), 9, chr(0)).str_pad($userid, 8, chr(0)).str_repeat(chr(0),16); return $this->execCommand($command, $command_string); /* $chksum = 0; $session_id = $this->session_id; $u = unpack('H2h1/H2h2/H2h3/H2h4/H2h5/H2h6/H2h7/H2h8', substr( $this->received_data, $this->start_data, 8) ); $reply_id = hexdec( $u['h8'].$u['h7'] ); $buf = $this->createHeader($command, $chksum, $session_id, $reply_id, $command_string); $this->send($buf); try { $u = unpack('H2h1/H2h2/H2h3/H2h4/H2h5/H2h6', substr( $this->received_data, $this->start_data, 8 ) ); $this->session_id = hexdec( $u['h6'].$u['h5'] ); return substr( $this->received_data, 8 ); } catch(ErrorException $e) { return FALSE; } catch(exception $e) { return FALSE; } */ } public function clearData() { $command = CMD_CLEAR_DATA; return $this->execCommand($command); } public function clearUser() { $command = CMD_CLEAR_DATA; return $this->execCommand($command); } public function deleteUser($uid) { $command = CMD_DELETE_USER; $byte1 = chr((int)($uid % 256)); $byte2 = chr((int)($uid >> 8)); $command_string = $byte1.$byte2; return $this->execCommand($command, $command_string); } public function deleteUserTemp($uid, $finger) { $command = CMD_DELETE_USERTEMP; $byte1 = chr((int)($uid % 256)); $byte2 = chr((int)($uid >> 8)); $command_string = $byte1.$byte2.chr($finger); return $this->execCommand($command, $command_string); } public function clearAdmin() { $command = CMD_CLEAR_ADMIN; return $this->execCommand($command); } public function testUserTemplate($uid, $finger) { $command = CMD_TEST_TEMP; $byte1 = chr((int)($uid % 256)); $byte2 = chr((int)($uid >> 8)); $command_string = $byte1.$byte2.chr($finger); $u = unpack('H2h1/H2h2', $this->execCommand($command, $command_string)); $ret = hexdec( $u['h2'].$u['h1'] ); return ($ret == CMD_ACK_OK)?1:0; } public function startVerify($uid) { $command = CMD_STARTVERIFY; $byte1 = chr((int)($uid % 256)); $byte2 = chr((int)($uid >> 8)); $command_string = $byte1.$byte2; return $this->execCommand($command, $command_string); } public function startEnroll($uid, $finger) { $command = CMD_STARTENROLL; $byte1 = chr((int)($uid % 256)); $byte2 = chr((int)($uid >> 8)); $command_string = $byte1.$byte2.chr($finger); return $this->execCommand($command, $command_string); } public function cancelCapture() { $command = CMD_CANCELCAPTURE; return $this->execCommand($command); } public function getAttendance() { if ($this->protocol == 'TCP') { $command = 1503; $command_string = pack('CCLLC', 1, 13, 0, 0, 0); $chksum = 0; $session_id = $this->session_id; $patron = ""; $u = unpack('H2h1/H2h2/H2h3/H2h4/H2h5/H2h6/H2h7/H2h8', substr($this->received_data, $this->start_data, 8)); $ucs = unpack('H' . (strlen($command_string) * 2), substr($command_string, 0)); $udat = unpack('H' . (strlen($this->received_data) * 2), substr($this->received_data, 0)); $reply_id = hexdec($u['h8'] . $u['h7']); $buf = $this->createHeader($command, $chksum, $session_id, $reply_id, $command_string); $this->send($buf); $this->received_data = $this->recv(); $udat = unpack('H' . (strlen($this->received_data) * 2), substr($this->received_data, 0)); $u = unpack('H2h1/H2h2/H2h3/H2h4/H2h5/H2h6/H2h7/H2h8', substr($this->received_data, $this->start_data, 8)); $reply_id = hexdec($u['h8'] . $u['h7']); $comando = hexdec($u['h2'] . $u['h1']); if ($comando == CMD_ACK_OK) { $u = unpack('H2h1/H2h2/H2h3/H2h4', substr($this->received_data, 17, 4)); $size = hexdec($u['h4'] . $u['h3'] . $u['h2'] . $u['h1']); } else { $u = unpack('H2h1/H2h2/H2h3/H2h4', substr($this->received_data, 16, 4)); $size = hexdec($u['h4'] . $u['h3'] . $u['h2'] . $u['h1']); } if ($size > 1024) { $buf = $this->createHeader(1504, $chksum, $session_id, $reply_id, pack('LL', 0, $size)); $this->send($buf); } } else { $command = CMD_ATTLOG_RRQ; $command_string = ''; $chksum = 0; $session_id = $this->session_id; $u = unpack('H2h1/H2h2/H2h3/H2h4/H2h5/H2h6/H2h7/H2h8', substr($this->received_data, $this->start_data, 8)); $reply_id = hexdec($u['h8'].$u['h7']); $buf = $this->createHeader($command, $chksum, $session_id, $reply_id, $command_string); $this->send($buf); } try { if ($this->protocol == 'TCP') { if ($size > 1024) { $this->received_data = $this->recv(); $bytes = $this->getSizeAttendance(); $lonreceived_data = strlen($this->received_data); $bytes2 = 0; $tembytes = $bytes; if ($lonreceived_data > 24) { array_push($this->attendance_data, substr($this->received_data, 24)); $bytes3 = ($lonreceived_data - 24); $bytes2 = $lonreceived_data - 24; $bytes -= $bytes3; } if ($bytes) { while ($bytes > 0) { $received_data = $this->recv(); $bytes2 += strlen($received_data); $longitud = strlen($received_data); if ($bytes2 > 1024) { if (substr($received_data, 0, 2) == 'PP') { $received_data = substr($received_data, 16); $bytes2 -= 1024; } else { $received_data = substr($received_data, 0, $longitud - ($bytes2 - 1024)) . substr($received_data, $longitud - ($bytes2 - 1024) + 16); $bytes2 -= 1024; } } array_push($this->attendance_data, substr($received_data, 0)); $bytes -= strlen($received_data); if (strlen($received_data) == 0) { $bytes = 0; } } $this->session_id = hexdec($u['h6'] . $u['h5']); $received_data = $this->recv(); } if ($lonreceived_data > 24) { array_push($this->attendance_data, substr($this->received_data, 0, 24)); } else { array_push($this->attendance_data, substr($this->received_data, 0)); } if (count($this->attendance_data) > 0) { $this->attendance_data[0] = substr($this->attendance_data[0], 8); } } else { $ssize = $size; $sizerecibido = 0; array_push($this->attendance_data, substr($this->received_data, 8)); if ($size > 0) { $u = unpack('H' . (strlen($this->received_data) * 2), substr($this->received_data, 0)); $size -= strlen($this->received_data); $sizerecibido += strlen($this->received_data); while ($size > 0) { $received_data = $this->recv(); $u = unpack('H' . (strlen($received_data) * 2), substr($received_data, 0)); array_push($this->attendance_data, substr($received_data, 0)); $size -= strlen($received_data); $sizerecibido += strlen($received_data); if (strlen($received_data) == 0) { $size = 0; } } if ($sizerecibido <> ($ssize + 20)) { $received_data = $this->recv(); $u = unpack('H' . (strlen($received_data) * 2), substr($received_data, 0)); array_push($this->attendance_data, substr($received_data, 0)); $sizerecibido += strlen($received_data); } } } } else { $this->received_data = $this->recv(); $bytes = $this->getSizeAttendance(); if($bytes) { while($bytes > 0) { $received_data = $this->recv(1032); array_push($this->attendance_data, $received_data); $bytes -= 1024; } $this->session_id = hexdec($u['h6'].$u['h5']); $received_data = $this->recv(); } } $attendance = array(); if(count($this->attendance_data) > 0) { if ($this->protocol != 'TCP') { for($x=0; $xattendance_data); $x++) { if($x > 0) { $this->attendance_data[$x] = substr($this->attendance_data[$x], 8); } } } $attendance_data = implode('', $this->attendance_data); $attendance_data = substr($attendance_data, 10); while(strlen($attendance_data) > 40) { $u = unpack('H80', substr($attendance_data, 0, 40)); $u1 = hexdec(substr($u[1], 4, 2)); $u2 = hexdec(substr($u[1], 6, 2)); $uid = $u1+($u2*256); $id = str_replace("\0", '', hex2bin(substr($u[1], 8, 16))); $state = hexdec(substr( $u[1], 56, 2 ) ); $timestamp = $this->decodeTime(hexdec($this->reverseHex(substr($u[1], 58, 8)))); array_push($attendance, array($uid, $id, $state, $timestamp)); $attendance_data = substr($attendance_data, 40 ); } } return $attendance; } catch(ErrorException $e) { return FALSE; } catch(exception $e) { return FALSE; } } public function clearAttendance() { $command = CMD_CLEAR_ATTLOG; return $this->execCommand($command); } } ?>