use of de.janrufmonitor.exception.Message in project janrufmonitor by tbrandt77.
the class TR064FritzBoxFirmware method init.
public void init() throws FritzBoxInitializationException, FritzBoxNotFoundException, InvalidSessionIDException {
try {
if (!this.isTR064Enabled())
throw new FritzBoxInitializationException("FRITZ!Box " + this.m_server + " does not support TR064 or TR064 is disabled.");
this.m_useHttp = Boolean.parseBoolean(System.getProperty("jam.fritzbox.useHttp", "false"));
String version = FritzBoxTR064Manager.getInstance().getFirmwareVersion(this.m_user, this.m_password, this.m_server, (this.m_useHttp ? FritzBoxTR064Manager.getInstance().getDefaultFritzBoxTR064Port() : FritzBoxTR064Manager.getInstance().getDefaultFritzBoxTR064SecurePort(this.m_server)), (this.m_useHttp ? "http" : "https"));
if (this.m_logger.isLoggable(Level.INFO))
this.m_logger.info("FritzBox firmware version string: " + version);
if (version != null && version.length() > 0) {
StringTokenizer st = new StringTokenizer(version, ".");
if (st.countTokens() == 3) {
this.m_firmware = new FirmwareData(st.nextToken(), st.nextToken(), st.nextToken());
if (this.m_logger.isLoggable(Level.INFO))
this.m_logger.info("Initializing of FritzBox firmware succuessfully finished: " + this.m_firmware.toString());
this.m_loginUptime = FritzBoxTR064Manager.getInstance().getUptime(this.m_user, this.m_password, this.m_server, (this.m_useHttp ? FritzBoxTR064Manager.getInstance().getDefaultFritzBoxTR064Port() : FritzBoxTR064Manager.getInstance().getDefaultFritzBoxTR064SecurePort(this.m_server)), (this.m_useHttp ? "http" : "https"));
if (this.m_loginUptime == -1L) {
throw new FritzBoxInitializationException("FritzBox did not provide uptime attribute: " + this.m_loginUptime);
}
} else {
throw new FritzBoxInitializationException("FritzBox version string is invalid: " + version);
}
} else
throw new InvalidSessionIDException("FritzBox could not receive firmware version. Invalid Login data.");
} catch (IOException e) {
if (this.m_logger.isLoggable(Level.SEVERE))
this.m_logger.log(Level.SEVERE, e.getMessage(), e);
if (e.getMessage().indexOf("DH keypair") > 0) {
if (OSUtils.isMacOSX()) {
System.setProperty("jam.fritzbox.useHttp", "true");
if (this.m_logger.isLoggable(Level.INFO))
this.m_logger.info("SSL over HTTPS not possible on this Mac. Using HTTP. Set jam.fritzbox.useHttp=true");
this.init();
return;
}
PropagationFactory.getInstance().fire(new Message(Message.ERROR, "fritzbox.firmware.hardware", "sslerror", new String[] { this.m_server, System.getProperty("java.runtime.version", "-") }, new Exception("SSL Handshake failed for server: " + this.m_server), true));
}
throw new FritzBoxInitializationException("FritzBox initializing failed: " + e.getMessage());
}
}
use of de.janrufmonitor.exception.Message in project janrufmonitor by tbrandt77.
the class FritzBoxDialogPlugin method run.
public void run() {
new SWTExecuter(this.getLabel()) {
protected void execute() {
ICaller o = m_dialog.getCall().getCaller();
String dial = ((ICaller) o).getPhoneNumber().getTelephoneNumber();
if (!((ICaller) o).getPhoneNumber().getIntAreaCode().equalsIgnoreCase(getRuntime().getConfigManagerFactory().getConfigManager().getProperty(IJAMConst.GLOBAL_NAMESPACE, IJAMConst.GLOBAL_INTAREA))) {
dial = "00" + ((ICaller) o).getPhoneNumber().getIntAreaCode() + dial;
}
if (!dial.startsWith("0"))
dial = "0" + dial;
String text = getI18nManager().getString(getNamespaceDial(), "dial", "description", getLanguage());
text = StringUtils.replaceString(text, "{%1}", dial);
if (MessageDialog.openConfirm(new Shell(DisplayManager.getDefaultDisplay()), getI18nManager().getString(getNamespaceDial(), "success", "label", getLanguage()), text)) {
Properties config = getRuntime().getConfigManagerFactory().getConfigManager().getProperties(FritzBoxMonitor.NAMESPACE);
FirmwareManager fwm = FirmwareManager.getInstance();
try {
if (!fwm.isLoggedIn())
fwm.login();
fwm.doCall(dial, config.getProperty(CFG_CLICKDIAL, "50"));
text = getI18nManager().getString(getNamespaceDial(), "success", "description", getLanguage());
text = StringUtils.replaceString(text, "{%1}", dial);
MessageDialog.openInformation(new Shell(DisplayManager.getDefaultDisplay()), getI18nManager().getString(getNamespaceDial(), "success", "label", getLanguage()), text);
} catch (IOException e) {
m_logger.warning(e.toString());
PropagationFactory.getInstance().fire(new Message(Message.ERROR, getNamespaceDial(), "faileddial", e));
} catch (FritzBoxLoginException e) {
m_logger.warning(e.toString());
PropagationFactory.getInstance().fire(new Message(Message.ERROR, getNamespaceDial(), "faileddial", e));
} catch (DoCallException e) {
m_logger.warning(e.toString());
PropagationFactory.getInstance().fire(new Message(Message.ERROR, getNamespaceDial(), "faileddial", e));
}
}
}
}.start();
}
use of de.janrufmonitor.exception.Message in project janrufmonitor by tbrandt77.
the class UpdateWizard method performFinish.
public boolean performFinish() {
final List l = ((UpdatesPage) this.m_pages[0]).getResult();
final boolean isMoreUpdates = ((UpdatesPage) this.m_pages[0]).isMoreUpdates();
if (l.size() > 0) {
try {
IRunnableWithProgress op = new IRunnableWithProgress() {
public void run(IProgressMonitor pm) throws InvocationTargetException, InterruptedException {
pm.setTaskName(m_i18n.getString(getNamespace(), "updates", "label", m_language));
Properties p = null;
String url, name = null;
StreamRequester sr = null;
for (int i = 0, n = l.size(); i < n; i++) {
p = (Properties) l.get(i);
url = p.getProperty(InstallerConst.DESCRIPTOR_UPDATE);
name = p.getProperty(InstallerConst.DESCRIPTOR_NAME) + "." + p.getProperty(InstallerConst.DESCRIPTOR_VERSION) + InstallerConst.EXTENSION_ARCHIVE;
if (url != null && url.length() > 6) {
pm.subTask(m_i18n.getString(getNamespace(), "install", "label", m_language) + name);
sr = new StreamRequester(url);
sr.go();
try {
InstallerEngine.getInstance().install(name, sr.getInputStream(), (i == (n - 1)));
} catch (InstallerException e) {
m_logger.severe(e.getMessage());
PropagationFactory.getInstance().fire(new Message(Message.ERROR, getNamespace(), "failed", new Exception("Installation failed for module " + url)));
}
}
}
DisplayManager.getDefaultDisplay().asyncExec(new Runnable() {
public void run() {
MessageDialog.openInformation(getShell(), m_i18n.getString(getNamespace(), "success", "label", m_language), m_i18n.getString(getNamespace(), "success", "description", m_language));
m_finished = true;
}
});
if (isMoreUpdates) {
DisplayManager.getDefaultDisplay().asyncExec(new Runnable() {
public void run() {
MessageDialog.openInformation(getShell(), m_i18n.getString(getNamespace(), "moreupdates", "label", m_language), m_i18n.getString(getNamespace(), "moreupdates", "description", m_language));
m_finished = true;
}
});
}
}
};
ProgressMonitorDialog pmd = new ProgressMonitorDialog(getShell());
pmd.run(true, true, op);
} catch (InvocationTargetException e) {
this.m_logger.log(Level.SEVERE, e.getMessage(), e);
m_finished = true;
} catch (InterruptedException e) {
this.m_logger.log(Level.SEVERE, e.getMessage(), e);
m_finished = true;
}
}
while (!m_finished) {
try {
Thread.sleep(100);
} catch (InterruptedException e) {
this.m_logger.log(Level.SEVERE, e.getMessage(), e);
m_finished = true;
}
}
return true;
}
use of de.janrufmonitor.exception.Message in project janrufmonitor by tbrandt77.
the class HibernateDetect method startup.
public void startup() {
super.startup();
getRuntime().getEventBroker().register(this);
if (isEnabled()) {
this.isHibernateChecking = true;
Thread t = new Thread(new Runnable() {
public void run() {
// check file system
File trackFolder = new File(PathResolver.getInstance(getRuntime()).getLogDirectory(), "~" + ID.toLowerCase());
if (!trackFolder.exists())
trackFolder.mkdirs();
if (m_logger.isLoggable(Level.INFO))
m_logger.info("Hibernate tracking directory: " + trackFolder.getAbsolutePath());
// clear folder if exists
File[] files = trackFolder.listFiles();
for (int i = 0; i < files.length; i++) {
files[i].delete();
}
File pid = null;
while (isHibernateChecking) {
pid = new File(trackFolder, Long.toString(System.currentTimeMillis()));
try {
pid.createNewFile();
} catch (IOException e) {
m_logger.log(Level.SEVERE, e.toString(), e);
}
try {
Thread.sleep(getDelayTime());
} catch (InterruptedException e) {
m_logger.log(Level.SEVERE, e.toString(), e);
}
// check if time stamps are there
files = trackFolder.listFiles();
if (files.length == 0) {
isHibernateChecking = false;
continue;
}
if (files.length == 1) {
try {
long l = Long.parseLong(files[0].getName());
long result = System.currentTimeMillis() - l;
if (m_logger.isLoggable(Level.INFO))
m_logger.info("Delta hibernate detection time (ms): " + result);
if (result > (2 * getDelayTime())) {
PropagationFactory.getInstance().fire(new Message(Message.WARNING, getNamespace(), "hibernate", new Exception("Programm out of sync: OS was probably in hibernate mode.")));
getRuntime().getEventBroker().send(HibernateDetect.this, getRuntime().getEventBroker().createEvent(IEventConst.EVENT_TYPE_RETURNED_HIBERNATE));
}
} catch (Exception e) {
m_logger.log(Level.SEVERE, e.toString(), e);
}
}
for (int i = 0; i < files.length; i++) {
files[i].delete();
}
}
}
});
t.setDaemon(true);
t.setName("JAM-" + ID + "-Thread-(deamon)");
t.start();
}
}
use of de.janrufmonitor.exception.Message in project janrufmonitor by tbrandt77.
the class AutoUpdateService method triggerUpdate.
private void triggerUpdate() {
this.m_logger.info("Starting automatic Update-Check...");
UpdateManager m = new UpdateManager();
List u = m.getUpdates();
if (u != null && u.size() > 0) {
PropagationFactory.getInstance().fire(new Message(Message.INFO, getRuntime().getI18nManagerFactory().getI18nManager().getString(getNamespace(), "title", "label", getRuntime().getConfigManagerFactory().getConfigManager().getProperty(IJAMConst.GLOBAL_NAMESPACE, IJAMConst.GLOBAL_LANGUAGE)), new Exception(getRuntime().getI18nManagerFactory().getI18nManager().getString(getNamespace(), "newupdates", "label", getRuntime().getConfigManagerFactory().getConfigManager().getProperty(IJAMConst.GLOBAL_NAMESPACE, IJAMConst.GLOBAL_LANGUAGE)))), "Tray");
this.m_logger.info("Automatic Update-Check is executed for " + u.size() + " modules.");
ICommand updateCommand = this.getRuntime().getCommandFactory().getCommand("UpdatesCommand");
if (updateCommand != null && updateCommand.isExecutable()) {
try {
this.m_logger.info("Executing UpdateCommand...");
Map parameter = new HashMap(1);
parameter.put("preload", Boolean.TRUE);
updateCommand.setParameters(parameter);
updateCommand.execute();
} catch (Exception e) {
this.m_logger.log(Level.SEVERE, e.getMessage(), e);
}
}
} else {
this.m_logger.info("No updates available.");
}
getRuntime().getConfigManagerFactory().getConfigManager().setProperty(NAMESPACE, "lastupdatecheck", Long.toString(System.currentTimeMillis()));
getRuntime().getConfigManagerFactory().getConfigManager().saveConfiguration();
}
Aggregations