/** * function will chmod dirs and files recursively * @param type $start_dir * @param type $debug (set false if you don't want the function to echo) * http://www.os-cms.net/blog/view/27/recursive-chmod-files-with-php * // settings $start_dir = '/home/dennis/www/default'; $files = chmod_recursive($start_dir); */ function chmod_recursive($start_dir, $debug = true) { $dir_perms = 0755; $file_perms = 0644; $str = ""; $files = array(); if (is_dir($start_dir)) { $fh = opendir($start_dir); while (($file = readdir($fh)) !== false) { // skip hidden files and dirs and recursing if necessary if (strpos($file, '.') === 0) { continue; } $filepath = $start_dir . '/' . $file; if (is_dir($filepath)) { //$newname = sanitize_file_name($filepath); echo $str = "chmod {$filepath} To {$dir_perms}\n"; chmod($filepath, $dir_perms); chmod_recursive($filepath); } else { ////$newname = sanitize_file_name($filepath); echo $str = "chmod {$filepath} tp {$file_perms}\n"; chmod($filepath, $file_perms); } } closedir($fh); } if ($debug) { echo $str; } }
function chmod_recursive($path, $mode) { umask(00); if (!is_dir($path)) { return chmod($path, $mode); } $dh = opendir($path); while ($file = readdir($dh)) { if ($file != '.' && $file != '..') { $fullpath = $path . '/' . $file; if (!is_dir($fullpath)) { if (!chmod($fullpath, $mode)) { return false; } else { if (!chmod_recursive($fullpath, $mode)) { return false; } } } } } closedir($dh); if (chmod($path, $mode)) { return true; } return false; }
function chmodRecursive($item, $mode) { if (nx_isFTPMode()) { return $GLOBALS['FTPCONNECTION']->chmodRecursive($item, $mode); } else { chmod_recursive($item, $mode); } }
function chmodRecursive($item, $mode) { if (ext_isFTPMode()) { return $GLOBALS['FTPCONNECTION']->chmodRecursive($item, $mode); } else { return chmod_recursive(ext_TextEncoding::fromUTF8($item), $mode); } }
function chmodRecursive($item, $mode) { if (ext_isFTPMode()) { return $GLOBALS['FTPCONNECTION']->chmodRecursive($item, $mode); } else { return chmod_recursive(utf8_decode($item), $mode); } }
function chmodRecursive($item, $mode) { if (ext_isFTPMode()) { return $GLOBALS['FTPCONNECTION']->chmodRecursive($item, $mode); } else { if ($GLOBALS['use_mb']) { if (mb_detect_encoding($item) == 'ASCII') { return chmod_recursive(utf8_decode($item), $mode); } else { return chmod_recursive($item, $mode); } } else { return chmod_recursive(utf8_decode($item), $mode); } } }
/** * Requires the entry from $_FILES of a zip file. */ public static function install($source) { try { Zipper::unzip($source['tmp_name']); } catch (Exception $e) { self::$error = $e->getMessage(); return false; } $folder = Zipper::find_folder($source['name']); // Get config and verify it if (!file_exists($folder . '/elefant.json')) { self::$error = __('Verification failed: No configuration file found.'); return false; } $conf = json_decode(file_get_contents($folder . '/elefant.json')); if ($conf === false) { self::$error = __('Verification failed: Invalid configuration file.'); return false; } if (!self::verify($conf)) { // self::$error already set by verify() return false; } // Move files over if ($conf->type === 'app') { if (!rename($folder, 'apps/' . $conf->folder)) { self::$error = __('Unable to write to apps folder.'); return false; } chmod_recursive('apps/' . $conf->folder, 0777); } else { if (!rename($folder, 'layouts/' . $conf->folder)) { self::$error = __('Unable to write to layouts folder.'); } chmod_recursive('layouts/' . $conf->folder, 0777); } // Remove the original zip file @unlink($source['tmp_name']); return $conf; }
function chmod_recursive($item, $mode) { // chmod file / dir $ok = true; if (@is_link($item) || @is_file($item)) { $ok = @chmod($item, $mode); if ($ok) { ext_Result::add_message($GLOBALS['messages']['permchange'] . ' ' . $new_item); } else { ext_Result::add_error($GLOBALS['error_msg']['permchange'] . ' ' . $new_item); } } elseif (@is_dir($item)) { if (($handle = @opendir($item)) === false) { ext_Result::add_error(basename($item) . ": " . $GLOBALS["error_msg"]["opendir"]); return false; } while (($file = readdir($handle)) !== false) { if ($file == ".." || $file == ".") { continue; } $new_item = $item . "/" . $file; if (!@file_exists($new_item)) { ext_Result::add_error(basename($item) . ": " . $GLOBALS["error_msg"]["readdir"]); continue; } //if(!get_show_item($item, $new_item)) continue; if (@is_dir($new_item)) { $ok = chmod_recursive($new_item, $mode); } else { $ok = @chmod($new_item, $mode); if ($ok) { ext_Result::add_message($GLOBALS['messages']['permchange'] . ' ' . $new_item); } else { ext_Result::add_error($GLOBALS['error_msg']['permchange'] . ' ' . $new_item); } } } closedir($handle); if (@is_dir($item)) { $bin = decbin($mode); // when we chmod a directory we must care for the permissions // to prevent that the directory becomes not readable (when the "execute bits" are removed) $bin = substr_replace($bin, '1', 2, 1); // set 1st x bit to 1 $bin = substr_replace($bin, '1', 5, 1); // set 2nd x bit to 1 $bin = substr_replace($bin, '1', 8, 1); // set 3rd x bit to 1 $mode = bindec($bin); } $ok = @chmod($item, $mode); if ($ok) { ext_Result::add_message($GLOBALS['messages']['permchange'] . ' ' . $item); } else { ext_Result::add_error($GLOBALS['error_msg']['permchange'] . ' ' . $item); } } return $ok; }
/** * Optimizes the index after adding documents. */ function optimize() { @chmod_recursive($this->path, 0777); return $this->client->optimize(); }
/** * Requires the Github reponsitory link (e.g., git://github.com/user/project.git). */ public static function install($source) { list($user, $project) = github_parse_url($source); $github = new GithubFetcher($user, $project); $tree = $github->tree(); // Get config and verify it $found = false; $conf = false; foreach ($tree as $item) { if ($item->path === 'elefant.json') { $data = $github->get($item); if (!$data) { self::$error = i18n_get('Unable to fetch configuration file.'); return false; } $conf = json_decode($data); if (!$conf) { self::$error = i18n_get('Verification failed: Invalid configuration file.'); return false; } if (!self::verify($conf)) { // self::$error already set by verify() return false; } $found = true; break; } } if (!$found) { self::$error = i18n_get('Configuration file not found.'); return false; } // Create new install folder if ($conf->type === 'app') { $dest = 'apps/' . $conf->folder; if (!mkdir($dest)) { self::$error = i18n_get('Unable to write to apps folder.'); return false; } } else { $dest = 'layouts/' . $conf->folder; if (!mkdir($dest)) { self::$error = i18n_get('Unable to write to layouts folder.'); return false; } } // This may take some time for larger apps set_time_limit(120); // Build files from tree foreach ($tree as $n => $item) { if ($item->type === 'tree') { mkdir($dest . '/' . $item->path); } else { $data = $github->get($item); if ($data === false) { self::$error = i18n_get('Unable to fetch file') . ' ' . $item->path; rmdir_recursive($dest); return false; } file_put_contents($dest . '/' . $item->path, $data); // Create our own rate-limiting to be nice with Github $data = null; if ($n % 20 === 0) { sleep(1); } } } chmod_recursive($dest, 0777); return $conf; }
} else { $body = extractor_run($f); if (!$body) { $body = ''; } $description = ''; $keywords = ''; $title = basename($f); } $data = array('title' => $title, 'url' => $url, 'description' => $description, 'keywords' => $keywords, 'body' => $body, 'access' => 'public', 'status' => 'approved', 'team' => 'none', 'ctype' => $ctype, 'mtime' => (string) $mtime, 'domain' => $domain); // add file to index $counts[$ctype]++; $res = $search->addDocument($data); if (!$res) { echo 'Error adding document: ' . $search->error . NEWLINE; echo 'Document URL: ' . $data['url'] . NEWLINE; return; } } if ($info['type'] == 'site') { Dir::rmdirRecursive('tmp'); $search->deleteExpired((string) $mtime - 1, $info['domain']); } } } $search->deleteExpired((string) $mtime - 1, $default_domain); @chmod_recursive($search->path, 0777); $etime = time(); // log our activities for big brother $logger = new SiteSearchLogger(); $logger->logIndex($mtime, $etime, $counts);