Search in sources :

Example 26 with UIManager

use of com.biglybt.pif.ui.UIManager in project BiglyBT by BiglySoftware.

the class CoreImpl method executeInternalCloseAction.

private void executeInternalCloseAction(final boolean obey_reset, final boolean download_trigger, final String action, final String reason) {
    // prevent immediate retriggering if user aborts
    ca_last_time_downloading = -1;
    ca_last_time_seeding = -1;
    String type_str = reason == null ? MessageText.getString(download_trigger ? "core.shutdown.dl" : "core.shutdown.se") : reason;
    String action_str = MessageText.getString("ConfigView.label.stop." + action);
    String message = MessageText.getString("core.shutdown.alert", new String[] { action_str, type_str });
    UIFunctions ui_functions = UIFunctionsManager.getUIFunctions();
    if (ui_functions != null) {
        ui_functions.forceNotify(UIFunctions.STATUSICON_NONE, null, message, null, new Object[0], -1);
    }
    Logger.log(new LogAlert(LogAlert.UNREPEATABLE, LogEvent.LT_INFORMATION, message));
    if (COConfigurationManager.getBooleanParameter("Prompt To Abort Shutdown")) {
        UIManager ui_manager = StaticUtilities.getUIManager(30 * 1000);
        if (ui_manager != null) {
            Map<String, Object> options = new HashMap<>();
            options.put(UIManager.MB_PARAM_AUTO_CLOSE_MS, 30 * 1000);
            if (ui_manager.showMessageBox("core.shutdown.prompt.title", "core.shutdown.prompt.msg", UIManagerEvent.MT_OK_DEFAULT | UIManagerEvent.MT_CANCEL, options) == UIManagerEvent.MT_CANCEL) {
                return;
            }
        }
    }
    executeCloseActionSupport(obey_reset, download_trigger, action, reason);
}
Also used : UIFunctions(com.biglybt.ui.UIFunctions) UIManager(com.biglybt.pif.ui.UIManager) LogAlert(com.biglybt.core.logging.LogAlert)

Example 27 with UIManager

use of com.biglybt.pif.ui.UIManager in project BiglyBT by BiglySoftware.

the class PairingManagerImpl method sendRequest.

private Map<String, Object> sendRequest(String command, Map<String, Object> payload) throws PairingException {
    try {
        Map<String, Object> request = new HashMap<>();
        CryptoManager cman = CryptoManagerFactory.getSingleton();
        String azid = Base32.encode(cman.getSecureID());
        payload.put("_azid", azid);
        try {
            String pk = Base32.encode(cman.getECCHandler().getPublicKey("pairing"));
            payload.put("_pk", pk);
        } catch (Throwable e) {
        }
        request.put("req", payload);
        String request_str = Base32.encode(BEncoder.encode(request));
        String sig = null;
        try {
            sig = Base32.encode(cman.getECCHandler().sign(request_str.getBytes("UTF-8"), "pairing"));
        } catch (Throwable e) {
        }
        String other_params = "&ver=" + UrlUtils.encode(Constants.AZUREUS_VERSION) + "&app=" + UrlUtils.encode(SystemProperties.getApplicationName()) + "&locale=" + UrlUtils.encode(MessageText.getCurrentLocale().toString());
        if (sig != null) {
            other_params += "&sig=" + sig;
        }
        URL target = new URL(SERVICE_URL + "/client/" + command + "?request=" + request_str + other_params);
        Properties http_properties = new Properties();
        http_properties.put(ClientIDGenerator.PR_URL, target);
        try {
            ClientIDManagerImpl.getSingleton().generateHTTPProperties(null, http_properties);
        } catch (ClientIDException e) {
            throw (new IOException(e.getMessage()));
        }
        target = (URL) http_properties.get(ClientIDGenerator.PR_URL);
        HttpURLConnection connection = (HttpURLConnection) target.openConnection();
        connection.setConnectTimeout(30 * 1000);
        InputStream is = connection.getInputStream();
        Map<String, Object> response = (Map<String, Object>) BDecoder.decode(new BufferedInputStream(is));
        synchronized (this) {
            Long min_retry = (Long) response.get("min_secs");
            if (min_retry != null) {
                min_update_period = min_retry.intValue() * 1000;
            }
            Long max_retry = (Long) response.get("max_secs");
            if (max_retry != null) {
                max_update_period = max_retry.intValue() * 1000;
            }
        }
        final String message = getString(response, "message");
        if (message != null) {
            if (last_message == null || !last_message.equals(message)) {
                last_message = message;
                try {
                    byte[] message_sig = (byte[]) response.get("message_sig");
                    AEVerifier.verifyData(message, message_sig);
                    new AEThread2("PairMsg", true) {

                        @Override
                        public void run() {
                            UIManager ui_manager = StaticUtilities.getUIManager(120 * 1000);
                            if (ui_manager != null) {
                                ui_manager.showMessageBox("pairing.server.warning.title", "!" + message + "!", UIManagerEvent.MT_OK);
                            }
                        }
                    }.start();
                } catch (Throwable e) {
                }
            }
        }
        String error = getString(response, "error");
        if (error != null) {
            throw (new PairingException(error));
        }
        setLastServerError(null);
        Map<String, Object> reply = (Map<String, Object>) response.get("rep");
        Long qr_v = (Long) reply.get("qr_v");
        if (qr_v != null) {
            if (qr_version != qr_v.longValue()) {
                qr_version = qr_v;
                COConfigurationManager.setParameter("pairing.qr.ver", qr_version);
            }
        }
        return (reply);
    } catch (Throwable e) {
        setLastServerError(Debug.getNestedExceptionMessage(e));
        if (e instanceof PairingException) {
            throw ((PairingException) e);
        }
        throw (new PairingException("invocation failed", e));
    }
}
Also used : BufferedInputStream(java.io.BufferedInputStream) InputStream(java.io.InputStream) UIManager(com.biglybt.pif.ui.UIManager) CryptoManager(com.biglybt.core.security.CryptoManager) IOException(java.io.IOException) ClientIDException(com.biglybt.pif.clientid.ClientIDException) BufferedInputStream(java.io.BufferedInputStream)

Example 28 with UIManager

use of com.biglybt.pif.ui.UIManager in project BiglyBT by BiglySoftware.

the class DeviceManagerImpl method importVuzeFile.

void importVuzeFile(Map map, boolean warn_user) {
    Map m = (Map) map.get("device");
    try {
        DeviceImpl device = DeviceImpl.importFromBEncodedMapStatic(this, m);
        DeviceImpl existing;
        synchronized (this) {
            existing = device_map.get(device.getID());
        }
        if (existing == null) {
            if (warn_user) {
                UIManager ui_manager = StaticUtilities.getUIManager(120 * 1000);
                String details = MessageText.getString("device.import.desc", new String[] { device.getName() });
                long res = ui_manager.showMessageBox("device.import.title", "!" + details + "!", UIManagerEvent.MT_YES | UIManagerEvent.MT_NO);
                if (res != UIManagerEvent.MT_YES) {
                    return;
                }
            }
            addDevice(device, false);
        } else {
            if (warn_user) {
                UIManager ui_manager = StaticUtilities.getUIManager(120 * 1000);
                String details = MessageText.getString("device.import.dup.desc", new String[] { existing.getName() });
                ui_manager.showMessageBox("device.import.dup.title", "!" + details + "!", UIManagerEvent.MT_OK);
            }
        }
    } catch (Throwable e) {
        Debug.out(e);
    }
}
Also used : UIManager(com.biglybt.pif.ui.UIManager)

Example 29 with UIManager

use of com.biglybt.pif.ui.UIManager in project BiglyBT by BiglySoftware.

the class CustomizationManagerImpl method initialize.

@Override
public void initialize() {
    synchronized (this) {
        if (initialised) {
            return;
        }
        initialised = true;
    }
    VuzeFileHandler.getSingleton().addProcessor(new VuzeFileProcessor() {

        @Override
        public void process(VuzeFile[] files, int expected_types) {
            for (int i = 0; i < files.length; i++) {
                VuzeFile vf = files[i];
                VuzeFileComponent[] comps = vf.getComponents();
                for (int j = 0; j < comps.length; j++) {
                    VuzeFileComponent comp = comps[j];
                    if (comp.getType() == VuzeFileComponent.COMP_TYPE_CUSTOMIZATION) {
                        try {
                            Map map = comp.getContent();
                            ((CustomizationManagerImpl) getSingleton()).importCustomization(map);
                            comp.setProcessed();
                        } catch (Throwable e) {
                            Debug.printStackTrace(e);
                        }
                    } else if (comp.getType() == VuzeFileComponent.COMP_TYPE_CONFIG_SETTINGS) {
                        try {
                            Map map = comp.getContent();
                            String name = new String((byte[]) map.get("name"));
                            UIManager ui_manager = StaticUtilities.getUIManager(120 * 1000);
                            String details = MessageText.getString("custom.settings.import", new String[] { name });
                            long res = ui_manager.showMessageBox("custom.settings.import.title", "!" + details + "!", UIManagerEvent.MT_YES | UIManagerEvent.MT_NO);
                            if (res == UIManagerEvent.MT_YES) {
                                Map<String, Object> config = (Map<String, Object>) map.get("settings");
                                int num_set = 0;
                                for (Map.Entry<String, Object> entry : config.entrySet()) {
                                    String key = entry.getKey();
                                    Object value = entry.getValue();
                                    if (value instanceof Long) {
                                        COConfigurationManager.setParameter(key, (Long) value);
                                    } else if (value instanceof byte[]) {
                                        COConfigurationManager.setParameter(key, (byte[]) value);
                                    } else if (value instanceof List) {
                                        COConfigurationManager.setParameter(key, (List) value);
                                    } else if (value instanceof Map) {
                                        COConfigurationManager.setParameter(key, (Map) value);
                                    } else {
                                        Debug.out("Unsupported entry: " + key + "=" + value);
                                    }
                                    num_set++;
                                }
                                Long l_restart = (Long) map.get("restart");
                                boolean restart = l_restart != null && l_restart != 0;
                                String restart_text = "";
                                if (restart) {
                                    restart_text = "\r\n\r\n" + MessageText.getString("ConfigView.section.security.restart.title");
                                }
                                String res_details = MessageText.getString("custom.settings.import.res", new String[] { String.valueOf(num_set), restart_text });
                                ui_manager.showMessageBox("custom.settings.import.res.title", "!" + res_details + "!", UIManagerEvent.MT_OK);
                            }
                            comp.setProcessed();
                        } catch (Throwable e) {
                            Debug.printStackTrace(e);
                        }
                    }
                }
            }
        }
    });
    File user_dir = FileUtil.getUserFile("custom");
    File app_dir = FileUtil.getApplicationFile("custom");
    loadCustomizations(app_dir);
    if (!user_dir.equals(app_dir)) {
        loadCustomizations(user_dir);
    }
    String active = COConfigurationManager.getStringParameter("customization.active.name", "");
    if (customization_file_map.get(active) == null) {
        // hmm, its been deleted or not set yet. look for new ones
        Iterator it = customization_file_map.keySet().iterator();
        while (it.hasNext()) {
            String name = (String) it.next();
            final String version_key = "customization.name." + name + ".version";
            String existing_version = COConfigurationManager.getStringParameter(version_key, "0");
            if (existing_version.equals("0")) {
                active = name;
                String version = ((String[]) customization_file_map.get(name))[0];
                COConfigurationManager.setParameter("customization.active.name", active);
                COConfigurationManager.setParameter(version_key, version);
                break;
            }
        }
    }
    synchronized (this) {
        current_customization_name = active;
    }
}
Also used : VuzeFileComponent(com.biglybt.core.vuzefile.VuzeFileComponent) UIManager(com.biglybt.pif.ui.UIManager) VuzeFileProcessor(com.biglybt.core.vuzefile.VuzeFileProcessor) VuzeFile(com.biglybt.core.vuzefile.VuzeFile) File(java.io.File) VuzeFile(com.biglybt.core.vuzefile.VuzeFile)

Example 30 with UIManager

use of com.biglybt.pif.ui.UIManager in project BiglyBT by BiglySoftware.

the class WebPlugin method initialize.

