|
|
|
@ -56,7 +56,7 @@ class EncryptTask extends AbstractTask
|
|
|
|
|
* |
|
|
|
|
* @var array |
|
|
|
|
*/ |
|
|
|
|
private $default = array (); |
|
|
|
|
private $default = array(); |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Array of YAML Ioncube |
|
|
|
@ -64,7 +64,7 @@ class EncryptTask extends AbstractTask
|
|
|
|
|
* |
|
|
|
|
* @var array |
|
|
|
|
*/ |
|
|
|
|
private $yaml = array (); |
|
|
|
|
private $yaml = array(); |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Array of file Ioncube |
|
|
|
@ -73,7 +73,7 @@ class EncryptTask extends AbstractTask
|
|
|
|
|
* |
|
|
|
|
* @var array |
|
|
|
|
*/ |
|
|
|
|
private $file = array (); |
|
|
|
|
private $file = array(); |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Source directory as used by |
|
|
|
@ -106,7 +106,7 @@ class EncryptTask extends AbstractTask
|
|
|
|
|
* |
|
|
|
|
* @var array |
|
|
|
|
*/ |
|
|
|
|
private $mageConfig = array (); |
|
|
|
|
private $mageConfig = array(); |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Final version of the IonCube |
|
|
|
@ -115,7 +115,7 @@ class EncryptTask extends AbstractTask
|
|
|
|
|
* |
|
|
|
|
* @var array |
|
|
|
|
*/ |
|
|
|
|
private $ionCubeConfig = array (); |
|
|
|
|
private $ionCubeConfig = array(); |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Default encoder version to use |
|
|
|
@ -171,7 +171,8 @@ class EncryptTask extends AbstractTask
|
|
|
|
|
* |
|
|
|
|
* @see \Mage\Task\AbstractTask::getName() |
|
|
|
|
*/ |
|
|
|
|
public function getName() { |
|
|
|
|
public function getName() |
|
|
|
|
{ |
|
|
|
|
return $this->name; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -180,9 +181,10 @@ class EncryptTask extends AbstractTask
|
|
|
|
|
* |
|
|
|
|
* @see \Mage\Task\AbstractTask::init() |
|
|
|
|
*/ |
|
|
|
|
public function init() { |
|
|
|
|
public function init() |
|
|
|
|
{ |
|
|
|
|
// Set the default extensions to ignore |
|
|
|
|
$this->checkIgnoreExtens = array ( |
|
|
|
|
$this->checkIgnoreExtens = array( |
|
|
|
|
'jpg', |
|
|
|
|
'jpeg', |
|
|
|
|
'png', |
|
|
|
@ -196,7 +198,7 @@ class EncryptTask extends AbstractTask
|
|
|
|
|
|
|
|
|
|
); |
|
|
|
|
// Get any options specfic to this task |
|
|
|
|
$this->mageConfig = $this->getConfig()->environmentConfig( 'ioncube' ); |
|
|
|
|
$this->mageConfig = $this->getConfig()->environmentConfig('ioncube'); |
|
|
|
|
/* |
|
|
|
|
* Get all our IonCube config options |
|
|
|
|
*/ |
|
|
|
@ -204,12 +206,12 @@ class EncryptTask extends AbstractTask
|
|
|
|
|
/* |
|
|
|
|
* get the source code location |
|
|
|
|
*/ |
|
|
|
|
$this->source = $this->getConfig ()->deployment ( 'from' ); |
|
|
|
|
$this->source = $this->getConfig()->deployment('from'); |
|
|
|
|
/* |
|
|
|
|
* remove trailing slash if present |
|
|
|
|
*/ |
|
|
|
|
if (substr ( $this->source, - 1 ) == DIRECTORY_SEPARATOR) { |
|
|
|
|
$this->source = substr ( $this->source, 0, - 1 ); |
|
|
|
|
if (substr($this->source, -1) == DIRECTORY_SEPARATOR) { |
|
|
|
|
$this->source = substr($this->source, 0, -1); |
|
|
|
|
} |
|
|
|
|
/* |
|
|
|
|
* Set the name of the folder that the un-encrypted |
|
|
|
@ -224,7 +226,7 @@ class EncryptTask extends AbstractTask
|
|
|
|
|
* Check if we have been given an encoder script |
|
|
|
|
* If not then we will just use the default |
|
|
|
|
*/ |
|
|
|
|
if (isset ( $this->mageConfig ['encoder'] )) { |
|
|
|
|
if (isset ($this->mageConfig ['encoder'])) { |
|
|
|
|
$this->encoder = $this->mageConfig ['encoder']; |
|
|
|
|
} |
|
|
|
|
/* |
|
|
|
@ -232,15 +234,15 @@ class EncryptTask extends AbstractTask
|
|
|
|
|
* supplied, this defines how the 3 differant |
|
|
|
|
* config files will be merged together. |
|
|
|
|
*/ |
|
|
|
|
if (isset ( $this->mageConfig ['override'] )) { |
|
|
|
|
if (isset ($this->mageConfig ['override'])) { |
|
|
|
|
$this->ionOverRide = $this->mageConfig ['override']; |
|
|
|
|
} |
|
|
|
|
/* |
|
|
|
|
* Check if we have been asked to |
|
|
|
|
* confirm all encodings |
|
|
|
|
*/ |
|
|
|
|
if (isset ( $this->mageConfig ['checkencoding'])) { |
|
|
|
|
$this->checkEncoding=true; |
|
|
|
|
if (isset ($this->mageConfig ['checkencoding'])) { |
|
|
|
|
$this->checkEncoding = true; |
|
|
|
|
} |
|
|
|
|
/* |
|
|
|
|
* Check if we have been passed any extra |
|
|
|
@ -248,8 +250,8 @@ class EncryptTask extends AbstractTask
|
|
|
|
|
* encrypt/encode file check |
|
|
|
|
* |
|
|
|
|
*/ |
|
|
|
|
if (isset ( $this->mageConfig ['checkignoreextens'])) { |
|
|
|
|
$this->checkIgnoreExtens=array_merge($this->ignoreExtens, $this->mageConfig['ignoreextens']); |
|
|
|
|
if (isset ($this->mageConfig ['checkignoreextens'])) { |
|
|
|
|
$this->checkIgnoreExtens = array_merge($this->ignoreExtens, $this->mageConfig['ignoreextens']); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/* |
|
|
|
@ -258,15 +260,15 @@ class EncryptTask extends AbstractTask
|
|
|
|
|
* encrypt/encode file check |
|
|
|
|
* |
|
|
|
|
*/ |
|
|
|
|
if (isset ( $this->mageConfig ['checkignorepaths'])) { |
|
|
|
|
$this->checkIgnorePaths=array_merge($this->checkIgnorePaths, $this->mageConfig['checkignorepaths']); |
|
|
|
|
if (isset ($this->mageConfig ['checkignorepaths'])) { |
|
|
|
|
$this->checkIgnorePaths = array_merge($this->checkIgnorePaths, $this->mageConfig['checkignorepaths']); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* |
|
|
|
|
* now merge all the config options together |
|
|
|
|
*/ |
|
|
|
|
$this->ionCubeConfig = $this->mergeConfigFiles (); |
|
|
|
|
$this->ionCubeConfig = $this->mergeConfigFiles(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
@ -283,29 +285,29 @@ class EncryptTask extends AbstractTask
|
|
|
|
|
/* |
|
|
|
|
* Get a set of default IonCube options |
|
|
|
|
*/ |
|
|
|
|
$this->default = $this->getOptionsDefault (); |
|
|
|
|
$this->default = $this->getOptionsDefault(); |
|
|
|
|
/* |
|
|
|
|
* Check if there is a 'project' section, |
|
|
|
|
* if so then get the options from there |
|
|
|
|
*/ |
|
|
|
|
if (isset ( $this->mageConfig ['project'] )) { |
|
|
|
|
$this->yaml = $this->getOptionsFromYaml ( $this->mageConfig ['project'] ); |
|
|
|
|
if (isset ($this->mageConfig ['project'])) { |
|
|
|
|
$this->yaml = $this->getOptionsFromYaml($this->mageConfig ['project']); |
|
|
|
|
} else { |
|
|
|
|
$this->yaml = array ( |
|
|
|
|
's' => array (), |
|
|
|
|
'p' => array () |
|
|
|
|
$this->yaml = array( |
|
|
|
|
's' => array(), |
|
|
|
|
'p' => array() |
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
/* |
|
|
|
|
* Check if a seperate projectfile has been specified, and if so |
|
|
|
|
* then read the options from there. |
|
|
|
|
*/ |
|
|
|
|
if (isset ( $this->mageConfig ['projectfile'] )) { |
|
|
|
|
$this->file = $this->getOptionsFromFile ( $this->mageConfig ['projectfile'] ); |
|
|
|
|
if (isset ($this->mageConfig ['projectfile'])) { |
|
|
|
|
$this->file = $this->getOptionsFromFile($this->mageConfig ['projectfile']); |
|
|
|
|
} else { |
|
|
|
|
$this->file = array ( |
|
|
|
|
's' => array (), |
|
|
|
|
'p' => array () |
|
|
|
|
$this->file = array( |
|
|
|
|
's' => array(), |
|
|
|
|
'p' => array() |
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
@ -324,20 +326,21 @@ class EncryptTask extends AbstractTask
|
|
|
|
|
* @return bool |
|
|
|
|
* @throws \Mage\Task\ErrorWithMessageException |
|
|
|
|
*/ |
|
|
|
|
public function run() { |
|
|
|
|
$this->switchSrcToTmp (); |
|
|
|
|
$this->writeProjectFile (); |
|
|
|
|
$result = $this->runIonCube (); |
|
|
|
|
Console::output("Encoding result :".($result ? '<green>OK</green>' : '<red>Bad!</red>')."\n", 0, 2); |
|
|
|
|
public function run() |
|
|
|
|
{ |
|
|
|
|
$this->switchSrcToTmp(); |
|
|
|
|
$this->writeProjectFile(); |
|
|
|
|
$result = $this->runIonCube(); |
|
|
|
|
Console::output("Encoding result :" . ($result ? '<green>OK</green>' : '<red>Bad!</red>') . "\n", 0, 2); |
|
|
|
|
if (!$result) { |
|
|
|
|
$this->deleteTmpFiles (); |
|
|
|
|
throw new ErrorWithMessageException('Ioncube failed to encode your project :'.$result); |
|
|
|
|
$this->deleteTmpFiles(); |
|
|
|
|
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(); |
|
|
|
|
return $result; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -351,33 +354,34 @@ class EncryptTask extends AbstractTask
|
|
|
|
|
* |
|
|
|
|
* @return bool |
|
|
|
|
*/ |
|
|
|
|
private function checkEncoding() { |
|
|
|
|
private function checkEncoding() |
|
|
|
|
{ |
|
|
|
|
$src = $this->source; |
|
|
|
|
// $ask holds flag to indicate we need to prompt the end user |
|
|
|
|
$ask = false; |
|
|
|
|
// scan through the directory |
|
|
|
|
$rit = new \RecursiveDirectoryIterator ( $src ); |
|
|
|
|
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 )); |
|
|
|
|
$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 )) { |
|
|
|
|
foreach ($this->checkIgnorePaths as $path) { |
|
|
|
|
if (fnmatch($path, $srcFileName)) { |
|
|
|
|
$skip = true; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
// check if we should test this file |
|
|
|
|
if (! $skip) { |
|
|
|
|
if (!$skip) { |
|
|
|
|
// get the file exten for this file and compare to our fileexten exclude array |
|
|
|
|
$exten = pathinfo ( $filename, PATHINFO_EXTENSION ); |
|
|
|
|
if (! in_array ( strtolower ( $exten ), $this->checkIgnoreExtens )) { |
|
|
|
|
$exten = pathinfo($filename, PATHINFO_EXTENSION); |
|
|
|
|
if (!in_array(strtolower($exten), $this->checkIgnoreExtens)) { |
|
|
|
|
// ok, this extension needs to be checked |
|
|
|
|
if ($this->checkFileCoding ( $filename )) { |
|
|
|
|
if ($this->checkFileCoding($filename)) { |
|
|
|
|
// file was encrypted/encoded |
|
|
|
|
} else { |
|
|
|
|
// file was not encrypted/encoded |
|
|
|
@ -390,7 +394,7 @@ class EncryptTask extends AbstractTask
|
|
|
|
|
if ($ask) { |
|
|
|
|
// ok lets ask the user if they want to procede |
|
|
|
|
Console::output("\n\nDo you wish to procede (y/N):", 0, 0); |
|
|
|
|
if (! $this->promptYn ()) { |
|
|
|
|
if (!$this->promptYn()) { |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
@ -407,10 +411,11 @@ class EncryptTask extends AbstractTask
|
|
|
|
|
* |
|
|
|
|
* @return bool True if 'y' pressed |
|
|
|
|
*/ |
|
|
|
|
private function promptYn() { |
|
|
|
|
$handle = fopen ("php://stdin","r"); |
|
|
|
|
private function promptYn() |
|
|
|
|
{ |
|
|
|
|
$handle = fopen("php://stdin", "r"); |
|
|
|
|
$line = strtolower(fgets($handle)); |
|
|
|
|
if(trim($line) != 'y'){ |
|
|
|
|
if (trim($line) != 'y') { |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
return true; |
|
|
|
@ -428,23 +433,24 @@ class EncryptTask extends AbstractTask
|
|
|
|
|
* |
|
|
|
|
* @return boolean True if file was encoded/encrypted |
|
|
|
|
*/ |
|
|
|
|
private function checkFileCoding($filename) { |
|
|
|
|
private function checkFileCoding($filename) |
|
|
|
|
{ |
|
|
|
|
// check to see if this is an encrypted file |
|
|
|
|
$ioncube = ioncube_read_file($filename, $ioncubeType); |
|
|
|
|
if (is_int ( $ioncube )) { |
|
|
|
|
if (is_int($ioncube)) { |
|
|
|
|
// we got an error from ioncube, so its encrypted |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
// read first line of file |
|
|
|
|
$f = fopen ( $filename, 'r' ); |
|
|
|
|
$line = trim ( fgets ( $f, 32 ) ); |
|
|
|
|
fclose ( $f ); |
|
|
|
|
$f = fopen($filename, 'r'); |
|
|
|
|
$line = trim(fgets($f, 32)); |
|
|
|
|
fclose($f); |
|
|
|
|
// if first line is longer than 30, then this isnt a php file |
|
|
|
|
if (strlen ( $line ) > 30) { |
|
|
|
|
if (strlen($line) > 30) { |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
// if first line starts '<?php //0' then we can be pretty certain its encoded
|
|
|
|
|
if (substr ( $line, 0, 9 ) == '<?php //0') {
|
|
|
|
|
if (substr($line, 0, 9) == '<?php //0') {
|
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
// otherwise its most likley un-encrypted/encoded |
|
|
|
@ -461,17 +467,18 @@ class EncryptTask extends AbstractTask
|
|
|
|
|
* |
|
|
|
|
* @return void |
|
|
|
|
*/ |
|
|
|
|
private function deleteTmpFiles() { |
|
|
|
|
if (isset ( $this->mageConfig ['keeptemp'] )) { |
|
|
|
|
private function deleteTmpFiles() |
|
|
|
|
{ |
|
|
|
|
if (isset ($this->mageConfig ['keeptemp'])) { |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
Console::log('Deleting tempory files :', 1); |
|
|
|
|
$ret1 = Console::executeCommand ( 'rm -Rf ' . $this->ionSource, $out1 ); |
|
|
|
|
$ret2 = Console::executeCommand ( 'rm ' . $this->projectFile, $out2 ); |
|
|
|
|
$ret1 = Console::executeCommand('rm -Rf ' . $this->ionSource, $out1); |
|
|
|
|
$ret2 = Console::executeCommand('rm ' . $this->projectFile, $out2); |
|
|
|
|
if ($ret1 && $ret2) { |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
throw new ErrorWithMessageException ( 'Error deleting temp files :' . $out1 . ' : ' . $out2, 40 ); |
|
|
|
|
throw new ErrorWithMessageException ('Error deleting temp files :' . $out1 . ' : ' . $out2, 40); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
@ -480,9 +487,10 @@ class EncryptTask extends AbstractTask
|
|
|
|
|
* |
|
|
|
|
* @return bool |
|
|
|
|
*/ |
|
|
|
|
private function runIonCube() { |
|
|
|
|
$cli = $this->encoder . ' --project-file ' . $this->projectFile . ' ' . $this->ionSource . DIRECTORY_SEPARATOR.'*'; |
|
|
|
|
$ret = Console::executeCommand ( $cli, $out ); |
|
|
|
|
private function runIonCube() |
|
|
|
|
{ |
|
|
|
|
$cli = $this->encoder . ' --project-file ' . $this->projectFile . ' ' . $this->ionSource . DIRECTORY_SEPARATOR . '*'; |
|
|
|
|
$ret = Console::executeCommand($cli, $out); |
|
|
|
|
return $ret; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -495,37 +503,38 @@ class EncryptTask extends AbstractTask
|
|
|
|
|
* |
|
|
|
|
* @return void |
|
|
|
|
*/ |
|
|
|
|
private function writeProjectFile() { |
|
|
|
|
private function writeProjectFile() |
|
|
|
|
{ |
|
|
|
|
// array used to build config file into |
|
|
|
|
$out = array (); |
|
|
|
|
$out = array(); |
|
|
|
|
// set the project destination |
|
|
|
|
$out [] = '--into ' . $this->source . PHP_EOL; |
|
|
|
|
// output the switches |
|
|
|
|
foreach ( $this->ionCubeConfig ['s'] as $key => $value ) { |
|
|
|
|
foreach ($this->ionCubeConfig ['s'] as $key => $value) { |
|
|
|
|
if ($value) { |
|
|
|
|
// switch was set to true, so output it |
|
|
|
|
$out [] = '--' . $key . PHP_EOL; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
// output the options |
|
|
|
|
foreach ( $this->ionCubeConfig ['p'] as $key => $value ) { |
|
|
|
|
foreach ($this->ionCubeConfig ['p'] as $key => $value) { |
|
|
|
|
// check if we have an array of values |
|
|
|
|
if (is_array ( $value )) { |
|
|
|
|
foreach ( $value as $entry ) { |
|
|
|
|
if (is_array($value)) { |
|
|
|
|
foreach ($value as $entry) { |
|
|
|
|
$out [] = '--' . $key . ' "' . $entry . '"' . PHP_EOL; |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
// ok just a normal single option |
|
|
|
|
if (strlen ( $value ) > 0) { |
|
|
|
|
if (strlen($value) > 0) { |
|
|
|
|
$out [] = '--' . $key . ' "' . $value . '"' . PHP_EOL; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
$ret = file_put_contents ( $this->projectFile, $out ); |
|
|
|
|
if (! $ret) { |
|
|
|
|
$ret = file_put_contents($this->projectFile, $out); |
|
|
|
|
if (!$ret) { |
|
|
|
|
// something went wrong |
|
|
|
|
$this->deleteTmpFiles (); |
|
|
|
|
throw new ErrorWithMessageException ( 'Unable to create project file.', 20 ); |
|
|
|
|
$this->deleteTmpFiles(); |
|
|
|
|
throw new ErrorWithMessageException ('Unable to create project file.', 20); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -535,7 +544,8 @@ class EncryptTask extends AbstractTask
|
|
|
|
|
* |
|
|
|
|
* @return array Final config array |
|
|
|
|
*/ |
|
|
|
|
private function mergeConfigFiles() { |
|
|
|
|
private function mergeConfigFiles() |
|
|
|
|
{ |
|
|
|
|
/* |
|
|
|
|
* Options are the order the arrays are in |
|
|
|
|
* F - Project File |
|
|
|
@ -546,24 +556,24 @@ class EncryptTask extends AbstractTask
|
|
|
|
|
* @todo I'm sure this could be combined into a loop to make it easier and shorter |
|
|
|
|
* |
|
|
|
|
*/ |
|
|
|
|
$s = array (); |
|
|
|
|
$p = array (); |
|
|
|
|
switch (strtolower ( $this->ionOverRide )) { |
|
|
|
|
$s = array(); |
|
|
|
|
$p = array(); |
|
|
|
|
switch (strtolower($this->ionOverRide)) { |
|
|
|
|
case 'fyd' : |
|
|
|
|
// FILE / YAML / DEFAULT |
|
|
|
|
$s = array_merge ( $this->file ['s'], $this->yaml ['s'], $this->default ['s'] ); |
|
|
|
|
$p = array_merge ( $this->file ['p'], $this->yaml ['p'], $this->default ['p'] ); |
|
|
|
|
$s = array_merge($this->file ['s'], $this->yaml ['s'], $this->default ['s']); |
|
|
|
|
$p = array_merge($this->file ['p'], $this->yaml ['p'], $this->default ['p']); |
|
|
|
|
break; |
|
|
|
|
|
|
|
|
|
case 'yfd' : |
|
|
|
|
// YAML / FILE / DEFAULT |
|
|
|
|
$s = array_merge ( $this->yaml ['s'], $this->file ['s'], $this->default ['s'] ); |
|
|
|
|
$p = array_merge ( $this->yaml ['p'], $this->file ['p'], $this->default ['p'] ); |
|
|
|
|
$s = array_merge($this->yaml ['s'], $this->file ['s'], $this->default ['s']); |
|
|
|
|
$p = array_merge($this->yaml ['p'], $this->file ['p'], $this->default ['p']); |
|
|
|
|
break; |
|
|
|
|
case 'dyf' : |
|
|
|
|
// DEFAULT / YAML / FILE |
|
|
|
|
$s = array_merge ( $this->default ['s'], $this->yaml ['s'], $this->file ['s'] ); |
|
|
|
|
$p = array_merge ( $this->default ['p'], $this->yaml ['p'], $this->file ['p'] ); |
|
|
|
|
$s = array_merge($this->default ['s'], $this->yaml ['s'], $this->file ['s']); |
|
|
|
|
$p = array_merge($this->default ['p'], $this->yaml ['p'], $this->file ['p']); |
|
|
|
|
break; |
|
|
|
|
case 'd' : |
|
|
|
|
default : |
|
|
|
@ -572,7 +582,7 @@ class EncryptTask extends AbstractTask
|
|
|
|
|
$p = $this->default ['p']; |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
return array ( |
|
|
|
|
return array( |
|
|
|
|
's' => $s, |
|
|
|
|
'p' => $p |
|
|
|
|
); |
|
|
|
@ -591,14 +601,15 @@ class EncryptTask extends AbstractTask
|
|
|
|
|
* |
|
|
|
|
* @return bool |
|
|
|
|
*/ |
|
|
|
|
private function switchSrcToTmp() { |
|
|
|
|
$ret = Console::executeCommand ( 'mv ' . $this->source . ' ' . $this->ionSource, $out ); |
|
|
|
|
if (! $ret) { |
|
|
|
|
throw new ErrorWithMessageException ( 'Cant create tmp dir :' . $out, $ret ); |
|
|
|
|
private function switchSrcToTmp() |
|
|
|
|
{ |
|
|
|
|
$ret = Console::executeCommand('mv ' . $this->source . ' ' . $this->ionSource, $out); |
|
|
|
|
if (!$ret) { |
|
|
|
|
throw new ErrorWithMessageException ('Cant create tmp dir :' . $out, $ret); |
|
|
|
|
} |
|
|
|
|
$ret = Console::executeCommand ( 'mkdir -p ' . $this->source, $out ); |
|
|
|
|
if (! $ret) { |
|
|
|
|
throw new ErrorWithMessageException ( 'Cant re-create dir :' . $out, $ret ); |
|
|
|
|
$ret = Console::executeCommand('mkdir -p ' . $this->source, $out); |
|
|
|
|
if (!$ret) { |
|
|
|
|
throw new ErrorWithMessageException ('Cant re-create dir :' . $out, $ret); |
|
|
|
|
} |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
@ -611,18 +622,19 @@ class EncryptTask extends AbstractTask
|
|
|
|
|
* |
|
|
|
|
* return array |
|
|
|
|
*/ |
|
|
|
|
private function getOptionsFromYaml($options) { |
|
|
|
|
$s = array (); |
|
|
|
|
$p = array (); |
|
|
|
|
foreach ( $options as $key => $value ) { |
|
|
|
|
if (array_key_exists ( $key, $this->default ['s'] )) { |
|
|
|
|
private function getOptionsFromYaml($options) |
|
|
|
|
{ |
|
|
|
|
$s = array(); |
|
|
|
|
$p = array(); |
|
|
|
|
foreach ($options as $key => $value) { |
|
|
|
|
if (array_key_exists($key, $this->default ['s'])) { |
|
|
|
|
$s [$key] = true; |
|
|
|
|
} |
|
|
|
|
if (array_key_exists ( $key, $this->default ['p'] )) { |
|
|
|
|
if (array_key_exists($key, $this->default ['p'])) { |
|
|
|
|
$p [$key] = $value; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
return array ( |
|
|
|
|
return array( |
|
|
|
|
's' => $s, |
|
|
|
|
'p' => $p |
|
|
|
|
); |
|
|
|
@ -635,48 +647,49 @@ class EncryptTask extends AbstractTask
|
|
|
|
|
* @param $fileName |
|
|
|
|
* @return array |
|
|
|
|
*/ |
|
|
|
|
private function getOptionsFromFile($fileName) { |
|
|
|
|
$s = array (); |
|
|
|
|
$p = array (); |
|
|
|
|
$fileContents = file_get_contents ( $fileName ); |
|
|
|
|
private function getOptionsFromFile($fileName) |
|
|
|
|
{ |
|
|
|
|
$s = array(); |
|
|
|
|
$p = array(); |
|
|
|
|
$fileContents = file_get_contents($fileName); |
|
|
|
|
/* |
|
|
|
|
* split the config file on every occurance of '--' at start of a line |
|
|
|
|
* Adds a PHP_EOL at the start, so we can catch the first '--' |
|
|
|
|
*/ |
|
|
|
|
$entrys = explode ( PHP_EOL . '--', PHP_EOL . $fileContents ); |
|
|
|
|
foreach ( $entrys as $line ) { |
|
|
|
|
$line = trim ( $line ); |
|
|
|
|
$entrys = explode(PHP_EOL . '--', PHP_EOL . $fileContents); |
|
|
|
|
foreach ($entrys as $line) { |
|
|
|
|
$line = trim($line); |
|
|
|
|
if ($line != '') { |
|
|
|
|
/* |
|
|
|
|
* get position of first space |
|
|
|
|
* so we can split the options out |
|
|
|
|
*/ |
|
|
|
|
$str = strpos ( $line, ' ' ); |
|
|
|
|
$str = strpos($line, ' '); |
|
|
|
|
if ($str === false) { |
|
|
|
|
/* |
|
|
|
|
* Ok, no spaces found, so take this as a single line |
|
|
|
|
*/ |
|
|
|
|
$str = strlen ( $line ); |
|
|
|
|
$str = strlen($line); |
|
|
|
|
} |
|
|
|
|
$key = substr ( $line, $str ); |
|
|
|
|
$value = substr ( $line, $str + 1 ); |
|
|
|
|
if ((array_key_exists ( $key, $this->default ['s'] ))) { |
|
|
|
|
$key = substr($line, $str); |
|
|
|
|
$value = substr($line, $str + 1); |
|
|
|
|
if ((array_key_exists($key, $this->default ['s']))) { |
|
|
|
|
/* |
|
|
|
|
* ok this key appears in the switch config |
|
|
|
|
* so store it as a switch |
|
|
|
|
*/ |
|
|
|
|
$s [$key] = true; |
|
|
|
|
} |
|
|
|
|
if ((array_key_exists ( $key, $this->default ['p'] ))) { |
|
|
|
|
if ((array_key_exists($key, $this->default ['p']))) { |
|
|
|
|
/* |
|
|
|
|
* Ok this key exists in the parameter section, |
|
|
|
|
* So store it allong with its value |
|
|
|
|
*/ |
|
|
|
|
$p [$key] = $this->splitParam ( $value ); |
|
|
|
|
$p [$key] = $this->splitParam($value); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
return array ( |
|
|
|
|
return array( |
|
|
|
|
's' => $s, |
|
|
|
|
'p' => $p |
|
|
|
|
); |
|
|
|
@ -693,13 +706,14 @@ class EncryptTask extends AbstractTask
|
|
|
|
|
* |
|
|
|
|
* @return mixed |
|
|
|
|
*/ |
|
|
|
|
private function splitParam($string) { |
|
|
|
|
$split = explode ( PHP_EOL, $string ); |
|
|
|
|
private function splitParam($string) |
|
|
|
|
{ |
|
|
|
|
$split = explode(PHP_EOL, $string); |
|
|
|
|
if ($split === false) { |
|
|
|
|
// nothing found, so return a blank string |
|
|
|
|
return ''; |
|
|
|
|
} |
|
|
|
|
if (count ( $split ) == 1) { |
|
|
|
|
if (count($split) == 1) { |
|
|
|
|
return $split [0]; |
|
|
|
|
} else { |
|
|
|
|
return $split; |
|
|
|
@ -715,9 +729,10 @@ class EncryptTask extends AbstractTask
|
|
|
|
|
* |
|
|
|
|
* @return array |
|
|
|
|
*/ |
|
|
|
|
private function getOptionsDefault() { |
|
|
|
|
$s = array (); |
|
|
|
|
$p = array (); |
|
|
|
|
private function getOptionsDefault() |
|
|
|
|
{ |
|
|
|
|
$s = array(); |
|
|
|
|
$p = array(); |
|
|
|
|
// Set the switches |
|
|
|
|
$s ['allow-encoding-into-source'] = false; |
|
|
|
|
|
|
|
|
@ -751,9 +766,9 @@ class EncryptTask extends AbstractTask
|
|
|
|
|
|
|
|
|
|
// Now set the params |
|
|
|
|
$p ['encrypt'] [] = '*.tpl.html'; |
|
|
|
|
$p ['encode'] = array (); |
|
|
|
|
$p ['copy'] = array (); |
|
|
|
|
$p ['ignore'] = array ( |
|
|
|
|
$p ['encode'] = array(); |
|
|
|
|
$p ['copy'] = array(); |
|
|
|
|
$p ['ignore'] = array( |
|
|
|
|
'.git', |
|
|
|
|
'.svn', |
|
|
|
|
getcwd() . '/.mage', |
|
|
|
@ -761,7 +776,7 @@ class EncryptTask extends AbstractTask
|
|
|
|
|
'.gitkeep', |
|
|
|
|
'nohup.out' |
|
|
|
|
); |
|
|
|
|
$p ['keep'] = array (); |
|
|
|
|
$p ['keep'] = array(); |
|
|
|
|
$p ['obfuscate'] = ''; |
|
|
|
|
$p ['obfuscation-key'] = ''; |
|
|
|
|
$p ['obfuscation-exclusion-file'] = ''; |
|
|
|
@ -773,23 +788,23 @@ class EncryptTask extends AbstractTask
|
|
|
|
|
$p ['license-check'] = ''; |
|
|
|
|
$p ['apply-file-user'] = ''; |
|
|
|
|
$p ['apply-file-group'] = ''; |
|
|
|
|
$p ['register-autoglobal'] = array (); |
|
|
|
|
$p ['register-autoglobal'] = array(); |
|
|
|
|
$p ['message-if-no-loader'] = ''; |
|
|
|
|
$p ['action-if-no-loader'] = ''; |
|
|
|
|
$p ['loader-path'] = ''; |
|
|
|
|
$p ['preamble-file'] = ''; |
|
|
|
|
$p ['add-comment'] = array (); |
|
|
|
|
$p ['add-comment'] = array(); |
|
|
|
|
$p ['add-comments'] = ''; |
|
|
|
|
$p ['loader-event'] = array (); |
|
|
|
|
$p ['loader-event'] = array(); |
|
|
|
|
$p ['callback-file'] = ''; |
|
|
|
|
$p ['property'] = ''; |
|
|
|
|
$p ['propertys'] = ''; |
|
|
|
|
$p ['include-if-property'] = array (); |
|
|
|
|
$p ['include-if-property'] = array(); |
|
|
|
|
$p ['optimise'] = 'max'; |
|
|
|
|
$p ['shell-script-line'] = ''; |
|
|
|
|
$p ['min-loader-version'] = ''; |
|
|
|
|
|
|
|
|
|
return array ( |
|
|
|
|
return array( |
|
|
|
|
's' => $s, |
|
|
|
|
'p' => $p |
|
|
|
|
); |
|
|
|
|