use of com.biglybt.pif.ui.UIManager in project BiglyBT by BiglySoftware.
the class NetworkAdminImpl method maybeVPN.
private void maybeVPN(final NetworkInterface intf) {
final UIManager ui_manager = StaticUtilities.getUIManager(5 * 1000);
if (ui_manager == null) {
return;
}
if (maybeVPNDone(intf)) {
return;
}
COConfigurationManager.setParameter("network.admin.maybe.vpn.done." + getConfigKey(intf), true);
new AEThread2("NetworkAdmin:vpn?") {
@Override
public void run() {
String msg_details = MessageText.getString("network.admin.maybe.vpn.msg", new String[] { intf.getName() + " - " + intf.getDisplayName() });
long res = ui_manager.showMessageBox("network.admin.maybe.vpn.title", "!" + msg_details + "!", UIManagerEvent.MT_YES | UIManagerEvent.MT_NO_DEFAULT);
if (res == UIManagerEvent.MT_YES) {
COConfigurationManager.setParameter("User Mode", 2);
COConfigurationManager.setParameter("Bind IP", intf.getName());
COConfigurationManager.setParameter("Enforce Bind IP", true);
COConfigurationManager.setParameter("Check Bind IP On Start", true);
COConfigurationManager.save();
try {
Set<NetworkConnectionBase> connections = NetworkManager.getSingleton().getConnections();
Map<InetAddress, Object[]> lookup_map = new HashMap<>();
for (NetworkConnectionBase connection : connections) {
TransportBase tb = connection.getTransportBase();
if (tb instanceof Transport) {
boolean ok = false;
Transport transport = (Transport) tb;
if (transport.isTCP()) {
TransportStartpoint start = transport.getTransportStartpoint();
if (start != null) {
InetSocketAddress socket_address = start.getProtocolStartpoint().getAddress();
if (socket_address != null) {
InetAddress address = socket_address.getAddress();
Object[] details = lookup_map.get(address);
if (details == null) {
if (!lookup_map.containsKey(address)) {
details = getInterfaceForAddress(address);
lookup_map.put(address, details);
}
if (details[0] == intf) {
ok = true;
}
}
}
}
}
if (!ok) {
transport.close("Explicit bind IP set, disconnecting incompatible connections");
}
}
}
} catch (Throwable e) {
Debug.out(e);
}
bs_last_calc = 0;
ui_manager.showMessageBox("settings.updated.title", "settings.updated.msg", UIManagerEvent.MT_OK);
}
}
}.start();
}
use of com.biglybt.pif.ui.UIManager in project BiglyBT by BiglySoftware.
the class SubscriptionManagerImpl method importSubscription.
public Subscription importSubscription(int type, Map map, boolean warn_user) throws SubscriptionException {
boolean log_errors = true;
try {
try {
if (type == VuzeFileComponent.COMP_TYPE_SUBSCRIPTION_SINGLETON) {
String name = new String((byte[]) map.get("name"), "UTF-8");
URL url = new URL(new String((byte[]) map.get("url"), "UTF-8"));
Long l_interval = (Long) map.get("check_interval_mins");
int check_interval_mins = l_interval == null ? SubscriptionHistoryImpl.DEFAULT_CHECK_INTERVAL_MINS : l_interval.intValue();
Long l_public = (Long) map.get("public");
boolean is_public = l_public == null ? true : l_public.longValue() == 1;
Long l_anon = (Long) map.get("anon");
boolean is_anon = l_anon == null ? false : l_anon.longValue() == 1;
SubscriptionImpl existing = lookupSingletonRSS(name, url, is_public, check_interval_mins, is_anon);
if (UrlFilter.getInstance().urlCanRPC(url.toExternalForm())) {
warn_user = false;
}
if (existing != null && existing.isSubscribed()) {
if (warn_user) {
UIManager ui_manager = StaticUtilities.getUIManager(120 * 1000);
String details = MessageText.getString("subscript.add.dup.desc", new String[] { existing.getName() });
ui_manager.showMessageBox("subscript.add.dup.title", "!" + details + "!", UIManagerEvent.MT_OK);
}
selectSubscription(existing);
return (existing);
} else {
if (warn_user) {
UIManager ui_manager = StaticUtilities.getUIManager(120 * 1000);
String details = MessageText.getString("subscript.add.desc", new String[] { name });
long res = ui_manager.showMessageBox("subscript.add.title", "!" + details + "!", UIManagerEvent.MT_YES | UIManagerEvent.MT_NO);
if (res != UIManagerEvent.MT_YES) {
log_errors = false;
throw (new SubscriptionException("User declined addition"));
}
}
if (existing == null) {
SubscriptionImpl new_subs = (SubscriptionImpl) createSingletonRSSSupport(name, url, is_public, check_interval_mins, is_anon, SubscriptionImpl.ADD_TYPE_IMPORT, true);
log("Imported new singleton subscription: " + new_subs.getString());
return (new_subs);
} else {
existing.setSubscribed(true);
selectSubscription(existing);
return (existing);
}
}
} else {
SubscriptionBodyImpl body = new SubscriptionBodyImpl(this, map);
SubscriptionImpl existing = getSubscriptionFromSID(body.getShortID());
if (existing != null && existing.isSubscribed()) {
if (existing.getVersion() >= body.getVersion()) {
log("Not upgrading subscription: " + existing.getString() + " as supplied (" + body.getVersion() + ") is not more recent than existing (" + existing.getVersion() + ")");
if (warn_user) {
UIManager ui_manager = StaticUtilities.getUIManager(120 * 1000);
String details = MessageText.getString("subscript.add.dup.desc", new String[] { existing.getName() });
ui_manager.showMessageBox("subscript.add.dup.title", "!" + details + "!", UIManagerEvent.MT_OK);
}
// we have a newer one, ignore
selectSubscription(existing);
return (existing);
} else {
if (warn_user) {
UIManager ui_manager = StaticUtilities.getUIManager(120 * 1000);
String details = MessageText.getString("subscript.add.upgrade.desc", new String[] { existing.getName() });
long res = ui_manager.showMessageBox("subscript.add.upgrade.title", "!" + details + "!", UIManagerEvent.MT_YES | UIManagerEvent.MT_NO);
if (res != UIManagerEvent.MT_YES) {
throw (new SubscriptionException("User declined upgrade"));
}
}
log("Upgrading subscription: " + existing.getString());
existing.upgrade(body);
saveConfig();
subscriptionUpdated();
return (existing);
}
} else {
SubscriptionImpl new_subs = null;
String subs_name;
if (existing == null) {
new_subs = new SubscriptionImpl(this, body, SubscriptionImpl.ADD_TYPE_IMPORT, true);
subs_name = new_subs.getName();
} else {
subs_name = existing.getName();
}
if (warn_user) {
UIManager ui_manager = StaticUtilities.getUIManager(120 * 1000);
String details = MessageText.getString("subscript.add.desc", new String[] { subs_name });
long res = ui_manager.showMessageBox("subscript.add.title", "!" + details + "!", UIManagerEvent.MT_YES | UIManagerEvent.MT_NO);
if (res != UIManagerEvent.MT_YES) {
throw (new SubscriptionException("User declined addition"));
}
}
if (new_subs == null) {
existing.setSubscribed(true);
selectSubscription(existing);
return (existing);
} else {
log("Imported new subscription: " + new_subs.getString());
new_subs = addSubscription(new_subs);
return (new_subs);
}
}
}
} catch (Throwable e) {
throw (new SubscriptionException("Subscription import failed", e));
}
} catch (SubscriptionException e) {
if (warn_user && log_errors) {
UIManager ui_manager = StaticUtilities.getUIManager(120 * 1000);
String details = MessageText.getString("subscript.import.fail.desc", new String[] { Debug.getNestedExceptionMessage(e) });
ui_manager.showMessageBox("subscript.import.fail.title", "!" + details + "!", UIManagerEvent.MT_OK);
}
throw (e);
}
}
use of com.biglybt.pif.ui.UIManager in project BiglyBT by BiglySoftware.
the class SubscriptionManagerImpl method askIfCanUpgrade.
protected boolean askIfCanUpgrade(SubscriptionImpl subs, int new_version) {
subs.setHighestUserPromptedVersion(new_version);
UIManager ui_manager = StaticUtilities.getUIManager(120 * 1000);
String details = MessageText.getString("subscript.add.upgradeto.desc", new String[] { String.valueOf(new_version), subs.getName() });
long res = ui_manager.showMessageBox("subscript.add.upgrade.title", "!" + details + "!", UIManagerEvent.MT_YES | UIManagerEvent.MT_NO);
if (res != UIManagerEvent.MT_YES) {
log(" User declined upgrade");
return (false);
}
return (true);
}
use of com.biglybt.pif.ui.UIManager in project BiglyBT by BiglySoftware.
the class DHTPlugin method initialize.
@Override
public void initialize(PluginInterface _plugin_interface) {
status = STATUS_INITALISING;
plugin_interface = _plugin_interface;
dht_data_port = UDPNetworkManager.getSingleton().getUDPNonDataListeningPortNumber();
log = plugin_interface.getLogger().getTimeStampedChannel(PLUGIN_NAME);
UIManager ui_manager = plugin_interface.getUIManager();
final BasicPluginViewModel model = ui_manager.createBasicPluginViewModel(PLUGIN_RESOURCE_ID);
model.setConfigSectionID(PLUGIN_CONFIGSECTION_ID);
BasicPluginConfigModel config = ui_manager.createBasicPluginConfigModel(ConfigSection.SECTION_PLUGINS, PLUGIN_CONFIGSECTION_ID);
config.addLabelParameter2("dht.info");
final BooleanParameter enabled_param = config.addBooleanParameter2("dht.enabled", "dht.enabled", true);
plugin_interface.getPluginconfig().addListener(new PluginConfigListener() {
@Override
public void configSaved() {
int new_dht_data_port = UDPNetworkManager.getSingleton().getUDPNonDataListeningPortNumber();
if (new_dht_data_port != dht_data_port) {
changePort(new_dht_data_port);
}
}
});
LabelParameter reseed_label = config.addLabelParameter2("dht.reseed.label");
final StringParameter reseed_ip = config.addStringParameter2("dht.reseed.ip", "dht.reseed.ip", "");
final IntParameter reseed_port = config.addIntParameter2("dht.reseed.port", "dht.reseed.port", 0);
reseed = config.addActionParameter2("dht.reseed.info", "dht.reseed");
reseed.setEnabled(false);
config.createGroup("dht.reseed.group", new Parameter[] { reseed_label, reseed_ip, reseed_port, reseed });
final BooleanParameter ipfilter_logging_param = config.addBooleanParameter2("dht.ipfilter.log", "dht.ipfilter.log", true);
ipfilter_logging[0] = ipfilter_logging_param.getValue();
ipfilter_logging_param.addListener(new ParameterListener() {
@Override
public void parameterChanged(Parameter p) {
ipfilter_logging[0] = ipfilter_logging_param.getValue();
}
});
warn_user = config.addBooleanParameter2("dht.warn.user", "dht.warn.user", true);
prefer_i2p = config.addBooleanParameter2("dht.prefer.i2p", "dht.prefer.i2p", false);
BooleanParameter sleeping = config.addBooleanParameter2("dht.is.sleeping", "dht.is.sleeping", false);
AERunStateHandler.addListener(new AERunStateHandler.RunStateChangeListener() {
@Override
public void runStateChanged(long run_state) {
sleeping.setValue(AERunStateHandler.isDHTSleeping());
}
}, true);
sleeping.addListener(new ParameterListener() {
@Override
public void parameterChanged(Parameter param) {
AERunStateHandler.setDHTSleeping(sleeping.getValue());
}
});
final BooleanParameter advanced = config.addBooleanParameter2("dht.advanced", "dht.advanced", false);
LabelParameter advanced_label = config.addLabelParameter2("dht.advanced.label");
final StringParameter override_ip = config.addStringParameter2("dht.override.ip", "dht.override.ip", "");
config.createGroup("dht.advanced.group", new Parameter[] { advanced_label, override_ip });
advanced.addEnabledOnSelection(advanced_label);
advanced.addEnabledOnSelection(override_ip);
final StringParameter command = config.addStringParameter2("dht.execute.command", "dht.execute.command", "print");
ActionParameter execute = config.addActionParameter2("dht.execute.info", "dht.execute");
final BooleanParameter logging = config.addBooleanParameter2("dht.logging", "dht.logging", false);
config.createGroup("dht.diagnostics.group", new Parameter[] { command, execute, logging });
logging.addListener(new ParameterListener() {
@Override
public void parameterChanged(Parameter param) {
if (dhts != null) {
for (int i = 0; i < dhts.length; i++) {
dhts[i].setLogging(logging.getValue());
}
}
}
});
final DHTPluginOperationListener log_polistener = new DHTPluginOperationListener() {
@Override
public boolean diversified() {
return (true);
}
@Override
public void starts(byte[] key) {
}
@Override
public void valueRead(DHTPluginContact originator, DHTPluginValue value) {
log.log("valueRead: " + new String(value.getValue()) + " from " + originator.getName() + "/" + originator.getAddress() + ", flags=" + Integer.toHexString(value.getFlags() & 0x00ff));
if ((value.getFlags() & DHTPlugin.FLAG_STATS) != 0) {
DHTPluginKeyStats stats = decodeStats(value);
log.log(" stats: size=" + (stats == null ? "null" : stats.getSize()));
}
}
@Override
public void valueWritten(DHTPluginContact target, DHTPluginValue value) {
log.log("valueWritten:" + new String(value.getValue()) + " to " + target.getName() + "/" + target.getAddress());
}
@Override
public void complete(byte[] key, boolean timeout_occurred) {
log.log("complete: timeout = " + timeout_occurred);
}
};
execute.addListener(new ParameterListener() {
@Override
public void parameterChanged(Parameter param) {
AEThread2 t = new AEThread2("DHT:commandrunner", true) {
@Override
public void run() {
try {
if (dhts == null) {
return;
}
String c = command.getValue().trim();
String lc = c.toLowerCase();
if (lc.equals("suspend")) {
if (!setSuspended(true)) {
Debug.out("Suspend failed");
}
return;
} else if (lc.equals("resume")) {
if (!setSuspended(false)) {
Debug.out("Resume failed");
}
return;
} else if (lc.equals("bridge_put")) {
try {
List<DistributedDatabase> ddbs = plugin_interface.getUtilities().getDistributedDatabases(new String[] { AENetworkClassifier.AT_I2P });
DistributedDatabase ddb = ddbs.get(0);
DistributedDatabaseKey key = ddb.createKey("fred");
key.setFlags(DistributedDatabaseKey.FL_BRIDGED);
ddb.write(new DistributedDatabaseListener() {
@Override
public void event(DistributedDatabaseEvent event) {
// TODO Auto-generated method stub
}
}, key, ddb.createValue("bill"));
} catch (Throwable e) {
e.printStackTrace();
}
return;
}
for (int i = 0; i < dhts.length; i++) {
DHT dht = dhts[i].getDHT();
DHTTransportUDP transport = (DHTTransportUDP) dht.getTransport();
if (lc.equals("print")) {
dht.print(true);
dhts[i].logStats();
} else if (lc.equals("pingall")) {
if (i == 1) {
dht.getControl().pingAll();
}
} else if (lc.equals("versions")) {
List<DHTRouterContact> contacts = dht.getRouter().getAllContacts();
Map<Byte, Integer> counts = new TreeMap<>();
for (DHTRouterContact r : contacts) {
DHTControlContact contact = (DHTControlContact) r.getAttachment();
byte v = contact.getTransportContact().getProtocolVersion();
Integer count = counts.get(v);
if (count == null) {
counts.put(v, 1);
} else {
counts.put(v, count + 1);
}
}
log.log("Net " + dht.getTransport().getNetwork());
int total = contacts.size();
if (total == 0) {
log.log(" no contacts");
} else {
String ver = "";
for (Map.Entry<Byte, Integer> entry : counts.entrySet()) {
ver += (ver.length() == 0 ? "" : ", ") + entry.getKey() + "=" + 100 * entry.getValue() / total + "%";
}
log.log(" contacts=" + total + ": " + ver);
}
} else if (lc.equals("testca")) {
((DHTTransportUDPImpl) transport).testExternalAddressChange();
} else if (lc.equals("testnd")) {
((DHTTransportUDPImpl) transport).testNetworkAlive(false);
} else if (lc.equals("testna")) {
((DHTTransportUDPImpl) transport).testNetworkAlive(true);
} else {
int pos = c.indexOf(' ');
if (pos != -1) {
String lhs = lc.substring(0, pos);
String rhs = c.substring(pos + 1);
if (lhs.equals("set")) {
pos = rhs.indexOf('=');
if (pos != -1) {
DHTPlugin.this.put(rhs.substring(0, pos).getBytes(), "DHT Plugin: set", rhs.substring(pos + 1).getBytes(), (byte) 0, log_polistener);
}
} else if (lhs.equals("get")) {
DHTPlugin.this.get(rhs.getBytes("UTF-8"), "DHT Plugin: get", (byte) 0, 1, 10000, true, false, log_polistener);
} else if (lhs.equals("query")) {
DHTPlugin.this.get(rhs.getBytes("UTF-8"), "DHT Plugin: get", DHTPlugin.FLAG_STATS, 1, 10000, true, false, log_polistener);
} else if (lhs.equals("punch")) {
Map originator_data = new HashMap();
originator_data.put("hello", "mum");
DHTNATPuncher puncher = dht.getNATPuncher();
if (puncher != null) {
puncher.punch("Test", transport.getLocalContact(), null, originator_data);
}
} else if (lhs.equals("stats")) {
try {
pos = rhs.lastIndexOf(":");
DHTTransportContact contact;
if (pos == -1) {
contact = transport.getLocalContact();
} else {
String host = rhs.substring(0, pos);
int port = Integer.parseInt(rhs.substring(pos + 1));
contact = transport.importContact(new InetSocketAddress(host, port), transport.getProtocolVersion(), false);
}
log.log("Stats request to " + contact.getName());
DHTTransportFullStats stats = contact.getStats();
log.log("Stats:" + (stats == null ? "<null>" : stats.getString()));
DHTControlActivity[] activities = dht.getControl().getActivities();
for (int j = 0; j < activities.length; j++) {
log.log(" act:" + activities[j].getString());
}
} catch (Throwable e) {
Debug.printStackTrace(e);
}
}
}
}
}
} catch (Throwable e) {
Debug.out(e);
}
}
};
t.start();
}
});
reseed.addListener(new ParameterListener() {
@Override
public void parameterChanged(Parameter param) {
reseed.setEnabled(false);
AEThread2 t = new AEThread2("DHT:reseeder", true) {
@Override
public void run() {
try {
String ip = reseed_ip.getValue().trim();
if (dhts == null) {
return;
}
int port = reseed_port.getValue();
for (int i = 0; i < dhts.length; i++) {
DHTPluginImpl dht = dhts[i];
if (ip.length() == 0 || port == 0) {
dht.checkForReSeed(true);
} else {
DHTTransportContact seed = dht.importSeed(ip, port);
if (seed != null) {
dht.integrateDHT(false, seed);
}
}
}
} finally {
reseed.setEnabled(true);
}
}
};
t.start();
}
});
model.getActivity().setVisible(false);
model.getProgress().setVisible(false);
log.addListener(new LoggerChannelListener() {
@Override
public void messageLogged(int type, String message) {
model.getLogArea().appendText(message + "\n");
}
@Override
public void messageLogged(String str, Throwable error) {
model.getLogArea().appendText(error.toString() + "\n");
}
});
dht_log = new DHTLogger() {
@Override
public void log(String str) {
log.log(str);
}
@Override
public void log(Throwable e) {
log.log(e);
}
@Override
public void log(int log_type, String str) {
if (isEnabled(log_type)) {
log.log(str);
}
}
@Override
public boolean isEnabled(int log_type) {
if (log_type == DHTLogger.LT_IP_FILTER) {
return ipfilter_logging[0];
}
return (true);
}
@Override
public PluginInterface getPluginInterface() {
return (log.getLogger().getPluginInterface());
}
};
if (!enabled_param.getValue()) {
model.getStatus().setText("Disabled");
status = STATUS_DISABLED;
init_sem.releaseForever();
return;
}
setPluginInfo();
plugin_interface.addListener(new PluginListener() {
@Override
public void initializationComplete() {
PluginInterface pi_upnp = plugin_interface.getPluginManager().getPluginInterfaceByClass(UPnPPlugin.class);
if (pi_upnp == null) {
log.log("UPnP plugin not found, can't map port");
} else {
upnp_mapping = ((UPnPPlugin) pi_upnp.getPlugin()).addMapping(plugin_interface.getPluginName(), false, dht_data_port, true);
}
String ip = null;
if (advanced.getValue()) {
ip = override_ip.getValue().trim();
if (ip.length() == 0) {
ip = null;
}
}
initComplete(model.getStatus(), logging.getValue(), ip);
}
@Override
public void closedownInitiated() {
if (dhts != null) {
for (int i = 0; i < dhts.length; i++) {
dhts[i].closedownInitiated();
}
}
saveClockSkew();
}
@Override
public void closedownComplete() {
}
});
final int sample_frequency = 60 * 1000;
// every 15 mins
final int sample_stats_ticks = 15;
plugin_interface.getUtilities().createTimer("DHTStats", true).addPeriodicEvent(sample_frequency, new UTTimerEventPerformer() {
@Override
public void perform(UTTimerEvent event) {
if (dhts != null) {
for (int i = 0; i < dhts.length; i++) {
dhts[i].updateStats(sample_stats_ticks);
}
}
setPluginInfo();
saveClockSkew();
}
});
}
use of com.biglybt.pif.ui.UIManager in project BiglyBT by BiglySoftware.
the class CoreUpdateChecker method handleZIPUpdate.
protected void handleZIPUpdate(UpdateChecker checker, InputStream data) throws Exception {
ZipInputStream zip = null;
Properties update_properties = new Properties();
File temp_dir = AETemporaryFileHandler.createTempDir();
File update_file = null;
try {
zip = new ZipInputStream(data);
ZipEntry entry = null;
while ((entry = zip.getNextEntry()) != null) {
String name = entry.getName().trim();
if (name.equals("azureus.sig") || name.endsWith("/") || name.length() == 0) {
continue;
}
if (name.equals("update.properties")) {
update_properties.load(zip);
} else {
if (update_file != null) {
throw (new Exception("Multiple update files are not supported"));
}
update_file = new File(temp_dir, name);
FileUtil.copyFile(zip, update_file, false);
}
}
} finally {
if (zip != null) {
try {
zip.close();
} catch (Throwable e) {
}
}
}
if (update_properties == null) {
throw (new Exception("Update properties missing"));
}
if (update_file == null) {
throw (new Exception("Update file missing"));
}
String info_url = update_properties.getProperty("info.url");
if (info_url == null) {
throw (new Exception("Update property 'info.url' missing"));
}
// update_properties.setProperty( "launch.args" , "-silent" );
// update_properties.setProperty( "launch.silent" , "true" );
String s_args = update_properties.getProperty("launch.args", "").trim();
final String[] args;
if (s_args.length() > 0) {
args = GeneralUtils.splitQuotedTokens(s_args);
} else {
args = new String[0];
}
UIFunctions uif = UIFunctionsManager.getUIFunctions();
if (uif == null) {
throw (new Exception("Update can't proceed - UI functions unavailable"));
}
checker.getCheckInstance().setProperty(UpdateCheckInstance.PT_CLOSE_OR_RESTART_ALREADY_IN_PROGRESS, true);
final File f_update_file = update_file;
boolean silent = update_properties.getProperty("launch.silent", "false").equals("true");
if (silent) {
if (Constants.isOSX) {
String app_name = SystemProperties.getApplicationName();
if (!(app_name.equals("Vuze") || app_name.equals("Azureus") || app_name.equals("BiglyBT") || app_name.equals(Constants.AZUREUS_NAME))) {
UIManager ui_manager = StaticUtilities.getUIManager(120 * 1000);
String details = MessageText.getString("update.fail.app.changed", new String[] { app_name });
ui_manager.showMessageBox("update.fail.app.changed.title", "!" + details + "!", UIManagerEvent.MT_OK);
return;
}
}
uif.performAction(UIFunctions.ACTION_UPDATE_RESTART_REQUEST, !FileUtil.canReallyWriteToAppDirectory(), new UIFunctions.actionListener() {
@Override
public void actionComplete(Object result) {
if ((Boolean) result) {
launchUpdate(f_update_file, args);
}
}
});
} else {
uif.performAction(UIFunctions.ACTION_FULL_UPDATE, info_url, new UIFunctions.actionListener() {
@Override
public void actionComplete(Object result) {
if ((Boolean) result) {
launchUpdate(f_update_file, args);
}
}
});
}
}
Aggregations