@Override
public void initialize(PluginInterface _plugin_interface) throws PluginException {
    plugin_interface = _plugin_interface;
    plugin_config = plugin_interface.getPluginconfig();
    Properties plugin_properties = plugin_interface.getPluginProperties();
    if (plugin_properties != null) {
        Object o = plugin_properties.get("plugin." + PR_ROOT_DIR.replaceAll(" ", "_"));
        if (o instanceof String) {
            properties.put(PR_ROOT_DIR, o);
        }
    }
    Boolean pr_enable = (Boolean) properties.get(PR_ENABLE);
    if (pr_enable != null) {
        CONFIG_ENABLE_DEFAULT = pr_enable.booleanValue();
    }
    Integer pr_port = (Integer) properties.get(PR_PORT);
    if (pr_port != null) {
        CONFIG_PORT_DEFAULT = pr_port.intValue();
    }
    String pr_bind_ip = (String) properties.get(PR_BIND_IP);
    if (pr_bind_ip != null) {
        CONFIG_BIND_IP_DEFAULT = pr_bind_ip.trim();
    }
    String pr_root_resource = (String) properties.get(PR_ROOT_RESOURCE);
    if (pr_root_resource != null) {
        CONFIG_ROOT_RESOURCE_DEFAULT = pr_root_resource;
    }
    String pr_home_page = (String) properties.get(PR_HOME_PAGE);
    if (pr_home_page != null) {
        CONFIG_HOME_PAGE_DEFAULT = pr_home_page;
    }
    String pr_root_dir = (String) properties.get(PR_ROOT_DIR);
    if (pr_root_dir != null) {
        CONFIG_ROOT_DIR_DEFAULT = pr_root_dir;
    }
    String pr_access = (String) properties.get(PR_ACCESS);
    if (pr_access != null) {
        CONFIG_ACCESS_DEFAULT = pr_access;
    }
    Boolean pr_enable_upnp = (Boolean) properties.get(PR_ENABLE_UPNP);
    if (pr_enable_upnp != null) {
        CONFIG_UPNP_ENABLE_DEFAULT = pr_enable_upnp.booleanValue();
    }
    Boolean pr_hide_resource_config = (Boolean) properties.get(PR_HIDE_RESOURCE_CONFIG);
    log = (LoggerChannel) properties.get(PR_LOG);
    if (log == null) {
        log = plugin_interface.getLogger().getChannel("WebPlugin");
    }
    Boolean prop_pairing_enable = (Boolean) properties.get(PR_ENABLE_PAIRING);
    if (prop_pairing_enable == null || prop_pairing_enable) {
        // default is based on sid availability
        p_sid = (String) properties.get(PR_PAIRING_SID);
    }
    UIManager ui_manager = plugin_interface.getUIManager();
    view_model = (BasicPluginViewModel) properties.get(PR_VIEW_MODEL);
    if (view_model == null) {
        view_model = ui_manager.createBasicPluginViewModel(plugin_interface.getPluginName());
    }
    String plugin_id = plugin_interface.getPluginID();
    String sConfigSectionID = "plugins." + plugin_id;
    view_model.setConfigSectionID(sConfigSectionID);
    view_model.getStatus().setText("Running");
    view_model.getActivity().setVisible(false);
    view_model.getProgress().setVisible(false);
    log.addListener(new LoggerChannelListener() {

        @Override
        public void messageLogged(int type, String message) {
            log(message + "\n");
        }

        @Override
        public void messageLogged(String str, Throwable error) {
            log(str + "\n");
            log(error.toString() + "\n");
        }

        private void log(String str) {
            UITextArea area = view_model.getLogArea();
            if (area != null) {
                area.appendText(str);
            }
        }
    });
    config_model = (BasicPluginConfigModel) properties.get(PR_CONFIG_MODEL);
    if (config_model == null) {
        String[] cm_params = (String[]) properties.get(PR_CONFIG_MODEL_PARAMS);
        if (cm_params == null || cm_params.length == 0) {
            config_model = ui_manager.createBasicPluginConfigModel(ConfigSection.SECTION_PLUGINS, sConfigSectionID);
        } else if (cm_params.length == 1) {
            config_model = ui_manager.createBasicPluginConfigModel(cm_params[0]);
        } else {
            config_model = ui_manager.createBasicPluginConfigModel(cm_params[0], cm_params[1]);
        }
    }
    /* removed 2017/12/01 - no longer needed 
	
		boolean	save_needed = false;

		if ( !plugin_config.getPluginBooleanParameter( CONFIG_MIGRATED, false )){

			plugin_config.setPluginParameter( CONFIG_MIGRATED, true );

			save_needed	= true;

			plugin_config.setPluginParameter(
					CONFIG_PASSWORD_ENABLE,
					plugin_config.getUnsafeBooleanParameter(
							"Tracker Password Enable Web", CONFIG_PASSWORD_ENABLE_DEFAULT ));

			plugin_config.setPluginParameter(
					CONFIG_USER,
					plugin_config.getUnsafeStringParameter(
							"Tracker Username", CONFIG_USER_DEFAULT ));

			plugin_config.setPluginParameter(
					CONFIG_PASSWORD,
					plugin_config.getUnsafeByteParameter(
							"Tracker Password", CONFIG_PASSWORD_DEFAULT ));

		}

		if ( !plugin_config.getPluginBooleanParameter( PROPERTIES_MIGRATED, false )){

			plugin_config.setPluginParameter( PROPERTIES_MIGRATED, true );

			Properties	props = plugin_interface.getPluginProperties();

				// make sure we've got an old properties file too

			if ( props.getProperty( "port", "" ).length() > 0 ){

				save_needed = true;

				String	prop_port		= props.getProperty( "port",			""+CONFIG_PORT_DEFAULT );
				String	prop_protocol	= props.getProperty( "protocol", 		CONFIG_PROTOCOL_DEFAULT );
				String	prop_home		= props.getProperty( "homepage", 		CONFIG_HOME_PAGE_DEFAULT );
				String	prop_rootdir	= props.getProperty( "rootdir", 		CONFIG_ROOT_DIR_DEFAULT );
				String	prop_rootres	= props.getProperty( "rootresource", 	CONFIG_ROOT_RESOURCE_DEFAULT );
				String	prop_mode		= props.getProperty( "mode", 			CONFIG_MODE_DEFAULT );
				String	prop_access		= props.getProperty( "access", 			CONFIG_ACCESS_DEFAULT );

				int	prop_port_int = CONFIG_PORT_DEFAULT;

				try{
					prop_port_int	= Integer.parseInt( prop_port );

				}catch( Throwable e ){
				}

				plugin_config.setPluginParameter(CONFIG_PORT, prop_port_int );
				plugin_config.setPluginParameter(CONFIG_PROTOCOL, prop_protocol );
				plugin_config.setPluginParameter(CONFIG_HOME_PAGE, prop_home );
				plugin_config.setPluginParameter(CONFIG_ROOT_DIR, prop_rootdir );
				plugin_config.setPluginParameter(CONFIG_ROOT_RESOURCE, prop_rootres );
				plugin_config.setPluginParameter(CONFIG_MODE, prop_mode );
				plugin_config.setPluginParameter(CONFIG_ACCESS, prop_access );

				File	props_file = new File( plugin_interface.getPluginDirectoryName(), "plugin.properties" );

				PrintWriter pw = null;

				try{
					File	backup = new File( plugin_interface.getPluginDirectoryName(), "plugin.properties.bak" );

					props_file.renameTo( backup );

					pw = new PrintWriter( new FileWriter( props_file ));

					pw.println( "plugin.class=" + props.getProperty( "plugin.class" ));
					pw.println( "plugin.name=" + props.getProperty( "plugin.name" ));
					pw.println( "plugin.version=" + props.getProperty( "plugin.version" ));
					pw.println( "plugin.id=" + props.getProperty( "plugin.id" ));
					pw.println( "" );
					pw.println( "# configuration has been migrated to plugin config - see view->config->plugins" );
					pw.println( "# in the SWT user interface" );

					log.logAlert( 	LoggerChannel.LT_INFORMATION,
							plugin_interface.getPluginName() + " - plugin.properties settings migrated to plugin configuration." );

				}catch( Throwable  e ){

					Debug.printStackTrace( e );

					log.logAlert( 	LoggerChannel.LT_ERROR,
									plugin_interface.getPluginName() + " - plugin.properties settings migration failed." );

				}finally{

					if ( pw != null ){

						pw.close();
					}
				}
			}
		}

		if ( save_needed ){

			plugin_config.save();
		}
		*/
    Boolean disablable = (Boolean) properties.get(PR_DISABLABLE);
    final BooleanParameter param_enable;
    if (disablable != null && disablable) {
        param_enable = config_model.addBooleanParameter2(CONFIG_ENABLE, "webui.enable", CONFIG_ENABLE_DEFAULT);
        plugin_enabled = param_enable.getValue();
    } else {
        param_enable = null;
        plugin_enabled = true;
    }
    initStage(1);
    // connection group
    param_port = config_model.addIntParameter2(CONFIG_PORT, "webui.port", CONFIG_PORT_DEFAULT);
    param_port.setGenerateIntermediateEvents(false);
    param_bind = config_model.addStringParameter2(CONFIG_BIND_IP, "webui.bindip", CONFIG_BIND_IP_DEFAULT);
    param_bind.setGenerateIntermediateEvents(false);
    param_protocol = config_model.addStringListParameter2(CONFIG_PROTOCOL, "webui.protocol", new String[] { "http", "https" }, CONFIG_PROTOCOL_DEFAULT);
    param_protocol.setGenerateIntermediateEvents(false);
    ParameterListener update_server_listener = new ParameterListener() {

        @Override
        public void parameterChanged(Parameter param) {
            setupServer();
        }
    };
    param_port.addListener(update_server_listener);
    param_bind.addListener(update_server_listener);
    param_protocol.addListener(update_server_listener);
    param_i2p_dest = config_model.addInfoParameter2("webui.i2p_dest", "");
    param_i2p_dest.setVisible(false);
    param_tor_dest = config_model.addInfoParameter2("webui.tor_dest", "");
    param_tor_dest.setVisible(false);
    if (param_enable != null) {
        COConfigurationManager.registerExportedParameter(plugin_id + ".enable", param_enable.getConfigKeyName());
    }
    COConfigurationManager.registerExportedParameter(plugin_id + ".port", param_port.getConfigKeyName());
    COConfigurationManager.registerExportedParameter(plugin_id + ".protocol", param_protocol.getConfigKeyName());
    p_upnp_enable = config_model.addBooleanParameter2(CONFIG_UPNP_ENABLE, "webui.upnpenable", CONFIG_UPNP_ENABLE_DEFAULT);
    p_upnp_enable.addListener(new ParameterListener() {

        @Override
        public void parameterChanged(Parameter param) {
            setupUPnP();
        }
    });
    plugin_interface.addListener(new PluginListener() {

        @Override
        public void initializationComplete() {
            setupUPnP();
        }

        @Override
        public void closedownInitiated() {
        }

        @Override
        public void closedownComplete() {
        }
    });
    final LabelParameter pairing_info;
    final BooleanParameter pairing_enable;
    final HyperlinkParameter pairing_test;
    final HyperlinkParameter connection_test;
    if (p_sid != null) {
        final PairingManager pm = PairingManagerFactory.getSingleton();
        pairing_info = config_model.addLabelParameter2("webui.pairing.info." + (pm.isEnabled() ? "y" : "n"));
        pairing_enable = config_model.addBooleanParameter2(CONFIG_PAIRING_ENABLE, "webui.pairingenable", CONFIG_PAIRING_ENABLE_DEFAULT);
        if (!plugin_config.getPluginBooleanParameter(PAIRING_MIGRATED, false)) {
            // if they already have a password, don't override it by setting auto-auth
            boolean has_pw_enabled = plugin_config.getPluginBooleanParameter(CONFIG_PASSWORD_ENABLE, CONFIG_PASSWORD_ENABLE_DEFAULT);
            if (has_pw_enabled) {
                plugin_config.setPluginParameter(CONFIG_PAIRING_AUTO_AUTH, false);
            }
            plugin_config.setPluginParameter(PAIRING_MIGRATED, true);
        }
        param_port_or = config_model.addIntParameter2(CONFIG_PORT_OVERRIDE, "webui.port.override", 0);
        param_auto_auth = config_model.addBooleanParameter2(CONFIG_PAIRING_AUTO_AUTH, "webui.pairing.autoauth", CONFIG_PAIRING_AUTO_AUTH_DEFAULT);
        param_auto_auth.addListener(new ParameterListener() {

            @Override
            public void parameterChanged(Parameter param) {
                if (pairing_enable.getValue() && pm.isEnabled()) {
                    setupAutoAuth();
                } else {
                    setupSessionCode(null);
                }
            }
        });
        connection_test = config_model.addHyperlinkParameter2("webui.connectiontest", getConnectionTestURL(p_sid));
        pairing_test = config_model.addHyperlinkParameter2("webui.pairingtest", "http://remote.vuze.com/?sid=" + p_sid);
        // listeners setup later as they depend on userame params etc
        String sid_key = "Plugin." + plugin_id + ".pairing.sid";
        COConfigurationManager.setStringDefault(sid_key, p_sid);
        COConfigurationManager.registerExportedParameter(plugin_id + ".pairing.sid", sid_key);
        COConfigurationManager.registerExportedParameter(plugin_id + ".pairing.enable", pairing_enable.getConfigKeyName());
        COConfigurationManager.registerExportedParameter(plugin_id + ".pairing.auto_auth", param_auto_auth.getConfigKeyName());
    } else {
        pairing_info = null;
        pairing_enable = null;
        param_auto_auth = null;
        param_port_or = null;
        pairing_test = null;
        connection_test = null;
    }
    config_model.createGroup("ConfigView.section.Pairing", new Parameter[] { pairing_info, pairing_enable, param_port_or, param_auto_auth, connection_test, pairing_test });
    config_model.createGroup("ConfigView.section.server", new Parameter[] { param_port, param_bind, param_protocol, param_i2p_dest, param_tor_dest, p_upnp_enable });
    param_home = config_model.addStringParameter2(CONFIG_HOME_PAGE, "webui.homepage", CONFIG_HOME_PAGE_DEFAULT);
    param_rootdir = config_model.addStringParameter2(CONFIG_ROOT_DIR, "webui.rootdir", CONFIG_ROOT_DIR_DEFAULT);
    param_rootres = config_model.addStringParameter2(CONFIG_ROOT_RESOURCE, "webui.rootres", CONFIG_ROOT_RESOURCE_DEFAULT);
    if (pr_hide_resource_config != null && pr_hide_resource_config.booleanValue()) {
        param_home.setVisible(false);
        param_rootdir.setVisible(false);
        param_rootres.setVisible(false);
    } else {
        ParameterListener update_resources_listener = new ParameterListener() {

            @Override
            public void parameterChanged(Parameter param) {
                setupResources();
            }
        };
        param_home.addListener(update_resources_listener);
        param_rootdir.addListener(update_resources_listener);
        param_rootres.addListener(update_resources_listener);
    }
    // access group
    LabelParameter a_label1 = config_model.addLabelParameter2("webui.mode.info");
    StringListParameter param_mode = config_model.addStringListParameter2(CONFIG_MODE, "webui.mode", new String[] { "full", "view" }, CONFIG_MODE_DEFAULT);
    LabelParameter a_label2 = config_model.addLabelParameter2("webui.access.info");
    param_access = config_model.addStringParameter2(CONFIG_ACCESS, "webui.access", CONFIG_ACCESS_DEFAULT);
    param_access.addListener(new ParameterListener() {

        @Override
        public void parameterChanged(Parameter param) {
            setupAccess();
        }
    });
    pw_enable = config_model.addBooleanParameter2(CONFIG_PASSWORD_ENABLE, "webui.passwordenable", CONFIG_PASSWORD_ENABLE_DEFAULT);
    p_user_name = config_model.addStringParameter2(CONFIG_USER, "webui.user", CONFIG_USER_DEFAULT);
    p_password = config_model.addPasswordParameter2(CONFIG_PASSWORD, "webui.password", PasswordParameter.ET_SHA1, CONFIG_PASSWORD_DEFAULT);
    p_no_pw_whitelist = config_model.addStringParameter2(CONFIG_NO_PW_WHITELIST, "webui.nopwwhitelist", CONFIG_NO_PW_WHITELIST_DEFAULT);
    pw_enable.addEnabledOnSelection(p_user_name);
    pw_enable.addEnabledOnSelection(p_password);
    pw_enable.addDisabledOnSelection(p_no_pw_whitelist);
    ParameterListener auth_change_listener = new ParameterListener() {

        @Override
        public void parameterChanged(Parameter param) {
            if (param_auto_auth != null) {
                if (!setting_auto_auth) {
                    log("Disabling pairing auto-authentication as overridden by user");
                    param_auto_auth.setValue(false);
                }
            }
            if (param == p_user_name || param == p_password) {
                setupSessionCode(null);
            }
        }
    };
    p_user_name.addListener(auth_change_listener);
    p_password.addListener(auth_change_listener);
    pw_enable.addListener(auth_change_listener);
    config_model.createGroup("webui.group.access", new Parameter[] { a_label1, param_mode, a_label2, param_access, pw_enable, p_user_name, p_password, p_no_pw_whitelist });
    if (p_sid != null) {
        final PairingManager pm = PairingManagerFactory.getSingleton();
        pairing_enable.addListener(new ParameterListener() {

            @Override
            public void parameterChanged(Parameter param) {
                boolean enabled = pairing_enable.getValue();
                param_auto_auth.setEnabled(pm.isEnabled() && enabled);
                param_port_or.setEnabled(pm.isEnabled() && enabled);
                boolean test_ok = pm.isEnabled() && pairing_enable.getValue() && pm.peekAccessCode() != null && !pm.hasActionOutstanding();
                pairing_test.setEnabled(test_ok);
                connection_test.setEnabled(test_ok);
                setupPairing(p_sid, enabled);
            }
        });
        pairing_listener = new PairingManagerListener() {

            @Override
            public void somethingChanged(PairingManager pm) {
                pairing_info.setLabelKey("webui.pairing.info." + (pm.isEnabled() ? "y" : "n"));
                if (plugin_enabled) {
                    pairing_enable.setEnabled(pm.isEnabled());
                    param_auto_auth.setEnabled(pm.isEnabled() && pairing_enable.getValue());
                    param_port_or.setEnabled(pm.isEnabled() && pairing_enable.getValue());
                    boolean test_ok = pm.isEnabled() && pairing_enable.getValue() && pm.peekAccessCode() != null && !pm.hasActionOutstanding();
                    pairing_test.setEnabled(test_ok);
                    connection_test.setEnabled(test_ok);
                }
                connection_test.setHyperlink(getConnectionTestURL(p_sid));
                setupPairing(p_sid, pairing_enable.getValue());
            }
        };
        pairing_listener.somethingChanged(pm);
        pm.addListener(pairing_listener);
        setupPairing(p_sid, pairing_enable.getValue());
        ParameterListener update_pairing_listener = new ParameterListener() {

            @Override
            public void parameterChanged(Parameter param) {
                updatePairing(p_sid);
                setupUPnP();
            }
        };
        param_port.addListener(update_pairing_listener);
        param_port_or.addListener(update_pairing_listener);
        param_protocol.addListener(update_pairing_listener);
    /*
			config_model.addActionParameter2( "test", "test" ).addListener(
				new ParameterListener()
				{
					public void
					parameterChanged(
						Parameter param )
					{
						try{
							pm.testService(
								p_sid,
								new PairingTestListener()
								{
									public void
									testStarted(
										PairingTest test )
									{
										System.out.println( "Test starts" );
									}

									public void
									testComplete(
										PairingTest test)
									{
										System.out.println( "Test complete: " + test.getOutcome() + "/" + test.getErrorMessage());
									}
								});
						}catch( Throwable e ){

							Debug.out( e );
						}
					}
				});
			*/
    }
    if (param_enable != null) {
        final List<Parameter> changed_params = new ArrayList<>();
        if (!plugin_enabled) {
            Parameter[] params = config_model.getParameters();
            for (Parameter param : params) {
                if (param == param_enable) {
                    continue;
                }
                if (param.isEnabled()) {
                    changed_params.add(param);
                    param.setEnabled(false);
                }
            }
        }
        param_enable.addListener(new ParameterListener() {

            @Override
            public void parameterChanged(Parameter e_p) {
                // this doesn't quite work as tne enabler/disabler parameter logic is implemented
                // badly and only toggles the UI component, not the enabled state of the
                // underlying parameter. grr. better than nothing though
                plugin_enabled = ((BooleanParameter) e_p).getValue();
                if (plugin_enabled) {
                    for (Parameter p : changed_params) {
                        p.setEnabled(true);
                    }
                } else {
                    changed_params.clear();
                    Parameter[] params = config_model.getParameters();
                    for (Parameter param : params) {
                        if (param == e_p) {
                            continue;
                        }
                        if (param.isEnabled()) {
                            changed_params.add(param);
                            param.setEnabled(false);
                        }
                    }
                }
                setupServer();
                setupUPnP();
                if (p_sid != null) {
                    setupPairing(p_sid, pairing_enable.getValue());
                }
            }
        });
    }
    // end config
    setupResources();
    setupAccess();
    setupServer();
}
Also used : LoggerChannelListener(com.biglybt.pif.logging.LoggerChannelListener) UIManager(com.biglybt.pif.ui.UIManager) UITextArea(com.biglybt.pif.ui.components.UITextArea) JSONObject(org.json.simple.JSONObject)

