Advertisement
Guest User

Untitled

a guest
Nov 21st, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.68 KB | None | 0 0
  1. <?php
  2.  
  3. /**
  4. * This is a HOOK POINT in the Softaculous Installation process.
  5. * NOTE : You must rename this file to pre_install_cagefs.php
  6. */
  7.  
  8. //////////////////////////////////////////////////////////////
  9. //===========================================================
  10. // pre_install_cagefs.php
  11. //===========================================================
  12. // SOFTACULOUS
  13. // Version : 1.1
  14. // Inspired by the DESIRE to be the BEST OF ALL
  15. // ----------------------------------------------------------
  16. // Started by: Alons
  17. // Date: 10th Jan 2009
  18. // Time: 21:00 hrs
  19. // Site: http://www.softaculous.com/ (SOFTACULOUS)
  20. // ----------------------------------------------------------
  21. // Please Read the Terms of use at http://www.softaculous.com
  22. // ----------------------------------------------------------
  23. //===========================================================
  24. // (c)Softaculous Inc.
  25. //===========================================================
  26. //////////////////////////////////////////////////////////////
  27.  
  28. if(!defined('SOFTACULOUS')){
  29.  
  30. die('Hacking Attempt');
  31.  
  32. }
  33.  
  34. /**
  35. * This function will be called whenever a script is installed.
  36. * $software will have details of the script being installed.
  37. *
  38. * @package CageFS hooks
  39. * @author Pulkit Gupta
  40. * @return bool
  41. * @since 4.3.0
  42. */
  43. function __pre_install_cagefs(){
  44.  
  45. global $soft, $software, $globals, $scripts, $softpanel, $error, $__hooks;
  46.  
  47. // Is CageFS enabled ?
  48. if(file_exists('/usr/bin/selectorctl') && !defined('php_version')){
  49.  
  50. /*// Lets check if the user is in the disabled list of CageFS
  51. // This is allowed only for root
  52. @exec("/usr/sbin/cagefsctl --list-disabled | grep ".$softpanel->user['name'], $dout, $dret);
  53. if(preg_match('/'.$softpanel->user['name'].'/is', implode('', $dout))){
  54. return true;
  55. }*/
  56.  
  57. // Lets check if CageFS is enabled for this user
  58. @exec("/usr/bin/selectorctl --user-current --user=".$softpanel->user['name'].' 2>&1', $cout, $cret);
  59.  
  60. if(preg_match('/ERROR/is', implode('', $cout))){
  61. return true;
  62. }
  63.  
  64. // If it is native than we will find the verison using sphpversion()
  65. if(preg_match('/native/is', implode('', $cout))){
  66. $native = sphpversion();
  67. }
  68.  
  69. // Get the list of enabled extensions for this user
  70. $command = '/usr/bin/selectorctl --list-user-extensions --user='.$softpanel->user['name'];
  71. @exec($command, $extout, $extret);
  72.  
  73. if(!empty($extout) && is_array($extout)){
  74.  
  75. if(in_array('nd_mysqli', $extout)){
  76. $__hooks['loaded_extension'][] = 'mysqli';
  77. }
  78.  
  79.  
  80. if(in_array('nd_mysql', $extout)){
  81. $__hooks['loaded_extension'][] = 'mysql';
  82. }
  83.  
  84. //added check for nd_pdo_mysql extension so that script that requires pdo_mysql extension enabled will find it as enabled
  85. if(in_array('nd_pdo_mysql', $extout)){
  86. $__hooks['loaded_extension'][] = 'pdo_mysql';
  87. }
  88.  
  89. if(!empty($__hooks['loaded_extension']) && is_array($__hooks['loaded_extension'])){
  90. $__hooks['loaded_extension'] = array_merge($__hooks['loaded_extension'], $extout);
  91. }else{
  92. $__hooks['loaded_extension'] = $extout;
  93. }
  94. }
  95.  
  96. // Get the list of Default enabled extensions
  97. $curr_version = str_replace('.', '', substr($cout[0],0,3)); //current php version
  98. $cagefs_phpbin = '/opt/alt/php'.$curr_version.'/usr/bin/php';
  99.  
  100. if(!empty($native)){
  101. define(eu_php_bin, 'php');
  102. $cagefs_phpbin = '/usr/bin/php';
  103. }
  104.  
  105. @exec($cagefs_phpbin.' -n -m', $extout1, $extret1);
  106.  
  107. if(!empty($extout1) && is_array($extout1)){
  108. if(!empty($__hooks['loaded_extension']) && is_array($__hooks['loaded_extension'])){
  109. $__hooks['loaded_extension'] = array_merge($__hooks['loaded_extension'], $extout1);
  110. }else{
  111. $__hooks['loaded_extension'] = $extout1;
  112. }
  113. }
  114.  
  115. // these extensions are returned by php and we need to convert it to CageFS format
  116. foreach($__hooks['loaded_extension'] as $ke => $ve){
  117. $__hooks['loaded_extension'][$ke] = strtolower(str_replace(' ', '_', $ve));
  118. }
  119.  
  120. // This indicates that the PHP extensions list loaded in $__hooks is exhaustive list
  121. //If cageFS has native php installed, the loaded extensions return empty value
  122. if(!empty($__hooks['loaded_extension']) && empty($native)){
  123. define('PHP_EXT_EXHAUSTIVE', 1);
  124. }
  125.  
  126. // What is the user's PHP version ?
  127. @exec("/usr/bin/selectorctl --user-current --user=".$softpanel->user['name']." | awk '{print $2}'", $out, $ret);
  128.  
  129. if(!empty($native)){
  130. $tmp_out = $native;
  131. }else{
  132. $tmp_out = current($out);
  133. }
  134.  
  135. (!empty($tmp_out) ? $php_version = $tmp_out : '');
  136.  
  137. if(!empty($scripts[$soft]['php_min'])){
  138.  
  139. $short_ver = substr($scripts[$soft]['php_min'], 0, 3);
  140.  
  141. // Is it lower than the required version ?
  142. if(sversion_compare($tmp_out, $scripts[$soft]['php_min'], '<')){
  143.  
  144. // Can the required version be enabled ?
  145. @exec("/usr/bin/selectorctl --list | grep ".$short_ver." | awk '{print $2}'", $eout, $eret);
  146.  
  147. if(!empty($eout) && sversion_compare(current($eout), $scripts[$soft]['php_min'], '>=')){
  148.  
  149. // Ask for a confirmation
  150. if(!checkbox('php_version_select')){
  151. $error[] = 'PHP version is less than the required '.$scripts[$soft]['php_min'].'<br />
  152. <input type="checkbox" name="php_version_select" '.POSTChecked('php_version_select').' />
  153. Do you wish to enable PHP '.current($eout).' ? (Might cause issues with your existing installations).';
  154. // Lets enable the version for the user
  155. }else{
  156. @exec("/usr/bin/selectorctl --set-user-current=".$short_ver." --user=".$softpanel->user['name'], $sout, $sret);
  157.  
  158. @exec("/usr/bin/selectorctl --user-current --user=".$softpanel->user['name']." | awk '{print $2}'", $nout, $nret);
  159.  
  160. $php_version = current($nout);
  161. }
  162. }
  163. }
  164. }
  165.  
  166. if(!empty($scripts[$soft]['php_max'])){
  167.  
  168. $short_ver = substr($scripts[$soft]['php_max'], 0, 3) - (0.1);
  169.  
  170. // Is it lower than the required version ?
  171. if(sversion_compare($tmp_out, $scripts[$soft]['php_max'], '>')){
  172.  
  173. // Can the required version be enabled ?
  174.  
  175. @exec("/usr/bin/selectorctl --list | grep ".$short_ver." | awk '{print $2}'", $eout, $eret);
  176.  
  177. if(!empty($eout) && sversion_compare(current($eout), $scripts[$soft]['php_max'], '<')){
  178.  
  179. // Ask for a confirmation
  180. if(!checkbox('php_max_version_select')){
  181. $error[] = 'This script is not compatible with PHP version : '.$scripts[$soft]['php_max'].'+<br />
  182. <input type="checkbox" name="php_max_version_select" '.POSTChecked('php_max_version_select').' />
  183. Do you wish to enable PHP '.current($eout).' ? (Might cause issues with your existing installations).';
  184. // Lets enable the version for the user
  185. }else{
  186. @exec("/usr/bin/selectorctl --set-user-current=".$short_ver." --user=".$softpanel->user['name'], $sout, $sret);
  187.  
  188. @exec("/usr/bin/selectorctl --user-current --user=".$softpanel->user['name']." | awk '{print $2}'", $nout, $nret);
  189.  
  190. $php_version = current($nout);
  191. }
  192. }
  193. }
  194. }
  195. }
  196.  
  197. if(!empty($php_version)) define('php_version', $php_version);
  198. if(!empty($cagefs_phpbin)) define('eu_php_bin', $cagefs_phpbin);
  199. }
  200.  
  201. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement