⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 proxyutil.java

📁 这是linux下ssl vpn的实现程序
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
package com.sslexplorer.vpn.base;

import java.io.BufferedReader;
import java.io.File;
import java.io.InputStreamReader;
import java.util.Properties;
import java.io.FileInputStream;
import java.util.Enumeration;
import java.util.StringTokenizer;
import ca.beq.util.win32.registry.RegistryKey;
import java.util.Hashtable;
import ca.beq.util.win32.registry.RootKey;
import java.util.Vector;
import java.io.IOException;

import com.sslexplorer.vpn.util.*;

public class ProxyUtil {

    /* DEBUG */static org.apache.commons.logging.Log log = org.apache.commons.logging.LogFactory.getLog(ProxyUtil.class);

    /**
     * 
     */

    public static BrowserProxySettings lookupFirefoxProxySettings() throws IOException {

        try {

            Vector proxies = new Vector();
            Vector bypassAddr = new Vector();

            File home = new File(Utils.getHomeDirectory());
            File firefoxAppData;

            if (System.getProperty("os.name") != null && System.getProperty("os.name").startsWith("Windows")) {
                firefoxAppData = new File(home, "Application Data\\Mozilla\\Firefox\\profiles.ini");
            } else {
                firefoxAppData = new File(home, ".mozilla/firefox/profiles.ini");
            }

            // Look for Path elements in the profiles.ini
            BufferedReader reader = null;
            Hashtable profiles = new Hashtable();
            String line;
            try {
                reader = new BufferedReader(new InputStreamReader(new FileInputStream(firefoxAppData)));
                String currentProfileName = "";

                while ((line = reader.readLine()) != null) {
                    line = line.trim();
                    if (line.startsWith("[") && line.endsWith("]")) {
                        currentProfileName = line.substring(1, line.length() - 1);
                        continue;
                    }

                    if (line.startsWith("Path=")) {
                        profiles.put(currentProfileName, new File(firefoxAppData.getParent(), line.substring(5)));
                    }
                }
            } finally {
                if (reader != null) {
                    reader.close();
                }
            }

            // Iterate through all the profiles and load the proxy infos from
            // the prefs.js file

            File prefsJS;
            String profileName;
            for (Enumeration e = profiles.keys(); e.hasMoreElements();) {
                profileName = (String) e.nextElement();
                prefsJS = new File((File) profiles.get(profileName), "prefs.js");
                Properties props = new Properties();
                reader = null;
                try {
                    reader = new BufferedReader(new InputStreamReader(new FileInputStream(prefsJS)));
                    while ((line = reader.readLine()) != null) {
                        line = line.trim();
                        if (line.startsWith("user_pref(\"")) {
                            int idx = line.indexOf("\"", 11);
                            if (idx == -1)
                                continue;
                            String pref = line.substring(11, idx);

                            // Save this position
                            int pos = idx + 1;

                            // Look for another quote
                            idx = line.indexOf("\"", idx + 1);

                            String value;
                            if (idx == -1) {
                                // No more quotes
                                idx = line.indexOf(" ", pos);

                                if (idx == -1)
                                    continue;

                                int idx2 = line.indexOf(")", pos);

                                if (idx2 == -1)
                                    continue;

                                value = line.substring(idx + 1, idx2);

                            } else {

                                // String value
                                int idx2 = line.indexOf("\"", idx + 1);

                                if (idx2 == -1)
                                    continue;

                                value = line.substring(idx + 1, idx2);
                            }

                            props.put(pref, value);

                        }
                    }
                } finally {
                    if (reader != null) {
                        reader.close();
                    }
                }
                ProxyInfo p;
                /**
                 * Extract some proxies from the properites, if the proxy is
                 * enabled
                 */
                if ("1".equals(props.get("network.proxy.type"))) {
                    if (props.containsKey("network.proxy.ftp")) {
                        p = createProxyInfo("ftp=" + props.get("network.proxy.ftp") + ":" + props.get("network.proxy.ftp_port"),
                                            "Firefox Profile [" + profileName + "]");
                        proxies.addElement(p);
                    }

                    if (props.containsKey("network.proxy.http")) {
                        p = createProxyInfo("http=" + props.get("network.proxy.http") + ":" + props.get("network.proxy.http_port"),
                                            "Firefox Profile [" + profileName + "]");
                        proxies.addElement(p);
                    }

                    if (props.containsKey("network.proxy.ssl")) {
                        p = createProxyInfo("ssl=" + props.get("network.proxy.ssl") + ":" + props.get("network.proxy.ssl_port"),
                                            "Firefox Profile [" + profileName + "]");
                        proxies.addElement(p);
                    }

                    if (props.containsKey("network.proxy.socks")) {
                        p = createProxyInfo("socks=" + props.get("network.proxy.socks") + ":"
                                        + props.get("network.proxy.socks_port"), "Firefox Profile [" + profileName + "]");
                        proxies.addElement(p);
                    }

                    if (props.containsKey("network.proxy.no_proxies_on")) {

                        StringTokenizer tokens = new StringTokenizer(props.getProperty("network.proxy.no_proxies_on"), ",");

                        while (tokens.hasMoreTokens()) {
                            bypassAddr.addElement(((String) tokens.nextToken()).trim());
                        }

                    }
                }
            }

            BrowserProxySettings bps = new BrowserProxySettings();

            bps.browser = "Mozilla Firefox";

            bps.proxies = new ProxyInfo[proxies.size()];
            proxies.copyInto(bps.proxies);

            bps.bypassAddr = new String[bypassAddr.size()];
            bypassAddr.copyInto(bps.bypassAddr);

            return bps;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -