Ejemplo n.º 1
0
 public static function isOwner($path)
 {
     mimport('framework.filesystem.file');
     $tmp = md5(MUserHelper::genRandomPassword(16));
     $ssp = ini_get('session.save_path');
     $jtp = MPATH_SITE . '/tmp';
     // Try to find a writable directory
     $dir = is_writable('/tmp') ? '/tmp' : false;
     $dir = !$dir && is_writable($ssp) ? $ssp : false;
     $dir = !$dir && is_writable($jtp) ? $jtp : false;
     if ($dir) {
         $test = $dir . '/' . $tmp;
         // Create the test file
         $blank = '';
         MFile::write($test, $blank, false);
         // Test ownership
         $return = fileowner($test) == fileowner($path);
         // Delete the test file
         MFile::delete($test);
         return $return;
     }
     return false;
 }
Ejemplo n.º 2
0
 public function deleteLangs()
 {
     # Admin
     $admin_lang_dir = MPATH_WP_CNT . '/miwi/languages/admin';
     if (MFolder::exists($admin_lang_dir)) {
         $lang_folders = MFolder::folders($admin_lang_dir);
         foreach ($lang_folders as $lang_folder) {
             $files = MFolder::files($admin_lang_dir . '/' . $lang_folder);
             foreach ($files as $file) {
                 if (strpos($file, $this->context) !== false) {
                     MFile::delete($admin_lang_dir . '/' . $lang_folder . '/' . $file);
                 }
             }
         }
     }
     # Site
     $site_lang_dir = MPATH_WP_CNT . '/miwi/languages/site';
     if (MFolder::exists($site_lang_dir)) {
         $lang_folders = MFolder::folders($site_lang_dir);
         foreach ($lang_folders as $lang_folder) {
             $files = MFolder::files($site_lang_dir . '/' . $lang_folder);
             foreach ($files as $file) {
                 if (strpos($file, $this->context) !== false) {
                     MFile::delete($site_lang_dir . '/' . $lang_folder . '/' . $file);
                 }
             }
         }
     }
 }
Ejemplo n.º 3
0
 public static function delete($path)
 {
     @set_time_limit(ini_get('max_execution_time'));
     // Sanity check
     if (!$path) {
         // Bad programmer! Bad Bad programmer!
         MError::raiseWarning(500, __METHOD__ . ': ' . MText::_('MLIB_FILESYSTEM_ERROR_DELETE_BASE_DIRECTORY'));
         return false;
     }
     // Initialise variables.
     $FTPOptions = MClientHelper::getCredentials('ftp');
     try {
         // Check to make sure the path valid and clean
         $path = MPath::clean($path);
     } catch (UnexpectedValueException $e) {
         throw new UnexpectedValueException($e);
     }
     // Is this really a folder?
     if (!is_dir($path)) {
         MError::raiseWarning(21, MText::sprintf('MLIB_FILESYSTEM_ERROR_PATH_IS_NOT_A_FOLDER', $path));
         return false;
     }
     // Remove all the files in folder if they exist; disable all filtering
     $files = self::files($path, '.', false, true, array(), array());
     if (!empty($files)) {
         mimport('framework.filesystem.file');
         if (MFile::delete($files) !== true) {
             // MFile::delete throws an error
             return false;
         }
     }
     // Remove sub-folders of folder; disable all filtering
     $folders = self::folders($path, '.', false, true, array(), array());
     foreach ($folders as $folder) {
         if (is_link($folder)) {
             // Don't descend into linked directories, just delete the link.
             mimport('framework.filesystem.file');
             if (MFile::delete($folder) !== true) {
                 // MFile::delete throws an error
                 return false;
             }
         } elseif (self::delete($folder) !== true) {
             // MFolder::delete throws an error
             return false;
         }
     }
     if ($FTPOptions['enabled'] == 1) {
         // Connect the FTP client
         mimport('framework.client.ftp');
         $ftp = MFTP::getInstance($FTPOptions['host'], $FTPOptions['port'], null, $FTPOptions['user'], $FTPOptions['pass']);
     }
     // In case of restricted permissions we zap it one way or the other
     // as long as the owner is either the webserver or the ftp.
     if (@rmdir($path)) {
         $ret = true;
     } elseif ($FTPOptions['enabled'] == 1) {
         // Translate path and delete
         $path = MPath::clean(str_replace(MPATH_ROOT, $FTPOptions['root'], $path), '/');
         // FTP connector throws an error
         $ret = $ftp->delete($path);
     } else {
         MError::raiseWarning('SOME_ERROR_CODE', MText::sprintf('MLIB_FILESYSTEM_ERROR_FOLDER_DELETE', $path));
         $ret = false;
     }
     return $ret;
 }