Overview

Packages

  • Core
    • Authentication
    • Backend
    • Cache
    • CEC
    • Chain
    • ContentType
    • Database
    • Datatype
    • Debug
    • Exception
    • Frontend
      • Search
      • URI
      • Util
    • GenericDB
      • Model
    • GUI
      • HTML
    • I18N
    • LayoutHandler
    • Log
    • Security
    • Session
    • Util
    • Validation
    • Versioning
    • XML
  • Module
    • ContentSitemapHtml
    • ContentSitemapXml
    • ContentUserForum
    • NavigationTop
  • mpAutoloaderClassMap
  • None
  • Plugin
    • ContentAllocation
    • CronjobOverview
    • FormAssistant
    • FrontendLogic
    • FrontendUsers
    • Linkchecker
    • ModRewrite
    • Newsletter
    • Repository
      • FrontendNavigation
      • KeywordDensity
    • SearchSolr
    • SmartyWrapper
    • UrlShortener
    • UserForum
    • Workflow
  • PluginManager
  • Setup
    • Form
    • GUI
    • Helper
      • Environment
      • Filesystem
      • MySQL
      • PHP
    • UpgradeJob

Functions

  • canWriteDir
  • canWriteFile
  • checkOpenBasedirCompatibility
  • getFileInfo
  • predictCorrectFilepermissions
  • Overview
  • Package
  • Function
  • Tree
  • Deprecated
  • Todo
  1: <?php
  2: /**
  3:  * This file contains various helper functions to read specific values needed for setup checks.
  4:  *
  5:  * @package    Setup
  6:  * @subpackage Helper_Filesystem
  7:  * @version    SVN Revision $Rev:$
  8:  *
  9:  * @author     Unknown
 10:  * @copyright  four for business AG <www.4fb.de>
 11:  * @license    http://www.contenido.org/license/LIZENZ.txt
 12:  * @link       http://www.4fb.de
 13:  * @link       http://www.contenido.org
 14:  */
 15: 
 16: defined('CON_FRAMEWORK') || die('Illegal call: Missing framework initialization - request aborted.');
 17: 
 18: define('CON_PREDICT_SUFFICIENT', 1);
 19: 
 20: define('CON_PREDICT_NOTPREDICTABLE', 2);
 21: 
 22: define('CON_PREDICT_CHANGEPERM_SAMEOWNER', 3);
 23: 
 24: define('CON_PREDICT_CHANGEPERM_SAMEGROUP', 4);
 25: 
 26: define('CON_PREDICT_CHANGEPERM_OTHERS', 5);
 27: 
 28: define('CON_PREDICT_CHANGEUSER', 6);
 29: 
 30: define('CON_PREDICT_CHANGEGROUP', 7);
 31: 
 32: define('CON_PREDICT_WINDOWS', 8);
 33: 
 34: define('CON_BASEDIR_NORESTRICTION', 1);
 35: 
 36: define('CON_BASEDIR_DOTRESTRICTION', 2);
 37: 
 38: define('CON_BASEDIR_RESTRICTIONSUFFICIENT', 3);
 39: 
 40: define('CON_BASEDIR_INCOMPATIBLE', 4);
 41: 
 42: function canWriteFile($filename) {
 43:     clearstatcache();
 44:     if (is_file($filename)) {
 45:         return is_writable($filename);
 46:     } else {
 47:         return is_writable(dirname($filename));
 48:     }
 49: }
 50: 
 51: function canWriteDir($dirname) {
 52:     clearstatcache();
 53:     return is_dir($dirname) && is_writable($dirname);
 54: }
 55: 
 56: function getFileInfo($sFilename) {
 57:     if (!cFileHandler::exists($sFilename)) {
 58:         return false;
 59:     }
 60: 
 61:     $oiFilePermissions = fileperms($sFilename);
 62:     if ($oiFilePermissions === false) {
 63:         return false;
 64:     }
 65: 
 66:     switch (true) {
 67:         case (($oiFilePermissions & 0xC000) == 0xC000):
 68:             $info = 's';
 69:             $type = "socket";
 70:             break;
 71:         case (($oiFilePermissions & 0xA000) == 0xA000):
 72:             $info = 'l';
 73:             $type = "symbolic link";
 74:             break;
 75:         case (($oiFilePermissions & 0x8000) == 0x8000):
 76:             $info = '-';
 77:             $type = "regular file";
 78:             break;
 79:         case (($oiFilePermissions & 0x6000) == 0x6000):
 80:             $info = 'b';
 81:             $type = "block special";
 82:             break;
 83:         case (($oiFilePermissions & 0x4000) == 0x4000):
 84:             $info = 'd';
 85:             $type = "directory";
 86:             break;
 87:         case (($oiFilePermissions & 0x2000) == 0x2000):
 88:             $info = 'c';
 89:             $type = "character special";
 90:             break;
 91:         case (($oiFilePermissions & 0x1000) == 0x1000):
 92:             $info = 'p';
 93:             $type = "FIFO pipe";
 94:             break;
 95:         default:
 96:             $info = "u";
 97:             $type = "Unknown";
 98:             break;
 99:     }
100: 
101:     $aFileinfo = array();
102:     $aFileinfo["info"] = $info;
103:     $aFileinfo["type"] = $type;
104:     $aFileinfo["owner"]["read"] = ($oiFilePermissions & 0x0100) ? true : false;
105:     $aFileinfo["owner"]["write"] = ($oiFilePermissions & 0x0080) ? true : false;
106:     $aFileinfo["group"]["read"] = ($oiFilePermissions & 0x0020) ? true : false;
107:     $aFileinfo["group"]["write"] = ($oiFilePermissions & 0x0010) ? true : false;
108:     $aFileinfo["others"]["read"] = ($oiFilePermissions & 0x0004) ? true : false;
109:     $aFileinfo["others"]["write"] = ($oiFilePermissions & 0x0002) ? true : false;
110:     $aFileinfo["owner"]["id"] = fileowner($sFilename);
111:     $aFileinfo["group"]["id"] = filegroup($sFilename);
112:     return ($aFileinfo);
113: }
114: 
115: function checkOpenBasedirCompatibility() {
116:     $value = getPHPIniSetting("open_basedir");
117: 
118:     if (isWindows()) {
119:         $aBasedirEntries = explode(";", $value);
120:     } else {
121:         $aBasedirEntries = explode(":", $value);
122:     }
123: 
124:     if (count($aBasedirEntries) == 1 && $aBasedirEntries[0] == $value) {
125:         return CON_BASEDIR_NORESTRICTION;
126:     }
127: 
128:     if (in_array(".", $aBasedirEntries) && count($aBasedirEntries) == 1) {
129:         return CON_BASEDIR_DOTRESTRICTION;
130:     }
131: 
132:     $sCurrentDirectory = getcwd();
133: 
134:     foreach ($aBasedirEntries as $entry) {
135:         if (stristr($sCurrentDirectory, $entry)) {
136:             return CON_BASEDIR_RESTRICTIONSUFFICIENT;
137:         }
138:     }
139: 
140:     return CON_BASEDIR_INCOMPATIBLE;
141: }
142: 
143: function predictCorrectFilepermissions($file) {
144:     // Check if the system is a windows system. If yes, we can't predict
145:     // anything.
146:     if (isWindows()) {
147:         return CON_PREDICT_WINDOWS;
148:     }
149: 
150:     // Check if the file is read- and writeable. If yes, we don't need to do any
151:     // further checks.
152:     if (is_writable($file) && is_readable($file)) {
153:         return CON_PREDICT_SUFFICIENT;
154:     }
155: 
156:     // If we can't find out the web server UID, we cannot predict the correct
157:     // mask.
158:     $iServerUID = getServerUID();
159:     if ($iServerUID === false) {
160:         return CON_PREDICT_NOTPREDICTABLE;
161:     }
162: 
163:     // If we can't find out the web server GID, we cannot predict the correct
164:     // mask.
165:     $iServerGID = getServerGID();
166:     if ($iServerGID === false) {
167:         return CON_PREDICT_NOTPREDICTABLE;
168:     }
169: 
170:     $aFilePermissions = getFileInfo($file);
171: 
172:     if (getSafeModeStatus()) {
173:         // SAFE-Mode related checks
174:         if ($iServerUID == $aFilePermissions["owner"]["id"]) {
175:             return CON_PREDICT_CHANGEPERM_SAMEOWNER;
176:         }
177: 
178:         if (getSafeModeGidStatus()) {
179:             // SAFE-Mode GID related checks
180:             if ($iServerGID == $aFilePermissions["group"]["id"]) {
181:                 return CON_PREDICT_CHANGEPERM_SAMEGROUP;
182:             }
183: 
184:             return CON_PREDICT_CHANGEGROUP;
185:         }
186:     } else {
187:         // Regular checks
188:         if ($iServerUID == $aFilePermissions["owner"]["id"]) {
189:             return CON_PREDICT_CHANGEPERM_SAMEOWNER;
190:         }
191: 
192:         if ($iServerGID == $aFilePermissions["group"]["id"]) {
193:             return CON_PREDICT_CHANGEPERM_SAMEGROUP;
194:         }
195: 
196:         return CON_PREDICT_CHANGEPERM_OTHERS;
197:     }
198: }
CMS CONTENIDO 4.9.3 API documentation generated by ApiGen 2.8.0