Permalink
Browse files

Add support for license checking

  • Loading branch information...
1 parent 79a5fc6 commit 0e47092d895c0b1cbf87080602fd1ad5a88d2976 @romaninsh romaninsh committed Jun 4, 2012
Showing with 100 additions and 4 deletions.
  1. +41 −0 cert/atk4.crt
  2. +59 −4 lib/ApiWeb.php
View
@@ -0,0 +1,41 @@
+-----BEGIN CERTIFICATE-----
+MIIHOzCCBiOgAwIBAgIDBnSTMA0GCSqGSIb3DQEBBQUAMIGMMQswCQYDVQQGEwJJ
+TDEWMBQGA1UEChMNU3RhcnRDb20gTHRkLjErMCkGA1UECxMiU2VjdXJlIERpZ2l0
+YWwgQ2VydGlmaWNhdGUgU2lnbmluZzE4MDYGA1UEAxMvU3RhcnRDb20gQ2xhc3Mg
+MSBQcmltYXJ5IEludGVybWVkaWF0ZSBTZXJ2ZXIgQ0EwHhcNMTIwNjAzMjAzNTU0
+WhcNMTMwNjA1MTc0NjAxWjB2MRkwFwYDVQQNExA3M1hIVDA4bUFpMmM3OFI0MQsw
+CQYDVQQGEwJHQjEgMB4GA1UEAxMXc2VjdXJlLmFnaWxldG9vbGtpdC5vcmcxKjAo
+BgkqhkiG9w0BCQEWG2hvc3RtYXN0ZXJAYWdpbGV0b29sa2l0Lm9yZzCCASIwDQYJ
+KoZIhvcNAQEBBQADggEPADCCAQoCggEBAMyaZRLXMs6Us/zB3zVW64KmnRKAtQbd
+sxRn7CCX0/oVdU8EG9lOIx3B9sQxOCINSnYoB+6bsriuHiXGwIpVhWdE2cGePGs2
+XrVNHcr/o+CFn6m+OWagPaUu+X70wGPRyNE5LZiSkY/daRnyfv5EKbjvQkism1sk
+mnqAra/8sVoCGCdBiA/jY7gnWjjJJgmjiIaqYUmkC4KWoOFsUrHExrC/rZrqYTNH
+Oi81fEebVkpvaU2X8EnnkFyZMIqJKX/afH2uwamzKZmE90NW/bN3TDu5T5bKBK7Z
+iuyeJS/gMhAiPmxPCqadr8k/ndzQ4XR3IcmjJpWsqIO+5ixJ06jaqzcCAwEAAaOC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bC5jcmwwgY4GCCsGAQUFBwEBBIGBMH8wOQYIKwYBBQUHMAGGLWh0dHA6Ly9vY3Nw
+LnN0YXJ0c3NsLmNvbS9zdWIvY2xhc3MxL3NlcnZlci9jYTBCBggrBgEFBQcwAoY2
+aHR0cDovL2FpYS5zdGFydHNzbC5jb20vY2VydHMvc3ViLmNsYXNzMS5zZXJ2ZXIu
+Y2EuY3J0MCMGA1UdEgQcMBqGGGh0dHA6Ly93d3cuc3RhcnRzc2wuY29tLzANBgkq
+hkiG9w0BAQUFAAOCAQEAgwbVOtH2mv/KEsfRyW2D7KAq9c/4GJMc01ZrgUdkvnWn
+krgWNqR7ClvBD5q7G2EOVstl8koLaDtkz8SnB4tk2hwOm0pqFUVZAfdpQiENSDLf
+AakBAgDrhtJf19BBax1uNGFO9hUzi1sJQOliRXPyr5IJIHRikPpSO22+mrYAjm8t
+5N2yx2FG17f+JNyuKd4g5VQw/xcO7jprBNvjEwf6WruLBB36aI9H1PK215DrWbdl
+P0tn871HwHG2xV7J8irpomstmLxpd58bndcblusoJX5tQw5Pqw7MGt+Lb2eKLga5
+YgKHeC/+vXlCYB/J70q2ioUfJDUDqXiMXhHTGuwTFQ==
+-----END CERTIFICATE-----
View
@@ -26,6 +26,9 @@ class ApiWeb extends ApiCLI {
/** recorded time when execution has started */
public $start_time=null;
+ private $_license_checksum=null;
+ private $_license='unlicensed';
+
// {{{ Start-up
function __construct($realm=null,$skin='default'){
$this->start_time=time()+microtime();
@@ -51,6 +54,9 @@ function init(){
//$this->calculatePageName();
$this->pm=$this->add('PageManager');
+ // Verify Licensing
+ $this->licenseCheck('atk4');
+
// send headers, no caching
$this->sendHeaders();
@@ -111,12 +117,61 @@ function _showExecutionTime(){
function _showExecutionTimeJS(){
echo "\n\n/* Took ".number_format(time()+microtime()-$this->start_time,5).'s */';
}
+ // }}}
+
+ // {{{ License checking function
+ final function license(){
+ return $this->_license;
+ }
+ final function license_checksum(){
+ return $this->_license_checksum;
+ }
+ final function licenseCheck($product){
+ $id=$this->api->getConfig('license/'.$product.'/id',false);
+ if(!$id)return false;
+
+ $type=$this->api->getConfig('license/'.$product.'/type',false);
+
+ $data=$_SERVER['HTTP_HOST'].'|'.$id.'|'.$type;
+
+ if($type=='agpl'){
+ $data.='|'.$this->api->getConfig('license/'.$product.'/repo',false);
+ }
+
+ // License checksum is required by several modules as they communicate with the main site.
+ // This checksum identifies your Agile Toolkit installation.
+ $this->api->_license_checksum=md5($data);
+
+ if(!function_exists('openssl_get_publickey'))return false;
+
+ $cert=$this->api->getConfig('license/'.$product.'/public',dirname(dirname(__FILE__)).DIRECTORY_SEPARATOR.'cert'.
+ DIRECTORY_SEPARATOR.'atk4.crt');
+
+ $signature=$this->api->getConfig('license/'.$product.'/signature',false);
+ if(!$signature)return false;
+
+ $cert=openssl_get_publickey(file_get_contents($cert));
+ if(!$cert)return false;
+
+ $result = openssl_verify($data,base64_decode($signature),$cert);
+ openssl_free_key($cert);
+
+ if($result==1 && $product=='atk4'){
+ $this->_license=$type;
+ return true; // certificate matched
+ }
+
+ return false;
+ }
/** If version tag is defined in template, inserts current version of Agile Toolkit there. If newer verison is available, it will be reflected */
function upgradeChecker(){
- // Checks for ATK upgrades and shows current version
- if($this->template && $this->template->is_set('version')){
- $this->add('UpgradeChecker',null,'version');
- }
+
+ // try{
+ if($this->template && $this->template->is_set('version')){
+ $this->add('licensor/UpgradeChecker',null,'version');
+ }
+// }catch(PathFinder_Exception $e){}
+
}
// }}}

0 comments on commit 0e47092

Please sign in to comment.