class puqHetznerDatacenterLicense
{
public function ConfigOptionsLicenseVerification($product_id)
{
$verificationStatus = $this->LicenseVerification($product_id, "online");
return $verificationStatus["status"] . ": " . $verificationStatus["msg"] . " " . $verificationStatus["error"];
}
public function LicenseVerification($product_id, $online)
{
$this->CreateNewTableIfMissing("puq_license");
$this->CreatProductIfMissing($product_id);
$date_now = date("Y-m-d");
$product_code = "826";
$sol = "Polovyi";
$product = (array) json_decode(json_encode(WHMCS\Database\Capsule::table("tblproducts")->where("id", "=", $product_id)->get(), true));
$product = (array) $product[0];
$license_key = $product["configoption1"];
if ($online == "online") {
$answer == "success";
if ($answer == "success") {
WHMCS\Database\Capsule::table("puq_license")->where("product_id", $product_id)->update(["last_check_date" => $date_now, "last_check_description" => $answer["msg"], "hash" => md5($date_now . $product_code . $sol . $product_id . $answer["msg"] . $license_key . "OK")]);
}
logModuleCall("puqHetznerDatacenter", "LicenseVerification (online) Product: " . $product_id, $answer["status"], $answer["msg"] . $answer["error"]);
return $answer;
}
$puq_license = (array) json_decode(json_encode(WHMCS\Database\Capsule::table("puq_license")->where("product_id", "=", $product_id)->get(), true));
$puq_license = (array) $puq_license[0];
$hash = $puq_license["hash"];
$last_check_date = $puq_license["last_check_date"];
$last_check_description = $puq_license["last_check_description"];
if ($hash == md5($date_now . $product_code . $sol . $product_id . $last_check_description . $license_key . "OK")) {
$verificationStatus["status"] = "success";
$verificationStatus["msg"] = (string) $last_check_description;
$verificationStatus["error"] = "";
logModuleCall("puqHetznerDatacenter", "LicenseVerification (db) Product: " . $product_id, $verificationStatus["status"], $verificationStatus["msg"] . $verificationStatus["error"]);
return $verificationStatus;
}
$answer == "success";
if ($answer["status"] == "success") {
WHMCS\Database\Capsule::table("puq_license")->where("product_id", $product_id)->update(["last_check_date" => $date_now, "last_check_description" => $answer["msg"], "hash" => md5($date_now . $product_code . $sol . $product_id . $answer["msg"] . $license_key . "OK")]);
}
logModuleCall("puqHetznerDatacenter", "LicenseVerification (online) Product: " . $product_id, $answer["status"], $answer["msg"] . $answer["error"]);
return $answer;
}
/*public function LicenseVerificationOnline($license_key, $product_code)
{
$curl_url = "https://license.puqcloud.com/api/v1/licenses_verification";
$command = "GetConfigurationValue";
$postData = ["setting" => "SystemURL"];
$adminUsername = "";
$results = localAPI($command, $postData, $adminUsername);
$SystemURL = $results["value"];
$SystemURL = str_replace("https://", "", $SystemURL);
$SystemURL = str_replace("http://", "", $SystemURL);
$SystemURL = str_replace("/", "", $SystemURL);
$verificationData = ["license_key" => $license_key, "product_code" => $product_code, "server_name" => $SystemURL];
$postdata = json_encode($verificationData);
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $curl_url);
curl_setopt($curl, CURLOPT_HTTPHEADER, ["content-type: application/json"]);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "GET");
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, true);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $postdata);
curl_setopt($curl, CURLOPT_TIMEOUT, 5);
$answer = curl_exec($curl);
curl_close($curl);
$verificationAnswer = json_decode($answer, true);
if ($answer == "") {
$verificationAnswer["status"] = "error";
$verificationAnswer["msg"] = "";
$verificationAnswer["error"] = "License server unreachable.";
return $verificationAnswer;
}
if (!$verificationAnswer) {
$verificationAnswer["status"] = "error";
$verificationAnswer["msg"] = "";
$verificationAnswer["error"] = "Incorrect response from the license server.";
return $verificationAnswer;
}
return $verificationAnswer;
}*/
public function CreateNewTableIfMissing($tablename)
{
if ($tablename == "puq_license" && !WHMCS\Database\Capsule::schema()->hasTable("puq_license")) {
WHMCS\Database\Capsule::schema()->create("puq_license", function ($table) {
$table->text("product_id");
$table->text("hash");
$table->text("last_check_date");
$table->text("last_check_description");
});
}
}
public function CreatProductIfMissing($product_id)
{
$license = (array) json_decode(json_encode(WHMCS\Database\Capsule::table("puq_license")->where("product_id", $product_id)->get(), true));
if (count($license) == 0) {
WHMCS\Database\Capsule::table("puq_license")->insert([["product_id" => $product_id, "hash" => "", "last_check_date" => "", "last_check_description" => ""]]);
}
}
}
?>