hier ist ein PhP Skript, welches die UDP-Pakete des EKEY-Systems interpretiert.
[ul]
[li]Alle Ereignisse (erfolgreich/erfolglos) werden in eine Access-Datenbank abgelegt. [/li][li]Alle erfolgreiche Ereignisse werden auch via email verschickt. [/li][li]Mithilfe des Skripts ist es natürlich einfach, allerlei Ereignisse zu triggern. Z.B. ein Gong läuten zu lassen, wenn jemand rein kommt - oder die Alarmanlage deaktivieren, wenn ein Fingerprint korrekt eingelesen wird.[/li][li]Dieses Skript wurde in einer „Ekey Net Business“ Umgebung getestet. Ich glaube, dass andere Versionen nur sehr leichte Unterschiede beim UDP-String aufweisen.[/li][/ul]
Ich hoffe, dass dieses Skript für Andere nützlich sein wird!
<?
// UDP Data Block Structure
// long nVersion; // Version of the data (3)
// long nCmd; // action code (TERMCMD_ENTER,...)
// long nTerminalID; // Terminal ID
// char strTerminalSerial[14]; // Serial number of the Terminal (for net)
// char nRelayID; // Relay number
// char nReserved; // unused
// long nUserID; // User
// long nFinger; // Finger ID
// char strEvent[16]; // Event, which is to be triggered
// char sTime[16]; // yyyymmdd hhmmss
// unsigned short strName[1]; // Name of the User in Unicode, if available
// unsigned short strPersonalID[1]; // Personal ID + \0 (used only in Version 2)
$ekeyStringHex = "";
if ($IPS_SENDER == "Execute")
{
$ekeyStringHex ="0300000001000000f903100074657374383530393039303030390000680000000f0000000000000000000000000000000000000032303131313131392031323337323500610061006700000031000000";
}
else
{
$data = $IPS_VALUE;
for ($i=0; $i < strlen($data); $i++)
{
$ekeyStringHex .= str_pad(dechex(ord($data[$i])), 2, '0', STR_PAD_LEFT);
}
}
$ekeyString = preg_replace('/[\x00-\x1F\x7F]/', '', hextostr($ekeyStringHex))."
";
$lenEkeyStringHex = strlen($ekeyStringHex);
$nVersion = intval(substr($ekeyStringHex,0,8)); // Version of the data (3)
$nCmd = intval(substr($ekeyStringHex,8,8)); // action code (TERMCMD_ENTER,...)
$nTerminalID = intval(substr($ekeyStringHex,16,8)); // Terminal ID
$strTerminalSerial = hextostr(substr($ekeyStringHex,24,28)); // Serial number of the Terminal (for net)
$nRelayID = intval(substr($ekeyStringHex,52,2)); // Relay number
$nReserved = intval(substr($ekeyStringHex,54,2)); // unused
$nUserID = intval(substr($ekeyStringHex,56,8)); // User
$nFinger = intval(substr($ekeyStringHex,64,8)); // Finger ID
$strEvent = hextostr(substr($ekeyStringHex,72,32)); // Event which is to be triggered
$sTimeStamp = hextostr(substr($ekeyStringHex,104,15)); // yyyymmdd hhmmss
$ekeyYear = hextostr(substr($ekeyStringHex,104,8));
$ekeyMonth = hextostr(substr($ekeyStringHex,112,4));
$ekeyDay = hextostr(substr($ekeyStringHex,116,4));
$ekeyHH = hextostr(substr($ekeyStringHex,122,4));
$ekeyMM = hextostr(substr($ekeyStringHex,126,4));
$ekeySS = hextostr(substr($ekeyStringHex,130,4));
$strName = preg_replace('/[\x00-\x1F\x7F]/', '', hextostr(substr($ekeyStringHex,134)));
$ekeyTimeStamp = $ekeyDay . "-" . $ekeyMonth . "-" . $ekeyYear . " " . $ekeyHH . ":" . $ekeyMM . ":" . $ekeySS;
$emailDebugBody = "nVersion : " . $nVersion . "
"
. "nCmd : ".$nCmd. "
"
. "nTerminalID : ".$nTerminalID. "
"
. "strTerminalSerial : ".$strTerminalSerial. "
"
. "nRelayID : ".$nRelayID. "
"
. "nReserved : ".$nReserved. "
"
. "nUserID : ".$nUserID. "
"
. "nFinger : ".$nFinger. "
"
. "ekeyYear : ".$ekeyYear. "
"
. "ekeyMonth : ".$ekeyMonth. "
"
. "ekeyDay : ".$ekeyDay. "
"
. "ekeyHH : ".$ekeyHH. "
"
. "ekeyMM : ".$ekeyMM. "
"
. "ekeySS : ".$ekeySS. "
"
. "lenEkeyStringHex : ".$lenEkeyStringHex. "
"
. "strName : " . $strName. "
"
. "ekeyTimeStamp : " . $ekeyTimeStamp ;
$emailHeader = $strName;
if ($nCmd == "4000000")
{
// SMTP_SendMail(18471 /*[E-Mail senden (SMTP)]*/ ,
// $emailHeader." Finger not recognized",
// $emailDebugBody . "
"
// . $ekeyStringHex . "
"
// . $ekeyString . "
");
}
else
{
SMTP_SendMail(18471 /*[E-Mail senden (SMTP)]*/ ,
$emailHeader,
$emailDebugBody . "
"
. $ekeyStringHex . "
"
. $ekeyString . "
");
}
// $mdbFilename = "\\GRUEMPELCHAMMER\SSD_Grumpelchammer\TimeSheets\ekeyPhP.accdb";
$conn=odbc_connect('ekey_SysWOW64','','');
$sql="SELECT * FROM tblEkeyPhP";
$rs=odbc_exec($conn,$sql);
echo $strEvent;
/* run insert */
// $stmt = odbc_prepare($conn, "INSERT INTO tblEkeyPhP (nTerminalID, strEvent,
// VALUES($nVersion, $nCmd, $nTerminalID, '$strTerminalSerial', $nRelayID, $nReserved, $nUserID, $nFinger, '$strEvent', '$sTimeStamp', '$strName', '$ekeyTimeStamp');" );
$stmt = odbc_prepare($conn, "INSERT INTO tblEkeyPhP (nTerminalID, nVersion, strTerminalSerial, strName, ekeyTimeStamp, nCmd, nRelayID, nReserved, nUserID, nFinger, ekeyStringHex)
VALUES($nTerminalID, $nVersion, '$strTerminalSerial', '$strName', '$ekeyTimeStamp', $nCmd, $nRelayID, $nReserved, $nUserID, $nFinger, '$ekeyStringHex');" );
//$stmt = odbc_prepare($conn, "INSERT INTO tblEkeyPhP (strTerminalSerial) VALUES ('$strTerminalSerial');" );
/* check for errors */
if (!odbc_execute( $stmt))
{
/* error */
echo "Whoops odbc error";
}
function hextostr($x) {
$s='';
foreach(explode("
",trim(chunk_split($x,2))) as $h) $s.=chr(hexdec($h));
return($s);
}
function strtohex($x) {
$s='';
foreach(str_split($x) as $c) $s.=sprintf("%02X",ord($c));
return($s);
}
?>