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

📄 frameappli.java

📁 SOCK VIA HTTP是通过HTTP建立通道的SOCK
💻 JAVA
字号:
/*This file is part of Socks via HTTP.This package is free software; you can redistribute it and/or modifyit under the terms of the GNU General Public License as published bythe Free Software Foundation; either version 2 of the License, or(at your option) any later version.Socks via HTTP is distributed in the hope that it will be useful,but WITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See theGNU General Public License for more details.You should have received a copy of the GNU General Public Licensealong with Socks via HTTP; if not, write to the Free SoftwareFoundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA*/// Title :        FrameAppli.java// Version :      0.40// Copyright :    Copyright (c) 2001// Author :       Florent CUETO (fcueto@wanadoo.fr)// Description :  GUIpackage socks4;import java.awt.*;import java.awt.event.*;public class FrameAppli extends Frame implements Output{  private static final String PROPERTIES_FILE = "socks4.init";  private java.text.SimpleDateFormat dateFormat = new java.text.SimpleDateFormat("[HH:mm]");  private ConnectionServer srv = null;  TextField textField1 = new TextField();  Label label1 = new Label();  Label label2 = new Label();  TextField textField2 = new TextField();  Checkbox checkbox1 = new Checkbox();  Label label3 = new Label();  Label label4 = new Label();  TextField textField3 = new TextField();  TextField textField4 = new TextField();  Button button1 = new Button();  Button button2 = new Button();  TextField textField5 = new TextField();  Label label5 = new Label();  Label label6 = new Label();  TextField textField6 = new TextField();  TextArea textArea1 = new TextArea();  Button button3 = new Button();  Checkbox checkbox2 = new Checkbox();  Checkbox checkbox3 = new Checkbox();  TextField textField7 = new TextField();  Label label7 = new Label();  TextField textField8 = new TextField();  Label label8 = new Label();  Button button4 = new Button();  public FrameAppli()  {    try    {      jbInit();    }    catch(Exception e)    {      e.printStackTrace();    }    initIconCorner("icon.jpg");    Log.output = this;    // Welcome message    Log.printLog(Const.APPLICATION_NAME + " v" + Const.APPLICATION_VERSION + " starting...");    initProp();    Log.printLog(Const.APPLICATION_NAME + " v" + Const.APPLICATION_VERSION + " ready...");  }  private void jbInit() throws Exception  {    this.setSize(760, 386);    textField1.setBounds(new Rectangle(56, 38, 331, 26));    this.setLayout(null);    label1.setText("URL");    label1.setBounds(new Rectangle(17, 38, 35, 25));    label2.setText("PORT");    label2.setBounds(new Rectangle(13, 77, 38, 24));    textField2.setBounds(new Rectangle(55, 77, 62, 25));    checkbox1.setBackground(Color.lightGray);    checkbox1.setLabel("Use proxy");    checkbox1.setBounds(new Rectangle(32, 168, 103, 28));    checkbox1.addItemListener(new java.awt.event.ItemListener()    {      public void itemStateChanged(ItemEvent e)      {        checkbox1_itemStateChanged(e);      }    });    label3.setText("Proxy Host");    label3.setBounds(new Rectangle(11, 200, 65, 23));    label4.setText("Proxy Port");    label4.setBounds(new Rectangle(9, 231, 65, 23));    textField3.setEnabled(false);    textField3.setBounds(new Rectangle(77, 197, 305, 28));    textField4.setEnabled(false);    textField4.setBounds(new Rectangle(77, 229, 65, 29));    button1.setLabel("Start");    button1.setBounds(new Rectangle(308, 344, 84, 29));    button1.addActionListener(new java.awt.event.ActionListener()    {      public void actionPerformed(ActionEvent e)      {        button1_actionPerformed(e);      }    });    this.addWindowListener(new java.awt.event.WindowAdapter()    {      public void windowClosing(WindowEvent e)      {        this_windowClosing(e);      }    });    this.setBackground(Color.lightGray);    this.setTitle(Const.APPLICATION_NAME + " v" + Const.APPLICATION_VERSION);    this.setResizable(false);    button2.setEnabled(false);    button2.setLabel("Stop");    button2.setBounds(new Rectangle(215, 344, 84, 29));    button2.addActionListener(new java.awt.event.ActionListener()    {      public void actionPerformed(ActionEvent e)      {        button2_actionPerformed(e);      }    });    textField5.setEnabled(false);    textField5.setBounds(new Rectangle(77, 262, 305, 28));    label5.setText("Username");    label5.setBounds(new Rectangle(11, 265, 65, 23));    label6.setText("Password");    label6.setBounds(new Rectangle(9, 297, 65, 23));    textField6.setEchoChar('*');    textField6.setEnabled(false);    textField6.setBounds(new Rectangle(77, 294, 305, 29));    textArea1.setEditable(false);    textArea1.setBounds(new Rectangle(402, 37, 340, 301));    button3.setLabel("Clear");    button3.setBounds(new Rectangle(658, 344, 84, 29));    button3.addActionListener(new java.awt.event.ActionListener()    {      public void actionPerformed(ActionEvent e)      {        button3_actionPerformed(e);      }    });    checkbox2.setBackground(Color.lightGray);    checkbox2.setLabel("Only allow connections from localhost");    checkbox2.setBounds(new Rectangle(138, 75, 248, 28));    checkbox2.addItemListener(new java.awt.event.ItemListener()    {      public void itemStateChanged(ItemEvent e)      {        checkbox2_itemStateChanged(e);      }    });    checkbox3.setBackground(Color.lightGray);    checkbox3.setEnabled(false);    checkbox3.setLabel("Proxy needs authentication");    checkbox3.setBounds(new Rectangle(165, 230, 179, 28));    checkbox3.addItemListener(new java.awt.event.ItemListener()    {      public void itemStateChanged(ItemEvent e)      {        checkbox3_itemStateChanged(e);      }    });    textField7.setBounds(new Rectangle(55, 118, 120, 29));    label7.setText("User");    label7.setBounds(new Rectangle(19, 121, 33, 24));    textField8.setEchoChar('*');    textField8.setBounds(new Rectangle(269, 118, 115, 30));    label8.setText("Password");    label8.setBounds(new Rectangle(206, 122, 63, 24));    button4.setLabel("About");    button4.setBounds(new Rectangle(568, 345, 84, 29));    button4.addActionListener(new java.awt.event.ActionListener()    {      public void actionPerformed(ActionEvent e)      {        button4_actionPerformed(e);      }    });    this.add(textField1, null);    this.add(label2, null);    this.add(textField2, null);    this.add(label1, null);    this.add(textArea1, null);    this.add(checkbox2, null);    this.add(checkbox1, null);    this.add(label3, null);    this.add(textField3, null);    this.add(textField4, null);    this.add(textField5, null);    this.add(label5, null);    this.add(textField6, null);    this.add(label6, null);    this.add(label4, null);    this.add(checkbox3, null);    this.add(button3, null);    this.add(button1, null);    this.add(button2, null);    this.add(textField7, null);    this.add(label7, null);    this.add(textField8, null);    this.add(label8, null);    this.add(button4, null);  }  void button1_actionPerformed(ActionEvent e)  {    // START Button    // Disable the start button    button1.setEnabled(false);    // Start the server    startServer();    // Enable the stop button    button2.setEnabled(true);  }  void this_windowClosing(WindowEvent e)  {    // The user close the window    // Stop the server    stopServer();    // Exit    System.exit(0);  }  void checkbox1_itemStateChanged(ItemEvent e)  {    textField3.setEnabled(checkbox1.getState());    textField4.setEnabled(checkbox1.getState());    // Enable the "proxy needs authentication" checkbox    checkbox3.setEnabled(checkbox1.getState());    textField5.setEnabled(checkbox1.getState() && checkbox3.getState());    textField6.setEnabled(checkbox1.getState() && checkbox3.getState());  }  void button2_actionPerformed(ActionEvent e)  {    // STOP Button    // Disable the stop button    button2.setEnabled(false);    // Stop the server    stopServer();    // Enable the start button    button1.setEnabled(true);  }  public void stopServer()  {    if (srv == null) return;    // Stop the server    Log.printLog("Stopping server...");    srv.listening = false;    try    {      srv.join(60000);    }    catch(Exception ex){}    srv = null;    Log.printLog("Server stopped...");  }  public void startServer()  {    // Start the server    // Proxy on    if (checkbox1.getState())    {      System.getProperties().put("proxySet", "true");      System.getProperties().put("proxyHost", textField3.getText());      System.getProperties().put("proxyPort", textField4.getText());    }    else    {      System.getProperties().remove("proxySet");      System.getProperties().remove("proxyHost");      System.getProperties().remove("proxyPort");    }    int SOCKS_PORT = Integer.parseInt(textField2.getText());    String VIA_HTTP_URL = textField1.getText();    String proxyUser = (checkbox1.getState() && checkbox3.getState() ? textField5.getText() : null);    String proxyPassword = (checkbox1.getState() && checkbox3.getState() ? textField6.getText() : null);    String httpServerUser = textField7.getText();    String httpServerPassword = textField8.getText();    Log.printLog("Starting server on port " + SOCKS_PORT + (checkbox1.getState() ? " (Using" + (proxyUser != null ? " authenticated" : "") + " Proxy)" : "") + "...");    srv = new ConnectionServer(SOCKS_PORT, VIA_HTTP_URL, proxyUser, proxyPassword, checkbox2.getState(), httpServerUser, httpServerPassword);    srv.start();    Log.printLog("Server started...");  }  void button3_actionPerformed(ActionEvent e)  {    // CLEAR Button    textArea1.setText("");  }  public synchronized void println(String line)  {    textArea1.append(dateFormat.format(new java.util.Date()) + " " + line + "\n");  }  void checkbox2_itemStateChanged(ItemEvent e)  {    // Checkbox "only allow connection from localhost"  }  void checkbox3_itemStateChanged(ItemEvent e)  {    // Checkbox "proxy needs authentication"    textField5.setEnabled(checkbox3.getState());    textField6.setEnabled(checkbox3.getState());  }  public void initProp()  {    // Init the application with the .properties file    Log.printLog("Reading properties file...");    // Read the file    textField1.setText(PropertiesFileReader.getPropertyStringValue(PROPERTIES_FILE, "socks.http.servlet.url"));    textField2.setText(PropertiesFileReader.getPropertyStringValue(PROPERTIES_FILE, "socks.server.port"));    checkbox2.setState(new Boolean(PropertiesFileReader.getPropertyStringValue(PROPERTIES_FILE, "socks.listen.localhost")).booleanValue());    checkbox1.setState(new Boolean(PropertiesFileReader.getPropertyStringValue(PROPERTIES_FILE, "socks.proxy")).booleanValue());    textField3.setText(PropertiesFileReader.getPropertyStringValue(PROPERTIES_FILE, "socks.proxy.host"));    textField4.setText(PropertiesFileReader.getPropertyStringValue(PROPERTIES_FILE, "socks.proxy.port"));    checkbox3.setState(new Boolean(PropertiesFileReader.getPropertyStringValue(PROPERTIES_FILE, "socks.proxy.authentication")).booleanValue());    textField5.setText(PropertiesFileReader.getPropertyStringValue(PROPERTIES_FILE, "socks.proxy.user"));    textField6.setText(PropertiesFileReader.getPropertyStringValue(PROPERTIES_FILE, "socks.proxy.password"));    textField7.setText(PropertiesFileReader.getPropertyStringValue(PROPERTIES_FILE, "socks.httpserver.user"));    textField8.setText(PropertiesFileReader.getPropertyStringValue(PROPERTIES_FILE, "socks.httpserver.password"));    // Set the states    textField3.setEnabled(checkbox1.getState());    textField4.setEnabled(checkbox1.getState());    checkbox3.setEnabled(checkbox1.getState());    textField5.setEnabled(checkbox1.getState() && checkbox3.getState());    textField6.setEnabled(checkbox1.getState() && checkbox3.getState());    // Init OK    Log.printLog("Properties file processed...");  }  public void initIconCorner(String iconPath)  {    Image cornerImage = Toolkit.getDefaultToolkit().getImage(iconPath);    this.setIconImage(cornerImage);  }  void button4_actionPerformed(ActionEvent e)  {    // About    Log.printLog(Const.APPLICATION_NAME + " v" + Const.APPLICATION_VERSION + " by " + Const.AUTHOR_NAME);    Log.printLog("Contact " + Const.AUTHOR_NAME + " at " + Const.AUTHOR_EMAIL);    Log.printLog("Feedback wanted. Thank you.");  }}

⌨️ 快捷键说明

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