ioncube_encoder.sh 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407
  1. #!/bin/sh
  2. encoder=""
  3. fullEncoder="Current (v9.0)"
  4. language=""
  5. selectedArch=""
  6. sysArch=""
  7. encoderOptions=""
  8. encoderPath=""
  9. warning=""
  10. isFreeBSD="" # Whether the script is running on FreeBSD which does not have any 64-bit encoders.
  11. currentV="9.0"
  12. legacyV="8.3"
  13. obsoleteV="7.0"
  14. # Encoder-Arch-Language
  15. encodersForV9="C-64-5.3 C-64-5.4 C-64-5.5 C-64-5.6
  16. C-32-4 C-32-5 C-32-5.3 C-32-5.4 C-32-5.5 C-32-5.6
  17. L-32-4 L-32-5 L-32-5.3 L-32-5.4 L-32-5.5
  18. L-64-5.3 L-64-5.4 L-64-5.5
  19. O-32-4 O-32-5 O-32-53"
  20. fail() {
  21. echo $*
  22. exit 1
  23. }
  24. checkSelectionCompatibility() {
  25. var="$encoder-$selectedArch-$language"
  26. #echo "$var"
  27. #check if 64-bit Legacy or obsolete is selected.
  28. if [ "$encoder-$selectedArch" = "O-64" ] ; then
  29. echo O64
  30. return
  31. fi
  32. # check if selected encoder, arch and language combination is valid.
  33. for validEncoder in $encodersForV9; do
  34. [ "$validEncoder" = "$var" ] && echo valid & return
  35. done
  36. #else it is invalid.
  37. echo invalid
  38. }
  39. checkSystemCompatibility() {
  40. # check for 64-bit Encoder running on FreeBSD which does not have any 64-bit encoders.
  41. [ "$selectedArch" = "64" ] && [ "$isFreeBSD" = 1 ] && fail "64-bit ionCube Encoders do not exist for FreeBSD. Please use the 32-bit Encoders."
  42. # check for 64-bit Encoder running on a 32-bit system.
  43. [ "$selectedArch" = "64" ] && [ "$sysArch" = "32" ] && fail "You cannot run the 64-bit ionCube Encoder on a 32-bit system."
  44. # check for 32-bit Encoder running on a 64-bit system.
  45. [ "$selectedArch" = "32" ] && [ "$sysArch" = "64" ] && warning="Warning: you are running the 32-bit ionCube Encoder on a 64-bit system."
  46. }
  47. setEncoder() {
  48. if [ "$encoder" = "" ] ; then
  49. encoder="$1"
  50. [ "$1" = "C" ] && fullEncoder="Current (v9.0)"
  51. [ "$1" = "L" ] && fullEncoder="Legacy (v8.3)"
  52. [ "$1" = "O" ] && fullEncoder="Obsolete (v7.0)"
  53. else
  54. fail "You cannot set more than one Encoder version."
  55. fi
  56. }
  57. setLanguage() {
  58. if [ "$language" = "" ] ; then
  59. language="$1"
  60. else
  61. fail "You cannot set more than one Encoding language."
  62. fi
  63. }
  64. setArch() {
  65. if [ "$selectedArch" = "" ] ; then
  66. selectedArch="$1"
  67. else
  68. fail "You cannot set more than one architecture type"
  69. fi
  70. }
  71. setSysArch() {
  72. localArch=`uname -m`
  73. isFreeBSD=`uname -s | grep -ic "FreeBSD"`
  74. sysArch="32"
  75. if [ "$isFreeBSD" = "1" ]
  76. then
  77. # AJT FreeBSD only has 32-bit Encoders presently.
  78. sysArch="32"
  79. else
  80. #echo "$localArch"
  81. case "$localArch" in
  82. "i686" | "i386")
  83. sysArch="32"
  84. ;;
  85. "x86_64" | "amd64")
  86. sysArch="64"
  87. ;;
  88. esac
  89. fi
  90. }
  91. checkLanguage() {
  92. if [ "$language" = "" ] ; then
  93. echo notSet
  94. else
  95. echo set
  96. fi
  97. }
  98. printHelp32() {
  99. echo "
  100. The following is a summary of command options for this script and its basic usage.
  101. Usage: ioncube_encoder.sh [-C | -L | -O] [-4 | -5 | -53 | -54 | -55 | -56 ] [-x86] <encoder options>
  102. Encoder Version (optional):
  103. -O : Use Obsolete Encoder (v7.0)
  104. -L : Use Legacy Encoder (v8.3)
  105. -C : Use Current Encoder (v9.0) - Default
  106. PHP Languages:
  107. -4 : Encode file in PHP 4
  108. -5 : Encode file in PHP 5
  109. -53 : Encode file in PHP 53
  110. -54 : Encode file in PHP 54
  111. -55 : Encode file in PHP 55
  112. -56 : Encode file in PHP 56
  113. Architecture (optional):
  114. -x86 : Run the 32-bit Encoder
  115. -h : Display this help and exit.
  116. If -h is specified before a language has been selected, help will be displayed by the script.
  117. if -h is specified after a language has been selected, help will be displayed by the Encoder.
  118. If an Encoder version is not selected, the Current Encoder (9.0) will be selected.
  119. If a PHP language is not selected, the script will exit.
  120. If an architecture is not selected, the script will run the Encoder that matches your system architecture.
  121. Once an unknown option is selected, the script will pass the remaining options to the Encoder.
  122. You cannot select more than one Encoder version, PHP language or Architecture.
  123. Usage examples:
  124. Current Encoder, encoded in PHP 5.6
  125. ./ioncube_encoder.sh -C -56 source_file.php -o target_file.php
  126. Current Encoder, encoded in PHP 5.4. Encoder displays help.
  127. ./ioncube_encoder.sh -C -54 -h
  128. Legacy Encoder, encoded in PHP 5.3
  129. ./ioncube_encoder.sh -L -53
  130. "
  131. exit
  132. }
  133. printHelp64() {
  134. echo "
  135. The following is a summary of command options for this script and its basic usage.
  136. Usage: ioncube_encoder.sh [-C | -L | -O] [-4 | -5 | -53 | -54 | -55 | -56 ] [-x86 | -x86-64] <encoder options>
  137. Encoder Version (optional):
  138. -O : Use Obsolete Encoder (v7.0)
  139. -L : Use Legacy Encoder (v8.3)
  140. -C : Use Current Encoder (v9.0) - Default
  141. PHP Languages:
  142. -4 : Encode file in PHP 4
  143. -5 : Encode file in PHP 5
  144. -53 : Encode file in PHP 53
  145. -54 : Encode file in PHP 54
  146. -55 : Encode file in PHP 55
  147. -56 : Encode file in PHP 56
  148. Architecture (optional):
  149. -x86 : Run the 32-bit Encoder
  150. -x86-64 : Run the 64-bit Encoder
  151. -h : Display this help and exit.
  152. If -h is specified before a language has been selected, help will be displayed by the script.
  153. if -h is specified after a language has been selected, help will be displayed by the Encoder.
  154. If an Encoder version is not selected, the Current Encoder (9.0) will be selected.
  155. If a PHP language is not selected, the script will exit.
  156. If an architecture is not selected, the script will run the Encoder that matches your system architecture.
  157. Once an unknown option is selected, the script will pass the remaining options to the Encoder.
  158. You cannot select more than one Encoder version, PHP language or Architecture.
  159. Script will exit should you try to run the 64-bit Encoder on a 32-bit system.
  160. Usage examples:
  161. Current 64-bit Encoder, encoded in PHP 5.6
  162. ./ioncube_encoder.sh -C -x86-64 -56 source_file.php -o target_file.php
  163. Current 64-bit Encoder, encoded in PHP 5.4. Encoder displays help.
  164. ./ioncube_encoder.sh -C -x86-64 -54 -h
  165. Legacy 32-bit Encoder, encoded in PHP 5.3
  166. ./ioncube_encoder.sh -L -x86 -53
  167. "
  168. exit
  169. }
  170. printHelp() {
  171. if [ "$sysArch" = "64" ]
  172. then
  173. printHelp64
  174. else
  175. printHelp32
  176. fi
  177. }
  178. setEncoderFilePath() {
  179. # AJT 20150423 Change so that all executables go in a bin directory but are suffixed with version number and, if 64 bit, "_64".
  180. encoderPath=`cd \`dirname $0\` ; pwd`/bin/
  181. case "$language" in
  182. 4)
  183. encoderPath="$encoderPath""ioncube_encoder4"
  184. ;;
  185. 5)
  186. encoderPath="$encoderPath""ioncube_encoder5"
  187. ;;
  188. 5.3)
  189. encoderPath="$encoderPath""ioncube_encoder53"
  190. ;;
  191. 5.4)
  192. encoderPath="$encoderPath""ioncube_encoder54"
  193. ;;
  194. 5.5)
  195. encoderPath="$encoderPath""ioncube_encoder55"
  196. ;;
  197. 5.6)
  198. encoderPath="$encoderPath""ioncube_encoder56"
  199. ;;
  200. esac
  201. case "$encoder" in
  202. C)
  203. encoderPath="$encoderPath""_""$currentV"
  204. ;;
  205. L)
  206. encoderPath="$encoderPath""_""$legacyV"
  207. ;;
  208. O)
  209. encoderPath="$encoderPath""_""$obsoleteV"
  210. ;;
  211. esac
  212. # AJT 20150423 Now just suffix 64-bit with "_64".
  213. case "$selectedArch" in
  214. 32)
  215. encoderPath="$encoderPath"
  216. ;;
  217. 64)
  218. encoderPath="$encoderPath""_64"
  219. ;;
  220. esac
  221. }
  222. checkEncoderExists() {
  223. if [ -f $encoderPath ] ; then
  224. if [ -x $encoderPath ] ; then
  225. true
  226. else
  227. fail "The Encoder is not executable."
  228. fi
  229. else
  230. fail "The Encoder does not exist at the path: $encoderPath"
  231. fi
  232. }
  233. setSysArch
  234. if [ $# -eq 0 ] ; then
  235. printHelp
  236. fi
  237. #while [ "$1" ]
  238. for var in "$@"
  239. do
  240. case "$var" in
  241. -L)
  242. setEncoder "L"
  243. ;;
  244. -O)
  245. setEncoder "O"
  246. ;;
  247. -C)
  248. setEncoder "C"
  249. ;;
  250. -4)
  251. setLanguage "4"
  252. ;;
  253. -5)
  254. setLanguage "5"
  255. ;;
  256. -53)
  257. setLanguage "5.3"
  258. ;;
  259. -54)
  260. setLanguage "5.4"
  261. ;;
  262. -55)
  263. setLanguage "5.5"
  264. ;;
  265. -56)
  266. setLanguage "5.6"
  267. ;;
  268. -x86)
  269. setArch "32"
  270. ;;
  271. -x86-64)
  272. setArch "64"
  273. ;;
  274. -h)
  275. if [ "$language" ] ; then
  276. break
  277. else
  278. printHelp
  279. fi;
  280. ;;
  281. *)
  282. break;
  283. ;;
  284. esac
  285. shift
  286. done
  287. [ "$language" = "" ] && fail "You must set an Encoding language. Enter -h for help."
  288. [ "$encoder" = "" ] && encoder="C"
  289. [ "$selectedArch" = "" ] && selectedArch="$sysArch"
  290. #checkSelectionCompatibility
  291. selection="$(checkSelectionCompatibility)"
  292. if [ "$selection" = "valid" ] ; then
  293. true
  294. elif [ "$selection" = "invalid" ] ; then
  295. fail "The PHP language ($language) you have selected is not supported by the $fullEncoder $selectedArch-bit ionCube Encoder. Enter -h for help."
  296. elif [ "$selection" = "O64" ] ; then
  297. fail "There is no 64-bit version of the $fullEncoder ionCube Encoder. Enter -H for help."
  298. fi
  299. checkSystemCompatibility
  300. #echo "$encoder $language $selectedArch"
  301. setEncoderFilePath
  302. #echo "encoder options: $@"
  303. #echo "path: $encoderPath"
  304. checkEncoderExists
  305. [ "$warning" != "" ] && echo "$warning"
  306. exec $encoderPath "$@"