Public paste
Boot System Requirements
By: fruffl | Date: Jan 25 2010 21:22 | Format: PHP | Expires: never | Size: 7.24 KB | Hits: 999

  1. <?php
  2.  
  3.         FINAL CLASS ILLI_SequenceBoot_LinkSystem_SegmentRequirements EXTENDS ILLI_SequenceBoot_LinkSystem_Segment
  4.         {
  5.                 private $serverIni       = 'server.availableness.ini';
  6.        
  7.                 public function init()
  8.                 {      
  9.                         $this->serverIni = $this->_root->Boot->System->Registry->get()->CORE_DIR->CACHE.DIRECTORY_SEPARATOR.$this->serverIni;                  
  10.                        
  11.                         file_exists($this->serverIni) && !$this->_root->getApplicationTest()
  12.                                 ? $this->loadIniFile()
  13.                                 : $this->createIniFile();
  14.                 }
  15.                
  16.                 public function run()
  17.                 {
  18.                         if($this->_root->getApplicationTest())
  19.                                 $this->createIniFile();
  20.                 }
  21.                
  22.                 private function loadIniFile()
  23.                 {
  24.                
  25.                         $INI = $this->_root->Boot->System->Loader->ini($this->serverIni);
  26.                        
  27.                         if(!$INI->offsetExists('AVAILABLENESS') || count($INI->AVAILABLENESS) !== 26)
  28.                         {
  29.                                 $this->createIniFile();
  30.                                 return;
  31.                         }
  32.  
  33.                         foreach($INI->AVAILABLENESS as $key => $value)
  34.                                 $this->_root->Boot->System->Registry->add('AVAILABLENESS', $key, $value);
  35.                 }
  36.                
  37.                 private function createIniFile()
  38.                 {
  39.                         $ini  = '; DONT EDIT THIS FILE!';
  40.                         $ini .= "n".'; some server-settings to bypass the detections at every request.';
  41.                         $ini .= "n".'; TO UPDATE VALUES DELETE THIS FILE.';
  42.                         $ini .= "n".'[AVAILABLENESS]';
  43.                        
  44.                         $this->checkAvailableness();
  45.                        
  46.                         foreach($this->_root->Boot->System->Registry->get()->AVAILABLENESS as $key => $value)
  47.                         {
  48.                                 if($value === NULL || $value === '')
  49.                                         $value = 'NULL';
  50.                                        
  51.                                 if($value === 0 || $value === false)
  52.                                         $value = 'FALSE';
  53.                                        
  54.                                 if($value === 1 || $value === true)
  55.                                         $value = 'TRUE';
  56.                                        
  57.                                 $ini .= "n".strtoupper($key).' = '.$value;
  58.                         }
  59.                        
  60.                         file_put_contents($this->serverIni, $ini);;
  61.                 }              
  62.                
  63.                 private function checkAvailableness()
  64.                 {
  65.                         function parsePHPModules()
  66.                         {
  67.                                 ob_start();
  68.                                 phpinfo(INFO_MODULES);
  69.                                 $s = ob_get_contents();
  70.                                 ob_end_clean();
  71.                        
  72.                                 $s = strip_tags($s,'<h2><th><td>');
  73.                                 $s = preg_replace('/<th[^>]*>([^<]+)</th>/',"<info>\1</info>",$s);
  74.                                 $s = preg_replace('/<td[^>]*>([^<]+)</td>/',"<info>\1</info>",$s);
  75.                                 $vTmp = preg_split('/(<h2[^>]*>[^<]+</h2>)/',$s,-1,PREG_SPLIT_DELIM_CAPTURE);
  76.                                
  77.                                 $vModules = array();
  78.                                
  79.                                 for ($i=1;$i<count($vTmp);$i++)
  80.                                         if (preg_match('/<h2[^>]*>([^<]+)</h2>/',$vTmp[$i],$vMat))
  81.                                         {
  82.                                                 $vName = trim($vMat[1]);
  83.                                                 $vTmp2 = explode("n",$vTmp[$i+1]);
  84.                                                
  85.                                                 foreach ($vTmp2 AS $vOne)
  86.                                                 {
  87.                                                         $vPat = '<info>([^<]+)</info>';
  88.                                                         $vPat3 = "/$vPats*$vPats*$vPat/";
  89.                                                         $vPat2 = "/$vPats*$vPat/";
  90.                                                        
  91.                                                         if(preg_match($vPat3,$vOne,$vMat))
  92.                                                                 $vModules[$vName][trim($vMat[1])] =
  93.                                                                         array(trim($vMat[2]),trim($vMat[3]));
  94.                                                         else
  95.                                                         if(preg_match($vPat2,$vOne,$vMat))
  96.                                                                 $vModules[$vName][trim($vMat[1])] = trim($vMat[2]);
  97.                                                 }
  98.                                         }
  99.                                        
  100.                                 return $vModules;
  101.                         }
  102.                        
  103.                         function parseApacheModules()
  104.                         {
  105.                                 $input = parsePHPModules();
  106.                                
  107.                                 if(isset($input['apache']))
  108.                                 {
  109.                                         $modules = $input['apache']['Loaded Modules'];
  110.                                         $mod_list = explode(",",$modules);
  111.                                         foreach($mod_list as $key=>$value)
  112.                                                 $mod_list[$key] = trim($value);
  113.                                                
  114.                                         return $mod_list;
  115.                                 }
  116.                                 else
  117.                                 if(isset($input['apache2handler']))
  118.                                 {
  119.                                         $modules = $input['apache2handler']['Loaded Modules'];
  120.                                         $mod_list = explode(" ",$modules);
  121.                                         foreach($mod_list as $key=>$value)
  122.                                                 $mod_list[$key] = trim($value);
  123.                                                
  124.                                         return $mod_list;
  125.                                 }
  126.                                
  127.                                 return array();
  128.                         }
  129.                
  130.                         $REGISTRY = $this->_root->Boot->System->Registry;
  131.                
  132.                         $REGISTRY
  133.                         -> add('AVAILABLENESS', 'CHECK_SAFEMODE',
  134.                                 (bool) ini_get('safe_mode'))
  135.                                
  136.                         -> add('AVAILABLENESS', 'CHECK_CURL',
  137.                                 (bool) function_exists('curl_init'))
  138.                                
  139.                         -> add('AVAILABLENESS', 'CHECK_URLFOPEN',
  140.                                 (!$REGISTRY->get()->AVAILABLENESS->CHECK_SAFEMODE && ini_get('allow_url_fopen')))
  141.  
  142.                         -> add('AVAILABLENESS', 'CHECK_ZENDENGINE1_COMPATIBILITY',
  143.                                 (bool) ini_get('zend.ze1_compatibility_mode'))
  144.  
  145.                         -> add('AVAILABLENESS', 'CHECK_FTP',
  146.                                 (bool) function_exists('ftp_login'))
  147.  
  148.                         -> add('AVAILABLENESS', 'CHECK_FILEUPLOADS',
  149.                                 (bool) ini_get('file_uploads'))
  150.  
  151.                         -> add('AVAILABLENESS', 'CHECK_MYSQ',
  152.                                 (bool) function_exists('mysql_connect'))
  153.  
  154.                         -> add('AVAILABLENESS', 'CHECK_PGSQL',
  155.                                 (bool) function_exists('pg_connect'))
  156.  
  157.                         -> add('AVAILABLENESS', 'CHECK_IMAP',
  158.                                 (bool) function_exists('imap_open'))
  159.  
  160.                         -> add('AVAILABLENESS', 'CHECK_GD',
  161.                                 (bool) function_exists('imagegd'))
  162.  
  163.                         -> add('AVAILABLENESS', 'CHECK_ZLIB',
  164.                                 (bool) function_exists('gzwrite'))
  165.  
  166.                         -> add('AVAILABLENESS', 'CHECK_PSPELL',  
  167.                                 (bool) function_exists('pspell_suggest'))
  168.  
  169.                         -> add('AVAILABLENESS', 'CHECK_FSOCKOPEN',
  170.                                 (bool) function_exists('fsockopen'))
  171.  
  172.                         -> add('AVAILABLENESS', 'CHECK_SIMPLEXML',
  173.                                 (bool) function_exists('simplexml_load_string') && class_exists('SimpleXMLElement'))
  174.  
  175.                         -> add('AVAILABLENESS', 'CHECK_SOAP',
  176.                                 (bool) class_exists('SoapServer'))
  177.  
  178.                         -> add('AVAILABLENESS', 'CHECK_MCRYPT',
  179.                                 (bool) function_exists('mcrypt_encrypt'))
  180.  
  181.                         -> add('AVAILABLENESS', 'CHECK_SESSION_AUTOSTART',
  182.                                 (bool) ini_get('session.auto_start'))
  183.  
  184.                         -> add('AVAILABLENESS', 'CHECK_SESSION_DIR',
  185.                                 (bool) is_dir(ini_get('session.save_path')))
  186.  
  187.                         -> add('AVAILABLENESS', 'CHECK_SESSION_REFERER_CHECK_CORRECT',
  188.                                 ini_get('session.referer_check') == '' || strpos($_SERVER['HTTP_HOST'], ini_get('session.referer_check')))
  189.  
  190.                         -> add('AVAILABLENESS', 'CHECK_SESSION_CHECK',
  191.                                 (bool) isset($_SESSION['CHECK_SESSION_CHECK']) && $_SESSION['CHECK_SESSION_CHECK'] === TRUE)
  192.  
  193.                         -> add('AVAILABLENESS', 'CHECK_PHP_SAPI',
  194.                                 php_sapi_name())
  195.  
  196.                         -> add('AVAILABLENESS', 'CHECK_CGI_MODE',
  197.                                 (is_numeric(strpos($REGISTRY->get('AVAILABLENESS', 'CHECK_PHP_SAPI'), 'cgi')) ? TRUE : FALSE))
  198.  
  199.                         -> add('AVAILABLENESS', 'CHECK_BASEDIR_OK',
  200.                                 (bool) is_null(ini_get('open_basedir')) || ini_get('open_basedir') === false || ini_get('open_basedir') == '');
  201.                        
  202.                                        
  203.                         if(in_array($REGISTRY->get()->AVAILABLENESS->CHECK_PHP_SAPI, array('apache', 'apache2handler')))
  204.                         {
  205.                                 $REGISTRY
  206.                                 -> add('AVAILABLENESS', 'CHECK_MOD_REWRITE_AVAILABLE',
  207.                                         (bool) in_array("mod_rewrite", parseApacheModules()))
  208.  
  209.                                 -> add('AVAILABLENESS', 'CHECK_MOD_SECURITY_ENABLED',
  210.                                         (bool) in_array("mod_security", parseApacheModules()));
  211.                         }
  212.                         else
  213.                         {
  214.                                 $REGISTRY
  215.                                 -> add('AVAILABLENESS', 'CHECK_MOD_REWRITE_AVAILABLE',
  216.                                          NULL)
  217.  
  218.                                 -> add('AVAILABLENESS', 'CHECK_MOD_SECURITY_ENABLED',
  219.                                         NULL);
  220.                         }
  221.                        
  222.                         $remoteAccess = FALSE;                 
  223.                        
  224.                         if($REGISTRY->get()->AVAILABLENESS->CHECK_CURL)
  225.                         {
  226.                                 $curl = curl_init();
  227.                                
  228.                                 curl_setopt($curl, CURLOPT_URL, 'http://nopaste.nl/');
  229.                                 curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
  230.                                 curl_setopt($curl, CURLOPT_FAILONERROR, true);
  231.                                 curl_setopt($curl, CURLOPT_TIMEOUT, 10);
  232.                
  233.                                 $temp = curl_exec($curl);
  234.                                
  235.                                 curl_close($curl);
  236.                
  237.                                 if(!empty($temp))
  238.                                         $remoteAccess = TRUE;
  239.                         }
  240.                         else
  241.                         if($REGISTRY->get()->AVAILABLENESS->CHECK_URLFOPEN)
  242.                         {
  243.                                 $temp = file_get_contents('http://nopaste.nl/');
  244.                                
  245.                                 if(!empty($temp))
  246.                                         $remoteAccess = TRUE;
  247.                         }
  248.                
  249.                         $REGISTRY
  250.                         -> add('AVAILABLENESS', 'CHECK_REMOTE_ACCESS',
  251.                                 $remoteAccess);
  252.                 }
  253.                
  254.         }