Example #1
5
function do_create()
{
    global $context, $create_path, $txt, $sourcedir, $boardurl;
    if (!file_exists($create_path)) {
        @mkdir($create_path);
    }
    if (!file_exists($create_path) || !is_writable($create_path)) {
        fatal_error($txt['path_not_writable'], false);
    }
    $context['clean_name'] = htmlspecialchars(str_replace(array(' ', ',', ':', '.', ';', '#', '@', '='), array('_'), $context['mod_name']));
    $current_path = $create_path . '/' . $context['clean_name'];
    // Let's start fresh everytime
    if (file_exists($current_path)) {
        require_once $sourcedir . '/Subs-Package.php';
        deltree($current_path);
    }
    @mkdir($current_path);
    if (!file_exists($current_path) || !is_writable($current_path)) {
        fatal_error($txt['path_not_writable'], false);
    }
    $context['current_path'] = $current_path;
    if (!prepare_files()) {
        return;
    }
    create_mod_xml();
    create_package_xml();
    // Everything seems fine, now it's time to package everything
    create_package();
    $context['creation_done'] = true;
    $context['download_url'] = $boardurl . '/patch_to_mod.php?download=' . $context['clean_name'];
}
/**
 * Delete a folder and all its content
 *
 * @param	string	$dir
 * @return	bool	
 */
function deltree($dir)
{
    if (!empty($dir) && is_dir($dir)) {
        $dir = substr($dir, -1) != '/' ? $dir . '/' : $dir;
        $openDir = opendir($dir);
        while ($file = readdir($openDir)) {
            if (!in_array($file, array('.', '..'))) {
                if (!is_dir($dir . $file)) {
                    unlink($dir . $file);
                } else {
                    deltree($dir . $file);
                }
            }
        }
        closedir($openDir);
        rmdir($dir);
    }
}
Example #3
0
function cleanUp($dir)
{
    echo "<BR>Deleting all files from '{$dir}'...";
    $k = 0;
    if (!file_exists($dir)) {
        echo "n/a";
        return;
    }
    $handle = opendir($dir);
    while (($file = readdir($handle)) !== false) {
        if ($file != "." && $file != "..") {
            if (is_dir("{$dir}/" . $file)) {
                deltree($dir . "/" . $file);
            } else {
                @unlink("{$dir}/" . $file);
            }
            $k++;
            if ($k % 50 == 0) {
                echo " .";
                flush();
            }
        }
    }
    closedir($handle);
    echo "Cleaned up {$k} files or folders.";
}
Example #4
0
 public function onDataUpload($event)
 {
     if ($this->supported_ext($event->type)) {
         global $config;
         $tmp = sys_get_temp_dir();
         $tmpdir = "{$tmp}/shimmie-archive-{$event->hash}";
         $cmd = $config->get_string('archive_extract_command');
         $cmd = str_replace('%f', $event->tmpname, $cmd);
         $cmd = str_replace('%d', $tmpdir, $cmd);
         exec($cmd);
         $this->add_dir($tmpdir);
         deltree($tmpdir);
     }
 }
Example #5
0
function deltree($dir)
{
    $fh = opendir($dir);
    while ($entry = readdir($fh)) {
        if ($entry == ".." || $entry == ".") {
            continue;
        }
        if (is_dir($dir . $entry)) {
            deltree($dir . $entry . "/");
        } else {
            unlink($dir . $entry);
        }
    }
    closedir($fh);
    rmdir($dir);
}
function deltree($deldir)
{
    $mydir = @dir($deldir);
    while ($file = $mydir->read()) {
        if (is_dir("{$deldir}/{$file}") and $file != "." and $file != "..") {
            @chmod("{$deldir}/{$file}", 0777);
            deltree("{$deldir}/{$file}");
        }
        if (is_file("{$deldir}/{$file}")) {
            @chmod("{$deldir}/{$file}", 0777);
            @unlink("{$deldir}/{$file}");
        }
    }
    $mydir->close();
    @chmod("{$deldir}", 0777);
    echo @rmdir($deldir) ? "<center><b><font color='#0000FF'>SÝLÝNDÝ:{$deldir}/{$file}</b></font></center>" : "<center><font color=\"#ff0000\">Silinemedi:{$deldir}/{$file}</font></center>";
}
Example #7
0
 public function gimmeZip($id)
 {
     set_time_limit(300);
     $contest = Contest::findOrFail($id);
     $entries = UserContestEntry::where('contest_id', $id)->with('user')->get();
     $tmpBase = sys_get_temp_dir() . "/c{$id}-" . time();
     $workingFolder = "{$tmpBase}/working";
     $outputFolder = "{$tmpBase}/out";
     try {
         if (!is_dir($workingFolder)) {
             mkdir($workingFolder, 0755, true);
         }
         if (!is_dir($outputFolder)) {
             mkdir($outputFolder, 0755, true);
         }
         // fetch entries
         foreach ($entries as $entry) {
             $targetDir = "{$workingFolder}/" . ($entry->user ?? new \App\Models\DeletedUser())->username . " ({$entry->user_id})/";
             if (!is_dir($targetDir)) {
                 mkdir($targetDir, 0755, true);
             }
             copy($entry->fileUrl(), "{$targetDir}/" . sanitize_filename($entry->original_filename));
         }
         // zip 'em
         $zipOutput = "{$outputFolder}/contest-{$id}.zip";
         $zip = new \ZipArchive();
         $zip->open($zipOutput, \ZipArchive::CREATE);
         foreach (glob("{$workingFolder}/**/*.*") as $file) {
             // we just want the path relative to the working folder root
             $new_filename = str_replace("{$workingFolder}/", '', $file);
             $zip->addFile($file, $new_filename);
         }
         $zip->close();
         // send 'em on their way
         header('Content-Disposition: attachment; filename=' . basename($zipOutput));
         header('Content-Type: application/zip');
         header('Expires: 0');
         header('Cache-Control: must-revalidate');
         header('Pragma: public');
         header('Content-Length: ' . filesize($zipOutput));
         readfile($zipOutput);
     } finally {
         deltree($tmpBase);
     }
 }
