License Registration
Overview
When you buy a commercial version of JSPrintManager you are provided with license information to register the product in your website. The license information you've received includes three values: the License Owner, the License Key and the License Token.
- License Owner and License Key are used to compute the license response for every validation request.
- License Token is a digitally signed proof of your license, issued by Neodynamic. It's returned as-is together with the license response and it's validated by JSPrintManager App version 9.0.26.1005 and later.
Note
If your license info does not include a License Token, you can still register the product with the License Owner and License Key only. Please contact our Support Team to get your License Token; future major versions of JSPrintManager App will require it.
There are three ways to setup the license info. License registration requires coding a page or controller in some web server-side language like PHP, .NET, Java, etc. so refer to Option ❶ or Option ❷ below. In case you cannot use server-side code, then please refer to Option ❸.
Important
Whatever option you choose, we strongly recommend protecting the license controller so that only your own website and users can get your license info.
❶ License Setting On Website
This license setting option is done on the same website that is using the JSPrintManager.js file. To register JSPrintManager in your website or project, you must code a page or controller in some server-side programming language so the license information is returned by this URL: //ORIGIN/jspm where ORIGIN is the one displayed by localhost's origin entry for your website. Here's a sample from our online demo website:

In this case, the license info must be configured under https://jsprintmanager.azurewebsites.net/jspm
Note
Alternatively you could specify a different URL to provide the license info but it must be located under the same ORIGIN 1. For example, based on the website sample, if we decided to return the license info from https://jsprintmanager.azurewebsites.net/licenses/jsprintmanager, then we must specify it in the Javascript code as follows
JSPM.JSPrintManager.license_url = "https://jsprintmanager.azurewebsites.net/licenses/jsprintmanager";
1 The ORIGIN restriction does not apply for Unlimited WebApp and Unlimited WebServer Licenses i.e. in these cases license can be served from anywhere! For that very reason, protecting the license controller is especially important for Unlimited licenses.
❷ License Setting On an external server/URL
This license setting option is done outside the boundary of the website that is using the JSPrintManager.js file. License registration requires coding a page or controller in some web server-side language like PHP, .NET, Java, etc. so if the website that is using the JSPrintManager.js does not allow you to use server-side code, then this option allows you to setup the license info on an external URL.
Important
This option requires a special License Owner format where the ORIGIN/DOMAIN (as described above and shown in the sample figure) of the printing website must be specified. You must request this type of license to our sales team after placing an order by specifying the ORIGIN value in your case.
The URL from where the license info must be returned must be specified in Javascript code to JSPM.JSPrintManager.license_url as shown in the following snipped code:
JSPM.JSPrintManager.license_url = "https://external-server/whatever/get-jspm-license";
JSPM.JSPrintManager.auto_reconnect = true;
JSPM.JSPrintManager.start();
//... more code...
The specified license_url must be coded in your preferred server-side language as shown in the below templates for most known web technologies languages.
❸ License Setting On Neodynamic server
If you cannot use server-side code in your website and you cannot create another website to return the license info, then Neodynamic offers you to host your license info at https://neodynamic.com which runs on MS Azure data centers at no extra costs. If this is an option for you, then please contact our Support Team
How license validation works
When a page of your website connects to JSPrintManager App, the app sends a request to your license controller (//ORIGIN/jspm or license_url) with these query string parameters:
| Parameter | Description |
|---|---|
timestamp |
A value that changes on every request. Your controller uses it to compute the license hash. |
origin |
The origin of the page that is using JSPrintManager, e.g. https://app.yourcompany.com (JSPrintManager App 9.0.26.1005 and later). |
lv |
The license protocol version (JSPrintManager App 9.0.26.1005and later). |
Your controller answers with the License Owner and the license hash in the response body, plus the following response headers (JSPrintManager App 9.0.26.1005 and later; older versions just ignore them):
| Response header | Description |
|---|---|
X-JSPM-License-Token |
Your License Token, as provided by Neodynamic. |
X-JSPM-License-TTL |
Number of seconds each JSPrintManager App may reuse a successful validation before asking your controller again. Allowed range: 300 (5 minutes) to 2592000 (30 days). If not specified, 30 days is used. |
X-JSPM-License-Grace |
Number of extra seconds a validation may still be used, once expired, if your controller cannot be reached (server down, network issues, etc.). Allowed range: 0 to 2592000 (30 days). If not specified, 0 (no offline tolerance) is used. |
The templates below use a TTL of 1 day and a grace period of 3 days. Adjust them to your needs:
- A shorter TTL means that changes on your side (e.g. stopping to serve the license to some origin or user) take effect sooner, at the cost of more requests to your controller.
- A longer grace period keeps your users printing during an outage of your controller; a grace period of 0 means users can't print as soon as the TTL expires and your controller is unreachable.
Important
To deny a request on purpose (e.g. an unauthorized caller), answer with HTTP status 200 and any text that is not a valid license (e.g. denied), as shown in the next section. Any other status code (401, 403, 500, etc.) is treated as "controller unreachable", so a previously cached validation would still be honored during the grace period.
Note
Make sure your controller response is never cached by proxies or CDNs (all templates send Cache-Control: no-store). A cached response contains an old hash and will fail validation.
Protecting the license controller
If your license controller allows anonymous access, anyone who knows its URL can request your license info. For licenses restricted to your website ORIGIN/DOMAIN the impact is limited, but for Unlimited WebApp/WebServer licenses and for licenses restricted to machine names, an unprotected controller could let third parties use your license. That's why we strongly recommend protecting it with one or more of the following options.
Authorization header
The license controller can be protected from unauthorized requests through any HTTP Authorization Header protection options. The Authorization header content must be specified through the JSPM.JSPrintManager.license_authorization_header property. For instance, you could use JSON Web Tokens (JWT) and set it as follows:
// Set the JSON Web Token (JWT) ... REPLACE <token> with the real value!!!
JSPM.JSPrintManager.license_authorization_header = "Bearer <token>";
// Setting the license_url is OPTIONAL
JSPM.JSPrintManager.license_url = "https://external-server/whatever/get-jspm-license";
JSPM.JSPrintManager.auto_reconnect = true;
JSPM.JSPrintManager.start();
//... more code...
Tip
Anything you write in your Javascript code can be seen by anyone loading the page, so a fixed password or token hardcoded in a public page does not protect the controller. The recommended approach is to issue a short-lived token per signed-in user (e.g. a JWT valid for some hours, generated by your server after the user logs in and written into the page) and to validate it in the license controller. This way, only your authenticated users can get your license info.
Custom headers
You could also provide any custom headers if the standard HTTP Authorization Header is not sufficient or not required. If that's your case, then you must set the JSPM.JSPrintManager.license_custom_headers property. Each custom header must be on a new line (\n) and follow the 'Name: Value' format e.g. "Header-Name: value\nAnother-Header: value" format. Here is an example:
// Set custom headers
JSPM.JSPrintManager.license_custom_headers = "CF-Access-Client-Id: abc123\nCF-Access-Client-Secret: xyz789";
// Setting the license_url is OPTIONAL
JSPM.JSPrintManager.license_url = "https://external-server/whatever/get-jspm-license";
JSPM.JSPrintManager.auto_reconnect = true;
JSPM.JSPrintManager.start();
//... more code...
Allowed origins
Starting with JSPrintManager App 9.0.26.1005, the origin query string parameter tells your controller which website is asking for the license. You can answer only for your own websites, which is especially useful for Unlimited licenses. For example, in Express.js:
var allowed_origins = ['https://app.yourcompany.com', 'https://intranet.yourcompany.com'];
// requests from older JSPrintManager App versions don't include "lv" nor "origin"
if (req.query.lv && allowed_origins.indexOf(req.query.origin) < 0) {
// deny with HTTP 200 + invalid text (see "How license validation works")
return res.type('text/plain').send('denied');
}
Note
The origin check is a convenient filter for requests coming from browsers, but it's not a replacement for the authorization header: the origin value is reported by the client, so it should be combined with one of the options above.
Where to add your authorization logic
All the templates below include a commented line OPTIONAL: authorize the request here. That's the place to validate the Authorization header, your custom headers and/or the allowed origins, and to deny the request (HTTP 200 + invalid text) when the check fails.
IMPORTANT: Be aware that if you do not provide any authorization method, then you must allow ANONYMOUS access on the license controller.
Template Code for most known Web Platforms
Refer to the following templates based on your Web Platform. If your dev platform is missing, please contact our Support Team
Note
Be aware that inside the following code you must specify the License Owner, License Key & License Token values you've received. If you don't have a License Token yet, leave it empty. You can also adjust the TTL and grace period values as explained in How license validation works.
Tip
Upgrading an existing license controller? Just add the License Token, TTL and grace period settings and the response headers shown in the templates. The response body does not change, so all JSPrintManager App versions keep working.
For Express.js / Node.js
- Create a new route handler and name it jspm.js; or edit the file that will be pointed by
license_url
Important
If you have protected the license controller then be sure you change the template code below to add the authorization logic. If you will not protect your controller, then it's mandatory that the URL //your-website/jspm or the license_url must be set up to allow ANONYMOUS access
- Then copy/paste the following code:
var express = require('express');
var router = express.Router();
var sha256 = require('sha256');
router.get('/', function(req, res, next){
//SET THE LICENSE INFO
var license_owner = "YOUR-LICENSE-OWNER-HERE";
var license_key = "YOUR-LICENSE-KEY-HERE";
var license_token = "YOUR-LICENSE-TOKEN-HERE"; // leave it empty if you don't have one
//LICENSE VALIDATION CACHING (seconds)
var license_ttl = 86400; // 1 day
var license_grace = 259200; // 3 days
//OPTIONAL: authorize the request here (see "Protecting the license controller")
//DO NOT MODIFY THE FOLLOWING CODE
var timestamp = req.query.timestamp;
var license_hash = sha256(license_key + timestamp);
res.set('Cache-Control', 'no-store');
res.set('X-JSPM-License-Token', license_token);
res.set('X-JSPM-License-TTL', String(license_ttl));
res.set('X-JSPM-License-Grace', String(license_grace));
res.type('text/plain').send(license_owner + "|" + license_hash);
});
module.exports = router;
For Next.js API Routes
- Create a new route handler under app/api/jspm/ folder and name it route.js (or route.ts); or edit the file that will be pointed by
license_url
Important
If you have protected the license controller then be sure you change the template code below to add the authorization logic. If you will not protect your controller, then it's mandatory that the URL //your-website/api/jspm or the license_url must be set up to allow ANONYMOUS access
- Then copy/paste the following code:
import crypto from "crypto";
// the license response must never be cached
export const dynamic = "force-dynamic";
export async function GET(req) {
//SET THE LICENSE INFO
const licenseOwner = "YOUR-LICENSE-OWNER-HERE";
const licenseKey = "YOUR-LICENSE-KEY-HERE";
const licenseToken = "YOUR-LICENSE-TOKEN-HERE"; // leave it empty if you don't have one
//LICENSE VALIDATION CACHING (seconds)
const licenseTtl = 86400; // 1 day
const licenseGrace = 259200; // 3 days
//OPTIONAL: authorize the request here (see "Protecting the license controller")
//DO NOT MODIFY THE FOLLOWING CODE
const { searchParams } = new URL(req.url);
const timestamp = searchParams.get("timestamp") ?? "";
const licenseHash = crypto
.createHash("sha256")
.update(licenseKey + timestamp)
.digest("hex");
return new Response(`${licenseOwner}|${licenseHash}`, {
status: 200,
headers: {
"Content-Type": "text/plain",
"Cache-Control": "no-store",
"X-JSPM-License-Token": licenseToken,
"X-JSPM-License-TTL": String(licenseTtl),
"X-JSPM-License-Grace": String(licenseGrace),
},
});
}
Set the JSPM.JSPrintManager.license_url prop based on your lic controller name, for instance:
JSPM.JSPrintManager.license_url = "https://your-website/api/jspm";
JSPM.JSPrintManager.auto_reconnect = true;
JSPM.JSPrintManager.start();
For Electron Desktop Apps
For licensing Electron Desktop apps, express & sha256 packages are required.
In the main.js file of your app, add the following:
const express = require('express');
const sha256 = require('sha256');
var _appExpress;
- License info must be served from some localhost port e.g. 9999 (change it to whatever is available in the target machine). In the same main.js file, add the following inside the createWindow() function:
function createWindow () {
// JSPrintManager Licensing
_appExpress = express();
_appExpress.listen(9999); // LICENSE PORT
_appExpress.get('/', function(req, res, next){
//SET THE LICENSE INFO
var license_owner = "YOUR-LICENSE-OWNER-HERE";
var license_key = "YOUR-LICENSE-KEY-HERE";
var license_token = "YOUR-LICENSE-TOKEN-HERE"; // leave it empty if you don't have one
//LICENSE VALIDATION CACHING (seconds)
var license_ttl = 86400; // 1 day
var license_grace = 259200; // 3 days
//DO NOT MODIFY THE FOLLOWING CODE
var timestamp = req.query.timestamp;
var license_hash = sha256(license_key + timestamp);
res.set('Cache-Control', 'no-store');
res.set('X-JSPM-License-Token', license_token);
res.set('X-JSPM-License-TTL', String(license_ttl));
res.set('X-JSPM-License-Grace', String(license_grace));
res.type('text/plain').send(license_owner + "|" + license_hash);
});
// -- end JSPrintManager Licensing
// Create the browser window.
const mainWindow = new BrowserWindow({
width: 800,
height: 600,
webPreferences: {
preload: path.join(__dirname, 'preload.js')
}
})
//...
}
- Finally, add this line to the source code file where you starts JSPrintManager and remember to change the license port if needed!
JSPM.JSPrintManager.license_url = "http://localhost:9999"; // LICENSE PORT
JSPM.JSPrintManager.auto_reconnect = true;
JSPM.JSPrintManager.start();
//...
For PHP
- Create a new file, name it index.php and place it under //your-website/jspm/; or edit the file that will be pointed by
license_url
Important
If you have protected the license controller then be sure you change the template code below to add the authorization logic. If you will not protect your controller, then it's mandatory that the URL //your-website/jspm/index.php or the license_url must be set up to allow ANONYMOUS access
- Then copy/paste the following code:
<?php
//SET THE LICENSE INFO
$license_owner = 'YOUR-LICENSE-OWNER-HERE';
$license_key = 'YOUR-LICENSE-KEY-HERE';
$license_token = 'YOUR-LICENSE-TOKEN-HERE'; // leave it empty if you don't have one
//LICENSE VALIDATION CACHING (seconds)
$license_ttl = 86400; // 1 day
$license_grace = 259200; // 3 days
//OPTIONAL: authorize the request here (see "Protecting the license controller")
//DO NOT MODIFY THE FOLLOWING CODE
$timestamp = isset($_GET['timestamp']) ? $_GET['timestamp'] : '';
$license_hash = hash('sha256', $license_key . $timestamp, false);
$resp = $license_owner . '|' . $license_hash;
ob_start();
ob_clean();
header('Content-type: text/plain');
header('Cache-Control: no-store');
header('X-JSPM-License-Token: ' . $license_token);
header('X-JSPM-License-TTL: ' . $license_ttl);
header('X-JSPM-License-Grace: ' . $license_grace);
echo $resp;
ob_end_flush();
exit();
For Laravel PHP
- Create a new controller and name it JSPMController or edit the file that will be pointed by
license_url
Important
If you have protected the license controller then be sure you change the template code below to add the authorization logic. If you will not protect your controller, then it's mandatory that the URL //your-website/jspm or the license_url must be set up to allow ANONYMOUS access
- Then copy/paste the following code:
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
class JSPMController extends Controller
{
public function index(Request $request){
//SET THE LICENSE INFO
$license_owner = 'YOUR-LICENSE-OWNER-HERE';
$license_key = 'YOUR-LICENSE-KEY-HERE';
$license_token = 'YOUR-LICENSE-TOKEN-HERE'; // leave it empty if you don't have one
//LICENSE VALIDATION CACHING (seconds)
$license_ttl = 86400; // 1 day
$license_grace = 259200; // 3 days
//OPTIONAL: authorize the request here (see "Protecting the license controller")
//DO NOT MODIFY THE FOLLOWING CODE
$timestamp = $request->query('timestamp', '');
$license_hash = hash('sha256', $license_key . $timestamp, false);
$resp = $license_owner . '|' . $license_hash;
return response($resp)
->header('Content-Type', 'text/plain')
->header('Cache-Control', 'no-store')
->header('X-JSPM-License-Token', $license_token)
->header('X-JSPM-License-TTL', (string)$license_ttl)
->header('X-JSPM-License-Grace', (string)$license_grace);
}
}
For Azure Function (C#)
Important
This option requires a special License Owner format where the ORIGIN/DOMAIN (as described above and shown in the sample figure) of the printing website must be specified. You must request this type of license to our sales team after placing an order by specifying the ORIGIN value in your case.
Create a new Azure Function (Http Trigger) and name it JSPMLic
Then copy/paste the following code:
public class JSPMLic
{
private readonly ILogger _logger;
public JSPMLic(ILoggerFactory loggerFactory)
{
_logger = loggerFactory.CreateLogger<JSPMLic>();
}
[Function("JSPMLic")]
public async Task<HttpResponseData> Run([HttpTrigger(AuthorizationLevel.Anonymous, "get", "post")] HttpRequestData req)
{
//SET THE LICENSE INFO
string license_owner = "YOUR-LICENSE-OWNER-HERE";
string license_key = "YOUR-LICENSE-KEY-HERE";
string license_token = "YOUR-LICENSE-TOKEN-HERE"; // leave it empty if you don't have one
//LICENSE VALIDATION CACHING (seconds)
int license_ttl = 86400; // 1 day
int license_grace = 259200; // 3 days
//OPTIONAL: authorize the request here (see "Protecting the license controller")
//DO NOT MODIFY THE FOLLOWING CODE
var queryCollection = HttpUtility.ParseQueryString(req.Url.Query);
string timestamp = queryCollection["timestamp"];
string license_hash = "";
using (System.Security.Cryptography.SHA256 sha256Hash = System.Security.Cryptography.SHA256.Create())
{
license_hash = BitConverter.ToString(sha256Hash.ComputeHash(System.Text.Encoding.UTF8.GetBytes(license_key + timestamp))).Replace("-","").ToLower();
}
var response = req.CreateResponse(HttpStatusCode.OK);
response.Headers.Add("Content-Type", "text/plain; charset=utf-8");
response.Headers.Add("Cache-Control", "no-store");
response.Headers.Add("X-JSPM-License-Token", license_token);
response.Headers.Add("X-JSPM-License-TTL", license_ttl.ToString());
response.Headers.Add("X-JSPM-License-Grace", license_grace.ToString());
response.WriteString(license_owner + '|' + license_hash);
return response;
}
}
Then add the following first line (change the URL based on your own value):
JSPM.JSPrintManager.license_url = '//azure-function-domain/api/JSPMLic';
JSPM.JSPrintManager.auto_reconnect = true;
JSPM.JSPrintManager.start();
For ASP.NET CORE
- Create a new Controller and name it JSPMController; or edit the file that will be pointed by
license_url
Important
If you have protected the license controller then be sure you change the template code below to add the authorization logic (and remove the [AllowAnonymous] attribute if you use ASP.NET Core authorization). If you will not protect your controller, then it's mandatory that the URL //your-website/jspm or the license_url must be set up to allow ANONYMOUS access
- Then copy/paste the following code:
public class JSPMController : Controller
{
[AllowAnonymous]
public IActionResult Index(string timestamp)
{
//SET THE LICENSE INFO
string license_owner = "YOUR-LICENSE-OWNER-HERE";
string license_key = "YOUR-LICENSE-KEY-HERE";
string license_token = "YOUR-LICENSE-TOKEN-HERE"; // leave it empty if you don't have one
//LICENSE VALIDATION CACHING (seconds)
int license_ttl = 86400; // 1 day
int license_grace = 259200; // 3 days
//OPTIONAL: authorize the request here (see "Protecting the license controller")
//DO NOT MODIFY THE FOLLOWING CODE
string license_hash = "";
using (System.Security.Cryptography.SHA256 sha256Hash = System.Security.Cryptography.SHA256.Create())
{
license_hash = BitConverter.ToString(sha256Hash.ComputeHash(System.Text.Encoding.UTF8.GetBytes(license_key + timestamp))).Replace("-","").ToLower();
}
Response.Headers["Cache-Control"] = "no-store";
Response.Headers["X-JSPM-License-Token"] = license_token;
Response.Headers["X-JSPM-License-TTL"] = license_ttl.ToString();
Response.Headers["X-JSPM-License-Grace"] = license_grace.ToString();
return File(System.Text.Encoding.UTF8.GetBytes(license_owner + '|' + license_hash), "text/plain");
}
}
For ASP.NET MVC
- Create a new Controller and name it JSPMController; or edit the file that will be pointed by
license_url
Important
If you have protected the license controller then be sure you change the template code below to add the authorization logic (and remove the [AllowAnonymous] attribute if you use ASP.NET authorization). If you will not protect your controller, then it's mandatory that the URL //your-website/jspm or the license_url must be set up to allow ANONYMOUS access
- Then copy/paste the following code:
public class JSPMController : Controller
{
[AllowAnonymous]
public void Index(string timestamp)
{
//SET THE LICENSE INFO
string license_owner = "YOUR-LICENSE-OWNER-HERE";
string license_key = "YOUR-LICENSE-KEY-HERE";
string license_token = "YOUR-LICENSE-TOKEN-HERE"; // leave it empty if you don't have one
//LICENSE VALIDATION CACHING (seconds)
int license_ttl = 86400; // 1 day
int license_grace = 259200; // 3 days
//OPTIONAL: authorize the request here (see "Protecting the license controller")
//DO NOT MODIFY THE FOLLOWING CODE
string license_hash = "";
using (System.Security.Cryptography.SHA256 sha256Hash = System.Security.Cryptography.SHA256.Create())
{
license_hash = BitConverter.ToString(sha256Hash.ComputeHash(System.Text.Encoding.UTF8.GetBytes(license_key + timestamp))).Replace("-","").ToLower();
}
var response = System.Web.HttpContext.Current.Response;
response.ContentType = "text/plain";
response.AppendHeader("Cache-Control", "no-store");
response.AppendHeader("X-JSPM-License-Token", license_token);
response.AppendHeader("X-JSPM-License-TTL", license_ttl.ToString());
response.AppendHeader("X-JSPM-License-Grace", license_grace.ToString());
response.Write(license_owner + '|' + license_hash);
}
}
For ASP.NET WebForms
- Create a new file, name it default.aspx and place it under //your-website/jspm/; or edit the file that will be pointed by
license_url
Important
If you have protected the license controller then be sure you change the template code below to add the authorization logic. If you will not protect your controller, then it's mandatory that the URL //your-website/jspm/default.aspx or the license_url must be set up to allow ANONYMOUS access
- Then copy/paste the following code:
protected void Page_Load(object sender, EventArgs e)
{
//SET THE LICENSE INFO
string license_owner = "YOUR-LICENSE-OWNER-HERE";
string license_key = "YOUR-LICENSE-KEY-HERE";
string license_token = "YOUR-LICENSE-TOKEN-HERE"; // leave it empty if you don't have one
//LICENSE VALIDATION CACHING (seconds)
int license_ttl = 86400; // 1 day
int license_grace = 259200; // 3 days
//OPTIONAL: authorize the request here (see "Protecting the license controller")
//DO NOT MODIFY THE FOLLOWING CODE
string timestamp = Request["timestamp"];
string license_hash = "";
using (System.Security.Cryptography.SHA256 sha256Hash = System.Security.Cryptography.SHA256.Create())
{
license_hash = BitConverter.ToString(sha256Hash.ComputeHash(System.Text.Encoding.UTF8.GetBytes(license_key + timestamp))).Replace("-","").ToLower();
}
Response.ContentType = "text/plain";
Response.AppendHeader("Cache-Control", "no-store");
Response.AppendHeader("X-JSPM-License-Token", license_token);
Response.AppendHeader("X-JSPM-License-TTL", license_ttl.ToString());
Response.AppendHeader("X-JSPM-License-Grace", license_grace.ToString());
Response.Write(license_owner + '|' + license_hash);
}
For Legacy ASP/VBScript
- Create a new file, name it default.asp and place it under //your-website/jspm/; or edit the file that will be pointed by
license_url
Important
If you have protected the license controller then be sure you change the template code below to add the authorization logic. If you will not protect your controller, then it's mandatory that the URL //your-website/jspm/default.asp or the license_url must be set up to allow ANONYMOUS access
Note
Requires SHA256.asp from https://www.freevbcode.com/ShowCode.asp?ID=2565
- Then copy/paste the following code:
<%
' Requires SHA256.asp from https://www.freevbcode.com/ShowCode.asp?ID=2565
%>
<!--#include file="sha256.asp"-->
<%
'SET THE LICENSE INFO
Dim license_owner
Dim license_key
Dim license_token
license_owner = "YOUR-LICENSE-OWNER-HERE"
license_key = "YOUR-LICENSE-KEY-HERE"
license_token = "YOUR-LICENSE-TOKEN-HERE" ' leave it empty if you don't have one
'LICENSE VALIDATION CACHING (seconds)
Dim license_ttl
Dim license_grace
license_ttl = 86400 ' 1 day
license_grace = 259200 ' 3 days
'OPTIONAL: authorize the request here (see "Protecting the license controller")
'DO NOT MODIFY THE FOLLOWING CODE
Dim timestamp
timestamp = Request.QueryString("timestamp")
Dim license_hash
license_hash = lcase(sha256(license_key & timestamp))
Response.ContentType = "text/plain"
Response.AddHeader "Cache-Control", "no-store"
Response.AddHeader "X-JSPM-License-Token", license_token
Response.AddHeader "X-JSPM-License-TTL", CStr(license_ttl)
Response.AddHeader "X-JSPM-License-Grace", CStr(license_grace)
Response.Write(license_owner & "|" & license_hash)
%>
For Java Servlet
- Create a new HttpServlet and name it jspm.java; or edit the file that will be pointed by
license_url
Important
If you have protected the license controller then be sure you change the template code below to add the authorization logic. If you will not protect your controller, then it's mandatory that the URL //your-website/jspm or the license_url must be set up to allow ANONYMOUS access
- Then copy/paste the following code:
@Override
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// SET THE LICENSE INFO
String license_owner = "YOUR-LICENSE-OWNER-HERE";
String license_key = "YOUR-LICENSE-KEY-HERE";
String license_token = "YOUR-LICENSE-TOKEN-HERE"; // leave it empty if you don't have one
// LICENSE VALIDATION CACHING (seconds)
int license_ttl = 86400; // 1 day
int license_grace = 259200; // 3 days
// OPTIONAL: authorize the request here (see "Protecting the license controller")
// DO NOT MODIFY THE FOLLOWING CODE
String timestamp = request.getParameter("timestamp");
if (timestamp == null) timestamp = "";
String license_hash = sha256Hash(license_key + timestamp);
response.setContentType("text/plain");
response.setCharacterEncoding("UTF-8");
response.setHeader("Cache-Control", "no-store");
response.setHeader("X-JSPM-License-Token", license_token);
response.setHeader("X-JSPM-License-TTL", String.valueOf(license_ttl));
response.setHeader("X-JSPM-License-Grace", String.valueOf(license_grace));
PrintWriter pw = response.getWriter();
pw.write(license_owner + "|" + license_hash);
pw.close();
}
private static String sha256Hash(String value) {
try{
java.security.MessageDigest md = java.security.MessageDigest.getInstance("SHA-256");
md.update(value.getBytes(java.nio.charset.StandardCharsets.UTF_8));
return bytesToHex(md.digest());
} catch(Exception ex){
throw new RuntimeException(ex);
}
}
private static String bytesToHex(byte[] bytes) {
StringBuilder result = new StringBuilder();
for (byte b : bytes) result.append(Integer.toString((b & 0xff) + 0x100, 16).substring(1));
return result.toString();
}
For Python (Odoo)
- Create a new controller and name it JSPrintManager; or edit the file that will be pointed by
license_url
Important
If you have protected the license controller then be sure you change the template code below to add the authorization logic. If you will not protect your controller, then it's mandatory that the URL //your-website/jspm or the license_url must be set up to allow ANONYMOUS access
- Then copy/paste the following code:
import hashlib
from odoo import http
from odoo.http import request
class JSPrintManager(http.Controller):
@http.route('/jspm', type='http', auth='public', methods=['GET'], csrf=False)
def get_jspm_license(self, **kw):
# SET THE LICENSE INFO
license_owner = 'YOUR-LICENSE-OWNER-HERE'
license_key = 'YOUR-LICENSE-KEY-HERE'
license_token = 'YOUR-LICENSE-TOKEN-HERE' # leave it empty if you don't have one
# LICENSE VALIDATION CACHING (seconds)
license_ttl = 86400 # 1 day
license_grace = 259200 # 3 days
# OPTIONAL: authorize the request here (see "Protecting the license controller")
# DO NOT MODIFY THE FOLLOWING CODE
timestamp = kw.get('timestamp', '')
license_hash = hashlib.sha256((license_key + timestamp).encode()).hexdigest()
resp = license_owner + '|' + license_hash
return request.make_response(resp, headers=[
('Content-Type', 'text/plain'),
('Cache-Control', 'no-store'),
('X-JSPM-License-Token', license_token),
('X-JSPM-License-TTL', str(license_ttl)),
('X-JSPM-License-Grace', str(license_grace)),
])
For Django
- Create a new View (the URL //your-website/jspm must resolve to it); or edit the file that will be pointed by
license_url
Important
If you have protected the license controller then be sure you change the template code below to add the authorization logic. If you will not protect your controller, then it's mandatory that the URL //your-website/jspm or the license_url must be set up to allow ANONYMOUS access
- Then copy/paste the following code:
from django.http import HttpResponse
import hashlib
def get_jspm_license(request):
# SET THE LICENSE INFO
license_owner = 'YOUR-LICENSE-OWNER-HERE'
license_key = 'YOUR-LICENSE-KEY-HERE'
license_token = 'YOUR-LICENSE-TOKEN-HERE' # leave it empty if you don't have one
# LICENSE VALIDATION CACHING (seconds)
license_ttl = 86400 # 1 day
license_grace = 259200 # 3 days
# OPTIONAL: authorize the request here (see "Protecting the license controller")
# DO NOT MODIFY THE FOLLOWING CODE
timestamp = request.GET.get('timestamp', default='')
license_hash = hashlib.sha256((license_key + timestamp).encode()).hexdigest()
response = HttpResponse(license_owner + '|' + license_hash, content_type='text/plain')
response['Cache-Control'] = 'no-store'
response['X-JSPM-License-Token'] = license_token
response['X-JSPM-License-TTL'] = str(license_ttl)
response['X-JSPM-License-Grace'] = str(license_grace)
return response
For Ruby on Rails (RoR)
- Create a new Controller (the URL //your-website/jspm must resolve to it); or edit the file that will be pointed by
license_url
Important
If you have protected the license controller then be sure you change the template code below to add the authorization logic. If you will not protect your controller, then it's mandatory that the URL //your-website/jspm or the license_url must be set up to allow ANONYMOUS access
- Then copy/paste the following code:
require 'digest'
class JspmController < ApplicationController
def index
# SET THE LICENSE INFO
license_owner = 'YOUR-LICENSE-OWNER-HERE'
license_key = 'YOUR-LICENSE-KEY-HERE'
license_token = 'YOUR-LICENSE-TOKEN-HERE' # leave it empty if you don't have one
# LICENSE VALIDATION CACHING (seconds)
license_ttl = 86400 # 1 day
license_grace = 259200 # 3 days
# OPTIONAL: authorize the request here (see "Protecting the license controller")
# DO NOT MODIFY THE FOLLOWING CODE
timestamp = params[:timestamp].to_s
license_hash = Digest::SHA256.hexdigest(license_key + timestamp)
response.headers['Cache-Control'] = 'no-store'
response.headers['X-JSPM-License-Token'] = license_token
response.headers['X-JSPM-License-TTL'] = license_ttl.to_s
response.headers['X-JSPM-License-Grace'] = license_grace.to_s
render plain: license_owner + '|' + license_hash
end
end
For Cold Fusion
- Create a new page under //your-website/jspm.cfm
Important
If you have protected the license controller then be sure you change the template code below to add the authorization logic. If you will not protect your controller, then it's mandatory that the URL //your-website/jspm.cfm must be set up to allow ANONYMOUS access
- Then copy/paste the following code:
<!--- SET THE LICENSE INFO --->
<cfset license_owner = "YOUR-LICENSE-OWNER-HERE">
<cfset license_key = "YOUR-LICENSE-KEY-HERE">
<cfset license_token = "YOUR-LICENSE-TOKEN-HERE"> <!--- leave it empty if you don't have one --->
<!--- LICENSE VALIDATION CACHING (seconds) --->
<cfset license_ttl = 86400> <!--- 1 day --->
<cfset license_grace = 259200> <!--- 3 days --->
<!--- OPTIONAL: authorize the request here (see "Protecting the license controller") --->
<!--- DO NOT MODIFY THE FOLLOWING CODE --->
<cfparam name="url.timestamp" default="">
<cfset license_hash = Hash(license_key & url.timestamp, "SHA-256")>
<cfset response_string = ToBinary( ToBase64( license_owner & "|" & LCase(license_hash) ) )>
<cfheader name="Content-type" value="text/plain">
<cfheader name="Cache-Control" value="no-store">
<cfheader name="X-JSPM-License-Token" value="#license_token#">
<cfheader name="X-JSPM-License-TTL" value="#license_ttl#">
<cfheader name="X-JSPM-License-Grace" value="#license_grace#">
<cfcontent type="text/plain" variable="#response_string#" reset="true">
Then add the following first line (change the URL based on your own value):
JSPM.JSPrintManager.license_url = '//your-website/jspm.cfm';
JSPM.JSPrintManager.auto_reconnect = true;
JSPM.JSPrintManager.start();