Advertisement
Guest User

Untitled

a guest
Feb 19th, 2013
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 18.78 KB | None | 0 0
  1. <?php
  2. /**
  3. *
  4. * @ This file is created by deZender.Net
  5. * @ deZender (PHP5 Decoder for ionCube Encoder)
  6. *
  7. * @ Version : 1.1.5.0
  8. * @ Author : DeZender
  9. * @ Release on : 09.06.2012
  10. * @ Official site : http://DeZender.Net
  11. *
  12. */
  13.  
  14.  
  15. class spbas_wp_obs {
  16. var $errors = null;
  17. var $license_key = null;
  18. var $api_server = null;
  19. var $remote_port = null;
  20. var $remote_timeout = null;
  21. var $local_key_storage = null;
  22. var $read_query = null;
  23. var $update_query = null;
  24. var $local_key_path = null;
  25. var $local_key_name = null;
  26. var $local_key_transport_order = null;
  27. var $local_key_grace_period = null;
  28. var $local_key_last = null;
  29. var $validate_download_access = null;
  30. var $release_date = null;
  31. var $key_data = null;
  32. var $status_messages = null;
  33. var $valid_for_product_tiers = null;
  34.  
  35. function spbas_wp_obs() {
  36. $this->errors = false;
  37. $this->remote_port = 80;
  38. $this->remote_timeout = 10;
  39. $this->valid_local_key_types = array( 'spbas' );
  40. $this->local_key_type = 'spbas';
  41. $this->local_key_storage = 'filesystem';
  42. $this->local_key_grace_period = 0;
  43. $this->local_key_last = 0;
  44. $this->read_query = false;
  45. $this->update_query = false;
  46. $this->local_key_path = '';
  47. $this->local_key_name = 'license.txt';
  48. $this->local_key_transport_order = 'scf';
  49. $this->validate_download_access = false;
  50. $this->release_date = false;
  51. $this->valid_for_product_tiers = false;
  52. $this->key_data = array( 'custom_fields' => array( ), 'download_access_expires' => 0, 'license_expires' => 0, 'local_key_expires' => 0, 'status' => 'Invalid' );
  53. $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: Please enter your license key to continue.', '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 />
  54. <br />
  55. ', '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.' );
  56. $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.' );
  57. }
  58.  
  59. function validate() {
  60. if (!$this->license_key) {
  61. return $this->errors = $this->status_messages['missing_license_key'];
  62. }
  63.  
  64.  
  65. if (!in_array( strtolower( $this->local_key_type ), $this->valid_local_key_types )) {
  66. return $this->errors = $this->status_messages['unknown_local_key_type'];
  67. }
  68.  
  69. $this->trigger_grace_period = $this->status_messages['could_not_obtain_local_key'];
  70. switch ($this->local_key_storage) {
  71. case 'database': {
  72. $local_key = $this->db_read_local_key( );
  73. break;
  74. }
  75.  
  76. case 'filesystem': {
  77. $local_key = $this->read_local_key( );
  78. break;
  79. }
  80.  
  81. default: {
  82. $this->errors = $this->status_messages['missing_license_key'];
  83. }
  84. }
  85.  
  86. return ;
  87.  
  88. if (( $this->errors == $this->trigger_grace_period && $this->local_key_grace_period )) {
  89. $grace = $this->process_grace_period( $this->local_key_last );
  90.  
  91. if ($grace['write']) {
  92. if ($this->local_key_storage == 'database') {
  93. $this->db_write_local_key( $grace['local_key'] );
  94. } else {
  95. if ($this->local_key_storage == 'filesystem') {
  96. $this->write_local_key( $grace['local_key'], '' . $this->local_key_path . $this->local_key_name );
  97. }
  98. }
  99. }
  100.  
  101.  
  102. if ($grace['errors']) {
  103. return $this->errors = $grace['errors'];
  104. }
  105.  
  106. $this->errors = false;
  107. return $this;
  108. }
  109.  
  110.  
  111. if ($this->errors) {
  112. return $this->errors;
  113. }
  114.  
  115. return $this->validate_local_key( $local_key );
  116. }
  117.  
  118. function calc_max_grace($local_key_expires, &$grace) {
  119. return (int)$local_key_expires + (int)$grace * 86400;
  120. }
  121.  
  122. function process_grace_period($local_key) {
  123. $local_key_src = $this->decode_key( $local_key );
  124. $parts = $this->split_key( $local_key_src );
  125. $key_data = unserialize( $parts[0] );
  126. $local_key_expires = (int)$key_data['local_key_expires'];
  127. unset( $parts );
  128. unset( $key_data );
  129. $write_new_key = false;
  130. $parts = explode( '
  131.  
  132. ', $local_key );
  133. $local_key = $parts[0];
  134. $local_key_grace_period = explode( ',', $this->local_key_grace_period );
  135. foreach ($local_key_grace_period as $key => $grace) {
  136.  
  137. if (!$key) {
  138. $local_key .= '
  139. ';
  140. }
  141.  
  142.  
  143. if (time( ) < $this->calc_max_grace( $local_key_expires, $grace )) {
  144. continue;
  145. }
  146.  
  147. $local_key .= ( '' . '
  148. ' ) . $grace;
  149. $write_new_key = true;
  150. }
  151.  
  152.  
  153. if ($this->calc_max_grace( $local_key_expires, array_pop( $local_key_grace_period ) ) < time( )) {
  154. return array( 'write' => false, 'local_key' => '', 'errors' => $this->status_messages['maximum_grace_period_expired'] );
  155. }
  156.  
  157. return array( 'write' => $write_new_key, 'local_key' => $local_key, 'errors' => false );
  158. }
  159.  
  160. function in_grace_period($local_key, $local_key_expires) {
  161. $grace = $this->split_key( $local_key, '
  162.  
  163. ' );
  164.  
  165. if (!isset( $grace[1] )) {
  166. return 0 - 1;
  167. }
  168.  
  169. return (int)$this->calc_max_grace( $local_key_expires, array_pop( explode( '
  170. ', $grace[1] ) ) ) - time( );
  171. }
  172.  
  173. function decode_key($local_key) {
  174. return base64_decode( str_replace( '
  175. ', '', urldecode( $local_key ) ) );
  176. }
  177.  
  178. function split_key($local_key, $token = '{spbas}') {
  179. return explode( $token, $local_key );
  180. }
  181.  
  182. function validate_access($key, $valid_accesses) {
  183. return in_array( $key, (array)$valid_accesses );
  184. }
  185.  
  186. function wildcard_ip($key) {
  187. $octets = explode( '.', $key );
  188. array_pop( $octets );
  189. $ip_range[] = implode( '.', $octets ) . '.*';
  190. array_pop( $octets );
  191. $ip_range[] = implode( '.', $octets ) . '.*';
  192. array_pop( $octets );
  193. $ip_range[] = implode( '.', $octets ) . '.*';
  194. return $ip_range;
  195. }
  196.  
  197. function wildcard_domain($key) {
  198. return '*.' . str_replace( 'www.', '', $key );
  199. }
  200.  
  201. function wildcard_server_hostname($key) {
  202. $hostname = explode( '.', $key );
  203. unset( $hostname[0] );
  204. $hostname = (!isset( $hostname[1] ) ? array( $key ) : $hostname);
  205. return '*.' . implode( '.', $hostname );
  206. }
  207.  
  208. function extract_access_set($instances, $enforce) {
  209. foreach ($instances as $key => $instance) {
  210.  
  211. if ($key != $enforce) {
  212. continue;
  213. }
  214.  
  215. return $instance;
  216. }
  217.  
  218. return array( );
  219. }
  220.  
  221. function validate_local_key($local_key) {
  222. $local_key_src = $this->decode_key( $local_key );
  223. $parts = $this->split_key( $local_key_src );
  224.  
  225. if (!isset( $parts[1] )) {
  226. return $this->errors = $this->status_messages['local_key_tampering'];
  227. }
  228.  
  229.  
  230. if (md5( $this->secret_key . $parts[0] ) != $parts[1]) {
  231. return $this->errors = $this->status_messages['local_key_tampering'];
  232. }
  233.  
  234. unset( $this->secret_key );
  235. $key_data = unserialize( $parts[0] );
  236. $instance = $key_data['instance'];
  237. unset( $key_data[instance] );
  238. $enforce = $key_data['enforce'];
  239. unset( $key_data[enforce] );
  240. $this->key_data = $key_data;
  241.  
  242. if ((bool)$key_data['license_key_string'] != (bool)$this->license_key) {
  243. return $this->errors = $this->status_messages['license_key_string_mismatch'];
  244. }
  245.  
  246.  
  247. if ((bool)$key_data['status'] != 'active') {
  248. return $this->errors = $this->status_messages[$key_data['status']];
  249. }
  250.  
  251.  
  252. if (( (bool)$key_data['license_expires'] != 'never' && (int)$key_data['license_expires'] < time( ) )) {
  253. return $this->errors = $this->status_messages['expired'];
  254. }
  255.  
  256.  
  257. if (( (bool)$key_data['local_key_expires'] != 'never' && (int)$key_data['local_key_expires'] < time( ) )) {
  258. if ($this->in_grace_period( $local_key, $key_data['local_key_expires'] ) < 0) {
  259. $this->clear_cache_local_key( true );
  260. return $this->validate( );
  261. }
  262. }
  263.  
  264.  
  265. if (( $this->validate_download_access && (int)$key_data['download_access_expires'] < strtotime( $this->release_date ) )) {
  266. return $this->errors = $this->status_messages['download_access_expired'];
  267. }
  268.  
  269. $conflicts = array( );
  270. $access_details = $this->access_details( );
  271. foreach ((array)$enforce as $key) {
  272. $valid_accesses = $this->extract_access_set( $instance, $key );
  273.  
  274. if (!$this->validate_access( $access_details[$key], $valid_accesses )) {
  275. $conflicts[$key] = true;
  276.  
  277. if (in_array( $key, array( 'ip', 'server_ip' ) )) {
  278. foreach ($this->wildcard_ip( $access_details[$key] ) as $ip) {
  279.  
  280. if ($this->validate_access( $ip, $valid_accesses )) {
  281. unset( $conflicts[$key] );
  282. break;
  283. }
  284. }
  285.  
  286. continue;
  287. }
  288.  
  289.  
  290. if (in_array( $key, array( 'domain' ) )) {
  291. if ($this->validate_access( $this->wildcard_domain( $access_details[$key] ), $valid_accesses )) {
  292. unset( $conflicts[$key] );
  293. continue;
  294. }
  295.  
  296. continue;
  297. }
  298.  
  299.  
  300. if (in_array( $key, array( 'server_hostname' ) )) {
  301. if ($this->validate_access( $this->wildcard_server_hostname( $access_details[$key] ), $valid_accesses )) {
  302. unset( $conflicts[$key] );
  303. continue;
  304. }
  305.  
  306. continue;
  307. }
  308.  
  309. continue;
  310. }
  311. }
  312.  
  313.  
  314. if (!empty( $conflicts )) {
  315. return $this->errors = $this->status_messages['local_key_invalid_for_location'];
  316. }
  317.  
  318. }
  319.  
  320. function db_read_local_key() {
  321. $result = array( );
  322.  
  323. if (is_array( $this->read_query )) {
  324. $result = $this->read_query;
  325. } else {
  326. $query = @mysql_query( $this->read_query );
  327.  
  328. if ($mysql_error = mysql_error( )) {
  329. return $this->errors = '' . 'Error: ' . $mysql_error;
  330. }
  331.  
  332. $result = @mysql_fetch_assoc( $query );
  333.  
  334. if ($mysql_error = mysql_error( )) {
  335. return $this->errors = '' . 'Error: ' . $mysql_error;
  336. }
  337. }
  338.  
  339.  
  340. if (!$result['local_key']) {
  341. $result['local_key'] = $this->fetch_new_local_key( );
  342.  
  343. if ($this->errors) {
  344. return $this->errors;
  345. }
  346.  
  347. $this->db_write_local_key( $result['local_key'] );
  348. }
  349.  
  350. return $this->local_key_last = $result['local_key'];
  351. }
  352.  
  353. function db_write_local_key($local_key) {
  354. if (is_array( $this->update_query )) {
  355. $run = $this->update_query['function'];
  356. return $run( $this->update_query['key'], $local_key );
  357. }
  358.  
  359. @mysql_query( @str_replace( '{local_key}', $local_key, $this->update_query ) );
  360.  
  361. if ($mysql_error = mysql_error( )) {
  362. return $this->errors = '' . 'Error: ' . $mysql_error;
  363. }
  364.  
  365. return true;
  366. }
  367.  
  368. function read_local_key() {
  369. if (!file_exists( $path = '' . $this->local_key_path . $this->local_key_name )) {
  370. return $this->errors = $this->status_messages['missing_license_file'] . $path;
  371. }
  372.  
  373.  
  374. if (!is_writable( $path )) {
  375. return $this->errors = $this->status_messages['license_file_not_writable'] . $path;
  376. }
  377.  
  378.  
  379. if (!$local_key = @file_get_contents( $path )) {
  380. $local_key = $this->fetch_new_local_key( );
  381.  
  382. if ($this->errors) {
  383. return $this->errors;
  384. }
  385.  
  386. $this->write_local_key( urldecode( $local_key ), $path );
  387. }
  388.  
  389. return $this->local_key_last = $local_key;
  390. }
  391.  
  392. function clear_cache_local_key($clear = false) {
  393. switch (strtolower( $this->local_key_storage )) {
  394. case 'database': {
  395. $this->db_write_local_key( '' );
  396. break;
  397. }
  398.  
  399. case 'filesystem': {
  400. $this->write_local_key( '', '' . $this->local_key_path . $this->local_key_name );
  401. break;
  402. }
  403.  
  404. default: {
  405. $this->errors = $this->status_messages['invalid_local_key_storage'];
  406. }
  407. }
  408.  
  409. return ;
  410. }
  411.  
  412. function write_local_key($local_key, $path) {
  413. $fp = @fopen( $path, 'w' );
  414.  
  415. if (!$fp) {
  416. return $this->errors = $this->status_messages['could_not_save_local_key'];
  417. }
  418.  
  419. @fwrite( $fp, $local_key );
  420. @fclose( $fp );
  421. return true;
  422. }
  423.  
  424. function fetch_new_local_key() {
  425. $querystring .= $querystring = '' . 'mod=license&task=SPBAS_validate_license&license_key=' . $this->license_key . '&';
  426.  
  427. if ($this->errors) {
  428. return false;
  429. }
  430.  
  431. $this->local_key_transport_order;
  432. $priority = $this->build_querystring( $this->access_details( ) );
  433.  
  434. while (strlen( $priority )) {
  435. $use = substr( $priority, 0, 1 );
  436.  
  437. if ($use == 's') {
  438.  
  439. if ($result = $this->use_fsockopen( $this->api_server, $querystring )) {
  440. break;
  441. }
  442. }
  443.  
  444.  
  445. if ($use == 'c') {
  446.  
  447. if ($result = $this->use_curl( $this->api_server, $querystring )) {
  448. break;
  449. }
  450. }
  451.  
  452.  
  453. if ($use == 'f') {
  454.  
  455. if ($result = $this->use_fopen( $this->api_server, $querystring )) {
  456. break;
  457. }
  458. }
  459.  
  460. $priority = substr( $priority, 1 );
  461. }
  462.  
  463.  
  464. if (!$result) {
  465. $this->errors = $this->status_messages['could_not_obtain_local_key'];
  466. return false;
  467. }
  468.  
  469.  
  470. if (substr( $result, 0, 7 ) == 'Invalid') {
  471. $this->errors = str_replace( 'Invalid', 'Error', $result );
  472. return false;
  473. }
  474.  
  475.  
  476. if (substr( $result, 0, 5 ) == 'Error') {
  477. $this->errors = $result;
  478. return false;
  479. }
  480.  
  481. return $result;
  482. }
  483.  
  484. function build_querystring($array) {
  485. $buffer = '';
  486. foreach ((array)$array as $key => $value) {
  487.  
  488. if ($buffer) {
  489. $buffer .= '&';
  490. }
  491.  
  492. $buffer .= '' . $key . '=' . $value;
  493. }
  494.  
  495. return $buffer;
  496. }
  497.  
  498. function access_details() {
  499. $access_details = array( );
  500.  
  501. if (function_exists( 'phpinfo' )) {
  502. phpinfo( INFO_GENERAL );
  503. phpinfo( INFO_ENVIRONMENT );
  504. ob_get_contents( );
  505. $phpinfo = ob_start( );
  506. ob_end_clean( );
  507. $list = strip_tags( $phpinfo );
  508. $access_details['domain'] = $this->scrape_phpinfo( $list, 'HTTP_HOST' );
  509. $access_details['ip'] = $this->scrape_phpinfo( $list, 'SERVER_ADDR' );
  510. $access_details['directory'] = $this->scrape_phpinfo( $list, 'SCRIPT_FILENAME' );
  511. $access_details['server_hostname'] = $this->scrape_phpinfo( $list, 'System' );
  512. $access_details['server_ip'] = @gethostbyname( $access_details['server_hostname'] );
  513. }
  514.  
  515. $access_details['domain'] = ($access_details['domain'] ? $access_details['domain'] : $_SERVER['HTTP_HOST']);
  516. $access_details['ip'] = ($access_details['ip'] ? $access_details['ip'] : $this->server_addr( ));
  517. $access_details['directory'] = ($access_details['directory'] ? $access_details['directory'] : $this->path_translated( ));
  518. $access_details['server_hostname'] = ($access_details['server_hostname'] ? $access_details['server_hostname'] : @gethostbyaddr( $access_details['ip'] ));
  519. $access_details['server_hostname'] = ($access_details['server_hostname'] ? $access_details['server_hostname'] : 'Unknown');
  520. $access_details['server_ip'] = ($access_details['server_ip'] ? $access_details['server_ip'] : @gethostbyaddr( $access_details['ip'] ));
  521. $access_details['server_ip'] = ($access_details['server_ip'] ? $access_details['server_ip'] : 'Unknown');
  522. foreach ($access_details as $key => $value) {
  523. $access_details[$key] = ($access_details[$key] ? $access_details[$key] : 'Unknown');
  524. }
  525.  
  526.  
  527. if ($this->valid_for_product_tiers) {
  528. $access_details['valid_for_product_tiers'] = $this->valid_for_product_tiers;
  529. }
  530.  
  531. return $access_details;
  532. }
  533.  
  534. function path_translated() {
  535. $option = array( 'PATH_TRANSLATED', '||IG_PATH_TRANSLATED', 'SCRIPT_FILENAME', 'DOCUMENT_ROOT', 'APPL_PHYSICAL_PATH' );
  536. foreach ($option as $key) {
  537.  
  538. if (( !isset( $_SERVER[$key] ) || strlen( trim( $_SERVER[$key] ) ) <= 0 )) {
  539. continue;
  540. }
  541.  
  542.  
  543. if (( $this->is_windows( ) && strpos( $_SERVER[$key], '\\' ) )) {
  544. return substr( $_SERVER[$key], 0, @strrpos( $_SERVER[$key], '\\' ) );
  545. }
  546.  
  547. return substr( $_SERVER[$key], 0, @strrpos( $_SERVER[$key], '/' ) );
  548. }
  549.  
  550. return false;
  551. }
  552.  
  553. function server_addr() {
  554. $options = array( 'SERVER_ADDR', 'LOCAL_ADDR' );
  555. foreach ($options as $key) {
  556.  
  557. if (isset( $_SERVER[$key] )) {
  558. return $_SERVER[$key];
  559. }
  560. }
  561.  
  562. return false;
  563. }
  564.  
  565. function scrape_phpinfo($all, $target) {
  566. $all = explode( $target, $all );
  567.  
  568. if (count( $all ) < 2) {
  569. return false;
  570. }
  571.  
  572. $all = explode( '
  573. ', $all[1] );
  574.  
  575. $all = trim( $all[0] );
  576.  
  577. if ($target == 'System') {
  578. $all = explode( ' ', $all );
  579. $all = trim( $all[(( strtolower( $all[0] ) == 'windows' && strtolower( $all[1] ) == 'nt' ) ? 2 : 1)] );
  580. }
  581.  
  582.  
  583. if ($target == 'SCRIPT_FILENAME') {
  584. $slash = ($this->is_windows( ) ? '\\' : '/');
  585. $all = explode( $slash, $all );
  586. array_pop( $all );
  587. $all = implode( $slash, $all );
  588. }
  589.  
  590.  
  591. if (substr( $all, 1, 1 ) == ']') {
  592. return false;
  593. }
  594.  
  595. return $all;
  596. }
  597.  
  598. function use_fsockopen($url, $querystring) {
  599. if (!function_exists( 'fsockopen' )) {
  600. return false;
  601. }
  602.  
  603. $url = parse_url( $url );
  604. $fp = @fsockopen( $url['host'], $this->remote_port, $errno, $errstr, $this->remote_timeout );
  605.  
  606. if (!$fp) {
  607. return false;
  608. }
  609.  
  610. $header = '' . 'POST ' . $url['path'] . ' HTTP/1.0
  611. ';
  612. $header .= ( ( '' . 'Host: ' . $url['host'] . '
  613. ' ) . '
  614. ' );
  615. $header .= 'Content-type: application/x-www-form-urlencoded
  616. ';
  617. $header .= 'User-Agent: SPBAS (http://www.spbas.com)
  618. ';
  619. $header .= 'Content-length: ' . @strlen( $querystring ) . '
  620. ';
  621. $header .= 'Connection: close
  622.  
  623. ';
  624. $header .= $querystring;
  625. $result = false;
  626. fputs( $fp, $header );
  627.  
  628. while (!feof( $fp )) {
  629. $result .= fgets( $fp, 1024 );
  630. }
  631.  
  632. fclose( $fp );
  633.  
  634. if (strpos( $result, '200' ) === false) {
  635. return false;
  636. }
  637.  
  638. $result = explode( '
  639.  
  640. ', $result, 2 );
  641.  
  642. if (!$result[1]) {
  643. return false;
  644. }
  645.  
  646. return $result[1];
  647. }
  648. .................................................................
  649. ......................................
  650. ...............
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement