Пример #1
0
function fetch_blacklist()
{
    global $config, $g;
    $url = $config['installedpackages']['dansguardianblacklist']['config'][0]['url'];
    if (is_url($url)) {
        conf_mount_rw();
        print "file download start..";
        unlink_if_exists("/usr/local/etc/dansguardian/lists/blacklist.tgz");
        exec("/usr/bin/fetch -o /usr/local/etc/dansguardian/lists/blacklist.tgz " . escapeshellarg($url));
        chdir("/usr/local/etc/dansguardian/lists");
        if (is_dir("blacklists.old")) {
            exec('rm -rf /usr/local/etc/dansguardian/lists/blacklists.old');
        }
        rename("blacklists", "blacklists.old");
        exec('/usr/bin/tar -xvzf /usr/local/etc/dansguardian/lists/blacklist.tgz 2>&1', $output, $return);
        if (preg_match("/x\\W+(\\w+)/", $output[0], $matches)) {
            if ($matches[1] != "blacklists") {
                rename("./" . $matches[1], "blacklists");
            }
            read_lists();
        } else {
            file_notice("Dansguardian - Could not determine Blacklist extract dir. Categories not updated", "");
        }
    } else {
        file_notice("Dansguardian - Blacklist url is invalid.", "");
    }
}
function fetch_blacklist($log_notice = true, $install_process = false)
{
    global $config, $g;
    if (is_array($config['installedpackages']['dansguardianblacklist']) && is_array($config['installedpackages']['dansguardianblacklist']['config'])) {
        $url = $config['installedpackages']['dansguardianblacklist']['config'][0]['url'];
        $uw = "Found a previouns install, checking Blacklist config...";
    } else {
        $uw = "Found a clean install, reading default access lists...";
    }
    conf_mount_rw();
    if ($install_process == true) {
        update_output_window($uw);
    }
    if (isset($url) && is_url($url)) {
        if ($log_notice == true) {
            print "file download start..";
            unlink_if_exists("/usr/local/pkg/blacklist.tgz");
            exec("/usr/bin/fetch -o /usr/local/pkg/blacklist.tgz " . escapeshellarg($url), $output, $return);
        } else {
            #install process
            if (file_exists("/usr/local/pkg/blacklist.tgz")) {
                update_output_window("Found previous blacklist database, skipping download...");
                $return = 0;
            } else {
                update_output_window("Fetching blacklist");
                download_file_with_progress_bar($url, "/usr/local/pkg/blacklist.tgz");
                if (file_exists("/usr/local/pkg/blacklist.tgz")) {
                    $return = 0;
                }
            }
        }
        if ($return == 0) {
            chdir(DANSGUARDIAN_DIR . "/etc/dansguardian/lists");
            if (is_dir("blacklists.old")) {
                exec('rm -rf ' . DANSGUARDIAN_DIR . '/etc/dansguardian/lists/blacklists.old');
            }
            rename("blacklists", "blacklists.old");
            exec('/usr/bin/tar -xvzf /usr/local/pkg/blacklist.tgz 2>&1', $output, $return);
            if (preg_match("/x\\W+(\\w+)/", $output[1], $matches)) {
                if ($matches[1] != "blacklists") {
                    rename("./" . $matches[1], "blacklists");
                }
                read_lists($log_notice);
            } else {
                file_notice("Dansguardian - Could not determine Blacklist extract dir. Categories not updated", "");
            }
        } else {
            file_notice("Dansguardian - Could not fetch blacklists from url", "");
        }
    } else {
        if ($install_process == true) {
            read_lists(false, $uw);
        } elseif (!empty($url)) {
            file_notice("Dansguardian - Blacklist url is invalid.", "");
        }
    }
}