Advertisement
Guest User

Untitled

a guest
Feb 16th, 2016
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 33.42 KB | None | 0 0
  1. <?php
  2.  
  3. abstract class nucleo
  4. {
  5. public static function obtenerParametro(&$arr, $nombre, $defecto = NULL)
  6. {
  7. if( isset($arr[$nombre]) )
  8. {
  9. return $arr[$nombre];
  10. }
  11.  
  12. return $defecto;
  13. }
  14.  
  15. public static function modSecStatus()
  16. {
  17. $file = "/usr/share/ilabs_antimalware/logs/ok.txt";
  18. file_put_contents($file, "");
  19. $cmd = "wget local.pyxsoft.com?PYX_getStatus -O /dev/null -q";
  20. shell_exec($cmd);
  21. $res = file_get_contents($file);
  22. return $res == "OK" ? true : false;
  23. }
  24.  
  25. public static function guardarEnArchivo($datos, $file, $encoded = false)
  26. {
  27. $datos = serialize($datos);
  28. if( $encoded )
  29. {
  30. $datos = self::encodeString(base64_encode($datos));
  31. }
  32.  
  33. if( !file_put_contents($file, $datos) )
  34. {
  35. error_log("No se pudo escribir el archivo cache/datos/" . $file . " (nucleo::guardarEnArchivo)");
  36. }
  37.  
  38. }
  39.  
  40. public static function obtenerDeArchivo($file, $defecto = NULL)
  41. {
  42. $datos = $defecto;
  43. if( file_exists($file) )
  44. {
  45. $datos = file_get_contents($file);
  46. if( strpos($datos, "**!ENC!**") !== false )
  47. {
  48. $datos = base64_decode(self::decodeString($datos));
  49. }
  50.  
  51. $datos = unserialize($datos);
  52. }
  53.  
  54. return $datos;
  55. }
  56.  
  57. public static function base64UrlEncode($data)
  58. {
  59. return strtr(rtrim(base64_encode($data), "="), "+/", "-_");
  60. }
  61.  
  62. public static function base64UrlDecode($base64)
  63. {
  64. return base64_decode(strtr($base64, "-_", "+/"));
  65. }
  66.  
  67. public static function getExt($filename)
  68. {
  69. $e = preg_match("/\\.([^\\.]+)\$/", $filename, $res);
  70. if( isset($res[1]) )
  71. {
  72. return strtolower("." . $res[1]);
  73. }
  74.  
  75. return "";
  76. }
  77.  
  78. public static function obtenerConfiguracion()
  79. {
  80. $dir = "/usr/share/ilabs_antimalware";
  81. require($dir . "/default_conf.php");
  82. foreach( $dcf as $key => $value )
  83. {
  84. $v[$key] = $value["default"];
  85. }
  86. if( file_exists($dir . "/conf.dat") )
  87. {
  88. $datos = file_get_contents($dir . "/conf.dat");
  89. $datos = unserialize($datos);
  90. $v = array_merge($v, $datos);
  91. }
  92.  
  93. return $v;
  94. }
  95.  
  96. public static function mySQL_obtenerCredenciales()
  97. {
  98. $file = "/root/.my.cnf";
  99. $res = array( "user" => "", "pass" => "" );
  100. if( file_exists($file) )
  101. {
  102. $data = file_get_contents($file);
  103. if( preg_match("/^pass=(.+)/im", $data, $matches) )
  104. {
  105. $res["pass"] = trim($matches[1], " \"\n\r");
  106. }
  107.  
  108. if( preg_match("/^user=(.+)/im", $data, $matches) )
  109. {
  110. $res["user"] = trim($matches[1], " \n\r");
  111. }
  112.  
  113. }
  114.  
  115. return $res;
  116. }
  117.  
  118. public static function obtenerIdiomaUsuario($username)
  119. {
  120. $res = "en";
  121. if( file_exists("/var/cpanel/users/" . $username) )
  122. {
  123. $res = shell_exec("grep 'LOCALE' /var/cpanel/users/" . $username . " | cut -d '=' -f 2");
  124. if( $res == "" )
  125. {
  126. $res = "en";
  127. }
  128.  
  129. }
  130.  
  131. return $res;
  132. }
  133.  
  134. private static function clamav_getPath()
  135. {
  136. $res = "/usr/bin";
  137. if( file_exists("/usr/local/cpanel/3rdparty/bin/clamscan") )
  138. {
  139. $res = "/usr/local/cpanel/3rdparty/bin";
  140. }
  141.  
  142. return $res;
  143. }
  144.  
  145. public static function clamav_getClamscan()
  146. {
  147. return self::clamav_getPath() . "/clamscan";
  148. }
  149.  
  150. public static function clamav_getClamdscan()
  151. {
  152. return self::clamav_getPath() . "/clamdscan";
  153. }
  154.  
  155. public static function clamav_getDBPath()
  156. {
  157. $res = "";
  158. if( file_exists("/var/lib/clamav") )
  159. {
  160. $res = "/var/lib/clamav";
  161. }
  162.  
  163. if( file_exists("/var/clamav") )
  164. {
  165. $res = "/var/clamav";
  166. }
  167.  
  168. if( file_exists("/usr/share/clamav") )
  169. {
  170. $res = "/usr/share/clamav";
  171. }
  172.  
  173. if( file_exists("/usr/local/cpanel/3rdparty/share/clamav") )
  174. {
  175. $res = "/usr/local/cpanel/3rdparty/share/clamav";
  176. }
  177.  
  178. return $res;
  179. }
  180.  
  181. public static function age()
  182. {
  183. if( !file_exists("/usr/local/cpanel/whostmgr/docroot/cgi/addon_antimalware.php") )
  184. {
  185. return 1000;
  186. }
  187.  
  188. $r = filemtime("/usr/local/cpanel/whostmgr/docroot/cgi/addon_antimalware.php");
  189. $d = time() - $r;
  190. return floor($d / (3600 * 24));
  191. }
  192.  
  193. public static function licencia_valida($cached = true)
  194. {
  195. static $conf;
  196. if( !isset($conf) )
  197. {
  198. $conf = self::obtenerConfiguracion();
  199. }
  200.  
  201. $valor = nucleo::obtenerParametro($conf, "al", NULL);
  202. if( $cached && !is_null($valor) )
  203. {
  204. return $valor;
  205. }
  206.  
  207. $status = nucleo::validar_licencia();
  208. if( $status == "TRIAL" || $status == "" )
  209. {
  210. $valor = 1;
  211. }
  212. else
  213. {
  214. $valor = 0;
  215. }
  216.  
  217. $conf["al"] = $valor;
  218. file_put_contents("/usr/share/ilabs_antimalware/conf.dat", serialize($conf));
  219. return $valor;
  220. }
  221.  
  222. public static function validar_licencia(&$key_data = array( ))
  223. {
  224.  
  225. $key_data["status"] = "Active";
  226. $key_data["license_expires"] = "never";
  227. $key_data["customer"]["name"] = "Nulled By MrQaidi";
  228. $status = "1";
  229.  
  230. }
  231.  
  232. public static function hexToStr($hex)
  233. {
  234. $string = "";
  235. $i = 0;
  236. while( $i < strlen($hex) - 1 )
  237. {
  238. $string .= chr(hexdec($hex[$i] . $hex[$i + 1]));
  239. $i += 2;
  240. }
  241. return $string;
  242. }
  243.  
  244. public static function encodeString($string, $password = "")
  245. {
  246. mb_internal_encoding("UTF-8");
  247. if( $password == "" )
  248. {
  249. $password = self::get_encoderPassword();
  250. }
  251.  
  252. $chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789:{}()[]+-,.= ";
  253. $largo = mb_strlen($chars);
  254. $largoString = mb_strlen($string);
  255. $res = "**!ENC!**";
  256. $idx_pas = 0;
  257. for( $i = 0; $i < $largoString; $i++ )
  258. {
  259. $c = mb_substr($string, $i, 1);
  260. $idx_c = mb_strpos($chars, $c);
  261. if( $idx_c === false )
  262. {
  263. $res .= $c;
  264. }
  265. else
  266. {
  267. $offset = $i + ord($password[$idx_pas]) + $largoString;
  268. $num = $idx_c + $offset;
  269. $idx_pas++;
  270. $idx_pas = $idx_pas % mb_strlen($password);
  271. $num = $num % $largo;
  272. $res .= $chars[$num];
  273. }
  274.  
  275. }
  276. return $res;
  277. }
  278.  
  279. public static function decodeString($string, $password = "")
  280. {
  281. mb_internal_encoding("UTF-8");
  282. if( $password == "" )
  283. {
  284. $password = self::get_encoderPassword();
  285. }
  286.  
  287. $chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789:{}()[]+-,.= ";
  288. $largo = mb_strlen($chars);
  289. $sig = "**!ENC!**";
  290. if( strpos($string, $sig) !== 0 )
  291. {
  292. return $string;
  293. }
  294.  
  295. $res = "";
  296. $string = mb_substr($string, strlen($sig));
  297. $largoString = mb_strlen($string);
  298. $idx_pas = 0;
  299. for( $i = 0; $i < $largoString; $i++ )
  300. {
  301. $c = mb_substr($string, $i, 1);
  302. $idx_c = mb_strpos($chars, $c);
  303. if( $idx_c === false )
  304. {
  305. $res .= $c;
  306. }
  307. else
  308. {
  309. $offset = $i + ord($password[$idx_pas]) + $largoString;
  310. $num = $idx_c - $offset;
  311. $num = ($largo + $num % $largo) % $largo;
  312. if( $num < 0 )
  313. {
  314. $num = $num + $largo;
  315. }
  316.  
  317. $res .= $chars[$num];
  318. $idx_pas++;
  319. $idx_pas = $idx_pas % mb_strlen($password);
  320. }
  321.  
  322. }
  323. return $res;
  324. }
  325.  
  326. public static function autoquarantine_class($name)
  327. {
  328. static $exclude;
  329. if( is_null($exclude) )
  330. {
  331. $conf = self::obtenerConfiguracion();
  332. $exclude = self::obtenerParametro($conf, "aq_exclude", "");
  333. $exclude .= "|txt.pyxsoft-text-file|inject.unclassed|injected: unknown|.susp";
  334. $exclude = strtolower($exclude);
  335. $exclude = explode("|", $exclude);
  336. }
  337.  
  338. if( !$conf["aq_enabled"] )
  339. {
  340. return false;
  341. }
  342.  
  343. $name = strtolower($name);
  344. foreach( $exclude as $e )
  345. {
  346. if( $e == "" )
  347. {
  348. continue;
  349. }
  350.  
  351. if( !strstr($name, $e) === false )
  352. {
  353. return false;
  354. }
  355.  
  356. }
  357. return true;
  358. }
  359.  
  360. public static function isTrial()
  361. {
  362. static $conf;
  363.  
  364. return false;
  365. }
  366.  
  367.  
  368. public static function isLicenseValid(&$status)
  369. { //mrqaidi
  370.  
  371. return true;
  372.  
  373. }
  374.  
  375. public static function graceDay()
  376. {
  377. $file = "/usr/share/ilabs_antimalware/data/gd.dat";
  378. $last = nucleo::obtenerDeArchivo($file, NULL);
  379. if( is_null($last) )
  380. {
  381. return 5000;
  382. }
  383.  
  384. $ahora = floor(time() / 86400);
  385. return $ahora - $last;
  386. }
  387.  
  388. public static function _obfuscated_6372656172436F6E7472617365C3B161_($maxlen = 5)
  389. {
  390. $cadena = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890";
  391. $largo = strlen($cadena);
  392. $password = "";
  393. for( $i = 1; $i <= $maxlen; $i++ )
  394. {
  395. $num = rand(1, $largo) - 1;
  396. $password .= substr($cadena, $num, 1);
  397. }
  398. return $password;
  399. }
  400.  
  401. private static function get_encoderPassword()
  402. {
  403. $file = "/usr/share/ilabs_antimalware/data/enc_pas.dat";
  404. $pas = nucleo::obtenerDeArchivo($file, "");
  405. if( $pas == "" )
  406. {
  407. $pas = self::_obfuscated_6372656172436F6E7472617365C3B161_(10);
  408. $pas = self::encodeString($pas, "ESP209L");
  409. $pas = base64_encode($pas);
  410. if( is_writable($file) )
  411. {
  412. self::guardarEnArchivo($pas, $file);
  413. chmod($file, 420);
  414. }
  415.  
  416. }
  417.  
  418. $pas = self::decodeString(base64_decode($pas), "ESP209L");
  419. return $pas;
  420. }
  421.  
  422. public static function get_platform()
  423. {
  424. if( file_exists("/usr/bin/lscpu") )
  425. {
  426. $res = shell_exec("lscpu");
  427. if( preg_match("#Hypervisor vendor:[\\s\\t]*(.+)#", $res, $matches) )
  428. {
  429. $res = trim(strtoupper($matches[1]));
  430. if( $res == "KVM" )
  431. {
  432. return "KVM";
  433. }
  434.  
  435. if( $res == "XEN" )
  436. {
  437. return "XEN";
  438. }
  439.  
  440. if( $res == "MICROSOFT" )
  441. {
  442. return "Microsoft Hyper-V";
  443. }
  444.  
  445. }
  446.  
  447. }
  448.  
  449. if( file_exists("/proc/vz") && file_exists("/proc/vz/veinfo") )
  450. {
  451. return "OpenVZ/Virtuozzo VPS";
  452. }
  453.  
  454. if( shell_exec("grep 'QEMU' /proc/cpuinfo") != "" )
  455. {
  456. return "KVM VPS";
  457. }
  458.  
  459. if( file_exists("/proc/xen") )
  460. {
  461. return "XEN VPS";
  462. }
  463.  
  464. if( shell_exec("grep 'vps' /var/cpanel/flagscache") != "" )
  465. {
  466. return "cPanel VPS Optimized";
  467. }
  468.  
  469. return "Dedicated Server";
  470. }
  471.  
  472. }
  473.  
  474.  
  475. class spbas
  476. {
  477. public $errors = NULL;
  478. public $license_key = NULL;
  479. public $api_server = NULL;
  480. public $remote_port = NULL;
  481. public $remote_timeout = NULL;
  482. public $local_key_storage = NULL;
  483. public $read_query = NULL;
  484. public $update_query = NULL;
  485. public $local_key_path = NULL;
  486. public $local_key_name = NULL;
  487. public $local_key_transport_order = NULL;
  488. public $local_key_grace_period = NULL;
  489. public $local_key_last = NULL;
  490. public $validate_download_access = NULL;
  491. public $release_date = NULL;
  492. public $key_data = NULL;
  493. public $status_messages = NULL;
  494. public $valid_for_product_tiers = NULL;
  495. public $enable_offline = NULL;
  496. public $offline_token = NULL;
  497. public $offline_token_url = NULL;
  498.  
  499. public function spbas()
  500. {
  501. $this->errors = false;
  502. $this->remote_port = 80;
  503. $this->remote_timeout = 10;
  504. $this->valid_local_key_types = array( "spbas" );
  505. $this->local_key_type = "spbas";
  506. $this->local_key_storage = "filesystem";
  507. $this->local_key_grace_period = 0;
  508. $this->local_key_last = 0;
  509. $this->read_query = false;
  510. $this->update_query = false;
  511. $this->local_key_path = "./";
  512. $this->local_key_name = "license.txt";
  513. $this->local_key_transport_order = "scf";
  514. $this->validate_download_access = false;
  515. $this->release_date = false;
  516. $this->valid_for_product_tiers = false;
  517. $this->enable_offline = false;
  518. $this->offline_token = false;
  519. $this->offline_token_url = false;
  520. $this->key_data = array( "custom_fields" => array( ), "download_access_expires" => 0, "license_expires" => 0, "local_key_expires" => 0, "status" => "Invalid" );
  521. $this->status_messages = array( "active" => "This license is active.", "suspended" => "Error: This license has been suspended.", "expired" => "Error: This license has expired.", "pending" => "Error: This license is pending review.", "download_access_expired" => "Error: This version of the software was released " . "after your download access expired. Please " . "downgrade or contact support for more information.", "missing_license_key" => "Error: The license key variable is empty.", "unknown_local_key_type" => "Error: An unknown type of local key validation was requested.", "could_not_obtain_local_key" => "Error: I could not obtain a new local license key.", "maximum_grace_period_expired" => "Error: The maximum local license key grace period has expired.", "local_key_tampering" => "Error: The local license key has been tampered with or is invalid.", "local_key_invalid_for_location" => "Error: The local license key is invalid for this location.", "missing_license_file" => "Error: Please create the following file (and directories if they don't exist already):<br />\r\n<br />\r\n", "license_file_not_writable" => "Error: Please make the following path writable:<br />", "invalid_local_key_storage" => "Error: I could not determine the local key storage on clear.", "could_not_save_local_key" => "Error: I could not save the local license key.", "license_key_string_mismatch" => "Error: The local key is invalid for this license.", "offline_license_key" => "Error: Manual license activation will be required." );
  522. $this->localization = array( "active" => "This license is active.", "suspended" => "Error: This license has been suspended.", "expired" => "Error: This license has expired.", "pending" => "Error: This license is pending review.", "download_access_expired" => "Error: This version of the software was released " . "after your download access expired. Please " . "downgrade or contact support for more information." );
  523. }
  524.  
  525. public function validate()
  526. {
  527. if( !$this->license_key )
  528. {
  529. return $this->errors = $this->status_messages["missing_license_key"];
  530. }
  531.  
  532.  
  533. return $this->validate_local_key($local_key);
  534. }
  535.  
  536. public function go_offline()
  537. {
  538. if( isset($this->enable_offline) && $this->enable_offline )
  539. {
  540. return $this->generate_token();
  541. }
  542.  
  543. }
  544.  
  545. public function generate_token()
  546. {
  547. $signature = $this->build_querystring($this->access_details());
  548. $signature .= "&license_key=" . $this->license_key;
  549. $lkp = $this->local_key_path == "./" ? getcwd() . "/" : $this->local_key_path;
  550. $signature .= "&local_key_path=" . $lkp;
  551. $signature .= "&local_key_name=" . $this->local_key_name;
  552. $validator = md5($this->secret_key . $signature);
  553. $token = base64_encode($signature) . $validator;
  554. $this->offline_token = wordwrap($token, 42, "\n", 1);
  555. return $this->errors = $this->status_messages["offline_license_key"];
  556. }
  557.  
  558. public function calc_max_grace($local_key_expires, $grace)
  559. {
  560. return (int) $local_key_expires + (int) $grace * 86400;
  561. }
  562.  
  563. public function process_grace_period($local_key)
  564. {
  565. $local_key_src = $this->decode_key($local_key);
  566. $parts = $this->split_key($local_key_src);
  567. $key_data = unserialize($parts[0]);
  568. $local_key_expires = (int) $key_data["local_key_expires"];
  569. unset($parts);
  570. unset($key_data);
  571. $write_new_key = false;
  572. $parts = explode("\n\n", $local_key);
  573. $local_key = $parts[0];
  574. foreach( $local_key_grace_period = explode(",", $this->local_key_grace_period) as $key => $grace )
  575. {
  576. if( !$key )
  577. {
  578. $local_key .= "\n";
  579. }
  580.  
  581. if( time() < $this->calc_max_grace($local_key_expires, $grace) )
  582. {
  583. continue;
  584. }
  585.  
  586. $local_key .= "\n" . $grace;
  587. $write_new_key = true;
  588. }
  589. if( $this->calc_max_grace($local_key_expires, array_pop($local_key_grace_period)) < time() )
  590. {
  591. return array( "write" => false, "local_key" => "", "errors" => $this->status_messages["maximum_grace_period_expired"] );
  592. }
  593.  
  594. return array( "write" => $write_new_key, "local_key" => $local_key, "errors" => false );
  595. }
  596.  
  597. public function in_grace_period($local_key, $local_key_expires)
  598. {
  599. $grace = $this->split_key($local_key, "\n\n");
  600. if( !isset($grace[1]) )
  601. {
  602. return -1;
  603. }
  604.  
  605. return (int) ($this->calc_max_grace($local_key_expires, array_pop(explode("\n", $grace[1]))) - time());
  606. }
  607.  
  608. public function decode_key($local_key)
  609. {
  610. return base64_decode(str_replace("\n", "", urldecode($local_key)));
  611. }
  612.  
  613. public function split_key($local_key, $token = "{spbas}")
  614. {
  615. return explode($token, $local_key);
  616. }
  617.  
  618. public function validate_access($key, $valid_accesses)
  619. {
  620. return in_array($key, (array) $valid_accesses);
  621. }
  622.  
  623. public function wildcard_ip($key)
  624. {
  625. $octets = explode(".", $key);
  626. array_pop($octets);
  627. $ip_range[] = implode(".", $octets) . ".*";
  628. array_pop($octets);
  629. $ip_range[] = implode(".", $octets) . ".*";
  630. array_pop($octets);
  631. $ip_range[] = implode(".", $octets) . ".*";
  632. return $ip_range;
  633. }
  634.  
  635. public function wildcard_domain($key)
  636. {
  637. return "*." . str_replace("www.", "", $key);
  638. }
  639.  
  640. public function wildcard_server_hostname($key)
  641. {
  642. $hostname = explode(".", $key);
  643. unset($hostname[0]);
  644. $hostname = !isset($hostname[1]) ? array( $key ) : $hostname;
  645. return "*." . implode(".", $hostname);
  646. }
  647.  
  648. public function extract_access_set($instances, $enforce)
  649. {
  650. foreach( $instances as $key => $instance )
  651. {
  652. if( $key != $enforce )
  653. {
  654. continue;
  655. }
  656.  
  657. return $instance;
  658. }
  659. return array( );
  660. }
  661.  
  662. public function validate_local_key($local_key)
  663. {
  664.  
  665.  
  666.  
  667. }
  668.  
  669. public function db_read_local_key()
  670. {
  671. $result = array( );
  672. if( is_array($this->read_query) )
  673. {
  674. $result = $this->read_query;
  675. }
  676. else
  677. {
  678. $query = @mysql_query($this->read_query);
  679. if( $mysql_error = mysql_error() )
  680. {
  681. return $this->errors = "Error: " . $mysql_error;
  682. }
  683.  
  684. $result = @mysql_fetch_assoc($query);
  685. if( $mysql_error = mysql_error() )
  686. {
  687. return $this->errors = "Error: " . $mysql_error;
  688. }
  689.  
  690. }
  691.  
  692. if( !$result["local_key"] )
  693. {
  694. $result["local_key"] = $this->fetch_new_local_key();
  695. if( $this->errors )
  696. {
  697. return $this->errors;
  698. }
  699.  
  700. $this->db_write_local_key($result["local_key"]);
  701. }
  702.  
  703. return $this->local_key_last = $result["local_key"];
  704. }
  705.  
  706. public function db_write_local_key($local_key)
  707. {
  708. if( is_array($this->update_query) )
  709. {
  710. $run = $this->update_query["function"];
  711. return $run($this->update_query["key"], $local_key);
  712. }
  713.  
  714. @mysql_query(@str_replace("{local_key}", $local_key, $this->update_query));
  715. if( $mysql_error = mysql_error() )
  716. {
  717. return $this->errors = "Error: " . $mysql_error;
  718. }
  719.  
  720. return true;
  721. }
  722.  
  723. public function read_local_key()
  724. {
  725. if( !file_exists($path = $this->local_key_path . $this->local_key_name) )
  726. {
  727. return $this->errors = $this->status_messages["missing_license_file"] . $path;
  728. }
  729.  
  730. if( !is_writable($path) )
  731. {
  732. return $this->errors = $this->status_messages["license_file_not_writable"] . $path;
  733. }
  734.  
  735. if( !($local_key = @file_get_contents($path)) )
  736. {
  737. $local_key = $this->fetch_new_local_key();
  738. if( $this->errors )
  739. {
  740. if( isset($this->enable_offline) && $this->enable_offline )
  741. {
  742. return $this->go_offline();
  743. }
  744.  
  745. return $this->errors;
  746. }
  747.  
  748. $this->write_local_key(urldecode($local_key), $path);
  749. }
  750.  
  751. return $this->local_key_last = $local_key;
  752. }
  753.  
  754. public function clear_cache_local_key()
  755. {
  756. switch( strtolower($this->local_key_storage) )
  757. {
  758. case "database":
  759. $this->db_write_local_key("");
  760. break;
  761. case "filesystem":
  762. $this->write_local_key("", $this->local_key_path . $this->local_key_name);
  763. break;
  764. default:
  765. return $this->errors = $this->status_messages["invalid_local_key_storage"];
  766. }
  767. }
  768.  
  769. public function write_local_key($local_key, $path)
  770. {
  771. $fp = @fopen($path, "w");
  772. if( !$fp )
  773. {
  774. return $this->errors = $this->status_messages["could_not_save_local_key"];
  775. }
  776.  
  777. @fwrite($fp, $local_key);
  778. @fclose($fp);
  779. return true;
  780. }
  781.  
  782. public function fetch_new_local_key()
  783. {
  784. $querystring = "mod=license&task=SPBAS_validate_license&license_key=" . $this->license_key . "&";
  785. $querystring .= $this->build_querystring($this->access_details());
  786. if( $this->errors )
  787. {
  788. return false;
  789. }
  790.  
  791. $priority = $this->local_key_transport_order;
  792. while( strlen($priority) )
  793. {
  794. $use = substr($priority, 0, 1);
  795. if( $use == "s" && ($result = $this->use_fsockopen($this->api_server, $querystring)) )
  796. {
  797. break;
  798. }
  799.  
  800. if( $use == "c" && ($result = $this->use_curl($this->api_server, $querystring)) )
  801. {
  802. break;
  803. }
  804.  
  805. if( $use == "f" && ($result = $this->use_fopen($this->api_server, $querystring)) )
  806. {
  807. break;
  808. }
  809.  
  810. $priority = substr($priority, 1);
  811. }
  812. if( !$result )
  813. {
  814. $this->errors = $this->status_messages["could_not_obtain_local_key"];
  815. return false;
  816. }
  817.  
  818. if( substr($result, 0, 7) == "Invalid" )
  819. {
  820. $this->errors = str_replace("Invalid", "Error", $result);
  821. return false;
  822. }
  823.  
  824. if( substr($result, 0, 5) == "Error" )
  825. {
  826. $this->errors = $result;
  827. return false;
  828. }
  829.  
  830. return $result;
  831. }
  832.  
  833. public function build_querystring($array)
  834. {
  835. $buffer = "";
  836. foreach( (array) $array as $key => $value )
  837. {
  838. if( $buffer )
  839. {
  840. $buffer .= "&";
  841. }
  842.  
  843. $buffer .= $key . "=" . $value;
  844. }
  845. return $buffer;
  846. }
  847.  
  848. public function access_details()
  849. {
  850. $access_details = array( );
  851. $access_details["domain"] = "";
  852. $access_details["ip"] = "";
  853. $access_details["directory"] = "";
  854. $access_details["server_hostname"] = "";
  855. $access_details["server_ip"] = "";
  856. $access_details["valid_for_product_tiers"] = "";
  857. if( function_exists("phpinfo") )
  858. {
  859. ob_start();
  860. phpinfo(INFO_GENERAL);
  861. phpinfo(INFO_ENVIRONMENT);
  862. $phpinfo = ob_get_contents();
  863. ob_end_clean();
  864. $list = strip_tags($phpinfo);
  865. $access_details["domain"] = $this->scrape_phpinfo($list, "HTTP_HOST");
  866. $access_details["ip"] = $this->scrape_phpinfo($list, "SERVER_ADDR");
  867. $access_details["directory"] = $this->scrape_phpinfo($list, "SCRIPT_FILENAME");
  868. $access_details["server_hostname"] = $this->scrape_phpinfo($list, "System");
  869. $access_details["server_ip"] = @gethostbyname($access_details["server_hostname"]);
  870. }
  871.  
  872. $access_details["domain"] = $access_details["domain"] ? $access_details["domain"] : $_SERVER["HTTP_HOST"];
  873. $access_details["ip"] = $access_details["ip"] ? $access_details["ip"] : $this->server_addr();
  874. $access_details["directory"] = $access_details["directory"] ? $access_details["directory"] : $this->path_translated();
  875. $access_details["server_hostname"] = $access_details["server_hostname"] ? $access_details["server_hostname"] : @gethostbyaddr($access_details["ip"]);
  876. $access_details["server_hostname"] = $access_details["server_hostname"] ? $access_details["server_hostname"] : "Unknown";
  877. $access_details["server_ip"] = $access_details["server_ip"] ? $access_details["server_ip"] : @gethostbyaddr($access_details["ip"]);
  878. $access_details["server_ip"] = $access_details["server_ip"] ? $access_details["server_ip"] : "Unknown";
  879. foreach( $access_details as $key => $value )
  880. {
  881. if( $key == "valid_for_product_tiers" )
  882. {
  883. continue;
  884. }
  885.  
  886. $access_details[$key] = $access_details[$key] ? $access_details[$key] : "Unknown";
  887. }
  888. if( $this->valid_for_product_tiers )
  889. {
  890. $access_details["valid_for_product_tiers"] = $this->valid_for_product_tiers;
  891. }
  892.  
  893. return $access_details;
  894. }
  895.  
  896. public function path_translated()
  897. {
  898. $option = array( "PATH_TRANSLATED", "ORIG_PATH_TRANSLATED", "SCRIPT_FILENAME", "DOCUMENT_ROOT", "APPL_PHYSICAL_PATH" );
  899. foreach( $option as $key )
  900. {
  901. if( !isset($_SERVER[$key]) || strlen(trim($_SERVER[$key])) <= 0 )
  902. {
  903. continue;
  904. }
  905.  
  906. if( $this->is_windows() && strpos($_SERVER[$key], "\\") )
  907. {
  908. return @substr($_SERVER[$key], 0, @strrpos($_SERVER[$key], "\\"));
  909. }
  910.  
  911. return @substr($_SERVER[$key], 0, @strrpos($_SERVER[$key], "/"));
  912. }
  913. return false;
  914. }
  915.  
  916. public function server_addr()
  917. {
  918. $options = array( "SERVER_ADDR", "LOCAL_ADDR" );
  919. foreach( $options as $key )
  920. {
  921. if( isset($_SERVER[$key]) )
  922. {
  923. return $_SERVER[$key];
  924. }
  925.  
  926. }
  927. return false;
  928. }
  929.  
  930. public function scrape_phpinfo($all, $target)
  931. {
  932. $all = explode($target, $all);
  933. if( count($all) < 2 )
  934. {
  935. return false;
  936. }
  937.  
  938. $all = explode("\n", $all[1]);
  939. $all = trim($all[0]);
  940. if( $target == "System" )
  941. {
  942. $all = explode(" ", $all);
  943. $all = trim($all[strtolower($all[0]) == "windows" && strtolower($all[1]) == "nt" ? 2 : 1]);
  944. }
  945.  
  946. if( $target == "SCRIPT_FILENAME" )
  947. {
  948. $slash = $this->is_windows() ? "\\" : "/";
  949. $all = explode($slash, $all);
  950. array_pop($all);
  951. $all = implode($slash, $all);
  952. }
  953.  
  954. if( substr($all, 1, 1) == "]" )
  955. {
  956. return false;
  957. }
  958.  
  959. return $all;
  960. }
  961.  
  962. public function use_fsockopen($url, $querystring)
  963. {
  964. if( !function_exists("fsockopen") )
  965. {
  966. return false;
  967. }
  968.  
  969. $url = parse_url($url);
  970. $fp = @fsockopen($url["host"], $this->remote_port, $errno, $errstr, $this->remote_timeout);
  971. if( !$fp )
  972. {
  973. return false;
  974. }
  975.  
  976. $header = "POST " . $url["path"] . " HTTP/1.0\r\n";
  977. $header .= "Host: " . $url["host"] . "\r\n";
  978. $header .= "Content-type: application/x-www-form-urlencoded\r\n";
  979. $header .= "User-Agent: SPBAS (http://www.spbas.com)\r\n";
  980. $header .= "Content-length: " . @strlen($querystring) . "\r\n";
  981. $header .= "Connection: close\r\n\r\n";
  982. $header .= $querystring;
  983. $result = false;
  984. fputs($fp, $header);
  985. while( !feof($fp) )
  986. {
  987. $result .= fgets($fp, 1024);
  988. }
  989. fclose($fp);
  990. if( strpos($result, "200") === false )
  991. {
  992. return false;
  993. }
  994.  
  995. $result = explode("\r\n\r\n", $result, 2);
  996. if( !$result[1] )
  997. {
  998. return false;
  999. }
  1000.  
  1001. return $result[1];
  1002. }
  1003.  
  1004. public function use_curl($url, $querystring)
  1005. {
  1006. if( !function_exists("curl_init") )
  1007. {
  1008. return false;
  1009. }
  1010.  
  1011. $curl = curl_init();
  1012. $header[0] = "Accept: text/xml,application/xml,application/xhtml+xml,";
  1013. $header[0] .= "text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5";
  1014. $header[] = "Cache-Control: max-age=0";
  1015. $header[] = "Connection: keep-alive";
  1016. $header[] = "Keep-Alive: 300";
  1017. $header[] = "Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7";
  1018. $header[] = "Accept-Language: en-us,en;q=0.5";
  1019. $header[] = "Pragma: ";
  1020. curl_setopt($curl, CURLOPT_URL, $url);
  1021. curl_setopt($curl, CURLOPT_USERAGENT, "SPBAS (http://www.spbas.com)");
  1022. curl_setopt($curl, CURLOPT_HTTPHEADER, $header);
  1023. curl_setopt($curl, CURLOPT_ENCODING, "gzip,deflate");
  1024. curl_setopt($curl, CURLOPT_AUTOREFERER, true);
  1025. curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
  1026. curl_setopt($curl, CURLOPT_POSTFIELDS, $querystring);
  1027. curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
  1028. curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0);
  1029. curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, $this->remote_timeout);
  1030. curl_setopt($curl, CURLOPT_TIMEOUT, $this->remote_timeout);
  1031. $result = curl_exec($curl);
  1032. $info = curl_getinfo($curl);
  1033. curl_close($curl);
  1034. if( (int) $info["http_code"] != 200 )
  1035. {
  1036. return false;
  1037. }
  1038.  
  1039. return $result;
  1040. }
  1041.  
  1042. public function use_fopen($url, $querystring)
  1043. {
  1044. if( !function_exists("file_get_contents") )
  1045. {
  1046. return false;
  1047. }
  1048.  
  1049. return @file_get_contents($url . "?" . $querystring);
  1050. }
  1051.  
  1052. public function is_windows()
  1053. {
  1054. return strtoupper(substr(PHP_OS, 0, 3)) === "WIN";
  1055. }
  1056.  
  1057. public function pr($stack, $stop_execution = true)
  1058. {
  1059. $formatted = "<pre>" . var_export((array) $stack, 1) . "</pre>";
  1060. if( $stop_execution )
  1061. {
  1062. exit( $formatted );
  1063. }
  1064.  
  1065. return $formatted;
  1066. }
  1067.  
  1068. }
  1069.  
  1070.  
  1071. abstract class whmcs
  1072. {
  1073. private static function internal_check_license($licensekey, $localkey = "")
  1074. {
  1075. $results=array();
  1076. $results["status"] = "Active";
  1077.  
  1078.  
  1079. return $results;
  1080. }
  1081.  
  1082. public static function check_license($licensekey)
  1083. {
  1084. $archivolocal = "/usr/share/ilabs_antimalware/license.txt";
  1085. $localkey = file_get_contents($archivolocal);
  1086. $results = self::internal_check_license($licensekey, $localkey);
  1087. switch( $results["status"] )
  1088. {
  1089. case "Active":
  1090. $localkeydata = $results["localkey"];
  1091. file_put_contents($archivolocal, $localkeydata);
  1092. return "";
  1093. case "Invalid":
  1094. return "License invalid";
  1095. case "Expired":
  1096. return "License expired";
  1097. case "Suspended":
  1098. return "License suspended";
  1099. }
  1100. return "Unknown status: " . $results["status"];
  1101. }
  1102.  
  1103. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement