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

📄 extensioninstaller.java

📁 这是linux下ssl vpn的实现程序
💻 JAVA
字号:
/*
 *  SSL-Explorer
 *
 *  Copyright (C) 2003-2006 3SP LTD. All Rights Reserved
 *
 *  This program is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU General Public License
 *  as published by the Free Software Foundation; either version 2 of
 *  the License, or (at your option) any later version.
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public
 *  License along with this program; if not, write to the Free Software
 *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */
			
package com.sslexplorer.extensions;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.sslexplorer.boot.Util;
import com.sslexplorer.core.CoreUtil;

public class ExtensionInstaller {
    private List ops;
    final static Log log = LogFactory.getLog(ExtensionInstaller.class);
    private ExtensionBundle bundle;

    public ExtensionInstaller(ExtensionBundle bundle) {
        this.bundle = bundle;
        ops = new ArrayList();
    }

    public ExtensionBundle getBundle() {
        return bundle;
    }

    public void addOp(ExtensionInstallOp op) {
        ops.add(op);
    }

    public static File checkFile(File f) throws IOException {
        /*
         * TODO Make sure the file is ok for use (e.g. not a file somewhere
         * outside of SSL-Explorers tree)
         */
        return f;
    }

    public void doInstall() throws Exception {
        if (ops.size() == 0) {
        	if (log.isInfoEnabled())
        		log.info("Bundle " + bundle.getName() + " has no installer script.");
        } else {
            if (!"true".equalsIgnoreCase(System.getProperty("sslexplorer.useDevConfig", "false"))) {
            	if (log.isInfoEnabled())
            		log.info("Starting installer for " + bundle.getName());
                for (Iterator i = ops.iterator(); i.hasNext();) {
                    ExtensionInstallOp op = (ExtensionInstallOp) i.next();
                    op.doOp(this);
                }
                if (log.isInfoEnabled())
                	log.info("Completed installation for " + bundle.getName());

            } else {
                log.warn("SSL-Explorer is running in development mode, so the " +
                        "installer for " + bundle.getName() + " "
                          + "will NOT be run. If this extension requires are "
                          + "addditional files you will have to install " + "them manually.");
            }
        }
    }

    public static interface ExtensionInstallOp {
        public void doOp(ExtensionInstaller install) throws Exception;
    }

    public static class MkdirInstallOp implements ExtensionInstallOp {
        private String path;

        public MkdirInstallOp(String path) throws IllegalArgumentException {
            this.path = path;
        }

        public void doOp(ExtensionInstaller install) throws Exception {
            path = CoreUtil.platformPath(CoreUtil.doStandardReplacements(install.getBundle(), path));
            File f = checkFile(new File(path));
            if (log.isInfoEnabled())
            	log.info("Creating directory " + f.getAbsolutePath());
            f.mkdirs();
        }
    }

    public static class RmInstallOp implements ExtensionInstallOp {
        private String path;

        public RmInstallOp(String path) throws IllegalArgumentException {
            this.path = path;
        }

        public void doOp(ExtensionInstaller install) throws Exception {
            path = CoreUtil.platformPath(CoreUtil.doStandardReplacements(install.getBundle(), path));
            File f = checkFile(new File(path));
            Util.delTree(f);
        }
    }

    public static class CpInstallOp implements ExtensionInstallOp {
        private String from;
        private String to;
        private String toDir;

        public CpInstallOp(String from, String to, String toDir) throws IllegalArgumentException {
            this.from = from;
            this.to = to;
            this.toDir = toDir;
        }

        public void doOp(ExtensionInstaller install) throws Exception {
            from = CoreUtil.platformPath(CoreUtil.doStandardReplacements(install.getBundle(), from));
            File f = checkFile(new File(from));
            if (to != null) {
                File t = checkFile(new File(CoreUtil.platformPath(CoreUtil.doStandardReplacements(install.getBundle(), to))));
                if (f.isDirectory()) {
                    throw new Exception("Cannot copy directory to a file");
                }
                Util.copy(f, t);
            } else if (toDir != null) {
                Util.copyToDir(f, checkFile(new File(CoreUtil.doStandardReplacements(install.getBundle(), toDir))), false, true);
            }
        }
    }
}

⌨️ 快捷键说明

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