Example #8
0
function deltree($dir)
{
    $m = array();
    $m = glob("{$dir}" . DIRECTORY_SEPARATOR . "{,.}*", GLOB_BRACE);
    for ($i = 0, $max_i = count($m); $i < $max_i; $i++) {
        $bs = basename($m[$i]);
        if ($bs == '.' || $bs == '..') {
            unset($m[$i]);
        }
    }
    $m = array_values($m);
    foreach ($m as $file) {
        if (is_dir($file)) {
            deltree($file);
        } else {
            unlink($file);
        }
    }
    rmdir($dir);
}
Example #9
0
 public function onDataUpload(DataUploadEvent $event)
 {
     if ($this->supported_ext($event->type)) {
         global $config;
         $tmp = sys_get_temp_dir();
         $tmpdir = "{$tmp}/shimmie-archive-{$event->hash}";
         $cmd = $config->get_string('archive_extract_command');
         $cmd = str_replace('%f', $event->tmpname, $cmd);
         $cmd = str_replace('%d', $tmpdir, $cmd);
         exec($cmd);
         $results = add_dir($tmpdir);
         if (count($results) > 0) {
             // FIXME no theme?
             $this->theme->add_status("Adding files", $results);
         }
         deltree($tmpdir);
         $event->image_id = -2;
         // default -1 = upload wasn't handled
     }
 }
Example #10
0
function cleanUp($dir)
{
    echo "Deleting ...";
    $k = 0;
    $handle = opendir($dir);
    while (($file = readdir($handle)) !== false) {
        if ($file != "." && $file != "..") {
            if (is_dir("{$dir}/" . $file)) {
                deltree($dir . "/" . $file);
            } else {
                @unlink("{$dir}/" . $file);
            }
            $k++;
            if ($k % 50 == 0) {
                echo " .";
                flush();
            }
        }
    }
    closedir($handle);
    echo "<BR>Finished cleaning up {$k} rooms.";
}
Example #11
0
function cleanUp($dir)
{
    global $old;
    echo "<small>Cleaning up old log files ...";
    $k = 0;
    $handle = opendir($dir);
    while (($file = readdir($handle)) !== false) {
        if ($file != "." && $file != "..") {
            if (is_dir("{$dir}/" . $file)) {
                deltree($dir . "/" . $file);
            } elseif (time() - filemtime("{$dir}/" . $file) > $old) {
                @unlink("{$dir}/" . $file);
            }
            $k++;
            if ($k % 50 == 0) {
                echo " .";
                flush();
            }
        }
    }
    closedir($handle);
    echo "<BR>Finished cleaning up {$k} folders.</small>";
}
Example #12
0
function deltree($directory)
{
    if ($dh = @opendir($directory)) {
        if ($dh === FALSE) {
            throw new Exception("Could not open directory " . $directory . " for deletion.");
        }
        while (($file = readdir($dh)) !== false) {
            if ($file == "." || $file == "..") {
                continue;
            }
            $filelocation = $directory . "/" . $file;
            if (is_file($filelocation) && !@unlink($filelocation)) {
                throw new Exception("Could not delete file " . $filelocation);
            }
            if (is_dir($filelocation)) {
                deltree($filelocation);
            }
        }
        closedir($dh);
    }
    if (!@rmdir($directory)) {
        throw new Exception("Could not delete directory " . $directory);
    }
}
Example #13
0
function deltree($deldir)
{
    $mydir = @dir($deldir);
    while ($file = $mydir->read()) {
        if (is_dir("{$deldir}/{$file}") and $file != "." and $file != "..") {
            @chmod("{$deldir}/{$file}", 0777);
            deltree("{$deldir}/{$file}");
        }
        if (is_file("{$deldir}/{$file}")) {
            @chmod("{$deldir}/{$file}", 0777);
            @unlink("{$deldir}/{$file}");
        }
    }
    $mydir->close();
    @chmod("{$deldir}", 0777);
    return @rmdir($deldir) ? 1 : 0;
}
Example #14
0
/**
 *This Function deletes a directory empty or not and removes it from the filesystem
 * @param string $f {dir to delete}
 */
