How to

How to

PHP files

Install and setup

Net2web software requirements are Windows OS (Desktop or Server), Paxton Net2 software and SDK as well, Web server with PHP/ASP.NET support.
 

CloudBridge how to

Some time it's pretty complecated or not possible to change user firewall configuration, in that way the best thing use CloudBridge, it's going through akostyra.net server and doesn't requare any special settings on client pc or network. See below a small addon code for your code in case you don't use my own php files. You have to provide activation id, it can be found on Net2Web activation page, just double click on logo and id will be copied into clipboard, other way to find activation id is akostyra.net->My account->My subscription->ActivationID. Yours data stay under security protection all the time, by using HTTPS protocol and your own security key. CloudBridge has a restriction of 65535 bytes of transfer data, in the most cases this size is completely enought for any method, just be careful with "querydb" request. 
 
// net2web.inc file
...
// CLOUDBRIDGE addon
if (isset($GLOBALS['activationid'])) {
	$activationid = $GLOBALS['activationid'];
	$url_oem = "https://akostyra.net/cloudbridge/cloudbridge.php";
	$sid_url = ($sid_url == "?") ? $sid_url : $sid_url."&";
	$sid_url = $sid_url."aid=".$activationid."&";
}
// end of addon 
...

// net2web.sample.php
...
// CLOUDBRIDGE addon
// double click on logo on activation page and activationid will be copied to clipboard
$activationid = "272A-xxxx-3F8C-EFF3-6BD5-ABC8-C5B9-xxxx";
// end of addon 
...

net2web.sample.php

/*
# Program name: Net2Web v2
# Module name: Sample file
*/

// Step 0: include net2web file
include_once "net2web.inc.php";
    
// Step 1: User authentication
$userid = "System Engineer";
$password = "net2";

// CLOUDBRIDGE addon
// double click on logo on activation page and activationid will be copied to clipboard
$activationid = null; //"272A-xxxx-3F8C-EFF3-6BD5-ABC8-C5B9-xxxx";
// end of addon 

$SID = oemclient_sid($userid, $password); // Don't forget replace to your own

