JetBrainsLicenseServer 授权服务类
代码如下:
<?php
/**
* JetBrains许可服务器
*/
class JetBrainsLicenseServer
{
// 授权给谁
public $licensee = 'jxx';
// license 有效时间(单位:毫秒),默认约为7天多(607875500),原厂 server 传递的数值。
public $prolongationPeriod = 607875500;
// RSA 私钥
public $privateKey = <<<Eof
-----BEGIN RSA PRIVATE KEY-----
MIIBOwIBAAJBALecq3BwAI4YJZwhJ+snnDFj3lF3DMqNPorV6y5ZKXCiCMqj8OeO
mxk4YZW9aaV9ckl/zlAOI0mpB3pDT+Xlj2sCAwEAAQJAW6/aVD05qbsZHMvZuS2A
a5FpNNj0BDlf38hOtkhDzz/hkYb+EBYLLvldhgsD0OvRNy8yhz7EjaUqLCB0juIN
4QIhAMsJQ3xiJemnJ2pD65iRNCC/Kr7jtxbbBwa6ZFLjp12pAiEA54JCn41fF8GZ
90b9L5dtFQB2/yIcGX4Xo7bCvl8DaPMCIBgOZ+2T33QYtwXTOFXiVm/O1qy5ZFcT
6ng0m3BqwsjJAiEAqna/l7wAyP1E4U7kHqbhKxWsiTAUgLDXtzRbMNHFMQECIQCA
xlpXEPqnC3P8if0G9xHomqJ531rOJuzB8fNtRFmxnA==
-----END RSA PRIVATE KEY-----
Eof;
public function ping($salt, $isAnswer = false)
{
$str = '<PingResponse><message></message><responseCode>OK</responseCode><salt>%s</salt></PingResponse>';
$out = sprintf($str, $salt);
return $isAnswer ? $this->writeAnswer($out) : $out;
}
public function obtainTicket($salt, $isAnswer = false)
{
$ticketId = 1;
$str = "<ObtainTicketResponse><message></message><prolongationPeriod>%u</prolongationPeriod><responseCode>OK</responseCode><salt>%s</salt><ticketId>%d</ticketId><ticketProperties>licensee=%s\tlicenseType=0\t</ticketProperties></ObtainTicketResponse>";
$out = sprintf($str, $this->prolongationPeriod, $salt, $ticketId, $this->licensee);
return $isAnswer ? $this->writeAnswer($out) : $out;
}
public function prolongTicket($salt, $isAnswer = false)
{
$ticketId = 1;
$str = '<ProlongTicketResponse><message></message><responseCode>OK</responseCode><salt>%s</salt><ticketId>%d</ticketId></ProlongTicketResponse>';
$out = sprintf($str, $salt, $ticketId);
return $isAnswer ? $this->writeAnswer($out) : $out;
}
public function releaseTicket($salt, $isAnswer = false)
{
$str = '<ReleaseTicketResponse><message></message><responseCode>OK</responseCode><salt>%s</salt></ReleaseTicketResponse>';
$out = sprintf($str, $salt);
return $isAnswer ? $this->writeAnswer($out) : $out;
}
public function writeAnswer($str)
{
$signature = $this->sign($str);
$signatureHex = bin2hex($signature);
$out = sprintf("<!-- %s -->\n%s", $signatureHex, $str);
return $out;
}
private function sign($data)
{
if (empty ($data)) {
return null;
}
$pkeyid = openssl_get_privatekey($this->privateKey);
if (empty ($pkeyid)) {
return null;
}
$signature = '';
$verify = openssl_sign($data, $signature, $pkeyid, OPENSSL_ALGO_MD5);
openssl_free_key($pkeyid);
return $verify ? $signature : null;
}
}
index.php 文件
代码如下:
<?php
include 'JetBrainsLicenseServer.php';
$uri = htmlspecialchars($_SERVER['REQUEST_URI']);
if (stripos($uri, '/rpc/ping.action') !== false) {
$method = 'ping';
} elseif (stripos($uri, '/rpc/obtainTicket.action') !== false) {
$method = 'obtainTicket';
} elseif (stripos($uri, '/rpc/prolongTicket.action') !== false) {
$method = 'prolongTicket';
} elseif (stripos($uri, '/rpc/releaseTicket.action') !== false) {
$method = 'releaseTicket';
} else {
show404();
exit();
}
$jblicsvr = new JetBrainsLicenseServer();
$salt = htmlspecialchars(isset ($_GET['salt']) ? $_GET['salt'] : null);
if (!$salt) {
if (preg_match('/(&|&|\?)salt=(?<salt>.*?)(&|$)/', $uri, $result)) {
$salt = $result['salt'];
}
}
if (!$salt || !method_exists($jblicsvr, $method)) {
show404();
}
echo $jblicsvr->$method ($salt, true);
exit();
function show404($msg = '')
{
$protocol = htmlspecialchars($_SERVER['SERVER_PROTOCOL']) ?: 'HTTP/1.0';
header($protocol . ' 404 Not Found');
header('Status: 404 Not Found');
echo $msg ?: 'Not Found';
exit ();
}
重定向规则
RewriteRule ^rpc/(ping|obtainTicket|prolongTicket|releaseTicket).action$ index.php [QSA,PT,L]
使用方法
软件授权软件选择 License server,Licese server address 填写:
a. http://xxxx/index.php?
b. http://xxxx/index.php (如果使用该地址出错,则使用上面的地址)
c. http://xxxx (使用重定向后)