Sign in to follow this  
Cornel Iulian

[Tutorial] Instalare IPS 4.2 Fara cheia de licenta

1 post in this topic

Din init.php schimbati:

Spoiler

/**
	 * Get license key data
	 *
	 * @param	bool	$forceRefresh	If TRUE, will get data from server
	 * @return	array|NULL
	 */
	public static function licenseKey( $forceRefresh = FALSE )
	{
		/* Get the cached value */
		$cached = NULL;
		$setFetched = FALSE;
		if ( isset( \IPS\Data\Store::i()->license_data ) )
		{
			$cached = \IPS\Data\Store::i()->license_data;

			/* If it's younger than 21 days, just use that */
			if ( $cached['fetched'] > ( time() - 1814400 ) and !$forceRefresh )
			{
				/* If the license is not expired, return the data */
				if( !$cached['data']['expires'] OR strtotime( $cached['data']['expires'] ) > time() )
				{
					return $cached['data'];
				}
				/* Otherwise if the license is expired but we've automatically refetched, return the data */
				else if( $cached['data']['expires'] AND strtotime( $cached['data']['expires'] ) < time() AND isset( $cached['refetched'] ) )
				{
					return $cached['data'];
				}
				/* Otherwise remember to set the 'refetched' flag */
				else
				{
					$setFetched = TRUE;
				}
			}
		}

		/* Call the main server */
		try
		{
			/* Prevent a race condition and set the next check cycle to be 10 mins from the 21 day cut off in case this request fails */
			\IPS\Data\Store::i()->license_data	= array( 'fetched' => time() - 1813800, 'data' => NULL );
			
			$response = \IPS\Http\Url::ips( 'license/' . trim( \IPS\Settings::i()->ipb_reg_number ) )->request()->get();
			if ( $response->httpResponseCode == 404 )
			{
				\IPS\Data\Store::i()->license_data	= array( 'fetched' => time() - 1728000, 'data' => NULL );
				return $cached;
			}
			$response = $response->decodeJson();
		}
		catch ( \Exception $e )
		{
			/* If we can't access the license server right now, store something in cache to prevent a request on every page load. We
				set fetched to 20 days ago so that this cache is only good for 1 day instead of 21 days however. */
			if( $cached === NULL )
			{
				\IPS\Data\Store::i()->license_data	= array( 'fetched' => time() - 1728000, 'data' => NULL );
			}
			else
			{
				/* We wipe the data to prevent a race condition, but the license server failed so restore the data and set to try again in 1 day */
				\IPS\Data\Store::i()->license_data	= array( 'fetched' => time() - 1728000, 'data' => ( isset( $cached['data'] ) ? $cached['data'] : NULL ) );
			}

			/* If the server is offline right now, use the cached value from above */
			return $cached;
		}
		
		/* Update the license info in the store */
		$licenseData = array( 'fetched' => time(), 'data' => $response );

		if( $setFetched )
		{
			$licenseData['refetched']	= 1;
		}

		\IPS\Data\Store::i()->license_data	= $licenseData;

		/* Return */
		return $response;
	}
	
	/**
	 * Check license key
	 *
	 * @param	string	The license key
	 * @param	string	The site URL
	 * @return	void
	 * @throws	\DomainException
	 */
	public static function checkLicenseKey( $val, $url )
	{
		$test = FALSE;
		if ( mb_substr( $val, -12 ) === '-TESTINSTALL' )
		{
			$test = TRUE;
			$val = mb_substr( $val, 0, -12 );
		}
		$urlKey = $test ? 'test_url' : 'url';
						
		try
		{
			$response = \IPS\Http\Url::ips( 'license/' . $val )->setQueryString( $urlKey, $url )->request()->get();			
			switch ( $response->httpResponseCode )
			{
				case 200:
					$response = json_decode( $response, TRUE );
					if ( $response['legacy'] )
					{
						throw new \DomainException( 'license_key_legacy' );
					}
					
					if ( !$response[ $urlKey ] )
					{
						\IPS\Http\Url::ips( 'license/' . $val )->request()->post( array(
							$urlKey	=> $url
						) );
					}
					elseif ( $response[ $urlKey ] != $url )
					{
						if ( rtrim( preg_replace( '/^https?:\/\//', '', $response[ $urlKey ] ), '/' ) == rtrim( preg_replace( '/^https?:\/\//', '', $url ), '/' ) ) // Allow changing if the difference is http/https or just a trailing slash
						{
							\IPS\Http\Url::ips( 'license/' . $val )->request()->post( array(
								$urlKey	=> $url
							) );
						}
						else
						{							
							throw new \DomainException( $test ? 'license_key_test_active' : 'license_key_active' );
						}
					}
					break;
					
				case 404:
					throw new \DomainException( 'license_key_not_found' );
				
				default:
					throw new \DomainException( 'license_generic_error' );
			}
		}
		catch ( \IPS\Http\Request\Exception $e )
		{
			throw new \DomainException( sprintf( \IPS\Member::loggedIn()->language()->get( 'license_server_error' ), $e->getMessage() ) );
		}
	}

 