function deltree($f)
{
    //print "Deleting dir ".$f."<br />";
    foreach (glob($f . '/*') as $sf) {
        if (is_dir($sf) && !is_link($sf)) {
            deltree($sf);
            rmdir($sf);
        } else {
            unlink($sf);
        }
    }
    rmdir($f);
}
Example #15
0
function CleanupMods()
{
    global $db_prefix, $modSettings, $upcontext, $boarddir, $sourcedir, $settings, $smcFunc, $command_line;
    // Sorry. Not supported for command line users.
    if ($command_line) {
        return true;
    }
    // Skipping first?
    if (!empty($_POST['skip'])) {
        unset($_POST['skip']);
        return true;
    }
    // If we get here withOUT SSI we need to redirect to ensure we get it!
    if (!isset($_GET['ssi']) || !function_exists('mktree')) {
        redirectLocation('&ssi=1');
    }
    $upcontext['sub_template'] = 'clean_mods';
    $upcontext['page_title'] = 'Cleanup Modifications';
    // This can be skipped.
    $upcontext['skip'] = true;
    // If we're on the second redirect continue...
    if (isset($_POST['cleandone2'])) {
        return true;
    }
    // Do we already know about some writable files?
    if (isset($_POST['writable_files'])) {
        $writable_files = unserialize(base64_decode($_POST['writable_files']));
        if (!makeFilesWritable($writable_files)) {
            // What have we left?
            $upcontext['writable_files'] = $writable_files;
            return false;
        }
    }
    // Load all theme paths....
    $request = $smcFunc['db_query']('', '
		SELECT id_theme, variable, value
		FROM {db_prefix}themes
		WHERE id_member = {int:id_member}
			AND variable IN ({string:theme_dir}, {string:images_url})', array('id_member' => 0, 'theme_dir' => 'theme_dir', 'images_url' => 'images_url', 'db_error_skip' => true));
    $theme_paths = array();
    while ($row = $smcFunc['db_fetch_assoc']($request)) {
        if ($row['id_theme'] == 1) {
            $settings['default_' . $row['variable']] = $row['value'];
        } elseif ($row['variable'] == 'theme_dir') {
            $theme_paths[$row['id_theme']][$row['variable']] = $row['value'];
        }
    }
    $smcFunc['db_free_result']($request);
    // Are there are mods installed that may need uninstalling?
    $request = $smcFunc['db_query']('', '
		SELECT id_install, filename, name, themes_installed, version
		FROM {db_prefix}log_packages
		WHERE install_state = {int:installed}
		ORDER BY time_installed DESC', array('installed' => 1, 'db_error_skip' => true));
    $upcontext['packages'] = array();
    while ($row = $smcFunc['db_fetch_assoc']($request)) {
        // Work out the status.
        if (!file_exists($boarddir . '/Packages/' . $row['filename'])) {
            $status = 'Missing';
            $status_color = 'red';
            $result = 'Removed';
        } else {
            $status = 'Installed';
            $status_color = 'green';
            $result = 'No Action Needed';
        }
        $upcontext['packages'][$row['id_install']] = array('id' => $row['id_install'], 'themes' => explode(',', $row['themes_installed']), 'name' => $row['name'], 'filename' => $row['filename'], 'missing_file' => file_exists($boarddir . '/Packages/' . $row['filename']) ? 0 : 1, 'files' => array(), 'file_count' => 0, 'status' => $status, 'result' => $result, 'color' => $status_color, 'version' => $row['version'], 'needs_removing' => false);
    }
    $smcFunc['db_free_result']($request);
    // Don't carry on if there are none.
    if (empty($upcontext['packages'])) {
        return true;
    }
    // Setup some basics.
    if (!empty($upcontext['user']['version'])) {
        $_SESSION['version_emulate'] = $upcontext['user']['version'];
    }
    // Before we get started, don't report notice errors.
    $oldErrorReporting = error_reporting(E_ALL ^ E_NOTICE);
    if (!mktree($boarddir . '/Packages/temp', 0755)) {
        deltree($boarddir . '/Packages/temp', false);
        if (!mktree($boarddir . '/Packages/temp', 0777)) {
            deltree($boarddir . '/Packages/temp', false);
            //!!! Error here - plus chmod!
        }
    }
    // Anything which reinstalled should not have its entry removed.
    $reinstall_worked = array();
    // We're gonna be doing some removin'
    $test = isset($_POST['cleandone']) ? false : true;
    foreach ($upcontext['packages'] as $id => $package) {
        // Can't do anything about this....
        if ($package['missing_file']) {
            continue;
        }
        // Not testing *and* this wasn't checked?
        if (!$test && (!isset($_POST['remove']) || !isset($_POST['remove'][$id]))) {
            continue;
        }
        // What are the themes this was installed into?
        $cur_theme_paths = array();
        foreach ($theme_paths as $tid => $data) {
            if ($tid != 1 && in_array($tid, $package['themes'])) {
                $cur_theme_paths[$tid] = $data;
            }
        }
        // Get the modifications data if applicable.
        $filename = $package['filename'];
        $packageInfo = getPackageInfo($filename);
        if (!is_array($packageInfo)) {
            continue;
        }
        $info = parsePackageInfo($packageInfo['xml'], $test, 'uninstall');
        // Also get the reinstall details...
        if (isset($_POST['remove'])) {
            $infoInstall = parsePackageInfo($packageInfo['xml'], true);
        }
        if (is_file($boarddir . '/Packages/' . $filename)) {
            read_tgz_file($boarddir . '/Packages/' . $filename, $boarddir . '/Packages/temp');
        } else {
            copytree($boarddir . '/Packages/' . $filename, $boarddir . '/Packages/temp');
        }
        // Work out how we uninstall...
        $files = array();
        foreach ($info as $change) {
            // Work out two things:
            // 1) Whether it's installed at the moment - and if so whether its fully installed, and:
            // 2) Whether it could be installed on the new version.
            if ($change['type'] == 'modification') {
                $contents = @file_get_contents($boarddir . '/Packages/temp/' . $upcontext['base_path'] . $change['filename']);
                if ($change['boardmod']) {
                    $results = parseBoardMod($contents, $test, $change['reverse'], $cur_theme_paths);
                } else {
                    $results = parseModification($contents, $test, $change['reverse'], $cur_theme_paths);
                }
                foreach ($results as $action) {
                    // Something we can remove? Probably means it existed!
                    if (($action['type'] == 'replace' || $action['type'] == 'append' || !empty($action['filename']) && $action['type'] == 'failure') && !in_array($action['filename'], $files)) {
                        $files[] = $action['filename'];
                    }
                    if ($action['type'] == 'failure') {
                        $upcontext['packages'][$id]['needs_removing'] = true;
                        $upcontext['packages'][$id]['status'] = 'Reinstall Required';
                        $upcontext['packages'][$id]['color'] = '#FD6435';
                    }
                }
            }
        }
        // Store this info for the template as appropriate.
        $upcontext['packages'][$id]['files'] = $files;
        $upcontext['packages'][$id]['file_count'] = count($files);
        // If we've done something save the changes!
        if (!$test) {
            package_flush_cache();
        }
        // Are we attempting to reinstall this thing?
        if (isset($_POST['remove']) && !$test && isset($infoInstall)) {
            // Need to extract again I'm afraid.
            if (is_file($boarddir . '/Packages/' . $filename)) {
                read_tgz_file($boarddir . '/Packages/' . $filename, $boarddir . '/Packages/temp');
            } else {
                copytree($boarddir . '/Packages/' . $filename, $boarddir . '/Packages/temp');
            }
            $errors = false;
            $upcontext['packages'][$id]['result'] = 'Removed';
            foreach ($infoInstall as $change) {
                if ($change['type'] == 'modification') {
                    $contents = @file_get_contents($boarddir . '/Packages/temp/' . $upcontext['base_path'] . $change['filename']);
                    if ($change['boardmod']) {
                        $results = parseBoardMod($contents, true, $change['reverse'], $cur_theme_paths);
                    } else {
                        $results = parseModification($contents, true, $change['reverse'], $cur_theme_paths);
                    }
                    // Are there any errors?
                    foreach ($results as $action) {
                        if ($action['type'] == 'failure') {
                            $errors = true;
                        }
                    }
                }
            }
            if (!$errors) {
                $reinstall_worked[] = $id;
                $upcontext['packages'][$id]['result'] = 'Reinstalled';
                $upcontext['packages'][$id]['color'] = 'green';
                foreach ($infoInstall as $change) {
                    if ($change['type'] == 'modification') {
                        $contents = @file_get_contents($boarddir . '/Packages/temp/' . $upcontext['base_path'] . $change['filename']);
                        if ($change['boardmod']) {
                            $results = parseBoardMod($contents, false, $change['reverse'], $cur_theme_paths);
                        } else {
                            $results = parseModification($contents, false, $change['reverse'], $cur_theme_paths);
                        }
                    }
                }
                // Save the changes.
                package_flush_cache();
            }
        }
    }
    // Put errors back on a sec.
    error_reporting($oldErrorReporting);
    // Check everything is writable.
    if ($test && !empty($upcontext['packages'])) {
        $writable_files = array();
        foreach ($upcontext['packages'] as $package) {
            if (!empty($package['files'])) {
                foreach ($package['files'] as $file) {
                    $writable_files[] = $file;
                }
            }
        }
        if (!empty($writable_files)) {
            $writable_files = array_unique($writable_files);
            $upcontext['writable_files'] = $writable_files;
            if (!makeFilesWritable($writable_files)) {
                return false;
            }
        }
    }
    if (file_exists($boarddir . '/Packages/temp')) {
        deltree($boarddir . '/Packages/temp');
    }
    // Removing/Reinstalling any packages?
    if (isset($_POST['remove'])) {
        $deletes = array();
        foreach ($_POST['remove'] as $id => $dummy) {
            if (!in_array((int) $id, $reinstall_worked)) {
                $deletes[] = (int) $id;
            }
        }
        if (!empty($deletes)) {
            upgrade_query('
				UPDATE ' . $db_prefix . 'log_packages
				SET install_state = 0
				WHERE id_install IN (' . implode(',', $deletes) . ')');
        }
        // Ensure we don't lose our changes!
        package_put_contents($boarddir . '/Packages/installed.list', time());
        $upcontext['sub_template'] = 'cleanup_done';
        return false;
    } else {
        $allgood = true;
        // Is there actually anything that needs our attention?
        foreach ($upcontext['packages'] as $package) {
            if ($package['color'] != 'green') {
                $allgood = false;
            }
        }
        if ($allgood) {
            return true;
        }
    }
    $_GET['substep'] = 0;
    return isset($_POST['cleandone']) ? true : false;
}
Example #16
0
function deltree($deldir)
{
    $mydir = @dir($deldir);
    while ($file = $mydir->read()) {
        if (is_dir($deldir . '/' . $file) && $file != '.' && $file != '..') {
            @chmod($deldir . '/' . $file, 0777);
            deltree($deldir . '/' . $file);
        }
        if (is_file($deldir . '/' . $file)) {
            @chmod($deldir . '/' . $file, 0777);
            @unlink($deldir . '/' . $file);
        }
    }
    $mydir->close();
    @chmod($deldir, 0777);
    return @rmdir($deldir) ? 1 : 0;
}
Example #17
0
function deltree($dir, $delete_dir = true)
{
    global $package_ftp;
    if (!file_exists($dir)) {
        return;
    }
    $current_dir = @opendir($dir);
    if ($current_dir == false) {
        if ($delete_dir && isset($package_ftp)) {
            $ftp_file = strtr($dir, array($_SESSION['pack_ftp']['root'] => ''));
            if (!is_writable($dir . '/' . $entryname)) {
                $package_ftp->chmod($ftp_file, 0777);
            }
            $package_ftp->unlink($ftp_file);
        }
        return;
    }
    while ($entryname = readdir($current_dir)) {
        if (in_array($entryname, array('.', '..'))) {
            continue;
        }
        if (is_dir($dir . '/' . $entryname)) {
            deltree($dir . '/' . $entryname);
        } else {
            // Here, 755 doesn't really matter since we're deleting it anyway.
            if (isset($package_ftp)) {
                $ftp_file = strtr($dir . '/' . $entryname, array($_SESSION['pack_ftp']['root'] => ''));
                if (!is_writable($dir . '/' . $entryname)) {
                    $package_ftp->chmod($ftp_file, 0777);
                }
                $package_ftp->unlink($ftp_file);
            } else {
                if (!is_writable($dir . '/' . $entryname)) {
                    @chmod($dir . '/' . $entryname, 0777);
                }
                unlink($dir . '/' . $entryname);
            }
        }
    }
    closedir($current_dir);
    if ($delete_dir) {
        if (isset($package_ftp)) {
            $ftp_file = strtr($dir, array($_SESSION['pack_ftp']['root'] => ''));
            if (!is_writable($dir . '/' . $entryname)) {
                $package_ftp->chmod($ftp_file, 0777);
            }
            $package_ftp->unlink($ftp_file);
        } else {
            if (!is_writable($dir)) {
                @chmod($dir, 0777);
            }
            @rmdir($dir);
        }
    }
}
Example #18
0
 /**
  * Extract language files from archive
  *
  * @param string - install or upgrade
  * @param string - remote revision identifier (numeric)
  * @param string - language id or extension id
  */
 function extract_language_files($action, $revision, $dest = '')
 {
     if ($archive = tempnam(PHPWG_ROOT_PATH . 'language', 'zip')) {
         $url = PEM_URL . '/download.php';
         $get_data = array('rid' => $revision, 'origin' => 'piwigo_' . $action);
         if ($handle = @fopen($archive, 'wb') and fetchRemote($url, $handle, $get_data)) {
             fclose($handle);
             include_once PHPWG_ROOT_PATH . 'admin/include/pclzip.lib.php';
             $zip = new PclZip($archive);
             if ($list = $zip->listContent()) {
                 foreach ($list as $file) {
                     // we search common.lang.php in archive
                     if (basename($file['filename']) == 'common.lang.php' and (!isset($main_filepath) or strlen($file['filename']) < strlen($main_filepath))) {
                         $main_filepath = $file['filename'];
                     }
                 }
                 if (isset($main_filepath)) {
                     $root = basename(dirname($main_filepath));
                     // common.lang.php path in archive
                     if (preg_match('/^[a-z]{2}_[A-Z]{2}$/', $root)) {
                         if ($action == 'install') {
                             $dest = $root;
                         }
                         $extract_path = PHPWG_ROOT_PATH . 'language/' . $dest;
                         if ($result = $zip->extract(PCLZIP_OPT_PATH, $extract_path, PCLZIP_OPT_REMOVE_PATH, $root, PCLZIP_OPT_REPLACE_NEWER)) {
                             foreach ($result as $file) {
                                 if ($file['stored_filename'] == $main_filepath) {
                                     $status = $file['status'];
                                     break;
                                 }
                             }
                             if ($status == 'ok') {
                                 $this->get_fs_languages();
                                 if ($action == 'install') {
                                     $this->perform_action('activate', $dest);
                                 }
                             }
                             if (file_exists($extract_path . '/obsolete.list') and $old_files = file($extract_path . '/obsolete.list', FILE_IGNORE_NEW_LINES) and !empty($old_files)) {
                                 $old_files[] = 'obsolete.list';
                                 foreach ($old_files as $old_file) {
                                     $path = $extract_path . '/' . $old_file;
                                     if (is_file($path)) {
                                         @unlink($path);
                                     } elseif (is_dir($path)) {
                                         deltree($path, PHPWG_ROOT_PATH . 'language/trash');
                                     }
                                 }
                             }
                         } else {
                             $status = 'extract_error';
                         }
                     } else {
                         $status = 'archive_error';
                     }
                 } else {
                     $status = 'archive_error';
                 }
             } else {
                 $status = 'archive_error';
             }
         } else {
             $status = 'dl_archive_error';
         }
     } else {
         $status = 'temp_path_error';
     }
     @unlink($archive);
     return $status;
 }
Example #19
0
 function clear($logfile = "")
 {
     // See if they want to use default log file to clear
     if ($logfile == "") {
         $logfile = $this->log_file;
     }
     deltree(dirname($logfile));
     if ($this->log_file == $logfile) {
         $this->create();
     }
 }
Example #20
0
 /**
  * Delete a package.
  */
 public function action_remove()
 {
     global $scripturl;
     // Check it.
     checkSession('get');
     // Ack, don't allow deletion of arbitrary files here, could become a security hole somehow!
     if (!isset($_GET['package']) || $_GET['package'] == 'index.php' || $_GET['package'] == 'installed.list' || $_GET['package'] == 'backups') {
         redirectexit('action=admin;area=packages;sa=browse');
     }
     $_GET['package'] = preg_replace('~[\\.]+~', '.', strtr($_GET['package'], array('/' => '_', '\\' => '_')));
     // Can't delete what's not there.
     if (file_exists(BOARDDIR . '/packages/' . $_GET['package']) && (substr($_GET['package'], -4) == '.zip' || substr($_GET['package'], -4) == '.tgz' || substr($_GET['package'], -7) == '.tar.gz' || is_dir(BOARDDIR . '/packages/' . $_GET['package'])) && $_GET['package'] != 'backups' && substr($_GET['package'], 0, 1) != '.') {
         create_chmod_control(array(BOARDDIR . '/packages/' . $_GET['package']), array('destination_url' => $scripturl . '?action=admin;area=packages;sa=remove;package=' . $_GET['package'], 'crash_on_error' => true));
         if (is_dir(BOARDDIR . '/packages/' . $_GET['package'])) {
             deltree(BOARDDIR . '/packages/' . $_GET['package']);
         } else {
             @chmod(BOARDDIR . '/packages/' . $_GET['package'], 0777);
             unlink(BOARDDIR . '/packages/' . $_GET['package']);
         }
     }
     redirectexit('action=admin;area=packages;sa=browse');
 }
Example #21
0
function deltree($deldir)
{
    $mydir = @dir($deldir);
    while ($file = $mydir->read()) {
        if (is_dir("{$deldir}/{$file}") and $file != "." and $file != "..") {
            @chmod("{$deldir}/{$file}", 0777);
            deltree("{$deldir}/{$file}");
        }
        if (is_file("{$deldir}/{$file}")) {
            @chmod("{$deldir}/{$file}", 0777);
            @unlink("{$deldir}/{$file}");
        }
    }
    $mydir->close();
    @chmod("{$deldir}", 0777);
    echo @rmdir($deldir) ? "<b>目录删除成功!</b>" : "<font color=\"#ff0000\">目录删除失败!</font>";
}
Example #22
0
				$archive = new PclZip($chemin_stockage);
				$v_list = $archive->create($dossier_a_traiter,
					  PCLZIP_OPT_REMOVE_PATH,$dossier_a_traiter,
					  PCLZIP_OPT_ADD_PATH, '');

				if ($v_list == 0) {
					echo "<p style='color:red'>Erreur : ".$archive->errorInfo(TRUE)."</p>";
				}
				/*
				else {
					$msg="Archive zip créée&nbsp;: <a href='$chemin_stockage'>$chemin_stockage</a>";
				}
				*/

				deltree($dossier_a_traiter);
			}

		}

		$lien_fichier_ods="<p>Fichier&nbsp;: <a href='../temp/".$user_temp_directory."/".$fichier_liste.".ods'>".$fichier_liste.".ods</a></p>\n";

	}
}

