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()
{
public void
parameterChanged(
Parameter param )
{
if ( pairing_enable.getValue() && pm.isEnabled()){
setupAutoAuth();
}
}
});
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
}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, 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()
{
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()
{
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 );
pw_enable.addEnabledOnSelection( p_user_name );
pw_enable.addEnabledOnSelection( p_password );
ParameterListener auth_change_listener =
new ParameterListener()
{
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 );
}
}
}
};
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,
});
if ( p_sid != null ){
final PairingManager pm = PairingManagerFactory.getSingleton();
pairing_enable.addListener(
new ParameterListener()
{
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()
{
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()