// Step 2: If login ok, go ahead
if ($SID != "") 
   {
      
    // Call oemclient method
    $result_xml = oemclient_xml($SID, "getlistofoperators");  
	print_r($result_xml);
	     
	// Call oemclient method
	$userid_db = "1"; // could a list of user ids
	$user_details = oemclient_xml($SID, "querydb", array('query' => "select u.*,  al.AccessLevelID from usersex u, 
						AccessLevels al where u.userid IN ($userid_db) AND al.AccessLevelName = u.AccessLevelName"));    
    print_r($user_details);
	
	// Call oemclient method
    $result_xml = oemclient_xml($SID, "pulse");    
	// $result_xml = oemclient_xml($SID, "pulse", array('file' => "test.pul"));   
    print_r($result_xml);
	
   } 
   else 
     // If something wrong with login  
     echo "\nLogin failed, check userid or password !!!";

net2web.pushclient.php

/*
# Program name: Net2Web v2
# Module name: Sample of PUSH client file
*/

// Step 0: include net2web file
include_once "net2web.inc.php";

// Step 1: Parse URL parameters
$result = get_push_xml();

// Step 2: Proccess PUSH result, save to file
if (isset($result)) {
	$arr = xml2array($result);
	$result_to_str = "";
	foreach ($arr as $key => $value) {$result_to_str = $result_to_str.$key."=>".$value."  ";}
	file_put_contents('temp/push.txt', $result_to_str.PHP_EOL, FILE_APPEND | LOCK_EX);
}

net2web.inc.php

/*
# Program name: Net2Web v2 with CLOUDBRIDGE
# Module name: Include file of Ne2Web
*/

// OpenSSL crypt type
define('AES_128_ECB', 'aes-128-ecb');

// Don't forget replace key for your own
$securekey = "123456789012123456789012";
$connection_ok = True;

// Encrypt data 
function encryptOpenssl($data, $key) {
    $rtn = base64_encode(openssl_encrypt($data, AES_128_ECB, SubStr($key, 0, 16), OPENSSL_RAW_DATA));
    return($rtn);
}

// Decrypt data
function decryptOpenssl($data, $key) {
    $rtn = openssl_decrypt(base64_decode($data), AES_128_ECB, SubStr($key, 0, 16), OPENSSL_RAW_DATA);
    return($rtn);
}

// Encrypt data 
function encrypt3DEC($data, $key) {
    $rtn = base64_encode(mcrypt_encrypt(MCRYPT_3DES, $key, $data, MCRYPT_MODE_ECB));
    return($rtn);
}

// Decrypt data
function decrypt3DEC($data, $key) {
    $rtn = mcrypt_decrypt(MCRYPT_3DES, $key, base64_decode($data), MCRYPT_MODE_ECB);
    return($rtn);
}

function get_push_xml() {
    $result_xml = NULL;
    // extra test for incoming parameters
    if (isset($_POST["ssl"]) && isset($_POST["push"])) {
        // Get type of encoding
        $OpenSSL = strtolower($_POST["ssl"]) === 'true' ? true : false;
        // PUSH data works
        $pushdata = $_POST["push"];
        // Decode and convert to XML
        if ($OpenSSL)
            $result_xml = simplexml_load_string(decryptOpenssl($pushdata, $GLOBALS['securekey']));
        else
            $result_xml = simplexml_load_string(decrypt3DEC($pushdata, $GLOBALS['securekey']));
    }
    return $result_xml;
}

function xml2array($xml) {
    $arr = array();
    foreach ($xml->children() as $r) {
        $t = array();
        if (count($r->children()) == 0) {
            $arr[$r->getName()] = strval($r);
        } else {
            $arr[$r->getName()][] = xml2array($r);
        }
    }
    return $arr;
}

// Main OemClient part, return XML
function oemclient_xml($sid, $method, $parameters_array = array()) {
    // Connection settings
    $url = "http://localhost"; // Url address of your pc
    $url_port = "7070"; // Port of Net2web
    $url_oem = $url . ":" . $url_port . "/oemclient.xml"; // Oemclient service name DO NOT CHANGE
    // Get key from global variable, find it on top of file
    $key = $GLOBALS['securekey'];

    //Use OpenSSL
    $use_ssl = True;

    // Special hook of first time login 
    $sid_url = "?";
    if ($use_ssl)
        $sid_url = "?ssl=yes&";

    if ($sid != "") {
        if ($use_ssl)
            $sid_url = $sid_url . "sid=" . rawurlencode(encryptOpenssl($sid, $key)) . "&";
        else
            $sid_url = $sid_url . "sid=" . rawurlencode(encrypt3DEC($sid, $key)) . "&";
    }

    // Parse of parameters array
    $parameters = "";
    foreach ($parameters_array as $param_name => $param_value) {
        if ($use_ssl)
            $parameters = $parameters . "&" . $param_name . "=" . rawurlencode(encryptOpenssl($param_value, $key));
        else
            $parameters = $parameters . "&" . $param_name . "=" . rawurlencode(encrypt3DEC($param_value, $key));
    }

	// CLOUDBRIDGE addon
	if (isset($GLOBALS['activationid'])) {
		$activationid = $GLOBALS['activationid'];
		$url_oem = "https://akostyra.net/cloudbridge/cloudbridge.php";
		$sid_url = ($sid_url == "?") ? $sid_url : $sid_url."&";
		$sid_url = $sid_url."aid=".$activationid."&";
	}
	// end of addon 
	
    // Get result XML
    set_error_handler("warning_handler", E_WARNING);

    $result_encoded_data = file_get_contents($url_oem . $sid_url . "method=" . $method . $parameters);

    restore_error_handler();

    $result_xml = "";

    if ($GLOBALS['connection_ok']) {

        if ($use_ssl)
            $result_decoded_data = decryptOpenssl($result_encoded_data, $key);
        else
            $result_decoded_data = decrypt3DEC($result_encoded_data, $key);

        if (strlen($result_decoded_data) > 0) {
            if (substr($result_decoded_data, 0, 1) == '<')
                $result_xml = simplexml_load_string($result_decoded_data);
        }
    }
    return($result_xml);
}

function warning_handler($errno, $errstr) {
    $GLOBALS['connection_ok'] = False;
}

// Overloaded user login to oemclient
// Return: SID or empty string if not successful
function oemclient_sid($userid, $password, $activationid = null) {
    $result_sid = "";
    $result_xml = oemclient_xml("", "authenticateuser", array("userid" => $userid, "password" => $password), $activationid);

    if ($GLOBALS['connection_ok']) {

        $result_sid = "";

        if (gettype($result_xml) == "object")
            $result_sid = $result_xml->item[0]->value;

        if ($result_sid != "") {

            // Test for correct login
            if (strpos($result_sid, "error") != false) {

                $result_sid = "";

                echo "\nLogin failed, check userid or password !!!";
            }
        } else {
            echo("\nSecurity keys are not match !");
        }
    } else {
        echo "\nConnection failed, check Net2Web is running on remote host !!!";
    }

    return($result_sid);
}

Github Gyron php

declare( strict_types=1 );

namespace Gyron\Sample;

use Gyron\Net2Web\Client;
use Gyron\Net2Web\Encryption;
use Gyron\Net2Web\Session;

/**
 * Class AccessApiFactory
 * @package Gyron\Sample
 */
class AccessApiFactory {

  /**
   * @var string
   */
  private $sCachePath;

  /**
   * @param string $sCachePath
   */
  public function __construct( string $sCachePath ) {
    $this->sCachePath = $sCachePath;
  }

  /**
   * @param array $aConfig requires user_id, password, ip and port
   * @return Client
   * @throws \Exception
   */
  public function forConfig( array $aConfig ) {
    $sCacheFile = sprintf( '%s/net2web_session.sid', rtrim( $this->sCachePath, '/' ) );

    $sSessionId = null;
    if ( is_file( $sCacheFile ) ) {
      $sSessionId = trim( file_get_contents( $sCacheFile ) );
    }
        
    $oNet2Encryption = new Encryption( '1234567890123456', Encryption::OpenSSL );
    $oNet2Session = new Session( $aConfig['user_id'], $aConfig['password'], $aConfig['ip'], (string)$aConfig['port'], $oNet2Encryption, $sSessionId );
    if ( $sSessionId != $oNet2Session->getSessionId() ) {
      file_put_contents( $sCacheFile, trim( $oNet2Session->getSessionId() ) );
    }
    return ( new Client( oNet2Session ) );
  }
}

Gyron first official release

Supports Net2Web v2.0.0.7.

  • Handles the new "sidexpired" attribute indicating that the session has expired and that authentication should be reissued. Save and cache the new sid.
  • Supports the new Push feature. Simply reuse the Session and create a new instance of PushReceiver.
  • Add ability to change the encryption method

See it on GitHub

Net2Web methods description

Method Parameters
Common template oemclient_xml($SID, "methodname", array('param1' => "value", 'param2'=> "value",'param3'=> "value", ...));
addcard cardnumber, cardtypeid, userid
adddepartment newdepartmentname
addeventrecord eventtype, eventsubtype,  deviceserialaddress , devicesubaddress, userid, cardnumber, eventdetail, linkedeventid, ioboardid , ioboardinputid, ioboardoutputid
addnewuser accesslevelid, departmentid, antipassbackind, alarmuserind, firstname, middlename, surname, telephoneno, telephoneextension, pincode, picturefilename, activationdate, cardnumber, cardtypeid, active, faxno, expirydate, userpicture, field1, field2, field3, field4, field5, field6, field7, field8, field9, field10, field11, field12, field13, field14
adduserrecord (depricated) accesslevelid, departmentid, antipassbackind, alarmuserind, firstname, middlename, surname, telephoneno, telephoneextension, pincode, picturefilename, activationdate, cardnumber, cardtypeid, active, faxno, expirydate, userpicture, field1, field2, field3, field4, field5, field6, field7, field8, field9, field10, field11, field12, field13, field14
authenticateuser userid, password (userid can be operator name or operator id)
canauthenticate  
closedoor doorserialnumber
deleteaccesslevel accesslevelid
deletecard cardnumber
deletedepartment departmentid
deletetimezone timezoneid
flashaccessdenied acuserialnumber, readerlocation
flashaccesspermitted acuserialnumber, readerlocation
geteventdescriptions fromeventid, toeventid
getlistofoperators  
getoemsetting setting
getoperatorlevel userid
getproducttype  
holddooropen doorserialnumber
lasterrormessage  
opendoor doorserialnumber
pulse (Net2Web) {file=filename.pul}
purgeuser userid
querydb query
serverhostname  
serverlastchecked  
setdooropentime doorserialnumber, dooropentime
sidexpired (Net2Web)  
updatedepartment departmentid, departmentname
updateoemsetting setting, settingdata
updateuserrecord userid, accesslevelid, departmentid, antipassbackind, alarmuserind, firstname, middlename, surname, telephoneno, telephoneextension, pincode, picturefilename, activationdate, cardnumber, cardtypeid, active, faxno, expirydate, customfields, userpicture, field1, field2, field3, field4, field5, field6, field7, field8, field9, field10, field11, field12, field13, field14
username  
viewaccessleveldetail accesslevelid
viewaccesslevels {userid}
viewcards userid
viewcardtypes  
viewdepartments  
viewevents rows, query, sort
viewdoors  
viewioboardinputs ioboardid
viewioboardoutputs ioboardid
viewioboards  
viewtimezones  
viewuserrecords {sqlwhere}, {image}
Advanced Permissions  
viewuseraccesslevelsadvancedpermissions userid
viewuserindividualaccessadvancedpermissions userid
updateuserrecord advancedaccesslevelid, advancedindividualid, advancedindividualtimezoneid

Method response XML sample

//NET2WEB methods response is XML data, which can be parsed by PHP SimpleXMLElement Object.

SimpleXMLElement Object <-- $result_xml = oemclient_xml($SID, "username");
(
[@attributes] => Array
(
[method] => username <-- called method name
)

[item] => SimpleXMLElement Object
(
[value] => User1 <-- result of method
)

)
SimpleXMLElement Object <-- $result_xml = oemclient_xml($SID, "viewevents", array("rows" => "100", "query" => "UserID = ".$userid, "sort" => "EventID desc"));
(
[@attributes] => Array
(
[method] => viewevents <-- called method name
)

[item] => SimpleXMLElement Object
(
[value] => SimpleXMLElement Object <-- result of method
(
[EventsSet] => SimpleXMLElement Object
(
[Event] => Array
(
[0] => SimpleXMLElement Object
(

[EventID] => 4467
[EventDateTime] => 2012-08-13T08:15:10.047+01:00
[EventDate] => 13/08/2012
[EventTime] => 08:15:10
[EventType] => 517
[EventDescription] => Logged on as OEM client
[EventSubType] => 0
[EventSubDescription] => SimpleXMLElement Object
(
)
 

[UserID] => 1
[UserName] => User1
[FirstName] => User1
[MiddleName] => SimpleXMLElement Object
(
)

[Surname] => SimpleXMLElement Object
(
)

[Priority] => 0
[PrioritySortOrder] => 1
)

[1] => SimpleXMLElement Object
(

[EventID] => 4463
[EventDateTime] => 2012-08-09T08:13:27.137+01:00
[EventDate] => 09/08/2012
[EventTime] => 08:13:27
[EventType] => 518
[EventDescription] => Logged off as OEM client
[EventSubType] => 0
[EventSubDescription] => SimpleXMLElement Object
(
)
 

[UserID] => 1
[UserName] => User1
[FirstName] => User1
[MiddleName] => SimpleXMLElement Object
(
)

[Surname] => SimpleXMLElement Object
(
)

[Priority] => 0
[PrioritySortOrder] => 1
)

[2] => SimpleXMLElement Object
(

[EventID] => 4462
[EventDateTime] => 2012-08-09T08:12:53.107+01:00
[EventDate] => 09/08/2012
[EventTime] => 08:12:53
[EventType] => 517
[EventDescription] => Logged on as OEM client
[EventSubType] => 0
[EventSubDescription] => SimpleXMLElement Object
(
)
 

.....

How to create custom SQL 

I advise to use MS Management Studio for easy access to all of NET2 views and the creation of your custom SQL.

Full list of Paxton NET2 views.

Should you require read only access to the database tables via SQL Management Studio, the following credentials may be used:

User name: sdk_user
Password: E56ABED4-2918-44F9-A110-71B61B47142A

msmangestudio.png

PUSH how it works

The PUSH sends two requests in one set, the first one is GET and it only use is to test if the remote URL is alive. If the test was done succesfully, PUSH sends a second POST with event data into it. If you use Net2Web client php file, it's not very important, but in case you have your own developments, pay attention to double requests.
 

Session ID ($SID)

A new session ID creates everytime time you use the "authenticateuser" method and it will be active for next 8 hours (28,800 seconds).

$result_xml = oemclient_xml("", "authenticateuser", array("userid" => $userid, "password" => $password));
I do not recommend to run the "authenticateuser" method everytime before any other method, because your connection will be locked from the Paxton Net2 service side.
Instead of that, you can test if your $SID is still active and check the method response before you process it. See below the response of in case an expired $SID or call method "sidexpired" directly. 
SimpleXMLElement Object ( [@attributes] => Array ( [method] => sidexpired ) [item] => SimpleXMLElement Object ( [value] => True ) )

Advanced Permissions

// Reset all of user permissions
$result_xml = oemclient_xml($SID, "updateuserrecord", array('userid' => "3649", 'accesslevelid' => "0"));

//Add user permissions
$result_xml = oemclient_xml($SID, "updateuserrecord", array('userid' => "3649", 'advancedaccesslevelid' => "3", 'advancedindividualid' => "1000011", 'advancedindividualtimezoneid' => "1"));

//Remove user permissions, access id must be negotive
$result_xml = oemclient_xml($SID, "updateuserrecord", array('userid' => "3649", 'advancedaccesslevelid' => "-3", 'advancedindividualid' => "-1000011"));
Where you can find access/individual level ids and timezone ids.
You can use SQL management studio and check views: [AccessLevels], [Areas], [Timezones]
Net2 SDK methods: viewaccesslevels, viewaccessleveldetail, viewtimezones and for individuals is querydb(‘SELECT * FROM [Net2].[sdk].[AccessLevels] where AccessLevelID > 1000000’)
 

Install as service

Net2Web can be installed and run as Windows service. You have to download and unzip service tool into Net2Web directory and run "AsService.exe" with administrator rights. Net2Web service is not working as Local system account, user name and password must be provided. Before you run Net2Web as service you have to run in normal way and setup Net2 server connection, make sure you have "auto reconnect" checkbox ticked.