/** * Public function that creates a single instance */ public static function getInstance() { if (!isset(self::$_instance)) { self::$_instance = new self(); } return self::$_instance; }
public function saveDataLicense($results, $path) { try { //getting info about file $LicenseUid = G::generateUniqueID(); $LicenseUser = $results['DATA']['FIRST_NAME'] . ' ' . $results['DATA']['LAST_NAME']; $LicenseStart = $results['DATE']['START']; $LicenseEnd = $results['DATE']['END']; $LicenseSpan = $results['DATE']['SPAN']; $LicenseStatus = $this->lookForStatusLicense(); //we're looking for a status ACTIVE //getting the content from file G::LoadSystem('inputfilter'); $filter = new InputFilter(); $path = $filter->xssFilterHard($path, 'path'); $handle = fopen($path, "r"); $contents = fread($handle, filesize($path)); fclose($handle); $LicenseData = $contents; $LicensePath = $path; $LicenseWorkspace = isset($results['DATA']['DOMAIN_WORKSPACE']) ? $results['DATA']['DOMAIN_WORKSPACE'] : ''; $LicenseType = $results['DATA']['TYPE']; require_once "classes/model/LicenseManager.php"; //if exists the row in the database propel will update it, otherwise will insert. $tr = LicenseManagerPeer::retrieveByPK($LicenseUid); if (!(is_object($tr) && get_class($tr) == 'LicenseManager')) { $tr = new LicenseManager(); } $tr->setLicenseUid($LicenseUid); $tr->setLicenseUser($LicenseUser); $tr->setLicenseStart($LicenseStart); $tr->setLicenseEnd($LicenseEnd); $tr->setLicenseSpan($LicenseSpan); $tr->setLicenseStatus($LicenseStatus); $tr->setLicenseData($LicenseData); $tr->setLicensePath($LicensePath); $tr->setLicenseWorkspace($LicenseWorkspace); $tr->setLicenseType($LicenseType); $res = $tr->save(); } catch (Exception $e) { G::pr($e); } }
function testSecurity_Licensing_LicenseManager() { $base = dirname(__FILE__); define('LIC_PRODUCTID', 1); $LicenseManager = new LicenseManager(); $LicenseManager->ErrorOnFailure = false; $LicenseManager->SetFrequency(100); // Create temp file $path = ($path = ini_get("session.save_path")) ? $path : "/tmp"; @unlink("{$path}/ip.lic"); @unlink("{$path}/trial.lic"); // // Generate IP lic // $lic = $LicenseManager->GenerateLic("ip", "192.168.1.253", time() + 100000000, "10", "Jobs", LIC_PRODUCTID); $res = file_put_contents("{$path}/ip.lic", $lic); //exit(); $this->assertTrue($lic, "License string is not empty"); // Valdate lic if ($LicenseManager->DoTriggerValidation()) { $LicenseManager->LoadLicFiles($path); $result = $LicenseManager->ValidateLic(); $this->assertTrue($result, "IP lic not validated"); } @unlink("{$path}/ip.lic"); // // Generate trial expired lic // $lic = $LicenseManager->GenerateLic("trial", "", time() - 1, "10", "WHMCluster", LIC_PRODUCTID); $res = file_put_contents("{$path}/trial.lic", $lic); // Validate lic $LicenseManager->LoadLicFiles($path); $result = $LicenseManager->ValidateLic(); $this->assertFalse($result, "Trial expired lic not validated"); /* */ // // Validate trial then ip // $lic = $LicenseManager->GenerateLic("trial", "", time() - 1, "10", "WHMCluster", LIC_PRODUCTID); $res = file_put_contents("{$path}/trial.lic", $lic); $lic = $LicenseManager->GenerateLic("ip", "192.168.1.253", time() + 100000000, "10", "WorldOfEU", LIC_PRODUCTID); file_put_contents("{$path}/ip.lic", $lic); // Now we have 1 expired trial and 1 valid IP $LicenseManager->LoadLicFiles($path); $result = $LicenseManager->ValidateLic(); $this->assertTrue($result, "Expired trial and valid IP bundle validated ok"); // // Generate trial OK lic // $lic = $LicenseManager->GenerateLic("trial", "", time() + 100000000, "10", "WHMCluster", LIC_PRODUCTID); $res = file_put_contents("{$path}/trial.lic", $lic); // Valdate lic $LicenseManager->LoadLicFiles($path); $result = $LicenseManager->ValidateLic(); $this->assertTrue($result, "Trial lic validated ok"); @unlink("{$path}/trial.lic"); // Check frequency stuff $LicenseManager->SetFrequency(0); $this->assertFalse($LicenseManager->DoTriggerValidation(), "DoTriggerValidation() returned false"); #$lic = $LicenseManager->GenerateLic("trial", "", time()+1000000, "11", "WHMCluster"); #file_put_contents("$path/trial.lic", $lic); #$lic = $LicenseManager->GenerateLic("ip", "209.200.241.38", time()+200000000, "103", "EPP-DRS"); #$res = file_put_contents("$path/ip.lic", $lic); /* */ @unlink("{$path}/ip.lic"); @unlink("{$path}/trial.lic"); // generate lic for one product and validate for other $lic = $LicenseManager->GenerateLic("ip", "192.168.1.253", time() + 100000000, "10", "WorldOfEU", LIC_PRODUCTID . "1"); file_put_contents("{$path}/ip.lic", $lic); $LicenseManager->LoadLicFiles($path); $result = $LicenseManager->ValidateLic(); $this->assertFalse($result, "License generated for other product then validated"); @unlink("{$path}/ip.lic"); $md5_prepend = @md5_file(LIBWEBTA_BASE . "/../../prepend.inc.php"); $md5_lic = @md5_file(dirname(__FILE__) . "/class.LicenseManager.php"); // check md5 sum of files $lic = $LicenseManager->GenerateLic("ip", "192.168.1.253", time() + 100000000, "10", "WorldOfEU", LIC_PRODUCTID, $md5_prepend, $md5_lic); file_put_contents("{$path}/ip.lic", $lic); $LicenseManager->LoadLicFiles($path); $result = $LicenseManager->ValidateLic(); $this->assertTrue($result, "License generated with checking md5 is invalid"); // check md5 sum of files $lic = $LicenseManager->GenerateLic("ip", "192.168.1.253", time() + 100000000, "10", "WorldOfEU", LIC_PRODUCTID, $md5_prepend, "---"); file_put_contents("{$path}/ip.lic", $lic); $LicenseManager->LoadLicFiles($path); $result = $LicenseManager->ValidateLic(); $this->assertFalse($result, "License generated with checking md5 is valid"); }
/** * Handle drawing of license list * * @param array $tag_param * @param array $children */ public function tag_LicenseList($tag_param, $children) { $manager = LicenseManager::getInstance(); $items = $manager->getItems($manager->getFieldNames(), array()); if (isset($tag_params['template'])) { if (isset($tag_params['local']) && $tag_params['local'] == 1) { $template = new TemplateHandler($tag_params['template'], $this->path . 'templates/'); } else { $template = new TemplateHandler($tag_params['template']); } } else { $template = new TemplateHandler('list_item.xml', $this->path . 'templates/'); } if (count($items) > 0) { foreach ($items as $item) { $params = array('license' => $item->license, 'domain' => $item->domain, 'active' => $item->active, 'item_change' => url_MakeHyperlink($this->getLanguageConstant('change'), window_Open('licenses_change', 400, $this->getLanguageConstant('title_licenses_change'), false, false, url_Make('transfer_control', 'backend_module', array('module', $this->name), array('backend_action', 'change'), array('id', $item->id)))), 'item_delete' => url_MakeHyperlink($this->getLanguageConstant('delete'), window_Open('licenses_delete', 400, $this->getLanguageConstant('title_licenses_delete'), false, false, url_Make('transfer_control', 'backend_module', array('module', $this->name), array('backend_action', 'delete'), array('id', $item->id))))); $template->restoreXML(); $template->setLocalParams($params); $template->parse(); } } }