IoncubeLicenseTask.php 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. <?php
  2. /**
  3. * $Id: IoncubeLicenseTask.php 905 2010-10-05 16:28:03Z mrook $
  4. *
  5. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  6. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  7. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  8. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  9. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  10. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  11. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  12. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  13. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  14. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  15. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  16. *
  17. * This software consists of voluntary contributions made by many individuals
  18. * and is licensed under the LGPL. For more information please see
  19. * <http://phing.info>.
  20. */
  21. require_once 'phing/Task.php';
  22. require_once 'phing/tasks/ext/ioncube/IoncubeComment.php';
  23. /**
  24. * Invokes the ionCube "make_license" program
  25. *
  26. * @author Michiel Rook <michiel.rook@gmail.com>
  27. * @version $Id: IoncubeLicenseTask.php 905 2010-10-05 16:28:03Z mrook $
  28. * @package phing.tasks.ext.ioncube
  29. * @since 2.2.0
  30. */
  31. class IoncubeLicenseTask extends Task
  32. {
  33. private $ioncubePath = "/usr/local/ioncube";
  34. private $licensePath = "";
  35. private $passPhrase = "";
  36. private $allowedServer = "";
  37. private $expireOn = "";
  38. private $expireIn = "";
  39. private $comments = array();
  40. /**
  41. * Sets the path to the ionCube encoder
  42. */
  43. function setIoncubePath($ioncubePath)
  44. {
  45. $this->ioncubePath = $ioncubePath;
  46. }
  47. /**
  48. * Returns the path to the ionCube encoder
  49. */
  50. function getIoncubePath()
  51. {
  52. return $this->ioncubePath;
  53. }
  54. /**
  55. * Sets the path to the license file to use
  56. */
  57. function setLicensePath($licensePath)
  58. {
  59. $this->licensePath = $licensePath;
  60. }
  61. /**
  62. * Returns the path to the license file to use
  63. */
  64. function getLicensePath()
  65. {
  66. return $this->licensePath;
  67. }
  68. /**
  69. * Sets the passphrase to use when encoding files
  70. */
  71. function setPassPhrase($passPhrase)
  72. {
  73. $this->passPhrase = $passPhrase;
  74. }
  75. /**
  76. * Returns the passphrase to use when encoding files
  77. */
  78. function getPassPhrase()
  79. {
  80. return $this->passPhrase;
  81. }
  82. /**
  83. * Adds a comment to be used in encoded files
  84. */
  85. function addComment(IoncubeComment $comment)
  86. {
  87. $this->comments[] = $comment;
  88. }
  89. /**
  90. * Sets the --allowed-server option to use when generating the license
  91. */
  92. function setAllowedServer($allowedServer)
  93. {
  94. $this->allowedServer = $allowedServer;
  95. }
  96. /**
  97. * Returns the --allowed-server option
  98. */
  99. function getAllowedServer()
  100. {
  101. return $this->allowedServer;
  102. }
  103. /**
  104. * Sets the --expire-on option to use when generating the license
  105. */
  106. function setExpireOn($expireOn)
  107. {
  108. $this->expireOn = $expireOn;
  109. }
  110. /**
  111. * Returns the --expire-on option
  112. */
  113. function getExpireOn()
  114. {
  115. return $this->expireOn;
  116. }
  117. /**
  118. * Sets the --expire-in option to use when generating the license
  119. */
  120. function setExpireIn($expireIn)
  121. {
  122. $this->expireIn = $expireIn;
  123. }
  124. /**
  125. * Returns the --expire-in option
  126. */
  127. function getExpireIn()
  128. {
  129. return $this->expireIn;
  130. }
  131. /**
  132. * The main entry point
  133. *
  134. * @throws BuildException
  135. */
  136. function main()
  137. {
  138. $arguments = $this->constructArguments();
  139. $makelicense = new PhingFile($this->ioncubePath, 'make_license');
  140. $this->log("Running ionCube make_license...");
  141. exec($makelicense->__toString() . " " . $arguments . " 2>&1", $output, $return);
  142. if ($return != 0)
  143. {
  144. throw new BuildException("Could not execute ionCube make_license: " . implode(' ', $output));
  145. }
  146. }
  147. /**
  148. * Constructs an argument string for the ionCube make_license
  149. */
  150. private function constructArguments()
  151. {
  152. $arguments = "";
  153. if (!empty($this->passPhrase))
  154. {
  155. $arguments.= "--passphrase '" . $this->passPhrase . "' ";
  156. }
  157. foreach ($this->comments as $comment)
  158. {
  159. $arguments.= "--header-line '" . $comment->getValue() . "' ";
  160. }
  161. if (!empty($this->licensePath))
  162. {
  163. $arguments.= "--o '" . $this->licensePath . "' ";
  164. }
  165. if (!empty($this->allowedServer))
  166. {
  167. $arguments.= "--allowed-server {" . $this->allowedServer . "} ";
  168. }
  169. if (!empty($this->expireOn))
  170. {
  171. $arguments.= "--expire-on " . $this->expireOn . " ";
  172. }
  173. if (!empty($this->expireIn))
  174. {
  175. $arguments.= "--expire-in " . $this->expireIn . " ";
  176. }
  177. return $arguments;
  178. }
  179. }