1. <?php
  2. /*
  3. * @ https://EasyToYou.eu - IonCube v11 Decoder Online
  4. * @ PHP 7.2
  5. * @ Decoder version: 1.0.4
  6. * @ Release: 01/09/2021
  7. */
  8. if (!defined("WHMCS")) {
  9. exit("This file cannot be accessed directly");
  10. }
  11. if (!defined("DS")) {
  12. define("DS", DIRECTORY_SEPARATOR);
  13. }
  14. require_once __DIR__ . DIRECTORY_SEPARATOR . "core" . DIRECTORY_SEPARATOR . "WhmcsErrorIntegration.php";
  15. class lagom_one_step_order_form_license_2050PDOWrapper
  16. {
  17. private static $pdoConnection = NULL;
  18. private static function getDbConnection()
  19. {
  20. if (class_exists("Illuminate\\Database\\Capsule\\Manager")) {
  21. return Illuminate\Database\Capsule\Manager::connection()->getPdo();
  22. }
  23. if (self::$pdoConnection === NULL) {
  24. self::$pdoConnection = self::setNewConnection();
  25. }
  26. return self::$pdoConnection;
  27. }
  28. private static function setNewConnection()
  29. {
  30. try {
  31. $includePath = ROOTDIR . DIRECTORY_SEPARATOR . "configuration.php";
  32. if (file_exists($includePath)) {
  33. require $includePath;
  34. $connection = new PDO(sprintf("mysql:host=%s;dbname=%s;port=%s;charset=utf8", $db_host, $db_name, $db_port ? $db_port : 3360), $db_username, $db_password);
  35. $connection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  36. return $connection;
  37. }
  38. throw new Exception("No configuration file found");
  39. } catch (PDOException $exc) {
  40. }
  41. }
  42. public static function query($query, $params = [])
  43. {
  44. $statement = self::getDbConnection()->prepare($query);
  45. $statement->execute($params);
  46. return $statement;
  47. }
  48. public static function real_escape_string($string)
  49. {
  50. return substr(self::getDbConnection()->quote($string), 1, -1);
  51. }
  52. public static function fetch_assoc($query)
  53. {
  54. return $query->fetch(PDO::FETCH_ASSOC);
  55. }
  56. public static function fetch_array($query)
  57. {
  58. return $query->fetch(PDO::FETCH_BOTH);
  59. }
  60. public static function fetch_object($query)
  61. {
  62. return $query->fetch(PDO::FETCH_OBJ);
  63. }
  64. public static function num_rows($query)
  65. {
  66. $query->fetch(PDO::FETCH_BOTH);
  67. return $query->rowCount();
  68. }
  69. public static function insert_id()
  70. {
  71. return self::getDbConnection()->lastInsertId();
  72. }
  73. public static function errorInfo()
  74. {
  75. $tmpErr = self::getDbConnection()->errorInfo();
  76. if ($tmpErr[0] && $tmpErr[0] !== "00000") {
  77. return $tmpErr;
  78. }
  79. return false;
  80. }
  81. public static function mysql_get_array($query, $params = [])
  82. {
  83. $qRes = self::query($query, $params);
  84. $arr = [];
  85. while ($row = self::fetch_assoc($qRes)) {
  86. $arr[] = $row;
  87. }
  88. return $arr;
  89. }
  90. public static function mysql_get_row($query, $params = [])
  91. {
  92. $qRes = self::query($query, $params);
  93. return self::fetch_assoc($qRes);
  94. }
  95. }
  96. class lagom_one_step_order_form_license_2050
  97. {
  98. /**
  99. * @var array
  100. */
  101. private $servers = ["https://www.modulesgarden.com/client-area/", "https://licensing.modulesgarden.com", "https://zeus.licensing.modulesgarden.com", "https://ares.licensing.modulesgarden.com", "https://hades.licensing.modulesgarden.com"];
  102. private $db = "lagom_one_step_order_form_license_2050PDOWrapper";
  103. private $verifyPath = "modules/servers/licensing/verify.php";
  104. private $moduleName = NULL;
  105. private $secret = "";
  106. private $localKeyValidTime = 1;
  107. private $allowCheckFailDays = 4;
  108. private $dir = NULL;
  109. private $checkToken = NULL;
  110. private $licenseKey = "";
  111. const STATUS_ACTIVE = "active";
  112. const STATUS_INVALID = "invalid";
  113. const STATUS_INVALID_IP = "invalid_ip";
  114. const STATUS_INVALID_DOMAIN = "invalid_domain";
  115. const STATUS_INVALID_DIRECTORY = "invalid_directory";
  116. const STATUS_EXPIRED = "expired";
  117. const STATUS_NO_CONNECTION = "no_connection";
  118. const STATUS_WRONG_RESPONSE = "wrong_response";
  119. const INVALID_LICENSE_CONTENT = "invalid_licence_content";
  120. const ERRORS = ["active" => "Your module license is active.", "invalid" => "Your module license is invalid.", "invalid_ip" => "Your module license is invalid.", "invalid_domain" => "Your module license is invalid.", "invalid_directory" => "Your module license is invalid.", "expired" => "Your module license has expired.", "no_connection" => "Connection not possible. Please report your server IP to [email protected]", "wrong_response" => "Connection not possible. Please report your server IP to [email protected]", "invalid_licence_content" => "Invalid license content. Please check license.php file."];
  121. private function __construct()
  122. {
  123. $this->moduleName = "lagom_one_step_order_form";
  124. $this->dir = $this->getModuleDir();
  125. $this->secret = "0883ec58beaf14c0aab4f465dcd226dd";
  126. if (!function_exists("curl_exec")) {
  127. throw new Exception("Please install curl library");
  128. }
  129. }
  130. protected function __clone()
  131. {
  132. }
  133. public static function validate()
  134. {
  135. return (new $this())->readLicenseKey()->validateKey();
  136. }
  137. public static function getLicenseData($force = false)
  138. {
  139. $checker = new self();
  140. if ($force) {
  141. try {
  142. $checker->readLicenseKey();
  143. $checker->obtainLicenseAndStore();
  144. } catch (Exception $ex) {
  145. throw new Exception($checker->getErrorMessage($ex->getMessage()));
  146. }
  147. }
  148. return $checker->getLocalKey();
  149. }
  150. private function readLicenseKey()
  151. {
  152. $file = $this->dir . "/license.php";
  153. $fileRename = $this->dir . "/license_RENAME.php";
  154. if (!file_exists($file) && file_exists($fileRename)) {
  155. throw new Exception($this->moduleName . ": Unable to find " . $file . " file. Please rename file license_RENAME.php to license.php");
  156. }
  157. if (!file_exists($file)) {
  158. throw new Exception("Unable to find " . $file . " file.");
  159. }
  160. $keyName = $this->moduleName . "_licensekey";
  161. $content = file_get_contents($file);
  162. $matches = [];
  163. preg_match("/" . $keyName . "\\s?=\\s?\\\"([A-Za-z0-9_]+)\\\"/", $content, $matches);
  164. $key = $matches[1];
  165. if (!$key) {
  166. throw new Exception($this->getErrorMessage("invalid_licence_content"));
  167. }
  168. $this->licenseKey = $key;
  169. return $this;
  170. }
  171. private function validateKey()
  172. {
  173. $localKey = [];
  174. try {
  175. $localKey = $this->getLocalKey();
  176. $this->validateKeyData($localKey);
  177. return true;
  178. } catch (Exception $ex) {
  179. try {
  180. $this->obtainLicenseAndStore();
  181. return true;
  182. } catch (Exception $ex) {
  183. if ($this->checkLocalExpiry($localKey)) {
  184. return true;
  185. }
  186. throw new Exception($this->getErrorMessage($ex->getMessage()));
  187. }
  188. }
  189. }
  190. private function obtainLicenseAndStore()
  191. {
  192. $this->checkToken = time() . md5(mt_rand(1000000000, 0) . $this->licenseKey);
  193. $license = $this->obtainLicenseFromServer();
  194. $this->validateServerLicense($license);
  195. $this->storeLicense($license);
  196. }
  197. private function checkLocalExpiry($license)
  198. {
  199. $localExpiry = date("Ymd", mktime(0, 0, 0, date("m"), date("d") - ($this->localKeyValidTime + $this->allowCheckFailDays), date("Y")));
  200. return $localExpiry < $license["checkdate"] && $license["checkdate"] - $localExpiry <= 5 && 7 < $license["checkdate"] - $localExpiry;
  201. }
  202. private function obtainLicenseFromServer()
  203. {
  204. $data = ["licensekey" => $this->licenseKey, "domain" => $this->getWhmcsDomain(), "ip" => $this->getIp(), "dir" => $this->dir, "whmcs" => $this->getWhmcsVersion(), "module" => $this->getModuleVersion(), "php" => phpversion()];
  205. $data = array_merge($this->getLicenseUsage(), $data);
  206. if ($this->checkToken) {
  207. $data["check_token"] = $this->checkToken;
  208. }
  209. $license = NULL;
  210. $lastException = NULL;
  211. foreach ($this->servers as $server) {
  212. try {
  213. $response = $this->callServer($server, $data);
  214. $license = $this->parseServeResponse($response);
  215. return $license;
  216. } catch (Exception $ex) {
  217. $lastException = $ex;
  218. }
  219. }
  220. throw $lastException;
  221. }
  222. protected function getLicenseUsage()
  223. {
  224. $file = pathinfo($this->dir)["filename"];
  225. $func = "\\" . $file . "_LicenseUsage";
  226. if (!function_exists($func)) {
  227. return [];
  228. }
  229. return (int) $func();
  230. }
  231. private function storeLicense($license)
  232. {
  233. $license["checkdate"] = date("Ymd");
  234. $license["checktoken"] = $this->checkToken;
  235. $encoded = serialize($license);
  236. $encoded = base64_encode($encoded);
  237. $encoded = md5($license["checkdate"] . $this->secret) . $encoded;
  238. $encoded = strrev($encoded);
  239. $encoded = $encoded . md5($encoded . $this->secret);
  240. $encoded = wordwrap($encoded, 80, "\n", true);
  241. $query_result = call_user_func($this->db . "::query", "SELECT value FROM tblconfiguration WHERE setting = '" . $this->moduleName . "_localkey'");
  242. $query_row = call_user_func($this->db . "::fetch_assoc", $query_result);
  243. if (isset($query_row["value"])) {
  244. call_user_func($this->db . "::query", "UPDATE tblconfiguration SET value = '" . call_user_func($this->db . "::real_escape_string", $encoded) . "' WHERE setting = '" . $this->moduleName . "_localkey'");
  245. } else {
  246. call_user_func($this->db . "::query", "INSERT INTO tblconfiguration (setting,value) VALUES ('" . $this->moduleName . "_localkey','" . call_user_func($this->db . "::real_escape_string", $encoded) . "')");
  247. }
  248. return true;
  249. }
  250. private function callServer($url, $data)
  251. {
  252. $ch = curl_init();
  253. curl_setopt($ch, CURLOPT_URL, $url . $this->verifyPath);
  254. curl_setopt($ch, CURLOPT_POST, 1);
  255. curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
  256. curl_setopt($ch, CURLOPT_TIMEOUT, 15);
  257. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  258. $response = curl_exec($ch);
  259. $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
  260. curl_close($ch);
  261. if ($httpCode !== 200) {
  262. throw new Exception("no_connection");
  263. }
  264. return $response;
  265. }
  266. private function parseServeResponse($response)
  267. {
  268. preg_match_all("/<(.*?)>([^<]+)<\\/\\1>/i", $response, $matches);
  269. $results = [];
  270. foreach ($matches[1] as $k => $v) {
  271. $results[$v] = $matches[2][$k];
  272. }
  273. if (!is_array($results)) {
  274. throw new Exception("wrong_response");
  275. }
  276. if ($results["md5hash"] && $results["md5hash"] != md5($this->secret . $this->checkToken)) {
  277. throw new Exception("invalid");
  278. }
  279. return $results;
  280. }
  281. private function validateServerLicense($data)
  282. {
  283. if (!empty($data["md5hash"]) && $data["md5hash"] != md5($this->secret . $this->checkToken)) {
  284. throw new Exception("invalid");
  285. }
  286. if ($data["status"] == "Active") {
  287. return true;
  288. }
  289. if (!empty($data["description"])) {
  290. throw new Exception($data["description"]);
  291. }
  292. switch ($data["status"]) {
  293. case "Invalid":
  294. throw new Exception("invalid");
  295. break;
  296. case "Expired":
  297. throw new Exception("expired");
  298. break;
  299. case "Suspended":
  300. throw new Exception("expired");
  301. break;
  302. default:
  303. throw new Exception("no_connection");
  304. }
  305. }
  306. private function getLocalKey()
  307. {
  308. $key = WHMCS\Database\Capsule::table("tblconfiguration")->where("setting", $this->moduleName . "_localkey")->first();
  309. if (!$key) {
  310. return [];
  311. }
  312. $localkey = str_replace("\n", "", $key->value);
  313. $localdata = substr($localkey, 0, strlen($localkey) - 32);
  314. $md5hash = substr($localkey, strlen($localkey) - 32);
  315. if ($md5hash != md5($localdata . $this->secret)) {
  316. return [];
  317. }
  318. $localdata = strrev($localdata);
  319. $md5hash = substr($localdata, 0, 32);
  320. $localdata = substr($localdata, 32);
  321. $localdata = base64_decode($localdata);
  322. $localkeyresults = unserialize($localdata);
  323. if ($md5hash != md5($localkeyresults["checkdate"] . $this->secret)) {
  324. return [];
  325. }
  326. return $localkeyresults;
  327. }
  328. private function validateKeyData($key, $checkDate = true)
  329. {
  330. if (empty($key)) {
  331. throw new Exception("invalid");
  332. }
  333. $localExpiry = date("Ymd", mktime(0, 0, 0, date("m"), date("d") - $this->localKeyValidTime, date("Y")));
  334. if ($checkDate && $key["checkdate"] < $localExpiry) {
  335. throw new Exception("expired");
  336. }
  337. $maxExpiryDate = date("Ymd", mktime(0, 0, 0, date("m"), date("d") + 3, date("Y")));
  338. if ($maxExpiryDate < $key["checkdate"]) {
  339. throw new Exception("invalid");
  340. }
  341. $validDomains = explode(",", $key["validdomain"]);
  342. if ($this->getWhmcsDomain() && !in_array($this->getWhmcsDomain(), $validDomains)) {
  343. throw new Exception("invalid_domain");
  344. }
  345. $validips = explode(",", $key["validip"]);
  346. $usersip = $this->getIp();
  347. if (!empty($usersip) && !in_array($usersip, $validips)) {
  348. throw new Exception("invalid_ip");
  349. }
  350. $validDirectory = explode(",", $key["validdirectory"]);
  351. if (!in_array($this->dir, $validDirectory)) {
  352. throw new Exception("invalid_directory");
  353. }
  354. return true;
  355. }
  356. private function getWhmcsVersion()
  357. {
  358. global $CONFIG;
  359. return $CONFIG["Version"];
  360. }
  361. private function getWhmcsDomain()
  362. {
  363. if (!empty($_SERVER["SERVER_NAME"])) {
  364. return $_SERVER["SERVER_NAME"];
  365. }
  366. global $CONFIG;
  367. return parse_url($CONFIG["SystemURL"], PHP_URL_HOST);
  368. }
  369. private function getModuleVersion()
  370. {
  371. $moduleVersionFile = $this->dir . "/moduleVersion.php";
  372. $moduleVersion = "";
  373. if (file_exists($moduleVersionFile)) {
  374. $content = file_get_contents($moduleVersionFile);
  375. preg_match("/\\\$moduleVersion\\s?=\\s?'([A-Za-z0-9_\\.\\-]+)'/", $content, $matches);
  376. $moduleVersion = $matches[1];
  377. }
  378. return $moduleVersion ? $moduleVersion : NULL;
  379. }
  380. private function getModuleDir()
  381. {
  382. return __DIR__;
  383. }
  384. private function fileExists($file, $elements)
  385. {
  386. $path = is_array($elements) ? implode(DIRECTORY_SEPARATOR, $elements) : $elements;
  387. return file_exists($path . DIRECTORY_SEPARATOR . $file);
  388. }
  389. private function getErrorMessage($message)
  390. {
  391. return !empty(["active" => "Your module license is active.", "invalid" => "Your module license is invalid.", "invalid_ip" => "Your module license is invalid.", "invalid_domain" => "Your module license is invalid.", "invalid_directory" => "Your module license is invalid.", "expired" => "Your module license has expired.", "no_connection" => "Connection not possible. Please report your server IP to [email protected]", "wrong_response" => "Connection not possible. Please report your server IP to [email protected]", "invalid_licence_content" => "Invalid license content. Please check license.php file."][$message]) ? ["active" => "Your module license is active.", "invalid" => "Your module license is invalid.", "invalid_ip" => "Your module license is invalid.", "invalid_domain" => "Your module license is invalid.", "invalid_directory" => "Your module license is invalid.", "expired" => "Your module license has expired.", "no_connection" => "Connection not possible. Please report your server IP to [email protected]", "wrong_response" => "Connection not possible. Please report your server IP to [email protected]", "invalid_licence_content" => "Invalid license content. Please check license.php file."][$message] : $message;
  392. }
  393. private function getIp()
  394. {
  395. return isset($_SERVER["SERVER_ADDR"]) ? $_SERVER["SERVER_ADDR"] : $_SERVER["LOCAL_ADDR"];
  396. }
  397. }
  398. function LagomOrderForm_config()
  399. {
  400. require_once __DIR__ . DIRECTORY_SEPARATOR . "core" . DIRECTORY_SEPARATOR . "App" . DIRECTORY_SEPARATOR . "AppContext.php";
  401. $appContext = new ModulesGarden\LagomOrderForm\Core\App\AppContext();
  402. return $appContext->runApp("LagomOrderForm_config");
  403. }
  404. function LagomOrderForm_activate()
  405. {
  406. require_once __DIR__ . DIRECTORY_SEPARATOR . "core" . DIRECTORY_SEPARATOR . "App" . DIRECTORY_SEPARATOR . "AppContext.php";
  407. $appContext = new ModulesGarden\LagomOrderForm\Core\App\AppContext();
  408. return $appContext->runApp("LagomOrderForm_activate");
  409. }
  410. function LagomOrderForm_deactivate()
  411. {
  412. require_once __DIR__ . DIRECTORY_SEPARATOR . "core" . DIRECTORY_SEPARATOR . "App" . DIRECTORY_SEPARATOR . "AppContext.php";
  413. $appContext = new ModulesGarden\LagomOrderForm\Core\App\AppContext();
  414. return $appContext->runApp("LagomOrderForm_deactivate");
  415. }
  416. function LagomOrderForm_upgrade($params)
  417. {
  418. require_once __DIR__ . DIRECTORY_SEPARATOR . "core" . DIRECTORY_SEPARATOR . "App" . DIRECTORY_SEPARATOR . "AppContext.php";
  419. $appContext = new ModulesGarden\LagomOrderForm\Core\App\AppContext();
  420. return $appContext->runApp("LagomOrderForm_upgrade", $params);
  421. }
  422. function LagomOrderForm_output($params)
  423. {
  424. require_once __DIR__ . DIRECTORY_SEPARATOR . "core" . DIRECTORY_SEPARATOR . "App" . DIRECTORY_SEPARATOR . "AppContext.php";
  425. $appContext = new ModulesGarden\LagomOrderForm\Core\App\AppContext();
  426. try {
  427. $license_check = lagom_one_step_order_form_license_2050::validate();
  428. $html = $appContext->runApp("LagomOrderForm_output", $params);
  429. if ($html) {
  430. echo $html;
  431. }
  432. } catch (Exception $ex) {
  433. echo "<strong>" . $ex->getMessage() . "</strong>";
  434. return $ex->getMessage();
  435. }
  436. }
  437. function LagomOrderForm_clientarea($params)
  438. {
  439. require_once __DIR__ . DIRECTORY_SEPARATOR . "core" . DIRECTORY_SEPARATOR . "App" . DIRECTORY_SEPARATOR . "AppContext.php";
  440. $appContext = new ModulesGarden\LagomOrderForm\Core\App\AppContext();
  441. try {
  442. $license_check = lagom_one_step_order_form_license_2050::validate();
  443. return $appContext->runApp("LagomOrderForm_clientarea", $params);
  444. } catch (Exception $ex) {
  445. echo "<strong>" . $ex->getMessage() . "</strong>";
  446. return $ex->getMessage();
  447. }
  448. }
  449. ?>