(liniile 638 - 782) cu:

Spoiler

/**
	 * Get license key data
	 *
	 * @param	bool	$forceRefresh	If TRUE, will get data from server
	 * @return	array|NULL
	 */
	public static function licenseKey( $forceRefresh = FALSE )
	{
		/* We haven't license key saved in settings? Saving... */
		if ( !\IPS\Settings::i()->ipb_reg_number ) {
			\IPS\Db::i()->update( 'core_sys_conf_settings', array( 'conf_value' => 'LICENSE KEY GOES HERE!-123456789' ), array( 'conf_key=?', 'ipb_reg_number' ) );
			\IPS\Settings::i()->ipb_reg_number	= 'LICENSE KEY GOES HERE!-123456789';							
		}

		$response = array(
				'key' => \IPS\Settings::i()->ipb_reg_number, //IPS Key
				'active' => \IPS\Settings::i()->ipb_license_active, //License Active?
				'cloud' => \IPS\Settings::i()->ipb_license_cloud, //We are "cloud" clients?
				'url' => \IPS\Settings::i()->ipb_license_url, //Forum URL
				'test_url' => \IPS\Settings::i()->ipb_license_test_url, //Test URL
			 	'expires' => \IPS\Settings::i()->ipb_license_expires, //When our license will expire?
			 	'products' => array( //Array of components. Can we use...
			 	 	'forums' => \IPS\Settings::i()->ipb_license_product_forums, //...IP.Board // Forums?
			 	 	'calendar' => \IPS\Settings::i()->ipb_license_product_calendar, //...IP.Calendar // Calendar?
			 	 	'blog' => \IPS\Settings::i()->ipb_license_product_blog, //...IP.Blogs // Blogs?
			 	 	'gallery' => \IPS\Settings::i()->ipb_license_product_gallery, //...IP.Gallery // Gallery?
			 	 	'downloads' => \IPS\Settings::i()->ipb_license_product_downloads, //...IP.Downloads // Downloads?
			 	 	'cms' => \IPS\Settings::i()->ipb_license_product_cms, //...IP.Content // Pages?
			 	 	'nexus' => \IPS\Settings::i()->ipb_license_product_nexus, //...IP.Nexus // Commerce?
			 	 	'spam' => FALSE, //...IPS Spam Service? No! Hardcoded to prevent requests to IPS servers.
			 	 	'copyright' => \IPS\Settings::i()->ipb_license_product_copyright, //...remove copyright function?
		 		),
			 	'chat_limit' => \IPS\Settings::i()->ipb_license_chat_limit, //How many users can use IP.Chat?
			 	'support' => \IPS\Settings::i()->ipb_license_support, //Can we use Support?
			);

		$cached = NULL;
		if ( isset( \IPS\Data\Store::i()->license_data ) ) //License data exists in cache?
		{
			$cached = \IPS\Data\Store::i()->license_data;
			/* Keep license data updated in cache store */
			if ( $cached['fetched'] < ( time() - 1814400 ) )
			{
				/* Data older, than 21 days. Updating... */
				unset( \IPS\Data\Store::i()->license_data );
				\IPS\Data\Store::i()->license_data = array( //Add information to cache...
					'fetched' => time(),
					'data' => $response,
				);
				return $response;
			} else {
				return $cached['data'];
			} 
		}
		else
		{
			/* Cached license data is missing? Creating... */
			\IPS\Data\Store::i()->license_data = array( //Add information to cache...
				'fetched' => time(),
				'data' => $response,
			);
			return $response;
		}
	}
	
	/**
	 * Check license key
	 *
	 * @param	string	The license key
	 * @param	string	The site URL
	 * @return	void
	 * @throws	\DomainException
	 */
	public static function checkLicenseKey( $val, $url )
	{
		//Do Nothing
	}

 

 

(sursa codului: webflake.sx)

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this