Aggregations

UIManager (com.biglybt.pif.ui.UIManager)48 UIInstance (com.biglybt.pif.ui.UIInstance)14 PluginInterface (com.biglybt.pif.PluginInterface)13 UIManagerListener (com.biglybt.pif.ui.UIManagerListener)13 UISWTInstance (com.biglybt.ui.swt.pif.UISWTInstance)10 MenuItemListener (com.biglybt.pif.ui.menus.MenuItemListener)8 MenuItem (com.biglybt.pif.ui.menus.MenuItem)7 MenuManager (com.biglybt.pif.ui.menus.MenuManager)7 LoggerChannelListener (com.biglybt.pif.logging.LoggerChannelListener)6 DownloadManager (com.biglybt.core.download.DownloadManager)5 BasicPluginConfigModel (com.biglybt.pif.ui.model.BasicPluginConfigModel)5 URL (java.net.URL)5 TableManager (com.biglybt.pif.ui.tables.TableManager)4 TableColumnManager (com.biglybt.ui.common.table.impl.TableColumnManager)4 ArrayList (java.util.ArrayList)4 VuzeFile (com.biglybt.core.vuzefile.VuzeFile)3 PluginListener (com.biglybt.pif.PluginListener)3 MenuItemFillListener (com.biglybt.pif.ui.menus.MenuItemFillListener)3 BasicPluginViewModel (com.biglybt.pif.ui.model.BasicPluginViewModel)3 DelayedTask (com.biglybt.pif.utils.DelayedTask)3