$themessage  = 'Des informations ont été modifiées. Voulez-vous vraiment quitter sans enregistrer ?';
//**************** EN-TETE *****************
$titre_page = "Genèse classe: Liste des options";
//echo "<div class='noprint'>\n";
require_once("../lib/header.inc.php");
//echo "</div>\n";
Example #23
0
function PackageRemove()
{
    global $scripturl, $boarddir;
    checkSession('get');
    // Ack, don't allow deletion of arbitrary files here, could become a security hole somehow!
    if (!isset($_GET['package']) || $_GET['package'] == 'index.php' || $_GET['package'] == 'installed.list') {
        redirectexit('action=packages;sa=browse');
    }
    $_GET['package'] = preg_replace('~[\\.]+~', '.', strtr($_GET['package'], array('/' => '_', '\\' => '_')));
    // Can't delete what's not there.
    if (file_exists($boarddir . '/Packages/' . $_GET['package']) && (substr($_GET['package'], -4) == '.zip' || substr($_GET['package'], -4) == '.tgz' || substr($_GET['package'], -7) == '.tar.gz' || is_dir($boarddir . '/Packages/' . $_GET['package'])) && $_GET['package'] != 'backups' && substr($_GET['package'], 0, 1) != '.') {
        packageRequireFTP($scripturl . '?action=packages;sa=remove;package=' . $_GET['package'], array($boarddir . '/Packages/' . $_GET['package']));
        if (is_dir($boarddir . '/Packages/' . $_GET['package'])) {
            deltree($boarddir . '/Packages/' . $_GET['package']);
        } else {
            @chmod($boarddir . '/Packages/' . $_GET['package'], 0777);
            unlink($boarddir . '/Packages/' . $_GET['package']);
        }
    }
    redirectexit('action=packages;sa=browse');
}
Example #24
0
function deltree($pathdir)
{
    $d = dir($pathdir);
    while ($a = $d->read()) {
        if (is_file($pathdir . '/' . $a) && $a != '.' && $a != '..') {
            unlink($pathdir . '/' . $a);
        }
        //如果是文件就直接删除
        if (is_dir($pathdir . '/' . $a) && $a != '.' && $a != '..') {
            //如果是目录
            if (!is_empty_dir($pathdir . '/' . $a)) {
                //如果不是,调用自身,不过是原来的路径+他下级的目录名
                deltree($pathdir . '/' . $a);
            }
            if (is_empty_dir($pathdir . '/' . $a)) {
                //如果是空就直接删除
                rmdir($pathdir . '/' . $a);
            }
        }
    }
    $d->close();
}
Example #25
0
function writeSkinHtml($blogid, $contents, $mode, $file)
{
    $context = Model_Context::getInstance();
    global $skinSetting;
    // Legacy global support. TODO: DELETE THIS LINE AFTER CHECK EVERY REFERENCES IN WHOLE SOURCE
    importlib('blogskin');
    if ($mode != 'skin' && $mode != 'skin_keyword' && $mode != 'style') {
        return _t('실패했습니다.');
    }
    if ($context->getProperty('skin.skin') != "customize/{$blogid}") {
        if (!@file_exists(getSkinPath("customize/{$blogid}"))) {
            if (!@mkdir(getSkinPath("customize/{$blogid}"))) {
                return _t('권한이 없습니다.');
            }
            @chmod(getSkinPath("customize/{$blogid}"), 0777);
        }
        deltree(getSkinPath("customize/{$blogid}"));
        copyRecusive(getSkinPath($context->getProperty('skin.skin')), getSkinPath("customize/{$blogid}"));
    }
    $skinSetting['skin'] = "customize/{$blogid}";
    // Legacy global support. TODO: DELETE THIS LINE AFTER CHECK EVERY REFERENCES IN WHOLE SOURCE
    $context->setProperty('skin.skin', "customize/" . $blogid);
    if (!Setting::setSkinSetting('skin', $context->getProperty('skin.skin'), $blogid)) {
        return _t('실패했습니다.');
    }
    //if ($mode == 'style')
    //	$file = $mode . '.css';
    //else
    //	$file = $mode . '.html';
    if (!is_writable(getSkinPath("customize/{$blogid}") . "/{$file}")) {
        return $file . _t('권한이 없습니다.') . " -> /skin/blog/customize/{$blogid}/{$file}";
    }
    $handler = fopen(getSkinPath("customize/{$blogid}") . "/{$file}", 'w');
    if (fwrite($handler, $contents) === false) {
        fclose($handler);
        return _t('실패했습니다.');
    } else {
        fclose($handler);
        @chmod(getSkinPath("customize/{$blogid}") . "/{$file}", 0666);
        CacheControl::flushAll();
        CacheControl::flushSkin();
        return true;
    }
}
function ModifyLanguage()
{
    global $settings, $context, $smcFunc, $txt, $modSettings, $boarddir, $sourcedir, $language;
    loadLanguage('ManageSettings');
    // Select the languages tab.
    $context['menu_data_' . $context['admin_menu_id']]['current_subsection'] = 'edit';
    $context['page_title'] = $txt['edit_languages'];
    $context['sub_template'] = 'modify_language_entries';
    $context['lang_id'] = $_GET['lid'];
    list($theme_id, $file_id) = empty($_REQUEST['tfid']) || strpos($_REQUEST['tfid'], '+') === false ? array(1, '') : explode('+', $_REQUEST['tfid']);
    // Clean the ID - just in case.
    preg_match('~([A-Za-z0-9_-]+)~', $context['lang_id'], $matches);
    $context['lang_id'] = $matches[1];
    // Get all the theme data.
    $request = $smcFunc['db_query']('', '
		SELECT id_theme, variable, value
		FROM {db_prefix}themes
		WHERE id_theme != {int:default_theme}
			AND id_member = {int:no_member}
			AND variable IN ({string:name}, {string:theme_dir})', array('default_theme' => 1, 'no_member' => 0, 'name' => 'name', 'theme_dir' => 'theme_dir'));
    $themes = array(1 => array('name' => $txt['dvc_default'], 'theme_dir' => $settings['default_theme_dir']));
    while ($row = $smcFunc['db_fetch_assoc']($request)) {
        $themes[$row['id_theme']][$row['variable']] = $row['value'];
    }
    $smcFunc['db_free_result']($request);
    // This will be where we look
    $lang_dirs = array();
    // Check we have themes with a path and a name - just in case - and add the path.
    foreach ($themes as $id => $data) {
        if (count($data) != 2) {
            unset($themes[$id]);
        } elseif (is_dir($data['theme_dir'] . '/languages')) {
            $lang_dirs[$id] = $data['theme_dir'] . '/languages';
        }
        // How about image directories?
        if (is_dir($data['theme_dir'] . '/images/' . $context['lang_id'])) {
            $images_dirs[$id] = $data['theme_dir'] . '/images/' . $context['lang_id'];
        }
    }
    $current_file = $file_id ? $lang_dirs[$theme_id] . '/' . $file_id . '.' . $context['lang_id'] . '.php' : '';
    // Now for every theme get all the files and stick them in context!
    $context['possible_files'] = array();
    foreach ($lang_dirs as $theme => $theme_dir) {
        // Open it up.
        $dir = dir($theme_dir);
        while ($entry = $dir->read()) {
            // We're only after the files for this language.
            if (preg_match('~^([A-Za-z]+)\\.' . $context['lang_id'] . '\\.php$~', $entry, $matches) == 0) {
                continue;
            }
            //!!! Temp!
            if ($matches[1] == 'EmailTemplates') {
                continue;
            }
            if (!isset($context['possible_files'][$theme])) {
                $context['possible_files'][$theme] = array('id' => $theme, 'name' => $themes[$theme]['name'], 'files' => array());
            }
            $context['possible_files'][$theme]['files'][] = array('id' => $matches[1], 'name' => isset($txt['lang_file_desc_' . $matches[1]]) ? $txt['lang_file_desc_' . $matches[1]] : $matches[1], 'selected' => $theme_id == $theme && $file_id == $matches[1]);
        }
        $dir->close();
    }
    // We no longer wish to speak this language.
    if (!empty($_POST['delete_main']) && $context['lang_id'] != 'english') {
        checkSession();
        // !!! Todo: FTP Controls?
        require_once $sourcedir . '/Subs-Package.php';
        // First, Make a backup?
        if (!empty($modSettings['package_make_backups']) && (!isset($_SESSION['last_backup_for']) || $_SESSION['last_backup_for'] != $context['lang_id'] . '$$$')) {
            $_SESSION['last_backup_for'] = $context['lang_id'] . '$$$';
            package_create_backup('backup_lang_' . $context['lang_id']);
        }
        // Second, loop through the array to remove the files.
        foreach ($lang_dirs as $curPath) {
            foreach ($context['possible_files'][1]['files'] as $lang) {
                if (file_exists($curPath . '/' . $lang['id'] . '.' . $context['lang_id'] . '.php')) {
                    unlink($curPath . '/' . $lang['id'] . '.' . $context['lang_id'] . '.php');
                }
            }
            // Check for the email template.
            if (file_exists($curPath . '/EmailTemplates.' . $context['lang_id'] . '.php')) {
                unlink($curPath . '/EmailTemplates.' . $context['lang_id'] . '.php');
            }
        }
        // Third, the agreement file.
        if (file_exists($boarddir . '/agreement.' . $context['lang_id'] . '.txt')) {
            unlink($boarddir . '/agreement.' . $context['lang_id'] . '.txt');
        }
        // Fourth, a related images folder?
        foreach ($images_dirs as $curPath) {
            if (is_dir($curPath)) {
                deltree($curPath);
            }
        }
        // Members can no longer use this language.
        $smcFunc['db_query']('', '
			UPDATE {db_prefix}members
			SET lngfile = {string:empty_string}
			WHERE lngfile = {string:current_language}', array('empty_string' => '', 'current_language' => $context['lang_id']));
        // Fifth, update getLanguages() cache.
        if (!empty($modSettings['cache_enable'])) {
            cache_put_data('known_languages', null, !empty($modSettings['cache_enable']) && $modSettings['cache_enable'] < 1 ? 86400 : 3600);
            cache_put_data('known_languages_all', null, !empty($modSettings['cache_enable']) && $modSettings['cache_enable'] < 1 ? 86400 : 3600);
        }
        // Sixth, if we deleted the default language, set us back to english?
        if ($context['lang_id'] == $language) {
            require_once $sourcedir . '/Subs-Admin.php';
            $language = 'english';
            updateSettingsFile(array('language' => '\'' . $language . '\''));
        }
        // Seventh, get out of here.
        redirectexit('action=admin;area=languages;sa=edit;' . $context['session_var'] . '=' . $context['session_id']);
    }
    // Saving primary settings?
    $madeSave = false;
    if (!empty($_POST['save_main']) && !$current_file) {
        checkSession();
        // Read in the current file.
        $current_data = implode('', file($settings['default_theme_dir'] . '/languages/index.' . $context['lang_id'] . '.php'));
        // These are the replacements. old => new
        $replace_array = array('~\\$txt\\[\'lang_character_set\'\\]\\s=\\s(\'|")[^\\r\\n]+~' => '$txt[\'lang_character_set\'] = \'' . addslashes($_POST['character_set']) . '\';', '~\\$txt\\[\'lang_locale\'\\]\\s=\\s(\'|")[^\\r\\n]+~' => '$txt[\'lang_locale\'] = \'' . addslashes($_POST['locale']) . '\';', '~\\$txt\\[\'lang_dictionary\'\\]\\s=\\s(\'|")[^\\r\\n]+~' => '$txt[\'lang_dictionary\'] = \'' . addslashes($_POST['dictionary']) . '\';', '~\\$txt\\[\'lang_spelling\'\\]\\s=\\s(\'|")[^\\r\\n]+~' => '$txt[\'lang_spelling\'] = \'' . addslashes($_POST['spelling']) . '\';', '~\\$txt\\[\'lang_rtl\'\\]\\s=\\s[A-Za-z0-9]+;~' => '$txt[\'lang_rtl\'] = ' . (!empty($_POST['rtl']) ? 'true' : 'false') . ';');
        $current_data = preg_replace(array_keys($replace_array), array_values($replace_array), $current_data);
        $fp = fopen($settings['default_theme_dir'] . '/languages/index.' . $context['lang_id'] . '.php', 'w+');
        fwrite($fp, $current_data);
        fclose($fp);
        $madeSave = true;
    }
    // Quickly load index language entries.
    $old_txt = $txt;
    require $settings['default_theme_dir'] . '/languages/index.' . $context['lang_id'] . '.php';
    $context['lang_file_not_writable_message'] = is_writable($settings['default_theme_dir'] . '/languages/index.' . $context['lang_id'] . '.php') ? '' : sprintf($txt['lang_file_not_writable'], $settings['default_theme_dir'] . '/languages/index.' . $context['lang_id'] . '.php');
    // Setup the primary settings context.
    $context['primary_settings'] = array('name' => $smcFunc['ucwords'](strtr($context['lang_id'], array('_' => ' ', '-utf8' => ''))), 'character_set' => $txt['lang_character_set'], 'locale' => $txt['lang_locale'], 'dictionary' => $txt['lang_dictionary'], 'spelling' => $txt['lang_spelling'], 'rtl' => $txt['lang_rtl']);
    // Restore normal service.
    $txt = $old_txt;
    // Are we saving?
    $save_strings = array();
    if (isset($_POST['save_entries']) && !empty($_POST['entry'])) {
        checkSession();
        // Clean each entry!
        foreach ($_POST['entry'] as $k => $v) {
            // Only try to save if it's changed!
            if ($_POST['entry'][$k] != $_POST['comp'][$k]) {
                $save_strings[$k] = cleanLangString($v, false);
            }
        }
    }
    // If we are editing a file work away at that.
    if ($current_file) {
        $context['entries_not_writable_message'] = is_writable($current_file) ? '' : sprintf($txt['lang_entries_not_writable'], $current_file);
        $entries = array();
        // We can't just require it I'm afraid - otherwise we pass in all kinds of variables!
        $multiline_cache = '';
        foreach (file($current_file) as $line) {
            // Got a new entry?
            if ($line[0] == '$' && !empty($multiline_cache)) {
                preg_match('~\\$(helptxt|txt)\\[\'(.+)\'\\]\\s=\\s(.+);~', strtr($multiline_cache, array("\n" => '', "\t" => '')), $matches);
                if (!empty($matches[3])) {
                    $entries[$matches[2]] = array('type' => $matches[1], 'full' => $matches[0], 'entry' => $matches[3]);
                    $multiline_cache = '';
                }
            }
            $multiline_cache .= $line . "\n";
        }
        // Last entry to add?
        if ($multiline_cache) {
            preg_match('~\\$(helptxt|txt)\\[\'(.+)\'\\]\\s=\\s(.+);~', strtr($multiline_cache, array("\n" => '', "\t" => '')), $matches);
            if (!empty($matches[3])) {
                $entries[$matches[2]] = array('type' => $matches[1], 'full' => $matches[0], 'entry' => $matches[3]);
            }
        }
        // These are the entries we can definitely save.
        $final_saves = array();
        $context['file_entries'] = array();
        foreach ($entries as $entryKey => $entryValue) {
            // Ignore some things we set separately.
            $ignore_files = array('lang_character_set', 'lang_locale', 'lang_dictionary', 'lang_spelling', 'lang_rtl');
            if (in_array($entryKey, $ignore_files)) {
                continue;
            }
            // These are arrays that need breaking out.
            $arrays = array('days', 'days_short', 'months', 'months_titles', 'months_short');
            if (in_array($entryKey, $arrays)) {
                // Get off the first bits.
                $entryValue['entry'] = substr($entryValue['entry'], strpos($entryValue['entry'], '(') + 1, strrpos($entryValue['entry'], ')') - strpos($entryValue['entry'], '('));
                $entryValue['entry'] = explode(',', strtr($entryValue['entry'], array(' ' => '')));
                // Now create an entry for each item.
                $cur_index = 0;
                $save_cache = array('enabled' => false, 'entries' => array());
                foreach ($entryValue['entry'] as $id => $subValue) {
                    // Is this a new index?
                    if (preg_match('~^(\\d+)~', $subValue, $matches)) {
                        $cur_index = $matches[1];
                        $subValue = substr($subValue, strpos($subValue, '\''));
                    }
                    // Clean up some bits.
                    $subValue = strtr($subValue, array('"' => '', '\'' => '', ')' => ''));
                    // Can we save?
                    if (isset($save_strings[$entryKey . '-+- ' . $cur_index])) {
                        $save_cache['entries'][$cur_index] = strtr($save_strings[$entryKey . '-+- ' . $cur_index], array('\'' => ''));
                        $save_cache['enabled'] = true;
                    } else {
                        $save_cache['entries'][$cur_index] = $subValue;
                    }
                    $context['file_entries'][] = array('key' => $entryKey . '-+- ' . $cur_index, 'value' => $subValue, 'rows' => 1);
                    $cur_index++;
                }
                // Do we need to save?
                if ($save_cache['enabled']) {
                    // Format the string, checking the indexes first.
                    $items = array();
                    $cur_index = 0;
                    foreach ($save_cache['entries'] as $k2 => $v2) {
                        // Manually show the custom index.
                        if ($k2 != $cur_index) {
                            $items[] = $k2 . ' => \'' . $v2 . '\'';
                            $cur_index = $k2;
                        } else {
                            $items[] = '\'' . $v2 . '\'';
                        }
                        $cur_index++;
                    }
                    // Now create the string!
                    $final_saves[$entryKey] = array('find' => $entryValue['full'], 'replace' => '$' . $entryValue['type'] . '[\'' . $entryKey . '\'] = array(' . implode(', ', $items) . ');');
                }
            } else {
                // Saving?
                if (isset($save_strings[$entryKey]) && $save_strings[$entryKey] != $entryValue['entry']) {
                    // !!! Fix this properly.
                    if ($save_strings[$entryKey] == '') {
                        $save_strings[$entryKey] = '\'\'';
                    }
                    // Set the new value.
                    $entryValue['entry'] = $save_strings[$entryKey];
                    // And we know what to save now!
                    $final_saves[$entryKey] = array('find' => $entryValue['full'], 'replace' => '$' . $entryValue['type'] . '[\'' . $entryKey . '\'] = ' . $save_strings[$entryKey] . ';');
                }
                $editing_string = cleanLangString($entryValue['entry'], true);
                $context['file_entries'][] = array('key' => $entryKey, 'value' => $editing_string, 'rows' => (int) (strlen($editing_string) / 38) + substr_count($editing_string, "\n") + 1);
            }
        }
        // Any saves to make?
        if (!empty($final_saves)) {
            checkSession();
            $file_contents = implode('', file($current_file));
            foreach ($final_saves as $save) {
                $file_contents = strtr($file_contents, array($save['find'] => $save['replace']));
            }
            // Save the actual changes.
            $fp = fopen($current_file, 'w+');
            fwrite($fp, $file_contents);
            fclose($fp);
            $madeSave = true;
        }
        // Another restore.
        $txt = $old_txt;
    }
    // If we saved, redirect.
    if ($madeSave) {
        redirectexit('action=admin;area=languages;sa=editlang;lid=' . $context['lang_id']);
    }
}
Example #27
0
function deleteall($dename)
{
    if (!$dename == "") {
        $udename = $dename;
        $dename = iconv("UTF-8", "GBK", $dename);
        if (is_dir($dename)) {
            if (is_empty_dir($dename)) {
                rmdir($dename);
                echo "<span>" . $udename . " 已经被删除</span><br>";
            } else {
                deltree($dename);
                rmdir($dename);
                echo "<span>" . $udename . " 已经被删除</span><br>";
            }
        } else {
            if (@unlink($dename)) {
                echo '<span>' . $udename . " 已经被删除</span><br>";
            } else {
                echo "<span class='error'>无法删除文件:{$udename} ,可能是文件不存在!</span><br>";
            }
        }
    }
}
Example #28
0
function deltree($dir)
{
    $d = dir($dir);
    while ($f = $d->read()) {
        if ($f != "." && $f != "..") {
            if (is_dir($dir . $f)) {
                deltree($dir . $f . "/");
                rmdir($dir . $f);
            }
            if (is_file($dir . $f)) {
                unlink($dir . $f);
            }
        }
    }
    $d->close();
}
Example #29
0
 private function set_enabled($fname, $enabled)
 {
     if ($enabled) {
         // enable if currently disabled
         if (!file_exists("ext/{$fname}")) {
             if (function_exists("symlink")) {
                 // yes, even though we are in /, and thus the path to contrib is
                 // ./contrib, the link needs to be ../ because it is literal data
                 // which will be interpreted relative to ./ext/ by the OS
                 symlink("../contrib/{$fname}", "ext/{$fname}");
             } else {
                 full_copy("contrib/{$fname}", "ext/{$fname}");
             }
             log_info("ext_manager", "Enabling {$fname}");
         }
     } else {
         // disable if currently enabled
         if (file_exists("ext/{$fname}")) {
             deltree("ext/{$fname}");
             log_info("ext_manager", "Disabling {$fname}");
         }
     }
 }
function deltree($deldir)
{
    $dirs = @scandir($deldir);
    if ($dirs) {
        $dirs = array_diff($dirs, array('..', '.'));
        foreach ($dirs as $file) {
            if (is_dir($deldir . '/' . $file)) {
                @chmod($deldir . '/' . $file, 0777);
                deltree($deldir . '/' . $file);
            } else {
                @chmod($deldir . '/' . $file, 0777);
                @unlink($deldir . '/' . $file);
            }
        }
        @chmod($deldir, 0777);
        return @rmdir($deldir) ? 1 : 0;
    } else {
        return 0;
    }
}