pfSense fauxAPI in PHP
Basic fauxapi-include.php file that could be used with fauxapi for pfSense
<?php
//faux api key setup on pfsense box in /etc/fauxapi/credentials.ini
$key = "<your-api-key-here>";
//faux secret setup on pfsense box in /etc/fauxapi/credentials.ini
$secret = "<your-api-secret-here>";
// no need to edit any of the below
// generate some nonce
$random = base64_encode(mt_rand(100000,999999));
$nonce = str_replace(array('=','/','+'),"",$random);
// create a timestamp in UTC - must be within 60 seconds of pfSense server and in UTC
$utctimestamp = gmdate("Ymd\ZHis");
// Generate sha256 of the secret . timestamp . nonce
$hash = hash( 'sha256', $secret . $utctimestamp . $nonce);
// create faux api auth header
$fauxapiauth = $key .":" . $utctimestamp . ":" . $nonce .":". $hash;
// now you can use the variable $fauxapiauth as your HTTP header for "fauxapi-auth"
?>
//faux api key setup on pfsense box in /etc/fauxapi/credentials.ini
$key = "<your-api-key-here>";
//faux secret setup on pfsense box in /etc/fauxapi/credentials.ini
$secret = "<your-api-secret-here>";
// no need to edit any of the below
// generate some nonce
$random = base64_encode(mt_rand(100000,999999));
$nonce = str_replace(array('=','/','+'),"",$random);
// create a timestamp in UTC - must be within 60 seconds of pfSense server and in UTC
$utctimestamp = gmdate("Ymd\ZHis");
// Generate sha256 of the secret . timestamp . nonce
$hash = hash( 'sha256', $secret . $utctimestamp . $nonce);
// create faux api auth header
$fauxapiauth = $key .":" . $utctimestamp . ":" . $nonce .":". $hash;
// now you can use the variable $fauxapiauth as your HTTP header for "fauxapi-auth"
?>
This file could be included in any other php via :
require 'fauxapi-include.php';
Thank you very much, Works very well!
ReplyDelete