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

📄 cvsssh2preferencepage.java

📁 This archive file is for Eclipse 2.1.* and Eclipse 3.0 M5(or previous) users
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
    new TableColumn(table, SWT.NULL);    new TableColumn(table, SWT.NULL);    TableColumn[] columns = table.getColumns();    columns[0].setText(Policy.bind("CVSSSH2PreferencePage.134"));  //$NON-NLS-1$    columns[1].setText(Policy.bind("CVSSSH2PreferencePage.135"));  //$NON-NLS-1$    columns[2].setText(Policy.bind("CVSSSH2PreferencePage.136"));  //$NON-NLS-1$    viewer.setColumnProperties(new String[] {      Policy.bind("CVSSSH2PreferencePage.134"),  //$NON-NLS-1$       Policy.bind("CVSSSH2PreferencePage.135"),  //$NON-NLS-1$       Policy.bind("CVSSSH2PreferencePage.136")}); //$NON-NLS-1$    viewer.setLabelProvider(new TableLabelProvider());    viewer.setContentProvider(new IStructuredContentProvider() {	public void dispose() {	}	public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {	}	public Object[] getElements(Object inputElement) {	  if (inputElement == null) return null;	  return (Object[])inputElement;	}      });    TableLayout tl = new TableLayout();    tl.addColumnData(new ColumnWeightData(20));    tl.addColumnData(new ColumnWeightData(10));    tl.addColumnData(new ColumnWeightData(70));    table.setLayout(tl);	    Composite buttons = new Composite(group, SWT.NULL);    buttons.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_BEGINNING));    layout = new GridLayout();    layout.marginHeight = 0;    layout.marginWidth = 0;    buttons.setLayout(layout);    addHostKeyButton = new Button(buttons, SWT.PUSH);    addHostKeyButton.setText(Policy.bind("CVSSSH2PreferencePage.137"));  //$NON-NLS-1$    gd = new GridData();    gd.horizontalAlignment = GridData.FILL;    gd.heightHint = convertVerticalDLUsToPixels(IDialogConstants.BUTTON_HEIGHT);    int widthHint = convertHorizontalDLUsToPixels(IDialogConstants.BUTTON_WIDTH);    gd.widthHint = Math.max(widthHint, addHostKeyButton.computeSize(SWT.DEFAULT, SWT.DEFAULT, true).x);    addHostKeyButton.setLayoutData(gd);    addHostKeyButton.setEnabled(false);    addHostKeyButton.addListener(SWT.Selection, new Listener() {	public void handleEvent(Event e) {	  //addHostKey();	}      });    removeHostKeyButton = new Button(buttons, SWT.PUSH);    removeHostKeyButton.setText(Policy.bind("CVSSSH2PreferencePage.138"));  //$NON-NLS-1$    gd = new GridData();    gd.horizontalAlignment = GridData.FILL;    gd.heightHint = convertVerticalDLUsToPixels(IDialogConstants.BUTTON_HEIGHT);    widthHint = convertHorizontalDLUsToPixels(IDialogConstants.BUTTON_WIDTH);    gd.widthHint = Math.max(widthHint, addHostKeyButton.computeSize(SWT.DEFAULT, SWT.DEFAULT, true).x);    removeHostKeyButton.setLayoutData(gd);    removeHostKeyButton.setEnabled(false);    removeHostKeyButton.addListener(SWT.Selection, new Listener() {	public void handleEvent(Event e) {	  removeHostKey();	}      });	        Dialog.applyDialogFont(parent);	    JSchSession.loadKnownHosts();    viewer.setInput(JSchSession.getJSch().getHostKeys());    handleSelection();    return group;  }    private void handleSelection() {    boolean empty = viewer.getSelection().isEmpty();    removeHostKeyButton.setEnabled(!empty);  }  private void removeHostKey(){    JSch jsch=JSchSession.getJSch();    IStructuredSelection selection = (IStructuredSelection)viewer.getSelection();    for (Iterator iterator = selection.iterator(); iterator.hasNext();) {      KnownHosts.HostKey hostkey = (KnownHosts.HostKey) iterator.next();      jsch.removeHostKey(hostkey.getHost(), hostkey.getType());      viewer.remove(hostkey);    }		  }  private void export_via_sftp(String user, String host, int port, String target, byte[] pkey) throws JSchException{    try{      /*      int i=0;      String authorized_keys=target;      String dir="";      String separator="/";      i=target.lastIndexOf("/");      if(i<0){	i=target.lastIndexOf("\\");	if(i>=0){ separator="\\"; }      }      else{      }      if(i>=0){	authorized_keys=target.substring(i+1);	dir=target.substring(0, i+1);      }      */      IProgressMonitor pm=new org.eclipse.core.runtime.NullProgressMonitor();      Session session=JSchSession.getSession(null, user, "", host, port, new JSchSession.ResponsiveSocketFacory(pm)); //$NON-NLS-1$      if(session.getServerVersion().indexOf("OpenSSH")==-1){ //$NON-NLS-1$      	setErrorMessage(Policy.bind("CVSSSH2PreferencePage.110")); //$NON-NLS-1$    	return;      }      Channel channel=session.openChannel("sftp"); //$NON-NLS-1$      channel.connect();      ChannelSftp c=(ChannelSftp)channel;      String pwd=c.pwd();      SftpATTRS attr=null;      try{ attr=c.stat(".ssh"); } //$NON-NLS-1$      catch(SftpException ee){ }      if(attr==null){        try{ c.mkdir(".ssh"); } //$NON-NLS-1$	catch(SftpException ee){	  setErrorMessage(ee.message);	  return;	}      }      try{ c.cd(".ssh"); } //$NON-NLS-1$      catch(SftpException ee){	setErrorMessage(ee.message);	return;      }      try{	ByteArrayInputStream bis=new ByteArrayInputStream(pkey);	c.put(bis, "authorized_keys", null, ChannelSftp.APPEND); //$NON-NLS-1$	bis.close();	checkPermission(c, "authorized_keys"); //$NON-NLS-1$	checkPermission(c, ".");                // .ssh //$NON-NLS-1$	c.cd("..");                              //$NON-NLS-1$	checkPermission(c, ".");                //  home directory //$NON-NLS-1$      }      catch(SftpException ee){	//setErrorMessage(debug+ee.message);      }      MessageDialog.openInformation(getShell(),				    Policy.bind("CVSSSH2PreferencePage.information"),  //$NON-NLS-1$				    Policy.bind("CVSSSH2PreferencePage.109")+ //$NON-NLS-1$				    (user+"@"+host+(port==22 ? "" : ":"+port)+":~/.ssh/authorized_keys")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$      c.disconnect();      //session.disconnect();    }    catch(IOException eee){      setErrorMessage(eee.toString());    }  }  private void checkPermission(ChannelSftp c, String path) throws SftpException{    SftpATTRS attr=c.stat(path);    int permissions=attr.getPermissions();    if((permissions&00022)!=0){      permissions&=~00022;      c.chmod(permissions,path);    } 	  }  private void updateControls() {    boolean enable=enableProxy.getSelection();    proxyTypeLabel.setEnabled(enable);    proxyTypeCombo.setEnabled(enable);    proxyPortLabel.setEnabled(enable);    proxyPortText.setEnabled(enable);    proxyHostLabel.setEnabled(enable);    proxyHostText.setEnabled(enable);    enableAuth.setEnabled(enable);    enable&=enableAuth.getSelection();    proxyUserLabel.setEnabled(enable);    proxyUserText.setEnabled(enable);    proxyPassLabel.setEnabled(enable);    proxyPassText.setEnabled(enable);    enable=(kpair!=null);    publicKeylabel.setEnabled(enable);    publicKeyText.setEnabled(enable);    keyFingerPrintLabel.setEnabled(enable);    keyFingerPrintText.setEnabled(enable);    keyCommentLabel.setEnabled(enable);    keyCommentText.setEnabled(enable);    keyPassphrase1Label.setEnabled(enable);    keyPassphrase1Text.setEnabled(enable);    keyPassphrase2Label.setEnabled(enable);    keyPassphrase2Text.setEnabled(enable);    keyExport.setEnabled(enable);    saveKeyPair.setEnabled(enable);  }  public void init(IWorkbench workbench) {//    super.init(workbench);//    initControls();  }  public void initialize() {    initControls();  }  public static void initDefaults(IPreferenceStore store) {    setDefault(store, KEY_SSH2HOME, JSchSession.default_ssh_home);    setDefault(store, KEY_PRIVATEKEY, privatekeys);    setDefault(store, KEY_PROXY_TYPE, HTTP);    setDefault(store, KEY_PROXY_PORT, HTTP_DEFAULT_PORT);    setDefault(store, KEY_PROXY_AUTH, "false"); //$NON-NLS-1$    setDefault(store, KEY_PROXY_USER, ""); //$NON-NLS-1$    setDefault(store, KEY_PROXY_PASS, ""); //$NON-NLS-1$  }  private static void setDefault(IPreferenceStore store, String key, String value){    store.setDefault(key, value);    if(store.getString(key).length()==0)      store.setValue(key, value);  }  private void initControls(){    IPreferenceStore store=CVSSSH2Plugin.getDefault().getPreferenceStore();    ssh2HomeText.setText(store.getString(KEY_SSH2HOME));    privateKeyText.setText(store.getString(KEY_PRIVATEKEY));    useProxy=store.getString(KEY_PROXY).equals("true"); //$NON-NLS-1$    enableProxy.setSelection(useProxy);    proxyHostText.setText(store.getString(KEY_PROXY_HOST));    proxyPortText.setText(store.getString(KEY_PROXY_PORT));    proxyTypeCombo.select(store.getString(KEY_PROXY_TYPE).equals(HTTP)?0:1);    useAuth=store.getString(KEY_PROXY_AUTH).equals("true"); //$NON-NLS-1$    enableAuth.setSelection(useAuth);    proxyUserText.setText(store.getString(KEY_PROXY_USER));    proxyPassText.setText(store.getString(KEY_PROXY_PASS));    proxyPassText.setEchoChar('*');    updateControls();  }  public boolean performOk() {    boolean result=super.performOk();    if(result){    	setErrorMessage(null);      String home=ssh2HomeText.getText();      File _home=new File(home);      if(!_home.exists()){	MessageBox mb=new MessageBox(getShell(),SWT.YES|SWT.NO|SWT.ICON_QUESTION);	mb.setText(Policy.bind("CVSSSH2PreferencePage.question")); //$NON-NLS-1$	mb.setMessage(home+Policy.bind("CVSSSH2PreferencePage.99")); //$NON-NLS-1$	if(mb.open()==SWT.YES){	  if(!(_home.mkdirs())){	  setErrorMessage(Policy.bind("CVSSSH2PreferencePage.100")+home); //$NON-NLS-1$	  return false;	  }	}      }      if(!isValidPort(proxyPortText.getText())){	return false;      }      IPreferenceStore store=CVSSSH2Plugin.getDefault().getPreferenceStore();      store.setValue(KEY_SSH2HOME, home);      store.setValue(KEY_PRIVATEKEY, privateKeyText.getText());      store.setValue(KEY_PROXY, enableProxy.getSelection());      store.setValue(KEY_PROXY_TYPE, proxyTypeCombo.getText());      store.setValue(KEY_PROXY_HOST, proxyHostText.getText());      store.setValue(KEY_PROXY_PORT, proxyPortText.getText());      store.setValue(KEY_PROXY_AUTH, enableAuth.getSelection());      store.setValue(KEY_PROXY_USER, proxyUserText.getText());      store.setValue(KEY_PROXY_PASS, proxyPassText.getText());          }    CVSSSH2Plugin.getDefault().savePluginPreferences();    return result;  }  private boolean isValidPort(String port){    int i=-1;    try {      i=Integer.parseInt(port);    }    catch (NumberFormatException ee) {      setErrorMessage(Policy.bind("CVSSSH2PreferencePage.103")); //$NON-NLS-1$      return false;    }    if((i < 0) || (i > 65535)){      setErrorMessage(Policy.bind("CVSSSH2PreferencePage.104")); //$NON-NLS-1$      return false;    }    return true;  }  public void performApply() {    super.performApply();    setErrorMessage(null);        String home=ssh2HomeText.getText();    File _home=new File(home);    if(!_home.exists()){      MessageBox mb=new MessageBox(getShell(),SWT.YES|SWT.NO|SWT.ICON_QUESTION);      mb.setText(Policy.bind("CVSSSH2PreferencePage.question")); //$NON-NLS-1$            mb.setMessage(home+Policy.bind("CVSSSH2PreferencePage.101")); //$NON-NLS-1$      if(mb.open()==SWT.YES){	if(!(_home.mkdirs())){		setErrorMessage(Policy.bind("CVSSSH2PreferencePage.102")+home); //$NON-NLS-1$		return;	}      }    }    if(!isValidPort(proxyPortText.getText())){      return;    }        IPreferenceStore store=CVSSSH2Plugin.getDefault().getPreferenceStore();    store.setValue(KEY_SSH2HOME, ssh2HomeText.getText());    store.setValue(KEY_PRIVATEKEY, privateKeyText.getText());    store.setValue(KEY_PROXY, enableProxy.getSelection());    store.setValue(KEY_PROXY_TYPE, proxyTypeCombo.getText());    store.setValue(KEY_PROXY_HOST, proxyHostText.getText());    store.setValue(KEY_PROXY_PORT, proxyPortText.getText());    store.setValue(KEY_PROXY_AUTH, enableAuth.getSelection());    store.setValue(KEY_PROXY_USER, proxyUserText.getText());    store.setValue(KEY_PROXY_PASS, proxyPassText.getText());  }  protected void performDefaults(){    super.performDefaults();    enableProxy.setSelection(false);    proxyHostText.setText(""); //$NON-NLS-1$    proxyPortText.setText(HTTP_DEFAULT_PORT);    proxyTypeCombo.select(0);    enableAuth.setSelection(false);    proxyUserText.setText(""); //$NON-NLS-1$    proxyPassText.setText(""); //$NON-NLS-1$    updateControls();  }  protected void createSpacer(Composite composite, int columnSpan) {    Label label=new Label(composite, SWT.NONE);    GridData gd=new GridData();    gd.horizontalSpan=columnSpan;    label.setLayoutData(gd);  }}class ExportDialog extends Dialog {  protected Text field;  protected String target=null;  protected String title=null;  protected String message=null;  public ExportDialog(Shell parentShell, String title, String message) {    super(parentShell);    this.title=title;    this.message=message;  }  protected void configureShell(Shell newShell) {    super.configureShell(newShell);    newShell.setText(title);  }  public void create() {    super.create();    field.setFocus();  }  protected Control createDialogArea(Composite parent) {  	  	parent = new Composite(parent, SWT.NONE);	GridLayout layout = new GridLayout();	layout.numColumns = 1;		parent.setLayout(layout);	parent.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));	    Composite main=new Composite(parent, SWT.NONE);    layout=new GridLayout();    layout.numColumns=3;    main.setLayout(layout);    main.setLayoutData(new GridData(GridData.FILL_BOTH));	    if (message!=null) {      Label messageLabel=new Label(main, SWT.WRAP);      messageLabel.setText(message);      GridData data=new GridData(GridData.FILL_HORIZONTAL);      data.horizontalSpan=3;      messageLabel.setLayoutData(data);    }    createTargetFields(main);    Dialog.applyDialogFont(main);    return main;  }  protected void createTargetFields(Composite parent) {    new Label(parent, SWT.NONE).setText(Policy.bind("CVSSSH2PreferencePage.125")); //$NON-NLS-1$		    field=new Text(parent, SWT.BORDER);    GridData data=new GridData(GridData.FILL_HORIZONTAL);    data.widthHint=convertHorizontalDLUsToPixels(IDialogConstants.ENTRY_FIELD_WIDTH);    data.horizontalSpan=2;    field.setLayoutData(data);  }  public String getTarget() {    return target;  }  protected void okPressed() {    String _target=field.getText();    if(_target==null || _target.length()==0){      return;    }    target=_target;    super.okPressed();  }  protected void cancelPressed() {    target=null;    super.cancelPressed();  }}class PassphrasePrompt implements Runnable{  private String message;  private String passphrase;  PassphrasePrompt(String message){    this.message=message;  }  public void run(){    Display display=Display.getCurrent();    Shell shell=new Shell(display);    PassphraseDialog dialog=new PassphraseDialog(shell, message);    dialog.open();    shell.dispose();    passphrase=dialog.getPassphrase();  }  public String getPassphrase(){    return passphrase;  }}

⌨️ 快捷键说明

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