PageRenderTime 43ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/184.168.182.1/admin/old/ckfinder/core/connector/php/php5/Core/Config.php

https://gitlab.com/endomorphosis/falkenstein
PHP | 557 lines | 229 code | 40 blank | 288 comment | 37 complexity | e66cce7b5b2996a2aeb80266e49d4669 MD5 | raw file
  1. <?php
  2. /*
  3. * CKFinder
  4. * ========
  5. * http://ckfinder.com
  6. * Copyright (C) 2007-2012, CKSource - Frederico Knabben. All rights reserved.
  7. *
  8. * The software, this file and its contents are subject to the CKFinder
  9. * License. Please read the license.txt file before using, installing, copying,
  10. * modifying or distribute this file or part of its contents. The contents of
  11. * this file is part of the Source Code of CKFinder.
  12. */
  13. if (!defined('IN_CKFINDER')) exit;
  14. /**
  15. * @package CKFinder
  16. * @subpackage Config
  17. * @copyright CKSource - Frederico Knabben
  18. */
  19. /**
  20. * Include access control config class
  21. */
  22. require_once CKFINDER_CONNECTOR_LIB_DIR . "/Core/AccessControlConfig.php";
  23. /**
  24. * Include resource type config class
  25. */
  26. require_once CKFINDER_CONNECTOR_LIB_DIR . "/Core/ResourceTypeConfig.php";
  27. /**
  28. * Include thumbnails config class
  29. */
  30. require_once CKFINDER_CONNECTOR_LIB_DIR . "/Core/ThumbnailsConfig.php";
  31. /**
  32. * Include images config class
  33. */
  34. require_once CKFINDER_CONNECTOR_LIB_DIR . "/Core/ImagesConfig.php";
  35. /**
  36. * Main config parser
  37. *
  38. *
  39. * @package CKFinder
  40. * @subpackage Config
  41. * @copyright CKSource - Frederico Knabben
  42. * @global string $GLOBALS['config']
  43. */
  44. class CKFinder_Connector_Core_Config
  45. {
  46. /**
  47. * Is CKFinder enabled
  48. *
  49. * @var boolean
  50. * @access private
  51. */
  52. private $_isEnabled = false;
  53. /**
  54. * License Name
  55. *
  56. * @var string
  57. * @access private
  58. */
  59. private $_licenseName = "";
  60. /**
  61. * License Key
  62. *
  63. * @var string
  64. * @access private
  65. */
  66. private $_licenseKey = "";
  67. /**
  68. * Role session variable name
  69. *
  70. * @var string
  71. * @access private
  72. */
  73. private $_roleSessionVar = "CKFinder_UserRole";
  74. /**
  75. * Access Control Configuration
  76. *
  77. * @var CKFinder_Connector_Core_AccessControlConfig
  78. * @access private
  79. */
  80. private $_accessControlConfigCache;
  81. /**
  82. * ResourceType config cache
  83. *
  84. * @var array
  85. * @access private
  86. */
  87. private $_resourceTypeConfigCache = array();
  88. /**
  89. * Thumbnails config cache
  90. *
  91. * @var CKFinder_Connector_Core_ThumbnailsConfig
  92. * @access private
  93. */
  94. private $_thumbnailsConfigCache;
  95. /**
  96. * Images config cache
  97. *
  98. * @var CKFinder_Connector_Core_ImagesConfig
  99. * @access private
  100. */
  101. private $_imagesConfigCache;
  102. /**
  103. * Array with default resource types names
  104. *
  105. * @access private
  106. * @var array
  107. */
  108. private $_defaultResourceTypes = array();
  109. /**
  110. * Filesystem encoding
  111. *
  112. * @var string
  113. * @access private
  114. */
  115. private $_filesystemEncoding;
  116. /**
  117. * Check double extension
  118. *
  119. * @var boolean
  120. * @access private
  121. */
  122. private $_checkDoubleExtension = true;
  123. /**
  124. * Disallow unsafe characters in file and folder names
  125. *
  126. * @var boolean
  127. * @access private
  128. */
  129. private $_disallowUnsafeCharacters = false;
  130. /**
  131. * If set to true, validate image size
  132. *
  133. * @var boolean
  134. * @access private
  135. */
  136. private $_secureImageUploads = true;
  137. /**
  138. * Check file size after scaling images (applies to images only)
  139. *
  140. * @var boolean
  141. */
  142. private $_checkSizeAfterScaling = true;
  143. /**
  144. * For security, HTML is allowed in the first Kb of data for files having the following extensions only
  145. *
  146. * @var array
  147. * @access private
  148. */
  149. private $_htmlExtensions = array('html', 'htm', 'xml', 'xsd', 'txt', 'js');
  150. /**
  151. * Chmod files after upload to the following permission
  152. *
  153. * @var integer
  154. * @access private
  155. */
  156. private $_chmodFiles = 0777;
  157. /**
  158. * Chmod directories after creation
  159. *
  160. * @var integer
  161. * @access private
  162. */
  163. private $_chmodFolders = 0755;
  164. /**
  165. * Hide folders
  166. *
  167. * @var array
  168. * @access private
  169. */
  170. private $_hideFolders = array(".svn", "CVS");
  171. /**
  172. * Hide files
  173. *
  174. * @var integer
  175. * @access private
  176. */
  177. private $_hideFiles = array(".*");
  178. /**
  179. * If set to true, force ASCII names
  180. *
  181. * @var boolean
  182. * @access private
  183. */
  184. private $_forceAscii = false;
  185. function __construct()
  186. {
  187. $this->loadValues();
  188. }
  189. /**
  190. * Get file system encoding, returns null if encoding is not set
  191. *
  192. * @access public
  193. * @return string
  194. */
  195. public function getFilesystemEncoding()
  196. {
  197. return $this->_filesystemEncoding;
  198. }
  199. /**
  200. * Get "secureImageUploads" value
  201. *
  202. * @access public
  203. * @return boolean
  204. */
  205. public function getSecureImageUploads()
  206. {
  207. return $this->_secureImageUploads;
  208. }
  209. /**
  210. * Get "checkSizeAfterScaling" value
  211. *
  212. * @access public
  213. * @return boolean
  214. */
  215. public function checkSizeAfterScaling()
  216. {
  217. return $this->_checkSizeAfterScaling;
  218. }
  219. /**
  220. * Get "htmlExtensions" value
  221. *
  222. * @access public
  223. * @return array
  224. */
  225. public function getHtmlExtensions()
  226. {
  227. return $this->_htmlExtensions;
  228. }
  229. /**
  230. * Get "forceAscii" value
  231. *
  232. * @access public
  233. * @return array
  234. */
  235. public function forceAscii()
  236. {
  237. return $this->_forceAscii;
  238. }
  239. /**
  240. * Get regular expression to hide folders
  241. *
  242. * @access public
  243. * @return array
  244. */
  245. public function getHideFoldersRegex()
  246. {
  247. static $folderRegex;
  248. if (!isset($folderRegex)) {
  249. if (is_array($this->_hideFolders) && $this->_hideFolders) {
  250. $folderRegex = join("|", $this->_hideFolders);
  251. $folderRegex = strtr($folderRegex, array("?" => "__QMK__", "*" => "__AST__", "|" => "__PIP__"));
  252. $folderRegex = preg_quote($folderRegex, "/");
  253. $folderRegex = strtr($folderRegex, array("__QMK__" => ".", "__AST__" => ".*", "__PIP__" => "|"));
  254. $folderRegex = "/^(?:" . $folderRegex . ")$/uim";
  255. }
  256. else {
  257. $folderRegex = "";
  258. }
  259. }
  260. return $folderRegex;
  261. }
  262. /**
  263. * Get regular expression to hide files
  264. *
  265. * @access public
  266. * @return array
  267. */
  268. public function getHideFilesRegex()
  269. {
  270. static $fileRegex;
  271. if (!isset($fileRegex)) {
  272. if (is_array($this->_hideFiles) && $this->_hideFiles) {
  273. $fileRegex = join("|", $this->_hideFiles);
  274. $fileRegex = strtr($fileRegex, array("?" => "__QMK__", "*" => "__AST__", "|" => "__PIP__"));
  275. $fileRegex = preg_quote($fileRegex, "/");
  276. $fileRegex = strtr($fileRegex, array("__QMK__" => ".", "__AST__" => ".*", "__PIP__" => "|"));
  277. $fileRegex = "/^(?:" . $fileRegex . ")$/uim";
  278. }
  279. else {
  280. $fileRegex = "";
  281. }
  282. }
  283. return $fileRegex;
  284. }
  285. /**
  286. * Get "Check double extension" value
  287. *
  288. * @access public
  289. * @return boolean
  290. */
  291. public function getCheckDoubleExtension()
  292. {
  293. return $this->_checkDoubleExtension;
  294. }
  295. /**
  296. * Get "Disallow unsafe characters" value
  297. *
  298. * @access public
  299. * @return boolean
  300. */
  301. public function getDisallowUnsafeCharacters()
  302. {
  303. return $this->_disallowUnsafeCharacters;
  304. }
  305. /**
  306. * Get default resource types
  307. *
  308. * @access public
  309. * @return array()
  310. */
  311. public function getDefaultResourceTypes()
  312. {
  313. return $this->_defaultResourceTypes;
  314. }
  315. /**
  316. * Is CKFinder enabled
  317. *
  318. * @access public
  319. * @return boolean
  320. */
  321. public function getIsEnabled()
  322. {
  323. return $this->_isEnabled;
  324. }
  325. /**
  326. * Get license key
  327. *
  328. * @access public
  329. * @return string
  330. */
  331. public function getLicenseKey()
  332. {
  333. return $this->_licenseKey;
  334. }
  335. /**
  336. * Get license name
  337. *
  338. * @access public
  339. * @return string
  340. */
  341. public function getLicenseName()
  342. {
  343. return $this->_licenseName;
  344. }
  345. /**
  346. * Get chmod settings for uploaded files
  347. *
  348. * @access public
  349. * @return integer
  350. */
  351. public function getChmodFiles()
  352. {
  353. return $this->_chmodFiles;
  354. }
  355. /**
  356. * Get chmod settings for created directories
  357. *
  358. * @access public
  359. * @return integer
  360. */
  361. public function getChmodFolders()
  362. {
  363. return $this->_chmodFolders;
  364. }
  365. /**
  366. * Get role sesion variable name
  367. *
  368. * @access public
  369. * @return string
  370. */
  371. public function getRoleSessionVar()
  372. {
  373. return $this->_roleSessionVar;
  374. }
  375. /**
  376. * Get resourceTypeName config
  377. *
  378. * @param string $resourceTypeName
  379. * @return CKFinder_Connector_Core_ResourceTypeConfig|null
  380. * @access public
  381. */
  382. public function &getResourceTypeConfig($resourceTypeName)
  383. {
  384. $_null = null;
  385. if (isset($this->_resourceTypeConfigCache[$resourceTypeName])) {
  386. return $this->_resourceTypeConfigCache[$resourceTypeName];
  387. }
  388. if (!isset($GLOBALS['config']['ResourceType']) || !is_array($GLOBALS['config']['ResourceType'])) {
  389. return $_null;
  390. }
  391. reset($GLOBALS['config']['ResourceType']);
  392. while (list($_key,$_resourceTypeNode) = each($GLOBALS['config']['ResourceType'])) {
  393. if ($_resourceTypeNode['name'] === $resourceTypeName) {
  394. $this->_resourceTypeConfigCache[$resourceTypeName] = new CKFinder_Connector_Core_ResourceTypeConfig($_resourceTypeNode);
  395. return $this->_resourceTypeConfigCache[$resourceTypeName];
  396. }
  397. }
  398. return $_null;
  399. }
  400. /**
  401. * Get thumbnails config
  402. *
  403. * @access public
  404. * @return CKFinder_Connector_Core_ThumbnailsConfig
  405. */
  406. public function &getThumbnailsConfig()
  407. {
  408. if (!isset($this->_thumbnailsConfigCache)) {
  409. $this->_thumbnailsConfigCache = new CKFinder_Connector_Core_ThumbnailsConfig(isset($GLOBALS['config']['Thumbnails']) ? $GLOBALS['config']['Thumbnails'] : array());
  410. }
  411. return $this->_thumbnailsConfigCache;
  412. }
  413. /**
  414. * Get images config
  415. *
  416. * @access public
  417. * @return CKFinder_Connector_Core_ImagesConfig
  418. */
  419. public function &getImagesConfig()
  420. {
  421. if (!isset($this->_imagesConfigCache)) {
  422. $this->_imagesConfigCache = new CKFinder_Connector_Core_ImagesConfig(isset($GLOBALS['config']['Images']) ? $GLOBALS['config']['Images'] : array());
  423. }
  424. return $this->_imagesConfigCache;
  425. }
  426. /**
  427. * Get access control config
  428. *
  429. * @access public
  430. * @return CKFinder_Connector_Core_AccessControlConfig
  431. */
  432. public function &getAccessControlConfig()
  433. {
  434. if (!isset($this->_accessControlConfigCache)) {
  435. $this->_accessControlConfigCache = new CKFinder_Connector_Core_AccessControlConfig(isset($GLOBALS['config']['AccessControl']) ? $GLOBALS['config']['AccessControl'] : array());
  436. }
  437. return $this->_accessControlConfigCache;
  438. }
  439. /**
  440. * Load values from config
  441. *
  442. * @access private
  443. */
  444. private function loadValues()
  445. {
  446. if (function_exists('CheckAuthentication')) {
  447. $this->_isEnabled = CheckAuthentication();
  448. }
  449. if (isset($GLOBALS['config']['LicenseName'])) {
  450. $this->_licenseName = (string)$GLOBALS['config']['LicenseName'];
  451. }
  452. if (isset($GLOBALS['config']['LicenseKey'])) {
  453. $this->_licenseKey = (string)$GLOBALS['config']['LicenseKey'];
  454. }
  455. if (isset($GLOBALS['config']['FilesystemEncoding'])) {
  456. $this->_filesystemEncoding = (string)$GLOBALS['config']['FilesystemEncoding'];
  457. }
  458. if (isset($GLOBALS['config']['RoleSessionVar'])) {
  459. $this->_roleSessionVar = (string)$GLOBALS['config']['RoleSessionVar'];
  460. }
  461. if (isset($GLOBALS['config']['CheckDoubleExtension'])) {
  462. $this->_checkDoubleExtension = CKFinder_Connector_Utils_Misc::booleanValue($GLOBALS['config']['CheckDoubleExtension']);
  463. }
  464. if (isset($GLOBALS['config']['DisallowUnsafeCharacters'])) {
  465. $this->_disallowUnsafeCharacters = CKFinder_Connector_Utils_Misc::booleanValue($GLOBALS['config']['DisallowUnsafeCharacters']);
  466. }
  467. if (isset($GLOBALS['config']['SecureImageUploads'])) {
  468. $this->_secureImageUploads = CKFinder_Connector_Utils_Misc::booleanValue($GLOBALS['config']['SecureImageUploads']);
  469. }
  470. if (isset($GLOBALS['config']['CheckSizeAfterScaling'])) {
  471. $this->_checkSizeAfterScaling = CKFinder_Connector_Utils_Misc::booleanValue($GLOBALS['config']['CheckSizeAfterScaling']);
  472. }
  473. if (isset($GLOBALS['config']['ForceAscii'])) {
  474. $this->_forceAscii = CKFinder_Connector_Utils_Misc::booleanValue($GLOBALS['config']['ForceAscii']);
  475. }
  476. if (isset($GLOBALS['config']['HtmlExtensions'])) {
  477. $this->_htmlExtensions = (array)$GLOBALS['config']['HtmlExtensions'];
  478. }
  479. if (isset($GLOBALS['config']['HideFolders'])) {
  480. $this->_hideFolders = (array)$GLOBALS['config']['HideFolders'];
  481. }
  482. if (isset($GLOBALS['config']['HideFiles'])) {
  483. $this->_hideFiles = (array)$GLOBALS['config']['HideFiles'];
  484. }
  485. if (isset($GLOBALS['config']['ChmodFiles'])) {
  486. $this->_chmodFiles = $GLOBALS['config']['ChmodFiles'];
  487. }
  488. if (isset($GLOBALS['config']['ChmodFolders'])) {
  489. $this->_chmodFolders = $GLOBALS['config']['ChmodFolders'];
  490. }
  491. if (isset($GLOBALS['config']['DefaultResourceTypes'])) {
  492. $_defaultResourceTypes = (string)$GLOBALS['config']['DefaultResourceTypes'];
  493. if (strlen($_defaultResourceTypes)) {
  494. $this->_defaultResourceTypes = explode(",", $_defaultResourceTypes);
  495. }
  496. }
  497. }
  498. /**
  499. * Get all resource type names defined in config
  500. *
  501. * @return array
  502. * @access public
  503. */
  504. public function getResourceTypeNames()
  505. {
  506. if (!isset($GLOBALS['config']['ResourceType']) || !is_array($GLOBALS['config']['ResourceType'])) {
  507. return array();
  508. }
  509. $_names = array();
  510. foreach ($GLOBALS['config']['ResourceType'] as $key => $_resourceType) {
  511. if (isset($_resourceType['name'])) {
  512. $_names[] = (string)$_resourceType['name'];
  513. }
  514. }
  515. return $_names;
  516. }
  517. }