mirror of
				https://github.com/hauke68/Magallanes.git
				synced 2025-11-04 09:00:18 +01:00 
			
		
		
		
	Added method to allow checking the source code once IonCube has run for
any un-encoded/encrypted files. This checks against an array of file extens (used mainly to exclude images and javascript etc.) It also checks against an array of paths/filenames. These 2 should maybe be combined into a single array? If any files are found to not be encoded and havnt been excluded, then user is prompted to confirm they wish to proced. This is designed as a last confirmation that you have encoded all the files that you need, and are not about to push unsecured files to a server.
This commit is contained in:
		
							parent
							
								
									5fe1fdc168
								
							
						
					
					
						commit
						96981b72c7
					
				@ -144,12 +144,18 @@ class EncryptTask extends AbstractTask {
 | 
				
			|||||||
	 * 
 | 
						 * 
 | 
				
			||||||
	 * @var array
 | 
						 * @var array
 | 
				
			||||||
	 */
 | 
						 */
 | 
				
			||||||
	private $ignoreExtens	= array(
 | 
						private $checkIgnoreExtens	= array();
 | 
				
			||||||
		'jpg',
 | 
						
 | 
				
			||||||
			'jpeg',
 | 
						/**
 | 
				
			||||||
			'png',
 | 
						 * List of paths to exclude from
 | 
				
			||||||
			'js',
 | 
						 * encrypted/encoded test
 | 
				
			||||||
	);
 | 
						 * Paths must begin with '/'
 | 
				
			||||||
 | 
						 * and are all relative to the 
 | 
				
			||||||
 | 
						 * project root
 | 
				
			||||||
 | 
						 * 
 | 
				
			||||||
 | 
						 * @var array
 | 
				
			||||||
 | 
						 */
 | 
				
			||||||
 | 
						private $checkIgnorePaths	= array();
 | 
				
			||||||
	
 | 
						
 | 
				
			||||||
	/**
 | 
						/**
 | 
				
			||||||
	 * (non-PHPdoc)
 | 
						 * (non-PHPdoc)
 | 
				
			||||||
@ -166,10 +172,22 @@ class EncryptTask extends AbstractTask {
 | 
				
			|||||||
	 * @see \Mage\Task\AbstractTask::init()
 | 
						 * @see \Mage\Task\AbstractTask::init()
 | 
				
			||||||
	 */
 | 
						 */
 | 
				
			||||||
	public function init() {
 | 
						public function init() {
 | 
				
			||||||
 | 
							// Set the default extensions to ignore
 | 
				
			||||||
 | 
							$this->checkIgnoreExtens = array (
 | 
				
			||||||
 | 
									'jpg',
 | 
				
			||||||
 | 
									'jpeg',
 | 
				
			||||||
 | 
									'png',
 | 
				
			||||||
 | 
									'js',
 | 
				
			||||||
 | 
									'gif',
 | 
				
			||||||
 | 
									'css',
 | 
				
			||||||
 | 
									'ttf',
 | 
				
			||||||
 | 
									'svg',
 | 
				
			||||||
 | 
									'map',
 | 
				
			||||||
 | 
									'ico',
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
							);
 | 
				
			||||||
		// Get any options specfic to this task
 | 
							// Get any options specfic to this task
 | 
				
			||||||
		$this->mageConfig = $this->getConfig()->environmentConfig( 'ioncube' );
 | 
							$this->mageConfig = $this->getConfig()->environmentConfig( 'ioncube' );
 | 
				
			||||||
		var_dump($this->mageConfig);
 | 
					 | 
				
			||||||
		exit;
 | 
					 | 
				
			||||||
		/*
 | 
							/*
 | 
				
			||||||
		 * Get all our IonCube config options
 | 
							 * Get all our IonCube config options
 | 
				
			||||||
		 */
 | 
							 */
 | 
				
			||||||
@ -221,9 +239,21 @@ class EncryptTask extends AbstractTask {
 | 
				
			|||||||
		 * encrypt/encode file check
 | 
							 * encrypt/encode file check
 | 
				
			||||||
		 * 
 | 
							 * 
 | 
				
			||||||
		 */
 | 
							 */
 | 
				
			||||||
		if (isset ( $this->mageConfig ['ignoreextens'])) {
 | 
							if (isset ( $this->mageConfig ['checkignoreextens'])) {
 | 
				
			||||||
			$this->ignoreExtens=array_merge($this->ignoreExtens, $this->mageConfig['ignoreextens']);
 | 
								$this->checkIgnoreExtens=array_merge($this->ignoreExtens, $this->mageConfig['ignoreextens']);
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							/*
 | 
				
			||||||
 | 
							 * Check if we have been passed any extra
 | 
				
			||||||
 | 
							* file paths/files to exclude from
 | 
				
			||||||
 | 
							* encrypt/encode file check
 | 
				
			||||||
 | 
							*
 | 
				
			||||||
 | 
							*/
 | 
				
			||||||
 | 
							if (isset ( $this->mageConfig ['checkignorepaths'])) {
 | 
				
			||||||
 | 
								$this->checkIgnorePaths=array_merge($this->checkIgnorePaths, $this->mageConfig['checkignorepaths']);
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							
 | 
				
			||||||
		/*
 | 
							/*
 | 
				
			||||||
		 * now merge all the config options together
 | 
							 * now merge all the config options together
 | 
				
			||||||
		 */
 | 
							 */
 | 
				
			||||||
@ -289,13 +319,16 @@ class EncryptTask extends AbstractTask {
 | 
				
			|||||||
		$this->switchSrcToTmp ();
 | 
							$this->switchSrcToTmp ();
 | 
				
			||||||
		$this->writeProjectFile ();
 | 
							$this->writeProjectFile ();
 | 
				
			||||||
		$result = $this->runIonCube ();
 | 
							$result = $this->runIonCube ();
 | 
				
			||||||
		exit;
 | 
							Console::output("Encoding result :".($result ? '<green>OK</green>' : '<red>Bad!</red>')."\n", 0, 2);
 | 
				
			||||||
		echo "Encoding result :".($result ? 'True' : 'False')."\n";
 | 
							if (!$result) {
 | 
				
			||||||
		if (($this->checkEncoding) && ($this->checkEncoding())) {
 | 
								$this->deleteTmpFiles ();
 | 
				
			||||||
			$result=true;
 | 
								throw new ErrorWithMessageException('Ioncube failed to encode your project :'.$result);
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							if (($this->checkEncoding) && (!$this->checkEncoding())) {
 | 
				
			||||||
 | 
								$this->deleteTmpFiles();
 | 
				
			||||||
 | 
								throw new ErrorWithMessageException('Operation canceled by user.');
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		$this->deleteTmpFiles ();
 | 
							$this->deleteTmpFiles ();
 | 
				
			||||||
		exit;
 | 
					 | 
				
			||||||
		return $result;
 | 
							return $result;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	
 | 
						
 | 
				
			||||||
@ -311,46 +344,67 @@ class EncryptTask extends AbstractTask {
 | 
				
			|||||||
	 */
 | 
						 */
 | 
				
			||||||
	private function checkEncoding() {
 | 
						private function checkEncoding() {
 | 
				
			||||||
		$src = $this->source;
 | 
							$src = $this->source;
 | 
				
			||||||
 | 
							// $ask holds flag to indicate we need to prompt the end user
 | 
				
			||||||
		$ask = false;
 | 
							$ask = false;
 | 
				
			||||||
		$rit = new RecursiveDirectoryIterator ( $src );
 | 
							// scan through the directory
 | 
				
			||||||
		foreach ( new RecursiveIteratorIterator ( $rit ) as $filename => $cur ) {
 | 
							$rit = new \RecursiveDirectoryIterator ( $src );
 | 
				
			||||||
 | 
							foreach ( new \RecursiveIteratorIterator ( $rit ) as $filename => $cur ) {
 | 
				
			||||||
 | 
								// get the 'base dir' for the project, eg. relative to the temp folder
 | 
				
			||||||
 | 
								$srcFileName = (str_replace ( $this->source, '', $filename ));
 | 
				
			||||||
 | 
								/*
 | 
				
			||||||
 | 
								 * Scan through the ignor directorys array
 | 
				
			||||||
 | 
								 * and if it matches the current path/filename
 | 
				
			||||||
 | 
								 * then mark the file to be skipped from testing
 | 
				
			||||||
 | 
								 */
 | 
				
			||||||
 | 
								$skip = false;
 | 
				
			||||||
 | 
								foreach ( $this->checkIgnorePaths as $path ) {
 | 
				
			||||||
 | 
									if (fnmatch ( $path, $srcFileName )) {
 | 
				
			||||||
 | 
										$skip = true;
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								// check if we should test this file
 | 
				
			||||||
 | 
								if (! $skip) {
 | 
				
			||||||
 | 
									// get the file exten for this file and compare to our fileexten exclude array
 | 
				
			||||||
				$exten = pathinfo ( $filename, PATHINFO_EXTENSION );
 | 
									$exten = pathinfo ( $filename, PATHINFO_EXTENSION );
 | 
				
			||||||
			if (!array_key_exists($strtolower($exten), $this->ignoreExtens)) {
 | 
									if (! in_array ( strtolower ( $exten ), $this->checkIgnoreExtens )) {
 | 
				
			||||||
					// ok, this extension needs to be checked
 | 
										// ok, this extension needs to be checked
 | 
				
			||||||
				if ($this->checkFile($filename)) {
 | 
										if ($this->checkFileCoding ( $filename )) {
 | 
				
			||||||
						// file was encrypted/encoded
 | 
											// file was encrypted/encoded
 | 
				
			||||||
					} else {
 | 
										} else {
 | 
				
			||||||
						// file was not encrypted/encoded
 | 
											// file was not encrypted/encoded
 | 
				
			||||||
					echo "File :".$filename." -> Was not encrypted\n";
 | 
											Console::output("<blue>File :" . $srcFileName . "</blue> -> <red>Was not encrypted</red>", 0, 1);
 | 
				
			||||||
						$ask = true;
 | 
											$ask = true;
 | 
				
			||||||
					}
 | 
										}
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
		if ($ask) {
 | 
							if ($ask) {
 | 
				
			||||||
			// ok lets ask the user if they want to procede
 | 
								// ok lets ask the user if they want to procede
 | 
				
			||||||
			echo "\n\nDo you wish to procede (y/N):";
 | 
								Console::output("\n\nDo you wish to procede (y/N):", 0, 0);
 | 
				
			||||||
			$key=strtolower($this->inKey(array('y', 'Y', 'N', 'n', '')));
 | 
								if (! $this->promptYn ()) {
 | 
				
			||||||
			if ($key!='y') {
 | 
					 | 
				
			||||||
				return true;
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
				return false;
 | 
									return false;
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							return true;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
	
 | 
						
 | 
				
			||||||
	/**
 | 
						/**
 | 
				
			||||||
	 * This simply wiats for a single
 | 
						 * This simply for user to enter
 | 
				
			||||||
	 * key press, and returns it
 | 
						 * 'y' or 'Y' and press enter, if
 | 
				
			||||||
 | 
						 * a single 'y' is not entered then
 | 
				
			||||||
 | 
						 * false is returned, otherwise
 | 
				
			||||||
 | 
						 * true is returned.
 | 
				
			||||||
	 * 
 | 
						 * 
 | 
				
			||||||
	 * @param array $vals Array of posible key presses
 | 
						 * @return bool True if 'y' pressed
 | 
				
			||||||
	 * 
 | 
					 | 
				
			||||||
	 * @return string
 | 
					 | 
				
			||||||
	 */
 | 
						 */
 | 
				
			||||||
	private function inKey($vals) {
 | 
						private function promptYn() {
 | 
				
			||||||
		$inKey = "";
 | 
							$handle = fopen ("php://stdin","r");
 | 
				
			||||||
		While(!in_array($inKey,$vals)) {
 | 
							$line = strtolower(fgets($handle));
 | 
				
			||||||
			$inKey = trim(`read -s -n1 valu;echo \$valu`);
 | 
							if(trim($line) != 'y'){
 | 
				
			||||||
 | 
								return false;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		return $inKey;
 | 
							return true;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	
 | 
						
 | 
				
			||||||
	/**
 | 
						/**
 | 
				
			||||||
@ -402,11 +456,14 @@ class EncryptTask extends AbstractTask {
 | 
				
			|||||||
		if (isset ( $this->mageConfig ['keeptemp'] )) {
 | 
							if (isset ( $this->mageConfig ['keeptemp'] )) {
 | 
				
			||||||
			return;
 | 
								return;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
							Console::log('Deleting tempory files :', 0);
 | 
				
			||||||
		$ret1 = $this->runCommandLocal ( 'rm -Rf ' . $this->ionSource, $out1 );
 | 
							$ret1 = $this->runCommandLocal ( 'rm -Rf ' . $this->ionSource, $out1 );
 | 
				
			||||||
		$ret2 = $this->runCommandLocal ( 'rm ' . $this->projectFile, $out2 );
 | 
							$ret2 = $this->runCommandLocal ( 'rm ' . $this->projectFile, $out2 );
 | 
				
			||||||
		if ($ret1 && $ret2) {
 | 
							if ($ret1 && $ret2) {
 | 
				
			||||||
 | 
								Console::log('OK',0);
 | 
				
			||||||
			return;
 | 
								return;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
							Console::log('Failed!', 1);
 | 
				
			||||||
		throw new ErrorWithMessageException ( 'Error deleting temp files :' . $out1 . ' : ' . $out2, 40 );
 | 
							throw new ErrorWithMessageException ( 'Error deleting temp files :' . $out1 . ' : ' . $out2, 40 );
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	
 | 
						
 | 
				
			||||||
@ -528,7 +585,7 @@ class EncryptTask extends AbstractTask {
 | 
				
			|||||||
	 * @return bool
 | 
						 * @return bool
 | 
				
			||||||
	 */
 | 
						 */
 | 
				
			||||||
	private function switchSrcToTmp() {
 | 
						private function switchSrcToTmp() {
 | 
				
			||||||
		echo "\nSwitching :" . $this->source . " -> To :" . $this->ionSource."\n";
 | 
							//echo "\nSwitching :" . $this->source . " -> To :" . $this->ionSource."\n";
 | 
				
			||||||
		$ret = $this->runCommandLocal ( 'mv ' . $this->source . ' ' . $this->ionSource, $out );
 | 
							$ret = $this->runCommandLocal ( 'mv ' . $this->source . ' ' . $this->ionSource, $out );
 | 
				
			||||||
		if (! $ret) {
 | 
							if (! $ret) {
 | 
				
			||||||
			throw new ErrorWithMessageException ( 'Cant create tmp dir :' . $out, $ret );
 | 
								throw new ErrorWithMessageException ( 'Cant create tmp dir :' . $out, $ret );
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user