Advertisement
Guest User

Untitled

a guest
Feb 1st, 2017
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.21 KB | None | 0 0
  1. <?php
  2.  
  3. class XenForo_Install_Model_Install extends XenForo_Model
  4. {
  5. public function getRequirementErrors(Zend_Db_Adapter_Abstract $db = null)
  6. {
  7. $errors = array();
  8.  
  9. $phpVersion = phpversion();
  10. if (version_compare($phpVersion, '5.2.11', '<'))
  11. {
  12. $errors['phpVersion'] = new XenForo_Phrase('php_version_x_does_not_meet_requirements', array('version' => $phpVersion));
  13. }
  14.  
  15. $safeModeIni = @ini_get('safe_mode');
  16. if (is_bool($safeModeIni) || intval($safeModeIni))
  17. {
  18. $isSafeMode = (bool)$safeModeIni;
  19. }
  20. else
  21. {
  22. $isSafeMode = in_array(strtolower($safeModeIni), array('on', 'yes', 'true'));
  23. }
  24. if ($isSafeMode)
  25. {
  26. $errors['safe_mode'] = new XenForo_Phrase('php_must_not_be_in_safe_mode');
  27. }
  28.  
  29. if (!function_exists('mysqli_connect'))
  30. {
  31. $errors['mysqlPhp'] = new XenForo_Phrase('required_php_extension_x_not_found', array('extension' => 'MySQLi'));
  32. }
  33.  
  34. if (!function_exists('gd_info'))
  35. {
  36. $errors['gd'] = new XenForo_Phrase('required_php_extension_x_not_found', array('extension' => 'GD'));
  37. }
  38. else if (!function_exists('imagecreatefromjpeg'))
  39. {
  40. $errors['gdJpeg'] = new XenForo_Phrase('gd_jpeg_support_missing');
  41. }
  42.  
  43. if (!function_exists('iconv'))
  44. {
  45. $errors['iconv'] = new XenForo_Phrase('required_php_extension_x_not_found', array('extension' => 'Iconv'));
  46. }
  47.  
  48. if (!function_exists('ctype_alnum'))
  49. {
  50. $errors['ctype'] = new XenForo_Phrase('required_php_extension_x_not_found', array('extension' => 'Ctype'));
  51. }
  52.  
  53. if (!function_exists('preg_replace'))
  54. {
  55. $errors['pcre'] = new XenForo_Phrase('required_php_extension_x_not_found', array('extension' => 'PCRE'));
  56. }
  57. else
  58. {
  59. try
  60. {
  61. preg_match('/./u', 'x');
  62. }
  63. catch (Exception $e)
  64. {
  65. $errors['pcre'] = new XenForo_Phrase('pcre_unicode_support_missing');
  66. }
  67. }
  68.  
  69. if (!function_exists('spl_autoload_register'))
  70. {
  71. $errors['spl'] = new XenForo_Phrase('required_php_extension_x_not_found', array('extension' => 'SPL'));
  72. }
  73.  
  74. if (!function_exists('json_encode'))
  75. {
  76. $errors['json'] = new XenForo_Phrase('required_php_extension_x_not_found', array('extension' => 'JSON'));
  77. }
  78.  
  79. if (!class_exists('DOMDocument') || !class_exists('SimpleXMLElement'))
  80. {
  81. $errors['xml'] = new XenForo_Phrase('required_php_xml_extensions_not_found');
  82. }
  83.  
  84. if ($db)
  85. {
  86. $mySqlVersion = $db->getServerVersion();
  87. if ($mySqlVersion && intval($mySqlVersion) < 5)
  88. {
  89. $errors['mysqlVersion'] = new XenForo_Phrase('mysql_version_x_does_not_meet_requirements', array('version' => $mySqlVersion));
  90. }
  91. }
  92.  
  93. $dataDir = XenForo_Helper_File::getExternalDataPath();
  94. if (!is_dir($dataDir) || !is_writable($dataDir))
  95. {
  96. $errors['dataDir'] = new XenForo_Phrase('directory_x_must_be_writable', array('directory' => $dataDir));
  97. }
  98. else
  99. {
  100. foreach (scandir($dataDir) AS $file)
  101. {
  102. if ($file[0] == '.')
  103. {
  104. continue;
  105. }
  106.  
  107. $fullPath = "$dataDir/$file";
  108. if (is_dir($fullPath) && !is_writable($fullPath))
  109. {
  110. $errors['dataDir'] = new XenForo_Phrase('all_directories_under_x_must_be_writable', array('directory' => $dataDir));
  111. }
  112. }
  113. }
  114.  
  115. $internalDataDir = XenForo_Helper_File::getInternalDataPath();
  116. if (!is_dir($internalDataDir) || !is_writable($internalDataDir))
  117. {
  118. $errors['internalDataDir'] = new XenForo_Phrase('directory_x_must_be_writable', array('directory' => $internalDataDir));
  119. }
  120. else
  121. {
  122. foreach (scandir($internalDataDir) AS $file)
  123. {
  124. if ($file[0] == '.')
  125. {
  126. continue;
  127. }
  128.  
  129. $fullPath = "$internalDataDir/$file";
  130. if (is_dir($fullPath) && !is_writable($fullPath))
  131. {
  132. $errors['internalDataDir'] = new XenForo_Phrase('all_directories_under_x_must_be_writable', array('directory' => $internalDataDir));
  133. }
  134. }
  135. }
  136.  
  137. return $errors;
  138. }
  139.  
  140. public function getRequirementWarnings(Zend_Db_Adapter_Abstract $db = null)
  141. {
  142. $warnings = array();
  143.  
  144. $phpVersion = phpversion();
  145. if (version_compare($phpVersion, '5.4.0', '<'))
  146. {
  147. $warnings['phpVersion'] = new XenForo_Phrase('php_version_x_outdated_upgrade', array('version' => $phpVersion));
  148. }
  149.  
  150. $disabledFunctions = @ini_get('disable_functions');
  151. if (!is_string($disabledFunctions))
  152. {
  153. $warnings['disabledFunctions'] = new XenForo_Phrase('php_functions_disabled_impossible_check');
  154. }
  155. else if ($disabledFunctions)
  156. {
  157. $functions = preg_split('/,\s*/', $disabledFunctions, -1, PREG_SPLIT_NO_EMPTY);
  158. if (in_array('mail', $functions) || in_array('fsockopen', $functions))
  159. {
  160. $warnings['disabledFunctions'] = new XenForo_Phrase('php_functions_disabled_fundamental');
  161. }
  162. else
  163. {
  164. //$warnings['disabledFunctions'] = new XenForo_Phrase('php_functions_disabled_warning');
  165. }
  166. }
  167.  
  168. if (function_exists('preg_match'))
  169. {
  170. try
  171. {
  172. preg_match('/\p{C}/u', 'x');
  173. }
  174. catch (Exception $e)
  175. {
  176. $warnings['pcre'] = new XenForo_Phrase('pcre_unicode_property_support_missing');
  177. }
  178. }
  179.  
  180. if (!in_array('https', stream_get_wrappers()))
  181. {
  182. if (!function_exists('curl_version') || !defined('CURL_VERSION_SSL'))
  183. {
  184. $warnings['https'] = new XenForo_Phrase('php_no_ssl_support');
  185. }
  186. else
  187. {
  188. $curl = curl_version();
  189. if (!($curl['features'] & CURL_VERSION_SSL))
  190. {
  191. $warnings['https'] = new XenForo_Phrase('php_no_ssl_support');
  192. }
  193. }
  194. }
  195.  
  196. return $warnings;
  197. }
  198.  
  199. public function deleteApplicationTables()
  200. {
  201. $db = $this->_getDb();
  202.  
  203. $removed = array();
  204. foreach ($db->listTables() AS $table)
  205. {
  206. if ($this->isApplicationTable($table))
  207. {
  208. $removed[] = $table;
  209. $db->query('DROP TABLE ' . $table);
  210. }
  211. }
  212.  
  213. return $removed;
  214. }
  215.  
  216. public function hasApplicationTables()
  217. {
  218. $db = $this->_getDb();
  219.  
  220. foreach ($db->listTables() AS $table)
  221. {
  222. if ($this->isApplicationTable($table))
  223. {
  224. return true;
  225. }
  226. }
  227.  
  228. return false;
  229. }
  230.  
  231. public function isApplicationTable($table)
  232. {
  233. return (
  234. substr($table, 0, 3) == 'xf_'
  235. || substr($table, 0, 11) == 'xengallery_'
  236. );
  237. }
  238.  
  239. public function createApplicationTables($maxExecution = 0, $startOffset = 0, &$endOffset = false)
  240. {
  241. $db = $this->_getDb();
  242. $tables = XenForo_Install_Data_MySql::getTables();
  243. $s = microtime(true);
  244. $i = -1;
  245. $endOffset = false;
  246.  
  247. foreach ($tables AS $table)
  248. {
  249. $i++;
  250. if ($i < $startOffset)
  251. {
  252. continue;
  253. }
  254.  
  255. $db->query($table);
  256.  
  257. if ($maxExecution && microtime(true) - $s > $maxExecution)
  258. {
  259. // start at the next one
  260. $endOffset = $i + 1;
  261. break;
  262. }
  263. }
  264.  
  265. return array_keys($tables);
  266. }
  267.  
  268. public function insertDefaultData()
  269. {
  270. $db = $this->_getDb();
  271.  
  272. $insertData = XenForo_Install_Data_MySql::getData();
  273. foreach ($insertData AS $data)
  274. {
  275. $db->query($data);
  276. }
  277.  
  278. return count($data);
  279. }
  280.  
  281. public function createDirectories()
  282. {
  283. $internalDataDir = XenForo_Helper_File::getInternalDataPath();
  284.  
  285. $dirs = array(
  286. $internalDataDir . '/temp',
  287. $internalDataDir . '/page_cache',
  288. );
  289. foreach ($dirs AS $dir)
  290. {
  291. XenForo_Helper_File::createDirectory($dir, true);
  292. }
  293. }
  294.  
  295. public function insertAdministrator(array $data)
  296. {
  297. $password = $data['password'];
  298. $passwordConfirm = $data['password_confirm'];
  299. unset($data['password'], $data['password_confirm']);
  300.  
  301. XenForo_Db::beginTransaction();
  302.  
  303. /* @var $writer XenForo_DataWriter_User */
  304. $writer = XenForo_DataWriter::create('XenForo_DataWriter_User');
  305. $writer->bulkSet($data);
  306. $writer->set('user_group_id', XenForo_Model_User::$defaultRegisteredGroupId);
  307. $writer->set('user_state', 'valid');
  308. $writer->setPassword($password, $passwordConfirm, null, true);
  309. $writer->save();
  310. $user = $writer->getMergedData();
  311.  
  312. $admin = XenForo_DataWriter::create('XenForo_DataWriter_Admin');
  313. $admin->set('user_id', $user['user_id']);
  314. $admin->set('extra_user_group_ids', XenForo_Model_User::$defaultAdminGroupId);
  315. $admin->save();
  316.  
  317. $adminModel = $this->getModelFromCache('XenForo_Model_Admin');
  318. $adminPerms = $adminModel->getAllAdminPermissions();
  319. $adminModel->updateUserAdminPermissions($user['user_id'], array_keys($adminPerms));
  320.  
  321. // insert super mod with all permissions
  322. /* @var $moderatorModel XenForo_Model_Moderator */
  323. $moderatorModel = $this->getModelFromCache('XenForo_Model_Moderator');
  324. $modInterfaceGroupIds = $moderatorModel->getGeneralModeratorInterfaceGroupIds();
  325. $generalInterfaceGroupIds = $modInterfaceGroupIds;
  326. foreach($moderatorModel->getContentModeratorHandlers() AS $handler)
  327. {
  328. $modInterfaceGroupIds = array_merge($modInterfaceGroupIds, $handler->getModeratorInterfaceGroupIds());
  329. }
  330.  
  331. $modPerms = array();
  332. foreach ($moderatorModel->getModeratorPermissions($modInterfaceGroupIds) AS $permGroup => $perms)
  333. {
  334. foreach ($perms AS $permId => $perm)
  335. {
  336. $modPerms[$permGroup][$permId] = 1;
  337. }
  338. }
  339.  
  340. $extra = array(
  341. 'extra_user_group_ids' => XenForo_Model_User::$defaultModeratorGroupId,
  342. 'is_staff' => true
  343. );
  344. $moderatorModel->insertOrUpdateGeneralModerator($user['user_id'], $modPerms, true, $extra);
  345.  
  346. XenForo_Db::commit();
  347.  
  348. return $user;
  349. }
  350.  
  351. public function completeInstallation()
  352. {
  353. $this->writeInstallLock();
  354. $this->_getUpgradeModel()->insertUpgradeLog(null, 'install', 1);
  355. $this->_getUpgradeModel()->updateVersion();
  356.  
  357. $this->getModelFromCache('XenForo_Model_BbCode')->updateBbCodeParseCacheVersion();
  358. }
  359.  
  360. public function writeInstallLock()
  361. {
  362. $fileName = XenForo_Helper_File::getInternalDataPath() .'/install-lock.php';
  363.  
  364. $fp = fopen($fileName, 'w');
  365. fwrite($fp, '<?php header(\'Location: ../index.php\'); /* Installed: ' . date(DATE_RFC822) . ' */');
  366. fclose($fp);
  367.  
  368. XenForo_Helper_File::makeWritableByFtpUser($fileName);
  369. }
  370.  
  371. public function isInstalled()
  372. {
  373. return (
  374. file_exists(XenForo_Helper_File::getInternalDataPath() . '/install-lock.php')
  375. && file_exists(XenForo_Application::getInstance()->getConfigDir() . '/config.php')
  376. );
  377. }
  378.  
  379. public function generateConfig(array $config)
  380. {
  381. $esc = "'\\";
  382.  
  383. $lines = array();
  384. foreach ($config AS $key => $value)
  385. {
  386. if (is_array($value))
  387. {
  388. if (empty($value))
  389. {
  390. continue;
  391. }
  392. foreach ($value AS $subKey => $subValue)
  393. {
  394. $lines[] = '$config[\'' . addcslashes($key, $esc) . '\'][\'' . addcslashes($subKey, $esc) . '\'] = \'' . addcslashes($subValue, $esc) . '\';';
  395. }
  396. $lines[] = '';
  397. }
  398. else
  399. {
  400. $lines[] = '$config[\'' . addcslashes($key, $esc) . '\'] = ' . var_export($value, true) . ';';
  401. }
  402. }
  403.  
  404. // windows line breaks for notepad
  405. return "<?php\r\n\r\n"
  406. . implode("\r\n", $lines)
  407. . "\r\n\r\n" . '$config[\'superAdmins\'] = \'1\';';
  408. }
  409.  
  410. public function insertDeferredRebuild()
  411. {
  412. $rebuilds = array(
  413. 'ImportMasterData', 'Permission',
  414. 'ImportPhrase', 'Phrase',
  415. 'ImportTemplate', 'Template',
  416. 'ImportAdminTemplate', 'AdminTemplate',
  417. 'ImportEmailTemplate', 'EmailTemplate'
  418. );
  419.  
  420. XenForo_Application::defer('Atomic', array('simple' => $rebuilds), 'installUpgradeRebuild', true, null, true);
  421. }
  422.  
  423. /**
  424. * @return XenForo_Install_Model_Upgrade
  425. */
  426. protected function _getUpgradeModel()
  427. {
  428. return $this->getModelFromCache('XenForo_Install_Model_Upgrade');
  429. }
  430. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement